Exemplo n.º 1
0
DLRExpressionTree*
ETSemanticsForLambdas::ConvertSymbol
(
    ILTree::Expression* Input,
    ExpressionFlags Flags,
    Type* TargetType
)
{
    ThrowIfNull(Input);
    ThrowIfFalse(Input->bilop == SX_SYM);

    Declaration* Symbol = Input->AsSymbolReferenceExpression().pnamed;

    if(Symbol->IsVariable())
    {
        Variable *Var = Symbol->PVariable();

        // IsLocal check also required for Chimayo scenarios.
        if (Var->IsTemporary() || Var->IsFromScriptScope())
        {
            DLRExpressionTree **TreeNode = NULL;
            if((TreeNode = m_VariablesMap->HashFind(Var)) && *TreeNode)
            {
                return *TreeNode;
            }

            if (Var->IsFromScriptScope())
            {
                DLRExpressionTree *VarExprNode = m_ExprTreeGenerator->CreateVariableExpr(
                    Var->GetEmittedName(),
                    Var->GetType(),
                    TargetType,
                    Input->Loc
                    );

                // All variables need to be added to the map to ensure uniqueness.
                m_VariablesMap->HashAdd(Var, VarExprNode);

                return VarExprNode;
            }

            // Non-script scope variable should already exist from the outer block
            // since user lambdas in VB cannot result in creation of new locals.
            ThrowIfFalse(false);
        }
    }

    // fall back to the base implementation
    return ExpressionTreeSemantics<DLRExpressionTree>::ConvertSymbol(
        Input,
        Flags,
        TargetType
        );
}