public bool VisitNode(Struct node) { // struct [specifiers] structname [extends parentstruct] { \n contents \n }; Write("struct "); if (node.Specifiers.Count > 0) Append("{0} ", String.Join(" ", node.Specifiers.Select(x => x.Value))); Append("{0} ", node.Name); if (node.Parent != null) Append("extends {0} ", node.Parent.Name); Append("{0}", "{"); NestingLevel++; foreach (Variable member in node.Members) member.AcceptVisitor(this); NestingLevel--; Write("{0};", "}"); return true; }
public bool VisitNode(Struct node) { if (Symbols.SymbolExistsInCurrentScope(node.Name)) return Error("A member named '" + node.Name + "' already exists in this class!", node.StartPos, node.EndPos); Symbols.AddSymbol(node.Name, node); // TODO: add in package / global namespace. // If a symbol with that name exists, overwrite it with this symbol from now on. // damn this language... if (node.Parent != null) { ASTNode parent; if (!Symbols.TryGetSymbol(node.Parent.Name, out parent, NodeUtils.GetOuterClassScope(node))) Error("No parent struct named '" + node.Parent.Name + "' found!", node.Parent.StartPos, node.Parent.EndPos); if (parent != null) { if (parent.Type != ASTNodeType.Struct) Error("Parent named '" + node.Parent.Name + "' is not a struct!", node.Parent.StartPos, node.Parent.EndPos); else if ((parent as Struct).SameOrSubStruct(node.Name)) // TODO: not needed due to no forward declarations? Error("Extending from '" + node.Parent.Name + "' causes circular extension!", node.Parent.StartPos, node.Parent.EndPos); else node.Parent = parent as Struct; } } Symbols.PushScope(node.Name); // TODO: can all types of variable declarations be supported in a struct? // what does the parser let through? var unprocessed = node.Members.ToList(); foreach (VariableDeclaration decl in node.Members.ToList()) { decl.Outer = node; Success = Success && decl.AcceptVisitor(this); } Symbols.PopScope(); node.Declaration = node; return Success; }
public Struct ConvertStruct(ME3Struct obj) { var Vars = new List<VariableDeclaration>(); foreach (var member in obj.Variables) Vars.Add(ConvertVariable(member)); VariableType parent = obj.SuperField != null ? new VariableType(obj.SuperField.Name, null, null) : null; var node = new Struct(obj.Name, new List<Specifier>(), Vars, null, null, parent); foreach (var member in Vars) member.Outer = node; return node; }