From 2777bc4d269e2e56ebe19f11184aae132f676c61 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Sun, 28 Sep 2014 16:02:21 -0500 Subject: [PATCH] Output listener and visitor methods in grammar order --- tool/src/org/antlr/v4/codegen/model/ListenerFile.java | 8 ++++---- tool/src/org/antlr/v4/codegen/model/VisitorFile.java | 8 ++++---- tool/src/org/antlr/v4/tool/Rule.java | 3 ++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/tool/src/org/antlr/v4/codegen/model/ListenerFile.java b/tool/src/org/antlr/v4/codegen/model/ListenerFile.java index 8db1d18c3..99f6ebf94 100644 --- a/tool/src/org/antlr/v4/codegen/model/ListenerFile.java +++ b/tool/src/org/antlr/v4/codegen/model/ListenerFile.java @@ -36,8 +36,8 @@ import org.antlr.v4.tool.Rule; import org.antlr.v4.tool.ast.ActionAST; import org.antlr.v4.tool.ast.AltAST; -import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -52,13 +52,13 @@ public class ListenerFile extends OutputFile { /** * The names of all listener contexts. */ - public Set listenerNames = new HashSet(); + public Set listenerNames = new LinkedHashSet(); /** * For listener contexts created for a labeled outer alternative, maps from * a listener context name to the name of the rule which defines the * context. */ - public Map listenerLabelRuleNames = new HashMap(); + public Map listenerLabelRuleNames = new LinkedHashMap(); @ModelElement public Action header; diff --git a/tool/src/org/antlr/v4/codegen/model/VisitorFile.java b/tool/src/org/antlr/v4/codegen/model/VisitorFile.java index cd1732730..e1370a9f9 100644 --- a/tool/src/org/antlr/v4/codegen/model/VisitorFile.java +++ b/tool/src/org/antlr/v4/codegen/model/VisitorFile.java @@ -36,8 +36,8 @@ import org.antlr.v4.tool.Rule; import org.antlr.v4.tool.ast.ActionAST; import org.antlr.v4.tool.ast.AltAST; -import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -49,13 +49,13 @@ public class VisitorFile extends OutputFile { /** * The names of all rule contexts which may need to be visited. */ - public Set visitorNames = new HashSet(); + public Set visitorNames = new LinkedHashSet(); /** * For rule contexts created for a labeled outer alternative, maps from * a listener context name to the name of the rule which defines the * context. */ - public Map visitorLabelRuleNames = new HashMap(); + public Map visitorLabelRuleNames = new LinkedHashMap(); @ModelElement public Action header; diff --git a/tool/src/org/antlr/v4/tool/Rule.java b/tool/src/org/antlr/v4/tool/Rule.java index 8e1a1617e..cd58d1e94 100644 --- a/tool/src/org/antlr/v4/tool/Rule.java +++ b/tool/src/org/antlr/v4/tool/Rule.java @@ -41,6 +41,7 @@ import org.stringtemplate.v4.misc.MultiMap; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -212,7 +213,7 @@ public class Rule implements AttributeResolver { * this label. Unlabeled alternatives are not included in the result. */ public Map>> getAltLabels() { - Map>> labels = new HashMap>>(); + Map>> labels = new LinkedHashMap>>(); for (int i=1; i<=numberOfAlts; i++) { GrammarAST altLabel = alt[i].ast.altLabel; if ( altLabel!=null ) {