// File: /workspace/github_cpp_makefile_star2_O1/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
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq %rax, 0x10(%rbx)
leaq 0x70(%rsp), %r13
movq %r13, -0x10(%r13)
movq %rax, -0x8(%r13)
movb %al, (%r13)
movq -0x28(%r13), %rsi
movq %rbx, %rdi
callq 0xe77c
movl $0x122, 0x10(%r13)      # imm = 0x122
movq %r15, %rdi
movl $0x105, %esi            # imm = 0x105
callq 0x5c0a
movl %eax, %r12d
movzbl %al, %ebp
movq %rsp, %rsi
leaq 0x40(%rsp), %rdx
movq %r15, %rdi
movl %ebp, %ecx
callq 0x7008
testb %al, %al
je 0x6c8d
movq 0x90(%r15), %rdi
callq 0xfb86
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 0x3ba4
movq 0x40(%rsp), %rax
leaq 0x118(%rsp), %r15
movq %rax, -0x8(%r15)
movq %r15, %rdi
movq %rbx, %rsi
callq 0xe0e0
leaq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
addq %rsi, %rdx
callq 0x3ba4
movq 0x80(%rsp), %rax
leaq 0x110(%rsp), %rdx
movq %rax, 0x40(%rdx)
leaq 0x20(%rsp), %rsi
movq %r12, %rdi
movl %ebp, %ecx
callq 0xfc28
movq 0x130(%rsp), %rdi
cmpq %rbx, %rdi
je 0x6c5d
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r15, %rdi
callq 0xdea4
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x6c81
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2200
movb $0x1, (%r14)
movb $0x1, %bpl
jmp 0x6de2
movq %rsp, %rsi
leaq 0x40(%rsp), %rdx
movq %r15, %rdi
callq 0x708a
testb %al, %al
je 0x6d81
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 0x3ba4
movq 0x40(%rsp), %rax
leaq 0xd0(%rsp), %r12
movq %rax, -0x8(%r12)
movq %r12, %rdi
movq %rbx, %rsi
callq 0xe0e0
leaq 0xe8(%rsp), %rdi
leaq 0xf8(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
addq %rsi, %rdx
callq 0x3ba4
movq 0x80(%rsp), %rax
leaq 0xc8(%rsp), %rdx
movq %rax, 0x40(%rdx)
leaq 0xa8(%rsp), %rsi
movq %r15, %rdi
movl %ebp, %ecx
callq 0xfc28
movq 0xe8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x6d57
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r12, %rdi
callq 0xdea4
movq 0xa8(%rsp), %rdi
movb $0x1, %bpl
cmpq %r14, %rdi
je 0x6de2
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x6de2
testb %r12b, %r12b
je 0x6de0
leaq 0x98(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x1286b(%rip), %rsi     # 0x19605
leaq 0x128be(%rip), %rdx     # 0x1965f
leaq 0x88(%rsp), %rdi
callq 0x3c34
leaq 0x88(%rsp), %rsi
movq %r15, %rdi
movl $0x1, %edx
callq 0x4e82
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x6de0
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x2200
xorl %ebp, %ebp
leaq 0x10(%rsp), %rbx
movq 0x60(%rsp), %rdi
cmpq %r13, %rdi
je 0x6dfe
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x48(%rsp), %rdi
callq 0xdea4
movq (%rsp), %rdi
cmpq %rbx, %rdi
je 0x6e1e
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 0x6ece
movq 0x98(%rsp), %rsi
jmp 0x6ec1
jmp 0x6ecb
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0xde7a
jmp 0x6e74
movq %rax, %rbx
movq %r12, %rdi
callq 0xdea4
jmp 0x6e74
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %r14, %rdi
je 0x6ece
movq 0xb8(%rsp), %rsi
jmp 0x6ec1
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0xde7a
jmp 0x6ead
movq %rax, %rbx
movq %r15, %rdi
callq 0xdea4
jmp 0x6ead
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x6ece
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x6ece
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0xde7a
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x6ef3
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2330
nop