Пример #1
0
        public override ISymbolValue this[DVariable n]
        {
            get
            {
                if (n == null)
                {
                    return(new ErrorValue(new EvaluationException("There must be a valid variable node given in order to retrieve its value")));
                }

                if (n.IsConst)
                {
                    if (varsBeingResolved.Contains(n))
                    {
                        return(new ErrorValue(new EvaluationException("Cannot reference itself")));
                    }
                    varsBeingResolved.Add(n);
                    // .. resolve it's pre-compile time value and make the returned value the given argument
                    ISymbolValue val;
                    try{
                        val = Evaluation.EvaluateValue(n.Initializer, this);
                    }
                    finally{
                        varsBeingResolved.Remove(n);
                    }

                    // If it's null, then the initializer is null - which is equal to e.g. 0 or null !;

                    if (val != null)
                    {
                        return(val);
                    }
                }

                return(new ErrorValue(new EvaluationException(n + " must have a constant initializer")));
            }
            set
            {
                throw new NotImplementedException();
            }
        }
Пример #2
0
        /// <summary>
        /// Since most expressions should return a single type only, it's not needed to use this function unless you might
        /// want to pay attention on (illegal) multiple overloads.
        /// </summary>
        public static AbstractType[] EvaluateTypes(IExpression x, ResolutionContext ctxt)
        {
            var       ev = new Evaluation(ctxt);
            ISemantic t  = null;

            if (!Debugger.IsAttached)
            {
                try { t = ev.E(x); }
                catch { }
            }
            else
            {
                t = ev.E(x);
            }

            if (t is InternalOverloadValue)
            {
                return(((InternalOverloadValue)t).Overloads);
            }

            return(t == null ? null : new[] { AbstractType.Get(t) });
        }
Пример #3
0
		public static ISymbolValue EvaluateValue(IExpression x, AbstractSymbolValueProvider vp)
		{
			if (vp == null)
				vp = new StandardValueProvider(null);

			var ev = new Evaluation(vp);

			var v = ev.E(x) as ISymbolValue;

			if(v == null && ev.Errors.Count != 0)
				return new ErrorValue(ev.Errors.ToArray());

			return v;
		}
Пример #4
0
		public static AbstractType EvaluateType(IExpression x, ResolutionContext ctxt)
		{
			var ev = new Evaluation(ctxt);
			ISemantic t = null;
			if(!Debugger.IsAttached)
				try { t = ev.E(x); }
				catch { }
			else
				t = ev.E(x);

			return AbstractType.Get(t);
		}
Пример #5
0
		/// <summary>
		/// Since most expressions should return a single type only, it's not needed to use this function unless you might
		/// want to pay attention on (illegal) multiple overloads.
		/// </summary>
		public static AbstractType[] EvaluateTypes(IExpression x, ResolutionContext ctxt)
		{
			var ev = new Evaluation(ctxt);
			ISemantic t = null;
			if(!Debugger.IsAttached)
				try { t = ev.E(x); }
				catch { }
			else
				t = ev.E(x);

			if (t is InternalOverloadValue)
				return ((InternalOverloadValue)t).Overloads;

			return t == null ? null : new[]{ AbstractType.Get(t) };
		}
Пример #6
0
        public static AbstractType[] GetUnfilteredMethodOverloads(IExpression foreExpression, ResolutionContext ctxt, IExpression supExpression = null)
        {
            AbstractType[] overloads = null;

            if (foreExpression is TemplateInstanceExpression)
            {
                overloads = Evaluation.GetOverloads(foreExpression as TemplateInstanceExpression, ctxt, null);
            }
            else if (foreExpression is IdentifierExpression)
            {
                overloads = Evaluation.GetOverloads(foreExpression as IdentifierExpression, ctxt, false);
            }
            else if (foreExpression is PostfixExpression_Access)
            {
                overloads = Evaluation.GetAccessedOverloads((PostfixExpression_Access)foreExpression, ctxt, null, false);
            }
            else if (foreExpression is TokenExpression)
            {
                overloads = GetResolvedConstructorOverloads((TokenExpression)foreExpression, ctxt);
            }
            else
            {
                overloads = new[] { Evaluation.EvaluateType(foreExpression, ctxt) }
            };

            var  l          = new List <AbstractType>();
            bool staticOnly = true;

            foreach (var ov in DResolver.StripAliasSymbols(overloads))
            {
                var t = ov;
                if (ov is MemberSymbol)
                {
                    var ms = ov as MemberSymbol;
                    if (ms.Definition is Dom.DMethod)
                    {
                        l.Add(ms);
                        continue;
                    }

                    staticOnly = false;
                    t          = DResolver.StripAliasSymbol(ms.Base);
                }

                if (t is TemplateIntermediateType)
                {
                    var tit = t as TemplateIntermediateType;

                    var m = TypeDeclarationResolver.HandleNodeMatches(
                        GetOpCalls(tit, staticOnly), ctxt,
                        null, supExpression ?? foreExpression);

                    /*
                     * On structs, there must be a default () constructor all the time.
                     * If there are (other) constructors in structs, the explicit member initializer constructor is not
                     * provided anymore. This will be handled in the GetConstructors() method.
                     * If there are opCall overloads, canCreateeExplicitStructCtor overrides the ctor existence check in GetConstructors()
                     * and enforces that the explicit ctor will not be generated.
                     * An opCall overload with no parameters supersedes the default ctor.
                     */
                    var canCreateExplicitStructCtor = m == null || m.Length == 0;

                    if (!canCreateExplicitStructCtor)
                    {
                        l.AddRange(m);
                    }

                    m = TypeDeclarationResolver.HandleNodeMatches(
                        GetConstructors(tit, canCreateExplicitStructCtor), ctxt,
                        null, supExpression ?? foreExpression);

                    if (m != null && m.Length != 0)
                    {
                        l.AddRange(m);
                    }
                }
                else
                {
                    l.Add(ov);
                }
            }

            return(l.ToArray());
        }