예제 #1
0
        public static void TestPrimitive(string literal, int btToken, object val, AbstractSymbolValueProvider vp = null)
        {
            var pv = GetPrimitiveValue(literal, vp ?? GetDefaultSymbolVP());

            Assert.That(pv.BaseTypeToken, Is.EqualTo(btToken));
            Assert.That(pv.Value, Is.EqualTo(val));
        }
예제 #2
0
        public static PrimitiveValue GetPrimitiveValue(string literalCode, AbstractSymbolValueProvider vp = null)
        {
            var v = E(literalCode, vp ?? GetDefaultSymbolVP());

            Assert.That(v, Is.TypeOf(typeof(PrimitiveValue)));
            return((PrimitiveValue)v);
        }
예제 #3
0
		public InterpretationContext(AbstractSymbolValueProvider baseValueProvider) : base(baseValueProvider.ResolutionContext)
		{
			var ic = baseValueProvider as InterpretationContext;
			if (ic != null)
			{
				// Copy over already resolved types and parent template symbols etc.
			}
		}
예제 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dm"></param>
        /// <param name="args"></param>
        /// <param name="baseValueProvider">Required for evaluating missing default parameters.</param>
        public static bool AssignCallArgumentsToIC <T>(MemberSymbol mr, T[] args, AbstractSymbolValueProvider baseValueProvider,
                                                       out Dictionary <DVariable, T> targetArgs, ResolutionContext ctxt = null) where T : class, ISemantic
        {
            var dm   = mr.Definition as DMethod;
            int para = 0;

            ISemantic firstArg;

            if (TypeResolution.UFCSResolver.IsUfcsResult(mr, out firstArg))
            {
                para++;
            }

            targetArgs = new Dictionary <DVariable, T>();
            var argsRemaining = args != null ? args.Length : 0;
            int argu          = 0;

            for (; para < dm.Parameters.Count; para++)
            {
                var par = dm.Parameters[para] as DVariable;

                if (par.Type is VarArgDecl && argsRemaining > 0)
                {
                    var va_args = new T[argsRemaining];
                    args.CopyTo(va_args, argu);
                    argsRemaining = 0;
                    //TODO: Assign a value tuple to par
                    if (++para < dm.Parameters.Count)
                    {
                        return(false);
                    }
                }

                if (argsRemaining > 0)
                {
                    targetArgs[par] = args[argu++];
                    argsRemaining--;
                }
                else if (par.Initializer != null)
                {
                    if (typeof(T) == typeof(AbstractType))
                    {
                        targetArgs[par] = ExpressionTypeEvaluation.EvaluateType(par.Initializer, ctxt) as T;
                    }
                    else if (typeof(T) == typeof(ISymbolValue))
                    {
                        targetArgs[par] = Evaluation.EvaluateValue(par.Initializer, baseValueProvider) as T;
                    }
                }
                else
                {
                    return(false);
                }
            }

            return(argsRemaining == 0);
        }
예제 #5
0
        FunctionEvaluation(MemberSymbol method, AbstractSymbolValueProvider baseValueProvider, Dictionary <DVariable, ISymbolValue> args)
        {
            vp = new InterpretationContext(baseValueProvider);

            foreach (var kv in args)
            {
                vp[kv.Key] = kv.Value;
            }
        }
예제 #6
0
        public InterpretationContext(AbstractSymbolValueProvider baseValueProvider) : base(baseValueProvider.ResolutionContext)
        {
            var ic = baseValueProvider as InterpretationContext;

            if (ic != null)
            {
                // Copy over already resolved types and parent template symbols etc.
            }
        }
예제 #7
0
        public static bool EvalIsExpression(string IsExpressionCode, AbstractSymbolValueProvider vp)
        {
            var e = DParser.ParseExpression("is(" + IsExpressionCode + ")");

            var v = Evaluation.EvaluateValue(e, vp);

            Assert.That(v, Is.TypeOf(typeof(PrimitiveValue)));
            var pv = (PrimitiveValue)v;

            Assert.AreEqual(pv.BaseTypeToken, DTokens.Bool, "Type of 'is(" + IsExpressionCode + ")' result must be bool");
            return(pv.Value == 1M);
        }
예제 #8
0
        public static ISymbolValue TryEvalPropertyValue(AbstractSymbolValueProvider vp, ISemantic baseSymbol, int propName)
        {
            var props = Properties[PropOwnerType.Generic];
            StaticPropertyInfo prop;

            if (props.TryGetValue(propName, out prop) || (Properties.TryGetValue(GetOwnerType(baseSymbol), out props) && props.TryGetValue(propName, out prop)))
            {
                if (prop.ValueGetter != null)
                {
                    return(prop.ValueGetter(vp, baseSymbol));
                }
            }

            return(null);
        }
