// File: /workspace/github_cpp_makefile_star2_O3/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 0x1db91
movq %rsi, %r14
movq (%r12), %rcx
movq 0x10(%r12), %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 0x1dabb
movq (%rax), %rsi
xorl %edi, %edi
xorl %r15d, %r15d
movq %r15, %r8
movq (%rcx), %r9
movq %r9, %r10
shlq $0x5, %r10
movl 0x18(%rsi,%r10), %r10d
cmpl $0x5, %r10d
cmoveq %r9, %r15
cmpl $0xc, %r10d
cmoveq %r8, %r15
cmoveq %r9, %rdi
addq $0x8, %rcx
cmpq %rdx, %rcx
jne 0x1d883
testq %rdi, %rdi
je 0x1dabb
testq %r15, %r15
je 0x1dabb
shlq $0x5, %rdi
addq (%rax), %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x2325a
movq %rax, %rbx
movq %r12, -0x38(%rbp)
movq 0x10(%r12), %rax
shlq $0x5, %r15
addq (%rax), %r15
movq %r15, %rdi
movl $0x8, %esi
callq 0x209c6
movq %rax, -0x98(%rbp)
movq %r14, %rdi
callq 0x2f994
movq %rax, -0x80(%rbp)
movq (%rbx), %r12
movq 0x8(%rbx), %rax
movq %rax, -0x90(%rbp)
cmpq %rax, %r12
je 0x1daa9
leaq -0x70(%rbp), %r14
leaq -0x110(%rbp), %r13
movq 0x20(%r12), %rbx
movq %r14, %rdi
movq -0x98(%rbp), %rsi
callq 0x26e80
testq %rbx, %rbx
je 0x1d964
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x27308
movq %r14, %rdi
movq %r13, %rsi
callq 0x27c6c
movq %r13, %rdi
callq 0x27ca8
movq 0x8(%r12), %rax
movq 0x10(%r12), %rbx
cmpq %rbx, %rax
je 0x1d9bb
subq %rax, %rbx
sarq $0x3, %rbx
leaq (%rax,%rbx,8), %rax
addq $-0x8, %rax
decq %rbx
movq (%rax), %rdx
movq %r13, %rdi
movq %r14, %rsi
callq 0x272b6
movq %r14, %rdi
movq %r13, %rsi
callq 0x27c6c
movq %r13, %rdi
callq 0x27ca8
subq $0x1, %rbx
jb 0x1d9bb
leaq (,%rbx,8), %rax
addq 0x8(%r12), %rax
jmp 0x1d985
leaq 0x58(%r12), %rbx
movq (%r12), %rdi
testq %rdi, %rdi
je 0x1da17
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
shlq $0x5, %rdi
addq (%rax), %rdi
movl $0x100000, %esi         # imm = 0x100000
callq 0x220f6
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %rax, %rcx
movq $-0x1, %r8
callq 0x2e8e2
movq -0x80(%rbp), %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x2fcc2
leaq -0xb8(%rbp), %rdi
callq 0xe9e6
jmp 0x1da70
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 0x1dd4e
movq %rax, %rbx
movq -0x30(%rbp), %rdi
callq 0x2f994
movq %rax, -0x88(%rbp)
movq -0x30(%rbp), %r8
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x2e366
movq -0x88(%rbp), %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x2fb46
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x1da88
callq 0x42b0
movq %r13, %rdi
callq 0x27ca8
movq %r14, %rdi
callq 0x27ca8
addq $0x78, %r12
cmpq -0x90(%rbp), %r12
jne 0x1d92a
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x100(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x28174(%rip), %rsi     # 0x45c41
leaq 0x2819a(%rip), %rdx     # 0x45c6e
leaq -0x110(%rbp), %rdi
callq 0xf868
movq -0x30(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0xe50f
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 0x1db13
callq 0x42b0
leaq 0x27bca(%rip), %rsi     # 0x456e4
leaq -0x110(%rbp), %rdi
callq 0x45c0
movq (%r12), %rsi
leaq -0x70(%rbp), %rdi
callq 0xe50f
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
leaq -0x110(%rbp), %rdi
callq 0x4110
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x1db55
callq 0x42b0
movl $0x28, %edi
callq 0x4190
movq %rax, %r14
leaq -0x110(%rbp), %rdx
movq %rax, %rdi
movl $0x5, %esi
callq 0x333ee
leaq 0x3d1f3(%rip), %rsi     # 0x5ad70
leaq -0xf5e4(%rip), %rdx     # 0xe5a0
movq %r14, %rdi
callq 0x4540
jmp 0x1dc81
leaq -0x100(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x28063(%rip), %rsi     # 0x45c06
leaq 0x28096(%rip), %rdx     # 0x45c40
leaq -0x110(%rbp), %rdi
callq 0xf868
movl 0x18(%r12), %esi
leaq -0x70(%rbp), %rbx
movq %rbx, %rdi
callq 0x1a836
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 0x1dbec
callq 0x42b0
movq (%r12), %rsi
leaq -0x130(%rbp), %rdi
callq 0xe50f
leaq 0x27ae2(%rip), %rsi     # 0x456e5
leaq -0x70(%rbp), %rdi
leaq -0x130(%rbp), %rdx
callq 0xe495
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
leaq -0x110(%rbp), %rdi
callq 0x4110
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x1dc35
callq 0x42b0
leaq -0x120(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1dc4a
callq 0x42b0
movl $0x28, %edi
callq 0x4190
movq %rax, %r14
leaq -0x110(%rbp), %rdx
movq %rax, %rdi
movl $0x4, %esi
callq 0x333ee
leaq 0x3d0fe(%rip), %rsi     # 0x5ad70
leaq -0xf6d9(%rip), %rdx     # 0xe5a0
movq %r14, %rdi
callq 0x4540
jmp 0x1dc85
jmp 0x1dcde
movq %rax, %rbx
movq %r14, %rdi
callq 0x4250
jmp 0x1dce1
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
jne 0x1dcd7
jmp 0x1dce1
movq %rax, %rbx
movq -0x70(%rbp), %rdi
cmpq %r14, %rdi
je 0x1dcb8
callq 0x42b0
jmp 0x1dcb8
jmp 0x1dcde
movq %rax, %rbx
leaq -0x120(%rbp), %rax
jmp 0x1dcce
jmp 0x1dcde
jmp 0x1dcde
jmp 0x1dcc7
movq %rax, %rbx
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1dce1
callq 0x42b0
jmp 0x1dce1
movq %rax, %rbx
movq -0x110(%rbp), %rdi
cmpq %r15, %rdi
je 0x1dd46
callq 0x42b0
jmp 0x1dd46
jmp 0x1dcf6
movq %rax, %rbx
jmp 0x1dd46
jmp 0x1dd3a
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0xe8d8
jmp 0x1dd3d
jmp 0x1dd3a
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0xed28
jmp 0x1dd3d
jmp 0x1dd3a
jmp 0x1dd3a
jmp 0x1dd29
jmp 0x1dd3a
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0x27ca8
jmp 0x1dd3d
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x27ca8
movq %rbx, %rdi
callq 0x4560