// File: /workspace/github_cpp_makefile_star2_O2/zhengwangsun[P]pas2c/semantics.cpp
// Function: checkIdType(int)
int checkIdType(int id_position)
{
    if (isDefined(id_position) != 0)
    {
        int idType = -1;
        
        if (currentTable == tree.node[id_position].value || currentTable == "main")//说明此id就是此函数名字或者在主表内,此时只要遍历主符号表找到它对应类型
        {
            for(vector<Tuple>::iterator it = mainTable.begin(); it != mainTable.end();it++)
            {
                if (tree.node[id_position].value == it->name)
                {
                    idType = it->type;
                    return idType;
                }
            }
            cout<<"cannot check this id("<<tree.node[id_position].value<<") when checkIdType1!"<<endl;
            exit(1);
            return -1;
        }
        else//遍历子表
        {
            for(vector<subTableItem>::iterator it = subTable.begin(); it != subTable.end();it++)
            {
                if (currentTable == it->name)//匹配到子表名字
                {
                    for (vector<Tuple>::iterator it1 = it->item.begin(); it1 != it->item.end();it1++)
                    {
                        if (tree.node[id_position].value == it1->name)
                        {
                            idType = it1->type;
                            return idType;
                        }
                    }
                    //没找到继续查找参数表
                    for (vector<Tuple>::iterator it2 = it->argument.begin(); it2 != it->argument.end();it2++)
                    {
                        if (tree.node[id_position].value == it2->name)
                        {
                            idType = it2->type;
                            return idType;
                        }
                    }
                    //没找到继续找主表，是否是全局变量
                    for(vector<Tuple>::iterator it = mainTable.begin(); it != mainTable.end();it++)//遍历查重
                    {
                        if(it->name == tree.node[id_position].value)
                        {
                            idType = it->type;
                            return idType;
                        }
                    }
                    
                }
            }
            cout<<"cannot check this id("<<tree.node[id_position].value<<") when checkIdType2!"<<endl;
            exit(1);
            return -1;
        }
    }
    else
    {
        cout<<"cannot find this id("<<tree.node[id_position].value<<")when checkIdType3! line:"<<tree.node[id_position].row<<endl;
        exit(1);
        return -1;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebx
callq 0x6ab8
testl %eax, %eax
je 0x6e32
movslq %ebx, %rax
imulq $0xa8, %rax, %rax
leaq 0xad3b0(%rip), %rcx     # 0xb4098
leaq (%rcx,%rax), %rbx
addq $0x88, %rbx
leaq 0xa6bde(%rip), %rdi     # 0xad8d8
movq %rbx, %rsi
callq 0x5f9f
testb %al, %al
jne 0x6d1d
leaq 0xa6bcb(%rip), %rdi     # 0xad8d8
leaq 0x786c(%rip), %rsi      # 0xe580
callq 0x5f92
testb %al, %al
je 0x6d4a
movq 0xa6b6c(%rip), %r14     # 0xad890
cmpq 0xa6b6d(%rip), %r14     # 0xad898
je 0x6df5
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5f9f
testb %al, %al
jne 0x6de5
addq $0x50, %r14
jmp 0x6d24
movq 0xa6b57(%rip), %r12     # 0xad8a8
leaq 0xa6b80(%rip), %r15     # 0xad8d8
cmpq 0xa6b51(%rip), %r12     # 0xad8b0
je 0x6e88
leaq 0x30(%r12), %rsi
movq %r15, %rdi
callq 0x5f9f
testb %al, %al
je 0x6ddc
movq (%r12), %r14
cmpq 0x8(%r12), %r14
je 0x6d96
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5f9f
testb %al, %al
jne 0x6de5
addq $0x50, %r14
jmp 0x6d7a
movq 0x18(%r12), %r14
cmpq 0x20(%r12), %r14
je 0x6db7
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5f9f
testb %al, %al
jne 0x6de5
addq $0x50, %r14
jmp 0x6d9b
movq 0xa6ad2(%rip), %r14     # 0xad890
cmpq 0xa6ad3(%rip), %r14     # 0xad898
je 0x6ddc
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5f9f
testb %al, %al
jne 0x6de5
addq $0x50, %r14
jmp 0x6dbe
addq $0x60, %r12
jmp 0x6d58
movl 0x20(%r14), %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0xd1d4(%rip), %rdi      # 0x13fd0
leaq 0x7ef7(%rip), %rsi      # 0xecfa
callq 0x21d0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21c0
leaq 0x7ef6(%rip), %rsi      # 0xed10
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
pushq $0x1
popq %rdi
callq 0x2220
movq 0xd197(%rip), %rdi      # 0x13fd0
leaq 0x7efa(%rip), %rsi      # 0xed3a
callq 0x21d0
movslq %ebx, %rcx
imulq $0xa8, %rcx, %rcx
leaq 0xad242(%rip), %rdx     # 0xb4098
leaq (%rdx,%rcx), %rbx
addq $0x88, %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21c0
leaq 0x7edc(%rip), %rsi      # 0xed4f
movq %rax, %rdi
callq 0x21d0
movl 0x24(%rbx), %esi
movq %rax, %rdi
callq 0x2320
jmp 0x6e22
movq 0xd141(%rip), %rdi      # 0x13fd0
leaq 0x7e64(%rip), %rsi      # 0xecfa
callq 0x21d0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21c0
leaq 0x7e78(%rip), %rsi      # 0xed25
jmp 0x6e1a