コード例 #1
0
  public void handleStatement(ASTStatement node) {

    // System.out.println(node.getCode());

    // Drawing
    connector.startSnap(node.getLineNumber());

    // FIXME we'll see how this works

    // Nested scope for by macro
    SimpleNode s = (SimpleNode) node.jjtGetChild(0);

    if (s instanceof ASTStatementList) {
      System.out.println("This'll never happen");
      SymbolTable st = new SymbolTable(Global.getCurrentSymbolTable());
      st.setName("nested");
      Global.setCurrentSymbolTable(st);
      s.jjtAccept(this, null);
      Global.setCurrentSymbolTable(st.getPrevious());
    } else {

      node.jjtGetChild(0).jjtAccept(this, null);
      if (((SimpleNode) node.jjtGetChild(0)).getId() == JJTCALL) {
        ((ASTCall) (node.jjtGetChild(0))).setLineNumber(node.getLineNumber());
      }

      update(node.getLineNumber(), UPDATE_REASON_STATEMENT);
    }
    // System.out.println("endStatement");
    connector.endSnap();
  }
コード例 #2
0
 public void resolve(IdentifierHandler symbolsHandler, String key) {
   ASTValue aValue = (ASTValue) getChildOfType(ParserTreeConstants.JJTVALUE);
   // We are only going to process integer and oid ...
   //
   if (aValue == null) return;
   if (aValue.children == null) return;
   SimpleNode child = (SimpleNode) aValue.children[0];
   child.resolve(symbolsHandler, key);
 }
コード例 #3
0
  public Object visit(SimpleNode node, Object data) {
    int id = node.getId();
    Object retVal = null;

    switch (id) {
      case JJTPROGRAM:
        handleProgram((ASTProgram) node);
        break;
      case JJTDECLARATIONLIST:
        handleDeclarationList((ASTDeclarationList) node);
        break;
      case JJTDECLARATION:
        retVal = handleDeclaration((ASTDeclaration) node);
        break;
      case JJTVARDECL:
        handleVarDecl((ASTVarDecl) node);
        break;
      case JJTARRAYDECLARATION:
        retVal = handleArrayDeclaration((ASTArrayDeclaration) node);
        break;
      case JJTSTATEMENTLIST:
        handleStatementList((ASTStatementList) node);
        break;
      case JJTSTATEMENT:
        handleStatement((ASTStatement) node);
        break;
      case JJTCALL:
        retVal = handleCall((ASTCall) node);
        break;
      case JJTVAR:
        retVal = handleVar((ASTVar) node);
        break;
      case JJTASSIGNMENT:
        handleAssignment((ASTAssignment) node);
        break;
      case JJTEXPRESSION:
        retVal = handleExpression((ASTExpression) node);
        break;
      case JJTARGS:
        retVal = handleArgs((ASTArgs) node);
        break;
      case JJTOP:
        retVal = handleOp((ASTOp) node);
        break;
      case JJTNUM:
        retVal = handleNum((ASTNum) node);
        break;
      case JJTFUNCTION:
        handleFunction((ASTFunction) node);
        break;
      default:
        if (XAALScripter.debug) {
          System.out.println("Unimplemented");
        }
    }
    return retVal;
  }
コード例 #4
0
  // returning false means we're done executing now.
  public Boolean handleDeclaration(ASTDeclaration node) {

    // System.out.println("Visiting decl");
    SimpleNode child = (SimpleNode) node.jjtGetChild(0);
    if (child.getId() == JJTFUNCTION) {
      System.out.println("Found a function");

      startQuestion = questionFactory.getStartQuestion();
      connector.endPar(); // ENDPAR
      connector.endSnap();
      ASTFunction main = Global.getFunction("main");
      connector.addScope(main.getSymbolTable(), "main", "Global");

      main.jjtAccept(this, null);

      return false;
    } else {
      node.jjtGetChild(0).jjtAccept(this, null);
      // update();
      return true;
    }
  }
コード例 #5
0
ファイル: Tests.java プロジェクト: alfongj/gte
 static void doIt(String toParse, BufferedWriter fw, SimpleNode optNode) throws Exception {
   long[] testArray = new long[10];
   double d = 0;
   DoubleStack stack = new DoubleStack();
   for (int j = 0; j < 10; j++) {
     Thread.yield();
     long start = System.currentTimeMillis();
     for (int i = 0; i < 100000; i++) {
       d = optNode.getValue();
     }
     testArray[j] = System.currentTimeMillis() - start;
   }
   fw.write("100000 evaluations: ");
   for (int j = 0; j < 10; j++) {
     fw.write(testArray[j] + ", ");
   }
   fw.write("\n");
 }
