예제 #1
0
 // This is the constructor used from runFromShell
 public PrologBackend(String[] args) throws Exception {
   // This parses the args and the ABS program producing the AST whose root is model
   model = parse(args);
   if (model.hasParserErrors() || model.hasErrors() || model.hasTypeErrors())
     printParserErrorAndExit();
   initOutStreamEtc();
 }
예제 #2
0
  private void collectReachableCode(ArrayList<ASTNode<?>> entries) {
    reachInfo = new ReachabilityInformation(entries);

    while (reachInfo.changed()) {
      try {
        model.collectReachableCode(reachInfo);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    // System.out.println(reachInfo.toString());
  }
예제 #3
0
  private void generateProlog() {
    if (entries != null) { // mode with entries
      entriesMode = true;
      collectReachableCode(entries);
    }

    // print discontiguous predicate to avoid warnings when loading the file
    outStream.print(
        ":-discontiguous mainBlock/3,def/6, data/3,methodImpl/5,"
            + "module/1, starImport/1,type/2,interface/3,class/3.\n");

    model.generateProlog(outStream, reachInfo);
  }
예제 #4
0
 /**
  * Lists all products in the current project's module, incl. a "<base>" product if no particular
  * product is selected.
  *
  * @param preSelected The product that should be preselected, or null for <base>.
  */
 protected void fillProductDropDownMenue(String preSelected) {
   productDropDown.removeAll();
   productDropDown.add("<base>");
   IProject proj = getSelectedProject();
   if (proj == null) {
     return;
   }
   AbsNature n = UtilityFunctions.getAbsNature(proj);
   Model m = n.getCompleteModel();
   if (m == null) return;
   Collection<Product> prods = m.getProducts();
   if (prods == null) return;
   int i = 1; /* base comes first */
   int selected = 0;
   for (Product p : prods) {
     final String name = p.qualifiedName();
     productDropDown.add(name);
     if (name.equals(preSelected)) {
       selected = i;
     }
     i++;
   }
   productDropDown.select(selected);
 }
예제 #5
0
  /**
   * Don't recommend to start projects which have errors. TODO: manipulating the error message here
   * does not cooperate well with isValid().
   */
  protected boolean updateErrors() {
    boolean res = true;
    String projectName = getSelectedProjectName();
    String prod = getSelectedProductName();
    if (this.lastProjectName != null
        && this.lastProd != null
        && this.lastProjectName.equals(projectName)
        && this.lastProd.equals(prod)) {
      // use result from last time, so that we do not have to do a full typecheck
      // every time something changes in the run configuration dialog
      return lastResult;
    }

    if (projectName != null) {
      IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
      try {
        AbsNature nat = UtilityFunctions.getAbsNature(project);
        assert nat != null;
        synchronized (nat.modelLock) {
          Model model = nat.getCompleteModel();
          /* E.g. errors in the project */
          if (model == null) return false;
          /* Check product if any */

          // work on a copy:
          model = model.parseTreeCopy();

          if (prod != null) {
            model.flattenForProduct(prod);
            /* Type check again */
            model.flushCache(); // #335, see IncrementalModelBuilder#flushAll()
          }
          SemanticErrorList errs = model.getErrors();
          if (errs != null && !errs.isEmpty()) {
            createMarkers(nat, errs);
            throw new AbsJobException(new TypeCheckerException(errs));
          }
          errs = model.typeCheck();
          if (errs != null && !errs.isEmpty()) {
            createMarkers(nat, errs);
            throw new AbsJobException(new TypeCheckerException(errs));
          }
        }
        setErrorMessage(null);
      } catch (AbsJobException e) {
        setErrorMessage(e.getMessage());
        res = false;
      } catch (WrongProgramArgumentException e) {
        setErrorMessage(e.getMessage());
        res = false;
      } catch (DeltaModellingException e) {
        setErrorMessage(e.getMessage());
        res = false;
      }
      getLaunchConfigurationDialog().updateMessage();
    }
    // cache the result
    lastProd = prod;
    lastProjectName = projectName;
    lastResult = res;
    return res;
  }