mirror of https://github.com/aamine/cbc
r4732@macbookpro: aamine | 2009-05-04 19:00:37 +0900
* net/loveruby/cflat/compiler/LocalResolver.java: create ToplevelScope, ConstantTable here (instead of creating them in AST). * net/loveruby/cflat/ast/AST.java: do not create ToplevelScope, ConstantTable by myself. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4175 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
parent
4ff9cf1486
commit
4a93ac31fb
|
@ -1,3 +1,12 @@
|
|||
Mon May 4 19:00:33 2009 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* net/loveruby/cflat/compiler/LocalResolver.java: create
|
||||
ToplevelScope, ConstantTable here (instead of creating them in
|
||||
AST).
|
||||
|
||||
* net/loveruby/cflat/ast/AST.java: do not create ToplevelScope,
|
||||
ConstantTable by myself.
|
||||
|
||||
Sun May 3 22:17:57 2009 Minero Aoki <aamine@loveruby.net>
|
||||
|
||||
* net/loveruby/cflat/compiler/Compiler.java: new method dumpExpr
|
||||
|
|
|
@ -17,8 +17,6 @@ public class AST extends Node {
|
|||
super();
|
||||
this.source = source;
|
||||
this.declarations = declarations;
|
||||
this.scope = new ToplevelScope();
|
||||
this.constantTable = new ConstantTable();
|
||||
}
|
||||
|
||||
public Location location() {
|
||||
|
@ -29,17 +27,6 @@ public class AST extends Node {
|
|||
return source.token();
|
||||
}
|
||||
|
||||
public void setTypeTable(TypeTable table) {
|
||||
if (typeTable != null) {
|
||||
throw new Error("must not happen: typeTable != null");
|
||||
}
|
||||
this.typeTable = table;
|
||||
}
|
||||
|
||||
public TypeTable typeTable() {
|
||||
return this.typeTable;
|
||||
}
|
||||
|
||||
public List<TypeDefinition> types() {
|
||||
List<TypeDefinition> result = new ArrayList<TypeDefinition>();
|
||||
result.addAll(declarations.defstructs());
|
||||
|
@ -70,11 +57,48 @@ public class AST extends Node {
|
|||
return declarations.defuns();
|
||||
}
|
||||
|
||||
// called by Compiler
|
||||
public void setTypeTable(TypeTable table) {
|
||||
if (typeTable != null) {
|
||||
throw new Error("must not happen: AST.typeTable set twice");
|
||||
}
|
||||
this.typeTable = table;
|
||||
}
|
||||
|
||||
public TypeTable typeTable() {
|
||||
if (typeTable == null) {
|
||||
throw new Error("must not happen: AST.typeTable is null");
|
||||
}
|
||||
return this.typeTable;
|
||||
}
|
||||
|
||||
// called by LocalResolver
|
||||
public void setScope(ToplevelScope scope) {
|
||||
if (this.scope != null) {
|
||||
throw new Error("must not happen: ToplevelScope set twice");
|
||||
}
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public ToplevelScope scope() {
|
||||
if (this.scope == null) {
|
||||
throw new Error("must not happen: AST.scope is null");
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
|
||||
// called by LocalResolver
|
||||
public void setConstantTable(ConstantTable table) {
|
||||
if (this.constantTable != null) {
|
||||
throw new Error("must not happen: ConstantTable set twice");
|
||||
}
|
||||
this.constantTable = table;
|
||||
}
|
||||
|
||||
public ConstantTable constantTable() {
|
||||
if (this.constantTable == null) {
|
||||
throw new Error("must not happen: AST.constantTable is null");
|
||||
}
|
||||
return constantTable;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,10 +26,10 @@ public class LocalResolver extends Visitor {
|
|||
|
||||
// #@@range/resolve{
|
||||
public void resolve(AST ast) throws SemanticException {
|
||||
toplevel = ast.scope();
|
||||
toplevel = new ToplevelScope();
|
||||
scopeStack = new LinkedList<Scope>();
|
||||
scopeStack.add(toplevel);
|
||||
constantTable = ast.constantTable();
|
||||
constantTable = new ConstantTable();
|
||||
|
||||
// #@@range/declareToplevel{
|
||||
for (Entity decl : ast.declarations()) {
|
||||
|
@ -47,6 +47,9 @@ public class LocalResolver extends Visitor {
|
|||
if (errorHandler.errorOccured()) {
|
||||
throw new SemanticException("compile failed.");
|
||||
}
|
||||
|
||||
ast.setScope(toplevel);
|
||||
ast.setConstantTable(constantTable);
|
||||
}
|
||||
// #@@}
|
||||
|
||||
|
|
Loading…
Reference in New Issue