From 7010d343eeada24f41cfd6d872c85d591f86a5e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20=C3=96qvist?= <jesper.oqvist@cs.lth.se> Date: Thu, 4 Apr 2013 12:43:07 +0200 Subject: [PATCH] Limit attribute problem checks - don't check class and interface decls for attribute problems --- src/jastadd/ast/AttributeProblems.jrag | 93 +++++++++++++++----------- 1 file changed, 55 insertions(+), 38 deletions(-) diff --git a/src/jastadd/ast/AttributeProblems.jrag b/src/jastadd/ast/AttributeProblems.jrag index 4e507c9c..87b436a7 100644 --- a/src/jastadd/ast/AttributeProblems.jrag +++ b/src/jastadd/ast/AttributeProblems.jrag @@ -43,16 +43,33 @@ aspect AttributeProblems { /** * Collects semantic problems for attributes. */ - coll Collection<Problem> Grammar.attributeProblems() + syn Collection<Problem> Grammar.attributeProblems() { + Collection<Problem> problems = new LinkedList<Problem>(); + for(int i = 0; i < getNumTypeDecl(); i++) { + problems.addAll(getTypeDecl(i).attributeProblems()); + } + return problems; + } + + coll Collection<Problem> TypeDecl.attributeProblems() [new LinkedList<Problem>()] - with add; + with add + root TypeDecl; + + syn Collection<Problem> ClassDecl.attributeProblems() = + // don't collect problems for attributes in TypeDecls + Collections.emptyList(); + + syn Collection<Problem> InterfaceDecl.attributeProblems() = + // don't collect problems for attributes in TypeDecls + Collections.emptyList(); SynEq contributes new Problem.Error( "synthesized attribute " + name() + " assigned in class " + hostClass().name() + " is not declared", getFileName(), getStartLine()) when decl() == null - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); /** * @return Previous equation for same synthesized attribute @@ -64,24 +81,24 @@ aspect AttributeProblems { ", previously defined in " + prevEq().getFileName() + ":" + prevEq().getStartLine(), getFileName(), getStartLine()) when decl() != null && prevEq() != null && prevEq() != this - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); SynEq contributes new Problem.Error( "equation must have the same parameter names as attribute declaration in " + decl().getFileName() + ":" + decl().getStartLine(), getFileName(), getStartLine()) when decl() != null && !decl().parametersDecl().equals(parametersDecl()) - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); InhEq contributes new Problem.Error( "equation must have the same parameter names as attribute declaration in " + decl().getFileName() + ":" + decl().getStartLine(), getFileName(), getStartLine()) when decl() != null && !decl().parametersDecl().equals(parametersDecl()) - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); syn SynDecl SynDecl.prevDecl() = hostClass().lookupSynDecl(signature()); @@ -90,19 +107,19 @@ aspect AttributeProblems { ", previously declared in " + prevDecl().getFileName() + ":" + prevDecl().getStartLine(), getFileName(), getStartLine()) when prevDecl() != null && prevDecl() != this - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); SynDecl contributes missingEqProblem() when !missingEqs().isEmpty() - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); SynDecl contributes new Problem.Error("return type for NTA must be an AST node", getFileName(), getStartLine()) when getNTA() && !(hostClass().env().lookup(type().split("<")[0]) instanceof ASTDecl) - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); syn Problem SynDecl.missingEqProblem() { StringBuilder buf = new StringBuilder(); @@ -154,8 +171,8 @@ aspect AttributeProblems { InhEq contributes unknownChildProblem() when hasUnknownChildProblem() - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); syn boolean InhEq.hasUnknownChildProblem() = getComponents() == null && @@ -174,8 +191,8 @@ aspect AttributeProblems { InhEq contributes unknownNTAProblem() when hasUnknownNTAProblem() - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); syn boolean InhEq.hasUnknownNTAProblem() = !hasUnknownChildProblem() && @@ -196,8 +213,8 @@ aspect AttributeProblems { InhEq contributes multiDeclProblem() when hasMultiDeclProblem() - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); /** * @return Previous equation for this inherited attribute @@ -218,8 +235,8 @@ aspect AttributeProblems { InhEq contributes badIndexProblem() when hasBadIndexProblem() - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); syn boolean InhEq.hasBadIndexProblem() = hasIndex() && @@ -236,8 +253,8 @@ aspect AttributeProblems { InhDecl contributes multiDeclProblem() when isDuplicateInhDecl() - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); syn Problem InhDecl.multiDeclProblem() { StringBuilder buf = new StringBuilder(); @@ -248,8 +265,8 @@ aspect AttributeProblems { InhDecl contributes missingEqProblem() when hasMissingEqProblem() - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); syn boolean InhDecl.hasMissingEqProblem() = !grammar().noInhEqCheck && !missingEqs().isEmpty(); @@ -292,8 +309,8 @@ aspect AttributeProblems { CollDecl contributes unknownAnnotationProblem() when hasUnknownAnnotationProblem() - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); syn boolean CollDecl.hasUnknownAnnotationProblem() { for (Iterator iter = annotations.iterator(); iter.hasNext(); ) { @@ -324,8 +341,8 @@ aspect AttributeProblems { CollDecl contributes collectionGroupProblem() when hasCollectionGroupProblem() - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); syn boolean CollDecl.hasCollectionGroupProblem() { if (hasAnnotation("@CollectionGroup")) { @@ -354,8 +371,8 @@ aspect AttributeProblems { CollDecl contributes multipleRootsProblem() when hasMultipleRootsProblem() - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); syn boolean CollDecl.hasMultipleRootsProblem() = root == null && hostClass().env().roots().size() != 1; @@ -374,14 +391,14 @@ aspect AttributeProblems { "no contributions for this collection attribute", getFileName(), getStartLine()) when uses().isEmpty() - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); CollEq contributes new Problem.Error( "undeclared collection attribute '" + name() + "'", getFileName(), getStartLine()) when decl() == null - to Grammar.attributeProblems() - for grammar(); + to TypeDecl.attributeProblems() + for hostClass(); } -- GitLab