// File: /workspace/github_cpp_makefile_star2_O1/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 0xb07e8(%rip), %r15     # 0xba0c8
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 0x768e
leaq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x80(%rbx), %rsi
movq 0x88(%rbx), %rdx
addq %rsi, %rdx
callq 0x768e
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)
movl (%rbx), %eax
leaq 0xaccf(%rip), %rsi      # 0x14666
testl %eax, %eax
jle 0x9c58
movslq 0x4(%rbx), %rcx
imulq $0xa8, %rcx, %rcx
cmpl $0x9, 0x5c(%r15,%rcx)
jne 0x99c1
movl 0x4(%rbx), %edi
callq 0x9f3c
movl %eax, %ebx
jmp 0x9c9a
testl %eax, %eax
jle 0x9c58
movslq 0x4(%rbx), %rcx
imulq $0xa8, %rcx, %rcx
cmpl $0x6d, 0x5c(%r15,%rcx)
jne 0x9be2
movslq 0xc(%rbx), %rax
imulq $0xa8, %rax, %rax
movl $0x15, %r14d
leaq 0xac64(%rip), %rsi      # 0x1465c
cmpl $0x0, 0xa8(%r15,%rax)
jne 0x9c58
movslq 0x18(%rbx), %rax
imulq $0xa8, %rax, %rax
cmpl $0x0, 0xa8(%r15,%rax)
jne 0x9c58
movl $0x1, 0xa9efd(%rip)     # 0xb3928
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, 0xa9e63(%rip)     # 0xb392c
leaq 0x480(%rsp), %rdi
callq 0x2160
leaq 0x490(%rsp), %rdi
movl 0xa9e48(%rip), %esi     # 0xb392c
callq 0x2390
leaq 0x498(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x2340
movl 0x24(%rbx), %edi
callq 0x9f3c
movl %eax, %ebx
movslq 0xaaaa4(%rip), %rdi     # 0xb45b0
shlq $0x5, %rdi
leaq 0xa9e19(%rip), %r14     # 0xb3930
addq %r14, %rdi
leaq 0xa74f(%rip), %rsi      # 0x14270
callq 0x23d0
movslq 0xaaa83(%rip), %rdi     # 0xb45b0
shlq $0x5, %rdi
addq %r14, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x20a0
movslq 0xaaa66(%rip), %rax     # 0xb45b0
shlq $0x5, %rax
addq %rax, %r14
leaq 0xa71a(%rip), %rsi      # 0x14272
movq %r14, %rdi
callq 0x23d0
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9b7b
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x1041e(%rip), %rsi     # 0x19fa0
leaq 0x480(%rsp), %rdi
callq 0x2190
leaq 0x500(%rsp), %rdi
callq 0x20b0
movq 0x10425(%rip), %r14     # 0x19fc8
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 0x9c9a
testl %eax, %eax
jle 0x9c58
movslq 0x4(%rbx), %rax
imulq $0xa8, %rax, %rax
cmpl $0x73, 0x5c(%r15,%rax)
jne 0x9c58
movslq 0xaa9b0(%rip), %rdi     # 0xb45b0
leal 0x1(%rdi), %eax
movl %eax, 0xaa9a7(%rip)     # 0xb45b0
shlq $0x5, %rdi
leaq 0xa9d1c(%rip), %r14     # 0xb3930
addq %r14, %rdi
leaq 0xaa54(%rip), %rsi      # 0x14672
callq 0x23d0
movl 0x38(%rsp), %edi
callq 0x96e6
movslq 0xaa97d(%rip), %rax     # 0xb45b0
shlq $0x5, %rax
addq %rax, %r14
leaq 0xaa3a(%rip), %rsi      # 0x1467b
movq %r14, %rdi
callq 0x23d0
movl 0x8(%rbx), %edi
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
callq 0x96e6
jmp 0x9c9a
movq 0x10371(%rip), %rbx     # 0x19fd0
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 0x10348(%rip), %rdi     # 0x19fd0
callq 0x2030
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %rax, %rdi
callq 0x2150
movq 0x158(%rsp), %rdi
cmpq %rbp, %rdi
je 0x9cb7
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x138(%rsp), %rdi
cmpq %r13, %rdi
je 0x9cd4
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0xb0(%rsp), %rdi
cmpq %r12, %rdi
je 0x9cf1
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x9d16
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
jmp 0x9d2c
movq %rax, %rbx
jmp 0x9d5b
jmp 0x9d7e
movq %rax, %rbx
jmp 0x9da2
jmp 0x9def
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9d5b
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2230
movq 0x1023e(%rip), %rsi     # 0x19fa0
leaq 0x480(%rsp), %rdi
callq 0x2190
leaq 0x500(%rsp), %rdi
callq 0x20b0
jmp 0x9d81
movq %rax, %rbx
movq 0x10240(%rip), %rsi     # 0x19fc8
leaq 0x180(%rsp), %rdi
callq 0x22d0
leaq 0x1f8(%rsp), %rdi
callq 0x20b0
movq 0x1021f(%rip), %rsi     # 0x19fc8
leaq 0x300(%rsp), %rdi
callq 0x22d0
leaq 0x378(%rsp), %rdi
callq 0x20b0
jmp 0x9df2
movq %rax, %rbx
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x9e09
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2230
jmp 0x9e09
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0xf7a8
leaq 0x30(%rsp), %rdi
callq 0xf7a8
movq %rbx, %rdi
callq 0x23a0