Esempio n. 1
0
        public override AstNode Visit(TypedefDefinition node)
        {
            // Prevent redefinition.
            ScopeMember old = currentContainer.FindMember(node.GetName());

            if (old != null)
            {
                Error(node, "trying to redefine a typedef.");
            }

            // Create the type name.
            TypeNameMember typeName = new TypeNameMember(node.GetFlags(), node.GetName(), currentContainer);

            typeName.SetTypedefNode(node);
            node.SetTypeName(typeName);

            // Register the type name.
            if (currentContainer.IsNamespace())
            {
                Namespace space = (Namespace)currentContainer;
                space.AddMember(typeName);
            }
            else if (currentContainer.IsStructure() || currentContainer.IsClass())
            {
                Structure parent = (Structure)currentContainer;
                parent.AddTypeName(typeName);
            }
            else
            {
                Error(node, "unexpected place for a typedef.");
            }

            return(node);
        }
Esempio n. 2
0
        public static Namespace ParseNamespace(ParserContext context, TopLevelEntity parent, TokenStream tokens)
        {
            Token        namespaceToken = tokens.PopExpected("namespace");
            List <Token> nsNameParts    = new List <Token>();

            nsNameParts.Add(tokens.PopWord());
            while (tokens.IsNext("."))
            {
                tokens.PopExpected(".");
                nsNameParts.Add(tokens.PopWord());
            }
            Namespace ns = new Namespace(namespaceToken, nsNameParts, parent);

            tokens.PopExpected("{");
            while (!tokens.PopIfPresent("}"))
            {
                TopLevelEntity tle = Parse(context, tokens, ns);
                ns.AddMember(tle);
            }
            return(ns);
        }
Esempio n. 3
0
 //  Caller must take lock on this
 internal void LoadTypesInNamespace(
   Namespace moduleNamespace
 )
   //^ requires moduleNamespace.NamespaceNameOffset != 0xFFFFFFFF;
 {
   CoreTypes dummy = this.CoreTypes; //force core types to be initialized
   uint namespaceNameOffset = moduleNamespace.NamespaceNameOffset;
   Debug.Assert(namespaceNameOffset != 0xFFFFFFFF);
   uint numberOfTypeDefs = this.PEFileReader.TypeDefTable.NumberOfRows;
   var moduleTypeArray = this.ModuleTypeDefArray;
   for (uint i = 1; i <= numberOfTypeDefs; ++i) {
     TypeDefRow typeDefRow = this.PEFileReader.TypeDefTable[i];
     //  Check if its in the same namespace
     if (typeDefRow.Namespace != namespaceNameOffset || typeDefRow.IsNested)
       continue;
     //  Check if its already created by someone else
     NamespaceType/*?*/ type = (NamespaceType)moduleTypeArray[i];
     if (type == null) {
       type = this.CreateModuleNamespaceType(i, typeDefRow, moduleNamespace, MetadataReaderSignatureTypeCode.NotModulePrimitive);
       var redirectedType = this.ModuleReader.metadataReaderHost.Redirect(this.Module, type);
       if (redirectedType == type) moduleNamespace.AddMember(type);
       moduleTypeArray[i] = type;
       this.RedirectedTypeDefArray[i] = redirectedType;
       this.ModuleTypeDefLoadState[i] = LoadState.Loaded;
     }
   }
   uint numberOfExportedTypes = this.PEFileReader.ExportedTypeTable.NumberOfRows;
   ExportedTypeAliasBase/*?*/[] exportedTypeArray = this.ExportedTypeArray;
   for (uint i = 1; i <= numberOfExportedTypes; ++i) {
     ExportedTypeRow exportedTypeRow = this.PEFileReader.ExportedTypeTable[i];
     //  Check if its in the same namespace
     if (exportedTypeRow.TypeNamespace != namespaceNameOffset || exportedTypeRow.IsNested)
       continue;
     //  Check if its already created by someone else
     ExportedTypeAliasBase/*?*/ type = exportedTypeArray[i];
     if (type == null) {
       type = this.CreateExportedNamespaceType(i, exportedTypeRow, moduleNamespace);
       this.ExportedTypeArray[i] = type;
       this.ExportedTypeLoadState[i] = LoadState.Loaded;
     }
   }
 }
