public StructDescription(AStructDecl structDecl) { Parser parser = new Parser(structDecl); Name = parser.Name; IsEnum = Name.StartsWith("enum "); if (IsEnum) { Name = Name.Substring(5); foreach (VariableDescription field in parser.Fields) { field.PlacementPrefix = "Enum Field"; } } Fields = parser.Fields; Methods = parser.Methods; Constructors = parser.Constructors; Deconstructors = parser.Deconstructors; LineFrom = structDecl.GetName().Line; LineTo = structDecl.GetEndToken().Line; if (structDecl.GetBase() is AGenericType) { BaseRef = (ANamedType)((AGenericType)structDecl.GetBase()).GetBase(); } else { BaseRef = (ANamedType)structDecl.GetBase(); } structDecl.RemoveChild(BaseRef); foreach (TIdentifier identifier in structDecl.GetGenericVars()) { GenericVars.Add(identifier.Text); } IsClass = structDecl.GetClassToken() != null; Visibility = (PVisibilityModifier)structDecl.GetVisibilityModifier().Clone(); Position = TextPoint.FromCompilerCoords(structDecl.GetName()); }
private static void GetMatchingTypes(ANamedType node, List <string> names, List <ATypedefDecl> typeDefs, List <AStructDecl> structs, List <AMethodDecl> delegates, List <ANamespaceDecl> namespaces, List <TIdentifier> generics) { List <IList> decls = new List <IList>(); List <string> currentNamespace = Util.GetFullNamespace(node); AASourceFile currentSourceFile = Util.GetAncestor <AASourceFile>(node); if (names.Count == 1) { string name = names[0]; //Check generic vars AStructDecl currentStruct = Util.GetAncestor <AStructDecl>(node); if (currentStruct != null) { foreach (TIdentifier genericVar in currentStruct.GetGenericVars()) { if (genericVar.Text == name) { generics.Add(genericVar); } } } //Get all type decls and namespaces matching this name, visible from this location List <IList> visibleDecls = Util.GetVisibleDecls(node, ((AAName)node.GetName()).GetIdentifier().Count == 1); foreach (IList declList in visibleDecls) { bool sameFile = false; if (declList.Count > 0) { sameFile = currentSourceFile == Util.GetAncestor <AASourceFile>((PDecl)declList[0]); } foreach (PDecl decl in declList) { bool sameNS = Util.NamespacesEquals(currentNamespace, Util.GetFullNamespace(decl)); if (decl is ANamespaceDecl) { ANamespaceDecl aDecl = (ANamespaceDecl)decl; if (aDecl.GetName().Text == name) { namespaces.Add(aDecl); } continue; } if (decl is ATypedefDecl) { if (Util.IsAncestor(node, decl)) { continue; } ATypedefDecl aDecl = (ATypedefDecl)decl; if (aDecl.GetStatic() != null && !sameFile || aDecl.GetVisibilityModifier() is APrivateVisibilityModifier && !sameNS) { continue; } ANamedType namedType = (ANamedType)aDecl.GetName(); AAName aName = (AAName)namedType.GetName(); string n = ((TIdentifier)aName.GetIdentifier()[0]).Text; if (n == name) { typeDefs.Add(aDecl); } continue; } if (decl is AStructDecl) { AStructDecl aDecl = (AStructDecl)decl; if (!sameNS && aDecl.GetVisibilityModifier() is APrivateVisibilityModifier) { continue; } if (aDecl.GetName().Text == name) { structs.Add(aDecl); } continue; } if (decl is AMethodDecl) { AMethodDecl aDecl = (AMethodDecl)decl; if (!sameNS && aDecl.GetVisibilityModifier() is APrivateVisibilityModifier || !sameFile && aDecl.GetStatic() != null) { continue; } if (aDecl.GetDelegate() != null && aDecl.GetName().Text == name) { delegates.Add(aDecl); } continue; } } } } else { string name = names[names.Count - 1]; List <ANamespaceDecl> baseNamespaces = new List <ANamespaceDecl>(); List <string> baseNames = new List <string>(); baseNames.AddRange(names); baseNames.RemoveAt(baseNames.Count - 1); GetMatchingTypes(node, baseNames, new List <ATypedefDecl>(), new List <AStructDecl>(), new List <AMethodDecl>(), baseNamespaces, generics); foreach (ANamespaceDecl ns in baseNamespaces) { bool sameFile = currentSourceFile == Util.GetAncestor <AASourceFile>(ns); foreach (PDecl decl in ns.GetDecl()) { bool sameNS = Util.NamespacesEquals(currentNamespace, Util.GetFullNamespace(decl)); if (decl is ANamespaceDecl) { ANamespaceDecl aDecl = (ANamespaceDecl)decl; if (aDecl.GetName().Text == name) { namespaces.Add(aDecl); } continue; } if (decl is ATypedefDecl) { ATypedefDecl aDecl = (ATypedefDecl)decl; ANamedType namedType = (ANamedType)aDecl.GetName(); AAName aName = (AAName)namedType.GetName(); string n = ((TIdentifier)aName.GetIdentifier()[0]).Text; if (n == name) { typeDefs.Add(aDecl); } continue; } if (decl is AStructDecl) { AStructDecl aDecl = (AStructDecl)decl; if (!sameNS && aDecl.GetVisibilityModifier() is APrivateVisibilityModifier) { continue; } if (aDecl.GetName().Text == name) { structs.Add(aDecl); } continue; } if (decl is AMethodDecl) { AMethodDecl aDecl = (AMethodDecl)decl; if (!sameNS && aDecl.GetVisibilityModifier() is APrivateVisibilityModifier || !sameFile && aDecl.GetStatic() != null) { continue; } if (aDecl.GetDelegate() != null && aDecl.GetName().Text == name) { delegates.Add(aDecl); } continue; } } } } }