Package org.candle.decompiler.intermediate.expression

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


           
           
            //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();
                             
View Full Code Here


      if(!(apr.getArray() instanceof Variable)) {
        return false;
      }
     
      //cast both to variable. check the variables match the name and type of the ones found above.
      Variable arrayPosition = (Variable)apr.getArray();
      Variable arrayRef = (Variable)apr.getArray();
     
      if(!StringUtils.equals(arrayPosition.getName(), generatedArrayIterator.getName())) {
        return false;
      }
     
      if(!StringUtils.equals(arrayRef.getName(), generatedArrayRef.getName())) {
        return false;
      }
     
      return true;
    }
View Full Code Here

 
  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

      IntermediateVariable localVar = context.getVariableResolver().getLocalVariable(index, context.getCurrentInstruction().getPosition());

      if(localVar == null) {
        LOG.debug("Did not find local variable: "+index + " for position: "+context.getCurrentInstruction().getPosition());
      }
      Variable variable = null;
      if(localVar == null) {
        //probably need to create a variable for enhanced loops...
        Type type = instruction.getType(context.getMethodGen().getConstantPool());
        localVar = context.getVariableResolver().addLocalVariable(index, context.getCurrentInstruction(), type);
       
        variable = new GeneratedVariable(context.getCurrentInstruction(), localVar.getType(), localVar.getName());
      }
      else {
        variable = new Variable(context.getCurrentInstruction(), localVar.getType(), localVar.getName());
      }
     
      //Variable variable = new Variable(context.getCurrentInstruction(), localVar.getType(), localVar.getName());
     
      context.getExpressions().push(variable);
View Full Code Here

    ConstantPoolGen cpg = context.getMethodGen().getConstantPool();
    String fieldName = instruction.getFieldName(cpg);
    Type fieldType = instruction.getFieldType(cpg);
   
    Expression right = context.getExpressions().pop();
    Variable variable = new Variable(context.getCurrentInstruction(), fieldType, fieldName);
    Assignment assignment = new Assignment(context.getCurrentInstruction(), variable, right);
   
    if(LOG.isDebugEnabled()) {
      for(Field field : context.getJavaClass().getFields()) {
        LOG.debug(field);
View Full Code Here

    //increment variable.
    int index = instruction.getIndex();
   
    IntermediateVariable iv = context.getVariableResolver().getLocalVariable(index, context.getCurrentInstruction().getPosition());
   
    Variable variable = null;
    if(iv == null) {
      //generate IV.
      iv = context.getVariableResolver().addLocalVariable(index, context.getCurrentInstruction(), instruction.getType(context.getMethodGen().getConstantPool()));
      variable = new GeneratedVariable(context.getCurrentInstruction(), iv.getType(), iv.getName());
    }
    else {
      variable = new Variable(context.getCurrentInstruction(), iv.getType(), iv.getName());
    }
   
    //now, how much does it increment by?
    int incrementBy = instruction.getIncrement();
   
View Full Code Here

    IntermediateVariable iv = context.getVariableResolver().getLocalVariable(lvtIndex, pc);

    //if the variable is not null, it is declared.
    boolean declared = (iv != null);
   
    Variable variable = null;
    if(!declared) {
      //look it up from the next phase code.
      pc = this.context.getCurrentInstruction().getNext().getPosition();
      iv = context.getVariableResolver().getLocalVariable(lvtIndex, pc);

      if(iv == null) {
        //probably need to create a variable for enhanced loops...
        LOG.debug("Adding index: "+instruction.getIndex() + " as: "+type);
       
        //try and resolve the type for the variable from the right hand side.
        if(type == Type.OBJECT) {
          if(right instanceof TypedExpression) {
            type = ((TypedExpression) right).getType();
          }
        }
       
        //generate variable name...
        iv = context.getVariableResolver().addLocalVariable(instruction.getIndex(), context.getCurrentInstruction(), type);
        variable = new GeneratedVariable(context.getCurrentInstruction(), iv.getType(), iv.getName());
      }
    }
   
    //create the variable.
    if(variable == null) {
      variable = new Variable(context.getCurrentInstruction(), iv.getType(), iv.getName());
    }
   
    //create the assignment.
    Assignment assignment = new Assignment(context.getCurrentInstruction(), variable, right);
   
View Full Code Here

  public void write(Writer builder) throws IOException {
    final String indent = buildIndent();
    builder.append(indent);
    builder.append("catch(");
   
    Variable catchVariable = intermediate.getCatchVariable();
    String type = SignatureUtility.signatureToString(catchVariable.getType().getSignature());
   
    builder.append(type);
    builder.append(" ");
    builder.append(catchVariable.getName());
    builder.append(") ");
    super.write(builder);
  }
View Full Code Here

TOP

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

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.