Exemplo n.º 1
0
        public static AbstractType Demangle(string mangledString, out ITypeDeclaration qualifier, out bool isCFunction)
        {
            if (string.IsNullOrEmpty(mangledString))
            {
                throw new ArgumentException("input string must not be null or empty!");
            }

            if (!mangledString.StartsWith("_D"))
            {
                isCFunction = true;

                if (mangledString.StartsWith("__D"))
                {
                    mangledString = mangledString.Substring(1);
                }
                // C Functions
                else if (mangledString.StartsWith("_"))
                {
                    qualifier = new IdentifierDeclaration(mangledString.Substring(1));
                    return(null);
                }
            }

            //TODO: What about C functions that start with 'D'?
            isCFunction = false;

            var dmng = new Demangler(mangledString);

            return(dmng.MangledName(out qualifier));
        }
        bool HandleDecl(TemplateTypeParameter p, IdentifierDeclaration id, ISemantic r)
        {
            // Bottom-level reached
            if (id.InnerDeclaration == null && Contains(id.IdHash) && !id.ModuleScoped)
            {
                // Associate template param with r
                return(Set((p != null && id.IdHash == p.NameHash) ? p : null, r, id.IdHash));
            }

            var deducee = DResolver.StripMemberSymbols(AbstractType.Get(r)) as DSymbol;

            if (id.InnerDeclaration != null && deducee != null && deducee.Definition.NameHash == id.IdHash)
            {
                var physicalParentType = TypeDeclarationResolver.HandleNodeMatch(deducee.Definition.Parent, ctxt, null, id.InnerDeclaration);
                if (HandleDecl(p, id.InnerDeclaration, physicalParentType))
                {
                    if (Contains(id.IdHash))
                    {
                        Set((p != null && id.IdHash == p.NameHash) ? p : null, deducee, id.IdHash);
                    }
                    return(true);
                }
            }

            /*
             * If not stand-alone identifier or is not required as template param, resolve the id and compare it against r
             */
            var _r = TypeDeclarationResolver.ResolveSingle(id, ctxt);

            return(_r != null && (EnforceTypeEqualityWhenDeducing ?
                                  ResultComparer.IsEqual(r, _r) :
                                  ResultComparer.IsImplicitlyConvertible(r, _r)));
        }
		bool HandleDecl(TemplateTypeParameter p, IdentifierDeclaration id, ISemantic r)
		{
			// Bottom-level reached
			if (id.InnerDeclaration == null && Contains(id.IdHash) && !id.ModuleScoped)
			{
				// Associate template param with r
				return Set((p != null && id.IdHash == p.NameHash) ? p : null, r, id.IdHash);
			}

			var deducee = DResolver.StripMemberSymbols(AbstractType.Get(r)) as DSymbol;
			if (id.InnerDeclaration != null && deducee != null && deducee.Definition.NameHash == id.IdHash)
			{
				var physicalParentType = TypeDeclarationResolver.HandleNodeMatch(deducee.Definition.Parent, ctxt, null, id.InnerDeclaration);
				if (HandleDecl(p, id.InnerDeclaration, physicalParentType))
				{
					if (Contains(id.IdHash))
						Set((p != null && id.IdHash == p.NameHash) ? p : null, deducee, id.IdHash);
					return true;
				}
			}

			/*
			 * If not stand-alone identifier or is not required as template param, resolve the id and compare it against r
			 */
			var _r = TypeDeclarationResolver.Resolve(id, ctxt);

			ctxt.CheckForSingleResult(_r, id);

			return _r != null && _r.Length != 0 && 
				(EnforceTypeEqualityWhenDeducing ?
				ResultComparer.IsEqual(r,_r[0]) :
				ResultComparer.IsImplicitlyConvertible(r,_r[0]));
		}
Exemplo n.º 4
0
        /// <summary>
        /// See <see cref="Resolve"/>
        /// </summary>
        public static AbstractType ResolveSingle(IdentifierDeclaration id, ResolutionContext ctxt, AbstractType[] resultBases = null, bool filterForTemplateArgs = true)
        {
            var r = Resolve(id, ctxt, resultBases, filterForTemplateArgs);

            ctxt.CheckForSingleResult(r, id);

            return(r != null && r.Length != 0 ? r[0] : null);
        }
Exemplo n.º 5
0
        public static AbstractType getStringType(ResolverContextStack ctxt)
        {
            var str   = new IdentifierDeclaration("string");
            var sType = TypeDeclarationResolver.Resolve(str, ctxt);

            ctxt.CheckForSingleResult(sType, str);

            return(sType != null && sType.Length != 0 ? sType[0] : null);
        }