コード例 #6
0
ファイル: TypeDiff.java プロジェクト: pauloortins/TCC
  protected void compareDeclarations(
      ASTClassOrInterfaceDeclaration aNode, ASTClassOrInterfaceDeclaration bNode) {
    // now the children, below the modifiers in the AST.

    ASTClassOrInterfaceBodyDeclaration[] aDecls = TypeDeclarationUtil.getDeclarations(aNode);
    ASTClassOrInterfaceBodyDeclaration[] bDecls = TypeDeclarationUtil.getDeclarations(bNode);

    // compare declarations in A against B

    if (aDecls.length == 0) {
      if (bDecls.length == 0) {
        // tr.Ace.log("no change (both of zero length)");
      } else {
        addAllDeclarations(bDecls, aNode, true);
      }
    } else if (bDecls.length == 0) {
      addAllDeclarations(aDecls, bNode, false);
    } else {
      MethodUtil methodUtil = new MethodUtil();
      Map matches = TypeDeclarationUtil.matchDeclarations(aDecls, bDecls, methodUtil);
      Iterator sit = matches.keySet().iterator();
      List aSeen = new ArrayList();
      List bSeen = new ArrayList();

      // TimedEvent dte = new TimedEvent("diffs");

      Collection diffs = get();

      while (sit.hasNext()) {
        Double dScore = (Double) sit.next();
        List atScore = (List) matches.get(dScore);

        Iterator vit = atScore.iterator();
        while (vit.hasNext()) {
          Object[] values = (Object[]) vit.next();

          ASTClassOrInterfaceBodyDeclaration aDecl = (ASTClassOrInterfaceBodyDeclaration) values[0];
          ASTClassOrInterfaceBodyDeclaration bDecl = (ASTClassOrInterfaceBodyDeclaration) values[1];

          aSeen.add(aDecl);
          bSeen.add(bDecl);

          dubaj.tr.Ace.log("aDecl", aDecl);
          dubaj.tr.Ace.log("bDecl", bDecl);

          SimpleNode ad = TypeDeclarationUtil.getDeclaration(aDecl);
          SimpleNode bd = TypeDeclarationUtil.getDeclaration(bDecl);

          // TODO: Adiciona Mudanca do Metodo
          // we know that the classes of aDecl and bDecl are the same
          if (ad instanceof ASTMethodDeclaration) {
            MethodDiff differ = new MethodDiff(diffs);

            boolean achouMudanca = false;

            if (differ.compararAcessoMetodo(aDecl, bDecl, Relatorio.TipoDeclaracao.Metodo)) {
              Relatorio.getMudancaClasse().incrementarMudancasMetodo(new MudancaMetodo());
            }

            if (differ.comparar(
                (ASTMethodDeclaration) ad,
                (ASTMethodDeclaration) bd,
                Relatorio.TipoDeclaracao.Metodo)) {}

          } else if (ad instanceof ASTFieldDeclaration) {
            FieldDiff differ = new FieldDiff(diffs);

            if (differ.compararAcessoMetodo(aDecl, bDecl, Relatorio.TipoDeclaracao.Classe)) {
              Relatorio.getMudancaClasse().incrementarMudancasAtributo();
            }

            differ.compare(
                (ASTFieldDeclaration) ad,
                (ASTFieldDeclaration) bd,
                Relatorio.TipoDeclaracao.Classe);
          } else if (ad instanceof ASTConstructorDeclaration) {
            CtorDiff differ = new CtorDiff(diffs);

            boolean achouMudanca = false;

            if (differ.compararAcessoMetodo(aDecl, bDecl, Relatorio.TipoDeclaracao.Construtor)) {
              achouMudanca = true;
            }

            if (differ.comparar(
                (ASTConstructorDeclaration) ad,
                (ASTConstructorDeclaration) bd,
                Relatorio.TipoDeclaracao.Construtor)) {
              achouMudanca = true;
            }

            if (achouMudanca) {

              String nomeAntigo = CtorUtil.getFullName((ASTConstructorDeclaration) ad);
              String nomeNovo = CtorUtil.getFullName((ASTConstructorDeclaration) bd);
            }

          } else if (ad instanceof ASTClassOrInterfaceDeclaration) {
            // access comparison is done in TypeDiff; confusing.
            compare((ASTClassOrInterfaceDeclaration) ad, (ASTClassOrInterfaceDeclaration) bd);
          } else if (ad == null && bd == null) {
            // a match between semicolons.
            dubaj.tr.Ace.log("matched 'semicolon declarations'");
          } else {
            dubaj.tr.Ace.reverse("WTF? aDecl: " + ad.getClass());
          }
        }
      }

      // dte.close();

      addDeclarations(aDecls, aSeen, bNode, false);
      addDeclarations(bDecls, bSeen, aNode, true);
    }
  }
コード例 #7
0
 /** This method should never be called when evaluation a normal expression. */
 public Object visit(SimpleNode node, Object data) throws ParseException {
   throw new ParseException("No visit method for " + node.getClass().getName());
 }