// File: 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
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1a0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3370
leaq -0x88(%rbp), %rdi
callq 0x126b0
leaq -0x80(%rbp), %rdi
callq 0x126e0
movq -0x1a0(%rbp), %rdi
movl $0x122, -0x48(%rbp)     # imm = 0x122
movl $0x105, %esi            # imm = 0x105
callq 0x9300
movb %al, -0x192(%rbp)
jmp 0xa90c
movb -0x192(%rbp), %al
testb $0x1, %al
jne 0xa918
jmp 0xa935
movb $0x1, -0x19(%rbp)
jmp 0xa939
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xac3e
movb $0x0, -0x19(%rbp)
movq -0x1a0(%rbp), %rdi
movzbl -0x19(%rbp), %ecx
andl $0x1, %ecx
leaq -0x40(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0xae00
movb %al, -0x1a1(%rbp)
jmp 0xa95f
movb -0x1a1(%rbp), %al
testb $0x1, %al
jne 0xa96e
jmp 0xaa57
movq -0x1a0(%rbp), %rax
movq 0x90(%rax), %rdi
callq 0x18340
jmp 0xa983
movq -0x1a0(%rbp), %rax
movq 0x90(%rax), %rax
movq %rax, -0x1b0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3130
jmp 0xa9aa
leaq -0x100(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x12770
jmp 0xa9bf
movq -0x1b0(%rbp), %rdi
movzbl -0x19(%rbp), %ecx
andl $0x1, %ecx
leaq -0xb8(%rbp), %rsi
leaq -0x100(%rbp), %rdx
callq 0x183f0
jmp 0xa9e2
leaq -0x100(%rbp), %rdi
callq 0x12800
leaq -0xb8(%rbp), %rdi
callq 0x31a0
movq -0x18(%rbp), %rax
movb $0x1, (%rax)
movb $0x1, -0x1(%rbp)
movl $0x1, -0x104(%rbp)
jmp 0xac1b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xaa46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x12800
leaq -0xb8(%rbp), %rdi
callq 0x31a0
jmp 0xac3e
movq -0x1a0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0xaef0
movb %al, -0x1b1(%rbp)
jmp 0xaa76
movb -0x1b1(%rbp), %al
testb $0x1, %al
jne 0xaa85
jmp 0xab52
movq -0x1a0(%rbp), %rax
movq 0x90(%rax), %rax
movq %rax, -0x1c0(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3130
jmp 0xaaac
leaq -0x170(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x12770
jmp 0xaac1
movq -0x1c0(%rbp), %rdi
movzbl -0x19(%rbp), %ecx
andl $0x1, %ecx
leaq -0x128(%rbp), %rsi
leaq -0x170(%rbp), %rdx
callq 0x183f0
jmp 0xaae4
leaq -0x170(%rbp), %rdi
callq 0x12800
leaq -0x128(%rbp), %rdi
callq 0x31a0
movb $0x1, -0x1(%rbp)
movl $0x1, -0x104(%rbp)
jmp 0xac1b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xab41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x12800
leaq -0x128(%rbp), %rdi
callq 0x31a0
jmp 0xac3e
testb $0x1, -0x19(%rbp)
je 0xac0d
leaq -0x191(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x3430
movq -0x1c8(%rbp), %rdx
leaq 0x1ad4e(%rip), %rsi     # 0x258cb
leaq -0x190(%rbp), %rdi
callq 0x62d0
jmp 0xab8b
movq -0x1a0(%rbp), %rdi
leaq -0x190(%rbp), %rsi
movl $0x1, %edx
callq 0x8b50
jmp 0xaba5
leaq -0x190(%rbp), %rdi
callq 0x31a0
leaq -0x191(%rbp), %rdi
callq 0x32e0
movb $0x0, -0x1(%rbp)
movl $0x1, -0x104(%rbp)
jmp 0xac1b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xabff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x31a0
leaq -0x191(%rbp), %rdi
callq 0x32e0
jmp 0xac3e
movb $0x0, -0x1(%rbp)
movl $0x1, -0x104(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x12800
leaq -0x40(%rbp), %rdi
callq 0x31a0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
leaq -0x88(%rbp), %rdi
callq 0x12800
leaq -0x40(%rbp), %rdi
callq 0x31a0
movq -0x90(%rbp), %rdi
callq 0x3420
nop