use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.
the class ProgramAbstractionTest method core.
@Test
public void core() {
Model model = assertParseOk("module M;" + "class C(Rat myParam) { Int myField = 99; Int myMethod(String a, Bool b) { return 88; } }" + "productline PL;" + "features F;");
SemanticConditionList errors = new SemanticConditionList();
ProductLine pl = model.getProductLine();
DeltaTrie trie = ProductLineAnalysisHelper.buildPFGT(pl, errors);
ProgramAbstraction pa = trie.getRoot().getProgramAbstraction();
assertTrue(pa.getClasses().containsKey("M.C"));
assertEquals(2, pa.getClasses().get("M.C").get("fields").keySet().size());
assertTrue(pa.getClasses().get("M.C").get("fields").containsKey("myParam"));
assertEquals("Rat", pa.getClasses().get("M.C").get("fields").get("myParam").get(0));
assertTrue(pa.getClasses().get("M.C").get("fields").containsKey("myField"));
assertEquals("Int", pa.getClasses().get("M.C").get("fields").get("myField").get(0));
assertTrue(pa.getClasses().get("M.C").get("methods").containsKey("myMethod"));
assertEquals(3, pa.getClasses().get("M.C").get("methods").get("myMethod").size());
assertEquals("Int", pa.getClasses().get("M.C").get("methods").get("myMethod").get(0));
assertEquals("String", pa.getClasses().get("M.C").get("methods").get("myMethod").get(1));
assertEquals("Bool", pa.getClasses().get("M.C").get("methods").get("myMethod").get(2));
}
use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.
the class DeltaSamplesTest method test_ticket329_missingLineNo.
@Test
public void test_ticket329_missingLineNo() throws Exception {
Model m = assertParseFileOk("tests/abssamples/deltas/bug329.abs", true);
SemanticConditionList errs = m.typeCheck();
/* We are expecting a missing delta in product M.PL: */
assertThat(errs.getFirstError(), instanceOf(TypeError.class));
TypeError te = (TypeError) errs.getFirstError();
Assert.assertEquals(ErrorMessage.NAME_NOT_RESOLVABLE, te.msg);
Assert.assertEquals(10, te.getLine());
}
use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.
the class ABSTest method assertParse.
protected Model assertParse(String s, Config... config) {
String preamble = "module UnitTest; export *; ";
if (isSet(WITH_STD_LIB, config))
preamble = preamble + " import * from ABS.StdLib;";
if (!isSet(WITHOUT_MODULE_NAME, config))
s = preamble + s;
try {
Model p = Main.parseString(s, isSet(WITH_STD_LIB, config));
if (isSet(EXPECT_PARSE_ERROR, config)) {
if (!p.hasParserErrors())
fail("Expected to find parse error");
} else {
if (p.hasParserErrors()) {
fail("Failed to parse: " + s + "\n" + p.getParserErrors().get(0).getMessage());
} else {
// make ProductDecl.getProduct() not return null
p.evaluateAllProductDeclarations();
if (isSet(TYPE_CHECK, config)) {
if (isSet(WITH_LOC_INF, config)) {
LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(p);
p.registerTypeSystemExtension(ltie);
}
SemanticConditionList l = p.typeCheck();
if (isSet(EXPECT_TYPE_ERROR, config)) {
if (!l.containsErrors()) {
fail("Expected type errors, but none appeared");
}
} else {
if (l.containsErrors()) {
fail("Failed to typecheck: " + s + "\n" + l.getFirstError().getMessage());
}
}
}
}
}
return p;
} catch (Exception t) {
// TODO: remove
throw new RuntimeException(t);
}
}
use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.
the class LocationTypeInferrerExtension method finished.
@Override
public void finished() {
if (enablesStats) {
for (int i = 0; i < 4; i++) {
SatGenerator satGen = new SatGenerator(constraints);
// satGen.enableStats = enablesStats;
results = satGen.generate(errors);
}
}
SatGenerator satGen = new SatGenerator(constraints);
satGen.enableStats = enablesStats;
results = satGen.generate(errors);
if (!errors.containsErrors()) {
SemanticConditionList sel = new SemanticConditionList();
List<TypeSystemExtension> curr = model.getTypeExt().getTypeSystemExtensionList();
model.getTypeExt().clearTypeSystemExtensions();
model.getTypeExt().register(new LocationTypeExtension(model, this));
model.typeCheck(sel);
errors.addAll(sel);
model.getTypeExt().clearTypeSystemExtensions();
model.getTypeExt().registerAll(curr);
}
}
use of abs.frontend.analyser.SemanticConditionList in project abstools by abstools.
the class AbstractTab method updateErrors.
/**
* Don't recommend to start projects which have errors.
* TODO: manipulating the error message here does not cooperate well with isValid().
*/
protected boolean updateErrors() {
boolean res = true;
String projectName = getSelectedProjectName();
String prod = getSelectedProductName();
if (this.lastProjectName != null && this.lastProd != null && this.lastProjectName.equals(projectName) && this.lastProd.equals(prod)) {
// every time something changes in the run configuration dialog
return lastResult;
}
if (projectName != null) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
try {
AbsNature nat = UtilityFunctions.getAbsNature(project);
assert nat != null;
synchronized (nat.modelLock) {
Model model = nat.getCompleteModel();
/* E.g. errors in the project */
if (model == null)
return false;
/* Check product if any */
// work on a copy:
model = model.treeCopyNoTransform();
model.flushTreeCache();
if (prod != null) {
model.flattenForProduct(prod);
/* Type check again */
// #335, see IncrementalModelBuilder#flushAll()
model.flushCache();
}
SemanticConditionList errs = model.getErrors();
// TODO: check for warnings also
if (errs != null && errs.containsErrors()) {
createMarkers(nat, errs);
throw new AbsJobException(new TypeCheckerException(errs));
}
errs = model.typeCheck();
// TODO: check for warnings also
if (errs != null && errs.containsErrors()) {
createMarkers(nat, errs);
throw new AbsJobException(new TypeCheckerException(errs));
}
}
setErrorMessage(null);
} catch (AbsJobException e) {
setErrorMessage(e.getMessage());
res = false;
} catch (WrongProgramArgumentException e) {
setErrorMessage(e.getMessage());
res = false;
} catch (DeltaModellingException e) {
setErrorMessage(e.getMessage());
res = false;
}
getLaunchConfigurationDialog().updateMessage();
}
// cache the result
lastProd = prod;
lastProjectName = projectName;
lastResult = res;
return res;
}
Aggregations