Search in sources :

Example 21 with DSubTree

use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.

the class DOMDoStatement method handle.

@Override
public DSubTree handle() {
    DSubTree tree = new DSubTree();
    DSubTree cond = new DOMExpression(statement.getExpression(), visitor).handle();
    DSubTree body = new DOMStatement(statement.getBody(), visitor).handle();
    boolean loop = cond.isValid() && body.isValid();
    tree.addNodes(body.getNodes());
    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;
}
Also used : DSubTree(edu.rice.cs.caper.bayou.core.dsl.DSubTree) DLoop(edu.rice.cs.caper.bayou.core.dsl.DLoop)

Example 22 with DSubTree

use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.

the class DOMInfixExpression method handle.

@Override
public DSubTree handle() {
    DSubTree tree = new DSubTree();
    DSubTree Tleft = new DOMExpression(expr.getLeftOperand(), visitor).handle();
    DSubTree Tright = new DOMExpression(expr.getRightOperand(), visitor).handle();
    tree.addNodes(Tleft.getNodes());
    tree.addNodes(Tright.getNodes());
    return tree;
}
Also used : DSubTree(edu.rice.cs.caper.bayou.core.dsl.DSubTree)

Example 23 with DSubTree

use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.

the class DOMSwitchStatement method handle.

@Override
public DSubTree handle() {
    DSubTree Sexpr = new DOMExpression(statement.getExpression(), visitor).handle();
    boolean branch = Sexpr.isValid();
    for (Object o : statement.statements()) {
        int type = ((Statement) o).getNodeType();
        nodeType.add(type);
        DSubTree body = new DOMStatement((Statement) o, visitor).handle();
        bodies.add(body.getNodes());
        if (// excludes 'case' statement
        type != 49)
            branch |= body.isValid();
    }
    if (branch) {
        DSubTree switchNode = BuildTree(Sexpr, 1);
        tree.addNode(switchNode.getNodes().get(0));
    } else {
        // only one  will add nodes, the rest will add nothing
        tree.addNodes(Sexpr.getNodes());
        for (Iterator<Object> iter = statement.statements().iterator(); iter.hasNext(); ) {
            Object o = iter.next();
            DSubTree body = new DOMStatement((Statement) o, visitor).handle();
            tree.addNodes(body.getNodes());
        }
    }
    return tree;
}
Also used : DSubTree(edu.rice.cs.caper.bayou.core.dsl.DSubTree) SwitchStatement(org.eclipse.jdt.core.dom.SwitchStatement) Statement(org.eclipse.jdt.core.dom.Statement)

Example 24 with DSubTree

use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.

the class DOMSwitchStatement method BuildTree.

private DSubTree BuildTree(DSubTree Sexpr, int itPos) {
    DSubTree bodyPrev = new DSubTree();
    DSubTree caseNodes = new DSubTree();
    DSubTree bodyNext;
    for (int it1 = itPos; it1 < bodies.size(); it1++) {
        int typePrev = nodeType.get(it1);
        if (typePrev == 49) {
            // checks for 'case' statement
            bodyNext = BuildTree(Sexpr, it1 + 1);
            DASTNode caseNode = new DBranch(Sexpr.getNodesAsCalls(), bodyPrev.getNodes(), bodyNext.getNodes());
            caseNodes.addNode(caseNode);
            return caseNodes;
        } else {
            bodyPrev.addNodes(bodies.get(it1));
        }
    }
    return bodyPrev;
}
Also used : DSubTree(edu.rice.cs.caper.bayou.core.dsl.DSubTree) DASTNode(edu.rice.cs.caper.bayou.core.dsl.DASTNode) DBranch(edu.rice.cs.caper.bayou.core.dsl.DBranch)

Example 25 with DSubTree

use of edu.rice.cs.caper.bayou.core.dsl.DSubTree in project bayou by capergroup.

the class DOMVariableDeclarationStatement method handle.

@Override
public DSubTree handle() {
    DSubTree tree = new DSubTree();
    for (Object o : statement.fragments()) {
        VariableDeclarationFragment fragment = (VariableDeclarationFragment) o;
        DSubTree t = new DOMVariableDeclarationFragment(fragment, visitor).handle();
        tree.addNodes(t.getNodes());
    }
    return tree;
}
Also used : DSubTree(edu.rice.cs.caper.bayou.core.dsl.DSubTree) VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment)

Aggregations

DSubTree (edu.rice.cs.caper.bayou.core.dsl.DSubTree)26 ArrayList (java.util.ArrayList)7 DAPICall (edu.rice.cs.caper.bayou.core.dsl.DAPICall)5 DBranch (edu.rice.cs.caper.bayou.core.dsl.DBranch)3 DLoop (edu.rice.cs.caper.bayou.core.dsl.DLoop)3 Sequence (edu.rice.cs.caper.bayou.core.dsl.Sequence)3 DASTNode (edu.rice.cs.caper.bayou.core.dsl.DASTNode)2 HashSet (java.util.HashSet)2 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)2 Multiset (com.google.common.collect.Multiset)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 DExcept (edu.rice.cs.caper.bayou.core.dsl.DExcept)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 Pair (org.apache.commons.lang3.tuple.Pair)1