KyleFromKitware created this revision.
KyleFromKitware added a reviewer: clang.
KyleFromKitware created this object with edit policy "Only User: 
KyleFromKitware (Kyle Edwards)".
KyleFromKitware added a project: clang.
Herald added subscribers: carlosgalvezp, shchenz, kbarton, nemanjai.
Herald added a reviewer: njames93.
Herald added a project: All.
KyleFromKitware requested review of this revision.
Herald added a subscriber: cfe-commits.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D142465

Files:
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
  clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
  clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
  clang-tools-extra/docs/pp-trace.rst
  clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
  clang-tools-extra/pp-trace/PPCallbacksTracker.h
  clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp
  clang-tools-extra/test/pp-trace/pp-trace-pragma-ms.cpp
  clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
  clang/include/clang/Lex/PPCallbacks.h
  clang/lib/Lex/Pragma.cpp

Index: clang/lib/Lex/Pragma.cpp
===================================================================
--- clang/lib/Lex/Pragma.cpp
+++ clang/lib/Lex/Pragma.cpp
@@ -166,7 +166,7 @@
 /// rest of the pragma, passing it to the registered pragma handlers.
 void Preprocessor::HandlePragmaDirective(PragmaIntroducer Introducer) {
   if (Callbacks)
-    Callbacks->PragmaDirective(Introducer.Loc, Introducer.Kind);
+    Callbacks->PragmaDirective(Introducer);
 
   if (!PragmasEnabled)
     return;
Index: clang/include/clang/Lex/PPCallbacks.h
===================================================================
--- clang/include/clang/Lex/PPCallbacks.h
+++ clang/include/clang/Lex/PPCallbacks.h
@@ -183,9 +183,7 @@
   }
 
   /// Callback invoked when start reading any pragma directive.
-  virtual void PragmaDirective(SourceLocation Loc,
-                               PragmaIntroducerKind Introducer) {
-  }
+  virtual void PragmaDirective(PragmaIntroducer Introducer) {}
 
   /// Callback invoked when a \#pragma comment directive is read.
   virtual void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
@@ -493,10 +491,9 @@
     Second->Ident(Loc, str);
   }
 
