Search in sources :

Example 86 with Model

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

the class ModuleDecorator method checkModulePath.

private void checkModulePath(IDecoration decoration, ModulePath m) {
    AbsNature nature = m.getNature();
    Model model = nature.getCompleteModel();
    if (model != null) {
        for (ModuleDecl mod : model.getModuleDecls()) {
            if (mod.getName().startsWith(m.getModulePath() + ".")) {
                if (hasModuleDeclErrors(mod, nature)) {
                    addErrorOverlay(decoration);
                    return;
                }
            }
        }
    }
}
Also used : Model(abs.frontend.ast.Model) ModuleDecl(abs.frontend.ast.ModuleDecl) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Example 87 with Model

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

the class IncrementalModelBuilder method typeCheckModel.

public synchronized SemanticConditionList typeCheckModel(IProgressMonitor monitor, boolean locationTypeChecking, String defaultloctype, String locationTypePrecision, boolean checkProducts) throws NoModelException, TypecheckInternalException {
    if (model == null)
        throw new NoModelException();
    if (model.hasParserErrors())
        // don't typecheck if the model has parsererrors
        return new SemanticConditionList();
    // throw new TypecheckInternalException(new Exception("Model has parser errors!"));
    // model.flushCache();
    flushAll(model);
    model.getTypeExt().clearTypeSystemExtensions();
    if (locationTypeChecking) {
        LocationType defaultLocType = LocationType.createFromName(defaultloctype);
        LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(model);
        this.ltie = ltie;
        ltie.setDefaultType(defaultLocType);
        ltie.setLocationTypingPrecision(LocationTypingPrecision.valueOf(locationTypePrecision));
        model.registerTypeSystemExtension(ltie);
    }
    try {
        SemanticConditionList semerrors = model.getErrors();
        /* Don't typecheck with semerrors, it might trip up. */
        if (!semerrors.containsErrors())
            semerrors = model.typeCheck();
        /* Check products for errors.
			 * Only the first error is reported (if any), on the product AST-node.
			 * TODO: May be time-consuming for large projects, hence the checkProducts-switch.
			 *       Also could use a timer to switch off if it becomes excessive.
			 * TODO: Use Eclipse's nested markers to show ALL contained errors?
			 * TODO: The outline could indicate the broken product as well.
			 */
        if (!semerrors.containsErrors() && checkProducts) {
            // arbitrary value
            monitor = new SubProgressMonitor(monitor, 10);
            monitor.beginTask("Checking products", model.getProductDecls().size());
            for (ProductDecl p : model.getProductDecls()) {
                monitor.subTask("Checking " + p.getName());
                Model m2 = model.treeCopyNoTransform();
                m2.flushTreeCache();
                try {
                    m2.flattenForProduct(p);
                    SemanticConditionList p_errs = m2.typeCheck();
                    if (p_errs.containsErrors()) {
                        // Only show first error, on product
                        semerrors.add(new SemanticError(p, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), p_errs.getFirstError().getMessage()));
                    }
                } catch (WrongProgramArgumentException e) {
                    semerrors.add(new SemanticError(p, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), e.getMessage()));
                } catch (DeltaModellingException e) {
                    /* We we have a better location for error reporting? */
                    final ASTNode<?> loc;
                    if (e instanceof DeltaModellingWithNodeException)
                        loc = ((DeltaModellingWithNodeException) e).getNode();
                    else
                        loc = p;
                    if (e.getDelta() == null)
                        semerrors.add(new SemanticError(loc, ErrorMessage.ERROR_IN_PRODUCT, p.getName(), e.getMessage()));
                    else
                        semerrors.add(new SemanticError(loc, ErrorMessage.ERROR_IN_PRODUCT_WITH_DELTA, p.getName(), e.getDelta().getName(), e.getMessage()));
                }
            }
            monitor.done();
        }
        return semerrors;
    } catch (TypeCheckerException e) {
        return new SemanticConditionList(e);
    } catch (RuntimeException e) {
        throw new TypecheckInternalException(e);
    }
}
Also used : ProductDecl(abs.frontend.ast.ProductDecl) WrongProgramArgumentException(abs.common.WrongProgramArgumentException) DeltaModellingWithNodeException(abs.frontend.delta.DeltaModellingWithNodeException) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) TypeCheckerException(abs.frontend.typechecker.TypeCheckerException) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) SemanticError(abs.frontend.analyser.SemanticError) Model(abs.frontend.ast.Model) ASTNode(abs.frontend.ast.ASTNode) LocationType(abs.frontend.typechecker.locationtypes.LocationType) DeltaModellingException(abs.frontend.delta.DeltaModellingException)

Example 88 with Model

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

the class IncrementalModelBuilder method addCompilationUnit.

/**
 * Creates an empty model with only the stdlib when you pass null.
 */
public synchronized void addCompilationUnit(CompilationUnit cu) {
    if (model == null) {
        model = new Model();
        model.addCompilationUnit(getStdLibCompilationUnit());
        if (// just give us the stdlib
        cu != null)
            model.addCompilationUnit(cu);
        return;
    }
    if (cu == null)
        return;
    String filename = cu.getFileName();
    assert filename != null;
    CompilationUnit cuold = null;
    try {
        cuold = getCompilationUnit(filename);
    } catch (NoModelException e) {
        // we're pretty sure there's a model.
        assert false;
    }
    List<CompilationUnit> culist = model.getCompilationUnitList();
    int cindex = culist.getIndexOfChild(cuold);
    if (cindex > 0) {
        model.setCompilationUnit(cu, cindex);
    } else {
        model.addCompilationUnit(cu);
    }
    // model.flushCache();
    flushAll(model);
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) Model(abs.frontend.ast.Model)

Example 89 with Model

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

the class ABSUnitRunner method compile.

public void compile() throws Exception {
    final Model model = parseFiles(modelDir);
    if (model.hasParserErrors() || model.hasErrors() || model.hasTypeErrors())
        return;
    compile(model, new File(destDir));
    analyzeModelUnit(model);
}
Also used : Model(abs.frontend.ast.Model) File(java.io.File)

Example 90 with Model

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

the class ASTBasedABSTestRunnerGeneratorTest method testHasUnitTest.

@Test
public final void testHasUnitTest() {
    Model model = new Model();
    ABSTestRunnerGenerator generator = new ASTBasedABSTestRunnerGenerator(model);
    generator = setField(generator, AbstractABSTestRunnerGenerator.class, "isEmpty", Boolean.TRUE);
    assertFalse(generator.hasUnitTest());
    generator = setField(generator, AbstractABSTestRunnerGenerator.class, "isEmpty", Boolean.FALSE);
    assertTrue(generator.hasUnitTest());
}
Also used : Model(abs.frontend.ast.Model) Test(org.junit.Test)

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