org.tizen.nativeapp.assignmenttracing_1.0.0.201310011911

16:50:12.194 INFO  jd.cli.Main - Decompiling org.tizen.nativeapp.assignmenttracing_1.0.0.201310011911.jar
package org.tizen.nativeapp.assignmenttracing.core;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import org.eclipse.cdt.core.dom.ast.IASTArrayDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTArrayModifier;
import org.eclipse.cdt.core.dom.ast.IASTArraySubscriptExpression;
import org.eclipse.cdt.core.dom.ast.IASTBinaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
import org.eclipse.cdt.core.dom.ast.IASTCastExpression;
import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement;
import org.eclipse.cdt.core.dom.ast.IASTConditionalExpression;
import org.eclipse.cdt.core.dom.ast.IASTContinueStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
import org.eclipse.cdt.core.dom.ast.IASTEqualsInitializer;
import org.eclipse.cdt.core.dom.ast.IASTExpression;
import org.eclipse.cdt.core.dom.ast.IASTExpressionList;
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
import org.eclipse.cdt.core.dom.ast.IASTForStatement;
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTGotoStatement;
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
import org.eclipse.cdt.core.dom.ast.IASTIfStatement;
import org.eclipse.cdt.core.dom.ast.IASTInitializer;
import org.eclipse.cdt.core.dom.ast.IASTInitializerClause;
import org.eclipse.cdt.core.dom.ast.IASTInitializerList;
import org.eclipse.cdt.core.dom.ast.IASTLabelStatement;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNode;
import org.eclipse.cdt.core.dom.ast.IASTParameterDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTReturnStatement;
import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTStandardFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.IASTStatement;
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
import org.eclipse.cdt.core.dom.ast.IASTUnaryExpression;
import org.eclipse.cdt.core.dom.ast.IASTWhileStatement;
import org.eclipse.cdt.core.dom.ast.c.ICASTArrayDesignator;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignatedInitializer;
import org.eclipse.cdt.core.dom.ast.c.ICASTDesignator;
import org.eclipse.cdt.core.dom.ast.c.ICASTFieldDesignator;
import org.eclipse.cdt.core.dom.ast.c.ICASTTypeIdInitializerExpression;
import org.eclipse.cdt.core.dom.ast.gnu.IGNUASTCompoundStatementExpression;
import org.eclipse.cdt.core.dom.ast.gnu.c.ICASTKnRFunctionDeclarator;
import org.eclipse.cdt.core.dom.ast.gnu.c.IGCCASTArrayRangeDesignator;
import org.eclipse.core.runtime.IProgressMonitor;
import org.tizen.nativeapp.assignmenttracing.core.exceptions.TracingCancelException;
import org.tizen.nativeapp.assignmenttracing.core.exceptions.TracingUnsupportedException;

public class CFGBuilder
{
  private static final int DEF = 0;
  private static final int USE = 1;
  private static final int SKIP = 2;
  private static final boolean LHS = true;
  private static final boolean RHS = false;
  private List<CFGNode> nameMatchedNode;
  private HashMap<String, CFGNode> labels;
  private HashMap<CFGNode, CFGNode> defaultTable;
  private CFGNode start = null;
  private IASTName selectedName;
  private LinkedList<CFGNode> continueStack;
  private LinkedList<CFGNode> breakStack;
  private LinkedList<CFGNode> caseStack;
  private int nodeCount;
  private IProgressMonitor cancelMonitor;
  
  public CFGBuilder(IProgressMonitor monitor)
  {
    nameMatchedNode = new ArrayList();
    labels = new HashMap();
    defaultTable = new HashMap();
    
    continueStack = new LinkedList();
    breakStack = new LinkedList();
    caseStack = new LinkedList();
    
    nodeCount = 0;
    
    cancelMonitor = monitor;
  }
  
  public List<CFGNode> buildCFG(IASTFunctionDefinition func, IASTName selName)
  {
    selectedName = selName;
    if (isNestedFunction(func)) {
      throw new TracingUnsupportedException();
    }
    IASTFunctionDeclarator funDeclarator = func.getDeclarator();
    Object localObject;
    int j;
    int i;
    if ((funDeclarator instanceof IASTStandardFunctionDeclarator))
    {
      IASTStandardFunctionDeclarator sfd = (IASTStandardFunctionDeclarator)funDeclarator;
      IASTParameterDeclaration[] fp = sfd.getParameters();
      j = (localObject = fp).length;
      for (i = 0; i < j; i++)
      {
        IASTParameterDeclaration pd = localObject[i];
        start = createDeclarator(start, pd.getDeclarator());
      }
    }
    else if ((funDeclarator instanceof ICASTKnRFunctionDeclarator))
    {
      if ((selName.getParent() instanceof ICASTKnRFunctionDeclarator))
      {
        start = createNode(selName, Integer.valueOf(0));
      }
      else
      {
        ICASTKnRFunctionDeclarator krfd = (ICASTKnRFunctionDeclarator)funDeclarator;
        IASTDeclaration[] dc = krfd.getParameterDeclarations();
        j = (localObject = dc).length;
        for (i = 0; i < j; i++)
        {
          IASTDeclaration declaration = localObject[i];
          start = createDeclaration(start, declaration);
        }
      }
    }
    if (start == null) {
      start = createNode(null, Integer.valueOf(2));
    }
    createStatement(start, func.getBody());
    
    return nameMatchedNode;
  }
  
