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 (node.Parent() is ATypedefDecl && ((ATypedefDecl)node.Parent()).GetName() == node) return; //Link named type to their definition (structs) List<ATypedefDecl> typeDefs = new List<ATypedefDecl>(); List<AStructDecl> structs = new List<AStructDecl>(); List<AMethodDecl> delegates = new List<AMethodDecl>(); List<TIdentifier> generics = new List<TIdentifier>(); bool matchPrimitive; GetMatchingTypes(node, typeDefs, structs, delegates, generics, out matchPrimitive); int matches = typeDefs.Count + structs.Count + delegates.Count + (matchPrimitive ? 1 : 0) + generics.Count; if (matches == 0) { errors.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText49") + ((AAName)node.GetName()).AsString()), true); } else if (generics.Count != 1 && matches > 1) { List<ErrorCollection.Error> subError = new List<ErrorCollection.Error>(); if (matchPrimitive) subError.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText50") + ((AAName)node.GetName()).AsString())); foreach (ATypedefDecl typeDef in typeDefs) { subError.Add(new ErrorCollection.Error(typeDef.GetToken(), LocRM.GetString("ErrorText51"))); } foreach (AStructDecl structDecl in structs) { subError.Add(new ErrorCollection.Error(structDecl.GetName(), LocRM.GetString("ErrorText52") + Util.GetTypeName(structDecl))); } foreach (AMethodDecl methodDecl in delegates) { subError.Add(new ErrorCollection.Error(methodDecl.GetName(), LocRM.GetString("ErrorText53"))); } foreach (TIdentifier identifier in generics) { subError.Add(new ErrorCollection.Error(identifier, LocRM.GetString("ErrorText54"))); } errors.Add( new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText55") + ((AAName)node.GetName()).AsString(), false, subError.ToArray()), true); } else { if (generics.Count == 1) { data.GenericLinks[node] = generics[0]; return; } if (typeDefs.Count == 1) { ATypedefDecl typeDef = typeDefs[0]; //data.TypeDefLinks[node] = typeDef; PType type = (PType) typeDef.GetType().Clone(); node.ReplaceBy(type); type.Apply(this); return; } if (structs.Count == 1) { data.StructTypeLinks[node] = structs[0]; } else if (delegates.Count == 1) { data.DelegateTypeLinks[node] = delegates[0]; } if (!matchPrimitive && !(structs.Count == 1 && data.Enums.ContainsKey(structs[0])) && node.Parent() is AEnrichmentDecl) //Not allowed to enrich a struct, class or delegate { errors.Add(new ErrorCollection.Error(node.GetToken(), LocRM.GetString("ErrorText56"))); } } }