Exemplo n.º 6
0
        ITypeDeclaration QualifiedName()
        {
            ITypeDeclaration td = null;
            int n;

            while (PeekIsDecNumber)
            {
                // Read number of either the first LName or TemplateInstanceName
                n = (int)Number();
                sb.Clear();
                if ((char)r.Peek() == '_')
                {
                    r.Read();
                    sb.Append('_');
                    if ((char)r.Peek() == '_')
                    {
                        r.Read();
                        sb.Append('_');
                        if ((char)r.Peek() == 'T')
                        {
                            r.Read();
                            // We've got to handle a Template instance:
                            // Number __T LName TemplateArgs Z
                            var tpi = new TemplateInstanceExpression(new IdentifierDeclaration(LName()));

                            tpi.InnerDeclaration = td;
                            td = tpi;

                            var xx = new List <IExpression>();
                            while (r.Peek() != -1)
                            {
                                var arg = TemplateArg();
                                if (arg == null)
                                {
                                    break;
                                }
                                xx.Add(arg);
                            }
                            tpi.Arguments = xx.ToArray();
                            continue;
                        }
                    }
                }

                // Just an LName
                if (n > sb.Length)
                {
                    sb.Append(LName(n - sb.Length));
                }

                var ttd = new IdentifierDeclaration(sb.ToString());
                ttd.InnerDeclaration = td;
                td = ttd;
            }

            return(td);
        }
Exemplo n.º 7
0
        public override void Visit(IdentifierDeclaration td)
        {
            if (DoPrimaryIdCheck(td.IdHash))
            {
                AddResult(td);
            }

            base.Visit(td);
        }
Exemplo n.º 8
0
 public override void Visit(IdentifierDeclaration x)
 {
     if (x.Location <= caret && x.EndLocation >= caret)
     {
         IdNearCaret = x;
     }
     else
     {
         base.Visit(x);
     }
 }
Exemplo n.º 9
0
        public override void Visit(IdentifierDeclaration td)
        {
            byte type;

            if (DoPrimaryIdCheck(td.IdHash, out type))
            {
                AddResult(td, type);
            }

            base.Visit(td);
        }
Exemplo n.º 10
0
        private static void EmitDeclarationStatement(IdentifierDeclaration declaration, ILGenerator methodIL)
        {
            foreach (IdentifierExpression identifier in declaration.DeclaringIdentifiers)
            {
                EmitIdentifierExpression(identifier, methodIL);
            }

            if (declaration.AssingningExpression != null)
            {
                EmitAssignmentStatement(declaration.AssingningExpression, methodIL);
            }
        }
Exemplo n.º 11
0
        public override void Visit(IdentifierDeclaration id)
        {
            if (id.IdHash == searchHash || resolveAnyway)
            {
                ctxt.CurrentContext.Set(id.Location);
                if (TryAdd(TypeDeclarationResolver.ResolveSingle(id, ctxt), id))
                {
                    return;
                }
            }

            base.Visit(id);
        }
Exemplo n.º 12
0
 public static void ResolveDeclarationStatement(IdentifierDeclaration declaration, Table.Table table)
 {
     if (declaration.AssingningExpression != null)
     {
         ResolveAssignmentStatement(declaration.AssingningExpression, table);
     }
     else
     {
         foreach (IdentifierExpression identifier in declaration.DeclaringIdentifiers)
         {
             ResolveIdentifierExpression(identifier, table, null);
         }
     }
 }
Exemplo n.º 13
0
 public override void Visit(IdentifierDeclaration td)
 {
     if (td.IdHash == DTokens.IncompleteIdHash)
     {
         halt = true;
         if (td.InnerDeclaration != null)
         {
             prv = new MemberCompletionProvider(cdgen, td.InnerDeclaration, scopedBlock);
         }
     }
     else
     {
         base.Visit(td);
     }
 }
Exemplo n.º 14
0
        ITypeDeclaration VisitDSymbol(DSymbol t)
        {
            var def             = t.Definition;
            ITypeDeclaration td = new IdentifierDeclaration(def != null ? def.NameHash : 0);

            if (def != null && t.DeducedTypes != null && def.TemplateParameters != null)
            {
                var args = new List <IExpression>();
                foreach (var tp in def.TemplateParameters)
                {
                    IExpression argEx = null;
                    foreach (var tps in t.DeducedTypes)
                    {
                        if (tps != null && tps.Parameter == tp)
                        {
                            if (tps.ParameterValue != null)
                            {
                                //TODO: Convert ISymbolValues back to IExpression
                            }
                            else
                            {
                                argEx = new TypeDeclarationExpression(AcceptType(tps));
                            }
                            break;
                        }
                    }

                    args.Add(argEx ?? new IdentifierExpression(tp.NameHash));
                }

                td = new TemplateInstanceExpression(td)
                {
                    Arguments = args.ToArray()
                };
            }

            var ret = td;

            while (def != null && def != (def = def.Parent as DNode) &&
                   def != null && !(def is DModule))
            {
                td = td.InnerDeclaration = new IdentifierDeclaration(def.NameHash);
            }

            return(ret);
        }
