// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movq %rdi, %r14
movq 0x38(%rdi), %rdi
movq 0x58(%r14), %rbx
callq 0x189a0
movq %r12, %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0xc7ec
testq %rax, %rax
je 0xa853
movq 0x50(%r14), %rbx
movq %rax, 0x40(%rsp)
movq %rax, %rdi
callq 0x185ae
movq %rax, %r13
testq %rbx, %rbx
je 0xa8cb
addq $0x40, %r14
movq (%r14), %rax
cmpq %r14, %rax
je 0xa8cb
movq %r14, 0x48(%rsp)
movq %r12, 0x58(%rsp)
testq %r13, %r13
je 0xa8c8
movq %rax, 0x50(%rsp)
movq 0x10(%rax), %r15
movq %r13, %rdi
callq 0x7e76
movq %rax, %rdi
callq 0x7da6
movl %eax, %ebx
movq %r13, %rdi
callq 0x7e76
movq %rax, %rdi
cmpl $0x7, %ebx
jne 0xa5f8
callq 0x951e
cmpq 0x10(%r15), %rax
leaq 0x20(%rsp), %r14
jne 0xa8e0
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq (%r15), %rbx
cmpq %r15, %rbx
je 0xa777
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
movq %r12, %rsi
callq *0x10(%rax)
movq %rax, %rbp
movq %rax, %rdi
callq 0x7da6
cmpl $0x1, %eax
jne 0xa794
movq %rbp, %rdi
callq 0x8160
movq %rax, (%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0xa5de
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0xa5e9
movq %r14, %rdi
movq %rsp, %rdx
callq 0xba6c
movq (%rbp), %rax
movq %rbp, %rdi
callq *0x8(%rax)
movq (%rbx), %rbx
jmp 0xa58e
callq 0x7da6
cmpl $0x6, %eax
jne 0xa8c8
movq (%r15), %r14
cmpq %r15, %r14
je 0xa83e
movq %r15, 0x60(%rsp)
movq %r13, %rdi
callq 0x7e76
movq %rax, %rdi
callq 0x7da6
cmpl $0x6, %eax
jne 0xa886
movq %r13, %rdi
callq 0x7e76
movq %rax, %r15
movq 0x10(%r14), %rdi
movq (%rdi), %rax
movq %r12, %rsi
callq *0x10(%rax)
movq %rax, %rbp
movq (%rax), %rax
leaq 0x88(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
callq *0x18(%rax)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x8d10
movq %rax, %r13
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xa692
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x6270
testq %r13, %r13
jne 0xa757
movl $0x40, %edi
callq 0x6260
movq %rax, %r13
movq %rax, %rdi
callq 0x8a52
movl $0x10, %edi
callq 0x6260
movq %rax, %r12
movq %rax, %rdi
movq %r13, %rsi
callq 0x7dba
movl $0x20, %edi
callq 0x6260
movq %rax, %rbx
movq %rax, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x8826
movq %r15, %rdi
movq %rbx, %rsi
callq 0x8bde
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
movq %r12, %rdi
callq 0x7de0
movl $0x10, %esi
movq %r12, %rdi
callq 0x6270
movq (%r13), %rax
movq %r13, %rdi
callq *0x8(%rax)
movq (%rbp), %rax
leaq 0x68(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
callq *0x18(%rax)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x8d10
movq %rax, %r13
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
movq 0x58(%rsp), %r12
je 0xa757
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x6270
movq (%rbp), %rax
movq %rbp, %rdi
callq *0x8(%rax)
movq (%r14), %r14
movq 0x60(%rsp), %r15
cmpq %r15, %r14
jne 0xa617
jmp 0xa83e
movq %r13, %rdi
callq 0x7e76
movq %rax, %rdi
movq %r14, %rsi
callq 0x9268
movq %rax, %r13
movb $0x1, %bl
jmp 0xa81f
movl $0x30, %edx
movq 0x3c850(%rip), %rdi     # 0x46ff0
leaq 0x2a9f2(%rip), %rsi     # 0x35199
callq 0x62f0
movq %rsp, %rdi
movq 0x40(%rsp), %rsi
callq 0x1857c
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0x3c827(%rip), %rdi     # 0x46ff0
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 (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xa813
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6270
movq (%rbp), %rax
movq %rbp, %rdi
callq *0x8(%rax)
xorl %ebx, %ebx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xa836
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x6270
testb %bl, %bl
je 0xa8c8
movq 0x50(%rsp), %rax
movq (%rax), %rax
cmpq 0x48(%rsp), %rax
jne 0xa52e
jmp 0xa8cb
movq 0x3c796(%rip), %rbx     # 0x46ff0
leaq 0x2a8df(%rip), %rsi     # 0x35140
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
jmp 0xa8a4
leaq 0x2a93d(%rip), %rsi     # 0x351ca
movl $0x28, %edx
movq 0x3c757(%rip), %rbx     # 0x46ff0
movq %rbx, %rdi
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 %r13d, %r13d
movq %r13, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3c709(%rip), %rbx     # 0x46ff0
leaq 0x2a87c(%rip), %rsi     # 0x3516a
movl $0x2e, %edx
movq %rbx, %rdi
callq 0x62f0
movq %rsp, %r14
movq %r14, %rdi
movq 0x40(%rsp), %rsi
callq 0x1857c
movq (%r14), %rsi
movq 0x8(%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
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xa8c8
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6270
jmp 0xa8c8
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xaa34
movq 0x10(%rsp), %rsi
jmp 0xaa13
jmp 0xaa1a
jmp 0xaa1a
movq %rax, %r14
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0xaa1d
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x6270
jmp 0xaa1d
jmp 0xaa1a
movq %rax, %r14
movl $0x20, %esi
movq %rbx, %rdi
jmp 0xaa2f
movq %rax, %r14
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0xaa34
movq 0x78(%rsp), %rsi
jmp 0xaa13
movq %rax, %r14
movl $0x10, %esi
movq %r12, %rdi
jmp 0xaa2f
movq %rax, %r14
movl $0x40, %esi
movq %r13, %rdi
jmp 0xaa2f
movq %rax, %r14
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0xaa34
movq 0x98(%rsp), %rsi
incq %rsi
jmp 0xaa2f
jmp 0xaa1a
movq %rax, %r14
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xaa34
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x6270
movq %r14, %rdi
callq 0x6460