Search in sources :

Example 1 with KindedName

use of abs.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(abs.frontend.ast.ClassDecl) TypeError(abs.frontend.analyser.TypeError) KindedName(abs.frontend.typechecker.KindedName) Annotation(abs.frontend.ast.Annotation)

Example 2 with KindedName

use of abs.frontend.typechecker.KindedName in project abstools by abstools.

the class ABSCodeScanner method resolveTypeUse.

/**
 * resolves the type use in the type checked model.
 * @param tu
 * @param typeCheckedModel
 * @return the declaration or <b>null</b> if a {@link RuntimeException} occurs
 */
private ASTNode<?> resolveTypeUse(TypeUse tu, Model typeCheckedModel) {
    try {
        String tuname = tu.getName();
        ModuleDecl moduleDecl = tu.getModuleDecl();
        if (moduleDecl == null) {
            // Looks like we're in a delta.
            return tu;
        }
        ModuleDecl typecheckedMDecl = typeCheckedModel.lookupModule(moduleDecl.getName());
        if (typecheckedMDecl == null)
            return tu;
        Decl declNode = typecheckedMDecl.lookup(new KindedName(Kind.TYPE_DECL, tuname));
        if (declNode instanceof TypeSynDecl) {
            TypeSynDecl tsd = (TypeSynDecl) declNode;
            return resolveTypeUse(tsd.getValue(), typeCheckedModel);
        }
        return declNode;
    } catch (RuntimeException e) {
        // better make sure that can not happen
        if (doDebug)
            e.printStackTrace();
        return null;
    }
}
Also used : KindedName(abs.frontend.typechecker.KindedName)

Example 3 with KindedName

use of abs.frontend.typechecker.KindedName in project abstools by abstools.

the class ProposalFactory method addToplevelProposals.

/**
 * add proposals for all visible names.
 * @param node the node under the cursor
 */
private void addToplevelProposals(ASTNode<?> node) {
    ProposalComparator comp = new ProposalComparator();
    ArrayList<ICompletionProposal> tempNonqual = new ArrayList<ICompletionProposal>();
    ArrayList<ICompletionProposal> tempQual = new ArrayList<ICompletionProposal>();
    ModuleDecl moddecl = node.getModuleDecl();
    if (moddecl == null) {
        return;
    }
    try {
        Map<KindedName, ResolvedName> visibleNames = moddecl.getVisibleNames();
        for (Entry<KindedName, ResolvedName> kentry : visibleNames.entrySet()) {
            KindedName kname = kentry.getKey();
            if (qualifierIsPrefixOf(kname.getName())) {
                CompletionProposal proposal = makeVisibleNameProposal(kentry.getValue(), kname);
                if (kname.isQualified()) {
                    tempQual.add(proposal);
                } else {
                    tempNonqual.add(proposal);
                }
            }
        }
        Collections.sort(tempNonqual, comp);
        proposals.addAll(tempNonqual);
        Collections.sort(tempQual, comp);
        proposals.addAll(tempQual);
    } catch (TypeCheckerException e) {
    // ignore all type check exceptions
    }
}
Also used : TypeCheckerException(abs.frontend.typechecker.TypeCheckerException) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) ArrayList(java.util.ArrayList) ResolvedName(abs.frontend.typechecker.ResolvedName) KindedName(abs.frontend.typechecker.KindedName)

Example 4 with KindedName

use of abs.frontend.typechecker.KindedName in project abstools by abstools.

the class TypingTest method testFieldUse.

@Test
public void testFieldUse() {
    Model m = assertParseOkStdLib(" class C { Bool f; Bool m() { return this.f; } }");
    ClassDecl d = (ClassDecl) m.lookup(new KindedName(Kind.CLASS, "UnitTest.C"));
    FieldDecl f = d.getField(0);
    ReturnStmt s = (ReturnStmt) d.getMethod(0).getBlock().getStmt(0);
    assertEquals(f.getType(), s.getRetExp().getType());
}
Also used : FieldDecl(abs.frontend.ast.FieldDecl) ClassDecl(abs.frontend.ast.ClassDecl) Model(abs.frontend.ast.Model) KindedName(abs.frontend.typechecker.KindedName) ReturnStmt(abs.frontend.ast.ReturnStmt) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 5 with KindedName

use of abs.frontend.typechecker.KindedName in project abstools by abstools.

the class TypingTest method testNew.

@Test
public void testNew() {
    Model m = assertParseOk("interface I {} class C implements I {} { I i; i = new local C(); }");
    assertEquals(m.lookup(new KindedName(Kind.TYPE_DECL, "UnitTest.I")).getType(), ((UnionType) getTypeOfFirstAssignment(m)).getType(0));
}
Also used : Model(abs.frontend.ast.Model) KindedName(abs.frontend.typechecker.KindedName) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Aggregations

KindedName (abs.frontend.typechecker.KindedName)7 FrontendTest (abs.frontend.FrontendTest)2 ClassDecl (abs.frontend.ast.ClassDecl)2 Model (abs.frontend.ast.Model)2 ResolvedName (abs.frontend.typechecker.ResolvedName)2 ArrayList (java.util.ArrayList)2 CompletionProposal (org.eclipse.jface.text.contentassist.CompletionProposal)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 Test (org.junit.Test)2 TypeError (abs.frontend.analyser.TypeError)1 Annotation (abs.frontend.ast.Annotation)1 Decl (abs.frontend.ast.Decl)1 FieldDecl (abs.frontend.ast.FieldDecl)1 FunctionDecl (abs.frontend.ast.FunctionDecl)1 PartialFunctionDecl (abs.frontend.ast.PartialFunctionDecl)1 ReturnStmt (abs.frontend.ast.ReturnStmt)1 TypeCheckerException (abs.frontend.typechecker.TypeCheckerException)1