[cfe-commits] r127094 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/Sema/Sema.h lib/AST/Decl.cpp lib/Parse/ParseStmt.cpp lib/Sema/SemaLookup.cpp lib/Serialization/ASTReaderDecl.cpp lib/Serialization/ASTWriterDecl.cpp

Abramo Bagnara abramo.bagnara at gmail.com
Sat Mar 5 10:21:20 PST 2011


Author: abramo
Date: Sat Mar  5 12:21:20 2011
New Revision: 127094

URL: http://llvm.org/viewvc/llvm-project?rev=127094&view=rev
Log:
Fixed LabelDecl source range and cleaned creation code.

Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/Sema/Sema.h
    cfe/trunk/lib/AST/Decl.cpp
    cfe/trunk/lib/Parse/ParseStmt.cpp
    cfe/trunk/lib/Sema/SemaLookup.cpp
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/lib/Serialization/ASTWriterDecl.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=127094&r1=127093&r2=127094&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sat Mar  5 12:21:20 2011
@@ -309,21 +309,32 @@
 /// location of the statement.  For GNU local labels (__label__), the decl
 /// location is where the __label__ is.
 class LabelDecl : public NamedDecl {
-  llvm::PointerIntPair<LabelStmt *, 1, bool> StmtAndGnuLocal;
-  LabelDecl(DeclContext *DC, SourceLocation L, IdentifierInfo *II,
-            LabelStmt *S, bool isGnuLocal)
-    : NamedDecl(Label, DC, L, II), StmtAndGnuLocal(S, isGnuLocal) {}
-  
+  LabelStmt *TheStmt;
+  /// LocStart - For normal labels, this is the same as the main declaration
+  /// label, i.e., the location of the identifier; for GNU local labels,
+  /// this is the location of the __label__ keyword.
+  SourceLocation LocStart;
+
+  LabelDecl(DeclContext *DC, SourceLocation IdentL, IdentifierInfo *II,
+            LabelStmt *S, SourceLocation StartL)
+    : NamedDecl(Label, DC, IdentL, II), TheStmt(S), LocStart(StartL) {}
+
 public:
   static LabelDecl *Create(ASTContext &C, DeclContext *DC,
-                           SourceLocation L, IdentifierInfo *II,
-                           bool isGnuLocal = false);
+                           SourceLocation IdentL, IdentifierInfo *II);
+  static LabelDecl *Create(ASTContext &C, DeclContext *DC,
+                           SourceLocation IdentL, IdentifierInfo *II,
+                           SourceLocation GnuLabelL);
 
-  LabelStmt *getStmt() const { return StmtAndGnuLocal.getPointer(); }
-  void setStmt(LabelStmt *T) { StmtAndGnuLocal.setPointer(T); }
-  
-  bool isGnuLocal() const { return StmtAndGnuLocal.getInt(); }
-  void setGnuLocal(bool V = true) { StmtAndGnuLocal.setInt(V); }
+  LabelStmt *getStmt() const { return TheStmt; }
+  void setStmt(LabelStmt *T) { TheStmt = T; }
+
+  bool isGnuLocal() const { return LocStart != getLocation(); }
+  void setLocStart(SourceLocation L) { LocStart = L; }
+
+  SourceRange getSourceRange() const {
+    return SourceRange(LocStart, getLocation());
+  }
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=127094&r1=127093&r2=127094&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Sat Mar  5 12:21:20 2011
@@ -1448,9 +1448,9 @@
                                     QualType T1, QualType T2,
                                     UnresolvedSetImpl &Functions);
 