Esempio n. 4
0
 ExportedTypeNamespaceAlias CreateExportedNamespaceType(
   uint exportedTypeRowId,
   ExportedTypeRow exportedTypeRow,
   Namespace moduleNamespace
 ) {
   IName typeName = this.GetNameFromOffset(exportedTypeRow.TypeName);
   ExportedTypeNamespaceAlias exportedType = new ExportedTypeNamespaceAlias(this, typeName, exportedTypeRowId, exportedTypeRow.Flags, moduleNamespace);
   moduleNamespace.AddMember(exportedType);
   return exportedType;
 }
Esempio n. 5
0
 NamespaceType CreateModuleNamespaceType(
   uint typeDefRowId,
   TypeDefRow typeDefRow,
   Namespace moduleNamespace,
   ModuleSignatureTypeCode signatureTypeCode
 ) {
   IName typeName = this.GetNameFromOffset(typeDefRow.Name);
   uint genericParamRowIdStart;
   uint genericParamRowIdEnd;
   this.GetGenericParamInfoForType(typeDefRowId, out genericParamRowIdStart, out genericParamRowIdEnd);
   NamespaceType type;
   if (genericParamRowIdStart == 0) {
     if (signatureTypeCode == ModuleSignatureTypeCode.NotModulePrimitive)
       type = new NonGenericNamespaceTypeWithoutPrimitiveType(this, typeName, typeDefRowId, typeDefRow.Flags, moduleNamespace);
     else
       type = new NonGenericNamespaceTypeWithPrimitiveType(this, typeName, typeDefRowId, typeDefRow.Flags, moduleNamespace, signatureTypeCode);
   } else {
     IName unmangledTypeName = this.GetUnmangledNameFromOffset(typeDefRow.Name);
     type = new GenericNamespaceType(this, unmangledTypeName, typeDefRowId, typeDefRow.Flags, moduleNamespace, typeName, genericParamRowIdStart, genericParamRowIdEnd);
   }
   moduleNamespace.AddMember(type);
   return type;
 }
 ExportedTypeNamespaceAlias CreateExportedNamespaceType(uint exportedTypeRowId, ExportedTypeRow exportedTypeRow, Namespace moduleNamespace) {
   ExportedTypeNamespaceAlias exportedType = new ExportedTypeNamespaceAlias(this, exportedTypeRowId, exportedTypeRow.Flags, moduleNamespace);
   moduleNamespace.AddMember(exportedType);
   return exportedType;
 }
Esempio n. 7
0
        public override AstNode Visit(NamespaceDefinition node)
        {
            // Handle nested names.
            string        fullname    = node.GetName();
            StringBuilder nameBuilder = new StringBuilder();

            int numscopes = 0;

            for (int i = 0; i < fullname.Length; i++)
            {
                char c = fullname[i];
                if (c != '.')
                {
                    nameBuilder.Append(c);
                    if (i + 1 < fullname.Length)
                    {
                        continue;
                    }
                }

                // Expect full name.
                if (c == '.' && i + 1 == fullname.Length)
                {
                    Error(node, "expected complete namespace name.");
                }

                // Find an already declared namespace.
                string name = nameBuilder.ToString();
                nameBuilder.Length = 0;
                ScopeMember old = currentContainer.FindMember(name);
                if (old != null)
                {
                    if (!old.IsNamespace())
                    {
                        Error(node, "defining namespace collides with another thing.");
                    }

                    // Store a reference in the node.
                    node.SetNamespace((Namespace)old);
                }
                else
                {
                    // Cast the current scope.
                    Namespace space = (Namespace)currentContainer;

                    // Create, name and add the new namespace.
                    Namespace newNamespace = new Namespace(space);
                    newNamespace.SetName(name);
                    space.AddMember(newNamespace);

                    // Store a reference in the node.
                    node.SetNamespace(newNamespace);
                }

                // Update the scope.
                PushScope(node.GetNamespace());

                // Increase the number of scopes.
                numscopes++;
            }

            // Visit the children.
            VisitList(node.GetChildren());

            // Restore the scopes.
            for (int i = 0; i < numscopes; i++)
            {
                PopScope();
            }

            return(node);
        }