use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.
the class DOMConditionalExpression method handle.
@Override
public DSubTree handle() {
DSubTree tree = new DSubTree();
DSubTree Tcond = new DOMExpression(expression.getExpression(), visitor).handle();
DSubTree Tthen = new DOMExpression(expression.getThenExpression(), visitor).handle();
DSubTree Telse = new DOMExpression(expression.getElseExpression(), visitor).handle();
boolean branch = (Tcond.isValid() && Tthen.isValid()) || (Tcond.isValid() && Telse.isValid()) || (Tthen.isValid() && Telse.isValid());
if (branch)
tree.addNode(new DBranch(Tcond.getNodesAsCalls(), Tthen.getNodes(), Telse.getNodes()));
else {
// only one of these will add nodes, the rest will add nothing
tree.addNodes(Tcond.getNodes());
tree.addNodes(Tthen.getNodes());
tree.addNodes(Telse.getNodes());
}
return tree;
}
use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.
the class DOMEnhancedForStatement method handle.
/* TODO: handle this properly, by creating a call to Iterator.hasNext() and next() in a loop */
@Override
public DSubTree handle() {
DSubTree tree = new DSubTree();
DSubTree Texpr = new DOMExpression(statement.getExpression(), visitor).handle();
DSubTree Tbody = new DOMStatement(statement.getBody(), visitor).handle();
tree.addNodes(Texpr.getNodes());
tree.addNodes(Tbody.getNodes());
return tree;
}
use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.
the class DOMForStatement method handle.
@Override
public DSubTree handle() {
DSubTree tree = new DSubTree();
for (Object o : statement.initializers()) {
DSubTree init = new DOMExpression((Expression) o, visitor).handle();
tree.addNodes(init.getNodes());
}
DSubTree cond = new DOMExpression(statement.getExpression(), visitor).handle();
DSubTree body = new DOMStatement(statement.getBody(), visitor).handle();
for (Object o : statement.updaters()) {
DSubTree update = new DOMExpression((Expression) o, visitor).handle();
// updaters are part of body
body.addNodes(update.getNodes());
}
boolean loop = cond.isValid();
if (loop)
tree.addNode(new DLoop(cond.getNodesAsCalls(), body.getNodes()));
else {
// only one of these will add nodes
tree.addNodes(cond.getNodes());
tree.addNodes(body.getNodes());
}
return tree;
}
use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.
the class DOMIfStatement method handle.
@Override
public DSubTree handle() {
DSubTree tree = new DSubTree();
DSubTree Tcond = new DOMExpression(statement.getExpression(), visitor).handle();
DSubTree Tthen = new DOMStatement(statement.getThenStatement(), visitor).handle();
DSubTree Telse = new DOMStatement(statement.getElseStatement(), visitor).handle();
boolean branch = (Tcond.isValid() && Tthen.isValid()) || (Tcond.isValid() && Telse.isValid()) || (Tthen.isValid() && Telse.isValid());
if (branch)
tree.addNode(new DBranch(Tcond.getNodesAsCalls(), Tthen.getNodes(), Telse.getNodes()));
else {
// only one of these will add nodes, the rest will add nothing
tree.addNodes(Tcond.getNodes());
tree.addNodes(Tthen.getNodes());
tree.addNodes(Telse.getNodes());
}
return tree;
}
use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.
the class DOMMethodInvocation method handle.
@Override
public DSubTree handle() {
DSubTree tree = new DSubTree();
// add the expression's subtree (e.g: foo(..).bar() should handle foo(..) first)
DSubTree Texp = new DOMExpression(invocation.getExpression(), visitor).handle();
tree.addNodes(Texp.getNodes());
// evaluate arguments first
for (Object o : invocation.arguments()) {
DSubTree Targ = new DOMExpression((Expression) o, visitor).handle();
tree.addNodes(Targ.getNodes());
}
IMethodBinding binding = invocation.resolveMethodBinding();
// check if the binding is of a generic type that involves user-defined types
if (binding != null) {
ITypeBinding cls = binding.getDeclaringClass();
boolean userType = false;
if (cls != null && cls.isParameterizedType())
for (int i = 0; i < cls.getTypeArguments().length; i++) userType |= !cls.getTypeArguments()[i].getQualifiedName().startsWith("java.") && !cls.getTypeArguments()[i].getQualifiedName().startsWith("javax.");
if (// get to the generic declaration
userType || cls == null)
while (binding != null && binding.getMethodDeclaration() != binding) binding = binding.getMethodDeclaration();
}
MethodDeclaration localMethod = Utils.checkAndGetLocalMethod(binding, visitor);
if (localMethod != null) {
Stack<MethodDeclaration> callStack = visitor.callStack;
if (!callStack.contains(localMethod)) {
callStack.push(localMethod);
DSubTree Tmethod = new DOMMethodDeclaration(localMethod, visitor).handle();
callStack.pop();
tree.addNodes(Tmethod.getNodes());
}
} else if (Utils.isRelevantCall(binding, visitor)) {
try {
tree.addNode(new DAPICall(binding, visitor.getLineNumber(invocation)));
} catch (DAPICall.InvalidAPICallException e) {
// continue without adding the node
}
}
return tree;
}
Aggregations