summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/Sema.h
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2009-11-26 00:44:06 +0000
committerDouglas Gregor <dgregor@apple.com>2009-11-26 00:44:06 +0000
commitff790f15c4ec28062ef2cdec9674a6284c29c819 (patch)
tree16f225ee467790e61ab262c87a2de0d8423a2e38 /clang/lib/Sema/Sema.h
parenta4c986cbddac04d7bc496d977e32cfeee0f3d7ab (diff)
downloadbcm5719-llvm-ff790f15c4ec28062ef2cdec9674a6284c29c819.tar.gz
bcm5719-llvm-ff790f15c4ec28062ef2cdec9674a6284c29c819.zip
Refactor our handling of expression evaluation contexts, so that Sema
maintains a stack of evaluation contexts rather than having the parser do it. This change made it simpler to track in which contexts temporaries were created, so that we could... "Forget" about temporaries created within unevaluated contexts, so that we don't build a CXXExprWithTemporaries and, therefore, destroy the integral-constness of our expressions. Fixes PR5609. llvm-svn: 89908
Diffstat (limited to 'clang/lib/Sema/Sema.h')
-rw-r--r--clang/lib/Sema/Sema.h57
1 files changed, 43 insertions, 14 deletions
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h
index 084f720d4dd..5577cbd7d74 100644
--- a/clang/lib/Sema/Sema.h
+++ b/clang/lib/Sema/Sema.h
@@ -330,18 +330,49 @@ public:
/// have been declared.
bool GlobalNewDeleteDeclared;
- /// The current expression evaluation context.
- ExpressionEvaluationContext ExprEvalContext;
-
- typedef std::vector<std::pair<SourceLocation, Decl *> >
+ /// \brief The set of declarations that have been referenced within
+ /// a potentially evaluated expression.
+ typedef std::vector<std::pair<SourceLocation, Decl *> >
PotentiallyReferencedDecls;
- /// A stack of declarations, each element of which is a set of declarations
- /// that will be marked as referenced if the corresponding potentially
- /// potentially evaluated expression is potentially evaluated. Each element
- /// in the stack corresponds to a PotentiallyPotentiallyEvaluated expression
- /// evaluation context.
- std::list<PotentiallyReferencedDecls> PotentiallyReferencedDeclStack;
+ /// \brief Data structure used to record current or nested
+ /// expression evaluation contexts.
+ struct ExpressionEvaluationContextRecord {
+ /// \brief The expression evaluation context.
+ ExpressionEvaluationContext Context;
+
+ /// \brief The number of temporaries that were active when we
+ /// entered this expression evaluation context.
+ unsigned NumTemporaries;
+
+ /// \brief The set of declarations referenced within a
+ /// potentially potentially-evaluated context.
+ ///
+ /// When leaving a potentially potentially-evaluated context, each
+ /// of these elements will be as referenced if the corresponding
+ /// potentially potentially evaluated expression is potentially
+ /// evaluated.
+ PotentiallyReferencedDecls *PotentiallyReferenced;
+
+ ExpressionEvaluationContextRecord(ExpressionEvaluationContext Context,
+ unsigned NumTemporaries)
+ : Context(Context), NumTemporaries(NumTemporaries),
+ PotentiallyReferenced(0) { }
+
+ void addReferencedDecl(SourceLocation Loc, Decl *Decl) {
+ if (!PotentiallyReferenced)
+ PotentiallyReferenced = new PotentiallyReferencedDecls;
+ PotentiallyReferenced->push_back(std::make_pair(Loc, Decl));
+ }
+
+ void Destroy() {
+ delete PotentiallyReferenced;
+ PotentiallyReferenced = 0;
+ }
+ };
+
+ /// A stack of expression evaluation contexts.
+ llvm::SmallVector<ExpressionEvaluationContextRecord, 8> ExprEvalContexts;
/// \brief Whether the code handled by Sema should be considered a
/// complete translation unit or not.
@@ -1377,12 +1408,10 @@ public:
const PartialDiagnostic &PD,
bool Equality = false);
- virtual ExpressionEvaluationContext
+ virtual void
PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext);
- virtual void
- PopExpressionEvaluationContext(ExpressionEvaluationContext OldContext,
- ExpressionEvaluationContext NewContext);
+ virtual void PopExpressionEvaluationContext();
void MarkDeclarationReferenced(SourceLocation Loc, Decl *D);
OpenPOWER on IntegriCloud