Exemplo n.º 15
0
        public override void Visit(IdentifierDeclaration id)
        {
            var resolvedSymbol = TryPopPFAStack();

            if (id.IdHash == searchHash)
            {
                if (resolvedSymbol == null)
                {
                    resolvedSymbol = TypeDeclarationResolver.ResolveSingle(id, ctxt) as DSymbol;
                }

                if (resolvedSymbol != null && resolvedSymbol.Definition == symbol)
                {
                    l.Add(id);
                    return;
                }
            }
            base.Visit(id);
        }
Exemplo n.º 16
0
        bool HandleDecl(TemplateTypeParameter p, IdentifierDeclaration id, ISemantic r)
        {
            // Bottom-level reached
            if (id.InnerDeclaration == null && Contains(id.Id) && !id.ModuleScoped)
            {
                // Associate template param with r
                return(Set(p, r, id.Id));
            }

            /*
             * If not stand-alone identifier or is not required as template param, resolve the id and compare it against r
             */
            var _r = TypeDeclarationResolver.Resolve(id, ctxt);

            ctxt.CheckForSingleResult(_r, id);

            return(_r != null && _r.Length != 0 &&
                   (EnforceTypeEqualityWhenDeducing ?
                    ResultComparer.IsEqual(r, _r[0]) :
                    ResultComparer.IsImplicitlyConvertible(r, _r[0])));
        }
Exemplo n.º 17
0
        public static AbstractType[] Resolve(IdentifierDeclaration id, ResolutionContext ctxt, AbstractType[] resultBases = null, bool filterForTemplateArgs = true)
        {
            AbstractType[] res;

            if (id.InnerDeclaration == null && resultBases == null)
            {
                res = ResolveIdentifier(id.IdHash, ctxt, id, id.ModuleScoped);
            }
            else
            {
                var rbases = resultBases ?? Resolve(id.InnerDeclaration, ctxt);

                if (rbases == null || rbases.Length == 0)
                {
                    return(null);
                }

                res = ResolveFurtherTypeIdentifier(id.IdHash, rbases, ctxt, id);
            }

            if (filterForTemplateArgs && (ctxt.Options & ResolutionOptions.NoTemplateParameterDeduction) == 0)
            {
                var l_ = new List <AbstractType>();

                if (res != null)
                {
                    foreach (var s in res)
                    {
                        l_.Add(s);
                    }
                }

                return(TemplateInstanceHandler.DeduceParamsAndFilterOverloads(l_, null, false, ctxt));
            }
            else
            {
                return(res);
            }
        }
        /// <summary>
        /// Returns all constructors from the given class or struct.
        /// If no explicit constructor given, an artificial implicit constructor method stub will be created.
        /// </summary>
        public static IEnumerable <DMethod> GetConstructors(TemplateIntermediateType ct)
        {
            bool foundExplicitCtor = false;

            // Simply get all constructors that have the ctor id assigned. Makin' it faster ;)
            var ch = ct.Definition[DMethod.ConstructorIdentifier];

            if (ch != null)
            {
                foreach (var m in ch)
                {
                    // Not to forget: 'this' aliases are also possible - so keep checking for m being a genuine ctor
                    var dm = m as DMethod;
                    if (m != null && dm.SpecialType == DMethod.MethodType.Constructor)
                    {
                        yield return(dm);

                        foundExplicitCtor = true;
                    }
                }
            }

            if (!foundExplicitCtor)
            {
                yield return new DMethod(DMethod.MethodType.Constructor)
                       {
                           Name = DMethod.ConstructorIdentifier, Parent = ct.Definition, Description = "Default constructor for " + ct.Name
                       }
            }
            ;
        }

        ISemantic E(CastExpression ce)
        {
            AbstractType castedType = null;

            if (ce.Type != null)
            {
                var castedTypes = TypeDeclarationResolver.Resolve(ce.Type, ctxt);

                ctxt.CheckForSingleResult(castedTypes, ce.Type);

                if (castedTypes != null && castedTypes.Length != 0)
                {
                    castedType = castedTypes[0];
                }
            }
            else
            {
                castedType = AbstractType.Get(E(ce.UnaryExpression));

                if (castedType != null && ce.CastParamTokens != null && ce.CastParamTokens.Length > 0)
                {
                    //TODO: Wrap resolved type with member function attributes
                }
            }

            return(castedType);
        }

        ISemantic E(UnaryExpression_Cat x)         // a = ~b;
        {
            return(E(x.UnaryExpression));
        }

        ISemantic E(UnaryExpression_Increment x)
        {
            return(E(x.UnaryExpression));
        }

        ISemantic E(UnaryExpression_Decrement x)
        {
            return(E(x.UnaryExpression));
        }

        ISemantic E(UnaryExpression_Add x)
        {
            return(E(x.UnaryExpression));
        }

        ISemantic E(UnaryExpression_Sub x)
        {
            var v = E(x.UnaryExpression);

            if (eval)
            {
                if (v is AbstractType)
                {
                    v = DResolver.StripMemberSymbols((AbstractType)v);
                }

                if (v is PrimitiveValue)
                {
                    var pv = (PrimitiveValue)v;

                    return(new PrimitiveValue(pv.BaseTypeToken, -pv.Value, x, -pv.ImaginaryPart));
                }
            }

            return(v);
        }

        ISemantic E(UnaryExpression_Not x)
        {
            return(E(x.UnaryExpression));
        }

        ISemantic E(UnaryExpression_Mul x)
        {
            return(E(x.UnaryExpression));
        }

        ISemantic E(UnaryExpression_And x)
        {
            var ptrBase = E(x.UnaryExpression);

            if (eval)
            {
                // Create a new pointer
                //
            }

            // &i -- makes an int* out of an int
            return(new PointerType(AbstractType.Get(ptrBase), x));
        }

        ISemantic E(DeleteExpression x)
        {
            if (eval)
            {
                // Reset the content of the variable
            }

            return(null);
        }

        ISemantic E(UnaryExpression_Type x)
        {
            var uat = x as UnaryExpression_Type;

            if (uat.Type == null)
            {
                return(null);
            }

            var types = TypeDeclarationResolver.Resolve(uat.Type, ctxt);

            ctxt.CheckForSingleResult(types, uat.Type);

            if (types != null && types.Length != 0)
            {
                var id = new IdentifierDeclaration(uat.AccessIdentifier)
                {
                    EndLocation = uat.EndLocation
                };

                // First off, try to resolve static properties
                var statProp = StaticPropertyResolver.TryResolveStaticProperties(types[0], uat.AccessIdentifier, ctxt, eval, id);

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

                // If it's not the case, try the conservative way
                var res = TypeDeclarationResolver.Resolve(id, ctxt, types);

                ctxt.CheckForSingleResult(res, x);

                if (res != null && res.Length != 0)
                {
                    return(res[0]);
                }
            }

            return(null);
        }
    }
