Example #1
0
 /* find the api name for a file and chop it off the source path.
  * what remains from the source path is the directory that contains
  * the file( including sub-directories )
  */
 public static Path sourcePath(String file, APIName name) throws IOException {
   Debug.debug(Debug.Type.REPOSITORY, 2, "True api name is ", name);
   String fullPath = new File(file).getCanonicalPath();
   Debug.debug(Debug.Type.REPOSITORY, 2, "Path is ", fullPath);
   Path path = ProjectProperties.SOURCE_PATH;
   /* the path to the file is /absolute/path/a/b/c/foo.fss and the apiname is
    * a.b.c.foo, so we need to take off the apiname plus four more characters,
    * ".fss" or ".fsi"
    */
   String source = fullPath.substring(0, fullPath.length() - (name.toString().length() + 4));
   path = path.prepend(source);
   Debug.debug(Debug.Type.REPOSITORY, 2, "Source path is ", source);
   Debug.debug(Debug.Type.REPOSITORY, 2, "Lookup path is ", path);
   return path;
 }
Example #2
0
 public static boolean checkCompilationUnitName(String filename, String cuname) {
   String rootName = filename.substring(0, filename.lastIndexOf("."));
   rootName = rootName.replace('/', '.');
   rootName = rootName.replace('\\', '.');
   String regex = "(.*\\.)?" + cuname.replace(".", "\\.") + "$";
   Debug.debug(Debug.Type.REPOSITORY, 3, "Checking file name ", rootName, " vs cuname ", regex);
   return rootName.matches(regex);
 }
Example #3
0
  private static Iterable<? extends StaticError> compilerPhases(
      Path path, String file, Option<String> out, boolean link) throws UserError {
    GraphRepository bcr = null;
    Debug.debug(Debug.Type.FORTRESS, 2, "Compiling file ", file);
    APIName name = null;
    try {
      bcr = specificRepository(path);
      name = cuName(file);

      if (isApi(file)) {
        Api a = (Api) bcr.getApi(name).ast();
        if (out.isSome())
          ASTIO.writeJavaAst(
              a, // defaultRepository.getApi(name).ast(),
              out.unwrap());
      } else if (isComponent(file)) {
        Component c;
        if (link) c = (Component) bcr.getLinkedComponent(name).ast();
        else c = (Component) bcr.getComponent(name).ast();
        if (out.isSome()) {
          ASTIO.writeJavaAst(
              c, // defaultRepository.getComponent(name).ast(),
              out.unwrap());
          bcr.deleteComponent(name, true);
        }
      } else {
        throw new UserError(
            "What kind of file is " + file + "? Name should end with .fsi or .fss.");
      }
    } catch (ProgramError pe) {
      Iterable<? extends StaticError> se = pe.getStaticErrors();
      if (se == null) return IterUtil.singleton(new WrappedException(pe, Debug.stackTraceOn()));
      else return flattenErrors(se);
    } catch (RepositoryError ex) {
      throw ex;
    } catch (FileNotFoundException ex) {
      throw new WrappedException(ex);
    } catch (IOException e) {
      throw new WrappedException(e);
    } catch (StaticError ex) {
      return flattenErrors(ex);
    } catch (CompilerBug e) {
      return IterUtil.singleton(new WrappedException(e, Debug.stackTraceOn()));
    } catch (InterpreterBug e) {
      return IterUtil.singleton(new WrappedException(e, Debug.stackTraceOn()));
    } catch (FortressException e) {
      failureBoilerplate(e);
      System.exit(1);
    } finally {
      if (bcr != null && name != null) bcr.deleteComponent(name, false);
    }

    if (bcr != null && bcr.verbose()) System.err.println("Compiling done.");

    return IterUtil.empty();
  }
Example #4
0
 /* run all the analysis available */
 public static AnalyzeResult analyze(
     final FortressRepository repository,
     final GlobalEnvironment env,
     Iterable<Api> apis,
     Iterable<Component> components,
     final long lastModified)
     throws StaticError {
   Phase ph =
       PhaseOrder.makePhaseOrder(finalPhaseOrder, repository, env, apis, components, lastModified);
   AnalyzeResult result = ph.run();
   Debug.debug(Debug.Type.FORTRESS, 1, "All phases done");
   return result;
 }