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

working on decl analyser

parent 0eaaa81d
No related branches found
No related tags found
No related merge requests found
Pipeline #24 passed with warnings with stages
in 7 minutes and 33 seconds
......@@ -60,7 +60,6 @@ public class DeclarationAnalyzer extends AbstractNodeAnalyzer<SymbolType> {
@Override
public SymbolType analyze(ClassDef classDef) {
System.out.println("debug: classdef");
// TODO: check how do I create a obj type.
return new ClassValueType(classDef.name.name);
}
......@@ -69,6 +68,7 @@ public class DeclarationAnalyzer extends AbstractNodeAnalyzer<SymbolType> {
System.out.println("debug: start funcDef: " + funcDef.getClass().getName());
assert funcDef.symTable == null;
sym = funcDef.symTable = new SymbolTable<SymbolType>(sym);
assert funcDef.symTable != null; // may suck if partial-compiling happens...
// Func parameter list
for(TypedVar param : funcDef.params) {
......@@ -85,6 +85,30 @@ public class DeclarationAnalyzer extends AbstractNodeAnalyzer<SymbolType> {
return new FuncType(ValueType.annotationToValueType(funcDef.returnType));
}
@Override
public SymbolType analyze(GlobalDecl globalDecl) {
String name = globalDecl.variable.name;
SymbolType T = globals.get(name);
if(T == null)
errors.semError(globalDecl, "global id '" + name + "' not found in global scope..");
if(sym == globals)
errors.semError(globalDecl, "global declaration '" + name + "' not allowed in global scope.");
//sym.put(name, T);
return T;
}
@Override
public SymbolType analyze(NonLocalDecl nonLocalDecl) {
String name = nonLocalDecl.variable.name;
SymbolType T = sym.get(name); // auto-iterate through the tree.
if(T == null)
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.");
return T;
}
// Just a helper..
@Override
public SymbolType analyze(TypedVar node) {
return ValueType.annotationToValueType(node.type);
......
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