cbc/net/loveruby/cflat/ast/VariableNode.java

67 lines
1.4 KiB
Java
Raw Normal View History

package net.loveruby.cflat.ast;
import net.loveruby.cflat.type.Type;
import net.loveruby.cflat.entity.Entity;
import net.loveruby.cflat.entity.DefinedVariable;
r4865@macbookpro: aamine | 2009-05-18 03:02:28 +0900 * net/loveruby/cflat/parser/Parser.jj: change function pointer syntax: int(*)(int,int) -> int(int,int)*. Function type is int(int,int). * net/loveruby/cflat/parser/Parser.jj: function returns function type, not pointer to function. * net/loveruby/cflat/compiler/TypeResolver.java: resolve all function headers first, then resolve bodies. * net/loveruby/cflat/compiler/TypeResolver.java: generate a pointer for array-type expression. * net/loveruby/cflat/compiler/TypeResolver.java: isDereferable -> isPointer. * net/loveruby/cflat/compiler/TypeChecker.java: ditto. * net/loveruby/cflat/compiler/DereferenceChecker.java: ditto. * net/loveruby/cflat/compiler/IRGenerator.java: ditto. * net/loveruby/cflat/compiler/IRGenerator.java: shouldEvaluatedToAddress -> isLoadable (check arrays and functions, not only arrays). * net/loveruby/cflat/type/Type.java: remove #isDereferable. * net/loveruby/cflat/type/UserType.java: ditto. * net/loveruby/cflat/type/ArrayType.java: is not a scalar. * net/loveruby/cflat/type/ArrayType.java: is not dereferable itself. * net/loveruby/cflat/type/PointerType.java: is incompatible with arrays. * net/loveruby/cflat/type/IntegerType.java: ditto. * net/loveruby/cflat/type/FunctionType.java: is callable. * net/loveruby/cflat/type/ParamTypeRefs.java: x[] -> x* for param types. * net/loveruby/cflat/type/TypeTable.java: new method #getParamType. * net/loveruby/cflat/ast/ExprNode.java: new method #isLvalue. * net/loveruby/cflat/ast/ExprNode.java: new method #isAssignable. * net/loveruby/cflat/ast/ExprNode.java: new method #isLoadable. * net/loveruby/cflat/ast/CastNode.java: delegate them. * net/loveruby/cflat/ast/LHSNode.java: new super class of LHS nodes. * net/loveruby/cflat/ast/VariableNode.java: ditto. * net/loveruby/cflat/ast/DereferenceNode.java: ditto. * net/loveruby/cflat/ast/ArefNode.java: ditto. * net/loveruby/cflat/ast/MemberNode.java: ditto. * net/loveruby/cflat/ast/PtrMemberNode.java: ditto. * net/loveruby/cflat/entity/Entity.java: remove #cannotLoad. * net/loveruby/cflat/entity/Function.java: ditto. * net/loveruby/cflat/entity/Variable.java: ditto. * net/loveruby/cflat/entity/Constant.java: ditto. * net/loveruby/cflat/ir/Addr.java: is not LHS node now. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4220 1b9489fe-b721-0410-924e-b54b9192deb8
2009-05-18 02:35:02 +08:00
public class VariableNode extends LHSNode {
private Location location;
private String name;
private Entity entity;
public VariableNode(Location loc, String name) {
this.location = loc;
this.name = name;
}
public VariableNode(DefinedVariable var) {
this.entity = var;
this.name = var.name();
}
public String name() {
return name;
}
public boolean isResolved() {
return (entity != null);
}
public Entity entity() {
if (entity == null) {
throw new Error("VariableNode.entity == null");
}
return entity;
}
public void setEntity(Entity ent) {
entity = ent;
}
public TypeNode typeNode() {
return entity().typeNode();
}
public boolean isParameter() {
return entity().isParameter();
}
r4865@macbookpro: aamine | 2009-05-18 03:02:28 +0900 * net/loveruby/cflat/parser/Parser.jj: change function pointer syntax: int(*)(int,int) -> int(int,int)*. Function type is int(int,int). * net/loveruby/cflat/parser/Parser.jj: function returns function type, not pointer to function. * net/loveruby/cflat/compiler/TypeResolver.java: resolve all function headers first, then resolve bodies. * net/loveruby/cflat/compiler/TypeResolver.java: generate a pointer for array-type expression. * net/loveruby/cflat/compiler/TypeResolver.java: isDereferable -> isPointer. * net/loveruby/cflat/compiler/TypeChecker.java: ditto. * net/loveruby/cflat/compiler/DereferenceChecker.java: ditto. * net/loveruby/cflat/compiler/IRGenerator.java: ditto. * net/loveruby/cflat/compiler/IRGenerator.java: shouldEvaluatedToAddress -> isLoadable (check arrays and functions, not only arrays). * net/loveruby/cflat/type/Type.java: remove #isDereferable. * net/loveruby/cflat/type/UserType.java: ditto. * net/loveruby/cflat/type/ArrayType.java: is not a scalar. * net/loveruby/cflat/type/ArrayType.java: is not dereferable itself. * net/loveruby/cflat/type/PointerType.java: is incompatible with arrays. * net/loveruby/cflat/type/IntegerType.java: ditto. * net/loveruby/cflat/type/FunctionType.java: is callable. * net/loveruby/cflat/type/ParamTypeRefs.java: x[] -> x* for param types. * net/loveruby/cflat/type/TypeTable.java: new method #getParamType. * net/loveruby/cflat/ast/ExprNode.java: new method #isLvalue. * net/loveruby/cflat/ast/ExprNode.java: new method #isAssignable. * net/loveruby/cflat/ast/ExprNode.java: new method #isLoadable. * net/loveruby/cflat/ast/CastNode.java: delegate them. * net/loveruby/cflat/ast/LHSNode.java: new super class of LHS nodes. * net/loveruby/cflat/ast/VariableNode.java: ditto. * net/loveruby/cflat/ast/DereferenceNode.java: ditto. * net/loveruby/cflat/ast/ArefNode.java: ditto. * net/loveruby/cflat/ast/MemberNode.java: ditto. * net/loveruby/cflat/ast/PtrMemberNode.java: ditto. * net/loveruby/cflat/entity/Entity.java: remove #cannotLoad. * net/loveruby/cflat/entity/Function.java: ditto. * net/loveruby/cflat/entity/Variable.java: ditto. * net/loveruby/cflat/entity/Constant.java: ditto. * net/loveruby/cflat/ir/Addr.java: is not LHS node now. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4220 1b9489fe-b721-0410-924e-b54b9192deb8
2009-05-18 02:35:02 +08:00
protected Type origType() {
return entity().type();
* implement PIC generation. * lib/Makefile: should generate PIC for libcbc.o. * net/loveruby/cflat/compiler/Compiler.java: pass CodeGeneratorOptions to CodeGenerator. * net/loveruby/cflat/compiler/Options.java: new options -fpic, -fPIC. * net/loveruby/cflat/compiler/CodeGenerator.java: use position independent address for global variables, common symbols, defined/undefined functions and string constants. * net/loveruby/cflat/compiler/CodeGeneratorOptions.java: new class. * net/loveruby/cflat/asm/ELFConstants.java: new interface to define ELF-related constants. * net/loveruby/cflat/asm/Assembler.java: new method #hidden. * net/loveruby/cflat/asm/Assembler.java: new overload #section(s,s,s,s,s). * net/loveruby/cflat/asm/IndirectMemoryReference.java: offset may not long, but Literal. * net/loveruby/cflat/asm/Literal.java: new method #isZero. * net/loveruby/cflat/asm/IntegerLiteral.java: ditto. * net/loveruby/cflat/asm/LabelRef.java: ditto. * net/loveruby/cflat/ast/ExprNode.java: new method #shouldEvaluatedToAddres. * net/loveruby/cflat/ast/VariableNode.java: override it. * net/loveruby/cflat/ast/CastNode.java: override it. * net/loveruby/cflat/ast/Entity.java: new method #cannotLoad, to implement #shouldEvaluatedToAddress. * net/loveruby/cflat/ast/Variable.java: override it. * net/loveruby/cflat/ast/Function.java: override it. * net/loveruby/cflat/ast/ExprNode.java: rename method: #AsmLiteral -> #AsmValue because it now returns ImmediateValue instead of Literal. * net/loveruby/cflat/ast/CastNode.java: override it. * net/loveruby/cflat/ast/LiteralNode.java: rename method also. * net/loveruby/cflat/ast/IntegerLiteralNode.java: ditto. * net/loveruby/cflat/ast/StringLiteralNode.java: ditto. * net/loveruby/cflat/ast/Variable.java: holds memref and address here, not in subclasses. * net/loveruby/cflat/ast/DefinedVariable.java: ditto. * net/loveruby/cflat/ast/UndefinedVariable.java: ditto. * net/loveruby/cflat/ast/LiteralNode.java: new method #memref. * net/loveruby/cflat/ast/IntegerLiteralNode.java: implement it. * net/loveruby/cflat/ast/StringLiteralNode.java: implement it. * net/loveruby/cflat/ast/ConstantEntry.java: holds memref and address. * net/loveruby/cflat/ast/AST.java: new method #allFunctions, to access undefined functions from code generator. * net/loveruby/cflat/ast/ToplevelScope.java: ditto. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4057 1b9489fe-b721-0410-924e-b54b9192deb8
2008-09-28 04:07:49 +08:00
}
public Location location() {
return location;
}
protected void _dump(Dumper d) {
r4865@macbookpro: aamine | 2009-05-18 03:02:28 +0900 * net/loveruby/cflat/parser/Parser.jj: change function pointer syntax: int(*)(int,int) -> int(int,int)*. Function type is int(int,int). * net/loveruby/cflat/parser/Parser.jj: function returns function type, not pointer to function. * net/loveruby/cflat/compiler/TypeResolver.java: resolve all function headers first, then resolve bodies. * net/loveruby/cflat/compiler/TypeResolver.java: generate a pointer for array-type expression. * net/loveruby/cflat/compiler/TypeResolver.java: isDereferable -> isPointer. * net/loveruby/cflat/compiler/TypeChecker.java: ditto. * net/loveruby/cflat/compiler/DereferenceChecker.java: ditto. * net/loveruby/cflat/compiler/IRGenerator.java: ditto. * net/loveruby/cflat/compiler/IRGenerator.java: shouldEvaluatedToAddress -> isLoadable (check arrays and functions, not only arrays). * net/loveruby/cflat/type/Type.java: remove #isDereferable. * net/loveruby/cflat/type/UserType.java: ditto. * net/loveruby/cflat/type/ArrayType.java: is not a scalar. * net/loveruby/cflat/type/ArrayType.java: is not dereferable itself. * net/loveruby/cflat/type/PointerType.java: is incompatible with arrays. * net/loveruby/cflat/type/IntegerType.java: ditto. * net/loveruby/cflat/type/FunctionType.java: is callable. * net/loveruby/cflat/type/ParamTypeRefs.java: x[] -> x* for param types. * net/loveruby/cflat/type/TypeTable.java: new method #getParamType. * net/loveruby/cflat/ast/ExprNode.java: new method #isLvalue. * net/loveruby/cflat/ast/ExprNode.java: new method #isAssignable. * net/loveruby/cflat/ast/ExprNode.java: new method #isLoadable. * net/loveruby/cflat/ast/CastNode.java: delegate them. * net/loveruby/cflat/ast/LHSNode.java: new super class of LHS nodes. * net/loveruby/cflat/ast/VariableNode.java: ditto. * net/loveruby/cflat/ast/DereferenceNode.java: ditto. * net/loveruby/cflat/ast/ArefNode.java: ditto. * net/loveruby/cflat/ast/MemberNode.java: ditto. * net/loveruby/cflat/ast/PtrMemberNode.java: ditto. * net/loveruby/cflat/entity/Entity.java: remove #cannotLoad. * net/loveruby/cflat/entity/Function.java: ditto. * net/loveruby/cflat/entity/Variable.java: ditto. * net/loveruby/cflat/entity/Constant.java: ditto. * net/loveruby/cflat/ir/Addr.java: is not LHS node now. git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4220 1b9489fe-b721-0410-924e-b54b9192deb8
2009-05-18 02:35:02 +08:00
if (type != null) {
d.printMember("type", type);
}
d.printMember("name", name, isResolved());
}
public <S,E> E accept(ASTVisitor<S,E> visitor) {
return visitor.visit(this);
}
}