瀏覽代碼

NFC: Implement OMPClause dump in terms of visitors

Reviewers: aaron.ballman

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D56708

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351236 91177308-0d34-0410-b5e6-96231b3b80d8
Stephen Kelly 6 年之前
父節點
當前提交
fb4e678d5a
共有 3 個文件被更改,包括 31 次插入21 次删除
  1. 2 0
      include/clang/AST/TextNodeDumper.h
  2. 11 21
      lib/AST/ASTDumper.cpp
  3. 18 0
      lib/AST/TextNodeDumper.cpp

+ 2 - 0
include/clang/AST/TextNodeDumper.h

@@ -169,6 +169,8 @@ public:
 
   void Visit(const CXXCtorInitializer *Init);
 
+  void Visit(const OMPClause *C);
+
   void dumpPointer(const void *Ptr);
   void dumpLocation(SourceLocation Loc);
   void dumpSourceRange(SourceRange R);

+ 11 - 21
lib/AST/ASTDumper.cpp

@@ -292,6 +292,7 @@ namespace  {
     void VisitCapturedStmt(const CapturedStmt *Node);
 
     // OpenMP
+    void Visit(const OMPClause *C);
     void VisitOMPExecutableDirective(const OMPExecutableDirective *Node);
 
     // Exprs
@@ -1448,29 +1449,18 @@ void ASTDumper::VisitCapturedStmt(const CapturedStmt *Node) {
 //  OpenMP dumping methods.
 //===----------------------------------------------------------------------===//
 
+void ASTDumper::Visit(const OMPClause *C) {
+  dumpChild([=] {
+    NodeDumper.Visit(C);
+    for (auto *S : C->children())
+      dumpStmt(S);
+  });
+}
+
 void ASTDumper::VisitOMPExecutableDirective(
     const OMPExecutableDirective *Node) {
-  for (auto *C : Node->clauses()) {
-    dumpChild([=] {
-      if (!C) {
-        ColorScope Color(OS, ShowColors, NullColor);
-        OS << "<<<NULL>>> OMPClause";
-        return;
-      }
-      {
-        ColorScope Color(OS, ShowColors, AttrColor);
-        StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
-        OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
-           << ClauseName.drop_front() << "Clause";
-      }
-      NodeDumper.dumpPointer(C);
-      NodeDumper.dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
-      if (C->isImplicit())
-        OS << " <implicit>";
-      for (auto *S : C->children())
-        dumpStmt(S);
-    });
-  }
+  for (const auto *C : Node->clauses())
+    Visit(C);
 }
 
 //===----------------------------------------------------------------------===//

+ 18 - 0
lib/AST/TextNodeDumper.cpp

@@ -272,6 +272,24 @@ void TextNodeDumper::Visit(const CXXCtorInitializer *Init) {
   }
 }
 
+void TextNodeDumper::Visit(const OMPClause *C) {
+  if (!C) {
+    ColorScope Color(OS, ShowColors, NullColor);
+    OS << "<<<NULL>>> OMPClause";
+    return;
+  }
+  {
+    ColorScope Color(OS, ShowColors, AttrColor);
+    StringRef ClauseName(getOpenMPClauseName(C->getClauseKind()));
+    OS << "OMP" << ClauseName.substr(/*Start=*/0, /*N=*/1).upper()
+       << ClauseName.drop_front() << "Clause";
+  }
+  dumpPointer(C);
+  dumpSourceRange(SourceRange(C->getBeginLoc(), C->getEndLoc()));
+  if (C->isImplicit())
+    OS << " <implicit>";
+}
+
 void TextNodeDumper::dumpPointer(const void *Ptr) {
   ColorScope Color(OS, ShowColors, AddressColor);
   OS << ' ' << Ptr;