소스 검색

Add #pragma region support (#5074)

Add the pragma region handler to the HLSL pragma handlers list.

Fixes #676

Sorry for the slow turn around time.
Chris B 2 년 전
부모
커밋
364d5f9da2
3개의 변경된 파일26개의 추가작업 그리고 0개의 파일을 삭제
  1. 2 0
      tools/clang/lib/Lex/Pragma.cpp
  2. 19 0
      tools/clang/test/HLSL/pragma-region.hlsl
  3. 5 0
      tools/clang/unittests/HLSL/VerifierTest.cpp

+ 2 - 0
tools/clang/lib/Lex/Pragma.cpp

@@ -1437,6 +1437,8 @@ void Preprocessor::RegisterBuiltinPragmas() {
     AddPragmaHandler(new PragmaMarkHandler());
     AddPragmaHandler("dxc", new PragmaDiagnosticHandler("dxc"));
     AddPragmaHandler(new PragmaMessageHandler(PPCallbacks::PMK_Message));
+    AddPragmaHandler(new PragmaRegionHandler("region"));
+    AddPragmaHandler(new PragmaRegionHandler("endregion"));
     return;
   }
   // HLSL Change Ends

+ 19 - 0
tools/clang/test/HLSL/pragma-region.hlsl

@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -ffreestanding -verify %s
+
+// expected-no-diagnostics
+
+// Clang doesn't do anything with the pragma region diagnostics, so there's
+// nothing to test here except that we ignore them...
+
+#pragma region Doggo
+struct Doggo {
+  int legs;
+  int tailLength;
+};
+#pragma endregion Doggo
+
+#pragma region functions
+
+#pragma region foo
+int foo() { return 0; }
+#pragma region functions

+ 5 - 0
tools/clang/unittests/HLSL/VerifierTest.cpp

@@ -62,6 +62,7 @@ public:
   TEST_METHOD(RunObjectOperators)
   TEST_METHOD(RunOutParamDiags)
   TEST_METHOD(RunPackReg)
+  TEST_METHOD(RunPragmaRegion)
   TEST_METHOD(RunRayTracings)
   TEST_METHOD(RunScalarAssignments)
   TEST_METHOD(RunScalarAssignmentsExactPrecision)
@@ -287,6 +288,10 @@ TEST_F(VerifierTest, RunPackReg) {
   CheckVerifiesHLSL(L"packreg.hlsl");
 }
 
+TEST_F(VerifierTest, RunPragmaRegion) {
+  CheckVerifiesHLSL(L"pragma-region.hlsl");
+}
+
 TEST_F(VerifierTest, RunRayTracings) {
   CheckVerifiesHLSL(L"raytracings.hlsl");
 }