* net/loveruby/cflat/ast/FuncallNode.java: make a static funcall really static funcall (not use pointer).

net/loveruby/cflat/compiler/Simplifier.java: set aref result type.


git-svn-id: file:///Users/aamine/c/gitwork/public/cbc/trunk@4147 1b9489fe-b721-0410-924e-b54b9192deb8
This commit is contained in:
Minero Aoki 2009-04-26 06:48:12 +00:00
parent 78a2217cd9
commit 9e9f65d6ce
3 changed files with 29 additions and 8 deletions

View File

@ -1,3 +1,10 @@
Sun Apr 26 15:48:10 2009 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/ast/FuncallNode.java: make a static funcall
really static funcall (not use pointer).
net/loveruby/cflat/compiler/Simplifier.java: set aref result type.
Sun Apr 26 13:50:54 2009 Minero Aoki <aamine@loveruby.net>
* net/loveruby/cflat/ast/FuncallNode.java: detect static call.

View File

@ -22,11 +22,9 @@ public class FuncallNode extends ExprNode {
/** Returns true if this funcall is NOT a function pointer call. */
public boolean isStaticCall() {
if (! (expr instanceof AddressNode)) return false;
ExprNode var = ((AddressNode)expr).expr();
if (! (var instanceof VariableNode)) return false;
Entity e = ((VariableNode)var).entity();
return (e instanceof Function);
VariableNode var = getFunctionVariable();
if (var == null) return false;
return (var.entity() instanceof Function);
}
/**
@ -34,11 +32,25 @@ public class FuncallNode extends ExprNode {
* This method expects this is static function call (isStaticCall()).
*/
public Function function() {
AddressNode a = (AddressNode)expr;
VariableNode var = (VariableNode)a.expr();
VariableNode var = getFunctionVariable();
if (var == null) throw new Error("not a static funcall");
return (Function)var.entity();
}
private VariableNode getFunctionVariable() {
if (expr instanceof AddressNode) {
ExprNode e = ((AddressNode)expr).expr();
if (! (e instanceof VariableNode)) return null;
return (VariableNode)e;
}
else if (expr instanceof VariableNode) {
return (VariableNode)expr;
}
else {
return null;
}
}
/**
* Returns a type of return value of the function which is refered
* by expr. This method expects expr.type().isCallable() is true.

View File

@ -552,7 +552,9 @@ class Simplifier implements ASTVisitor<Void, ExprNode> {
public ExprNode visit(ArefNode node) {
ExprNode offset = binaryOp(intValue(node.elementSize()),
"*", transformArrayIndex(node));
return deref(binaryOp(transform(node.baseExpr()), "+", offset));
return deref(
binaryOp(pointerTo(node.type()),
transform(node.baseExpr()), "+", offset));
}
// For multidimension array: t[e][d][c][b][a];