17
17
import javax .lang .model .element .VariableElement ;
18
18
import javax .lang .model .type .TypeKind ;
19
19
import javax .lang .model .type .TypeMirror ;
20
- import javax .lang .model .util .Elements ;
21
- import javax .lang .model .util .Types ;
22
20
import javax .tools .Diagnostic ;
23
21
24
22
import com .oracle .truffle .api .dsl .CachedLanguage ;
31
29
32
30
public class CoreModuleChecks {
33
31
static void checks (
34
- CoreModuleProcessor coreModuleProcessor ,
32
+ CoreModuleProcessor processor ,
35
33
int [] lowerFixnum ,
36
34
CoreMethod coreMethod ,
37
35
TypeElement klass ,
38
36
boolean hasZeroArgument ) {
39
37
byte [] lowerArgs = null ;
40
38
41
39
TypeElement klassIt = klass ;
42
- while (!coreModuleProcessor .isNodeBaseType (klassIt )) {
40
+ while (!processor .isNodeBaseType (klassIt )) {
43
41
for (Element el : klassIt .getEnclosedElements ()) {
44
42
if (!(el instanceof ExecutableElement )) {
45
43
continue ; // we are interested only in executable elements
@@ -52,25 +50,25 @@ static void checks(
52
50
continue ; // we are interested only in Specialization methods
53
51
}
54
52
55
- lowerArgs = checkLowerFixnumArguments (coreModuleProcessor , specializationMethod , lowerArgs );
53
+ lowerArgs = checkLowerFixnumArguments (processor , specializationMethod , lowerArgs );
56
54
if (coreMethod != null ) {
57
55
checkAmbiguousOptionalArguments (
58
- coreModuleProcessor ,
56
+ processor ,
59
57
coreMethod ,
60
58
specializationMethod ,
61
59
specializationAnnotation );
62
60
}
63
61
64
62
}
65
63
66
- klassIt = coreModuleProcessor
64
+ klassIt = processor
67
65
.getProcessingEnvironment ()
68
66
.getElementUtils ()
69
67
.getTypeElement (klassIt .getSuperclass ().toString ());
70
68
}
71
69
72
70
if (lowerArgs == null ) {
73
- coreModuleProcessor .getProcessingEnvironment ().getMessager ().printMessage (
71
+ processor .getProcessingEnvironment ().getMessager ().printMessage (
74
72
Diagnostic .Kind .ERROR ,
75
73
"could not find specializations (lowerArgs == null)" ,
76
74
klass );
@@ -81,7 +79,7 @@ static void checks(
81
79
for (int i = 0 ; i < lowerArgs .length ; i ++) {
82
80
boolean shouldLower = lowerArgs [i ] == 0b01; // int without long
83
81
if (shouldLower && !contains (lowerFixnum , hasZeroArgument ? i : i + 1 )) {
84
- coreModuleProcessor .getProcessingEnvironment ().getMessager ().printMessage (
82
+ processor .getProcessingEnvironment ().getMessager ().printMessage (
85
83
Diagnostic .Kind .ERROR ,
86
84
"should use lowerFixnum for argument " + (hasZeroArgument ? i : i + 1 ),
87
85
klass );
@@ -90,16 +88,13 @@ static void checks(
90
88
}
91
89
92
90
private static byte [] checkLowerFixnumArguments (
93
- CoreModuleProcessor coreModuleProcessor ,
91
+ CoreModuleProcessor processor ,
94
92
ExecutableElement specializationMethod ,
95
93
byte [] lowerArgs ) {
96
94
List <? extends VariableElement > parameters = specializationMethod .getParameters ();
97
95
int start = 0 ;
98
96
99
- if (parameters .size () > 0 &&
100
- coreModuleProcessor .getProcessingEnvironment ().getTypeUtils ().isSameType (
101
- parameters .get (0 ).asType (),
102
- coreModuleProcessor .virtualFrameType )) {
97
+ if (parameters .size () > 0 && processor .isSameType (parameters .get (0 ).asType (), processor .virtualFrameType )) {
103
98
start ++;
104
99
}
105
100
@@ -141,7 +136,7 @@ private static boolean contains(int[] array, int value) {
141
136
}
142
137
143
138
private static void checkAmbiguousOptionalArguments (
144
- CoreModuleProcessor coreModuleProcessor ,
139
+ CoreModuleProcessor processor ,
145
140
CoreMethod coreMethod ,
146
141
ExecutableElement specializationMethod ,
147
142
Specialization specializationAnnotation ) {
@@ -158,27 +153,27 @@ private static void checkAmbiguousOptionalArguments(
158
153
159
154
if (coreMethod .needsBlock ()) {
160
155
if (n < 0 ) {
161
- coreModuleProcessor .getProcessingEnvironment ().getMessager ().printMessage (
156
+ processor .getProcessingEnvironment ().getMessager ().printMessage (
162
157
Diagnostic .Kind .ERROR ,
163
158
"invalid block method parameter position for" ,
164
159
specializationMethod );
165
160
return ;
166
161
}
167
- isParameterBlock (coreModuleProcessor , parameters .get (n ));
162
+ isParameterBlock (processor , parameters .get (n ));
168
163
n --; // Ignore block argument.
169
164
}
170
165
171
166
if (coreMethod .rest ()) {
172
167
if (n < 0 ) {
173
- coreModuleProcessor .getProcessingEnvironment ().getMessager ().printMessage (
168
+ processor .getProcessingEnvironment ().getMessager ().printMessage (
174
169
Diagnostic .Kind .ERROR ,
175
170
"missing rest method parameter" ,
176
171
specializationMethod );
177
172
return ;
178
173
}
179
174
180
175
if (parameters .get (n ).asType ().getKind () != TypeKind .ARRAY ) {
181
- coreModuleProcessor .getProcessingEnvironment ().getMessager ().printMessage (
176
+ processor .getProcessingEnvironment ().getMessager ().printMessage (
182
177
Diagnostic .Kind .ERROR ,
183
178
"rest method parameter is not array" ,
184
179
parameters .get (n ));
@@ -189,18 +184,18 @@ private static void checkAmbiguousOptionalArguments(
189
184
190
185
for (int i = 0 ; i < coreMethod .optional (); i ++, n --) {
191
186
if (n < 0 ) {
192
- coreModuleProcessor .getProcessingEnvironment ().getMessager ().printMessage (
187
+ processor .getProcessingEnvironment ().getMessager ().printMessage (
193
188
Diagnostic .Kind .ERROR ,
194
189
"invalid optional parameter count for" ,
195
190
specializationMethod );
196
191
continue ;
197
192
}
198
- isParameterUnguarded (coreModuleProcessor , specializationAnnotation , parameters .get (n ));
193
+ isParameterUnguarded (processor , specializationAnnotation , parameters .get (n ));
199
194
}
200
195
}
201
196
202
197
private static void isParameterUnguarded (
203
- CoreModuleProcessor coreModuleProcessor ,
198
+ CoreModuleProcessor processor ,
204
199
Specialization specializationAnnotation ,
205
200
VariableElement parameter ) {
206
201
String name = parameter .getSimpleName ().toString ();
@@ -215,13 +210,13 @@ private static void isParameterUnguarded(
215
210
// it clear in the parameter name (by using unused or maybe prefix) that it may not have been
216
211
// provided or is not used.
217
212
218
- if (coreModuleProcessor . getProcessingEnvironment (). getTypeUtils () .isSameType (
213
+ if (processor .isSameType (
219
214
parameter .asType (),
220
- coreModuleProcessor .objectType ) &&
215
+ processor .objectType ) &&
221
216
!name .startsWith ("unused" ) &&
222
217
!name .startsWith ("maybe" ) &&
223
218
!isGuarded (name , specializationAnnotation .guards ())) {
224
- coreModuleProcessor .getProcessingEnvironment ().getMessager ().printMessage (
219
+ processor .getProcessingEnvironment ().getMessager ().printMessage (
225
220
Diagnostic .Kind .ERROR ,
226
221
"Since Object is the super type of NotProvided any optional parameter declaration of type Object " +
227
222
"must have additional guards to check whether this specialization should be called, " +
@@ -243,20 +238,13 @@ private static boolean isGuarded(String name, String[] guards) {
243
238
return false ;
244
239
}
245
240
246
- private static void isParameterBlock (
247
- CoreModuleProcessor coreModuleProcessor ,
248
- VariableElement parameter ) {
249
- TypeMirror blockType = parameter .asType ();
250
- Types typeUtils = coreModuleProcessor .getProcessingEnvironment ().getTypeUtils ();
251
- Elements elementUtils = coreModuleProcessor .getProcessingEnvironment ().getElementUtils ();
252
- boolean isNil = typeUtils
253
- .isSameType (blockType , elementUtils .getTypeElement ("org.truffleruby.language.Nil" ).asType ());
254
- boolean isRubyProc = typeUtils
255
- .isSameType (blockType , elementUtils .getTypeElement ("org.truffleruby.core.proc.RubyProc" ).asType ());
256
- boolean isObject = typeUtils .isSameType (blockType , coreModuleProcessor .objectType );
241
+ private static void isParameterBlock (CoreModuleProcessor processor , VariableElement parameter ) {
242
+ final TypeMirror blockType = parameter .asType ();
257
243
258
- if (!(isNil || isRubyProc || isObject )) {
259
- coreModuleProcessor .getProcessingEnvironment ().getMessager ().printMessage (
244
+ if (!(processor .isSameType (blockType , processor .nilType ) ||
245
+ processor .isSameType (blockType , processor .rubyProcType ) ||
246
+ processor .isSameType (blockType , processor .objectType ))) {
247
+ processor .getProcessingEnvironment ().getMessager ().printMessage (
260
248
Diagnostic .Kind .ERROR ,
261
249
"A block parameter must be of type Nil, RubyProc or Object." ,
262
250
parameter );
0 commit comments