Exemplo n.º 19
0
        public static AbstractType ResolveKey(ArrayDecl ad, out int fixedArrayLength, out ISymbolValue keyVal, ResolutionContext ctxt)
        {
            keyVal           = null;
            fixedArrayLength = -1;
            AbstractType keyType = null;

            if (ad.KeyExpression != null)
            {
                //TODO: Template instance expressions?
                var id_x = ad.KeyExpression as IdentifierExpression;
                if (id_x != null && id_x.IsIdentifier)
                {
                    var id = new IdentifierDeclaration((string)id_x.Value)
                    {
                        Location    = id_x.Location,
                        EndLocation = id_x.EndLocation
                    };

                    keyType = TypeDeclarationResolver.ResolveSingle(id, ctxt);

                    if (keyType != null)
                    {
                        var tt = DResolver.StripAliasSymbol(keyType) as MemberSymbol;

                        if (tt == null ||
                            !(tt.Definition is DVariable) ||
                            ((DVariable)tt.Definition).Initializer == null)
                        {
                            return(keyType);
                        }
                    }
                }

                try
                {
                    keyVal = Evaluation.EvaluateValue(ad.KeyExpression, ctxt);

                    if (keyVal != null)
                    {
                        // Take the value's type as array key type
                        keyType = keyVal.RepresentedType;

                        // It should be mostly a number only that points out how large the final array should be
                        var pv = Evaluation.GetVariableContents(keyVal, new StandardValueProvider(ctxt)) as PrimitiveValue;
                        if (pv != null)
                        {
                            fixedArrayLength = System.Convert.ToInt32(pv.Value);

                            if (fixedArrayLength < 0)
                            {
                                ctxt.LogError(ad, "Invalid array size: Length value must be greater than 0");
                            }
                        }
                        //TODO Is there any other type of value allowed?
                    }
                }
                catch { }
            }
            else
            {
                var t = Resolve(ad.KeyType, ctxt);
                ctxt.CheckForSingleResult(t, ad.KeyType);

                if (t != null && t.Length != 0)
                {
                    return(t[0]);
                }
            }

            return(keyType);
        }
Exemplo n.º 20
0
 public ulong Visit(IdentifierDeclaration identifierDeclaration)
 {
     return(1001531);
 }
