[cfe-commits] r69463 - in /cfe/trunk/lib/Sema: Sema.h SemaDecl.cpp SemaExpr.cpp SemaStmt.cpp

Chris Lattner sabre at nondot.org
Sat Apr 18 13:01:55 PDT 2009


Author: lattner
Date: Sat Apr 18 15:01:55 2009
New Revision: 69463

URL: http://llvm.org/viewvc/llvm-project?rev=69463&view=rev
Log:
refactor some code, adding a new getLabelMap() accessor method
so that clients can't poke the function-local one when they really
want the current block label.  No functionality change.

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

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

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Sat Apr 18 15:01:55 2009
@@ -77,10 +77,37 @@
   class ObjCMethodDecl;
   class ObjCPropertyDecl;
   class ObjCContainerDecl;
-  struct BlockSemaInfo;
   class BasePaths;
   struct MemberLookupCriteria;
 
+/// BlockSemaInfo - When a block is being parsed, this contains information
+/// about the block.  It is pointed to from Sema::CurBlock.
+struct BlockSemaInfo {
+  llvm::SmallVector<ParmVarDecl*, 8> Params;
+  bool hasPrototype;
+  bool isVariadic;
+  bool hasBlockDeclRefExprs;
+  
+  BlockDecl *TheDecl;
+  
+  /// TheScope - This is the scope for the block itself, which contains
+  /// arguments etc.
+  Scope *TheScope;
+  
+  /// ReturnType - This will get set to block result type, by looking at
+  /// return types, if any, in the block body.
+  Type *ReturnType;
+  
+  /// LabelMap - This is a mapping from label identifiers to the LabelStmt for
+  /// it (which acts like the label decl in some ways).  Forward referenced
+  /// labels have a LabelStmt created for them with a null location & SubStmt.
+  llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
+  
+  /// PrevBlockInfo - If this is nested inside another block, this points
+  /// to the outer block.
+  BlockSemaInfo *PrevBlockInfo;
+};
+
 /// Sema - This implements semantic analysis and AST building for C.
 class Sema : public Action {
   Sema(const Sema&);           // DO NOT IMPLEMENT
@@ -108,10 +135,14 @@
   /// of 0 indicates default alignment.
   void *PackContext; // Really a "PragmaPackStack*"
 
-  /// LabelMap - This is a mapping from label identifiers to the LabelStmt for
-  /// it (which acts like the label decl in some ways).  Forward referenced
-  /// labels have a LabelStmt created for them with a null location & SubStmt.
-  llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
+  /// FunctionLabelMap - This is a mapping from label identifiers to the
+  /// LabelStmt for it (which acts like the label decl in some ways).  Forward
+  /// referenced labels have a LabelStmt created for them with a null location &
+  /// SubStmt.
+  ///
+  /// Note that this should always be accessed through getLabelMap() in order
+  /// to handle blocks properly.
+  llvm::DenseMap<IdentifierInfo*, LabelStmt*> FunctionLabelMap;
   
   llvm::SmallVector<SwitchStmt*, 8> SwitchStack;
   
@@ -299,6 +330,12 @@
 
   virtual void ActOnEndOfTranslationUnit();
 
+  /// getLabelMap() - Return the current label map.  If we're in a block, we
+  /// return it.
+  llvm::DenseMap<IdentifierInfo*, LabelStmt*> &getLabelMap() {
+    return CurBlock ? CurBlock->LabelMap : FunctionLabelMap;
+  }
+  
   //===--------------------------------------------------------------------===//
   // Type Analysis / Processing: SemaType.cpp.
   //
@@ -2514,34 +2551,7 @@
   void CheckFloatComparison(SourceLocation loc, Expr* lex, Expr* rex);
 };
 
