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;
}
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);
}
}
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);
}
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()));
}
}
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;
}
Aggregations