[cfe-commits] [PATCH] Add #pragma region for MSVC mode
Aaron Ballman
aaron at aaronballman.com
Mon Nov 12 15:37:55 PST 2012
On Mon, Nov 12, 2012 at 5:06 AM, pravic <ehysta at gmail.com> wrote:
> update patch (style changes)
>
> Hi triton, chapuni, rsmith,
>
> http://llvm-reviews.chandlerc.com/D65
>
> CHANGE SINCE LAST DIFF
> http://llvm-reviews.chandlerc.com/D65?vs=257&id=300#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,27 @@
> }
> };
>
> + /// \brief Handle "\#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: 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.
> + if (Introducer != PIK_HashPragma)
> + return;
The if statement isn't required (it does nothing of value), so it can
be removed.
> + }
> + };
> +
> } // end anonymous namespace
>
>
> @@ -1310,5 +1331,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 */
I would add that link to the comments around the pragma handler for
any who are curious about the feature. That's just me though...
> +
> +// 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
Otherwise, LGTM
~Aaron
More information about the cfe-commits
mailing list