// File: AshOlogn[P]ash-language-interpreter/src/parser.cpp
// Function: evalPostfixMemberAccess()
AbstractExpressionNode* evalPostfixMemberAccess() {
  
  AbstractExpressionNode* head = evalLiteralGroup();
  VariableNode* varNode = dynamic_cast<VariableNode*>(head);

  if(varNode && isPostfixStructure()) {

		string variableName(varNode->variable);

    //make sure variable is declared
    if(!symbolTable->isDeclared(variableName)) {
      throw StaticVariableScopeError(varNode->startLine, varNode->variable, getCodeLineBlock(varNode->startLine-1, varNode->startLine-1), false);   
    }

    //get variable type
    ParseDataType varType = varNode->evalType;

    Token* firstPlus = consume(); //consume first + or -
    Token* secondPlus = consume(); //consume second + or -

    if(secondPlus->type == ADD) {
      //make sure type is correct
      if(!typecheckUnaryExpression(POSTFIX_INC_OP, varType)) {
        throw StaticTypeError(varNode->startLine, secondPlus->line+1, getCodeLineBlock(varNode->startLine-1, secondPlus->line), "postfix increment", varType);
      }
      return new UnaryOperatorNode(POSTFIX_INC_OP, varNode, symbolTable, secondPlus->line+1);

    } else {
      //make sure type is correct
      if(!typecheckUnaryExpression(POSTFIX_DEC_OP, varType)) {
        throw StaticTypeError(varNode->startLine, secondPlus->line+1, getCodeLineBlock(varNode->startLine-1, secondPlus->line), "postfix decrement", varType);
      }
      return new UnaryOperatorNode(POSTFIX_DEC_OP, varNode, symbolTable, secondPlus->line+1); 
    }
  }

  while(peek()->type == LEFT_BRACKET) {
    head = handleMemberAccess(head);
  }

  return head;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
callq 0x35050
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
cmpq $0x0, %rax
je 0x3756c
movq -0xb0(%rbp), %rdi
leaq 0x1c57d(%rip), %rsi     # 0x53ad0
leaq 0x1c516(%rip), %rdx     # 0x53a70
xorl %eax, %eax
movl %eax, %ecx
callq 0x42b0
movq %rax, -0xb8(%rbp)
jmp 0x37577
xorl %eax, %eax
movq %rax, -0xb8(%rbp)
jmp 0x37577
movq -0xb8(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x37a0b
callq 0x369b0
testb $0x1, %al
jne 0x3759b
jmp 0x37a0b
movq -0x18(%rbp), %rsi
addq $0x20, %rsi
leaq -0x38(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x40f0
movq -0xc8(%rbp), %rsi
movq 0x1ce4f(%rip), %rax     # 0x54410
movq %rax, -0xc0(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x40f0
jmp 0x375d3
movq -0xc0(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x2bf50
movb %al, -0xc9(%rbp)
jmp 0x375eb
movb -0xc9(%rbp), %al
xorb $-0x1, %al
movb %al, -0xca(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x4170
movb -0xca(%rbp), %al
testb $0x1, %al
jne 0x37611
jmp 0x37719
movb $0x1, -0x89(%rbp)
movl $0x38, %edi
callq 0x4130
movq %rax, -0xd8(%rbp)
movq -0x18(%rbp), %rsi
movl 0x8(%rsi), %eax
movl %eax, -0xd0(%rbp)
addq $0x20, %rsi
leaq -0x88(%rbp), %rdi
callq 0x40f0
jmp 0x37648
movq -0x18(%rbp), %rax
movl 0x8(%rax), %esi
decl %esi
movl %esi, %edi
callq 0x2feb0
movq %rax, -0xe0(%rbp)
jmp 0x37661
movq -0xe0(%rbp), %rcx
movl -0xd0(%rbp), %esi
movq -0xd8(%rbp), %rdi
leaq -0x88(%rbp), %rdx
xorl %r8d, %r8d
callq 0x3a690
jmp 0x37686
movq -0xd8(%rbp), %rdi
movb $0x0, -0x89(%rbp)
leaq 0x1c08d(%rip), %rsi     # 0x53728
leaq -0x30692(%rip), %rdx    # 0x7010
callq 0x43f0
jmp 0x37a44
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x37a00
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x4170
jmp 0x37a00
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x376fd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x4170
testb $0x1, -0x89(%rbp)
jne 0x37708
jmp 0x37714
movq -0xd8(%rbp), %rdi
callq 0x41d0
jmp 0x37a00
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x90(%rbp)
callq 0x2fe10
movq %rax, -0xe8(%rbp)
jmp 0x37734
movq -0xe8(%rbp), %rax
movq %rax, -0x98(%rbp)
callq 0x2fe10
movq %rax, -0xf0(%rbp)
jmp 0x37750
movq -0xf0(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
cmpl $0x7, (%rax)
jne 0x378b3
movl -0x90(%rbp), %esi
xorl %edi, %edi
callq 0x2b5d0
movb %al, -0xf1(%rbp)
jmp 0x37783
movb -0xf1(%rbp), %al
testb $0x1, %al
jne 0x37840
jmp 0x37793
movl $0x38, %edi
callq 0x4130
movq %rax, -0x110(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edi
movl %edi, -0x108(%rbp)
movq -0xa0(%rbp), %rax
movl 0x10(%rax), %esi
movl %esi, %eax
incl %eax
movl %eax, -0x104(%rbp)
decl %edi
callq 0x2feb0
movq %rax, -0x100(%rbp)
jmp 0x377d5
movq -0x100(%rbp), %rcx
movl -0x104(%rbp), %edx
movl -0x108(%rbp), %esi
movq -0x110(%rbp), %rdi
movl -0x90(%rbp), %r9d
leaq 0x885b(%rip), %r8       # 0x40058
callq 0x3a720
jmp 0x37804
movq -0x110(%rbp), %rdi
leaq 0x1bed6(%rip), %rsi     # 0x536e8
leaq -0x30859(%rip), %rdx    # 0x6fc0
callq 0x43f0
jmp 0x37a44
movq -0x110(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
callq 0x41d0
jmp 0x37a00
movl $0x30, %edi
callq 0x4260
movq %rax, -0x118(%rbp)
jmp 0x37853
movq -0x118(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq 0x1cbab(%rip), %rcx     # 0x54410
movq -0xa0(%rbp), %rax
movl 0x10(%rax), %r8d
incl %r8d
xorl %esi, %esi
callq 0xd070
jmp 0x3787c
movq -0x118(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0xa4(%rbp)
jmp 0x379f5
movq -0x118(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
callq 0x4240
jmp 0x37a00
movl -0x90(%rbp), %esi
movl $0x1, %edi
callq 0x2b5d0
movb %al, -0x119(%rbp)
jmp 0x378cb
movb -0x119(%rbp), %al
testb $0x1, %al
jne 0x37985
jmp 0x378db
movl $0x38, %edi
callq 0x4130
movq %rax, -0x138(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %edi
movl %edi, -0x130(%rbp)
movq -0xa0(%rbp), %rax
movl 0x10(%rax), %esi
movl %esi, %eax
incl %eax
movl %eax, -0x12c(%rbp)
decl %edi
callq 0x2feb0
movq %rax, -0x128(%rbp)
jmp 0x3791d
movq -0x128(%rbp), %rcx
movl -0x12c(%rbp), %edx
movl -0x130(%rbp), %esi
movq -0x138(%rbp), %rdi
movl -0x90(%rbp), %r9d
leaq 0x8725(%rip), %r8       # 0x4006a
callq 0x3a720
jmp 0x3794c
movq -0x138(%rbp), %rdi
leaq 0x1bd8e(%rip), %rsi     # 0x536e8
leaq -0x309a1(%rip), %rdx    # 0x6fc0
callq 0x43f0
jmp 0x37a44
movq -0x138(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
callq 0x41d0
jmp 0x37a00
movl $0x30, %edi
callq 0x4260
movq %rax, -0x140(%rbp)
jmp 0x37998
movq -0x140(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq 0x1ca66(%rip), %rcx     # 0x54410
movq -0xa0(%rbp), %rax
movl 0x10(%rax), %r8d
incl %r8d
movl $0x1, %esi
callq 0xd070
jmp 0x379c4
movq -0x140(%rbp), %rax
movq %rax, -0x8(%rbp)
movl $0x1, -0xa4(%rbp)
jmp 0x379f5
movq -0x140(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
callq 0x4240
jmp 0x37a00
leaq -0x38(%rbp), %rdi
callq 0x4170
jmp 0x37a2e
leaq -0x38(%rbp), %rdi
callq 0x4170
jmp 0x37a3b
jmp 0x37a0d
callq 0x2fe60
cmpl $0x2, (%rax)
jne 0x37a26
movq -0x10(%rbp), %rdi
callq 0x36a10
movq %rax, -0x10(%rbp)
jmp 0x37a0d
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x4420
nopw %cs:(%rax,%rax)