use of org.abs_models.frontend.typechecker.KindedName in project abstools by abstools.
the class AddImportsTest method addExport.
@Test
public void addExport() throws DeltaModellingException {
Model model = assertParse("module Exporter;" + "interface I {}" + "module M;" + "class C {}" + "delta D1; uses Exporter;" + "adds export I;" + "delta D2; uses M;" + "adds import Exporter.I;" + "modifies class C { adds Exporter.I field1; } ");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
DeltaDecl d1 = findDelta(model, "D1");
DeltaDecl d2 = findDelta(model, "D2");
model.applyDeltas(new ArrayList<>(Arrays.asList(d1, d2)));
ModuleDecl clsmodule = cls.getModuleDecl();
Map<KindedName, ResolvedName> clsVisibleSymbols = clsmodule.getVisibleNames();
KindedName symbol1 = new KindedName(KindedName.Kind.TYPE_DECL, "Exporter.I");
assertTrue(clsVisibleSymbols.containsKey(symbol1));
}
use of org.abs_models.frontend.typechecker.KindedName in project abstools by abstools.
the class AddImportsTest method addImport.
@Test
public void addImport() throws DeltaModellingException {
Model model = assertParse("module Exporter; export *;" + "interface I {}" + "interface J {}" + "module Exporter2; export *;" + "interface K {}" + "module M;" + "class C {}" + "delta D; uses M;" + "adds import Exporter.I;" + "adds import J from Exporter;" + "adds import * from Exporter2;" + "modifies class C { adds Exporter.I field1; } " + "modifies class C { adds J field2; } " + "modifies class C { adds K field3; } ");
ClassDecl cls = (ClassDecl) findDecl(model, "M", "C");
DeltaDecl delta = findDelta(model, "D");
model.applyDeltas(new ArrayList<>(Arrays.asList(delta)));
ModuleDecl clsmodule = cls.getModuleDecl();
Map<KindedName, ResolvedName> clsVisibleSymbols = clsmodule.getVisibleNames();
KindedName symbol1 = new KindedName(KindedName.Kind.TYPE_DECL, "Exporter.I");
KindedName symbol2 = new KindedName(KindedName.Kind.TYPE_DECL, "J");
KindedName symbol3 = new KindedName(KindedName.Kind.TYPE_DECL, "K");
assertTrue(clsVisibleSymbols.containsKey(symbol1));
assertTrue(clsVisibleSymbols.containsKey(symbol2));
assertTrue(clsVisibleSymbols.containsKey(symbol3));
}
use of org.abs_models.frontend.typechecker.KindedName in project abstools by abstools.
the class ClassKindTypeExtension method checkNewExp.
@Override
public void checkNewExp(NewExp e) {
ClassDecl d = (ClassDecl) e.lookup(new KindedName(Kind.CLASS, e.getClassName()));
List<Annotation> anns = AnnotationHelper.getAnnotationsOfType(d.getAnnotations(), "ABS.StdLib.ClassKindAnnotation");
if (!anns.isEmpty()) {
String name = ((DataConstructorExp) anns.get(0).getValue()).getDecl().getName();
if (e.hasLocal()) {
if (name.equals("COG")) {
errors.add(new TypeError(e, ErrorMessage.CLASSKIND_PLAIN, d.getName()));
}
} else {
if (!name.equals("COG")) {
errors.add(new TypeError(e, ErrorMessage.CLASSKIND_COG, d.getName()));
}
}
}
}
use of org.abs_models.frontend.typechecker.KindedName in project abstools by abstools.
the class SchedulerChecker method checkNewExp.
@Override
public void checkNewExp(NewExp e) {
Stmt stmt = CompilerUtils.findStmtForExpression(e);
PureExp sched = AnnotationHelper.getAnnotationValueFromName(stmt.getAnnotations(), "ABS.Scheduler.Scheduler");
if (sched != null) {
ClassDecl decl = (ClassDecl) (e.lookup(new KindedName(KindedName.Kind.CLASS, e.getClassName())));
checkScheduleExp(sched, decl, stmt);
}
}
use of org.abs_models.frontend.typechecker.KindedName in project abstools by abstools.
the class ContractInference method typeInference.
/**
******************************************************
*/
// TODO:
// CaseExp : PureExp ::= Expr:PureExp Branch:CaseBranch* ;
// CaseBranch ::= Left:Pattern Right:PureExp ;
// abstract Pattern ;
// PatternVarUse: Pattern ::= <Name>;
// PatternVar: Pattern ::= Var:PatternVarDecl;
// ConstructorPattern: Pattern ::= <Constructor> Param:Pattern*;
// LiteralPattern: Pattern ::= Literal:LiteralExp;
// UnderscorePattern: Pattern;
// 2.4.2. Expressions with side effects.
public ResultInferenceEffExp typeInference(NewExp newExp) {
_log.logDebug("Contract Inference for the NewExp");
_log.beginIndent();
// 1. Create the record for the new object, and collect contract and
// constraints from arguments
ClassDecl cl = (ClassDecl) (newExp.lookup(new KindedName(Kind.CLASS, newExp.getClassName())));
LinkedList<RecordField> fields = new LinkedList<>();
int i = 0;
Contract contract = _df.newContractEmpty();
Constraint c = _df.newConstraint();
// 1.1. Params
_env.newScope();
ResultInferencePureExp resParam;
for (PureExp p : newExp.getParams()) {
resParam = typeInferenceAsPure(p);
ITypingEnvironmentVariableType x = _env.getRecord(resParam.getVariableType());
IRecord r = _env.getRecord(x);
fields.add(_df.newRecordField(cl.getParam(i).getName(), r));
_env.putVariable(cl.getParam(i).getName(), r);
c.add(resParam.getConstraint());
i++;
}
// 1.2. Fields
for (FieldDecl f : cl.getFields()) {
if (f.hasInitExp()) {
resParam = typeInferenceAsPure(f.getInitExp());
RecordField newRecordField = _df.newRecordField(f.getName(), (IRecord) resParam.getVariableType());
fields.add(newRecordField);
_env.putVariable(f.getName(), (IRecord) resParam.getVariableType());
c.add(resParam.getConstraint());
} else {
fields.add(_df.newRecordField(f.getName(), _df.newRecordVariable()));
}
}
// 1.3. Group Name
// depends if the new object is in the same cog or not
GroupName aprime;
if (!newExp.hasLocal()) {
aprime = _df.newGroupName();
} else {
aprime = _a;
}
IRecord r = _df.newRecordPresent(aprime, fields);
// 1.4. Calling the init of r
MethodInterface miinit = _df.newMethodInterface(r, new LinkedList<>(), _df.newRecordVariable());
c.addSemiEquation(new ASTNodeInformation(newExp), _env.getMethod(cl.getName(), _initName), miinit);
contract.add(_df.newContractInvk(newExp, cl.getName(), _initName, miinit));
_env.popScope();
_log.endIndent();
_log.logDebug("End Contract Inference for the NewExp");
return new ResultInferenceEffExp(r, contract, c, _env);
}
Aggregations