// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movl %edi, %ebx
callq 0x8b17
movslq %ebx, %rbx
testl %eax, %eax
je 0x91b2
imulq $0xa8, %rbx, %rax
leaq 0xb11be(%rip), %rcx     # 0xba0c8
leaq (%rcx,%rax), %rbx
addq $0x88, %rbx
movq 0xaa9f4(%rip), %rdx     # 0xb3910
cmpq 0x8(%rbx), %rdx
jne 0x8f42
testq %rdx, %rdx
je 0x9111
movq (%rbx), %rsi
movq 0xaa9d3(%rip), %rdi     # 0xb3908
callq 0x2240
testl %eax, %eax
je 0x9111
leaq 0xaa9bf(%rip), %rdi     # 0xb3908
leaq 0xb5d0(%rip), %rsi      # 0x14520
callq 0x2090
testl %eax, %eax
je 0x9111
movq 0xaa974(%rip), %r15     # 0xb38d8
movq 0xaa975(%rip), %r14     # 0xb38e0
cmpq %r14, %r15
sete %bpl
je 0x9192
movq 0xaa991(%rip), %r12     # 0xb3910
movq 0xaa982(%rip), %rax     # 0xb3908
movq %rax, 0x30(%rsp)
movq 0xaa92e(%rip), %rax     # 0xb38c0
movq 0xaa92f(%rip), %rcx     # 0xb38c8
movq %rax, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
cmpq %rcx, %rax
sete 0xb(%rsp)
movq %r14, 0x18(%rsp)
movq %r12, 0x10(%rsp)
cmpq 0x38(%r15), %r12
jne 0x90fb
testq %r12, %r12
je 0x8fdd
movq 0x30(%r15), %rsi
movq 0x30(%rsp), %rdi
movq %r12, %rdx
callq 0x2240
testl %eax, %eax
jne 0x90fb
movb %bpl, 0xa(%rsp)
movq (%r15), %r13
movq 0x8(%r15), %rbp
cmpq %rbp, %r13
sete %r14b
je 0x902b
movq 0x8(%rbx), %r12
cmpq 0x8(%r13), %r12
jne 0x9014
testq %r12, %r12
je 0x9023
movq (%r13), %rsi
movq (%rbx), %rdi
movq %r12, %rdx
callq 0x2240
testl %eax, %eax
je 0x9023
addq $0x50, %r13
cmpq %rbp, %r13
sete %r14b
jne 0x8ff6
jmp 0x902b
movl 0x20(%r13), %eax
movl %eax, 0xc(%rsp)
testb $0x1, %r14b
je 0x9194
movq 0x18(%r15), %r13
movq 0x20(%r15), %rbp
cmpq %rbp, %r13
sete %r14b
je 0x907f
movq 0x8(%rbx), %r12
cmpq 0x8(%r13), %r12
jne 0x9068
testq %r12, %r12
je 0x9077
movq (%r13), %rsi
movq (%rbx), %rdi
movq %r12, %rdx
callq 0x2240
testl %eax, %eax
je 0x9077
addq $0x50, %r13
cmpq %rbp, %r13
sete %r14b
jne 0x904a
jmp 0x907f
movl 0x20(%r13), %eax
movl %eax, 0xc(%rsp)
testb $0x1, %r14b
movq 0x10(%rsp), %r12
movq 0x28(%rsp), %r13
movq 0x20(%rsp), %rbp
je 0x9194
cmpq %rbp, %r13
je 0x90d3
movq 0x8(%rbx), %r12
movb 0xb(%rsp), %r14b
movq 0x8(%r13), %rdx
cmpq %r12, %rdx
jne 0x90c4
testq %rdx, %rdx
je 0x90da
movq (%rbx), %rsi
movq (%r13), %rdi
callq 0x2240
testl %eax, %eax
je 0x90da
addq $0x50, %r13
cmpq %rbp, %r13
sete %r14b
jne 0x90a6
jmp 0x90e2
movb 0xb(%rsp), %r14b
jmp 0x90e7
movl 0x20(%r13), %eax
movl %eax, 0xc(%rsp)
movq 0x10(%rsp), %r12
testb $0x1, %r14b
movb 0xa(%rsp), %bpl
movq 0x18(%rsp), %r14
je 0x9199
addq $0x60, %r15
cmpq %r14, %r15
sete %bpl
jne 0x8fb5
jmp 0x9199
movq 0xaa7a8(%rip), %r15     # 0xb38c0
movq 0xaa7a9(%rip), %r12     # 0xb38c8
cmpq %r12, %r15
sete %bpl
je 0x9158
movq 0x8(%rbx), %r14
cmpq 0x8(%r15), %r14
jne 0x9149
testq %r14, %r14
je 0x915a
movq (%r15), %rsi
movq (%rbx), %rdi
movq %r14, %rdx
callq 0x2240
testl %eax, %eax
je 0x915a
addq $0x50, %r15
cmpq %r12, %r15
sete %bpl
jne 0x912c
jmp 0x9162
jmp 0x9162
movl 0x20(%r15), %eax
movl %eax, 0xc(%rsp)
testb $0x1, %bpl
je 0x919f
movq 0x10e61(%rip), %rdi     # 0x19fd0
leaq 0xbb24(%rip), %rsi      # 0x14c9a
callq 0x2210
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21f0
leaq 0xbb23(%rip), %rsi      # 0x14cb0
jmp 0x922a
jmp 0x9199
movb 0xa(%rsp), %bpl
testb $0x1, %bpl
jne 0x9205
movl 0xc(%rsp), %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10e17(%rip), %rdi     # 0x19fd0
leaq 0xbb1a(%rip), %rsi      # 0x14cda
callq 0x2210
imulq $0xa8, %rbx, %rcx
leaq 0xb0ef5(%rip), %rdx     # 0xba0c8
leaq (%rdx,%rcx), %rbx
addq $0x88, %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21f0
leaq 0xbaff(%rip), %rsi      # 0x14cef
movq %rax, %rdi
callq 0x2210
movl 0x24(%rbx), %esi
movq %rax, %rdi
callq 0x2390
jmp 0x9232
movq 0x10dc4(%rip), %rdi     # 0x19fd0
leaq 0xba87(%rip), %rsi      # 0x14c9a
callq 0x2210
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21f0
leaq 0xba9b(%rip), %rsi      # 0x14cc5
movq %rax, %rdi
callq 0x2210
movq %rax, %rdi
callq 0x20f0
movl $0x1, %edi
callq 0x2290