-/// BlockSemaInfo - When a block is being parsed, this contains information
-/// about the block.  It is pointed to from Sema::CurBlock.
-struct BlockSemaInfo {
-  llvm::SmallVector<ParmVarDecl*, 8> Params;
-  bool hasPrototype;
-  bool isVariadic;
-  bool hasBlockDeclRefExprs;
 
-  BlockDecl *TheDecl;
-  
-  /// TheScope - This is the scope for the block itself, which contains
-  /// arguments etc.
-  Scope *TheScope;
-  
-  /// ReturnType - This will get set to block result type, by looking at
-  /// return types, if any, in the block body.
-  Type *ReturnType;
-  
-  /// LabelMap - This is a mapping from label identifiers to the LabelStmt for
-  /// it (which acts like the label decl in some ways).  Forward referenced
-  /// labels have a LabelStmt created for them with a null location & SubStmt.
-  llvm::DenseMap<IdentifierInfo*, LabelStmt*> LabelMap;
-  
-  /// PrevBlockInfo - If this is nested inside another block, this points
-  /// to the outer block.
-  BlockSemaInfo *PrevBlockInfo;
-};
-  
 //===--------------------------------------------------------------------===//
 // Typed version of Parser::ExprArg (smart pointer for wrapping Expr pointers).
 template <typename T>

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Apr 18 15:01:55 2009
@@ -3155,10 +3155,12 @@
   PopDeclContext();
   // Verify and clean out per-function state.
 
-  bool HaveLabels = !LabelMap.empty();
+  //assert(&getLabelMap() == &FunctionLabelMap && "Didn't pop block right?");
+  
+  bool HaveLabels = !FunctionLabelMap.empty();
   // Check goto/label use.
   for (llvm::DenseMap<IdentifierInfo*, LabelStmt*>::iterator
-       I = LabelMap.begin(), E = LabelMap.end(); I != E; ++I) {
+       I = FunctionLabelMap.begin(), E = FunctionLabelMap.end(); I != E; ++I) {
     LabelStmt *L = I->second;
     
     // Verify that we have no forward references left.  If so, there was a goto
@@ -3191,7 +3193,7 @@
     Elements.push_back(L);
     Body->setStmts(Context, &Elements[0], Elements.size());
   }
-  LabelMap.clear();
+  FunctionLabelMap.clear();
 
   if (!Body) return D;
 

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sat Apr 18 15:01:55 2009
@@ -4447,8 +4447,7 @@
                                             SourceLocation LabLoc,
                                             IdentifierInfo *LabelII) {
   // Look up the record for this label identifier.
-  LabelStmt *&LabelDecl = CurBlock ? CurBlock->LabelMap[LabelII] : 
-                                     LabelMap[LabelII];
+  LabelStmt *&LabelDecl = getLabelMap()[LabelII];
 
   // If we haven't seen this label yet, create a forward reference. It
   // will be validated and/or cleaned up in ActOnFinishFunctionBody.

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sat Apr 18 15:01:55 2009
@@ -152,7 +152,7 @@
                      SourceLocation ColonLoc, StmtArg subStmt) {
   Stmt *SubStmt = static_cast<Stmt*>(subStmt.release());
   // Look up the record for this label identifier.
-  LabelStmt *&LabelDecl = CurBlock ? CurBlock->LabelMap[II] : LabelMap[II];
+  LabelStmt *&LabelDecl = getLabelMap()[II];
 
   // If not forward referenced or defined already, just create a new LabelStmt.
   if (LabelDecl == 0)
@@ -656,8 +656,7 @@
     return StmtError(Diag(GotoLoc, diag::err_goto_in_block));
 
   // Look up the record for this label identifier.
-  LabelStmt *&LabelDecl = CurBlock ? CurBlock->LabelMap[LabelII] : 
-                                     LabelMap[LabelII];
+  LabelStmt *&LabelDecl = getLabelMap()[LabelII];
 
   // If we haven't seen this label yet, create a forward reference.
   if (LabelDecl == 0)





More information about the cfe-commits mailing list