Exemplo n.º 21
0
        static ResolveResult[] HandleIdDeclaration(IdentifierDeclaration typeId,
                                                   ResolverContext lastResCtxt,
                                                   IAbstractSyntaxTree SyntaxTree,
                                                   CodeScanResult csr,
                                                   Dictionary <string, ResolveResult> compDict)
        {
            var typeString = typeId.ToString();

            bool WasAlreadyResolved = false;

            ResolveResult[] allCurrentResults = null;
            ResolveResult   rr = null;

            /*
             * string,wstring,dstring are highlighted by the editor's syntax definition automatically..
             * Anyway, allow to resolve e.g. "object.string"
             */
            if (typeString == "" || typeString == "string" || typeString == "wstring" || typeString == "dstring")
            {
                return(null);
            }

            lastResCtxt.ScopedBlock = DResolver.SearchBlockAt(SyntaxTree, typeId.Location, out lastResCtxt.ScopedStatement);
            if (typeString == "th" && typeId.Location.Line == 114)
            {
            }
            if (!(WasAlreadyResolved = compDict.TryGetValue(typeString, out rr)))
            {
                allCurrentResults = DResolver.ResolveType(typeId, lastResCtxt);

                if (allCurrentResults != null && allCurrentResults.Length > 0)
                {
                    rr = allCurrentResults[0];
                }
            }

            if (rr == null)
            {
                if (typeId is IdentifierDeclaration)
                {
                    csr.UnresolvedIdentifiers.Add(typeId as IdentifierDeclaration);
                }
            }
            else
            {
                /*
                 * Note: It is of course possible to highlight more than one type in one type declaration!
                 * So, we scan down the result hierarchy for TypeResults and highlight all of them later.
                 */
                var curRes = rr;

                /*
                 * Note: Since we want to use results multiple times,
                 * we at least have to 'update' their type declarations
                 * to ensure that the second, third, fourth etc. occurence of this result
                 * are also highlit (and won't(!) cause an Already-Added-Exception of our finalDict-Array)
                 */
                var curTypeDeclBase = typeId as ITypeDeclaration;

                while (curRes != null)
                {
                    if (curRes is MemberResult)
                    {
                        var mr = curRes as MemberResult;

                        // If curRes is an alias or a template parameter, highlight it
                        if (mr.ResolvedMember is TemplateParameterNode ||
                            (mr.ResolvedMember is DVariable &&
                             (mr.ResolvedMember as DVariable).IsAlias))
                        {
                            try
                            {
                                csr.ResolvedIdentifiers.Add(curTypeDeclBase as IdentifierDeclaration, curRes);
                            }
                            catch { }

                            // See performance reasons
                            //if (curRes != rr && !WasAlreadyResolved && !) compDict.Add(curTypeDeclBase.ToString(), curRes);
                        }
                    }

                    else if (curRes is TypeResult)
                    {
                        // Yeah, in quite all cases we do identify a class via its name ;-)
                        if (curTypeDeclBase is IdentifierDeclaration &&
                            !(curTypeDeclBase is DTokenDeclaration) &&
                            !csr.ResolvedIdentifiers.ContainsKey(curTypeDeclBase as IdentifierDeclaration))
                        {
                            csr.ResolvedIdentifiers.Add(curTypeDeclBase as IdentifierDeclaration, curRes);

                            // See performance reasons
                            //if (curRes != rr && !WasAlreadyResolved) compDict.Add(curTypeDeclBase.ToString(), curRes);
                        }
                    }

                    else if (curRes is ModuleResult)
                    {
                        if (curTypeDeclBase is IdentifierDeclaration &&
                            !csr.ResolvedIdentifiers.ContainsKey(curTypeDeclBase as IdentifierDeclaration))
                        {
                            csr.ResolvedIdentifiers.Add(curTypeDeclBase as IdentifierDeclaration, curRes);
                        }
                    }

                    curRes          = curRes.ResultBase;
                    curTypeDeclBase = curTypeDeclBase.InnerDeclaration;
                }
            }
            return(allCurrentResults);
        }
		public static AbstractType[] Resolve(IdentifierDeclaration id, ResolutionContext ctxt, AbstractType[] resultBases = null, bool filterForTemplateArgs = true)
		{
			AbstractType[] res;

			if (id.InnerDeclaration == null && resultBases == null)
				res = ResolveIdentifier(id.IdHash, ctxt, id, id.ModuleScoped);
			else
			{
				var rbases = resultBases ?? Resolve(id.InnerDeclaration, ctxt);

				if (rbases == null || rbases.Length == 0)
					return null;

				res = ResolveFurtherTypeIdentifier(id.IdHash, rbases, ctxt, id);
			}

			if (filterForTemplateArgs && (ctxt.Options & ResolutionOptions.NoTemplateParameterDeduction) == 0)
			{
				var l_ = new List<AbstractType>();

				if (res != null)
					foreach (var s in res)
						l_.Add(s);

				return TemplateInstanceHandler.DeduceParamsAndFilterOverloads(l_, null, false, ctxt);
			}
			else
				return res;
		}
		public virtual void Visit(IdentifierDeclaration td)
		{
			VisitInner(td);
		}
