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