static List<TypedDeclaration> collectUninitializedMembers(Tree.Body body) {
   List<TypedDeclaration> uninitialized = new ArrayList<TypedDeclaration>();
   if (body != null) {
     List<Tree.Statement> statements = body.getStatements();
     for (Tree.Statement st : statements) {
       if (st instanceof Tree.AttributeDeclaration) {
         Tree.AttributeDeclaration ad = (Tree.AttributeDeclaration) st;
         if (ad.getSpecifierOrInitializerExpression() == null) {
           Value v = ad.getDeclarationModel();
           if (!v.isFormal()) {
             uninitialized.add(v);
           }
         }
       } else if (st instanceof Tree.MethodDeclaration) {
         Tree.MethodDeclaration md = (Tree.MethodDeclaration) st;
         if (md.getSpecifierExpression() == null) {
           Function m = md.getDeclarationModel();
           if (!m.isFormal()) {
             uninitialized.add(m);
           }
         }
       } else if (st instanceof Tree.SpecifierStatement) {
         Tree.SpecifierStatement ss = (Tree.SpecifierStatement) st;
         Tree.Term term = ss.getBaseMemberExpression();
         if (term instanceof Tree.BaseMemberExpression) {
           Tree.BaseMemberExpression bme = (Tree.BaseMemberExpression) term;
           uninitialized.remove(bme.getDeclaration());
         }
       }
     }
   }
   return uninitialized;
 }
Example #2
0
 private void importMembers(Tree.ImportMemberOrType member, Declaration d) {
   Tree.ImportMemberOrTypeList imtl = member.getImportMemberOrTypeList();
   if (imtl != null) {
     if (d instanceof Value) {
       Value v = (Value) d;
       TypeDeclaration td = v.getTypeDeclaration();
       if (td.isObjectClass()) {
         d = td;
       }
     }
     if (d instanceof TypeDeclaration) {
       Set<String> names = new HashSet<String>();
       ImportList til = imtl.getImportList();
       TypeDeclaration td = (TypeDeclaration) d;
       til.setImportedScope(td);
       List<Tree.ImportMemberOrType> imts = imtl.getImportMemberOrTypes();
       for (Tree.ImportMemberOrType imt : imts) {
         names.add(importMember(imt, td, til));
       }
       if (imtl.getImportWildcard() != null) {
         importAllMembers(td, names, til);
       } else if (imts.isEmpty()) {
         imtl.addError("empty import list", 1020);
       }
     } else {
       imtl.addError("member alias list must follow a type");
     }
   }
 }
Example #3
0
 private static boolean isLegalAliasFreeImport(Declaration dec, Declaration importedDec) {
   if (importedDec instanceof Value) {
     Value value = (Value) importedDec;
     TypeDeclaration td = value.getTypeDeclaration();
     return td.isObjectClass() && td.equals(dec);
   } else {
     return false;
   }
 }
 public static Declaration extractAnonymousClassIfRequired(Declaration d) {
   if (d instanceof Value) {
     Value value = (Value) d;
     TypeDeclaration typeDeclaration = value.getTypeDeclaration();
     if (typeDeclaration instanceof Class && typeDeclaration.isAnonymous()) {
       return typeDeclaration;
     }
   }
   return d;
 }
 public static boolean isIgnoredLanguageModuleValue(Value value) {
   String name = value.getName();
   return name.equals("process")
       || name.equals("runtime")
       || name.equals("system")
       || name.equals("operatingSystem")
       || name.equals("language")
       || name.equals("emptyIterator")
       || name.equals("infinity")
       || name.endsWith("IntegerValue")
       || name.equals("finished");
 }
 @Override
 public void visit(Tree.SpecifierStatement that) {
   Tree.Term term = that.getBaseMemberExpression();
   boolean parameterized = false;
   while (term instanceof Tree.ParameterizedExpression) {
     Tree.ParameterizedExpression pe = (Tree.ParameterizedExpression) term;
     term = pe.getPrimary();
     parameterized = true;
   }
   if (term instanceof Tree.StaticMemberOrTypeExpression) {
     Tree.StaticMemberOrTypeExpression bme = (Tree.StaticMemberOrTypeExpression) term;
     //            Declaration member = getTypedDeclaration(bme.getScope(),
     //                    name(bme.getIdentifier()), null, false, bme.getUnit());
     Declaration member = bme.getDeclaration();
     if (member == declaration) {
       if ((declaration.isFormal() || declaration.isDefault()) && !isForwardReferenceable()) {
         // TODO: is this error correct?! look at the condition above
         bme.addError(
             "member is formal and may not be specified: '"
                 + member.getName()
                 + "' is declared formal");
       }
       if (that.getRefinement()) {
         declare();
       }
       Tree.SpecifierExpression se = that.getSpecifierExpression();
       boolean lazy = se instanceof Tree.LazySpecifierExpression;
       if (declaration instanceof Value) {
         Value value = (Value) declaration;
         if (!value.isVariable() && lazy != value.isTransient()) {
           // check that all assignments to a non-variable, in
           // different paths of execution, all use the same
           // kind of specifier, all =>, or all =
           // TODO: sometimes this error appears only because
           //       of a later line which illegally reassigns
           se.addError(
               "value must be specified using => lazy specifier: '" + member.getName() + "'");
         }
         if (lazy) {
           if (value.isVariable()) {
             se.addError(
                 "variable value may not be specified using => lazy specifier: '"
                     + member.getName()
                     + "'");
           } else if (value.isLate()) {
             se.addError(
                 "late reference may not be specified using => lazy specifier: '"
                     + member.getName()
                     + "'");
           }
         }
       }
       if (!lazy || !parameterized) {
         se.visit(this);
       }
       boolean constant = !isVariable() && !isLate();
       Scope scope = that.getScope();
       if (constant && !declaration.isDefinedInScope(scope)) {
         // this error is added by ExpressionVisitor
         //                    that.addError("inherited member is not variable and may not be
         // specified here: '" +
         //                            member.getName() + "'");
       } else if (!declared && constant) {
         bme.addError(shortdesc() + " is not yet declared: '" + member.getName() + "'");
       } else if (inLoop && constant && !(endsInBreakReturnThrow && lastContinue == null)) {
         if (specified.definitely) {
           bme.addError(
               longdesc() + " is aready definitely specified: '" + member.getName() + "'", 803);
         } else {
           bme.addError(
               longdesc() + " is not definitely unspecified in loop: '" + member.getName() + "'",
               803);
         }
       } else if (withinDeclaration && constant && !that.getRefinement()) {
         Declaration dec = getContainingDeclarationOfScope(scope);
         if (dec != null && dec.equals(member)) {
           bme.addError(
               "cannot specify "
                   + shortdesc()
                   + " from within its own body: '"
                   + member.getName()
                   + "'");
         } else {
           bme.addError(
               "cannot specify "
                   + shortdesc()
                   + " declared in outer scope: '"
                   + member.getName()
                   + "'",
               803);
         }
       } else if (specified.possibly && constant) {
         if (specified.definitely) {
           bme.addError(
               longdesc() + " is aready definitely specified: '" + member.getName() + "'", 803);
         } else {
           bme.addError(
               longdesc() + " is not definitely unspecified: '" + member.getName() + "'", 803);
         }
       } else {
         specify();
         term.visit(this);
       }
       if (lazy && parameterized) {
         se.visit(this);
       }
     } else {
       super.visit(that);
     }
   } else {
     super.visit(that);
   }
 }