  public void checkReachability()
  {
    Stack<CFGNode> nodeStack = new Stack();
    
    nodeStack.push(start);
    Iterator localIterator;
    for (; !nodeStack.empty(); localIterator.hasNext())
    {
      CFGNode currentNode = (CFGNode)nodeStack.pop();
      currentNode.setReachable();
      localIterator = currentNode.getSucc().iterator(); continue;CFGNode succ = (CFGNode)localIterator.next();
      if (!succ.isReachable()) {
        nodeStack.push(succ);
      }
    }
  }
  
  private CFGNode createStatement(CFGNode prev, IASTStatement stmt)
  {
    if (cancelMonitor.isCanceled()) {
      throw new TracingCancelException();
    }
    if ((stmt instanceof IASTCompoundStatement))
    {
      IASTCompoundStatement compStmt = (IASTCompoundStatement)stmt;
      IASTStatement[] children = compStmt.getStatements();
      for (int idx = 0; idx < children.length; idx++)
      {
        IASTStatement node = children[idx];
        prev = createStatement(prev, node);
      }
      return prev;
    }
    if ((stmt instanceof IASTExpressionStatement)) {
      return createExpr(prev, ((IASTExpressionStatement)stmt).getExpression(), false);
    }
    if ((stmt instanceof IASTDeclarationStatement)) {
      return createDeclarationStatement(prev, (IASTDeclarationStatement)stmt);
    }
    if ((stmt instanceof IASTIfStatement)) {
      return createIfStatement(prev, (IASTIfStatement)stmt);
    }
    if ((stmt instanceof IASTForStatement)) {
      return createForStatement(prev, (IASTForStatement)stmt);
    }
    if ((stmt instanceof IASTWhileStatement)) {
      return createWhileStatement(prev, (IASTWhileStatement)stmt);
    }
    if ((stmt instanceof IASTDoStatement)) {
      return createDoWhileStatement(prev, (IASTDoStatement)stmt);
    }
    if ((stmt instanceof IASTSwitchStatement)) {
      return createSwitchStatement(prev, (IASTSwitchStatement)stmt);
    }
    if ((stmt instanceof IASTLabelStatement)) {
      return createLabelStatement(prev, (IASTLabelStatement)stmt);
    }
    if ((stmt instanceof IASTGotoStatement)) {
      return createGotoStatement(prev, (IASTGotoStatement)stmt);
    }
    if ((stmt instanceof IASTReturnStatement)) {
      return createReturnStatement(prev, (IASTReturnStatement)stmt);
    }
    if ((stmt instanceof IASTCaseStatement)) {
      return createCaseStatement(prev);
    }
    if ((stmt instanceof IASTDefaultStatement)) {
      return createDefaultStatement(prev);
    }
    if ((stmt instanceof IASTBreakStatement))
    {
      connectNodes(prev, (CFGNode)breakStack.peek());
      return null;
    }
    if ((stmt instanceof IASTContinueStatement))
    {
      connectNodes(prev, (CFGNode)continueStack.peek());
      return null;
    }
    return prev;
  }
  
  private CFGNode createDeclarationStatement(CFGNode prev, IASTDeclarationStatement stmt)
  {
    IASTDeclaration decl = stmt.getDeclaration();
    if ((decl instanceof IASTFunctionDefinition)) {
      throw new TracingUnsupportedException();
    }
    prev = createDeclaration(prev, decl);
    return prev;
  }
  
  private CFGNode createDeclaration(CFGNode prev, IASTDeclaration decl)
  {
    if ((decl instanceof IASTSimpleDeclaration))
    {
      IASTSimpleDeclaration simpleDecl = (IASTSimpleDeclaration)decl;
      IASTDeclarator[] declarators = simpleDecl.getDeclarators();
      IASTDeclarator[] arrayOfIASTDeclarator1;
      int j = (arrayOfIASTDeclarator1 = declarators).length;
      for (int i = 0; i < j; i++)
      {
        IASTDeclarator declarator = arrayOfIASTDeclarator1[i];
        prev = createDeclarator(prev, declarator);
      }
    }
    return prev;
  }
  
  private CFGNode createDeclarator(CFGNode prev, IASTDeclarator declarator)
  {
    IASTInitializer init = declarator.getInitializer();
    if (init != null) {
      prev = createInitializer(prev, init, false);
    }
    if ((declarator instanceof IASTArrayDeclarator))
    {
      IASTArrayDeclarator ad = (IASTArrayDeclarator)declarator;
      IASTArrayModifier[] am = ad.getArrayModifiers();
      for (int idx = am.length - 1; idx >= 0; idx--)
      {
        IASTExpression expr = am[idx].getConstantExpression();
        if (expr != null) {
          prev = createExpr(prev, expr, false);
        }
      }
    }
    if (declarator.getNestedDeclarator() == null)
    {
      IASTName name = declarator.getName();
      if (isSelectedBinding(name))
      {
        CFGNode node = createNode(name, Integer.valueOf(0));
        connectNodes(prev, node);
        prev = node;
      }
    }
    else
    {
      prev = createDeclarator(prev, declarator.getNestedDeclarator());
    }
    return prev;
  }
  
