[cfe-commits] r169028 - in /cfe/trunk: lib/Lex/Pragma.cpp test/Lexer/pragma-region.c
Aaron Ballman
aaron at aaronballman.com
Fri Nov 30 11:52:31 PST 2012
Author: aaronballman
Date: Fri Nov 30 13:52:30 2012
New Revision: 169028
URL: http://llvm.org/viewvc/llvm-project?rev=169028&view=rev
Log:
Support for #pragma region/endregion for MSVC compatibility. Patch thanks to pravic!
Added:
cfe/trunk/test/Lexer/pragma-region.c
Modified:
cfe/trunk/lib/Lex/Pragma.cpp
Modified: cfe/trunk/lib/Lex/Pragma.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Pragma.cpp?rev=169028&r1=169027&r2=169028&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Pragma.cpp (original)
+++ cfe/trunk/lib/Lex/Pragma.cpp Fri Nov 30 13:52:30 2012
@@ -1203,6 +1203,29 @@
}
};
+ /// \brief Handle "\#pragma region [...]"
+ ///
+ /// The syntax is
+ /// \code
+ /// \#pragma region [optional name]
+ /// \#pragma endregion [optional comment]
+ /// \endcode
+ ///
+ /// \note This is
+ /// <a href="http://msdn.microsoft.com/en-us/library/b6xkz944(v=vs.80).aspx">editor-only</a>
+ /// 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 @@
if (LangOpts.MicrosoftExt) {
AddPragmaHandler(new PragmaCommentHandler());
AddPragmaHandler(new PragmaIncludeAliasHandler());
+ AddPragmaHandler(new PragmaRegionHandler("region"));
+ AddPragmaHandler(new PragmaRegionHandler("endregion"));
}
}
Added: cfe/trunk/test/Lexer/pragma-region.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Lexer/pragma-region.c?rev=169028&view=auto
==============================================================================
--- cfe/trunk/test/Lexer/pragma-region.c (added)
+++ cfe/trunk/test/Lexer/pragma-region.c Fri Nov 30 13:52:30 2012
@@ -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
More information about the cfe-commits
mailing list