Mercurial > hg > truffle
annotate graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchProcessor.java @ 15966:27ff0792b048
made more services implement com.oracle.graal.api.runtime.Service for faster loading
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 28 May 2014 14:47:34 +0200 |
parents | d1822a8fe26f |
children | a8322288e838 |
rev | line source |
---|---|
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
1 /* |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
4 * |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
8 * |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
14 * |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
18 * |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
21 * questions. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
22 */ |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.compiler.match; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
24 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
25 import java.io.*; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
26 import java.util.*; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
27 import java.util.regex.*; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
28 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
29 import javax.annotation.processing.*; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
30 import javax.lang.model.*; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
31 import javax.lang.model.element.*; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
32 import javax.lang.model.type.*; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
33 import javax.lang.model.util.*; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
34 import javax.tools.Diagnostic.Kind; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
35 import javax.tools.*; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
36 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
37 import com.oracle.graal.compiler.common.*; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
38 import com.oracle.graal.compiler.gen.*; |
15548
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
39 import com.oracle.graal.graph.*; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
40 import com.oracle.graal.nodes.*; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
41 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
42 /** |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
43 * Processes classes annotated with {@link MatchRule}. A {@link MatchStatementSet} service is |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
44 * generated for each top level class containing at least one such field. These service objects can |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
45 * be retrieved as follows: |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
46 * |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
47 * <pre> |
15966
27ff0792b048
made more services implement com.oracle.graal.api.runtime.Service for faster loading
Doug Simon <doug.simon@oracle.com>
parents:
15844
diff
changeset
|
48 * Iterable<MatchStatementSet> sl = Services.load(MatchStatementSet.class); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
49 * for (MatchStatementSet rules : sl) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
50 * ... |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
51 * } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
52 * </pre> |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
53 */ |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
54 @SupportedAnnotationTypes({"com.oracle.graal.compiler.match.MatchRule", "com.oracle.graal.compiler.match.MatchRules", "com.oracle.graal.compiler.match.MatchableNode", |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
55 "com.oracle.graal.compiler.match.MatchableNodes"}) |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
56 public class MatchProcessor extends AbstractProcessor { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
57 |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
58 public MatchProcessor() { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
59 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
60 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
61 @Override |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
62 public SourceVersion getSupportedSourceVersion() { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
63 return SourceVersion.latest(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
64 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
65 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
66 private final Set<Element> processedMatchRule = new HashSet<>(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
67 private final Set<Element> processedMatchableNode = new HashSet<>(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
68 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
69 private static class RuleParseError extends RuntimeException { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
70 private static final long serialVersionUID = 6456128283609257490L; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
71 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
72 RuleParseError(String format, Object... args) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
73 super(String.format(format, args)); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
74 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
75 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
76 |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
77 private static Pattern tokenizer = Pattern.compile("\\s*([()=]|[A-Za-z][A-Za-z0-9]*)\\s*"); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
78 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
79 private class RuleParser { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
80 private ArrayList<TypeDescriptor> capturedTypes = new ArrayList<>(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
81 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
82 private ArrayList<String> capturedNames = new ArrayList<>(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
83 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
84 private final String[] tokens; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
85 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
86 private int current; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
87 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
88 private MatchDescriptor matchDescriptor; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
89 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
90 private final Set<Element> originatingElements = new HashSet<>(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
91 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
92 RuleParser(String rule) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
93 Matcher m = tokenizer.matcher(rule); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
94 List<String> list = new ArrayList<>(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
95 int end = 0; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
96 while (m.lookingAt()) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
97 list.add(m.group(1)); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
98 end = m.end(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
99 m.region(m.end(), m.regionEnd()); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
100 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
101 if (end != m.regionEnd()) { |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
102 throw new RuleParseError("Unexpected tokens :" + rule.substring(m.end(), m.regionEnd())); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
103 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
104 tokens = list.toArray(new String[0]); |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
105 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
106 matchDescriptor = parseExpression(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
107 if (!done()) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
108 throw new RuleParseError("didn't consume all tokens"); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
109 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
110 capturedNames.add(0, "root"); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
111 capturedTypes.add(0, matchDescriptor.nodeType); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
112 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
113 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
114 String next() { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
115 return tokens[current++]; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
116 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
117 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
118 String peek(String name) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
119 if (current >= tokens.length) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
120 if (name == null) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
121 throw new RuleParseError("Out of tokens"); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
122 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
123 throw new RuleParseError("Out of tokens looking for %s", name); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
124 } |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
125 return tokens[current]; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
126 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
127 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
128 boolean done() { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
129 return current == tokens.length; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
130 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
131 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
132 private MatchDescriptor parseExpression() { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
133 if (peek("(").equals("(")) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
134 next(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
135 MatchDescriptor descriptor = parseType(true); |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
136 for (int n = 0; n < descriptor.nodeType.inputs.length; n++) { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
137 if (peek("(").equals("(")) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
138 descriptor.inputs[n] = parseExpression(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
139 } else { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
140 descriptor.inputs[n] = parseType(false); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
141 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
142 } |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
143 for (int n = 0; n < descriptor.nodeType.inputs.length; n++) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
144 if (descriptor.inputs[n] == null) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
145 throw new RuleParseError("not enough inputs for " + descriptor.name); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
146 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
147 } |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
148 if (peek(")").equals(")")) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
149 next(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
150 return descriptor; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
151 } |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
152 throw new RuleParseError("Too many arguments to " + descriptor.nodeType.nodeClass); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
153 } |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
154 throw new RuleParseError("Extra tokens following match pattern: " + peek(null)); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
155 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
156 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
157 private MatchDescriptor parseType(boolean forExpression) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
158 TypeDescriptor type = null; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
159 String name = null; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
160 if (Character.isUpperCase(peek("node type or name").charAt(0))) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
161 String token = next(); |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
162 type = knownTypes.get(token); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
163 if (type == null) { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
164 throw new RuleParseError("Unknown node type: " + token); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
165 } |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
166 if (peek("=").equals("=")) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
167 next(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
168 name = next(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
169 } |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
170 originatingElements.addAll(type.originatingElements); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
171 } else if (Character.isLowerCase(peek("name").charAt(0))) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
172 name = next(); |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
173 type = valueType; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
174 } else { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
175 throw new RuleParseError("Unexpected token \"%s\" when looking for name or node type", peek(null)); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
176 } |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
177 if (name != null) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
178 if (!capturedNames.contains(name)) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
179 capturedNames.add(name); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
180 capturedTypes.add(type); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
181 } else { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
182 int index = capturedNames.indexOf(name); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
183 if (capturedTypes.get(index) != type) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
184 throw new RuleParseError("Captured node \"%s\" has differing types", name); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
185 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
186 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
187 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
188 return new MatchDescriptor(type, name, forExpression); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
189 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
190 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
191 List<String> generateVariants() { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
192 return matchDescriptor.generateVariants(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
193 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
194 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
195 /** |
15548
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
196 * Recursively accumulate any required NodeClass.Position declarations. |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
197 */ |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
198 void generatePositionDeclarations(Set<String> declarations) { |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
199 matchDescriptor.generatePositionDeclarations(declarations); |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
200 } |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
201 |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
202 /** |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
203 * |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
204 * @return the list of node types which are captured by name |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
205 */ |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
206 public ArrayList<TypeDescriptor> capturedTypes() { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
207 return capturedTypes; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
208 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
209 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
210 public ArrayList<String> capturedNames() { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
211 return capturedNames; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
212 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
213 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
214 |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
215 /** |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
216 * Set to true to enable logging to a local file during annotation processing. There's no normal |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
217 * channel for any debug messages and debugging annotation processors requires some special |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
218 * setup. |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
219 */ |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
220 private static final boolean DEBUG = false; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
221 |
15844 | 222 private static final String LOGFILE = new File(System.getProperty("java.io.tmpdir"), "matchprocessor.log").getPath(); |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
223 |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
224 private static PrintWriter log; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
225 |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
226 /** |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
227 * Logging facility for the debugging the annotation processor. |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
228 */ |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
229 |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
230 private static synchronized PrintWriter getLog() { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
231 if (log == null) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
232 try { |
15844 | 233 log = new PrintWriter(new FileWriter(LOGFILE, true)); |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
234 } catch (IOException e) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
235 // Do nothing |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
236 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
237 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
238 return log; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
239 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
240 |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
241 private static synchronized void logMessage(String format, Object... args) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
242 if (!DEBUG) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
243 return; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
244 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
245 PrintWriter bw = getLog(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
246 if (bw != null) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
247 bw.printf(format, args); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
248 bw.flush(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
249 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
250 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
251 |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
252 private static synchronized void logException(Throwable t) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
253 if (!DEBUG) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
254 return; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
255 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
256 PrintWriter bw = getLog(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
257 if (bw != null) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
258 t.printStackTrace(bw); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
259 bw.flush(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
260 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
261 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
262 |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
263 /** |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
264 * Bugs in an annotation processor can cause silent failure so try to report any exception |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
265 * throws as errors. |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
266 */ |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
267 private void reportExceptionThrow(Element element, Throwable t) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
268 logMessage("throw for %s:\n", element); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
269 logException(t); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
270 processingEnv.getMessager().printMessage(Kind.ERROR, "Exception throw during processing: " + t.toString() + " " + Arrays.toString(Arrays.copyOf(t.getStackTrace(), 4)), element); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
271 } |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
272 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
273 static class TypeDescriptor { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
274 final TypeMirror mirror; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
275 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
276 /** |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
277 * The name uses in match expressions to refer to this type. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
278 */ |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
279 final String shortName; |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
280 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
281 /** |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
282 * The simple name of the {@link ValueNode} class represented by this type. |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
283 */ |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
284 final String nodeClass; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
285 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
286 /** |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
287 * The package of {@link ValueNode} class represented by this type. |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
288 */ |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
289 final String nodePackage; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
290 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
291 /** |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
292 * The matchable inputs of the node. |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
293 */ |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
294 final String[] inputs; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
295 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
296 /** |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
297 * Should swapped variants of this match be generated. The user of the match is expected to |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
298 * compensate for any ordering differences in compare which are commutative but require |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
299 * reinterpreting the condition in that case. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
300 */ |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
301 final boolean commutative; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
302 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
303 /** |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
304 * Can multiple users of this node subsume it. Constants can be swallowed into a match even |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
305 * if there are multiple users. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
306 */ |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15458
diff
changeset
|
307 final boolean shareable; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
308 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
309 final Set<Element> originatingElements = new HashSet<>(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
310 |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
311 TypeDescriptor(TypeMirror mirror, String shortName, String nodeClass, String nodePackage, String[] inputs, boolean commutative, boolean shareable) { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
312 this.mirror = mirror; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
313 this.shortName = shortName; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
314 this.nodeClass = nodeClass; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
315 this.nodePackage = nodePackage; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
316 this.inputs = inputs; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
317 this.commutative = commutative; |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15458
diff
changeset
|
318 this.shareable = shareable; |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
319 assert !commutative || inputs.length == 2; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
320 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
321 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
322 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
323 /** |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
324 * The types which are know for purpose of parsing MatchRule expressions. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
325 */ |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
326 Map<String, TypeDescriptor> knownTypes = new HashMap<>(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
327 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
328 /** |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
329 * The set of packages which must be imported to refer to the known classes. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
330 */ |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
331 List<String> requiredPackages = new ArrayList<>(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
332 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
333 /** |
15699
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
334 * The mapping between elements with MatchRules and the wrapper class used invoke the code |
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
335 * generation after the match. |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
336 */ |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
337 private Map<ExecutableElement, MethodInvokerItem> invokers = new LinkedHashMap<>(); |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
338 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
339 private TypeDescriptor valueType; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
340 |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
341 private TypeMirror matchRulesTypeMirror; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
342 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
343 private TypeMirror matchRuleTypeMirror; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
344 |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
345 private TypeMirror matchableNodeTypeMirror; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
346 |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
347 private TypeMirror matchableNodesTypeMirror; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
348 |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
349 private void declareType(TypeMirror mirror, String shortName, String nodeClass, String nodePackage, String[] inputs, boolean commutative, boolean shareable, Element element) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
350 TypeDescriptor descriptor = new TypeDescriptor(mirror, shortName, nodeClass, nodePackage, inputs, commutative, shareable); |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
351 descriptor.originatingElements.add(element); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
352 knownTypes.put(shortName, descriptor); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
353 if (!requiredPackages.contains(descriptor.nodePackage)) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
354 requiredPackages.add(descriptor.nodePackage); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
355 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
356 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
357 |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
358 private String findPackage(Element type) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
359 PackageElement p = processingEnv.getElementUtils().getPackageOf(type); |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
360 if (p != null) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
361 return p.getQualifiedName().toString(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
362 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
363 throw new GraalInternalError("can't find package for %s", type); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
364 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
365 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
366 class MatchDescriptor { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
367 TypeDescriptor nodeType; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
368 String name; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
369 MatchDescriptor[] inputs; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
370 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
371 MatchDescriptor(TypeDescriptor nodeType, String name, boolean forExpression) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
372 this.nodeType = nodeType; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
373 this.name = name; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
374 if (forExpression) { |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
375 this.inputs = new MatchDescriptor[nodeType.inputs.length]; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
376 } else { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
377 this.inputs = new MatchDescriptor[0]; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
378 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
379 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
380 |
15548
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
381 public void generatePositionDeclarations(Set<String> declarations) { |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
382 if (inputs.length == 0) { |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
383 return; |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
384 } |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
385 declarations.add(generatePositionDeclaration()); |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
386 for (MatchDescriptor desc : inputs) { |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
387 desc.generatePositionDeclarations(declarations); |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
388 } |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
389 } |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
390 |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
391 List<String> recurseVariants(int index) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
392 if (inputs.length == 0) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
393 return new ArrayList<>(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
394 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
395 List<String> currentVariants = inputs[index].generateVariants(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
396 if (index == inputs.length - 1) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
397 return currentVariants; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
398 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
399 List<String> subVariants = recurseVariants(index + 1); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
400 List<String> result = new ArrayList<>(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
401 for (String current : currentVariants) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
402 for (String sub : subVariants) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
403 result.add(current + ", " + sub); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
404 if (nodeType.commutative) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
405 result.add(sub + ", " + current); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
406 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
407 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
408 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
409 return result; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
410 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
411 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
412 /** |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
413 * Recursively generate all the variants of this rule pattern. Currently that just means to |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
414 * swap the inputs for commutative rules, producing all possible permutations. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
415 * |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
416 * @return a list of Strings which will construct pattern matchers for this rule. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
417 */ |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
418 List<String> generateVariants() { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
419 String prefix = formatPrefix(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
420 String suffix = formatSuffix(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
421 ArrayList<String> variants = new ArrayList<>(); |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
422 if (inputs.length > 0) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
423 for (String var : recurseVariants(0)) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
424 variants.add(prefix + ", " + var + suffix); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
425 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
426 } else { |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15458
diff
changeset
|
427 assert inputs.length == 0; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
428 variants.add(prefix + suffix); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
429 } |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
430 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
431 return variants; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
432 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
433 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
434 private String formatPrefix() { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
435 if (nodeType == valueType) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
436 return String.format("new MatchPattern(%s, false", name != null ? ("\"" + name + "\"") : "null"); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
437 } else { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
438 return String.format("new MatchPattern(%s.class, %s", nodeType.nodeClass, name != null ? ("\"" + name + "\"") : "null"); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
439 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
440 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
441 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
442 private String formatSuffix() { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
443 if (nodeType != null) { |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
444 if (inputs.length != nodeType.inputs.length) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
445 return ", true)"; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
446 } else { |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
447 if (nodeType.inputs.length > 0) { |
15548
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
448 return ", " + nodeType.nodeClass + "_positions, " + !nodeType.shareable + ")"; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
449 } |
15520
4cdc787681d4
add support for more nodes inputs
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15458
diff
changeset
|
450 if (nodeType.shareable) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
451 return ", false)"; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
452 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
453 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
454 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
455 return ")"; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
456 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
457 |
15548
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
458 String generatePositionDeclaration() { |
15700
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
459 return String.format("NodeClass.Position[] %s_positions = MatchRuleRegistry.findPositions(lookup, %s.class, new String[]{\"%s\"});", nodeType.nodeClass, nodeType.nodeClass, |
15548
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
460 String.join("\", \"", nodeType.inputs)); |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
461 } |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
462 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
463 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
464 /** |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
465 * Strip the package off a class name leaving the full class name including any outer classes. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
466 */ |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
467 private String fullClassName(Element element) { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
468 assert element.getKind() == ElementKind.CLASS || element.getKind() == ElementKind.INTERFACE : element; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
469 String pkg = findPackage(element); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
470 return ((TypeElement) element).getQualifiedName().toString().substring(pkg.length() + 1); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
471 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
472 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
473 private void createFiles(MatchRuleDescriptor info) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
474 String pkg = ((PackageElement) info.topDeclaringType.getEnclosingElement()).getQualifiedName().toString(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
475 Name topDeclaringClass = info.topDeclaringType.getSimpleName(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
476 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
477 String matchStatementClassName = topDeclaringClass + "_" + MatchStatementSet.class.getSimpleName(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
478 Element[] originatingElements = info.originatingElements.toArray(new Element[info.originatingElements.size()]); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
479 |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
480 Types typeUtils = typeUtils(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
481 Filer filer = processingEnv.getFiler(); |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
482 try (PrintWriter out = createSourceFile(pkg, matchStatementClassName, filer, originatingElements)) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
483 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
484 out.println("// CheckStyle: stop header check"); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
485 out.println("// GENERATED CONTENT - DO NOT EDIT"); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
486 out.println("// Source: " + topDeclaringClass + ".java"); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
487 out.println("package " + pkg + ";"); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
488 out.println(""); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
489 out.println("import java.util.*;"); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
490 out.println("import " + MatchStatementSet.class.getPackage().getName() + ".*;"); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
491 out.println("import " + NodeLIRBuilder.class.getName() + ";"); |
15548
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
492 out.println("import " + NodeClass.class.getName() + ";"); |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
493 for (String p : requiredPackages) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
494 out.println("import " + p + ".*;"); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
495 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
496 out.println(""); |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
497 out.println("public class " + matchStatementClassName + " implements " + MatchStatementSet.class.getSimpleName() + " {"); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
498 |
15548
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
499 out.println(); |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
500 |
15699
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
501 // Generate declarations for the wrapper class to invoke the code generation methods. |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
502 for (MethodInvokerItem invoker : invokers.values()) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
503 StringBuilder args = new StringBuilder(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
504 StringBuilder types = new StringBuilder(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
505 int count = invoker.fields.size(); |
15699
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
506 int index = 0; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
507 for (VariableElement arg : invoker.fields) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
508 args.append('"'); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
509 args.append(arg.getSimpleName()); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
510 args.append('"'); |
15699
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
511 types.append(String.format("(%s) args[%s]", fullClassName(typeUtils.asElement(arg.asType())), index++)); |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
512 if (count-- > 1) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
513 args.append(", "); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
514 types.append(", "); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
515 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
516 } |
15548
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
517 out.printf(" private static final String[] %s = new String[] {%s};\n", invoker.argumentsListName(), args); |
15699
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
518 out.printf(" private static final class %s implements MatchGenerator {\n", invoker.wrapperClass()); |
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
519 out.printf(" static MatchGenerator instance = new %s();\n", invoker.wrapperClass()); |
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
520 out.printf(" public ComplexMatchResult match(NodeLIRBuilder builder, Object...args) {\n"); |
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
521 out.printf(" return ((%s) builder).%s(%s);\n", invoker.nodeLIRBuilderClass, invoker.methodName, types); |
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
522 out.printf(" }\n"); |
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
523 out.printf(" public String getName() {\n"); |
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
524 out.printf(" return \"%s\";\n", invoker.methodName); |
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
525 out.printf(" }\n"); |
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
526 out.printf(" }\n"); |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
527 out.println(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
528 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
529 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
530 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
531 String desc = MatchStatement.class.getSimpleName(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
532 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
533 out.println(" public Class<? extends NodeLIRBuilder> forClass() {"); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
534 out.println(" return " + topDeclaringClass + ".class;"); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
535 out.println(" }"); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
536 out.println(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
537 out.println(" @Override"); |
15700
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
538 out.println(" public List<" + desc + "> statements(MatchRuleRegistry.NodeClassLookup lookup) {"); |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
539 |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
540 for (String positionDeclaration : info.positionDeclarations) { |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
541 out.println(" " + positionDeclaration); |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
542 } |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
543 out.println(); |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
544 |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
545 out.println(" // CheckStyle: stop line length check"); |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
546 out.println(" List<" + desc + "> statements = Collections.unmodifiableList(Arrays.asList("); |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
547 |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
548 int i = 0; |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
549 for (MatchRuleItem matchRule : info.matchRules) { |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
550 String comma = i == info.matchRules.size() - 1 ? "" : ","; |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
551 out.printf(" %s%s\n", matchRule.ruleBuilder(), comma); |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
552 i++; |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
553 } |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
554 out.println(" ));"); |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
555 out.println(" // CheckStyle: resume line length check"); |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
556 out.println(" return statements;"); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
557 out.println(" }"); |
15700
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
558 |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
559 out.println(); |
98423229008c
allow overriding the NodeClass lookup when building MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15699
diff
changeset
|
560 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
561 out.println("}"); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
562 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
563 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
564 try { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
565 createProviderFile(pkg, matchStatementClassName, originatingElements); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
566 } catch (IOException e) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
567 processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage(), info.topDeclaringType); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
568 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
569 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
570 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
571 private void createProviderFile(String pkg, String providerClassName, Element... originatingElements) throws IOException { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
572 String filename = "META-INF/providers/" + pkg + "." + providerClassName; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
573 FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, originatingElements); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
574 PrintWriter writer = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8")); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
575 writer.println(MatchStatementSet.class.getName()); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
576 writer.close(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
577 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
578 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
579 protected PrintWriter createSourceFile(String pkg, String relativeName, Filer filer, Element... originatingElements) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
580 try { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
581 // Ensure Unix line endings to comply with Graal code style guide checked by Checkstyle |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
582 JavaFileObject sourceFile = filer.createSourceFile(pkg + "." + relativeName, originatingElements); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
583 return new PrintWriter(sourceFile.openWriter()) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
584 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
585 @Override |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
586 public void println() { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
587 print("\n"); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
588 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
589 }; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
590 } catch (IOException e) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
591 throw new RuntimeException(e); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
592 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
593 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
594 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
595 /** |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
596 * Used to generate the MatchStatement constructor invocation. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
597 */ |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
598 static class MatchRuleItem { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
599 private final String matchPattern; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
600 private final MethodInvokerItem invoker; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
601 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
602 public MatchRuleItem(String matchPattern, MethodInvokerItem invoker) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
603 this.matchPattern = matchPattern; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
604 this.invoker = invoker; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
605 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
606 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
607 /** |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
608 * @return a string which will construct the MatchStatement instance to match this pattern. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
609 */ |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
610 public String ruleBuilder() { |
15699
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
611 return String.format("new MatchStatement(\"%s\", %s, %s.instance, %s)", invoker.name, matchPattern, invoker.wrapperClass(), invoker.argumentsListName()); |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
612 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
613 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
614 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
615 /** |
15699
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
616 * Used to generate the wrapper class to invoke the code generation method. |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
617 */ |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
618 static class MethodInvokerItem { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
619 final String name; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
620 final String nodeLIRBuilderClass; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
621 final String methodName; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
622 final List<? extends VariableElement> fields; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
623 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
624 MethodInvokerItem(String name, String nodeLIRBuilderClass, String methodName, List<? extends VariableElement> fields) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
625 this.name = name; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
626 this.nodeLIRBuilderClass = nodeLIRBuilderClass; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
627 this.methodName = methodName; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
628 this.fields = fields; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
629 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
630 |
15699
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
631 String wrapperClass() { |
423bf61c9c32
use inner classes instead of reflection during matching
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15548
diff
changeset
|
632 return "MatchGenerator_" + methodName; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
633 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
634 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
635 String argumentsListName() { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
636 return methodName + "_arguments"; |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
637 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
638 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
639 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
640 static class MatchRuleDescriptor { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
641 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
642 final TypeElement topDeclaringType; |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
643 final List<MatchRuleItem> matchRules = new ArrayList<>(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
644 private final Set<Element> originatingElements = new HashSet<>(); |
15548
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
645 public Set<String> positionDeclarations = new LinkedHashSet<>(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
646 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
647 public MatchRuleDescriptor(TypeElement topDeclaringType) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
648 this.topDeclaringType = topDeclaringType; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
649 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
650 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
651 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
652 private static TypeElement topDeclaringType(Element element) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
653 Element enclosing = element.getEnclosingElement(); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
654 if (enclosing == null || enclosing.getKind() == ElementKind.PACKAGE) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
655 assert element.getKind() == ElementKind.CLASS || element.getKind() == ElementKind.INTERFACE; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
656 return (TypeElement) element; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
657 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
658 return topDeclaringType(enclosing); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
659 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
660 |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
661 private AnnotationMirror findAnnotationMirror(Element element, TypeMirror typeMirror) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
662 for (AnnotationMirror mirror : element.getAnnotationMirrors()) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
663 if (typeUtils().isSameType(mirror.getAnnotationType(), typeMirror)) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
664 return mirror; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
665 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
666 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
667 return null; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
668 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
669 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
670 @Override |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
671 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
672 if (roundEnv.processingOver()) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
673 return true; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
674 } |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
675 logMessage("Starting round %s\n", roundEnv); |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
676 matchRulesTypeMirror = processingEnv.getElementUtils().getTypeElement(MatchRules.class.getCanonicalName()).asType(); |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
677 matchRuleTypeMirror = processingEnv.getElementUtils().getTypeElement(MatchRule.class.getCanonicalName()).asType(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
678 |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
679 matchableNodeTypeMirror = processingEnv.getElementUtils().getTypeElement(MatchableNode.class.getCanonicalName()).asType(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
680 matchableNodesTypeMirror = processingEnv.getElementUtils().getTypeElement(MatchableNodes.class.getCanonicalName()).asType(); |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
681 |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
682 try { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
683 // Define a TypeDescriptor for the generic node but don't enter it into the nodeTypes |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
684 // table since it shouldn't be mentioned in match rules. |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
685 TypeMirror valueTypeMirror = processingEnv.getElementUtils().getTypeElement(ValueNode.class.getName()).asType(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
686 valueType = new TypeDescriptor(valueTypeMirror, "Value", ValueNode.class.getSimpleName(), ValueNode.class.getPackage().getName(), new String[0], false, false); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
687 |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
688 Map<TypeElement, MatchRuleDescriptor> map = new LinkedHashMap<>(); |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
689 |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
690 for (Element element : roundEnv.getElementsAnnotatedWith(MatchRule.class)) { |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
691 processMatchRule(map, element, findAnnotationMirror(element, matchRuleTypeMirror)); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
692 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
693 for (Element element : roundEnv.getElementsAnnotatedWith(MatchRules.class)) { |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
694 processMatchRule(map, element, findAnnotationMirror(element, matchRulesTypeMirror)); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
695 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
696 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
697 for (MatchRuleDescriptor info : map.values()) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
698 createFiles(info); |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
699 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
700 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
701 } catch (Throwable t) { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
702 processingEnv.getMessager().printMessage(Kind.ERROR, "Exception throw during processing: " + t.toString() + " " + Arrays.toString(Arrays.copyOf(t.getStackTrace(), 2))); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
703 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
704 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
705 return true; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
706 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
707 |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
708 /** |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
709 * Build up the type table to be used during parsing of the MatchRule. |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
710 */ |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
711 private void processMatchableNode(Element element) { |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
712 if (!processedMatchableNode.contains(element)) { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
713 try { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
714 processedMatchableNode.add(element); |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
715 |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
716 AnnotationMirror mirror = findAnnotationMirror(element, matchableNodesTypeMirror); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
717 if (mirror == null) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
718 mirror = findAnnotationMirror(element, matchableNodeTypeMirror); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
719 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
720 if (mirror == null) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
721 return; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
722 } |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
723 TypeElement topDeclaringType = topDeclaringType(element); |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
724 List<AnnotationMirror> mirrors = null; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
725 if (typeUtils().isSameType(mirror.getAnnotationType(), matchableNodesTypeMirror)) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
726 // Unpack the mirrors for a repeatable annotation |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
727 mirrors = getAnnotationValueList(AnnotationMirror.class, mirror, "value"); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
728 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
729 int i = 0; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
730 for (MatchableNode matchableNode : element.getAnnotationsByType(MatchableNode.class)) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
731 processMatchableNode(element, topDeclaringType, matchableNode, mirrors != null ? mirrors.get(i++) : mirror); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
732 } |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
733 } catch (Throwable t) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
734 reportExceptionThrow(element, t); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
735 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
736 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
737 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
738 |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
739 private void processMatchableNode(Element element, TypeElement topDeclaringType, MatchableNode matchable, AnnotationMirror mirror) throws GraalInternalError { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
740 logMessage("processMatchableNode %s %s %s\n", topDeclaringType, element, matchable); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
741 String nodeClass; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
742 String nodePackage; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
743 TypeMirror nodeClassMirror = null; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
744 try { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
745 matchable.nodeClass(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
746 } catch (MirroredTypeException e) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
747 nodeClassMirror = e.getTypeMirror(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
748 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
749 if (nodeClassMirror == null) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
750 throw new GraalInternalError("Can't get mirror for node class %s", element); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
751 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
752 if (nodeClassMirror.toString().equals(MatchableNode.class.getName())) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
753 nodeClass = topDeclaringType.getQualifiedName().toString(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
754 } else { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
755 nodeClass = nodeClassMirror.toString(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
756 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
757 nodePackage = findPackage(processingEnv.getElementUtils().getTypeElement(nodeClass)); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
758 assert nodeClass.startsWith(nodePackage); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
759 nodeClass = nodeClass.substring(nodePackage.length() + 1); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
760 assert nodeClass.endsWith("Node"); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
761 String shortName = nodeClass.substring(0, nodeClass.length() - 4); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
762 |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
763 Types typeUtils = processingEnv.getTypeUtils(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
764 TypeElement nodeClassElement = (TypeElement) typeUtils.asElement(nodeClassMirror); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
765 for (String input : matchable.inputs()) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
766 boolean ok = false; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
767 TypeElement current = nodeClassElement; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
768 while (!ok && current != null) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
769 for (Element fieldElement : ElementFilter.fieldsIn(current.getEnclosedElements())) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
770 if (fieldElement.getSimpleName().toString().equals(input)) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
771 ok = true; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
772 break; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
773 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
774 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
775 TypeMirror theSuper = current.getSuperclass(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
776 current = (TypeElement) typeUtils.asElement(theSuper); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
777 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
778 if (!ok) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
779 String msg = String.format("Input named \"%s\" doesn't exist in %s", input, nodeClassElement.getSimpleName()); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
780 processingEnv.getMessager().printMessage(Kind.ERROR, msg, element, mirror); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
781 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
782 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
783 |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
784 declareType(nodeClassMirror, shortName, nodeClass, nodePackage, matchable.inputs(), matchable.commutative(), matchable.shareable(), element); |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
785 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
786 |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
787 private void processMatchRule(Map<TypeElement, MatchRuleDescriptor> map, Element element, AnnotationMirror mirror) { |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
788 if (!processedMatchRule.contains(element)) { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
789 try { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
790 processedMatchRule.add(element); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
791 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
792 // The annotation element type should ensure this is true. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
793 assert element instanceof ExecutableElement; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
794 |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
795 findMatchableNodes(element); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
796 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
797 TypeElement topDeclaringType = topDeclaringType(element); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
798 MatchRuleDescriptor info = map.get(topDeclaringType); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
799 if (info == null) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
800 info = new MatchRuleDescriptor(topDeclaringType); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
801 map.put(topDeclaringType, info); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
802 } |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
803 List<AnnotationMirror> mirrors = null; |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
804 if (typeUtils().isSameType(mirror.getAnnotationType(), matchRulesTypeMirror)) { |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
805 // Unpack the mirrors for a repeatable annotation |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
806 mirrors = getAnnotationValueList(AnnotationMirror.class, mirror, "value"); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
807 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
808 int i = 0; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
809 for (MatchRule matchRule : element.getAnnotationsByType(MatchRule.class)) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
810 processMethodMatchRule((ExecutableElement) element, info, matchRule, mirrors != null ? mirrors.get(i++) : mirror); |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
811 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
812 } catch (Throwable t) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
813 reportExceptionThrow(element, t); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
814 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
815 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
816 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
817 |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
818 /** |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
819 * Search the super types of element for MatchableNode definitions. Any superclass or super |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
820 * interface can contain definitions of matchable nodes. |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
821 * |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
822 * @param element |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
823 */ |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
824 private void findMatchableNodes(Element element) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
825 processMatchableNode(element); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
826 Element enclosing = element.getEnclosingElement(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
827 while (enclosing != null) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
828 if (enclosing.getKind() == ElementKind.CLASS || enclosing.getKind() == ElementKind.INTERFACE) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
829 TypeElement current = (TypeElement) enclosing; |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
830 while (current != null) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
831 processMatchableNode(current); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
832 for (TypeMirror intf : current.getInterfaces()) { |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
833 Element interfaceElement = typeUtils().asElement(intf); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
834 processMatchableNode(interfaceElement); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
835 // Recurse |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
836 findMatchableNodes(interfaceElement); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
837 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
838 TypeMirror theSuper = current.getSuperclass(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
839 current = (TypeElement) typeUtils().asElement(theSuper); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
840 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
841 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
842 enclosing = enclosing.getEnclosingElement(); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
843 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
844 } |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
845 |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
846 private Types typeUtils() { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
847 return processingEnv.getTypeUtils(); |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
848 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
849 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
850 private void processMethodMatchRule(ExecutableElement method, MatchRuleDescriptor info, MatchRule matchRule, AnnotationMirror mirror) { |
15547
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
851 logMessage("processMethodMatchRule %s %s\n", method, mirror); |
cab432461b8b
use NodeClass.Position when matching graphs, rearrange MatchableNode annotations, improve error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15521
diff
changeset
|
852 |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
853 Types typeUtils = typeUtils(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
854 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
855 if (!method.getModifiers().contains(Modifier.PUBLIC)) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
856 String msg = String.format("MatchRule method %s must be public", method.getSimpleName()); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
857 processingEnv.getMessager().printMessage(Kind.ERROR, msg, method); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
858 return; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
859 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
860 if (method.getModifiers().contains(Modifier.STATIC)) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
861 String msg = String.format("MatchRule method %s must be non-static", method.getSimpleName()); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
862 processingEnv.getMessager().printMessage(Kind.ERROR, msg, method); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
863 return; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
864 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
865 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
866 try { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
867 TypeMirror returnType = method.getReturnType(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
868 if (!typeUtils.isSameType(returnType, processingEnv.getElementUtils().getTypeElement(ComplexMatchResult.class.getName()).asType())) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
869 String msg = String.format("MatchRule method return type must be %s", ComplexMatchResult.class.getName()); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
870 processingEnv.getMessager().printMessage(Kind.ERROR, msg, method); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
871 return; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
872 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
873 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
874 String rule = matchRule.value(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
875 RuleParser parser = new RuleParser(rule); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
876 ArrayList<TypeDescriptor> expectedTypes = parser.capturedTypes(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
877 ArrayList<String> expectedNames = parser.capturedNames(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
878 List<? extends VariableElement> actualParameters = method.getParameters(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
879 if (expectedTypes.size() + 1 < actualParameters.size()) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
880 String msg = String.format("Too many arguments for match method %s %s", expectedTypes.size() + 1, actualParameters.size()); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
881 processingEnv.getMessager().printMessage(Kind.ERROR, msg, method); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
882 return; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
883 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
884 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
885 // Walk through the parameters to the method and see if they exist in the match rule. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
886 // The order doesn't matter but only names mentioned in the rule can be used and they |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
887 // must be assignment compatible. |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
888 for (VariableElement parameter : actualParameters) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
889 String name = parameter.getSimpleName().toString(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
890 int nameIndex = expectedNames.indexOf(name); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
891 if (nameIndex == -1) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
892 String msg = String.format("Argument \"%s\" isn't captured in the match rule", name); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
893 processingEnv.getMessager().printMessage(Kind.ERROR, msg, method); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
894 return; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
895 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
896 TypeMirror type = parameter.asType(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
897 if (!typeUtils.isAssignable(expectedTypes.get(nameIndex).mirror, type)) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
898 String msg = String.format("Captured value \"%s\" of type %s is not assignable to argument of type %s", name, expectedTypes.get(nameIndex).mirror, type); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
899 processingEnv.getMessager().printMessage(Kind.ERROR, msg, method); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
900 return; |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
901 } |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
902 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
903 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
904 MethodInvokerItem invoker = invokers.get(method); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
905 if (invoker == null) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
906 invoker = new MethodInvokerItem(method.getSimpleName().toString(), topDeclaringType(method).getSimpleName().toString(), method.getSimpleName().toString(), actualParameters); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
907 invokers.put(method, invoker); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
908 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
909 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
910 Element enclosing = method.getEnclosingElement(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
911 String declaringClass = ""; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
912 String separator = ""; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
913 Set<Element> originatingElementsList = info.originatingElements; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
914 originatingElementsList.add(method); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
915 while (enclosing != null) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
916 if (enclosing.getKind() == ElementKind.CLASS || enclosing.getKind() == ElementKind.INTERFACE) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
917 if (enclosing.getModifiers().contains(Modifier.PRIVATE)) { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
918 String msg = String.format("MatchRule cannot be declared in a private %s %s", enclosing.getKind().name().toLowerCase(), enclosing); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
919 processingEnv.getMessager().printMessage(Kind.ERROR, msg, method); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
920 return; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
921 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
922 originatingElementsList.add(enclosing); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
923 declaringClass = enclosing.getSimpleName() + separator + declaringClass; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
924 separator = "."; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
925 } else { |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
926 assert enclosing.getKind() == ElementKind.PACKAGE; |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
927 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
928 enclosing = enclosing.getEnclosingElement(); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
929 } |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
930 |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
931 originatingElementsList.addAll(parser.originatingElements); |
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
932 |
15548
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
933 // Accumulate any position declarations. |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
934 parser.generatePositionDeclarations(info.positionDeclarations); |
23dbc25b10a8
share position computations in MatchStatements
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15547
diff
changeset
|
935 |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
936 List<String> matches = parser.generateVariants(); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
937 for (String match : matches) { |
15453
100306ae985b
switch MatchRule from class to method annotation and fix review feedback
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15370
diff
changeset
|
938 info.matchRules.add(new MatchRuleItem(match, invoker)); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
939 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
940 } catch (RuleParseError e) { |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
941 processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage(), method, mirror); |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
942 } |
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
943 } |
15521
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
944 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
945 // TODO borrowed from com.oracle.truffle.dsl.processor.Utils |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
946 @SuppressWarnings("unchecked") |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
947 private static <T> List<T> getAnnotationValueList(Class<T> expectedListType, AnnotationMirror mirror, String name) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
948 List<? extends AnnotationValue> values = getAnnotationValue(List.class, mirror, name); |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
949 List<T> result = new ArrayList<>(); |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
950 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
951 if (values != null) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
952 for (AnnotationValue value : values) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
953 T annotationValue = resolveAnnotationValue(expectedListType, value); |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
954 if (annotationValue != null) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
955 result.add(annotationValue); |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
956 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
957 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
958 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
959 return result; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
960 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
961 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
962 private static <T> T getAnnotationValue(Class<T> expectedType, AnnotationMirror mirror, String name) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
963 return resolveAnnotationValue(expectedType, getAnnotationValue(mirror, name)); |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
964 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
965 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
966 @SuppressWarnings({"unchecked"}) |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
967 private static <T> T resolveAnnotationValue(Class<T> expectedType, AnnotationValue value) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
968 if (value == null) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
969 return null; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
970 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
971 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
972 Object unboxedValue = value.accept(new AnnotationValueVisitorImpl(), null); |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
973 if (unboxedValue != null) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
974 if (expectedType == TypeMirror.class && unboxedValue instanceof String) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
975 return null; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
976 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
977 if (!expectedType.isAssignableFrom(unboxedValue.getClass())) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
978 throw new ClassCastException(unboxedValue.getClass().getName() + " not assignable from " + expectedType.getName()); |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
979 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
980 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
981 return (T) unboxedValue; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
982 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
983 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
984 private static AnnotationValue getAnnotationValue(AnnotationMirror mirror, String name) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
985 ExecutableElement valueMethod = null; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
986 for (ExecutableElement method : ElementFilter.methodsIn(mirror.getAnnotationType().asElement().getEnclosedElements())) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
987 if (method.getSimpleName().toString().equals(name)) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
988 valueMethod = method; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
989 break; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
990 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
991 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
992 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
993 if (valueMethod == null) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
994 return null; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
995 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
996 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
997 AnnotationValue value = mirror.getElementValues().get(valueMethod); |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
998 if (value == null) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
999 value = valueMethod.getDefaultValue(); |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1000 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1001 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1002 return value; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1003 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1004 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1005 private static class AnnotationValueVisitorImpl extends AbstractAnnotationValueVisitor7<Object, Void> { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1006 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1007 @Override |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1008 public Object visitBoolean(boolean b, Void p) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1009 return Boolean.valueOf(b); |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1010 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1011 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1012 @Override |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1013 public Object visitByte(byte b, Void p) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1014 return Byte.valueOf(b); |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1015 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1016 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1017 @Override |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1018 public Object visitChar(char c, Void p) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1019 return c; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1020 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1021 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1022 @Override |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1023 public Object visitDouble(double d, Void p) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1024 return d; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1025 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1026 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1027 @Override |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1028 public Object visitFloat(float f, Void p) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1029 return f; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1030 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1031 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1032 @Override |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1033 public Object visitInt(int i, Void p) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1034 return i; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1035 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1036 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1037 @Override |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1038 public Object visitLong(long i, Void p) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1039 return i; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1040 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1041 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1042 @Override |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1043 public Object visitShort(short s, Void p) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1044 return s; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1045 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1046 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1047 @Override |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1048 public Object visitString(String s, Void p) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1049 return s; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1050 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1051 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1052 @Override |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1053 public Object visitType(TypeMirror t, Void p) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1054 return t; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1055 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1056 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1057 @Override |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1058 public Object visitEnumConstant(VariableElement c, Void p) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1059 return c; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1060 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1061 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1062 @Override |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1063 public Object visitAnnotation(AnnotationMirror a, Void p) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1064 return a; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1065 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1066 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1067 @Override |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1068 public Object visitArray(List<? extends AnnotationValue> vals, Void p) { |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1069 return vals; |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1070 } |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1071 |
76213c9350ad
improve annotation error reporting
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
15520
diff
changeset
|
1072 } |
15370
319deee16746
add support for matching multiple HIR nodes when lowering to LIR
Tom Rodriguez <tom.rodriguez@oracle.com>
parents:
diff
changeset
|
1073 } |