  private CFGNode createIfStatement(CFGNode prev, IASTIfStatement stmt)
  {
    prev = createExpr(prev, stmt.getConditionExpression(), false);
    
    CFGNode thenNode = createStatement(prev, stmt.getThenClause());
    CFGNode joinNode = createNode(null, Integer.valueOf(2));
    CFGNode elseNode = null;
    
    connectNodes(thenNode, joinNode);
    if (stmt.getElseClause() == null)
    {
      connectNodes(prev, joinNode);
    }
    else
    {
      elseNode = createStatement(prev, stmt.getElseClause());
      connectNodes(elseNode, joinNode);
    }
    return joinNode;
  }
  
  private CFGNode createForStatement(CFGNode prev, IASTForStatement stmt)
  {
    CFGNode beforeCondNode = createNode(null, Integer.valueOf(2));
    CFGNode beforeIterNode = createNode(null, Integer.valueOf(2));
    CFGNode joinNode = createNode(null, Integer.valueOf(2));
    CFGNode lastNode = null;
    
    continueStack.push(beforeIterNode);
    breakStack.push(joinNode);
    
    prev = createStatement(prev, stmt.getInitializerStatement());
    
    connectNodes(prev, beforeCondNode);
    
    prev = createExpr(beforeCondNode, stmt.getConditionExpression(), false);
    lastNode = createStatement(prev, stmt.getBody());
    
    connectNodes(lastNode, beforeIterNode);
    connectNodes(prev, joinNode);
    
    prev = createExpr(beforeIterNode, stmt.getIterationExpression(), false);
    
    connectNodes(prev, beforeCondNode);
    
    breakStack.pop();
    continueStack.pop();
    
    return joinNode;
  }
  
  private CFGNode createWhileStatement(CFGNode prev, IASTWhileStatement stmt)
  {
    CFGNode joinNode = createNode(null, Integer.valueOf(2));
    CFGNode beforeCondNode = createNode(null, Integer.valueOf(2));
    CFGNode lastNode = null;
    
    continueStack.push(beforeCondNode);
    breakStack.push(joinNode);
    
    connectNodes(prev, beforeCondNode);
    
    prev = createExpr(beforeCondNode, stmt.getCondition(), false);
    lastNode = createStatement(prev, stmt.getBody());
    
    connectNodes(lastNode, beforeCondNode);
    
    connectNodes(prev, joinNode);
    
    breakStack.pop();
    continueStack.pop();
    
    return joinNode;
  }
  
  private CFGNode createDoWhileStatement(CFGNode prev, IASTDoStatement stmt)
  {
    CFGNode loopStartNode = createNode(null, Integer.valueOf(2));
    CFGNode beforeCondNode = createNode(null, Integer.valueOf(2));
    CFGNode joinNode = createNode(null, Integer.valueOf(2));
    CFGNode lastNode = null;
    
    continueStack.push(beforeCondNode);
    breakStack.push(joinNode);
    
    connectNodes(prev, loopStartNode);
    
    lastNode = createStatement(loopStartNode, stmt.getBody());
    
    connectNodes(lastNode, beforeCondNode);
    
    prev = createExpr(beforeCondNode, stmt.getCondition(), false);
    
    connectNodes(prev, loopStartNode);
    connectNodes(prev, joinNode);
    
    breakStack.pop();
    continueStack.pop();
    
    return joinNode;
  }
  
  private CFGNode createSwitchStatement(CFGNode prev, IASTSwitchStatement stmt)
  {
    prev = createExpr(prev, stmt.getControllerExpression(), false);
    
    CFGNode joinNode = createNode(null, Integer.valueOf(2));
    
    caseStack.push(prev);
    breakStack.push(joinNode);
    
    CFGNode lastNode = createStatement(null, stmt.getBody());
    connectNodes(lastNode, joinNode);
    if (defaultTable.get(caseStack.peek()) == null) {
      connectNodes((CFGNode)caseStack.peek(), joinNode);
    }
    breakStack.pop();
    caseStack.pop();
    
    return joinNode;
  }
  
  private CFGNode createLabelStatement(CFGNode prev, IASTLabelStatement stmt)
  {
    String labelName = stmt.getName().toString();
    CFGNode labelNode = (CFGNode)labels.get(labelName);
    if (labelNode == null)
    {
      labelNode = createNode(null, Integer.valueOf(2));
      labels.put(labelName, labelNode);
    }
    connectNodes(prev, labelNode);
    
    return createStatement(labelNode, stmt.getNestedStatement());
  }
  
