// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movq %rsi, -0x30(%rbp)
cmpl $0xe, 0x18(%rdi)
jne 0x1da51
movq (%r15), %rcx
movq 0x10(%r15), %rax
movq 0x60(%rax), %rdx
leaq (%rcx,%rcx,2), %rsi
movq (%rdx,%rsi,8), %rcx
movq 0x8(%rdx,%rsi,8), %rdx
cmpq %rdx, %rcx
je 0x1d854
movq (%rax), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
movq %r8, %r14
movq (%rcx), %r9
movq %r9, %r10
shlq $0x5, %r10
movl 0x18(%rsi,%r10), %r10d
cmpl $0x5, %r10d
cmoveq %r9, %r14
cmpl $0xc, %r10d
cmoveq %r8, %r14
cmoveq %r9, %rdi
addq $0x8, %rcx
movq %r14, %r8
cmpq %rdx, %rcx
jne 0x1d823
jmp 0x1d859
xorl %r14d, %r14d
xorl %edi, %edi
testq %rdi, %rdi
je 0x1db49
testq %r14, %r14
je 0x1db49
shlq $0x5, %rdi
addq (%rax), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x23742
movq %rax, %rbx
movq %r15, -0x38(%rbp)
movq 0x10(%r15), %rax
shlq $0x5, %r14
addq (%rax), %r14
movq %r14, %rdi
movl $0x8, %esi
callq 0x20b28
movq %rax, -0x98(%rbp)
movq -0x30(%rbp), %rdi
callq 0x30230
movq %rax, -0x80(%rbp)
movq (%rbx), %r12
movq 0x8(%rbx), %rax
movq %rax, -0x90(%rbp)
cmpq %rax, %r12
je 0x1da3f
leaq -0x70(%rbp), %r14
leaq -0x110(%rbp), %r13
movq 0x20(%r12), %rbx
movq %r14, %rdi
movq -0x98(%rbp), %rsi
callq 0x27510
testq %rbx, %rbx
je 0x1d90b
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x27980
movq %r14, %rdi
movq %r13, %rsi
callq 0x28300
movq %r13, %rdi
callq 0x28344
movq 0x8(%r12), %rax
movq 0x10(%r12), %rbx
cmpq %rbx, %rax
je 0x1d951
subq %rax, %rbx
sarq $0x3, %rbx
movq 0x8(%r12), %rax
movq -0x8(%rax,%rbx,8), %rdx
movq %r13, %rdi
movq %r14, %rsi
callq 0x2791c
movq %r14, %rdi
movq %r13, %rsi
callq 0x28300
decq %rbx
movq %r13, %rdi
callq 0x28344
testq %rbx, %rbx
jne 0x1d921
leaq 0x58(%r12), %rbx
movq (%r12), %rdi
testq %rdi, %rdi
je 0x1d9ad
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
shlq $0x5, %rdi
addq (%rax), %rdi
movl $0x100000, %esi         # imm = 0x100000
callq 0x2245c
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %rax, %rcx
movq $-0x1, %r8
callq 0x2f1a6
movq -0x80(%rbp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x3059e
leaq -0xb8(%rbp), %rdi
callq 0xe800
jmp 0x1da06
leaq 0x28(%r12), %rdx
movq -0x38(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq %r14, %rcx
movq %rbx, %r15
movq %rbx, %r8
leaq -0x30(%rbp), %r9
callq 0x1dcea
movq %rax, %rbx
movq -0x30(%rbp), %rdi
callq 0x30230
movq %rax, -0x88(%rbp)
movq -0x30(%rbp), %r8
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2ec26
movq -0x88(%rbp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x30400
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x1da1e
callq 0x42b0
movq %r13, %rdi
callq 0x28344
movq %r14, %rdi
callq 0x28344
addq $0x78, %r12
cmpq -0x90(%rbp), %r12
jne 0x1d8d1
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %r12
leaq -0x100(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x291a0(%rip), %rsi     # 0x46c06
leaq 0x291d3(%rip), %rdx     # 0x46c40
leaq -0x110(%rbp), %rdi
callq 0xf65c
movl 0x18(%r12), %esi
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
callq 0x1a7b2
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
leaq -0x110(%rbp), %rdi
callq 0x4110
leaq -0x60(%rbp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x1daaf
callq 0x42b0
movq (%r12), %rsi
leaq -0x130(%rbp), %rdi
callq 0xe329
leaq 0x28c1f(%rip), %rsi     # 0x466e5
leaq -0x70(%rbp), %rdi
leaq -0x130(%rbp), %rdx
callq 0xe2af
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
leaq -0x110(%rbp), %rdi
callq 0x4110
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x1daf8
callq 0x42b0
leaq -0x120(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1db0d
callq 0x42b0
movl $0x28, %edi
callq 0x4190
movq %rax, %r14
leaq -0x110(%rbp), %rdx
movq %rax, %rdi
movl $0x4, %esi
callq 0x33d12
leaq 0x3e23b(%rip), %rsi     # 0x5bd70
leaq -0xf782(%rip), %rdx     # 0xe3ba
movq %r14, %rdi
callq 0x4540
jmp 0x1dc1c
movq %r15, %rbx
leaq -0x100(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x290e3(%rip), %rsi     # 0x46c41
leaq 0x29109(%rip), %rdx     # 0x46c6e
leaq -0x110(%rbp), %rdi
callq 0xf65c
movq -0x30(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0xe329
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
leaq -0x110(%rbp), %rdi
callq 0x4110
leaq -0x60(%rbp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x1dba4
callq 0x42b0
leaq 0x28b39(%rip), %rsi     # 0x466e4
leaq -0x110(%rbp), %rdi
callq 0x45c0
movq (%rbx), %rsi
leaq -0x70(%rbp), %rdi
callq 0xe329
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
leaq -0x110(%rbp), %rdi
callq 0x4110
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x1dbe5
callq 0x42b0
movl $0x28, %edi
callq 0x4190
movq %rax, %r14
leaq -0x110(%rbp), %rdx
movq %rax, %rdi
movl $0x5, %esi
callq 0x33d12
leaq 0x3e163(%rip), %rsi     # 0x5bd70
leaq -0xf85a(%rip), %rdx     # 0xe3ba
movq %r14, %rdi
callq 0x4540
jmp 0x1dc2e
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
jne 0x1dc77
jmp 0x1dc7c
jmp 0x1dc62
movq %rax, %rbx
movq %r14, %rdi
callq 0x4250
jmp 0x1dc7c
jmp 0x1dc62
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x1dc53
callq 0x42b0
jmp 0x1dc53
movq %rax, %rbx
leaq -0x120(%rbp), %rax
jmp 0x1dc6e
jmp 0x1dc62
jmp 0x1dc67
jmp 0x1dc62
movq %rax, %rbx
jmp 0x1dc7c
movq %rax, %rbx
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1dc7c
callq 0x42b0
movq -0x110(%rbp), %rdi
cmpq %r15, %rdi
je 0x1dce1
callq 0x42b0
jmp 0x1dce1
jmp 0x1dc91
movq %rax, %rbx
jmp 0x1dce1
jmp 0x1dcd5
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0xe6f2
jmp 0x1dcd8
jmp 0x1dcd5
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0xeb42
jmp 0x1dcd8
jmp 0x1dcd5
jmp 0x1dcd5
jmp 0x1dcc4
jmp 0x1dcd5
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0x28344
jmp 0x1dcd8
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x28344
movq %rbx, %rdi
callq 0x4560
nop