Skip to content

Commit f4c8b6d

Browse files
committed
[GR-10012] merge Gihub PR #4
PullRequest: graalpython/62
2 parents 7505328 + b1aa81f commit f4c8b6d

File tree

5 files changed

+39
-18
lines changed

5 files changed

+39
-18
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
overlay: "04e081a67fa68810f0043968f7537f003ea8fbe6",
2+
overlay: "4c51f4dae2d670a4895aaafbe47780ac2541c008",
33

44
// ======================================================================================================
55
//

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/PythonLanguage.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ protected boolean isObjectOfLanguage(Object object) {
313313
protected Object findMetaObject(PythonContext context, Object value) {
314314
if (value != null) {
315315
if (value instanceof PythonObject) {
316-
return ((PythonObject) value).asPythonClass().getName();
316+
return ((PythonObject) value).asPythonClass();
317317
} else if (value instanceof PythonAbstractObject ||
318318
value instanceof Number ||
319319
value instanceof String ||
@@ -339,14 +339,16 @@ protected Iterable<Scope> findLocalScopes(PythonContext context, Node node, Fram
339339
for (Scope s : super.findLocalScopes(context, node, frame)) {
340340
scopes.add(s);
341341
}
342-
PythonObject globals = PArguments.getGlobals(frame);
343-
if (globals != null) {
344-
scopes.add(Scope.newBuilder("globals()", globals).build());
345-
}
346-
Frame generatorFrame = PArguments.getGeneratorFrame(frame);
347-
if (generatorFrame != null) {
348-
for (Scope s : super.findLocalScopes(context, node, generatorFrame)) {
349-
scopes.add(s);
342+
if (frame != null) {
343+
PythonObject globals = PArguments.getGlobals(frame);
344+
if (globals != null) {
345+
scopes.add(Scope.newBuilder("globals()", globals).build());
346+
}
347+
Frame generatorFrame = PArguments.getGeneratorFrame(frame);
348+
if (generatorFrame != null) {
349+
for (Scope s : super.findLocalScopes(context, node, generatorFrame)) {
350+
scopes.add(s);
351+
}
350352
}
351353
}
352354
return scopes;
@@ -356,6 +358,7 @@ protected Iterable<Scope> findLocalScopes(PythonContext context, Node node, Fram
356358
protected Iterable<Scope> findTopScopes(PythonContext context) {
357359
ArrayList<Scope> scopes = new ArrayList<>();
358360
scopes.add(Scope.newBuilder("__main__", context.getMainModule()).build());
361+
scopes.add(Scope.newBuilder("builtins", context.getBuiltins()).build());
359362
return scopes;
360363
}
361364

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/PythonBaseTreeTranslator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public Object visitChildren(RuleNode node) {
162162
}
163163

164164
protected void deriveSourceSection(RuleNode node, Object r) {
165-
if (r instanceof PNode) {
165+
if (r instanceof PNode && ((PNode) r).getSourceSection() == null) {
166166
SourceSection derivedSection = deriveSourceSection(node);
167167
if (derivedSection != null) {
168168
((PNode) r).assignSourceSection(derivedSection);
@@ -186,7 +186,7 @@ private SourceSection deriveSourceSection(RuleNode node) {
186186
} else if (node instanceof ParserRuleContext) {
187187
int start = ((ParserRuleContext) node).getStart().getStartIndex();
188188
int stop = ((ParserRuleContext) node).getStop().getStopIndex();
189-
return createSourceSection(start, stop - start);
189+
return createSourceSection(start, stop - start + 1);
190190
}
191191
return null;
192192
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/PythonParserImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ private static ParserRuleContext preParseWithAntlr(PythonCore core, Source sourc
9191
Token token = ((RecognitionException) e).getOffendingToken();
9292
line = token.getLine();
9393
column = token.getCharPositionInLine();
94-
} else if (e.getCause() instanceof NoViableAltException) {
95-
Token token = ((NoViableAltException) e.getCause()).getOffendingToken();
94+
} else if (e.getCause() instanceof RecognitionException) {
95+
Token token = ((RecognitionException) e.getCause()).getOffendingToken();
9696
line = token.getLine();
9797
column = token.getCharPositionInLine();
9898
} else {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/parser/antlr/DescriptiveBailErrorListener.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,15 @@
3838
*/
3939
package com.oracle.graal.python.parser.antlr;
4040

41-
import com.oracle.graal.python.runtime.PythonParser.PIncompleteSourceException;
42-
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
43-
4441
import org.antlr.v4.runtime.BaseErrorListener;
4542
import org.antlr.v4.runtime.RecognitionException;
4643
import org.antlr.v4.runtime.Recognizer;
44+
import org.antlr.v4.runtime.Token;
4745
import org.antlr.v4.runtime.misc.IntervalSet;
4846

47+
import com.oracle.graal.python.runtime.PythonParser.PIncompleteSourceException;
48+
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
49+
4950
/**
5051
* An error listener that immediately bails out of the parse (does not recover) and throws a runtime
5152
* exception with a descriptive error message.
@@ -73,7 +74,9 @@ public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
7374
throw handleRecognitionException;
7475
}
7576
}
76-
77+
if (offendingSymbol instanceof Token) {
78+
throw new RuntimeException(entireMessage, new EmptyRecognitionException(entireMessage, recognizer, (Token) offendingSymbol));
79+
}
7780
throw new RuntimeException(entireMessage, e);
7881
}
7982

@@ -83,4 +86,19 @@ private static PIncompleteSourceException handleRecognitionException(IntervalSet
8386
}
8487
return null;
8588
}
89+
90+
private static class EmptyRecognitionException extends RecognitionException {
91+
private static final long serialVersionUID = 1L;
92+
private Token offendingToken;
93+
94+
public EmptyRecognitionException(String message, Recognizer<?, ?> recognizer, Token offendingToken) {
95+
super(message, recognizer, offendingToken.getInputStream(), null);
96+
this.offendingToken = offendingToken;
97+
}
98+
99+
@Override
100+
public Token getOffendingToken() {
101+
return offendingToken;
102+
}
103+
}
86104
}

0 commit comments

Comments
 (0)