Exemplo n.º 24
0
        /// <summary>
        /// Tries to resolve a static property's name.
        /// Returns a result describing the theoretical member (".init"-%gt;MemberResult; ".typeof"-&gt;TypeResult etc).
        /// Returns null if nothing was found.
        /// </summary>
        /// <param name="InitialResult"></param>
        /// <returns></returns>
        public static MemberSymbol TryResolveStaticProperties(
            ISemantic InitialResult,
            string propertyIdentifier,
            ResolverContextStack ctxt          = null,
            bool Evaluate                      = false,
            IdentifierDeclaration idContainter = null)
        {
            // If a pointer'ed type is given, take its base type
            if (InitialResult is PointerType)
            {
                InitialResult = ((PointerType)InitialResult).Base;
            }

            if (InitialResult == null || InitialResult is ModuleSymbol)
            {
                return(null);
            }

            INode relatedNode = null;

            if (InitialResult is DSymbol)
            {
                relatedNode = ((DSymbol)InitialResult).Definition;
            }

            #region init
            if (propertyIdentifier == "init")
            {
                var prop_Init = new DVariable
                {
                    Name        = "init",
                    Description = "Initializer"
                };

                if (relatedNode != null)
                {
                    if (!(relatedNode is DVariable))
                    {
                        prop_Init.Parent = relatedNode.Parent;
                        prop_Init.Type   = new IdentifierDeclaration(relatedNode.Name);
                    }
                    else
                    {
                        prop_Init.Parent      = relatedNode;
                        prop_Init.Initializer = (relatedNode as DVariable).Initializer;
                        prop_Init.Type        = relatedNode.Type;
                    }
                }

                return(new MemberSymbol(prop_Init, DResolver.StripAliasSymbol(AbstractType.Get(InitialResult)), idContainter));
            }
            #endregion

            #region sizeof
            if (propertyIdentifier == "sizeof")
            {
                return(new MemberSymbol(new DVariable
                {
                    Name = "sizeof",
                    Type = new DTokenDeclaration(DTokens.Int),
                    Initializer = new IdentifierExpression(4),
                    Description = "Size in bytes (equivalent to C's sizeof(type))"
                }, new PrimitiveType(DTokens.Int), idContainter));
            }
            #endregion

            #region alignof
            if (propertyIdentifier == "alignof")
            {
                return(new MemberSymbol(new DVariable
                {
                    Name = "alignof",
                    Type = new DTokenDeclaration(DTokens.Int),
                    Description = "Alignment size"
                }, new PrimitiveType(DTokens.Int), idContainter));
            }
            #endregion

            #region mangleof
            if (propertyIdentifier == "mangleof")
            {
                return(new MemberSymbol(new DVariable
                {
                    Name = "mangleof",
                    Type = new IdentifierDeclaration("string"),
                    Description = "String representing the ‘mangled’ representation of the type"
                }, getStringType(ctxt), idContainter));
            }
            #endregion

            #region stringof
            if (propertyIdentifier == "stringof")
            {
                return(new MemberSymbol(new DVariable
                {
                    Name = "stringof",
                    Type = new IdentifierDeclaration("string"),
                    Description = "String representing the source representation of the type"
                }, getStringType(ctxt), idContainter));
            }
            #endregion

            #region classinfo
            else if (propertyIdentifier == "classinfo")
            {
                var tr = DResolver.StripMemberSymbols(AbstractType.Get(InitialResult)) as TemplateIntermediateType;

                if (tr is ClassType || tr is InterfaceType)
                {
                    var ci = new IdentifierDeclaration("TypeInfo_Class")
                    {
                        InnerDeclaration        = new IdentifierDeclaration("object"),
                        ExpressesVariableAccess = true,
                    };

                    var ti = TypeDeclarationResolver.Resolve(ci, ctxt);

                    ctxt.CheckForSingleResult(ti, ci);

                    return(new MemberSymbol(new DVariable {
                        Name = "classinfo", Type = ci
                    }, ti != null && ti.Length != 0?ti[0]:null, idContainter));
                }
            }
            #endregion

            //TODO: Resolve the types of type-specific properties (floats, ints, arrays, assocarrays etc.)

            return(null);
        }
		public static AbstractType ResolveKey(ArrayDecl ad, out int fixedArrayLength, out ISymbolValue keyVal, ResolutionContext ctxt)
		{
			keyVal = null;
			fixedArrayLength = -1;
			AbstractType keyType = null;

			if (ad.KeyExpression != null)
			{
				//TODO: Template instance expressions?
				var id_x = ad.KeyExpression as IdentifierExpression;
				if (id_x != null && id_x.IsIdentifier)
				{
					var id = new IdentifierDeclaration((string)id_x.Value)
					{
						Location = id_x.Location,
						EndLocation = id_x.EndLocation
					};

					keyType = TypeDeclarationResolver.ResolveSingle(id, ctxt);

					if (keyType != null)
					{
						var tt = DResolver.StripAliasSymbol(keyType) as MemberSymbol;

						if (tt == null ||
							!(tt.Definition is DVariable) ||
							((DVariable)tt.Definition).Initializer == null)
							return keyType;
					}
				}

				try
				{
					keyVal = Evaluation.EvaluateValue(ad.KeyExpression, ctxt);

					if (keyVal != null)
					{
						// Take the value's type as array key type
						keyType = keyVal.RepresentedType;

						// It should be mostly a number only that points out how large the final array should be
						var pv = Evaluation.GetVariableContents(keyVal, new StandardValueProvider(ctxt)) as PrimitiveValue;
						if (pv != null)
						{
							fixedArrayLength = System.Convert.ToInt32(pv.Value);

							if (fixedArrayLength < 0)
								ctxt.LogError(ad, "Invalid array size: Length value must be greater than 0");
						}
						//TODO Is there any other type of value allowed?
					}
				}
				catch { }
			}
			else
			{
				var t = Resolve(ad.KeyType, ctxt);
				ctxt.CheckForSingleResult(t, ad.KeyType);

				if (t != null && t.Length != 0)
					return t[0];
			}

			return keyType;
		}
		/// <summary>
		/// See <see cref="Resolve"/>
		/// </summary>
		public static AbstractType ResolveSingle(IdentifierDeclaration id, ResolutionContext ctxt, AbstractType[] resultBases = null, bool filterForTemplateArgs = true)
		{
			var r = Resolve(id, ctxt, resultBases, filterForTemplateArgs);

			ctxt.CheckForSingleResult(r, id);

			return r != null && r.Length != 0 ? r[0] : null;
		}
