Search in sources :

Example 1 with ASTNode

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

the class SourcePosition method findPosition.

public static SourcePosition findPosition(ASTNode<?> node, int searchline, int searchcolumn) {
    if (inNode(node, searchline, searchcolumn)) {
        for (int i = 0; i < node.getNumChildNoTransform(); i++) {
            ASTNode child = node.getChildNoTransform(i);
            SourcePosition pos = findPosition(child, searchline, searchcolumn);
            if (pos != null) {
                return pos;
            }
        }
        return new SourcePosition(node, searchline, searchcolumn);
    }
    return null;
}
Also used : ASTNode(abs.frontend.ast.ASTNode)

Example 2 with ASTNode

use of abs.frontend.ast.ASTNode 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 3 with ASTNode

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

the class NavigatorContentProvider method getChildren.

@Override
public Object[] getChildren(Object parentElement) {
    if (parentElement instanceof InternalASTNode) {
        return outlineProvider.getChildren(parentElement);
    } else if (parentElement instanceof IProject) {
        if (((IProject) parentElement).isOpen()) {
            AbsNature nature = UtilityFunctions.getAbsNature((IProject) parentElement);
            assert nature != null;
            return ModulePath.getRootHierarchy(nature).toArray();
        }
    } else if (parentElement instanceof ModulePath) {
        ModulePath mPath = (ModulePath) parentElement;
        ArrayList<Object> children = new ArrayList<Object>();
        children.addAll(mPath.getChildModulePathsAndModuleDecls());
        InternalASTNode<ModuleDecl> intNode = mPath.getModuleDecl();
        // if the module path has a matching module declaration unfold its content..
        if (intNode != null) {
            ModuleDecl md = intNode.getASTNode();
            ArrayList<ASTNode<?>> chld = getChildrenOf(md);
            ASTNode<?>[] chldArr = chld.toArray(new ASTNode<?>[chld.size()]);
            List<InternalASTNode<ASTNode<?>>> wrapASTNodes = InternalASTNode.wrapASTNodes(chldArr, mPath.getNature());
            children.addAll(wrapASTNodes);
            return (children.toArray());
        }
        return children.toArray();
    }
    return super.getChildren(parentElement);
}
Also used : InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ArrayList(java.util.ArrayList) IProject(org.eclipse.core.resources.IProject) InternalASTNode(org.absmodels.abs.plugin.util.InternalASTNode) ASTNode(abs.frontend.ast.ASTNode) ModuleDecl(abs.frontend.ast.ModuleDecl) UtilityFunctions.getAbsNature(org.absmodels.abs.plugin.util.UtilityFunctions.getAbsNature) AbsNature(org.absmodels.abs.plugin.builder.AbsNature)

Example 4 with ASTNode

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

the class ABSUnitTestCaseTranslator method printToFile.

@SuppressWarnings("rawtypes")
private void printToFile(List<ASTNode<ASTNode>> nodes, File file) {
    try {
        PrintStream stream = new PrintStream(file);
        PrintWriter writer = new PrintWriter(stream, true);
        ABSFormatter formatter = new DefaultABSFormatter(writer);
        for (ASTNode<ASTNode> n : nodes) {
            n.doPrettyPrint(writer, formatter);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace(new PrintStream(ConsoleHandler.getDefault().newMessageStream()));
    }
}
Also used : PrintStream(java.io.PrintStream) DefaultABSFormatter(abs.backend.prettyprint.DefaultABSFormatter) DefaultABSFormatter(abs.backend.prettyprint.DefaultABSFormatter) ABSFormatter(abs.frontend.tests.ABSFormatter) ASTNode(abs.frontend.ast.ASTNode) FileNotFoundException(java.io.FileNotFoundException) PrintWriter(java.io.PrintWriter)

Example 5 with ASTNode

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

the class ABSUnitTestCaseTranslator method generateABSUnitTests.

/**
 * Generates an ABS module {@link ModuleDecl} that defines the
 * given test suite.
 *
 * @param suite
 * @param validate
 * @return
 */
@SuppressWarnings("rawtypes")
public ModuleDecl generateABSUnitTests(ApetTestSuite suite, boolean validate) {
    console("Add basic imports...");
    for (String key : suite.keySet()) {
        console("Generating test suite for " + key + "...");
        generateABSUnitTest(suite.get(key), key);
    }
    Set<DeltaDecl> deltaDecls = new HashSet<DeltaDecl>();
    for (DeltaWrapper w : deltas) {
        DeltaDecl delta = w.getDelta();
        deltaDecls.add(delta);
        abs.frontend.ast.List<DeltaAccess> access = delta.getDeltaAccesss();
        if (access.hasChildren()) {
            String use = access.getChild(0).getModuleName();
            importModules.add(use);
        }
    }
    addImports(module);
    buildProductLine(module);
    console("Pretty printing ABSUnit tests...");
    List<ASTNode<ASTNode>> nodes = new ArrayList<ASTNode<ASTNode>>();
    nodes.add(module);
    nodes.addAll(deltaDecls);
    nodes.add(productline);
    nodes.add(product);
    printToFile(nodes, outputFile);
    if (validate) {
        console("Validating ABSUnit tests...");
        validateOutput();
    }
    console("ABSUnit tests generation successful");
    return module;
}
Also used : DeltaAccess(abs.frontend.ast.DeltaAccess) DeltaWrapper(apet.absunit.DeltaForGetSetFieldsBuilder.DeltaWrapper) ASTNode(abs.frontend.ast.ASTNode) ArrayList(java.util.ArrayList) DeltaDecl(abs.frontend.ast.DeltaDecl) HashSet(java.util.HashSet)

Aggregations

ASTNode (abs.frontend.ast.ASTNode)6 ArrayList (java.util.ArrayList)2 InternalASTNode (org.absmodels.abs.plugin.util.InternalASTNode)2 DefaultABSFormatter (abs.backend.prettyprint.DefaultABSFormatter)1 WrongProgramArgumentException (abs.common.WrongProgramArgumentException)1 SemanticConditionList (abs.frontend.analyser.SemanticConditionList)1 SemanticError (abs.frontend.analyser.SemanticError)1 DeltaAccess (abs.frontend.ast.DeltaAccess)1 DeltaDecl (abs.frontend.ast.DeltaDecl)1 Model (abs.frontend.ast.Model)1 ModuleDecl (abs.frontend.ast.ModuleDecl)1 ProductDecl (abs.frontend.ast.ProductDecl)1 DeltaModellingException (abs.frontend.delta.DeltaModellingException)1 DeltaModellingWithNodeException (abs.frontend.delta.DeltaModellingWithNodeException)1 ABSFormatter (abs.frontend.tests.ABSFormatter)1 TypeCheckerException (abs.frontend.typechecker.TypeCheckerException)1 LocationType (abs.frontend.typechecker.locationtypes.LocationType)1 LocationTypeInferrerExtension (abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension)1 DeltaWrapper (apet.absunit.DeltaForGetSetFieldsBuilder.DeltaWrapper)1 FileNotFoundException (java.io.FileNotFoundException)1