diff --git a/tool/src/org/antlr/v4/codegen/model/decl/StructDecl.java b/tool/src/org/antlr/v4/codegen/model/decl/StructDecl.java index 309d6caed..9fb681506 100644 --- a/tool/src/org/antlr/v4/codegen/model/decl/StructDecl.java +++ b/tool/src/org/antlr/v4/codegen/model/decl/StructDecl.java @@ -57,6 +57,16 @@ public class StructDecl extends Decl { @ModelElement public List interfaces; @ModelElement public List extensionMembers; + // Track these separately; Go target needs to generate getters/setters + // Do not make them templates; we only need the Decl object not the ST + // built from it. Avoids adding args to StructDecl template + public OrderedHashSet tokenDecls = new OrderedHashSet(); + public OrderedHashSet tokenTypeDecls = new OrderedHashSet(); + public OrderedHashSet tokenListDecls = new OrderedHashSet(); + public OrderedHashSet ruleContextDecls = new OrderedHashSet(); + public OrderedHashSet ruleContextListDecls = new OrderedHashSet(); + public OrderedHashSet attributeDecls = new OrderedHashSet(); + public StructDecl(OutputModelFactory factory, Rule r) { super(factory, factory.getGenerator().getTarget().getRuleFunctionContextStructName(r)); addDispatchMethods(r); @@ -80,8 +90,29 @@ public class StructDecl extends Decl { public void addDecl(Decl d) { d.ctx = this; + if ( d instanceof ContextGetterDecl ) getters.add(d); else attrs.add(d); + + // add to specific "lists" + if ( d instanceof TokenTypeDecl ) { + tokenTypeDecls.add(d); + } + else if ( d instanceof TokenListDecl ) { + tokenListDecls.add(d); + } + else if ( d instanceof TokenDecl ) { + tokenDecls.add(d); + } + else if ( d instanceof RuleContextListDecl ) { + ruleContextListDecls.add(d); + } + else if ( d instanceof RuleContextDecl ) { + ruleContextDecls.add(d); + } + else if ( d instanceof AttributeDecl ) { + attributeDecls.add(d); + } } public void addDecl(Attribute a) {