// File: 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
subq $0x3b0, %rsp            # imm = 0x3B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x350(%rbp)
cmpl $0xe, 0x18(%rax)
je 0x3edc0
leaq -0x39(%rbp), %rdi
movq %rdi, -0x358(%rbp)
callq 0x45f0
movq -0x358(%rbp), %rdx
leaq 0x50f39(%rip), %rsi     # 0x8fb73
leaq -0x38(%rbp), %rdi
callq 0x4450
jmp 0x3ec45
leaq -0x39(%rbp), %rdi
callq 0x4380
movq -0x350(%rbp), %rax
movl 0x18(%rax), %esi
leaq -0x70(%rbp), %rdi
movq %rdi, -0x360(%rbp)
callq 0x3bcf0
movq -0x360(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x43f0
jmp 0x3ec7a
leaq -0x70(%rbp), %rdi
callq 0x4688
movq -0x350(%rbp), %rax
movq (%rax), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x15db0
jmp 0x3ec9b
leaq 0x50a75(%rip), %rsi     # 0x8f717
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rdx
callq 0x15d60
jmp 0x3ecb7
leaq -0x38(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x43f0
jmp 0x3ecc9
leaq -0x90(%rbp), %rdi
callq 0x4688
leaq -0xb0(%rbp), %rdi
callq 0x4688
movl $0x28, %edi
callq 0x41c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x368(%rbp)
movl $0x4, %esi
leaq -0x38(%rbp), %rdx
callq 0x73a90
jmp 0x3ed08
movq -0x368(%rbp), %rdi
leaq 0x8703a(%rip), %rsi     # 0xc5d50
leaq -0x28e8d(%rip), %rdx    # 0x15e90
callq 0x45b0
jmp 0x3f4a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x4380
jmp 0x3f49e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x4688
jmp 0x3edb2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x3edb2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x3ed8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x4688
leaq -0xb0(%rbp), %rdi
callq 0x4688
jmp 0x3edb2
movq -0x368(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x4280
leaq -0x38(%rbp), %rdi
callq 0x4688
jmp 0x3f49e
movq -0x350(%rbp), %rax
movq $0x0, -0xb8(%rbp)
movq $0x0, -0xc0(%rbp)
movq 0x10(%rax), %rdi
addq $0x60, %rdi
movq (%rax), %rsi
callq 0x340a0
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x34240
movq %rax, -0xd0(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x34270
movq %rax, -0xd8(%rbp)
leaq -0xd0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x342a0
testb $0x1, %al
jne 0x3ee36
jmp 0x3eec5
leaq -0xd0(%rbp), %rdi
callq 0x342e0
movq %rax, %rcx
movq -0x350(%rbp), %rax
movq %rcx, -0xe0(%rbp)
movq 0x10(%rax), %rdi
movq -0xe0(%rbp), %rax
movq (%rax), %rsi
callq 0x34080
cmpl $0xc, 0x18(%rax)
jne 0x3ee7f
movq -0xe0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xb8(%rbp)
jmp 0x3eeb2
movq -0x350(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0xe0(%rbp), %rax
movq (%rax), %rsi
callq 0x34080
cmpl $0x5, 0x18(%rax)
jne 0x3eeb0
movq -0xe0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
jmp 0x3eeb2
jmp 0x3eeb4
leaq -0xd0(%rbp), %rdi
callq 0x34300
jmp 0x3ee1a
cmpq $0x0, -0xb8(%rbp)
je 0x3eedd
cmpq $0x0, -0xc0(%rbp)
jne 0x3f06a
leaq -0x101(%rbp), %rdi
movq %rdi, -0x370(%rbp)
callq 0x45f0
movq -0x370(%rbp), %rdx
leaq 0x50cb0(%rip), %rsi     # 0x8fbae
leaq -0x100(%rbp), %rdi
callq 0x4450
jmp 0x3ef0c
leaq -0x101(%rbp), %rdi
callq 0x4380
movq -0x10(%rbp), %rsi
leaq -0x128(%rbp), %rdi
callq 0x15db0
jmp 0x3ef2a
leaq -0x100(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x43f0
jmp 0x3ef3f
leaq -0x128(%rbp), %rdi
callq 0x4688
leaq 0x507c4(%rip), %rsi     # 0x8f716
leaq -0x100(%rbp), %rdi
callq 0x42e0
jmp 0x3ef60
movq -0x350(%rbp), %rax
movq (%rax), %rsi
leaq -0x148(%rbp), %rdi
callq 0x15db0
jmp 0x3ef78
leaq -0x100(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x43f0
jmp 0x3ef8d
leaq -0x148(%rbp), %rdi
callq 0x4688
movl $0x28, %edi
callq 0x41c0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x378(%rbp)
movl $0x5, %esi
leaq -0x100(%rbp), %rdx
callq 0x73a90
jmp 0x3efc3
movq -0x378(%rbp), %rdi
leaq 0x86d7f(%rip), %rsi     # 0xc5d50
leaq -0x29148(%rip), %rdx    # 0x15e90
callq 0x45b0
jmp 0x3f4a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x101(%rbp), %rdi
callq 0x4380
jmp 0x3f49e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x3f059
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x4688
jmp 0x3f059
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x4688
jmp 0x3f059
movq -0x378(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x4280
leaq -0x100(%rbp), %rdi
callq 0x4688
jmp 0x3f49e
movq -0x350(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0xb8(%rbp), %rsi
callq 0x34080
movq %rax, %rdi
callq 0x3de70
movq %rax, %rcx
movq -0x350(%rbp), %rax
movq %rcx, -0x150(%rbp)
movq 0x10(%rax), %rdi
movq -0xc0(%rbp), %rsi
callq 0x34080
movq %rax, %rdi
callq 0x3dd90
movq %rax, -0x158(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6a860
movq %rax, -0x160(%rbp)
movq -0x150(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rdi
callq 0x40190
movq %rax, -0x170(%rbp)
movq -0x168(%rbp), %rdi
callq 0x401c0
movq %rax, -0x178(%rbp)
leaq -0x170(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x401f0
testb $0x1, %al
jne 0x3f119
jmp 0x3f495
leaq -0x170(%rbp), %rdi
callq 0x40230
movq %rax, -0x180(%rbp)
movq -0x180(%rbp), %rdi
callq 0x40250
movq %rax, -0x188(%rbp)
movq -0x180(%rbp), %rdi
callq 0x40270
movq %rax, -0x190(%rbp)
movq -0x180(%rbp), %rdi
callq 0x40290
movq (%rax), %rax
movq %rax, -0x198(%rbp)
movq -0x180(%rbp), %rdi
callq 0x402d0
movq %rax, -0x1a0(%rbp)
movq -0x180(%rbp), %rdi
callq 0x402b0
movq %rax, -0x1a8(%rbp)
movq -0x158(%rbp), %rsi
leaq -0x1e0(%rbp), %rdi
callq 0x55d70
cmpq $0x0, -0x198(%rbp)
je 0x3f218
movq -0x198(%rbp), %rdx
leaq -0x218(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x565c0
jmp 0x3f1c7
leaq -0x1e0(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x572a0
jmp 0x3f1dc
leaq -0x218(%rbp), %rdi
callq 0x57350
jmp 0x3f218
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x3f487
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x218(%rbp), %rdi
callq 0x57350
jmp 0x3f487
movq -0x1a8(%rbp), %rdi
callq 0x167a0
testb $0x1, %al
jne 0x3f2d3
movq -0x1a8(%rbp), %rdi
callq 0x16570
subq $0x1, %rax
movq %rax, -0x220(%rbp)
movq -0x1a8(%rbp), %rdi
movq -0x220(%rbp), %rsi
callq 0x165e0
movq (%rax), %rdx
leaq -0x258(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x56540
jmp 0x3f26e
leaq -0x1e0(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x572a0
jmp 0x3f283
leaq -0x258(%rbp), %rdi
callq 0x57350
cmpq $0x0, -0x220(%rbp)
jne 0x3f2b8
jmp 0x3f2d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x57350
jmp 0x3f487
jmp 0x3f2ba
movq -0x220(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x220(%rbp)
jmp 0x3f243
jmp 0x3f2d3
movq -0x1a0(%rbp), %rax
cmpq $0x0, (%rax)
je 0x3f3a6
movq -0x350(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x1a0(%rbp), %rax
movq (%rax), %rsi
callq 0x34080
movq %rax, %rdi
callq 0x3e190
movq %rax, -0x380(%rbp)
jmp 0x3f30f
movq -0x380(%rbp), %rax
movq %rax, -0x260(%rbp)
movq -0x160(%rbp), %rax
movq %rax, -0x390(%rbp)
movq -0x188(%rbp), %rdx
movq %rdx, -0x388(%rbp)
movq -0x260(%rbp), %rcx
leaq -0x2d8(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
movq $-0x1, %r8
callq 0x68af0
jmp 0x3f35c
movq -0x388(%rbp), %rsi
movq -0x390(%rbp), %rdi
leaq -0x2d8(%rbp), %rdx
callq 0x6acc0
jmp 0x3f378
leaq -0x2d8(%rbp), %rdi
callq 0x16bc0
jmp 0x3f46a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x2d8(%rbp), %rdi
callq 0x16bc0
jmp 0x3f487
movq -0x350(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x190(%rbp), %rdx
movq -0x188(%rbp), %r8
leaq -0x1e0(%rbp), %rcx
leaq -0x10(%rbp), %r9
callq 0x3f4b0
movq %rax, -0x398(%rbp)
jmp 0x3f3d8
movq -0x398(%rbp), %rax
movq %rax, -0x2e0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x6a860
movq %rax, -0x3a0(%rbp)
jmp 0x3f3f8
movq -0x188(%rbp), %rdx
movq %rdx, -0x3a8(%rbp)
movq -0x2e0(%rbp), %rcx
movq -0x10(%rbp), %r8
leaq -0x348(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x68440
jmp 0x3f426
movq -0x3a8(%rbp), %rsi
movq -0x3a0(%rbp), %rdi
leaq -0x348(%rbp), %rdx
callq 0x6aac0
jmp 0x3f442
leaq -0x348(%rbp), %rdi
callq 0x16210
jmp 0x3f46a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x348(%rbp), %rdi
callq 0x16210
jmp 0x3f487
leaq -0x1e0(%rbp), %rdi
callq 0x57350
leaq -0x170(%rbp), %rdi
callq 0x402f0
jmp 0x3f0fd
leaq -0x1e0(%rbp), %rdi
callq 0x57350
jmp 0x3f49e
addq $0x3b0, %rsp            # imm = 0x3B0
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x45e0
nopw (%rax,%rax)