Exemplo n.º 27
0
		public ITypeDeclaration IdentifierList()
		{
			ITypeDeclaration td = null;

			bool notInit = false;
			do
			{
				if (notInit)
					Step();
				else
					notInit = true;

				ITypeDeclaration ttd;

				if (IsTemplateInstance)
					ttd = TemplateInstance(null);
				else if (Expect(Identifier))
					ttd = new IdentifierDeclaration(t.Value) { Location = t.Location, EndLocation = t.EndLocation };
				else if (IsEOF)
				{
					TrackerVariables.ExpectingIdentifier = true;
					return td == null ? null : new DTokenDeclaration(DTokens.INVALID, td);
				}
				else 
					ttd = null;
				if (ttd != null)
					ttd.InnerDeclaration = td;
				td = ttd;
			}
			while (laKind == Dot);

			return td;
		}
Exemplo n.º 28
0
		public static AbstractType Demangle(string mangledString, out ITypeDeclaration qualifier, out bool isCFunction)
		{
			if(string.IsNullOrEmpty(mangledString))
				throw new ArgumentException("строка ввода должна не быть пустой или null!");
			
			if (!mangledString.StartsWith("_D"))
			{
				isCFunction = true;

				if (mangledString.StartsWith ("__D"))
					mangledString = mangledString.Substring (1);
				// C Functions
				else if (mangledString.StartsWith ("_")) {
					qualifier = new IdentifierDeclaration (mangledString.Substring (1));
					return null;
				}
			}

			//TODO: What about C functions that start with 'D'?
			isCFunction = false;
			
			var dmng = new Demangler(mangledString);
			
			return dmng.MangledName(out qualifier);
		}
Exemplo n.º 29
0
		public override void Visit (IdentifierDeclaration id)
		{
			var resolvedSymbol = TryPopPFAStack ();
			if (id.IdHash == searchHash) {
				if(resolvedSymbol == null)
					resolvedSymbol = TypeDeclarationResolver.ResolveSingle (id, ctxt) as DSymbol;

				if (resolvedSymbol != null && resolvedSymbol.Definition == symbol) {
					l.Add (id);
					return;
				}
			}
			base.Visit (id);
		}
Exemplo n.º 30
0
		public override void Visit (IdentifierDeclaration td)
		{
			if (DoPrimaryIdCheck(td.IdHash))
				AddResult(td);

			base.Visit (td);
		}
Exemplo n.º 31
0
		ITypeDeclaration ModuleFullyQualifiedName()
		{
			if (!Expect(Identifier))
				return null;

			var td = new IdentifierDeclaration(t.Value) { Location=t.Location,EndLocation=t.EndLocation };

			while (laKind == Dot)
			{
				Step();
				Expect(Identifier);
				td = new IdentifierDeclaration(t.Value) { Location=t.Location, EndLocation=t.EndLocation, InnerDeclaration = td };
			}

			return td;
		}
