Package org.candle.decompiler.intermediate.expression

Examples of org.candle.decompiler.intermediate.expression.Declaration


            }
           
           
            //otherwise, let's see if the declaration is an iterator.
            if(declaration.getExpression() instanceof Declaration) {
              Declaration declarationExpression = (Declaration)declaration.getExpression();
              Variable v = (Variable)declarationExpression.getAssignment().getLeftHandSide();
             
              //check to see if the declaration is the same as the iterator's name.
              if(StringUtils.equals(iteratorName, v.getName())) {
                LOG.debug("Identified Likely Iterator: "+v.getName());
               
                //get the ".next()" statement, which should be the first child.
                AbstractIntermediate firstChild = igc.getTrueTarget(line);
               
                //see if this is a statement, if the statement is an assignment...
                //then check the right side to see if it is an invocation.. and the invocation has the method name "next"...
                if(firstChild instanceof StatementIntermediate) {
                  StatementIntermediate nextStatement = (StatementIntermediate)firstChild;
                  if(nextStatement.getExpression() instanceof Declaration) {
                    //the statement is indeed a declaration.
                    Declaration nextDeclaration = (Declaration)nextStatement.getExpression();
                   
                    if(nextDeclaration.getAssignment().getRightHandSide() instanceof MethodInvocation) {
                      MethodInvocation nextMethodInvocation = (MethodInvocation)nextDeclaration.getAssignment().getRightHandSide();
                     
                      if(StringUtils.equals("next", nextMethodInvocation.getMethodName())) {
                        //YES.
                       
                        //check to see if the next method is on the candidate iterator.
                        if(nextMethodInvocation.getTarget() instanceof Variable) {
                          Variable nextMethodTarget = (Variable)nextMethodInvocation.getTarget();
                         
                         
                          if(StringUtils.equals(iteratorName, nextMethodTarget.getName())) {
                            LOG.info("Definitely an enhanced for loop.");
                           
                            if(declarationExpression.getAssignment().getRightHandSide() instanceof MethodInvocation) {
                              MethodInvocation iteratorInvocation = (MethodInvocation)declarationExpression.getAssignment().getRightHandSide();
                             
                              if(StringUtils.equals("iterator", iteratorInvocation.getMethodName())) {
                                //now, we are pretty certain this is an enhanced for loop...  we can chop up the graph.
                               
                                EnhancedForIntermediate enhancedFor = new EnhancedForIntermediate(line, nextDeclaration.getVariable(), iteratorInvocation.getTarget());
                                igc.getGraph().addVertex(enhancedFor);
                               
                                igc.redirectSuccessors(line, enhancedFor);
                                igc.redirectPredecessors(line, enhancedFor);
                                igc.getGraph().removeVertex(line);
View Full Code Here


    }
   
    //at this point, we know both the statement is an assignment, and that the left assignment is to a constant array value.
    //find the one that is right before the array assignment.
   
    Declaration declaration = extractNextDeclaration(line);

    //if we didn't find the declaration, this must not be the constant array assignment proceeding the declaration.
    if(declaration == null) {
      return;
    }
   
    //check the right hand of the declaration...
    if(!(declaration.getAssignment().getRightHandSide() instanceof NewConstantArrayInstance)) {
      return;
    }
    NewConstantArrayInstance ncai = (NewConstantArrayInstance)declaration.getAssignment().getRightHandSide();
    Expression countExpression = ncai.getCount();
   
   
    AbstractIntermediate current = line;
    Map<Integer, Expression> values = new HashMap<Integer, Expression>();
    collectConstantAssignments(current, values);
   
    //create a new array...
    Integer count = toInteger(countExpression);
    List<Expression> expressions = new ArrayList<Expression>(count);
    for(int i=0, j=count; i<j; i++) {
      Expression exp = null;
      if(values.containsKey(i)) {
        exp = values.get(i);
      }
      else {
        exp = new Resolved(ncai.getInstructionHandle(), Type.NULL, "null");
      }
      expressions.add(i, exp);
    }
   
   
    //ok, we have the stack... now we need to just create a new expression.

    //create the contant...
    ConstantArray constantArray = new ConstantArray(declaration.getAssignment().getRightHandSide().getInstructionHandle(), expressions);
    declaration.getAssignment().setRightHandSide(constantArray);
   
   
    //excellent.  we have reordered the statements into the appropriate ContantArray assignment.  Now, we need to remove the dead nodes and heal the graph.
    AbstractIntermediate next = Graphs.successorListOf(igc.getGraph(), line).get(0);
   
View Full Code Here

    if(declared) {
      left = assignment;
    }
    else {
      //if it is currently not declared... create the declaration.
      left = new Declaration(context.getCurrentInstruction(), variable, assignment);
    }
   
    StatementIntermediate cl = new StatementIntermediate(context.getCurrentInstruction(), left);
    context.pushIntermediateToInstruction(cl);
View Full Code Here

      //at this point, both should be set.
      if(declaration != null && iteration != null) {
        //now, check the expression and validate these are correct via AST.
       
        if(declaration.getExpression() instanceof Declaration) {
          Declaration declarationExpression = (Declaration)declaration.getExpression();
         
          if(iteration.getExpression() instanceof Increment) {
            Increment incrementExpression = (Increment)iteration.getExpression();
           
            if(incrementExpression.getVariable().getType().equals(declarationExpression.getVariable().getType())) {
             
              //now check names.
              if(incrementExpression.getVariable().getName().equals(declarationExpression.getVariable().getName())) {
                //we can actually convert this to a for loop.
                ForIntermediate forIntermediate = new ForIntermediate(line, declarationExpression, incrementExpression);
                //forIntermediate.setTrueBranch(line.getTrueBranch());
                //forIntermediate.setFalseBranch(line.getFalseBranch());
               
View Full Code Here

    }
   
    //great; at this point we know the pattern matches.  check the next statement to see if the transformation is possible.
    //format should be: 40 : GENERATED_ARRAY_REFERENCE_TYPE i = GENERATED_ARRAY_REFERENCE[ARRAY_ITERATOR_VALUE] |
    StatementIntermediate childDeclarationStatement = ((StatementIntermediate)firstChild);
    Declaration childDeclaration = (Declaration)childDeclarationStatement.getExpression();
   
    if(firstMatchesGeneratedVariables(childDeclarationStatement, generatedArrayReference, arrayIteratorValue)) {
     
      LOG.debug("Likely a enhanced for loop for array: "+generatedArrayLength + " , "+ generatedArrayReference);
     
      //we are good to go here.  Now we just need to reorganize the graph.  Start by creating the new enhanced for loop.
      EnhancedForIntermediate efl = new EnhancedForIntermediate(line.getInstruction(), line.getConditionalIntermediate(), childDeclaration.getVariable(), extractExpressionFromGeneratedArrayAssignment(tempArrayCandidate));
      //efl.setTrueBranch(line.getTrueBranch());
      //efl.setFalseBranch(line.getFalseBranch());
      //add the new node...
      this.igc.getGraph().addVertex(efl);
     
View Full Code Here

 
  private Expression extractExpressionFromGeneratedArrayAssignment(AbstractIntermediate declaration) {
    if(declaration instanceof StatementIntermediate) {
      StatementIntermediate si = (StatementIntermediate)declaration;
     
      Declaration dec = (Declaration)si.getExpression();
      return dec.getAssignment().getRightHandSide();
    }
   
    return null;
  }
View Full Code Here

   
    return null;
  }
 
  private boolean firstMatchesGeneratedVariables(StatementIntermediate first, GeneratedVariable generatedArrayRef, GeneratedVariable generatedArrayIterator) {
    Declaration childDeclaration = (Declaration)first.getExpression();
    Expression right = childDeclaration.getAssignment().getRightHandSide();
   
    if(right instanceof ArrayAccess) {
      ArrayAccess apr = (ArrayAccess)right;
     
      if(!(apr.getIndex() instanceof Variable)) {
View Full Code Here

    return null;
  }
 
  private GeneratedVariable extractGeneratedVariableDeclaration(Expression expression) {
    if(expression instanceof Declaration) {
      Declaration dec = (Declaration)expression;
     
      Variable var = dec.getVariable();
     
      if(var instanceof GeneratedVariable) {
        return (GeneratedVariable)var;
      }
    }
View Full Code Here

    LOG.debug("Catch Declaration:"+catchDeclaration);
   
    if(catchDeclaration instanceof StatementIntermediate) {
      StatementIntermediate declarationStatement = (StatementIntermediate)catchDeclaration;
      if(declarationStatement.getExpression() instanceof Declaration) {
        Declaration declaration = (Declaration)declarationStatement.getExpression();
       
        //now, we can convert this into a catch block.
        CatchIntermediate catchIntermediate = new CatchIntermediate(declarationStatement.getInstruction(), ceg, declaration.getVariable());
        igc.getGraph().addVertex(catchIntermediate);
       
        //redirect statement to catch.
        igc.redirectPredecessors(declarationStatement, catchIntermediate);
        igc.redirectSuccessors(declarationStatement, catchIntermediate);
View Full Code Here

TOP

Related Classes of org.candle.decompiler.intermediate.expression.Declaration

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.