mirror of https://github.com/aamine/cbc
* 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:
parent
78a2217cd9
commit
9e9f65d6ce
|
|
@ -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>
|
Sun Apr 26 13:50:54 2009 Minero Aoki <aamine@loveruby.net>
|
||||||
|
|
||||||
* net/loveruby/cflat/ast/FuncallNode.java: detect static call.
|
* net/loveruby/cflat/ast/FuncallNode.java: detect static call.
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,9 @@ public class FuncallNode extends ExprNode {
|
||||||
|
|
||||||
/** Returns true if this funcall is NOT a function pointer call. */
|
/** Returns true if this funcall is NOT a function pointer call. */
|
||||||
public boolean isStaticCall() {
|
public boolean isStaticCall() {
|
||||||
if (! (expr instanceof AddressNode)) return false;
|
VariableNode var = getFunctionVariable();
|
||||||
ExprNode var = ((AddressNode)expr).expr();
|
if (var == null) return false;
|
||||||
if (! (var instanceof VariableNode)) return false;
|
return (var.entity() instanceof Function);
|
||||||
Entity e = ((VariableNode)var).entity();
|
|
||||||
return (e instanceof Function);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -34,11 +32,25 @@ public class FuncallNode extends ExprNode {
|
||||||
* This method expects this is static function call (isStaticCall()).
|
* This method expects this is static function call (isStaticCall()).
|
||||||
*/
|
*/
|
||||||
public Function function() {
|
public Function function() {
|
||||||
AddressNode a = (AddressNode)expr;
|
VariableNode var = getFunctionVariable();
|
||||||
VariableNode var = (VariableNode)a.expr();
|
if (var == null) throw new Error("not a static funcall");
|
||||||
return (Function)var.entity();
|
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
|
* Returns a type of return value of the function which is refered
|
||||||
* by expr. This method expects expr.type().isCallable() is true.
|
* by expr. This method expects expr.type().isCallable() is true.
|
||||||
|
|
|
||||||
|
|
@ -552,7 +552,9 @@ class Simplifier implements ASTVisitor<Void, ExprNode> {
|
||||||
public ExprNode visit(ArefNode node) {
|
public ExprNode visit(ArefNode node) {
|
||||||
ExprNode offset = binaryOp(intValue(node.elementSize()),
|
ExprNode offset = binaryOp(intValue(node.elementSize()),
|
||||||
"*", transformArrayIndex(node));
|
"*", 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];
|
// For multidimension array: t[e][d][c][b][a];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue