use of abs.frontend.analyser.SemanticCondition in project abstools by abstools.
the class CaseStudyTypeChecking method assertParseFilesOk.
protected Model assertParseFilesOk(String srcFolder, Config... config) throws IOException, WrongProgramArgumentException, InternalBackendException {
File srcFolderF = new File(srcFolder);
assertTrue(srcFolder, srcFolderF.exists());
Main main = new Main();
main.setWithStdLib(isSet(WITH_STD_LIB, config));
Model m = main.parseFiles(findAbsFiles(srcFolderF).toArray(new String[0]));
if (m != null) {
m.evaluateAllProductDeclarations();
if (m.hasParserErrors())
Assert.fail(m.getParserErrors().get(0).getMessage());
int numSemErrs = m.getErrors().getErrorCount();
StringBuffer errs = new StringBuffer("Semantic errors: " + numSemErrs + "\n");
if (numSemErrs > 0) {
for (SemanticCondition error : m.getErrors()) errs = errs.append(error.getHelpMessage() + "\n");
fail("Failed to parse: " + srcFolder + "\n" + errs.toString());
} else if (isSet(TYPE_CHECK, config)) {
SemanticConditionList l = m.typeCheck();
if (l.containsErrors()) {
for (SemanticCondition error : l) errs = errs.append(error.getHelpMessage() + "\n");
fail("Failed to typecheck: " + srcFolder + "\n" + errs.toString());
}
}
}
return m;
}
use of abs.frontend.analyser.SemanticCondition in project abstools by abstools.
the class Main method analyzeFlattenAndRewriteModel.
/**
* This horrible method does too many things and needs to be in every code
* path that expects a working model, especially when products are
* involved. (ProductDecl.getProduct() returns null until
* evaluateAllProductDeclarations() was called once.)
*
* @param m
* @throws WrongProgramArgumentException
* @throws DeltaModellingException
* @throws FileNotFoundException
* @throws ParserConfigurationException
*/
public void analyzeFlattenAndRewriteModel(Model m) throws WrongProgramArgumentException, DeltaModellingException, FileNotFoundException, ParserConfigurationException {
m.verbose = verbose;
m.debug = debug;
// drop attributes before calculating any attribute
if (ignoreattr)
m.dropAttributes();
if (verbose) {
System.out.println("Analyzing Model...");
}
if (m.hasParserErrors()) {
System.err.println("Syntactic errors: " + m.getParserErrors().size());
for (ParserError e : m.getParserErrors()) {
System.err.println(e.getHelpMessage());
System.err.flush();
}
return;
}
// resolve ProductExpressions to simple sets of features
m.evaluateAllProductDeclarations();
rewriteModel(m, product);
m.flattenTraitOnly();
m.collapseTraitModifiers();
m.expandPartialFunctions();
// check PL before flattening
if (checkspl)
typeCheckProductLine(m);
// flatten before checking error, to avoid calculating *wrong* attributes
if (fullabs) {
if (product == null) {
// Build all SPL configurations (valid feature selections, ignoring attributes), one by one (for performance measuring)
if (verbose)
System.out.println("Building ALL " + m.getProductList().getNumChild() + " feature model configurations...");
ProductLineAnalysisHelper.buildAllConfigurations(m);
return;
}
if (typecheck)
// apply deltas that correspond to given product
m.flattenForProduct(product);
else
m.flattenForProductUnsafe(product);
}
if (dump) {
m.dumpMVars();
m.dump();
}
final SemanticConditionList semErrs = m.getErrors();
if (semErrs.containsErrors()) {
System.err.println("Semantic errors: " + semErrs.getErrorCount());
}
for (SemanticCondition error : semErrs) {
// Print both errors and warnings
System.err.println(error.getHelpMessage());
System.err.flush();
}
if (!semErrs.containsErrors()) {
typeCheckModel(m);
analyzeMTVL(m);
}
}
use of abs.frontend.analyser.SemanticCondition in project abstools by abstools.
the class ModuleDecorator method checkSemanticErrorRange.
private boolean checkSemanticErrorRange(SemanticConditionList list, CompilationUnit c, int startLine, int endLine, AbsNature nature) {
synchronized (nature.modelLock) {
if (list != null) {
if (list.containsErrors()) {
for (SemanticCondition err : list) {
ASTNode<?> node = err.getNode();
int line = err.getLine();
CompilationUnit cu = node.getCompilationUnit();
if (c == cu && checkLine(line, startLine, endLine)) {
return true;
}
}
}
}
}
return false;
}
use of abs.frontend.analyser.SemanticCondition in project abstools by abstools.
the class ABSTest method assertParseModelOk.
public static Model assertParseModelOk(Model m, Config... config) throws IOException {
if (m != null) {
final StringBuffer errs;
String fileNames = m.getCompilationUnit(0).getFileName();
for (int i = 1; i < m.getCompilationUnits().getNumChild(); i++) fileNames += " & " + m.getCompilationUnit(i).getFileName();
int parseErrs = m.getParserErrors().size();
if (parseErrs > 0) {
errs = new StringBuffer("Parse errors: " + parseErrs + ". First error:\n");
errs.append(m.getParserErrors().get(0));
fail("Failed to parse: " + fileNames + "\n" + errs.toString());
return m;
}
int numSemErrs = m.getErrors().getErrorCount();
errs = new StringBuffer("Semantic errors: " + numSemErrs + "\n");
if (numSemErrs > 0) {
for (SemanticCondition error : m.getErrors()) errs.append(error.getHelpMessage() + "\n");
fail("Failed to parse: " + fileNames + "\n" + errs.toString());
} else if (isSet(TYPE_CHECK, config)) {
SemanticConditionList l = m.typeCheck();
if (l.containsErrors()) {
for (SemanticCondition error : l) errs.append(error.getHelpMessage() + "\n");
fail("Failed to typecheck: " + fileNames + "\n" + errs.toString());
}
}
}
return m;
}
use of abs.frontend.analyser.SemanticCondition in project abstools by abstools.
the class ASTBasedABSTestRunnerGeneratorTest method testGenerateTestRunner.
@Test
public final void testGenerateTestRunner() {
final Model model;
try {
model = Main.parseString(ABS_UNIT + TEST_CODE, true);
} catch (Exception e) {
throw new IllegalStateException("Cannot parse test code", e);
}
ABSTestRunnerGenerator generator = new ASTBasedABSTestRunnerGenerator(model);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
PrintStream print = new PrintStream(stream);
generator.generateTestRunner(print);
String runner = stream.toString();
try {
Model result = Main.parseString(ABS_UNIT + TEST_CODE + runner, true);
StringBuilder parseErrors = new StringBuilder();
if (result.hasParserErrors()) {
parseErrors.append("Syntactic errors: ");
List<ParserError> es = result.getParserErrors();
parseErrors.append(es.size());
parseErrors.append("\n");
for (ParserError e : es) {
parseErrors.append(e.getHelpMessage());
parseErrors.append("\n");
}
}
assertFalse("Generated code must not have parse error: " + parseErrors, result.hasParserErrors());
StringBuilder errors = new StringBuilder();
if (result.hasErrors()) {
SemanticConditionList el = result.getErrors();
errors.append("Semantic errors: ");
errors.append(el.getErrorCount());
errors.append("\n");
for (SemanticCondition error : el) {
errors.append(error.getHelpMessage());
errors.append("\n");
}
}
assertFalse("Generated code must not have semantic error: " + errors, result.hasErrors());
result.typeCheck();
assertFalse("Generated code must not have type error", result.hasTypeErrors());
assertThat("Has one module that has the name 'AbsUnit.TestRunner' and a main block", result.getModuleDecls(), hasItem(new ModuleMatcher()));
} catch (Exception e) {
fail("Cannot throw an exception ");
}
}
Aggregations