r193027 - Add isFirstDecl to DecBase too and use it instead of getPreviousDecl() == 0.

Sean Silva silvas at purdue.edu
Fri Oct 18 20:19:20 PDT 2013


+  /// \brief Returns true if this is the first declaration.
+  bool isFirstDecl() const {

This comment doesn't add anything. First declaration of what? in what?

-- Sean Silva


On Fri, Oct 18, 2013 at 10:13 PM, Rafael Espindola <
rafael.espindola at gmail.com> wrote:

> Author: rafael
> Date: Fri Oct 18 21:13:21 2013
> New Revision: 193027
>
> URL: http://llvm.org/viewvc/llvm-project?rev=193027&view=rev
> Log:
> Add isFirstDecl to DecBase too and use it instead of getPreviousDecl() ==
> 0.
>
> Redeclarable already had a isFirstDecl, but it was missing from DeclBase.
>
> Modified:
>     cfe/trunk/include/clang/AST/Decl.h
>     cfe/trunk/include/clang/AST/DeclBase.h
>     cfe/trunk/include/clang/AST/DeclObjC.h
>     cfe/trunk/include/clang/AST/DeclTemplate.h
>     cfe/trunk/lib/AST/ASTContext.cpp
>     cfe/trunk/lib/Sema/SemaDecl.cpp
>     cfe/trunk/lib/Serialization/ASTWriter.cpp
>
> Modified: cfe/trunk/include/clang/AST/Decl.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=193027&r1=193026&r2=193027&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/Decl.h (original)
> +++ cfe/trunk/include/clang/AST/Decl.h Fri Oct 18 21:13:21 2013
> @@ -368,6 +368,7 @@ public:
>    using redeclarable_base::redecls_end;
>    using redeclarable_base::getPreviousDecl;
>    using redeclarable_base::getMostRecentDecl;
> +  using redeclarable_base::isFirstDecl;
>
>    /// \brief Returns true if this is an anonymous namespace declaration.
>    ///
> @@ -775,6 +776,7 @@ public:
>    using redeclarable_base::redecls_end;
>    using redeclarable_base::getPreviousDecl;
>    using redeclarable_base::getMostRecentDecl;
> +  using redeclarable_base::isFirstDecl;
>
>    static VarDecl *Create(ASTContext &C, DeclContext *DC,
>                           SourceLocation StartLoc, SourceLocation IdLoc,
> @@ -1563,6 +1565,7 @@ public:
>    using redeclarable_base::redecls_end;
>    using redeclarable_base::getPreviousDecl;
>    using redeclarable_base::getMostRecentDecl;
> +  using redeclarable_base::isFirstDecl;
>
>    static FunctionDecl *Create(ASTContext &C, DeclContext *DC,
>                                SourceLocation StartLoc, SourceLocation
> NLoc,
> @@ -2390,6 +2393,7 @@ public:
>    using redeclarable_base::redecls_end;
>    using redeclarable_base::getPreviousDecl;
>    using redeclarable_base::getMostRecentDecl;
> +  using redeclarable_base::isFirstDecl;
>
>    bool isModed() const { return MaybeModedTInfo.is<ModedTInfo*>(); }
>
> @@ -2574,6 +2578,7 @@ public:
>    using redeclarable_base::redecls_end;
>    using redeclarable_base::getPreviousDecl;
>    using redeclarable_base::getMostRecentDecl;
> +  using redeclarable_base::isFirstDecl;
>
>    SourceLocation getRBraceLoc() const { return RBraceLoc; }
>    void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
>
> Modified: cfe/trunk/include/clang/AST/DeclBase.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=193027&r1=193026&r2=193027&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/DeclBase.h (original)
> +++ cfe/trunk/include/clang/AST/DeclBase.h Fri Oct 18 21:13:21 2013
> @@ -785,7 +785,12 @@ public:
>    const Decl *getPreviousDecl() const {
>      return const_cast<Decl *>(this)->getPreviousDeclImpl();
>    }
> -
> +
> +  /// \brief Returns true if this is the first declaration.
> +  bool isFirstDecl() const {
> +    return getPreviousDecl() == 0;
> +  }
> +
>    /// \brief Retrieve the most recent declaration that declares the same
> entity
>    /// as this declaration (which may be this declaration).
>    Decl *getMostRecentDecl() { return getMostRecentDeclImpl(); }
>
> Modified: cfe/trunk/include/clang/AST/DeclObjC.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclObjC.h?rev=193027&r1=193026&r2=193027&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/DeclObjC.h (original)
> +++ cfe/trunk/include/clang/AST/DeclObjC.h Fri Oct 18 21:13:21 2013
> @@ -1201,6 +1201,7 @@ public:
>    using redeclarable_base::redecls_end;
>    using redeclarable_base::getPreviousDecl;
>    using redeclarable_base::getMostRecentDecl;
> +  using redeclarable_base::isFirstDecl;
>
>    /// Retrieves the canonical declaration of this Objective-C class.
>    ObjCInterfaceDecl *getCanonicalDecl() { return getFirstDecl(); }
> @@ -1503,6 +1504,7 @@ public:
>    using redeclarable_base::redecls_end;
>    using redeclarable_base::getPreviousDecl;
>    using redeclarable_base::getMostRecentDecl;
> +  using redeclarable_base::isFirstDecl;
>
>    /// Retrieves the canonical declaration of this Objective-C protocol.
>    ObjCProtocolDecl *getCanonicalDecl() { return getFirstDecl(); }
>
> Modified: cfe/trunk/include/clang/AST/DeclTemplate.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclTemplate.h?rev=193027&r1=193026&r2=193027&view=diff
>
> ==============================================================================
> --- cfe/trunk/include/clang/AST/DeclTemplate.h (original)
> +++ cfe/trunk/include/clang/AST/DeclTemplate.h Fri Oct 18 21:13:21 2013
> @@ -715,6 +715,7 @@ public:
>    using redeclarable_base::redecls_end;
>    using redeclarable_base::getPreviousDecl;
>    using redeclarable_base::getMostRecentDecl;
> +  using redeclarable_base::isFirstDecl;
>
>    // Implement isa/cast/dyncast/etc.
>    static bool classof(const Decl *D) { return classofKind(D->getKind()); }
>
> Modified: cfe/trunk/lib/AST/ASTContext.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=193027&r1=193026&r2=193027&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/ASTContext.cpp (original)
> +++ cfe/trunk/lib/AST/ASTContext.cpp Fri Oct 18 21:13:21 2013
> @@ -2922,13 +2922,11 @@ QualType ASTContext::getTypeDeclTypeSlow
>           "Template type parameter types are always available.");
>
>    if (const RecordDecl *Record = dyn_cast<RecordDecl>(Decl)) {
> -    assert(!Record->getPreviousDecl() &&
> -           "struct/union has previous declaration");
> +    assert(Record->isFirstDecl() && "struct/union has previous
> declaration");
>      assert(!NeedsInjectedClassNameType(Record));
>      return getRecordType(Record);
>    } else if (const EnumDecl *Enum = dyn_cast<EnumDecl>(Decl)) {
> -    assert(!Enum->getPreviousDecl() &&
> -           "enum has previous declaration");
> +    assert(Enum->isFirstDecl() && "enum has previous declaration");
>      return getEnumType(Enum);
>    } else if (const UnresolvedUsingTypenameDecl *Using =
>                 dyn_cast<UnresolvedUsingTypenameDecl>(Decl)) {
>
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=193027&r1=193026&r2=193027&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Fri Oct 18 21:13:21 2013
> @@ -5388,7 +5388,7 @@ Sema::ActOnVariableDeclarator(Scope *S,
>
>    // If this is the first declaration of an extern C variable, update
>    // the map of such variables.
> -  if (!NewVD->getPreviousDecl() && !NewVD->isInvalidDecl() &&
> +  if (NewVD->isFirstDecl() && !NewVD->isInvalidDecl() &&
>        isIncompleteDeclExternC(*this, NewVD))
>      RegisterLocallyScopedExternCDecl(NewVD, S);
>
> @@ -7205,7 +7205,7 @@ Sema::ActOnFunctionDeclarator(Scope *S,
>
>    // If this is the first declaration of an extern C variable, update
>    // the map of such variables.
> -  if (!NewFD->getPreviousDecl() && !NewFD->isInvalidDecl() &&
> +  if (NewFD->isFirstDecl() && !NewFD->isInvalidDecl() &&
>        isIncompleteDeclExternC(*this, NewFD))
>      RegisterLocallyScopedExternCDecl(NewFD, S);
>
> @@ -8520,7 +8520,7 @@ void Sema::ActOnUninitializedDecl(Decl *
>            // is accepted by gcc. Hence here we issue a warning instead of
>            // an error and we do not invalidate the static declaration.
>            // NOTE: to avoid multiple warnings, only check the first
> declaration.
> -          if (Var->getPreviousDecl() == 0)
> +          if (Var->isFirstDecl())
>              RequireCompleteType(Var->getLocation(), Type,
>                                  diag::ext_typecheck_decl_incomplete_type);
>          }
> @@ -9619,7 +9619,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl
>      // The only way to be included in UndefinedButUsed is if there is an
>      // ODR use before the definition. Avoid the expensive map lookup if
> this
>      // is the first declaration.
> -    if (FD->getPreviousDecl() != 0 && FD->getPreviousDecl()->isUsed()) {
> +    if (!FD->isFirstDecl() && FD->getPreviousDecl()->isUsed()) {
>        if (!FD->isExternallyVisible())
>          UndefinedButUsed.erase(FD);
>        else if (FD->isInlined() &&
>
> Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=193027&r1=193026&r2=193027&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
> +++ cfe/trunk/lib/Serialization/ASTWriter.cpp Fri Oct 18 21:13:21 2013
> @@ -3531,7 +3531,7 @@ void ASTWriter::WriteRedeclarations() {
>
>    for (unsigned I = 0, N = Redeclarations.size(); I != N; ++I) {
>      Decl *First = Redeclarations[I];
> -    assert(First->getPreviousDecl() == 0 && "Not the first declaration?");
> +    assert(First->isFirstDecl() && "Not the first declaration?");
>
>      Decl *MostRecent = First->getMostRecentDecl();
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131018/67d1d3e3/attachment.html>


More information about the cfe-commits mailing list