Example #1
0
  /** Returns a formatted text string of this class. */
  public String toString(int indent) {

    StringBuffer sb = new StringBuffer();

    printSpace(indent, sb);

    sb.append("Iterate \n");
    if (maintaining != null) {
      printSpace(indent, sb);
      sb.append("\tmaintaining " + maintaining.toString(0) + ";\n");
    }
    if (decreasing != null) {
      printSpace(indent, sb);
      sb.append("\tdecreasing " + decreasing.toString(0) + ";\n");
    }
    if (!changing.isEmpty()) {
      printSpace(indent, sb);
      sb.append("\tchanging " + argumentsToString(changing) + ";\n");
    }
    //	printSpace(indent, sb);

    Iterator<Statement> i = statements.iterator();
    while (i.hasNext()) {
      sb.append((i.next()).toString(indent + 4 * 2) + ";\n");
    }
    printSpace(indent, sb);
    sb.append("repeat");

    return sb.toString();
  }
Example #2
0
  /**
   * Builds a list of <code>TheoremEntry</code>s representing all available theorems for Theories
   * currently in scope of the "target file".
   *
   * <p>TODO : Currently this will not include theorems included in theories referenced from
   * included theories. That is, if the target file lists Set_Theory in its "uses" clause, and
   * Set_Theory lists Boolean_Theory in its "uses" clause, only the theorems from Set_Theory will be
   * included.
   *
   * @return The list of Theorems.
   */
  private void buildTheories() {
    myTheorems.clear();
    myPExpTheorems.clear();

    File targetFileName = myInstanceEnvironment.getTargetFile();
    ModuleID targetFileID = myInstanceEnvironment.getModuleID(targetFileName);
    List<ModuleID> availableTheories = myInstanceEnvironment.getTheories(targetFileID);
    Exp curTheorem;

    // Add local axioms to the library
    ModuleDec targetDec = myInstanceEnvironment.getModuleDec(targetFileID);
    addLocalAxioms(targetDec);

    // Add any kind of mathematical assertions from any included library
    SymbolTable curSymbolTable;
    ModuleScope bindingsInScope;
    List<Symbol> symbolsInScope;
    for (ModuleID curModule : availableTheories) {
      curSymbolTable = myInstanceEnvironment.getSymbolTable(curModule);
      bindingsInScope = curSymbolTable.getModuleScope();
      symbolsInScope = bindingsInScope.getLocalTheoremNames();

      for (Symbol s : symbolsInScope) {

        curTheorem = bindingsInScope.getLocalTheorem(s).getValue();
        addTheoremToLibrary(s.getName(), curTheorem);
      }
    }
  }
Example #3
0
  /** Returns a formatted text string of this class. */
  public String asString(int indent, int increment) {

    StringBuffer sb = new StringBuffer();

    printSpace(indent, sb);
    sb.append("IterateStmt\n");

    if (changing != null) {
      sb.append(changing.asString(indent + increment, increment));
    }

    if (maintaining != null) {
      sb.append(maintaining.asString(indent + increment, increment));
    }

    if (decreasing != null) {
      sb.append(decreasing.asString(indent + increment, increment));
    }

    if (statements != null) {
      sb.append(statements.asString(indent + increment, increment));
    }

    return sb.toString();
  }
Example #4
0
  /** Iterates over the files in the list and compiles them one at a time. */
  private static void compileFiles(
      List<File> files, CompileEnvironment instanceEnvironment, MetaFile inputFile) {

    MathSymbolTableBuilder symbolTable = new MathSymbolTableBuilder();
    instanceEnvironment.setSymbolTable(symbolTable);

    for (Iterator<File> i = files.iterator(); i.hasNext(); ) {
      File file = i.next();
      if (file.isDirectory()) {
        if (compileDirs) {
          compileFilesInDir(file, instanceEnvironment);
        } else {
          System.err.println("Skipping directory " + file.getName());
        }
      } else if (!isResolveFile(file.getName())) {
        System.err.println("The file " + file.getName() + " is not a RESOLVE file.");
      } else if (!file.isFile()) {
        System.err.println("Cannot find the file " + file.getName() + " in this directory.");
      } else {
        instanceEnvironment.setTargetFile(file);
        compileMainFile(file, instanceEnvironment, symbolTable);
      }
    }
    if (files.size() == 0) {
      if (instanceEnvironment.flags.isFlagSet(ResolveCompiler.FLAG_WEB)) {
        compileMainSource(inputFile, instanceEnvironment, symbolTable);
      }
    }
  }
