// File: /workspace/github_cpp_makefile_star2_O1/marxn[P]pupp/src/parser/expression.cpp
// Function: VarExpression::GetVarRef(NodeContext*)
ValueBox * VarExpression::GetVarRef(NodeContext * context)
{
        Variable * var = context->GetVariable(this->VarLayer, this->VarDef->GetVarIndex());

        if(var==NULL)
        {
                cerr<<"pupp runtime error: cannot find variable:"<<this->VarName<<endl;
                return NULL;
        }

        if(this->ExprsList.size()==0)
        {
                return var->GetVBox();
        }

        ValueBox * result = var->GetVBox();

        for(list<list<Expression*>*>::iterator gitor = this->ExprsList.begin(); gitor!=this->ExprsList.end(); gitor++)
        {
            if(result==NULL)
            {
                    return NULL;
            }
            list<Expression*> * ExprList = *gitor;
            
            if(result->GetVal()->GetType()==Array)
            {
                    if(static_cast<ArrayValue*>(result->GetVal())->GetDimensionNum()!=ExprList->size())
                    {
                            cerr<<"pupp runtime error: wrong dimension variable: "<<var->GetVarName()<<endl;
                            return NULL;
                    }

                    vector<long> desc;
                    
                    for(list<Expression*>::iterator i = ExprList->begin(); i!=ExprList->end(); i++)
                    {
                            ConstValue * value = (*i)->Calculate(context);
                            if(value->GetType()!=Integer)
                            {
                                    cerr<<"pupp runtime error: invalid index for variable: "<<var->GetVarName()<<endl;
                                    delete value;
                                    return NULL;
                            }
                            
                            desc.push_back(static_cast<IntegerValue*>(value)->GetValue());
                            delete value;
                    }

                    ArrayValue * value = static_cast<ArrayValue*>(result->GetVal());
                    result = value->GetElementBox(desc);
            }
            else if(result->GetVal()->GetType()==Map)
            {
                    for(list<Expression*>::iterator i = ExprList->begin(); i!=ExprList->end(); i++)
                    {
                            if(result->GetVal()->GetType()!=Map)
                            {
                                    cerr<<"pupp runtime error: Expect a collection."<<endl;
                                    return NULL;
                            }

                            MapValue * local = static_cast<MapValue*>(result->GetVal());
                            
                            ConstValue * key = (*i)->Calculate(context);

                            result = local->FindByKey(key->toString());

                            if(result==NULL)
                            {
                                    MapValue * value = new MapValue();
                                    ValueBox * vb = new ValueBox(value);
                                    KVValue * kv = new KVValue(key, vb);
                                    local->AddKV(kv);

                                    delete kv;
                                    delete vb;
                                    delete value;
                                    
                                    result = local->FindByKey(key->toString());
                            }
                            
                            delete key;
                    }
            }
            else
            {
                    return NULL;
            }
        }
        
        return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %r15
movq %rdi, %r14
movq 0x38(%rdi), %rdi
movq 0x58(%r14), %rbx
callq 0x18cf4
movq %r15, 0x58(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0xc886
testq %rax, %rax
je 0xa95a
movq 0x50(%r14), %rbx
movq %rax, 0x50(%rsp)
movq %rax, %rdi
callq 0x18906
movq %rax, %r13
testq %rbx, %rbx
je 0xa9b2
addq $0x40, %r14
movq %r14, %rax
movq %r14, (%rsp)
movq (%rax), %rax
cmpq %r14, %rax
je 0xa9b2
testq %r13, %r13
je 0xa9af
movq %rax, 0x60(%rsp)
movq 0x10(%rax), %r15
movq %r13, %rdi
callq 0x7ec4
movq %rax, %rdi
callq 0x7dee
movl %eax, %ebx
movq %r13, %rdi
callq 0x7ec4
cmpl $0x7, %ebx
movq %r15, 0x28(%rsp)
movq %rax, %rdi
jne 0xa6c5
callq 0x956e
cmpq 0x10(%r15), %rax
jne 0xa845
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq %r15, %r14
movq (%r14), %r14
cmpq %r15, %r14
sete %r12b
je 0xa8cc
movq 0x10(%r14), %rdi
movq (%rdi), %rax
movq 0x58(%rsp), %rsi
callq *0x10(%rax)
movq %rax, %rbx
movq %rax, %rdi
callq 0x7dee
movl %eax, %ebp
cmpl $0x1, %eax
jne 0xa615
movq %rbx, %rdi
callq 0x81ae
movq %rax, 0x8(%rsp)
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0xa69f
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x38(%rsp)
jmp 0xa6ae
movl $0x30, %edx
movq 0x3d9cf(%rip), %rdi     # 0x47ff0
leaq 0x2bb71(%rip), %rsi     # 0x36199
callq 0x62f0
leaq 0x8(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x188d4
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x3d9a3(%rip), %rdi     # 0x47ff0
callq 0x62f0
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %r15, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
movq 0x28(%rsp), %r15
je 0xa6ae
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6270
jmp 0xa6ae
leaq 0x30(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0xbb28
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
cmpl $0x1, %ebp
je 0xa5b6
jmp 0xa8e4
callq 0x7dee
cmpl $0x6, %eax
jne 0xa8c7
movq (%r15), %r14
movb $0x1, %r12b
cmpq %r15, %r14
je 0xa946
movq %r13, %rdi
callq 0x7ec4
movq %rax, %rdi
callq 0x7dee
cmpl $0x6, %eax
jne 0xa901
movq %r13, %rdi
callq 0x7ec4
movq %rax, %rbp
movq 0x10(%r14), %rdi
movq (%rdi), %rax
movq 0x58(%rsp), %rsi
callq *0x10(%rax)
movq %rax, %rbx
movq (%rax), %rax
leaq 0x88(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq *0x18(%rax)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x8d58
movq %rax, %r13
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
movq 0x28(%rsp), %r15
je 0xa764
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x6270
testq %r13, %r13
jne 0xa828
movl $0x40, %edi
callq 0x6260
movq %rax, %r13
movq %rax, %rdi
callq 0x8a9a
movl $0x10, %edi
callq 0x6260
movq %rax, %r12
movq %rax, %rdi
movq %r13, %rsi
callq 0x7e02
movl $0x20, %edi
callq 0x6260
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x886e
movq %rbp, %rdi
movq %r15, %rsi
callq 0x8c26
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
movq %r12, %rdi
callq 0x7e28
movl $0x10, %esi
movq %r12, %rdi
callq 0x6270
movq (%r13), %rax
movq %r13, %rdi
callq *0x8(%rax)
movq (%rbx), %rax
leaq 0x68(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq *0x18(%rax)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x8d58
movq %rax, %r13
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
movq 0x28(%rsp), %r15
je 0xa828
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x6270
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movq (%r14), %r14
cmpq %r15, %r14
movb $0x1, %r12b
jne 0xa6e2
jmp 0xa946
movl $0x2e, %edx
movq 0x3d79f(%rip), %rbx     # 0x47ff0
movq %rbx, %rdi
leaq 0x2b90f(%rip), %rsi     # 0x3616a
callq 0x62f0
leaq 0x8(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x188d4
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %rbx, %rdi
callq 0x62f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xa8c7
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6270
xorl %r12d, %r12d
jmp 0xa94a
movq %r13, %rdi
callq 0x7ec4
movq %rax, %rdi
leaq 0x30(%rsp), %rsi
callq 0x92b0
movq %rax, %r13
movq (%rsp), %r14
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xa94a
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x6270
jmp 0xa94a
movl $0x28, %edx
movq 0x3d6e3(%rip), %rbx     # 0x47ff0
movq %rbx, %rdi
leaq 0x2b8b3(%rip), %rsi     # 0x361ca
callq 0x62f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
xorl %r12d, %r12d
movq (%rsp), %r14
testb %r12b, %r12b
movq 0x60(%rsp), %rax
jne 0xa54a
jmp 0xa9af
movq 0x3d68f(%rip), %rbx     # 0x47ff0
leaq 0x2b7d8(%rip), %rsi     # 0x36140
movl $0x29, %edx
movq %rbx, %rdi
callq 0x62f0
movq 0x18(%r14), %rsi
movq 0x20(%r14), %rdx
movq %rbx, %rdi
callq 0x62f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x6220
movsbl %al, %esi
movq %rbx, %rdi
callq 0x6040
movq %rax, %rdi
callq 0x61b0
xorl %r13d, %r13d
movq %r13, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xaa7c
movq %rax, %rbx
movl $0x20, %esi
movq %r15, %rdi
jmp 0xaa91
movq %rax, %rbx
movl $0x10, %esi
movq %r12, %rdi
jmp 0xaa91
movq %rax, %rbx
movl $0x40, %esi
movq %r13, %rdi
jmp 0xaa91
movq %rax, %rbx
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0xaa96
movq 0x78(%rsp), %rsi
jmp 0xaa54
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xaa96
movq 0x18(%rsp), %rsi
jmp 0xaa54
jmp 0xaa7c
movq %rax, %rbx
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xaa96
movq 0x98(%rsp), %rsi
incq %rsi
jmp 0xaa91
jmp 0xaa7c
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0xaa7f
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x6270
jmp 0xaa7f
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0xaa96
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x6270
movq %rbx, %rdi
callq 0x6470