diff options
Diffstat (limited to 'include/clang/Parse')
-rw-r--r-- | include/clang/Parse/Action.h | 71 | ||||
-rw-r--r-- | include/clang/Parse/Parser.h | 18 |
2 files changed, 63 insertions, 26 deletions
diff --git a/include/clang/Parse/Action.h b/include/clang/Parse/Action.h index 5b57521..8c85ba6 100644 --- a/include/clang/Parse/Action.h +++ b/include/clang/Parse/Action.h @@ -637,18 +637,50 @@ public: // Expression Parsing Callbacks. //===--------------------------------------------------------------------===// - /// \brief Notifies the action when the parser is processing an unevaluated - /// operand. + /// \brief Describes how the expressions currently being parsed are + /// evaluated at run-time, if at all. + enum ExpressionEvaluationContext { + /// \brief The current expression and its subexpressions occur within an + /// unevaluated operand (C++0x [expr]p8), such as a constant expression + /// or the subexpression of \c sizeof, where the type or the value of the + /// expression may be significant but no code will be generated to evaluate + /// the value of the expression at run time. + Unevaluated, + + /// \brief The current expression is potentially evaluated at run time, + /// which means that code may be generated to evaluate the value of the + /// expression at run time. + PotentiallyEvaluated, + + /// \brief The current expression may be potentially evaluated or it may + /// be unevaluated, but it is impossible to tell from the lexical context. + /// This evaluation context is used primary for the operand of the C++ + /// \c typeid expression, whose argument is potentially evaluated only when + /// it is an lvalue of polymorphic class type (C++ [basic.def.odr]p2). + PotentiallyPotentiallyEvaluated + }; + + /// \brief The parser is entering a new expression evaluation context. /// - /// \param UnevaluatedOperand true to indicate that the parser is processing - /// an unevaluated operand, or false otherwise. + /// \param NewContext is the new expression evaluation context. /// - /// \returns whether the the action module was previously in an unevaluated - /// operand. - virtual bool setUnevaluatedOperand(bool UnevaluatedOperand) { - return false; + /// \returns the previous expression evaluation context. + virtual ExpressionEvaluationContext + PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext) { + return PotentiallyEvaluated; } + /// \brief The parser is existing an expression evaluation context. + /// + /// \param OldContext the expression evaluation context that the parser is + /// leaving. + /// + /// \param NewContext the expression evaluation context that the parser is + /// returning to. + virtual void + PopExpressionEvaluationContext(ExpressionEvaluationContext OldContext, + ExpressionEvaluationContext NewContext) { } + // Primary Expressions. /// \brief Retrieve the source range that corresponds to the given @@ -1891,6 +1923,29 @@ public: virtual void print(llvm::raw_ostream &OS) const; }; +/// \brief RAII object that enters a new expression evaluation context. +class EnterExpressionEvaluationContext { + /// \brief The action object. + Action &Actions; + + /// \brief The previous expression evaluation context. + Action::ExpressionEvaluationContext PrevContext; + + /// \brief The current expression evaluation context. + Action::ExpressionEvaluationContext CurContext; + +public: + EnterExpressionEvaluationContext(Action &Actions, + Action::ExpressionEvaluationContext NewContext) + : Actions(Actions), CurContext(NewContext) { + PrevContext = Actions.PushExpressionEvaluationContext(NewContext); + } + + ~EnterExpressionEvaluationContext() { + Actions.PopExpressionEvaluationContext(CurContext, PrevContext); + } +}; + } // end namespace clang #endif diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 75458d8..7558793 100644 --- a/include/clang/Parse/Parser.h +++ b/include/clang/Parse/Parser.h @@ -104,24 +104,6 @@ class Parser { GreaterThanIsOperator = OldGreaterThanIsOperator; } }; - - /// \brief RAII object that enters an unevaluated operand. - class EnterUnevaluatedOperand { - /// \brief The action object. - Action &Actions; - - /// \brief Whether we were previously within an unevaluated operand. - bool PreviouslyInUnevaluatedOperand; - - public: - explicit EnterUnevaluatedOperand(Action &Actions) : Actions(Actions) { - PreviouslyInUnevaluatedOperand = Actions.setUnevaluatedOperand(true); - } - - ~EnterUnevaluatedOperand() { - Actions.setUnevaluatedOperand(PreviouslyInUnevaluatedOperand); - } - }; public: Parser(Preprocessor &PP, Action &Actions); |