Example #5
0
  public Exp replace(Exp old, Exp replacement) {
    if (!(old instanceof QuantExp)) {
      if (where != null) {
        Exp whr = where.replace(old, replacement);
        if (whr != null) this.setWhere(whr);
      }
      if (body != null) {
        Exp bdy = body.replace(old, replacement);
        if (bdy != null) this.setBody(bdy);
        // Not used anywhere below. - YS
        // String str = bdy.toString(0, 0);
      }
      if (vars != null && old instanceof VarExp && replacement instanceof VarExp) {
        // What if Replacement isn't VarExp?
        List<MathVarDec> newVars = new List<MathVarDec>();
        Iterator<MathVarDec> i = vars.iterator();
        while (i.hasNext()) {
          MathVarDec tmp = i.next();
          if (tmp.getName().toString().equals(((VarExp) old).getName().toString())) {
            tmp.setName(((VarExp) replacement).getName());
          }

          newVars.add(tmp);
        }
      }
      return this;
    } else return this;
  }
  private boolean paramCompare(ProgramParamExp p1, ProgramParamExp p2) {
    List<Exp> subExp1 = p1.getSubExpressions();
    List<Exp> subExp2 = p2.getSubExpressions();
    String varName1 = p2.getName().toString();
    String varName2 = p1.getName().toString();

    String semantic = p1.getSemanticExp().toString();
    // System.out.println("Semantic Exp:" + semantic);
    List args = p1.getArguments();
    for (int i = 0; i < args.size(); i++) {
      // System.out.println("args:" + args.get(i).toString());
    }

    // System.out.println(subExp1.toString());
    // System.out.println(subExp2.toString());

    // System.out.println("..." + varName1);
    // System.out.println(varName2);
    // System.out.println(p1.toString());

    if (varName1.equals(varName2)) {
      // System.out.println("they are equal");
      return true;
    }

    return false;
  }
 public List<Exp> getSubExpressions() {
   List<Exp> list = new List<Exp>();
   Iterator<VariableExp> segmentsIt = segments.iterator();
   while (segmentsIt.hasNext()) {
     list.add((Exp) (segmentsIt.next()));
   }
   return list;
 }
 /**
  * Sets the <code>stdUsesDepends</code> lists to the provided updated list
  *
  * @param list The <code>List</code> of <code>List</code> of <code>UsesItem</code> which will be
  *     assigned to the global <code>stdUsesDepends</code>
  */
 public List<OldSymbolTable> getSymbolTables() {
   List<OldSymbolTable> stList = new List<OldSymbolTable>();
   // Map<ModuleID, ModuleRecord> map = myOldEnvironment.getMap();
   for (java.util.Map.Entry<ModuleID, ModuleRecord> st : map.entrySet()) {
     stList.add(st.getValue().getSymbolTable());
   }
   return stList;
 }
Example #9
0
 public List<Exp> getSubExpressions() {
   List<Exp> list = new List<Exp>();
   Iterator<ProgramExp> argIt = arguments.iterator();
   while (argIt.hasNext()) {
     list.add((Exp) (argIt.next()));
   }
   return list;
 }
Example #10
0
  public Exp substituteChildren(java.util.Map<Exp, Exp> substitutions) {
    List<ProgramExp> newSegments = new List<ProgramExp>();
    for (ProgramExp e : segments) {
      newSegments.add((ProgramExp) substitute(e, substitutions));
    }

    return new ProgramDotExp(
        location, newSegments, (ProgramExp) substitute(semanticExp, substitutions));
  }
Example #11
0
  public Exp substituteChildren(java.util.Map<Exp, Exp> substitutions) {
    List<VariableExp> newSegments = new List<VariableExp>();
    for (VariableExp v : segments) {
      newSegments.add((VariableExp) substitute(v, substitutions));
    }

    return new VariableDotExp(
        location, newSegments, (VariableExp) substitute(semanticExp, substitutions));
  }
Example #12
0
  public static void compileFilesInDir(File dir, CompileEnvironment instanceEnvironment) {

    File[] fileArray = dir.listFiles();
    List<File> files = new List<File>();

    // JMH avoid problems with 1.5 generics files.addAll(fileArray);
    //        files.addAll(fileArray);
    for (int i = 0; i < fileArray.length; i++) {
      files.add(fileArray[i]);
    }
    MetaFile dummy = null;
    compileFiles(files, instanceEnvironment, dummy);
  }
Example #13
0
 public Object clone() {
   ProgramDotExp clone = new ProgramDotExp();
   clone.setSemanticExp((ProgramExp) this.getSemanticExp().clone());
   clone.setLocation(this.getLocation());
   if (segments != null) {
     Iterator<ProgramExp> i = segments.iterator();
     List<ProgramExp> newSegments = new List<ProgramExp>();
     while (i.hasNext()) {
       newSegments.add((ProgramExp) i.next().clone());
     }
     clone.setSegments(newSegments);
   }
   return clone;
 }
