1 1.1 joerg //===- StmtPrinter.cpp - Printing implementation for Stmt ASTs ------------===// 2 1.1 joerg // 3 1.1 joerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 1.1 joerg // See https://llvm.org/LICENSE.txt for license information. 5 1.1 joerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 1.1 joerg // 7 1.1 joerg //===----------------------------------------------------------------------===// 8 1.1 joerg // 9 1.1 joerg // This file implements the Stmt::dumpPretty/Stmt::printPretty methods, which 10 1.1 joerg // pretty print the AST back out to C code. 11 1.1 joerg // 12 1.1 joerg //===----------------------------------------------------------------------===// 13 1.1 joerg 14 1.1 joerg #include "clang/AST/ASTContext.h" 15 1.1 joerg #include "clang/AST/Attr.h" 16 1.1 joerg #include "clang/AST/Decl.h" 17 1.1 joerg #include "clang/AST/DeclBase.h" 18 1.1 joerg #include "clang/AST/DeclCXX.h" 19 1.1 joerg #include "clang/AST/DeclObjC.h" 20 1.1 joerg #include "clang/AST/DeclOpenMP.h" 21 1.1 joerg #include "clang/AST/DeclTemplate.h" 22 1.1 joerg #include "clang/AST/Expr.h" 23 1.1 joerg #include "clang/AST/ExprCXX.h" 24 1.1 joerg #include "clang/AST/ExprObjC.h" 25 1.1 joerg #include "clang/AST/ExprOpenMP.h" 26 1.1 joerg #include "clang/AST/NestedNameSpecifier.h" 27 1.1 joerg #include "clang/AST/OpenMPClause.h" 28 1.1 joerg #include "clang/AST/PrettyPrinter.h" 29 1.1 joerg #include "clang/AST/Stmt.h" 30 1.1 joerg #include "clang/AST/StmtCXX.h" 31 1.1 joerg #include "clang/AST/StmtObjC.h" 32 1.1 joerg #include "clang/AST/StmtOpenMP.h" 33 1.1 joerg #include "clang/AST/StmtVisitor.h" 34 1.1 joerg #include "clang/AST/TemplateBase.h" 35 1.1 joerg #include "clang/AST/Type.h" 36 1.1 joerg #include "clang/Basic/CharInfo.h" 37 1.1 joerg #include "clang/Basic/ExpressionTraits.h" 38 1.1 joerg #include "clang/Basic/IdentifierTable.h" 39 1.1 joerg #include "clang/Basic/JsonSupport.h" 40 1.1 joerg #include "clang/Basic/LLVM.h" 41 1.1 joerg #include "clang/Basic/Lambda.h" 42 1.1 joerg #include "clang/Basic/OpenMPKinds.h" 43 1.1 joerg #include "clang/Basic/OperatorKinds.h" 44 1.1 joerg #include "clang/Basic/SourceLocation.h" 45 1.1 joerg #include "clang/Basic/TypeTraits.h" 46 1.1 joerg #include "clang/Lex/Lexer.h" 47 1.1 joerg #include "llvm/ADT/ArrayRef.h" 48 1.1 joerg #include "llvm/ADT/SmallString.h" 49 1.1 joerg #include "llvm/ADT/SmallVector.h" 50 1.1 joerg #include "llvm/ADT/StringRef.h" 51 1.1 joerg #include "llvm/Support/Casting.h" 52 1.1 joerg #include "llvm/Support/Compiler.h" 53 1.1 joerg #include "llvm/Support/ErrorHandling.h" 54 1.1 joerg #include "llvm/Support/raw_ostream.h" 55 1.1 joerg #include <cassert> 56 1.1 joerg #include <string> 57 1.1 joerg 58 1.1 joerg using namespace clang; 59 1.1 joerg 60 1.1 joerg //===----------------------------------------------------------------------===// 61 1.1 joerg // StmtPrinter Visitor 62 1.1 joerg //===----------------------------------------------------------------------===// 63 1.1 joerg 64 1.1 joerg namespace { 65 1.1 joerg 66 1.1 joerg class StmtPrinter : public StmtVisitor<StmtPrinter> { 67 1.1 joerg raw_ostream &OS; 68 1.1 joerg unsigned IndentLevel; 69 1.1 joerg PrinterHelper* Helper; 70 1.1 joerg PrintingPolicy Policy; 71 1.1 joerg std::string NL; 72 1.1 joerg const ASTContext *Context; 73 1.1 joerg 74 1.1 joerg public: 75 1.1 joerg StmtPrinter(raw_ostream &os, PrinterHelper *helper, 76 1.1 joerg const PrintingPolicy &Policy, unsigned Indentation = 0, 77 1.1.1.2 joerg StringRef NL = "\n", const ASTContext *Context = nullptr) 78 1.1 joerg : OS(os), IndentLevel(Indentation), Helper(helper), Policy(Policy), 79 1.1 joerg NL(NL), Context(Context) {} 80 1.1 joerg 81 1.1.1.2 joerg void PrintStmt(Stmt *S) { PrintStmt(S, Policy.Indentation); } 82 1.1 joerg 83 1.1 joerg void PrintStmt(Stmt *S, int SubIndent) { 84 1.1 joerg IndentLevel += SubIndent; 85 1.1 joerg if (S && isa<Expr>(S)) { 86 1.1 joerg // If this is an expr used in a stmt context, indent and newline it. 87 1.1 joerg Indent(); 88 1.1 joerg Visit(S); 89 1.1 joerg OS << ";" << NL; 90 1.1 joerg } else if (S) { 91 1.1 joerg Visit(S); 92 1.1 joerg } else { 93 1.1 joerg Indent() << "<<<NULL STATEMENT>>>" << NL; 94 1.1 joerg } 95 1.1 joerg IndentLevel -= SubIndent; 96 1.1 joerg } 97 1.1 joerg 98 1.1 joerg void PrintInitStmt(Stmt *S, unsigned PrefixWidth) { 99 1.1 joerg // FIXME: Cope better with odd prefix widths. 100 1.1 joerg IndentLevel += (PrefixWidth + 1) / 2; 101 1.1 joerg if (auto *DS = dyn_cast<DeclStmt>(S)) 102 1.1 joerg PrintRawDeclStmt(DS); 103 1.1 joerg else 104 1.1 joerg PrintExpr(cast<Expr>(S)); 105 1.1 joerg OS << "; "; 106 1.1 joerg IndentLevel -= (PrefixWidth + 1) / 2; 107 1.1 joerg } 108 1.1 joerg 109 1.1 joerg void PrintControlledStmt(Stmt *S) { 110 1.1 joerg if (auto *CS = dyn_cast<CompoundStmt>(S)) { 111 1.1 joerg OS << " "; 112 1.1 joerg PrintRawCompoundStmt(CS); 113 1.1 joerg OS << NL; 114 1.1 joerg } else { 115 1.1 joerg OS << NL; 116 1.1 joerg PrintStmt(S); 117 1.1 joerg } 118 1.1 joerg } 119 1.1 joerg 120 1.1 joerg void PrintRawCompoundStmt(CompoundStmt *S); 121 1.1 joerg void PrintRawDecl(Decl *D); 122 1.1 joerg void PrintRawDeclStmt(const DeclStmt *S); 123 1.1 joerg void PrintRawIfStmt(IfStmt *If); 124 1.1 joerg void PrintRawCXXCatchStmt(CXXCatchStmt *Catch); 125 1.1 joerg void PrintCallArgs(CallExpr *E); 126 1.1 joerg void PrintRawSEHExceptHandler(SEHExceptStmt *S); 127 1.1 joerg void PrintRawSEHFinallyStmt(SEHFinallyStmt *S); 128 1.1 joerg void PrintOMPExecutableDirective(OMPExecutableDirective *S, 129 1.1 joerg bool ForceNoStmt = false); 130 1.1 joerg 131 1.1 joerg void PrintExpr(Expr *E) { 132 1.1 joerg if (E) 133 1.1 joerg Visit(E); 134 1.1 joerg else 135 1.1 joerg OS << "<null expr>"; 136 1.1 joerg } 137 1.1 joerg 138 1.1 joerg raw_ostream &Indent(int Delta = 0) { 139 1.1 joerg for (int i = 0, e = IndentLevel+Delta; i < e; ++i) 140 1.1 joerg OS << " "; 141 1.1 joerg return OS; 142 1.1 joerg } 143 1.1 joerg 144 1.1 joerg void Visit(Stmt* S) { 145 1.1 joerg if (Helper && Helper->handledStmt(S,OS)) 146 1.1 joerg return; 147 1.1 joerg else StmtVisitor<StmtPrinter>::Visit(S); 148 1.1 joerg } 149 1.1 joerg 150 1.1 joerg void VisitStmt(Stmt *Node) LLVM_ATTRIBUTE_UNUSED { 151 1.1 joerg Indent() << "<<unknown stmt type>>" << NL; 152 1.1 joerg } 153 1.1 joerg 154 1.1 joerg void VisitExpr(Expr *Node) LLVM_ATTRIBUTE_UNUSED { 155 1.1 joerg OS << "<<unknown expr type>>"; 156 1.1 joerg } 157 1.1 joerg 158 1.1 joerg void VisitCXXNamedCastExpr(CXXNamedCastExpr *Node); 159 1.1 joerg 160 1.1 joerg #define ABSTRACT_STMT(CLASS) 161 1.1 joerg #define STMT(CLASS, PARENT) \ 162 1.1 joerg void Visit##CLASS(CLASS *Node); 163 1.1 joerg #include "clang/AST/StmtNodes.inc" 164 1.1 joerg }; 165 1.1 joerg 166 1.1 joerg } // namespace 167 1.1 joerg 168 1.1 joerg //===----------------------------------------------------------------------===// 169 1.1 joerg // Stmt printing methods. 170 1.1 joerg //===----------------------------------------------------------------------===// 171 1.1 joerg 172 1.1 joerg /// PrintRawCompoundStmt - Print a compound stmt without indenting the {, and 173 1.1 joerg /// with no newline after the }. 174 1.1 joerg void StmtPrinter::PrintRawCompoundStmt(CompoundStmt *Node) { 175 1.1 joerg OS << "{" << NL; 176 1.1 joerg for (auto *I : Node->body()) 177 1.1 joerg PrintStmt(I); 178 1.1 joerg 179 1.1 joerg Indent() << "}"; 180 1.1 joerg } 181 1.1 joerg 182 1.1 joerg void StmtPrinter::PrintRawDecl(Decl *D) { 183 1.1 joerg D->print(OS, Policy, IndentLevel); 184 1.1 joerg } 185 1.1 joerg 186 1.1 joerg void StmtPrinter::PrintRawDeclStmt(const DeclStmt *S) { 187 1.1 joerg SmallVector<Decl *, 2> Decls(S->decls()); 188 1.1 joerg Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel); 189 1.1 joerg } 190 1.1 joerg 191 1.1 joerg void StmtPrinter::VisitNullStmt(NullStmt *Node) { 192 1.1 joerg Indent() << ";" << NL; 193 1.1 joerg } 194 1.1 joerg 195 1.1 joerg void StmtPrinter::VisitDeclStmt(DeclStmt *Node) { 196 1.1 joerg Indent(); 197 1.1 joerg PrintRawDeclStmt(Node); 198 1.1 joerg OS << ";" << NL; 199 1.1 joerg } 200 1.1 joerg 201 1.1 joerg void StmtPrinter::VisitCompoundStmt(CompoundStmt *Node) { 202 1.1 joerg Indent(); 203 1.1 joerg PrintRawCompoundStmt(Node); 204 1.1 joerg OS << "" << NL; 205 1.1 joerg } 206 1.1 joerg 207 1.1 joerg void StmtPrinter::VisitCaseStmt(CaseStmt *Node) { 208 1.1 joerg Indent(-1) << "case "; 209 1.1 joerg PrintExpr(Node->getLHS()); 210 1.1 joerg if (Node->getRHS()) { 211 1.1 joerg OS << " ... "; 212 1.1 joerg PrintExpr(Node->getRHS()); 213 1.1 joerg } 214 1.1 joerg OS << ":" << NL; 215 1.1 joerg 216 1.1 joerg PrintStmt(Node->getSubStmt(), 0); 217 1.1 joerg } 218 1.1 joerg 219 1.1 joerg void StmtPrinter::VisitDefaultStmt(DefaultStmt *Node) { 220 1.1 joerg Indent(-1) << "default:" << NL; 221 1.1 joerg PrintStmt(Node->getSubStmt(), 0); 222 1.1 joerg } 223 1.1 joerg 224 1.1 joerg void StmtPrinter::VisitLabelStmt(LabelStmt *Node) { 225 1.1 joerg Indent(-1) << Node->getName() << ":" << NL; 226 1.1 joerg PrintStmt(Node->getSubStmt(), 0); 227 1.1 joerg } 228 1.1 joerg 229 1.1 joerg void StmtPrinter::VisitAttributedStmt(AttributedStmt *Node) { 230 1.1 joerg for (const auto *Attr : Node->getAttrs()) { 231 1.1 joerg Attr->printPretty(OS, Policy); 232 1.1 joerg } 233 1.1 joerg 234 1.1 joerg PrintStmt(Node->getSubStmt(), 0); 235 1.1 joerg } 236 1.1 joerg 237 1.1 joerg void StmtPrinter::PrintRawIfStmt(IfStmt *If) { 238 1.1 joerg OS << "if ("; 239 1.1 joerg if (If->getInit()) 240 1.1 joerg PrintInitStmt(If->getInit(), 4); 241 1.1 joerg if (const DeclStmt *DS = If->getConditionVariableDeclStmt()) 242 1.1 joerg PrintRawDeclStmt(DS); 243 1.1 joerg else 244 1.1 joerg PrintExpr(If->getCond()); 245 1.1 joerg OS << ')'; 246 1.1 joerg 247 1.1 joerg if (auto *CS = dyn_cast<CompoundStmt>(If->getThen())) { 248 1.1 joerg OS << ' '; 249 1.1 joerg PrintRawCompoundStmt(CS); 250 1.1 joerg OS << (If->getElse() ? " " : NL); 251 1.1 joerg } else { 252 1.1 joerg OS << NL; 253 1.1 joerg PrintStmt(If->getThen()); 254 1.1 joerg if (If->getElse()) Indent(); 255 1.1 joerg } 256 1.1 joerg 257 1.1 joerg if (Stmt *Else = If->getElse()) { 258 1.1 joerg OS << "else"; 259 1.1 joerg 260 1.1 joerg if (auto *CS = dyn_cast<CompoundStmt>(Else)) { 261 1.1 joerg OS << ' '; 262 1.1 joerg PrintRawCompoundStmt(CS); 263 1.1 joerg OS << NL; 264 1.1 joerg } else if (auto *ElseIf = dyn_cast<IfStmt>(Else)) { 265 1.1 joerg OS << ' '; 266 1.1 joerg PrintRawIfStmt(ElseIf); 267 1.1 joerg } else { 268 1.1 joerg OS << NL; 269 1.1 joerg PrintStmt(If->getElse()); 270 1.1 joerg } 271 1.1 joerg } 272 1.1 joerg } 273 1.1 joerg 274 1.1 joerg void StmtPrinter::VisitIfStmt(IfStmt *If) { 275 1.1 joerg Indent(); 276 1.1 joerg PrintRawIfStmt(If); 277 1.1 joerg } 278 1.1 joerg 279 1.1 joerg void StmtPrinter::VisitSwitchStmt(SwitchStmt *Node) { 280 1.1 joerg Indent() << "switch ("; 281 1.1 joerg if (Node->getInit()) 282 1.1 joerg PrintInitStmt(Node->getInit(), 8); 283 1.1 joerg if (const DeclStmt *DS = Node->getConditionVariableDeclStmt()) 284 1.1 joerg PrintRawDeclStmt(DS); 285 1.1 joerg else 286 1.1 joerg PrintExpr(Node->getCond()); 287 1.1 joerg OS << ")"; 288 1.1 joerg PrintControlledStmt(Node->getBody()); 289 1.1 joerg } 290 1.1 joerg 291 1.1 joerg void StmtPrinter::VisitWhileStmt(WhileStmt *Node) { 292 1.1 joerg Indent() << "while ("; 293 1.1 joerg if (const DeclStmt *DS = Node->getConditionVariableDeclStmt()) 294 1.1 joerg PrintRawDeclStmt(DS); 295 1.1 joerg else 296 1.1 joerg PrintExpr(Node->getCond()); 297 1.1 joerg OS << ")" << NL; 298 1.1 joerg PrintStmt(Node->getBody()); 299 1.1 joerg } 300 1.1 joerg 301 1.1 joerg void StmtPrinter::VisitDoStmt(DoStmt *Node) { 302 1.1 joerg Indent() << "do "; 303 1.1 joerg if (auto *CS = dyn_cast<CompoundStmt>(Node->getBody())) { 304 1.1 joerg PrintRawCompoundStmt(CS); 305 1.1 joerg OS << " "; 306 1.1 joerg } else { 307 1.1 joerg OS << NL; 308 1.1 joerg PrintStmt(Node->getBody()); 309 1.1 joerg Indent(); 310 1.1 joerg } 311 1.1 joerg 312 1.1 joerg OS << "while ("; 313 1.1 joerg PrintExpr(Node->getCond()); 314 1.1 joerg OS << ");" << NL; 315 1.1 joerg } 316 1.1 joerg 317 1.1 joerg void StmtPrinter::VisitForStmt(ForStmt *Node) { 318 1.1 joerg Indent() << "for ("; 319 1.1 joerg if (Node->getInit()) 320 1.1 joerg PrintInitStmt(Node->getInit(), 5); 321 1.1 joerg else 322 1.1 joerg OS << (Node->getCond() ? "; " : ";"); 323 1.1 joerg if (Node->getCond()) 324 1.1 joerg PrintExpr(Node->getCond()); 325 1.1 joerg OS << ";"; 326 1.1 joerg if (Node->getInc()) { 327 1.1 joerg OS << " "; 328 1.1 joerg PrintExpr(Node->getInc()); 329 1.1 joerg } 330 1.1 joerg OS << ")"; 331 1.1 joerg PrintControlledStmt(Node->getBody()); 332 1.1 joerg } 333 1.1 joerg 334 1.1 joerg void StmtPrinter::VisitObjCForCollectionStmt(ObjCForCollectionStmt *Node) { 335 1.1 joerg Indent() << "for ("; 336 1.1 joerg if (auto *DS = dyn_cast<DeclStmt>(Node->getElement())) 337 1.1 joerg PrintRawDeclStmt(DS); 338 1.1 joerg else 339 1.1 joerg PrintExpr(cast<Expr>(Node->getElement())); 340 1.1 joerg OS << " in "; 341 1.1 joerg PrintExpr(Node->getCollection()); 342 1.1 joerg OS << ")"; 343 1.1 joerg PrintControlledStmt(Node->getBody()); 344 1.1 joerg } 345 1.1 joerg 346 1.1 joerg void StmtPrinter::VisitCXXForRangeStmt(CXXForRangeStmt *Node) { 347 1.1 joerg Indent() << "for ("; 348 1.1 joerg if (Node->getInit()) 349 1.1 joerg PrintInitStmt(Node->getInit(), 5); 350 1.1 joerg PrintingPolicy SubPolicy(Policy); 351 1.1 joerg SubPolicy.SuppressInitializers = true; 352 1.1 joerg Node->getLoopVariable()->print(OS, SubPolicy, IndentLevel); 353 1.1 joerg OS << " : "; 354 1.1 joerg PrintExpr(Node->getRangeInit()); 355 1.1 joerg OS << ")"; 356 1.1 joerg PrintControlledStmt(Node->getBody()); 357 1.1 joerg } 358 1.1 joerg 359 1.1 joerg void StmtPrinter::VisitMSDependentExistsStmt(MSDependentExistsStmt *Node) { 360 1.1 joerg Indent(); 361 1.1 joerg if (Node->isIfExists()) 362 1.1 joerg OS << "__if_exists ("; 363 1.1 joerg else 364 1.1 joerg OS << "__if_not_exists ("; 365 1.1 joerg 366 1.1 joerg if (NestedNameSpecifier *Qualifier 367 1.1 joerg = Node->getQualifierLoc().getNestedNameSpecifier()) 368 1.1 joerg Qualifier->print(OS, Policy); 369 1.1 joerg 370 1.1 joerg OS << Node->getNameInfo() << ") "; 371 1.1 joerg 372 1.1 joerg PrintRawCompoundStmt(Node->getSubStmt()); 373 1.1 joerg } 374 1.1 joerg 375 1.1 joerg void StmtPrinter::VisitGotoStmt(GotoStmt *Node) { 376 1.1 joerg Indent() << "goto " << Node->getLabel()->getName() << ";"; 377 1.1 joerg if (Policy.IncludeNewlines) OS << NL; 378 1.1 joerg } 379 1.1 joerg 380 1.1 joerg void StmtPrinter::VisitIndirectGotoStmt(IndirectGotoStmt *Node) { 381 1.1 joerg Indent() << "goto *"; 382 1.1 joerg PrintExpr(Node->getTarget()); 383 1.1 joerg OS << ";"; 384 1.1 joerg if (Policy.IncludeNewlines) OS << NL; 385 1.1 joerg } 386 1.1 joerg 387 1.1 joerg void StmtPrinter::VisitContinueStmt(ContinueStmt *Node) { 388 1.1 joerg Indent() << "continue;"; 389 1.1 joerg if (Policy.IncludeNewlines) OS << NL; 390 1.1 joerg } 391 1.1 joerg 392 1.1 joerg void StmtPrinter::VisitBreakStmt(BreakStmt *Node) { 393 1.1 joerg Indent() << "break;"; 394 1.1 joerg if (Policy.IncludeNewlines) OS << NL; 395 1.1 joerg } 396 1.1 joerg 397 1.1 joerg void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) { 398 1.1 joerg Indent() << "return"; 399 1.1 joerg if (Node->getRetValue()) { 400 1.1 joerg OS << " "; 401 1.1 joerg PrintExpr(Node->getRetValue()); 402 1.1 joerg } 403 1.1 joerg OS << ";"; 404 1.1 joerg if (Policy.IncludeNewlines) OS << NL; 405 1.1 joerg } 406 1.1 joerg 407 1.1 joerg void StmtPrinter::VisitGCCAsmStmt(GCCAsmStmt *Node) { 408 1.1 joerg Indent() << "asm "; 409 1.1 joerg 410 1.1 joerg if (Node->isVolatile()) 411 1.1 joerg OS << "volatile "; 412 1.1 joerg 413 1.1 joerg if (Node->isAsmGoto()) 414 1.1 joerg OS << "goto "; 415 1.1 joerg 416 1.1 joerg OS << "("; 417 1.1 joerg VisitStringLiteral(Node->getAsmString()); 418 1.1 joerg 419 1.1 joerg // Outputs 420 1.1 joerg if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 || 421 1.1 joerg Node->getNumClobbers() != 0 || Node->getNumLabels() != 0) 422 1.1 joerg OS << " : "; 423 1.1 joerg 424 1.1 joerg for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) { 425 1.1 joerg if (i != 0) 426 1.1 joerg OS << ", "; 427 1.1 joerg 428 1.1 joerg if (!Node->getOutputName(i).empty()) { 429 1.1 joerg OS << '['; 430 1.1 joerg OS << Node->getOutputName(i); 431 1.1 joerg OS << "] "; 432 1.1 joerg } 433 1.1 joerg 434 1.1 joerg VisitStringLiteral(Node->getOutputConstraintLiteral(i)); 435 1.1 joerg OS << " ("; 436 1.1 joerg Visit(Node->getOutputExpr(i)); 437 1.1 joerg OS << ")"; 438 1.1 joerg } 439 1.1 joerg 440 1.1 joerg // Inputs 441 1.1 joerg if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0 || 442 1.1 joerg Node->getNumLabels() != 0) 443 1.1 joerg OS << " : "; 444 1.1 joerg 445 1.1 joerg for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) { 446 1.1 joerg if (i != 0) 447 1.1 joerg OS << ", "; 448 1.1 joerg 449 1.1 joerg if (!Node->getInputName(i).empty()) { 450 1.1 joerg OS << '['; 451 1.1 joerg OS << Node->getInputName(i); 452 1.1 joerg OS << "] "; 453 1.1 joerg } 454 1.1 joerg 455 1.1 joerg VisitStringLiteral(Node->getInputConstraintLiteral(i)); 456 1.1 joerg OS << " ("; 457 1.1 joerg Visit(Node->getInputExpr(i)); 458 1.1 joerg OS << ")"; 459 1.1 joerg } 460 1.1 joerg 461 1.1 joerg // Clobbers 462 1.1 joerg if (Node->getNumClobbers() != 0 || Node->getNumLabels()) 463 1.1 joerg OS << " : "; 464 1.1 joerg 465 1.1 joerg for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) { 466 1.1 joerg if (i != 0) 467 1.1 joerg OS << ", "; 468 1.1 joerg 469 1.1 joerg VisitStringLiteral(Node->getClobberStringLiteral(i)); 470 1.1 joerg } 471 1.1 joerg 472 1.1 joerg // Labels 473 1.1 joerg if (Node->getNumLabels() != 0) 474 1.1 joerg OS << " : "; 475 1.1 joerg 476 1.1 joerg for (unsigned i = 0, e = Node->getNumLabels(); i != e; ++i) { 477 1.1 joerg if (i != 0) 478 1.1 joerg OS << ", "; 479 1.1 joerg OS << Node->getLabelName(i); 480 1.1 joerg } 481 1.1 joerg 482 1.1 joerg OS << ");"; 483 1.1 joerg if (Policy.IncludeNewlines) OS << NL; 484 1.1 joerg } 485 1.1 joerg 486 1.1 joerg void StmtPrinter::VisitMSAsmStmt(MSAsmStmt *Node) { 487 1.1 joerg // FIXME: Implement MS style inline asm statement printer. 488 1.1 joerg Indent() << "__asm "; 489 1.1 joerg if (Node->hasBraces()) 490 1.1 joerg OS << "{" << NL; 491 1.1 joerg OS << Node->getAsmString() << NL; 492 1.1 joerg if (Node->hasBraces()) 493 1.1 joerg Indent() << "}" << NL; 494 1.1 joerg } 495 1.1 joerg 496 1.1 joerg void StmtPrinter::VisitCapturedStmt(CapturedStmt *Node) { 497 1.1 joerg PrintStmt(Node->getCapturedDecl()->getBody()); 498 1.1 joerg } 499 1.1 joerg 500 1.1 joerg void StmtPrinter::VisitObjCAtTryStmt(ObjCAtTryStmt *Node) { 501 1.1 joerg Indent() << "@try"; 502 1.1 joerg if (auto *TS = dyn_cast<CompoundStmt>(Node->getTryBody())) { 503 1.1 joerg PrintRawCompoundStmt(TS); 504 1.1 joerg OS << NL; 505 1.1 joerg } 506 1.1 joerg 507 1.1 joerg for (unsigned I = 0, N = Node->getNumCatchStmts(); I != N; ++I) { 508 1.1 joerg ObjCAtCatchStmt *catchStmt = Node->getCatchStmt(I); 509 1.1 joerg Indent() << "@catch("; 510 1.1 joerg if (catchStmt->getCatchParamDecl()) { 511 1.1 joerg if (Decl *DS = catchStmt->getCatchParamDecl()) 512 1.1 joerg PrintRawDecl(DS); 513 1.1 joerg } 514 1.1 joerg OS << ")"; 515 1.1 joerg if (auto *CS = dyn_cast<CompoundStmt>(catchStmt->getCatchBody())) { 516 1.1 joerg PrintRawCompoundStmt(CS); 517 1.1 joerg OS << NL; 518 1.1 joerg } 519 1.1 joerg } 520 1.1 joerg 521 1.1 joerg if (auto *FS = static_cast<ObjCAtFinallyStmt *>(Node->getFinallyStmt())) { 522 1.1 joerg Indent() << "@finally"; 523 1.1 joerg PrintRawCompoundStmt(dyn_cast<CompoundStmt>(FS->getFinallyBody())); 524 1.1 joerg OS << NL; 525 1.1 joerg } 526 1.1 joerg } 527 1.1 joerg 528 1.1 joerg void StmtPrinter::VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Node) { 529 1.1 joerg } 530 1.1 joerg 531 1.1 joerg void StmtPrinter::VisitObjCAtCatchStmt (ObjCAtCatchStmt *Node) { 532 1.1 joerg Indent() << "@catch (...) { /* todo */ } " << NL; 533 1.1 joerg } 534 1.1 joerg 535 1.1 joerg void StmtPrinter::VisitObjCAtThrowStmt(ObjCAtThrowStmt *Node) { 536 1.1 joerg Indent() << "@throw"; 537 1.1 joerg if (Node->getThrowExpr()) { 538 1.1 joerg OS << " "; 539 1.1 joerg PrintExpr(Node->getThrowExpr()); 540 1.1 joerg } 541 1.1 joerg OS << ";" << NL; 542 1.1 joerg } 543 1.1 joerg 544 1.1 joerg void StmtPrinter::VisitObjCAvailabilityCheckExpr( 545 1.1 joerg ObjCAvailabilityCheckExpr *Node) { 546 1.1 joerg OS << "@available(...)"; 547 1.1 joerg } 548 1.1 joerg 549 1.1 joerg void StmtPrinter::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Node) { 550 1.1 joerg Indent() << "@synchronized ("; 551 1.1 joerg PrintExpr(Node->getSynchExpr()); 552 1.1 joerg OS << ")"; 553 1.1 joerg PrintRawCompoundStmt(Node->getSynchBody()); 554 1.1 joerg OS << NL; 555 1.1 joerg } 556 1.1 joerg 557 1.1 joerg void StmtPrinter::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *Node) { 558 1.1 joerg Indent() << "@autoreleasepool"; 559 1.1 joerg PrintRawCompoundStmt(dyn_cast<CompoundStmt>(Node->getSubStmt())); 560 1.1 joerg OS << NL; 561 1.1 joerg } 562 1.1 joerg 563 1.1 joerg void StmtPrinter::PrintRawCXXCatchStmt(CXXCatchStmt *Node) { 564 1.1 joerg OS << "catch ("; 565 1.1 joerg if (Decl *ExDecl = Node->getExceptionDecl()) 566 1.1 joerg PrintRawDecl(ExDecl); 567 1.1 joerg else 568 1.1 joerg OS << "..."; 569 1.1 joerg OS << ") "; 570 1.1 joerg PrintRawCompoundStmt(cast<CompoundStmt>(Node->getHandlerBlock())); 571 1.1 joerg } 572 1.1 joerg 573 1.1 joerg void StmtPrinter::VisitCXXCatchStmt(CXXCatchStmt *Node) { 574 1.1 joerg Indent(); 575 1.1 joerg PrintRawCXXCatchStmt(Node); 576 1.1 joerg OS << NL; 577 1.1 joerg } 578 1.1 joerg 579 1.1 joerg void StmtPrinter::VisitCXXTryStmt(CXXTryStmt *Node) { 580 1.1 joerg Indent() << "try "; 581 1.1 joerg PrintRawCompoundStmt(Node->getTryBlock()); 582 1.1 joerg for (unsigned i = 0, e = Node->getNumHandlers(); i < e; ++i) { 583 1.1 joerg OS << " "; 584 1.1 joerg PrintRawCXXCatchStmt(Node->getHandler(i)); 585 1.1 joerg } 586 1.1 joerg OS << NL; 587 1.1 joerg } 588 1.1 joerg 589 1.1 joerg void StmtPrinter::VisitSEHTryStmt(SEHTryStmt *Node) { 590 1.1 joerg Indent() << (Node->getIsCXXTry() ? "try " : "__try "); 591 1.1 joerg PrintRawCompoundStmt(Node->getTryBlock()); 592 1.1 joerg SEHExceptStmt *E = Node->getExceptHandler(); 593 1.1 joerg SEHFinallyStmt *F = Node->getFinallyHandler(); 594 1.1 joerg if(E) 595 1.1 joerg PrintRawSEHExceptHandler(E); 596 1.1 joerg else { 597 1.1 joerg assert(F && "Must have a finally block..."); 598 1.1 joerg PrintRawSEHFinallyStmt(F); 599 1.1 joerg } 600 1.1 joerg OS << NL; 601 1.1 joerg } 602 1.1 joerg 603 1.1 joerg void StmtPrinter::PrintRawSEHFinallyStmt(SEHFinallyStmt *Node) { 604 1.1 joerg OS << "__finally "; 605 1.1 joerg PrintRawCompoundStmt(Node->getBlock()); 606 1.1 joerg OS << NL; 607 1.1 joerg } 608 1.1 joerg 609 1.1 joerg void StmtPrinter::PrintRawSEHExceptHandler(SEHExceptStmt *Node) { 610 1.1 joerg OS << "__except ("; 611 1.1 joerg VisitExpr(Node->getFilterExpr()); 612 1.1 joerg OS << ")" << NL; 613 1.1 joerg PrintRawCompoundStmt(Node->getBlock()); 614 1.1 joerg OS << NL; 615 1.1 joerg } 616 1.1 joerg 617 1.1 joerg void StmtPrinter::VisitSEHExceptStmt(SEHExceptStmt *Node) { 618 1.1 joerg Indent(); 619 1.1 joerg PrintRawSEHExceptHandler(Node); 620 1.1 joerg OS << NL; 621 1.1 joerg } 622 1.1 joerg 623 1.1 joerg void StmtPrinter::VisitSEHFinallyStmt(SEHFinallyStmt *Node) { 624 1.1 joerg Indent(); 625 1.1 joerg PrintRawSEHFinallyStmt(Node); 626 1.1 joerg OS << NL; 627 1.1 joerg } 628 1.1 joerg 629 1.1 joerg void StmtPrinter::VisitSEHLeaveStmt(SEHLeaveStmt *Node) { 630 1.1 joerg Indent() << "__leave;"; 631 1.1 joerg if (Policy.IncludeNewlines) OS << NL; 632 1.1 joerg } 633 1.1 joerg 634 1.1 joerg //===----------------------------------------------------------------------===// 635 1.1 joerg // OpenMP directives printing methods 636 1.1 joerg //===----------------------------------------------------------------------===// 637 1.1 joerg 638 1.1.1.2 joerg void StmtPrinter::VisitOMPCanonicalLoop(OMPCanonicalLoop *Node) { 639 1.1.1.2 joerg PrintStmt(Node->getLoopStmt()); 640 1.1.1.2 joerg } 641 1.1.1.2 joerg 642 1.1 joerg void StmtPrinter::PrintOMPExecutableDirective(OMPExecutableDirective *S, 643 1.1 joerg bool ForceNoStmt) { 644 1.1 joerg OMPClausePrinter Printer(OS, Policy); 645 1.1 joerg ArrayRef<OMPClause *> Clauses = S->clauses(); 646 1.1 joerg for (auto *Clause : Clauses) 647 1.1 joerg if (Clause && !Clause->isImplicit()) { 648 1.1 joerg OS << ' '; 649 1.1 joerg Printer.Visit(Clause); 650 1.1 joerg } 651 1.1 joerg OS << NL; 652 1.1 joerg if (!ForceNoStmt && S->hasAssociatedStmt()) 653 1.1.1.2 joerg PrintStmt(S->getRawStmt()); 654 1.1 joerg } 655 1.1 joerg 656 1.1 joerg void StmtPrinter::VisitOMPParallelDirective(OMPParallelDirective *Node) { 657 1.1 joerg Indent() << "#pragma omp parallel"; 658 1.1 joerg PrintOMPExecutableDirective(Node); 659 1.1 joerg } 660 1.1 joerg 661 1.1 joerg void StmtPrinter::VisitOMPSimdDirective(OMPSimdDirective *Node) { 662 1.1 joerg Indent() << "#pragma omp simd"; 663 1.1 joerg PrintOMPExecutableDirective(Node); 664 1.1 joerg } 665 1.1 joerg 666 1.1.1.2 joerg void StmtPrinter::VisitOMPTileDirective(OMPTileDirective *Node) { 667 1.1.1.2 joerg Indent() << "#pragma omp tile"; 668 1.1.1.2 joerg PrintOMPExecutableDirective(Node); 669 1.1.1.2 joerg } 670 1.1.1.2 joerg 671 1.1 joerg void StmtPrinter::VisitOMPForDirective(OMPForDirective *Node) { 672 1.1 joerg Indent() << "#pragma omp for"; 673 1.1 joerg PrintOMPExecutableDirective(Node); 674 1.1 joerg } 675 1.1 joerg 676 1.1 joerg void StmtPrinter::VisitOMPForSimdDirective(OMPForSimdDirective *Node) { 677 1.1 joerg Indent() << "#pragma omp for simd"; 678 1.1 joerg PrintOMPExecutableDirective(Node); 679 1.1 joerg } 680 1.1 joerg 681 1.1 joerg void StmtPrinter::VisitOMPSectionsDirective(OMPSectionsDirective *Node) { 682 1.1 joerg Indent() << "#pragma omp sections"; 683 1.1 joerg PrintOMPExecutableDirective(Node); 684 1.1 joerg } 685 1.1 joerg 686 1.1 joerg void StmtPrinter::VisitOMPSectionDirective(OMPSectionDirective *Node) { 687 1.1 joerg Indent() << "#pragma omp section"; 688 1.1 joerg PrintOMPExecutableDirective(Node); 689 1.1 joerg } 690 1.1 joerg 691 1.1 joerg void StmtPrinter::VisitOMPSingleDirective(OMPSingleDirective *Node) { 692 1.1 joerg Indent() << "#pragma omp single"; 693 1.1 joerg PrintOMPExecutableDirective(Node); 694 1.1 joerg } 695 1.1 joerg 696 1.1 joerg void StmtPrinter::VisitOMPMasterDirective(OMPMasterDirective *Node) { 697 1.1 joerg Indent() << "#pragma omp master"; 698 1.1 joerg PrintOMPExecutableDirective(Node); 699 1.1 joerg } 700 1.1 joerg 701 1.1 joerg void StmtPrinter::VisitOMPCriticalDirective(OMPCriticalDirective *Node) { 702 1.1 joerg Indent() << "#pragma omp critical"; 703 1.1 joerg if (Node->getDirectiveName().getName()) { 704 1.1 joerg OS << " ("; 705 1.1.1.2 joerg Node->getDirectiveName().printName(OS, Policy); 706 1.1 joerg OS << ")"; 707 1.1 joerg } 708 1.1 joerg PrintOMPExecutableDirective(Node); 709 1.1 joerg } 710 1.1 joerg 711 1.1 joerg void StmtPrinter::VisitOMPParallelForDirective(OMPParallelForDirective *Node) { 712 1.1 joerg Indent() << "#pragma omp parallel for"; 713 1.1 joerg PrintOMPExecutableDirective(Node); 714 1.1 joerg } 715 1.1 joerg 716 1.1 joerg void StmtPrinter::VisitOMPParallelForSimdDirective( 717 1.1 joerg OMPParallelForSimdDirective *Node) { 718 1.1 joerg Indent() << "#pragma omp parallel for simd"; 719 1.1 joerg PrintOMPExecutableDirective(Node); 720 1.1 joerg } 721 1.1 joerg 722 1.1.1.2 joerg void StmtPrinter::VisitOMPParallelMasterDirective( 723 1.1.1.2 joerg OMPParallelMasterDirective *Node) { 724 1.1.1.2 joerg Indent() << "#pragma omp parallel master"; 725 1.1.1.2 joerg PrintOMPExecutableDirective(Node); 726 1.1.1.2 joerg } 727 1.1.1.2 joerg 728 1.1 joerg void StmtPrinter::VisitOMPParallelSectionsDirective( 729 1.1 joerg OMPParallelSectionsDirective *Node) { 730 1.1 joerg Indent() << "#pragma omp parallel sections"; 731 1.1 joerg PrintOMPExecutableDirective(Node); 732 1.1 joerg } 733 1.1 joerg 734 1.1 joerg void StmtPrinter::VisitOMPTaskDirective(OMPTaskDirective *Node) { 735 1.1 joerg Indent() << "#pragma omp task"; 736 1.1 joerg PrintOMPExecutableDirective(Node); 737 1.1 joerg } 738 1.1 joerg 739 1.1 joerg void StmtPrinter::VisitOMPTaskyieldDirective(OMPTaskyieldDirective *Node) { 740 1.1 joerg Indent() << "#pragma omp taskyield"; 741 1.1 joerg PrintOMPExecutableDirective(Node); 742 1.1 joerg } 743 1.1 joerg 744 1.1 joerg void StmtPrinter::VisitOMPBarrierDirective(OMPBarrierDirective *Node) { 745 1.1 joerg Indent() << "#pragma omp barrier"; 746 1.1 joerg PrintOMPExecutableDirective(Node); 747 1.1 joerg } 748 1.1 joerg 749 1.1 joerg void StmtPrinter::VisitOMPTaskwaitDirective(OMPTaskwaitDirective *Node) { 750 1.1 joerg Indent() << "#pragma omp taskwait"; 751 1.1 joerg PrintOMPExecutableDirective(Node); 752 1.1 joerg } 753 1.1 joerg 754 1.1 joerg void StmtPrinter::VisitOMPTaskgroupDirective(OMPTaskgroupDirective *Node) { 755 1.1 joerg Indent() << "#pragma omp taskgroup"; 756 1.1 joerg PrintOMPExecutableDirective(Node); 757 1.1 joerg } 758 1.1 joerg 759 1.1 joerg void StmtPrinter::VisitOMPFlushDirective(OMPFlushDirective *Node) { 760 1.1 joerg Indent() << "#pragma omp flush"; 761 1.1 joerg PrintOMPExecutableDirective(Node); 762 1.1 joerg } 763 1.1 joerg 764 1.1.1.2 joerg void StmtPrinter::VisitOMPDepobjDirective(OMPDepobjDirective *Node) { 765 1.1.1.2 joerg Indent() << "#pragma omp depobj"; 766 1.1.1.2 joerg PrintOMPExecutableDirective(Node); 767 1.1.1.2 joerg } 768 1.1.1.2 joerg 769 1.1.1.2 joerg void StmtPrinter::VisitOMPScanDirective(OMPScanDirective *Node) { 770 1.1.1.2 joerg Indent() << "#pragma omp scan"; 771 1.1.1.2 joerg PrintOMPExecutableDirective(Node); 772 1.1.1.2 joerg } 773 1.1.1.2 joerg 774 1.1 joerg void StmtPrinter::VisitOMPOrderedDirective(OMPOrderedDirective *Node) { 775 1.1 joerg Indent() << "#pragma omp ordered"; 776 1.1 joerg PrintOMPExecutableDirective(Node, Node->hasClausesOfKind<OMPDependClause>()); 777 1.1 joerg } 778 1.1 joerg 779 1.1 joerg void StmtPrinter::VisitOMPAtomicDirective(OMPAtomicDirective *Node) { 780 1.1 joerg Indent() << "#pragma omp atomic"; 781 1.1 joerg PrintOMPExecutableDirective(Node); 782 1.1 joerg } 783 1.1 joerg 784 1.1 joerg void StmtPrinter::VisitOMPTargetDirective(OMPTargetDirective *Node) { 785 1.1 joerg Indent() << "#pragma omp target"; 786 1.1 joerg PrintOMPExecutableDirective(Node); 787 1.1 joerg } 788 1.1 joerg 789 1.1 joerg void StmtPrinter::VisitOMPTargetDataDirective(OMPTargetDataDirective *Node) { 790 1.1 joerg Indent() << "#pragma omp target data"; 791 1.1 joerg PrintOMPExecutableDirective(Node); 792 1.1 joerg } 793 1.1 joerg 794 1.1 joerg void StmtPrinter::VisitOMPTargetEnterDataDirective( 795 1.1 joerg OMPTargetEnterDataDirective *Node) { 796 1.1 joerg Indent() << "#pragma omp target enter data"; 797 1.1 joerg PrintOMPExecutableDirective(Node, /*ForceNoStmt=*/true); 798 1.1 joerg } 799 1.1 joerg 800 1.1 joerg void StmtPrinter::VisitOMPTargetExitDataDirective( 801 1.1 joerg OMPTargetExitDataDirective *Node) { 802 1.1 joerg Indent() << "#pragma omp target exit data"; 803 1.1 joerg PrintOMPExecutableDirective(Node, /*ForceNoStmt=*/true); 804 1.1 joerg } 805 1.1 joerg 806 1.1 joerg void StmtPrinter::VisitOMPTargetParallelDirective( 807 1.1 joerg OMPTargetParallelDirective *Node) { 808 1.1 joerg Indent() << "#pragma omp target parallel"; 809 1.1 joerg PrintOMPExecutableDirective(Node); 810 1.1 joerg } 811 1.1 joerg 812 1.1 joerg void StmtPrinter::VisitOMPTargetParallelForDirective( 813 1.1 joerg OMPTargetParallelForDirective *Node) { 814 1.1 joerg Indent() << "#pragma omp target parallel for"; 815 1.1 joerg PrintOMPExecutableDirective(Node); 816 1.1 joerg } 817 1.1 joerg 818 1.1 joerg void StmtPrinter::VisitOMPTeamsDirective(OMPTeamsDirective *Node) { 819 1.1 joerg Indent() << "#pragma omp teams"; 820 1.1 joerg PrintOMPExecutableDirective(Node); 821 1.1 joerg } 822 1.1 joerg 823 1.1 joerg void StmtPrinter::VisitOMPCancellationPointDirective( 824 1.1 joerg OMPCancellationPointDirective *Node) { 825 1.1 joerg Indent() << "#pragma omp cancellation point " 826 1.1 joerg << getOpenMPDirectiveName(Node->getCancelRegion()); 827 1.1 joerg PrintOMPExecutableDirective(Node); 828 1.1 joerg } 829 1.1 joerg 830 1.1 joerg void StmtPrinter::VisitOMPCancelDirective(OMPCancelDirective *Node) { 831 1.1 joerg Indent() << "#pragma omp cancel " 832 1.1 joerg << getOpenMPDirectiveName(Node->getCancelRegion()); 833 1.1 joerg PrintOMPExecutableDirective(Node); 834 1.1 joerg } 835 1.1 joerg 836 1.1 joerg void StmtPrinter::VisitOMPTaskLoopDirective(OMPTaskLoopDirective *Node) { 837 1.1 joerg Indent() << "#pragma omp taskloop"; 838 1.1 joerg PrintOMPExecutableDirective(Node); 839 1.1 joerg } 840 1.1 joerg 841 1.1 joerg void StmtPrinter::VisitOMPTaskLoopSimdDirective( 842 1.1 joerg OMPTaskLoopSimdDirective *Node) { 843 1.1 joerg Indent() << "#pragma omp taskloop simd"; 844 1.1 joerg PrintOMPExecutableDirective(Node); 845 1.1 joerg } 846 1.1 joerg 847 1.1 joerg void StmtPrinter::VisitOMPMasterTaskLoopDirective( 848 1.1 joerg OMPMasterTaskLoopDirective *Node) { 849 1.1 joerg Indent() << "#pragma omp master taskloop"; 850 1.1 joerg PrintOMPExecutableDirective(Node); 851 1.1 joerg } 852 1.1 joerg 853 1.1 joerg void StmtPrinter::VisitOMPMasterTaskLoopSimdDirective( 854 1.1 joerg OMPMasterTaskLoopSimdDirective *Node) { 855 1.1 joerg Indent() << "#pragma omp master taskloop simd"; 856 1.1 joerg PrintOMPExecutableDirective(Node); 857 1.1 joerg } 858 1.1 joerg 859 1.1 joerg void StmtPrinter::VisitOMPParallelMasterTaskLoopDirective( 860 1.1 joerg OMPParallelMasterTaskLoopDirective *Node) { 861 1.1 joerg Indent() << "#pragma omp parallel master taskloop"; 862 1.1 joerg PrintOMPExecutableDirective(Node); 863 1.1 joerg } 864 1.1 joerg 865 1.1.1.2 joerg void StmtPrinter::VisitOMPParallelMasterTaskLoopSimdDirective( 866 1.1.1.2 joerg OMPParallelMasterTaskLoopSimdDirective *Node) { 867 1.1.1.2 joerg Indent() << "#pragma omp parallel master taskloop simd"; 868 1.1.1.2 joerg PrintOMPExecutableDirective(Node); 869 1.1.1.2 joerg } 870 1.1.1.2 joerg 871 1.1 joerg void StmtPrinter::VisitOMPDistributeDirective(OMPDistributeDirective *Node) { 872 1.1 joerg Indent() << "#pragma omp distribute"; 873 1.1 joerg PrintOMPExecutableDirective(Node); 874 1.1 joerg } 875 1.1 joerg 876 1.1 joerg void StmtPrinter::VisitOMPTargetUpdateDirective( 877 1.1 joerg OMPTargetUpdateDirective *Node) { 878 1.1 joerg Indent() << "#pragma omp target update"; 879 1.1 joerg PrintOMPExecutableDirective(Node, /*ForceNoStmt=*/true); 880 1.1 joerg } 881 1.1 joerg 882 1.1 joerg void StmtPrinter::VisitOMPDistributeParallelForDirective( 883 1.1 joerg OMPDistributeParallelForDirective *Node) { 884 1.1 joerg Indent() << "#pragma omp distribute parallel for"; 885 1.1 joerg PrintOMPExecutableDirective(Node); 886 1.1 joerg } 887 1.1 joerg 888 1.1 joerg void StmtPrinter::VisitOMPDistributeParallelForSimdDirective( 889 1.1 joerg OMPDistributeParallelForSimdDirective *Node) { 890 1.1 joerg Indent() << "#pragma omp distribute parallel for simd"; 891 1.1 joerg PrintOMPExecutableDirective(Node); 892 1.1 joerg } 893 1.1 joerg 894 1.1 joerg void StmtPrinter::VisitOMPDistributeSimdDirective( 895 1.1 joerg OMPDistributeSimdDirective *Node) { 896 1.1 joerg Indent() << "#pragma omp distribute simd"; 897 1.1 joerg PrintOMPExecutableDirective(Node); 898 1.1 joerg } 899 1.1 joerg 900 1.1 joerg void StmtPrinter::VisitOMPTargetParallelForSimdDirective( 901 1.1 joerg OMPTargetParallelForSimdDirective *Node) { 902 1.1 joerg Indent() << "#pragma omp target parallel for simd"; 903 1.1 joerg PrintOMPExecutableDirective(Node); 904 1.1 joerg } 905 1.1 joerg 906 1.1 joerg void StmtPrinter::VisitOMPTargetSimdDirective(OMPTargetSimdDirective *Node) { 907 1.1 joerg Indent() << "#pragma omp target simd"; 908 1.1 joerg PrintOMPExecutableDirective(Node); 909 1.1 joerg } 910 1.1 joerg 911 1.1 joerg void StmtPrinter::VisitOMPTeamsDistributeDirective( 912 1.1 joerg OMPTeamsDistributeDirective *Node) { 913 1.1 joerg Indent() << "#pragma omp teams distribute"; 914 1.1 joerg PrintOMPExecutableDirective(Node); 915 1.1 joerg } 916 1.1 joerg 917 1.1 joerg void StmtPrinter::VisitOMPTeamsDistributeSimdDirective( 918 1.1 joerg OMPTeamsDistributeSimdDirective *Node) { 919 1.1 joerg Indent() << "#pragma omp teams distribute simd"; 920 1.1 joerg PrintOMPExecutableDirective(Node); 921 1.1 joerg } 922 1.1 joerg 923 1.1 joerg void StmtPrinter::VisitOMPTeamsDistributeParallelForSimdDirective( 924 1.1 joerg OMPTeamsDistributeParallelForSimdDirective *Node) { 925 1.1 joerg Indent() << "#pragma omp teams distribute parallel for simd"; 926 1.1 joerg PrintOMPExecutableDirective(Node); 927 1.1 joerg } 928 1.1 joerg 929 1.1 joerg void StmtPrinter::VisitOMPTeamsDistributeParallelForDirective( 930 1.1 joerg OMPTeamsDistributeParallelForDirective *Node) { 931 1.1 joerg Indent() << "#pragma omp teams distribute parallel for"; 932 1.1 joerg PrintOMPExecutableDirective(Node); 933 1.1 joerg } 934 1.1 joerg 935 1.1 joerg void StmtPrinter::VisitOMPTargetTeamsDirective(OMPTargetTeamsDirective *Node) { 936 1.1 joerg Indent() << "#pragma omp target teams"; 937 1.1 joerg PrintOMPExecutableDirective(Node); 938 1.1 joerg } 939 1.1 joerg 940 1.1 joerg void StmtPrinter::VisitOMPTargetTeamsDistributeDirective( 941 1.1 joerg OMPTargetTeamsDistributeDirective *Node) { 942 1.1 joerg Indent() << "#pragma omp target teams distribute"; 943 1.1 joerg PrintOMPExecutableDirective(Node); 944 1.1 joerg } 945 1.1 joerg 946 1.1 joerg void StmtPrinter::VisitOMPTargetTeamsDistributeParallelForDirective( 947 1.1 joerg OMPTargetTeamsDistributeParallelForDirective *Node) { 948 1.1 joerg Indent() << "#pragma omp target teams distribute parallel for"; 949 1.1 joerg PrintOMPExecutableDirective(Node); 950 1.1 joerg } 951 1.1 joerg 952 1.1 joerg void StmtPrinter::VisitOMPTargetTeamsDistributeParallelForSimdDirective( 953 1.1 joerg OMPTargetTeamsDistributeParallelForSimdDirective *Node) { 954 1.1 joerg Indent() << "#pragma omp target teams distribute parallel for simd"; 955 1.1 joerg PrintOMPExecutableDirective(Node); 956 1.1 joerg } 957 1.1 joerg 958 1.1 joerg void StmtPrinter::VisitOMPTargetTeamsDistributeSimdDirective( 959 1.1 joerg OMPTargetTeamsDistributeSimdDirective *Node) { 960 1.1 joerg Indent() << "#pragma omp target teams distribute simd"; 961 1.1 joerg PrintOMPExecutableDirective(Node); 962 1.1 joerg } 963 1.1 joerg 964 1.1.1.2 joerg void StmtPrinter::VisitOMPInteropDirective(OMPInteropDirective *Node) { 965 1.1.1.2 joerg Indent() << "#pragma omp interop"; 966 1.1.1.2 joerg PrintOMPExecutableDirective(Node); 967 1.1.1.2 joerg } 968 1.1.1.2 joerg 969 1.1.1.2 joerg void StmtPrinter::VisitOMPDispatchDirective(OMPDispatchDirective *Node) { 970 1.1.1.2 joerg Indent() << "#pragma omp dispatch"; 971 1.1.1.2 joerg PrintOMPExecutableDirective(Node); 972 1.1.1.2 joerg } 973 1.1.1.2 joerg 974 1.1.1.2 joerg void StmtPrinter::VisitOMPMaskedDirective(OMPMaskedDirective *Node) { 975 1.1.1.2 joerg Indent() << "#pragma omp masked"; 976 1.1.1.2 joerg PrintOMPExecutableDirective(Node); 977 1.1.1.2 joerg } 978 1.1.1.2 joerg 979 1.1 joerg //===----------------------------------------------------------------------===// 980 1.1 joerg // Expr printing methods. 981 1.1 joerg //===----------------------------------------------------------------------===// 982 1.1 joerg 983 1.1 joerg void StmtPrinter::VisitSourceLocExpr(SourceLocExpr *Node) { 984 1.1 joerg OS << Node->getBuiltinStr() << "()"; 985 1.1 joerg } 986 1.1 joerg 987 1.1 joerg void StmtPrinter::VisitConstantExpr(ConstantExpr *Node) { 988 1.1 joerg PrintExpr(Node->getSubExpr()); 989 1.1 joerg } 990 1.1 joerg 991 1.1 joerg void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) { 992 1.1 joerg if (const auto *OCED = dyn_cast<OMPCapturedExprDecl>(Node->getDecl())) { 993 1.1 joerg OCED->getInit()->IgnoreImpCasts()->printPretty(OS, nullptr, Policy); 994 1.1 joerg return; 995 1.1 joerg } 996 1.1.1.2 joerg if (const auto *TPOD = dyn_cast<TemplateParamObjectDecl>(Node->getDecl())) { 997 1.1.1.2 joerg TPOD->printAsExpr(OS); 998 1.1.1.2 joerg return; 999 1.1.1.2 joerg } 1000 1.1 joerg if (NestedNameSpecifier *Qualifier = Node->getQualifier()) 1001 1.1 joerg Qualifier->print(OS, Policy); 1002 1.1 joerg if (Node->hasTemplateKeyword()) 1003 1.1 joerg OS << "template "; 1004 1.1 joerg OS << Node->getNameInfo(); 1005 1.1.1.2 joerg if (Node->hasExplicitTemplateArgs()) { 1006 1.1.1.2 joerg const TemplateParameterList *TPL = nullptr; 1007 1.1.1.2 joerg if (!Node->hadMultipleCandidates()) 1008 1.1.1.2 joerg if (auto *TD = dyn_cast<TemplateDecl>(Node->getDecl())) 1009 1.1.1.2 joerg TPL = TD->getTemplateParameters(); 1010 1.1.1.2 joerg printTemplateArgumentList(OS, Node->template_arguments(), Policy, TPL); 1011 1.1.1.2 joerg } 1012 1.1 joerg } 1013 1.1 joerg 1014 1.1 joerg void StmtPrinter::VisitDependentScopeDeclRefExpr( 1015 1.1 joerg DependentScopeDeclRefExpr *Node) { 1016 1.1 joerg if (NestedNameSpecifier *Qualifier = Node->getQualifier()) 1017 1.1 joerg Qualifier->print(OS, Policy); 1018 1.1 joerg if (Node->hasTemplateKeyword()) 1019 1.1 joerg OS << "template "; 1020 1.1 joerg OS << Node->getNameInfo(); 1021 1.1 joerg if (Node->hasExplicitTemplateArgs()) 1022 1.1 joerg printTemplateArgumentList(OS, Node->template_arguments(), Policy); 1023 1.1 joerg } 1024 1.1 joerg 1025 1.1 joerg void StmtPrinter::VisitUnresolvedLookupExpr(UnresolvedLookupExpr *Node) { 1026 1.1 joerg if (Node->getQualifier()) 1027 1.1 joerg Node->getQualifier()->print(OS, Policy); 1028 1.1 joerg if (Node->hasTemplateKeyword()) 1029 1.1 joerg OS << "template "; 1030 1.1 joerg OS << Node->getNameInfo(); 1031 1.1 joerg if (Node->hasExplicitTemplateArgs()) 1032 1.1 joerg printTemplateArgumentList(OS, Node->template_arguments(), Policy); 1033 1.1 joerg } 1034 1.1 joerg 1035 1.1 joerg static bool isImplicitSelf(const Expr *E) { 1036 1.1 joerg if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) { 1037 1.1 joerg if (const auto *PD = dyn_cast<ImplicitParamDecl>(DRE->getDecl())) { 1038 1.1 joerg if (PD->getParameterKind() == ImplicitParamDecl::ObjCSelf && 1039 1.1 joerg DRE->getBeginLoc().isInvalid()) 1040 1.1 joerg return true; 1041 1.1 joerg } 1042 1.1 joerg } 1043 1.1 joerg return false; 1044 1.1 joerg } 1045 1.1 joerg 1046 1.1 joerg void StmtPrinter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *Node) { 1047 1.1 joerg if (Node->getBase()) { 1048 1.1 joerg if (!Policy.SuppressImplicitBase || 1049 1.1 joerg !isImplicitSelf(Node->getBase()->IgnoreImpCasts())) { 1050 1.1 joerg PrintExpr(Node->getBase()); 1051 1.1 joerg OS << (Node->isArrow() ? "->" : "."); 1052 1.1 joerg } 1053 1.1 joerg } 1054 1.1 joerg OS << *Node->getDecl(); 1055 1.1 joerg } 1056 1.1 joerg 1057 1.1 joerg void StmtPrinter::VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *Node) { 1058 1.1 joerg if (Node->isSuperReceiver()) 1059 1.1 joerg OS << "super."; 1060 1.1 joerg else if (Node->isObjectReceiver() && Node->getBase()) { 1061 1.1 joerg PrintExpr(Node->getBase()); 1062 1.1 joerg OS << "."; 1063 1.1 joerg } else if (Node->isClassReceiver() && Node->getClassReceiver()) { 1064 1.1 joerg OS << Node->getClassReceiver()->getName() << "."; 1065 1.1 joerg } 1066 1.1 joerg 1067 1.1 joerg if (Node->isImplicitProperty()) { 1068 1.1 joerg if (const auto *Getter = Node->getImplicitPropertyGetter()) 1069 1.1 joerg Getter->getSelector().print(OS); 1070 1.1 joerg else 1071 1.1 joerg OS << SelectorTable::getPropertyNameFromSetterSelector( 1072 1.1 joerg Node->getImplicitPropertySetter()->getSelector()); 1073 1.1 joerg } else 1074 1.1 joerg OS << Node->getExplicitProperty()->getName(); 1075 1.1 joerg } 1076 1.1 joerg 1077 1.1 joerg void StmtPrinter::VisitObjCSubscriptRefExpr(ObjCSubscriptRefExpr *Node) { 1078 1.1 joerg PrintExpr(Node->getBaseExpr()); 1079 1.1 joerg OS << "["; 1080 1.1 joerg PrintExpr(Node->getKeyExpr()); 1081 1.1 joerg OS << "]"; 1082 1.1 joerg } 1083 1.1 joerg 1084 1.1 joerg void StmtPrinter::VisitPredefinedExpr(PredefinedExpr *Node) { 1085 1.1 joerg OS << PredefinedExpr::getIdentKindName(Node->getIdentKind()); 1086 1.1 joerg } 1087 1.1 joerg 1088 1.1 joerg void StmtPrinter::VisitCharacterLiteral(CharacterLiteral *Node) { 1089 1.1.1.2 joerg CharacterLiteral::print(Node->getValue(), Node->getKind(), OS); 1090 1.1 joerg } 1091 1.1 joerg 1092 1.1 joerg /// Prints the given expression using the original source text. Returns true on 1093 1.1 joerg /// success, false otherwise. 1094 1.1 joerg static bool printExprAsWritten(raw_ostream &OS, Expr *E, 1095 1.1 joerg const ASTContext *Context) { 1096 1.1 joerg if (!Context) 1097 1.1 joerg return false; 1098 1.1 joerg bool Invalid = false; 1099 1.1 joerg StringRef Source = Lexer::getSourceText( 1100 1.1 joerg CharSourceRange::getTokenRange(E->getSourceRange()), 1101 1.1 joerg Context->getSourceManager(), Context->getLangOpts(), &Invalid); 1102 1.1 joerg if (!Invalid) { 1103 1.1 joerg OS << Source; 1104 1.1 joerg return true; 1105 1.1 joerg } 1106 1.1 joerg return false; 1107 1.1 joerg } 1108 1.1 joerg 1109 1.1 joerg void StmtPrinter::VisitIntegerLiteral(IntegerLiteral *Node) { 1110 1.1 joerg if (Policy.ConstantsAsWritten && printExprAsWritten(OS, Node, Context)) 1111 1.1 joerg return; 1112 1.1 joerg bool isSigned = Node->getType()->isSignedIntegerType(); 1113 1.1 joerg OS << Node->getValue().toString(10, isSigned); 1114 1.1 joerg 1115 1.1 joerg // Emit suffixes. Integer literals are always a builtin integer type. 1116 1.1 joerg switch (Node->getType()->castAs<BuiltinType>()->getKind()) { 1117 1.1 joerg default: llvm_unreachable("Unexpected type for integer literal!"); 1118 1.1 joerg case BuiltinType::Char_S: 1119 1.1 joerg case BuiltinType::Char_U: OS << "i8"; break; 1120 1.1 joerg case BuiltinType::UChar: OS << "Ui8"; break; 1121 1.1 joerg case BuiltinType::Short: OS << "i16"; break; 1122 1.1 joerg case BuiltinType::UShort: OS << "Ui16"; break; 1123 1.1 joerg case BuiltinType::Int: break; // no suffix. 1124 1.1 joerg case BuiltinType::UInt: OS << 'U'; break; 1125 1.1 joerg case BuiltinType::Long: OS << 'L'; break; 1126 1.1 joerg case BuiltinType::ULong: OS << "UL"; break; 1127 1.1 joerg case BuiltinType::LongLong: OS << "LL"; break; 1128 1.1 joerg case BuiltinType::ULongLong: OS << "ULL"; break; 1129 1.1.1.2 joerg case BuiltinType::Int128: 1130 1.1.1.2 joerg break; // no suffix. 1131 1.1.1.2 joerg case BuiltinType::UInt128: 1132 1.1.1.2 joerg break; // no suffix. 1133 1.1 joerg } 1134 1.1 joerg } 1135 1.1 joerg 1136 1.1 joerg void StmtPrinter::VisitFixedPointLiteral(FixedPointLiteral *Node) { 1137 1.1 joerg if (Policy.ConstantsAsWritten && printExprAsWritten(OS, Node, Context)) 1138 1.1 joerg return; 1139 1.1 joerg OS << Node->getValueAsString(/*Radix=*/10); 1140 1.1 joerg 1141 1.1 joerg switch (Node->getType()->castAs<BuiltinType>()->getKind()) { 1142 1.1 joerg default: llvm_unreachable("Unexpected type for fixed point literal!"); 1143 1.1 joerg case BuiltinType::ShortFract: OS << "hr"; break; 1144 1.1 joerg case BuiltinType::ShortAccum: OS << "hk"; break; 1145 1.1 joerg case BuiltinType::UShortFract: OS << "uhr"; break; 1146 1.1 joerg case BuiltinType::UShortAccum: OS << "uhk"; break; 1147 1.1 joerg case BuiltinType::Fract: OS << "r"; break; 1148 1.1 joerg case BuiltinType::Accum: OS << "k"; break; 1149 1.1 joerg case BuiltinType::UFract: OS << "ur"; break; 1150 1.1 joerg case BuiltinType::UAccum: OS << "uk"; break; 1151 1.1 joerg case BuiltinType::LongFract: OS << "lr"; break; 1152 1.1 joerg case BuiltinType::LongAccum: OS << "lk"; break; 1153 1.1 joerg case BuiltinType::ULongFract: OS << "ulr"; break; 1154 1.1 joerg case BuiltinType::ULongAccum: OS << "ulk"; break; 1155 1.1 joerg } 1156 1.1 joerg } 1157 1.1 joerg 1158 1.1 joerg static void PrintFloatingLiteral(raw_ostream &OS, FloatingLiteral *Node, 1159 1.1 joerg bool PrintSuffix) { 1160 1.1 joerg SmallString<16> Str; 1161 1.1 joerg Node->getValue().toString(Str); 1162 1.1 joerg OS << Str; 1163 1.1 joerg if (Str.find_first_not_of("-0123456789") == StringRef::npos) 1164 1.1 joerg OS << '.'; // Trailing dot in order to separate from ints. 1165 1.1 joerg 1166 1.1 joerg if (!PrintSuffix) 1167 1.1 joerg return; 1168 1.1 joerg 1169 1.1 joerg // Emit suffixes. Float literals are always a builtin float type. 1170 1.1 joerg switch (Node->getType()->castAs<BuiltinType>()->getKind()) { 1171 1.1 joerg default: llvm_unreachable("Unexpected type for float literal!"); 1172 1.1 joerg case BuiltinType::Half: break; // FIXME: suffix? 1173 1.1 joerg case BuiltinType::Double: break; // no suffix. 1174 1.1 joerg case BuiltinType::Float16: OS << "F16"; break; 1175 1.1 joerg case BuiltinType::Float: OS << 'F'; break; 1176 1.1 joerg case BuiltinType::LongDouble: OS << 'L'; break; 1177 1.1 joerg case BuiltinType::Float128: OS << 'Q'; break; 1178 1.1 joerg } 1179 1.1 joerg } 1180 1.1 joerg 1181 1.1 joerg void StmtPrinter::VisitFloatingLiteral(FloatingLiteral *Node) { 1182 1.1 joerg if (Policy.ConstantsAsWritten && printExprAsWritten(OS, Node, Context)) 1183 1.1 joerg return; 1184 1.1 joerg PrintFloatingLiteral(OS, Node, /*PrintSuffix=*/true); 1185 1.1 joerg } 1186 1.1 joerg 1187 1.1 joerg void StmtPrinter::VisitImaginaryLiteral(ImaginaryLiteral *Node) { 1188 1.1 joerg PrintExpr(Node->getSubExpr()); 1189 1.1 joerg OS << "i"; 1190 1.1 joerg } 1191 1.1 joerg 1192 1.1 joerg void StmtPrinter::VisitStringLiteral(StringLiteral *Str) { 1193 1.1 joerg Str->outputString(OS); 1194 1.1 joerg } 1195 1.1 joerg 1196 1.1 joerg void StmtPrinter::VisitParenExpr(ParenExpr *Node) { 1197 1.1 joerg OS << "("; 1198 1.1 joerg PrintExpr(Node->getSubExpr()); 1199 1.1 joerg OS << ")"; 1200 1.1 joerg } 1201 1.1 joerg 1202 1.1 joerg void StmtPrinter::VisitUnaryOperator(UnaryOperator *Node) { 1203 1.1 joerg if (!Node->isPostfix()) { 1204 1.1 joerg OS << UnaryOperator::getOpcodeStr(Node->getOpcode()); 1205 1.1 joerg 1206 1.1 joerg // Print a space if this is an "identifier operator" like __real, or if 1207 1.1 joerg // it might be concatenated incorrectly like '+'. 1208 1.1 joerg switch (Node->getOpcode()) { 1209 1.1 joerg default: break; 1210 1.1 joerg case UO_Real: 1211 1.1 joerg case UO_Imag: 1212 1.1 joerg case UO_Extension: 1213 1.1 joerg OS << ' '; 1214 1.1 joerg break; 1215 1.1 joerg case UO_Plus: 1216 1.1 joerg case UO_Minus: 1217 1.1 joerg if (isa<UnaryOperator>(Node->getSubExpr())) 1218 1.1 joerg OS << ' '; 1219 1.1 joerg break; 1220 1.1 joerg } 1221 1.1 joerg } 1222 1.1 joerg PrintExpr(Node->getSubExpr()); 1223 1.1 joerg 1224 1.1 joerg if (Node->isPostfix()) 1225 1.1 joerg OS << UnaryOperator::getOpcodeStr(Node->getOpcode()); 1226 1.1 joerg } 1227 1.1 joerg 1228 1.1 joerg void StmtPrinter::VisitOffsetOfExpr(OffsetOfExpr *Node) { 1229 1.1 joerg OS << "__builtin_offsetof("; 1230 1.1 joerg Node->getTypeSourceInfo()->getType().print(OS, Policy); 1231 1.1 joerg OS << ", "; 1232 1.1 joerg bool PrintedSomething = false; 1233 1.1 joerg for (unsigned i = 0, n = Node->getNumComponents(); i < n; ++i) { 1234 1.1 joerg OffsetOfNode ON = Node->getComponent(i); 1235 1.1 joerg if (ON.getKind() == OffsetOfNode::Array) { 1236 1.1 joerg // Array node 1237 1.1 joerg OS << "["; 1238 1.1 joerg PrintExpr(Node->getIndexExpr(ON.getArrayExprIndex())); 1239 1.1 joerg OS << "]"; 1240 1.1 joerg PrintedSomething = true; 1241 1.1 joerg continue; 1242 1.1 joerg } 1243 1.1 joerg 1244 1.1 joerg // Skip implicit base indirections. 1245 1.1 joerg if (ON.getKind() == OffsetOfNode::Base) 1246 1.1 joerg continue; 1247 1.1 joerg 1248 1.1 joerg // Field or identifier node. 1249 1.1 joerg IdentifierInfo *Id = ON.getFieldName(); 1250 1.1 joerg if (!Id) 1251 1.1 joerg continue; 1252 1.1 joerg 1253 1.1 joerg if (PrintedSomething) 1254 1.1 joerg OS << "."; 1255 1.1 joerg else 1256 1.1 joerg PrintedSomething = true; 1257 1.1 joerg OS << Id->getName(); 1258 1.1 joerg } 1259 1.1 joerg OS << ")"; 1260 1.1 joerg } 1261 1.1 joerg 1262 1.1.1.2 joerg void StmtPrinter::VisitUnaryExprOrTypeTraitExpr( 1263 1.1.1.2 joerg UnaryExprOrTypeTraitExpr *Node) { 1264 1.1.1.2 joerg const char *Spelling = getTraitSpelling(Node->getKind()); 1265 1.1.1.2 joerg if (Node->getKind() == UETT_AlignOf) { 1266 1.1 joerg if (Policy.Alignof) 1267 1.1.1.2 joerg Spelling = "alignof"; 1268 1.1 joerg else if (Policy.UnderscoreAlignof) 1269 1.1.1.2 joerg Spelling = "_Alignof"; 1270 1.1 joerg else 1271 1.1.1.2 joerg Spelling = "__alignof"; 1272 1.1 joerg } 1273 1.1.1.2 joerg 1274 1.1.1.2 joerg OS << Spelling; 1275 1.1.1.2 joerg 1276 1.1 joerg if (Node->isArgumentType()) { 1277 1.1 joerg OS << '('; 1278 1.1 joerg Node->getArgumentType().print(OS, Policy); 1279 1.1 joerg OS << ')'; 1280 1.1 joerg } else { 1281 1.1 joerg OS << " "; 1282 1.1 joerg PrintExpr(Node->getArgumentExpr()); 1283 1.1 joerg } 1284 1.1 joerg } 1285 1.1 joerg 1286 1.1 joerg void StmtPrinter::VisitGenericSelectionExpr(GenericSelectionExpr *Node) { 1287 1.1 joerg OS << "_Generic("; 1288 1.1 joerg PrintExpr(Node->getControllingExpr()); 1289 1.1.1.2 joerg for (const GenericSelectionExpr::Association Assoc : Node->associations()) { 1290 1.1 joerg OS << ", "; 1291 1.1 joerg QualType T = Assoc.getType(); 1292 1.1 joerg if (T.isNull()) 1293 1.1 joerg OS << "default"; 1294 1.1 joerg else 1295 1.1 joerg T.print(OS, Policy); 1296 1.1 joerg OS << ": "; 1297 1.1 joerg PrintExpr(Assoc.getAssociationExpr()); 1298 1.1 joerg } 1299 1.1 joerg OS << ")"; 1300 1.1 joerg } 1301 1.1 joerg 1302 1.1 joerg void StmtPrinter::VisitArraySubscriptExpr(ArraySubscriptExpr *Node) { 1303 1.1 joerg PrintExpr(Node->getLHS()); 1304 1.1 joerg OS << "["; 1305 1.1 joerg PrintExpr(Node->getRHS()); 1306 1.1 joerg OS << "]"; 1307 1.1 joerg } 1308 1.1 joerg 1309 1.1.1.2 joerg void StmtPrinter::VisitMatrixSubscriptExpr(MatrixSubscriptExpr *Node) { 1310 1.1.1.2 joerg PrintExpr(Node->getBase()); 1311 1.1.1.2 joerg OS << "["; 1312 1.1.1.2 joerg PrintExpr(Node->getRowIdx()); 1313 1.1.1.2 joerg OS << "]"; 1314 1.1.1.2 joerg OS << "["; 1315 1.1.1.2 joerg PrintExpr(Node->getColumnIdx()); 1316 1.1.1.2 joerg OS << "]"; 1317 1.1.1.2 joerg } 1318 1.1.1.2 joerg 1319 1.1 joerg void StmtPrinter::VisitOMPArraySectionExpr(OMPArraySectionExpr *Node) { 1320 1.1 joerg PrintExpr(Node->getBase()); 1321 1.1 joerg OS << "["; 1322 1.1 joerg if (Node->getLowerBound()) 1323 1.1 joerg PrintExpr(Node->getLowerBound()); 1324 1.1.1.2 joerg if (Node->getColonLocFirst().isValid()) { 1325 1.1 joerg OS << ":"; 1326 1.1 joerg if (Node->getLength()) 1327 1.1 joerg PrintExpr(Node->getLength()); 1328 1.1 joerg } 1329 1.1.1.2 joerg if (Node->getColonLocSecond().isValid()) { 1330 1.1.1.2 joerg OS << ":"; 1331 1.1.1.2 joerg if (Node->getStride()) 1332 1.1.1.2 joerg PrintExpr(Node->getStride()); 1333 1.1.1.2 joerg } 1334 1.1 joerg OS << "]"; 1335 1.1 joerg } 1336 1.1 joerg 1337 1.1.1.2 joerg void StmtPrinter::VisitOMPArrayShapingExpr(OMPArrayShapingExpr *Node) { 1338 1.1.1.2 joerg OS << "("; 1339 1.1.1.2 joerg for (Expr *E : Node->getDimensions()) { 1340 1.1.1.2 joerg OS << "["; 1341 1.1.1.2 joerg PrintExpr(E); 1342 1.1.1.2 joerg OS << "]"; 1343 1.1.1.2 joerg } 1344 1.1.1.2 joerg OS << ")"; 1345 1.1.1.2 joerg PrintExpr(Node->getBase()); 1346 1.1.1.2 joerg } 1347 1.1.1.2 joerg 1348 1.1.1.2 joerg void StmtPrinter::VisitOMPIteratorExpr(OMPIteratorExpr *Node) { 1349 1.1.1.2 joerg OS << "iterator("; 1350 1.1.1.2 joerg for (unsigned I = 0, E = Node->numOfIterators(); I < E; ++I) { 1351 1.1.1.2 joerg auto *VD = cast<ValueDecl>(Node->getIteratorDecl(I)); 1352 1.1.1.2 joerg VD->getType().print(OS, Policy); 1353 1.1.1.2 joerg const OMPIteratorExpr::IteratorRange Range = Node->getIteratorRange(I); 1354 1.1.1.2 joerg OS << " " << VD->getName() << " = "; 1355 1.1.1.2 joerg PrintExpr(Range.Begin); 1356 1.1.1.2 joerg OS << ":"; 1357 1.1.1.2 joerg PrintExpr(Range.End); 1358 1.1.1.2 joerg if (Range.Step) { 1359 1.1.1.2 joerg OS << ":"; 1360 1.1.1.2 joerg PrintExpr(Range.Step); 1361 1.1.1.2 joerg } 1362 1.1.1.2 joerg if (I < E - 1) 1363 1.1.1.2 joerg OS << ", "; 1364 1.1.1.2 joerg } 1365 1.1.1.2 joerg OS << ")"; 1366 1.1.1.2 joerg } 1367 1.1.1.2 joerg 1368 1.1 joerg void StmtPrinter::PrintCallArgs(CallExpr *Call) { 1369 1.1 joerg for (unsigned i = 0, e = Call->getNumArgs(); i != e; ++i) { 1370 1.1 joerg if (isa<CXXDefaultArgExpr>(Call->getArg(i))) { 1371 1.1 joerg // Don't print any defaulted arguments 1372 1.1 joerg break; 1373 1.1 joerg } 1374 1.1 joerg 1375 1.1 joerg if (i) OS << ", "; 1376 1.1 joerg PrintExpr(Call->getArg(i)); 1377 1.1 joerg } 1378 1.1 joerg } 1379 1.1 joerg 1380 1.1 joerg void StmtPrinter::VisitCallExpr(CallExpr *Call) { 1381 1.1 joerg PrintExpr(Call->getCallee()); 1382 1.1 joerg OS << "("; 1383 1.1 joerg PrintCallArgs(Call); 1384 1.1 joerg OS << ")"; 1385 1.1 joerg } 1386 1.1 joerg 1387 1.1 joerg static bool isImplicitThis(const Expr *E) { 1388 1.1 joerg if (const auto *TE = dyn_cast<CXXThisExpr>(E)) 1389 1.1 joerg return TE->isImplicit(); 1390 1.1 joerg return false; 1391 1.1 joerg } 1392 1.1 joerg 1393 1.1 joerg void StmtPrinter::VisitMemberExpr(MemberExpr *Node) { 1394 1.1 joerg if (!Policy.SuppressImplicitBase || !isImplicitThis(Node->getBase())) { 1395 1.1 joerg PrintExpr(Node->getBase()); 1396 1.1 joerg 1397 1.1 joerg auto *ParentMember = dyn_cast<MemberExpr>(Node->getBase()); 1398 1.1 joerg FieldDecl *ParentDecl = 1399 1.1 joerg ParentMember ? dyn_cast<FieldDecl>(ParentMember->getMemberDecl()) 1400 1.1 joerg : nullptr; 1401 1.1 joerg 1402 1.1 joerg if (!ParentDecl || !ParentDecl->isAnonymousStructOrUnion()) 1403 1.1 joerg OS << (Node->isArrow() ? "->" : "."); 1404 1.1 joerg } 1405 1.1 joerg 1406 1.1 joerg if (auto *FD = dyn_cast<FieldDecl>(Node->getMemberDecl())) 1407 1.1 joerg if (FD->isAnonymousStructOrUnion()) 1408 1.1 joerg return; 1409 1.1 joerg 1410 1.1 joerg if (NestedNameSpecifier *Qualifier = Node->getQualifier()) 1411 1.1 joerg Qualifier->print(OS, Policy); 1412 1.1 joerg if (Node->hasTemplateKeyword()) 1413 1.1 joerg OS << "template "; 1414 1.1 joerg OS << Node->getMemberNameInfo(); 1415 1.1.1.2 joerg const TemplateParameterList *TPL = nullptr; 1416 1.1.1.2 joerg if (auto *FD = dyn_cast<FunctionDecl>(Node->getMemberDecl())) { 1417 1.1.1.2 joerg if (!Node->hadMultipleCandidates()) 1418 1.1.1.2 joerg if (auto *FTD = FD->getPrimaryTemplate()) 1419 1.1.1.2 joerg TPL = FTD->getTemplateParameters(); 1420 1.1.1.2 joerg } else if (auto *VTSD = 1421 1.1.1.2 joerg dyn_cast<VarTemplateSpecializationDecl>(Node->getMemberDecl())) 1422 1.1.1.2 joerg TPL = VTSD->getSpecializedTemplate()->getTemplateParameters(); 1423 1.1 joerg if (Node->hasExplicitTemplateArgs()) 1424 1.1.1.2 joerg printTemplateArgumentList(OS, Node->template_arguments(), Policy, TPL); 1425 1.1 joerg } 1426 1.1 joerg 1427 1.1 joerg void StmtPrinter::VisitObjCIsaExpr(ObjCIsaExpr *Node) { 1428 1.1 joerg PrintExpr(Node->getBase()); 1429 1.1 joerg OS << (Node->isArrow() ? "->isa" : ".isa"); 1430 1.1 joerg } 1431 1.1 joerg 1432 1.1 joerg void StmtPrinter::VisitExtVectorElementExpr(ExtVectorElementExpr *Node) { 1433 1.1 joerg PrintExpr(Node->getBase()); 1434 1.1 joerg OS << "."; 1435 1.1 joerg OS << Node->getAccessor().getName(); 1436 1.1 joerg } 1437 1.1 joerg 1438 1.1 joerg void StmtPrinter::VisitCStyleCastExpr(CStyleCastExpr *Node) { 1439 1.1 joerg OS << '('; 1440 1.1 joerg Node->getTypeAsWritten().print(OS, Policy); 1441 1.1 joerg OS << ')'; 1442 1.1 joerg PrintExpr(Node->getSubExpr()); 1443 1.1 joerg } 1444 1.1 joerg 1445 1.1 joerg void StmtPrinter::VisitCompoundLiteralExpr(CompoundLiteralExpr *Node) { 1446 1.1 joerg OS << '('; 1447 1.1 joerg Node->getType().print(OS, Policy); 1448 1.1 joerg OS << ')'; 1449 1.1 joerg PrintExpr(Node->getInitializer()); 1450 1.1 joerg } 1451 1.1 joerg 1452 1.1 joerg void StmtPrinter::VisitImplicitCastExpr(ImplicitCastExpr *Node) { 1453 1.1 joerg // No need to print anything, simply forward to the subexpression. 1454 1.1 joerg PrintExpr(Node->getSubExpr()); 1455 1.1 joerg } 1456 1.1 joerg 1457 1.1 joerg void StmtPrinter::VisitBinaryOperator(BinaryOperator *Node) { 1458 1.1 joerg PrintExpr(Node->getLHS()); 1459 1.1 joerg OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " "; 1460 1.1 joerg PrintExpr(Node->getRHS()); 1461 1.1 joerg } 1462 1.1 joerg 1463 1.1 joerg void StmtPrinter::VisitCompoundAssignOperator(CompoundAssignOperator *Node) { 1464 1.1 joerg PrintExpr(Node->getLHS()); 1465 1.1 joerg OS << " " << BinaryOperator::getOpcodeStr(Node->getOpcode()) << " "; 1466 1.1 joerg PrintExpr(Node->getRHS()); 1467 1.1 joerg } 1468 1.1 joerg 1469 1.1 joerg void StmtPrinter::VisitConditionalOperator(ConditionalOperator *Node) { 1470 1.1 joerg PrintExpr(Node->getCond()); 1471 1.1 joerg OS << " ? "; 1472 1.1 joerg PrintExpr(Node->getLHS()); 1473 1.1 joerg OS << " : "; 1474 1.1 joerg PrintExpr(Node->getRHS()); 1475 1.1 joerg } 1476 1.1 joerg 1477 1.1 joerg // GNU extensions. 1478 1.1 joerg 1479 1.1 joerg void 1480 1.1 joerg StmtPrinter::VisitBinaryConditionalOperator(BinaryConditionalOperator *Node) { 1481 1.1 joerg PrintExpr(Node->getCommon()); 1482 1.1 joerg OS << " ?: "; 1483 1.1 joerg PrintExpr(Node->getFalseExpr()); 1484 1.1 joerg } 1485 1.1 joerg 1486 1.1 joerg void StmtPrinter::VisitAddrLabelExpr(AddrLabelExpr *Node) { 1487 1.1 joerg OS << "&&" << Node->getLabel()->getName(); 1488 1.1 joerg } 1489 1.1 joerg 1490 1.1 joerg void StmtPrinter::VisitStmtExpr(StmtExpr *E) { 1491 1.1 joerg OS << "("; 1492 1.1 joerg PrintRawCompoundStmt(E->getSubStmt()); 1493 1.1 joerg OS << ")"; 1494 1.1 joerg } 1495 1.1 joerg 1496 1.1 joerg void StmtPrinter::VisitChooseExpr(ChooseExpr *Node) { 1497 1.1 joerg OS << "__builtin_choose_expr("; 1498 1.1 joerg PrintExpr(Node->getCond()); 1499 1.1 joerg OS << ", "; 1500 1.1 joerg PrintExpr(Node->getLHS()); 1501 1.1 joerg OS << ", "; 1502 1.1 joerg PrintExpr(Node->getRHS()); 1503 1.1 joerg OS << ")"; 1504 1.1 joerg } 1505 1.1 joerg 1506 1.1 joerg void StmtPrinter::VisitGNUNullExpr(GNUNullExpr *) { 1507 1.1 joerg OS << "__null"; 1508 1.1 joerg } 1509 1.1 joerg 1510 1.1 joerg void StmtPrinter::VisitShuffleVectorExpr(ShuffleVectorExpr *Node) { 1511 1.1 joerg OS << "__builtin_shufflevector("; 1512 1.1 joerg for (unsigned i = 0, e = Node->getNumSubExprs(); i != e; ++i) { 1513 1.1 joerg if (i) OS << ", "; 1514 1.1 joerg PrintExpr(Node->getExpr(i)); 1515 1.1 joerg } 1516 1.1 joerg OS << ")"; 1517 1.1 joerg } 1518 1.1 joerg 1519 1.1 joerg void StmtPrinter::VisitConvertVectorExpr(ConvertVectorExpr *Node) { 1520 1.1 joerg OS << "__builtin_convertvector("; 1521 1.1 joerg PrintExpr(Node->getSrcExpr()); 1522 1.1 joerg OS << ", "; 1523 1.1 joerg Node->getType().print(OS, Policy); 1524 1.1 joerg OS << ")"; 1525 1.1 joerg } 1526 1.1 joerg 1527 1.1 joerg void StmtPrinter::VisitInitListExpr(InitListExpr* Node) { 1528 1.1 joerg if (Node->getSyntacticForm()) { 1529 1.1 joerg Visit(Node->getSyntacticForm()); 1530 1.1 joerg return; 1531 1.1 joerg } 1532 1.1 joerg 1533 1.1 joerg OS << "{"; 1534 1.1 joerg for (unsigned i = 0, e = Node->getNumInits(); i != e; ++i) { 1535 1.1 joerg if (i) OS << ", "; 1536 1.1 joerg if (Node->getInit(i)) 1537 1.1 joerg PrintExpr(Node->getInit(i)); 1538 1.1 joerg else 1539 1.1 joerg OS << "{}"; 1540 1.1 joerg } 1541 1.1 joerg OS << "}"; 1542 1.1 joerg } 1543 1.1 joerg 1544 1.1 joerg void StmtPrinter::VisitArrayInitLoopExpr(ArrayInitLoopExpr *Node) { 1545 1.1 joerg // There's no way to express this expression in any of our supported 1546 1.1 joerg // languages, so just emit something terse and (hopefully) clear. 1547 1.1 joerg OS << "{"; 1548 1.1 joerg PrintExpr(Node->getSubExpr()); 1549 1.1 joerg OS << "}"; 1550 1.1 joerg } 1551 1.1 joerg 1552 1.1 joerg void StmtPrinter::VisitArrayInitIndexExpr(ArrayInitIndexExpr *Node) { 1553 1.1 joerg OS << "*"; 1554 1.1 joerg } 1555 1.1 joerg 1556 1.1 joerg void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) { 1557 1.1 joerg OS << "("; 1558 1.1 joerg for (unsigned i = 0, e = Node->getNumExprs(); i != e; ++i) { 1559 1.1 joerg if (i) OS << ", "; 1560 1.1 joerg PrintExpr(Node->getExpr(i)); 1561 1.1 joerg } 1562 1.1 joerg OS << ")"; 1563 1.1 joerg } 1564 1.1 joerg 1565 1.1 joerg void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) { 1566 1.1 joerg bool NeedsEquals = true; 1567 1.1 joerg for (const DesignatedInitExpr::Designator &D : Node->designators()) { 1568 1.1 joerg if (D.isFieldDesignator()) { 1569 1.1 joerg if (D.getDotLoc().isInvalid()) { 1570 1.1 joerg if (IdentifierInfo *II = D.getFieldName()) { 1571 1.1 joerg OS << II->getName() << ":"; 1572 1.1 joerg NeedsEquals = false; 1573 1.1 joerg } 1574 1.1 joerg } else { 1575 1.1 joerg OS << "." << D.getFieldName()->getName(); 1576 1.1 joerg } 1577 1.1 joerg } else { 1578 1.1 joerg OS << "["; 1579 1.1 joerg if (D.isArrayDesignator()) { 1580 1.1 joerg PrintExpr(Node->getArrayIndex(D)); 1581 1.1 joerg } else { 1582 1.1 joerg PrintExpr(Node->getArrayRangeStart(D)); 1583 1.1 joerg OS << " ... "; 1584 1.1 joerg PrintExpr(Node->getArrayRangeEnd(D)); 1585 1.1 joerg } 1586 1.1 joerg OS << "]"; 1587 1.1 joerg } 1588 1.1 joerg } 1589 1.1 joerg 1590 1.1 joerg if (NeedsEquals) 1591 1.1 joerg OS << " = "; 1592 1.1 joerg else 1593 1.1 joerg OS << " "; 1594 1.1 joerg PrintExpr(Node->getInit()); 1595 1.1 joerg } 1596 1.1 joerg 1597 1.1 joerg void StmtPrinter::VisitDesignatedInitUpdateExpr( 1598 1.1 joerg DesignatedInitUpdateExpr *Node) { 1599 1.1 joerg OS << "{"; 1600 1.1 joerg OS << "/*base*/"; 1601 1.1 joerg PrintExpr(Node->getBase()); 1602 1.1 joerg OS << ", "; 1603 1.1 joerg 1604 1.1 joerg OS << "/*updater*/"; 1605 1.1 joerg PrintExpr(Node->getUpdater()); 1606 1.1 joerg OS << "}"; 1607 1.1 joerg } 1608 1.1 joerg 1609 1.1 joerg void StmtPrinter::VisitNoInitExpr(NoInitExpr *Node) { 1610 1.1 joerg OS << "/*no init*/"; 1611 1.1 joerg } 1612 1.1 joerg 1613 1.1 joerg void StmtPrinter::VisitImplicitValueInitExpr(ImplicitValueInitExpr *Node) { 1614 1.1 joerg if (Node->getType()->getAsCXXRecordDecl()) { 1615 1.1 joerg OS << "/*implicit*/"; 1616 1.1 joerg Node->getType().print(OS, Policy); 1617 1.1 joerg OS << "()"; 1618 1.1 joerg } else { 1619 1.1 joerg OS << "/*implicit*/("; 1620 1.1 joerg Node->getType().print(OS, Policy); 1621 1.1 joerg OS << ')'; 1622 1.1 joerg if (Node->getType()->isRecordType()) 1623 1.1 joerg OS << "{}"; 1624 1.1 joerg else 1625 1.1 joerg OS << 0; 1626 1.1 joerg } 1627 1.1 joerg } 1628 1.1 joerg 1629 1.1 joerg void StmtPrinter::VisitVAArgExpr(VAArgExpr *Node) { 1630 1.1 joerg OS << "__builtin_va_arg("; 1631 1.1 joerg PrintExpr(Node->getSubExpr()); 1632 1.1 joerg OS << ", "; 1633 1.1 joerg Node->getType().print(OS, Policy); 1634 1.1 joerg OS << ")"; 1635 1.1 joerg } 1636 1.1 joerg 1637 1.1 joerg void StmtPrinter::VisitPseudoObjectExpr(PseudoObjectExpr *Node) { 1638 1.1 joerg PrintExpr(Node->getSyntacticForm()); 1639 1.1 joerg } 1640 1.1 joerg 1641 1.1 joerg void StmtPrinter::VisitAtomicExpr(AtomicExpr *Node) { 1642 1.1 joerg const char *Name = nullptr; 1643 1.1 joerg switch (Node->getOp()) { 1644 1.1 joerg #define BUILTIN(ID, TYPE, ATTRS) 1645 1.1 joerg #define ATOMIC_BUILTIN(ID, TYPE, ATTRS) \ 1646 1.1 joerg case AtomicExpr::AO ## ID: \ 1647 1.1 joerg Name = #ID "("; \ 1648 1.1 joerg break; 1649 1.1 joerg #include "clang/Basic/Builtins.def" 1650 1.1 joerg } 1651 1.1 joerg OS << Name; 1652 1.1 joerg 1653 1.1 joerg // AtomicExpr stores its subexpressions in a permuted order. 1654 1.1 joerg PrintExpr(Node->getPtr()); 1655 1.1 joerg if (Node->getOp() != AtomicExpr::AO__c11_atomic_load && 1656 1.1 joerg Node->getOp() != AtomicExpr::AO__atomic_load_n && 1657 1.1 joerg Node->getOp() != AtomicExpr::AO__opencl_atomic_load) { 1658 1.1 joerg OS << ", "; 1659 1.1 joerg PrintExpr(Node->getVal1()); 1660 1.1 joerg } 1661 1.1 joerg if (Node->getOp() == AtomicExpr::AO__atomic_exchange || 1662 1.1 joerg Node->isCmpXChg()) { 1663 1.1 joerg OS << ", "; 1664 1.1 joerg PrintExpr(Node->getVal2()); 1665 1.1 joerg } 1666 1.1 joerg if (Node->getOp() == AtomicExpr::AO__atomic_compare_exchange || 1667 1.1 joerg Node->getOp() == AtomicExpr::AO__atomic_compare_exchange_n) { 1668 1.1 joerg OS << ", "; 1669 1.1 joerg PrintExpr(Node->getWeak()); 1670 1.1 joerg } 1671 1.1 joerg if (Node->getOp() != AtomicExpr::AO__c11_atomic_init && 1672 1.1 joerg Node->getOp() != AtomicExpr::AO__opencl_atomic_init) { 1673 1.1 joerg OS << ", "; 1674 1.1 joerg PrintExpr(Node->getOrder()); 1675 1.1 joerg } 1676 1.1 joerg if (Node->isCmpXChg()) { 1677 1.1 joerg OS << ", "; 1678 1.1 joerg PrintExpr(Node->getOrderFail()); 1679 1.1 joerg } 1680 1.1 joerg OS << ")"; 1681 1.1 joerg } 1682 1.1 joerg 1683 1.1 joerg // C++ 1684 1.1 joerg void StmtPrinter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *Node) { 1685 1.1 joerg OverloadedOperatorKind Kind = Node->getOperator(); 1686 1.1 joerg if (Kind == OO_PlusPlus || Kind == OO_MinusMinus) { 1687 1.1 joerg if (Node->getNumArgs() == 1) { 1688 1.1 joerg OS << getOperatorSpelling(Kind) << ' '; 1689 1.1 joerg PrintExpr(Node->getArg(0)); 1690 1.1 joerg } else { 1691 1.1 joerg PrintExpr(Node->getArg(0)); 1692 1.1 joerg OS << ' ' << getOperatorSpelling(Kind); 1693 1.1 joerg } 1694 1.1 joerg } else if (Kind == OO_Arrow) { 1695 1.1 joerg PrintExpr(Node->getArg(0)); 1696 1.1 joerg } else if (Kind == OO_Call) { 1697 1.1 joerg PrintExpr(Node->getArg(0)); 1698 1.1 joerg OS << '('; 1699 1.1 joerg for (unsigned ArgIdx = 1; ArgIdx < Node->getNumArgs(); ++ArgIdx) { 1700 1.1 joerg if (ArgIdx > 1) 1701 1.1 joerg OS << ", "; 1702 1.1 joerg if (!isa<CXXDefaultArgExpr>(Node->getArg(ArgIdx))) 1703 1.1 joerg PrintExpr(Node->getArg(ArgIdx)); 1704 1.1 joerg } 1705 1.1 joerg OS << ')'; 1706 1.1 joerg } else if (Kind == OO_Subscript) { 1707 1.1 joerg PrintExpr(Node->getArg(0)); 1708 1.1 joerg OS << '['; 1709 1.1 joerg PrintExpr(Node->getArg(1)); 1710 1.1 joerg OS << ']'; 1711 1.1 joerg } else if (Node->getNumArgs() == 1) { 1712 1.1 joerg OS << getOperatorSpelling(Kind) << ' '; 1713 1.1 joerg PrintExpr(Node->getArg(0)); 1714 1.1 joerg } else if (Node->getNumArgs() == 2) { 1715 1.1 joerg PrintExpr(Node->getArg(0)); 1716 1.1 joerg OS << ' ' << getOperatorSpelling(Kind) << ' '; 1717 1.1 joerg PrintExpr(Node->getArg(1)); 1718 1.1 joerg } else { 1719 1.1 joerg llvm_unreachable("unknown overloaded operator"); 1720 1.1 joerg } 1721 1.1 joerg } 1722 1.1 joerg 1723 1.1 joerg void StmtPrinter::VisitCXXMemberCallExpr(CXXMemberCallExpr *Node) { 1724 1.1 joerg // If we have a conversion operator call only print the argument. 1725 1.1 joerg CXXMethodDecl *MD = Node->getMethodDecl(); 1726 1.1 joerg if (MD && isa<CXXConversionDecl>(MD)) { 1727 1.1 joerg PrintExpr(Node->getImplicitObjectArgument()); 1728 1.1 joerg return; 1729 1.1 joerg } 1730 1.1 joerg VisitCallExpr(cast<CallExpr>(Node)); 1731 1.1 joerg } 1732 1.1 joerg 1733 1.1 joerg void StmtPrinter::VisitCUDAKernelCallExpr(CUDAKernelCallExpr *Node) { 1734 1.1 joerg PrintExpr(Node->getCallee()); 1735 1.1 joerg OS << "<<<"; 1736 1.1 joerg PrintCallArgs(Node->getConfig()); 1737 1.1 joerg OS << ">>>("; 1738 1.1 joerg PrintCallArgs(Node); 1739 1.1 joerg OS << ")"; 1740 1.1 joerg } 1741 1.1 joerg 1742 1.1 joerg void StmtPrinter::VisitCXXRewrittenBinaryOperator( 1743 1.1 joerg CXXRewrittenBinaryOperator *Node) { 1744 1.1 joerg CXXRewrittenBinaryOperator::DecomposedForm Decomposed = 1745 1.1 joerg Node->getDecomposedForm(); 1746 1.1 joerg PrintExpr(const_cast<Expr*>(Decomposed.LHS)); 1747 1.1 joerg OS << ' ' << BinaryOperator::getOpcodeStr(Decomposed.Opcode) << ' '; 1748 1.1 joerg PrintExpr(const_cast<Expr*>(Decomposed.RHS)); 1749 1.1 joerg } 1750 1.1 joerg 1751 1.1 joerg void StmtPrinter::VisitCXXNamedCastExpr(CXXNamedCastExpr *Node) { 1752 1.1 joerg OS << Node->getCastName() << '<'; 1753 1.1 joerg Node->getTypeAsWritten().print(OS, Policy); 1754 1.1 joerg OS << ">("; 1755 1.1 joerg PrintExpr(Node->getSubExpr()); 1756 1.1 joerg OS << ")"; 1757 1.1 joerg } 1758 1.1 joerg 1759 1.1 joerg void StmtPrinter::VisitCXXStaticCastExpr(CXXStaticCastExpr *Node) { 1760 1.1 joerg VisitCXXNamedCastExpr(Node); 1761 1.1 joerg } 1762 1.1 joerg 1763 1.1 joerg void StmtPrinter::VisitCXXDynamicCastExpr(CXXDynamicCastExpr *Node) { 1764 1.1 joerg VisitCXXNamedCastExpr(Node); 1765 1.1 joerg } 1766 1.1 joerg 1767 1.1 joerg void StmtPrinter::VisitCXXReinterpretCastExpr(CXXReinterpretCastExpr *Node) { 1768 1.1 joerg VisitCXXNamedCastExpr(Node); 1769 1.1 joerg } 1770 1.1 joerg 1771 1.1 joerg void StmtPrinter::VisitCXXConstCastExpr(CXXConstCastExpr *Node) { 1772 1.1 joerg VisitCXXNamedCastExpr(Node); 1773 1.1 joerg } 1774 1.1 joerg 1775 1.1 joerg void StmtPrinter::VisitBuiltinBitCastExpr(BuiltinBitCastExpr *Node) { 1776 1.1 joerg OS << "__builtin_bit_cast("; 1777 1.1 joerg Node->getTypeInfoAsWritten()->getType().print(OS, Policy); 1778 1.1 joerg OS << ", "; 1779 1.1 joerg PrintExpr(Node->getSubExpr()); 1780 1.1 joerg OS << ")"; 1781 1.1 joerg } 1782 1.1 joerg 1783 1.1.1.2 joerg void StmtPrinter::VisitCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *Node) { 1784 1.1.1.2 joerg VisitCXXNamedCastExpr(Node); 1785 1.1.1.2 joerg } 1786 1.1.1.2 joerg 1787 1.1 joerg void StmtPrinter::VisitCXXTypeidExpr(CXXTypeidExpr *Node) { 1788 1.1 joerg OS << "typeid("; 1789 1.1 joerg if (Node->isTypeOperand()) { 1790 1.1 joerg Node->getTypeOperandSourceInfo()->getType().print(OS, Policy); 1791 1.1 joerg } else { 1792 1.1 joerg PrintExpr(Node->getExprOperand()); 1793 1.1 joerg } 1794 1.1 joerg OS << ")"; 1795 1.1 joerg } 1796 1.1 joerg 1797 1.1 joerg void StmtPrinter::VisitCXXUuidofExpr(CXXUuidofExpr *Node) { 1798 1.1 joerg OS << "__uuidof("; 1799 1.1 joerg if (Node->isTypeOperand()) { 1800 1.1 joerg Node->getTypeOperandSourceInfo()->getType().print(OS, Policy); 1801 1.1 joerg } else { 1802 1.1 joerg PrintExpr(Node->getExprOperand()); 1803 1.1 joerg } 1804 1.1 joerg OS << ")"; 1805 1.1 joerg } 1806 1.1 joerg 1807 1.1 joerg void StmtPrinter::VisitMSPropertyRefExpr(MSPropertyRefExpr *Node) { 1808 1.1 joerg PrintExpr(Node->getBaseExpr()); 1809 1.1 joerg if (Node->isArrow()) 1810 1.1 joerg OS << "->"; 1811 1.1 joerg else 1812 1.1 joerg OS << "."; 1813 1.1 joerg if (NestedNameSpecifier *Qualifier = 1814 1.1 joerg Node->getQualifierLoc().getNestedNameSpecifier()) 1815 1.1 joerg Qualifier->print(OS, Policy); 1816 1.1 joerg OS << Node->getPropertyDecl()->getDeclName(); 1817 1.1 joerg } 1818 1.1 joerg 1819 1.1 joerg void StmtPrinter::VisitMSPropertySubscriptExpr(MSPropertySubscriptExpr *Node) { 1820 1.1 joerg PrintExpr(Node->getBase()); 1821 1.1 joerg OS << "["; 1822 1.1 joerg PrintExpr(Node->getIdx()); 1823 1.1 joerg OS << "]"; 1824 1.1 joerg } 1825 1.1 joerg 1826 1.1 joerg void StmtPrinter::VisitUserDefinedLiteral(UserDefinedLiteral *Node) { 1827 1.1 joerg switch (Node->getLiteralOperatorKind()) { 1828 1.1 joerg case UserDefinedLiteral::LOK_Raw: 1829 1.1 joerg OS << cast<StringLiteral>(Node->getArg(0)->IgnoreImpCasts())->getString(); 1830 1.1 joerg break; 1831 1.1 joerg case UserDefinedLiteral::LOK_Template: { 1832 1.1 joerg const auto *DRE = cast<DeclRefExpr>(Node->getCallee()->IgnoreImpCasts()); 1833 1.1 joerg const TemplateArgumentList *Args = 1834 1.1 joerg cast<FunctionDecl>(DRE->getDecl())->getTemplateSpecializationArgs(); 1835 1.1 joerg assert(Args); 1836 1.1 joerg 1837 1.1 joerg if (Args->size() != 1) { 1838 1.1.1.2 joerg const TemplateParameterList *TPL = nullptr; 1839 1.1.1.2 joerg if (!DRE->hadMultipleCandidates()) 1840 1.1.1.2 joerg if (const auto *TD = dyn_cast<TemplateDecl>(DRE->getDecl())) 1841 1.1.1.2 joerg TPL = TD->getTemplateParameters(); 1842 1.1 joerg OS << "operator\"\"" << Node->getUDSuffix()->getName(); 1843 1.1.1.2 joerg printTemplateArgumentList(OS, Args->asArray(), Policy, TPL); 1844 1.1 joerg OS << "()"; 1845 1.1 joerg return; 1846 1.1 joerg } 1847 1.1 joerg 1848 1.1 joerg const TemplateArgument &Pack = Args->get(0); 1849 1.1 joerg for (const auto &P : Pack.pack_elements()) { 1850 1.1 joerg char C = (char)P.getAsIntegral().getZExtValue(); 1851 1.1 joerg OS << C; 1852 1.1 joerg } 1853 1.1 joerg break; 1854 1.1 joerg } 1855 1.1 joerg case UserDefinedLiteral::LOK_Integer: { 1856 1.1 joerg // Print integer literal without suffix. 1857 1.1 joerg const auto *Int = cast<IntegerLiteral>(Node->getCookedLiteral()); 1858 1.1 joerg OS << Int->getValue().toString(10, /*isSigned*/false); 1859 1.1 joerg break; 1860 1.1 joerg } 1861 1.1 joerg case UserDefinedLiteral::LOK_Floating: { 1862 1.1 joerg // Print floating literal without suffix. 1863 1.1 joerg auto *Float = cast<FloatingLiteral>(Node->getCookedLiteral()); 1864 1.1 joerg PrintFloatingLiteral(OS, Float, /*PrintSuffix=*/false); 1865 1.1 joerg break; 1866 1.1 joerg } 1867 1.1 joerg case UserDefinedLiteral::LOK_String: 1868 1.1 joerg case UserDefinedLiteral::LOK_Character: 1869 1.1 joerg PrintExpr(Node->getCookedLiteral()); 1870 1.1 joerg break; 1871 1.1 joerg } 1872 1.1 joerg OS << Node->getUDSuffix()->getName(); 1873 1.1 joerg } 1874 1.1 joerg 1875 1.1 joerg void StmtPrinter::VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *Node) { 1876 1.1 joerg OS << (Node->getValue() ? "true" : "false"); 1877 1.1 joerg } 1878 1.1 joerg 1879 1.1 joerg void StmtPrinter::VisitCXXNullPtrLiteralExpr(CXXNullPtrLiteralExpr *Node) { 1880 1.1 joerg OS << "nullptr"; 1881 1.1 joerg } 1882 1.1 joerg 1883 1.1 joerg void StmtPrinter::VisitCXXThisExpr(CXXThisExpr *Node) { 1884 1.1 joerg OS << "this"; 1885 1.1 joerg } 1886 1.1 joerg 1887 1.1 joerg void StmtPrinter::VisitCXXThrowExpr(CXXThrowExpr *Node) { 1888 1.1 joerg if (!Node->getSubExpr()) 1889 1.1 joerg OS << "throw"; 1890 1.1 joerg else { 1891 1.1 joerg OS << "throw "; 1892 1.1 joerg PrintExpr(Node->getSubExpr()); 1893 1.1 joerg } 1894 1.1 joerg } 1895 1.1 joerg 1896 1.1 joerg void StmtPrinter::VisitCXXDefaultArgExpr(CXXDefaultArgExpr *Node) { 1897 1.1 joerg // Nothing to print: we picked up the default argument. 1898 1.1 joerg } 1899 1.1 joerg 1900 1.1 joerg void StmtPrinter::VisitCXXDefaultInitExpr(CXXDefaultInitExpr *Node) { 1901 1.1 joerg // Nothing to print: we picked up the default initializer. 1902 1.1 joerg } 1903 1.1 joerg 1904 1.1 joerg void StmtPrinter::VisitCXXFunctionalCastExpr(CXXFunctionalCastExpr *Node) { 1905 1.1 joerg Node->getType().print(OS, Policy); 1906 1.1 joerg // If there are no parens, this is list-initialization, and the braces are 1907 1.1 joerg // part of the syntax of the inner construct. 1908 1.1 joerg if (Node->getLParenLoc().isValid()) 1909 1.1 joerg OS << "("; 1910 1.1 joerg PrintExpr(Node->getSubExpr()); 1911 1.1 joerg if (Node->getLParenLoc().isValid()) 1912 1.1 joerg OS << ")"; 1913 1.1 joerg } 1914 1.1 joerg 1915 1.1 joerg void StmtPrinter::VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *Node) { 1916 1.1 joerg PrintExpr(Node->getSubExpr()); 1917 1.1 joerg } 1918 1.1 joerg 1919 1.1 joerg void StmtPrinter::VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *Node) { 1920 1.1 joerg Node->getType().print(OS, Policy); 1921 1.1 joerg if (Node->isStdInitListInitialization()) 1922 1.1 joerg /* Nothing to do; braces are part of creating the std::initializer_list. */; 1923 1.1 joerg else if (Node->isListInitialization()) 1924 1.1 joerg OS << "{"; 1925 1.1 joerg else 1926 1.1 joerg OS << "("; 1927 1.1 joerg for (CXXTemporaryObjectExpr::arg_iterator Arg = Node->arg_begin(), 1928 1.1 joerg ArgEnd = Node->arg_end(); 1929 1.1 joerg Arg != ArgEnd; ++Arg) { 1930 1.1 joerg if ((*Arg)->isDefaultArgument()) 1931 1.1 joerg break; 1932 1.1 joerg if (Arg != Node->arg_begin()) 1933 1.1 joerg OS << ", "; 1934 1.1 joerg PrintExpr(*Arg); 1935 1.1 joerg } 1936 1.1 joerg if (Node->isStdInitListInitialization()) 1937 1.1 joerg /* See above. */; 1938 1.1 joerg else if (Node->isListInitialization()) 1939 1.1 joerg OS << "}"; 1940 1.1 joerg else 1941 1.1 joerg OS << ")"; 1942 1.1 joerg } 1943 1.1 joerg 1944 1.1 joerg void StmtPrinter::VisitLambdaExpr(LambdaExpr *Node) { 1945 1.1 joerg OS << '['; 1946 1.1 joerg bool NeedComma = false; 1947 1.1 joerg switch (Node->getCaptureDefault()) { 1948 1.1 joerg case LCD_None: 1949 1.1 joerg break; 1950 1.1 joerg 1951 1.1 joerg case LCD_ByCopy: 1952 1.1 joerg OS << '='; 1953 1.1 joerg NeedComma = true; 1954 1.1 joerg break; 1955 1.1 joerg 1956 1.1 joerg case LCD_ByRef: 1957 1.1 joerg OS << '&'; 1958 1.1 joerg NeedComma = true; 1959 1.1 joerg break; 1960 1.1 joerg } 1961 1.1 joerg for (LambdaExpr::capture_iterator C = Node->explicit_capture_begin(), 1962 1.1 joerg CEnd = Node->explicit_capture_end(); 1963 1.1 joerg C != CEnd; 1964 1.1 joerg ++C) { 1965 1.1 joerg if (C->capturesVLAType()) 1966 1.1 joerg continue; 1967 1.1 joerg 1968 1.1 joerg if (NeedComma) 1969 1.1 joerg OS << ", "; 1970 1.1 joerg NeedComma = true; 1971 1.1 joerg 1972 1.1 joerg switch (C->getCaptureKind()) { 1973 1.1 joerg case LCK_This: 1974 1.1 joerg OS << "this"; 1975 1.1 joerg break; 1976 1.1 joerg 1977 1.1 joerg case LCK_StarThis: 1978 1.1 joerg OS << "*this"; 1979 1.1 joerg break; 1980 1.1 joerg 1981 1.1 joerg case LCK_ByRef: 1982 1.1 joerg if (Node->getCaptureDefault() != LCD_ByRef || Node->isInitCapture(C)) 1983 1.1 joerg OS << '&'; 1984 1.1 joerg OS << C->getCapturedVar()->getName(); 1985 1.1 joerg break; 1986 1.1 joerg 1987 1.1 joerg case LCK_ByCopy: 1988 1.1 joerg OS << C->getCapturedVar()->getName(); 1989 1.1 joerg break; 1990 1.1 joerg 1991 1.1 joerg case LCK_VLAType: 1992 1.1 joerg llvm_unreachable("VLA type in explicit captures."); 1993 1.1 joerg } 1994 1.1 joerg 1995 1.1 joerg if (C->isPackExpansion()) 1996 1.1 joerg OS << "..."; 1997 1.1 joerg 1998 1.1.1.2 joerg if (Node->isInitCapture(C)) { 1999 1.1.1.2 joerg VarDecl *D = C->getCapturedVar(); 2000 1.1.1.2 joerg 2001 1.1.1.2 joerg llvm::StringRef Pre; 2002 1.1.1.2 joerg llvm::StringRef Post; 2003 1.1.1.2 joerg if (D->getInitStyle() == VarDecl::CallInit && 2004 1.1.1.2 joerg !isa<ParenListExpr>(D->getInit())) { 2005 1.1.1.2 joerg Pre = "("; 2006 1.1.1.2 joerg Post = ")"; 2007 1.1.1.2 joerg } else if (D->getInitStyle() == VarDecl::CInit) { 2008 1.1.1.2 joerg Pre = " = "; 2009 1.1.1.2 joerg } 2010 1.1.1.2 joerg 2011 1.1.1.2 joerg OS << Pre; 2012 1.1.1.2 joerg PrintExpr(D->getInit()); 2013 1.1.1.2 joerg OS << Post; 2014 1.1.1.2 joerg } 2015 1.1 joerg } 2016 1.1 joerg OS << ']'; 2017 1.1 joerg 2018 1.1 joerg if (!Node->getExplicitTemplateParameters().empty()) { 2019 1.1 joerg Node->getTemplateParameterList()->print( 2020 1.1 joerg OS, Node->getLambdaClass()->getASTContext(), 2021 1.1 joerg /*OmitTemplateKW*/true); 2022 1.1 joerg } 2023 1.1 joerg 2024 1.1 joerg if (Node->hasExplicitParameters()) { 2025 1.1 joerg OS << '('; 2026 1.1 joerg CXXMethodDecl *Method = Node->getCallOperator(); 2027 1.1 joerg NeedComma = false; 2028 1.1 joerg for (const auto *P : Method->parameters()) { 2029 1.1 joerg if (NeedComma) { 2030 1.1 joerg OS << ", "; 2031 1.1 joerg } else { 2032 1.1 joerg NeedComma = true; 2033 1.1 joerg } 2034 1.1 joerg std::string ParamStr = P->getNameAsString(); 2035 1.1 joerg P->getOriginalType().print(OS, Policy, ParamStr); 2036 1.1 joerg } 2037 1.1 joerg if (Method->isVariadic()) { 2038 1.1 joerg if (NeedComma) 2039 1.1 joerg OS << ", "; 2040 1.1 joerg OS << "..."; 2041 1.1 joerg } 2042 1.1 joerg OS << ')'; 2043 1.1 joerg 2044 1.1 joerg if (Node->isMutable()) 2045 1.1 joerg OS << " mutable"; 2046 1.1 joerg 2047 1.1 joerg auto *Proto = Method->getType()->castAs<FunctionProtoType>(); 2048 1.1 joerg Proto->printExceptionSpecification(OS, Policy); 2049 1.1 joerg 2050 1.1 joerg // FIXME: Attributes 2051 1.1 joerg 2052 1.1 joerg // Print the trailing return type if it was specified in the source. 2053 1.1 joerg if (Node->hasExplicitResultType()) { 2054 1.1 joerg OS << " -> "; 2055 1.1 joerg Proto->getReturnType().print(OS, Policy); 2056 1.1 joerg } 2057 1.1 joerg } 2058 1.1 joerg 2059 1.1 joerg // Print the body. 2060 1.1 joerg OS << ' '; 2061 1.1 joerg if (Policy.TerseOutput) 2062 1.1 joerg OS << "{}"; 2063 1.1 joerg else 2064 1.1.1.2 joerg PrintRawCompoundStmt(Node->getCompoundStmtBody()); 2065 1.1 joerg } 2066 1.1 joerg 2067 1.1 joerg void StmtPrinter::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *Node) { 2068 1.1 joerg if (TypeSourceInfo *TSInfo = Node->getTypeSourceInfo()) 2069 1.1 joerg TSInfo->getType().print(OS, Policy); 2070 1.1 joerg else 2071 1.1 joerg Node->getType().print(OS, Policy); 2072 1.1 joerg OS << "()"; 2073 1.1 joerg } 2074 1.1 joerg 2075 1.1 joerg void StmtPrinter::VisitCXXNewExpr(CXXNewExpr *E) { 2076 1.1 joerg if (E->isGlobalNew()) 2077 1.1 joerg OS << "::"; 2078 1.1 joerg OS << "new "; 2079 1.1 joerg unsigned NumPlace = E->getNumPlacementArgs(); 2080 1.1 joerg if (NumPlace > 0 && !isa<CXXDefaultArgExpr>(E->getPlacementArg(0))) { 2081 1.1 joerg OS << "("; 2082 1.1 joerg PrintExpr(E->getPlacementArg(0)); 2083 1.1 joerg for (unsigned i = 1; i < NumPlace; ++i) { 2084 1.1 joerg if (isa<CXXDefaultArgExpr>(E->getPlacementArg(i))) 2085 1.1 joerg break; 2086 1.1 joerg OS << ", "; 2087 1.1 joerg PrintExpr(E->getPlacementArg(i)); 2088 1.1 joerg } 2089 1.1 joerg OS << ") "; 2090 1.1 joerg } 2091 1.1 joerg if (E->isParenTypeId()) 2092 1.1 joerg OS << "("; 2093 1.1 joerg std::string TypeS; 2094 1.1 joerg if (Optional<Expr *> Size = E->getArraySize()) { 2095 1.1 joerg llvm::raw_string_ostream s(TypeS); 2096 1.1 joerg s << '['; 2097 1.1 joerg if (*Size) 2098 1.1 joerg (*Size)->printPretty(s, Helper, Policy); 2099 1.1 joerg s << ']'; 2100 1.1 joerg } 2101 1.1 joerg E->getAllocatedType().print(OS, Policy, TypeS); 2102 1.1 joerg if (E->isParenTypeId()) 2103 1.1 joerg OS << ")"; 2104 1.1 joerg 2105 1.1 joerg CXXNewExpr::InitializationStyle InitStyle = E->getInitializationStyle(); 2106 1.1 joerg if (InitStyle) { 2107 1.1 joerg if (InitStyle == CXXNewExpr::CallInit) 2108 1.1 joerg OS << "("; 2109 1.1 joerg PrintExpr(E->getInitializer()); 2110 1.1 joerg if (InitStyle == CXXNewExpr::CallInit) 2111 1.1 joerg OS << ")"; 2112 1.1 joerg } 2113 1.1 joerg } 2114 1.1 joerg 2115 1.1 joerg void StmtPrinter::VisitCXXDeleteExpr(CXXDeleteExpr *E) { 2116 1.1 joerg if (E->isGlobalDelete()) 2117 1.1 joerg OS << "::"; 2118 1.1 joerg OS << "delete "; 2119 1.1 joerg if (E->isArrayForm()) 2120 1.1 joerg OS << "[] "; 2121 1.1 joerg PrintExpr(E->getArgument()); 2122 1.1 joerg } 2123 1.1 joerg 2124 1.1 joerg void StmtPrinter::VisitCXXPseudoDestructorExpr(CXXPseudoDestructorExpr *E) { 2125 1.1 joerg PrintExpr(E->getBase()); 2126 1.1 joerg if (E->isArrow()) 2127 1.1 joerg OS << "->"; 2128 1.1 joerg else 2129 1.1 joerg OS << '.'; 2130 1.1 joerg if (E->getQualifier()) 2131 1.1 joerg E->getQualifier()->print(OS, Policy); 2132 1.1 joerg OS << "~"; 2133 1.1 joerg 2134 1.1 joerg if (IdentifierInfo *II = E->getDestroyedTypeIdentifier()) 2135 1.1 joerg OS << II->getName(); 2136 1.1 joerg else 2137 1.1 joerg E->getDestroyedType().print(OS, Policy); 2138 1.1 joerg } 2139 1.1 joerg 2140 1.1 joerg void StmtPrinter::VisitCXXConstructExpr(CXXConstructExpr *E) { 2141 1.1 joerg if (E->isListInitialization() && !E->isStdInitListInitialization()) 2142 1.1 joerg OS << "{"; 2143 1.1 joerg 2144 1.1 joerg for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) { 2145 1.1 joerg if (isa<CXXDefaultArgExpr>(E->getArg(i))) { 2146 1.1 joerg // Don't print any defaulted arguments 2147 1.1 joerg break; 2148 1.1 joerg } 2149 1.1 joerg 2150 1.1 joerg if (i) OS << ", "; 2151 1.1 joerg PrintExpr(E->getArg(i)); 2152 1.1 joerg } 2153 1.1 joerg 2154 1.1 joerg if (E->isListInitialization() && !E->isStdInitListInitialization()) 2155 1.1 joerg OS << "}"; 2156 1.1 joerg } 2157 1.1 joerg 2158 1.1 joerg void StmtPrinter::VisitCXXInheritedCtorInitExpr(CXXInheritedCtorInitExpr *E) { 2159 1.1 joerg // Parens are printed by the surrounding context. 2160 1.1 joerg OS << "<forwarded>"; 2161 1.1 joerg } 2162 1.1 joerg 2163 1.1 joerg void StmtPrinter::VisitCXXStdInitializerListExpr(CXXStdInitializerListExpr *E) { 2164 1.1 joerg PrintExpr(E->getSubExpr()); 2165 1.1 joerg } 2166 1.1 joerg 2167 1.1 joerg void StmtPrinter::VisitExprWithCleanups(ExprWithCleanups *E) { 2168 1.1 joerg // Just forward to the subexpression. 2169 1.1 joerg PrintExpr(E->getSubExpr()); 2170 1.1 joerg } 2171 1.1 joerg 2172 1.1 joerg void 2173 1.1 joerg StmtPrinter::VisitCXXUnresolvedConstructExpr( 2174 1.1 joerg CXXUnresolvedConstructExpr *Node) { 2175 1.1 joerg Node->getTypeAsWritten().print(OS, Policy); 2176 1.1 joerg OS << "("; 2177 1.1 joerg for (CXXUnresolvedConstructExpr::arg_iterator Arg = Node->arg_begin(), 2178 1.1 joerg ArgEnd = Node->arg_end(); 2179 1.1 joerg Arg != ArgEnd; ++Arg) { 2180 1.1 joerg if (Arg != Node->arg_begin()) 2181 1.1 joerg OS << ", "; 2182 1.1 joerg PrintExpr(*Arg); 2183 1.1 joerg } 2184 1.1 joerg OS << ")"; 2185 1.1 joerg } 2186 1.1 joerg 2187 1.1 joerg void StmtPrinter::VisitCXXDependentScopeMemberExpr( 2188 1.1 joerg CXXDependentScopeMemberExpr *Node) { 2189 1.1 joerg if (!Node->isImplicitAccess()) { 2190 1.1 joerg PrintExpr(Node->getBase()); 2191 1.1 joerg OS << (Node->isArrow() ? "->" : "."); 2192 1.1 joerg } 2193 1.1 joerg if (NestedNameSpecifier *Qualifier = Node->getQualifier()) 2194 1.1 joerg Qualifier->print(OS, Policy); 2195 1.1 joerg if (Node->hasTemplateKeyword()) 2196 1.1 joerg OS << "template "; 2197 1.1 joerg OS << Node->getMemberNameInfo(); 2198 1.1 joerg if (Node->hasExplicitTemplateArgs()) 2199 1.1 joerg printTemplateArgumentList(OS, Node->template_arguments(), Policy); 2200 1.1 joerg } 2201 1.1 joerg 2202 1.1 joerg void StmtPrinter::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *Node) { 2203 1.1 joerg if (!Node->isImplicitAccess()) { 2204 1.1 joerg PrintExpr(Node->getBase()); 2205 1.1 joerg OS << (Node->isArrow() ? "->" : "."); 2206 1.1 joerg } 2207 1.1 joerg if (NestedNameSpecifier *Qualifier = Node->getQualifier()) 2208 1.1 joerg Qualifier->print(OS, Policy); 2209 1.1 joerg if (Node->hasTemplateKeyword()) 2210 1.1 joerg OS << "template "; 2211 1.1 joerg OS << Node->getMemberNameInfo(); 2212 1.1 joerg if (Node->hasExplicitTemplateArgs()) 2213 1.1 joerg printTemplateArgumentList(OS, Node->template_arguments(), Policy); 2214 1.1 joerg } 2215 1.1 joerg 2216 1.1 joerg void StmtPrinter::VisitTypeTraitExpr(TypeTraitExpr *E) { 2217 1.1.1.2 joerg OS << getTraitSpelling(E->getTrait()) << "("; 2218 1.1 joerg for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { 2219 1.1 joerg if (I > 0) 2220 1.1 joerg OS << ", "; 2221 1.1 joerg E->getArg(I)->getType().print(OS, Policy); 2222 1.1 joerg } 2223 1.1 joerg OS << ")"; 2224 1.1 joerg } 2225 1.1 joerg 2226 1.1 joerg void StmtPrinter::VisitArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { 2227 1.1.1.2 joerg OS << getTraitSpelling(E->getTrait()) << '('; 2228 1.1 joerg E->getQueriedType().print(OS, Policy); 2229 1.1 joerg OS << ')'; 2230 1.1 joerg } 2231 1.1 joerg 2232 1.1 joerg void StmtPrinter::VisitExpressionTraitExpr(ExpressionTraitExpr *E) { 2233 1.1.1.2 joerg OS << getTraitSpelling(E->getTrait()) << '('; 2234 1.1 joerg PrintExpr(E->getQueriedExpression()); 2235 1.1 joerg OS << ')'; 2236 1.1 joerg } 2237 1.1 joerg 2238 1.1 joerg void StmtPrinter::VisitCXXNoexceptExpr(CXXNoexceptExpr *E) { 2239 1.1 joerg OS << "noexcept("; 2240 1.1 joerg PrintExpr(E->getOperand()); 2241 1.1 joerg OS << ")"; 2242 1.1 joerg } 2243 1.1 joerg 2244 1.1 joerg void StmtPrinter::VisitPackExpansionExpr(PackExpansionExpr *E) { 2245 1.1 joerg PrintExpr(E->getPattern()); 2246 1.1 joerg OS << "..."; 2247 1.1 joerg } 2248 1.1 joerg 2249 1.1 joerg void StmtPrinter::VisitSizeOfPackExpr(SizeOfPackExpr *E) { 2250 1.1 joerg OS << "sizeof...(" << *E->getPack() << ")"; 2251 1.1 joerg } 2252 1.1 joerg 2253 1.1 joerg void StmtPrinter::VisitSubstNonTypeTemplateParmPackExpr( 2254 1.1 joerg SubstNonTypeTemplateParmPackExpr *Node) { 2255 1.1 joerg OS << *Node->getParameterPack(); 2256 1.1 joerg } 2257 1.1 joerg 2258 1.1 joerg void StmtPrinter::VisitSubstNonTypeTemplateParmExpr( 2259 1.1 joerg SubstNonTypeTemplateParmExpr *Node) { 2260 1.1 joerg Visit(Node->getReplacement()); 2261 1.1 joerg } 2262 1.1 joerg 2263 1.1 joerg void StmtPrinter::VisitFunctionParmPackExpr(FunctionParmPackExpr *E) { 2264 1.1 joerg OS << *E->getParameterPack(); 2265 1.1 joerg } 2266 1.1 joerg 2267 1.1 joerg void StmtPrinter::VisitMaterializeTemporaryExpr(MaterializeTemporaryExpr *Node){ 2268 1.1.1.2 joerg PrintExpr(Node->getSubExpr()); 2269 1.1 joerg } 2270 1.1 joerg 2271 1.1 joerg void StmtPrinter::VisitCXXFoldExpr(CXXFoldExpr *E) { 2272 1.1 joerg OS << "("; 2273 1.1 joerg if (E->getLHS()) { 2274 1.1 joerg PrintExpr(E->getLHS()); 2275 1.1 joerg OS << " " << BinaryOperator::getOpcodeStr(E->getOperator()) << " "; 2276 1.1 joerg } 2277 1.1 joerg OS << "..."; 2278 1.1 joerg if (E->getRHS()) { 2279 1.1 joerg OS << " " << BinaryOperator::getOpcodeStr(E->getOperator()) << " "; 2280 1.1 joerg PrintExpr(E->getRHS()); 2281 1.1 joerg } 2282 1.1 joerg OS << ")"; 2283 1.1 joerg } 2284 1.1 joerg 2285 1.1 joerg void StmtPrinter::VisitConceptSpecializationExpr(ConceptSpecializationExpr *E) { 2286 1.1 joerg NestedNameSpecifierLoc NNS = E->getNestedNameSpecifierLoc(); 2287 1.1 joerg if (NNS) 2288 1.1 joerg NNS.getNestedNameSpecifier()->print(OS, Policy); 2289 1.1 joerg if (E->getTemplateKWLoc().isValid()) 2290 1.1 joerg OS << "template "; 2291 1.1 joerg OS << E->getFoundDecl()->getName(); 2292 1.1 joerg printTemplateArgumentList(OS, E->getTemplateArgsAsWritten()->arguments(), 2293 1.1.1.2 joerg Policy, 2294 1.1.1.2 joerg E->getNamedConcept()->getTemplateParameters()); 2295 1.1.1.2 joerg } 2296 1.1.1.2 joerg 2297 1.1.1.2 joerg void StmtPrinter::VisitRequiresExpr(RequiresExpr *E) { 2298 1.1.1.2 joerg OS << "requires "; 2299 1.1.1.2 joerg auto LocalParameters = E->getLocalParameters(); 2300 1.1.1.2 joerg if (!LocalParameters.empty()) { 2301 1.1.1.2 joerg OS << "("; 2302 1.1.1.2 joerg for (ParmVarDecl *LocalParam : LocalParameters) { 2303 1.1.1.2 joerg PrintRawDecl(LocalParam); 2304 1.1.1.2 joerg if (LocalParam != LocalParameters.back()) 2305 1.1.1.2 joerg OS << ", "; 2306 1.1.1.2 joerg } 2307 1.1.1.2 joerg 2308 1.1.1.2 joerg OS << ") "; 2309 1.1.1.2 joerg } 2310 1.1.1.2 joerg OS << "{ "; 2311 1.1.1.2 joerg auto Requirements = E->getRequirements(); 2312 1.1.1.2 joerg for (concepts::Requirement *Req : Requirements) { 2313 1.1.1.2 joerg if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) { 2314 1.1.1.2 joerg if (TypeReq->isSubstitutionFailure()) 2315 1.1.1.2 joerg OS << "<<error-type>>"; 2316 1.1.1.2 joerg else 2317 1.1.1.2 joerg TypeReq->getType()->getType().print(OS, Policy); 2318 1.1.1.2 joerg } else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) { 2319 1.1.1.2 joerg if (ExprReq->isCompound()) 2320 1.1.1.2 joerg OS << "{ "; 2321 1.1.1.2 joerg if (ExprReq->isExprSubstitutionFailure()) 2322 1.1.1.2 joerg OS << "<<error-expression>>"; 2323 1.1.1.2 joerg else 2324 1.1.1.2 joerg PrintExpr(ExprReq->getExpr()); 2325 1.1.1.2 joerg if (ExprReq->isCompound()) { 2326 1.1.1.2 joerg OS << " }"; 2327 1.1.1.2 joerg if (ExprReq->getNoexceptLoc().isValid()) 2328 1.1.1.2 joerg OS << " noexcept"; 2329 1.1.1.2 joerg const auto &RetReq = ExprReq->getReturnTypeRequirement(); 2330 1.1.1.2 joerg if (!RetReq.isEmpty()) { 2331 1.1.1.2 joerg OS << " -> "; 2332 1.1.1.2 joerg if (RetReq.isSubstitutionFailure()) 2333 1.1.1.2 joerg OS << "<<error-type>>"; 2334 1.1.1.2 joerg else if (RetReq.isTypeConstraint()) 2335 1.1.1.2 joerg RetReq.getTypeConstraint()->print(OS, Policy); 2336 1.1.1.2 joerg } 2337 1.1.1.2 joerg } 2338 1.1.1.2 joerg } else { 2339 1.1.1.2 joerg auto *NestedReq = cast<concepts::NestedRequirement>(Req); 2340 1.1.1.2 joerg OS << "requires "; 2341 1.1.1.2 joerg if (NestedReq->isSubstitutionFailure()) 2342 1.1.1.2 joerg OS << "<<error-expression>>"; 2343 1.1.1.2 joerg else 2344 1.1.1.2 joerg PrintExpr(NestedReq->getConstraintExpr()); 2345 1.1.1.2 joerg } 2346 1.1.1.2 joerg OS << "; "; 2347 1.1.1.2 joerg } 2348 1.1.1.2 joerg OS << "}"; 2349 1.1 joerg } 2350 1.1 joerg 2351 1.1 joerg // C++ Coroutines TS 2352 1.1 joerg 2353 1.1 joerg void StmtPrinter::VisitCoroutineBodyStmt(CoroutineBodyStmt *S) { 2354 1.1 joerg Visit(S->getBody()); 2355 1.1 joerg } 2356 1.1 joerg 2357 1.1 joerg void StmtPrinter::VisitCoreturnStmt(CoreturnStmt *S) { 2358 1.1 joerg OS << "co_return"; 2359 1.1 joerg if (S->getOperand()) { 2360 1.1 joerg OS << " "; 2361 1.1 joerg Visit(S->getOperand()); 2362 1.1 joerg } 2363 1.1 joerg OS << ";"; 2364 1.1 joerg } 2365 1.1 joerg 2366 1.1 joerg void StmtPrinter::VisitCoawaitExpr(CoawaitExpr *S) { 2367 1.1 joerg OS << "co_await "; 2368 1.1 joerg PrintExpr(S->getOperand()); 2369 1.1 joerg } 2370 1.1 joerg 2371 1.1 joerg void StmtPrinter::VisitDependentCoawaitExpr(DependentCoawaitExpr *S) { 2372 1.1 joerg OS << "co_await "; 2373 1.1 joerg PrintExpr(S->getOperand()); 2374 1.1 joerg } 2375 1.1 joerg 2376 1.1 joerg void StmtPrinter::VisitCoyieldExpr(CoyieldExpr *S) { 2377 1.1 joerg OS << "co_yield "; 2378 1.1 joerg PrintExpr(S->getOperand()); 2379 1.1 joerg } 2380 1.1 joerg 2381 1.1 joerg // Obj-C 2382 1.1 joerg 2383 1.1 joerg void StmtPrinter::VisitObjCStringLiteral(ObjCStringLiteral *Node) { 2384 1.1 joerg OS << "@"; 2385 1.1 joerg VisitStringLiteral(Node->getString()); 2386 1.1 joerg } 2387 1.1 joerg 2388 1.1 joerg void StmtPrinter::VisitObjCBoxedExpr(ObjCBoxedExpr *E) { 2389 1.1 joerg OS << "@"; 2390 1.1 joerg Visit(E->getSubExpr()); 2391 1.1 joerg } 2392 1.1 joerg 2393 1.1 joerg void StmtPrinter::VisitObjCArrayLiteral(ObjCArrayLiteral *E) { 2394 1.1 joerg OS << "@[ "; 2395 1.1 joerg ObjCArrayLiteral::child_range Ch = E->children(); 2396 1.1 joerg for (auto I = Ch.begin(), E = Ch.end(); I != E; ++I) { 2397 1.1 joerg if (I != Ch.begin()) 2398 1.1 joerg OS << ", "; 2399 1.1 joerg Visit(*I); 2400 1.1 joerg } 2401 1.1 joerg OS << " ]"; 2402 1.1 joerg } 2403 1.1 joerg 2404 1.1 joerg void StmtPrinter::VisitObjCDictionaryLiteral(ObjCDictionaryLiteral *E) { 2405 1.1 joerg OS << "@{ "; 2406 1.1 joerg for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { 2407 1.1 joerg if (I > 0) 2408 1.1 joerg OS << ", "; 2409 1.1 joerg 2410 1.1 joerg ObjCDictionaryElement Element = E->getKeyValueElement(I); 2411 1.1 joerg Visit(Element.Key); 2412 1.1 joerg OS << " : "; 2413 1.1 joerg Visit(Element.Value); 2414 1.1 joerg if (Element.isPackExpansion()) 2415 1.1 joerg OS << "..."; 2416 1.1 joerg } 2417 1.1 joerg OS << " }"; 2418 1.1 joerg } 2419 1.1 joerg 2420 1.1 joerg void StmtPrinter::VisitObjCEncodeExpr(ObjCEncodeExpr *Node) { 2421 1.1 joerg OS << "@encode("; 2422 1.1 joerg Node->getEncodedType().print(OS, Policy); 2423 1.1 joerg OS << ')'; 2424 1.1 joerg } 2425 1.1 joerg 2426 1.1 joerg void StmtPrinter::VisitObjCSelectorExpr(ObjCSelectorExpr *Node) { 2427 1.1 joerg OS << "@selector("; 2428 1.1 joerg Node->getSelector().print(OS); 2429 1.1 joerg OS << ')'; 2430 1.1 joerg } 2431 1.1 joerg 2432 1.1 joerg void StmtPrinter::VisitObjCProtocolExpr(ObjCProtocolExpr *Node) { 2433 1.1 joerg OS << "@protocol(" << *Node->getProtocol() << ')'; 2434 1.1 joerg } 2435 1.1 joerg 2436 1.1 joerg void StmtPrinter::VisitObjCMessageExpr(ObjCMessageExpr *Mess) { 2437 1.1 joerg OS << "["; 2438 1.1 joerg switch (Mess->getReceiverKind()) { 2439 1.1 joerg case ObjCMessageExpr::Instance: 2440 1.1 joerg PrintExpr(Mess->getInstanceReceiver()); 2441 1.1 joerg break; 2442 1.1 joerg 2443 1.1 joerg case ObjCMessageExpr::Class: 2444 1.1 joerg Mess->getClassReceiver().print(OS, Policy); 2445 1.1 joerg break; 2446 1.1 joerg 2447 1.1 joerg case ObjCMessageExpr::SuperInstance: 2448 1.1 joerg case ObjCMessageExpr::SuperClass: 2449 1.1 joerg OS << "Super"; 2450 1.1 joerg break; 2451 1.1 joerg } 2452 1.1 joerg 2453 1.1 joerg OS << ' '; 2454 1.1 joerg Selector selector = Mess->getSelector(); 2455 1.1 joerg if (selector.isUnarySelector()) { 2456 1.1 joerg OS << selector.getNameForSlot(0); 2457 1.1 joerg } else { 2458 1.1 joerg for (unsigned i = 0, e = Mess->getNumArgs(); i != e; ++i) { 2459 1.1 joerg if (i < selector.getNumArgs()) { 2460 1.1 joerg if (i > 0) OS << ' '; 2461 1.1 joerg if (selector.getIdentifierInfoForSlot(i)) 2462 1.1 joerg OS << selector.getIdentifierInfoForSlot(i)->getName() << ':'; 2463 1.1 joerg else 2464 1.1 joerg OS << ":"; 2465 1.1 joerg } 2466 1.1 joerg else OS << ", "; // Handle variadic methods. 2467 1.1 joerg 2468 1.1 joerg PrintExpr(Mess->getArg(i)); 2469 1.1 joerg } 2470 1.1 joerg } 2471 1.1 joerg OS << "]"; 2472 1.1 joerg } 2473 1.1 joerg 2474 1.1 joerg void StmtPrinter::VisitObjCBoolLiteralExpr(ObjCBoolLiteralExpr *Node) { 2475 1.1 joerg OS << (Node->getValue() ? "__objc_yes" : "__objc_no"); 2476 1.1 joerg } 2477 1.1 joerg 2478 1.1 joerg void 2479 1.1 joerg StmtPrinter::VisitObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { 2480 1.1 joerg PrintExpr(E->getSubExpr()); 2481 1.1 joerg } 2482 1.1 joerg 2483 1.1 joerg void 2484 1.1 joerg StmtPrinter::VisitObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { 2485 1.1 joerg OS << '(' << E->getBridgeKindName(); 2486 1.1 joerg E->getType().print(OS, Policy); 2487 1.1 joerg OS << ')'; 2488 1.1 joerg PrintExpr(E->getSubExpr()); 2489 1.1 joerg } 2490 1.1 joerg 2491 1.1 joerg void StmtPrinter::VisitBlockExpr(BlockExpr *Node) { 2492 1.1 joerg BlockDecl *BD = Node->getBlockDecl(); 2493 1.1 joerg OS << "^"; 2494 1.1 joerg 2495 1.1 joerg const FunctionType *AFT = Node->getFunctionType(); 2496 1.1 joerg 2497 1.1 joerg if (isa<FunctionNoProtoType>(AFT)) { 2498 1.1 joerg OS << "()"; 2499 1.1 joerg } else if (!BD->param_empty() || cast<FunctionProtoType>(AFT)->isVariadic()) { 2500 1.1 joerg OS << '('; 2501 1.1 joerg for (BlockDecl::param_iterator AI = BD->param_begin(), 2502 1.1 joerg E = BD->param_end(); AI != E; ++AI) { 2503 1.1 joerg if (AI != BD->param_begin()) OS << ", "; 2504 1.1 joerg std::string ParamStr = (*AI)->getNameAsString(); 2505 1.1 joerg (*AI)->getType().print(OS, Policy, ParamStr); 2506 1.1 joerg } 2507 1.1 joerg 2508 1.1 joerg const auto *FT = cast<FunctionProtoType>(AFT); 2509 1.1 joerg if (FT->isVariadic()) { 2510 1.1 joerg if (!BD->param_empty()) OS << ", "; 2511 1.1 joerg OS << "..."; 2512 1.1 joerg } 2513 1.1 joerg OS << ')'; 2514 1.1 joerg } 2515 1.1 joerg OS << "{ }"; 2516 1.1 joerg } 2517 1.1 joerg 2518 1.1 joerg void StmtPrinter::VisitOpaqueValueExpr(OpaqueValueExpr *Node) { 2519 1.1 joerg PrintExpr(Node->getSourceExpr()); 2520 1.1 joerg } 2521 1.1 joerg 2522 1.1 joerg void StmtPrinter::VisitTypoExpr(TypoExpr *Node) { 2523 1.1 joerg // TODO: Print something reasonable for a TypoExpr, if necessary. 2524 1.1 joerg llvm_unreachable("Cannot print TypoExpr nodes"); 2525 1.1 joerg } 2526 1.1 joerg 2527 1.1.1.2 joerg void StmtPrinter::VisitRecoveryExpr(RecoveryExpr *Node) { 2528 1.1.1.2 joerg OS << "<recovery-expr>("; 2529 1.1.1.2 joerg const char *Sep = ""; 2530 1.1.1.2 joerg for (Expr *E : Node->subExpressions()) { 2531 1.1.1.2 joerg OS << Sep; 2532 1.1.1.2 joerg PrintExpr(E); 2533 1.1.1.2 joerg Sep = ", "; 2534 1.1.1.2 joerg } 2535 1.1.1.2 joerg OS << ')'; 2536 1.1.1.2 joerg } 2537 1.1.1.2 joerg 2538 1.1 joerg void StmtPrinter::VisitAsTypeExpr(AsTypeExpr *Node) { 2539 1.1 joerg OS << "__builtin_astype("; 2540 1.1 joerg PrintExpr(Node->getSrcExpr()); 2541 1.1 joerg OS << ", "; 2542 1.1 joerg Node->getType().print(OS, Policy); 2543 1.1 joerg OS << ")"; 2544 1.1 joerg } 2545 1.1 joerg 2546 1.1 joerg //===----------------------------------------------------------------------===// 2547 1.1 joerg // Stmt method implementations 2548 1.1 joerg //===----------------------------------------------------------------------===// 2549 1.1 joerg 2550 1.1 joerg void Stmt::dumpPretty(const ASTContext &Context) const { 2551 1.1 joerg printPretty(llvm::errs(), nullptr, PrintingPolicy(Context.getLangOpts())); 2552 1.1 joerg } 2553 1.1 joerg 2554 1.1 joerg void Stmt::printPretty(raw_ostream &Out, PrinterHelper *Helper, 2555 1.1 joerg const PrintingPolicy &Policy, unsigned Indentation, 2556 1.1 joerg StringRef NL, const ASTContext *Context) const { 2557 1.1 joerg StmtPrinter P(Out, Helper, Policy, Indentation, NL, Context); 2558 1.1 joerg P.Visit(const_cast<Stmt *>(this)); 2559 1.1 joerg } 2560 1.1 joerg 2561 1.1 joerg void Stmt::printJson(raw_ostream &Out, PrinterHelper *Helper, 2562 1.1 joerg const PrintingPolicy &Policy, bool AddQuotes) const { 2563 1.1 joerg std::string Buf; 2564 1.1 joerg llvm::raw_string_ostream TempOut(Buf); 2565 1.1 joerg 2566 1.1 joerg printPretty(TempOut, Helper, Policy); 2567 1.1 joerg 2568 1.1 joerg Out << JsonFormat(TempOut.str(), AddQuotes); 2569 1.1 joerg } 2570 1.1 joerg 2571 1.1 joerg //===----------------------------------------------------------------------===// 2572 1.1 joerg // PrinterHelper 2573 1.1 joerg //===----------------------------------------------------------------------===// 2574 1.1 joerg 2575 1.1 joerg // Implement virtual destructor. 2576 1.1 joerg PrinterHelper::~PrinterHelper() = default; 2577