Esempio n. 1
0
  /**
   * @param out
   * @param path
   * @param file_name
   * @param doLink
   * @return
   * @throws UserError
   * @throws IOException
   */
  private static int compileWithErrorHandling(String s, Option<String> out, boolean doLink)
      throws UserError, IOException {
    int return_code = 0;
    try {
      APIName name = NodeUtil.apiName(s);
      Path path = sourcePath(s, name);
      String file_name = name.toString() + (s.endsWith(".fss") ? ".fss" : ".fsi");

      List<StaticError> errors = new ArrayList<StaticError>();
      for (StaticError error :
          IterUtil.sort(compilerPhases(path, file_name, out, doLink), StaticError.comparator)) {
        if (!error.toString().equals("")) errors.add(error);
      }
      return_code = reportErrors(errors, file_name);
    } catch (StaticError e) {
      return_code = reportErrors(flattenErrors(e), new File(s).getName());
    } catch (ProgramError e) {
      System.err.println(e.getMessage());
      e.printInterpreterStackTrace(System.err);
      if (Debug.stackTraceOn()) {
        e.printStackTrace();
      } else {
        System.err.println(turnOnDebugMessage);
      }
      return_code = 1;
    }
    return return_code;
  }
Esempio n. 2
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;
 }