  private CFGNode createGotoStatement(CFGNode prev, IASTGotoStatement stmt)
  {
    String labelName = stmt.getName().toString();
    CFGNode labelNode = (CFGNode)labels.get(labelName);
    if (labelNode == null)
    {
      labelNode = createNode(null, Integer.valueOf(2));
      labels.put(labelName, labelNode);
    }
    connectNodes(prev, labelNode);
    
    return null;
  }
  
  private CFGNode createReturnStatement(CFGNode prev, IASTReturnStatement stmt)
  {
    IASTExpression expr = stmt.getReturnValue();
    if (expr != null) {
      createExpr(prev, expr, false);
    }
    return null;
  }
  
  private CFGNode createCaseStatement(CFGNode prev)
  {
    CFGNode caseSkipNode = createNode(null, Integer.valueOf(2));
    
    connectNodes(prev, caseSkipNode);
    connectNodes((CFGNode)caseStack.peek(), caseSkipNode);
    
    return caseSkipNode;
  }
  
  private CFGNode createDefaultStatement(CFGNode prev)
  {
    CFGNode defaultSkipNode = createNode(null, Integer.valueOf(2));
    
    connectNodes(prev, defaultSkipNode);
    connectNodes((CFGNode)caseStack.peek(), defaultSkipNode);
    
    defaultTable.put((CFGNode)caseStack.peek(), defaultSkipNode);
    
    return defaultSkipNode;
  }
  
  private CFGNode createExpr(CFGNode prev, IASTExpression expr, boolean side)
  {
    if ((expr instanceof IASTFieldReference))
    {
      IASTFieldReference fieldRef = (IASTFieldReference)expr;
      IASTExpression fieldOwner = fieldRef.getFieldOwner();
      if (fieldRef.isPointerDereference()) {
        prev = createExpr(prev, fieldOwner, false);
      } else if (searchId(fieldOwner) == null) {
        prev = createExpr(prev, fieldOwner, false);
      }
    }
    else if ((expr instanceof ICASTTypeIdInitializerExpression))
    {
      ICASTTypeIdInitializerExpression initExpr = (ICASTTypeIdInitializerExpression)expr;
      prev = createInitializer(prev, initExpr.getInitializer(), false);
    }
    else if ((expr instanceof IASTIdExpression))
    {
      IASTName name = ((IASTIdExpression)expr).getName();
      if (isSelectedBinding(name))
      {
        CFGNode node;
        CFGNode node;
        if (side) {
          node = createNode(name, Integer.valueOf(0));
        } else {
          node = createNode(name, Integer.valueOf(1));
        }
        connectNodes(prev, node);
        prev = node;
      }
    }
    else if ((expr instanceof IGNUASTCompoundStatementExpression))
    {
      IGNUASTCompoundStatementExpression compoundStmtExpr = 
        (IGNUASTCompoundStatementExpression)expr;
      prev = createStatement(prev, compoundStmtExpr.getCompoundStatement());
    }
    else if ((expr instanceof IASTArraySubscriptExpression))
    {
      IASTArraySubscriptExpression arrayExpr = (IASTArraySubscriptExpression)expr;
      prev = createExpr(prev, (IASTExpression)arrayExpr.getArgument(), false);
      prev = createExpr(prev, arrayExpr.getArrayExpression(), false);
    }
    else if ((expr instanceof IASTBinaryExpression))
    {
      IASTBinaryExpression binaryExpr = (IASTBinaryExpression)expr;
      int operator = binaryExpr.getOperator();
      IASTExpression operand1 = binaryExpr.getOperand1();
      IASTExpression operand2 = binaryExpr.getOperand2();
      switch (operator)
      {
      case 17: 
        prev = createExpr(prev, operand2, false);
        prev = createExpr(prev, operand1, true);
        break;
      case 18: 
      case 19: 
      case 20: 
      case 21: 
      case 22: 
      case 23: 
      case 24: 
      case 25: 
      case 26: 
      case 27: 
        prev = createExpr(prev, operand1, false);
        prev = createExpr(prev, operand2, false);
        prev = createExpr(prev, operand1, true);
        break;
      case 15: 
      case 16: 
        CFGNode skip = createNode(null, Integer.valueOf(2));
        CFGNode cond = createExpr(prev, operand1, false);
        prev = createExpr(cond, operand2, false);
        connectNodes(prev, skip);
        connectNodes(cond, skip);
        prev = skip;
        break;
      default: 
        prev = createExpr(prev, operand1, false);
        prev = createExpr(prev, operand2, false);break;
      }
    }
    else if ((expr instanceof IASTUnaryExpression))
    {
      IASTUnaryExpression unaryExpr = (IASTUnaryExpression)expr;
      int operator = unaryExpr.getOperator();
      IASTExpression operand = unaryExpr.getOperand();
      switch (operator)
      {
      case 0: 
      case 1: 
        IASTIdExpression id = searchId(operand);
        if ((id != null) && 
          (isSelectedBinding(id.getName())))
        {
          CFGNode use = createNode(id.getName(), Integer.valueOf(1));
          connectNodes(prev, use);
          CFGNode def = createNode(id.getName(), Integer.valueOf(0));
          connectNodes(use, def);
          prev = def;
        }
        prev = createExpr(prev, operand, false);
        break;
      case 9: 
      case 10: 
        IASTIdExpression id = searchId(operand);
        prev = createExpr(prev, operand, false);
        if ((id == null) || 
          (!isSelectedBinding(id.getName()))) {
          break;
        }
        CFGNode use = createNode(id.getName(), Integer.valueOf(1));
        connectNodes(prev, use);
        CFGNode def = createNode(id.getName(), Integer.valueOf(0));
        connectNodes(use, def);
        prev = def;
        
        break;
      case 11: 
        prev = createExpr(prev, operand, side);
        break;
      case 5: 
        if (searchId(operand) == null)
        {
          prev = createExpr(prev, operand, false); break;
        }
        throw new TracingUnsupportedException();
      case 2: 
      case 3: 
      case 4: 
      case 6: 
      case 7: 
      case 8: 
      default: 
        prev = createExpr(prev, operand, false);break;
      }
    }
    else if ((expr instanceof IASTCastExpression))
    {
      prev = createExpr(prev, ((IASTCastExpression)expr).getOperand(), false);
    }
    else
    {
      IASTExpression positiveExpr;
      IASTExpression negativeExpr;
      CFGNode skip;
      if ((expr instanceof IASTConditionalExpression))
      {
        IASTConditionalExpression conditionalExpr = (IASTConditionalExpression)expr;
        IASTExpression conditionExpr = conditionalExpr.getLogicalConditionExpression();
        positiveExpr = conditionalExpr.getPositiveResultExpression();
        negativeExpr = conditionalExpr.getNegativeResultExpression();
        skip = createNode(null, Integer.valueOf(2));
        if (!side)
        {
          prev = createExpr(prev, conditionExpr, false);
          connectNodes(createExpr(prev, positiveExpr, false), skip);
          connectNodes(createExpr(prev, negativeExpr, false), skip);
        }
        else
        {
          prev = createExpr(prev, conditionExpr, false);
          connectNodes(createExpr(prev, positiveExpr, true), skip);
          connectNodes(createExpr(prev, negativeExpr, true), skip);
        }
        prev = skip;
      }
      else if ((expr instanceof IASTExpressionList))
      {
        IASTExpression[] exprs = ((IASTExpressionList)expr).getExpressions();
        negativeExpr = (skip = exprs).length;
        for (positiveExpr = 0; positiveExpr < negativeExpr; positiveExpr++)
        {
          IASTExpression subexpr = skip[positiveExpr];
          prev = createExpr(prev, subexpr, false);
        }
      }
      else if ((expr instanceof IASTFunctionCallExpression))
      {
        IASTFunctionCallExpression functionExpr = (IASTFunctionCallExpression)expr;
        prev = createExpr(prev, functionExpr.getFunctionNameExpression(), false);
        IASTInitializerClause[] clauses = functionExpr.getArguments();
        for (int i = clauses.length - 1; i >= 0; i--) {
          prev = createInitializerClause(prev, clauses[i], false);
        }
      }
    }
    return prev;
  }
  
