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

pravic ehysta at gmail.com
Mon Nov 5 11:54:05 PST 2012


  Updated patch with much more context.

Hi triton, chapuni, rsmith,

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

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D65?vs=177&id=257#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,33 @@
   }
 };
 
+/// \bried PragmaRegionHandler - "\#pragma region [...]"
+///
+/// The syntax is
+/// \code
+///   \#pragma region [optional name]
+///   \#pragma endregion [optional comment]
+/// \endcode
+struct PragmaRegionHandler : public PragmaHandler {
+  PragmaRegionHandler(const char* pragma)
+    :PragmaHandler(pragma)
+  {}
+
+  virtual void HandlePragma(Preprocessor &PP, PragmaIntroducerKind Introducer,
+    Token &NameTok) {
+    // #pragma region: just skip it
+    // __pragma(region): no sense, but ignored by msvc too
+    // _Pragma is not valid for MSVC
+    if (Introducer == PIK__Pragma) {
+      PP.Diag(NameTok.getLocation(), diag::warn_pragma_ignored);
+    }
+  }
+
+
+};
+
+
+
 }  // end anonymous namespace
 
 
@@ -1310,5 +1337,7 @@
   if (LangOpts.MicrosoftExt) {
     AddPragmaHandler(new PragmaCommentHandler());
     AddPragmaHandler(new PragmaIncludeAliasHandler());
+    AddPragmaHandler(new PragmaRegionHandler("region"));
+    AddPragmaHandler(new PragmaRegionHandler("endregion"));
   }
 }
Index: test/Lexer/pragma-region.c
===================================================================
--- test/Lexer/pragma-region.c
+++ test/Lexer/pragma-region.c
@@ -0,0 +1,22 @@
+/* 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
+
+__pragma(region) // no sense, but ignored
+#pragma region2 // expected-warning {{unknown pragma ignored}}
+_Pragma("region") // expected-warning {{unknown pragma ignored}}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65.3.patch
Type: text/x-patch
Size: 2012 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121105/b12336f4/attachment.bin>


More information about the cfe-commits mailing list