コード例 #1
0
ファイル: STRCommands.java プロジェクト: seba--/sugarj
  public static Path compile(
      Path str,
      String main,
      Map<Path, Integer> dependentFiles,
      SGLR strParser,
      ModuleKeyCache<Path> strCache,
      Environment environment,
      AbstractBaseProcessor baseProcessor)
      throws IOException, InvalidParseTableException, TokenExpectedException, BadTokenException,
          SGLRException {
    ModuleKey key = getModuleKeyForAssimilation(str, main, dependentFiles, strParser);
    Path prog = lookupAssimilationInCache(strCache, key);
    StrategoException error = null;

    if (prog == null) {
      try {
        prog = generateAssimilator(key, str, main, environment.getIncludePath(), baseProcessor);
      } catch (StrategoException e) {
        prog = FAILED_COMPILATION_PATH;
        error = e;
      } finally {
        if (prog != null && FileCommands.exists(prog) && !FileCommands.isEmptyFile(prog))
          prog = cacheAssimilator(strCache, key, prog, environment);
      }

      if (error != null) throw error;
    }

    return prog;
  }
コード例 #2
0
 /**
  * Checks if a consistencycheck needs to be made.
  *
  * @param currentTime the time to check if the consistency needs to be checked.
  * @return true if a consistencycheck needs to be made.
  */
 private boolean needsConsistencyCheck(long currentTime) {
   if (!FileCommands.exists(persistentPath)) {
     writePersistentPath(currentTime);
     return true;
   }
   if (consistencyCheckInterval == NEVER_CHECK) {
     return false;
   }
   long lastConsistencyCheck = readPersistentPath();
   if (lastConsistencyCheck + consistencyCheckInterval < currentTime) {
     return true;
   }
   return false;
 }
コード例 #3
0
ファイル: STRCommands.java プロジェクト: seba--/sugarj
 private static Path generateAssimilator(
     ModuleKey key, Path str, String main, List<Path> paths, AbstractBaseProcessor baseProcessor)
     throws IOException {
   boolean success = false;
   log.beginTask("Generating", "Generate the assimilator", Log.TRANSFORM);
   try {
     Path prog = FileCommands.newTempFile("ctree");
     log.log("calling STRJ", Log.TRANSFORM);
     strj(true, str, prog, main, paths, baseProcessor);
     success = FileCommands.exists(prog);
     return prog;
   } finally {
     log.endTask(success);
   }
 }
コード例 #4
0
ファイル: STRCommands.java プロジェクト: seba--/sugarj
  private static Path cacheAssimilator(
      ModuleKeyCache<Path> strCache, ModuleKey key, Path prog, Environment environment)
      throws IOException {
    if (strCache == null) return prog;

    log.beginTask("Caching", "Cache assimilator", Log.CACHING);
    try {
      Path cacheProg = environment.createCachePath(prog.getFile().getName());
      if (FileCommands.exists(prog)) FileCommands.copyFile(prog, cacheProg);
      else cacheProg = prog;

      Path oldProg = strCache.putGet(key, cacheProg);
      //      FileCommands.delete(oldProg);

      log.log("Cache Location: " + cacheProg, Log.CACHING);
      return cacheProg;
    } finally {
      log.endTask();
    }
  }