// File: /workspace/github_cpp_makefile_star2_O3/AndrewAlbert[P]Compiler-Theory/SourceCode/parser.cpp
// Function: Parser::Declaration(bool&)
bool Parser::Declaration(bool &procDec){
	bool global;
	string id;
	scopeValue newSymbol;
	
	/* Ensure that the arguments member and paramType are both cleared before starting. 
	 * None of these cases will set paramType, that will be set later
	 * ProcedureDeclaration will set the arguments based on the procedure's parameters. */
	newSymbol.arguments.clear();
	newSymbol.paramType = TYPE_PARAM_NULL;
	
	//determine if symbol declaration is global in scope
	if( CheckToken(T_GLOBAL) ) global = true;
	else global = false;

	//Determine if a procedure or variable declaration exists
	if( ProcedureDeclaration(id, newSymbol, global) ){
		Scopes->exitScope();
		Scopes->addSymbol(id, newSymbol, global);
		procDec = true;
		return true;
	}
	else if( VariableDeclaration(id, newSymbol) ){
		//Add symbol to current scope. VariableDeclaration will pass the symbol's type and size members.
		Scopes->addSymbol(id, newSymbol, global);
		return true;
	}
	else if( global ){
		ReportLineError("Bad line. Expected either a valid procedure or variable declaration after 'global' keyword");
		return false;
	}
	else return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rsi, %r14
movq %rdi, %r15
leaq 0x10(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x48(%rsp), %rbx
movq %rax, 0x10(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
leaq 0x70(%rsp), %r12
movq %r12, -0x10(%r12)
movq %rax, -0x8(%r12)
movb %al, (%r12)
movq %rbx, %rdi
xorl %esi, %esi
callq 0xe698
movl $0x122, 0x10(%r12)      # imm = 0x122
movq %r15, %rdi
movl $0x105, %esi            # imm = 0x105
callq 0x5c08
movl %eax, %r12d
movzbl %al, %ebp
movq %rsp, %rsi
leaq 0x40(%rsp), %rdx
movq %r15, %rdi
movl %ebp, %ecx
callq 0x700a
testb %al, %al
je 0x6c81
movq 0x90(%r15), %rdi
callq 0xfae6
movq 0x90(%r15), %r12
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
leaq 0x20(%rsp), %rdi
callq 0x3bac
movq 0x40(%rsp), %rax
leaq 0x118(%rsp), %r15
movq %rax, -0x8(%r15)
movq %r15, %rdi
movq %rbx, %r13
movq %rbx, %rsi
callq 0xdfee
leaq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
addq %rsi, %rdx
callq 0x3bac
movq 0x80(%rsp), %rax
leaq 0x110(%rsp), %rdx
movq %rax, 0x40(%rdx)
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
movl %ebp, %ecx
callq 0xfb86
movq 0x130(%rsp), %rdi
cmpq %rbx, %rdi
je 0x6c51
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r15, %rdi
callq 0xdda4
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x6c75
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2200
movb $0x1, (%r14)
movb $0x1, %bpl
jmp 0x6de1
movq %rsp, %rsi
leaq 0x40(%rsp), %rdx
movq %r15, %rdi
callq 0x708c
testb %al, %al
je 0x6d78
movq 0x90(%r15), %r15
leaq 0xb8(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
leaq 0xa8(%rsp), %rdi
callq 0x3bac
movq 0x40(%rsp), %rax
leaq 0xd0(%rsp), %r12
movq %rax, -0x8(%r12)
movq %r12, %rdi
movq %rbx, %r13
movq %rbx, %rsi
callq 0xdfee
leaq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
addq %rsi, %rdx
callq 0x3bac
movq 0x80(%rsp), %rax
leaq 0xc8(%rsp), %rdx
movq %rax, 0x40(%rdx)
leaq 0xa8(%rsp), %rsi
movq %r15, %rdi
movl %ebp, %ecx
callq 0xfb86
movq 0xe8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x6d4e
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r12, %rdi
callq 0xdda4
movq 0xa8(%rsp), %rdi
movb $0x1, %bpl
cmpq %r14, %rdi
je 0x6de1
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x6de1
testb %r12b, %r12b
je 0x6ddc
leaq 0x98(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x12874(%rip), %rsi     # 0x19605
leaq 0x128c7(%rip), %rdx     # 0x1965f
leaq 0x88(%rsp), %rdi
callq 0x3c42
leaq 0x88(%rsp), %rsi
movq %r15, %rdi
movl $0x1, %edx
callq 0x4e96
movq %rbx, %r13
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x6ddf
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x6ddf
movq %rbx, %r13
xorl %ebp, %ebp
leaq 0x10(%rsp), %rbx
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x6e02
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r13, %rdi
callq 0xdda4
movq (%rsp), %rdi
cmpq %rbx, %rdi
je 0x6e20
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2200
movl %ebp, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x6ed0
movq 0x98(%rsp), %rsi
jmp 0x6ec3
jmp 0x6ecd
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0xdd7a
jmp 0x6e76
movq %rax, %rbx
movq %r12, %rdi
callq 0xdda4
jmp 0x6e76
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %r14, %rdi
je 0x6ed0
movq 0xb8(%rsp), %rsi
jmp 0x6ec3
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0xdd7a
jmp 0x6eaf
movq %rax, %rbx
movq %r15, %rdi
callq 0xdda4
jmp 0x6eaf
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x6ed0
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x6ed0
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xdd7a
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x6ef5
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2330
nop