* net/loveruby/cflat/compiler/Visitor.java: make all return types generic.

* net/loveruby/cflat/compiler/TypeChecker.java: ditto.
* net/loveruby/cflat/ast/*.java: ditto.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4132 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
Minero Aoki 2009-04-12 06:31:12 +00:00
parent 33dcef983b
commit d514300aef
49 changed files with 105 additions and 96 deletions

View File

@ -1,3 +1,12 @@
Sun Apr 12 15:31:07 2009 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/compiler/Visitor.java: make all return types
generic.
* net/loveruby/cflat/compiler/TypeChecker.java: ditto.
* net/loveruby/cflat/ast/*.java: ditto.
Mon Apr 6 07:04:30 2009 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/compiler/Compiler.java: call JumpResolver at

View File

@ -1,50 +1,50 @@
package net.loveruby.cflat.ast;
public interface ASTVisitor {
public interface ASTVisitor<S, E> {
// Declarations
public DefinedVariable visit(DefinedVariable var);
public UndefinedVariable visit(UndefinedVariable var);
public DefinedFunction visit(DefinedFunction func);
public UndefinedFunction visit(UndefinedFunction func);
public StructNode visit(StructNode struct);
public UnionNode visit(UnionNode union);
public TypedefNode visit(TypedefNode typedef);
public S visit(DefinedVariable var);
public S visit(UndefinedVariable var);
public S visit(DefinedFunction func);
public S visit(UndefinedFunction func);
public S visit(StructNode struct);
public S visit(UnionNode union);
public S visit(TypedefNode typedef);
// Statements
public BlockNode visit(BlockNode node);
public ExprStmtNode visit(ExprStmtNode node);
public IfNode visit(IfNode node);
public SwitchNode visit(SwitchNode node);
public CaseNode visit(CaseNode node);
public WhileNode visit(WhileNode node);
public DoWhileNode visit(DoWhileNode node);
public ForNode visit(ForNode node);
public BreakNode visit(BreakNode node);
public ContinueNode visit(ContinueNode node);
public GotoNode visit(GotoNode node);
public LabelNode visit(LabelNode node);
public ReturnNode visit(ReturnNode node);
public S visit(BlockNode node);
public S visit(ExprStmtNode node);
public S visit(IfNode node);
public S visit(SwitchNode node);
public S visit(CaseNode node);
public S visit(WhileNode node);
public S visit(DoWhileNode node);
public S visit(ForNode node);
public S visit(BreakNode node);
public S visit(ContinueNode node);
public S visit(GotoNode node);
public S visit(LabelNode node);
public S visit(ReturnNode node);
// Expressions
public AssignNode visit(AssignNode node);
public OpAssignNode visit(OpAssignNode node);
public CondExprNode visit(CondExprNode node);
public LogicalOrNode visit(LogicalOrNode node);
public LogicalAndNode visit(LogicalAndNode node);
public BinaryOpNode visit(BinaryOpNode node);
public UnaryOpNode visit(UnaryOpNode node);
public PrefixOpNode visit(PrefixOpNode node);
public SuffixOpNode visit(SuffixOpNode node);
public ArefNode visit(ArefNode node);
public MemberNode visit(MemberNode node);
public PtrMemberNode visit(PtrMemberNode node);
public FuncallNode visit(FuncallNode node);
public DereferenceNode visit(DereferenceNode node);
public AddressNode visit(AddressNode node);
public CastNode visit(CastNode node);
public SizeofExprNode visit(SizeofExprNode node);
public SizeofTypeNode visit(SizeofTypeNode node);
public VariableNode visit(VariableNode node);
public IntegerLiteralNode visit(IntegerLiteralNode node);
public StringLiteralNode visit(StringLiteralNode node);
public E visit(AssignNode node);
public E visit(OpAssignNode node);
public E visit(CondExprNode node);
public E visit(LogicalOrNode node);
public E visit(LogicalAndNode node);
public E visit(BinaryOpNode node);
public E visit(UnaryOpNode node);
public E visit(PrefixOpNode node);
public E visit(SuffixOpNode node);
public E visit(ArefNode node);
public E visit(MemberNode node);
public E visit(PtrMemberNode node);
public E visit(FuncallNode node);
public E visit(DereferenceNode node);
public E visit(AddressNode node);
public E visit(CastNode node);
public E visit(SizeofExprNode node);
public E visit(SizeofTypeNode node);
public E visit(VariableNode node);
public E visit(IntegerLiteralNode node);
public E visit(StringLiteralNode node);
}

View File

@ -24,7 +24,7 @@ public class AddressNode extends UnaryOpNode {
this.type = type;
}
public AddressNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -60,7 +60,7 @@ public class ArefNode extends ExprNode {
d.printMember("index", index);
}
public ArefNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}

View File

@ -5,7 +5,7 @@ public class AssignNode extends AbstractAssignNode {
super(lhs, rhs);
}
public AssignNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -53,7 +53,7 @@ public class BinaryOpNode extends ExprNode {
d.printMember("right", right);
}
public BinaryOpNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -38,7 +38,7 @@ public class BlockNode extends StmtNode {
d.printNodeList("stmts", stmts);
}
public BlockNode accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -26,7 +26,7 @@ public class BreakNode extends StmtNode {
protected void _dump(Dumper d) {
}
public BreakNode accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -39,7 +39,7 @@ public class CaseNode extends StmtNode {
d.printMember("body", body);
}
public CaseNode accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -66,7 +66,7 @@ public class CastNode extends ExprNode {
d.printMember("expr", expr);
}
public CastNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -55,7 +55,7 @@ public class CondExprNode extends ExprNode {
d.printMember("elseExpr", elseExpr);
}
public CondExprNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -22,7 +22,7 @@ public class ContinueNode extends StmtNode {
protected void _dump(Dumper d) {
}
public ContinueNode accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -115,7 +115,7 @@ public class DefinedFunction extends Function {
d.printMember("body", body);
}
public DefinedFunction accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -50,7 +50,7 @@ public class DefinedVariable extends Variable {
d.printMember("initializer", initializer);
}
public DefinedVariable accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -13,7 +13,7 @@ public class DereferenceNode extends UnaryOpNode {
public boolean isAssignable() { return true; }
public boolean isConstantAddress() { return false; }
public DereferenceNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}

View File

@ -24,7 +24,7 @@ public class DoWhileNode extends LoopNode {
d.printMember("cond", cond);
}
public DoWhileNode accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -90,5 +90,5 @@ abstract public class Entity extends Node {
return typeNode.location();
}
abstract public Entity accept(ASTVisitor visitor);
abstract public <S,E> S accept(ASTVisitor<S,E> visitor);
}

View File

@ -62,5 +62,5 @@ abstract public class ExprNode extends Node {
throw new Error("ExprNode#memref called");
}
abstract public ExprNode accept(ASTVisitor visitor);
abstract public <S,E> E accept(ASTVisitor<S,E> visitor);
}

View File

@ -20,7 +20,7 @@ public class ExprStmtNode extends StmtNode {
d.printMember("expr", expr);
}
public ExprStmtNode accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -39,7 +39,7 @@ public class ForNode extends LoopNode {
d.printMember("body", body);
}
public ForNode accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -77,7 +77,7 @@ public class FuncallNode extends ExprNode {
d.printNodeList("arguments", arguments);
}
public FuncallNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -27,7 +27,7 @@ public class GotoNode extends StmtNode {
d.printMember("target", target);
}
public GotoNode accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -47,7 +47,7 @@ public class IfNode extends StmtNode {
d.printMember("elseBody", elseBody);
}
public IfNode accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -29,7 +29,7 @@ public class IntegerLiteralNode extends LiteralNode {
d.printMember("value", value);
}
public IntegerLiteralNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -34,7 +34,7 @@ public class LabelNode extends StmtNode {
d.printMember("stmt", stmt);
}
public LabelNode accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -9,7 +9,7 @@ public class LogicalAndNode extends BinaryOpNode {
this.endLabel = new Label();
}
public LogicalAndNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}

View File

@ -9,7 +9,7 @@ public class LogicalOrNode extends BinaryOpNode {
this.endLabel = new Label();
}
public LogicalOrNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}

View File

@ -56,7 +56,7 @@ public class MemberNode extends ExprNode {
d.printMember("member", member);
}
public MemberNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}

View File

@ -12,7 +12,7 @@ public class OpAssignNode extends AbstractAssignNode {
return operator;
}
public OpAssignNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -5,7 +5,7 @@ public class PrefixOpNode extends UnaryArithmeticOpNode {
super(op, expr);
}
public PrefixOpNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -64,7 +64,7 @@ public class PtrMemberNode extends ExprNode {
d.printMember("member", member);
}
public PtrMemberNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}

View File

@ -33,7 +33,7 @@ public class ReturnNode extends StmtNode {
d.printMember("expr", expr);
}
public ReturnNode accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -34,7 +34,7 @@ public class SizeofExprNode extends ExprNode {
d.printMember("expr", expr);
}
public SizeofExprNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -34,7 +34,7 @@ public class SizeofTypeNode extends ExprNode {
d.printMember("operand", type);
}
public SizeofTypeNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -11,5 +11,5 @@ abstract public class StmtNode extends Node {
return location;
}
abstract public StmtNode accept(ASTVisitor visitor);
abstract public <S,E> S accept(ASTVisitor<S,E> visitor);
}

View File

@ -51,7 +51,7 @@ public class StringLiteralNode extends LiteralNode {
d.printMember("value", value);
}
public StringLiteralNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -21,7 +21,7 @@ public class StructNode extends CompositeTypeDefinition {
}
// #@@}
public StructNode accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -5,7 +5,7 @@ public class SuffixOpNode extends UnaryArithmeticOpNode {
super(op, expr);
}
public SuffixOpNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -35,7 +35,7 @@ public class SwitchNode extends StmtNode implements BreakableStmt {
d.printNodeList("cases", cases);
}
public SwitchNode accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -33,5 +33,5 @@ abstract public class TypeDefinition extends Node {
}
abstract public Type definingType();
abstract public TypeDefinition accept(ASTVisitor visitor);
abstract public <S,E> S accept(ASTVisitor<S,E> visitor);
}

View File

@ -36,7 +36,7 @@ public class TypedefNode extends TypeDefinition {
d.printMember("typeNode", typeNode);
}
public TypedefNode accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -40,7 +40,7 @@ public class UnaryOpNode extends ExprNode {
d.printMember("expr", expr);
}
public UnaryOpNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -25,7 +25,7 @@ public class UndefinedFunction extends Function {
d.printMember("params", params);
}
public UndefinedFunction accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -16,7 +16,7 @@ public class UndefinedVariable extends Variable {
d.printMember("typeNode", typeNode);
}
public UndefinedVariable accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -21,7 +21,7 @@ public class UnionNode extends CompositeTypeDefinition {
}
// #@@}
public UnionNode accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -73,7 +73,7 @@ public class VariableNode extends ExprNode {
d.printMember("name", name, isResolved());
}
public VariableNode accept(ASTVisitor visitor) {
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}

View File

@ -22,7 +22,7 @@ public class WhileNode extends LoopNode {
d.printMember("body", body);
}
public WhileNode accept(ASTVisitor visitor) {
public <S,E> S accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}

View File

@ -4,7 +4,7 @@ import net.loveruby.cflat.type.*;
import net.loveruby.cflat.exception.*;
import java.util.*;
class TypeChecker implements ASTVisitor {
class TypeChecker implements ASTVisitor<Node, ExprNode> {
protected TypeTable typeTable;
protected ErrorHandler errorHandler;
private DefinedFunction currentFunction;

View File

@ -2,7 +2,7 @@ package net.loveruby.cflat.compiler;
import net.loveruby.cflat.ast.*;
import java.util.*;
abstract public class Visitor implements ASTVisitor {
abstract public class Visitor implements ASTVisitor<Node, ExprNode> {
public Visitor() {
}
@ -228,34 +228,34 @@ abstract public class Visitor implements ASTVisitor {
return null;
}
public AddressNode visit(AddressNode node) {
public ExprNode visit(AddressNode node) {
visitExpr(node.expr());
return null;
}
public CastNode visit(CastNode node) {
public ExprNode visit(CastNode node) {
visitExpr(node.expr());
return null;
}
public SizeofExprNode visit(SizeofExprNode node) {
public ExprNode visit(SizeofExprNode node) {
visitExpr(node.expr());
return null;
}
public SizeofTypeNode visit(SizeofTypeNode node) {
public ExprNode visit(SizeofTypeNode node) {
return null;
}
public VariableNode visit(VariableNode node) {
public ExprNode visit(VariableNode node) {
return null;
}
public IntegerLiteralNode visit(IntegerLiteralNode node) {
public ExprNode visit(IntegerLiteralNode node) {
return null;
}
public StringLiteralNode visit(StringLiteralNode node) {
public ExprNode visit(StringLiteralNode node) {
return null;
}
}