// File: /workspace/github_c_makefile_star2_O2/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)
xorl %eax, %eax
leaq 0xa9c7(%rip), %rbx      # 0xe3a0
leaq 0x5f34(%rip), %r13      # 0x9914
pushq $0x4
popq %r12
movl (%rbx), %ecx
testb $0x1, %al
jne 0x3a38
cmpl $0x32, %ecx
je 0x3a16
movb $0x1, %al
cmpl $0x2b, %ecx
jne 0x39e4
cmpl $0x5, (%r15)
movl %r12d, %r14d
jne 0x3a07
movq %r13, %rdi
callq 0x6515
movl %r14d, (%r15)
movq %rbx, %rdi
callq 0x66f4
xorl %eax, %eax
jmp 0x39e4
movl (%r15), %eax
cmpl $0x2, %eax
jne 0x3a2d
leaq 0x5f22(%rip), %rdi      # 0x9947
callq 0x6515
movl (%r15), %eax
pushq $0x5
popq %r14
cmpl $0x4, %eax
je 0x39ff
jmp 0x3a07
leal -0x1e(%rcx), %eax
cmpl $0xc, %eax
ja 0x3a63
leaq 0x5e79(%rip), %rcx      # 0x98c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xa949(%rip), %rdi      # 0xe3a0
callq 0x66f4
pushq $0x10
jmp 0x3c0b
cmpl $0x36, %ecx
jne 0x3aae
leaq 0xa961(%rip), %rdi      # 0xe3d0
callq 0x7d21
movq %rax, %rbx
testq %rax, %rax
jne 0x3a8f
leaq 0x60ca(%rip), %rdi      # 0x9b4d
leaq 0xa946(%rip), %rsi      # 0xe3d0
callq 0x641f
leaq 0xa90a(%rip), %rdi      # 0xe3a0
callq 0x66f4
movq 0x18(%rbx), %rax
movq -0x30(%rbp), %rcx
movq %rax, (%rcx)
movl 0x10(%rbx), %eax
jmp 0x3c0c
movq 0x8(%rbx), %rsi
leaq 0x5ec1(%rip), %rdi      # 0x997a
callq 0x641f
jmp 0x3c0c
leaq -0x34(%rbp), %r12
andl $0x0, (%r12)
leaq 0xa8cd(%rip), %rbx      # 0xe3a0
movq %rbx, %rdi
callq 0x66f4
movq -0x30(%rbp), %rdi
movq %r12, %rsi
callq 0x39b8
movl %eax, %r15d
cmpl $0x0, (%r12)
je 0x3afd
leaq 0x600b(%rip), %rdi      # 0x9b03
callq 0x6515
leaq 0xa8cc(%rip), %rdi      # 0xe3d0
callq 0x7d21
testq %rax, %rax
je 0x3b21
leaq 0x6020(%rip), %rdi      # 0x9b35
leaq 0xa8b4(%rip), %rsi      # 0xe3d0
callq 0x641f
movl %r15d, %edi
callq 0x3f2c
movl %eax, %r15d
movq -0x30(%rbp), %rax
movq (%rax), %rdx
leaq 0xa896(%rip), %rdi      # 0xe3d0
movl %r15d, %esi
callq 0x7b62
movq %rbx, %rdi
callq 0x66f4
cmpl $0x35, (%rbx)
pushq $-0x1
popq %rax
cmovnel %r15d, %eax
jmp 0x3c0c
movq %rbx, %rdi
callq 0x66f4
movl (%rbx), %eax
xorl %r15d, %r15d
cmpl $0x37, %eax
je 0x3c39
cmpl $0x36, %eax
jne 0x3bab
leaq 0xa855(%rip), %r14      # 0xe3d0
movq %r14, %rdi
callq 0x7cef
movq %rax, %r12
movq %r14, %rdi
callq 0x2190
movq %rax, %r15
movq %rbx, %rdi
callq 0x66f4
cmpl $0x37, (%rbx)
je 0x3c3c
testq %r12, %r12
jne 0x3cfc
leaq 0x5eef(%rip), %rdi      # 0x9aa1
movq %r15, %rsi
callq 0x641f
jmp 0x3cfc
leaq 0xa7da(%rip), %rdi      # 0xe3a0
callq 0x66f4
pushq $0x30
jmp 0x3c0b
leaq 0xa7ca(%rip), %rdi      # 0xe3a0
callq 0x66f4
pushq $0x20
jmp 0x3c0b
pushq $0x50
popq %rdi
callq 0x3d0e
movq -0x30(%rbp), %rcx
movq %rax, (%rcx)
xorl %eax, %eax
cmpl $0x35, (%rbx)
sete %al
negl %eax
orl $0x50, %eax
jmp 0x3c0c
leaq 0xa79c(%rip), %rdi      # 0xe3a0
callq 0x66f4
pushq $0x40
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x60
popq %rdi
callq 0x3d0e
movq -0x30(%rbp), %rcx
movq %rax, (%rcx)
xorl %eax, %eax
cmpl $0x35, (%rbx)
sete %al
negl %eax
orl $0x60, %eax
jmp 0x3c0c
xorl %r12d, %r12d
leaq 0xa75d(%rip), %r14      # 0xe3a0
movq %r14, %rdi
callq 0x66f4
testq %r12, %r12
je 0x3c63
movq 0x8(%r12), %rsi
leaq 0x5e5b(%rip), %rdi      # 0x9ab7
callq 0x641f
jmp 0x3c70
pushq $0x9
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x7b24
xorl %r12d, %r12d
leaq 0xa756(%rip), %r15      # 0xe3d0
callq 0x64e9
movq %r15, %rdi
callq 0x2190
movq %rax, %r13
movq %rax, %rdi
callq 0x7d08
testq %rax, %rax
je 0x3ca6
leaq 0x5e2f(%rip), %rdi      # 0x9acd
movq %r15, %rsi
callq 0x641f
cmpl $0x1, (%r14)
jne 0x3cd2
movq %r14, %rdi
callq 0x66f4
cmpl $0x33, (%r14)
je 0x3cc6
leaq 0x5e23(%rip), %rdi      # 0x9ae4
callq 0x6515
movl 0x10(%r14), %r12d
movq %r14, %rdi
callq 0x66f4
movq %r13, %rdi
pushq $0xa
popq %rsi
movl %r12d, %edx
callq 0x7b24
cmpl $0x38, (%r14)
je 0x3cf0
incl %r12d
callq 0x64ff
jmp 0x3c7a
leaq 0xa6a9(%rip), %rdi      # 0xe3a0
callq 0x66f4
xorl %eax, %eax
cmpl $0x35, (%rbx)
sete %al
negl %eax
orl $0x30, %eax
jmp 0x3c0c