-  void PragmaDirective(SourceLocation Loc,
-                       PragmaIntroducerKind Introducer) override {
-    First->PragmaDirective(Loc, Introducer);
-    Second->PragmaDirective(Loc, Introducer);
+  void PragmaDirective(PragmaIntroducer Introducer) override {
+    First->PragmaDirective(Introducer);
+    Second->PragmaDirective(Introducer);
   }
 
   void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
Index: clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
===================================================================
--- clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
+++ clang-tools-extra/test/pp-trace/pp-trace-pragma-opencl.cpp
@@ -6,24 +6,21 @@
 
 // CHECK: ---
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:3:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:3:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaOpenCLExtension
 // CHECK-NEXT:   NameLoc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:3:26"
 // CHECK-NEXT:   Name: all
 // CHECK-NEXT:   StateLoc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:3:32"
 // CHECK-NEXT:   State: 0
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:4:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:4:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaOpenCLExtension
 // CHECK-NEXT:   NameLoc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:4:26"
 // CHECK-NEXT:   Name: cl_khr_int64_base_atomics
 // CHECK-NEXT:   StateLoc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:4:54"
 // CHECK-NEXT:   State: 0
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:5:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:5:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaOpenCLExtension
 // CHECK-NEXT:   NameLoc: "{{.*}}{{[/\\]}}pp-trace-pragma-opencl.cpp:5:26"
 // CHECK-NEXT:   Name: cl_khr_int64_base_atomics
Index: clang-tools-extra/test/pp-trace/pp-trace-pragma-ms.cpp
===================================================================
--- clang-tools-extra/test/pp-trace/pp-trace-pragma-ms.cpp
+++ clang-tools-extra/test/pp-trace/pp-trace-pragma-ms.cpp
@@ -18,72 +18,61 @@
 
 // CHECK: ---
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:3:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:3:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaComment
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:3:9"
 // CHECK-NEXT:   Kind: compiler
 // CHECK-NEXT:   Str: compiler comment
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:4:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:4:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaComment
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:4:9"
 // CHECK-NEXT:   Kind: exestr
 // CHECK-NEXT:   Str: exestr comment
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:5:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:5:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaComment
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:5:9"
 // CHECK-NEXT:   Kind: lib
 // CHECK-NEXT:   Str: lib comment
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:6:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:6:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaComment
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:6:9"
 // CHECK-NEXT:   Kind: linker
 // CHECK-NEXT:   Str: linker comment
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:7:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:7:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaComment
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:7:9"
 // CHECK-NEXT:   Kind: user
 // CHECK-NEXT:   Str: user comment
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:9:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:9:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaDetectMismatch
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:9:9"
 // CHECK-NEXT:   Name: name argument
 // CHECK-NEXT:   Value: value argument
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:11:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:11:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:13:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:13:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaMessage
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:13:9"
 // CHECK-NEXT:   Namespace: 
 // CHECK-NEXT:   Kind: PMK_Message
 // CHECK-NEXT:   Str: message argument
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:15:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:15:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaWarningPush
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:15:9"
 // CHECK-NEXT:   Level: 1
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:16:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:16:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaWarningPop
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:16:9"
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:17:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:17:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaWarning
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-ms.cpp:17:9"
 // CHECK-NEXT:   WarningSpec: PWS_Disable
Index: clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp
===================================================================
--- clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp
+++ clang-tools-extra/test/pp-trace/pp-trace-pragma-general.cpp
@@ -21,96 +21,83 @@
 
 // CHECK: ---
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:3:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:3:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaDiagnosticPush
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:3:15"
 // CHECK-NEXT:   Namespace: clang
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:4:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:4:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaDiagnosticPop
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:4:15"
 // CHECK-NEXT:   Namespace: clang
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:5:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:5:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaDiagnostic
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:5:15"
 // CHECK-NEXT:   Namespace: clang
 // CHECK-NEXT:   Mapping: MAP_IGNORE
 // CHECK-NEXT:   Str: -Wformat
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:6:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:6:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaDiagnostic
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:6:15"
 // CHECK-NEXT:   Namespace: clang
 // CHECK-NEXT:   Mapping: MAP_WARNING
 // CHECK-NEXT:   Str: -Wformat
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:7:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:7:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaDiagnostic
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:7:15"
 // CHECK-NEXT:   Namespace: clang
 // CHECK-NEXT:   Mapping: MAP_ERROR
 // CHECK-NEXT:   Str: -Wformat
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:8:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:8:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaDiagnostic
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:8:15"
 // CHECK-NEXT:   Namespace: clang
 // CHECK-NEXT:   Mapping: MAP_FATAL
 // CHECK-NEXT:   Str: -Wformat
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:10:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:10:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaDiagnosticPush
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:10:13"
 // CHECK-NEXT:   Namespace: GCC
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:11:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:11:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaDiagnosticPop
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:11:13"
 // CHECK-NEXT:   Namespace: GCC
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:12:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:12:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaDiagnostic
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:12:13"
 // CHECK-NEXT:   Namespace: GCC
 // CHECK-NEXT:   Mapping: MAP_IGNORE
 // CHECK-NEXT:   Str: -Wformat
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:13:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:13:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaDiagnostic
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:13:13"
 // CHECK-NEXT:   Namespace: GCC
 // CHECK-NEXT:   Mapping: MAP_WARNING
 // CHECK-NEXT:   Str: -Wformat
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:14:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:14:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaDiagnostic
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:14:13"
 // CHECK-NEXT:   Namespace: GCC
 // CHECK-NEXT:   Mapping: MAP_ERROR
 // CHECK-NEXT:   Str: -Wformat
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:15:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:15:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaDiagnostic
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:15:13"
 // CHECK-NEXT:   Namespace: GCC
 // CHECK-NEXT:   Mapping: MAP_FATAL
 // CHECK-NEXT:   Str: -Wformat
 // CHECK-NEXT: - Callback: PragmaDirective
-// CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:18:1"
-// CHECK-NEXT:   Introducer: PIK_HashPragma
+// CHECK-NEXT:   Introducer: {Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:18:1", Kind: PIK_HashPragma}
 // CHECK-NEXT: - Callback: PragmaDebug
 // CHECK-NEXT:   Loc: "{{.*}}{{[/\\]}}pp-trace-pragma-general.cpp:18:23"
 // CHECK-NEXT:   DebugType: captured
Index: clang-tools-extra/pp-trace/PPCallbacksTracker.h
===================================================================
--- clang-tools-extra/pp-trace/PPCallbacksTracker.h
+++ clang-tools-extra/pp-trace/PPCallbacksTracker.h
@@ -101,8 +101,7 @@
                     const Module *Imported) override;
   void EndOfMainFile() override;
   void Ident(SourceLocation Loc, llvm::StringRef str) override;
-  void PragmaDirective(SourceLocation Loc,
-                       PragmaIntroducerKind Introducer) override;
+  void PragmaDirective(PragmaIntroducer Introducer) override;
   void PragmaComment(SourceLocation Loc, const IdentifierInfo *Kind,
                      llvm::StringRef Str) override;
   void PragmaDetectMismatch(SourceLocation Loc, llvm::StringRef Name,
@@ -208,6 +207,9 @@
   /// Append a Module argument to the top trace item.
   void appendArgument(const char *Name, const Module *Value);
 
+  // Append a PragmaIntroducer argument to the top trace item.
+  void appendArgument(const char *Name, PragmaIntroducer Introducer);
+
   /// Append a double-quoted argument to the top trace item.
   void appendQuotedArgument(const char *Name, const std::string &Value);
 
Index: clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
===================================================================
--- clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
+++ clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
@@ -171,11 +171,9 @@
 }
 
 // Callback invoked when start reading any pragma directive.
