]> granicus.if.org Git - clang/commitdiff
refactor some code, adding a new getLabelMap() accessor method
authorChris Lattner <sabre@nondot.org>
Sat, 18 Apr 2009 20:01:55 +0000 (20:01 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 18 Apr 2009 20:01:55 +0000 (20:01 +0000)
so that clients can't poke the function-local one when they really
want the current block label.  No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69463 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.h
lib/Sema/SemaDecl.cpp
lib/Sema/SemaExpr.cpp
lib/Sema/SemaStmt.cpp

index 20bea4ca0fef76eaf870b5a733b46e339a6a134e..48e465ea1f6ceb6f8441b31dbf54adbd05afd14b 100644 (file)
@@ -77,10 +77,37 @@ namespace clang {
   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 @@ public:
   /// 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 @@ public:
 
   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 @@ private:
   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>
index 814b730575f00bc307dfcd12371a8d99ff17cf86..4df6feec9f67d24883034321ed58d8bb3f5f796d 100644 (file)
@@ -3155,10 +3155,12 @@ Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg) {
   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 @@ Sema::DeclPtrTy Sema::ActOnFinishFunctionBody(DeclPtrTy D, StmtArg BodyArg) {
     Elements.push_back(L);
     Body->setStmts(Context, &Elements[0], Elements.size());
   }
-  LabelMap.clear();
+  FunctionLabelMap.clear();
 
   if (!Body) return D;
 
index 20a150fad60776f810072cb3b450ee3753e65ad8..d8e57f928ddb2cb7e05f6a8e3573d6e78dab2b7e 100644 (file)
@@ -4447,8 +4447,7 @@ Sema::OwningExprResult Sema::ActOnAddrLabel(SourceLocation OpLoc,
                                             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.
index a34fc2410e1cd0cdf77e88feb153cede28f9ebd2..a5b188696a53b55a84de9b5abe3bc9be2fe7758e 100644 (file)
@@ -152,7 +152,7 @@ Sema::ActOnLabelStmt(SourceLocation IdentLoc, IdentifierInfo *II,
                      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 @@ Sema::ActOnGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
     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)