2007-12-24 16:19:51 +08:00
|
|
|
package net.loveruby.cflat.ast;
|
|
|
|
import net.loveruby.cflat.type.Type;
|
2009-04-27 01:55:46 +08:00
|
|
|
import net.loveruby.cflat.entity.Entity;
|
|
|
|
import net.loveruby.cflat.entity.DefinedVariable;
|
2007-12-24 16:19:51 +08:00
|
|
|
|
2009-05-18 02:35:02 +08:00
|
|
|
public class VariableNode extends LHSNode {
|
|
|
|
private Location location;
|
|
|
|
private String name;
|
|
|
|
private Entity entity;
|
2007-12-24 16:19:51 +08:00
|
|
|
|
2008-01-05 09:34:27 +08:00
|
|
|
public VariableNode(Location loc, String name) {
|
|
|
|
this.location = loc;
|
|
|
|
this.name = name;
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
2009-04-19 22:52:48 +08:00
|
|
|
public VariableNode(DefinedVariable var) {
|
|
|
|
this.entity = var;
|
2009-04-20 02:52:12 +08:00
|
|
|
this.name = var.name();
|
2009-04-19 22:52:48 +08:00
|
|
|
}
|
|
|
|
|
2007-12-24 16:19:51 +08:00
|
|
|
public String name() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2008-01-13 03:48:31 +08:00
|
|
|
public boolean isResolved() {
|
|
|
|
return (entity != null);
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public Entity entity() {
|
|
|
|
if (entity == null) {
|
|
|
|
throw new Error("VariableNode.entity == null");
|
|
|
|
}
|
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
|
2008-01-13 03:48:31 +08:00
|
|
|
public void setEntity(Entity ent) {
|
|
|
|
entity = ent;
|
|
|
|
}
|
|
|
|
|
2007-12-24 16:19:51 +08:00
|
|
|
public TypeNode typeNode() {
|
|
|
|
return entity().typeNode();
|
|
|
|
}
|
|
|
|
|
2008-02-18 03:08:48 +08:00
|
|
|
public boolean isParameter() {
|
|
|
|
return entity().isParameter();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-01-05 09:34:27 +08:00
|
|
|
public Location location() {
|
|
|
|
return location;
|
|
|
|
}
|
|
|
|
|
2008-01-04 07:01:49 +08:00
|
|
|
protected void _dump(Dumper d) {
|
2009-05-18 02:35:02 +08:00
|
|
|
if (type != null) {
|
|
|
|
d.printMember("type", type);
|
|
|
|
}
|
2008-01-13 03:48:31 +08:00
|
|
|
d.printMember("name", name, isResolved());
|
2008-01-04 07:01:49 +08:00
|
|
|
}
|
|
|
|
|
2009-04-12 14:31:12 +08:00
|
|
|
public <S,E> E accept(ASTVisitor<S,E> visitor) {
|
2009-04-04 22:47:11 +08:00
|
|
|
return visitor.visit(this);
|
2008-01-04 07:01:49 +08:00
|
|
|
}
|
2007-12-24 16:19:51 +08:00
|
|
|
}
|