Search in sources :

Example 6 with KindedName

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));
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) ResolvedName(org.abs_models.frontend.typechecker.ResolvedName) KindedName(org.abs_models.frontend.typechecker.KindedName) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) Test(org.junit.Test)

Example 7 with KindedName

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));
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) Model(org.abs_models.frontend.ast.Model) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) ResolvedName(org.abs_models.frontend.typechecker.ResolvedName) KindedName(org.abs_models.frontend.typechecker.KindedName) DeltaDecl(org.abs_models.frontend.ast.DeltaDecl) Test(org.junit.Test)

Example 8 with KindedName

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()));
            }
        }
    }
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) TypeError(org.abs_models.frontend.analyser.TypeError) KindedName(org.abs_models.frontend.typechecker.KindedName) Annotation(org.abs_models.frontend.ast.Annotation)

Example 9 with KindedName

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);
    }
}
Also used : ClassDecl(org.abs_models.frontend.ast.ClassDecl) PureExp(org.abs_models.frontend.ast.PureExp) KindedName(org.abs_models.frontend.typechecker.KindedName) Stmt(org.abs_models.frontend.ast.Stmt)

Example 10 with KindedName

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);
}
Also used : Constraint(com.gzoumix.semisolver.constraint.Constraint) LinkedList(java.util.LinkedList) Constraint(com.gzoumix.semisolver.constraint.Constraint) KindedName(org.abs_models.frontend.typechecker.KindedName)

Aggregations

KindedName (org.abs_models.frontend.typechecker.KindedName)13 ClassDecl (org.abs_models.frontend.ast.ClassDecl)10 Model (org.abs_models.frontend.ast.Model)9 Test (org.junit.Test)9 FrontendTest (org.abs_models.frontend.FrontendTest)7 ReturnStmt (org.abs_models.frontend.ast.ReturnStmt)6 ModuleDecl (org.abs_models.frontend.ast.ModuleDecl)5 ABSTest (org.abs_models.ABSTest)3 MethodImpl (org.abs_models.frontend.ast.MethodImpl)3 ParamDecl (org.abs_models.frontend.ast.ParamDecl)3 VarOrFieldUse (org.abs_models.frontend.ast.VarOrFieldUse)3 DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)2 FieldDecl (org.abs_models.frontend.ast.FieldDecl)2 MethodSig (org.abs_models.frontend.ast.MethodSig)2 VarUse (org.abs_models.frontend.ast.VarUse)2 ResolvedName (org.abs_models.frontend.typechecker.ResolvedName)2 Constraint (com.gzoumix.semisolver.constraint.Constraint)1 LinkedList (java.util.LinkedList)1 TypeError (org.abs_models.frontend.analyser.TypeError)1 Annotation (org.abs_models.frontend.ast.Annotation)1