Search in sources :

Example 81 with Model

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

the class JavaJob method generateJavaCode.

/**
 * Generates .java files (no .class files).
 * If 'product' is set, will flatten accordingly.
 * @param monitor - must not be null
 * @param path - where to add the modules / java-files
 * @param project - the ABS project
 * @throws IOException, if unable to create java files
 * @throws AbsJobException, if unable to generate java files
 * @throws JavaCodeGenerationException, if unable to generate java files
 * @throws CoreException
 * @throws NoModelException
 */
private void generateJavaCode(IProgressMonitor monitor, Path path, IProject project) throws AbsJobException, IOException, JavaCodeGenerationException, CoreException, NoModelException {
    assert monitor != null;
    monitor.subTask("Creating java source files");
    AbsNature nat = UtilityFunctions.getAbsNature(project);
    synchronized (nat.modelLock) {
        Model model = nat.getCompleteModel();
        if (model == null)
            throw new NoModelException();
        JavaCode javaCode = new JavaCode(path.toFile());
        if (product != null) {
            /* [stolz] Flattening for a product will mangle the model according to [ramus]...
                 */
            // work on a copy:
            model = model.treeCopyNoTransform();
            model.flushTreeCache();
            String productN = product.getName();
            try {
                model.flattenForProduct(productN);
                model.flushCache();
                if (model.hasErrors() || model.hasTypeErrors()) {
                    nat.createMarkers(model);
                    throw new AbsJobException("An ABS file in the project has type errors after applying deltas");
                }
            } catch (WrongProgramArgumentException e) {
                throw new AbsJobException(e);
            } catch (DeltaModellingException e) {
                throw new AbsJobException(e);
            }
        }
        // TODO: the second parameter toggles listener code creation (3
        // Java method calls per ABS statement); make this configurable
        model.generateJavaCode(javaCode, true);
        int countUnits = model.getNumCompilationUnit();
        if (countUnits == 0)
            throw new AbsJobException("No compilation unit found");
    }
}
Also used : NoModelException(org.absmodels.abs.plugin.internal.NoModelException) Model(abs.frontend.ast.Model) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) JavaCode(abs.backend.java.codegeneration.JavaCode) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature) DeltaModellingException(abs.frontend.delta.DeltaModellingException) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Example 82 with Model

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

the class JavaJob method getModelFromProject.

/**
 * @Deprecated According to Yannick, you need to hold {@link AbsNature#modelLock} to safely do anything with the model,
 * which means you need the nature first, and then this helper is just a fancy wrapper around {@link AbsNature#getCompleteModel()}...
 * @see AbsNature#getCompleteModel()
 */
public static Model getModelFromProject(IProject project) throws AbsJobException {
    AbsNature nature = UtilityFunctions.getAbsNature(project);
    if (nature == null) {
        throw new AbsJobException("The file is not in an ABS project!");
    }
    Model model = nature.getCompleteModel();
    // if (model==null && curFile!=null ) model = abs.frontend.parser.Main.parse(new File(curFile.getLocation().toString()), withStdLib);
    if (model == null) {
        throw new AbsJobException("No ABS model found");
    }
    if (model.hasParserErrors() || model.hasErrors() || model.hasTypeErrors()) {
        // just to be sure
        throw new AbsJobException("An ABS file in the project has type or parser errors");
    }
    return model;
}
Also used : Model(abs.frontend.ast.Model) AbsNature(org.absmodels.abs.plugin.builder.AbsNature) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature) AbsJobException(org.absmodels.abs.plugin.exceptions.AbsJobException)

Example 83 with Model

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

the class AbstractTab method fillProductDropDownMenue.

/**
 * Lists all products in the current project's module, incl. a "<base>" product if
 * no particular product is selected.
 * @param preSelected The product that should be preselected, or null for <base>.
 */
protected void fillProductDropDownMenue(String preSelected) {
    productDropDown.removeAll();
    productDropDown.add("<base>");
    IProject proj = getSelectedProject();
    if (proj == null) {
        return;
    }
    AbsNature n = UtilityFunctions.getAbsNature(proj);
    Model m = n.getCompleteModel();
    if (m == null)
        return;
    Collection<ProductDecl> prods = m.getProductDecls();
    if (prods == null)
        return;
    int i = 1;
    /* base comes first */
    int selected = 0;
    for (ProductDecl p : prods) {
        final String name = p.getName();
        productDropDown.add(name);
        if (name.equals(preSelected)) {
            selected = i;
        }
        i++;
    }
    productDropDown.select(selected);
}
Also used : ProductDecl(abs.frontend.ast.ProductDecl) Model(abs.frontend.ast.Model) IProject(org.eclipse.core.resources.IProject) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Example 84 with Model

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

the class CoreAbsBackend method mainMethod.

public int mainMethod(final String... args) {
    try {
        Model m = new CoreAbsBackend().parse(args);
        PrintStream stream = System.out;
        m.generateCoreABS(stream);
        return 0;
    } catch (Exception e) {
        printError(e.getMessage());
        return 1;
    }
}
Also used : PrintStream(java.io.PrintStream) Model(abs.frontend.ast.Model) InternalBackendException(abs.backend.common.InternalBackendException)

Example 85 with Model

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

the class Tester method compile.

private void compile(String[] args) throws DeltaModellingException, IOException, WrongProgramArgumentException, ParserConfigurationException, FileNotFoundException, InternalBackendException {
    final Model model = this.parse(args);
    // added later with a delta).
    if (model.hasParserErrors() || model.hasErrors())
        return;
    if (verbose) {
        System.out.println("Starting Dependency information extraction...");
    }
    DeployInformation di = new DeployInformation();
    di.extractInformation(model);
    if (verbose) {
        System.out.println("Starting JSON generation...");
    }
    PrintWriter f = new PrintWriter(new File(_JSONName));
    di.generateJSON(f);
    f.close();
}
Also used : Model(abs.frontend.ast.Model) File(java.io.File) PrintWriter(java.io.PrintWriter)

Aggregations

Model (abs.frontend.ast.Model)224 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