  private CFGNode createInitializer(CFGNode prev, IASTInitializer init, boolean side)
  {
    if ((init instanceof IASTEqualsInitializer)) {
      prev = createEqualsInitializer(prev, (IASTEqualsInitializer)init, side);
    } else if ((init instanceof IASTInitializerList)) {
      prev = createInitializerList(prev, (IASTInitializerList)init, side);
    } else if ((init instanceof ICASTDesignatedInitializer)) {
      prev = createDesignatedInitializer(prev, (ICASTDesignatedInitializer)init, side);
    }
    return prev;
  }
  
  private CFGNode createEqualsInitializer(CFGNode prev, IASTEqualsInitializer init, boolean side)
  {
    return createInitializerClause(prev, init.getInitializerClause(), side);
  }
  
  private CFGNode createInitializerClause(CFGNode prev, IASTInitializerClause clause, boolean side)
  {
    if ((clause instanceof ICASTDesignatedInitializer)) {
      prev = createDesignatedInitializer(prev, (ICASTDesignatedInitializer)clause, side);
    } else if ((clause instanceof IASTInitializerList)) {
      prev = createInitializerList(prev, (IASTInitializerList)clause, side);
    } else if ((clause instanceof IASTExpression)) {
      prev = createExpr(prev, (IASTExpression)clause, side);
    }
    return prev;
  }
  
  private CFGNode createDesignatedInitializer(CFGNode prev, ICASTDesignatedInitializer desgInit, boolean side)
  {
    prev = createInitializerClause(prev, desgInit.getOperand(), false);
    ICASTDesignator[] desgs = desgInit.getDesignators();
    ICASTDesignator[] arrayOfICASTDesignator1;
    int j = (arrayOfICASTDesignator1 = desgs).length;
    for (int i = 0; i < j; i++)
    {
      ICASTDesignator desg = arrayOfICASTDesignator1[i];
      prev = createDesignator(prev, desg, false);
    }
    return prev;
  }
  
