diff --git a/ChangeLog b/ChangeLog index 6e1e203..3ec9e1b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Sun May 24 02:08:47 2009 Minero Aoki + + * utilize final field. + Sun May 24 01:18:36 2009 Minero Aoki * net/loveruby/cflat/compiler/IRGenerator.java: reorder methods. diff --git a/net/loveruby/cflat/compiler/Compiler.java b/net/loveruby/cflat/compiler/Compiler.java index 9e18bee..81c4d9d 100644 --- a/net/loveruby/cflat/compiler/Compiler.java +++ b/net/loveruby/cflat/compiler/Compiler.java @@ -20,7 +20,7 @@ public class Compiler { new Compiler(ProgramName).commandMain(args); } - private ErrorHandler errorHandler; + private final ErrorHandler errorHandler; public Compiler(String programName) { this.errorHandler = new ErrorHandler(programName); @@ -111,7 +111,7 @@ public class Compiler { TypeTable types = opts.typeTable(); AST sem = semanticAnalyze(ast, types, opts); if (dumpSemant(sem, opts.mode())) return; - IR ir = new IRGenerator(errorHandler).generate(sem, types); + IR ir = new IRGenerator(types, errorHandler).generate(sem); if (dumpIR(ir, opts.mode())) return; String asm = generateAssembly(ir, opts); if (dumpAsm(asm, opts.mode())) return; @@ -124,17 +124,17 @@ public class Compiler { opts.loader(), errorHandler, opts.doesDebugParser()); } - public AST semanticAnalyze(AST ast, TypeTable typeTable, + public AST semanticAnalyze(AST ast, TypeTable types, Options opts) throws SemanticException { new LocalResolver(errorHandler).resolve(ast); - new TypeResolver(errorHandler).resolve(ast, typeTable); - typeTable.semanticCheck(errorHandler); + new TypeResolver(types, errorHandler).resolve(ast); + types.semanticCheck(errorHandler); if (opts.mode() == CompilerMode.DumpReference) { ast.dump(); return ast; } - new DereferenceChecker(errorHandler).check(ast, typeTable); - new TypeChecker(errorHandler).check(ast, typeTable); + new DereferenceChecker(types, errorHandler).check(ast); + new TypeChecker(types, errorHandler).check(ast); return ast; } diff --git a/net/loveruby/cflat/compiler/CompilerMode.java b/net/loveruby/cflat/compiler/CompilerMode.java index 352c317..d0658bc 100644 --- a/net/loveruby/cflat/compiler/CompilerMode.java +++ b/net/loveruby/cflat/compiler/CompilerMode.java @@ -45,7 +45,7 @@ enum CompilerMode { return m; } - private String option; + private final String option; CompilerMode(String option) { this.option = option; diff --git a/net/loveruby/cflat/compiler/DereferenceChecker.java b/net/loveruby/cflat/compiler/DereferenceChecker.java index e3f17d8..3500f76 100644 --- a/net/loveruby/cflat/compiler/DereferenceChecker.java +++ b/net/loveruby/cflat/compiler/DereferenceChecker.java @@ -8,19 +8,17 @@ import java.util.*; class DereferenceChecker extends Visitor { // #@@range/ctor{ - private ErrorHandler errorHandler; + private final TypeTable typeTable; + private final ErrorHandler errorHandler; - public DereferenceChecker(ErrorHandler h) { + public DereferenceChecker(TypeTable typeTable, ErrorHandler h) { + this.typeTable = typeTable; this.errorHandler = h; } // #@@} // #@@range/check_AST{ - private TypeTable typeTable; - - public void check(AST ast, TypeTable typeTable) - throws SemanticException { - this.typeTable = typeTable; + public void check(AST ast) throws SemanticException { for (DefinedVariable var : ast.definedVariables()) { checkToplevelVariable(var); } diff --git a/net/loveruby/cflat/compiler/IRGenerator.java b/net/loveruby/cflat/compiler/IRGenerator.java index 468076f..c4847ec 100644 --- a/net/loveruby/cflat/compiler/IRGenerator.java +++ b/net/loveruby/cflat/compiler/IRGenerator.java @@ -11,19 +11,18 @@ import net.loveruby.cflat.exception.*; import java.util.*; class IRGenerator implements ASTVisitor { - private ErrorHandler errorHandler; - private TypeTable typeTable; + private final TypeTable typeTable; + private final ErrorHandler errorHandler; // #@@range/ctor{ - public IRGenerator(ErrorHandler errorHandler) { + public IRGenerator(TypeTable typeTable, ErrorHandler errorHandler) { + this.typeTable = typeTable; this.errorHandler = errorHandler; } // #@@} // #@@range/generate{ - public IR generate(AST ast, TypeTable typeTable) - throws SemanticException { - this.typeTable = typeTable; + public IR generate(AST ast) throws SemanticException { for (DefinedVariable var : ast.definedVariables()) { if (var.hasInitializer()) { var.setIR(transformExpr(var.initializer())); @@ -33,7 +32,7 @@ class IRGenerator implements ASTVisitor { f.setIR(compileFunctionBody(f)); } if (errorHandler.errorOccured()) { - throw new SemanticException("Simplify failed."); + throw new SemanticException("IR generation failed."); } return ast.ir(); } @@ -43,11 +42,11 @@ class IRGenerator implements ASTVisitor { // Definitions // - private List stmts; - private LinkedList scopeStack; - private LinkedList