From: Enea Zaffanella Date: Sat, 20 Jul 2013 20:09:11 +0000 (+0000) Subject: Added preproc callback for pragma directives. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0189fd61ec72d86e008aa5615be80581f84cf703;p=clang Added preproc callback for pragma directives. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@186770 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Lex/PPCallbacks.h b/include/clang/Lex/PPCallbacks.h index d156c52291..cb635bcb2d 100644 --- a/include/clang/Lex/PPCallbacks.h +++ b/include/clang/Lex/PPCallbacks.h @@ -19,6 +19,7 @@ #include "clang/Basic/SourceLocation.h" #include "clang/Lex/DirectoryLookup.h" #include "clang/Lex/ModuleLoader.h" +#include "clang/Lex/Pragma.h" #include "llvm/ADT/StringRef.h" #include @@ -155,6 +156,11 @@ public: virtual void Ident(SourceLocation Loc, const std::string &str) { } + /// \brief Callback invoked when start reading any pragma directive. + virtual void PragmaDirective(SourceLocation Loc, + PragmaIntroducerKind Introducer) { + } + /// \brief Callback invoked when a \#pragma comment directive is read. virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind, const std::string &Str) { diff --git a/include/clang/Lex/Preprocessor.h b/include/clang/Lex/Preprocessor.h index 60051ec112..86eabf080d 100644 --- a/include/clang/Lex/Preprocessor.h +++ b/include/clang/Lex/Preprocessor.h @@ -1457,7 +1457,8 @@ private: void HandleElifDirective(Token &Tok); // Pragmas. - void HandlePragmaDirective(unsigned Introducer); + void HandlePragmaDirective(SourceLocation IntroducerLoc, + PragmaIntroducerKind Introducer); public: void HandlePragmaOnce(Token &OnceTok); void HandlePragmaMark(); diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 51ddb2d3a7..c70019ffb0 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -757,7 +757,7 @@ void Preprocessor::HandleDirective(Token &Result) { // C99 6.10.6 - Pragma Directive. case tok::pp_pragma: - return HandlePragmaDirective(PIK_HashPragma); + return HandlePragmaDirective(SavedHash.getLocation(), PIK_HashPragma); // GNU Extensions. case tok::pp_import: diff --git a/lib/Lex/Pragma.cpp b/lib/Lex/Pragma.cpp index 3293823c21..324bbd29a2 100644 --- a/lib/Lex/Pragma.cpp +++ b/lib/Lex/Pragma.cpp @@ -101,7 +101,11 @@ void PragmaNamespace::HandlePragma(Preprocessor &PP, /// HandlePragmaDirective - The "\#pragma" directive has been parsed. Lex the /// rest of the pragma, passing it to the registered pragma handlers. -void Preprocessor::HandlePragmaDirective(unsigned Introducer) { +void Preprocessor::HandlePragmaDirective(SourceLocation IntroducerLoc, + PragmaIntroducerKind Introducer) { + if (Callbacks) + Callbacks->PragmaDirective(IntroducerLoc, Introducer); + if (!PragmasEnabled) return; @@ -109,7 +113,7 @@ void Preprocessor::HandlePragmaDirective(unsigned Introducer) { // Invoke the first level of pragma handlers which reads the namespace id. Token Tok; - PragmaHandlers->HandlePragma(*this, PragmaIntroducerKind(Introducer), Tok); + PragmaHandlers->HandlePragma(*this, Introducer, Tok); // If the pragma handler didn't read the rest of the line, consume it now. if ((CurTokenLexer && CurTokenLexer->isParsingPreprocessorDirective()) @@ -287,7 +291,7 @@ void Preprocessor::Handle_Pragma(Token &Tok) { EnterSourceFileWithLexer(TL, 0); // With everything set up, lex this as a #pragma directive. - HandlePragmaDirective(PIK__Pragma); + HandlePragmaDirective(PragmaLoc, PIK__Pragma); // Finally, return whatever came after the pragma directive. return Lex(Tok); @@ -336,7 +340,7 @@ void Preprocessor::HandleMicrosoft__pragma(Token &Tok) { EnterTokenStream(TokArray, PragmaToks.size(), true, true); // With everything set up, lex this as a #pragma directive. - HandlePragmaDirective(PIK___pragma); + HandlePragmaDirective(PragmaLoc, PIK___pragma); // Finally, return whatever came after the pragma directive. return Lex(Tok);