// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movl %edi, -0x8(%rbp)
movl -0x8(%rbp), %edi
callq 0xda80
cmpl $0x0, %eax
je 0xe529
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
movslq -0x8(%rbp), %rax
leaq 0xb8037(%rip), %rsi     # 0xc6138
addq $0x8, %rsi
imulq $0xa8, %rax, %rax
addq %rax, %rsi
addq $0x80, %rsi
leaq 0xb185b(%rip), %rdi     # 0xbf978
callq 0xc840
testb $0x1, %al
jne 0xe142
leaq 0xb184b(%rip), %rdi     # 0xbf978
leaq 0x10386(%rip), %rsi     # 0x1e4ba
callq 0xc770
testb $0x1, %al
jne 0xe142
jmp 0xe24c
leaq 0xb17e7(%rip), %rdi     # 0xbf930
callq 0x14c50
movq %rax, -0x18(%rbp)
leaq 0xb17d7(%rip), %rdi     # 0xbf930
callq 0x14cc0
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x14c80
testb $0x1, %al
jne 0xe175
jmp 0xe1e9
movslq -0x8(%rbp), %rcx
leaq 0xb7fb8(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
addq $0x80, %rax
movq %rax, -0x90(%rbp)
leaq -0x18(%rbp), %rdi
callq 0x14cf0
movq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0xc840
testb $0x1, %al
jne 0xe1b9
jmp 0xe1d3
leaq -0x18(%rbp), %rdi
callq 0x14cf0
movl 0x20(%rax), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xe5b3
jmp 0xe1d5
leaq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x14d30
movq %rax, -0x28(%rbp)
jmp 0xe152
movq 0x17dd8(%rip), %rdi     # 0x25fc8
leaq 0x10ae1(%rip), %rsi     # 0x1ecd8
callq 0x3280
movq %rax, %rdi
movslq -0x8(%rbp), %rax
leaq 0xb7f2e(%rip), %rsi     # 0xc6138
addq $0x8, %rsi
imulq $0xa8, %rax, %rax
addq %rax, %rsi
addq $0x80, %rsi
callq 0x3260
movq %rax, %rdi
leaq 0x10ac0(%rip), %rsi     # 0x1ecee
callq 0x3280
movq %rax, %rdi
movq 0x17d73(%rip), %rsi     # 0x25fb0
callq 0x32b0
movl $0x1, %edi
callq 0x3340
leaq 0xb16f5(%rip), %rdi     # 0xbf948
callq 0x14b00
movq %rax, -0x30(%rbp)
leaq 0xb16e5(%rip), %rdi     # 0xbf948
callq 0x14b70
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x14b30
testb $0x1, %al
jne 0xe282
jmp 0xe4c6
leaq -0x30(%rbp), %rdi
callq 0x14ba0
movq %rax, %rsi
addq $0x30, %rsi
leaq 0xb16df(%rip), %rdi     # 0xbf978
callq 0xc840
testb $0x1, %al
jne 0xe2a7
jmp 0xe4ad
leaq -0x30(%rbp), %rdi
callq 0x14ba0
movq %rax, %rdi
callq 0x14c50
movq %rax, -0x40(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x14ba0
movq %rax, %rdi
callq 0x14cc0
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x14c80
testb $0x1, %al
jne 0xe2e4
jmp 0xe358
movslq -0x8(%rbp), %rcx
leaq 0xb7e49(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
addq $0x80, %rax
movq %rax, -0x98(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x14cf0
movq -0x98(%rbp), %rdi
movq %rax, %rsi
callq 0xc840
testb $0x1, %al
jne 0xe328
jmp 0xe342
leaq -0x40(%rbp), %rdi
callq 0x14cf0
movl 0x20(%rax), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xe5b3
jmp 0xe344
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x14d30
movq %rax, -0x50(%rbp)
jmp 0xe2bc
leaq -0x30(%rbp), %rdi
callq 0x14ba0
movq %rax, %rdi
addq $0x18, %rdi
callq 0x14c50
movq %rax, -0x58(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x14ba0
movq %rax, %rdi
addq $0x18, %rdi
callq 0x14cc0
movq %rax, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x14c80
testb $0x1, %al
jne 0xe39d
jmp 0xe411
movslq -0x8(%rbp), %rcx
leaq 0xb7d90(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
addq $0x80, %rax
movq %rax, -0xa0(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x14cf0
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
callq 0xc840
testb $0x1, %al
jne 0xe3e1
jmp 0xe3fb
leaq -0x58(%rbp), %rdi
callq 0x14cf0
movl 0x20(%rax), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xe5b3
jmp 0xe3fd
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x14d30
movq %rax, -0x68(%rbp)
jmp 0xe371
leaq 0xb1518(%rip), %rdi     # 0xbf930
callq 0x14c50
movq %rax, -0x70(%rbp)
leaq 0xb1508(%rip), %rdi     # 0xbf930
callq 0x14cc0
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x14c80
testb $0x1, %al
jne 0xe444
jmp 0xe4ab
leaq -0x70(%rbp), %rdi
callq 0x14cf0
movq %rax, %rdi
movslq -0x8(%rbp), %rax
leaq 0xb7cdd(%rip), %rsi     # 0xc6138
addq $0x8, %rsi
imulq $0xa8, %rax, %rax
addq %rax, %rsi
addq $0x80, %rsi
callq 0xc840
testb $0x1, %al
jne 0xe47b
jmp 0xe495
leaq -0x70(%rbp), %rdi
callq 0x14cf0
movl 0x20(%rax), %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xe5b3
jmp 0xe497
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
callq 0x14d30
movq %rax, -0x80(%rbp)
jmp 0xe421
jmp 0xe4ad
jmp 0xe4af
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x14bc0
movq %rax, -0x88(%rbp)
jmp 0xe25c
movq 0x17afb(%rip), %rdi     # 0x25fc8
leaq 0x10804(%rip), %rsi     # 0x1ecd8
callq 0x3280
movq %rax, %rdi
movslq -0x8(%rbp), %rax
leaq 0xb7c51(%rip), %rsi     # 0xc6138
addq $0x8, %rsi
imulq $0xa8, %rax, %rax
addq %rax, %rsi
addq $0x80, %rsi
callq 0x3260
movq %rax, %rdi
leaq 0x107f8(%rip), %rsi     # 0x1ed03
callq 0x3280
movq %rax, %rdi
movq 0x17a96(%rip), %rsi     # 0x25fb0
callq 0x32b0
movl $0x1, %edi
callq 0x3340
movq 0x17a98(%rip), %rdi     # 0x25fc8
leaq 0x107e1(%rip), %rsi     # 0x1ed18
callq 0x3280
movq %rax, %rdi
movslq -0x8(%rbp), %rax
leaq 0xb7bee(%rip), %rsi     # 0xc6138
addq $0x8, %rsi
imulq $0xa8, %rax, %rax
addq %rax, %rsi
addq $0x80, %rsi
callq 0x3260
movq %rax, %rdi
leaq 0x107bf(%rip), %rsi     # 0x1ed2d
callq 0x3280
movq %rax, %rdi
movslq -0x8(%rbp), %rcx
leaq 0xb7bb7(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0xa4(%rax), %esi
callq 0x3440
movq %rax, %rdi
movq 0x17a0c(%rip), %rsi     # 0x25fb0
callq 0x32b0
movl $0x1, %edi
callq 0x3340
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nop