// File: AndrewAlbert[P]Compiler-Theory/SourceCode/parser.cpp
// Function: Parser::Name(int&, int&)
bool Parser::Name(int &type, int &size){
	string id;
	scopeValue nameValue;
	bool isGlobal;
	if( Identifier(id) ){
		bool symbolExists = Scopes->checkSymbol(id, nameValue, isGlobal);
		if(symbolExists){
			if(nameValue.type == TYPE_PROCEDURE){
				ReportError(id + " is a procedure in this scope, not a variable.");
			}
			else{
				size = nameValue.size;
				type = nameValue.type;
			}
		}
		else{
			ReportError(id + " has not been declared in this scope.");
			size = 0;
			type = T_UNKNOWN;
		}

		if( CheckToken(T_LBRACKET) ){
			if(nameValue.size == 0 && nameValue.type != TYPE_PROCEDURE) ReportError(id + " is not an array");
			int type2, size2;
			if( Expression(type2, size2) ){
				if( (size2 > 1) || ( (type2 != TYPE_INTEGER) && (type2 != TYPE_FLOAT) && (type2 != TYPE_BOOL) ) )
					ReportError("Array index must be a scalar numeric value.");
				size = 0;
				if( CheckToken(T_RBRACKET) ){
					// Save the variable <name> values in the generator to be used for arguments
					generator->setArgument( nameValue, isGlobal, 0, true );
					
					// MM to REG for specific array element in IN/INOUT argument
					if( !outArg ) generator->mm2reg(type, size, nameValue.FPoffset, isGlobal, -1, true, type2);
					
					return true;
				}
				else ReportError("Expected ']' after expression in name.");
			}
			else ReportFatalError("Expected expression between brackets.");
		}
		else{
			// Save the variable <name> values in the generator to be used for arguments
			generator->setArgument( nameValue, isGlobal);
			
			// MM to REG for scalars / full arrays that are IN/INOUT arguments
			 if( !outArg ) generator->mm2reg(type, size, nameValue.FPoffset, isGlobal);				
			return true;

		}
	}
	else return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2f0, %rsp            # imm = 0x2F0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x290(%rbp)
leaq -0x40(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x3370
leaq -0x88(%rbp), %rdi
callq 0x126b0
movq -0x290(%rbp), %rdi
movq -0x288(%rbp), %rsi
callq 0xa800
movb %al, -0x279(%rbp)
jmp 0x11659
movb -0x279(%rbp), %al
testb $0x1, %al
jne 0x11668
jmp 0x11d48
movq -0x290(%rbp), %rax
movq 0x90(%rax), %rax
movq %rax, -0x298(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3130
jmp 0x1168f
movq -0x298(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0x88(%rbp), %rdx
leaq -0x89(%rbp), %rcx
callq 0x18720
movb %al, -0x299(%rbp)
jmp 0x116b8
leaq -0xc0(%rbp), %rdi
callq 0x31a0
movb -0x299(%rbp), %al
andb $0x1, %al
movb %al, -0x9d(%rbp)
testb $0x1, -0x9d(%rbp)
je 0x117a2
cmpl $0x11e, -0x88(%rbp)     # imm = 0x11E
jne 0x11788
leaq 0x15200(%rip), %rdx     # 0x268f6
leaq -0xe0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x12a60
jmp 0x11708
movq -0x290(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x9060
jmp 0x1171d
leaq -0xe0(%rbp), %rdi
callq 0x31a0
jmp 0x117a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x11d7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x31a0
jmp 0x11d7d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x31a0
jmp 0x11d7d
movl -0x84(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x88(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
jmp 0x11815
leaq 0x1517c(%rip), %rdx     # 0x26925
leaq -0x100(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x12a60
jmp 0x117bb
movq -0x290(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x9060
jmp 0x117d0
leaq -0x100(%rbp), %rdi
callq 0x31a0
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movl $0x15e, (%rax)          # imm = 0x15E
jmp 0x11815
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x31a0
jmp 0x11d7d
movq -0x290(%rbp), %rdi
movl $0x135, %esi            # imm = 0x135
callq 0x9300
movb %al, -0x29a(%rbp)
jmp 0x1182e
movb -0x29a(%rbp), %al
testb $0x1, %al
jne 0x1183d
jmp 0x11c44
cmpl $0x0, -0x84(%rbp)
jne 0x118b1
cmpl $0x11e, -0x88(%rbp)     # imm = 0x11E
je 0x118b1
leaq 0x150f2(%rip), %rdx     # 0x2694b
leaq -0x120(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x12a60
jmp 0x1186b
movq -0x290(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x9060
jmp 0x11880
leaq -0x120(%rbp), %rdi
callq 0x31a0
jmp 0x118b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x31a0
jmp 0x11d7d
movq -0x290(%rbp), %rdi
leaq -0x124(%rbp), %rsi
leaq -0x128(%rbp), %rdx
callq 0xcab0
movb %al, -0x29b(%rbp)
jmp 0x118d3
movb -0x29b(%rbp), %al
testb $0x1, %al
jne 0x118e2
jmp 0x11b9e
cmpl $0x1, -0x128(%rbp)
jg 0x1191b
cmpl $0x10a, -0x124(%rbp)    # imm = 0x10A
je 0x119bc
cmpl $0x10b, -0x124(%rbp)    # imm = 0x10B
je 0x119bc
cmpl $0x10c, -0x124(%rbp)    # imm = 0x10C
je 0x119bc
leaq -0x149(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x3430
movq -0x2a8(%rbp), %rdx
leaq 0x15020(%rip), %rsi     # 0x2695c
leaq -0x148(%rbp), %rdi
callq 0x62d0
jmp 0x1194a
movq -0x290(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x9060
jmp 0x1195f
leaq -0x148(%rbp), %rdi
callq 0x31a0
leaq -0x149(%rbp), %rdi
callq 0x32e0
jmp 0x119bc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x119ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x31a0
leaq -0x149(%rbp), %rdi
callq 0x32e0
jmp 0x11d7d
movq -0x290(%rbp), %rdi
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movl $0x136, %esi            # imm = 0x136
callq 0x9300
movb %al, -0x2a9(%rbp)
jmp 0x119df
movb -0x2a9(%rbp), %al
testb $0x1, %al
jne 0x119ee
jmp 0x11af8
movq -0x290(%rbp), %rax
movq 0x98(%rax), %rax
movq %rax, -0x2b8(%rbp)
leaq -0x198(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x12770
jmp 0x11a18
movq -0x2b8(%rbp), %rdi
movzbl -0x89(%rbp), %edx
andl $0x1, %edx
leaq -0x198(%rbp), %rsi
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x1e940
jmp 0x11a3f
leaq -0x198(%rbp), %rdi
callq 0x12800
movq -0x290(%rbp), %rax
testb $0x1, 0x7c(%rax)
jne 0x11ae5
movq -0x290(%rbp), %rax
movq 0x98(%rax), %rsi
movq -0x18(%rbp), %rax
movl (%rax), %edx
movq -0x20(%rbp), %rax
movl (%rax), %ecx
movl -0x44(%rbp), %r8d
movl -0x124(%rbp), %edi
movzbl -0x89(%rbp), %r9d
movq %rsp, %rax
movl %edi, 0x10(%rax)
movl $0x0, 0x18(%rax)
movl $0x1, 0x8(%rax)
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
andl $0x1, %r9d
leaq -0x1b8(%rbp), %rdi
callq 0x1c760
jmp 0x11ab4
leaq -0x1b8(%rbp), %rdi
callq 0x31a0
jmp 0x11ae5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x12800
jmp 0x11d7d
movb $0x1, -0x1(%rbp)
movl $0x1, -0x1bc(%rbp)
jmp 0x11d5a
leaq -0x1e1(%rbp), %rdi
movq %rdi, -0x2c0(%rbp)
callq 0x3430
movq -0x2c0(%rbp), %rdx
leaq 0x14e6f(%rip), %rsi     # 0x26988
leaq -0x1e0(%rbp), %rdi
callq 0x62d0
jmp 0x11b27
movq -0x290(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
callq 0x9060
jmp 0x11b3c
leaq -0x1e0(%rbp), %rdi
callq 0x31a0
leaq -0x1e1(%rbp), %rdi
callq 0x32e0
jmp 0x11b99
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x11b88
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x31a0
leaq -0x1e1(%rbp), %rdi
callq 0x32e0
jmp 0x11d7d
jmp 0x11c3f
leaq -0x209(%rbp), %rdi
movq %rdi, -0x2c8(%rbp)
callq 0x3430
movq -0x2c8(%rbp), %rdx
leaq 0x14df0(%rip), %rsi     # 0x269af
leaq -0x208(%rbp), %rdi
callq 0x62d0
jmp 0x11bcd
movq -0x290(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x88a0
jmp 0x11be2
leaq -0x208(%rbp), %rdi
callq 0x31a0
leaq -0x209(%rbp), %rdi
callq 0x32e0
jmp 0x11c3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x11c2e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x31a0
leaq -0x209(%rbp), %rdi
callq 0x32e0
jmp 0x11d7d
jmp 0x11d46
movq -0x290(%rbp), %rax
movq 0x98(%rax), %rax
movq %rax, -0x2d0(%rbp)
leaq -0x258(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x12770
jmp 0x11c6e
movq -0x2d0(%rbp), %rdi
movzbl -0x89(%rbp), %edx
andl $0x1, %edx
leaq -0x258(%rbp), %rsi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
callq 0x1e940
jmp 0x11c95
leaq -0x258(%rbp), %rdi
callq 0x12800
movq -0x290(%rbp), %rax
testb $0x1, 0x7c(%rax)
jne 0x11d36
movq -0x290(%rbp), %rax
movq 0x98(%rax), %rsi
movq -0x18(%rbp), %rax
movl (%rax), %edx
movq -0x20(%rbp), %rax
movl (%rax), %ecx
movl -0x44(%rbp), %r8d
movzbl -0x89(%rbp), %r9d
movq %rsp, %rax
movl $0x0, 0x18(%rax)
movl $0x10a, 0x10(%rax)      # imm = 0x10A
movl $0x0, 0x8(%rax)
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
andl $0x1, %r9d
leaq -0x278(%rbp), %rdi
callq 0x1c760
jmp 0x11d08
leaq -0x278(%rbp), %rdi
callq 0x31a0
jmp 0x11d36
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x258(%rbp), %rdi
callq 0x12800
jmp 0x11d7d
movb $0x1, -0x1(%rbp)
movl $0x1, -0x1bc(%rbp)
jmp 0x11d5a
jmp 0x11d58
movb $0x0, -0x1(%rbp)
movl $0x1, -0x1bc(%rbp)
jmp 0x11d5a
ud2
leaq -0x88(%rbp), %rdi
callq 0x12800
leaq -0x40(%rbp), %rdi
callq 0x31a0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x2f0, %rsp            # imm = 0x2F0
popq %rbp
retq
leaq -0x88(%rbp), %rdi
callq 0x12800
leaq -0x40(%rbp), %rdi
callq 0x31a0
movq -0x98(%rbp), %rdi
callq 0x3420
nop