]> granicus.if.org Git - clang/commitdiff
Support for printing/dumping static asserts
authorPeter Collingbourne <peter@pcc.me.uk>
Wed, 16 Mar 2011 18:37:27 +0000 (18:37 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Wed, 16 Mar 2011 18:37:27 +0000 (18:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@127744 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclPrinter.cpp
lib/AST/StmtDumper.cpp

index 278163238493b742e3e6fa3c853627795e495302..446b4d4646464892bfcf03342af21fd0bfc4b00f 100644 (file)
@@ -54,6 +54,7 @@ namespace {
     void VisitLabelDecl(LabelDecl *D);
     void VisitParmVarDecl(ParmVarDecl *D);
     void VisitFileScopeAsmDecl(FileScopeAsmDecl *D);
+    void VisitStaticAssertDecl(StaticAssertDecl *D);
     void VisitNamespaceDecl(NamespaceDecl *D);
     void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
     void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
@@ -590,6 +591,14 @@ void DeclPrinter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) {
   Out << ")";
 }
 
+void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl *D) {
+  Out << "static_assert(";
+  D->getAssertExpr()->printPretty(Out, Context, 0, Policy, Indentation);
+  Out << ", ";
+  D->getMessage()->printPretty(Out, Context, 0, Policy, Indentation);
+  Out << ")";
+}
+
 //----------------------------------------------------------------------------
 // C++ declarations
 //----------------------------------------------------------------------------
index 21ed8489677be9067ea207b1f274e669735c043f..e167441c4437579098d81df81f351ce66578a3f2 100644 (file)
@@ -284,6 +284,12 @@ void StmtDumper::DumpDeclarator(Decl *D) {
     OS << ";\"";
   } else if (LabelDecl *LD = dyn_cast<LabelDecl>(D)) {
     OS << "label " << LD->getNameAsString();
+  } else if (StaticAssertDecl *SAD = dyn_cast<StaticAssertDecl>(D)) {
+    OS << "\"static_assert(\n";
+    DumpSubTree(SAD->getAssertExpr());
+    OS << ",\n";
+    DumpSubTree(SAD->getMessage());
+    OS << ");\"";
   } else {
     assert(0 && "Unexpected decl");
   }