[cfe-commits] r56014 - in /cfe/trunk/lib/Sema: Sema.h SemaDecl.cpp

Argiris Kirtzidis akyrtzi at gmail.com
Tue Sep 9 14:18:04 PDT 2008


Author: akirtzidis
Date: Tue Sep  9 16:18:04 2008
New Revision: 56014

URL: http://llvm.org/viewvc/llvm-project?rev=56014&view=rev
Log:
Add Sema::isDeclInScope which wraps IdentifierResolver::isDeclInScope.
No functionality change.

Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=56014&r1=56013&r2=56014&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Tue Sep  9 16:18:04 2008
@@ -301,6 +301,13 @@
   /// Add this decl to the scope shadowed decl chains.
   void PushOnScopeChains(NamedDecl *D, Scope *S);
 
+  /// isDeclInScope - If 'Ctx' is a function/method, isDeclInScope returns true
+  /// if 'D' is in Scope 'S', otherwise 'S' is ignored and isDeclInScope returns
+  /// true if 'D' belongs to the given declaration context.
+  bool isDeclInScope(Decl *D, DeclContext *Ctx, Scope *S = 0) {
+    return IdResolver.isDeclInScope(D, Ctx, S);
+  }
+
   /// Subroutines of ActOnDeclarator().
   TypedefDecl *ParseTypedefDecl(Scope *S, Declarator &D, QualType T,
                                 ScopedDecl *LastDecl);

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=56014&r1=56013&r2=56014&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Sep  9 16:18:04 2008
@@ -86,8 +86,7 @@
     IdentifierResolver::iterator
         I = IdResolver.begin(TD->getIdentifier(),
                              TD->getDeclContext(), false/*LookInParentCtx*/);
-    if (I != IdResolver.end() &&
-        IdResolver.isDeclInScope(*I, TD->getDeclContext(), S)) {
+    if (I != IdResolver.end() && isDeclInScope(*I, TD->getDeclContext(), S)) {
       // There is already a declaration with the same name in the same
       // scope. It must be found before we find the new declaration,
       // so swap the order on the shadowed declaration chain.
@@ -392,7 +391,7 @@
        I = IdResolver.begin(VD->getIdentifier(), 
                             VD->getDeclContext(), false/*LookInParentCtx*/), 
        E = IdResolver.end(); I != E; ++I) {
-    if (*I != VD && IdResolver.isDeclInScope(*I, VD->getDeclContext(), S)) {
+    if (*I != VD && isDeclInScope(*I, VD->getDeclContext(), S)) {
       VarDecl *OldDecl = dyn_cast<VarDecl>(*I);
       
       // Handle the following case:
@@ -621,7 +620,7 @@
     ProcessDeclAttributes(NewTD, D);
     // Merge the decl with the existing one if appropriate. If the decl is
     // in an outer scope, it isn't the same thing.
-    if (PrevDecl && IdResolver.isDeclInScope(PrevDecl, CurContext, S)) {
+    if (PrevDecl && isDeclInScope(PrevDecl, CurContext, S)) {
       NewTD = MergeTypeDefDecl(NewTD, PrevDecl);
       if (NewTD == 0) return 0;
     }
@@ -714,8 +713,7 @@
     // Merge the decl with the existing one if appropriate. Since C functions
     // are in a flat namespace, make sure we consider decls in outer scopes.
     if (PrevDecl &&
-        (!getLangOptions().CPlusPlus ||
-         IdResolver.isDeclInScope(PrevDecl, CurContext, S)) ) {
+        (!getLangOptions().CPlusPlus||isDeclInScope(PrevDecl, CurContext, S))) {
       bool Redeclaration = false;
       NewFD = MergeFunctionDecl(NewFD, PrevDecl, Redeclaration);
       if (NewFD == 0) return 0;
@@ -792,7 +790,7 @@
     }
     // Merge the decl with the existing one if appropriate. If the decl is
     // in an outer scope, it isn't the same thing.
-    if (PrevDecl && IdResolver.isDeclInScope(PrevDecl, CurContext, S)) {
+    if (PrevDecl && isDeclInScope(PrevDecl, CurContext, S)) {
       NewVD = MergeVarDecl(NewVD, PrevDecl);
       if (NewVD == 0) return 0;
     }
@@ -1547,7 +1545,7 @@
   // See if this is a redefinition.
   Decl *PrevDcl = LookupDecl(D.getIdentifier(), Decl::IDNS_Ordinary,
                              GlobalScope);
-  if (PrevDcl && IdResolver.isDeclInScope(PrevDcl, CurContext)) {
+  if (PrevDcl && isDeclInScope(PrevDcl, CurContext)) {
     if (FunctionDecl *FD = dyn_cast<FunctionDecl>(PrevDcl)) {
       const FunctionDecl *Definition;
       if (FD->getBody(Definition)) {
@@ -1714,8 +1712,7 @@
       // If this is a use of a previous tag, or if the tag is already declared
       // in the same scope (so that the definition/declaration completes or
       // rementions the tag), reuse the decl.
-      if (TK == TK_Reference ||
-          IdResolver.isDeclInScope(PrevDecl, CurContext, S)) {
+      if (TK == TK_Reference || isDeclInScope(PrevDecl, CurContext, S)) {
         // Make sure that this wasn't declared as an enum and now used as a
         // struct or something similar.
         if (PrevTagDecl->getTagKind() != Kind) {
@@ -1750,7 +1747,7 @@
       // type.
     } else {
       // PrevDecl is a namespace.
-      if (IdResolver.isDeclInScope(PrevDecl, CurContext, S)) {
+      if (isDeclInScope(PrevDecl, CurContext, S)) {
         // The tag name clashes with a namespace name, issue an error and
         // recover by making this tag be anonymous.
         Diag(NameLoc, diag::err_redefinition_different_kind, Name->getName());
@@ -1822,8 +1819,7 @@
       // If this is a use of a previous tag, or if the tag is already declared
       // in the same scope (so that the definition/declaration completes or
       // rementions the tag), reuse the decl.
-      if (TK == TK_Reference ||
-          IdResolver.isDeclInScope(PrevDecl, CurContext, S)) {
+      if (TK == TK_Reference || isDeclInScope(PrevDecl, CurContext, S)) {
         // Make sure that this wasn't declared as an enum and now used as a
         // struct or something similar.
         if (PrevTagDecl->getTagKind() != Kind) {
@@ -1871,7 +1867,7 @@
       }
     } else {
       // PrevDecl is a namespace.
-      if (IdResolver.isDeclInScope(PrevDecl, CurContext, S)) {
+      if (isDeclInScope(PrevDecl, CurContext, S)) {
         // The tag name clashes with a namespace name, issue an error and
         // recover by making this tag be anonymous.
         Diag(NameLoc, diag::err_redefinition_different_kind, Name->getName());
@@ -2276,8 +2272,7 @@
     // enum constant will 'hide' the tag.
     assert((getLangOptions().CPlusPlus || !isa<TagDecl>(PrevDecl)) &&
            "Received TagDecl when not in C++!");
-    if (!isa<TagDecl>(PrevDecl) &&
-        IdResolver.isDeclInScope(PrevDecl, CurContext, S)) {
+    if (!isa<TagDecl>(PrevDecl) && isDeclInScope(PrevDecl, CurContext, S)) {
       if (isa<EnumConstantDecl>(PrevDecl))
         Diag(IdLoc, diag::err_redefinition_of_enumerator, Id->getName());
       else





More information about the cfe-commits mailing list