  private CFGNode createDesignator(CFGNode prev, ICASTDesignator desg, boolean side)
  {
    if ((desg instanceof ICASTArrayDesignator)) {
      prev = createArrayDesignator(prev, (ICASTArrayDesignator)desg, side);
    } else if ((desg instanceof ICASTFieldDesignator)) {
      prev = createFieldDesignator(prev, (ICASTFieldDesignator)desg, side);
    } else if ((desg instanceof IGCCASTArrayRangeDesignator)) {
      prev = createArrayRangeDesignator(prev, (IGCCASTArrayRangeDesignator)desg, side);
    }
    return prev;
  }
  
  private CFGNode createArrayDesignator(CFGNode prev, ICASTArrayDesignator arrayDesg, boolean side)
  {
    return prev = createExpr(prev, arrayDesg.getSubscriptExpression(), side);
  }
  
  private CFGNode createFieldDesignator(CFGNode prev, ICASTFieldDesignator fieldDesg, boolean side)
  {
    return prev;
  }
  
  private CFGNode createArrayRangeDesignator(CFGNode prev, IGCCASTArrayRangeDesignator arrayRangeDesg, boolean side)
  {
    prev = createExpr(prev, arrayRangeDesg.getRangeFloor(), side);
    prev = createExpr(prev, arrayRangeDesg.getRangeCeiling(), side);
    return prev;
  }
  
  private CFGNode createInitializerList(CFGNode prev, IASTInitializerList initList, boolean side)
  {
    IASTInitializerClause[] clauses = initList.getClauses();
    IASTInitializerClause[] arrayOfIASTInitializerClause1;
    int j = (arrayOfIASTInitializerClause1 = clauses).length;
    for (int i = 0; i < j; i++)
    {
      IASTInitializerClause clause = arrayOfIASTInitializerClause1[i];
      prev = createInitializerClause(prev, clause, side);
    }
    return prev;
  }
  
  private void connectNodes(CFGNode prev, CFGNode next)
  {
    if ((prev == null) || (next == null)) {
      return;
    }
    prev.addSucc(next);
    next.addPred(prev);
  }
  
  private CFGNode createNode(IASTName name, Integer nodeType)
  {
    CFGNode node = null;
    if (nodeType.intValue() == 0) {
      node = new DefNode(name, nodeCount);
    } else if (nodeType.intValue() == 1) {
      node = new UseNode(name, nodeCount);
    } else if (nodeType.intValue() == 2) {
      node = new SkipNode(nodeCount);
    }
    if (name == selectedName) {
      nameMatchedNode.add(node);
    }
    nodeCount += 1;
    
    return node;
  }
  
  private boolean isNestedFunction(IASTFunctionDefinition currentFunction)
  {
    IASTNode parent = currentFunction.getParent();
    while (parent != null)
    {
      if ((parent instanceof IASTFunctionDefinition)) {
        return true;
      }
      parent = parent.getParent();
    }
    return false;
  }
  
  private boolean isSelectedBinding(IASTName name)
  {
    return selectedName.resolveBinding().equals(name.resolveBinding());
  }
  
  private IASTIdExpression searchId(IASTExpression expr)
  {
    if ((expr instanceof IASTIdExpression))
    {
      IASTIdExpression idExpr = (IASTIdExpression)expr;
      if (isSelectedBinding(idExpr.getName())) {
        return idExpr;
      }
      return null;
    }
    if ((expr instanceof IASTUnaryExpression))
    {
      IASTUnaryExpression unaryExpr = (IASTUnaryExpression)expr;
      if (unaryExpr.getOperator() == 11) {
        return searchId(unaryExpr.getOperand());
      }
      return null;
    }
    return null;
  }
  
