// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
subq $0x600, %rsp            # imm = 0x600
movslq %edi, %r14
imulq $0xa8, %r14, %rax
leaq 0xace8d(%rip), %r15     # 0xb4098
leaq (%r15,%rax), %rbx
addq $0x8, %rbx
leaq 0xd0(%rsp), %rdi
movq %rbx, %rsi
callq 0xa562
leaq 0x98(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0xb8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
movl %r14d, %edi
callq 0x603d
cmpl $0x73, %eax
je 0x741d
cmpl $0x6d, %eax
je 0x7279
cmpl $0x9, %eax
jne 0x747a
movl 0x4(%rbx), %edi
callq 0x7601
movl %eax, %ebx
jmp 0x7498
movslq 0xc(%rbx), %rax
imulq $0xa8, %rax, %rax
leaq 0x7431(%rip), %rsi      # 0xe6bc
cmpl $0x0, 0xa8(%r15,%rax)
jne 0x7481
movslq 0x18(%rbx), %rax
imulq $0xa8, %rax, %rax
cmpl $0x0, 0xa8(%r15,%rax)
jne 0x7481
andl $0x0, 0x4(%rsp)
movl $0x1, 0xa6635(%rip)     # 0xad8f8
andl $0x0, (%rsp)
leaq 0x2f8(%rsp), %rdi
callq 0x2160
leaq 0x178(%rsp), %rdi
callq 0x2160
movslq 0xc(%rbx), %rax
imulq $0xa8, %rax, %rax
leaq (%r15,%rax), %rsi
addq $0x88, %rsi
leaq 0x308(%rsp), %rdi
callq 0x22b0
leaq 0x2f8(%rsp), %rdi
movq %rsp, %rsi
callq 0x2120
movslq 0x18(%rbx), %rax
imulq $0xa8, %rax, %rax
leaq (%r15,%rax), %rsi
addq $0x88, %rsi
leaq 0x188(%rsp), %rdi
callq 0x22b0
leaq 0x178(%rsp), %rdi
leaq 0x4(%rsp), %rsi
callq 0x2120
movl 0x4(%rsp), %eax
subl (%rsp), %eax
incl %eax
movl %eax, 0xa65a4(%rip)     # 0xad8fc
leaq 0x478(%rsp), %rdi
callq 0x2140
leaq 0x488(%rsp), %rdi
movl 0xa6589(%rip), %esi     # 0xad8fc
callq 0x2320
leaq 0x490(%rsp), %rsi
leaq 0x8(%rsp), %rdi
callq 0x22d0
movl 0x24(%rbx), %edi
callq 0x7601
movl %eax, %ebx
movslq 0xa71e5(%rip), %rdi     # 0xae580
shlq $0x5, %rdi
leaq 0xa655a(%rip), %r14     # 0xad900
addq %r14, %rdi
leaq 0x6f18(%rip), %rsi      # 0xe2c8
callq 0x2350
movslq 0xa71c4(%rip), %rdi     # 0xae580
shlq $0x5, %rdi
addq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0x2370
movslq 0xa71ac(%rip), %rax     # 0xae580
shlq $0x5, %rax
addq %rax, %r14
leaq 0x6ee8(%rip), %rsi      # 0xe2ca
movq %r14, %rdi
callq 0x2350
leaq 0x8(%rsp), %rdi
callq 0x2388
leaq 0x478(%rsp), %rdi
callq 0x2170
leaq 0x178(%rsp), %rdi
callq 0x20e0
leaq 0x2f8(%rsp), %rdi
callq 0x20e0
jmp 0x7498
movslq 0xa715c(%rip), %rdi     # 0xae580
leal 0x1(%rdi), %eax
movl %eax, 0xa7153(%rip)     # 0xae580
shlq $0x5, %rdi
leaq 0xa64c8(%rip), %r14     # 0xad900
addq %r14, %rdi
leaq 0x7290(%rip), %rsi      # 0xe6d2
callq 0x2350
movl 0xd8(%rsp), %edi
callq 0x7100
movslq 0xa7126(%rip), %rax     # 0xae580
shlq $0x5, %rax
addq %rax, %r14
leaq 0x7273(%rip), %rsi      # 0xe6db
movq %r14, %rdi
callq 0x2350
movl 0x8(%rbx), %edi
callq 0x7100
jmp 0x7495
leaq 0x7245(%rip), %rsi      # 0xe6c6
movq 0xcb48(%rip), %rdi      # 0x13fd0
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
pushq $-0x1
popq %rbx
leaq 0x28(%rsp), %rdi
callq 0xa600
leaq 0xd0(%rsp), %rdi
callq 0xa600
movl %ebx, %eax
addq $0x600, %rsp            # imm = 0x600
popq %rbx
popq %r14
popq %r15
retq
jmp 0x74c0
movq %rax, %rbx
jmp 0x74db
jmp 0x74ea
movq %rax, %rbx
jmp 0x74fa
jmp 0x7509
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2388
leaq 0x478(%rsp), %rdi
callq 0x2170
jmp 0x74ed
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
callq 0x20e0
leaq 0x2f8(%rsp), %rdi
callq 0x20e0
jmp 0x750c
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0xa600
leaq 0xd0(%rsp), %rdi
callq 0xa600
movq %rbx, %rdi
callq 0x2330