public override void DefaultIn(Node node) { if (isFirst) { isFirst = false; } else { int index = 0; CloneMethod.GetChildTypeIndex getChildTypeIndex = new CloneMethod.GetChildTypeIndex() { Parent = node.Parent(), Child = node }; node.Parent().Apply(getChildTypeIndex); index = getChildTypeIndex.Index; CloneMethod.GetChildTypeByIndex getChildTypeByIndex = new CloneMethod.GetChildTypeByIndex() { Child = node, Index = index, Parent = currentClone }; currentClone.Apply(getChildTypeByIndex); currentClone = getChildTypeByIndex.Child; } if (node is ANamedType && data.GenericLinks.ContainsKey((ANamedType)node)) { TIdentifier name = data.GenericLinks[(ANamedType)node]; AStructDecl str = (AStructDecl)name.Parent(); PType type = types[str.GetGenericVars().IndexOf(name)]; replacer = Util.MakeClone(type, data); } }
public override void OutAStructDecl(AStructDecl node) { if (node.GetGenericVars().Count > 0 && !Refferences.ContainsKey(node)) { Refferences[node] = new List <AGenericType>(); } base.OutAStructDecl(node); }
public override void OutAGenericType(AGenericType node) { if (!(node.GetBase() is ANamedType)) { errors.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText44"))); return; } ANamedType Base = (ANamedType)node.GetBase(); if (!data.StructTypeLinks.ContainsKey(Base)) { errors.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText44"))); return; } AStructDecl str = data.StructTypeLinks[Base]; if (str.GetGenericVars().Count != node.GetGenericTypes().Count) { errors.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText45"), false, new ErrorCollection.Error(str.GetName(), LocRM.GetString("ErrorText46") + Util.GetTypeName(str)))); return; } LookForGenericVar finder = new LookForGenericVar(); foreach (PType genericType in node.GetGenericTypes()) { genericType.Apply(finder); if (finder.ContainsGenericVar || finder.ContainsNestedGenerics) { //if (finder.ContainsGenericVar) structsWithGenerics.Add(Util.GetAncestor <AStructDecl>(node)); if (finder.ContainsNestedGenerics) { if (!Util.HasAncestor <AStructDecl>(node) || Util.GetAncestor <AStructDecl>(node).GetGenericVars().Count == 0) { needAnotherPass = true; } } return; } } if (!Refferences.ContainsKey(str)) { Refferences[str] = new List <AGenericType>(); } Refferences[str].Add(node); base.OutAGenericType(node); }
public override void OutANamedType(ANamedType node) { //If using a generic type, you must us it as a generic if (data.StructTypeLinks.ContainsKey(node)) { AStructDecl str = data.StructTypeLinks[node]; if (str.GetGenericVars().Count > 0) { if (!(node.Parent() is AGenericType)) { errors.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText46"), false, new ErrorCollection.Error(str.GetName(), LocRM.GetString("ErrorText48") + Util.GetTypeName(str)))); } } } base.OutANamedType(node); }
public override void OutANamedType(ANamedType node) { //If using a generic type, you must us it as a generic if (data.StructTypeLinks.ContainsKey(node)) { AStructDecl str = data.StructTypeLinks[node]; if (str.GetGenericVars().Count > 0) { if (!(node.Parent() is AGenericType)) { errors.Add(new ErrorCollection.Error(node.GetToken(), "Target struct is a generic type. You must specify types for the generics.", false, new ErrorCollection.Error(str.GetName(), "Matching " + Util.GetTypeName(str)))); } } } base.OutANamedType(node); }
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; } } } } }