From 406ea51cfbb027162e3df2c7d13fd515018e8d76 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Fri, 30 Nov 2012 19:52:30 +0000 Subject: [PATCH] Support for #pragma region/endregion for MSVC compatibility. Patch thanks to pravic! llvm-svn: 169028 --- clang/lib/Lex/Pragma.cpp | 25 +++++++++++++++++++++++++ clang/test/Lexer/pragma-region.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 clang/test/Lexer/pragma-region.c diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index 783588e..c1e90cc 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -1203,6 +1203,29 @@ struct PragmaARCCFCodeAuditedHandler : public PragmaHandler { } }; + /// \brief Handle "\#pragma region [...]" + /// + /// The syntax is + /// \code + /// \#pragma region [optional name] + /// \#pragma endregion [optional comment] + /// \endcode + /// + /// \note This is + /// editor-only + /// pragma, just skipped by compiler. + struct PragmaRegionHandler : public PragmaHandler { + PragmaRegionHandler(const char *pragma) : PragmaHandler(pragma) { } + + virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer, + Token &NameTok) { + // #pragma region: endregion matches can be verified + // __pragma(region): no sense, but ignored by msvc + // _Pragma is not valid for MSVC, but there isn't any point + // to handle a _Pragma differently. + } + }; + } // end anonymous namespace @@ -1236,5 +1259,7 @@ void Preprocessor::RegisterBuiltinPragmas() { if (LangOpts.MicrosoftExt) { AddPragmaHandler(new PragmaCommentHandler()); AddPragmaHandler(new PragmaIncludeAliasHandler()); + AddPragmaHandler(new PragmaRegionHandler("region")); + AddPragmaHandler(new PragmaRegionHandler("endregion")); } } diff --git a/clang/test/Lexer/pragma-region.c b/clang/test/Lexer/pragma-region.c new file mode 100644 index 0000000..502db22 --- /dev/null +++ b/clang/test/Lexer/pragma-region.c @@ -0,0 +1,33 @@ +/* Test pragma region directive from + http://msdn.microsoft.com/en-us/library/b6xkz944(v=vs.80).aspx */ + +// Editor-only pragma, just skipped by compiler. +// Syntax: +// #pragma region optional name +// #pragma endregion optional comment +// +// RUN: %clang_cc1 -fsyntax-only -verify -Wall -fms-extensions %s + +#pragma region +/* inner space */ +#pragma endregion + +#pragma region long name +/* inner space */ +void foo(void){} +#pragma endregion long comment + +void inner(); + +__pragma(region) // no sense, but ignored +_Pragma("region")// ditto + +#pragma region2 // expected-warning {{unknown pragma ignored}} + +#pragma region one +#pragma region inner +//#pragma endregion inner + +#pragma endregion end + +// {{unclosed pragma region}} - region mismatches is not detected yet -- 2.7.4