Search in sources :

Example 46 with SemanticConditionList

use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class ABSUnitTestCaseTranslator method validateOutput.

private void validateOutput(Model model, String product) {
    Model copy = model.treeCopyNoTransform();
    if (product != null) {
        try {
            copy.flattenForProduct(product);
        } catch (Exception e) {
            throw new IllegalStateException("Cannot select product " + product, e);
        }
    }
    SemanticConditionList typeerrors = copy.typeCheck();
    for (SemanticCondition se : typeerrors) {
        System.err.println(se.getHelpMessage());
    }
}
Also used : SemanticConditionList(abs.frontend.analyser.SemanticConditionList) SemanticCondition(abs.frontend.analyser.SemanticCondition) Model(abs.frontend.ast.Model) FileNotFoundException(java.io.FileNotFoundException)

Example 47 with SemanticConditionList

use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class ModuleDecorator method hasModuleDeclErrors.

/**
 * Determines if a module declaration has any errors
 *
 * @param m
 *            the module declaration
 * @param nature
 *            the ABS nature
 * @return TRUE if the module declaration has errors, FALSE if not or m or
 *         nature is null
 */
public boolean hasModuleDeclErrors(ModuleDecl m, AbsNature nature) {
    synchronized (nature.modelLock) {
        if (m != null) {
            CompilationUnit cu = m.getCompilationUnit();
            EditorPosition pos = UtilityFunctions.getPosition(m);
            int startLine = pos.getLinestart();
            int endLine = pos.getLineend();
            List<ParserError> parserErrors = cu.getParserErrors();
            SemanticConditionList list = cu.getModel().getTypeErrors();
            if (checkParserErrorRange(startLine, endLine, parserErrors)) {
                return true;
            } else {
                return checkSemanticErrorRange(list, cu, startLine, endLine, nature);
            }
        }
        return false;
    }
}
Also used : CompilationUnit(abs.frontend.ast.CompilationUnit) EditorPosition(org.absmodels.abs.plugin.util.UtilityFunctions.EditorPosition) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) ParserError(abs.frontend.parser.ParserError)

Example 48 with SemanticConditionList

use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class AbsNature method typeCheckModel.

/**
 * takes the properties from the project preference store for location type checking and location type precision. Typeckecks
 * the current model in the current model builder.
 * Note that your model must be sufficiently "complete" and not have any semantic errors .
 * @param monitor
 * @throws CoreException {@link IResource#deleteMarkers(String, boolean, int)} does not handle exceptions thrown by
 * #createMarker(SemanticError) and #createMarker(TypecheckInternalException)
 */
void typeCheckModel(IProgressMonitor monitor) throws CoreException {
    getProject().deleteMarkers(TYPECHECK_MARKER_TYPE, true, IResource.DEPTH_INFINITE);
    getProject().deleteMarkers(LOCATION_TYPE_INFERENCE_MARKER_TYPE, true, IResource.DEPTH_INFINITE);
    boolean dolocationtypecheck = getProjectPreferenceStore().getBoolean(LOCATION_TYPECHECK);
    String defaultlocationtype = getProjectPreferenceStore().getString(DEFAULT_LOCATION_TYPE);
    String defaultlocationtypeprecision = getProjectPreferenceStore().getString(LOCATION_TYPE_PRECISION);
    boolean checkProducts = getProjectPreferenceStore().getBoolean(PRODUCT_TYPECHECK);
    try {
        addPackagesForTypeChecking();
        final SemanticConditionList typeerrors = modelbuilder.typeCheckModel(monitor, dolocationtypecheck, defaultlocationtype, defaultlocationtypeprecision, checkProducts);
        createMarkers(typeerrors);
        if (dolocationtypecheck) {
            createLocationTypeInferenceMarker();
        }
    } catch (NoModelException e) {
        // ignore
        return;
    } catch (TypecheckInternalException e) {
        /* Internal error caught. Log, and turn into an error marker */
        Activator.logException(e);
        createMarker(e);
        return;
    }
}
Also used : NoModelException(org.absmodels.abs.plugin.internal.NoModelException) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) TypecheckInternalException(org.absmodels.abs.plugin.internal.TypecheckInternalException)

Example 49 with SemanticConditionList

use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class AbsModelManagerImpl method extendedTypechecking.

private void extendedTypechecking() {
    if (absNature.getProject() != null) {
        IPersistentPreferenceStore projectPreferences = absNature.getProjectPreferenceStore();
        IncrementalModelBuilder.flushAll(model);
        model.getTypeExt().clearTypeSystemExtensions();
        boolean dolocationtypecheck = projectPreferences.getBoolean(LOCATION_TYPECHECK);
        if (dolocationtypecheck) {
            String defaultlocationtypeprecision = projectPreferences.getString(LOCATION_TYPE_PRECISION);
            LocationType defaultLocType = LocationType.createFromName(projectPreferences.getString(DEFAULT_LOCATION_TYPE));
            LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(model);
            ltie.setDefaultType(defaultLocType);
            ltie.setLocationTypingPrecision(LocationTypingPrecision.valueOf(defaultlocationtypeprecision));
            model.registerTypeSystemExtension(ltie);
        }
    }
    SemanticConditionList typeErrors = model.typeCheck();
    updateMarkers(typeErrors);
}
Also used : LocationTypeInferrerExtension(abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension) SemanticConditionList(abs.frontend.analyser.SemanticConditionList) LocationType(abs.frontend.typechecker.locationtypes.LocationType) IPersistentPreferenceStore(org.eclipse.jface.preference.IPersistentPreferenceStore)

Example 50 with SemanticConditionList

use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.

the class Main method typeCheckProductLine.

private void typeCheckProductLine(Model m) {
    // int n = m.getFeatureModelConfigurations().size();
    int n = m.getProductList().getNumChild();
    if (n == 0)
        return;
    if (verbose) {
        System.out.println("Typechecking Software Product Line (" + n + " products)...");
    }
    SemanticConditionList errors = m.typeCheckPL();
    for (SemanticCondition err : errors) {
        System.err.println(err.getHelpMessage());
    }
}
Also used : SemanticConditionList(abs.frontend.analyser.SemanticConditionList) SemanticCondition(abs.frontend.analyser.SemanticCondition) Constraint(choco.kernel.model.constraints.Constraint)

Aggregations

SemanticConditionList (abs.frontend.analyser.SemanticConditionList)51 Test (org.junit.Test)30 Model (abs.frontend.ast.Model)24 FrontendTest (abs.frontend.FrontendTest)7 SemanticCondition (abs.frontend.analyser.SemanticCondition)7 LocationTypeInferrerExtension (abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension)7 LocationType (abs.frontend.typechecker.locationtypes.LocationType)5 LocationTypeExtension (abs.frontend.typechecker.locationtypes.LocationTypeExtension)4 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)3 ProductLine (abs.frontend.ast.ProductLine)3 TypeError (abs.frontend.analyser.TypeError)2 CompilationUnit (abs.frontend.ast.CompilationUnit)2 DeltaModellingException (abs.frontend.delta.DeltaModellingException)2 Main (abs.frontend.parser.Main)2 ParserError (abs.frontend.parser.ParserError)2 File (java.io.File)2 ABSTest (abs.ABSTest)1 InternalBackendException (abs.backend.common.InternalBackendException)1 DefaultABSFormatter (abs.backend.prettyprint.DefaultABSFormatter)1 SemanticError (abs.frontend.analyser.SemanticError)1