From 6a04b5e8c4f15c724b8b89a9c0ea702586ad1852 Mon Sep 17 00:00:00 2001 From: John Thompson Date: Thu, 18 Jul 2013 00:00:36 +0000 Subject: [PATCH] Add condition expression result to if and elif callbacks. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186547 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Lex/PPCallbacks.h | 22 +++++++++++-------- .../clang/Lex/PPConditionalDirectiveRecord.h | 5 +++-- lib/Lex/PPConditionalDirectiveRecord.cpp | 4 +++- lib/Lex/PPDirectives.cpp | 8 ++++--- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/include/clang/Lex/PPCallbacks.h b/include/clang/Lex/PPCallbacks.h index 021cef00b3..71e621fb72 100644 --- a/include/clang/Lex/PPCallbacks.h +++ b/include/clang/Lex/PPCallbacks.h @@ -243,18 +243,21 @@ public: /// \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. + /// \param ConditionValue The evaluated value of the condition. /// // FIXME: better to pass in a list (or tree!) of Tokens. - virtual void If(SourceLocation Loc, SourceRange ConditionRange) { + virtual void If(SourceLocation Loc, SourceRange ConditionRange, + bool ConditionValue) { } /// \brief Hook called whenever an \#elif is seen. /// \param Loc the source location of the directive. /// \param ConditionRange The SourceRange of the expression being tested. + /// \param ConditionValue The evaluated value of the condition. /// \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, - SourceLocation IfLoc) { + bool ConditionValue, SourceLocation IfLoc) { } /// \brief Hook called whenever an \#ifdef is seen. @@ -418,16 +421,17 @@ public: } /// \brief Hook called whenever an \#if is seen. - virtual void If(SourceLocation Loc, SourceRange ConditionRange) { - First->If(Loc, ConditionRange); - Second->If(Loc, ConditionRange); + virtual void If(SourceLocation Loc, SourceRange ConditionRange, + bool ConditionValue) { + First->If(Loc, ConditionRange, ConditionValue); + Second->If(Loc, ConditionRange, ConditionValue); } - /// \brief Hook called whenever an \#if is seen. + /// \brief Hook called whenever an \#elif is seen. virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, - SourceLocation IfLoc) { - First->Elif(Loc, ConditionRange, IfLoc); - Second->Elif(Loc, ConditionRange, IfLoc); + bool ConditionValue, SourceLocation IfLoc) { + First->Elif(Loc, ConditionRange, ConditionValue, IfLoc); + Second->Elif(Loc, ConditionRange, ConditionValue, IfLoc); } /// \brief Hook called whenever an \#ifdef is seen. diff --git a/include/clang/Lex/PPConditionalDirectiveRecord.h b/include/clang/Lex/PPConditionalDirectiveRecord.h index b9a22529e2..54a132d586 100644 --- a/include/clang/Lex/PPConditionalDirectiveRecord.h +++ b/include/clang/Lex/PPConditionalDirectiveRecord.h @@ -86,9 +86,10 @@ public: SourceLocation findConditionalDirectiveRegionLoc(SourceLocation Loc) const; private: - virtual void If(SourceLocation Loc, SourceRange ConditionRange); + virtual void If(SourceLocation Loc, SourceRange ConditionRange, + bool ConditionValue); virtual void Elif(SourceLocation Loc, SourceRange ConditionRange, - SourceLocation IfLoc); + bool 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 16ce3efb04..16dc1d8f09 100644 --- a/lib/Lex/PPConditionalDirectiveRecord.cpp +++ b/lib/Lex/PPConditionalDirectiveRecord.cpp @@ -76,7 +76,8 @@ void PPConditionalDirectiveRecord::addCondDirectiveLoc( } void PPConditionalDirectiveRecord::If(SourceLocation Loc, - SourceRange ConditionRange) { + SourceRange ConditionRange, + bool ConditionValue) { addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); CondDirectiveStack.push_back(Loc); } @@ -97,6 +98,7 @@ void PPConditionalDirectiveRecord::Ifndef(SourceLocation Loc, void PPConditionalDirectiveRecord::Elif(SourceLocation Loc, SourceRange ConditionRange, + bool ConditionValue, SourceLocation IfLoc) { addCondDirectiveLoc(CondDirectiveLoc(Loc, CondDirectiveStack.back())); CondDirectiveStack.back() = Loc; diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index cb56615ddc..51ddb2d3a7 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -430,7 +430,7 @@ void Preprocessor::SkipExcludedConditionalBlock(SourceLocation IfTokenLoc, if (Callbacks) Callbacks->Elif(Tok.getLocation(), SourceRange(ConditionalBegin, ConditionalEnd), - CondInfo.IfLoc); + ShouldEnter, CondInfo.IfLoc); break; } } @@ -2181,7 +2181,8 @@ void Preprocessor::HandleIfDirective(Token &IfToken, if (Callbacks) Callbacks->If(IfToken.getLocation(), - SourceRange(ConditionalBegin, ConditionalEnd)); + SourceRange(ConditionalBegin, ConditionalEnd), + ConditionalTrue); // Should we include the stuff contained by this directive? if (ConditionalTrue) { @@ -2277,7 +2278,8 @@ void Preprocessor::HandleElifDirective(Token &ElifToken) { if (Callbacks) Callbacks->Elif(ElifToken.getLocation(), - SourceRange(ConditionalBegin, ConditionalEnd), CI.IfLoc); + SourceRange(ConditionalBegin, ConditionalEnd), + true, CI.IfLoc); // Finally, skip the rest of the contents of this block. SkipExcludedConditionalBlock(CI.IfLoc, /*Foundnonskip*/true, -- 2.40.0