Skip to content

Commit 38efed7

Browse files
committed
Fix warnings
1 parent ec6d51e commit 38efed7

File tree

21 files changed

+188
-146
lines changed

21 files changed

+188
-146
lines changed

graalpython/com.oracle.graal.python.pegparser.test/src/com/oracle/graal/python/pegparser/ParserTestBase.java

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public class ParserTestBase {
6868
private static final String SCOPE_FILE_EXT = ".scope";
6969

7070
protected boolean printDifferenceDetails = false;
71-
protected boolean printFormatStringLiteralValues = false;
7271
protected int printOnlyDiffIfLenIsBigger = 1000;
7372

7473
private static final boolean REGENERATE_TREE = false;
@@ -77,8 +76,6 @@ public class ParserTestBase {
7776

7877
@Rule public TestName name = new TestName();
7978

80-
private SSTNode lastSST;
81-
8279
public ParserTestBase() {
8380
}
8481

@@ -91,6 +88,8 @@ private String getFileName() {
9188
// return PythonLanguage.newSource(context, src, getFileName(testFile));
9289
// }
9390

91+
// TODO
92+
@SuppressWarnings("unused")
9493
public ModTy parse(String src, String moduleName, int mode) {
9594

9695
ParserTokenizer tokenizer = new ParserTokenizer(src);
@@ -106,8 +105,6 @@ public ExprTy parse(String code) {
106105
Parser parser = new Parser(tokenizer, factory, fexpParser);
107106
ModTy result = (ModTy) parser.parse(InputType.FILE);
108107
lastParserErrorCallback = parser.getErrorCallback();
109-
// lastGlobalScope = ((PythonParserImpl) parser).getLastGlobaScope();
110-
// lastSST = ((PythonParserImpl) parser).getLastSST();
111108
return result;
112109
}
113110

@@ -123,18 +120,14 @@ public ExprTy parse(String code) {
123120
// return result;
124121
// }
125122

126-
protected SSTNode getLastSST() {
127-
return lastSST;
128-
}
129-
130-
public void checkSyntaxError(String source) throws Exception {
123+
public void checkSyntaxError(String source) {
131124
parse(source, getFileName(), 1);
132125
DefaultParserErrorCallback ec = (DefaultParserErrorCallback) lastParserErrorCallback;
133126
assertTrue("Expected Error.", ec.hasErrors());
134127
assertSame("Expected SyntaxError", ec.getErrors().get(0).getType(), ParserErrorCallback.ErrorType.Syntax);
135128
}
136129

137-
public void checkSyntaxErrorMessageContains(String source, String expectedMessage) throws Exception {
130+
public void checkSyntaxErrorMessageContains(String source, String expectedMessage) {
138131
parse(source, getFileName(), 1);
139132
DefaultParserErrorCallback ec = (DefaultParserErrorCallback) lastParserErrorCallback;
140133
assertTrue("Expected Error.", ec.hasErrors());
@@ -143,7 +136,7 @@ public void checkSyntaxErrorMessageContains(String source, String expectedMessag
143136
assertTrue("The expected message:\n\"" + expectedMessage + "\"\nwas not found in\n\"" + error.getMessage() + "\"", error.getMessage().contains(expectedMessage));
144137
}
145138

146-
public void checkSyntaxErrorMessage(String source, String expectedMessage) throws Exception {
139+
public void checkSyntaxErrorMessage(String source, String expectedMessage) {
147140
parse(source, getFileName(), 1);
148141
DefaultParserErrorCallback ec = (DefaultParserErrorCallback) lastParserErrorCallback;
149142
assertTrue("Expected Error.", ec.hasErrors());
@@ -152,11 +145,6 @@ public void checkSyntaxErrorMessage(String source, String expectedMessage) throw
152145
assertEquals("The expected message:\n\"" + expectedMessage + "\"\n was not found. The message is: \n\"" + error.getMessage() + "\"", error.getMessage(), expectedMessage);
153146
}
154147

155-
protected static boolean isSyntaxError(Exception e) throws Exception {
156-
// return InteropLibrary.getUncached().getExceptionType(e) == ExceptionType.PARSE_ERROR;
157-
return false;
158-
}
159-
160148
public void checkTreeFromFile(File testFile, boolean goldenFileNextToTestFile) throws Exception {
161149
assertTrue("The test files " + testFile.getAbsolutePath() + " was not found.", testFile.exists());
162150
String source = readFile(testFile);
@@ -254,10 +242,6 @@ public void checkScopeResult(String source, int mode) throws Exception {
254242
// }
255243

256244
protected String printTreeToString(SSTNode node) {
257-
return printTreeToString(node, true);
258-
}
259-
260-
protected String printTreeToString(SSTNode node, boolean printTmpSlots) {
261245
SSTTreePrinterVisitor visitor = new SSTTreePrinterVisitor();
262246
return node.accept(visitor);
263247
}
@@ -277,7 +261,7 @@ protected void assertDescriptionMatches(String actual, File goldenFile) throws E
277261
assertDescriptionMatches(actual, expected, goldenFile.getName());
278262
}
279263

280-
protected void assertDescriptionMatches(String actual, String expected, String someName) throws Exception {
264+
protected void assertDescriptionMatches(String actual, String expected, String someName) {
281265
final String expectedTrimmed = expected.trim();
282266
final String actualTrimmed = actual.trim();
283267

@@ -322,8 +306,7 @@ public File getTestFileFromTestAndTestMethod() {
322306
if (!testDir.exists()) {
323307
testDir.mkdir();
324308
}
325-
File testFile = new File(testDir, getFileName() + ".py");
326-
return testFile;
309+
return new File(testDir, getFileName() + ".py");
327310
}
328311

329312
public File getGoldenDataDir() {

graalpython/com.oracle.graal.python.pegparser.test/src/com/oracle/graal/python/pegparser/sst/SSTTreePrinterVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private String indent() {
5757
return sb.toString();
5858
}
5959

60-
private String addHeader(SSTNode node) {
60+
private static String addHeader(SSTNode node) {
6161
StringBuilder sb = new StringBuilder();
6262
sb.append(node.getClass().getSimpleName()).append("[").append(node.getStartOffset());
6363
sb.append(", ").append(node.getEndOffset()).append("]");
@@ -229,10 +229,10 @@ public String visit(ExprTy.Constant node) {
229229
sb.append(" Value: ");
230230
switch (node.kind) {
231231
case LONG:
232-
sb.append((Long) node.value);
232+
sb.append((long) node.value);
233233
break;
234234
case DOUBLE:
235-
sb.append((Double) node.value);
235+
sb.append((double) node.value);
236236
break;
237237
case COMPLEX:
238238
double[] val = (double[]) node.value;

graalpython/com.oracle.graal.python.pegparser.test/src/com/oracle/graal/python/tokenizer/TokenizerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public void testUnderscoreLiterals() throws Exception {
176176
}
177177

178178
@Test
179-
public void testInvalidUnderscoreLiterals() throws Exception {
179+
public void testInvalidUnderscoreLiterals() {
180180
String[] invalid = new String[]{
181181
// Trailing underscores:
182182
"0_", "42_", /* "1.4j_", */ "0x_", "0b1_", "0xf_", "0o5_", "0 if 1_Else 1",
@@ -248,7 +248,7 @@ public void testNewLines() {
248248
"Token NUMBER [10, 11] (3, 5) (3, 6) '2'"});
249249
}
250250

251-
private Token[] getTokens(String code) {
251+
private static Token[] getTokens(String code) {
252252
Tokenizer tokenizer = new Tokenizer(code, EnumSet.of(Tokenizer.Flag.EXECT_INPUT, Tokenizer.Flag.TYPE_COMMENT));
253253
Token token;
254254

@@ -265,7 +265,7 @@ private String getFileName() {
265265
return name.getMethodName();
266266
}
267267

268-
private void checkTokens(String code, String[] tokens) {
268+
private static void checkTokens(String code, String[] tokens) {
269269
Tokenizer tokenizer = new Tokenizer(code, EnumSet.of(Tokenizer.Flag.EXECT_INPUT, Tokenizer.Flag.TYPE_COMMENT));
270270
Token token = tokenizer.next();
271271
int index = 0;

graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/AbstractParser.java

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ abstract class AbstractParser {
6767
/**
6868
* Corresponds to TARGET_TYPES in CPython
6969
*/
70-
static public enum TargetsType {
70+
public enum TargetsType {
7171
STAR_TARGETS,
7272
DEL_TARGETS,
7373
FOR_TARGETS
74-
};
74+
}
7575

7676
/**
7777
* Corresponds to PyPARSE_BARRY_AS_BDFL, check whether <> should be used instead != .
@@ -94,7 +94,7 @@ static public enum TargetsType {
9494
* Indicates, whether there was found an error
9595
*/
9696
protected boolean errorIndicator = false;
97-
/** Currently used just for idicating, if there was readed something **/
97+
/** Currently used just for indicating, if something was read **/
9898
protected int fill;
9999

100100
private ExprTy.Name cachedDummyName;
@@ -220,7 +220,7 @@ public Token expect(String text) {
220220

221221
/**
222222
* Check if the next token that'll be read is if the expected kind. This has does not advance
223-
* the tokenizer, in contrast to {@link expect(int)}.
223+
* the tokenizer, in contrast to {@link #expect(int)}.
224224
*/
225225
protected boolean lookahead(boolean match, int kind) {
226226
int pos = mark();
@@ -231,7 +231,7 @@ protected boolean lookahead(boolean match, int kind) {
231231

232232
/**
233233
* Check if the next token that'll be read is if the expected kind. This has does not advance
234-
* the tokenizer, in contrast to {@link expect(String)}.
234+
* the tokenizer, in contrast to {@link #expect(String)}.
235235
*/
236236
protected boolean lookahead(boolean match, String text) {
237237
int pos = mark();
@@ -242,9 +242,6 @@ protected boolean lookahead(boolean match, String text) {
242242

243243
/**
244244
* Shortcut to Tokenizer.getText(Token)
245-
*
246-
* @param token
247-
* @return
248245
*/
249246
public String getText(Token token) {
250247
if (token == null) {
@@ -362,10 +359,10 @@ public ExprTy number_token() {
362359
/**
363360
* _PyPegen_expect_forced_token
364361
*/
365-
public Token expect_forced_token(int kind, String msg) {
362+
public Token expect_forced_token(int kind, String expected) {
366363
Token t = getAndInitializeToken();
367364
if (t.type != kind) {
368-
// TODO: raise error
365+
raiseSyntaxErrorKnownLocation(t, "expected '%s'", expected);
369366
return null;
370367
}
371368
tokenizer.getToken(); // advance
@@ -400,7 +397,7 @@ public ExprTy.Name soft_keyword_token() {
400397
/**
401398
* _PyPegen_dummy_name
402399
*/
403-
public ExprTy.Name dummyName(Object... args) {
400+
public ExprTy.Name dummyName(@SuppressWarnings("unused") Object... args) {
404401
if (cachedDummyName != null) {
405402
return cachedDummyName;
406403
}
@@ -532,11 +529,8 @@ public String getExprName(ExprTy e) {
532529
case NONE:
533530
return "None";
534531
case BOOLEAN:
535-
Boolean value = (Boolean) constant.value;
536-
if (value.booleanValue()) {
537-
return "True";
538-
}
539-
return "False";
532+
boolean value = (Boolean) constant.value;
533+
return value ? "True" : "False";
540534
case ELLIPSIS:
541535
return "Ellipsis";
542536
}
@@ -598,7 +592,7 @@ protected <T> T[] join(T[] a, T[] b) {
598592
return a;
599593
}
600594

601-
if (a != null && b != null) {
595+
if (a != null) {
602596
T[] result = Arrays.copyOf(a, a.length + b.length);
603597
System.arraycopy(b, 0, result, a.length, b.length);
604598
return result;
@@ -624,22 +618,11 @@ private void indent(StringBuffer sb) {
624618
}
625619
}
626620

627-
void debugMessage(String text) {
628-
debugMessage(text, true);
629-
}
630-
631-
void debugMessage(String text, boolean indent) {
632-
StringBuffer sb = new StringBuffer();
633-
indent(sb);
634-
sb.append(text);
635-
System.out.print(sb.toString());
636-
}
637-
638621
void debugMessageln(String text, Object... args) {
639622
StringBuffer sb = new StringBuffer();
640623
indent(sb);
641624
sb.append(String.format(text, args));
642-
System.out.println(sb.toString());
625+
System.out.println(sb);
643626
}
644627

645628
// Helper classes that are not really meaningful parts of the AST, just containers to move the
@@ -894,8 +877,6 @@ SSTNode raiseErrorKnownLocation(ParserErrorCallback.ErrorType typeError, SSTNode
894877

895878
/**
896879
* CHECK Simple check whether the node is not null.
897-
*
898-
* @return
899880
*/
900881
<T> T check(T node) {
901882
if (node == null) {
@@ -906,7 +887,7 @@ <T> T check(T node) {
906887

907888
@SuppressWarnings("unused")
908889
// TODO implement the check
909-
final <T> T checkVersion(int version, String msg, T node) {
890+
static <T> T checkVersion(int version, String msg, T node) {
910891
return node;
911892
}
912893
}

graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/DefaultParserErrorCallback.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@
4242
package com.oracle.graal.python.pegparser;
4343

4444
import java.util.ArrayList;
45-
import java.util.HashSet;
4645
import java.util.List;
47-
import java.util.Set;
4846

4947
public class DefaultParserErrorCallback implements ParserErrorCallback {
5048

graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/NodeFactoryImp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public ExprTy createNumber(String numberWithUnderscores, int startOffset, int en
251251

252252
@Override
253253
public ExprTy createString(String[] values, int startOffset, int endOffset, FExprParser exprParser, ParserErrorCallback errorCb) {
254-
return StringLiteralUtils.createStringLiteral(values, startOffset, endOffset, this, exprParser, errorCb);
254+
return StringLiteralUtils.createStringLiteral(values, startOffset, endOffset, exprParser, errorCb);
255255
}
256256

257257
@Override

graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/ParserTokenizer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@
4141
package com.oracle.graal.python.pegparser;
4242

4343
import java.util.ArrayList;
44+
import java.util.EnumSet;
45+
4446
import com.oracle.graal.python.pegparser.tokenizer.Token;
4547
import com.oracle.graal.python.pegparser.tokenizer.Tokenizer;
46-
import java.util.EnumSet;
4748

4849
public class ParserTokenizer {
4950
private int pos; // position of the mark
@@ -84,9 +85,9 @@ protected Token peekToken() {
8485
return tokens.get(pos);
8586
}
8687

87-
protected Token peekToken(int pos) {
88-
assert pos < tokens.size();
89-
return tokens.get(pos);
88+
protected Token peekToken(int position) {
89+
assert position < tokens.size();
90+
return tokens.get(position);
9091
}
9192

9293
public String getText(Token token) {

graalpython/com.oracle.graal.python.pegparser/src/com/oracle/graal/python/pegparser/RuleResultCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public T putResult(int pos, int ruleId, T node) {
8787
posCache = new HashMap<>();
8888
mainCache.put(pos, posCache);
8989
}
90-
posCache.put(ruleId, new CachedItem<T>(node, parser.mark()));
90+
posCache.put(ruleId, new CachedItem<>(node, parser.mark()));
9191
return node;
9292
}
9393

0 commit comments

Comments
 (0)