// File: /workspace/github_cpp_makefile_star2_O2/acliusBackHome[P]kamaya/dist/ParseNode.cpp
// Function: ParseNode::action_declaration(unsigned long, IR&) const
void ParseNode::action_declaration(size_t scope_id, IR &ir) const {
    if (type != N_DECLARATION) {
        // 目前只允许声明节点做这个声明动作
        string info = "ParseNode::action_declaration(size_t scope_id): node_type=";
        info += get_node_type_name(type);
        info += "node_id=" + to_string(node_id);
        throw ParseException(EX_NODE_NOT_ALLOW_OP, info);
    }
    // 寻找初始化器节点和类型声明节点
    size_t init_declarator_list_node = 0, declaration_specifiers_node = 0;
    for (const auto &each :tree.node_children[node_id]) {
        if (tree.nodes[each].type == N_INIT_DECLARATOR_LIST) {
            init_declarator_list_node = each;
        } else if (tree.nodes[each].type == N_DECLARATION_SPE) {
            declaration_specifiers_node = each;
        }
    }
    if (!init_declarator_list_node || !declaration_specifiers_node) {
        // 找不到所需信息, 树结构不完整
        string info = "action_declaration(size_t scope_id) scope_id=";
        info += to_string(scope_id);
        info += " node_id=";
        info += to_string(node_id);
        throw ParseException(EX_TREE_NOT_INCOMPLETE, info);
    }
    // 初始化所需所有信息列表
    const auto &init_dec_list = tree.nodes[init_declarator_list_node].get_init_declarators();
    // 声明的类型
    const auto &dec_type = tree.nodes[declaration_specifiers_node].get_type();
    auto &which_scope = ParseScope::get_scope(scope_id);
    for (const auto &each : init_dec_list) {
        const string &symbol = get<0>(each);// 变量符号
        const ParseExpression &init_expr = get<1>(each);// 初始化表达式
        size_t ptr_level = get<2>(each);// 指针级数
        const size_t &param_list_node = get<4>(each);// 声明为函数时的参数列表节点, 如果不声明为函数该值为0
        const vector<size_t> &array_size = get<3>(each);
        ParseType this_type(dec_type);
        if (ptr_level) {
            this_type = ParseType::get_pointer(this_type, ptr_level);
        }
        if (!array_size.empty()) {
            for (size_t i = array_size.size() - 1;; --i) {
                this_type = ParseType::get_array(this_type, array_size[i]);
                if (!i) {
                    break;
                }
            }
        }
        if (param_list_node) {
            // 这里是函数声明
            const auto &args = tree.nodes[param_list_node].get_parameters_list();
            which_scope.declaration(symbol, ParseFunction(this_type, symbol, args)
            );
        } else {
            // 这里是变量声明
            size_t addr = action_variable_declaration_code_generate(ir, init_expr, this_type, symbol, scope_id);
            ParseScope::get_scope(scope_id).declaration(symbol, ParseVariable(this_type, symbol, addr, scope_id));
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdx, -0x78(%rbp)
movq %rdi, %r12
movq %rsi, -0x30(%rbp)
cmpl $0xe, 0x18(%rdi)
jne 0x19944
movq %rsi, %r14
movq 0x10(%r12), %rax
movq 0x60(%rax), %rdx
imulq $0x18, (%r12), %rsi
movq (%rdx,%rsi), %rcx
movq 0x8(%rdx,%rsi), %rdx
xorl %r15d, %r15d
xorl %edi, %edi
cmpq %rdx, %rcx
je 0x1977e
movq (%rcx), %rsi
movq (%rax), %r8
movq %rsi, %r9
shlq $0x5, %r9
movl 0x18(%r8,%r9), %r8d
cmpl $0x5, %r8d
movq %r15, %r9
cmoveq %rsi, %r9
cmpl $0xc, %r8d
cmovneq %r9, %r15
cmoveq %rsi, %rdi
addq $0x8, %rcx
jmp 0x1974a
testq %rdi, %rdi
je 0x19a08
testq %r15, %r15
je 0x19a08
shlq $0x5, %rdi
addq (%rax), %rdi
callq 0x18f0c
movq %rax, %rbx
movq %r12, -0x38(%rbp)
movq 0x10(%r12), %rax
shlq $0x5, %r15
addq (%rax), %r15
movq %r15, %rdi
callq 0x18ea6
movq %rax, -0x90(%rbp)
movq %r14, %rdi
callq 0x28370
movq %rax, -0x80(%rbp)
movq (%rbx), %r12
movq 0x8(%rbx), %rax
movq %rax, -0x98(%rbp)
leaq -0x70(%rbp), %r13
leaq -0x110(%rbp), %r14
cmpq -0x98(%rbp), %r12
je 0x19932
movq 0x20(%r12), %rbx
movq %r13, %rdi
movq -0x90(%rbp), %rsi
callq 0x210f4
testq %rbx, %rbx
je 0x1982a
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x214f6
movq %r13, %rdi
movq %r14, %rsi
callq 0x21c00
movq %r14, %rdi
callq 0x21c36
movq 0x8(%r12), %rax
movq 0x10(%r12), %rbx
cmpq %rbx, %rax
je 0x19870
subq %rax, %rbx
sarq $0x3, %rbx
movq 0x8(%r12), %rax
movq -0x8(%rax,%rbx,8), %rdx
movq %r14, %rdi
movq %r13, %rsi
callq 0x214a6
movq %r13, %rdi
movq %r14, %rsi
callq 0x21c00
decq %rbx
movq %r14, %rdi
callq 0x21c36
testq %rbx, %rbx
jne 0x19840
leaq 0x58(%r12), %rbx
movq (%r12), %rdi
testq %rdi, %rdi
je 0x198c0
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
shlq $0x5, %rdi
addq (%rax), %rdi
callq 0x190b6
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %rax, %rcx
pushq $-0x1
popq %r8
callq 0x2767e
movq -0x80(%rbp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x285fc
movq %r14, %rdi
callq 0xcdb4
jmp 0x19921
leaq 0x28(%r12), %rdx
movq -0x38(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq %r13, %rcx
movq %rbx, %r15
movq %rbx, %r8
leaq -0x30(%rbp), %r9
callq 0x19b60
movq %rax, %rbx
movq -0x30(%rbp), %rdi
callq 0x28370
movq %rax, -0x88(%rbp)
movq -0x30(%rbp), %r8
movq %r14, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x27360
movq -0x88(%rbp), %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x284ce
movq %r14, %rdi
callq 0xca7e
movq %r13, %rdi
callq 0x21c36
addq $0x78, %r12
jmp 0x197e3
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x21250(%rip), %rsi     # 0x3ab9b
leaq -0x110(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x4130
movl 0x18(%r12), %esi
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
callq 0x17f38
leaq -0x110(%rbp), %rdi
movq %rbx, %rsi
callq 0x4580
leaq -0x70(%rbp), %rdi
callq 0x4598
movq (%r12), %rsi
leaq -0x130(%rbp), %rdi
callq 0xc865
leaq 0x20d56(%rip), %rsi     # 0x3a6f1
leaq -0x70(%rbp), %rdi
leaq -0x130(%rbp), %rdx
callq 0xc837
leaq -0x110(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4580
leaq -0x70(%rbp), %rdi
callq 0x4598
leaq -0x130(%rbp), %rdi
callq 0x4598
pushq $0x28
popq %rdi
callq 0x4180
movq %rax, %r14
pushq $0x4
popq %rsi
leaq -0x110(%rbp), %rdx
movq %rax, %rdi
callq 0x2b53c
leaq 0x3937c(%rip), %rsi     # 0x52d70
leaq -0xd153(%rip), %rdx     # 0xc8a8
movq %r14, %rdi
callq 0x44e0
jmp 0x19ab1
leaq 0x211c7(%rip), %rsi     # 0x3abd6
leaq -0x110(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x4130
movq -0x30(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0xc865
leaq -0x110(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4580
leaq -0x70(%rbp), %rdi
callq 0x4598
leaq 0x20ca4(%rip), %rsi     # 0x3a6f0
leaq -0x110(%rbp), %rdi
callq 0x4540
movq (%r12), %rsi
leaq -0x70(%rbp), %rdi
callq 0xc865
leaq -0x110(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4580
leaq -0x70(%rbp), %rdi
callq 0x4598
pushq $0x28
popq %rdi
callq 0x4180
movq %rax, %r14
pushq $0x5
popq %rsi
leaq -0x110(%rbp), %rdx
movq %rax, %rdi
callq 0x2b53c
leaq 0x392ce(%rip), %rsi     # 0x52d70
leaq -0xd201(%rip), %rdx     # 0xc8a8
movq %r14, %rdi
callq 0x44e0
jmp 0x19ab7
jmp 0x19aeb
jmp 0x19ae6
movq %rax, %rbx
movq %r14, %rdi
callq 0x4220
jmp 0x19af7
jmp 0x19ae6
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x4598
jmp 0x19ad7
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
jmp 0x19af2
jmp 0x19ae6
jmp 0x19aeb
jmp 0x19ae6
movq %rax, %rbx
jmp 0x19af7
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x4598
leaq -0x110(%rbp), %rdi
callq 0x4598
jmp 0x19b57
jmp 0x19b07
movq %rax, %rbx
jmp 0x19b57
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0xca7e
jmp 0x19b4e
jmp 0x19b4b
jmp 0x19b4b
jmp 0x19b4b
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0xcdb4
jmp 0x19b4e
jmp 0x19b3a
jmp 0x19b4b
jmp 0x19b4b
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0x21c36
jmp 0x19b4e
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x21c36
movq %rbx, %rdi
callq 0x4500
nop