Package edu.cmu.cs.crystal.tac.model

Examples of edu.cmu.cs.crystal.tac.model.TACInstruction


    if(astNode == null)
      throw new IllegalArgumentException("No node given.");

    if(instr.containsKey(astNode))
      return instr.get(astNode);
    TACInstruction result = createInstruction(astNode);
    instr.put(astNode, result);
    return result;
  }
View Full Code Here


      throw new IllegalArgumentException("No node given.");
   
    // first look for a matching instruction
    // need this order because SimpleName nodes can have instruction
    // (see ConditionalExpression) and be a variable by themselves
    TACInstruction result = instruction(astNode);
    if(result != null) {
      if(result instanceof ResultfulInstruction)
        return ((ResultfulInstruction<?>) result).getResultVariable();
      throw new IllegalArgumentException("AST node has no result: " + astNode);
    }
View Full Code Here

       * @see org.eclipse.jdt.core.dom.ASTVisitor#postVisit(org.eclipse.jdt.core.dom.ASTNode)
       */
      @Override
      public void postVisit(ASTNode node) {
        try {
          TACInstruction instr = tac.instruction(node);
          if(log.isLoggable(Level.FINE)) {
            log.fine("Node: " + node);
            log.fine("Instruction: " + instr);
          }
        }
View Full Code Here

  public void testArrayRead() throws Exception {
    CompilationUnit cu = EclipseTACSimpleTestDriver.parseCode("ArrayRead", ARRAY_READ);
    MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(cu);
    EclipseTAC tac = new EclipseTAC(m.resolveBinding());
    ArrayAccess read = (ArrayAccess) EclipseTACSimpleTestDriver.getLastStatementReturn(m).getExpression();
    TACInstruction instr = tac.instruction(read);
    Assert.assertTrue(instr != null);
    Assert.assertTrue(instr instanceof LoadArrayInstruction);
    LoadArrayInstruction load = (LoadArrayInstruction) instr;
   
    Assert.assertEquals(tac.variable(read.getArray()), load.getSourceArray());
View Full Code Here

  public void testArrayWrite() throws Exception {
    CompilationUnit cu = EclipseTACSimpleTestDriver.parseCode("ArrayWrite", ARRAY_WRITE);
    MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(cu);
    EclipseTAC tac = new EclipseTAC(m.resolveBinding());
    Assignment write = (Assignment) ((ExpressionStatement) EclipseTACSimpleTestDriver.getLastStatement(m)).getExpression();
    TACInstruction instr = tac.instruction(write);
    Assert.assertTrue(instr != null);
    Assert.assertTrue(instr instanceof StoreArrayInstruction);
    StoreArrayInstruction store = (StoreArrayInstruction) instr;

    EclipseTACSimpleTestDriver.assertMethodParameter(store.getDestinationArray(), m, 0, tac);
View Full Code Here

  public void testArrayInc() throws Exception {
    CompilationUnit cu = EclipseTACSimpleTestDriver.parseCode("ArrayInc", ARRAY_INC);
    MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(cu);
    EclipseTAC tac = new EclipseTAC(m.resolveBinding());
    PrefixExpression inc = (PrefixExpression) EclipseTACSimpleTestDriver.getLastStatementReturn(m).getExpression();
    TACInstruction instr = tac.instruction(inc);
    Assert.assertTrue(instr != null);
    Assert.assertTrue(instr instanceof EclipseInstructionSequence);
    LoadArrayInstruction load = (LoadArrayInstruction) tac.instruction(inc.getOperand());
   
    EclipseInstructionSequence seq = (EclipseInstructionSequence) instr;
View Full Code Here

  public void testNestedArrayWrite() throws Exception {
    CompilationUnit cu = EclipseTACSimpleTestDriver.parseCode("NestedArrayWrite", NESTED_ARRAY_WRITE);
    MethodDeclaration m = EclipseTACSimpleTestDriver.getFirstMethod(cu);
    EclipseTAC tac = new EclipseTAC(m.resolveBinding());
    MethodInvocation inv = (MethodInvocation) ((ExpressionStatement) EclipseTACSimpleTestDriver.getLastStatement(m)).getExpression();
    TACInstruction instr = tac.instruction(inv);
    Assert.assertTrue(instr != null);
    Assert.assertTrue(instr instanceof MethodCallInstruction);
    MethodCallInstruction call = (MethodCallInstruction) instr;
   
    List<Variable> args = call.getArgOperands();
View Full Code Here

    EclipseTAC tac = new EclipseTAC(c.resolveBinding());
    VariableDeclarationFragment f = EclipseTACSimpleTestDriver.getFirstField(cu);
    Expression init = f.getInitializer();
    Assert.assertNotNull(init);

    TACInstruction decl = tac.instruction(f);
    Assert.assertNotNull(decl);
    Assert.assertTrue(decl instanceof StoreFieldInstruction);
   
    StoreFieldInstruction store = (StoreFieldInstruction) decl;
    Assert.assertTrue(store.getDestinationObject() instanceof ThisVariable);
    Assert.assertEquals("f", store.getFieldName());

    TACInstruction instr = tac.instruction(init);
    Assert.assertNotNull(instr);
    Assert.assertTrue(instr instanceof LoadLiteralInstruction);
   
    LoadLiteralInstruction load = (LoadLiteralInstruction) instr;
    Assert.assertEquals(load.getTarget(), store.getSourceOperand());
   
    Assignment write = (Assignment) ((ExpressionStatement) EclipseTACSimpleTestDriver.getLastStatement(c)).getExpression();
    TACInstruction again = tac.instruction(write);
    Assert.assertNotNull(again);
    Assert.assertTrue(again instanceof StoreFieldInstruction);
    Assert.assertFalse(store.equals(again));
  }
View Full Code Here

    EclipseTAC tac = new EclipseTAC(c.resolveBinding());
    VariableDeclarationFragment f = EclipseTACSimpleTestDriver.getFirstField(cu);
    Expression init = f.getInitializer();
    Assert.assertNotNull(init);

    TACInstruction decl = tac.instruction(f);
    Assert.assertNotNull(decl);
    Assert.assertTrue(decl instanceof StoreFieldInstruction);
   
    StoreFieldInstruction store = (StoreFieldInstruction) decl;
    Assert.assertTrue(store.getDestinationObject() instanceof ThisVariable);
    Assert.assertEquals("f", store.getFieldName());

    TACInstruction instr = tac.instruction(init);
    Assert.assertNotNull(instr);
    Assert.assertTrue(instr instanceof NewObjectInstruction);
   
    NewObjectInstruction alloc = (NewObjectInstruction) instr;
    Assert.assertEquals(alloc.getTarget(), store.getSourceOperand());
View Full Code Here

    EclipseTAC tac = new EclipseTAC(c.resolveBinding());
    VariableDeclarationFragment f = EclipseTACSimpleTestDriver.getFirstField(cu);
    Expression init = f.getInitializer();
    Assert.assertNull(init);

    TACInstruction decl = tac.instruction(f);
    Assert.assertNull(decl); // make sure the field declaration doesn't become a local
  }
View Full Code Here

TOP

Related Classes of edu.cmu.cs.crystal.tac.model.TACInstruction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.