# HG changeset patch # User Tom Rodriguez # Date 1411772494 25200 # Node ID 15c8e24f027a4c9317a6b7c235d9b060d0afc216 # Parent 6fcb6691fe5fb51503671c1c48ea8c82bc867b73 Limit imports in generated matchers to only the used packages diff -r 6fcb6691fe5f -r 15c8e24f027a graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchProcessor.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchProcessor.java Fri Sep 26 16:00:09 2014 -0700 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchProcessor.java Fri Sep 26 16:01:34 2014 -0700 @@ -89,6 +89,8 @@ private final Set originatingElements = new HashSet<>(); + private Set requiredPackages = new HashSet<>(); + RuleParser(String rule) { Matcher m = tokenizer.matcher(rule); List list = new ArrayList<>(); @@ -168,6 +170,7 @@ name = next(); } originatingElements.addAll(type.originatingElements); + requiredPackages.add(type.nodePackage); } else if (Character.isLowerCase(peek("name").charAt(0))) { name = next(); type = valueType; @@ -330,11 +333,6 @@ Map knownTypes = new HashMap<>(); /** - * The set of packages which must be imported to refer to the known classes. - */ - List requiredPackages = new ArrayList<>(); - - /** * The mapping between elements with MatchRules and the wrapper class used invoke the code * generation after the match. */ @@ -354,9 +352,6 @@ TypeDescriptor descriptor = new TypeDescriptor(mirror, shortName, nodeClass, nodePackage, inputs, commutative, shareable); descriptor.originatingElements.add(element); knownTypes.put(shortName, descriptor); - if (!requiredPackages.contains(descriptor.nodePackage)) { - requiredPackages.add(descriptor.nodePackage); - } } private String findPackage(Element type) { @@ -494,16 +489,11 @@ out.println("import " + MatchStatementSet.class.getPackage().getName() + ".*;"); out.println("import " + NodeLIRBuilder.class.getName() + ";"); out.println("import " + Position.class.getName() + ";"); - for (String p : requiredPackages) { + for (String p : info.requiredPackages) { out.println("import " + p + ".*;"); } out.println(""); - // FIXME: Ugly hack, don't know how to work this problem around (import - // com.oracle.graal.nodes.*; is unused, but cannot be avoided - if (matchStatementClassName.contains("SPARCNodeLIRBuilder")) { - out.println("@SuppressWarnings(\"unused\")"); - } out.println("public class " + matchStatementClassName + " implements " + MatchStatementSet.class.getSimpleName() + " {"); out.println(); @@ -654,6 +644,11 @@ private final Set originatingElements = new HashSet<>(); public Set positionDeclarations = new LinkedHashSet<>(); + /** + * The set of packages which must be imported to refer the classes mention in matchRules. + */ + Set requiredPackages = new HashSet<>(); + public MatchRuleDescriptor(TypeElement topDeclaringType) { this.topDeclaringType = topDeclaringType; } @@ -955,6 +950,7 @@ } originatingElementsList.addAll(parser.originatingElements); + info.requiredPackages.addAll(parser.requiredPackages); // Accumulate any position declarations. parser.generatePositionDeclarations(info.positionDeclarations);