  public int getNodeCount()
  {
    return nodeCount;
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativeapp.assignmenttracing.core.CFGBuilder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativeapp.assignmenttracing.core;

import java.util.ArrayList;
import java.util.List;

public class CFGNode
{
  private List<CFGNode> pred;
  private List<CFGNode> succ;
  private boolean reachable = false;
  private int id;
  
  CFGNode(int id)
  {
    this.id = id;
    
    pred = new ArrayList();
    succ = new ArrayList();
  }
  
  public int getID()
  {
    return id;
  }
  
  public List<CFGNode> getPred()
  {
    return pred;
  }
  
  public List<CFGNode> getSucc()
  {
    return succ;
  }
  
  void addSucc(CFGNode node)
  {
    succ.add(node);
  }
  
  void addPred(CFGNode node)
  {
    pred.add(node);
  }
  
  public void setReachable()
  {
    reachable = true;
  }
  
  public boolean isReachable()
  {
    return reachable;
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativeapp.assignmenttracing.core.CFGNode
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativeapp.assignmenttracing.core;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.tizen.nativeapp.assignmenttracing.core.exceptions.TracingUnsupportedException;

public class ChainBuilder
{
  private ArrayList<IASTName> udChain;
  private ArrayList<IASTName> duChain;
  private boolean[] explored;
  private int visitedNodes;
  private int visitedSkipNodes;
  private int visitedUseNodes;
  private int visitedDefNodes;
  
  public void buildChain(List<CFGNode> selNodes, int nodeCount)
  {
    explored = new boolean[nodeCount];
    duChain = new ArrayList();
    udChain = new ArrayList();
    for (CFGNode selNode : selNodes) {
      if (selNode.isReachable())
      {
        if ((selNode instanceof DefNode))
        {
          initializeFlagArray();
          calcDUChain(selNode);
        }
        else if ((selNode instanceof UseNode))
        {
          initializeFlagArray();
          calcUDChain(selNode);
        }
      }
      else {
        throw new TracingUnsupportedException();
      }
    }
    explored = null;
  }
  
  public List<IASTName> getDUChain()
  {
    return duChain;
  }
  
  public List<IASTName> getUDChain()
  {
    return udChain;
  }
  
  private void initializeFlagArray()
  {
    for (int i = 0; i < explored.length; i++) {
      explored[i] = false;
    }
  }
  
  private void calcDUChain(CFGNode node)
  {
    Stack<CFGNode> nodeStack = new Stack();
    nodeStack.push(node);
    Iterator localIterator;
    for (; !nodeStack.empty(); localIterator.hasNext())
    {
      CFGNode currentNode = (CFGNode)nodeStack.pop();
      
      explored[currentNode.getID()] = true;
      localIterator = currentNode.getSucc().iterator(); continue;CFGNode succ = (CFGNode)localIterator.next();
      if (explored[succ.getID()] == 0)
      {
        if ((succ instanceof UseNode))
        {
          UseNode useNode = (UseNode)succ;
          duChain.add(useNode.getASTName());
        }
        if (!(succ instanceof DefNode)) {
          nodeStack.push(succ);
        }
      }
    }
  }
  
  private void calcUDChain(CFGNode node)
  {
    Stack<CFGNode> nodeStack = new Stack();
    nodeStack.push(node);
    Iterator localIterator;
    for (; !nodeStack.empty(); localIterator.hasNext())
    {
      CFGNode currentNode = (CFGNode)nodeStack.pop();
      
      explored[currentNode.getID()] = true;
      localIterator = currentNode.getPred().iterator(); continue;CFGNode pred = (CFGNode)localIterator.next();
      if ((explored[pred.getID()] == 0) && (pred.isReachable())) {
        if ((pred instanceof DefNode))
        {
          explored[pred.getID()] = true;
          DefNode defNode = (DefNode)pred;
          udChain.add(defNode.getASTName());
        }
        else
        {
          nodeStack.push(pred);
        }
      }
    }
  }
  
  private void initStat()
  {
    visitedNodes = 0;
    visitedSkipNodes = 0;
    visitedUseNodes = 0;
    visitedDefNodes = 0;
  }
  
  private void checkStat(CFGNode node)
  {
    visitedNodes += 1;
    if ((node instanceof UseNode)) {
      visitedUseNodes += 1;
    } else if ((node instanceof DefNode)) {
      visitedDefNodes += 1;
    } else if ((node instanceof SkipNode)) {
      visitedSkipNodes += 1;
    }
  }
  
  private void printStat()
  {
    System.out.println("ChainBuilder visited " + visitedNodes + 
      "(skip " + visitedSkipNodes + 
      ",use " + visitedUseNodes + 
      ",def " + visitedDefNodes + 
      ")");
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativeapp.assignmenttracing.core.ChainBuilder
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativeapp.assignmenttracing.core;

import org.eclipse.cdt.core.dom.ast.IASTName;

public class DefNode
  extends CFGNode
{
  private IASTName name;
  
  DefNode(IASTName name, int id)
  {
    super(id);
    this.name = name;
  }
  
  public IASTName getASTName()
  {
    return name;
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativeapp.assignmenttracing.core.DefNode
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativeapp.assignmenttracing.core;

public class SkipNode
  extends CFGNode
{
  SkipNode(int id)
  {
    super(id);
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativeapp.assignmenttracing.core.SkipNode
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativeapp.assignmenttracing.core;

import org.eclipse.cdt.core.dom.ast.IASTName;

public class UseNode
  extends CFGNode
{
  private IASTName name;
  
  UseNode(IASTName name, int id)
  {
    super(id);
    this.name = name;
  }
  
  public IASTName getASTName()
  {
    return name;
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativeapp.assignmenttracing.core.UseNode
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativeapp.assignmenttracing.core.exceptions;

public class NameFoundException
  extends Exception
{
  static final long serialVersionUID = 3944807270362832384L;
}

/* Location:
 * Qualified Name:     org.tizen.nativeapp.assignmenttracing.core.exceptions.NameFoundException
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativeapp.assignmenttracing.core.exceptions;

public class TracingCancelException
  extends RuntimeException
{
  private static final long serialVersionUID = -6162831020705844096L;
}

/* Location:
 * Qualified Name:     org.tizen.nativeapp.assignmenttracing.core.exceptions.TracingCancelException
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativeapp.assignmenttracing.core.exceptions;

public class TracingUnsupportedException
  extends RuntimeException
{
  private static final long serialVersionUID = 1357647060362109017L;
}

/* Location:
 * Qualified Name:     org.tizen.nativeapp.assignmenttracing.core.exceptions.TracingUnsupportedException
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativeapp.assignmenttracing.ui;

import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;

class AssignmentTracingUI$1
  implements ISelectionListener
{
  AssignmentTracingUI$1(AssignmentTracingUI paramAssignmentTracingUI) {}
  
  public void selectionChanged(IWorkbenchPart part, ISelection selection)
  {
    if (!(part instanceof IEditorPart)) {
      return;
    }
    AssignmentTracingUI.msg("selected");
    if (AssignmentTracingUI.access$0(this$0) == null) {
      return;
    }
    if (!AssignmentTracingUI.access$0(this$0).equals(part)) {
      return;
    }
    if ((selection instanceof ITextSelection)) {
      this$0.showDUSelection((ITextSelection)selection);
    } else {
      AssignmentTracingUI.access$1(this$0);
    }
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativeapp.assignmenttracing.ui.AssignmentTracingUI.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativeapp.assignmenttracing.ui;

import java.util.Comparator;
import org.eclipse.jface.text.Position;

class AssignmentTracingUI$2$1
  implements Comparator<Position>
{
  AssignmentTracingUI$2$1(AssignmentTracingUI.2 param2) {}
  
  public int compare(Position arg0, Position arg1)
  {
    return arg0.getOffset() - arg1.getOffset();
  }
}

/* Location:
 * Qualified Name:     org.tizen.nativeapp.assignmenttracing.ui.AssignmentTracingUI.2.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package org.tizen.nativeapp.assignmenttracing.ui;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.dom.ast.IASTNodeSelector;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.text.SharedASTJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.Position;
import org.tizen.nativeapp.assignmenttracing.core.CFGBuilder;
import org.tizen.nativeapp.assignmenttracing.core.CFGNode;
import org.tizen.nativeapp.assignmenttracing.core.ChainBuilder;
import org.tizen.nativeapp.assignmenttracing.core.exceptions.TracingCancelException;
import org.tizen.nativeapp.assignmenttracing.core.exceptions.TracingUnsupportedException;

class AssignmentTracingUI$2
  extends SharedASTJob
{
  AssignmentTracingUI$2(AssignmentTracingUI paramAssignmentTracingUI, String $anonymous0, ITranslationUnit $anonymous1, ITextSelection paramITextSelection)
  {
    super($anonymous0, $anonymous1);
  }
  
  private IProgressMonitor cancelMonitor = new NullProgressMonitor();
  private final Comparator<Position> offsetComparator = new Comparator()
  {
    public int compare(Position arg0, Position arg1)
    {
      return arg0.getOffset() - arg1.getOffset();
    }
  };
  
  protected void canceling()
  {
    AssignmentTracingUI.msg("canceling " + this);
    cancelMonitor.setCanceled(true);
  }
  
  public IStatus runOnAST(ILanguage lang, IASTTranslationUnit ast)
    throws CoreException
  {
    AssignmentTracingUI.msg("start " + this);
    if (cancelMonitor.isCanceled()) {
      return Status.CANCEL_STATUS;
    }
    synchronized (this$0)
    {
      AssignmentTracingUI.access$2(this$0, null);
      
      IASTNodeSelector selector = ast.getNodeSelector(null);
      IASTName name = selector.findEnclosingName(
        val$selection.getOffset(), val$selection.getLength());
      if (name == null) {
        name = selector.findEnclosingImplicitName(
          val$selection.getOffset(), val$selection.getLength());
      }
      if (name == null)
      {
        AssignmentTracingUI.access$1(this$0);
        return Status.CANCEL_STATUS;
      }
      if (cancelMonitor.isCanceled()) {
        return Status.CANCEL_STATUS;
      }
      if (!AssignmentTracingUI.isInteresting(name))
      {
        AssignmentTracingUI.access$1(this$0);
        return Status.CANCEL_STATUS;
      }
      IASTFunctionDefinition func = AssignmentTracingUI.access$3(this$0, name);
      if (func == null) {
        return Status.CANCEL_STATUS;
      }
      if (cancelMonitor.isCanceled()) {
        return Status.CANCEL_STATUS;
      }
      CFGBuilder cfgBuilder = new CFGBuilder(cancelMonitor);
      try
      {
        List<CFGNode> cfgNodes = cfgBuilder.buildCFG(func, name);
        cfgBuilder.checkReachability();
      }
      catch (TracingCancelException localTracingCancelException)
      {
        return Status.CANCEL_STATUS;
      }
      catch (TracingUnsupportedException localTracingUnsupportedException1)
      {
        AssignmentTracingUI.access$1(this$0);
        return Status.CANCEL_STATUS;
      }
      List<CFGNode> cfgNodes;
      if (cancelMonitor.isCanceled()) {
        return Status.CANCEL_STATUS;
      }
      ChainBuilder chainBuilder = new ChainBuilder();
      try
      {
        chainBuilder.buildChain(cfgNodes, cfgBuilder.getNodeCount())
1 2

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd