Search in sources :

Example 1 with Model

use of abs.frontend.ast.Model in project abstools by abstools.

the class NavigatorUtilsTests method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    natureMock = mock(AbsNature.class);
    natureMock.modelLock = new Object();
    moduleDecl1 = mock(ModuleDecl.class);
    moduleDecl2 = mock(ModuleDecl.class);
    moduleDecl3 = mock(ModuleDecl.class);
    moduleDecl4 = mock(ModuleDecl.class);
    when(moduleDecl1.getName()).thenReturn("A");
    when(moduleDecl2.getName()).thenReturn("A.A");
    when(moduleDecl3.getName()).thenReturn("A.A.A");
    when(moduleDecl4.getName()).thenReturn("A.A.A.A");
    Model modelMock = mock(Model.class);
    when(modelMock.getModuleDecls()).thenReturn(Arrays.asList(moduleDecl1, moduleDecl2, moduleDecl3, moduleDecl4));
    when(natureMock.getCompleteModel()).thenReturn(modelMock);
}
Also used : Model(abs.frontend.ast.Model) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) Before(org.junit.Before)

Example 2 with Model

use of abs.frontend.ast.Model in project abstools by abstools.

the class InternalASTNodeTests method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    natureMock = mock(AbsNature.class);
    natureMock.modelLock = new Object();
    moduleDecl1 = mock(ModuleDecl.class);
    moduleDecl2 = mock(ModuleDecl.class);
    moduleDecl3 = mock(ModuleDecl.class);
    moduleDecl4 = mock(ModuleDecl.class);
    when(moduleDecl1.getName()).thenReturn("A");
    when(moduleDecl2.getName()).thenReturn("A.A");
    when(moduleDecl3.getName()).thenReturn("A.A.A");
    when(moduleDecl4.getName()).thenReturn("A.A.A.A");
    Model modelMock = mock(Model.class);
    when(modelMock.getModuleDecls()).thenReturn(Arrays.asList(moduleDecl1, moduleDecl2, moduleDecl3, moduleDecl4));
    when(natureMock.getCompleteModel()).thenReturn(modelMock);
}
Also used : Model(abs.frontend.ast.Model) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) Before(org.junit.Before)

Example 3 with Model

use of abs.frontend.ast.Model in project abstools by abstools.

the class MaudeCompiler method compile.

/**
 * @param args
 * @throws Exception
 */
public int compile(String[] args) throws Exception {
    if (verbose)
        System.out.println("Generating Maude code...");
    final Model model = parse(args);
    if (model.hasParserErrors() || model.hasErrors() || model.hasTypeErrors()) {
        printErrorMessage();
        return 1;
    }
    PrintStream stream = System.out;
    if (outputfile != null) {
        stream = new PrintStream(outputfile);
    }
    InputStream is = ClassLoader.getSystemResourceAsStream(RUNTIME_INTERPRETER_PATH);
    if (is == null) {
        throw new InternalBackendException("Could not locate abs-interpreter.maude");
    }
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    stream.println("*** Generated " + dateFormat.format(new Date()));
    ByteStreams.copy(is, stream);
    model.generateMaude(stream, module, mainBlock, clocklimit, defaultResources);
    if (verbose)
        System.out.println("Finished.  Start `maude " + outputfile.toString() + "' to run the model.");
    return 0;
}
Also used : PrintStream(java.io.PrintStream) InputStream(java.io.InputStream) InternalBackendException(abs.backend.common.InternalBackendException) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Model(abs.frontend.ast.Model) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 4 with Model

use of abs.frontend.ast.Model in project abstools by abstools.

the class PrettyPrinterBackEnd method compile.

/**
 * @param args
 * @throws Exception
 */
public int compile(String[] args) throws Exception {
    final Model model = parseFiles(parseArgs(args).toArray(new String[0]));
    if (keepsugar) {
        model.doAACrewrite = false;
        model.doForEachRewrite = false;
    }
    analyzeFlattenAndRewriteModel(model);
    if (!force && (model.hasParserErrors() || model.hasErrors() || model.hasTypeErrors())) {
        printErrorMessage();
        return 1;
    }
    final PrintStream stream;
    final String loc;
    if (outputfile != null) {
        stream = new PrintStream(outputfile);
        loc = outputfile.getAbsolutePath();
    } else {
        stream = System.out;
        loc = "Standard Output Stream";
    }
    if (verbose) {
        System.out.println("Output ABS model source code to " + loc + "...");
    }
    PrintWriter writer = new PrintWriter(stream, true);
    ABSFormatter formatter = new DefaultABSFormatter(writer);
    model.doPrettyPrint(writer, formatter);
    return 0;
}
Also used : PrintStream(java.io.PrintStream) ABSFormatter(abs.frontend.tests.ABSFormatter) Model(abs.frontend.ast.Model) PrintWriter(java.io.PrintWriter)

Example 5 with Model

use of abs.frontend.ast.Model in project abstools by abstools.

the class TraitTest method removeExistingMethodInClassSucc.

@Test
public void removeExistingMethodInClassSucc() {
    Model model = assertParseOk("module M;" + "trait T = {Unit myMethod(){skip;}}  " + "class C {uses T removes Unit myMethod();;  }");
    ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
    assertNotNull(cls);
    assertTrue(cls.getMethods().getNumChild() == 0);
    model.applyTraits();
    assertTrue(cls.getMethods().getNumChild() == 0);
}
Also used : ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) Test(org.junit.Test)

Aggregations

Model (abs.frontend.ast.Model)226 Test (org.junit.Test)170 FrontendTest (abs.frontend.FrontendTest)93 ClassDecl (abs.frontend.ast.ClassDecl)57 DeltaDecl (abs.frontend.ast.DeltaDecl)30 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)24 FunctionDecl (abs.frontend.ast.FunctionDecl)15 PrintStream (java.io.PrintStream)14 ModifyClassModifier (abs.frontend.ast.ModifyClassModifier)12 SkipStmt (abs.frontend.ast.SkipStmt)11 AbsNature (org.absmodels.abs.plugin.builder.AbsNature)11 ExpFunctionDef (abs.frontend.ast.ExpFunctionDef)9 ModuleDecl (abs.frontend.ast.ModuleDecl)9 CompilationUnit (abs.frontend.ast.CompilationUnit)7 DeltaTraitModifier (abs.frontend.ast.DeltaTraitModifier)7 ModifyMethodModifier (abs.frontend.ast.ModifyMethodModifier)7 PartialFunctionDecl (abs.frontend.ast.PartialFunctionDecl)7 PureExp (abs.frontend.ast.PureExp)7 TraitExpr (abs.frontend.ast.TraitExpr)7 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)6