Esempio n. 1
0
        public Expr Variable(AnalyzerContext analyzer, string varName)
        {
            var variable = analyzer.Context.GetVariableAssignableTo(varName, analyzer.ExpectedType ?? TypeSingleton.Any);

            if (variable == null)
            {
                analyzer.Fail("No such variable: " + varName + " " + analyzer.ExpectedType);
            }
            if (variable.ConstantValue != null)
            {
                return(variable.ConstantValue);
            }
            return(new ExprImpl(variable.Type, exprWriter.ReadVariable(analyzer.Context.GetReferenceIndex(variable))));
        }
Esempio n. 2
0
        public Expr ContextVariable(AnalyzerContext analyzer, ExprBuilderObj leftExpr, string varName)
        {
            var type        = new TypeContext(new Variable(varName, analyzer.ExpectedType ?? TypeSingleton.Any));
            var left        = analyzer.Analyze(leftExpr, type);
            var contextType = left.Type.ConcreteType as TypeContext;
            var variable    = contextType.Variables.GetAssignableTo(varName, analyzer.ExpectedType);

            if (variable == null)
            {
                analyzer.Fail("Unknown context variable name: " + varName);
            }
            var variable2 = contextType.Variables.GetAssignableTo(varName, analyzer.ExpectedType);

            var refIndex = contextType.Variables.GetReferenceIndex(variable) + 1; // TODO +1 is for the base context
            var expr     = new ExprImpl(variable.Type, exprWriter.ReadContextVariable(refIndex));

            return(new ExprImpl(variable.Type, exprWriter.Sequence(left, expr)));
        }