Exemplo n.º 32
0
		public TemplateInstanceExpression TemplateInstance(IBlockNode Scope)
		{
			var loc = la.Location;

			var mod = INVALID;

			if (DTokens.StorageClass [laKind]) {
				mod = laKind;
				Step ();
			}

			if (!Expect (Identifier))
				return null;

			ITypeDeclaration td = new IdentifierDeclaration (t.Value) { 
				Location = t.Location, 
				EndLocation = t.EndLocation
			};

			td = new TemplateInstanceExpression(mod != DTokens.INVALID ? new MemberFunctionAttributeDecl(mod) { InnerType = td } : td) {
				Location = loc
			};
			LastParsedObject = td;

			var args = new List<IExpression>();

			if (!Expect(Not))
				return td as TemplateInstanceExpression;

			if (laKind == (OpenParenthesis))
			{
				Step();

				if (laKind != CloseParenthesis)
				{
					bool init = true;
					while (laKind == Comma || init)
					{
						if (!init) Step();
						init = false;

						if (laKind == CloseParenthesis)
							break;

						if (IsEOF)
						{
							args.Add(new TokenExpression(DTokens.INVALID) { Location= la.Location, EndLocation=la.EndLocation });
							break;
						}
						
						Lexer.PushLookAheadBackup();

						bool wp = AllowWeakTypeParsing;
						AllowWeakTypeParsing = true;

						var typeArg = Type();

						AllowWeakTypeParsing = wp;

						if (typeArg != null && (laKind == CloseParenthesis || laKind==Comma)){
							Lexer.PopLookAheadBackup();
							args.Add(new TypeDeclarationExpression(typeArg));
						}else
						{
							Lexer.RestoreLookAheadBackup();
							args.Add(AssignExpression(Scope));
						}
					}
				}
				Expect(CloseParenthesis);
			}
			else
			{
				Step();

				/*
				 * TemplateSingleArgument: 
				 *		Identifier 
				 *		BasicTypeX 
				 *		CharacterLiteral 
				 *		StringLiteral 
				 *		IntegerLiteral 
				 *		FloatLiteral 
				 *		true 
				 *		false 
				 *		null 
				 *		__FILE__ 
				 *		__LINE__
				 */

				IExpression arg= null;

				if (t.Kind == Literal)
					arg = new IdentifierExpression(t.LiteralFormat == LiteralFormat.StringLiteral || 
					                               t.LiteralFormat == LiteralFormat.VerbatimStringLiteral ? 
					                               t.Value :
					                               t.LiteralValue,
					                               t.LiteralFormat, 
					                               t.Subformat)
					{
						Location = t.Location,
						EndLocation = t.EndLocation
					};
				else if (t.Kind == Identifier)
					arg = new IdentifierExpression(t.Value)
					{
						Location = t.Location,
						EndLocation = t.EndLocation
					};
				else if (BasicTypes[t.Kind])
					arg = new TypeDeclarationExpression(new DTokenDeclaration(t.Kind)
					{
						Location = t.Location,
						EndLocation = t.EndLocation
					});
				else if (
					t.Kind == True ||
					t.Kind == False ||
					t.Kind == Null ||
					t.Kind == __FILE__ ||
					t.Kind == __LINE__)
					arg = new TokenExpression(t.Kind)
					{
						Location = t.Location,
						EndLocation = t.EndLocation
					};
				else if (IsEOF)
				{
					TrackerVariables.ExpectingIdentifier = false;
					td.EndLocation = CodeLocation.Empty;
					return td as TemplateInstanceExpression;
				}

				args.Add(arg);
			}
			(td as TemplateInstanceExpression).Arguments = args.ToArray();
			td.EndLocation = t.EndLocation;
			return td as TemplateInstanceExpression;
		}
Exemplo n.º 33
0
		ImportStatement.ImportBindings ImportBindings(ImportStatement.Import imp)
		{
			var importBindings = new ImportStatement.ImportBindings { Module=imp };
			LastParsedObject = importBindings;

			bool init = true;
			while (laKind == Comma || init)
			{
				if (init)
					init = false;
				else
					Step();

				if (Expect(Identifier))
				{
					var symbolAlias = new IdentifierDeclaration(t.Value){ Location = t.Location, EndLocation = t.EndLocation };
						
					if (laKind == Assign)
					{
						Step();
						if (Expect (Identifier))
							importBindings.SelectedSymbols.Add (new ImportStatement.ImportBinding (new IdentifierDeclaration (t.Value) {
								Location = t.Location,
								EndLocation = t.EndLocation
							}, symbolAlias));
					}
					else
						importBindings.SelectedSymbols.Add(new ImportStatement.ImportBinding(symbolAlias));
				}
			}

			if (!IsEOF)
				LastParsedObject = null;

			return importBindings;
		}
Exemplo n.º 34
0
		ITypeDeclaration QualifiedName()
		{
			ITypeDeclaration td = null;
			int n;
			
			while(PeekIsDecNumber)
			{
				// Read number of either the first LName or TemplateInstanceName
				n = (int)Number();
				sb.Clear();
				if((char)r.Peek() == '_')
				{
					r.Read();
					sb.Append('_');
					if((char)r.Peek() == '_')
					{
						r.Read();
						sb.Append('_');
						if((char)r.Peek() == 'T')
						{
							r.Read();
							// We've got to handle a Template instance:
							// Number __T LName TemplateArgs Z
							var tpi = new TemplateInstanceExpression(new IdentifierDeclaration(LName()));

							tpi.InnerDeclaration = td;
							td = tpi;
							
							var xx = new List<IExpression>();
							while(r.Peek() != -1)
							{
								var arg = TemplateArg();
								if(arg == null)
									break;
								xx.Add(arg);
							}
							tpi.Arguments = xx.ToArray();
							continue;
						}
					}
				}
				
				// Just an LName
				if(n > sb.Length)
					sb.Append(LName(n-sb.Length));
				
				var ttd = new IdentifierDeclaration(sb.ToString());
				ttd.InnerDeclaration = td;
				td = ttd;
			}
			
			return td;
		}