예제 #9
0
        public static void TestBool(string literal, bool v = true, AbstractSymbolValueProvider vp = null)
        {
            var pv = GetPrimitiveValue(literal, vp);

            Assert.AreEqual(DTokens.Bool, pv.BaseTypeToken);

            if (v)
            {
                Assert.AreEqual(1M, pv.Value, literal + " must be true");
            }
            else
            {
                Assert.AreEqual(0M, pv.Value, literal + " must be false");
            }
        }
예제 #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dm"></param>
        /// <param name="args"></param>
        /// <param name="baseValueProvider">Required for evaluating missing default parameters.</param>
        public static bool AssignCallArgumentsToIC(DMethod dm, ISymbolValue[] args, AbstractSymbolValueProvider baseValueProvider,
                                                   out Dictionary <DVariable, ISymbolValue> targetArgs)
        {
            targetArgs = new Dictionary <DVariable, ISymbolValue>();
            var argsRemaining = args != null ? args.Length : 0;
            int argu          = 0;

            for (int para = 0; para < dm.Parameters.Count; para++)
            {
                var par = dm.Parameters[para] as DVariable;

                if (par.Type is VarArgDecl && argsRemaining > 0)
                {
                    var va_args = new ISemantic[argsRemaining];
                    args.CopyTo(va_args, argu);
                    argsRemaining = 0;
                    //TODO: Assign a value tuple to par
                    if (++para < dm.Parameters.Count)
                    {
                        return(false);
                    }
                }

                if (argsRemaining > 0)
                {
                    targetArgs[par] = args[argu++];
                    argsRemaining--;
                }
                else if (par.Initializer != null)
                {
                    targetArgs[par] = Evaluation.EvaluateValue(par.Initializer, baseValueProvider);
                }
                else
                {
                    return(false);
                }
            }

            return(argsRemaining == 0);
        }
예제 #11
0
        public static ISymbolValue Execute(MemberSymbol method, Dictionary <DVariable, ISymbolValue> arguments, AbstractSymbolValueProvider vp)
        {
            if (vp.ResolutionContext.CancelOperation)
            {
                return(null);
            }

            var dm = method.Definition as DMethod;

            if (dm == null || dm.BlockStartLocation.IsEmpty)
            {
                return(new ErrorValue(new EvaluationException("Method either not declared or undefined", method)));
            }
            var          eval = new FunctionEvaluation(method, vp, arguments);
            ISymbolValue ret;

            using (vp.ResolutionContext.Push(method, dm.BlockStartLocation))
            {
                try
                {
                    dm.Body.Accept(eval);
                }
                catch (CtfeException ex)
                {
                    vp.LogError(dm, "Can't execute function at precompile time: " + ex.Message);
                }

                ret = Evaluation.GetVariableContents(eval.returnedValue, eval.vp);
            }

            return(ret);

            //return new ErrorValue(new EvaluationException("CTFE is not implemented yet."));
        }
예제 #12
0
 public static ISymbolValue Execute(DMethod method, ISymbolValue[] arguments, AbstractSymbolValueProvider vp)
 {
     throw new NotImplementedException("CTFE is not implemented yet.");
 }
예제 #13
0
 public static ISymbolValue Execute(MemberSymbol method, ISymbolValue[] arguments, AbstractSymbolValueProvider vp)
 {
     return(new ErrorValue(new EvaluationException("CTFE пока ещё не реализован.")));
 }
예제 #14
0
        public static ISymbolValue Execute(MemberSymbol method, Dictionary <DVariable, ISymbolValue> arguments, AbstractSymbolValueProvider vp)
        {
            var dm   = method.Definition as DMethod;
            var eval = new FunctionEvaluation(method, vp, arguments);

            var ctxt = vp.ResolutionContext;

            ctxt.PushNewScope(dm, dm.Body);

            try
            {
                dm.Body.Accept(eval);
            }
            catch (CtfeException ex)
            {
                vp.LogError(dm, "Can't execute function at precompile time: " + ex.Message);
            }

            var ret = Evaluation.GetVariableContents(eval.returnedValue, eval.vp);

            ctxt.Pop();

            return(ret);

            //return new ErrorValue(new EvaluationException("CTFE is not implemented yet."));
        }
예제 #15
0
 public static ISymbolValue E(string expression, AbstractSymbolValueProvider vp = null)
 {
     return(Evaluation.EvaluateValue(DParser.ParseExpression(expression), vp ?? GetDefaultSymbolVP()));
 }