[cfe-commits] [PATCH] Add #pragma region for MSVC mode

pravic ehysta at gmail.com
Tue Nov 13 00:40:12 PST 2012


  update according to latest notes.

Hi triton, chapuni, rsmith,

http://llvm-reviews.chandlerc.com/D65

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D65?vs=300&id=305#toc

Files:
  lib/Lex/Pragma.cpp
  test/Lexer/pragma-region.c

Index: lib/Lex/Pragma.cpp
===================================================================
--- lib/Lex/Pragma.cpp
+++ lib/Lex/Pragma.cpp
@@ -1277,6 +1277,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
 
 
@@ -1310,5 +1333,7 @@
   if (LangOpts.MicrosoftExt) {
     AddPragmaHandler(new PragmaCommentHandler());
     AddPragmaHandler(new PragmaIncludeAliasHandler());
+    AddPragmaHandler(new PragmaRegionHandler("region"));
+    AddPragmaHandler(new PragmaRegionHandler("endregion"));
   }
 }
Index: test/Lexer/pragma-region.c
===================================================================
--- /dev/null
+++ 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65.5.patch
Type: text/x-patch
Size: 2314 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121113/86c8318f/attachment.bin>


More information about the cfe-commits mailing list