// File: /workspace/github_cpp_makefile_star2_O3/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edi, %ebx
callq 0x8b17
movslq %ebx, %rbx
testl %eax, %eax
je 0x9121
imulq $0xa8, %rbx, %rax
leaq 0xb01f8(%rip), %rcx     # 0xb90c8
leaq (%rcx,%rax), %rbx
addq $0x88, %rbx
movq 0xa9a2e(%rip), %rdx     # 0xb2910
cmpq 0x8(%rbx), %rdx
jne 0x8f08
testq %rdx, %rdx
je 0x9091
movq (%rbx), %rsi
movq 0xa9a0d(%rip), %rdi     # 0xb2908
callq 0x2240
testl %eax, %eax
je 0x9091
leaq 0xa99f9(%rip), %rdi     # 0xb2908
leaq 0xa63a(%rip), %rsi      # 0x13550
callq 0x2090
testl %eax, %eax
je 0x9091
movq 0xa99ae(%rip), %rbp     # 0xb28d8
movq 0xa99af(%rip), %r15     # 0xb28e0
cmpq %r15, %rbp
je 0x906a
movq 0xa99cf(%rip), %r14     # 0xb2910
movq 0xa99c0(%rip), %rax     # 0xb2908
movq %rax, 0x20(%rsp)
movq 0xa996c(%rip), %rax     # 0xb28c0
movq %rax, 0x8(%rsp)
movq 0xa9968(%rip), %rax     # 0xb28c8
movq %rax, 0x10(%rsp)
movq %r15, 0x18(%rsp)
cmpq 0x38(%rbp), %r14
jne 0x905d
testq %r14, %r14
je 0x8f92
movq 0x30(%rbp), %rsi
movq 0x20(%rsp), %rdi
movq %r14, %rdx
callq 0x2240
testl %eax, %eax
jne 0x905d
movq (%rbp), %r13
movq 0x8(%rbp), %r15
cmpq %r15, %r13
je 0x8fd2
movq 0x8(%rbx), %r12
cmpq 0x8(%r13), %r12
jne 0x8fc9
testq %r12, %r12
je 0x910e
movq (%r13), %rsi
movq (%rbx), %rdi
movq %r12, %rdx
callq 0x2240
testl %eax, %eax
je 0x910e
addq $0x50, %r13
cmpq %r15, %r13
jne 0x8fa3
movq 0x18(%rbp), %r13
movq 0x20(%rbp), %r15
cmpq %r15, %r13
je 0x9012
movq 0x8(%rbx), %r12
cmpq 0x8(%r13), %r12
jne 0x9009
testq %r12, %r12
je 0x910e
movq (%r13), %rsi
movq (%rbx), %rdi
movq %r12, %rdx
callq 0x2240
testl %eax, %eax
je 0x910e
addq $0x50, %r13
cmpq %r15, %r13
jne 0x8fe3
movq 0x10(%rsp), %rax
cmpq %rax, 0x8(%rsp)
movq 0x18(%rsp), %r15
je 0x905d
movq 0x8(%rbx), %r12
movq 0x8(%rsp), %r13
cmpq %r12, 0x8(%r13)
jne 0x9052
testq %r12, %r12
je 0x910e
movq (%rbx), %rsi
movq (%r13), %rdi
movq %r12, %rdx
callq 0x2240
testl %eax, %eax
je 0x910e
addq $0x50, %r13
cmpq 0x10(%rsp), %r13
jne 0x902c
addq $0x60, %rbp
cmpq %r15, %rbp
jne 0x8f6a
movq 0xff5f(%rip), %rdi      # 0x18fd0
leaq 0xac52(%rip), %rsi      # 0x13cca
callq 0x2210
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21f0
leaq 0xac66(%rip), %rsi      # 0x13cf5
jmp 0x90f4
movq 0xa9828(%rip), %r13     # 0xb28c0
movq 0xa9829(%rip), %r15     # 0xb28c8
cmpq %r15, %r13
je 0x90cf
movq 0x8(%rbx), %r14
cmpq 0x8(%r13), %r14
jne 0x90c6
testq %r14, %r14
je 0x910e
movq (%r13), %rsi
movq (%rbx), %rdi
movq %r14, %rdx
callq 0x2240
testl %eax, %eax
je 0x910e
addq $0x50, %r13
cmpq %r15, %r13
jne 0x90a8
movq 0xfefa(%rip), %rdi      # 0x18fd0
leaq 0xabed(%rip), %rsi      # 0x13cca
callq 0x2210
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21f0
leaq 0xabec(%rip), %rsi      # 0x13ce0
movq %rax, %rdi
callq 0x2210
movq %rax, %rdi
callq 0x20f0
movl $0x1, %edi
callq 0x2290
movl 0x20(%r13), %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xfea8(%rip), %rdi      # 0x18fd0
leaq 0xabdb(%rip), %rsi      # 0x13d0a
callq 0x2210
imulq $0xa8, %rbx, %rcx
leaq 0xaff86(%rip), %rdx     # 0xb90c8
leaq (%rdx,%rcx), %rbx
addq $0x88, %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21f0
leaq 0xabc0(%rip), %rsi      # 0x13d1f
movq %rax, %rdi
callq 0x2210
movl 0x24(%rbx), %esi
movq %rax, %rdi
callq 0x2390
jmp 0x90fc