// File: /workspace/github_c_makefile_star2_O3/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 0xb705(%rip), %rbx      # 0xf3a0
leaq 0x6ca5(%rip), %r12      # 0xa947
leaq 0x6c6b(%rip), %r13      # 0xa914
movl (%rbx), %eax
cmpl $0x32, %eax
je 0x3cc3
cmpl $0x2b, %eax
jne 0x3cf6
movl $0x4, %r14d
cmpl $0x5, (%r15)
je 0x3ce1
jmp 0x3ce9
movl (%r15), %eax
cmpl $0x2, %eax
jne 0x3cd6
movq %r12, %rdi
callq 0x6937
movl (%r15), %eax
movl $0x5, %r14d
cmpl $0x4, %eax
jne 0x3ce9
movq %r13, %rdi
callq 0x6937
movl %r14d, (%r15)
movq %rbx, %rdi
callq 0x6b20
jmp 0x3ca9
movl (%rbx), %ecx
leal -0x1e(%rcx), %eax
cmpl $0xc, %eax
ja 0x3d26
leaq 0x6bb9(%rip), %rcx      # 0xa8c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xb689(%rip), %rdi      # 0xf3a0
callq 0x6b20
movl $0x10, %eax
jmp 0x3ff1
cmpl $0x36, %ecx
jne 0x3d71
leaq 0xb69e(%rip), %rdi      # 0xf3d0
callq 0x8418
movq %rax, %rbx
testq %rax, %rax
jne 0x3d52
leaq 0x6e07(%rip), %rdi      # 0xab4d
leaq 0xb683(%rip), %rsi      # 0xf3d0
callq 0x683f
leaq 0xb647(%rip), %rdi      # 0xf3a0
callq 0x6b20
movq 0x18(%rbx), %rax
movq -0x30(%rbp), %rcx
movq %rax, (%rcx)
movl 0x10(%rbx), %eax
jmp 0x3ff1
movq 0x8(%rbx), %rsi
leaq 0x6bfe(%rip), %rdi      # 0xa97a
callq 0x683f
jmp 0x3ff1
leaq -0x34(%rbp), %r12
movl $0x0, (%r12)
leaq 0xb607(%rip), %rbx      # 0xf3a0
movq %rbx, %rdi
callq 0x6b20
movq -0x30(%rbp), %rdi
movq %r12, %rsi
callq 0x3c7c
movl %eax, %r15d
cmpl $0x0, (%r12)
je 0x3dc3
leaq 0x6d45(%rip), %rdi      # 0xab03
callq 0x6937
leaq 0xb606(%rip), %rdi      # 0xf3d0
callq 0x8418
testq %rax, %rax
je 0x3de7
leaq 0x6d5a(%rip), %rdi      # 0xab35
leaq 0xb5ee(%rip), %rsi      # 0xf3d0
callq 0x683f
movl %r15d, %edi
callq 0x41f9
movl %eax, %r15d
movq -0x30(%rbp), %rax
movq (%rax), %rdx
leaq 0xb5d0(%rip), %rdi      # 0xf3d0
movl %r15d, %esi
callq 0x811d
movq %rbx, %rdi
callq 0x6b20
cmpl $0x35, (%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovnel %r15d, %eax
jmp 0x3ff1
movq %rbx, %rdi
callq 0x6b20
movl (%rbx), %eax
cmpl $0x37, %eax
je 0x3f1d
cmpl $0x36, %eax
jne 0x3fcb
leaq 0xb58c(%rip), %r14      # 0xf3d0
movq %r14, %rdi
callq 0x83e6
movq %rax, %r15
movq %r14, %rdi
callq 0x2180
movq %rax, %r14
movq %rbx, %rdi
callq 0x6b20
cmpl $0x37, (%rbx)
jne 0x3fdf
leaq 0xb52e(%rip), %rdi      # 0xf3a0
callq 0x6b20
testq %r15, %r15
je 0x3f2c
movq 0x8(%r15), %rsi
leaq 0x6c2c(%rip), %rdi      # 0xaab7
callq 0x683f
jmp 0x3f3b
leaq 0xb504(%rip), %rdi      # 0xf3a0
callq 0x6b20
movl $0x30, %eax
jmp 0x3ff1
leaq 0xb4ee(%rip), %rdi      # 0xf3a0
callq 0x6b20
movl $0x20, %eax
jmp 0x3ff1
movl $0x50, %edi
callq 0x4000
movq -0x30(%rbp), %rcx
movq %rax, (%rcx)
xorl %eax, %eax
cmpl $0x35, (%rbx)
sete %al
negl %eax
orl $0x50, %eax
jmp 0x3ff1
leaq 0xb4b5(%rip), %rdi      # 0xf3a0
callq 0x6b20
movl $0x40, %eax
jmp 0x3ff1
movl $0x60, %edi
callq 0x4000
movq -0x30(%rbp), %rcx
movq %rax, (%rcx)
xorl %eax, %eax
cmpl $0x35, (%rbx)
sete %al
negl %eax
orl $0x60, %eax
jmp 0x3ff1
leaq 0xb47c(%rip), %rdi      # 0xf3a0
callq 0x6b20
xorl %r14d, %r14d
movq %r14, %rdi
movl $0x9, %esi
xorl %edx, %edx
callq 0x80b5
xorl %r13d, %r13d
leaq 0xb48b(%rip), %r14      # 0xf3d0
leaq 0x6b81(%rip), %r12      # 0xaacd
callq 0x690b
movq %r14, %rdi
callq 0x2180
movq %rax, %r15
movq %rax, %rdi
callq 0x83ff
testq %rax, %rax
je 0x3f74
movq %r12, %rdi
movq %r14, %rsi
callq 0x683f
cmpl $0x1, (%rbx)
jne 0x3f9e
movq %rbx, %rdi
callq 0x6b20
cmpl $0x33, (%rbx)
je 0x3f92
leaq 0x6b57(%rip), %rdi      # 0xaae4
callq 0x6937
movl 0x10(%rbx), %r13d
movq %rbx, %rdi
callq 0x6b20
movq %r15, %rdi
movl $0xa, %esi
movl %r13d, %edx
callq 0x80b5
cmpl $0x38, (%rbx)
je 0x3fbd
incl %r13d
callq 0x6921
jmp 0x3f4c
leaq 0xb3dc(%rip), %rdi      # 0xf3a0
callq 0x6b20
jmp 0x3fe4
xorl %r14d, %r14d
leaq 0x6acc(%rip), %rdi      # 0xaaa1
movq %r14, %rsi
callq 0x683f
jmp 0x3fe4
testq %r15, %r15
je 0x3fce
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