use of abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension in project abstools by abstools.
the class LocationTypeTests method assertInfer.
private Model assertInfer(String code, LocationType expected, boolean fails) {
Model m = assertParse(code, WITH_STD_LIB);
// m.setLocationTypingEnabled(true);
LocationTypeInferrerExtension ltie = new LocationTypeInferrerExtension(m);
m.registerTypeSystemExtension(ltie);
SemanticConditionList e = m.typeCheck();
// System.out.println(ltie.getConstraints());
assertEquals(!e.containsErrors() ? "" : "Found error: " + e.getFirstError().getMessage(), fails, e.containsErrors());
// assertEquals(fails, generated == null);
if (expected != null) {
VarDeclStmt vds = ((VarDeclStmt) m.getMainBlock().getStmt(0));
LocationType t = ltie.getResults().get(LocationTypeInferrerExtension.getLV(vds.getVarDecl().getType()));
assertTrue(t.toString(), expected == LocationType.FAR ? t == LocationType.FAR || t.isParametricFar() : expected == t);
}
return m;
}
use of abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension 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.typechecker.locationtypes.infer.LocationTypeInferrerExtension in project abstools by abstools.
the class AbsNature method createLocationTypeInferenceMarker.
private void createLocationTypeInferenceMarker() throws CoreException {
synchronized (modelLock) {
LocationTypeInferrerExtension locationTypeInferrerExtension = modelbuilder.getLocationTypeInferrerExtension();
if (locationTypeInferrerExtension != null) {
Map<LocationTypeVariable, LocationType> inferResult = locationTypeInferrerExtension.getResults();
if (inferResult != null) {
if (getProjectPreferenceStore().getBoolean(LOCATION_TYPE_OVERLAY)) {
for (Entry<LocationTypeVariable, LocationType> e : inferResult.entrySet()) {
LocationType annoType = e.getKey().getAnnotatedType();
if (annoType == null || annoType.equals(LocationType.INFER)) {
int severity = IMarker.SEVERITY_ERROR;
if (e.getValue().isNear()) {
severity = IMarker.SEVERITY_INFO;
} else if (e.getValue().isSomewhere()) {
severity = IMarker.SEVERITY_WARNING;
}
createMarker(e.getKey().getNode(), "Inferred Location Type: " + e.getValue(), severity, LOCATION_TYPE_INFERENCE_MARKER_TYPE);
}
}
}
} else {
IMarker marker = getProject().createMarker(TYPECHECK_MARKER_TYPE);
marker.setAttribute(IMarker.MESSAGE, "Location Type Inference Failed");
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
}
}
}
}
use of abs.frontend.typechecker.locationtypes.infer.LocationTypeInferrerExtension 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);
}
Aggregations