From 88ec34020d741ceefb3a542798709add6ca53304 Mon Sep 17 00:00:00 2001 From: John Thompson Date: Sat, 7 Dec 2013 08:41:15 +0000 Subject: [PATCH] Changed ConditionValue argument to PPCallbacks If and Elif callbacks to be a 3-state enum. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@196648 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Lex/PPCallbacks.h | 12 ++++++++---- include/clang/Lex/PPConditionalDirectiveRecord.h | 4 ++-- lib/Lex/PPConditionalDirectiveRecord.cpp | 4 ++-- lib/Lex/PPDirectives.cpp | 6 +++--- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/include/clang/Lex/PPCallbacks.h b/include/clang/Lex/PPCallbacks.h index 0e11218279..f1ed897251 100644 --- a/include/clang/Lex/PPCallbacks.h +++ b/include/clang/Lex/PPCallbacks.h @@ -267,6 +267,10 @@ public: virtual void SourceRangeSkipped(SourceRange Range) { } + enum ConditionValueKind { + CVK_NotEvaluated, CVK_False, CVK_True + }; + /// \brief Hook called whenever an \#if is seen. /// \param Loc the source location of the directive. /// \param ConditionRange The SourceRange of the expression being tested. @@ -274,7 +278,7 @@ public: /// // FIXME: better to pass in a list (or tree!) of Tokens. virtual void If(SourceLocation Loc, SourceRange ConditionRange, - bool ConditionValue) { + ConditionValueKind ConditionValue) { } /// \brief Hook called whenever an \#elif is seen. @@ -284,7 +288,7 @@ public: /// \param IfLoc the source location of the \#if/\#ifdef/\#ifndef directive. // FIXME: better to pass in a list (or tree!) of Tokens. virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, - bool ConditionValue, SourceLocation IfLoc) { + ConditionValueKind ConditionValue, SourceLocation IfLoc) { } /// \brief Hook called whenever an \#ifdef is seen. @@ -473,14 +477,14 @@ public: /// \brief Hook called whenever an \#if is seen. virtual void If(SourceLocation Loc, SourceRange ConditionRange, - bool ConditionValue) { + ConditionValueKind ConditionValue) { First->If(Loc, ConditionRange, ConditionValue); Second->If(Loc, ConditionRange, ConditionValue); } /// \brief Hook called whenever an \#elif is seen. virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, - bool ConditionValue, SourceLocation IfLoc) { + ConditionValueKind ConditionValue, SourceLocation IfLoc) { First->Elif(Loc, ConditionRange, ConditionValue, IfLoc); Second->Elif(Loc, ConditionRange, ConditionValue, IfLoc); } diff --git a/include/clang/Lex/PPConditionalDirectiveRecord.h b/include/clang/Lex/PPConditionalDirectiveRecord.h index 54a132d586..9da46cdbfc 100644 --- a/include/clang/Lex/PPConditionalDirectiveRecord.h +++ b/include/clang/Lex/PPConditionalDirectiveRecord.h @@ -87,9 +87,9 @@ public: private: virtual void If(SourceLocation Loc, SourceRange ConditionRange, - bool ConditionValue); + ConditionValueKind ConditionValue); virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, - bool ConditionValue, SourceLocation IfLoc); + ConditionValueKind ConditionValue, SourceLocation IfLoc); virtual void Ifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDirective *MD); virtual void Ifndef(SourceLocation Loc, const Token &MacroNameTok, diff --git a/lib/Lex/PPConditionalDirectiveRecord.cpp b/lib/Lex/PPConditionalDirectiveRecord.cpp index 16dc1d8f09..99b87a0a15 100644 --- a/lib/Lex/PPConditionalDirectiveRecord.cpp +++ b/lib/Lex/PPConditionalDirectiveRecord.cpp @@ -77,7 +77,7 @@ void PPConditionalDirectiveRecord::addCondDirectiveLoc( void PPConditionalDirectiveRecord::If(SourceLocation Loc, SourceRange ConditionRange, - bool ConditionValue) { + ConditionValueKind ConditionValue) { addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); CondDirectiveStack.push_back(Loc); } @@ -98,7 +98,7 @@ void PPConditionalDirectiveRecord::Ifndef(SourceLocation Loc, void PPConditionalDirectiveRecord::Elif(SourceLocation Loc, SourceRange ConditionRange, - bool ConditionValue, + ConditionValueKind ConditionValue, SourceLocation IfLoc) { addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); CondDirectiveStack.back() = Loc; diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 70c32c3dc6..2aa67fb862 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -424,7 +424,7 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, const SourceLocation CondEnd = CurPPLexer->getSourceLocation(); Callbacks->Elif(Tok.getLocation(), SourceRange(CondBegin, CondEnd), - CondValue, CondInfo.IfLoc); + (CondValue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False), CondInfo.IfLoc); } // If this condition is true, enter it! if (CondValue) { @@ -2280,7 +2280,7 @@ void Preprocessor::HandleIfDirective(Token &IfToken, if (Callbacks) Callbacks->If(IfToken.getLocation(), SourceRange(ConditionalBegin, ConditionalEnd), - ConditionalTrue); + (ConditionalTrue ? PPCallbacks::CVK_True : PPCallbacks::CVK_False)); // Should we include the stuff contained by this directive? if (ConditionalTrue) { @@ -2377,7 +2377,7 @@ void Preprocessor::HandleElifDirective(Token &ElifToken) { if (Callbacks) Callbacks->Elif(ElifToken.getLocation(), SourceRange(ConditionalBegin, ConditionalEnd), - true, CI.IfLoc); + PPCallbacks::CVK_NotEvaluated, CI.IfLoc); // Finally, skip the rest of the contents of this block. SkipExcludedConditionalBlock(CI.IfLoc, /*Foundnonskip*/true, -- 2.40.0