-void PPCallbacksTracker::PragmaDirective(SourceLocation Loc,
-                                         PragmaIntroducerKind Introducer) {
+void PPCallbacksTracker::PragmaDirective(PragmaIntroducer Introducer) {
   beginCallback("PragmaDirective");
-  appendArgument("Loc", Loc);
-  appendArgument("Introducer", Introducer, PragmaIntroducerKindStrings);
+  appendArgument("Introducer", Introducer);
 }
 
 // Callback invoked when a #pragma comment directive is read.
@@ -636,6 +634,21 @@
   appendArgument(Name, Value->Name.c_str());
 }
 
+// Append a PragmaIntroducer argument to the top trace item.
+void PPCallbacksTracker::appendArgument(const char *Name,
+                                        PragmaIntroducer Value) {
+  std::string Str;
+  llvm::raw_string_ostream SS(Str);
+
+  SS << "{Loc: ";
+  if (Value.Loc.isInvalid())
+    SS << "(invalid)";
+  else
+    SS << getSourceLocationString(PP, Value.Loc);
+  SS << ", Kind: " << PragmaIntroducerKindStrings[Value.Kind] << "}";
+  appendArgument(Name, SS.str());
+}
+
 // Append a double-quoted argument to the top trace item.
 void PPCallbacksTracker::appendQuotedArgument(const char *Name,
                                               const std::string &Value) {
Index: clang-tools-extra/docs/pp-trace.rst
===================================================================
--- clang-tools-extra/docs/pp-trace.rst
+++ clang-tools-extra/docs/pp-trace.rst
@@ -299,12 +299,11 @@
 
 Argument descriptions:
 
-==============   ==================================================   ============================== =================================
-Argument Name    Argument Value Syntax                                Clang C++ Type                 Description
-==============   ==================================================   ============================== =================================
-Loc              "(file):(line):(col)"                                SourceLocation                 The location of the directive.
-Introducer       (PIK_HashPragma|PIK__Pragma|PIK___pragma)            PragmaIntroducerKind           The type of the pragma directive.
-==============   ==================================================   ============================== =================================
+==============   =============================================================================   ============================== ===============================================
+Argument Name    Argument Value Syntax                                                           Clang C++ Type                 Description
+==============   =============================================================================   ============================== ===============================================
+Introducer       {Loc: "(file):(line):(col)", Kind: (PIK_HashPragma|PIK__Pragma|PIK___pragma)}   PragmaIntroducer               The location and kind of the pragma introducer.
+==============   =============================================================================   ============================== ===============================================
 
 Example:::
 
Index: clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
+++ clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
@@ -174,8 +174,7 @@
     PPCallbacks::Elifndef(Loc, ConditionRange, IfLoc);
   }
   void Endif(SourceLocation Loc, SourceLocation IfLoc) override;
-  void PragmaDirective(SourceLocation Loc,
-                       PragmaIntroducerKind Introducer) override;
+  void PragmaDirective(PragmaIntroducer Introducer) override;
 
   // After we've seen everything, issue warnings and fix-its.
   void EndOfMainFile() override;
@@ -409,14 +408,13 @@
 
 } // namespace
 
-void MacroToEnumCallbacks::PragmaDirective(SourceLocation Loc,
-                                           PragmaIntroducerKind Introducer) {
+void MacroToEnumCallbacks::PragmaDirective(PragmaIntroducer Introducer) {
   if (CurrentFile->GuardScanner != IncludeGuard::FileChanged)
     return;
 
   bool Invalid = false;
   const char *Text = SM.getCharacterData(
-      Lexer::getLocForEndOfToken(Loc, 0, SM, LangOpts), &Invalid);
+      Lexer::getLocForEndOfToken(Introducer.Loc, 0, SM, LangOpts), &Invalid);
   if (Invalid)
     return;
 
Index: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
===================================================================
--- clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
+++ clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
@@ -80,7 +80,7 @@
   // Just parse to the corresponding location to generate PPCallbacks for the
   // corresponding range
   void Ident(SourceLocation Loc, StringRef) override;
-  void PragmaDirective(SourceLocation Loc, PragmaIntroducerKind) override;
+  void PragmaDirective(PragmaIntroducer Introducer) override;
   void PragmaComment(SourceLocation Loc, const IdentifierInfo *,
                      StringRef) override;
   void PragmaDetectMismatch(SourceLocation Loc, StringRef, StringRef) override;
Index: clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
===================================================================
--- clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -185,9 +185,9 @@
 void ExpandModularHeadersPPCallbacks::Ident(SourceLocation Loc, StringRef) {
   parseToLocation(Loc);
 }
-void ExpandModularHeadersPPCallbacks::PragmaDirective(SourceLocation Loc,
-                                                      PragmaIntroducerKind) {
-  parseToLocation(Loc);
+void ExpandModularHeadersPPCallbacks::PragmaDirective(
+    PragmaIntroducer Introducer) {
+  parseToLocation(Introducer.Loc);
 }
 void ExpandModularHeadersPPCallbacks::PragmaComment(SourceLocation Loc,
                                                     const IdentifierInfo *,
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to