Skip to content
Snippets Groups Projects
Verified Commit 6b771591 authored by Recolic Keghart's avatar Recolic Keghart
Browse files

nonlocal_forward pass

parent 17598816
No related branches found
No related tags found
No related merge requests found
Pipeline #51 passed with warnings with stages
in 3 minutes and 56 seconds
......@@ -196,7 +196,6 @@ public class TypeChecker extends AbstractNodeAnalyzer<SymbolType> {
public SymbolType analyze(GlobalDecl globalDecl) {
String name = globalDecl.variable.name;
SymbolType T = globals.get(name);
System.out.println("DEBUG< GOL< " + isBuildingSym + " buildingSym, name=" + name + ", Type=" + T);
if(T == null) {
if(isBuildingSym)
return OBJECT_TYPE; // workaround for fucking use-before-decl
......@@ -213,14 +212,16 @@ public class TypeChecker extends AbstractNodeAnalyzer<SymbolType> {
@Override
public SymbolType analyze(NonLocalDecl nonLocalDecl) {
String name = nonLocalDecl.variable.name;
SymbolType T = sym.get(name); // auto-iterate through the tree.
if(sym.getParent() == null) {
errors.semError(nonLocalDecl, "nonlocal declaration '" + name + "' not allowed in global scope.");
}
SymbolType T = sym.getParent().get(name); // auto-iterate through the tree.
System.out.println("DEBUG< NONL< " + isBuildingSym + " buildingSym, name=" + name + ", Type=" + T);
if(T == null) {
if(isBuildingSym)
return OBJECT_TYPE;
errors.semError(nonLocalDecl, "nonlocal id '" + name + "' not found in parent scope..");
}
if(sym == globals)
errors.semError(nonLocalDecl, "nonlocal declaration '" + name + "' not allowed in global scope.");
if(!isBuildingSym)
// dirty! see comment in StudentAnalysis.java
sym.overwrite_put(name, T);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment