// File: 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
movq %rsp, %rbp
subq $0x640, %rsp            # imm = 0x640
movl %edi, -0x8(%rbp)
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb75c8(%rip), %rax     # 0xc6138
leaq 0x8(%rax,%rcx), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x14920
leaq -0x158(%rbp), %rdi
callq 0x149d0
movl -0x8(%rbp), %edi
callq 0xca50
movl %eax, -0x620(%rbp)
jmp 0xeb9d
movl -0x620(%rbp), %eax
cmpl $0x9, %eax
jne 0xebfa
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb757e(%rip), %rax     # 0xc6138
movl 0xc(%rax,%rcx), %edi
callq 0xf1b0
movl %eax, -0x624(%rbp)
jmp 0xebcb
movl -0x624(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x168(%rbp)
jmp 0xf040
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0xf064
movl -0x8(%rbp), %edi
callq 0xca50
movl %eax, -0x628(%rbp)
jmp 0xec0a
movl -0x628(%rbp), %eax
cmpl $0x6d, %eax
jne 0xef52
movslq -0x8(%rbp), %rcx
leaq 0xb7514(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movslq 0xc(%rax), %rcx
leaq 0xb74fb(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0xa0(%rax)
jne 0xec8f
movslq -0x8(%rbp), %rcx
leaq 0xb74d9(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movslq 0x18(%rax), %rcx
leaq 0xb74c0(%rip), %rax     # 0xc6138
addq $0x8, %rax
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0xa0(%rax)
je 0xecd6
movq 0x17332(%rip), %rdi     # 0x25fc8
leaq 0xf959(%rip), %rsi      # 0x1e5f6
callq 0x3280
movq %rax, -0x630(%rbp)
jmp 0xecab
movq -0x630(%rbp), %rdi
movq 0x172f7(%rip), %rsi     # 0x25fb0
callq 0x32b0
jmp 0xecc0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x168(%rbp)
jmp 0xf040
movl $0x1, 0xb0cb8(%rip)     # 0xbf998
movl $0x0, -0x16c(%rbp)
movl $0x0, -0x170(%rbp)
leaq -0x2f0(%rbp), %rdi
callq 0x31e0
jmp 0xed02
leaq -0x470(%rbp), %rdi
callq 0x31e0
jmp 0xed10
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb7416(%rip), %rax     # 0xc6138
movslq 0x14(%rax,%rcx), %rcx
imulq $0xa8, %rcx, %rcx
leaq 0x88(%rax,%rcx), %rsi
leaq -0x2f0(%rbp), %rdi
callq 0x3310
jmp 0xed44
leaq -0x2f0(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x3170
jmp 0xed59
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb73cd(%rip), %rax     # 0xc6138
movslq 0x20(%rax,%rcx), %rcx
imulq $0xa8, %rcx, %rcx
leaq 0x88(%rax,%rcx), %rsi
leaq -0x470(%rbp), %rdi
callq 0x3310
jmp 0xed8d
leaq -0x470(%rbp), %rdi
leaq -0x16c(%rbp), %rsi
callq 0x3170
jmp 0xeda2
movl -0x16c(%rbp), %eax
movl -0x170(%rbp), %ecx
subl %ecx, %eax
incl %eax
movl %eax, 0xb0be4(%rip)     # 0xbf99c
leaq -0x5f8(%rbp), %rdi
callq 0x31c0
jmp 0xedc6
leaq -0x5e8(%rbp), %rdi
movl 0xb0bc9(%rip), %esi     # 0xbf99c
callq 0x3440
jmp 0xedda
leaq -0x618(%rbp), %rdi
leaq -0x5f8(%rbp), %rsi
callq 0x3270
jmp 0xedef
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb7337(%rip), %rax     # 0xc6138
movl 0x2c(%rax,%rcx), %edi
callq 0xf1b0
movl %eax, -0x634(%rbp)
jmp 0xee12
movl -0x634(%rbp), %eax
movl %eax, -0x61c(%rbp)
movslq 0xb17fb(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xb0b70(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xf412(%rip), %rsi      # 0x1e24c
callq 0x3490
jmp 0xee41
movslq 0xb17d8(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xb0b4d(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq -0x618(%rbp), %rsi
callq 0x34a0
jmp 0xee64
movslq 0xb17b5(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xb0b2a(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xf3ce(%rip), %rsi      # 0x1e24e
callq 0x3490
jmp 0xee87
movl -0x61c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl $0x1, -0x168(%rbp)
leaq -0x618(%rbp), %rdi
callq 0x34c8
leaq -0x5f8(%rbp), %rdi
callq 0x31f0
leaq -0x470(%rbp), %rdi
callq 0x3120
leaq -0x2f0(%rbp), %rdi
callq 0x3120
jmp 0xf040
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0xef41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0xef35
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
jmp 0xef29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x160(%rbp)
movl %eax, -0x164(%rbp)
leaq -0x618(%rbp), %rdi
callq 0x34c8
leaq -0x5f8(%rbp), %rdi
callq 0x31f0
leaq -0x470(%rbp), %rdi
callq 0x3120
leaq -0x2f0(%rbp), %rdi
callq 0x3120
jmp 0xf064
movl -0x8(%rbp), %edi
callq 0xca50
movl %eax, -0x638(%rbp)
jmp 0xef62
movl -0x638(%rbp), %eax
cmpl $0x73, %eax
jne 0xeffe
movslq 0xb16a8(%rip), %rax     # 0xc0620
movl %eax, %ecx
incl %ecx
movl %ecx, 0xb169e(%rip)     # 0xc0620
shlq $0x5, %rax
leaq 0xb0a13(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xf675(%rip), %rsi      # 0x1e60c
callq 0x3490
jmp 0xef9e
movl -0xa8(%rbp), %edi
callq 0xe9c0
jmp 0xefab
movslq 0xb166e(%rip), %rax     # 0xc0620
shlq $0x5, %rax
leaq 0xb09e3(%rip), %rdi     # 0xbf9a0
addq %rax, %rdi
leaq 0xf64e(%rip), %rsi      # 0x1e615
callq 0x3490
jmp 0xefce
movslq -0x8(%rbp), %rax
imulq $0xa8, %rax, %rcx
leaq 0xb7158(%rip), %rax     # 0xc6138
movl 0x10(%rax,%rcx), %edi
callq 0xe9c0
jmp 0xefeb
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x168(%rbp)
jmp 0xf040
movq 0x16fc3(%rip), %rdi     # 0x25fc8
leaq 0xf5f4(%rip), %rsi      # 0x1e600
callq 0x3280
movq %rax, -0x640(%rbp)
jmp 0xf01a
movq -0x640(%rbp), %rdi
movq 0x16f88(%rip), %rsi     # 0x25fb0
callq 0x32b0
jmp 0xf02f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl $0x1, -0x168(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x14a90
leaq -0xb0(%rbp), %rdi
callq 0x14a90
movl -0x4(%rbp), %eax
addq $0x640, %rsp            # imm = 0x640
popq %rbp
retq
leaq -0x158(%rbp), %rdi
callq 0x14a90
leaq -0xb0(%rbp), %rdi
callq 0x14a90
movq -0x160(%rbp), %rdi
callq 0x3450
nopl (%rax,%rax)