-  LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation Loc,
-                                 bool isLocalLabel = false);
-  
+  LabelDecl *LookupOrCreateLabel(IdentifierInfo *II, SourceLocation IdentLoc,
+                                 SourceLocation GnuLabelLoc = SourceLocation());
+
   DeclContextLookupResult LookupConstructors(CXXRecordDecl *Class);
   CXXDestructorDecl *LookupDestructor(CXXRecordDecl *Class);
 

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=127094&r1=127093&r2=127094&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Sat Mar  5 12:21:20 2011
@@ -2207,9 +2207,15 @@
 }
 
 LabelDecl *LabelDecl::Create(ASTContext &C, DeclContext *DC,
-                             SourceLocation L, IdentifierInfo *II,
-                             bool isGnuLocal) {
-  return new (C) LabelDecl(DC, L, II, 0, isGnuLocal);
+                             SourceLocation IdentL, IdentifierInfo *II) {
+  return new (C) LabelDecl(DC, IdentL, II, 0, IdentL);
+}
+
+LabelDecl *LabelDecl::Create(ASTContext &C, DeclContext *DC,
+                             SourceLocation IdentL, IdentifierInfo *II,
+                             SourceLocation GnuLabelL) {
+  assert(GnuLabelL != IdentL && "Use this only for GNU local labels");
+  return new (C) LabelDecl(DC, IdentL, II, 0, GnuLabelL);
 }
 
 

Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=127094&r1=127093&r2=127094&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Sat Mar  5 12:21:20 2011
@@ -493,7 +493,7 @@
       
       IdentifierInfo *II = Tok.getIdentifierInfo();
       SourceLocation IdLoc = ConsumeToken();
-      DeclsInGroup.push_back(Actions.LookupOrCreateLabel(II, IdLoc, true));
+      DeclsInGroup.push_back(Actions.LookupOrCreateLabel(II, IdLoc, LabelLoc));
       
       if (!Tok.is(tok::comma))
         break;

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=127094&r1=127093&r2=127094&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Sat Mar  5 12:21:20 2011
@@ -2766,30 +2766,35 @@
 }
 
 /// LookupOrCreateLabel - Do a name lookup of a label with the specified name.
-/// If isLocalLabel is true, then this is a definition of an __label__ label
-/// name, otherwise it is a normal label definition or use.
+/// If GnuLabelLoc is a valid source location, then this is a definition
+/// of an __label__ label name, otherwise it is a normal label definition
+/// or use.
 LabelDecl *Sema::LookupOrCreateLabel(IdentifierInfo *II, SourceLocation Loc,
-                                     bool isLocalLabel) {
+                                     SourceLocation GnuLabelLoc) {
   // Do a lookup to see if we have a label with this name already.
   NamedDecl *Res = 0;
-  
-  // Local label definitions always shadow existing labels.
-  if (!isLocalLabel)
-    Res = LookupSingleName(CurScope, II, Loc, LookupLabel, NotForRedeclaration);
-  
-  // If we found a label, check to see if it is in the same context as us.  When
-  // in a Block, we don't want to reuse a label in an enclosing function.
+
+  if (GnuLabelLoc.isValid()) {
+    // Local label definitions always shadow existing labels.
+    Res = LabelDecl::Create(Context, CurContext, Loc, II, GnuLabelLoc);
+    Scope *S = CurScope;
+    PushOnScopeChains(Res, S, true);
+    return cast<LabelDecl>(Res);
+  }
+
+  // Not a GNU local label.
+  Res = LookupSingleName(CurScope, II, Loc, LookupLabel, NotForRedeclaration);
+  // If we found a label, check to see if it is in the same context as us.
+  // When in a Block, we don't want to reuse a label in an enclosing function.
   if (Res && Res->getDeclContext() != CurContext)
     Res = 0;
-  
   if (Res == 0) {
     // If not forward referenced or defined already, create the backing decl.
-    Res = LabelDecl::Create(Context, CurContext, Loc, II, isLocalLabel);
-    Scope *S = isLocalLabel ? CurScope : CurScope->getFnParent();
+    Res = LabelDecl::Create(Context, CurContext, Loc, II);
+    Scope *S = CurScope->getFnParent();
     assert(S && "Not in a function?");
     PushOnScopeChains(Res, S, true);
   }
-  
   return cast<LabelDecl>(Res);
 }
 

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=127094&r1=127093&r2=127094&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Sat Mar  5 12:21:20 2011
@@ -748,8 +748,7 @@
 
 void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
   VisitNamedDecl(D);
-  bool IsGnuLocal = Record[Idx++];
-  D->setGnuLocal(IsGnuLocal);
+  D->setLocStart(ReadSourceLocation(Record, Idx));
 }
 
 

Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=127094&r1=127093&r2=127094&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Sat Mar  5 12:21:20 2011
@@ -653,7 +653,7 @@
 
 void ASTDeclWriter::VisitLabelDecl(LabelDecl *D) {
   VisitNamedDecl(D);
-  Record.push_back(D->isGnuLocal());
+  Writer.AddSourceLocation(D->getLocStart(), Record);
   Code = serialization::DECL_LABEL;
 }
 





More information about the cfe-commits mailing list