// File: /workspace/github_c_makefile_star2_O0/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
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x1, -0x18(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x4389
leaq 0xe238(%rip), %rax      # 0x12530
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
subl $0x2b, %eax
je 0x430e
jmp 0x4304
movl -0x1c(%rbp), %eax
subl $0x32, %eax
je 0x433b
jmp 0x437d
movq -0x10(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x4323
leaq 0x85f6(%rip), %rdi      # 0xc914
callq 0x8110
movq -0x10(%rbp), %rax
movl $0x4, (%rax)
leaq 0xe1fc(%rip), %rdi      # 0x12530
callq 0x84c0
jmp 0x4384
movq -0x10(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x4350
leaq 0x85fc(%rip), %rdi      # 0xc947
callq 0x8110
movq -0x10(%rbp), %rax
cmpl $0x4, (%rax)
jne 0x4365
leaq 0x85b4(%rip), %rdi      # 0xc914
callq 0x8110
movq -0x10(%rbp), %rax
movl $0x5, (%rax)
leaq 0xe1ba(%rip), %rdi      # 0x12530
callq 0x84c0
jmp 0x4384
movl $0x0, -0x18(%rbp)
jmp 0x42e7
leaq 0xe1a0(%rip), %rax      # 0x12530
movl (%rax), %eax
addl $-0x1e, %eax
movl %eax, %ecx
movq %rcx, -0x28(%rbp)
subl $0x18, %eax
ja 0x44d2
movq -0x28(%rbp), %rax
leaq 0x84e1(%rip), %rcx      # 0xc890
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x10, -0x14(%rbp)
leaq 0xe16a(%rip), %rdi      # 0x12530
callq 0x84c0
jmp 0x44e9
movl $0x20, -0x14(%rbp)
leaq 0xe152(%rip), %rdi      # 0x12530
callq 0x84c0
jmp 0x44e9
movl $0x30, -0x14(%rbp)
leaq 0xe13a(%rip), %rdi      # 0x12530
callq 0x84c0
jmp 0x44e9
movl $0x40, -0x14(%rbp)
leaq 0xe122(%rip), %rdi      # 0x12530
callq 0x84c0
jmp 0x44e9
movl $0x50, -0x14(%rbp)
movl $0x50, %edi
callq 0x4500
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
leaq 0xe0f6(%rip), %rax      # 0x12530
cmpl $0x35, (%rax)
jne 0x4446
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0x44e9
movl $0x60, -0x14(%rbp)
movl $0x60, %edi
callq 0x4500
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
leaq 0xe0c3(%rip), %rax      # 0x12530
cmpl $0x35, (%rax)
jne 0x4479
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0x44e9
movl $0x30, -0x14(%rbp)
callq 0x47a0
leaq 0xe0a2(%rip), %rax      # 0x12530
cmpl $0x35, (%rax)
jne 0x449a
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0x44e9
movq -0x8(%rbp), %rdi
callq 0x4940
movl %eax, -0x14(%rbp)
leaq 0xe081(%rip), %rax      # 0x12530
cmpl $0x35, (%rax)
jne 0x44bb
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0x44e9
movq -0x8(%rbp), %rsi
leaq 0xe098(%rip), %rdi      # 0x12560
callq 0x49e0
movl %eax, -0x14(%rbp)
jmp 0x44e9
leaq 0xe057(%rip), %rax      # 0x12530
movq 0x8(%rax), %rsi
leaq 0x8496(%rip), %rdi      # 0xc97a
callq 0x7fc0
movl -0x14(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)