Mercurial > hg > truffle
changeset 17242:15c8e24f027a
Limit imports in generated matchers to only the used packages
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Fri, 26 Sep 2014 16:01:34 -0700 |
parents | 6fcb6691fe5f |
children | 5b00a1e62a5e |
files | graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchProcessor.java |
diffstat | 1 files changed, 10 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- 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<Element> originatingElements = new HashSet<>(); + private Set<String> requiredPackages = new HashSet<>(); + RuleParser(String rule) { Matcher m = tokenizer.matcher(rule); List<String> 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<String, TypeDescriptor> knownTypes = new HashMap<>(); /** - * The set of packages which must be imported to refer to the known classes. - */ - List<String> 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<Element> originatingElements = new HashSet<>(); public Set<String> positionDeclarations = new LinkedHashSet<>(); + /** + * The set of packages which must be imported to refer the classes mention in matchRules. + */ + Set<String> 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);