// File: /workspace/github_c_makefile_star2_O1/ejunjsh[P]mycc/decl.c
// Function: parse_type
int parse_type(struct symtable **ctype, int *class) {
  int type, exstatic = 1;

  // 是否有一个存储类变成extern或者static
  while (exstatic) {
    switch (Token.token) {
      case T_EXTERN:
        if (*class == C_STATIC)
            fatal("Illegal to have extern and static at the same time");
        *class = C_EXTERN;
        scan(&Token);
        break;
      case T_STATIC:
        if (*class == C_LOCAL)
            fatal("Compiler doesn't support static local declarations");
        if (*class == C_EXTERN)
            fatal("Illegal to have extern and static at the same time");
        *class = C_STATIC;
        scan(&Token);
        break;
      default:
	    exstatic = 0;
    }
  }

  // 现在开始解析类型关键字
  switch (Token.token) {
    case T_VOID:
      type = P_VOID;
      scan(&Token);
      break;
    case T_CHAR:
      type = P_CHAR;
      scan(&Token);
      break;
    case T_INT:
      type = P_INT;
      scan(&Token);
      break;
    case T_LONG:
      type = P_LONG;
      scan(&Token);
      break;

      // 如果类型后面跟着';' ，那就是代表不是在用类型声明变量
      // 而是声明类型，所以返回-1
      // 例如: struct x {int y; int z};
    case T_STRUCT:
      type = P_STRUCT;
      *ctype = composite_declaration(P_STRUCT);
      if (Token.token == T_SEMI)
	    type = -1;
      break;
    case T_UNION:
      type = P_UNION;
      *ctype = composite_declaration(P_UNION);
      if (Token.token == T_SEMI)
	    type = -1;
      break;
    case T_ENUM:
      type = P_INT;		// 枚举其实就是整型
      enum_declaration();
      if (Token.token == T_SEMI)
	    type = -1;
      break;
    case T_TYPEDEF:
      type = typedef_declaration(ctype);
      if (Token.token == T_SEMI)
	    type = -1;
      break;
    case T_IDENT:
      type = type_of_typedef(Text, ctype);
      break;
    default:
      fatals("Illegal type, token", Token.tokstr);
  }
  return (type);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r15
movq %rdi, -0x30(%rbp)
leaq 0xb73d(%rip), %rbx      # 0xf3a0
leaq 0x6cdd(%rip), %r12      # 0xa947
leaq 0x6ca3(%rip), %r13      # 0xa914
movl (%rbx), %eax
cmpl $0x32, %eax
je 0x3c8b
cmpl $0x2b, %eax
jne 0x3cba
movl $0x4, %r14d
cmpl $0x5, (%r15)
je 0x3ca5
jmp 0x3cad
cmpl $0x2, (%r15)
jne 0x3c99
movq %r12, %rdi
callq 0x688f
movl $0x5, %r14d
cmpl $0x4, (%r15)
jne 0x3cad
movq %r13, %rdi
callq 0x688f
movl %r14d, (%r15)
movq %rbx, %rdi
callq 0x6a78
jmp 0x3c71
movl (%rbx), %ecx
leal -0x1e(%rcx), %eax
cmpl $0xc, %eax
ja 0x3cea
leaq 0x6bf5(%rip), %rcx      # 0xa8c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xb6c5(%rip), %rdi      # 0xf3a0
callq 0x6a78
movl $0x10, %eax
jmp 0x3fa4
cmpl $0x36, %ecx
jne 0x3d35
leaq 0xb6da(%rip), %rdi      # 0xf3d0
callq 0x83ac
movq %rax, %rbx
testq %rax, %rax
jne 0x3d16
leaq 0x6e43(%rip), %rdi      # 0xab4d
leaq 0xb6bf(%rip), %rsi      # 0xf3d0
callq 0x6797
leaq 0xb683(%rip), %rdi      # 0xf3a0
callq 0x6a78
movq 0x18(%rbx), %rax
movq -0x30(%rbp), %rcx
movq %rax, (%rcx)
movl 0x10(%rbx), %eax
jmp 0x3fa4
movq 0x8(%rbx), %rsi
leaq 0x6c3a(%rip), %rdi      # 0xa97a
callq 0x6797
jmp 0x3fa4
leaq -0x34(%rbp), %r12
movl $0x0, (%r12)
leaq 0xb643(%rip), %rbx      # 0xf3a0
movq %rbx, %rdi
callq 0x6a78
movq -0x30(%rbp), %rdi
movq %r12, %rsi
callq 0x3c44
movl %eax, %r15d
cmpl $0x0, (%r12)
je 0x3d87
leaq 0x6d81(%rip), %rdi      # 0xab03
callq 0x688f
leaq 0xb642(%rip), %rdi      # 0xf3d0
callq 0x83ac
testq %rax, %rax
je 0x3dab
leaq 0x6d96(%rip), %rdi      # 0xab35
leaq 0xb62a(%rip), %rsi      # 0xf3d0
callq 0x6797
movl %r15d, %edi
callq 0x41a4
movl %eax, %r15d
movq -0x30(%rbp), %rax
movq (%rax), %rdx
leaq 0xb60c(%rip), %rdi      # 0xf3d0
movl %r15d, %esi
callq 0x8097
movq %rbx, %rdi
callq 0x6a78
cmpl $0x35, (%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnel %r15d, %eax
jmp 0x3fa4
movq %rbx, %rdi
callq 0x6a78
cmpl $0x36, (%rbx)
jne 0x3eac
leaq 0xb5d3(%rip), %r14      # 0xf3d0
movq %r14, %rdi
callq 0x837a
movq %rax, %r15
movq %r14, %rdi
callq 0x2180
movq %rax, %r12
leaq 0xb586(%rip), %rdi      # 0xf3a0
callq 0x6a78
jmp 0x3eb2
leaq 0xb575(%rip), %rdi      # 0xf3a0
callq 0x6a78
movl $0x30, %eax
jmp 0x3fa4
leaq 0xb55f(%rip), %rdi      # 0xf3a0
callq 0x6a78
movl $0x20, %eax
jmp 0x3fa4
movl $0x50, %edi
callq 0x3fb3
movq -0x30(%rbp), %rcx
movq %rax, (%rcx)
xorl %eax, %eax
cmpl $0x35, (%rbx)
sete %al
negl %eax
orl $0x50, %eax
jmp 0x3fa4
leaq 0xb526(%rip), %rdi      # 0xf3a0
callq 0x6a78
movl $0x40, %eax
jmp 0x3fa4
movl $0x60, %edi
callq 0x3fb3
movq -0x30(%rbp), %rcx
movq %rax, (%rcx)
xorl %eax, %eax
cmpl $0x35, (%rbx)
sete %al
negl %eax
orl $0x60, %eax
jmp 0x3fa4
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpl $0x37, (%rbx)
jne 0x3edd
leaq 0xb4e2(%rip), %r14      # 0xf3a0
movq %r14, %rdi
callq 0x6a78
testq %r15, %r15
je 0x3efa
movq 0x8(%r15), %rsi
leaq 0x6be1(%rip), %rdi      # 0xaab7
callq 0x6797
jmp 0x3f09
testq %r15, %r15
jne 0x3f97
leaq 0x6bb4(%rip), %rdi      # 0xaaa1
movq %r12, %rsi
callq 0x6797
jmp 0x3f97
movq %r12, %rdi
movl $0x9, %esi
xorl %edx, %edx
callq 0x802f
xorl %r12d, %r12d
leaq 0xb4bd(%rip), %r15      # 0xf3d0
callq 0x6863
movq %r15, %rdi
callq 0x2180
movq %rax, %r13
movq %rax, %rdi
callq 0x8393
testq %rax, %rax
je 0x3f3f
leaq 0x6b96(%rip), %rdi      # 0xaacd
movq %r15, %rsi
callq 0x6797
cmpl $0x1, (%r14)
jne 0x3f6b
movq %r14, %rdi
callq 0x6a78
cmpl $0x33, (%r14)
je 0x3f5f
leaq 0x6b8a(%rip), %rdi      # 0xaae4
callq 0x688f
movl 0x10(%r14), %r12d
movq %r14, %rdi
callq 0x6a78
movq %r13, %rdi
movl $0xa, %esi
movl %r12d, %edx
callq 0x802f
cmpl $0x38, (%r14)
je 0x3f8b
incl %r12d
callq 0x6879
jmp 0x3f13
leaq 0xb40e(%rip), %rdi      # 0xf3a0
callq 0x6a78
xorl %eax, %eax
cmpl $0x35, (%rbx)
sete %al
negl %eax
orl $0x30, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq