| ... | ... | @@ -6,8 +6,10 @@ |
| 6 | 6 | // |
| 7 | 7 | //===----------------------------------------------------------------------===// |
| 8 | 8 | // |
| 9 | | // Generic itanium demangler library. This file has two byte-per-byte identical |
| 10 | | // copies in the source tree, one in libcxxabi, and the other in llvm. |
| 9 | // Generic itanium demangler library. |
| 10 | // There are two copies of this file in the source tree. The one under |
| 11 | // libcxxabi is the original and the one under llvm is the copy. Use |
| 12 | // cp-to-llvm.sh to update the copy. See README.txt for more details. |
| 11 | 13 | // |
| 12 | 14 | //===----------------------------------------------------------------------===// |
| 13 | 15 | |
| ... | ... | @@ -21,12 +23,13 @@ |
| 21 | 23 | #include "DemangleConfig.h" |
| 22 | 24 | #include "StringView.h" |
| 23 | 25 | #include "Utility.h" |
| 26 | #include <algorithm> |
| 24 | 27 | #include <cassert> |
| 25 | 28 | #include <cctype> |
| 26 | 29 | #include <cstdio> |
| 27 | 30 | #include <cstdlib> |
| 28 | 31 | #include <cstring> |
| 29 | | #include <numeric> |
| 32 | #include <limits> |
| 30 | 33 | #include <utility> |
| 31 | 34 | |
| 32 | 35 | #define FOR_EACH_NODE_KIND(X) \ |
| ... | ... | @@ -57,6 +60,7 @@ |
| 57 | 60 | X(LocalName) \ |
| 58 | 61 | X(VectorType) \ |
| 59 | 62 | X(PixelVectorType) \ |
| 63 | X(BinaryFPType) \ |
| 60 | 64 | X(SyntheticTemplateParamName) \ |
| 61 | 65 | X(TypeTemplateParamDecl) \ |
| 62 | 66 | X(NonTypeTemplateParamDecl) \ |
| ... | ... | @@ -109,6 +113,126 @@ |
| 109 | 113 | |
| 110 | 114 | DEMANGLE_NAMESPACE_BEGIN |
| 111 | 115 | |
| 116 | template <class T, size_t N> class PODSmallVector { |
| 117 | static_assert(std::is_pod<T>::value, |
| 118 | "T is required to be a plain old data type"); |
| 119 | |
| 120 | T *First = nullptr; |
| 121 | T *Last = nullptr; |
| 122 | T *Cap = nullptr; |
| 123 | T Inline[N] = {0}; |
| 124 | |
| 125 | bool isInline() const { return First == Inline; } |
| 126 | |
| 127 | void clearInline() { |
| 128 | First = Inline; |
| 129 | Last = Inline; |
| 130 | Cap = Inline + N; |
| 131 | } |
| 132 | |
| 133 | void reserve(size_t NewCap) { |
| 134 | size_t S = size(); |
| 135 | if (isInline()) { |
| 136 | auto *Tmp = static_cast<T *>(std::malloc(NewCap * sizeof(T))); |
| 137 | if (Tmp == nullptr) |
| 138 | std::terminate(); |
| 139 | std::copy(First, Last, Tmp); |
| 140 | First = Tmp; |
| 141 | } else { |
| 142 | First = static_cast<T *>(std::realloc(First, NewCap * sizeof(T))); |
| 143 | if (First == nullptr) |
| 144 | std::terminate(); |
| 145 | } |
| 146 | Last = First + S; |
| 147 | Cap = First + NewCap; |
| 148 | } |
| 149 | |
| 150 | public: |
| 151 | PODSmallVector() : First(Inline), Last(First), Cap(Inline + N) {} |
| 152 | |
| 153 | PODSmallVector(const PODSmallVector &) = delete; |
| 154 | PODSmallVector &operator=(const PODSmallVector &) = delete; |
| 155 | |
| 156 | PODSmallVector(PODSmallVector &&Other) : PODSmallVector() { |
| 157 | if (Other.isInline()) { |
| 158 | std::copy(Other.begin(), Other.end(), First); |
| 159 | Last = First + Other.size(); |
| 160 | Other.clear(); |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | First = Other.First; |
| 165 | Last = Other.Last; |
| 166 | Cap = Other.Cap; |
| 167 | Other.clearInline(); |
| 168 | } |
| 169 | |
| 170 | PODSmallVector &operator=(PODSmallVector &&Other) { |
| 171 | if (Other.isInline()) { |
| 172 | if (!isInline()) { |
| 173 | std::free(First); |
| 174 | clearInline(); |
| 175 | } |
| 176 | std::copy(Other.begin(), Other.end(), First); |
| 177 | Last = First + Other.size(); |
| 178 | Other.clear(); |
| 179 | return *this; |
| 180 | } |
| 181 | |
| 182 | if (isInline()) { |
| 183 | First = Other.First; |
| 184 | Last = Other.Last; |
| 185 | Cap = Other.Cap; |
| 186 | Other.clearInline(); |
| 187 | return *this; |
| 188 | } |
| 189 | |
| 190 | std::swap(First, Other.First); |
| 191 | std::swap(Last, Other.Last); |
| 192 | std::swap(Cap, Other.Cap); |
| 193 | Other.clear(); |
| 194 | return *this; |
| 195 | } |
| 196 | |
| 197 | // NOLINTNEXTLINE(readability-identifier-naming) |
| 198 | void push_back(const T &Elem) { |
| 199 | if (Last == Cap) |
| 200 | reserve(size() * 2); |
| 201 | *Last++ = Elem; |
| 202 | } |
| 203 | |
| 204 | // NOLINTNEXTLINE(readability-identifier-naming) |
| 205 | void pop_back() { |
| 206 | assert(Last != First && "Popping empty vector!"); |
| 207 | --Last; |
| 208 | } |
| 209 | |
| 210 | void dropBack(size_t Index) { |
| 211 | assert(Index <= size() && "dropBack() can't expand!"); |
| 212 | Last = First + Index; |
| 213 | } |
| 214 | |
| 215 | T *begin() { return First; } |
| 216 | T *end() { return Last; } |
| 217 | |
| 218 | bool empty() const { return First == Last; } |
| 219 | size_t size() const { return static_cast<size_t>(Last - First); } |
| 220 | T &back() { |
| 221 | assert(Last != First && "Calling back() on empty vector!"); |
| 222 | return *(Last - 1); |
| 223 | } |
| 224 | T &operator[](size_t Index) { |
| 225 | assert(Index < size() && "Invalid access!"); |
| 226 | return *(begin() + Index); |
| 227 | } |
| 228 | void clear() { Last = First; } |
| 229 | |
| 230 | ~PODSmallVector() { |
| 231 | if (!isInline()) |
| 232 | std::free(First); |
| 233 | } |
| 234 | }; |
| 235 | |
| 112 | 236 | // Base class of all AST nodes. The AST is built by the parser, then is |
| 113 | 237 | // traversed by the printLeft/Right functions to produce a demangled string. |
| 114 | 238 | class Node { |
| ... | ... | @@ -155,50 +279,48 @@ public: |
| 155 | 279 | // would construct an equivalent node. |
| 156 | 280 | //template<typename Fn> void match(Fn F) const; |
| 157 | 281 | |
| 158 | | bool hasRHSComponent(OutputStream &S) const { |
| 282 | bool hasRHSComponent(OutputBuffer &OB) const { |
| 159 | 283 | if (RHSComponentCache != Cache::Unknown) |
| 160 | 284 | return RHSComponentCache == Cache::Yes; |
| 161 | | return hasRHSComponentSlow(S); |
| 285 | return hasRHSComponentSlow(OB); |
| 162 | 286 | } |
| 163 | 287 | |
| 164 | | bool hasArray(OutputStream &S) const { |
| 288 | bool hasArray(OutputBuffer &OB) const { |
| 165 | 289 | if (ArrayCache != Cache::Unknown) |
| 166 | 290 | return ArrayCache == Cache::Yes; |
| 167 | | return hasArraySlow(S); |
| 291 | return hasArraySlow(OB); |
| 168 | 292 | } |
| 169 | 293 | |
| 170 | | bool hasFunction(OutputStream &S) const { |
| 294 | bool hasFunction(OutputBuffer &OB) const { |
| 171 | 295 | if (FunctionCache != Cache::Unknown) |
| 172 | 296 | return FunctionCache == Cache::Yes; |
| 173 | | return hasFunctionSlow(S); |
| 297 | return hasFunctionSlow(OB); |
| 174 | 298 | } |
| 175 | 299 | |
| 176 | 300 | Kind getKind() const { return K; } |
| 177 | 301 | |
| 178 | | virtual bool hasRHSComponentSlow(OutputStream &) const { return false; } |
| 179 | | virtual bool hasArraySlow(OutputStream &) const { return false; } |
| 180 | | virtual bool hasFunctionSlow(OutputStream &) const { return false; } |
| 302 | virtual bool hasRHSComponentSlow(OutputBuffer &) const { return false; } |
| 303 | virtual bool hasArraySlow(OutputBuffer &) const { return false; } |
| 304 | virtual bool hasFunctionSlow(OutputBuffer &) const { return false; } |
| 181 | 305 | |
| 182 | 306 | // Dig through "glue" nodes like ParameterPack and ForwardTemplateReference to |
| 183 | 307 | // get at a node that actually represents some concrete syntax. |
| 184 | | virtual const Node *getSyntaxNode(OutputStream &) const { |
| 185 | | return this; |
| 186 | | } |
| 308 | virtual const Node *getSyntaxNode(OutputBuffer &) const { return this; } |
| 187 | 309 | |
| 188 | | void print(OutputStream &S) const { |
| 189 | | printLeft(S); |
| 310 | void print(OutputBuffer &OB) const { |
| 311 | printLeft(OB); |
| 190 | 312 | if (RHSComponentCache != Cache::No) |
| 191 | | printRight(S); |
| 313 | printRight(OB); |
| 192 | 314 | } |
| 193 | 315 | |
| 194 | | // Print the "left" side of this Node into OutputStream. |
| 195 | | virtual void printLeft(OutputStream &) const = 0; |
| 316 | // Print the "left" side of this Node into OutputBuffer. |
| 317 | virtual void printLeft(OutputBuffer &) const = 0; |
| 196 | 318 | |
| 197 | 319 | // Print the "right". This distinction is necessary to represent C++ types |
| 198 | 320 | // that appear on the RHS of their subtype, such as arrays or functions. |
| 199 | 321 | // Since most types don't have such a component, provide a default |
| 200 | 322 | // implementation. |
| 201 | | virtual void printRight(OutputStream &) const {} |
| 323 | virtual void printRight(OutputBuffer &) const {} |
| 202 | 324 | |
| 203 | 325 | virtual StringView getBaseName() const { return StringView(); } |
| 204 | 326 | |
| ... | ... | @@ -227,19 +349,19 @@ public: |
| 227 | 349 | |
| 228 | 350 | Node *operator[](size_t Idx) const { return Elements[Idx]; } |
| 229 | 351 | |
| 230 | | void printWithComma(OutputStream &S) const { |
| 352 | void printWithComma(OutputBuffer &OB) const { |
| 231 | 353 | bool FirstElement = true; |
| 232 | 354 | for (size_t Idx = 0; Idx != NumElements; ++Idx) { |
| 233 | | size_t BeforeComma = S.getCurrentPosition(); |
| 355 | size_t BeforeComma = OB.getCurrentPosition(); |
| 234 | 356 | if (!FirstElement) |
| 235 | | S += ", "; |
| 236 | | size_t AfterComma = S.getCurrentPosition(); |
| 237 | | Elements[Idx]->print(S); |
| 357 | OB += ", "; |
| 358 | size_t AfterComma = OB.getCurrentPosition(); |
| 359 | Elements[Idx]->print(OB); |
| 238 | 360 | |
| 239 | 361 | // Elements[Idx] is an empty parameter pack expansion, we should erase the |
| 240 | 362 | // comma we just printed. |
| 241 | | if (AfterComma == S.getCurrentPosition()) { |
| 242 | | S.setCurrentPosition(BeforeComma); |
| 363 | if (AfterComma == OB.getCurrentPosition()) { |
| 364 | OB.setCurrentPosition(BeforeComma); |
| 243 | 365 | continue; |
| 244 | 366 | } |
| 245 | 367 | |
| ... | ... | @@ -254,9 +376,7 @@ struct NodeArrayNode : Node { |
| 254 | 376 | |
| 255 | 377 | template<typename Fn> void match(Fn F) const { F(Array); } |
| 256 | 378 | |
| 257 | | void printLeft(OutputStream &S) const override { |
| 258 | | Array.printWithComma(S); |
| 259 | | } |
| 379 | void printLeft(OutputBuffer &OB) const override { Array.printWithComma(OB); } |
| 260 | 380 | }; |
| 261 | 381 | |
| 262 | 382 | class DotSuffix final : public Node { |
| ... | ... | @@ -269,11 +389,11 @@ public: |
| 269 | 389 | |
| 270 | 390 | template<typename Fn> void match(Fn F) const { F(Prefix, Suffix); } |
| 271 | 391 | |
| 272 | | void printLeft(OutputStream &s) const override { |
| 273 | | Prefix->print(s); |
| 274 | | s += " ("; |
| 275 | | s += Suffix; |
| 276 | | s += ")"; |
| 392 | void printLeft(OutputBuffer &OB) const override { |
| 393 | Prefix->print(OB); |
| 394 | OB += " ("; |
| 395 | OB += Suffix; |
| 396 | OB += ")"; |
| 277 | 397 | } |
| 278 | 398 | }; |
| 279 | 399 | |
| ... | ... | @@ -288,12 +408,12 @@ public: |
| 288 | 408 | |
| 289 | 409 | template <typename Fn> void match(Fn F) const { F(Ty, Ext, TA); } |
| 290 | 410 | |
| 291 | | void printLeft(OutputStream &S) const override { |
| 292 | | Ty->print(S); |
| 293 | | S += " "; |
| 294 | | S += Ext; |
| 411 | void printLeft(OutputBuffer &OB) const override { |
| 412 | Ty->print(OB); |
| 413 | OB += " "; |
| 414 | OB += Ext; |
| 295 | 415 | if (TA != nullptr) |
| 296 | | TA->print(S); |
| 416 | TA->print(OB); |
| 297 | 417 | } |
| 298 | 418 | }; |
| 299 | 419 | |
| ... | ... | @@ -319,13 +439,13 @@ protected: |
| 319 | 439 | const Qualifiers Quals; |
| 320 | 440 | const Node *Child; |
| 321 | 441 | |
| 322 | | void printQuals(OutputStream &S) const { |
| 442 | void printQuals(OutputBuffer &OB) const { |
| 323 | 443 | if (Quals & QualConst) |
| 324 | | S += " const"; |
| 444 | OB += " const"; |
| 325 | 445 | if (Quals & QualVolatile) |
| 326 | | S += " volatile"; |
| 446 | OB += " volatile"; |
| 327 | 447 | if (Quals & QualRestrict) |
| 328 | | S += " restrict"; |
| 448 | OB += " restrict"; |
| 329 | 449 | } |
| 330 | 450 | |
| 331 | 451 | public: |
| ... | ... | @@ -336,22 +456,22 @@ public: |
| 336 | 456 | |
| 337 | 457 | template<typename Fn> void match(Fn F) const { F(Child, Quals); } |
| 338 | 458 | |
| 339 | | bool hasRHSComponentSlow(OutputStream &S) const override { |
| 340 | | return Child->hasRHSComponent(S); |
| 459 | bool hasRHSComponentSlow(OutputBuffer &OB) const override { |
| 460 | return Child->hasRHSComponent(OB); |
| 341 | 461 | } |
| 342 | | bool hasArraySlow(OutputStream &S) const override { |
| 343 | | return Child->hasArray(S); |
| 462 | bool hasArraySlow(OutputBuffer &OB) const override { |
| 463 | return Child->hasArray(OB); |
| 344 | 464 | } |
| 345 | | bool hasFunctionSlow(OutputStream &S) const override { |
| 346 | | return Child->hasFunction(S); |
| 465 | bool hasFunctionSlow(OutputBuffer &OB) const override { |
| 466 | return Child->hasFunction(OB); |
| 347 | 467 | } |
| 348 | 468 | |
| 349 | | void printLeft(OutputStream &S) const override { |
| 350 | | Child->printLeft(S); |
| 351 | | printQuals(S); |
| 469 | void printLeft(OutputBuffer &OB) const override { |
| 470 | Child->printLeft(OB); |
| 471 | printQuals(OB); |
| 352 | 472 | } |
| 353 | 473 | |
| 354 | | void printRight(OutputStream &S) const override { Child->printRight(S); } |
| 474 | void printRight(OutputBuffer &OB) const override { Child->printRight(OB); } |
| 355 | 475 | }; |
| 356 | 476 | |
| 357 | 477 | class ConversionOperatorType final : public Node { |
| ... | ... | @@ -363,9 +483,9 @@ public: |
| 363 | 483 | |
| 364 | 484 | template<typename Fn> void match(Fn F) const { F(Ty); } |
| 365 | 485 | |
| 366 | | void printLeft(OutputStream &S) const override { |
| 367 | | S += "operator "; |
| 368 | | Ty->print(S); |
| 486 | void printLeft(OutputBuffer &OB) const override { |
| 487 | OB += "operator "; |
| 488 | Ty->print(OB); |
| 369 | 489 | } |
| 370 | 490 | }; |
| 371 | 491 | |
| ... | ... | @@ -379,9 +499,9 @@ public: |
| 379 | 499 | |
| 380 | 500 | template<typename Fn> void match(Fn F) const { F(Ty, Postfix); } |
| 381 | 501 | |
| 382 | | void printLeft(OutputStream &s) const override { |
| 383 | | Ty->printLeft(s); |
| 384 | | s += Postfix; |
| 502 | void printLeft(OutputBuffer &OB) const override { |
| 503 | Ty->printLeft(OB); |
| 504 | OB += Postfix; |
| 385 | 505 | } |
| 386 | 506 | }; |
| 387 | 507 | |
| ... | ... | @@ -396,7 +516,7 @@ public: |
| 396 | 516 | StringView getName() const { return Name; } |
| 397 | 517 | StringView getBaseName() const override { return Name; } |
| 398 | 518 | |
| 399 | | void printLeft(OutputStream &s) const override { s += Name; } |
| 519 | void printLeft(OutputBuffer &OB) const override { OB += Name; } |
| 400 | 520 | }; |
| 401 | 521 | |
| 402 | 522 | class ElaboratedTypeSpefType : public Node { |
| ... | ... | @@ -408,10 +528,10 @@ public: |
| 408 | 528 | |
| 409 | 529 | template<typename Fn> void match(Fn F) const { F(Kind, Child); } |
| 410 | 530 | |
| 411 | | void printLeft(OutputStream &S) const override { |
| 412 | | S += Kind; |
| 413 | | S += ' '; |
| 414 | | Child->print(S); |
| 531 | void printLeft(OutputBuffer &OB) const override { |
| 532 | OB += Kind; |
| 533 | OB += ' '; |
| 534 | Child->print(OB); |
| 415 | 535 | } |
| 416 | 536 | }; |
| 417 | 537 | |
| ... | ... | @@ -426,11 +546,11 @@ struct AbiTagAttr : Node { |
| 426 | 546 | |
| 427 | 547 | template<typename Fn> void match(Fn F) const { F(Base, Tag); } |
| 428 | 548 | |
| 429 | | void printLeft(OutputStream &S) const override { |
| 430 | | Base->printLeft(S); |
| 431 | | S += "[abi:"; |
| 432 | | S += Tag; |
| 433 | | S += "]"; |
| 549 | void printLeft(OutputBuffer &OB) const override { |
| 550 | Base->printLeft(OB); |
| 551 | OB += "[abi:"; |
| 552 | OB += Tag; |
| 553 | OB += "]"; |
| 434 | 554 | } |
| 435 | 555 | }; |
| 436 | 556 | |
| ... | ... | @@ -442,10 +562,10 @@ public: |
| 442 | 562 | |
| 443 | 563 | template<typename Fn> void match(Fn F) const { F(Conditions); } |
| 444 | 564 | |
| 445 | | void printLeft(OutputStream &S) const override { |
| 446 | | S += " [enable_if:"; |
| 447 | | Conditions.printWithComma(S); |
| 448 | | S += ']'; |
| 565 | void printLeft(OutputBuffer &OB) const override { |
| 566 | OB += " [enable_if:"; |
| 567 | Conditions.printWithComma(OB); |
| 568 | OB += ']'; |
| 449 | 569 | } |
| 450 | 570 | }; |
| 451 | 571 | |
| ... | ... | @@ -466,11 +586,11 @@ public: |
| 466 | 586 | static_cast<const NameType *>(Ty)->getName() == "objc_object"; |
| 467 | 587 | } |
| 468 | 588 | |
| 469 | | void printLeft(OutputStream &S) const override { |
| 470 | | Ty->print(S); |
| 471 | | S += "<"; |
| 472 | | S += Protocol; |
| 473 | | S += ">"; |
| 589 | void printLeft(OutputBuffer &OB) const override { |
| 590 | Ty->print(OB); |
| 591 | OB += "<"; |
| 592 | OB += Protocol; |
| 593 | OB += ">"; |
| 474 | 594 | } |
| 475 | 595 | }; |
| 476 | 596 | |
| ... | ... | @@ -484,34 +604,34 @@ public: |
| 484 | 604 | |
| 485 | 605 | template<typename Fn> void match(Fn F) const { F(Pointee); } |
| 486 | 606 | |
| 487 | | bool hasRHSComponentSlow(OutputStream &S) const override { |
| 488 | | return Pointee->hasRHSComponent(S); |
| 607 | bool hasRHSComponentSlow(OutputBuffer &OB) const override { |
| 608 | return Pointee->hasRHSComponent(OB); |
| 489 | 609 | } |
| 490 | 610 | |
| 491 | | void printLeft(OutputStream &s) const override { |
| 611 | void printLeft(OutputBuffer &OB) const override { |
| 492 | 612 | // We rewrite objc_object<SomeProtocol>* into id<SomeProtocol>. |
| 493 | 613 | if (Pointee->getKind() != KObjCProtoName || |
| 494 | 614 | !static_cast<const ObjCProtoName *>(Pointee)->isObjCObject()) { |
| 495 | | Pointee->printLeft(s); |
| 496 | | if (Pointee->hasArray(s)) |
| 497 | | s += " "; |
| 498 | | if (Pointee->hasArray(s) || Pointee->hasFunction(s)) |
| 499 | | s += "("; |
| 500 | | s += "*"; |
| 615 | Pointee->printLeft(OB); |
| 616 | if (Pointee->hasArray(OB)) |
| 617 | OB += " "; |
| 618 | if (Pointee->hasArray(OB) || Pointee->hasFunction(OB)) |
| 619 | OB += "("; |
| 620 | OB += "*"; |
| 501 | 621 | } else { |
| 502 | 622 | const auto *objcProto = static_cast<const ObjCProtoName *>(Pointee); |
| 503 | | s += "id<"; |
| 504 | | s += objcProto->Protocol; |
| 505 | | s += ">"; |
| 623 | OB += "id<"; |
| 624 | OB += objcProto->Protocol; |
| 625 | OB += ">"; |
| 506 | 626 | } |
| 507 | 627 | } |
| 508 | 628 | |
| 509 | | void printRight(OutputStream &s) const override { |
| 629 | void printRight(OutputBuffer &OB) const override { |
| 510 | 630 | if (Pointee->getKind() != KObjCProtoName || |
| 511 | 631 | !static_cast<const ObjCProtoName *>(Pointee)->isObjCObject()) { |
| 512 | | if (Pointee->hasArray(s) || Pointee->hasFunction(s)) |
| 513 | | s += ")"; |
| 514 | | Pointee->printRight(s); |
| 632 | if (Pointee->hasArray(OB) || Pointee->hasFunction(OB)) |
| 633 | OB += ")"; |
| 634 | Pointee->printRight(OB); |
| 515 | 635 | } |
| 516 | 636 | } |
| 517 | 637 | }; |
| ... | ... | @@ -531,15 +651,30 @@ class ReferenceType : public Node { |
| 531 | 651 | // Dig through any refs to refs, collapsing the ReferenceTypes as we go. The |
| 532 | 652 | // rule here is rvalue ref to rvalue ref collapses to a rvalue ref, and any |
| 533 | 653 | // other combination collapses to a lvalue ref. |
| 534 | | std::pair<ReferenceKind, const Node *> collapse(OutputStream &S) const { |
| 654 | // |
| 655 | // A combination of a TemplateForwardReference and a back-ref Substitution |
| 656 | // from an ill-formed string may have created a cycle; use cycle detection to |
| 657 | // avoid looping forever. |
| 658 | std::pair<ReferenceKind, const Node *> collapse(OutputBuffer &OB) const { |
| 535 | 659 | auto SoFar = std::make_pair(RK, Pointee); |
| 660 | // Track the chain of nodes for the Floyd's 'tortoise and hare' |
| 661 | // cycle-detection algorithm, since getSyntaxNode(S) is impure |
| 662 | PODSmallVector<const Node *, 8> Prev; |
| 536 | 663 | for (;;) { |
| 537 | | const Node *SN = SoFar.second->getSyntaxNode(S); |
| 664 | const Node *SN = SoFar.second->getSyntaxNode(OB); |
| 538 | 665 | if (SN->getKind() != KReferenceType) |
| 539 | 666 | break; |
| 540 | 667 | auto *RT = static_cast<const ReferenceType *>(SN); |
| 541 | 668 | SoFar.second = RT->Pointee; |
| 542 | 669 | SoFar.first = std::min(SoFar.first, RT->RK); |
| 670 | |
| 671 | // The middle of Prev is the 'slow' pointer moving at half speed |
| 672 | Prev.push_back(SoFar.second); |
| 673 | if (Prev.size() > 1 && SoFar.second == Prev[(Prev.size() - 1) / 2]) { |
| 674 | // Cycle detected |
| 675 | SoFar.second = nullptr; |
| 676 | break; |
| 677 | } |
| 543 | 678 | } |
| 544 | 679 | return SoFar; |
| 545 | 680 | } |
| ... | ... | @@ -551,31 +686,35 @@ public: |
| 551 | 686 | |
| 552 | 687 | template<typename Fn> void match(Fn F) const { F(Pointee, RK); } |
| 553 | 688 | |
| 554 | | bool hasRHSComponentSlow(OutputStream &S) const override { |
| 555 | | return Pointee->hasRHSComponent(S); |
| 689 | bool hasRHSComponentSlow(OutputBuffer &OB) const override { |
| 690 | return Pointee->hasRHSComponent(OB); |
| 556 | 691 | } |
| 557 | 692 | |
| 558 | | void printLeft(OutputStream &s) const override { |
| 693 | void printLeft(OutputBuffer &OB) const override { |
| 559 | 694 | if (Printing) |
| 560 | 695 | return; |
| 561 | 696 | SwapAndRestore<bool> SavePrinting(Printing, true); |
| 562 | | std::pair<ReferenceKind, const Node *> Collapsed = collapse(s); |
| 563 | | Collapsed.second->printLeft(s); |
| 564 | | if (Collapsed.second->hasArray(s)) |
| 565 | | s += " "; |
| 566 | | if (Collapsed.second->hasArray(s) || Collapsed.second->hasFunction(s)) |
| 567 | | s += "("; |
| 697 | std::pair<ReferenceKind, const Node *> Collapsed = collapse(OB); |
| 698 | if (!Collapsed.second) |
| 699 | return; |
| 700 | Collapsed.second->printLeft(OB); |
| 701 | if (Collapsed.second->hasArray(OB)) |
| 702 | OB += " "; |
| 703 | if (Collapsed.second->hasArray(OB) || Collapsed.second->hasFunction(OB)) |
| 704 | OB += "("; |
| 568 | 705 | |
| 569 | | s += (Collapsed.first == ReferenceKind::LValue ? "&" : "&&"); |
| 706 | OB += (Collapsed.first == ReferenceKind::LValue ? "&" : "&&"); |
| 570 | 707 | } |
| 571 | | void printRight(OutputStream &s) const override { |
| 708 | void printRight(OutputBuffer &OB) const override { |
| 572 | 709 | if (Printing) |
| 573 | 710 | return; |
| 574 | 711 | SwapAndRestore<bool> SavePrinting(Printing, true); |
| 575 | | std::pair<ReferenceKind, const Node *> Collapsed = collapse(s); |
| 576 | | if (Collapsed.second->hasArray(s) || Collapsed.second->hasFunction(s)) |
| 577 | | s += ")"; |
| 578 | | Collapsed.second->printRight(s); |
| 712 | std::pair<ReferenceKind, const Node *> Collapsed = collapse(OB); |
| 713 | if (!Collapsed.second) |
| 714 | return; |
| 715 | if (Collapsed.second->hasArray(OB) || Collapsed.second->hasFunction(OB)) |
| 716 | OB += ")"; |
| 717 | Collapsed.second->printRight(OB); |
| 579 | 718 | } |
| 580 | 719 | }; |
| 581 | 720 | |
| ... | ... | @@ -590,24 +729,24 @@ public: |
| 590 | 729 | |
| 591 | 730 | template<typename Fn> void match(Fn F) const { F(ClassType, MemberType); } |
| 592 | 731 | |
| 593 | | bool hasRHSComponentSlow(OutputStream &S) const override { |
| 594 | | return MemberType->hasRHSComponent(S); |
| 732 | bool hasRHSComponentSlow(OutputBuffer &OB) const override { |
| 733 | return MemberType->hasRHSComponent(OB); |
| 595 | 734 | } |
| 596 | 735 | |
| 597 | | void printLeft(OutputStream &s) const override { |
| 598 | | MemberType->printLeft(s); |
| 599 | | if (MemberType->hasArray(s) || MemberType->hasFunction(s)) |
| 600 | | s += "("; |
| 736 | void printLeft(OutputBuffer &OB) const override { |
| 737 | MemberType->printLeft(OB); |
| 738 | if (MemberType->hasArray(OB) || MemberType->hasFunction(OB)) |
| 739 | OB += "("; |
| 601 | 740 | else |
| 602 | | s += " "; |
| 603 | | ClassType->print(s); |
| 604 | | s += "::*"; |
| 741 | OB += " "; |
| 742 | ClassType->print(OB); |
| 743 | OB += "::*"; |
| 605 | 744 | } |
| 606 | 745 | |
| 607 | | void printRight(OutputStream &s) const override { |
| 608 | | if (MemberType->hasArray(s) || MemberType->hasFunction(s)) |
| 609 | | s += ")"; |
| 610 | | MemberType->printRight(s); |
| 746 | void printRight(OutputBuffer &OB) const override { |
| 747 | if (MemberType->hasArray(OB) || MemberType->hasFunction(OB)) |
| 748 | OB += ")"; |
| 749 | MemberType->printRight(OB); |
| 611 | 750 | } |
| 612 | 751 | }; |
| 613 | 752 | |
| ... | ... | @@ -624,19 +763,19 @@ public: |
| 624 | 763 | |
| 625 | 764 | template<typename Fn> void match(Fn F) const { F(Base, Dimension); } |
| 626 | 765 | |
| 627 | | bool hasRHSComponentSlow(OutputStream &) const override { return true; } |
| 628 | | bool hasArraySlow(OutputStream &) const override { return true; } |
| 766 | bool hasRHSComponentSlow(OutputBuffer &) const override { return true; } |
| 767 | bool hasArraySlow(OutputBuffer &) const override { return true; } |
| 629 | 768 | |
| 630 | | void printLeft(OutputStream &S) const override { Base->printLeft(S); } |
| 769 | void printLeft(OutputBuffer &OB) const override { Base->printLeft(OB); } |
| 631 | 770 | |
| 632 | | void printRight(OutputStream &S) const override { |
| 633 | | if (S.back() != ']') |
| 634 | | S += " "; |
| 635 | | S += "["; |
| 771 | void printRight(OutputBuffer &OB) const override { |
| 772 | if (OB.back() != ']') |
| 773 | OB += " "; |
| 774 | OB += "["; |
| 636 | 775 | if (Dimension) |
| 637 | | Dimension->print(S); |
| 638 | | S += "]"; |
| 639 | | Base->printRight(S); |
| 776 | Dimension->print(OB); |
| 777 | OB += "]"; |
| 778 | Base->printRight(OB); |
| 640 | 779 | } |
| 641 | 780 | }; |
| 642 | 781 | |
| ... | ... | @@ -660,8 +799,8 @@ public: |
| 660 | 799 | F(Ret, Params, CVQuals, RefQual, ExceptionSpec); |
| 661 | 800 | } |
| 662 | 801 | |
| 663 | | bool hasRHSComponentSlow(OutputStream &) const override { return true; } |
| 664 | | bool hasFunctionSlow(OutputStream &) const override { return true; } |
| 802 | bool hasRHSComponentSlow(OutputBuffer &) const override { return true; } |
| 803 | bool hasFunctionSlow(OutputBuffer &) const override { return true; } |
| 665 | 804 | |
| 666 | 805 | // Handle C++'s ... quirky decl grammar by using the left & right |
| 667 | 806 | // distinction. Consider: |
| ... | ... | @@ -670,32 +809,32 @@ public: |
| 670 | 809 | // that takes a char and returns an int. If we're trying to print f, start |
| 671 | 810 | // by printing out the return types's left, then print our parameters, then |
| 672 | 811 | // finally print right of the return type. |
| 673 | | void printLeft(OutputStream &S) const override { |
| 674 | | Ret->printLeft(S); |
| 675 | | S += " "; |
| 812 | void printLeft(OutputBuffer &OB) const override { |
| 813 | Ret->printLeft(OB); |
| 814 | OB += " "; |
| 676 | 815 | } |
| 677 | 816 | |
| 678 | | void printRight(OutputStream &S) const override { |
| 679 | | S += "("; |
| 680 | | Params.printWithComma(S); |
| 681 | | S += ")"; |
| 682 | | Ret->printRight(S); |
| 817 | void printRight(OutputBuffer &OB) const override { |
| 818 | OB += "("; |
| 819 | Params.printWithComma(OB); |
| 820 | OB += ")"; |
| 821 | Ret->printRight(OB); |
| 683 | 822 | |
| 684 | 823 | if (CVQuals & QualConst) |
| 685 | | S += " const"; |
| 824 | OB += " const"; |
| 686 | 825 | if (CVQuals & QualVolatile) |
| 687 | | S += " volatile"; |
| 826 | OB += " volatile"; |
| 688 | 827 | if (CVQuals & QualRestrict) |
| 689 | | S += " restrict"; |
| 828 | OB += " restrict"; |
| 690 | 829 | |
| 691 | 830 | if (RefQual == FrefQualLValue) |
| 692 | | S += " &"; |
| 831 | OB += " &"; |
| 693 | 832 | else if (RefQual == FrefQualRValue) |
| 694 | | S += " &&"; |
| 833 | OB += " &&"; |
| 695 | 834 | |
| 696 | 835 | if (ExceptionSpec != nullptr) { |
| 697 | | S += ' '; |
| 698 | | ExceptionSpec->print(S); |
| 836 | OB += ' '; |
| 837 | ExceptionSpec->print(OB); |
| 699 | 838 | } |
| 700 | 839 | } |
| 701 | 840 | }; |
| ... | ... | @@ -707,10 +846,10 @@ public: |
| 707 | 846 | |
| 708 | 847 | template<typename Fn> void match(Fn F) const { F(E); } |
| 709 | 848 | |
| 710 | | void printLeft(OutputStream &S) const override { |
| 711 | | S += "noexcept("; |
| 712 | | E->print(S); |
| 713 | | S += ")"; |
| 849 | void printLeft(OutputBuffer &OB) const override { |
| 850 | OB += "noexcept("; |
| 851 | E->print(OB); |
| 852 | OB += ")"; |
| 714 | 853 | } |
| 715 | 854 | }; |
| 716 | 855 | |
| ... | ... | @@ -722,10 +861,10 @@ public: |
| 722 | 861 | |
| 723 | 862 | template<typename Fn> void match(Fn F) const { F(Types); } |
| 724 | 863 | |
| 725 | | void printLeft(OutputStream &S) const override { |
| 726 | | S += "throw("; |
| 727 | | Types.printWithComma(S); |
| 728 | | S += ')'; |
| 864 | void printLeft(OutputBuffer &OB) const override { |
| 865 | OB += "throw("; |
| 866 | Types.printWithComma(OB); |
| 867 | OB += ')'; |
| 729 | 868 | } |
| 730 | 869 | }; |
| 731 | 870 | |
| ... | ... | @@ -756,41 +895,41 @@ public: |
| 756 | 895 | NodeArray getParams() const { return Params; } |
| 757 | 896 | const Node *getReturnType() const { return Ret; } |
| 758 | 897 | |
| 759 | | bool hasRHSComponentSlow(OutputStream &) const override { return true; } |
| 760 | | bool hasFunctionSlow(OutputStream &) const override { return true; } |
| 898 | bool hasRHSComponentSlow(OutputBuffer &) const override { return true; } |
| 899 | bool hasFunctionSlow(OutputBuffer &) const override { return true; } |
| 761 | 900 | |
| 762 | 901 | const Node *getName() const { return Name; } |
| 763 | 902 | |
| 764 | | void printLeft(OutputStream &S) const override { |
| 903 | void printLeft(OutputBuffer &OB) const override { |
| 765 | 904 | if (Ret) { |
| 766 | | Ret->printLeft(S); |
| 767 | | if (!Ret->hasRHSComponent(S)) |
| 768 | | S += " "; |
| 905 | Ret->printLeft(OB); |
| 906 | if (!Ret->hasRHSComponent(OB)) |
| 907 | OB += " "; |
| 769 | 908 | } |
| 770 | | Name->print(S); |
| 909 | Name->print(OB); |
| 771 | 910 | } |
| 772 | 911 | |
| 773 | | void printRight(OutputStream &S) const override { |
| 774 | | S += "("; |
| 775 | | Params.printWithComma(S); |
| 776 | | S += ")"; |
| 912 | void printRight(OutputBuffer &OB) const override { |
| 913 | OB += "("; |
| 914 | Params.printWithComma(OB); |
| 915 | OB += ")"; |
| 777 | 916 | if (Ret) |
| 778 | | Ret->printRight(S); |
| 917 | Ret->printRight(OB); |
| 779 | 918 | |
| 780 | 919 | if (CVQuals & QualConst) |
| 781 | | S += " const"; |
| 920 | OB += " const"; |
| 782 | 921 | if (CVQuals & QualVolatile) |
| 783 | | S += " volatile"; |
| 922 | OB += " volatile"; |
| 784 | 923 | if (CVQuals & QualRestrict) |
| 785 | | S += " restrict"; |
| 924 | OB += " restrict"; |
| 786 | 925 | |
| 787 | 926 | if (RefQual == FrefQualLValue) |
| 788 | | S += " &"; |
| 927 | OB += " &"; |
| 789 | 928 | else if (RefQual == FrefQualRValue) |
| 790 | | S += " &&"; |
| 929 | OB += " &&"; |
| 791 | 930 | |
| 792 | 931 | if (Attrs != nullptr) |
| 793 | | Attrs->print(S); |
| 932 | Attrs->print(OB); |
| 794 | 933 | } |
| 795 | 934 | }; |
| 796 | 935 | |
| ... | ... | @@ -803,9 +942,9 @@ public: |
| 803 | 942 | |
| 804 | 943 | template<typename Fn> void match(Fn F) const { F(OpName); } |
| 805 | 944 | |
| 806 | | void printLeft(OutputStream &S) const override { |
| 807 | | S += "operator\"\" "; |
| 808 | | OpName->print(S); |
| 945 | void printLeft(OutputBuffer &OB) const override { |
| 946 | OB += "operator\"\" "; |
| 947 | OpName->print(OB); |
| 809 | 948 | } |
| 810 | 949 | }; |
| 811 | 950 | |
| ... | ... | @@ -819,9 +958,9 @@ public: |
| 819 | 958 | |
| 820 | 959 | template<typename Fn> void match(Fn F) const { F(Special, Child); } |
| 821 | 960 | |
| 822 | | void printLeft(OutputStream &S) const override { |
| 823 | | S += Special; |
| 824 | | Child->print(S); |
| 961 | void printLeft(OutputBuffer &OB) const override { |
| 962 | OB += Special; |
| 963 | Child->print(OB); |
| 825 | 964 | } |
| 826 | 965 | }; |
| 827 | 966 | |
| ... | ... | @@ -836,11 +975,11 @@ public: |
| 836 | 975 | |
| 837 | 976 | template<typename Fn> void match(Fn F) const { F(FirstType, SecondType); } |
| 838 | 977 | |
| 839 | | void printLeft(OutputStream &S) const override { |
| 840 | | S += "construction vtable for "; |
| 841 | | FirstType->print(S); |
| 842 | | S += "-in-"; |
| 843 | | SecondType->print(S); |
| 978 | void printLeft(OutputBuffer &OB) const override { |
| 979 | OB += "construction vtable for "; |
| 980 | FirstType->print(OB); |
| 981 | OB += "-in-"; |
| 982 | SecondType->print(OB); |
| 844 | 983 | } |
| 845 | 984 | }; |
| 846 | 985 | |
| ... | ... | @@ -855,10 +994,10 @@ struct NestedName : Node { |
| 855 | 994 | |
| 856 | 995 | StringView getBaseName() const override { return Name->getBaseName(); } |
| 857 | 996 | |
| 858 | | void printLeft(OutputStream &S) const override { |
| 859 | | Qual->print(S); |
| 860 | | S += "::"; |
| 861 | | Name->print(S); |
| 997 | void printLeft(OutputBuffer &OB) const override { |
| 998 | Qual->print(OB); |
| 999 | OB += "::"; |
| 1000 | Name->print(OB); |
| 862 | 1001 | } |
| 863 | 1002 | }; |
| 864 | 1003 | |
| ... | ... | @@ -871,10 +1010,10 @@ struct LocalName : Node { |
| 871 | 1010 | |
| 872 | 1011 | template<typename Fn> void match(Fn F) const { F(Encoding, Entity); } |
| 873 | 1012 | |
| 874 | | void printLeft(OutputStream &S) const override { |
| 875 | | Encoding->print(S); |
| 876 | | S += "::"; |
| 877 | | Entity->print(S); |
| 1013 | void printLeft(OutputBuffer &OB) const override { |
| 1014 | Encoding->print(OB); |
| 1015 | OB += "::"; |
| 1016 | Entity->print(OB); |
| 878 | 1017 | } |
| 879 | 1018 | }; |
| 880 | 1019 | |
| ... | ... | @@ -891,10 +1030,10 @@ public: |
| 891 | 1030 | |
| 892 | 1031 | StringView getBaseName() const override { return Name->getBaseName(); } |
| 893 | 1032 | |
| 894 | | void printLeft(OutputStream &S) const override { |
| 895 | | Qualifier->print(S); |
| 896 | | S += "::"; |
| 897 | | Name->print(S); |
| 1033 | void printLeft(OutputBuffer &OB) const override { |
| 1034 | Qualifier->print(OB); |
| 1035 | OB += "::"; |
| 1036 | Name->print(OB); |
| 898 | 1037 | } |
| 899 | 1038 | }; |
| 900 | 1039 | |
| ... | ... | @@ -909,12 +1048,12 @@ public: |
| 909 | 1048 | |
| 910 | 1049 | template<typename Fn> void match(Fn F) const { F(BaseType, Dimension); } |
| 911 | 1050 | |
| 912 | | void printLeft(OutputStream &S) const override { |
| 913 | | BaseType->print(S); |
| 914 | | S += " vector["; |
| 1051 | void printLeft(OutputBuffer &OB) const override { |
| 1052 | BaseType->print(OB); |
| 1053 | OB += " vector["; |
| 915 | 1054 | if (Dimension) |
| 916 | | Dimension->print(S); |
| 917 | | S += "]"; |
| 1055 | Dimension->print(OB); |
| 1056 | OB += "]"; |
| 918 | 1057 | } |
| 919 | 1058 | }; |
| 920 | 1059 | |
| ... | ... | @@ -927,11 +1066,26 @@ public: |
| 927 | 1066 | |
| 928 | 1067 | template<typename Fn> void match(Fn F) const { F(Dimension); } |
| 929 | 1068 | |
| 930 | | void printLeft(OutputStream &S) const override { |
| 1069 | void printLeft(OutputBuffer &OB) const override { |
| 931 | 1070 | // FIXME: This should demangle as "vector pixel". |
| 932 | | S += "pixel vector["; |
| 933 | | Dimension->print(S); |
| 934 | | S += "]"; |
| 1071 | OB += "pixel vector["; |
| 1072 | Dimension->print(OB); |
| 1073 | OB += "]"; |
| 1074 | } |
| 1075 | }; |
| 1076 | |
| 1077 | class BinaryFPType final : public Node { |
| 1078 | const Node *Dimension; |
| 1079 | |
| 1080 | public: |
| 1081 | BinaryFPType(const Node *Dimension_) |
| 1082 | : Node(KBinaryFPType), Dimension(Dimension_) {} |
| 1083 | |
| 1084 | template<typename Fn> void match(Fn F) const { F(Dimension); } |
| 1085 | |
| 1086 | void printLeft(OutputBuffer &OB) const override { |
| 1087 | OB += "_Float"; |
| 1088 | Dimension->print(OB); |
| 935 | 1089 | } |
| 936 | 1090 | }; |
| 937 | 1091 | |
| ... | ... | @@ -953,20 +1107,20 @@ public: |
| 953 | 1107 | |
| 954 | 1108 | template<typename Fn> void match(Fn F) const { F(Kind, Index); } |
| 955 | 1109 | |
| 956 | | void printLeft(OutputStream &S) const override { |
| 1110 | void printLeft(OutputBuffer &OB) const override { |
| 957 | 1111 | switch (Kind) { |
| 958 | 1112 | case TemplateParamKind::Type: |
| 959 | | S += "$T"; |
| 1113 | OB += "$T"; |
| 960 | 1114 | break; |
| 961 | 1115 | case TemplateParamKind::NonType: |
| 962 | | S += "$N"; |
| 1116 | OB += "$N"; |
| 963 | 1117 | break; |
| 964 | 1118 | case TemplateParamKind::Template: |
| 965 | | S += "$TT"; |
| 1119 | OB += "$TT"; |
| 966 | 1120 | break; |
| 967 | 1121 | } |
| 968 | 1122 | if (Index > 0) |
| 969 | | S << Index - 1; |
| 1123 | OB << Index - 1; |
| 970 | 1124 | } |
| 971 | 1125 | }; |
| 972 | 1126 | |
| ... | ... | @@ -980,13 +1134,9 @@ public: |
| 980 | 1134 | |
| 981 | 1135 | template<typename Fn> void match(Fn F) const { F(Name); } |
| 982 | 1136 | |
| 983 | | void printLeft(OutputStream &S) const override { |
| 984 | | S += "typename "; |
| 985 | | } |
| 1137 | void printLeft(OutputBuffer &OB) const override { OB += "typename "; } |
| 986 | 1138 | |
| 987 | | void printRight(OutputStream &S) const override { |
| 988 | | Name->print(S); |
| 989 | | } |
| 1139 | void printRight(OutputBuffer &OB) const override { Name->print(OB); } |
| 990 | 1140 | }; |
| 991 | 1141 | |
| 992 | 1142 | /// A non-type template parameter declaration, 'int N'. |
| ... | ... | @@ -1000,15 +1150,15 @@ public: |
| 1000 | 1150 | |
| 1001 | 1151 | template<typename Fn> void match(Fn F) const { F(Name, Type); } |
| 1002 | 1152 | |
| 1003 | | void printLeft(OutputStream &S) const override { |
| 1004 | | Type->printLeft(S); |
| 1005 | | if (!Type->hasRHSComponent(S)) |
| 1006 | | S += " "; |
| 1153 | void printLeft(OutputBuffer &OB) const override { |
| 1154 | Type->printLeft(OB); |
| 1155 | if (!Type->hasRHSComponent(OB)) |
| 1156 | OB += " "; |
| 1007 | 1157 | } |
| 1008 | 1158 | |
| 1009 | | void printRight(OutputStream &S) const override { |
| 1010 | | Name->print(S); |
| 1011 | | Type->printRight(S); |
| 1159 | void printRight(OutputBuffer &OB) const override { |
| 1160 | Name->print(OB); |
| 1161 | Type->printRight(OB); |
| 1012 | 1162 | } |
| 1013 | 1163 | }; |
| 1014 | 1164 | |
| ... | ... | @@ -1025,15 +1175,13 @@ public: |
| 1025 | 1175 | |
| 1026 | 1176 | template<typename Fn> void match(Fn F) const { F(Name, Params); } |
| 1027 | 1177 | |
| 1028 | | void printLeft(OutputStream &S) const override { |
| 1029 | | S += "template<"; |
| 1030 | | Params.printWithComma(S); |
| 1031 | | S += "> typename "; |
| 1178 | void printLeft(OutputBuffer &OB) const override { |
| 1179 | OB += "template<"; |
| 1180 | Params.printWithComma(OB); |
| 1181 | OB += "> typename "; |
| 1032 | 1182 | } |
| 1033 | 1183 | |
| 1034 | | void printRight(OutputStream &S) const override { |
| 1035 | | Name->print(S); |
| 1036 | | } |
| 1184 | void printRight(OutputBuffer &OB) const override { Name->print(OB); } |
| 1037 | 1185 | }; |
| 1038 | 1186 | |
| 1039 | 1187 | /// A template parameter pack declaration, 'typename ...T'. |
| ... | ... | @@ -1046,14 +1194,12 @@ public: |
| 1046 | 1194 | |
| 1047 | 1195 | template<typename Fn> void match(Fn F) const { F(Param); } |
| 1048 | 1196 | |
| 1049 | | void printLeft(OutputStream &S) const override { |
| 1050 | | Param->printLeft(S); |
| 1051 | | S += "..."; |
| 1197 | void printLeft(OutputBuffer &OB) const override { |
| 1198 | Param->printLeft(OB); |
| 1199 | OB += "..."; |
| 1052 | 1200 | } |
| 1053 | 1201 | |
| 1054 | | void printRight(OutputStream &S) const override { |
| 1055 | | Param->printRight(S); |
| 1056 | | } |
| 1202 | void printRight(OutputBuffer &OB) const override { Param->printRight(OB); } |
| 1057 | 1203 | }; |
| 1058 | 1204 | |
| 1059 | 1205 | /// An unexpanded parameter pack (either in the expression or type context). If |
| ... | ... | @@ -1067,11 +1213,12 @@ public: |
| 1067 | 1213 | class ParameterPack final : public Node { |
| 1068 | 1214 | NodeArray Data; |
| 1069 | 1215 | |
| 1070 | | // Setup OutputStream for a pack expansion unless we're already expanding one. |
| 1071 | | void initializePackExpansion(OutputStream &S) const { |
| 1072 | | if (S.CurrentPackMax == std::numeric_limits<unsigned>::max()) { |
| 1073 | | S.CurrentPackMax = static_cast<unsigned>(Data.size()); |
| 1074 | | S.CurrentPackIndex = 0; |
| 1216 | // Setup OutputBuffer for a pack expansion, unless we're already expanding |
| 1217 | // one. |
| 1218 | void initializePackExpansion(OutputBuffer &OB) const { |
| 1219 | if (OB.CurrentPackMax == std::numeric_limits<unsigned>::max()) { |
| 1220 | OB.CurrentPackMax = static_cast<unsigned>(Data.size()); |
| 1221 | OB.CurrentPackIndex = 0; |
| 1075 | 1222 | } |
| 1076 | 1223 | } |
| 1077 | 1224 | |
| ... | ... | @@ -1094,38 +1241,38 @@ public: |
| 1094 | 1241 | |
| 1095 | 1242 | template<typename Fn> void match(Fn F) const { F(Data); } |
| 1096 | 1243 | |
| 1097 | | bool hasRHSComponentSlow(OutputStream &S) const override { |
| 1098 | | initializePackExpansion(S); |
| 1099 | | size_t Idx = S.CurrentPackIndex; |
| 1100 | | return Idx < Data.size() && Data[Idx]->hasRHSComponent(S); |
| 1244 | bool hasRHSComponentSlow(OutputBuffer &OB) const override { |
| 1245 | initializePackExpansion(OB); |
| 1246 | size_t Idx = OB.CurrentPackIndex; |
| 1247 | return Idx < Data.size() && Data[Idx]->hasRHSComponent(OB); |
| 1101 | 1248 | } |
| 1102 | | bool hasArraySlow(OutputStream &S) const override { |
| 1103 | | initializePackExpansion(S); |
| 1104 | | size_t Idx = S.CurrentPackIndex; |
| 1105 | | return Idx < Data.size() && Data[Idx]->hasArray(S); |
| 1249 | bool hasArraySlow(OutputBuffer &OB) const override { |
| 1250 | initializePackExpansion(OB); |
| 1251 | size_t Idx = OB.CurrentPackIndex; |
| 1252 | return Idx < Data.size() && Data[Idx]->hasArray(OB); |
| 1106 | 1253 | } |
| 1107 | | bool hasFunctionSlow(OutputStream &S) const override { |
| 1108 | | initializePackExpansion(S); |
| 1109 | | size_t Idx = S.CurrentPackIndex; |
| 1110 | | return Idx < Data.size() && Data[Idx]->hasFunction(S); |
| 1254 | bool hasFunctionSlow(OutputBuffer &OB) const override { |
| 1255 | initializePackExpansion(OB); |
| 1256 | size_t Idx = OB.CurrentPackIndex; |
| 1257 | return Idx < Data.size() && Data[Idx]->hasFunction(OB); |
| 1111 | 1258 | } |
| 1112 | | const Node *getSyntaxNode(OutputStream &S) const override { |
| 1113 | | initializePackExpansion(S); |
| 1114 | | size_t Idx = S.CurrentPackIndex; |
| 1115 | | return Idx < Data.size() ? Data[Idx]->getSyntaxNode(S) : this; |
| 1259 | const Node *getSyntaxNode(OutputBuffer &OB) const override { |
| 1260 | initializePackExpansion(OB); |
| 1261 | size_t Idx = OB.CurrentPackIndex; |
| 1262 | return Idx < Data.size() ? Data[Idx]->getSyntaxNode(OB) : this; |
| 1116 | 1263 | } |
| 1117 | 1264 | |
| 1118 | | void printLeft(OutputStream &S) const override { |
| 1119 | | initializePackExpansion(S); |
| 1120 | | size_t Idx = S.CurrentPackIndex; |
| 1265 | void printLeft(OutputBuffer &OB) const override { |
| 1266 | initializePackExpansion(OB); |
| 1267 | size_t Idx = OB.CurrentPackIndex; |
| 1121 | 1268 | if (Idx < Data.size()) |
| 1122 | | Data[Idx]->printLeft(S); |
| 1269 | Data[Idx]->printLeft(OB); |
| 1123 | 1270 | } |
| 1124 | | void printRight(OutputStream &S) const override { |
| 1125 | | initializePackExpansion(S); |
| 1126 | | size_t Idx = S.CurrentPackIndex; |
| 1271 | void printRight(OutputBuffer &OB) const override { |
| 1272 | initializePackExpansion(OB); |
| 1273 | size_t Idx = OB.CurrentPackIndex; |
| 1127 | 1274 | if (Idx < Data.size()) |
| 1128 | | Data[Idx]->printRight(S); |
| 1275 | Data[Idx]->printRight(OB); |
| 1129 | 1276 | } |
| 1130 | 1277 | }; |
| 1131 | 1278 | |
| ... | ... | @@ -1144,8 +1291,8 @@ public: |
| 1144 | 1291 | |
| 1145 | 1292 | NodeArray getElements() const { return Elements; } |
| 1146 | 1293 | |
| 1147 | | void printLeft(OutputStream &S) const override { |
| 1148 | | Elements.printWithComma(S); |
| 1294 | void printLeft(OutputBuffer &OB) const override { |
| 1295 | Elements.printWithComma(OB); |
| 1149 | 1296 | } |
| 1150 | 1297 | }; |
| 1151 | 1298 | |
| ... | ... | @@ -1162,35 +1309,35 @@ public: |
| 1162 | 1309 | |
| 1163 | 1310 | const Node *getChild() const { return Child; } |
| 1164 | 1311 | |
| 1165 | | void printLeft(OutputStream &S) const override { |
| 1312 | void printLeft(OutputBuffer &OB) const override { |
| 1166 | 1313 | constexpr unsigned Max = std::numeric_limits<unsigned>::max(); |
| 1167 | | SwapAndRestore<unsigned> SavePackIdx(S.CurrentPackIndex, Max); |
| 1168 | | SwapAndRestore<unsigned> SavePackMax(S.CurrentPackMax, Max); |
| 1169 | | size_t StreamPos = S.getCurrentPosition(); |
| 1314 | SwapAndRestore<unsigned> SavePackIdx(OB.CurrentPackIndex, Max); |
| 1315 | SwapAndRestore<unsigned> SavePackMax(OB.CurrentPackMax, Max); |
| 1316 | size_t StreamPos = OB.getCurrentPosition(); |
| 1170 | 1317 | |
| 1171 | 1318 | // Print the first element in the pack. If Child contains a ParameterPack, |
| 1172 | 1319 | // it will set up S.CurrentPackMax and print the first element. |
| 1173 | | Child->print(S); |
| 1320 | Child->print(OB); |
| 1174 | 1321 | |
| 1175 | 1322 | // No ParameterPack was found in Child. This can occur if we've found a pack |
| 1176 | 1323 | // expansion on a <function-param>. |
| 1177 | | if (S.CurrentPackMax == Max) { |
| 1178 | | S += "..."; |
| 1324 | if (OB.CurrentPackMax == Max) { |
| 1325 | OB += "..."; |
| 1179 | 1326 | return; |
| 1180 | 1327 | } |
| 1181 | 1328 | |
| 1182 | 1329 | // We found a ParameterPack, but it has no elements. Erase whatever we may |
| 1183 | 1330 | // of printed. |
| 1184 | | if (S.CurrentPackMax == 0) { |
| 1185 | | S.setCurrentPosition(StreamPos); |
| 1331 | if (OB.CurrentPackMax == 0) { |
| 1332 | OB.setCurrentPosition(StreamPos); |
| 1186 | 1333 | return; |
| 1187 | 1334 | } |
| 1188 | 1335 | |
| 1189 | 1336 | // Else, iterate through the rest of the elements in the pack. |
| 1190 | | for (unsigned I = 1, E = S.CurrentPackMax; I < E; ++I) { |
| 1191 | | S += ", "; |
| 1192 | | S.CurrentPackIndex = I; |
| 1193 | | Child->print(S); |
| 1337 | for (unsigned I = 1, E = OB.CurrentPackMax; I < E; ++I) { |
| 1338 | OB += ", "; |
| 1339 | OB.CurrentPackIndex = I; |
| 1340 | Child->print(OB); |
| 1194 | 1341 | } |
| 1195 | 1342 | } |
| 1196 | 1343 | }; |
| ... | ... | @@ -1205,12 +1352,12 @@ public: |
| 1205 | 1352 | |
| 1206 | 1353 | NodeArray getParams() { return Params; } |
| 1207 | 1354 | |
| 1208 | | void printLeft(OutputStream &S) const override { |
| 1209 | | S += "<"; |
| 1210 | | Params.printWithComma(S); |
| 1211 | | if (S.back() == '>') |
| 1212 | | S += " "; |
| 1213 | | S += ">"; |
| 1355 | void printLeft(OutputBuffer &OB) const override { |
| 1356 | OB += "<"; |
| 1357 | Params.printWithComma(OB); |
| 1358 | if (OB.back() == '>') |
| 1359 | OB += " "; |
| 1360 | OB += ">"; |
| 1214 | 1361 | } |
| 1215 | 1362 | }; |
| 1216 | 1363 | |
| ... | ... | @@ -1252,42 +1399,42 @@ struct ForwardTemplateReference : Node { |
| 1252 | 1399 | // special handling. |
| 1253 | 1400 | template<typename Fn> void match(Fn F) const = delete; |
| 1254 | 1401 | |
| 1255 | | bool hasRHSComponentSlow(OutputStream &S) const override { |
| 1402 | bool hasRHSComponentSlow(OutputBuffer &OB) const override { |
| 1256 | 1403 | if (Printing) |
| 1257 | 1404 | return false; |
| 1258 | 1405 | SwapAndRestore<bool> SavePrinting(Printing, true); |
| 1259 | | return Ref->hasRHSComponent(S); |
| 1406 | return Ref->hasRHSComponent(OB); |
| 1260 | 1407 | } |
| 1261 | | bool hasArraySlow(OutputStream &S) const override { |
| 1408 | bool hasArraySlow(OutputBuffer &OB) const override { |
| 1262 | 1409 | if (Printing) |
| 1263 | 1410 | return false; |
| 1264 | 1411 | SwapAndRestore<bool> SavePrinting(Printing, true); |
| 1265 | | return Ref->hasArray(S); |
| 1412 | return Ref->hasArray(OB); |
| 1266 | 1413 | } |
| 1267 | | bool hasFunctionSlow(OutputStream &S) const override { |
| 1414 | bool hasFunctionSlow(OutputBuffer &OB) const override { |
| 1268 | 1415 | if (Printing) |
| 1269 | 1416 | return false; |
| 1270 | 1417 | SwapAndRestore<bool> SavePrinting(Printing, true); |
| 1271 | | return Ref->hasFunction(S); |
| 1418 | return Ref->hasFunction(OB); |
| 1272 | 1419 | } |
| 1273 | | const Node *getSyntaxNode(OutputStream &S) const override { |
| 1420 | const Node *getSyntaxNode(OutputBuffer &OB) const override { |
| 1274 | 1421 | if (Printing) |
| 1275 | 1422 | return this; |
| 1276 | 1423 | SwapAndRestore<bool> SavePrinting(Printing, true); |
| 1277 | | return Ref->getSyntaxNode(S); |
| 1424 | return Ref->getSyntaxNode(OB); |
| 1278 | 1425 | } |
| 1279 | 1426 | |
| 1280 | | void printLeft(OutputStream &S) const override { |
| 1427 | void printLeft(OutputBuffer &OB) const override { |
| 1281 | 1428 | if (Printing) |
| 1282 | 1429 | return; |
| 1283 | 1430 | SwapAndRestore<bool> SavePrinting(Printing, true); |
| 1284 | | Ref->printLeft(S); |
| 1431 | Ref->printLeft(OB); |
| 1285 | 1432 | } |
| 1286 | | void printRight(OutputStream &S) const override { |
| 1433 | void printRight(OutputBuffer &OB) const override { |
| 1287 | 1434 | if (Printing) |
| 1288 | 1435 | return; |
| 1289 | 1436 | SwapAndRestore<bool> SavePrinting(Printing, true); |
| 1290 | | Ref->printRight(S); |
| 1437 | Ref->printRight(OB); |
| 1291 | 1438 | } |
| 1292 | 1439 | }; |
| 1293 | 1440 | |
| ... | ... | @@ -1303,9 +1450,9 @@ struct NameWithTemplateArgs : Node { |
| 1303 | 1450 | |
| 1304 | 1451 | StringView getBaseName() const override { return Name->getBaseName(); } |
| 1305 | 1452 | |
| 1306 | | void printLeft(OutputStream &S) const override { |
| 1307 | | Name->print(S); |
| 1308 | | TemplateArgs->print(S); |
| 1453 | void printLeft(OutputBuffer &OB) const override { |
| 1454 | Name->print(OB); |
| 1455 | TemplateArgs->print(OB); |
| 1309 | 1456 | } |
| 1310 | 1457 | }; |
| 1311 | 1458 | |
| ... | ... | @@ -1320,9 +1467,9 @@ public: |
| 1320 | 1467 | |
| 1321 | 1468 | StringView getBaseName() const override { return Child->getBaseName(); } |
| 1322 | 1469 | |
| 1323 | | void printLeft(OutputStream &S) const override { |
| 1324 | | S += "::"; |
| 1325 | | Child->print(S); |
| 1470 | void printLeft(OutputBuffer &OB) const override { |
| 1471 | OB += "::"; |
| 1472 | Child->print(OB); |
| 1326 | 1473 | } |
| 1327 | 1474 | }; |
| 1328 | 1475 | |
| ... | ... | @@ -1335,9 +1482,9 @@ struct StdQualifiedName : Node { |
| 1335 | 1482 | |
| 1336 | 1483 | StringView getBaseName() const override { return Child->getBaseName(); } |
| 1337 | 1484 | |
| 1338 | | void printLeft(OutputStream &S) const override { |
| 1339 | | S += "std::"; |
| 1340 | | Child->print(S); |
| 1485 | void printLeft(OutputBuffer &OB) const override { |
| 1486 | OB += "std::"; |
| 1487 | Child->print(OB); |
| 1341 | 1488 | } |
| 1342 | 1489 | }; |
| 1343 | 1490 | |
| ... | ... | @@ -1377,26 +1524,26 @@ public: |
| 1377 | 1524 | DEMANGLE_UNREACHABLE; |
| 1378 | 1525 | } |
| 1379 | 1526 | |
| 1380 | | void printLeft(OutputStream &S) const override { |
| 1527 | void printLeft(OutputBuffer &OB) const override { |
| 1381 | 1528 | switch (SSK) { |
| 1382 | 1529 | case SpecialSubKind::allocator: |
| 1383 | | S += "std::allocator"; |
| 1530 | OB += "std::allocator"; |
| 1384 | 1531 | break; |
| 1385 | 1532 | case SpecialSubKind::basic_string: |
| 1386 | | S += "std::basic_string"; |
| 1533 | OB += "std::basic_string"; |
| 1387 | 1534 | break; |
| 1388 | 1535 | case SpecialSubKind::string: |
| 1389 | | S += "std::basic_string<char, std::char_traits<char>, " |
| 1390 | | "std::allocator<char> >"; |
| 1536 | OB += "std::basic_string<char, std::char_traits<char>, " |
| 1537 | "std::allocator<char> >"; |
| 1391 | 1538 | break; |
| 1392 | 1539 | case SpecialSubKind::istream: |
| 1393 | | S += "std::basic_istream<char, std::char_traits<char> >"; |
| 1540 | OB += "std::basic_istream<char, std::char_traits<char> >"; |
| 1394 | 1541 | break; |
| 1395 | 1542 | case SpecialSubKind::ostream: |
| 1396 | | S += "std::basic_ostream<char, std::char_traits<char> >"; |
| 1543 | OB += "std::basic_ostream<char, std::char_traits<char> >"; |
| 1397 | 1544 | break; |
| 1398 | 1545 | case SpecialSubKind::iostream: |
| 1399 | | S += "std::basic_iostream<char, std::char_traits<char> >"; |
| 1546 | OB += "std::basic_iostream<char, std::char_traits<char> >"; |
| 1400 | 1547 | break; |
| 1401 | 1548 | } |
| 1402 | 1549 | } |
| ... | ... | @@ -1429,25 +1576,25 @@ public: |
| 1429 | 1576 | DEMANGLE_UNREACHABLE; |
| 1430 | 1577 | } |
| 1431 | 1578 | |
| 1432 | | void printLeft(OutputStream &S) const override { |
| 1579 | void printLeft(OutputBuffer &OB) const override { |
| 1433 | 1580 | switch (SSK) { |
| 1434 | 1581 | case SpecialSubKind::allocator: |
| 1435 | | S += "std::allocator"; |
| 1582 | OB += "std::allocator"; |
| 1436 | 1583 | break; |
| 1437 | 1584 | case SpecialSubKind::basic_string: |
| 1438 | | S += "std::basic_string"; |
| 1585 | OB += "std::basic_string"; |
| 1439 | 1586 | break; |
| 1440 | 1587 | case SpecialSubKind::string: |
| 1441 | | S += "std::string"; |
| 1588 | OB += "std::string"; |
| 1442 | 1589 | break; |
| 1443 | 1590 | case SpecialSubKind::istream: |
| 1444 | | S += "std::istream"; |
| 1591 | OB += "std::istream"; |
| 1445 | 1592 | break; |
| 1446 | 1593 | case SpecialSubKind::ostream: |
| 1447 | | S += "std::ostream"; |
| 1594 | OB += "std::ostream"; |
| 1448 | 1595 | break; |
| 1449 | 1596 | case SpecialSubKind::iostream: |
| 1450 | | S += "std::iostream"; |
| 1597 | OB += "std::iostream"; |
| 1451 | 1598 | break; |
| 1452 | 1599 | } |
| 1453 | 1600 | } |
| ... | ... | @@ -1465,10 +1612,10 @@ public: |
| 1465 | 1612 | |
| 1466 | 1613 | template<typename Fn> void match(Fn F) const { F(Basename, IsDtor, Variant); } |
| 1467 | 1614 | |
| 1468 | | void printLeft(OutputStream &S) const override { |
| 1615 | void printLeft(OutputBuffer &OB) const override { |
| 1469 | 1616 | if (IsDtor) |
| 1470 | | S += "~"; |
| 1471 | | S += Basename->getBaseName(); |
| 1617 | OB += "~"; |
| 1618 | OB += Basename->getBaseName(); |
| 1472 | 1619 | } |
| 1473 | 1620 | }; |
| 1474 | 1621 | |
| ... | ... | @@ -1480,9 +1627,9 @@ public: |
| 1480 | 1627 | |
| 1481 | 1628 | template<typename Fn> void match(Fn F) const { F(Base); } |
| 1482 | 1629 | |
| 1483 | | void printLeft(OutputStream &S) const override { |
| 1484 | | S += "~"; |
| 1485 | | Base->printLeft(S); |
| 1630 | void printLeft(OutputBuffer &OB) const override { |
| 1631 | OB += "~"; |
| 1632 | Base->printLeft(OB); |
| 1486 | 1633 | } |
| 1487 | 1634 | }; |
| 1488 | 1635 | |
| ... | ... | @@ -1494,10 +1641,10 @@ public: |
| 1494 | 1641 | |
| 1495 | 1642 | template<typename Fn> void match(Fn F) const { F(Count); } |
| 1496 | 1643 | |
| 1497 | | void printLeft(OutputStream &S) const override { |
| 1498 | | S += "'unnamed"; |
| 1499 | | S += Count; |
| 1500 | | S += "\'"; |
| 1644 | void printLeft(OutputBuffer &OB) const override { |
| 1645 | OB += "'unnamed"; |
| 1646 | OB += Count; |
| 1647 | OB += "\'"; |
| 1501 | 1648 | } |
| 1502 | 1649 | }; |
| 1503 | 1650 | |
| ... | ... | @@ -1516,22 +1663,22 @@ public: |
| 1516 | 1663 | F(TemplateParams, Params, Count); |
| 1517 | 1664 | } |
| 1518 | 1665 | |
| 1519 | | void printDeclarator(OutputStream &S) const { |
| 1666 | void printDeclarator(OutputBuffer &OB) const { |
| 1520 | 1667 | if (!TemplateParams.empty()) { |
| 1521 | | S += "<"; |
| 1522 | | TemplateParams.printWithComma(S); |
| 1523 | | S += ">"; |
| 1668 | OB += "<"; |
| 1669 | TemplateParams.printWithComma(OB); |
| 1670 | OB += ">"; |
| 1524 | 1671 | } |
| 1525 | | S += "("; |
| 1526 | | Params.printWithComma(S); |
| 1527 | | S += ")"; |
| 1672 | OB += "("; |
| 1673 | Params.printWithComma(OB); |
| 1674 | OB += ")"; |
| 1528 | 1675 | } |
| 1529 | 1676 | |
| 1530 | | void printLeft(OutputStream &S) const override { |
| 1531 | | S += "\'lambda"; |
| 1532 | | S += Count; |
| 1533 | | S += "\'"; |
| 1534 | | printDeclarator(S); |
| 1677 | void printLeft(OutputBuffer &OB) const override { |
| 1678 | OB += "\'lambda"; |
| 1679 | OB += Count; |
| 1680 | OB += "\'"; |
| 1681 | printDeclarator(OB); |
| 1535 | 1682 | } |
| 1536 | 1683 | }; |
| 1537 | 1684 | |
| ... | ... | @@ -1543,10 +1690,10 @@ public: |
| 1543 | 1690 | |
| 1544 | 1691 | template<typename Fn> void match(Fn F) const { F(Bindings); } |
| 1545 | 1692 | |
| 1546 | | void printLeft(OutputStream &S) const override { |
| 1547 | | S += '['; |
| 1548 | | Bindings.printWithComma(S); |
| 1549 | | S += ']'; |
| 1693 | void printLeft(OutputBuffer &OB) const override { |
| 1694 | OB += '['; |
| 1695 | Bindings.printWithComma(OB); |
| 1696 | OB += ']'; |
| 1550 | 1697 | } |
| 1551 | 1698 | }; |
| 1552 | 1699 | |
| ... | ... | @@ -1564,22 +1711,22 @@ public: |
| 1564 | 1711 | |
| 1565 | 1712 | template<typename Fn> void match(Fn F) const { F(LHS, InfixOperator, RHS); } |
| 1566 | 1713 | |
| 1567 | | void printLeft(OutputStream &S) const override { |
| 1714 | void printLeft(OutputBuffer &OB) const override { |
| 1568 | 1715 | // might be a template argument expression, then we need to disambiguate |
| 1569 | 1716 | // with parens. |
| 1570 | 1717 | if (InfixOperator == ">") |
| 1571 | | S += "("; |
| 1718 | OB += "("; |
| 1572 | 1719 | |
| 1573 | | S += "("; |
| 1574 | | LHS->print(S); |
| 1575 | | S += ") "; |
| 1576 | | S += InfixOperator; |
| 1577 | | S += " ("; |
| 1578 | | RHS->print(S); |
| 1579 | | S += ")"; |
| 1720 | OB += "("; |
| 1721 | LHS->print(OB); |
| 1722 | OB += ") "; |
| 1723 | OB += InfixOperator; |
| 1724 | OB += " ("; |
| 1725 | RHS->print(OB); |
| 1726 | OB += ")"; |
| 1580 | 1727 | |
| 1581 | 1728 | if (InfixOperator == ">") |
| 1582 | | S += ")"; |
| 1729 | OB += ")"; |
| 1583 | 1730 | } |
| 1584 | 1731 | }; |
| 1585 | 1732 | |
| ... | ... | @@ -1593,12 +1740,12 @@ public: |
| 1593 | 1740 | |
| 1594 | 1741 | template<typename Fn> void match(Fn F) const { F(Op1, Op2); } |
| 1595 | 1742 | |
| 1596 | | void printLeft(OutputStream &S) const override { |
| 1597 | | S += "("; |
| 1598 | | Op1->print(S); |
| 1599 | | S += ")["; |
| 1600 | | Op2->print(S); |
| 1601 | | S += "]"; |
| 1743 | void printLeft(OutputBuffer &OB) const override { |
| 1744 | OB += "("; |
| 1745 | Op1->print(OB); |
| 1746 | OB += ")["; |
| 1747 | Op2->print(OB); |
| 1748 | OB += "]"; |
| 1602 | 1749 | } |
| 1603 | 1750 | }; |
| 1604 | 1751 | |
| ... | ... | @@ -1612,11 +1759,11 @@ public: |
| 1612 | 1759 | |
| 1613 | 1760 | template<typename Fn> void match(Fn F) const { F(Child, Operator); } |
| 1614 | 1761 | |
| 1615 | | void printLeft(OutputStream &S) const override { |
| 1616 | | S += "("; |
| 1617 | | Child->print(S); |
| 1618 | | S += ")"; |
| 1619 | | S += Operator; |
| 1762 | void printLeft(OutputBuffer &OB) const override { |
| 1763 | OB += "("; |
| 1764 | Child->print(OB); |
| 1765 | OB += ")"; |
| 1766 | OB += Operator; |
| 1620 | 1767 | } |
| 1621 | 1768 | }; |
| 1622 | 1769 | |
| ... | ... | @@ -1631,14 +1778,14 @@ public: |
| 1631 | 1778 | |
| 1632 | 1779 | template<typename Fn> void match(Fn F) const { F(Cond, Then, Else); } |
| 1633 | 1780 | |
| 1634 | | void printLeft(OutputStream &S) const override { |
| 1635 | | S += "("; |
| 1636 | | Cond->print(S); |
| 1637 | | S += ") ? ("; |
| 1638 | | Then->print(S); |
| 1639 | | S += ") : ("; |
| 1640 | | Else->print(S); |
| 1641 | | S += ")"; |
| 1781 | void printLeft(OutputBuffer &OB) const override { |
| 1782 | OB += "("; |
| 1783 | Cond->print(OB); |
| 1784 | OB += ") ? ("; |
| 1785 | Then->print(OB); |
| 1786 | OB += ") : ("; |
| 1787 | Else->print(OB); |
| 1788 | OB += ")"; |
| 1642 | 1789 | } |
| 1643 | 1790 | }; |
| 1644 | 1791 | |
| ... | ... | @@ -1653,10 +1800,10 @@ public: |
| 1653 | 1800 | |
| 1654 | 1801 | template<typename Fn> void match(Fn F) const { F(LHS, Kind, RHS); } |
| 1655 | 1802 | |
| 1656 | | void printLeft(OutputStream &S) const override { |
| 1657 | | LHS->print(S); |
| 1658 | | S += Kind; |
| 1659 | | RHS->print(S); |
| 1803 | void printLeft(OutputBuffer &OB) const override { |
| 1804 | LHS->print(OB); |
| 1805 | OB += Kind; |
| 1806 | RHS->print(OB); |
| 1660 | 1807 | } |
| 1661 | 1808 | }; |
| 1662 | 1809 | |
| ... | ... | @@ -1677,20 +1824,20 @@ public: |
| 1677 | 1824 | F(Type, SubExpr, Offset, UnionSelectors, OnePastTheEnd); |
| 1678 | 1825 | } |
| 1679 | 1826 | |
| 1680 | | void printLeft(OutputStream &S) const override { |
| 1681 | | SubExpr->print(S); |
| 1682 | | S += ".<"; |
| 1683 | | Type->print(S); |
| 1684 | | S += " at offset "; |
| 1827 | void printLeft(OutputBuffer &OB) const override { |
| 1828 | SubExpr->print(OB); |
| 1829 | OB += ".<"; |
| 1830 | Type->print(OB); |
| 1831 | OB += " at offset "; |
| 1685 | 1832 | if (Offset.empty()) { |
| 1686 | | S += "0"; |
| 1833 | OB += "0"; |
| 1687 | 1834 | } else if (Offset[0] == 'n') { |
| 1688 | | S += "-"; |
| 1689 | | S += Offset.dropFront(); |
| 1835 | OB += "-"; |
| 1836 | OB += Offset.dropFront(); |
| 1690 | 1837 | } else { |
| 1691 | | S += Offset; |
| 1838 | OB += Offset; |
| 1692 | 1839 | } |
| 1693 | | S += ">"; |
| 1840 | OB += ">"; |
| 1694 | 1841 | } |
| 1695 | 1842 | }; |
| 1696 | 1843 | |
| ... | ... | @@ -1706,10 +1853,10 @@ public: |
| 1706 | 1853 | |
| 1707 | 1854 | template<typename Fn> void match(Fn F) const { F(Prefix, Infix, Postfix); } |
| 1708 | 1855 | |
| 1709 | | void printLeft(OutputStream &S) const override { |
| 1710 | | S += Prefix; |
| 1711 | | Infix->print(S); |
| 1712 | | S += Postfix; |
| 1856 | void printLeft(OutputBuffer &OB) const override { |
| 1857 | OB += Prefix; |
| 1858 | Infix->print(OB); |
| 1859 | OB += Postfix; |
| 1713 | 1860 | } |
| 1714 | 1861 | }; |
| 1715 | 1862 | |
| ... | ... | @@ -1725,13 +1872,13 @@ public: |
| 1725 | 1872 | |
| 1726 | 1873 | template<typename Fn> void match(Fn F) const { F(CastKind, To, From); } |
| 1727 | 1874 | |
| 1728 | | void printLeft(OutputStream &S) const override { |
| 1729 | | S += CastKind; |
| 1730 | | S += "<"; |
| 1731 | | To->printLeft(S); |
| 1732 | | S += ">("; |
| 1733 | | From->printLeft(S); |
| 1734 | | S += ")"; |
| 1875 | void printLeft(OutputBuffer &OB) const override { |
| 1876 | OB += CastKind; |
| 1877 | OB += "<"; |
| 1878 | To->printLeft(OB); |
| 1879 | OB += ">("; |
| 1880 | From->printLeft(OB); |
| 1881 | OB += ")"; |
| 1735 | 1882 | } |
| 1736 | 1883 | }; |
| 1737 | 1884 | |
| ... | ... | @@ -1744,11 +1891,11 @@ public: |
| 1744 | 1891 | |
| 1745 | 1892 | template<typename Fn> void match(Fn F) const { F(Pack); } |
| 1746 | 1893 | |
| 1747 | | void printLeft(OutputStream &S) const override { |
| 1748 | | S += "sizeof...("; |
| 1894 | void printLeft(OutputBuffer &OB) const override { |
| 1895 | OB += "sizeof...("; |
| 1749 | 1896 | ParameterPackExpansion PPE(Pack); |
| 1750 | | PPE.printLeft(S); |
| 1751 | | S += ")"; |
| 1897 | PPE.printLeft(OB); |
| 1898 | OB += ")"; |
| 1752 | 1899 | } |
| 1753 | 1900 | }; |
| 1754 | 1901 | |
| ... | ... | @@ -1762,11 +1909,11 @@ public: |
| 1762 | 1909 | |
| 1763 | 1910 | template<typename Fn> void match(Fn F) const { F(Callee, Args); } |
| 1764 | 1911 | |
| 1765 | | void printLeft(OutputStream &S) const override { |
| 1766 | | Callee->print(S); |
| 1767 | | S += "("; |
| 1768 | | Args.printWithComma(S); |
| 1769 | | S += ")"; |
| 1912 | void printLeft(OutputBuffer &OB) const override { |
| 1913 | Callee->print(OB); |
| 1914 | OB += "("; |
| 1915 | Args.printWithComma(OB); |
| 1916 | OB += ")"; |
| 1770 | 1917 | } |
| 1771 | 1918 | }; |
| 1772 | 1919 | |
| ... | ... | @@ -1787,25 +1934,24 @@ public: |
| 1787 | 1934 | F(ExprList, Type, InitList, IsGlobal, IsArray); |
| 1788 | 1935 | } |
| 1789 | 1936 | |
| 1790 | | void printLeft(OutputStream &S) const override { |
| 1937 | void printLeft(OutputBuffer &OB) const override { |
| 1791 | 1938 | if (IsGlobal) |
| 1792 | | S += "::operator "; |
| 1793 | | S += "new"; |
| 1939 | OB += "::operator "; |
| 1940 | OB += "new"; |
| 1794 | 1941 | if (IsArray) |
| 1795 | | S += "[]"; |
| 1796 | | S += ' '; |
| 1942 | OB += "[]"; |
| 1943 | OB += ' '; |
| 1797 | 1944 | if (!ExprList.empty()) { |
| 1798 | | S += "("; |
| 1799 | | ExprList.printWithComma(S); |
| 1800 | | S += ")"; |
| 1945 | OB += "("; |
| 1946 | ExprList.printWithComma(OB); |
| 1947 | OB += ")"; |
| 1801 | 1948 | } |
| 1802 | | Type->print(S); |
| 1949 | Type->print(OB); |
| 1803 | 1950 | if (!InitList.empty()) { |
| 1804 | | S += "("; |
| 1805 | | InitList.printWithComma(S); |
| 1806 | | S += ")"; |
| 1951 | OB += "("; |
| 1952 | InitList.printWithComma(OB); |
| 1953 | OB += ")"; |
| 1807 | 1954 | } |
| 1808 | | |
| 1809 | 1955 | } |
| 1810 | 1956 | }; |
| 1811 | 1957 | |
| ... | ... | @@ -1820,13 +1966,13 @@ public: |
| 1820 | 1966 | |
| 1821 | 1967 | template<typename Fn> void match(Fn F) const { F(Op, IsGlobal, IsArray); } |
| 1822 | 1968 | |
| 1823 | | void printLeft(OutputStream &S) const override { |
| 1969 | void printLeft(OutputBuffer &OB) const override { |
| 1824 | 1970 | if (IsGlobal) |
| 1825 | | S += "::"; |
| 1826 | | S += "delete"; |
| 1971 | OB += "::"; |
| 1972 | OB += "delete"; |
| 1827 | 1973 | if (IsArray) |
| 1828 | | S += "[] "; |
| 1829 | | Op->print(S); |
| 1974 | OB += "[] "; |
| 1975 | Op->print(OB); |
| 1830 | 1976 | } |
| 1831 | 1977 | }; |
| 1832 | 1978 | |
| ... | ... | @@ -1840,11 +1986,11 @@ public: |
| 1840 | 1986 | |
| 1841 | 1987 | template<typename Fn> void match(Fn F) const { F(Prefix, Child); } |
| 1842 | 1988 | |
| 1843 | | void printLeft(OutputStream &S) const override { |
| 1844 | | S += Prefix; |
| 1845 | | S += "("; |
| 1846 | | Child->print(S); |
| 1847 | | S += ")"; |
| 1989 | void printLeft(OutputBuffer &OB) const override { |
| 1990 | OB += Prefix; |
| 1991 | OB += "("; |
| 1992 | Child->print(OB); |
| 1993 | OB += ")"; |
| 1848 | 1994 | } |
| 1849 | 1995 | }; |
| 1850 | 1996 | |
| ... | ... | @@ -1856,9 +2002,9 @@ public: |
| 1856 | 2002 | |
| 1857 | 2003 | template<typename Fn> void match(Fn F) const { F(Number); } |
| 1858 | 2004 | |
| 1859 | | void printLeft(OutputStream &S) const override { |
| 1860 | | S += "fp"; |
| 1861 | | S += Number; |
| 2005 | void printLeft(OutputBuffer &OB) const override { |
| 2006 | OB += "fp"; |
| 2007 | OB += Number; |
| 1862 | 2008 | } |
| 1863 | 2009 | }; |
| 1864 | 2010 | |
| ... | ... | @@ -1872,12 +2018,12 @@ public: |
| 1872 | 2018 | |
| 1873 | 2019 | template<typename Fn> void match(Fn F) const { F(Type, Expressions); } |
| 1874 | 2020 | |
| 1875 | | void printLeft(OutputStream &S) const override { |
| 1876 | | S += "("; |
| 1877 | | Type->print(S); |
| 1878 | | S += ")("; |
| 1879 | | Expressions.printWithComma(S); |
| 1880 | | S += ")"; |
| 2021 | void printLeft(OutputBuffer &OB) const override { |
| 2022 | OB += "("; |
| 2023 | Type->print(OB); |
| 2024 | OB += ")("; |
| 2025 | Expressions.printWithComma(OB); |
| 2026 | OB += ")"; |
| 1881 | 2027 | } |
| 1882 | 2028 | }; |
| 1883 | 2029 | |
| ... | ... | @@ -1894,12 +2040,12 @@ public: |
| 1894 | 2040 | |
| 1895 | 2041 | template<typename Fn> void match(Fn F) const { F(Type, SubExpr, Offset); } |
| 1896 | 2042 | |
| 1897 | | void printLeft(OutputStream &S) const override { |
| 1898 | | S += "("; |
| 1899 | | Type->print(S); |
| 1900 | | S += ")("; |
| 1901 | | SubExpr->print(S); |
| 1902 | | S += ")"; |
| 2043 | void printLeft(OutputBuffer &OB) const override { |
| 2044 | OB += "("; |
| 2045 | Type->print(OB); |
| 2046 | OB += ")("; |
| 2047 | SubExpr->print(OB); |
| 2048 | OB += ")"; |
| 1903 | 2049 | } |
| 1904 | 2050 | }; |
| 1905 | 2051 | |
| ... | ... | @@ -1912,12 +2058,12 @@ public: |
| 1912 | 2058 | |
| 1913 | 2059 | template<typename Fn> void match(Fn F) const { F(Ty, Inits); } |
| 1914 | 2060 | |
| 1915 | | void printLeft(OutputStream &S) const override { |
| 2061 | void printLeft(OutputBuffer &OB) const override { |
| 1916 | 2062 | if (Ty) |
| 1917 | | Ty->print(S); |
| 1918 | | S += '{'; |
| 1919 | | Inits.printWithComma(S); |
| 1920 | | S += '}'; |
| 2063 | Ty->print(OB); |
| 2064 | OB += '{'; |
| 2065 | Inits.printWithComma(OB); |
| 2066 | OB += '}'; |
| 1921 | 2067 | } |
| 1922 | 2068 | }; |
| 1923 | 2069 | |
| ... | ... | @@ -1931,18 +2077,18 @@ public: |
| 1931 | 2077 | |
| 1932 | 2078 | template<typename Fn> void match(Fn F) const { F(Elem, Init, IsArray); } |
| 1933 | 2079 | |
| 1934 | | void printLeft(OutputStream &S) const override { |
| 2080 | void printLeft(OutputBuffer &OB) const override { |
| 1935 | 2081 | if (IsArray) { |
| 1936 | | S += '['; |
| 1937 | | Elem->print(S); |
| 1938 | | S += ']'; |
| 2082 | OB += '['; |
| 2083 | Elem->print(OB); |
| 2084 | OB += ']'; |
| 1939 | 2085 | } else { |
| 1940 | | S += '.'; |
| 1941 | | Elem->print(S); |
| 2086 | OB += '.'; |
| 2087 | Elem->print(OB); |
| 1942 | 2088 | } |
| 1943 | 2089 | if (Init->getKind() != KBracedExpr && Init->getKind() != KBracedRangeExpr) |
| 1944 | | S += " = "; |
| 1945 | | Init->print(S); |
| 2090 | OB += " = "; |
| 2091 | Init->print(OB); |
| 1946 | 2092 | } |
| 1947 | 2093 | }; |
| 1948 | 2094 | |
| ... | ... | @@ -1956,15 +2102,15 @@ public: |
| 1956 | 2102 | |
| 1957 | 2103 | template<typename Fn> void match(Fn F) const { F(First, Last, Init); } |
| 1958 | 2104 | |
| 1959 | | void printLeft(OutputStream &S) const override { |
| 1960 | | S += '['; |
| 1961 | | First->print(S); |
| 1962 | | S += " ... "; |
| 1963 | | Last->print(S); |
| 1964 | | S += ']'; |
| 2105 | void printLeft(OutputBuffer &OB) const override { |
| 2106 | OB += '['; |
| 2107 | First->print(OB); |
| 2108 | OB += " ... "; |
| 2109 | Last->print(OB); |
| 2110 | OB += ']'; |
| 1965 | 2111 | if (Init->getKind() != KBracedExpr && Init->getKind() != KBracedRangeExpr) |
| 1966 | | S += " = "; |
| 1967 | | Init->print(S); |
| 2112 | OB += " = "; |
| 2113 | Init->print(OB); |
| 1968 | 2114 | } |
| 1969 | 2115 | }; |
| 1970 | 2116 | |
| ... | ... | @@ -1983,43 +2129,43 @@ public: |
| 1983 | 2129 | F(IsLeftFold, OperatorName, Pack, Init); |
| 1984 | 2130 | } |
| 1985 | 2131 | |
| 1986 | | void printLeft(OutputStream &S) const override { |
| 2132 | void printLeft(OutputBuffer &OB) const override { |
| 1987 | 2133 | auto PrintPack = [&] { |
| 1988 | | S += '('; |
| 1989 | | ParameterPackExpansion(Pack).print(S); |
| 1990 | | S += ')'; |
| 2134 | OB += '('; |
| 2135 | ParameterPackExpansion(Pack).print(OB); |
| 2136 | OB += ')'; |
| 1991 | 2137 | }; |
| 1992 | 2138 | |
| 1993 | | S += '('; |
| 2139 | OB += '('; |
| 1994 | 2140 | |
| 1995 | 2141 | if (IsLeftFold) { |
| 1996 | 2142 | // init op ... op pack |
| 1997 | 2143 | if (Init != nullptr) { |
| 1998 | | Init->print(S); |
| 1999 | | S += ' '; |
| 2000 | | S += OperatorName; |
| 2001 | | S += ' '; |
| 2144 | Init->print(OB); |
| 2145 | OB += ' '; |
| 2146 | OB += OperatorName; |
| 2147 | OB += ' '; |
| 2002 | 2148 | } |
| 2003 | 2149 | // ... op pack |
| 2004 | | S += "... "; |
| 2005 | | S += OperatorName; |
| 2006 | | S += ' '; |
| 2150 | OB += "... "; |
| 2151 | OB += OperatorName; |
| 2152 | OB += ' '; |
| 2007 | 2153 | PrintPack(); |
| 2008 | 2154 | } else { // !IsLeftFold |
| 2009 | 2155 | // pack op ... |
| 2010 | 2156 | PrintPack(); |
| 2011 | | S += ' '; |
| 2012 | | S += OperatorName; |
| 2013 | | S += " ..."; |
| 2157 | OB += ' '; |
| 2158 | OB += OperatorName; |
| 2159 | OB += " ..."; |
| 2014 | 2160 | // pack op ... op init |
| 2015 | 2161 | if (Init != nullptr) { |
| 2016 | | S += ' '; |
| 2017 | | S += OperatorName; |
| 2018 | | S += ' '; |
| 2019 | | Init->print(S); |
| 2162 | OB += ' '; |
| 2163 | OB += OperatorName; |
| 2164 | OB += ' '; |
| 2165 | Init->print(OB); |
| 2020 | 2166 | } |
| 2021 | 2167 | } |
| 2022 | | S += ')'; |
| 2168 | OB += ')'; |
| 2023 | 2169 | } |
| 2024 | 2170 | }; |
| 2025 | 2171 | |
| ... | ... | @@ -2031,9 +2177,9 @@ public: |
| 2031 | 2177 | |
| 2032 | 2178 | template<typename Fn> void match(Fn F) const { F(Op); } |
| 2033 | 2179 | |
| 2034 | | void printLeft(OutputStream &S) const override { |
| 2035 | | S += "throw "; |
| 2036 | | Op->print(S); |
| 2180 | void printLeft(OutputBuffer &OB) const override { |
| 2181 | OB += "throw "; |
| 2182 | Op->print(OB); |
| 2037 | 2183 | } |
| 2038 | 2184 | }; |
| 2039 | 2185 | |
| ... | ... | @@ -2045,8 +2191,8 @@ public: |
| 2045 | 2191 | |
| 2046 | 2192 | template<typename Fn> void match(Fn F) const { F(Value); } |
| 2047 | 2193 | |
| 2048 | | void printLeft(OutputStream &S) const override { |
| 2049 | | S += Value ? StringView("true") : StringView("false"); |
| 2194 | void printLeft(OutputBuffer &OB) const override { |
| 2195 | OB += Value ? StringView("true") : StringView("false"); |
| 2050 | 2196 | } |
| 2051 | 2197 | }; |
| 2052 | 2198 | |
| ... | ... | @@ -2058,10 +2204,10 @@ public: |
| 2058 | 2204 | |
| 2059 | 2205 | template<typename Fn> void match(Fn F) const { F(Type); } |
| 2060 | 2206 | |
| 2061 | | void printLeft(OutputStream &S) const override { |
| 2062 | | S += "\"<"; |
| 2063 | | Type->print(S); |
| 2064 | | S += ">\""; |
| 2207 | void printLeft(OutputBuffer &OB) const override { |
| 2208 | OB += "\"<"; |
| 2209 | Type->print(OB); |
| 2210 | OB += ">\""; |
| 2065 | 2211 | } |
| 2066 | 2212 | }; |
| 2067 | 2213 | |
| ... | ... | @@ -2073,11 +2219,11 @@ public: |
| 2073 | 2219 | |
| 2074 | 2220 | template<typename Fn> void match(Fn F) const { F(Type); } |
| 2075 | 2221 | |
| 2076 | | void printLeft(OutputStream &S) const override { |
| 2077 | | S += "[]"; |
| 2222 | void printLeft(OutputBuffer &OB) const override { |
| 2223 | OB += "[]"; |
| 2078 | 2224 | if (Type->getKind() == KClosureTypeName) |
| 2079 | | static_cast<const ClosureTypeName *>(Type)->printDeclarator(S); |
| 2080 | | S += "{...}"; |
| 2225 | static_cast<const ClosureTypeName *>(Type)->printDeclarator(OB); |
| 2226 | OB += "{...}"; |
| 2081 | 2227 | } |
| 2082 | 2228 | }; |
| 2083 | 2229 | |
| ... | ... | @@ -2092,15 +2238,15 @@ public: |
| 2092 | 2238 | |
| 2093 | 2239 | template<typename Fn> void match(Fn F) const { F(Ty, Integer); } |
| 2094 | 2240 | |
| 2095 | | void printLeft(OutputStream &S) const override { |
| 2096 | | S << "("; |
| 2097 | | Ty->print(S); |
| 2098 | | S << ")"; |
| 2241 | void printLeft(OutputBuffer &OB) const override { |
| 2242 | OB << "("; |
| 2243 | Ty->print(OB); |
| 2244 | OB << ")"; |
| 2099 | 2245 | |
| 2100 | 2246 | if (Integer[0] == 'n') |
| 2101 | | S << "-" << Integer.dropFront(1); |
| 2247 | OB << "-" << Integer.dropFront(1); |
| 2102 | 2248 | else |
| 2103 | | S << Integer; |
| 2249 | OB << Integer; |
| 2104 | 2250 | } |
| 2105 | 2251 | }; |
| 2106 | 2252 | |
| ... | ... | @@ -2114,21 +2260,21 @@ public: |
| 2114 | 2260 | |
| 2115 | 2261 | template<typename Fn> void match(Fn F) const { F(Type, Value); } |
| 2116 | 2262 | |
| 2117 | | void printLeft(OutputStream &S) const override { |
| 2263 | void printLeft(OutputBuffer &OB) const override { |
| 2118 | 2264 | if (Type.size() > 3) { |
| 2119 | | S += "("; |
| 2120 | | S += Type; |
| 2121 | | S += ")"; |
| 2265 | OB += "("; |
| 2266 | OB += Type; |
| 2267 | OB += ")"; |
| 2122 | 2268 | } |
| 2123 | 2269 | |
| 2124 | 2270 | if (Value[0] == 'n') { |
| 2125 | | S += "-"; |
| 2126 | | S += Value.dropFront(1); |
| 2271 | OB += "-"; |
| 2272 | OB += Value.dropFront(1); |
| 2127 | 2273 | } else |
| 2128 | | S += Value; |
| 2274 | OB += Value; |
| 2129 | 2275 | |
| 2130 | 2276 | if (Type.size() <= 3) |
| 2131 | | S += Type; |
| 2277 | OB += Type; |
| 2132 | 2278 | } |
| 2133 | 2279 | }; |
| 2134 | 2280 | |
| ... | ... | @@ -2158,7 +2304,7 @@ public: |
| 2158 | 2304 | |
| 2159 | 2305 | template<typename Fn> void match(Fn F) const { F(Contents); } |
| 2160 | 2306 | |
| 2161 | | void printLeft(OutputStream &s) const override { |
| 2307 | void printLeft(OutputBuffer &OB) const override { |
| 2162 | 2308 | const char *first = Contents.begin(); |
| 2163 | 2309 | const char *last = Contents.end() + 1; |
| 2164 | 2310 | |
| ... | ... | @@ -2184,7 +2330,7 @@ public: |
| 2184 | 2330 | #endif |
| 2185 | 2331 | char num[FloatData<Float>::max_demangled_size] = {0}; |
| 2186 | 2332 | int n = snprintf(num, sizeof(num), FloatData<Float>::spec, value); |
| 2187 | | s += StringView(num, num + n); |
| 2333 | OB += StringView(num, num + n); |
| 2188 | 2334 | } |
| 2189 | 2335 | } |
| 2190 | 2336 | }; |
| ... | ... | @@ -2217,125 +2363,6 @@ FOR_EACH_NODE_KIND(SPECIALIZATION) |
| 2217 | 2363 | |
| 2218 | 2364 | #undef FOR_EACH_NODE_KIND |
| 2219 | 2365 | |
| 2220 | | template <class T, size_t N> |
| 2221 | | class PODSmallVector { |
| 2222 | | static_assert(std::is_pod<T>::value, |
| 2223 | | "T is required to be a plain old data type"); |
| 2224 | | |
| 2225 | | T* First = nullptr; |
| 2226 | | T* Last = nullptr; |
| 2227 | | T* Cap = nullptr; |
| 2228 | | T Inline[N] = {0}; |
| 2229 | | |
| 2230 | | bool isInline() const { return First == Inline; } |
| 2231 | | |
| 2232 | | void clearInline() { |
| 2233 | | First = Inline; |
| 2234 | | Last = Inline; |
| 2235 | | Cap = Inline + N; |
| 2236 | | } |
| 2237 | | |
| 2238 | | void reserve(size_t NewCap) { |
| 2239 | | size_t S = size(); |
| 2240 | | if (isInline()) { |
| 2241 | | auto* Tmp = static_cast<T*>(std::malloc(NewCap * sizeof(T))); |
| 2242 | | if (Tmp == nullptr) |
| 2243 | | std::terminate(); |
| 2244 | | std::copy(First, Last, Tmp); |
| 2245 | | First = Tmp; |
| 2246 | | } else { |
| 2247 | | First = static_cast<T*>(std::realloc(First, NewCap * sizeof(T))); |
| 2248 | | if (First == nullptr) |
| 2249 | | std::terminate(); |
| 2250 | | } |
| 2251 | | Last = First + S; |
| 2252 | | Cap = First + NewCap; |
| 2253 | | } |
| 2254 | | |
| 2255 | | public: |
| 2256 | | PODSmallVector() : First(Inline), Last(First), Cap(Inline + N) {} |
| 2257 | | |
| 2258 | | PODSmallVector(const PODSmallVector&) = delete; |
| 2259 | | PODSmallVector& operator=(const PODSmallVector&) = delete; |
| 2260 | | |
| 2261 | | PODSmallVector(PODSmallVector&& Other) : PODSmallVector() { |
| 2262 | | if (Other.isInline()) { |
| 2263 | | std::copy(Other.begin(), Other.end(), First); |
| 2264 | | Last = First + Other.size(); |
| 2265 | | Other.clear(); |
| 2266 | | return; |
| 2267 | | } |
| 2268 | | |
| 2269 | | First = Other.First; |
| 2270 | | Last = Other.Last; |
| 2271 | | Cap = Other.Cap; |
| 2272 | | Other.clearInline(); |
| 2273 | | } |
| 2274 | | |
| 2275 | | PODSmallVector& operator=(PODSmallVector&& Other) { |
| 2276 | | if (Other.isInline()) { |
| 2277 | | if (!isInline()) { |
| 2278 | | std::free(First); |
| 2279 | | clearInline(); |
| 2280 | | } |
| 2281 | | std::copy(Other.begin(), Other.end(), First); |
| 2282 | | Last = First + Other.size(); |
| 2283 | | Other.clear(); |
| 2284 | | return *this; |
| 2285 | | } |
| 2286 | | |
| 2287 | | if (isInline()) { |
| 2288 | | First = Other.First; |
| 2289 | | Last = Other.Last; |
| 2290 | | Cap = Other.Cap; |
| 2291 | | Other.clearInline(); |
| 2292 | | return *this; |
| 2293 | | } |
| 2294 | | |
| 2295 | | std::swap(First, Other.First); |
| 2296 | | std::swap(Last, Other.Last); |
| 2297 | | std::swap(Cap, Other.Cap); |
| 2298 | | Other.clear(); |
| 2299 | | return *this; |
| 2300 | | } |
| 2301 | | |
| 2302 | | void push_back(const T& Elem) { |
| 2303 | | if (Last == Cap) |
| 2304 | | reserve(size() * 2); |
| 2305 | | *Last++ = Elem; |
| 2306 | | } |
| 2307 | | |
| 2308 | | void pop_back() { |
| 2309 | | assert(Last != First && "Popping empty vector!"); |
| 2310 | | --Last; |
| 2311 | | } |
| 2312 | | |
| 2313 | | void dropBack(size_t Index) { |
| 2314 | | assert(Index <= size() && "dropBack() can't expand!"); |
| 2315 | | Last = First + Index; |
| 2316 | | } |
| 2317 | | |
| 2318 | | T* begin() { return First; } |
| 2319 | | T* end() { return Last; } |
| 2320 | | |
| 2321 | | bool empty() const { return First == Last; } |
| 2322 | | size_t size() const { return static_cast<size_t>(Last - First); } |
| 2323 | | T& back() { |
| 2324 | | assert(Last != First && "Calling back() on empty vector!"); |
| 2325 | | return *(Last - 1); |
| 2326 | | } |
| 2327 | | T& operator[](size_t Index) { |
| 2328 | | assert(Index < size() && "Invalid access!"); |
| 2329 | | return *(begin() + Index); |
| 2330 | | } |
| 2331 | | void clear() { Last = First; } |
| 2332 | | |
| 2333 | | ~PODSmallVector() { |
| 2334 | | if (!isInline()) |
| 2335 | | std::free(First); |
| 2336 | | } |
| 2337 | | }; |
| 2338 | | |
| 2339 | 2366 | template <typename Derived, typename Alloc> struct AbstractManglingParser { |
| 2340 | 2367 | const char *First; |
| 2341 | 2368 | const char *Last; |
| ... | ... | @@ -2450,7 +2477,7 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser { |
| 2450 | 2477 | |
| 2451 | 2478 | char consume() { return First != Last ? *First++ : '\0'; } |
| 2452 | 2479 | |
| 2453 | | char look(unsigned Lookahead = 0) { |
| 2480 | char look(unsigned Lookahead = 0) const { |
| 2454 | 2481 | if (static_cast<size_t>(Last - First) <= Lookahead) |
| 2455 | 2482 | return '\0'; |
| 2456 | 2483 | return First[Lookahead]; |
| ... | ... | @@ -2568,34 +2595,38 @@ Node *AbstractManglingParser<Derived, Alloc>::parseName(NameState *State) { |
| 2568 | 2595 | if (look() == 'Z') |
| 2569 | 2596 | return getDerived().parseLocalName(State); |
| 2570 | 2597 | |
| 2571 | | // ::= <unscoped-template-name> <template-args> |
| 2572 | | if (look() == 'S' && look(1) != 't') { |
| 2573 | | Node *S = getDerived().parseSubstitution(); |
| 2574 | | if (S == nullptr) |
| 2575 | | return nullptr; |
| 2576 | | if (look() != 'I') |
| 2577 | | return nullptr; |
| 2578 | | Node *TA = getDerived().parseTemplateArgs(State != nullptr); |
| 2579 | | if (TA == nullptr) |
| 2580 | | return nullptr; |
| 2581 | | if (State) State->EndsWithTemplateArgs = true; |
| 2582 | | return make<NameWithTemplateArgs>(S, TA); |
| 2598 | Node *Result = nullptr; |
| 2599 | bool IsSubst = look() == 'S' && look(1) != 't'; |
| 2600 | if (IsSubst) { |
| 2601 | // A substitution must lead to: |
| 2602 | // ::= <unscoped-template-name> <template-args> |
| 2603 | Result = getDerived().parseSubstitution(); |
| 2604 | } else { |
| 2605 | // An unscoped name can be one of: |
| 2606 | // ::= <unscoped-name> |
| 2607 | // ::= <unscoped-template-name> <template-args> |
| 2608 | Result = getDerived().parseUnscopedName(State); |
| 2583 | 2609 | } |
| 2584 | | |
| 2585 | | Node *N = getDerived().parseUnscopedName(State); |
| 2586 | | if (N == nullptr) |
| 2610 | if (Result == nullptr) |
| 2587 | 2611 | return nullptr; |
| 2588 | | // ::= <unscoped-template-name> <template-args> |
| 2612 | |
| 2589 | 2613 | if (look() == 'I') { |
| 2590 | | Subs.push_back(N); |
| 2614 | // ::= <unscoped-template-name> <template-args> |
| 2615 | if (!IsSubst) |
| 2616 | // An unscoped-template-name is substitutable. |
| 2617 | Subs.push_back(Result); |
| 2591 | 2618 | Node *TA = getDerived().parseTemplateArgs(State != nullptr); |
| 2592 | 2619 | if (TA == nullptr) |
| 2593 | 2620 | return nullptr; |
| 2594 | | if (State) State->EndsWithTemplateArgs = true; |
| 2595 | | return make<NameWithTemplateArgs>(N, TA); |
| 2621 | if (State) |
| 2622 | State->EndsWithTemplateArgs = true; |
| 2623 | Result = make<NameWithTemplateArgs>(Result, TA); |
| 2624 | } else if (IsSubst) { |
| 2625 | // The substitution case must be followed by <template-args>. |
| 2626 | return nullptr; |
| 2596 | 2627 | } |
| 2597 | | // ::= <unscoped-name> |
| 2598 | | return N; |
| 2628 | |
| 2629 | return Result; |
| 2599 | 2630 | } |
| 2600 | 2631 | |
| 2601 | 2632 | // <local-name> := Z <function encoding> E <entity name> [<discriminator>] |
| ... | ... | @@ -2640,13 +2671,17 @@ Node *AbstractManglingParser<Derived, Alloc>::parseLocalName(NameState *State) { |
| 2640 | 2671 | template <typename Derived, typename Alloc> |
| 2641 | 2672 | Node * |
| 2642 | 2673 | AbstractManglingParser<Derived, Alloc>::parseUnscopedName(NameState *State) { |
| 2643 | | if (consumeIf("StL") || consumeIf("St")) { |
| 2644 | | Node *R = getDerived().parseUnqualifiedName(State); |
| 2645 | | if (R == nullptr) |
| 2646 | | return nullptr; |
| 2647 | | return make<StdQualifiedName>(R); |
| 2648 | | } |
| 2649 | | return getDerived().parseUnqualifiedName(State); |
| 2674 | bool IsStd = consumeIf("St"); |
| 2675 | if (IsStd) |
| 2676 | consumeIf('L'); |
| 2677 | |
| 2678 | Node *Result = getDerived().parseUnqualifiedName(State); |
| 2679 | if (Result == nullptr) |
| 2680 | return nullptr; |
| 2681 | if (IsStd) |
| 2682 | Result = make<StdQualifiedName>(Result); |
| 2683 | |
| 2684 | return Result; |
| 2650 | 2685 | } |
| 2651 | 2686 | |
| 2652 | 2687 | // <unqualified-name> ::= <operator-name> [abi-tags] |
| ... | ... | @@ -3884,6 +3919,16 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() { |
| 3884 | 3919 | case 'h': |
| 3885 | 3920 | First += 2; |
| 3886 | 3921 | return make<NameType>("half"); |
| 3922 | // ::= DF <number> _ # ISO/IEC TS 18661 binary floating point (N bits) |
| 3923 | case 'F': { |
| 3924 | First += 2; |
| 3925 | Node *DimensionNumber = make<NameType>(parseNumber()); |
| 3926 | if (!DimensionNumber) |
| 3927 | return nullptr; |
| 3928 | if (!consumeIf('_')) |
| 3929 | return nullptr; |
| 3930 | return make<BinaryFPType>(DimensionNumber); |
| 3931 | } |
| 3887 | 3932 | // ::= Di # char32_t |
| 3888 | 3933 | case 'i': |
| 3889 | 3934 | First += 2; |
| ... | ... | @@ -4031,9 +4076,9 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() { |
| 4031 | 4076 | } |
| 4032 | 4077 | // ::= <substitution> # See Compression below |
| 4033 | 4078 | case 'S': { |
| 4034 | | if (look(1) && look(1) != 't') { |
| 4035 | | Node *Sub = getDerived().parseSubstitution(); |
| 4036 | | if (Sub == nullptr) |
| 4079 | if (look(1) != 't') { |
| 4080 | Result = getDerived().parseSubstitution(); |
| 4081 | if (Result == nullptr) |
| 4037 | 4082 | return nullptr; |
| 4038 | 4083 | |
| 4039 | 4084 | // Sub could be either of: |
| ... | ... | @@ -4050,13 +4095,13 @@ Node *AbstractManglingParser<Derived, Alloc>::parseType() { |
| 4050 | 4095 | Node *TA = getDerived().parseTemplateArgs(); |
| 4051 | 4096 | if (TA == nullptr) |
| 4052 | 4097 | return nullptr; |
| 4053 | | Result = make<NameWithTemplateArgs>(Sub, TA); |
| 4054 | | break; |
| 4098 | Result = make<NameWithTemplateArgs>(Result, TA); |
| 4099 | } else { |
| 4100 | // If all we parsed was a substitution, don't re-insert into the |
| 4101 | // substitution table. |
| 4102 | return Result; |
| 4055 | 4103 | } |
| 4056 | | |
| 4057 | | // If all we parsed was a substitution, don't re-insert into the |
| 4058 | | // substitution table. |
| 4059 | | return Sub; |
| 4104 | break; |
| 4060 | 4105 | } |
| 4061 | 4106 | DEMANGLE_FALLTHROUGH; |
| 4062 | 4107 | } |
| ... | ... | @@ -5404,38 +5449,35 @@ Node *AbstractManglingParser<Derived, Alloc>::parseSubstitution() { |
| 5404 | 5449 | if (!consumeIf('S')) |
| 5405 | 5450 | return nullptr; |
| 5406 | 5451 | |
| 5407 | | if (std::islower(look())) { |
| 5408 | | Node *SpecialSub; |
| 5452 | if (look() >= 'a' && look() <= 'z') { |
| 5453 | SpecialSubKind Kind; |
| 5409 | 5454 | switch (look()) { |
| 5410 | 5455 | case 'a': |
| 5411 | | ++First; |
| 5412 | | SpecialSub = make<SpecialSubstitution>(SpecialSubKind::allocator); |
| 5456 | Kind = SpecialSubKind::allocator; |
| 5413 | 5457 | break; |
| 5414 | 5458 | case 'b': |
| 5415 | | ++First; |
| 5416 | | SpecialSub = make<SpecialSubstitution>(SpecialSubKind::basic_string); |
| 5459 | Kind = SpecialSubKind::basic_string; |
| 5417 | 5460 | break; |
| 5418 | | case 's': |
| 5419 | | ++First; |
| 5420 | | SpecialSub = make<SpecialSubstitution>(SpecialSubKind::string); |
| 5461 | case 'd': |
| 5462 | Kind = SpecialSubKind::iostream; |
| 5421 | 5463 | break; |
| 5422 | 5464 | case 'i': |
| 5423 | | ++First; |
| 5424 | | SpecialSub = make<SpecialSubstitution>(SpecialSubKind::istream); |
| 5465 | Kind = SpecialSubKind::istream; |
| 5425 | 5466 | break; |
| 5426 | 5467 | case 'o': |
| 5427 | | ++First; |
| 5428 | | SpecialSub = make<SpecialSubstitution>(SpecialSubKind::ostream); |
| 5468 | Kind = SpecialSubKind::ostream; |
| 5429 | 5469 | break; |
| 5430 | | case 'd': |
| 5431 | | ++First; |
| 5432 | | SpecialSub = make<SpecialSubstitution>(SpecialSubKind::iostream); |
| 5470 | case 's': |
| 5471 | Kind = SpecialSubKind::string; |
| 5433 | 5472 | break; |
| 5434 | 5473 | default: |
| 5435 | 5474 | return nullptr; |
| 5436 | 5475 | } |
| 5476 | ++First; |
| 5477 | auto *SpecialSub = make<SpecialSubstitution>(Kind); |
| 5437 | 5478 | if (!SpecialSub) |
| 5438 | 5479 | return nullptr; |
| 5480 | |
| 5439 | 5481 | // Itanium C++ ABI 5.1.2: If a name that would use a built-in <substitution> |
| 5440 | 5482 | // has ABI tags, the tags are appended to the substitution; the result is a |
| 5441 | 5483 | // substitutable component. |