// File: /workspace/github_cpp_makefile_star2_O3/zhengwangsun[P]pas2c/semantics.cpp
// Function: type(int)
int type(int k)
{
	TreeNode tNode= tree.node[k];
	TreeNode childNode;
    if (lookahead(k) == 9)//9是standard_type
        return standard_type(tree.node[k].child[0]);
    
    else if(lookahead(k) == 109)//109是array
    {                                                               //类型检查
        if (tree.node[tree.node[k].child[2]].numType != 0 || tree.node[tree.node[k].child[5]].numType != 0)
        {
            cout<<"array num type error!"<<endl;
            return -1;
        }
        else//如果[]里面正确，就改变全局标志位isArray，然后将全局dimension设为数组维数
        {
            isArray = 1;
            int num2 = 0, num1 = 0;
            
            istringstream stream1, stream2;

            stream1.str(tree.node[tree.node[k].child[2]].value);
            stream1 >> num1;
            
            stream2.str(tree.node[tree.node[k].child[5]].value);
            stream2 >> num2;
            
            demension = num2 - num1 + 1;
            stringstream ss;
            ss<<demension;
            string s1=ss.str();
            int temp= standard_type(tree.node[k].child[8]);//是8没错吧 ---------wrong,6
            code[currentLine].append("[");
            code[currentLine].append(s1);
            code[currentLine].append("]"); // 数组声明翻译
            return temp; //声明翻译 应该 从符号表中读出信息；
        }
    }
    else if (lookahead(k) == 115)//115是record
    {
    	code[currentLine++].append("struct{\n");
		declaration(tNode.child[1]);
		code[currentLine].append("}");
        declaration(tree.node[k].child[1]);
        return -1;//要改
    }
    else
    {
        cout<<"type error!"<<endl;
        return -1;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x608, %rsp            # imm = 0x608
movslq %edi, %rax
imulq $0xa8, %rax, %rax
leaq 0xaf8cd(%rip), %r15     # 0xb90c8
leaq (%r15,%rax), %rbx
addq $0x8, %rbx
movl $0xb, %r14d
leaq 0x30(%rsp), %rax
movl $0xb, %ecx
movq %rax, %rdi
movq %rbx, %rsi
rep  movsq (%rsi), %es:(%rdi)
movb 0x58(%rbx), %cl
movb %cl, 0x58(%rax)
leaq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x60(%rbx), %rsi
movq 0x68(%rbx), %rdx
addq %rsi, %rdx
callq 0x7666
leaq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x80(%rbx), %rsi
movq 0x88(%rbx), %rdx
addq %rsi, %rdx
callq 0x7666
movq 0xa0(%rbx), %rax
movq %rax, 0xd0(%rsp)
leaq 0x148(%rsp), %r13
movq %r13, -0x10(%r13)
xorl %eax, %eax
movq %rax, -0x8(%r13)
movb %al, (%r13)
leaq 0x168(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq %rax, -0x8(%rbp)
movb %al, (%rbp)
leaq 0x9de6(%rip), %rsi      # 0x13696
cmpl $0x0, (%rbx)
jle 0x991e
movslq 0x4(%rbx), %rdi
imulq $0xa8, %rdi, %rax
movl 0x5c(%r15,%rax), %eax
cmpl $0x73, %eax
je 0x99f0
cmpl $0x6d, %eax
je 0x98e1
cmpl $0x9, %eax
jne 0x991e
callq 0x9e24
movl %eax, %ebx
jmp 0x9960
movslq 0xc(%rbx), %rax
imulq $0xa8, %rax, %rax
movl $0x15, %r14d
leaq 0x9d93(%rip), %rsi      # 0x1368c
cmpl $0x0, 0xa8(%r15,%rax)
jne 0x991e
movslq 0x18(%rbx), %rax
imulq $0xa8, %rax, %rax
cmpl $0x0, 0xa8(%r15,%rax)
je 0x9a52
movq 0xf6ab(%rip), %rbx      # 0x18fd0
movq %rbx, %rdi
movq %r14, %rdx
callq 0x2280
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2200
movsbl %al, %esi
movq 0xf682(%rip), %rdi      # 0x18fd0
callq 0x2030
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x2150
movq 0x158(%rsp), %rdi
cmpq %rbp, %rdi
je 0x997d
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x138(%rsp), %rdi
cmpq %r13, %rdi
je 0x999a
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0xb0(%rsp), %rdi
cmpq %r12, %rdi
je 0x99b7
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x99dc
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2230
movl %ebx, %eax
addq $0x608, %rsp            # imm = 0x608
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq 0xa9bb9(%rip), %rdi     # 0xb35b0
leal 0x1(%rdi), %eax
movl %eax, 0xa9bb0(%rip)     # 0xb35b0
shlq $0x5, %rdi
leaq 0xa8f25(%rip), %r14     # 0xb2930
addq %r14, %rdi
leaq 0x9c8d(%rip), %rsi      # 0x136a2
callq 0x23d0
movl 0x38(%rsp), %edi
callq 0x9601
movslq 0xa9b86(%rip), %rax     # 0xb35b0
shlq $0x5, %rax
addq %rax, %r14
leaq 0x9c73(%rip), %rsi      # 0x136ab
movq %r14, %rdi
callq 0x23d0
movl 0x8(%rbx), %edi
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
callq 0x9601
jmp 0x9960
movl $0x1, 0xa8ecc(%rip)     # 0xb2928
xorl %eax, %eax
movl %eax, 0xc(%rsp)
movl %eax, 0x8(%rsp)
leaq 0x300(%rsp), %rdi
callq 0x2180
leaq 0x180(%rsp), %rdi
callq 0x2180
movslq 0xc(%rbx), %rax
imulq $0xa8, %rax, %rax
leaq (%r15,%rax), %rsi
addq $0x88, %rsi
leaq 0x310(%rsp), %rdi
callq 0x2310
leaq 0x300(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2130
movslq 0x18(%rbx), %rax
imulq $0xa8, %rax, %rax
leaq (%r15,%rax), %rsi
addq $0x88, %rsi
leaq 0x190(%rsp), %rdi
callq 0x2310
leaq 0x180(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x2130
movl 0xc(%rsp), %eax
subl 0x8(%rsp), %eax
incl %eax
movl %eax, 0xa8e32(%rip)     # 0xb292c
leaq 0x480(%rsp), %rdi
callq 0x2160
leaq 0x490(%rsp), %rdi
movl 0xa8e17(%rip), %esi     # 0xb292c
callq 0x2390
leaq 0x498(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x2340
movl 0x24(%rbx), %edi
callq 0x9e24
movl %eax, %ebx
movslq 0xa9a73(%rip), %rdi     # 0xb35b0
shlq $0x5, %rdi
leaq 0xa8de8(%rip), %r14     # 0xb2930
addq %r14, %rdi
leaq 0x971e(%rip), %rsi      # 0x13270
callq 0x23d0
movslq 0xa9a52(%rip), %rdi     # 0xb35b0
shlq $0x5, %rdi
addq %r14, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x20a0
movslq 0xa9a35(%rip), %rax     # 0xb35b0
shlq $0x5, %rax
addq %rax, %r14
leaq 0x96e9(%rip), %rsi      # 0x13272
movq %r14, %rdi
callq 0x23d0
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9bac
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0xf3ed(%rip), %rsi      # 0x18fa0
leaq 0x480(%rsp), %rdi
callq 0x2190
leaq 0x500(%rsp), %rdi
callq 0x20b0
movq 0xf3f4(%rip), %r14      # 0x18fc8
leaq 0x180(%rsp), %rdi
movq %r14, %rsi
callq 0x22d0
leaq 0x1f8(%rsp), %rdi
callq 0x20b0
leaq 0x300(%rsp), %rdi
movq %r14, %rsi
callq 0x22d0
leaq 0x378(%rsp), %rdi
callq 0x20b0
jmp 0x9960
jmp 0x9c15
movq %rax, %rbx
jmp 0x9c44
jmp 0x9c67
movq %rax, %rbx
jmp 0x9c8b
jmp 0x9cd8
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9c44
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0xf355(%rip), %rsi      # 0x18fa0
leaq 0x480(%rsp), %rdi
callq 0x2190
leaq 0x500(%rsp), %rdi
callq 0x20b0
jmp 0x9c6a
movq %rax, %rbx
movq 0xf357(%rip), %rsi      # 0x18fc8
leaq 0x180(%rsp), %rdi
callq 0x22d0
leaq 0x1f8(%rsp), %rdi
callq 0x20b0
movq 0xf336(%rip), %rsi      # 0x18fc8
leaq 0x300(%rsp), %rdi
callq 0x22d0
leaq 0x378(%rsp), %rdi
callq 0x20b0
jmp 0x9cdb
movq %rax, %rbx
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x9cf2
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x9cf2
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0xf396
leaq 0x30(%rsp), %rdi
callq 0xf396
movq %rbx, %rdi
callq 0x23a0