Example #14
0
 private boolean differentVariableTypeExactCheck(
     List<ProgramParamExp> programParamExpressions, List<VariableExp> variableExpressions) {
   for (int a = 0; a < variableExpressions.size(); a++) {
     for (int b = 0; b < programParamExpressions.size(); b++) {
       // System.out.println("." + variableExpressions.get(a).toString()+".");
       // System.out.println("." + programParamExpressions.get(b).getName().toString()+".");
       if (differentTypeCompare1(programParamExpressions.get(b), variableExpressions.get(a))) {
         // System.out.println("it is possible that it is a,a(i)");
         return true;
       }
     }
   }
   return false;
 }
Example #15
0
  private boolean exactDuplicateCheck2(List<ProgramParamExp> variableExpressions) {
    for (int a = 0; a < variableExpressions.size() - 1; a++) {
      for (int b = 1; b < variableExpressions.size(); b++) {
        // System.out.println("." +variableExpressions.get(a).toString()+".");
        // System.out.println("."+variableExpressions.get(b).toString()+".");
        if (paramCompare(variableExpressions.get(a), variableExpressions.get(b)) == true) {
          // System.out.println("Yes, I am herererererer");
          return true;
        }
      }
    }

    return false;
  }
Example #16
0
  public Exp substituteChildren(java.util.Map<Exp, Exp> substitutions) {
    Exp retval;

    List<ProgramExp> newArguments = new List<ProgramExp>();
    for (ProgramExp a : arguments) {
      newArguments.add((ProgramExp) substitute(a, substitutions));
    }

    retval =
        new ProgramParamExp(
            location, name, newArguments, (ProgramExp) substitute(semanticExp, substitutions));

    retval.setType(type);
    return retval;
  }
 /** Adds a file to the environment which failed to parse. */
 public void abortCompile(File file) {
   if (fmap.containsKey(file)) {
     abortCompile(fmap.get(file));
   } else {
     unparsables.add(file);
     err.message("Add unparsable: " + file.getName()); // DEBUG
   }
 }
Example #18
0
  public Object clone() {
    QuantExp clone = new QuantExp();

    clone.setOperator(this.operator);

    List<MathVarDec> newVars = new List<MathVarDec>();
    Iterator<MathVarDec> i = vars.iterator();
    while (i.hasNext()) {
      newVars.add((MathVarDec) i.next().clone());
    }
    clone.setVars(newVars);
    if (where != null) clone.setWhere((Exp) this.getWhere().clone());
    if (body != null) clone.setBody((Exp) this.getBody().clone());
    clone.setLocation(this.getLocation());
    clone.setType(getType());
    return clone;
  }
Example #19
0
  public Exp copy() {
    int newOperator = operator;
    Iterator<MathVarDec> it = vars.iterator();
    List<MathVarDec> newVars = new List<MathVarDec>();
    while (it.hasNext()) {
      newVars.add(it.next().copy());
    }
    Exp newWhere = null;
    if (where != null) {
      newWhere = where.copy();
    }
    Exp newBody = body.copy();
    Exp retval = new QuantExp(null, newOperator, newVars, newWhere, newBody);

    retval.setType(type);

    return retval;
  }
Example #20
0
  public String split(int indent) {
    StringBuffer sb = new StringBuffer();
    printSpace(indent, sb);
    if (where != null) sb.append(where.toString(1));
    sb.append(printConstant(operator));

    List<MathVarDec> list = vars;
    Iterator<MathVarDec> i = list.iterator();

    while (i.hasNext()) {
      MathVarDec tmp = i.next();
      sb.append(" ");
      sb.append(tmp.toString(0));
    }
    sb.append(", ");
    if (body != null) sb.append(body.toString(0));
    return sb.toString();
  }
Example #21
0
 String argumentsToString(List<ProgramExp> arguments) {
   String str = new String();
   Iterator<ProgramExp> i = arguments.iterator();
   while (i.hasNext()) {
     ProgramExp exp = (ProgramExp) i.next();
     str = str.concat(exp.toString(0));
     if (i.hasNext()) str = str.concat(", ");
   }
   return str;
 }
 /**
  * Returns true if a compile had been attempted on the specified file and was aborted due to
  * errors.
  */
 public boolean compileAborted(File file) {
   if (unparsables.contains(file)) {
     return true;
   }
   if (!fmap.containsKey(file)) {
     return false;
   } else {
     return map.get(fmap.get(file)).containsErrors();
   }
 }
