public override bool Equals(object obj) { if (!(obj is NamespaceDescription)) { return(false); } NamespaceDescription other = (NamespaceDescription)obj; if (decl.GetName().Text != other.decl.GetName().Text) { return(false); } if (Methods.Count != other.Methods.Count || Fields.Count != other.Fields.Count || Structs.Count != other.Structs.Count || Enrichments.Count != other.Enrichments.Count || Usings.Count != other.Usings.Count || Typedefs.Count != other.Typedefs.Count || Namespaces.Count != other.Namespaces.Count) { return(false); } return(!(Methods.Where((t, i) => !t.Equals(other.Methods[i])).Any() || Fields.Where((t, i) => !t.Equals(other.Fields[i])).Any() || Structs.Where((t, i) => !t.Equals(other.Structs[i])).Any() || Enrichments.Where((t, i) => !t.Equals(other.Enrichments[i])).Any() || Usings.Where((t, i) => t != other.Usings[i]).Any() || Typedefs.Where((t, i) => !t.Equals(other.Typedefs[i])).Any() || Namespaces.Where((t, i) => !t.Equals(other.Namespaces[i])).Any())); }
public ParserState(IEnumerable <string> knownNames) : this() { foreach (var name in knownNames) { Typedefs.Add(name); } }
public TypedefNameDecl FindTypedef(string name, bool createDecl = false) { var entries = name.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (entries.Count <= 1) { var typeDef = Typedefs.Find(e => e.Name.Equals(name)); if (typeDef == null && createDecl) { typeDef = new TypedefDecl { Name = name, Namespace = this }; Typedefs.Add(typeDef); } return(typeDef); } var typeDefName = entries[entries.Count - 1]; var namespaces = entries.Take(entries.Count - 1); var @namespace = FindNamespace(namespaces); if (@namespace == null) { return(null); } return(@namespace.FindTypedef(typeDefName, createDecl)); }
public void Clear() { //Includes.Clear(); Methods.Clear(); Fields.Clear(); Structs.Clear(); Typedefs.Clear(); Enrichments.Clear(); Usings.Clear(); Namespaces.Clear(); }
public override string ToString() { var sb = new StringBuilder(); sb.AppendLine($"interface {Name}"); sb.AppendLine(); sb.AppendJoin('\n', Typedefs.Select(td => $"type {td.Name} {td}")); sb.AppendLine(); sb.AppendJoin('\n', Errors); sb.AppendLine(); sb.AppendJoin('\n', Methods); sb.AppendLine(); return(sb.ToString()); }
public void Dump(IndentedTextWriter writer, bool forInline) { if (forInline && Typedefs.Count > 0) { writer.Write(string.Join(", ", Typedefs.Select(_ => _.Value.AsCode(_.Key, true)))); return; } string cType; switch (_size) { case 1: cType = "char"; break; case 2: cType = "short"; break; case 4: cType = "int"; break; default: throw new Exception($"Cannot determine primitive type for size {_size}"); } writer.WriteLine(forInline ? $"enum : {cType} {{" : $"enum {Name} : {cType} {{"); ++writer.Indent; foreach (var(key, value) in _members) { writer.WriteLine($"{key} = {value},"); } --writer.Indent; if (forInline) { writer.Write("}"); } else { writer.WriteLine("};"); } }
public ITypeAlias FindTypeAlias(string Name, bool Create = false) { var foundTypeAlias = Typedefs.FirstOrDefault(t => t.Name == Name); if (foundTypeAlias != null) { return((ITypeAlias)foundTypeAlias); } if (!Create) { return(null); } var talias = new TypeAlias(); talias.Name = Name; talias.Namespace = this; return(talias); }
ITypedefDecl IDeclarationContext.FindTypedef(string Name, bool Create) { var foundTypedef = Typedefs.FirstOrDefault(td => td.Name == Name); if (foundTypedef != null) { return((ITypedefDecl)foundTypedef); } if (!Create) { return(null); } var tdef = new TypedefDecl(); tdef.Name = Name; tdef.Namespace = this; return(tdef); }
public void Dump(IndentedTextWriter writer, bool forInline) { if (forInline && Typedefs.Count > 0) { writer.Write(string.Join(", ", Typedefs.Select(_ => _.Value.AsCode(_.Key, true)))); return; } writer.WriteLine(forInline ? "struct {" : $"struct {Name} {{"); ++writer.Indent; foreach (var m in _members) { writer.WriteLine(m); } --writer.Indent; if (forInline) { writer.Write("}"); } else { writer.WriteLine("};"); } }
public ParserState(SymbolTable symbolTable) : this() { Typedefs.UnionWith(symbolTable.PrimitiveTypes.Keys); Typedefs.UnionWith(symbolTable.NamedTypes.Keys); }
public bool Parse(Start ast, GalaxyCompiler compiler) { this.compiler = compiler; Parser parser = new Parser(ast); //Includes = parser.Includes; //To save time, only update if there has been changes //I assume that the Elements are in the same order //Check if recouluring is needed List <StructDescription> preUpdateStructs = GetAllStructs(); List <StructDescription> postUpdateStructs = new List <StructDescription>(); postUpdateStructs.AddRange(parser.Structs); List <IDeclContainer> list = new List <IDeclContainer>(); list.AddRange(parser.Namespaces); while (list.Count > 0) { List <IDeclContainer> nextList = new List <IDeclContainer>(); foreach (IDeclContainer declContainer in list) { postUpdateStructs.AddRange(declContainer.Structs); nextList.AddRange(declContainer.Namespaces); } list = nextList; } bool restyle = preUpdateStructs.Count != postUpdateStructs.Count; if (!restyle) { for (int i = 0; i < preUpdateStructs.Count; i++) { if (preUpdateStructs[i].Name != postUpdateStructs[i].Name) { restyle = true; break; } } } if (restyle && Form1.Form.CurrentOpenFile != null && Form1.Form.CurrentOpenFile.OpenFile != null) { Form1.Form.CurrentOpenFile.OpenFile.Editor.Restyle(); } bool needUpdate = Methods.Count != parser.Methods.Count || Fields.Count != parser.Fields.Count || Structs.Count != parser.Structs.Count || Enrichments.Count != parser.Enrichments.Count || Usings.Count != parser.Usings.Count || Typedefs.Count != parser.Typedefs.Count || Namespaces.Count != parser.Namespaces.Count; if (!needUpdate) { needUpdate = Methods.Where((t, i) => !t.Equals(parser.Methods[i])).Any() || Fields.Where((t, i) => !t.Equals(parser.Fields[i])).Any() || Structs.Where((t, i) => !t.Equals(parser.Structs[i])).Any() || Enrichments.Where((t, i) => !t.Equals(parser.Enrichments[i])).Any() || Usings.Where((t, i) => t != parser.Usings[i]).Any() || Typedefs.Where((t, i) => !t.Equals(parser.Typedefs[i])).Any() || Namespaces.Where((t, i) => !t.Equals(parser.Namespaces[i])).Any(); } if (needUpdate) { Methods = parser.Methods; foreach (MethodDescription method in Methods) { method.ParentFile = this; } Fields = parser.Fields; foreach (VariableDescription field in Fields) { field.ParentFile = this; } Structs = parser.Structs; foreach (StructDescription structDescription in Structs) { foreach (MethodDescription method in structDescription.Methods) { method.ParentFile = this; } foreach (VariableDescription field in structDescription.Fields) { field.ParentFile = this; } structDescription.ParentFile = this; } Enrichments = parser.Enrichments; foreach (EnrichmentDescription structDescription in Enrichments) { structDescription.ParentFile = this; foreach (MethodDescription method in structDescription.Methods) { method.ParentFile = this; } foreach (VariableDescription field in structDescription.Fields) { field.ParentFile = this; } } Typedefs = parser.Typedefs; foreach (TypedefDescription typedef in Typedefs) { typedef.ParentFile = this; } Usings = parser.Usings; Namespaces = parser.Namespaces; foreach (NamespaceDescription namespaceDescription in Namespaces) { namespaceDescription.Parent = this; } if (SourceFileChanged != null) { SourceFileChanged(this); } } return(needUpdate); }
public void AddTypeAliase(ITypeAlias value) { Typedefs.Add((TypeAlias)value); }
public void AddTypedef(ITypedefDecl value) { Typedefs.Add((TypedefDecl)value); }