Skip to content

Commit 3def288

Browse files
committed
Make CoreModuleChecks methods non-static to avoid always passing the CoreModuleProcessor
1 parent d1a2518 commit 3def288

File tree

2 files changed

+20
-27
lines changed

2 files changed

+20
-27
lines changed

src/processor/java/org/truffleruby/processor/CoreModuleChecks.java

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@
2828
import com.oracle.truffle.api.library.CachedLibrary;
2929

3030
public class CoreModuleChecks {
31-
static void checks(
32-
CoreModuleProcessor processor,
33-
int[] lowerFixnum,
34-
CoreMethod coreMethod,
35-
TypeElement klass,
36-
boolean hasZeroArgument) {
31+
32+
final CoreModuleProcessor processor;
33+
34+
CoreModuleChecks(CoreModuleProcessor processor) {
35+
this.processor = processor;
36+
}
37+
38+
void checks(int[] lowerFixnum, CoreMethod coreMethod, TypeElement klass, boolean hasZeroArgument) {
3739
byte[] lowerArgs = null;
3840
List<ExecutableElement> specializationMethods = new ArrayList<>();
3941

@@ -52,10 +54,9 @@ static void checks(
5254
}
5355
specializationMethods.add(specializationMethod);
5456

55-
lowerArgs = checkLowerFixnumArguments(processor, specializationMethod, lowerArgs);
57+
lowerArgs = checkLowerFixnumArguments(specializationMethod, lowerArgs);
5658
if (coreMethod != null) {
5759
checkAmbiguousOptionalArguments(
58-
processor,
5960
coreMethod,
6061
specializationMethod,
6162
specializationAnnotation);
@@ -75,7 +76,7 @@ static void checks(
7576
}
7677

7778
if (coreMethod == null) { // @Primitive
78-
checkPrimitiveArguments(processor, specializationMethods);
79+
checkPrimitiveArguments(specializationMethods);
7980
}
8081

8182
// Verify against the lowerFixnum annotation
@@ -87,10 +88,7 @@ static void checks(
8788
}
8889
}
8990

90-
private static byte[] checkLowerFixnumArguments(
91-
CoreModuleProcessor processor,
92-
ExecutableElement specializationMethod,
93-
byte[] lowerArgs) {
91+
private byte[] checkLowerFixnumArguments(ExecutableElement specializationMethod, byte[] lowerArgs) {
9492
List<? extends VariableElement> parameters = specializationMethod.getParameters();
9593
int start = 0;
9694

@@ -135,8 +133,7 @@ private static boolean contains(int[] array, int value) {
135133
return false;
136134
}
137135

138-
private static void checkAmbiguousOptionalArguments(
139-
CoreModuleProcessor processor,
136+
private void checkAmbiguousOptionalArguments(
140137
CoreMethod coreMethod,
141138
ExecutableElement specializationMethod,
142139
Specialization specializationAnnotation) {
@@ -148,7 +145,7 @@ private static void checkAmbiguousOptionalArguments(
148145
processor.error("invalid block method parameter position for", specializationMethod);
149146
return;
150147
}
151-
isParameterBlock(processor, parameters.get(n));
148+
isParameterBlock(parameters.get(n));
152149
n--; // Ignore block argument.
153150
}
154151

@@ -170,13 +167,11 @@ private static void checkAmbiguousOptionalArguments(
170167
processor.error("invalid optional parameter count for", specializationMethod);
171168
continue;
172169
}
173-
isParameterUnguarded(processor, specializationAnnotation, parameters.get(n));
170+
isParameterUnguarded(specializationAnnotation, parameters.get(n));
174171
}
175172
}
176173

177-
private static void checkPrimitiveArguments(
178-
CoreModuleProcessor processor,
179-
List<ExecutableElement> specializationMethods) {
174+
private void checkPrimitiveArguments(List<ExecutableElement> specializationMethods) {
180175
boolean hasRubyProcLastArgument = false;
181176
for (ExecutableElement specialization : specializationMethods) {
182177
List<? extends VariableElement> parameters = specialization.getParameters();
@@ -214,10 +209,7 @@ private static int getLastParameterIndex(List<? extends VariableElement> paramet
214209
return n;
215210
}
216211

217-
private static void isParameterUnguarded(
218-
CoreModuleProcessor processor,
219-
Specialization specializationAnnotation,
220-
VariableElement parameter) {
212+
private void isParameterUnguarded(Specialization specializationAnnotation, VariableElement parameter) {
221213
String name = parameter.getSimpleName().toString();
222214

223215
// A specialization will only be called if the types of the arguments match its declared parameter
@@ -257,7 +249,7 @@ private static boolean isGuarded(String name, String[] guards) {
257249
return false;
258250
}
259251

260-
private static void isParameterBlock(CoreModuleProcessor processor, VariableElement parameter) {
252+
private void isParameterBlock(VariableElement parameter) {
261253
final TypeMirror blockType = parameter.asType();
262254

263255
if (!(processor.isSameType(blockType, processor.nilType) ||

src/processor/java/org/truffleruby/processor/CoreModuleProcessor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ private void processCoreModule(TypeElement coreModuleElement) throws IOException
139139
coreModule.value().replace("::", "/") + ".rb",
140140
(Element[]) null);
141141

142+
final CoreModuleChecks coreModuleChecks = new CoreModuleChecks(this);
142143

143144
try (PrintStream stream = new PrintStream(output.openOutputStream(), true, "UTF-8")) {
144145
try (PrintStream rubyStream = new PrintStream(rubyFile.openOutputStream(), true, "UTF-8")) {
@@ -183,7 +184,7 @@ private void processCoreModule(TypeElement coreModuleElement) throws IOException
183184
CoreMethod checkAmbiguous = coreMethod.optional() > 0 || coreMethod.needsBlock()
184185
? coreMethod
185186
: null;
186-
CoreModuleChecks.checks(this, coreMethod.lowerFixnum(), checkAmbiguous, klass, needsSelf);
187+
coreModuleChecks.checks(coreMethod.lowerFixnum(), checkAmbiguous, klass, needsSelf);
187188
processCoreMethod(stream, rubyStream, coreModuleElement, coreModule, klass, coreMethod);
188189
}
189190
}
@@ -201,7 +202,7 @@ private void processCoreModule(TypeElement coreModuleElement) throws IOException
201202
final Primitive primitive = e.getAnnotation(Primitive.class);
202203
if (primitive != null) {
203204
processPrimitive(stream, rubyPrimitives, coreModuleElement, klass, primitive);
204-
CoreModuleChecks.checks(this, primitive.lowerFixnum(), null, klass, true);
205+
coreModuleChecks.checks(primitive.lowerFixnum(), null, klass, true);
205206
}
206207
}
207208
}

0 commit comments

Comments
 (0)