Exemplo n.º 1
0
  public static IStrategoTerm assimilate(
      String strategy, Path ctree, IStrategoTerm in, HybridInterpreter interp) throws IOException {
    try {
      interp.load(ctree.getAbsolutePath());
      interp.setCurrent(in);

      if (interp.invoke(strategy)) {
        IStrategoTerm term = interp.current();

        // XXX performance improvement?
        //        interp.reset();

        //        IToken left = ImploderAttachment.getLeftToken(in);
        //        IToken right = ImploderAttachment.getRightToken(in);
        //        String sort = ImploderAttachment.getSort(in);
        //
        //        try {
        //          term = ATermCommands.makeMutable(term);
        //          ImploderAttachment.putImploderAttachment(term, false, sort, left, right);
        //        } catch (Exception e) {
        //          log.log("origin annotation failed");
        //        }
        return term;
      } else throw new RuntimeException("hybrid interpreter failed");
    } catch (InterpreterException e) {
      throw new StrategoException(
          "desugaring failed: " + (e.getCause() == null ? e : e.getCause()).getMessage(), e);
    } catch (Exception e) {
      throw new StrategoException("desugaring failed", e);
    }
  }
Exemplo n.º 2
0
  @Test
  public void extractOriginFromTermLoadedByOtherHybridInterpreter() {
    GlobalFunctionsScript script = new GlobalFunctionsScript();
    script.init();

    HybridInterpreter i = HybridInterpreterHelper.createHybridInterpreter();
    boolean b = true;

    i.setCurrent(script.getApplication());
    b = HybridInterpreterHelper.safeInvoke(i, "origin-location");
    Assert.assertTrue(b);
    Assert.assertNotNull(i.current());
    Assert.assertEquals("(1,0,14,20)", i.current().toString());

    i.setCurrent(script.getResetScheduleFunction());
    b = HybridInterpreterHelper.safeInvoke(i, "origin-location");
    Assert.assertTrue(b);
    Assert.assertNotNull(i.current());
    Assert.assertEquals("(3,1,8,1)", i.current().toString());

    i.setCurrent(script.getResetScheduleBody());
    b = HybridInterpreterHelper.safeInvoke(i, "origin-location");
    Assert.assertTrue(b);
    Assert.assertNotNull(i.current());
    Assert.assertEquals("(3,25,8,1)", i.current().toString());

    i.setCurrent(script.getValidateEmailFunction());
    b = HybridInterpreterHelper.safeInvoke(i, "origin-location");
    Assert.assertTrue(b);
    Assert.assertNotNull(i.current());
    Assert.assertEquals("(10,4,12,1)", i.current().toString());

    i.setCurrent(script.getValidateEmailBody());
    b = HybridInterpreterHelper.safeInvoke(i, "origin-location");
    Assert.assertTrue(b);
    Assert.assertNotNull(i.current());
    Assert.assertEquals("(10,49,12,1)", i.current().toString());

    i.uninit();
    i.shutdown();
  }
 public static @Nullable IStrategoTerm invoke(
     HybridInterpreter interpreter, IStrategoTerm input, String function) throws SpoofaxException {
   try {
     interpreter.setCurrent(input);
     final boolean success = interpreter.invoke(function);
     if (!success) {
       return null;
     }
     return interpreter.current();
   } catch (InterpreterException e) {
     throw new SpoofaxException("Invoking Stratego function failed", e);
   }
 }
Exemplo n.º 4
0
  @Test
  public void extractOriginFromLocalvar() {
    HybridInterpreter i = HybridInterpreterHelper.createHybridInterpreter();

    String program_location =
        WebdslTestConstants.WEBDSL_SCRIPTS_TESTCASES_DIR
            + "/fragments/functions/global/globalfunctions.app";
    File file = new File(program_location);
    Assert.assertTrue(file.exists());

    i.setCurrent(i.getFactory().makeString(program_location));
    boolean b = HybridInterpreterHelper.safeInvoke(i, WebdslTestConstants.PARSE_WEBDSL_FILE);
    Assert.assertTrue(b);
    IStrategoTerm dslProgramAterm = i.current();

    b = HybridInterpreterHelper.safeInvoke(i, "origin-location");
    Assert.assertTrue(b);
    Assert.assertNotNull(i.current());
    Assert.assertEquals("(1,0,14,20)", i.current().toString());

    GlobalFunctionsScript script = new GlobalFunctionsScript();
    script.init(dslProgramAterm);

    i.setCurrent(script.getApplication());
    b = HybridInterpreterHelper.safeInvoke(i, "origin-location");
    Assert.assertTrue(b);
    Assert.assertNotNull(i.current());
    Assert.assertEquals("(1,0,14,20)", i.current().toString());

    i.setCurrent(script.getResetScheduleFunction());
    b = HybridInterpreterHelper.safeInvoke(i, "origin-location");
    Assert.assertTrue(b);
    Assert.assertNotNull(i.current());
    Assert.assertEquals("(3,1,8,1)", i.current().toString());

    i.setCurrent(script.getResetScheduleBody());
    b = HybridInterpreterHelper.safeInvoke(i, "origin-location");
    Assert.assertTrue(b);
    Assert.assertNotNull(i.current());
    Assert.assertEquals("(3,25,8,1)", i.current().toString());

    i.setCurrent(script.getValidateEmailFunction());
    b = HybridInterpreterHelper.safeInvoke(i, "origin-location");
    Assert.assertTrue(b);
    Assert.assertNotNull(i.current());
    Assert.assertEquals("(10,4,12,1)", i.current().toString());

    i.setCurrent(script.getValidateEmailBody());
    b = HybridInterpreterHelper.safeInvoke(i, "origin-location");
    Assert.assertTrue(b);
    Assert.assertNotNull(i.current());
    Assert.assertEquals("(10,49,12,1)", i.current().toString());

    i.uninit();
    i.shutdown();
  }