From: Douglas Gregor Date: Mon, 1 Mar 2010 20:44:28 +0000 (+0000) Subject: Start detangling the BlockSemaInfo/Sema mess. No functionality change. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=076ceb093e5e4c1d6e8f6fcd27a816277a1041e2;p=clang Start detangling the BlockSemaInfo/Sema mess. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97494 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h index 4d017cada3..3072dfeaf2 100644 --- a/lib/Sema/Sema.h +++ b/lib/Sema/Sema.h @@ -108,9 +108,30 @@ namespace clang { class TargetAttributesSema; class ADLResult; -/// BlockSemaInfo - When a block is being parsed, this contains information -/// about the block. It is pointed to from Sema::CurBlock. -struct BlockSemaInfo { +/// \brief Retains information about a function, method, or block that is +/// currently being parsed. +struct FunctionScopeInfo { + /// 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 LabelMap; + + /// SwitchStack - This is the current set of active switch statements in the + /// block. + llvm::SmallVector SwitchStack; + + /// \brief Whether this scope information structure defined information for + /// a block. + bool IsBlockInfo; + + FunctionScopeInfo() : IsBlockInfo(false) { } + + static bool classof(const FunctionScopeInfo *FSI) { return true; } +}; + + +/// \brief Retains information about a block that is currently being parsed. +struct BlockScopeInfo : FunctionScopeInfo { llvm::SmallVector Params; bool hasPrototype; bool isVariadic; @@ -126,22 +147,16 @@ struct BlockSemaInfo { /// return types, if any, in the block body. QualType 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 LabelMap; - - /// SwitchStack - This is the current set of active switch statements in the - /// block. - llvm::SmallVector SwitchStack; - /// SavedFunctionNeedsScopeChecking - This is the value of /// CurFunctionNeedsScopeChecking at the point when the block started. bool SavedFunctionNeedsScopeChecking; - /// PrevBlockInfo - If this is nested inside another block, this points - /// to the outer block. - BlockSemaInfo *PrevBlockInfo; + BlockScopeInfo *PrevBlockInfo; + + BlockScopeInfo() : FunctionScopeInfo() { IsBlockInfo = true; } + + static bool classof(const FunctionScopeInfo *FSI) { return FSI->IsBlockInfo; } + static bool classof(const BlockScopeInfo *BSI) { return true; } }; /// \brief Holds a QualType and a TypeSourceInfo* that came out of a declarator @@ -202,7 +217,7 @@ public: /// CurBlock - If inside of a block definition, this contains a pointer to /// the active block object that represents it. - BlockSemaInfo *CurBlock; + BlockScopeInfo *CurBlock; /// PackContext - Manages the stack for #pragma pack. An alignment /// of 0 indicates default alignment. diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 6c1377f3cb..0d1614abe9 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -393,10 +393,10 @@ Sema::ActOnStringLiteral(const Token *StringToks, unsigned NumStringToks) { /// variables defined outside the block) or false if this is not needed (e.g. /// for values inside the block or for globals). /// -/// This also keeps the 'hasBlockDeclRefExprs' in the BlockSemaInfo records +/// This also keeps the 'hasBlockDeclRefExprs' in the BlockScopeInfo records /// up-to-date. /// -static bool ShouldSnapshotBlockValueReference(BlockSemaInfo *CurBlock, +static bool ShouldSnapshotBlockValueReference(BlockScopeInfo *CurBlock, ValueDecl *VD) { // If the value is defined inside the block, we couldn't snapshot it even if // we wanted to. @@ -421,7 +421,7 @@ static bool ShouldSnapshotBlockValueReference(BlockSemaInfo *CurBlock, // which case that outer block doesn't get "hasBlockDeclRefExprs") or it may // be defined outside all of the current blocks (in which case the blocks do // all get the bit). Walk the nesting chain. - for (BlockSemaInfo *NextBlock = CurBlock->PrevBlockInfo; NextBlock; + for (BlockScopeInfo *NextBlock = CurBlock->PrevBlockInfo; NextBlock; NextBlock = NextBlock->PrevBlockInfo) { // If we found the defining block for the variable, don't mark the block as // having a reference outside it. @@ -6723,7 +6723,7 @@ Sema::OwningExprResult Sema::ActOnChooseExpr(SourceLocation BuiltinLoc, /// ActOnBlockStart - This callback is invoked when a block literal is started. void Sema::ActOnBlockStart(SourceLocation CaretLoc, Scope *BlockScope) { // Analyze block parameters. - BlockSemaInfo *BSI = new BlockSemaInfo(); + BlockScopeInfo *BSI = new BlockScopeInfo(); // Add BSI to CurBlock. BSI->PrevBlockInfo = CurBlock; @@ -6846,7 +6846,7 @@ void Sema::ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) { /// is invoked to pop the information about the block from the action impl. void Sema::ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope) { // Ensure that CurBlock is deleted. - llvm::OwningPtr CC(CurBlock); + llvm::OwningPtr CC(CurBlock); CurFunctionNeedsScopeChecking = CurBlock->SavedFunctionNeedsScopeChecking; @@ -6865,7 +6865,7 @@ Sema::OwningExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, Diag(CaretLoc, diag::err_blocks_disable); // Ensure that CurBlock is deleted. - llvm::OwningPtr BSI(CurBlock); + llvm::OwningPtr BSI(CurBlock); PopDeclContext();