// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %rax
movups %xmm0, -0x28(%rax)
andq $0x0, -0x18(%rax)
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x10(%rsp), %rsi
callq 0x52ec
movl %eax, %ebx
testb %al, %al
je 0x92b1
movq 0x90(%r14), %r13
leaq 0x118(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2270
leaq 0x118(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x6(%rsp), %rcx
movq %r13, %rdi
callq 0xb36a
movl %eax, %ebp
leaq 0x118(%rsp), %rdi
callq 0x20f0
testb %bpl, %bpl
je 0x9046
movl 0x30(%rsp), %eax
cmpl $0x11e, %eax            # imm = 0x11E
jne 0x908a
leaq 0x961b(%rip), %rdx      # 0x12630
leaq 0xf8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x98d8
leaq 0xf8(%rsp), %rsi
movq %r14, %rdi
callq 0x47e0
leaq 0xf8(%rsp), %rdi
callq 0x20f0
jmp 0x9095
leaq 0x9612(%rip), %rdx      # 0x1265f
leaq 0xd8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x98d8
leaq 0xd8(%rsp), %rsi
movq %r14, %rdi
callq 0x47e0
leaq 0xd8(%rsp), %rdi
callq 0x20f0
andl $0x0, (%r15)
movl $0x15e, (%r12)          # imm = 0x15E
jmp 0x9095
movl 0x34(%rsp), %ecx
movl %ecx, (%r15)
movl %eax, (%r12)
movq %r14, %rdi
movl $0x135, %esi            # imm = 0x135
callq 0x49b0
testb %al, %al
je 0x91fd
cmpl $0x0, 0x34(%rsp)
jne 0x90f1
cmpl $0x11e, 0x30(%rsp)      # imm = 0x11E
je 0x90f1
leaq 0x95c3(%rip), %rdx      # 0x12685
leaq 0xb8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x98d8
leaq 0xb8(%rsp), %rsi
movq %r14, %rdi
callq 0x47e0
leaq 0xb8(%rsp), %rdi
callq 0x20f0
leaq 0x8(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %r14, %rdi
callq 0x64cc
testb %al, %al
je 0x92d9
cmpl $0x1, 0xc(%rsp)
jg 0x9120
movl $0xfffffef3, %eax       # imm = 0xFFFFFEF3
addl 0x8(%rsp), %eax
cmpl $-0x4, %eax
ja 0x9156
leaq 0x956f(%rip), %rsi      # 0x12696
leaq 0x98(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x36b8
leaq 0x98(%rsp), %rsi
movq %r14, %rdi
callq 0x47e0
leaq 0x98(%rsp), %rdi
callq 0x20f0
andl $0x0, (%r15)
movq %r14, %rdi
movl $0x136, %esi            # imm = 0x136
callq 0x49b0
testb %al, %al
je 0x9284
movq 0x98(%r14), %r13
leaq 0x1e0(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x97e6
movzbl 0x6(%rsp), %edx
leaq 0x1e0(%rsp), %rsi
pushq $0x1
popq %r8
movq %r13, %rdi
xorl %ecx, %ecx
callq 0xf056
leaq 0x1e0(%rsp), %rdi
callq 0x9836
cmpb $0x0, 0x7c(%r14)
jne 0x92b1
movq 0x98(%r14), %rsi
movl (%r12), %edx
movl (%r15), %ecx
movl 0x74(%rsp), %r8d
movzbl 0x6(%rsp), %r9d
movl 0x8(%rsp), %eax
leaq 0x178(%rsp), %rdi
pushq $0x0
pushq %rax
pushq $0x1
pushq $-0x1
callq 0xdbce
addq $0x20, %rsp
leaq 0x178(%rsp), %rdi
jmp 0x92ac
movq 0x98(%r14), %r13
leaq 0x198(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x97e6
movzbl 0x6(%rsp), %edx
leaq 0x198(%rsp), %rsi
pushq $-0x1
popq %rcx
movq %r13, %rdi
xorl %r8d, %r8d
callq 0xf056
leaq 0x198(%rsp), %rdi
callq 0x9836
cmpb $0x0, 0x7c(%r14)
jne 0x92b1
movq 0x98(%r14), %rsi
movl (%r12), %edx
movl (%r15), %ecx
movl 0x74(%rsp), %r8d
movzbl 0x6(%rsp), %r9d
leaq 0x158(%rsp), %rdi
pushq $0x0
pushq $0x10a                  # imm = 0x10A
pushq $0x0
pushq $-0x1
callq 0xdbce
addq $0x20, %rsp
leaq 0x158(%rsp), %rdi
jmp 0x92ac
leaq 0x9437(%rip), %rsi      # 0x126c2
leaq 0x78(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x36b8
leaq 0x78(%rsp), %rsi
movq %r14, %rdi
callq 0x47e0
leaq 0x78(%rsp), %rdi
callq 0x20f0
leaq 0x30(%rsp), %rdi
callq 0x9836
leaq 0x10(%rsp), %rdi
callq 0x20f0
movl %ebx, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x9409(%rip), %rsi      # 0x126e9
leaq 0x138(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x36b8
leaq 0x138(%rsp), %rsi
movq %r14, %rdi
callq 0x4278
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
jmp 0x937d
movq %rax, %rbx
leaq 0x1e0(%rsp), %rdi
jmp 0x935e
jmp 0x9388
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
jmp 0x937d
jmp 0x9388
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
jmp 0x937d
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
jmp 0x937d
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
jmp 0x937d
jmp 0x9388
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
callq 0x9836
jmp 0x938b
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
jmp 0x937d
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
callq 0x20f0
jmp 0x938b
jmp 0x9388
jmp 0x9388
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x9836
leaq 0x10(%rsp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x2310
nop