Example #23
0
  private String segmentsToString(List<ProgramExp> segments) {
    StringBuffer sb = new StringBuffer();
    if (segments != null) {
      Iterator<ProgramExp> i = segments.iterator();

      while (i.hasNext()) {
        sb.append(i.next().toString(0));
        if (i.hasNext()) sb.append(".");
      }
    }
    return sb.toString();
  }
Example #24
0
  private void addTheoremToLibrary(String name, Exp theorem) {
    try {

      Exp quantifiersAppliedTheorem = Utilities.applyQuantification(theorem);

      if (quantifiersAppliedTheorem instanceof EqualsExp) {
        myTheorems.add(quantifiersAppliedTheorem);
        myPExpTheorems.add(PExp.buildPExp(quantifiersAppliedTheorem, myTyper));
        myTheoremNames.add(name);
      } else if (quantifiersAppliedTheorem instanceof InfixExp) {
        InfixExp theoremAsInfixExp = (InfixExp) quantifiersAppliedTheorem;
        if (theoremAsInfixExp.getOpName().getName().equals("implies")) {
          myImplications.add(
              new Implication(theoremAsInfixExp.getLeft(), theoremAsInfixExp.getRight()));
        }
      }

    } catch (IllegalArgumentException e) {
      // This theorem contains a "where" clause and just shouldn't
      // be added.
    }
  }
Example #25
0
  private String segmentsToString(List<VariableExp> segments) {
    StringBuffer sb = new StringBuffer();
    // Environment env = Environment.getInstance();
    if (segments != null) {
      Iterator<VariableExp> i = segments.iterator();

      while (i.hasNext()) {
        sb.append(i.next().toString(0));
        if (i.hasNext()) // && !env.isabelle())
        sb.append(".");
      }
    }
    return sb.toString();
  }
 private String getResolveNames(List<File> files) {
   StringBuffer sb = new StringBuffer();
   sb.append("( ");
   Iterator<File> i = files.iterator();
   while (i.hasNext()) {
     File file = i.next();
     sb.append(getResolveName(file));
     if (i.hasNext()) {
       sb.append(", ");
     }
   }
   sb.append(" )");
   return sb.toString();
 }
Example #27
0
  public String toString(int indent) {
    // Environment   env	= Environment.getInstance();
    // if(env.isabelle()){return toIsabelleString(indent);};

    StringBuffer sb = new StringBuffer();
    printSpace(indent, sb);
    if (where != null) sb.append(where.toString(1));
    sb.append(printConstant(operator));

    List<MathVarDec> list = vars;
    Iterator<MathVarDec> i = list.iterator();

    while (i.hasNext()) {
      MathVarDec tmp = i.next();
      sb.append(" ");
      sb.append(tmp.toString(0));
      if (i.hasNext()) {
        sb.append(", ");
      }
    }
    sb.append(" such that ");
    if (body != null) sb.append(body.toString(0));
    return sb.toString();
  }
Example #28
0
 /** Returns true if the variable is found in any sub expression of this one. * */
 public boolean containsVar(String varName, boolean IsOldExp) {
   Iterator<ProgramExp> i = arguments.iterator();
   while (i.hasNext()) {
     ProgramExp temp = i.next();
     if (temp != null) {
       if (temp.containsVar(varName, IsOldExp)) {
         return true;
       }
     }
   }
   if (semanticExp != null) {
     if (semanticExp.containsVar(varName, IsOldExp)) {
       return true;
     }
   }
   return false;
 }
Example #29
0
  /** Returns a formatted text string of this class. */
  public String asString(int indent, int increment) {

    StringBuffer sb = new StringBuffer();

    printSpace(indent, sb);
    sb.append("VariableDotExp\n");

    if (segments != null) {
      sb.append(segments.asString(indent + increment, increment));
    }

    if (semanticExp != null) {
      sb.append(semanticExp.asString(indent + increment, increment));
    }

    return sb.toString();
  }
Example #30
0
 public void prettyPrint() {
   if (operator == FORALL) System.out.print("For all ");
   else if (operator == EXISTS) System.out.print("There exists ");
   else if (operator == UNIQUE) System.out.print("There exists unique ");
   Iterator<MathVarDec> it = vars.iterator();
   if (it.hasNext()) {
     it.next().prettyPrint();
   }
   while (it.hasNext()) {
     System.out.print(", ");
     it.next().prettyPrint();
   }
   if (where != null) {
     System.out.print(", ");
     where.prettyPrint();
   }
   System.out.print(", ");
   body.prettyPrint();
 }