Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1 | //===------------------------- ItaniumDemangle.h ----------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 87bc9b4 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
Erik Pilkington | 870950f | 2019-01-17 20:37:51 +0000 | [diff] [blame] | 9 | // Generic itanium demangler library. This file has two byte-per-byte identical |
| 10 | // copies in the source tree, one in libcxxabi, and the other in llvm. |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Erik Pilkington | 870950f | 2019-01-17 20:37:51 +0000 | [diff] [blame] | 14 | #ifndef DEMANGLE_ITANIUMDEMANGLE_H |
| 15 | #define DEMANGLE_ITANIUMDEMANGLE_H |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 16 | |
| 17 | // FIXME: (possibly) incomplete list of features that clang mangles that this |
| 18 | // file does not yet support: |
| 19 | // - C++ modules TS |
| 20 | |
Erik Pilkington | 870950f | 2019-01-17 20:37:51 +0000 | [diff] [blame] | 21 | #include "DemangleConfig.h" |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 22 | #include "StringView.h" |
| 23 | #include "Utility.h" |
Nathan Sidwell | 96c7331 | 2022-01-24 04:11:59 -0800 | [diff] [blame] | 24 | #include <algorithm> |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 25 | #include <cassert> |
| 26 | #include <cctype> |
| 27 | #include <cstdio> |
| 28 | #include <cstdlib> |
| 29 | #include <cstring> |
Nathan Sidwell | 96c7331 | 2022-01-24 04:11:59 -0800 | [diff] [blame] | 30 | #include <limits> |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 31 | #include <utility> |
| 32 | |
| 33 | #define FOR_EACH_NODE_KIND(X) \ |
| 34 | X(NodeArrayNode) \ |
| 35 | X(DotSuffix) \ |
| 36 | X(VendorExtQualType) \ |
| 37 | X(QualType) \ |
| 38 | X(ConversionOperatorType) \ |
| 39 | X(PostfixQualifiedType) \ |
| 40 | X(ElaboratedTypeSpefType) \ |
| 41 | X(NameType) \ |
| 42 | X(AbiTagAttr) \ |
| 43 | X(EnableIfAttr) \ |
| 44 | X(ObjCProtoName) \ |
| 45 | X(PointerType) \ |
| 46 | X(ReferenceType) \ |
| 47 | X(PointerToMemberType) \ |
| 48 | X(ArrayType) \ |
| 49 | X(FunctionType) \ |
| 50 | X(NoexceptSpec) \ |
| 51 | X(DynamicExceptionSpec) \ |
| 52 | X(FunctionEncoding) \ |
| 53 | X(LiteralOperator) \ |
| 54 | X(SpecialName) \ |
| 55 | X(CtorVtableSpecialName) \ |
| 56 | X(QualifiedName) \ |
| 57 | X(NestedName) \ |
| 58 | X(LocalName) \ |
| 59 | X(VectorType) \ |
| 60 | X(PixelVectorType) \ |
Pengfei Wang | 036d315 | 2021-09-23 11:02:25 +0800 | [diff] [blame] | 61 | X(BinaryFPType) \ |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 62 | X(SyntheticTemplateParamName) \ |
| 63 | X(TypeTemplateParamDecl) \ |
| 64 | X(NonTypeTemplateParamDecl) \ |
| 65 | X(TemplateTemplateParamDecl) \ |
| 66 | X(TemplateParamPackDecl) \ |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 67 | X(ParameterPack) \ |
| 68 | X(TemplateArgumentPack) \ |
| 69 | X(ParameterPackExpansion) \ |
| 70 | X(TemplateArgs) \ |
| 71 | X(ForwardTemplateReference) \ |
| 72 | X(NameWithTemplateArgs) \ |
| 73 | X(GlobalQualifiedName) \ |
| 74 | X(StdQualifiedName) \ |
| 75 | X(ExpandedSpecialSubstitution) \ |
| 76 | X(SpecialSubstitution) \ |
| 77 | X(CtorDtorName) \ |
| 78 | X(DtorName) \ |
| 79 | X(UnnamedTypeName) \ |
| 80 | X(ClosureTypeName) \ |
| 81 | X(StructuredBindingName) \ |
| 82 | X(BinaryExpr) \ |
| 83 | X(ArraySubscriptExpr) \ |
| 84 | X(PostfixExpr) \ |
| 85 | X(ConditionalExpr) \ |
| 86 | X(MemberExpr) \ |
Richard Smith | 2b38a69 | 2020-10-22 19:29:36 -0700 | [diff] [blame] | 87 | X(SubobjectExpr) \ |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 88 | X(EnclosingExpr) \ |
| 89 | X(CastExpr) \ |
| 90 | X(SizeofParamPackExpr) \ |
| 91 | X(CallExpr) \ |
| 92 | X(NewExpr) \ |
| 93 | X(DeleteExpr) \ |
| 94 | X(PrefixExpr) \ |
| 95 | X(FunctionParam) \ |
| 96 | X(ConversionExpr) \ |
Richard Smith | 2b38a69 | 2020-10-22 19:29:36 -0700 | [diff] [blame] | 97 | X(PointerToMemberConversionExpr) \ |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 98 | X(InitListExpr) \ |
| 99 | X(FoldExpr) \ |
| 100 | X(ThrowExpr) \ |
| 101 | X(BoolExpr) \ |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 102 | X(StringLiteral) \ |
| 103 | X(LambdaExpr) \ |
Erik Pilkington | 27011a8 | 2020-05-13 14:13:37 -0400 | [diff] [blame] | 104 | X(EnumLiteral) \ |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 105 | X(IntegerLiteral) \ |
| 106 | X(FloatLiteral) \ |
| 107 | X(DoubleLiteral) \ |
| 108 | X(LongDoubleLiteral) \ |
| 109 | X(BracedExpr) \ |
| 110 | X(BracedRangeExpr) |
| 111 | |
Erik Pilkington | 870950f | 2019-01-17 20:37:51 +0000 | [diff] [blame] | 112 | DEMANGLE_NAMESPACE_BEGIN |
| 113 | |
Mikhail Borisov | 5f4d2ce | 2021-08-17 18:06:53 -0400 | [diff] [blame] | 114 | template <class T, size_t N> class PODSmallVector { |
| 115 | static_assert(std::is_pod<T>::value, |
| 116 | "T is required to be a plain old data type"); |
| 117 | |
| 118 | T *First = nullptr; |
| 119 | T *Last = nullptr; |
| 120 | T *Cap = nullptr; |
| 121 | T Inline[N] = {0}; |
| 122 | |
| 123 | bool isInline() const { return First == Inline; } |
| 124 | |
| 125 | void clearInline() { |
| 126 | First = Inline; |
| 127 | Last = Inline; |
| 128 | Cap = Inline + N; |
| 129 | } |
| 130 | |
| 131 | void reserve(size_t NewCap) { |
| 132 | size_t S = size(); |
| 133 | if (isInline()) { |
| 134 | auto *Tmp = static_cast<T *>(std::malloc(NewCap * sizeof(T))); |
| 135 | if (Tmp == nullptr) |
| 136 | std::terminate(); |
| 137 | std::copy(First, Last, Tmp); |
| 138 | First = Tmp; |
| 139 | } else { |
| 140 | First = static_cast<T *>(std::realloc(First, NewCap * sizeof(T))); |
| 141 | if (First == nullptr) |
| 142 | std::terminate(); |
| 143 | } |
| 144 | Last = First + S; |
| 145 | Cap = First + NewCap; |
| 146 | } |
| 147 | |
| 148 | public: |
| 149 | PODSmallVector() : First(Inline), Last(First), Cap(Inline + N) {} |
| 150 | |
| 151 | PODSmallVector(const PODSmallVector &) = delete; |
| 152 | PODSmallVector &operator=(const PODSmallVector &) = delete; |
| 153 | |
| 154 | PODSmallVector(PODSmallVector &&Other) : PODSmallVector() { |
| 155 | if (Other.isInline()) { |
| 156 | std::copy(Other.begin(), Other.end(), First); |
| 157 | Last = First + Other.size(); |
| 158 | Other.clear(); |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | First = Other.First; |
| 163 | Last = Other.Last; |
| 164 | Cap = Other.Cap; |
| 165 | Other.clearInline(); |
| 166 | } |
| 167 | |
| 168 | PODSmallVector &operator=(PODSmallVector &&Other) { |
| 169 | if (Other.isInline()) { |
| 170 | if (!isInline()) { |
| 171 | std::free(First); |
| 172 | clearInline(); |
| 173 | } |
| 174 | std::copy(Other.begin(), Other.end(), First); |
| 175 | Last = First + Other.size(); |
| 176 | Other.clear(); |
| 177 | return *this; |
| 178 | } |
| 179 | |
| 180 | if (isInline()) { |
| 181 | First = Other.First; |
| 182 | Last = Other.Last; |
| 183 | Cap = Other.Cap; |
| 184 | Other.clearInline(); |
| 185 | return *this; |
| 186 | } |
| 187 | |
| 188 | std::swap(First, Other.First); |
| 189 | std::swap(Last, Other.Last); |
| 190 | std::swap(Cap, Other.Cap); |
| 191 | Other.clear(); |
| 192 | return *this; |
| 193 | } |
| 194 | |
| 195 | // NOLINTNEXTLINE(readability-identifier-naming) |
| 196 | void push_back(const T &Elem) { |
| 197 | if (Last == Cap) |
| 198 | reserve(size() * 2); |
| 199 | *Last++ = Elem; |
| 200 | } |
| 201 | |
| 202 | // NOLINTNEXTLINE(readability-identifier-naming) |
| 203 | void pop_back() { |
| 204 | assert(Last != First && "Popping empty vector!"); |
| 205 | --Last; |
| 206 | } |
| 207 | |
| 208 | void dropBack(size_t Index) { |
| 209 | assert(Index <= size() && "dropBack() can't expand!"); |
| 210 | Last = First + Index; |
| 211 | } |
| 212 | |
| 213 | T *begin() { return First; } |
| 214 | T *end() { return Last; } |
| 215 | |
| 216 | bool empty() const { return First == Last; } |
| 217 | size_t size() const { return static_cast<size_t>(Last - First); } |
| 218 | T &back() { |
| 219 | assert(Last != First && "Calling back() on empty vector!"); |
| 220 | return *(Last - 1); |
| 221 | } |
| 222 | T &operator[](size_t Index) { |
| 223 | assert(Index < size() && "Invalid access!"); |
| 224 | return *(begin() + Index); |
| 225 | } |
| 226 | void clear() { Last = First; } |
| 227 | |
| 228 | ~PODSmallVector() { |
| 229 | if (!isInline()) |
| 230 | std::free(First); |
| 231 | } |
| 232 | }; |
| 233 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 234 | // Base class of all AST nodes. The AST is built by the parser, then is |
| 235 | // traversed by the printLeft/Right functions to produce a demangled string. |
| 236 | class Node { |
| 237 | public: |
| 238 | enum Kind : unsigned char { |
| 239 | #define ENUMERATOR(NodeKind) K ## NodeKind, |
| 240 | FOR_EACH_NODE_KIND(ENUMERATOR) |
| 241 | #undef ENUMERATOR |
| 242 | }; |
| 243 | |
| 244 | /// Three-way bool to track a cached value. Unknown is possible if this node |
| 245 | /// has an unexpanded parameter pack below it that may affect this cache. |
| 246 | enum class Cache : unsigned char { Yes, No, Unknown, }; |
| 247 | |
| 248 | private: |
| 249 | Kind K; |
| 250 | |
| 251 | // FIXME: Make these protected. |
| 252 | public: |
| 253 | /// Tracks if this node has a component on its right side, in which case we |
| 254 | /// need to call printRight. |
| 255 | Cache RHSComponentCache; |
| 256 | |
| 257 | /// Track if this node is a (possibly qualified) array type. This can affect |
| 258 | /// how we format the output string. |
| 259 | Cache ArrayCache; |
| 260 | |
| 261 | /// Track if this node is a (possibly qualified) function type. This can |
| 262 | /// affect how we format the output string. |
| 263 | Cache FunctionCache; |
| 264 | |
| 265 | public: |
| 266 | Node(Kind K_, Cache RHSComponentCache_ = Cache::No, |
| 267 | Cache ArrayCache_ = Cache::No, Cache FunctionCache_ = Cache::No) |
| 268 | : K(K_), RHSComponentCache(RHSComponentCache_), ArrayCache(ArrayCache_), |
| 269 | FunctionCache(FunctionCache_) {} |
| 270 | |
| 271 | /// Visit the most-derived object corresponding to this object. |
| 272 | template<typename Fn> void visit(Fn F) const; |
| 273 | |
| 274 | // The following function is provided by all derived classes: |
| 275 | // |
| 276 | // Call F with arguments that, when passed to the constructor of this node, |
| 277 | // would construct an equivalent node. |
| 278 | //template<typename Fn> void match(Fn F) const; |
| 279 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 280 | bool hasRHSComponent(OutputBuffer &OB) const { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 281 | if (RHSComponentCache != Cache::Unknown) |
| 282 | return RHSComponentCache == Cache::Yes; |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 283 | return hasRHSComponentSlow(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 284 | } |
| 285 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 286 | bool hasArray(OutputBuffer &OB) const { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 287 | if (ArrayCache != Cache::Unknown) |
| 288 | return ArrayCache == Cache::Yes; |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 289 | return hasArraySlow(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 290 | } |
| 291 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 292 | bool hasFunction(OutputBuffer &OB) const { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 293 | if (FunctionCache != Cache::Unknown) |
| 294 | return FunctionCache == Cache::Yes; |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 295 | return hasFunctionSlow(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | Kind getKind() const { return K; } |
| 299 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 300 | virtual bool hasRHSComponentSlow(OutputBuffer &) const { return false; } |
| 301 | virtual bool hasArraySlow(OutputBuffer &) const { return false; } |
| 302 | virtual bool hasFunctionSlow(OutputBuffer &) const { return false; } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 303 | |
| 304 | // Dig through "glue" nodes like ParameterPack and ForwardTemplateReference to |
| 305 | // get at a node that actually represents some concrete syntax. |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 306 | virtual const Node *getSyntaxNode(OutputBuffer &) const { return this; } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 307 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 308 | void print(OutputBuffer &OB) const { |
| 309 | printLeft(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 310 | if (RHSComponentCache != Cache::No) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 311 | printRight(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 312 | } |
| 313 | |
Nathan Sidwell | 64e94ec | 2022-01-20 07:40:12 -0800 | [diff] [blame] | 314 | // Print the "left" side of this Node into OutputBuffer. |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 315 | virtual void printLeft(OutputBuffer &) const = 0; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 316 | |
| 317 | // Print the "right". This distinction is necessary to represent C++ types |
| 318 | // that appear on the RHS of their subtype, such as arrays or functions. |
| 319 | // Since most types don't have such a component, provide a default |
| 320 | // implementation. |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 321 | virtual void printRight(OutputBuffer &) const {} |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 322 | |
| 323 | virtual StringView getBaseName() const { return StringView(); } |
| 324 | |
| 325 | // Silence compiler warnings, this dtor will never be called. |
| 326 | virtual ~Node() = default; |
| 327 | |
| 328 | #ifndef NDEBUG |
Erik Pilkington | 870950f | 2019-01-17 20:37:51 +0000 | [diff] [blame] | 329 | DEMANGLE_DUMP_METHOD void dump() const; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 330 | #endif |
| 331 | }; |
| 332 | |
| 333 | class NodeArray { |
| 334 | Node **Elements; |
| 335 | size_t NumElements; |
| 336 | |
| 337 | public: |
| 338 | NodeArray() : Elements(nullptr), NumElements(0) {} |
| 339 | NodeArray(Node **Elements_, size_t NumElements_) |
| 340 | : Elements(Elements_), NumElements(NumElements_) {} |
| 341 | |
| 342 | bool empty() const { return NumElements == 0; } |
| 343 | size_t size() const { return NumElements; } |
| 344 | |
| 345 | Node **begin() const { return Elements; } |
| 346 | Node **end() const { return Elements + NumElements; } |
| 347 | |
| 348 | Node *operator[](size_t Idx) const { return Elements[Idx]; } |
| 349 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 350 | void printWithComma(OutputBuffer &OB) const { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 351 | bool FirstElement = true; |
| 352 | for (size_t Idx = 0; Idx != NumElements; ++Idx) { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 353 | size_t BeforeComma = OB.getCurrentPosition(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 354 | if (!FirstElement) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 355 | OB += ", "; |
| 356 | size_t AfterComma = OB.getCurrentPosition(); |
| 357 | Elements[Idx]->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 358 | |
| 359 | // Elements[Idx] is an empty parameter pack expansion, we should erase the |
| 360 | // comma we just printed. |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 361 | if (AfterComma == OB.getCurrentPosition()) { |
| 362 | OB.setCurrentPosition(BeforeComma); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 363 | continue; |
| 364 | } |
| 365 | |
| 366 | FirstElement = false; |
| 367 | } |
| 368 | } |
| 369 | }; |
| 370 | |
| 371 | struct NodeArrayNode : Node { |
| 372 | NodeArray Array; |
| 373 | NodeArrayNode(NodeArray Array_) : Node(KNodeArrayNode), Array(Array_) {} |
| 374 | |
| 375 | template<typename Fn> void match(Fn F) const { F(Array); } |
| 376 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 377 | void printLeft(OutputBuffer &OB) const override { Array.printWithComma(OB); } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 378 | }; |
| 379 | |
| 380 | class DotSuffix final : public Node { |
| 381 | const Node *Prefix; |
| 382 | const StringView Suffix; |
| 383 | |
| 384 | public: |
| 385 | DotSuffix(const Node *Prefix_, StringView Suffix_) |
| 386 | : Node(KDotSuffix), Prefix(Prefix_), Suffix(Suffix_) {} |
| 387 | |
| 388 | template<typename Fn> void match(Fn F) const { F(Prefix, Suffix); } |
| 389 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 390 | void printLeft(OutputBuffer &OB) const override { |
| 391 | Prefix->print(OB); |
| 392 | OB += " ("; |
| 393 | OB += Suffix; |
| 394 | OB += ")"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 395 | } |
| 396 | }; |
| 397 | |
| 398 | class VendorExtQualType final : public Node { |
| 399 | const Node *Ty; |
| 400 | StringView Ext; |
Alex Orlov | 1540db3 | 2021-03-24 10:21:32 +0400 | [diff] [blame] | 401 | const Node *TA; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 402 | |
| 403 | public: |
Alex Orlov | 1540db3 | 2021-03-24 10:21:32 +0400 | [diff] [blame] | 404 | VendorExtQualType(const Node *Ty_, StringView Ext_, const Node *TA_) |
| 405 | : Node(KVendorExtQualType), Ty(Ty_), Ext(Ext_), TA(TA_) {} |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 406 | |
Alex Orlov | 1540db3 | 2021-03-24 10:21:32 +0400 | [diff] [blame] | 407 | template <typename Fn> void match(Fn F) const { F(Ty, Ext, TA); } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 408 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 409 | void printLeft(OutputBuffer &OB) const override { |
| 410 | Ty->print(OB); |
| 411 | OB += " "; |
| 412 | OB += Ext; |
Alex Orlov | 1540db3 | 2021-03-24 10:21:32 +0400 | [diff] [blame] | 413 | if (TA != nullptr) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 414 | TA->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 415 | } |
| 416 | }; |
| 417 | |
| 418 | enum FunctionRefQual : unsigned char { |
| 419 | FrefQualNone, |
| 420 | FrefQualLValue, |
| 421 | FrefQualRValue, |
| 422 | }; |
| 423 | |
| 424 | enum Qualifiers { |
| 425 | QualNone = 0, |
| 426 | QualConst = 0x1, |
| 427 | QualVolatile = 0x2, |
| 428 | QualRestrict = 0x4, |
| 429 | }; |
| 430 | |
| 431 | inline Qualifiers operator|=(Qualifiers &Q1, Qualifiers Q2) { |
| 432 | return Q1 = static_cast<Qualifiers>(Q1 | Q2); |
| 433 | } |
| 434 | |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 435 | class QualType final : public Node { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 436 | protected: |
| 437 | const Qualifiers Quals; |
| 438 | const Node *Child; |
| 439 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 440 | void printQuals(OutputBuffer &OB) const { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 441 | if (Quals & QualConst) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 442 | OB += " const"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 443 | if (Quals & QualVolatile) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 444 | OB += " volatile"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 445 | if (Quals & QualRestrict) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 446 | OB += " restrict"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | public: |
| 450 | QualType(const Node *Child_, Qualifiers Quals_) |
| 451 | : Node(KQualType, Child_->RHSComponentCache, |
| 452 | Child_->ArrayCache, Child_->FunctionCache), |
| 453 | Quals(Quals_), Child(Child_) {} |
| 454 | |
| 455 | template<typename Fn> void match(Fn F) const { F(Child, Quals); } |
| 456 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 457 | bool hasRHSComponentSlow(OutputBuffer &OB) const override { |
| 458 | return Child->hasRHSComponent(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 459 | } |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 460 | bool hasArraySlow(OutputBuffer &OB) const override { |
| 461 | return Child->hasArray(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 462 | } |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 463 | bool hasFunctionSlow(OutputBuffer &OB) const override { |
| 464 | return Child->hasFunction(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 465 | } |
| 466 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 467 | void printLeft(OutputBuffer &OB) const override { |
| 468 | Child->printLeft(OB); |
| 469 | printQuals(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 470 | } |
| 471 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 472 | void printRight(OutputBuffer &OB) const override { Child->printRight(OB); } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 473 | }; |
| 474 | |
| 475 | class ConversionOperatorType final : public Node { |
| 476 | const Node *Ty; |
| 477 | |
| 478 | public: |
| 479 | ConversionOperatorType(const Node *Ty_) |
| 480 | : Node(KConversionOperatorType), Ty(Ty_) {} |
| 481 | |
| 482 | template<typename Fn> void match(Fn F) const { F(Ty); } |
| 483 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 484 | void printLeft(OutputBuffer &OB) const override { |
| 485 | OB += "operator "; |
| 486 | Ty->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 487 | } |
| 488 | }; |
| 489 | |
| 490 | class PostfixQualifiedType final : public Node { |
| 491 | const Node *Ty; |
| 492 | const StringView Postfix; |
| 493 | |
| 494 | public: |
| 495 | PostfixQualifiedType(Node *Ty_, StringView Postfix_) |
| 496 | : Node(KPostfixQualifiedType), Ty(Ty_), Postfix(Postfix_) {} |
| 497 | |
| 498 | template<typename Fn> void match(Fn F) const { F(Ty, Postfix); } |
| 499 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 500 | void printLeft(OutputBuffer &OB) const override { |
| 501 | Ty->printLeft(OB); |
| 502 | OB += Postfix; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 503 | } |
| 504 | }; |
| 505 | |
| 506 | class NameType final : public Node { |
| 507 | const StringView Name; |
| 508 | |
| 509 | public: |
| 510 | NameType(StringView Name_) : Node(KNameType), Name(Name_) {} |
| 511 | |
| 512 | template<typename Fn> void match(Fn F) const { F(Name); } |
| 513 | |
| 514 | StringView getName() const { return Name; } |
| 515 | StringView getBaseName() const override { return Name; } |
| 516 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 517 | void printLeft(OutputBuffer &OB) const override { OB += Name; } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 518 | }; |
| 519 | |
| 520 | class ElaboratedTypeSpefType : public Node { |
| 521 | StringView Kind; |
| 522 | Node *Child; |
| 523 | public: |
| 524 | ElaboratedTypeSpefType(StringView Kind_, Node *Child_) |
| 525 | : Node(KElaboratedTypeSpefType), Kind(Kind_), Child(Child_) {} |
| 526 | |
| 527 | template<typename Fn> void match(Fn F) const { F(Kind, Child); } |
| 528 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 529 | void printLeft(OutputBuffer &OB) const override { |
| 530 | OB += Kind; |
| 531 | OB += ' '; |
| 532 | Child->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 533 | } |
| 534 | }; |
| 535 | |
| 536 | struct AbiTagAttr : Node { |
| 537 | Node *Base; |
| 538 | StringView Tag; |
| 539 | |
| 540 | AbiTagAttr(Node* Base_, StringView Tag_) |
| 541 | : Node(KAbiTagAttr, Base_->RHSComponentCache, |
| 542 | Base_->ArrayCache, Base_->FunctionCache), |
| 543 | Base(Base_), Tag(Tag_) {} |
| 544 | |
| 545 | template<typename Fn> void match(Fn F) const { F(Base, Tag); } |
| 546 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 547 | void printLeft(OutputBuffer &OB) const override { |
| 548 | Base->printLeft(OB); |
| 549 | OB += "[abi:"; |
| 550 | OB += Tag; |
| 551 | OB += "]"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 552 | } |
| 553 | }; |
| 554 | |
| 555 | class EnableIfAttr : public Node { |
| 556 | NodeArray Conditions; |
| 557 | public: |
| 558 | EnableIfAttr(NodeArray Conditions_) |
| 559 | : Node(KEnableIfAttr), Conditions(Conditions_) {} |
| 560 | |
| 561 | template<typename Fn> void match(Fn F) const { F(Conditions); } |
| 562 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 563 | void printLeft(OutputBuffer &OB) const override { |
| 564 | OB += " [enable_if:"; |
| 565 | Conditions.printWithComma(OB); |
| 566 | OB += ']'; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 567 | } |
| 568 | }; |
| 569 | |
| 570 | class ObjCProtoName : public Node { |
| 571 | const Node *Ty; |
| 572 | StringView Protocol; |
| 573 | |
| 574 | friend class PointerType; |
| 575 | |
| 576 | public: |
| 577 | ObjCProtoName(const Node *Ty_, StringView Protocol_) |
| 578 | : Node(KObjCProtoName), Ty(Ty_), Protocol(Protocol_) {} |
| 579 | |
| 580 | template<typename Fn> void match(Fn F) const { F(Ty, Protocol); } |
| 581 | |
| 582 | bool isObjCObject() const { |
| 583 | return Ty->getKind() == KNameType && |
| 584 | static_cast<const NameType *>(Ty)->getName() == "objc_object"; |
| 585 | } |
| 586 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 587 | void printLeft(OutputBuffer &OB) const override { |
| 588 | Ty->print(OB); |
| 589 | OB += "<"; |
| 590 | OB += Protocol; |
| 591 | OB += ">"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 592 | } |
| 593 | }; |
| 594 | |
| 595 | class PointerType final : public Node { |
| 596 | const Node *Pointee; |
| 597 | |
| 598 | public: |
| 599 | PointerType(const Node *Pointee_) |
| 600 | : Node(KPointerType, Pointee_->RHSComponentCache), |
| 601 | Pointee(Pointee_) {} |
| 602 | |
| 603 | template<typename Fn> void match(Fn F) const { F(Pointee); } |
| 604 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 605 | bool hasRHSComponentSlow(OutputBuffer &OB) const override { |
| 606 | return Pointee->hasRHSComponent(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 607 | } |
| 608 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 609 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 610 | // We rewrite objc_object<SomeProtocol>* into id<SomeProtocol>. |
| 611 | if (Pointee->getKind() != KObjCProtoName || |
| 612 | !static_cast<const ObjCProtoName *>(Pointee)->isObjCObject()) { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 613 | Pointee->printLeft(OB); |
| 614 | if (Pointee->hasArray(OB)) |
| 615 | OB += " "; |
| 616 | if (Pointee->hasArray(OB) || Pointee->hasFunction(OB)) |
| 617 | OB += "("; |
| 618 | OB += "*"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 619 | } else { |
| 620 | const auto *objcProto = static_cast<const ObjCProtoName *>(Pointee); |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 621 | OB += "id<"; |
| 622 | OB += objcProto->Protocol; |
| 623 | OB += ">"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 627 | void printRight(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 628 | if (Pointee->getKind() != KObjCProtoName || |
| 629 | !static_cast<const ObjCProtoName *>(Pointee)->isObjCObject()) { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 630 | if (Pointee->hasArray(OB) || Pointee->hasFunction(OB)) |
| 631 | OB += ")"; |
| 632 | Pointee->printRight(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | }; |
| 636 | |
| 637 | enum class ReferenceKind { |
| 638 | LValue, |
| 639 | RValue, |
| 640 | }; |
| 641 | |
| 642 | // Represents either a LValue or an RValue reference type. |
| 643 | class ReferenceType : public Node { |
| 644 | const Node *Pointee; |
| 645 | ReferenceKind RK; |
| 646 | |
| 647 | mutable bool Printing = false; |
| 648 | |
| 649 | // Dig through any refs to refs, collapsing the ReferenceTypes as we go. The |
| 650 | // rule here is rvalue ref to rvalue ref collapses to a rvalue ref, and any |
| 651 | // other combination collapses to a lvalue ref. |
Mikhail Borisov | cf1381e | 2021-08-17 18:10:57 -0400 | [diff] [blame] | 652 | // |
| 653 | // A combination of a TemplateForwardReference and a back-ref Substitution |
| 654 | // from an ill-formed string may have created a cycle; use cycle detection to |
| 655 | // avoid looping forever. |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 656 | std::pair<ReferenceKind, const Node *> collapse(OutputBuffer &OB) const { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 657 | auto SoFar = std::make_pair(RK, Pointee); |
Mikhail Borisov | cf1381e | 2021-08-17 18:10:57 -0400 | [diff] [blame] | 658 | // Track the chain of nodes for the Floyd's 'tortoise and hare' |
| 659 | // cycle-detection algorithm, since getSyntaxNode(S) is impure |
| 660 | PODSmallVector<const Node *, 8> Prev; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 661 | for (;;) { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 662 | const Node *SN = SoFar.second->getSyntaxNode(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 663 | if (SN->getKind() != KReferenceType) |
| 664 | break; |
| 665 | auto *RT = static_cast<const ReferenceType *>(SN); |
| 666 | SoFar.second = RT->Pointee; |
| 667 | SoFar.first = std::min(SoFar.first, RT->RK); |
Mikhail Borisov | cf1381e | 2021-08-17 18:10:57 -0400 | [diff] [blame] | 668 | |
| 669 | // The middle of Prev is the 'slow' pointer moving at half speed |
| 670 | Prev.push_back(SoFar.second); |
| 671 | if (Prev.size() > 1 && SoFar.second == Prev[(Prev.size() - 1) / 2]) { |
| 672 | // Cycle detected |
| 673 | SoFar.second = nullptr; |
| 674 | break; |
| 675 | } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 676 | } |
| 677 | return SoFar; |
| 678 | } |
| 679 | |
| 680 | public: |
| 681 | ReferenceType(const Node *Pointee_, ReferenceKind RK_) |
| 682 | : Node(KReferenceType, Pointee_->RHSComponentCache), |
| 683 | Pointee(Pointee_), RK(RK_) {} |
| 684 | |
| 685 | template<typename Fn> void match(Fn F) const { F(Pointee, RK); } |
| 686 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 687 | bool hasRHSComponentSlow(OutputBuffer &OB) const override { |
| 688 | return Pointee->hasRHSComponent(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 689 | } |
| 690 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 691 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 692 | if (Printing) |
| 693 | return; |
| 694 | SwapAndRestore<bool> SavePrinting(Printing, true); |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 695 | std::pair<ReferenceKind, const Node *> Collapsed = collapse(OB); |
Mikhail Borisov | cf1381e | 2021-08-17 18:10:57 -0400 | [diff] [blame] | 696 | if (!Collapsed.second) |
| 697 | return; |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 698 | Collapsed.second->printLeft(OB); |
| 699 | if (Collapsed.second->hasArray(OB)) |
| 700 | OB += " "; |
| 701 | if (Collapsed.second->hasArray(OB) || Collapsed.second->hasFunction(OB)) |
| 702 | OB += "("; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 703 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 704 | OB += (Collapsed.first == ReferenceKind::LValue ? "&" : "&&"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 705 | } |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 706 | void printRight(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 707 | if (Printing) |
| 708 | return; |
| 709 | SwapAndRestore<bool> SavePrinting(Printing, true); |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 710 | std::pair<ReferenceKind, const Node *> Collapsed = collapse(OB); |
Mikhail Borisov | cf1381e | 2021-08-17 18:10:57 -0400 | [diff] [blame] | 711 | if (!Collapsed.second) |
| 712 | return; |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 713 | if (Collapsed.second->hasArray(OB) || Collapsed.second->hasFunction(OB)) |
| 714 | OB += ")"; |
| 715 | Collapsed.second->printRight(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 716 | } |
| 717 | }; |
| 718 | |
| 719 | class PointerToMemberType final : public Node { |
| 720 | const Node *ClassType; |
| 721 | const Node *MemberType; |
| 722 | |
| 723 | public: |
| 724 | PointerToMemberType(const Node *ClassType_, const Node *MemberType_) |
| 725 | : Node(KPointerToMemberType, MemberType_->RHSComponentCache), |
| 726 | ClassType(ClassType_), MemberType(MemberType_) {} |
| 727 | |
| 728 | template<typename Fn> void match(Fn F) const { F(ClassType, MemberType); } |
| 729 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 730 | bool hasRHSComponentSlow(OutputBuffer &OB) const override { |
| 731 | return MemberType->hasRHSComponent(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 732 | } |
| 733 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 734 | void printLeft(OutputBuffer &OB) const override { |
| 735 | MemberType->printLeft(OB); |
| 736 | if (MemberType->hasArray(OB) || MemberType->hasFunction(OB)) |
| 737 | OB += "("; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 738 | else |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 739 | OB += " "; |
| 740 | ClassType->print(OB); |
| 741 | OB += "::*"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 742 | } |
| 743 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 744 | void printRight(OutputBuffer &OB) const override { |
| 745 | if (MemberType->hasArray(OB) || MemberType->hasFunction(OB)) |
| 746 | OB += ")"; |
| 747 | MemberType->printRight(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 748 | } |
| 749 | }; |
| 750 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 751 | class ArrayType final : public Node { |
| 752 | const Node *Base; |
Erik Pilkington | 87529ae | 2019-11-04 10:47:44 -0800 | [diff] [blame] | 753 | Node *Dimension; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 754 | |
| 755 | public: |
Erik Pilkington | 87529ae | 2019-11-04 10:47:44 -0800 | [diff] [blame] | 756 | ArrayType(const Node *Base_, Node *Dimension_) |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 757 | : Node(KArrayType, |
| 758 | /*RHSComponentCache=*/Cache::Yes, |
| 759 | /*ArrayCache=*/Cache::Yes), |
| 760 | Base(Base_), Dimension(Dimension_) {} |
| 761 | |
| 762 | template<typename Fn> void match(Fn F) const { F(Base, Dimension); } |
| 763 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 764 | bool hasRHSComponentSlow(OutputBuffer &) const override { return true; } |
| 765 | bool hasArraySlow(OutputBuffer &) const override { return true; } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 766 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 767 | void printLeft(OutputBuffer &OB) const override { Base->printLeft(OB); } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 768 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 769 | void printRight(OutputBuffer &OB) const override { |
| 770 | if (OB.back() != ']') |
| 771 | OB += " "; |
| 772 | OB += "["; |
Erik Pilkington | 87529ae | 2019-11-04 10:47:44 -0800 | [diff] [blame] | 773 | if (Dimension) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 774 | Dimension->print(OB); |
| 775 | OB += "]"; |
| 776 | Base->printRight(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 777 | } |
| 778 | }; |
| 779 | |
| 780 | class FunctionType final : public Node { |
| 781 | const Node *Ret; |
| 782 | NodeArray Params; |
| 783 | Qualifiers CVQuals; |
| 784 | FunctionRefQual RefQual; |
| 785 | const Node *ExceptionSpec; |
| 786 | |
| 787 | public: |
| 788 | FunctionType(const Node *Ret_, NodeArray Params_, Qualifiers CVQuals_, |
| 789 | FunctionRefQual RefQual_, const Node *ExceptionSpec_) |
| 790 | : Node(KFunctionType, |
| 791 | /*RHSComponentCache=*/Cache::Yes, /*ArrayCache=*/Cache::No, |
| 792 | /*FunctionCache=*/Cache::Yes), |
| 793 | Ret(Ret_), Params(Params_), CVQuals(CVQuals_), RefQual(RefQual_), |
| 794 | ExceptionSpec(ExceptionSpec_) {} |
| 795 | |
| 796 | template<typename Fn> void match(Fn F) const { |
| 797 | F(Ret, Params, CVQuals, RefQual, ExceptionSpec); |
| 798 | } |
| 799 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 800 | bool hasRHSComponentSlow(OutputBuffer &) const override { return true; } |
| 801 | bool hasFunctionSlow(OutputBuffer &) const override { return true; } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 802 | |
| 803 | // Handle C++'s ... quirky decl grammar by using the left & right |
| 804 | // distinction. Consider: |
| 805 | // int (*f(float))(char) {} |
| 806 | // f is a function that takes a float and returns a pointer to a function |
| 807 | // that takes a char and returns an int. If we're trying to print f, start |
| 808 | // by printing out the return types's left, then print our parameters, then |
| 809 | // finally print right of the return type. |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 810 | void printLeft(OutputBuffer &OB) const override { |
| 811 | Ret->printLeft(OB); |
| 812 | OB += " "; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 813 | } |
| 814 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 815 | void printRight(OutputBuffer &OB) const override { |
| 816 | OB += "("; |
| 817 | Params.printWithComma(OB); |
| 818 | OB += ")"; |
| 819 | Ret->printRight(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 820 | |
| 821 | if (CVQuals & QualConst) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 822 | OB += " const"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 823 | if (CVQuals & QualVolatile) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 824 | OB += " volatile"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 825 | if (CVQuals & QualRestrict) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 826 | OB += " restrict"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 827 | |
| 828 | if (RefQual == FrefQualLValue) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 829 | OB += " &"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 830 | else if (RefQual == FrefQualRValue) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 831 | OB += " &&"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 832 | |
| 833 | if (ExceptionSpec != nullptr) { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 834 | OB += ' '; |
| 835 | ExceptionSpec->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 836 | } |
| 837 | } |
| 838 | }; |
| 839 | |
| 840 | class NoexceptSpec : public Node { |
| 841 | const Node *E; |
| 842 | public: |
| 843 | NoexceptSpec(const Node *E_) : Node(KNoexceptSpec), E(E_) {} |
| 844 | |
| 845 | template<typename Fn> void match(Fn F) const { F(E); } |
| 846 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 847 | void printLeft(OutputBuffer &OB) const override { |
| 848 | OB += "noexcept("; |
| 849 | E->print(OB); |
| 850 | OB += ")"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 851 | } |
| 852 | }; |
| 853 | |
| 854 | class DynamicExceptionSpec : public Node { |
| 855 | NodeArray Types; |
| 856 | public: |
| 857 | DynamicExceptionSpec(NodeArray Types_) |
| 858 | : Node(KDynamicExceptionSpec), Types(Types_) {} |
| 859 | |
| 860 | template<typename Fn> void match(Fn F) const { F(Types); } |
| 861 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 862 | void printLeft(OutputBuffer &OB) const override { |
| 863 | OB += "throw("; |
| 864 | Types.printWithComma(OB); |
| 865 | OB += ')'; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 866 | } |
| 867 | }; |
| 868 | |
| 869 | class FunctionEncoding final : public Node { |
| 870 | const Node *Ret; |
| 871 | const Node *Name; |
| 872 | NodeArray Params; |
| 873 | const Node *Attrs; |
| 874 | Qualifiers CVQuals; |
| 875 | FunctionRefQual RefQual; |
| 876 | |
| 877 | public: |
| 878 | FunctionEncoding(const Node *Ret_, const Node *Name_, NodeArray Params_, |
| 879 | const Node *Attrs_, Qualifiers CVQuals_, |
| 880 | FunctionRefQual RefQual_) |
| 881 | : Node(KFunctionEncoding, |
| 882 | /*RHSComponentCache=*/Cache::Yes, /*ArrayCache=*/Cache::No, |
| 883 | /*FunctionCache=*/Cache::Yes), |
| 884 | Ret(Ret_), Name(Name_), Params(Params_), Attrs(Attrs_), |
| 885 | CVQuals(CVQuals_), RefQual(RefQual_) {} |
| 886 | |
| 887 | template<typename Fn> void match(Fn F) const { |
| 888 | F(Ret, Name, Params, Attrs, CVQuals, RefQual); |
| 889 | } |
| 890 | |
| 891 | Qualifiers getCVQuals() const { return CVQuals; } |
| 892 | FunctionRefQual getRefQual() const { return RefQual; } |
| 893 | NodeArray getParams() const { return Params; } |
| 894 | const Node *getReturnType() const { return Ret; } |
| 895 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 896 | bool hasRHSComponentSlow(OutputBuffer &) const override { return true; } |
| 897 | bool hasFunctionSlow(OutputBuffer &) const override { return true; } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 898 | |
| 899 | const Node *getName() const { return Name; } |
| 900 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 901 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 902 | if (Ret) { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 903 | Ret->printLeft(OB); |
| 904 | if (!Ret->hasRHSComponent(OB)) |
| 905 | OB += " "; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 906 | } |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 907 | Name->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 908 | } |
| 909 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 910 | void printRight(OutputBuffer &OB) const override { |
| 911 | OB += "("; |
| 912 | Params.printWithComma(OB); |
| 913 | OB += ")"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 914 | if (Ret) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 915 | Ret->printRight(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 916 | |
| 917 | if (CVQuals & QualConst) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 918 | OB += " const"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 919 | if (CVQuals & QualVolatile) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 920 | OB += " volatile"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 921 | if (CVQuals & QualRestrict) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 922 | OB += " restrict"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 923 | |
| 924 | if (RefQual == FrefQualLValue) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 925 | OB += " &"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 926 | else if (RefQual == FrefQualRValue) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 927 | OB += " &&"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 928 | |
| 929 | if (Attrs != nullptr) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 930 | Attrs->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 931 | } |
| 932 | }; |
| 933 | |
| 934 | class LiteralOperator : public Node { |
| 935 | const Node *OpName; |
| 936 | |
| 937 | public: |
| 938 | LiteralOperator(const Node *OpName_) |
| 939 | : Node(KLiteralOperator), OpName(OpName_) {} |
| 940 | |
| 941 | template<typename Fn> void match(Fn F) const { F(OpName); } |
| 942 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 943 | void printLeft(OutputBuffer &OB) const override { |
| 944 | OB += "operator\"\" "; |
| 945 | OpName->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 946 | } |
| 947 | }; |
| 948 | |
| 949 | class SpecialName final : public Node { |
| 950 | const StringView Special; |
| 951 | const Node *Child; |
| 952 | |
| 953 | public: |
| 954 | SpecialName(StringView Special_, const Node *Child_) |
| 955 | : Node(KSpecialName), Special(Special_), Child(Child_) {} |
| 956 | |
| 957 | template<typename Fn> void match(Fn F) const { F(Special, Child); } |
| 958 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 959 | void printLeft(OutputBuffer &OB) const override { |
| 960 | OB += Special; |
| 961 | Child->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 962 | } |
| 963 | }; |
| 964 | |
| 965 | class CtorVtableSpecialName final : public Node { |
| 966 | const Node *FirstType; |
| 967 | const Node *SecondType; |
| 968 | |
| 969 | public: |
| 970 | CtorVtableSpecialName(const Node *FirstType_, const Node *SecondType_) |
| 971 | : Node(KCtorVtableSpecialName), |
| 972 | FirstType(FirstType_), SecondType(SecondType_) {} |
| 973 | |
| 974 | template<typename Fn> void match(Fn F) const { F(FirstType, SecondType); } |
| 975 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 976 | void printLeft(OutputBuffer &OB) const override { |
| 977 | OB += "construction vtable for "; |
| 978 | FirstType->print(OB); |
| 979 | OB += "-in-"; |
| 980 | SecondType->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 981 | } |
| 982 | }; |
| 983 | |
| 984 | struct NestedName : Node { |
| 985 | Node *Qual; |
| 986 | Node *Name; |
| 987 | |
| 988 | NestedName(Node *Qual_, Node *Name_) |
| 989 | : Node(KNestedName), Qual(Qual_), Name(Name_) {} |
| 990 | |
| 991 | template<typename Fn> void match(Fn F) const { F(Qual, Name); } |
| 992 | |
| 993 | StringView getBaseName() const override { return Name->getBaseName(); } |
| 994 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 995 | void printLeft(OutputBuffer &OB) const override { |
| 996 | Qual->print(OB); |
| 997 | OB += "::"; |
| 998 | Name->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 999 | } |
| 1000 | }; |
| 1001 | |
| 1002 | struct LocalName : Node { |
| 1003 | Node *Encoding; |
| 1004 | Node *Entity; |
| 1005 | |
| 1006 | LocalName(Node *Encoding_, Node *Entity_) |
| 1007 | : Node(KLocalName), Encoding(Encoding_), Entity(Entity_) {} |
| 1008 | |
| 1009 | template<typename Fn> void match(Fn F) const { F(Encoding, Entity); } |
| 1010 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1011 | void printLeft(OutputBuffer &OB) const override { |
| 1012 | Encoding->print(OB); |
| 1013 | OB += "::"; |
| 1014 | Entity->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1015 | } |
| 1016 | }; |
| 1017 | |
| 1018 | class QualifiedName final : public Node { |
| 1019 | // qualifier::name |
| 1020 | const Node *Qualifier; |
| 1021 | const Node *Name; |
| 1022 | |
| 1023 | public: |
| 1024 | QualifiedName(const Node *Qualifier_, const Node *Name_) |
| 1025 | : Node(KQualifiedName), Qualifier(Qualifier_), Name(Name_) {} |
| 1026 | |
| 1027 | template<typename Fn> void match(Fn F) const { F(Qualifier, Name); } |
| 1028 | |
| 1029 | StringView getBaseName() const override { return Name->getBaseName(); } |
| 1030 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1031 | void printLeft(OutputBuffer &OB) const override { |
| 1032 | Qualifier->print(OB); |
| 1033 | OB += "::"; |
| 1034 | Name->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1035 | } |
| 1036 | }; |
| 1037 | |
| 1038 | class VectorType final : public Node { |
| 1039 | const Node *BaseType; |
Erik Pilkington | 87529ae | 2019-11-04 10:47:44 -0800 | [diff] [blame] | 1040 | const Node *Dimension; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1041 | |
| 1042 | public: |
Erik Pilkington | 87529ae | 2019-11-04 10:47:44 -0800 | [diff] [blame] | 1043 | VectorType(const Node *BaseType_, Node *Dimension_) |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1044 | : Node(KVectorType), BaseType(BaseType_), |
| 1045 | Dimension(Dimension_) {} |
| 1046 | |
| 1047 | template<typename Fn> void match(Fn F) const { F(BaseType, Dimension); } |
| 1048 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1049 | void printLeft(OutputBuffer &OB) const override { |
| 1050 | BaseType->print(OB); |
| 1051 | OB += " vector["; |
Erik Pilkington | 87529ae | 2019-11-04 10:47:44 -0800 | [diff] [blame] | 1052 | if (Dimension) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1053 | Dimension->print(OB); |
| 1054 | OB += "]"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1055 | } |
| 1056 | }; |
| 1057 | |
| 1058 | class PixelVectorType final : public Node { |
Erik Pilkington | 87529ae | 2019-11-04 10:47:44 -0800 | [diff] [blame] | 1059 | const Node *Dimension; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1060 | |
| 1061 | public: |
Erik Pilkington | 87529ae | 2019-11-04 10:47:44 -0800 | [diff] [blame] | 1062 | PixelVectorType(const Node *Dimension_) |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1063 | : Node(KPixelVectorType), Dimension(Dimension_) {} |
| 1064 | |
| 1065 | template<typename Fn> void match(Fn F) const { F(Dimension); } |
| 1066 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1067 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1068 | // FIXME: This should demangle as "vector pixel". |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1069 | OB += "pixel vector["; |
| 1070 | Dimension->print(OB); |
| 1071 | OB += "]"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1072 | } |
| 1073 | }; |
| 1074 | |
Pengfei Wang | 036d315 | 2021-09-23 11:02:25 +0800 | [diff] [blame] | 1075 | class BinaryFPType final : public Node { |
| 1076 | const Node *Dimension; |
| 1077 | |
| 1078 | public: |
| 1079 | BinaryFPType(const Node *Dimension_) |
| 1080 | : Node(KBinaryFPType), Dimension(Dimension_) {} |
| 1081 | |
| 1082 | template<typename Fn> void match(Fn F) const { F(Dimension); } |
| 1083 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1084 | void printLeft(OutputBuffer &OB) const override { |
| 1085 | OB += "_Float"; |
| 1086 | Dimension->print(OB); |
Pengfei Wang | 036d315 | 2021-09-23 11:02:25 +0800 | [diff] [blame] | 1087 | } |
| 1088 | }; |
| 1089 | |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1090 | enum class TemplateParamKind { Type, NonType, Template }; |
| 1091 | |
| 1092 | /// An invented name for a template parameter for which we don't have a |
| 1093 | /// corresponding template argument. |
| 1094 | /// |
| 1095 | /// This node is created when parsing the <lambda-sig> for a lambda with |
| 1096 | /// explicit template arguments, which might be referenced in the parameter |
| 1097 | /// types appearing later in the <lambda-sig>. |
| 1098 | class SyntheticTemplateParamName final : public Node { |
| 1099 | TemplateParamKind Kind; |
| 1100 | unsigned Index; |
| 1101 | |
| 1102 | public: |
| 1103 | SyntheticTemplateParamName(TemplateParamKind Kind_, unsigned Index_) |
| 1104 | : Node(KSyntheticTemplateParamName), Kind(Kind_), Index(Index_) {} |
| 1105 | |
| 1106 | template<typename Fn> void match(Fn F) const { F(Kind, Index); } |
| 1107 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1108 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1109 | switch (Kind) { |
| 1110 | case TemplateParamKind::Type: |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1111 | OB += "$T"; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1112 | break; |
| 1113 | case TemplateParamKind::NonType: |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1114 | OB += "$N"; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1115 | break; |
| 1116 | case TemplateParamKind::Template: |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1117 | OB += "$TT"; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1118 | break; |
| 1119 | } |
| 1120 | if (Index > 0) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1121 | OB << Index - 1; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1122 | } |
| 1123 | }; |
| 1124 | |
| 1125 | /// A template type parameter declaration, 'typename T'. |
| 1126 | class TypeTemplateParamDecl final : public Node { |
| 1127 | Node *Name; |
| 1128 | |
| 1129 | public: |
| 1130 | TypeTemplateParamDecl(Node *Name_) |
| 1131 | : Node(KTypeTemplateParamDecl, Cache::Yes), Name(Name_) {} |
| 1132 | |
| 1133 | template<typename Fn> void match(Fn F) const { F(Name); } |
| 1134 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1135 | void printLeft(OutputBuffer &OB) const override { OB += "typename "; } |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1136 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1137 | void printRight(OutputBuffer &OB) const override { Name->print(OB); } |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1138 | }; |
| 1139 | |
| 1140 | /// A non-type template parameter declaration, 'int N'. |
| 1141 | class NonTypeTemplateParamDecl final : public Node { |
| 1142 | Node *Name; |
| 1143 | Node *Type; |
| 1144 | |
| 1145 | public: |
| 1146 | NonTypeTemplateParamDecl(Node *Name_, Node *Type_) |
| 1147 | : Node(KNonTypeTemplateParamDecl, Cache::Yes), Name(Name_), Type(Type_) {} |
| 1148 | |
| 1149 | template<typename Fn> void match(Fn F) const { F(Name, Type); } |
| 1150 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1151 | void printLeft(OutputBuffer &OB) const override { |
| 1152 | Type->printLeft(OB); |
| 1153 | if (!Type->hasRHSComponent(OB)) |
| 1154 | OB += " "; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1157 | void printRight(OutputBuffer &OB) const override { |
| 1158 | Name->print(OB); |
| 1159 | Type->printRight(OB); |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1160 | } |
| 1161 | }; |
| 1162 | |
| 1163 | /// A template template parameter declaration, |
| 1164 | /// 'template<typename T> typename N'. |
| 1165 | class TemplateTemplateParamDecl final : public Node { |
| 1166 | Node *Name; |
| 1167 | NodeArray Params; |
| 1168 | |
| 1169 | public: |
| 1170 | TemplateTemplateParamDecl(Node *Name_, NodeArray Params_) |
| 1171 | : Node(KTemplateTemplateParamDecl, Cache::Yes), Name(Name_), |
| 1172 | Params(Params_) {} |
| 1173 | |
| 1174 | template<typename Fn> void match(Fn F) const { F(Name, Params); } |
| 1175 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1176 | void printLeft(OutputBuffer &OB) const override { |
| 1177 | OB += "template<"; |
| 1178 | Params.printWithComma(OB); |
| 1179 | OB += "> typename "; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1182 | void printRight(OutputBuffer &OB) const override { Name->print(OB); } |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1183 | }; |
| 1184 | |
| 1185 | /// A template parameter pack declaration, 'typename ...T'. |
| 1186 | class TemplateParamPackDecl final : public Node { |
| 1187 | Node *Param; |
| 1188 | |
| 1189 | public: |
| 1190 | TemplateParamPackDecl(Node *Param_) |
| 1191 | : Node(KTemplateParamPackDecl, Cache::Yes), Param(Param_) {} |
| 1192 | |
| 1193 | template<typename Fn> void match(Fn F) const { F(Param); } |
| 1194 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1195 | void printLeft(OutputBuffer &OB) const override { |
| 1196 | Param->printLeft(OB); |
| 1197 | OB += "..."; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1200 | void printRight(OutputBuffer &OB) const override { Param->printRight(OB); } |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1201 | }; |
| 1202 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1203 | /// An unexpanded parameter pack (either in the expression or type context). If |
| 1204 | /// this AST is correct, this node will have a ParameterPackExpansion node above |
| 1205 | /// it. |
| 1206 | /// |
| 1207 | /// This node is created when some <template-args> are found that apply to an |
| 1208 | /// <encoding>, and is stored in the TemplateParams table. In order for this to |
| 1209 | /// appear in the final AST, it has to referenced via a <template-param> (ie, |
| 1210 | /// T_). |
| 1211 | class ParameterPack final : public Node { |
| 1212 | NodeArray Data; |
| 1213 | |
Nathan Sidwell | 64e94ec | 2022-01-20 07:40:12 -0800 | [diff] [blame] | 1214 | // Setup OutputBuffer for a pack expansion, unless we're already expanding |
| 1215 | // one. |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1216 | void initializePackExpansion(OutputBuffer &OB) const { |
| 1217 | if (OB.CurrentPackMax == std::numeric_limits<unsigned>::max()) { |
| 1218 | OB.CurrentPackMax = static_cast<unsigned>(Data.size()); |
| 1219 | OB.CurrentPackIndex = 0; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | public: |
| 1224 | ParameterPack(NodeArray Data_) : Node(KParameterPack), Data(Data_) { |
| 1225 | ArrayCache = FunctionCache = RHSComponentCache = Cache::Unknown; |
| 1226 | if (std::all_of(Data.begin(), Data.end(), [](Node* P) { |
| 1227 | return P->ArrayCache == Cache::No; |
| 1228 | })) |
| 1229 | ArrayCache = Cache::No; |
| 1230 | if (std::all_of(Data.begin(), Data.end(), [](Node* P) { |
| 1231 | return P->FunctionCache == Cache::No; |
| 1232 | })) |
| 1233 | FunctionCache = Cache::No; |
| 1234 | if (std::all_of(Data.begin(), Data.end(), [](Node* P) { |
| 1235 | return P->RHSComponentCache == Cache::No; |
| 1236 | })) |
| 1237 | RHSComponentCache = Cache::No; |
| 1238 | } |
| 1239 | |
| 1240 | template<typename Fn> void match(Fn F) const { F(Data); } |
| 1241 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1242 | bool hasRHSComponentSlow(OutputBuffer &OB) const override { |
| 1243 | initializePackExpansion(OB); |
| 1244 | size_t Idx = OB.CurrentPackIndex; |
| 1245 | return Idx < Data.size() && Data[Idx]->hasRHSComponent(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1246 | } |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1247 | bool hasArraySlow(OutputBuffer &OB) const override { |
| 1248 | initializePackExpansion(OB); |
| 1249 | size_t Idx = OB.CurrentPackIndex; |
| 1250 | return Idx < Data.size() && Data[Idx]->hasArray(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1251 | } |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1252 | bool hasFunctionSlow(OutputBuffer &OB) const override { |
| 1253 | initializePackExpansion(OB); |
| 1254 | size_t Idx = OB.CurrentPackIndex; |
| 1255 | return Idx < Data.size() && Data[Idx]->hasFunction(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1256 | } |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1257 | const Node *getSyntaxNode(OutputBuffer &OB) const override { |
| 1258 | initializePackExpansion(OB); |
| 1259 | size_t Idx = OB.CurrentPackIndex; |
| 1260 | return Idx < Data.size() ? Data[Idx]->getSyntaxNode(OB) : this; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1263 | void printLeft(OutputBuffer &OB) const override { |
| 1264 | initializePackExpansion(OB); |
| 1265 | size_t Idx = OB.CurrentPackIndex; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1266 | if (Idx < Data.size()) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1267 | Data[Idx]->printLeft(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1268 | } |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1269 | void printRight(OutputBuffer &OB) const override { |
| 1270 | initializePackExpansion(OB); |
| 1271 | size_t Idx = OB.CurrentPackIndex; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1272 | if (Idx < Data.size()) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1273 | Data[Idx]->printRight(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1274 | } |
| 1275 | }; |
| 1276 | |
| 1277 | /// A variadic template argument. This node represents an occurrence of |
| 1278 | /// J<something>E in some <template-args>. It isn't itself unexpanded, unless |
| 1279 | /// one of it's Elements is. The parser inserts a ParameterPack into the |
| 1280 | /// TemplateParams table if the <template-args> this pack belongs to apply to an |
| 1281 | /// <encoding>. |
| 1282 | class TemplateArgumentPack final : public Node { |
| 1283 | NodeArray Elements; |
| 1284 | public: |
| 1285 | TemplateArgumentPack(NodeArray Elements_) |
| 1286 | : Node(KTemplateArgumentPack), Elements(Elements_) {} |
| 1287 | |
| 1288 | template<typename Fn> void match(Fn F) const { F(Elements); } |
| 1289 | |
| 1290 | NodeArray getElements() const { return Elements; } |
| 1291 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1292 | void printLeft(OutputBuffer &OB) const override { |
| 1293 | Elements.printWithComma(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1294 | } |
| 1295 | }; |
| 1296 | |
| 1297 | /// A pack expansion. Below this node, there are some unexpanded ParameterPacks |
| 1298 | /// which each have Child->ParameterPackSize elements. |
| 1299 | class ParameterPackExpansion final : public Node { |
| 1300 | const Node *Child; |
| 1301 | |
| 1302 | public: |
| 1303 | ParameterPackExpansion(const Node *Child_) |
| 1304 | : Node(KParameterPackExpansion), Child(Child_) {} |
| 1305 | |
| 1306 | template<typename Fn> void match(Fn F) const { F(Child); } |
| 1307 | |
| 1308 | const Node *getChild() const { return Child; } |
| 1309 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1310 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1311 | constexpr unsigned Max = std::numeric_limits<unsigned>::max(); |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1312 | SwapAndRestore<unsigned> SavePackIdx(OB.CurrentPackIndex, Max); |
| 1313 | SwapAndRestore<unsigned> SavePackMax(OB.CurrentPackMax, Max); |
| 1314 | size_t StreamPos = OB.getCurrentPosition(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1315 | |
| 1316 | // Print the first element in the pack. If Child contains a ParameterPack, |
| 1317 | // it will set up S.CurrentPackMax and print the first element. |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1318 | Child->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1319 | |
| 1320 | // No ParameterPack was found in Child. This can occur if we've found a pack |
| 1321 | // expansion on a <function-param>. |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1322 | if (OB.CurrentPackMax == Max) { |
| 1323 | OB += "..."; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1324 | return; |
| 1325 | } |
| 1326 | |
| 1327 | // We found a ParameterPack, but it has no elements. Erase whatever we may |
| 1328 | // of printed. |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1329 | if (OB.CurrentPackMax == 0) { |
| 1330 | OB.setCurrentPosition(StreamPos); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1331 | return; |
| 1332 | } |
| 1333 | |
| 1334 | // Else, iterate through the rest of the elements in the pack. |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1335 | for (unsigned I = 1, E = OB.CurrentPackMax; I < E; ++I) { |
| 1336 | OB += ", "; |
| 1337 | OB.CurrentPackIndex = I; |
| 1338 | Child->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1339 | } |
| 1340 | } |
| 1341 | }; |
| 1342 | |
| 1343 | class TemplateArgs final : public Node { |
| 1344 | NodeArray Params; |
| 1345 | |
| 1346 | public: |
| 1347 | TemplateArgs(NodeArray Params_) : Node(KTemplateArgs), Params(Params_) {} |
| 1348 | |
| 1349 | template<typename Fn> void match(Fn F) const { F(Params); } |
| 1350 | |
| 1351 | NodeArray getParams() { return Params; } |
| 1352 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1353 | void printLeft(OutputBuffer &OB) const override { |
| 1354 | OB += "<"; |
| 1355 | Params.printWithComma(OB); |
| 1356 | if (OB.back() == '>') |
| 1357 | OB += " "; |
| 1358 | OB += ">"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1359 | } |
| 1360 | }; |
| 1361 | |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 1362 | /// A forward-reference to a template argument that was not known at the point |
| 1363 | /// where the template parameter name was parsed in a mangling. |
| 1364 | /// |
| 1365 | /// This is created when demangling the name of a specialization of a |
| 1366 | /// conversion function template: |
| 1367 | /// |
| 1368 | /// \code |
| 1369 | /// struct A { |
| 1370 | /// template<typename T> operator T*(); |
| 1371 | /// }; |
| 1372 | /// \endcode |
| 1373 | /// |
| 1374 | /// When demangling a specialization of the conversion function template, we |
| 1375 | /// encounter the name of the template (including the \c T) before we reach |
| 1376 | /// the template argument list, so we cannot substitute the parameter name |
| 1377 | /// for the corresponding argument while parsing. Instead, we create a |
| 1378 | /// \c ForwardTemplateReference node that is resolved after we parse the |
| 1379 | /// template arguments. |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1380 | struct ForwardTemplateReference : Node { |
| 1381 | size_t Index; |
| 1382 | Node *Ref = nullptr; |
| 1383 | |
| 1384 | // If we're currently printing this node. It is possible (though invalid) for |
| 1385 | // a forward template reference to refer to itself via a substitution. This |
| 1386 | // creates a cyclic AST, which will stack overflow printing. To fix this, bail |
| 1387 | // out if more than one print* function is active. |
| 1388 | mutable bool Printing = false; |
| 1389 | |
| 1390 | ForwardTemplateReference(size_t Index_) |
| 1391 | : Node(KForwardTemplateReference, Cache::Unknown, Cache::Unknown, |
| 1392 | Cache::Unknown), |
| 1393 | Index(Index_) {} |
| 1394 | |
| 1395 | // We don't provide a matcher for these, because the value of the node is |
| 1396 | // not determined by its construction parameters, and it generally needs |
| 1397 | // special handling. |
| 1398 | template<typename Fn> void match(Fn F) const = delete; |
| 1399 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1400 | bool hasRHSComponentSlow(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1401 | if (Printing) |
| 1402 | return false; |
| 1403 | SwapAndRestore<bool> SavePrinting(Printing, true); |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1404 | return Ref->hasRHSComponent(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1405 | } |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1406 | bool hasArraySlow(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1407 | if (Printing) |
| 1408 | return false; |
| 1409 | SwapAndRestore<bool> SavePrinting(Printing, true); |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1410 | return Ref->hasArray(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1411 | } |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1412 | bool hasFunctionSlow(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1413 | if (Printing) |
| 1414 | return false; |
| 1415 | SwapAndRestore<bool> SavePrinting(Printing, true); |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1416 | return Ref->hasFunction(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1417 | } |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1418 | const Node *getSyntaxNode(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1419 | if (Printing) |
| 1420 | return this; |
| 1421 | SwapAndRestore<bool> SavePrinting(Printing, true); |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1422 | return Ref->getSyntaxNode(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1423 | } |
| 1424 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1425 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1426 | if (Printing) |
| 1427 | return; |
| 1428 | SwapAndRestore<bool> SavePrinting(Printing, true); |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1429 | Ref->printLeft(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1430 | } |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1431 | void printRight(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1432 | if (Printing) |
| 1433 | return; |
| 1434 | SwapAndRestore<bool> SavePrinting(Printing, true); |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1435 | Ref->printRight(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1436 | } |
| 1437 | }; |
| 1438 | |
| 1439 | struct NameWithTemplateArgs : Node { |
| 1440 | // name<template_args> |
| 1441 | Node *Name; |
| 1442 | Node *TemplateArgs; |
| 1443 | |
| 1444 | NameWithTemplateArgs(Node *Name_, Node *TemplateArgs_) |
| 1445 | : Node(KNameWithTemplateArgs), Name(Name_), TemplateArgs(TemplateArgs_) {} |
| 1446 | |
| 1447 | template<typename Fn> void match(Fn F) const { F(Name, TemplateArgs); } |
| 1448 | |
| 1449 | StringView getBaseName() const override { return Name->getBaseName(); } |
| 1450 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1451 | void printLeft(OutputBuffer &OB) const override { |
| 1452 | Name->print(OB); |
| 1453 | TemplateArgs->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1454 | } |
| 1455 | }; |
| 1456 | |
| 1457 | class GlobalQualifiedName final : public Node { |
| 1458 | Node *Child; |
| 1459 | |
| 1460 | public: |
| 1461 | GlobalQualifiedName(Node* Child_) |
| 1462 | : Node(KGlobalQualifiedName), Child(Child_) {} |
| 1463 | |
| 1464 | template<typename Fn> void match(Fn F) const { F(Child); } |
| 1465 | |
| 1466 | StringView getBaseName() const override { return Child->getBaseName(); } |
| 1467 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1468 | void printLeft(OutputBuffer &OB) const override { |
| 1469 | OB += "::"; |
| 1470 | Child->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1471 | } |
| 1472 | }; |
| 1473 | |
| 1474 | struct StdQualifiedName : Node { |
| 1475 | Node *Child; |
| 1476 | |
| 1477 | StdQualifiedName(Node *Child_) : Node(KStdQualifiedName), Child(Child_) {} |
| 1478 | |
| 1479 | template<typename Fn> void match(Fn F) const { F(Child); } |
| 1480 | |
| 1481 | StringView getBaseName() const override { return Child->getBaseName(); } |
| 1482 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1483 | void printLeft(OutputBuffer &OB) const override { |
| 1484 | OB += "std::"; |
| 1485 | Child->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1486 | } |
| 1487 | }; |
| 1488 | |
| 1489 | enum class SpecialSubKind { |
| 1490 | allocator, |
| 1491 | basic_string, |
| 1492 | string, |
| 1493 | istream, |
| 1494 | ostream, |
| 1495 | iostream, |
| 1496 | }; |
| 1497 | |
| 1498 | class ExpandedSpecialSubstitution final : public Node { |
| 1499 | SpecialSubKind SSK; |
| 1500 | |
| 1501 | public: |
| 1502 | ExpandedSpecialSubstitution(SpecialSubKind SSK_) |
| 1503 | : Node(KExpandedSpecialSubstitution), SSK(SSK_) {} |
| 1504 | |
| 1505 | template<typename Fn> void match(Fn F) const { F(SSK); } |
| 1506 | |
| 1507 | StringView getBaseName() const override { |
| 1508 | switch (SSK) { |
| 1509 | case SpecialSubKind::allocator: |
| 1510 | return StringView("allocator"); |
| 1511 | case SpecialSubKind::basic_string: |
| 1512 | return StringView("basic_string"); |
| 1513 | case SpecialSubKind::string: |
| 1514 | return StringView("basic_string"); |
| 1515 | case SpecialSubKind::istream: |
| 1516 | return StringView("basic_istream"); |
| 1517 | case SpecialSubKind::ostream: |
| 1518 | return StringView("basic_ostream"); |
| 1519 | case SpecialSubKind::iostream: |
| 1520 | return StringView("basic_iostream"); |
| 1521 | } |
Erik Pilkington | 870950f | 2019-01-17 20:37:51 +0000 | [diff] [blame] | 1522 | DEMANGLE_UNREACHABLE; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1525 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1526 | switch (SSK) { |
| 1527 | case SpecialSubKind::allocator: |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1528 | OB += "std::allocator"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1529 | break; |
| 1530 | case SpecialSubKind::basic_string: |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1531 | OB += "std::basic_string"; |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 1532 | break; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1533 | case SpecialSubKind::string: |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1534 | OB += "std::basic_string<char, std::char_traits<char>, " |
| 1535 | "std::allocator<char> >"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1536 | break; |
| 1537 | case SpecialSubKind::istream: |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1538 | OB += "std::basic_istream<char, std::char_traits<char> >"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1539 | break; |
| 1540 | case SpecialSubKind::ostream: |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1541 | OB += "std::basic_ostream<char, std::char_traits<char> >"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1542 | break; |
| 1543 | case SpecialSubKind::iostream: |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1544 | OB += "std::basic_iostream<char, std::char_traits<char> >"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1545 | break; |
| 1546 | } |
| 1547 | } |
| 1548 | }; |
| 1549 | |
| 1550 | class SpecialSubstitution final : public Node { |
| 1551 | public: |
| 1552 | SpecialSubKind SSK; |
| 1553 | |
| 1554 | SpecialSubstitution(SpecialSubKind SSK_) |
| 1555 | : Node(KSpecialSubstitution), SSK(SSK_) {} |
| 1556 | |
| 1557 | template<typename Fn> void match(Fn F) const { F(SSK); } |
| 1558 | |
| 1559 | StringView getBaseName() const override { |
| 1560 | switch (SSK) { |
| 1561 | case SpecialSubKind::allocator: |
| 1562 | return StringView("allocator"); |
| 1563 | case SpecialSubKind::basic_string: |
| 1564 | return StringView("basic_string"); |
| 1565 | case SpecialSubKind::string: |
| 1566 | return StringView("string"); |
| 1567 | case SpecialSubKind::istream: |
| 1568 | return StringView("istream"); |
| 1569 | case SpecialSubKind::ostream: |
| 1570 | return StringView("ostream"); |
| 1571 | case SpecialSubKind::iostream: |
| 1572 | return StringView("iostream"); |
| 1573 | } |
Erik Pilkington | 870950f | 2019-01-17 20:37:51 +0000 | [diff] [blame] | 1574 | DEMANGLE_UNREACHABLE; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1575 | } |
| 1576 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1577 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1578 | switch (SSK) { |
| 1579 | case SpecialSubKind::allocator: |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1580 | OB += "std::allocator"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1581 | break; |
| 1582 | case SpecialSubKind::basic_string: |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1583 | OB += "std::basic_string"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1584 | break; |
| 1585 | case SpecialSubKind::string: |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1586 | OB += "std::string"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1587 | break; |
| 1588 | case SpecialSubKind::istream: |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1589 | OB += "std::istream"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1590 | break; |
| 1591 | case SpecialSubKind::ostream: |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1592 | OB += "std::ostream"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1593 | break; |
| 1594 | case SpecialSubKind::iostream: |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1595 | OB += "std::iostream"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1596 | break; |
| 1597 | } |
| 1598 | } |
| 1599 | }; |
| 1600 | |
| 1601 | class CtorDtorName final : public Node { |
| 1602 | const Node *Basename; |
| 1603 | const bool IsDtor; |
Pavel Labath | 3605009 | 2018-10-10 08:39:16 +0000 | [diff] [blame] | 1604 | const int Variant; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1605 | |
| 1606 | public: |
Pavel Labath | 3605009 | 2018-10-10 08:39:16 +0000 | [diff] [blame] | 1607 | CtorDtorName(const Node *Basename_, bool IsDtor_, int Variant_) |
| 1608 | : Node(KCtorDtorName), Basename(Basename_), IsDtor(IsDtor_), |
| 1609 | Variant(Variant_) {} |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1610 | |
Pavel Labath | 3605009 | 2018-10-10 08:39:16 +0000 | [diff] [blame] | 1611 | template<typename Fn> void match(Fn F) const { F(Basename, IsDtor, Variant); } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1612 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1613 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1614 | if (IsDtor) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1615 | OB += "~"; |
| 1616 | OB += Basename->getBaseName(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1617 | } |
| 1618 | }; |
| 1619 | |
| 1620 | class DtorName : public Node { |
| 1621 | const Node *Base; |
| 1622 | |
| 1623 | public: |
| 1624 | DtorName(const Node *Base_) : Node(KDtorName), Base(Base_) {} |
| 1625 | |
| 1626 | template<typename Fn> void match(Fn F) const { F(Base); } |
| 1627 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1628 | void printLeft(OutputBuffer &OB) const override { |
| 1629 | OB += "~"; |
| 1630 | Base->printLeft(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1631 | } |
| 1632 | }; |
| 1633 | |
| 1634 | class UnnamedTypeName : public Node { |
| 1635 | const StringView Count; |
| 1636 | |
| 1637 | public: |
| 1638 | UnnamedTypeName(StringView Count_) : Node(KUnnamedTypeName), Count(Count_) {} |
| 1639 | |
| 1640 | template<typename Fn> void match(Fn F) const { F(Count); } |
| 1641 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1642 | void printLeft(OutputBuffer &OB) const override { |
| 1643 | OB += "'unnamed"; |
| 1644 | OB += Count; |
| 1645 | OB += "\'"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1646 | } |
| 1647 | }; |
| 1648 | |
| 1649 | class ClosureTypeName : public Node { |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1650 | NodeArray TemplateParams; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1651 | NodeArray Params; |
| 1652 | StringView Count; |
| 1653 | |
| 1654 | public: |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1655 | ClosureTypeName(NodeArray TemplateParams_, NodeArray Params_, |
| 1656 | StringView Count_) |
| 1657 | : Node(KClosureTypeName), TemplateParams(TemplateParams_), |
| 1658 | Params(Params_), Count(Count_) {} |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1659 | |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1660 | template<typename Fn> void match(Fn F) const { |
| 1661 | F(TemplateParams, Params, Count); |
| 1662 | } |
| 1663 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1664 | void printDeclarator(OutputBuffer &OB) const { |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1665 | if (!TemplateParams.empty()) { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1666 | OB += "<"; |
| 1667 | TemplateParams.printWithComma(OB); |
| 1668 | OB += ">"; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1669 | } |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1670 | OB += "("; |
| 1671 | Params.printWithComma(OB); |
| 1672 | OB += ")"; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 1673 | } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1674 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1675 | void printLeft(OutputBuffer &OB) const override { |
| 1676 | OB += "\'lambda"; |
| 1677 | OB += Count; |
| 1678 | OB += "\'"; |
| 1679 | printDeclarator(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1680 | } |
| 1681 | }; |
| 1682 | |
| 1683 | class StructuredBindingName : public Node { |
| 1684 | NodeArray Bindings; |
| 1685 | public: |
| 1686 | StructuredBindingName(NodeArray Bindings_) |
| 1687 | : Node(KStructuredBindingName), Bindings(Bindings_) {} |
| 1688 | |
| 1689 | template<typename Fn> void match(Fn F) const { F(Bindings); } |
| 1690 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1691 | void printLeft(OutputBuffer &OB) const override { |
| 1692 | OB += '['; |
| 1693 | Bindings.printWithComma(OB); |
| 1694 | OB += ']'; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1695 | } |
| 1696 | }; |
| 1697 | |
| 1698 | // -- Expression Nodes -- |
| 1699 | |
| 1700 | class BinaryExpr : public Node { |
| 1701 | const Node *LHS; |
| 1702 | const StringView InfixOperator; |
| 1703 | const Node *RHS; |
| 1704 | |
| 1705 | public: |
| 1706 | BinaryExpr(const Node *LHS_, StringView InfixOperator_, const Node *RHS_) |
| 1707 | : Node(KBinaryExpr), LHS(LHS_), InfixOperator(InfixOperator_), RHS(RHS_) { |
| 1708 | } |
| 1709 | |
| 1710 | template<typename Fn> void match(Fn F) const { F(LHS, InfixOperator, RHS); } |
| 1711 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1712 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1713 | // might be a template argument expression, then we need to disambiguate |
| 1714 | // with parens. |
| 1715 | if (InfixOperator == ">") |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1716 | OB += "("; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1717 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1718 | OB += "("; |
| 1719 | LHS->print(OB); |
| 1720 | OB += ") "; |
| 1721 | OB += InfixOperator; |
| 1722 | OB += " ("; |
| 1723 | RHS->print(OB); |
| 1724 | OB += ")"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1725 | |
| 1726 | if (InfixOperator == ">") |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1727 | OB += ")"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1728 | } |
| 1729 | }; |
| 1730 | |
| 1731 | class ArraySubscriptExpr : public Node { |
| 1732 | const Node *Op1; |
| 1733 | const Node *Op2; |
| 1734 | |
| 1735 | public: |
| 1736 | ArraySubscriptExpr(const Node *Op1_, const Node *Op2_) |
| 1737 | : Node(KArraySubscriptExpr), Op1(Op1_), Op2(Op2_) {} |
| 1738 | |
| 1739 | template<typename Fn> void match(Fn F) const { F(Op1, Op2); } |
| 1740 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1741 | void printLeft(OutputBuffer &OB) const override { |
| 1742 | OB += "("; |
| 1743 | Op1->print(OB); |
| 1744 | OB += ")["; |
| 1745 | Op2->print(OB); |
| 1746 | OB += "]"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1747 | } |
| 1748 | }; |
| 1749 | |
| 1750 | class PostfixExpr : public Node { |
| 1751 | const Node *Child; |
| 1752 | const StringView Operator; |
| 1753 | |
| 1754 | public: |
| 1755 | PostfixExpr(const Node *Child_, StringView Operator_) |
| 1756 | : Node(KPostfixExpr), Child(Child_), Operator(Operator_) {} |
| 1757 | |
| 1758 | template<typename Fn> void match(Fn F) const { F(Child, Operator); } |
| 1759 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1760 | void printLeft(OutputBuffer &OB) const override { |
| 1761 | OB += "("; |
| 1762 | Child->print(OB); |
| 1763 | OB += ")"; |
| 1764 | OB += Operator; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1765 | } |
| 1766 | }; |
| 1767 | |
| 1768 | class ConditionalExpr : public Node { |
| 1769 | const Node *Cond; |
| 1770 | const Node *Then; |
| 1771 | const Node *Else; |
| 1772 | |
| 1773 | public: |
| 1774 | ConditionalExpr(const Node *Cond_, const Node *Then_, const Node *Else_) |
| 1775 | : Node(KConditionalExpr), Cond(Cond_), Then(Then_), Else(Else_) {} |
| 1776 | |
| 1777 | template<typename Fn> void match(Fn F) const { F(Cond, Then, Else); } |
| 1778 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1779 | void printLeft(OutputBuffer &OB) const override { |
| 1780 | OB += "("; |
| 1781 | Cond->print(OB); |
| 1782 | OB += ") ? ("; |
| 1783 | Then->print(OB); |
| 1784 | OB += ") : ("; |
| 1785 | Else->print(OB); |
| 1786 | OB += ")"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1787 | } |
| 1788 | }; |
| 1789 | |
| 1790 | class MemberExpr : public Node { |
| 1791 | const Node *LHS; |
| 1792 | const StringView Kind; |
| 1793 | const Node *RHS; |
| 1794 | |
| 1795 | public: |
| 1796 | MemberExpr(const Node *LHS_, StringView Kind_, const Node *RHS_) |
| 1797 | : Node(KMemberExpr), LHS(LHS_), Kind(Kind_), RHS(RHS_) {} |
| 1798 | |
| 1799 | template<typename Fn> void match(Fn F) const { F(LHS, Kind, RHS); } |
| 1800 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1801 | void printLeft(OutputBuffer &OB) const override { |
| 1802 | LHS->print(OB); |
| 1803 | OB += Kind; |
| 1804 | RHS->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1805 | } |
| 1806 | }; |
| 1807 | |
Richard Smith | 2b38a69 | 2020-10-22 19:29:36 -0700 | [diff] [blame] | 1808 | class SubobjectExpr : public Node { |
| 1809 | const Node *Type; |
| 1810 | const Node *SubExpr; |
| 1811 | StringView Offset; |
| 1812 | NodeArray UnionSelectors; |
| 1813 | bool OnePastTheEnd; |
| 1814 | |
| 1815 | public: |
| 1816 | SubobjectExpr(const Node *Type_, const Node *SubExpr_, StringView Offset_, |
| 1817 | NodeArray UnionSelectors_, bool OnePastTheEnd_) |
| 1818 | : Node(KSubobjectExpr), Type(Type_), SubExpr(SubExpr_), Offset(Offset_), |
| 1819 | UnionSelectors(UnionSelectors_), OnePastTheEnd(OnePastTheEnd_) {} |
| 1820 | |
| 1821 | template<typename Fn> void match(Fn F) const { |
| 1822 | F(Type, SubExpr, Offset, UnionSelectors, OnePastTheEnd); |
| 1823 | } |
| 1824 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1825 | void printLeft(OutputBuffer &OB) const override { |
| 1826 | SubExpr->print(OB); |
| 1827 | OB += ".<"; |
| 1828 | Type->print(OB); |
| 1829 | OB += " at offset "; |
Richard Smith | 2b38a69 | 2020-10-22 19:29:36 -0700 | [diff] [blame] | 1830 | if (Offset.empty()) { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1831 | OB += "0"; |
Richard Smith | 2b38a69 | 2020-10-22 19:29:36 -0700 | [diff] [blame] | 1832 | } else if (Offset[0] == 'n') { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1833 | OB += "-"; |
| 1834 | OB += Offset.dropFront(); |
Richard Smith | 2b38a69 | 2020-10-22 19:29:36 -0700 | [diff] [blame] | 1835 | } else { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1836 | OB += Offset; |
Richard Smith | 2b38a69 | 2020-10-22 19:29:36 -0700 | [diff] [blame] | 1837 | } |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1838 | OB += ">"; |
Richard Smith | 2b38a69 | 2020-10-22 19:29:36 -0700 | [diff] [blame] | 1839 | } |
| 1840 | }; |
| 1841 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1842 | class EnclosingExpr : public Node { |
| 1843 | const StringView Prefix; |
| 1844 | const Node *Infix; |
| 1845 | const StringView Postfix; |
| 1846 | |
| 1847 | public: |
| 1848 | EnclosingExpr(StringView Prefix_, Node *Infix_, StringView Postfix_) |
| 1849 | : Node(KEnclosingExpr), Prefix(Prefix_), Infix(Infix_), |
| 1850 | Postfix(Postfix_) {} |
| 1851 | |
| 1852 | template<typename Fn> void match(Fn F) const { F(Prefix, Infix, Postfix); } |
| 1853 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1854 | void printLeft(OutputBuffer &OB) const override { |
| 1855 | OB += Prefix; |
| 1856 | Infix->print(OB); |
| 1857 | OB += Postfix; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1858 | } |
| 1859 | }; |
| 1860 | |
| 1861 | class CastExpr : public Node { |
| 1862 | // cast_kind<to>(from) |
| 1863 | const StringView CastKind; |
| 1864 | const Node *To; |
| 1865 | const Node *From; |
| 1866 | |
| 1867 | public: |
| 1868 | CastExpr(StringView CastKind_, const Node *To_, const Node *From_) |
| 1869 | : Node(KCastExpr), CastKind(CastKind_), To(To_), From(From_) {} |
| 1870 | |
| 1871 | template<typename Fn> void match(Fn F) const { F(CastKind, To, From); } |
| 1872 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1873 | void printLeft(OutputBuffer &OB) const override { |
| 1874 | OB += CastKind; |
| 1875 | OB += "<"; |
| 1876 | To->printLeft(OB); |
| 1877 | OB += ">("; |
| 1878 | From->printLeft(OB); |
| 1879 | OB += ")"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1880 | } |
| 1881 | }; |
| 1882 | |
| 1883 | class SizeofParamPackExpr : public Node { |
| 1884 | const Node *Pack; |
| 1885 | |
| 1886 | public: |
| 1887 | SizeofParamPackExpr(const Node *Pack_) |
| 1888 | : Node(KSizeofParamPackExpr), Pack(Pack_) {} |
| 1889 | |
| 1890 | template<typename Fn> void match(Fn F) const { F(Pack); } |
| 1891 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1892 | void printLeft(OutputBuffer &OB) const override { |
| 1893 | OB += "sizeof...("; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1894 | ParameterPackExpansion PPE(Pack); |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1895 | PPE.printLeft(OB); |
| 1896 | OB += ")"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1897 | } |
| 1898 | }; |
| 1899 | |
| 1900 | class CallExpr : public Node { |
| 1901 | const Node *Callee; |
| 1902 | NodeArray Args; |
| 1903 | |
| 1904 | public: |
| 1905 | CallExpr(const Node *Callee_, NodeArray Args_) |
| 1906 | : Node(KCallExpr), Callee(Callee_), Args(Args_) {} |
| 1907 | |
| 1908 | template<typename Fn> void match(Fn F) const { F(Callee, Args); } |
| 1909 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1910 | void printLeft(OutputBuffer &OB) const override { |
| 1911 | Callee->print(OB); |
| 1912 | OB += "("; |
| 1913 | Args.printWithComma(OB); |
| 1914 | OB += ")"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1915 | } |
| 1916 | }; |
| 1917 | |
| 1918 | class NewExpr : public Node { |
| 1919 | // new (expr_list) type(init_list) |
| 1920 | NodeArray ExprList; |
| 1921 | Node *Type; |
| 1922 | NodeArray InitList; |
| 1923 | bool IsGlobal; // ::operator new ? |
| 1924 | bool IsArray; // new[] ? |
| 1925 | public: |
| 1926 | NewExpr(NodeArray ExprList_, Node *Type_, NodeArray InitList_, bool IsGlobal_, |
| 1927 | bool IsArray_) |
| 1928 | : Node(KNewExpr), ExprList(ExprList_), Type(Type_), InitList(InitList_), |
| 1929 | IsGlobal(IsGlobal_), IsArray(IsArray_) {} |
| 1930 | |
| 1931 | template<typename Fn> void match(Fn F) const { |
| 1932 | F(ExprList, Type, InitList, IsGlobal, IsArray); |
| 1933 | } |
| 1934 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1935 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1936 | if (IsGlobal) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1937 | OB += "::operator "; |
| 1938 | OB += "new"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1939 | if (IsArray) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1940 | OB += "[]"; |
| 1941 | OB += ' '; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1942 | if (!ExprList.empty()) { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1943 | OB += "("; |
| 1944 | ExprList.printWithComma(OB); |
| 1945 | OB += ")"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1946 | } |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1947 | Type->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1948 | if (!InitList.empty()) { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1949 | OB += "("; |
| 1950 | InitList.printWithComma(OB); |
| 1951 | OB += ")"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1952 | } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1953 | } |
| 1954 | }; |
| 1955 | |
| 1956 | class DeleteExpr : public Node { |
| 1957 | Node *Op; |
| 1958 | bool IsGlobal; |
| 1959 | bool IsArray; |
| 1960 | |
| 1961 | public: |
| 1962 | DeleteExpr(Node *Op_, bool IsGlobal_, bool IsArray_) |
| 1963 | : Node(KDeleteExpr), Op(Op_), IsGlobal(IsGlobal_), IsArray(IsArray_) {} |
| 1964 | |
| 1965 | template<typename Fn> void match(Fn F) const { F(Op, IsGlobal, IsArray); } |
| 1966 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1967 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1968 | if (IsGlobal) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1969 | OB += "::"; |
| 1970 | OB += "delete"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1971 | if (IsArray) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1972 | OB += "[] "; |
| 1973 | Op->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1974 | } |
| 1975 | }; |
| 1976 | |
| 1977 | class PrefixExpr : public Node { |
| 1978 | StringView Prefix; |
| 1979 | Node *Child; |
| 1980 | |
| 1981 | public: |
| 1982 | PrefixExpr(StringView Prefix_, Node *Child_) |
| 1983 | : Node(KPrefixExpr), Prefix(Prefix_), Child(Child_) {} |
| 1984 | |
| 1985 | template<typename Fn> void match(Fn F) const { F(Prefix, Child); } |
| 1986 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 1987 | void printLeft(OutputBuffer &OB) const override { |
| 1988 | OB += Prefix; |
| 1989 | OB += "("; |
| 1990 | Child->print(OB); |
| 1991 | OB += ")"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 1992 | } |
| 1993 | }; |
| 1994 | |
| 1995 | class FunctionParam : public Node { |
| 1996 | StringView Number; |
| 1997 | |
| 1998 | public: |
| 1999 | FunctionParam(StringView Number_) : Node(KFunctionParam), Number(Number_) {} |
| 2000 | |
| 2001 | template<typename Fn> void match(Fn F) const { F(Number); } |
| 2002 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2003 | void printLeft(OutputBuffer &OB) const override { |
| 2004 | OB += "fp"; |
| 2005 | OB += Number; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2006 | } |
| 2007 | }; |
| 2008 | |
| 2009 | class ConversionExpr : public Node { |
| 2010 | const Node *Type; |
| 2011 | NodeArray Expressions; |
| 2012 | |
| 2013 | public: |
| 2014 | ConversionExpr(const Node *Type_, NodeArray Expressions_) |
| 2015 | : Node(KConversionExpr), Type(Type_), Expressions(Expressions_) {} |
| 2016 | |
| 2017 | template<typename Fn> void match(Fn F) const { F(Type, Expressions); } |
| 2018 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2019 | void printLeft(OutputBuffer &OB) const override { |
| 2020 | OB += "("; |
| 2021 | Type->print(OB); |
| 2022 | OB += ")("; |
| 2023 | Expressions.printWithComma(OB); |
| 2024 | OB += ")"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2025 | } |
| 2026 | }; |
| 2027 | |
Richard Smith | 2b38a69 | 2020-10-22 19:29:36 -0700 | [diff] [blame] | 2028 | class PointerToMemberConversionExpr : public Node { |
| 2029 | const Node *Type; |
| 2030 | const Node *SubExpr; |
| 2031 | StringView Offset; |
| 2032 | |
| 2033 | public: |
| 2034 | PointerToMemberConversionExpr(const Node *Type_, const Node *SubExpr_, |
| 2035 | StringView Offset_) |
| 2036 | : Node(KPointerToMemberConversionExpr), Type(Type_), SubExpr(SubExpr_), |
| 2037 | Offset(Offset_) {} |
| 2038 | |
| 2039 | template<typename Fn> void match(Fn F) const { F(Type, SubExpr, Offset); } |
| 2040 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2041 | void printLeft(OutputBuffer &OB) const override { |
| 2042 | OB += "("; |
| 2043 | Type->print(OB); |
| 2044 | OB += ")("; |
| 2045 | SubExpr->print(OB); |
| 2046 | OB += ")"; |
Richard Smith | 2b38a69 | 2020-10-22 19:29:36 -0700 | [diff] [blame] | 2047 | } |
| 2048 | }; |
| 2049 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2050 | class InitListExpr : public Node { |
| 2051 | const Node *Ty; |
| 2052 | NodeArray Inits; |
| 2053 | public: |
| 2054 | InitListExpr(const Node *Ty_, NodeArray Inits_) |
| 2055 | : Node(KInitListExpr), Ty(Ty_), Inits(Inits_) {} |
| 2056 | |
| 2057 | template<typename Fn> void match(Fn F) const { F(Ty, Inits); } |
| 2058 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2059 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2060 | if (Ty) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2061 | Ty->print(OB); |
| 2062 | OB += '{'; |
| 2063 | Inits.printWithComma(OB); |
| 2064 | OB += '}'; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2065 | } |
| 2066 | }; |
| 2067 | |
| 2068 | class BracedExpr : public Node { |
| 2069 | const Node *Elem; |
| 2070 | const Node *Init; |
| 2071 | bool IsArray; |
| 2072 | public: |
| 2073 | BracedExpr(const Node *Elem_, const Node *Init_, bool IsArray_) |
| 2074 | : Node(KBracedExpr), Elem(Elem_), Init(Init_), IsArray(IsArray_) {} |
| 2075 | |
| 2076 | template<typename Fn> void match(Fn F) const { F(Elem, Init, IsArray); } |
| 2077 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2078 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2079 | if (IsArray) { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2080 | OB += '['; |
| 2081 | Elem->print(OB); |
| 2082 | OB += ']'; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2083 | } else { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2084 | OB += '.'; |
| 2085 | Elem->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2086 | } |
| 2087 | if (Init->getKind() != KBracedExpr && Init->getKind() != KBracedRangeExpr) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2088 | OB += " = "; |
| 2089 | Init->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2090 | } |
| 2091 | }; |
| 2092 | |
| 2093 | class BracedRangeExpr : public Node { |
| 2094 | const Node *First; |
| 2095 | const Node *Last; |
| 2096 | const Node *Init; |
| 2097 | public: |
| 2098 | BracedRangeExpr(const Node *First_, const Node *Last_, const Node *Init_) |
| 2099 | : Node(KBracedRangeExpr), First(First_), Last(Last_), Init(Init_) {} |
| 2100 | |
| 2101 | template<typename Fn> void match(Fn F) const { F(First, Last, Init); } |
| 2102 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2103 | void printLeft(OutputBuffer &OB) const override { |
| 2104 | OB += '['; |
| 2105 | First->print(OB); |
| 2106 | OB += " ... "; |
| 2107 | Last->print(OB); |
| 2108 | OB += ']'; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2109 | if (Init->getKind() != KBracedExpr && Init->getKind() != KBracedRangeExpr) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2110 | OB += " = "; |
| 2111 | Init->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2112 | } |
| 2113 | }; |
| 2114 | |
| 2115 | class FoldExpr : public Node { |
| 2116 | const Node *Pack, *Init; |
| 2117 | StringView OperatorName; |
| 2118 | bool IsLeftFold; |
| 2119 | |
| 2120 | public: |
| 2121 | FoldExpr(bool IsLeftFold_, StringView OperatorName_, const Node *Pack_, |
| 2122 | const Node *Init_) |
| 2123 | : Node(KFoldExpr), Pack(Pack_), Init(Init_), OperatorName(OperatorName_), |
| 2124 | IsLeftFold(IsLeftFold_) {} |
| 2125 | |
| 2126 | template<typename Fn> void match(Fn F) const { |
| 2127 | F(IsLeftFold, OperatorName, Pack, Init); |
| 2128 | } |
| 2129 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2130 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2131 | auto PrintPack = [&] { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2132 | OB += '('; |
| 2133 | ParameterPackExpansion(Pack).print(OB); |
| 2134 | OB += ')'; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2135 | }; |
| 2136 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2137 | OB += '('; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2138 | |
| 2139 | if (IsLeftFold) { |
| 2140 | // init op ... op pack |
| 2141 | if (Init != nullptr) { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2142 | Init->print(OB); |
| 2143 | OB += ' '; |
| 2144 | OB += OperatorName; |
| 2145 | OB += ' '; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2146 | } |
| 2147 | // ... op pack |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2148 | OB += "... "; |
| 2149 | OB += OperatorName; |
| 2150 | OB += ' '; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2151 | PrintPack(); |
| 2152 | } else { // !IsLeftFold |
| 2153 | // pack op ... |
| 2154 | PrintPack(); |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2155 | OB += ' '; |
| 2156 | OB += OperatorName; |
| 2157 | OB += " ..."; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2158 | // pack op ... op init |
| 2159 | if (Init != nullptr) { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2160 | OB += ' '; |
| 2161 | OB += OperatorName; |
| 2162 | OB += ' '; |
| 2163 | Init->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2164 | } |
| 2165 | } |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2166 | OB += ')'; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2167 | } |
| 2168 | }; |
| 2169 | |
| 2170 | class ThrowExpr : public Node { |
| 2171 | const Node *Op; |
| 2172 | |
| 2173 | public: |
| 2174 | ThrowExpr(const Node *Op_) : Node(KThrowExpr), Op(Op_) {} |
| 2175 | |
| 2176 | template<typename Fn> void match(Fn F) const { F(Op); } |
| 2177 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2178 | void printLeft(OutputBuffer &OB) const override { |
| 2179 | OB += "throw "; |
| 2180 | Op->print(OB); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2181 | } |
| 2182 | }; |
| 2183 | |
| 2184 | class BoolExpr : public Node { |
| 2185 | bool Value; |
| 2186 | |
| 2187 | public: |
| 2188 | BoolExpr(bool Value_) : Node(KBoolExpr), Value(Value_) {} |
| 2189 | |
| 2190 | template<typename Fn> void match(Fn F) const { F(Value); } |
| 2191 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2192 | void printLeft(OutputBuffer &OB) const override { |
| 2193 | OB += Value ? StringView("true") : StringView("false"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2194 | } |
| 2195 | }; |
| 2196 | |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2197 | class StringLiteral : public Node { |
| 2198 | const Node *Type; |
| 2199 | |
| 2200 | public: |
| 2201 | StringLiteral(const Node *Type_) : Node(KStringLiteral), Type(Type_) {} |
| 2202 | |
| 2203 | template<typename Fn> void match(Fn F) const { F(Type); } |
| 2204 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2205 | void printLeft(OutputBuffer &OB) const override { |
| 2206 | OB += "\"<"; |
| 2207 | Type->print(OB); |
| 2208 | OB += ">\""; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2209 | } |
| 2210 | }; |
| 2211 | |
| 2212 | class LambdaExpr : public Node { |
| 2213 | const Node *Type; |
| 2214 | |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2215 | public: |
| 2216 | LambdaExpr(const Node *Type_) : Node(KLambdaExpr), Type(Type_) {} |
| 2217 | |
| 2218 | template<typename Fn> void match(Fn F) const { F(Type); } |
| 2219 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2220 | void printLeft(OutputBuffer &OB) const override { |
| 2221 | OB += "[]"; |
Richard Smith | 069f19d | 2019-09-09 22:26:04 +0000 | [diff] [blame] | 2222 | if (Type->getKind() == KClosureTypeName) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2223 | static_cast<const ClosureTypeName *>(Type)->printDeclarator(OB); |
| 2224 | OB += "{...}"; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2225 | } |
| 2226 | }; |
| 2227 | |
Erik Pilkington | 27011a8 | 2020-05-13 14:13:37 -0400 | [diff] [blame] | 2228 | class EnumLiteral : public Node { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2229 | // ty(integer) |
| 2230 | const Node *Ty; |
| 2231 | StringView Integer; |
| 2232 | |
| 2233 | public: |
Erik Pilkington | 27011a8 | 2020-05-13 14:13:37 -0400 | [diff] [blame] | 2234 | EnumLiteral(const Node *Ty_, StringView Integer_) |
| 2235 | : Node(KEnumLiteral), Ty(Ty_), Integer(Integer_) {} |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2236 | |
| 2237 | template<typename Fn> void match(Fn F) const { F(Ty, Integer); } |
| 2238 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2239 | void printLeft(OutputBuffer &OB) const override { |
| 2240 | OB << "("; |
| 2241 | Ty->print(OB); |
| 2242 | OB << ")"; |
Erik Pilkington | 27011a8 | 2020-05-13 14:13:37 -0400 | [diff] [blame] | 2243 | |
| 2244 | if (Integer[0] == 'n') |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2245 | OB << "-" << Integer.dropFront(1); |
Erik Pilkington | 27011a8 | 2020-05-13 14:13:37 -0400 | [diff] [blame] | 2246 | else |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2247 | OB << Integer; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2248 | } |
| 2249 | }; |
| 2250 | |
| 2251 | class IntegerLiteral : public Node { |
| 2252 | StringView Type; |
| 2253 | StringView Value; |
| 2254 | |
| 2255 | public: |
| 2256 | IntegerLiteral(StringView Type_, StringView Value_) |
| 2257 | : Node(KIntegerLiteral), Type(Type_), Value(Value_) {} |
| 2258 | |
| 2259 | template<typename Fn> void match(Fn F) const { F(Type, Value); } |
| 2260 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2261 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2262 | if (Type.size() > 3) { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2263 | OB += "("; |
| 2264 | OB += Type; |
| 2265 | OB += ")"; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2266 | } |
| 2267 | |
| 2268 | if (Value[0] == 'n') { |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2269 | OB += "-"; |
| 2270 | OB += Value.dropFront(1); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2271 | } else |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2272 | OB += Value; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2273 | |
| 2274 | if (Type.size() <= 3) |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2275 | OB += Type; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2276 | } |
| 2277 | }; |
| 2278 | |
| 2279 | template <class Float> struct FloatData; |
| 2280 | |
| 2281 | namespace float_literal_impl { |
| 2282 | constexpr Node::Kind getFloatLiteralKind(float *) { |
| 2283 | return Node::KFloatLiteral; |
| 2284 | } |
| 2285 | constexpr Node::Kind getFloatLiteralKind(double *) { |
| 2286 | return Node::KDoubleLiteral; |
| 2287 | } |
| 2288 | constexpr Node::Kind getFloatLiteralKind(long double *) { |
| 2289 | return Node::KLongDoubleLiteral; |
| 2290 | } |
| 2291 | } |
| 2292 | |
| 2293 | template <class Float> class FloatLiteralImpl : public Node { |
| 2294 | const StringView Contents; |
| 2295 | |
| 2296 | static constexpr Kind KindForClass = |
| 2297 | float_literal_impl::getFloatLiteralKind((Float *)nullptr); |
| 2298 | |
| 2299 | public: |
| 2300 | FloatLiteralImpl(StringView Contents_) |
| 2301 | : Node(KindForClass), Contents(Contents_) {} |
| 2302 | |
| 2303 | template<typename Fn> void match(Fn F) const { F(Contents); } |
| 2304 | |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2305 | void printLeft(OutputBuffer &OB) const override { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2306 | const char *first = Contents.begin(); |
| 2307 | const char *last = Contents.end() + 1; |
| 2308 | |
| 2309 | const size_t N = FloatData<Float>::mangled_size; |
| 2310 | if (static_cast<std::size_t>(last - first) > N) { |
| 2311 | last = first + N; |
| 2312 | union { |
| 2313 | Float value; |
| 2314 | char buf[sizeof(Float)]; |
| 2315 | }; |
| 2316 | const char *t = first; |
| 2317 | char *e = buf; |
| 2318 | for (; t != last; ++t, ++e) { |
| 2319 | unsigned d1 = isdigit(*t) ? static_cast<unsigned>(*t - '0') |
| 2320 | : static_cast<unsigned>(*t - 'a' + 10); |
| 2321 | ++t; |
| 2322 | unsigned d0 = isdigit(*t) ? static_cast<unsigned>(*t - '0') |
| 2323 | : static_cast<unsigned>(*t - 'a' + 10); |
| 2324 | *e = static_cast<char>((d1 << 4) + d0); |
| 2325 | } |
| 2326 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
| 2327 | std::reverse(buf, e); |
| 2328 | #endif |
| 2329 | char num[FloatData<Float>::max_demangled_size] = {0}; |
| 2330 | int n = snprintf(num, sizeof(num), FloatData<Float>::spec, value); |
LuÃs Ferreira | 4fb856a | 2021-10-21 17:31:53 -0700 | [diff] [blame] | 2331 | OB += StringView(num, num + n); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2332 | } |
| 2333 | } |
| 2334 | }; |
| 2335 | |
| 2336 | using FloatLiteral = FloatLiteralImpl<float>; |
| 2337 | using DoubleLiteral = FloatLiteralImpl<double>; |
| 2338 | using LongDoubleLiteral = FloatLiteralImpl<long double>; |
| 2339 | |
| 2340 | /// Visit the node. Calls \c F(P), where \c P is the node cast to the |
| 2341 | /// appropriate derived class. |
| 2342 | template<typename Fn> |
| 2343 | void Node::visit(Fn F) const { |
| 2344 | switch (K) { |
| 2345 | #define CASE(X) case K ## X: return F(static_cast<const X*>(this)); |
| 2346 | FOR_EACH_NODE_KIND(CASE) |
| 2347 | #undef CASE |
| 2348 | } |
| 2349 | assert(0 && "unknown mangling node kind"); |
| 2350 | } |
| 2351 | |
| 2352 | /// Determine the kind of a node from its type. |
| 2353 | template<typename NodeT> struct NodeKind; |
| 2354 | #define SPECIALIZATION(X) \ |
| 2355 | template<> struct NodeKind<X> { \ |
| 2356 | static constexpr Node::Kind Kind = Node::K##X; \ |
| 2357 | static constexpr const char *name() { return #X; } \ |
| 2358 | }; |
| 2359 | FOR_EACH_NODE_KIND(SPECIALIZATION) |
| 2360 | #undef SPECIALIZATION |
| 2361 | |
| 2362 | #undef FOR_EACH_NODE_KIND |
| 2363 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2364 | template <typename Derived, typename Alloc> struct AbstractManglingParser { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2365 | const char *First; |
| 2366 | const char *Last; |
| 2367 | |
| 2368 | // Name stack, this is used by the parser to hold temporary names that were |
| 2369 | // parsed. The parser collapses multiple names into new nodes to construct |
| 2370 | // the AST. Once the parser is finished, names.size() == 1. |
| 2371 | PODSmallVector<Node *, 32> Names; |
| 2372 | |
| 2373 | // Substitution table. Itanium supports name substitutions as a means of |
| 2374 | // compression. The string "S42_" refers to the 44nd entry (base-36) in this |
| 2375 | // table. |
| 2376 | PODSmallVector<Node *, 32> Subs; |
| 2377 | |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2378 | using TemplateParamList = PODSmallVector<Node *, 8>; |
| 2379 | |
| 2380 | class ScopedTemplateParamList { |
| 2381 | AbstractManglingParser *Parser; |
| 2382 | size_t OldNumTemplateParamLists; |
| 2383 | TemplateParamList Params; |
| 2384 | |
| 2385 | public: |
Louis Dionne | 83a7521 | 2020-10-30 17:33:02 -0400 | [diff] [blame] | 2386 | ScopedTemplateParamList(AbstractManglingParser *TheParser) |
| 2387 | : Parser(TheParser), |
| 2388 | OldNumTemplateParamLists(TheParser->TemplateParams.size()) { |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2389 | Parser->TemplateParams.push_back(&Params); |
| 2390 | } |
| 2391 | ~ScopedTemplateParamList() { |
| 2392 | assert(Parser->TemplateParams.size() >= OldNumTemplateParamLists); |
| 2393 | Parser->TemplateParams.dropBack(OldNumTemplateParamLists); |
| 2394 | } |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2395 | }; |
| 2396 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2397 | // Template parameter table. Like the above, but referenced like "T42_". |
| 2398 | // This has a smaller size compared to Subs and Names because it can be |
| 2399 | // stored on the stack. |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2400 | TemplateParamList OuterTemplateParams; |
| 2401 | |
| 2402 | // Lists of template parameters indexed by template parameter depth, |
| 2403 | // referenced like "TL2_4_". If nonempty, element 0 is always |
| 2404 | // OuterTemplateParams; inner elements are always template parameter lists of |
| 2405 | // lambda expressions. For a generic lambda with no explicit template |
| 2406 | // parameter list, the corresponding parameter list pointer will be null. |
| 2407 | PODSmallVector<TemplateParamList *, 4> TemplateParams; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2408 | |
| 2409 | // Set of unresolved forward <template-param> references. These can occur in a |
| 2410 | // conversion operator's type, and are resolved in the enclosing <encoding>. |
| 2411 | PODSmallVector<ForwardTemplateReference *, 4> ForwardTemplateRefs; |
| 2412 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2413 | bool TryToParseTemplateArgs = true; |
| 2414 | bool PermitForwardTemplateReferences = false; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2415 | size_t ParsingLambdaParamsAtLevel = (size_t)-1; |
| 2416 | |
| 2417 | unsigned NumSyntheticTemplateParameters[3] = {}; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2418 | |
| 2419 | Alloc ASTAllocator; |
| 2420 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2421 | AbstractManglingParser(const char *First_, const char *Last_) |
| 2422 | : First(First_), Last(Last_) {} |
| 2423 | |
| 2424 | Derived &getDerived() { return static_cast<Derived &>(*this); } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2425 | |
| 2426 | void reset(const char *First_, const char *Last_) { |
| 2427 | First = First_; |
| 2428 | Last = Last_; |
| 2429 | Names.clear(); |
| 2430 | Subs.clear(); |
| 2431 | TemplateParams.clear(); |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2432 | ParsingLambdaParamsAtLevel = (size_t)-1; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2433 | TryToParseTemplateArgs = true; |
| 2434 | PermitForwardTemplateReferences = false; |
Richard Smith | b38f700 | 2019-09-07 00:11:53 +0000 | [diff] [blame] | 2435 | for (int I = 0; I != 3; ++I) |
| 2436 | NumSyntheticTemplateParameters[I] = 0; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2437 | ASTAllocator.reset(); |
| 2438 | } |
| 2439 | |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 2440 | template <class T, class... Args> Node *make(Args &&... args) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2441 | return ASTAllocator.template makeNode<T>(std::forward<Args>(args)...); |
| 2442 | } |
| 2443 | |
| 2444 | template <class It> NodeArray makeNodeArray(It begin, It end) { |
| 2445 | size_t sz = static_cast<size_t>(end - begin); |
| 2446 | void *mem = ASTAllocator.allocateNodeArray(sz); |
| 2447 | Node **data = new (mem) Node *[sz]; |
| 2448 | std::copy(begin, end, data); |
| 2449 | return NodeArray(data, sz); |
| 2450 | } |
| 2451 | |
| 2452 | NodeArray popTrailingNodeArray(size_t FromPosition) { |
| 2453 | assert(FromPosition <= Names.size()); |
| 2454 | NodeArray res = |
| 2455 | makeNodeArray(Names.begin() + (long)FromPosition, Names.end()); |
| 2456 | Names.dropBack(FromPosition); |
| 2457 | return res; |
| 2458 | } |
| 2459 | |
| 2460 | bool consumeIf(StringView S) { |
| 2461 | if (StringView(First, Last).startsWith(S)) { |
| 2462 | First += S.size(); |
| 2463 | return true; |
| 2464 | } |
| 2465 | return false; |
| 2466 | } |
| 2467 | |
| 2468 | bool consumeIf(char C) { |
| 2469 | if (First != Last && *First == C) { |
| 2470 | ++First; |
| 2471 | return true; |
| 2472 | } |
| 2473 | return false; |
| 2474 | } |
| 2475 | |
| 2476 | char consume() { return First != Last ? *First++ : '\0'; } |
| 2477 | |
Nathan Sidwell | 64e94ec | 2022-01-20 07:40:12 -0800 | [diff] [blame] | 2478 | char look(unsigned Lookahead = 0) const { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2479 | if (static_cast<size_t>(Last - First) <= Lookahead) |
| 2480 | return '\0'; |
| 2481 | return First[Lookahead]; |
| 2482 | } |
| 2483 | |
| 2484 | size_t numLeft() const { return static_cast<size_t>(Last - First); } |
| 2485 | |
| 2486 | StringView parseNumber(bool AllowNegative = false); |
| 2487 | Qualifiers parseCVQualifiers(); |
| 2488 | bool parsePositiveInteger(size_t *Out); |
| 2489 | StringView parseBareSourceName(); |
| 2490 | |
| 2491 | bool parseSeqId(size_t *Out); |
| 2492 | Node *parseSubstitution(); |
| 2493 | Node *parseTemplateParam(); |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2494 | Node *parseTemplateParamDecl(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2495 | Node *parseTemplateArgs(bool TagTemplates = false); |
| 2496 | Node *parseTemplateArg(); |
| 2497 | |
| 2498 | /// Parse the <expr> production. |
| 2499 | Node *parseExpr(); |
| 2500 | Node *parsePrefixExpr(StringView Kind); |
| 2501 | Node *parseBinaryExpr(StringView Kind); |
| 2502 | Node *parseIntegerLiteral(StringView Lit); |
| 2503 | Node *parseExprPrimary(); |
| 2504 | template <class Float> Node *parseFloatingLiteral(); |
| 2505 | Node *parseFunctionParam(); |
| 2506 | Node *parseNewExpr(); |
| 2507 | Node *parseConversionExpr(); |
| 2508 | Node *parseBracedExpr(); |
| 2509 | Node *parseFoldExpr(); |
Richard Smith | 2b38a69 | 2020-10-22 19:29:36 -0700 | [diff] [blame] | 2510 | Node *parsePointerToMemberConversionExpr(); |
| 2511 | Node *parseSubobjectExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2512 | |
| 2513 | /// Parse the <type> production. |
| 2514 | Node *parseType(); |
| 2515 | Node *parseFunctionType(); |
| 2516 | Node *parseVectorType(); |
| 2517 | Node *parseDecltype(); |
| 2518 | Node *parseArrayType(); |
| 2519 | Node *parsePointerToMemberType(); |
| 2520 | Node *parseClassEnumType(); |
| 2521 | Node *parseQualifiedType(); |
| 2522 | |
| 2523 | Node *parseEncoding(); |
| 2524 | bool parseCallOffset(); |
| 2525 | Node *parseSpecialName(); |
| 2526 | |
| 2527 | /// Holds some extra information about a <name> that is being parsed. This |
| 2528 | /// information is only pertinent if the <name> refers to an <encoding>. |
| 2529 | struct NameState { |
| 2530 | bool CtorDtorConversion = false; |
| 2531 | bool EndsWithTemplateArgs = false; |
| 2532 | Qualifiers CVQualifiers = QualNone; |
| 2533 | FunctionRefQual ReferenceQualifier = FrefQualNone; |
| 2534 | size_t ForwardTemplateRefsBegin; |
| 2535 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2536 | NameState(AbstractManglingParser *Enclosing) |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2537 | : ForwardTemplateRefsBegin(Enclosing->ForwardTemplateRefs.size()) {} |
| 2538 | }; |
| 2539 | |
| 2540 | bool resolveForwardTemplateRefs(NameState &State) { |
| 2541 | size_t I = State.ForwardTemplateRefsBegin; |
| 2542 | size_t E = ForwardTemplateRefs.size(); |
| 2543 | for (; I < E; ++I) { |
| 2544 | size_t Idx = ForwardTemplateRefs[I]->Index; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2545 | if (TemplateParams.empty() || !TemplateParams[0] || |
| 2546 | Idx >= TemplateParams[0]->size()) |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2547 | return true; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2548 | ForwardTemplateRefs[I]->Ref = (*TemplateParams[0])[Idx]; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2549 | } |
| 2550 | ForwardTemplateRefs.dropBack(State.ForwardTemplateRefsBegin); |
| 2551 | return false; |
| 2552 | } |
| 2553 | |
| 2554 | /// Parse the <name> production> |
| 2555 | Node *parseName(NameState *State = nullptr); |
| 2556 | Node *parseLocalName(NameState *State); |
| 2557 | Node *parseOperatorName(NameState *State); |
| 2558 | Node *parseUnqualifiedName(NameState *State); |
| 2559 | Node *parseUnnamedTypeName(NameState *State); |
| 2560 | Node *parseSourceName(NameState *State); |
| 2561 | Node *parseUnscopedName(NameState *State); |
| 2562 | Node *parseNestedName(NameState *State); |
| 2563 | Node *parseCtorDtorName(Node *&SoFar, NameState *State); |
| 2564 | |
| 2565 | Node *parseAbiTags(Node *N); |
| 2566 | |
| 2567 | /// Parse the <unresolved-name> production. |
| 2568 | Node *parseUnresolvedName(); |
| 2569 | Node *parseSimpleId(); |
| 2570 | Node *parseBaseUnresolvedName(); |
| 2571 | Node *parseUnresolvedType(); |
| 2572 | Node *parseDestructorName(); |
| 2573 | |
| 2574 | /// Top-level entry point into the parser. |
| 2575 | Node *parse(); |
| 2576 | }; |
| 2577 | |
| 2578 | const char* parse_discriminator(const char* first, const char* last); |
| 2579 | |
| 2580 | // <name> ::= <nested-name> // N |
| 2581 | // ::= <local-name> # See Scope Encoding below // Z |
| 2582 | // ::= <unscoped-template-name> <template-args> |
| 2583 | // ::= <unscoped-name> |
| 2584 | // |
| 2585 | // <unscoped-template-name> ::= <unscoped-name> |
| 2586 | // ::= <substitution> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2587 | template <typename Derived, typename Alloc> |
| 2588 | Node *AbstractManglingParser<Derived, Alloc>::parseName(NameState *State) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2589 | consumeIf('L'); // extension |
| 2590 | |
| 2591 | if (look() == 'N') |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2592 | return getDerived().parseNestedName(State); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2593 | if (look() == 'Z') |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2594 | return getDerived().parseLocalName(State); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2595 | |
Nathan Sidwell | bbc2443 | 2022-01-24 04:28:09 -0800 | [diff] [blame] | 2596 | Node *Result = nullptr; |
| 2597 | bool IsSubst = look() == 'S' && look(1) != 't'; |
| 2598 | if (IsSubst) { |
| 2599 | // A substitution must lead to: |
| 2600 | // ::= <unscoped-template-name> <template-args> |
| 2601 | Result = getDerived().parseSubstitution(); |
| 2602 | } else { |
| 2603 | // An unscoped name can be one of: |
| 2604 | // ::= <unscoped-name> |
| 2605 | // ::= <unscoped-template-name> <template-args> |
| 2606 | Result = getDerived().parseUnscopedName(State); |
| 2607 | } |
| 2608 | if (Result == nullptr) |
| 2609 | return nullptr; |
| 2610 | |
| 2611 | if (look() == 'I') { |
| 2612 | // ::= <unscoped-template-name> <template-args> |
| 2613 | if (!IsSubst) |
| 2614 | // An unscoped-template-name is substitutable. |
| 2615 | Subs.push_back(Result); |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2616 | Node *TA = getDerived().parseTemplateArgs(State != nullptr); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2617 | if (TA == nullptr) |
| 2618 | return nullptr; |
Nathan Sidwell | bbc2443 | 2022-01-24 04:28:09 -0800 | [diff] [blame] | 2619 | if (State) |
| 2620 | State->EndsWithTemplateArgs = true; |
| 2621 | Result = make<NameWithTemplateArgs>(Result, TA); |
| 2622 | } else if (IsSubst) { |
| 2623 | // The substitution case must be followed by <template-args>. |
| 2624 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2625 | } |
| 2626 | |
Nathan Sidwell | bbc2443 | 2022-01-24 04:28:09 -0800 | [diff] [blame] | 2627 | return Result; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2628 | } |
| 2629 | |
| 2630 | // <local-name> := Z <function encoding> E <entity name> [<discriminator>] |
| 2631 | // := Z <function encoding> E s [<discriminator>] |
| 2632 | // := Z <function encoding> Ed [ <parameter number> ] _ <entity name> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2633 | template <typename Derived, typename Alloc> |
| 2634 | Node *AbstractManglingParser<Derived, Alloc>::parseLocalName(NameState *State) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2635 | if (!consumeIf('Z')) |
| 2636 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2637 | Node *Encoding = getDerived().parseEncoding(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2638 | if (Encoding == nullptr || !consumeIf('E')) |
| 2639 | return nullptr; |
| 2640 | |
| 2641 | if (consumeIf('s')) { |
| 2642 | First = parse_discriminator(First, Last); |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 2643 | auto *StringLitName = make<NameType>("string literal"); |
| 2644 | if (!StringLitName) |
| 2645 | return nullptr; |
| 2646 | return make<LocalName>(Encoding, StringLitName); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2647 | } |
| 2648 | |
| 2649 | if (consumeIf('d')) { |
| 2650 | parseNumber(true); |
| 2651 | if (!consumeIf('_')) |
| 2652 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2653 | Node *N = getDerived().parseName(State); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2654 | if (N == nullptr) |
| 2655 | return nullptr; |
| 2656 | return make<LocalName>(Encoding, N); |
| 2657 | } |
| 2658 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2659 | Node *Entity = getDerived().parseName(State); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2660 | if (Entity == nullptr) |
| 2661 | return nullptr; |
| 2662 | First = parse_discriminator(First, Last); |
| 2663 | return make<LocalName>(Encoding, Entity); |
| 2664 | } |
| 2665 | |
| 2666 | // <unscoped-name> ::= <unqualified-name> |
| 2667 | // ::= St <unqualified-name> # ::std:: |
| 2668 | // extension ::= StL<unqualified-name> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2669 | template <typename Derived, typename Alloc> |
| 2670 | Node * |
| 2671 | AbstractManglingParser<Derived, Alloc>::parseUnscopedName(NameState *State) { |
Nathan Sidwell | bbc2443 | 2022-01-24 04:28:09 -0800 | [diff] [blame] | 2672 | bool IsStd = consumeIf("St"); |
| 2673 | if (IsStd) |
| 2674 | consumeIf('L'); |
| 2675 | |
| 2676 | Node *Result = getDerived().parseUnqualifiedName(State); |
| 2677 | if (Result == nullptr) |
| 2678 | return nullptr; |
| 2679 | if (IsStd) |
| 2680 | Result = make<StdQualifiedName>(Result); |
| 2681 | |
| 2682 | return Result; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2683 | } |
| 2684 | |
| 2685 | // <unqualified-name> ::= <operator-name> [abi-tags] |
| 2686 | // ::= <ctor-dtor-name> |
| 2687 | // ::= <source-name> |
| 2688 | // ::= <unnamed-type-name> |
| 2689 | // ::= DC <source-name>+ E # structured binding declaration |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2690 | template <typename Derived, typename Alloc> |
| 2691 | Node * |
| 2692 | AbstractManglingParser<Derived, Alloc>::parseUnqualifiedName(NameState *State) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2693 | // <ctor-dtor-name>s are special-cased in parseNestedName(). |
| 2694 | Node *Result; |
| 2695 | if (look() == 'U') |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2696 | Result = getDerived().parseUnnamedTypeName(State); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2697 | else if (look() >= '1' && look() <= '9') |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2698 | Result = getDerived().parseSourceName(State); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2699 | else if (consumeIf("DC")) { |
| 2700 | size_t BindingsBegin = Names.size(); |
| 2701 | do { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2702 | Node *Binding = getDerived().parseSourceName(State); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2703 | if (Binding == nullptr) |
| 2704 | return nullptr; |
| 2705 | Names.push_back(Binding); |
| 2706 | } while (!consumeIf('E')); |
| 2707 | Result = make<StructuredBindingName>(popTrailingNodeArray(BindingsBegin)); |
| 2708 | } else |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2709 | Result = getDerived().parseOperatorName(State); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2710 | if (Result != nullptr) |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2711 | Result = getDerived().parseAbiTags(Result); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2712 | return Result; |
| 2713 | } |
| 2714 | |
| 2715 | // <unnamed-type-name> ::= Ut [<nonnegative number>] _ |
| 2716 | // ::= <closure-type-name> |
| 2717 | // |
| 2718 | // <closure-type-name> ::= Ul <lambda-sig> E [ <nonnegative number> ] _ |
| 2719 | // |
| 2720 | // <lambda-sig> ::= <parameter type>+ # Parameter types or "v" if the lambda has no parameters |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2721 | template <typename Derived, typename Alloc> |
| 2722 | Node * |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2723 | AbstractManglingParser<Derived, Alloc>::parseUnnamedTypeName(NameState *State) { |
| 2724 | // <template-params> refer to the innermost <template-args>. Clear out any |
| 2725 | // outer args that we may have inserted into TemplateParams. |
| 2726 | if (State != nullptr) |
| 2727 | TemplateParams.clear(); |
| 2728 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2729 | if (consumeIf("Ut")) { |
| 2730 | StringView Count = parseNumber(); |
| 2731 | if (!consumeIf('_')) |
| 2732 | return nullptr; |
| 2733 | return make<UnnamedTypeName>(Count); |
| 2734 | } |
| 2735 | if (consumeIf("Ul")) { |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2736 | SwapAndRestore<size_t> SwapParams(ParsingLambdaParamsAtLevel, |
| 2737 | TemplateParams.size()); |
| 2738 | ScopedTemplateParamList LambdaTemplateParams(this); |
| 2739 | |
| 2740 | size_t ParamsBegin = Names.size(); |
| 2741 | while (look() == 'T' && |
| 2742 | StringView("yptn").find(look(1)) != StringView::npos) { |
| 2743 | Node *T = parseTemplateParamDecl(); |
| 2744 | if (!T) |
| 2745 | return nullptr; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2746 | Names.push_back(T); |
| 2747 | } |
| 2748 | NodeArray TempParams = popTrailingNodeArray(ParamsBegin); |
| 2749 | |
| 2750 | // FIXME: If TempParams is empty and none of the function parameters |
| 2751 | // includes 'auto', we should remove LambdaTemplateParams from the |
| 2752 | // TemplateParams list. Unfortunately, we don't find out whether there are |
| 2753 | // any 'auto' parameters until too late in an example such as: |
| 2754 | // |
| 2755 | // template<typename T> void f( |
| 2756 | // decltype([](decltype([]<typename T>(T v) {}), |
| 2757 | // auto) {})) {} |
| 2758 | // template<typename T> void f( |
| 2759 | // decltype([](decltype([]<typename T>(T w) {}), |
| 2760 | // int) {})) {} |
| 2761 | // |
| 2762 | // Here, the type of v is at level 2 but the type of w is at level 1. We |
| 2763 | // don't find this out until we encounter the type of the next parameter. |
| 2764 | // |
| 2765 | // However, compilers can't actually cope with the former example in |
| 2766 | // practice, and it's likely to be made ill-formed in future, so we don't |
| 2767 | // need to support it here. |
| 2768 | // |
| 2769 | // If we encounter an 'auto' in the function parameter types, we will |
| 2770 | // recreate a template parameter scope for it, but any intervening lambdas |
| 2771 | // will be parsed in the 'wrong' template parameter depth. |
| 2772 | if (TempParams.empty()) |
| 2773 | TemplateParams.pop_back(); |
| 2774 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2775 | if (!consumeIf("vE")) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2776 | do { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2777 | Node *P = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2778 | if (P == nullptr) |
| 2779 | return nullptr; |
| 2780 | Names.push_back(P); |
| 2781 | } while (!consumeIf('E')); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2782 | } |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2783 | NodeArray Params = popTrailingNodeArray(ParamsBegin); |
| 2784 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2785 | StringView Count = parseNumber(); |
| 2786 | if (!consumeIf('_')) |
| 2787 | return nullptr; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 2788 | return make<ClosureTypeName>(TempParams, Params, Count); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2789 | } |
Erik Pilkington | f0b7439 | 2019-01-17 21:37:51 +0000 | [diff] [blame] | 2790 | if (consumeIf("Ub")) { |
| 2791 | (void)parseNumber(); |
| 2792 | if (!consumeIf('_')) |
| 2793 | return nullptr; |
| 2794 | return make<NameType>("'block-literal'"); |
| 2795 | } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2796 | return nullptr; |
| 2797 | } |
| 2798 | |
| 2799 | // <source-name> ::= <positive length number> <identifier> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2800 | template <typename Derived, typename Alloc> |
| 2801 | Node *AbstractManglingParser<Derived, Alloc>::parseSourceName(NameState *) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2802 | size_t Length = 0; |
| 2803 | if (parsePositiveInteger(&Length)) |
| 2804 | return nullptr; |
| 2805 | if (numLeft() < Length || Length == 0) |
| 2806 | return nullptr; |
| 2807 | StringView Name(First, First + Length); |
| 2808 | First += Length; |
| 2809 | if (Name.startsWith("_GLOBAL__N")) |
| 2810 | return make<NameType>("(anonymous namespace)"); |
| 2811 | return make<NameType>(Name); |
| 2812 | } |
| 2813 | |
| 2814 | // <operator-name> ::= aa # && |
| 2815 | // ::= ad # & (unary) |
| 2816 | // ::= an # & |
| 2817 | // ::= aN # &= |
| 2818 | // ::= aS # = |
| 2819 | // ::= cl # () |
| 2820 | // ::= cm # , |
| 2821 | // ::= co # ~ |
| 2822 | // ::= cv <type> # (cast) |
| 2823 | // ::= da # delete[] |
| 2824 | // ::= de # * (unary) |
| 2825 | // ::= dl # delete |
| 2826 | // ::= dv # / |
| 2827 | // ::= dV # /= |
| 2828 | // ::= eo # ^ |
| 2829 | // ::= eO # ^= |
| 2830 | // ::= eq # == |
| 2831 | // ::= ge # >= |
| 2832 | // ::= gt # > |
| 2833 | // ::= ix # [] |
| 2834 | // ::= le # <= |
| 2835 | // ::= li <source-name> # operator "" |
| 2836 | // ::= ls # << |
| 2837 | // ::= lS # <<= |
| 2838 | // ::= lt # < |
| 2839 | // ::= mi # - |
| 2840 | // ::= mI # -= |
| 2841 | // ::= ml # * |
| 2842 | // ::= mL # *= |
| 2843 | // ::= mm # -- (postfix in <expression> context) |
| 2844 | // ::= na # new[] |
| 2845 | // ::= ne # != |
| 2846 | // ::= ng # - (unary) |
| 2847 | // ::= nt # ! |
| 2848 | // ::= nw # new |
| 2849 | // ::= oo # || |
| 2850 | // ::= or # | |
| 2851 | // ::= oR # |= |
| 2852 | // ::= pm # ->* |
| 2853 | // ::= pl # + |
| 2854 | // ::= pL # += |
| 2855 | // ::= pp # ++ (postfix in <expression> context) |
| 2856 | // ::= ps # + (unary) |
| 2857 | // ::= pt # -> |
| 2858 | // ::= qu # ? |
| 2859 | // ::= rm # % |
| 2860 | // ::= rM # %= |
| 2861 | // ::= rs # >> |
| 2862 | // ::= rS # >>= |
| 2863 | // ::= ss # <=> C++2a |
| 2864 | // ::= v <digit> <source-name> # vendor extended operator |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2865 | template <typename Derived, typename Alloc> |
| 2866 | Node * |
| 2867 | AbstractManglingParser<Derived, Alloc>::parseOperatorName(NameState *State) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2868 | switch (look()) { |
| 2869 | case 'a': |
| 2870 | switch (look(1)) { |
| 2871 | case 'a': |
| 2872 | First += 2; |
| 2873 | return make<NameType>("operator&&"); |
| 2874 | case 'd': |
| 2875 | case 'n': |
| 2876 | First += 2; |
| 2877 | return make<NameType>("operator&"); |
| 2878 | case 'N': |
| 2879 | First += 2; |
| 2880 | return make<NameType>("operator&="); |
| 2881 | case 'S': |
| 2882 | First += 2; |
| 2883 | return make<NameType>("operator="); |
| 2884 | } |
| 2885 | return nullptr; |
| 2886 | case 'c': |
| 2887 | switch (look(1)) { |
| 2888 | case 'l': |
| 2889 | First += 2; |
| 2890 | return make<NameType>("operator()"); |
| 2891 | case 'm': |
| 2892 | First += 2; |
| 2893 | return make<NameType>("operator,"); |
| 2894 | case 'o': |
| 2895 | First += 2; |
| 2896 | return make<NameType>("operator~"); |
| 2897 | // ::= cv <type> # (cast) |
| 2898 | case 'v': { |
| 2899 | First += 2; |
| 2900 | SwapAndRestore<bool> SaveTemplate(TryToParseTemplateArgs, false); |
| 2901 | // If we're parsing an encoding, State != nullptr and the conversion |
| 2902 | // operators' <type> could have a <template-param> that refers to some |
| 2903 | // <template-arg>s further ahead in the mangled name. |
| 2904 | SwapAndRestore<bool> SavePermit(PermitForwardTemplateReferences, |
| 2905 | PermitForwardTemplateReferences || |
| 2906 | State != nullptr); |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2907 | Node *Ty = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2908 | if (Ty == nullptr) |
| 2909 | return nullptr; |
| 2910 | if (State) State->CtorDtorConversion = true; |
| 2911 | return make<ConversionOperatorType>(Ty); |
| 2912 | } |
| 2913 | } |
| 2914 | return nullptr; |
| 2915 | case 'd': |
| 2916 | switch (look(1)) { |
| 2917 | case 'a': |
| 2918 | First += 2; |
| 2919 | return make<NameType>("operator delete[]"); |
| 2920 | case 'e': |
| 2921 | First += 2; |
| 2922 | return make<NameType>("operator*"); |
| 2923 | case 'l': |
| 2924 | First += 2; |
| 2925 | return make<NameType>("operator delete"); |
| 2926 | case 'v': |
| 2927 | First += 2; |
| 2928 | return make<NameType>("operator/"); |
| 2929 | case 'V': |
| 2930 | First += 2; |
| 2931 | return make<NameType>("operator/="); |
| 2932 | } |
| 2933 | return nullptr; |
| 2934 | case 'e': |
| 2935 | switch (look(1)) { |
| 2936 | case 'o': |
| 2937 | First += 2; |
| 2938 | return make<NameType>("operator^"); |
| 2939 | case 'O': |
| 2940 | First += 2; |
| 2941 | return make<NameType>("operator^="); |
| 2942 | case 'q': |
| 2943 | First += 2; |
| 2944 | return make<NameType>("operator=="); |
| 2945 | } |
| 2946 | return nullptr; |
| 2947 | case 'g': |
| 2948 | switch (look(1)) { |
| 2949 | case 'e': |
| 2950 | First += 2; |
| 2951 | return make<NameType>("operator>="); |
| 2952 | case 't': |
| 2953 | First += 2; |
| 2954 | return make<NameType>("operator>"); |
| 2955 | } |
| 2956 | return nullptr; |
| 2957 | case 'i': |
| 2958 | if (look(1) == 'x') { |
| 2959 | First += 2; |
| 2960 | return make<NameType>("operator[]"); |
| 2961 | } |
| 2962 | return nullptr; |
| 2963 | case 'l': |
| 2964 | switch (look(1)) { |
| 2965 | case 'e': |
| 2966 | First += 2; |
| 2967 | return make<NameType>("operator<="); |
| 2968 | // ::= li <source-name> # operator "" |
| 2969 | case 'i': { |
| 2970 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 2971 | Node *SN = getDerived().parseSourceName(State); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 2972 | if (SN == nullptr) |
| 2973 | return nullptr; |
| 2974 | return make<LiteralOperator>(SN); |
| 2975 | } |
| 2976 | case 's': |
| 2977 | First += 2; |
| 2978 | return make<NameType>("operator<<"); |
| 2979 | case 'S': |
| 2980 | First += 2; |
| 2981 | return make<NameType>("operator<<="); |
| 2982 | case 't': |
| 2983 | First += 2; |
| 2984 | return make<NameType>("operator<"); |
| 2985 | } |
| 2986 | return nullptr; |
| 2987 | case 'm': |
| 2988 | switch (look(1)) { |
| 2989 | case 'i': |
| 2990 | First += 2; |
| 2991 | return make<NameType>("operator-"); |
| 2992 | case 'I': |
| 2993 | First += 2; |
| 2994 | return make<NameType>("operator-="); |
| 2995 | case 'l': |
| 2996 | First += 2; |
| 2997 | return make<NameType>("operator*"); |
| 2998 | case 'L': |
| 2999 | First += 2; |
| 3000 | return make<NameType>("operator*="); |
| 3001 | case 'm': |
| 3002 | First += 2; |
| 3003 | return make<NameType>("operator--"); |
| 3004 | } |
| 3005 | return nullptr; |
| 3006 | case 'n': |
| 3007 | switch (look(1)) { |
| 3008 | case 'a': |
| 3009 | First += 2; |
| 3010 | return make<NameType>("operator new[]"); |
| 3011 | case 'e': |
| 3012 | First += 2; |
| 3013 | return make<NameType>("operator!="); |
| 3014 | case 'g': |
| 3015 | First += 2; |
| 3016 | return make<NameType>("operator-"); |
| 3017 | case 't': |
| 3018 | First += 2; |
| 3019 | return make<NameType>("operator!"); |
| 3020 | case 'w': |
| 3021 | First += 2; |
| 3022 | return make<NameType>("operator new"); |
| 3023 | } |
| 3024 | return nullptr; |
| 3025 | case 'o': |
| 3026 | switch (look(1)) { |
| 3027 | case 'o': |
| 3028 | First += 2; |
| 3029 | return make<NameType>("operator||"); |
| 3030 | case 'r': |
| 3031 | First += 2; |
| 3032 | return make<NameType>("operator|"); |
| 3033 | case 'R': |
| 3034 | First += 2; |
| 3035 | return make<NameType>("operator|="); |
| 3036 | } |
| 3037 | return nullptr; |
| 3038 | case 'p': |
| 3039 | switch (look(1)) { |
| 3040 | case 'm': |
| 3041 | First += 2; |
| 3042 | return make<NameType>("operator->*"); |
| 3043 | case 'l': |
| 3044 | First += 2; |
| 3045 | return make<NameType>("operator+"); |
| 3046 | case 'L': |
| 3047 | First += 2; |
| 3048 | return make<NameType>("operator+="); |
| 3049 | case 'p': |
| 3050 | First += 2; |
| 3051 | return make<NameType>("operator++"); |
| 3052 | case 's': |
| 3053 | First += 2; |
| 3054 | return make<NameType>("operator+"); |
| 3055 | case 't': |
| 3056 | First += 2; |
| 3057 | return make<NameType>("operator->"); |
| 3058 | } |
| 3059 | return nullptr; |
| 3060 | case 'q': |
| 3061 | if (look(1) == 'u') { |
| 3062 | First += 2; |
| 3063 | return make<NameType>("operator?"); |
| 3064 | } |
| 3065 | return nullptr; |
| 3066 | case 'r': |
| 3067 | switch (look(1)) { |
| 3068 | case 'm': |
| 3069 | First += 2; |
| 3070 | return make<NameType>("operator%"); |
| 3071 | case 'M': |
| 3072 | First += 2; |
| 3073 | return make<NameType>("operator%="); |
| 3074 | case 's': |
| 3075 | First += 2; |
| 3076 | return make<NameType>("operator>>"); |
| 3077 | case 'S': |
| 3078 | First += 2; |
| 3079 | return make<NameType>("operator>>="); |
| 3080 | } |
| 3081 | return nullptr; |
| 3082 | case 's': |
| 3083 | if (look(1) == 's') { |
| 3084 | First += 2; |
| 3085 | return make<NameType>("operator<=>"); |
| 3086 | } |
| 3087 | return nullptr; |
| 3088 | // ::= v <digit> <source-name> # vendor extended operator |
| 3089 | case 'v': |
| 3090 | if (std::isdigit(look(1))) { |
| 3091 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3092 | Node *SN = getDerived().parseSourceName(State); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3093 | if (SN == nullptr) |
| 3094 | return nullptr; |
| 3095 | return make<ConversionOperatorType>(SN); |
| 3096 | } |
| 3097 | return nullptr; |
| 3098 | } |
| 3099 | return nullptr; |
| 3100 | } |
| 3101 | |
| 3102 | // <ctor-dtor-name> ::= C1 # complete object constructor |
| 3103 | // ::= C2 # base object constructor |
| 3104 | // ::= C3 # complete object allocating constructor |
Nico Weber | ba88b37 | 2019-04-03 23:14:33 +0000 | [diff] [blame] | 3105 | // extension ::= C4 # gcc old-style "[unified]" constructor |
| 3106 | // extension ::= C5 # the COMDAT used for ctors |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3107 | // ::= D0 # deleting destructor |
| 3108 | // ::= D1 # complete object destructor |
| 3109 | // ::= D2 # base object destructor |
Nico Weber | ba88b37 | 2019-04-03 23:14:33 +0000 | [diff] [blame] | 3110 | // extension ::= D4 # gcc old-style "[unified]" destructor |
| 3111 | // extension ::= D5 # the COMDAT used for dtors |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3112 | template <typename Derived, typename Alloc> |
| 3113 | Node * |
| 3114 | AbstractManglingParser<Derived, Alloc>::parseCtorDtorName(Node *&SoFar, |
| 3115 | NameState *State) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3116 | if (SoFar->getKind() == Node::KSpecialSubstitution) { |
| 3117 | auto SSK = static_cast<SpecialSubstitution *>(SoFar)->SSK; |
| 3118 | switch (SSK) { |
| 3119 | case SpecialSubKind::string: |
| 3120 | case SpecialSubKind::istream: |
| 3121 | case SpecialSubKind::ostream: |
| 3122 | case SpecialSubKind::iostream: |
| 3123 | SoFar = make<ExpandedSpecialSubstitution>(SSK); |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 3124 | if (!SoFar) |
| 3125 | return nullptr; |
Reid Kleckner | 9ddef32 | 2018-11-01 18:24:03 +0000 | [diff] [blame] | 3126 | break; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3127 | default: |
| 3128 | break; |
| 3129 | } |
| 3130 | } |
| 3131 | |
| 3132 | if (consumeIf('C')) { |
| 3133 | bool IsInherited = consumeIf('I'); |
Nico Weber | ba88b37 | 2019-04-03 23:14:33 +0000 | [diff] [blame] | 3134 | if (look() != '1' && look() != '2' && look() != '3' && look() != '4' && |
| 3135 | look() != '5') |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3136 | return nullptr; |
Pavel Labath | 3605009 | 2018-10-10 08:39:16 +0000 | [diff] [blame] | 3137 | int Variant = look() - '0'; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3138 | ++First; |
| 3139 | if (State) State->CtorDtorConversion = true; |
| 3140 | if (IsInherited) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3141 | if (getDerived().parseName(State) == nullptr) |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3142 | return nullptr; |
| 3143 | } |
Nico Weber | ba88b37 | 2019-04-03 23:14:33 +0000 | [diff] [blame] | 3144 | return make<CtorDtorName>(SoFar, /*IsDtor=*/false, Variant); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3145 | } |
| 3146 | |
Nico Weber | ba88b37 | 2019-04-03 23:14:33 +0000 | [diff] [blame] | 3147 | if (look() == 'D' && (look(1) == '0' || look(1) == '1' || look(1) == '2' || |
| 3148 | look(1) == '4' || look(1) == '5')) { |
Pavel Labath | 3605009 | 2018-10-10 08:39:16 +0000 | [diff] [blame] | 3149 | int Variant = look(1) - '0'; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3150 | First += 2; |
| 3151 | if (State) State->CtorDtorConversion = true; |
Nico Weber | ba88b37 | 2019-04-03 23:14:33 +0000 | [diff] [blame] | 3152 | return make<CtorDtorName>(SoFar, /*IsDtor=*/true, Variant); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3153 | } |
| 3154 | |
| 3155 | return nullptr; |
| 3156 | } |
| 3157 | |
| 3158 | // <nested-name> ::= N [<CV-Qualifiers>] [<ref-qualifier>] <prefix> <unqualified-name> E |
| 3159 | // ::= N [<CV-Qualifiers>] [<ref-qualifier>] <template-prefix> <template-args> E |
| 3160 | // |
| 3161 | // <prefix> ::= <prefix> <unqualified-name> |
| 3162 | // ::= <template-prefix> <template-args> |
| 3163 | // ::= <template-param> |
| 3164 | // ::= <decltype> |
| 3165 | // ::= # empty |
| 3166 | // ::= <substitution> |
| 3167 | // ::= <prefix> <data-member-prefix> |
| 3168 | // extension ::= L |
| 3169 | // |
| 3170 | // <data-member-prefix> := <member source-name> [<template-args>] M |
| 3171 | // |
| 3172 | // <template-prefix> ::= <prefix> <template unqualified-name> |
| 3173 | // ::= <template-param> |
| 3174 | // ::= <substitution> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3175 | template <typename Derived, typename Alloc> |
| 3176 | Node * |
| 3177 | AbstractManglingParser<Derived, Alloc>::parseNestedName(NameState *State) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3178 | if (!consumeIf('N')) |
| 3179 | return nullptr; |
| 3180 | |
| 3181 | Qualifiers CVTmp = parseCVQualifiers(); |
| 3182 | if (State) State->CVQualifiers = CVTmp; |
| 3183 | |
| 3184 | if (consumeIf('O')) { |
| 3185 | if (State) State->ReferenceQualifier = FrefQualRValue; |
| 3186 | } else if (consumeIf('R')) { |
| 3187 | if (State) State->ReferenceQualifier = FrefQualLValue; |
| 3188 | } else |
| 3189 | if (State) State->ReferenceQualifier = FrefQualNone; |
| 3190 | |
| 3191 | Node *SoFar = nullptr; |
| 3192 | auto PushComponent = [&](Node *Comp) { |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 3193 | if (!Comp) return false; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3194 | if (SoFar) SoFar = make<NestedName>(SoFar, Comp); |
| 3195 | else SoFar = Comp; |
| 3196 | if (State) State->EndsWithTemplateArgs = false; |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 3197 | return SoFar != nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3198 | }; |
| 3199 | |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 3200 | if (consumeIf("St")) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3201 | SoFar = make<NameType>("std"); |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 3202 | if (!SoFar) |
| 3203 | return nullptr; |
| 3204 | } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3205 | |
| 3206 | while (!consumeIf('E')) { |
| 3207 | consumeIf('L'); // extension |
| 3208 | |
| 3209 | // <data-member-prefix> := <member source-name> [<template-args>] M |
| 3210 | if (consumeIf('M')) { |
| 3211 | if (SoFar == nullptr) |
| 3212 | return nullptr; |
| 3213 | continue; |
| 3214 | } |
| 3215 | |
| 3216 | // ::= <template-param> |
| 3217 | if (look() == 'T') { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3218 | if (!PushComponent(getDerived().parseTemplateParam())) |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3219 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3220 | Subs.push_back(SoFar); |
| 3221 | continue; |
| 3222 | } |
| 3223 | |
| 3224 | // ::= <template-prefix> <template-args> |
| 3225 | if (look() == 'I') { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3226 | Node *TA = getDerived().parseTemplateArgs(State != nullptr); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3227 | if (TA == nullptr || SoFar == nullptr) |
| 3228 | return nullptr; |
| 3229 | SoFar = make<NameWithTemplateArgs>(SoFar, TA); |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 3230 | if (!SoFar) |
| 3231 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3232 | if (State) State->EndsWithTemplateArgs = true; |
| 3233 | Subs.push_back(SoFar); |
| 3234 | continue; |
| 3235 | } |
| 3236 | |
| 3237 | // ::= <decltype> |
| 3238 | if (look() == 'D' && (look(1) == 't' || look(1) == 'T')) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3239 | if (!PushComponent(getDerived().parseDecltype())) |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3240 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3241 | Subs.push_back(SoFar); |
| 3242 | continue; |
| 3243 | } |
| 3244 | |
| 3245 | // ::= <substitution> |
| 3246 | if (look() == 'S' && look(1) != 't') { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3247 | Node *S = getDerived().parseSubstitution(); |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 3248 | if (!PushComponent(S)) |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3249 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3250 | if (SoFar != S) |
| 3251 | Subs.push_back(S); |
| 3252 | continue; |
| 3253 | } |
| 3254 | |
| 3255 | // Parse an <unqualified-name> thats actually a <ctor-dtor-name>. |
| 3256 | if (look() == 'C' || (look() == 'D' && look(1) != 'C')) { |
| 3257 | if (SoFar == nullptr) |
| 3258 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3259 | if (!PushComponent(getDerived().parseCtorDtorName(SoFar, State))) |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3260 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3261 | SoFar = getDerived().parseAbiTags(SoFar); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3262 | if (SoFar == nullptr) |
| 3263 | return nullptr; |
| 3264 | Subs.push_back(SoFar); |
| 3265 | continue; |
| 3266 | } |
| 3267 | |
| 3268 | // ::= <prefix> <unqualified-name> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3269 | if (!PushComponent(getDerived().parseUnqualifiedName(State))) |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3270 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3271 | Subs.push_back(SoFar); |
| 3272 | } |
| 3273 | |
| 3274 | if (SoFar == nullptr || Subs.empty()) |
| 3275 | return nullptr; |
| 3276 | |
| 3277 | Subs.pop_back(); |
| 3278 | return SoFar; |
| 3279 | } |
| 3280 | |
| 3281 | // <simple-id> ::= <source-name> [ <template-args> ] |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3282 | template <typename Derived, typename Alloc> |
| 3283 | Node *AbstractManglingParser<Derived, Alloc>::parseSimpleId() { |
| 3284 | Node *SN = getDerived().parseSourceName(/*NameState=*/nullptr); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3285 | if (SN == nullptr) |
| 3286 | return nullptr; |
| 3287 | if (look() == 'I') { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3288 | Node *TA = getDerived().parseTemplateArgs(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3289 | if (TA == nullptr) |
| 3290 | return nullptr; |
| 3291 | return make<NameWithTemplateArgs>(SN, TA); |
| 3292 | } |
| 3293 | return SN; |
| 3294 | } |
| 3295 | |
| 3296 | // <destructor-name> ::= <unresolved-type> # e.g., ~T or ~decltype(f()) |
| 3297 | // ::= <simple-id> # e.g., ~A<2*N> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3298 | template <typename Derived, typename Alloc> |
| 3299 | Node *AbstractManglingParser<Derived, Alloc>::parseDestructorName() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3300 | Node *Result; |
| 3301 | if (std::isdigit(look())) |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3302 | Result = getDerived().parseSimpleId(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3303 | else |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3304 | Result = getDerived().parseUnresolvedType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3305 | if (Result == nullptr) |
| 3306 | return nullptr; |
| 3307 | return make<DtorName>(Result); |
| 3308 | } |
| 3309 | |
| 3310 | // <unresolved-type> ::= <template-param> |
| 3311 | // ::= <decltype> |
| 3312 | // ::= <substitution> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3313 | template <typename Derived, typename Alloc> |
| 3314 | Node *AbstractManglingParser<Derived, Alloc>::parseUnresolvedType() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3315 | if (look() == 'T') { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3316 | Node *TP = getDerived().parseTemplateParam(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3317 | if (TP == nullptr) |
| 3318 | return nullptr; |
| 3319 | Subs.push_back(TP); |
| 3320 | return TP; |
| 3321 | } |
| 3322 | if (look() == 'D') { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3323 | Node *DT = getDerived().parseDecltype(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3324 | if (DT == nullptr) |
| 3325 | return nullptr; |
| 3326 | Subs.push_back(DT); |
| 3327 | return DT; |
| 3328 | } |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3329 | return getDerived().parseSubstitution(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3330 | } |
| 3331 | |
| 3332 | // <base-unresolved-name> ::= <simple-id> # unresolved name |
| 3333 | // extension ::= <operator-name> # unresolved operator-function-id |
| 3334 | // extension ::= <operator-name> <template-args> # unresolved operator template-id |
| 3335 | // ::= on <operator-name> # unresolved operator-function-id |
| 3336 | // ::= on <operator-name> <template-args> # unresolved operator template-id |
| 3337 | // ::= dn <destructor-name> # destructor or pseudo-destructor; |
| 3338 | // # e.g. ~X or ~X<N-1> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3339 | template <typename Derived, typename Alloc> |
| 3340 | Node *AbstractManglingParser<Derived, Alloc>::parseBaseUnresolvedName() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3341 | if (std::isdigit(look())) |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3342 | return getDerived().parseSimpleId(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3343 | |
| 3344 | if (consumeIf("dn")) |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3345 | return getDerived().parseDestructorName(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3346 | |
| 3347 | consumeIf("on"); |
| 3348 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3349 | Node *Oper = getDerived().parseOperatorName(/*NameState=*/nullptr); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3350 | if (Oper == nullptr) |
| 3351 | return nullptr; |
| 3352 | if (look() == 'I') { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3353 | Node *TA = getDerived().parseTemplateArgs(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3354 | if (TA == nullptr) |
| 3355 | return nullptr; |
| 3356 | return make<NameWithTemplateArgs>(Oper, TA); |
| 3357 | } |
| 3358 | return Oper; |
| 3359 | } |
| 3360 | |
| 3361 | // <unresolved-name> |
| 3362 | // extension ::= srN <unresolved-type> [<template-args>] <unresolved-qualifier-level>* E <base-unresolved-name> |
| 3363 | // ::= [gs] <base-unresolved-name> # x or (with "gs") ::x |
| 3364 | // ::= [gs] sr <unresolved-qualifier-level>+ E <base-unresolved-name> |
| 3365 | // # A::x, N::y, A<T>::z; "gs" means leading "::" |
| 3366 | // ::= sr <unresolved-type> <base-unresolved-name> # T::x / decltype(p)::x |
| 3367 | // extension ::= sr <unresolved-type> <template-args> <base-unresolved-name> |
| 3368 | // # T::N::x /decltype(p)::N::x |
| 3369 | // (ignored) ::= srN <unresolved-type> <unresolved-qualifier-level>+ E <base-unresolved-name> |
| 3370 | // |
| 3371 | // <unresolved-qualifier-level> ::= <simple-id> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3372 | template <typename Derived, typename Alloc> |
| 3373 | Node *AbstractManglingParser<Derived, Alloc>::parseUnresolvedName() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3374 | Node *SoFar = nullptr; |
| 3375 | |
| 3376 | // srN <unresolved-type> [<template-args>] <unresolved-qualifier-level>* E <base-unresolved-name> |
| 3377 | // srN <unresolved-type> <unresolved-qualifier-level>+ E <base-unresolved-name> |
| 3378 | if (consumeIf("srN")) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3379 | SoFar = getDerived().parseUnresolvedType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3380 | if (SoFar == nullptr) |
| 3381 | return nullptr; |
| 3382 | |
| 3383 | if (look() == 'I') { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3384 | Node *TA = getDerived().parseTemplateArgs(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3385 | if (TA == nullptr) |
| 3386 | return nullptr; |
| 3387 | SoFar = make<NameWithTemplateArgs>(SoFar, TA); |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 3388 | if (!SoFar) |
| 3389 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3390 | } |
| 3391 | |
| 3392 | while (!consumeIf('E')) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3393 | Node *Qual = getDerived().parseSimpleId(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3394 | if (Qual == nullptr) |
| 3395 | return nullptr; |
| 3396 | SoFar = make<QualifiedName>(SoFar, Qual); |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 3397 | if (!SoFar) |
| 3398 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3399 | } |
| 3400 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3401 | Node *Base = getDerived().parseBaseUnresolvedName(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3402 | if (Base == nullptr) |
| 3403 | return nullptr; |
| 3404 | return make<QualifiedName>(SoFar, Base); |
| 3405 | } |
| 3406 | |
| 3407 | bool Global = consumeIf("gs"); |
| 3408 | |
| 3409 | // [gs] <base-unresolved-name> # x or (with "gs") ::x |
| 3410 | if (!consumeIf("sr")) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3411 | SoFar = getDerived().parseBaseUnresolvedName(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3412 | if (SoFar == nullptr) |
| 3413 | return nullptr; |
| 3414 | if (Global) |
| 3415 | SoFar = make<GlobalQualifiedName>(SoFar); |
| 3416 | return SoFar; |
| 3417 | } |
| 3418 | |
| 3419 | // [gs] sr <unresolved-qualifier-level>+ E <base-unresolved-name> |
| 3420 | if (std::isdigit(look())) { |
| 3421 | do { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3422 | Node *Qual = getDerived().parseSimpleId(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3423 | if (Qual == nullptr) |
| 3424 | return nullptr; |
| 3425 | if (SoFar) |
| 3426 | SoFar = make<QualifiedName>(SoFar, Qual); |
| 3427 | else if (Global) |
| 3428 | SoFar = make<GlobalQualifiedName>(Qual); |
| 3429 | else |
| 3430 | SoFar = Qual; |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 3431 | if (!SoFar) |
| 3432 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3433 | } while (!consumeIf('E')); |
| 3434 | } |
| 3435 | // sr <unresolved-type> <base-unresolved-name> |
| 3436 | // sr <unresolved-type> <template-args> <base-unresolved-name> |
| 3437 | else { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3438 | SoFar = getDerived().parseUnresolvedType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3439 | if (SoFar == nullptr) |
| 3440 | return nullptr; |
| 3441 | |
| 3442 | if (look() == 'I') { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3443 | Node *TA = getDerived().parseTemplateArgs(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3444 | if (TA == nullptr) |
| 3445 | return nullptr; |
| 3446 | SoFar = make<NameWithTemplateArgs>(SoFar, TA); |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 3447 | if (!SoFar) |
| 3448 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3449 | } |
| 3450 | } |
| 3451 | |
| 3452 | assert(SoFar != nullptr); |
| 3453 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3454 | Node *Base = getDerived().parseBaseUnresolvedName(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3455 | if (Base == nullptr) |
| 3456 | return nullptr; |
| 3457 | return make<QualifiedName>(SoFar, Base); |
| 3458 | } |
| 3459 | |
| 3460 | // <abi-tags> ::= <abi-tag> [<abi-tags>] |
| 3461 | // <abi-tag> ::= B <source-name> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3462 | template <typename Derived, typename Alloc> |
| 3463 | Node *AbstractManglingParser<Derived, Alloc>::parseAbiTags(Node *N) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3464 | while (consumeIf('B')) { |
| 3465 | StringView SN = parseBareSourceName(); |
| 3466 | if (SN.empty()) |
| 3467 | return nullptr; |
| 3468 | N = make<AbiTagAttr>(N, SN); |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 3469 | if (!N) |
| 3470 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3471 | } |
| 3472 | return N; |
| 3473 | } |
| 3474 | |
| 3475 | // <number> ::= [n] <non-negative decimal integer> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3476 | template <typename Alloc, typename Derived> |
| 3477 | StringView |
| 3478 | AbstractManglingParser<Alloc, Derived>::parseNumber(bool AllowNegative) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3479 | const char *Tmp = First; |
| 3480 | if (AllowNegative) |
| 3481 | consumeIf('n'); |
| 3482 | if (numLeft() == 0 || !std::isdigit(*First)) |
| 3483 | return StringView(); |
| 3484 | while (numLeft() != 0 && std::isdigit(*First)) |
| 3485 | ++First; |
| 3486 | return StringView(Tmp, First); |
| 3487 | } |
| 3488 | |
| 3489 | // <positive length number> ::= [0-9]* |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3490 | template <typename Alloc, typename Derived> |
| 3491 | bool AbstractManglingParser<Alloc, Derived>::parsePositiveInteger(size_t *Out) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3492 | *Out = 0; |
| 3493 | if (look() < '0' || look() > '9') |
| 3494 | return true; |
| 3495 | while (look() >= '0' && look() <= '9') { |
| 3496 | *Out *= 10; |
| 3497 | *Out += static_cast<size_t>(consume() - '0'); |
| 3498 | } |
| 3499 | return false; |
| 3500 | } |
| 3501 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3502 | template <typename Alloc, typename Derived> |
| 3503 | StringView AbstractManglingParser<Alloc, Derived>::parseBareSourceName() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3504 | size_t Int = 0; |
| 3505 | if (parsePositiveInteger(&Int) || numLeft() < Int) |
| 3506 | return StringView(); |
| 3507 | StringView R(First, First + Int); |
| 3508 | First += Int; |
| 3509 | return R; |
| 3510 | } |
| 3511 | |
| 3512 | // <function-type> ::= [<CV-qualifiers>] [<exception-spec>] [Dx] F [Y] <bare-function-type> [<ref-qualifier>] E |
| 3513 | // |
| 3514 | // <exception-spec> ::= Do # non-throwing exception-specification (e.g., noexcept, throw()) |
| 3515 | // ::= DO <expression> E # computed (instantiation-dependent) noexcept |
| 3516 | // ::= Dw <type>+ E # dynamic exception specification with instantiation-dependent types |
| 3517 | // |
| 3518 | // <ref-qualifier> ::= R # & ref-qualifier |
| 3519 | // <ref-qualifier> ::= O # && ref-qualifier |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3520 | template <typename Derived, typename Alloc> |
| 3521 | Node *AbstractManglingParser<Derived, Alloc>::parseFunctionType() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3522 | Qualifiers CVQuals = parseCVQualifiers(); |
| 3523 | |
| 3524 | Node *ExceptionSpec = nullptr; |
| 3525 | if (consumeIf("Do")) { |
| 3526 | ExceptionSpec = make<NameType>("noexcept"); |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 3527 | if (!ExceptionSpec) |
| 3528 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3529 | } else if (consumeIf("DO")) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3530 | Node *E = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3531 | if (E == nullptr || !consumeIf('E')) |
| 3532 | return nullptr; |
| 3533 | ExceptionSpec = make<NoexceptSpec>(E); |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 3534 | if (!ExceptionSpec) |
| 3535 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3536 | } else if (consumeIf("Dw")) { |
| 3537 | size_t SpecsBegin = Names.size(); |
| 3538 | while (!consumeIf('E')) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3539 | Node *T = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3540 | if (T == nullptr) |
| 3541 | return nullptr; |
| 3542 | Names.push_back(T); |
| 3543 | } |
| 3544 | ExceptionSpec = |
| 3545 | make<DynamicExceptionSpec>(popTrailingNodeArray(SpecsBegin)); |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 3546 | if (!ExceptionSpec) |
| 3547 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3548 | } |
| 3549 | |
| 3550 | consumeIf("Dx"); // transaction safe |
| 3551 | |
| 3552 | if (!consumeIf('F')) |
| 3553 | return nullptr; |
| 3554 | consumeIf('Y'); // extern "C" |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3555 | Node *ReturnType = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3556 | if (ReturnType == nullptr) |
| 3557 | return nullptr; |
| 3558 | |
| 3559 | FunctionRefQual ReferenceQualifier = FrefQualNone; |
| 3560 | size_t ParamsBegin = Names.size(); |
| 3561 | while (true) { |
| 3562 | if (consumeIf('E')) |
| 3563 | break; |
| 3564 | if (consumeIf('v')) |
| 3565 | continue; |
| 3566 | if (consumeIf("RE")) { |
| 3567 | ReferenceQualifier = FrefQualLValue; |
| 3568 | break; |
| 3569 | } |
| 3570 | if (consumeIf("OE")) { |
| 3571 | ReferenceQualifier = FrefQualRValue; |
| 3572 | break; |
| 3573 | } |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3574 | Node *T = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3575 | if (T == nullptr) |
| 3576 | return nullptr; |
| 3577 | Names.push_back(T); |
| 3578 | } |
| 3579 | |
| 3580 | NodeArray Params = popTrailingNodeArray(ParamsBegin); |
| 3581 | return make<FunctionType>(ReturnType, Params, CVQuals, |
| 3582 | ReferenceQualifier, ExceptionSpec); |
| 3583 | } |
| 3584 | |
| 3585 | // extension: |
| 3586 | // <vector-type> ::= Dv <positive dimension number> _ <extended element type> |
| 3587 | // ::= Dv [<dimension expression>] _ <element type> |
| 3588 | // <extended element type> ::= <element type> |
| 3589 | // ::= p # AltiVec vector pixel |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3590 | template <typename Derived, typename Alloc> |
| 3591 | Node *AbstractManglingParser<Derived, Alloc>::parseVectorType() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3592 | if (!consumeIf("Dv")) |
| 3593 | return nullptr; |
| 3594 | if (look() >= '1' && look() <= '9') { |
Erik Pilkington | 87529ae | 2019-11-04 10:47:44 -0800 | [diff] [blame] | 3595 | Node *DimensionNumber = make<NameType>(parseNumber()); |
| 3596 | if (!DimensionNumber) |
| 3597 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3598 | if (!consumeIf('_')) |
| 3599 | return nullptr; |
| 3600 | if (consumeIf('p')) |
| 3601 | return make<PixelVectorType>(DimensionNumber); |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3602 | Node *ElemType = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3603 | if (ElemType == nullptr) |
| 3604 | return nullptr; |
| 3605 | return make<VectorType>(ElemType, DimensionNumber); |
| 3606 | } |
| 3607 | |
| 3608 | if (!consumeIf('_')) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3609 | Node *DimExpr = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3610 | if (!DimExpr) |
| 3611 | return nullptr; |
| 3612 | if (!consumeIf('_')) |
| 3613 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3614 | Node *ElemType = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3615 | if (!ElemType) |
| 3616 | return nullptr; |
| 3617 | return make<VectorType>(ElemType, DimExpr); |
| 3618 | } |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3619 | Node *ElemType = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3620 | if (!ElemType) |
| 3621 | return nullptr; |
Erik Pilkington | 87529ae | 2019-11-04 10:47:44 -0800 | [diff] [blame] | 3622 | return make<VectorType>(ElemType, /*Dimension=*/nullptr); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | // <decltype> ::= Dt <expression> E # decltype of an id-expression or class member access (C++0x) |
| 3626 | // ::= DT <expression> E # decltype of an expression (C++0x) |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3627 | template <typename Derived, typename Alloc> |
| 3628 | Node *AbstractManglingParser<Derived, Alloc>::parseDecltype() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3629 | if (!consumeIf('D')) |
| 3630 | return nullptr; |
| 3631 | if (!consumeIf('t') && !consumeIf('T')) |
| 3632 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3633 | Node *E = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3634 | if (E == nullptr) |
| 3635 | return nullptr; |
| 3636 | if (!consumeIf('E')) |
| 3637 | return nullptr; |
| 3638 | return make<EnclosingExpr>("decltype(", E, ")"); |
| 3639 | } |
| 3640 | |
| 3641 | // <array-type> ::= A <positive dimension number> _ <element type> |
| 3642 | // ::= A [<dimension expression>] _ <element type> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3643 | template <typename Derived, typename Alloc> |
| 3644 | Node *AbstractManglingParser<Derived, Alloc>::parseArrayType() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3645 | if (!consumeIf('A')) |
| 3646 | return nullptr; |
| 3647 | |
Erik Pilkington | 87529ae | 2019-11-04 10:47:44 -0800 | [diff] [blame] | 3648 | Node *Dimension = nullptr; |
Pavel Labath | 3605009 | 2018-10-10 08:39:16 +0000 | [diff] [blame] | 3649 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3650 | if (std::isdigit(look())) { |
Erik Pilkington | 87529ae | 2019-11-04 10:47:44 -0800 | [diff] [blame] | 3651 | Dimension = make<NameType>(parseNumber()); |
| 3652 | if (!Dimension) |
| 3653 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3654 | if (!consumeIf('_')) |
| 3655 | return nullptr; |
Pavel Labath | 3605009 | 2018-10-10 08:39:16 +0000 | [diff] [blame] | 3656 | } else if (!consumeIf('_')) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3657 | Node *DimExpr = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3658 | if (DimExpr == nullptr) |
| 3659 | return nullptr; |
| 3660 | if (!consumeIf('_')) |
| 3661 | return nullptr; |
Pavel Labath | 3605009 | 2018-10-10 08:39:16 +0000 | [diff] [blame] | 3662 | Dimension = DimExpr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3663 | } |
| 3664 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3665 | Node *Ty = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3666 | if (Ty == nullptr) |
| 3667 | return nullptr; |
Pavel Labath | 3605009 | 2018-10-10 08:39:16 +0000 | [diff] [blame] | 3668 | return make<ArrayType>(Ty, Dimension); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | // <pointer-to-member-type> ::= M <class type> <member type> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3672 | template <typename Derived, typename Alloc> |
| 3673 | Node *AbstractManglingParser<Derived, Alloc>::parsePointerToMemberType() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3674 | if (!consumeIf('M')) |
| 3675 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3676 | Node *ClassType = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3677 | if (ClassType == nullptr) |
| 3678 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3679 | Node *MemberType = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3680 | if (MemberType == nullptr) |
| 3681 | return nullptr; |
| 3682 | return make<PointerToMemberType>(ClassType, MemberType); |
| 3683 | } |
| 3684 | |
| 3685 | // <class-enum-type> ::= <name> # non-dependent type name, dependent type name, or dependent typename-specifier |
| 3686 | // ::= Ts <name> # dependent elaborated type specifier using 'struct' or 'class' |
| 3687 | // ::= Tu <name> # dependent elaborated type specifier using 'union' |
| 3688 | // ::= Te <name> # dependent elaborated type specifier using 'enum' |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3689 | template <typename Derived, typename Alloc> |
| 3690 | Node *AbstractManglingParser<Derived, Alloc>::parseClassEnumType() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3691 | StringView ElabSpef; |
| 3692 | if (consumeIf("Ts")) |
| 3693 | ElabSpef = "struct"; |
| 3694 | else if (consumeIf("Tu")) |
| 3695 | ElabSpef = "union"; |
| 3696 | else if (consumeIf("Te")) |
| 3697 | ElabSpef = "enum"; |
| 3698 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3699 | Node *Name = getDerived().parseName(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3700 | if (Name == nullptr) |
| 3701 | return nullptr; |
| 3702 | |
| 3703 | if (!ElabSpef.empty()) |
| 3704 | return make<ElaboratedTypeSpefType>(ElabSpef, Name); |
| 3705 | |
| 3706 | return Name; |
| 3707 | } |
| 3708 | |
| 3709 | // <qualified-type> ::= <qualifiers> <type> |
| 3710 | // <qualifiers> ::= <extended-qualifier>* <CV-qualifiers> |
| 3711 | // <extended-qualifier> ::= U <source-name> [<template-args>] # vendor extended type qualifier |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3712 | template <typename Derived, typename Alloc> |
| 3713 | Node *AbstractManglingParser<Derived, Alloc>::parseQualifiedType() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3714 | if (consumeIf('U')) { |
| 3715 | StringView Qual = parseBareSourceName(); |
| 3716 | if (Qual.empty()) |
| 3717 | return nullptr; |
| 3718 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3719 | // extension ::= U <objc-name> <objc-type> # objc-type<identifier> |
| 3720 | if (Qual.startsWith("objcproto")) { |
| 3721 | StringView ProtoSourceName = Qual.dropFront(std::strlen("objcproto")); |
| 3722 | StringView Proto; |
| 3723 | { |
| 3724 | SwapAndRestore<const char *> SaveFirst(First, ProtoSourceName.begin()), |
| 3725 | SaveLast(Last, ProtoSourceName.end()); |
| 3726 | Proto = parseBareSourceName(); |
| 3727 | } |
| 3728 | if (Proto.empty()) |
| 3729 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3730 | Node *Child = getDerived().parseQualifiedType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3731 | if (Child == nullptr) |
| 3732 | return nullptr; |
| 3733 | return make<ObjCProtoName>(Child, Proto); |
| 3734 | } |
| 3735 | |
Alex Orlov | 1540db3 | 2021-03-24 10:21:32 +0400 | [diff] [blame] | 3736 | Node *TA = nullptr; |
| 3737 | if (look() == 'I') { |
| 3738 | TA = getDerived().parseTemplateArgs(); |
| 3739 | if (TA == nullptr) |
| 3740 | return nullptr; |
| 3741 | } |
| 3742 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3743 | Node *Child = getDerived().parseQualifiedType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3744 | if (Child == nullptr) |
| 3745 | return nullptr; |
Alex Orlov | 1540db3 | 2021-03-24 10:21:32 +0400 | [diff] [blame] | 3746 | return make<VendorExtQualType>(Child, Qual, TA); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | Qualifiers Quals = parseCVQualifiers(); |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3750 | Node *Ty = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3751 | if (Ty == nullptr) |
| 3752 | return nullptr; |
| 3753 | if (Quals != QualNone) |
| 3754 | Ty = make<QualType>(Ty, Quals); |
| 3755 | return Ty; |
| 3756 | } |
| 3757 | |
| 3758 | // <type> ::= <builtin-type> |
| 3759 | // ::= <qualified-type> |
| 3760 | // ::= <function-type> |
| 3761 | // ::= <class-enum-type> |
| 3762 | // ::= <array-type> |
| 3763 | // ::= <pointer-to-member-type> |
| 3764 | // ::= <template-param> |
| 3765 | // ::= <template-template-param> <template-args> |
| 3766 | // ::= <decltype> |
| 3767 | // ::= P <type> # pointer |
| 3768 | // ::= R <type> # l-value reference |
| 3769 | // ::= O <type> # r-value reference (C++11) |
| 3770 | // ::= C <type> # complex pair (C99) |
| 3771 | // ::= G <type> # imaginary (C99) |
| 3772 | // ::= <substitution> # See Compression below |
| 3773 | // extension ::= U <objc-name> <objc-type> # objc-type<identifier> |
| 3774 | // extension ::= <vector-type> # <vector-type> starts with Dv |
| 3775 | // |
| 3776 | // <objc-name> ::= <k0 number> objcproto <k1 number> <identifier> # k0 = 9 + <number of digits in k1> + k1 |
| 3777 | // <objc-type> ::= <source-name> # PU<11+>objcproto 11objc_object<source-name> 11objc_object -> id<source-name> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3778 | template <typename Derived, typename Alloc> |
| 3779 | Node *AbstractManglingParser<Derived, Alloc>::parseType() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3780 | Node *Result = nullptr; |
| 3781 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3782 | switch (look()) { |
| 3783 | // ::= <qualified-type> |
| 3784 | case 'r': |
| 3785 | case 'V': |
| 3786 | case 'K': { |
| 3787 | unsigned AfterQuals = 0; |
| 3788 | if (look(AfterQuals) == 'r') ++AfterQuals; |
| 3789 | if (look(AfterQuals) == 'V') ++AfterQuals; |
| 3790 | if (look(AfterQuals) == 'K') ++AfterQuals; |
| 3791 | |
| 3792 | if (look(AfterQuals) == 'F' || |
| 3793 | (look(AfterQuals) == 'D' && |
| 3794 | (look(AfterQuals + 1) == 'o' || look(AfterQuals + 1) == 'O' || |
| 3795 | look(AfterQuals + 1) == 'w' || look(AfterQuals + 1) == 'x'))) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3796 | Result = getDerived().parseFunctionType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3797 | break; |
| 3798 | } |
Erik Pilkington | 870950f | 2019-01-17 20:37:51 +0000 | [diff] [blame] | 3799 | DEMANGLE_FALLTHROUGH; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3800 | } |
| 3801 | case 'U': { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3802 | Result = getDerived().parseQualifiedType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3803 | break; |
| 3804 | } |
| 3805 | // <builtin-type> ::= v # void |
| 3806 | case 'v': |
| 3807 | ++First; |
| 3808 | return make<NameType>("void"); |
| 3809 | // ::= w # wchar_t |
| 3810 | case 'w': |
| 3811 | ++First; |
| 3812 | return make<NameType>("wchar_t"); |
| 3813 | // ::= b # bool |
| 3814 | case 'b': |
| 3815 | ++First; |
| 3816 | return make<NameType>("bool"); |
| 3817 | // ::= c # char |
| 3818 | case 'c': |
| 3819 | ++First; |
| 3820 | return make<NameType>("char"); |
| 3821 | // ::= a # signed char |
| 3822 | case 'a': |
| 3823 | ++First; |
| 3824 | return make<NameType>("signed char"); |
| 3825 | // ::= h # unsigned char |
| 3826 | case 'h': |
| 3827 | ++First; |
| 3828 | return make<NameType>("unsigned char"); |
| 3829 | // ::= s # short |
| 3830 | case 's': |
| 3831 | ++First; |
| 3832 | return make<NameType>("short"); |
| 3833 | // ::= t # unsigned short |
| 3834 | case 't': |
| 3835 | ++First; |
| 3836 | return make<NameType>("unsigned short"); |
| 3837 | // ::= i # int |
| 3838 | case 'i': |
| 3839 | ++First; |
| 3840 | return make<NameType>("int"); |
| 3841 | // ::= j # unsigned int |
| 3842 | case 'j': |
| 3843 | ++First; |
| 3844 | return make<NameType>("unsigned int"); |
| 3845 | // ::= l # long |
| 3846 | case 'l': |
| 3847 | ++First; |
| 3848 | return make<NameType>("long"); |
| 3849 | // ::= m # unsigned long |
| 3850 | case 'm': |
| 3851 | ++First; |
| 3852 | return make<NameType>("unsigned long"); |
| 3853 | // ::= x # long long, __int64 |
| 3854 | case 'x': |
| 3855 | ++First; |
| 3856 | return make<NameType>("long long"); |
| 3857 | // ::= y # unsigned long long, __int64 |
| 3858 | case 'y': |
| 3859 | ++First; |
| 3860 | return make<NameType>("unsigned long long"); |
| 3861 | // ::= n # __int128 |
| 3862 | case 'n': |
| 3863 | ++First; |
| 3864 | return make<NameType>("__int128"); |
| 3865 | // ::= o # unsigned __int128 |
| 3866 | case 'o': |
| 3867 | ++First; |
| 3868 | return make<NameType>("unsigned __int128"); |
| 3869 | // ::= f # float |
| 3870 | case 'f': |
| 3871 | ++First; |
| 3872 | return make<NameType>("float"); |
| 3873 | // ::= d # double |
| 3874 | case 'd': |
| 3875 | ++First; |
| 3876 | return make<NameType>("double"); |
| 3877 | // ::= e # long double, __float80 |
| 3878 | case 'e': |
| 3879 | ++First; |
| 3880 | return make<NameType>("long double"); |
| 3881 | // ::= g # __float128 |
| 3882 | case 'g': |
| 3883 | ++First; |
| 3884 | return make<NameType>("__float128"); |
| 3885 | // ::= z # ellipsis |
| 3886 | case 'z': |
| 3887 | ++First; |
| 3888 | return make<NameType>("..."); |
| 3889 | |
| 3890 | // <builtin-type> ::= u <source-name> # vendor extended type |
| 3891 | case 'u': { |
| 3892 | ++First; |
| 3893 | StringView Res = parseBareSourceName(); |
| 3894 | if (Res.empty()) |
| 3895 | return nullptr; |
Erik Pilkington | a11a622 | 2019-06-10 21:02:39 +0000 | [diff] [blame] | 3896 | // Typically, <builtin-type>s are not considered substitution candidates, |
| 3897 | // but the exception to that exception is vendor extended types (Itanium C++ |
| 3898 | // ABI 5.9.1). |
| 3899 | Result = make<NameType>(Res); |
| 3900 | break; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3901 | } |
| 3902 | case 'D': |
| 3903 | switch (look(1)) { |
| 3904 | // ::= Dd # IEEE 754r decimal floating point (64 bits) |
| 3905 | case 'd': |
| 3906 | First += 2; |
| 3907 | return make<NameType>("decimal64"); |
| 3908 | // ::= De # IEEE 754r decimal floating point (128 bits) |
| 3909 | case 'e': |
| 3910 | First += 2; |
| 3911 | return make<NameType>("decimal128"); |
| 3912 | // ::= Df # IEEE 754r decimal floating point (32 bits) |
| 3913 | case 'f': |
| 3914 | First += 2; |
| 3915 | return make<NameType>("decimal32"); |
| 3916 | // ::= Dh # IEEE 754r half-precision floating point (16 bits) |
| 3917 | case 'h': |
| 3918 | First += 2; |
Stuart Brady | 19025d1 | 2021-06-07 16:30:22 +0100 | [diff] [blame] | 3919 | return make<NameType>("half"); |
Pengfei Wang | 036d315 | 2021-09-23 11:02:25 +0800 | [diff] [blame] | 3920 | // ::= DF <number> _ # ISO/IEC TS 18661 binary floating point (N bits) |
| 3921 | case 'F': { |
| 3922 | First += 2; |
| 3923 | Node *DimensionNumber = make<NameType>(parseNumber()); |
| 3924 | if (!DimensionNumber) |
| 3925 | return nullptr; |
| 3926 | if (!consumeIf('_')) |
| 3927 | return nullptr; |
| 3928 | return make<BinaryFPType>(DimensionNumber); |
| 3929 | } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3930 | // ::= Di # char32_t |
| 3931 | case 'i': |
| 3932 | First += 2; |
| 3933 | return make<NameType>("char32_t"); |
| 3934 | // ::= Ds # char16_t |
| 3935 | case 's': |
| 3936 | First += 2; |
| 3937 | return make<NameType>("char16_t"); |
Erik Pilkington | cabc7f0 | 2019-06-28 19:54:19 +0000 | [diff] [blame] | 3938 | // ::= Du # char8_t (C++2a, not yet in the Itanium spec) |
| 3939 | case 'u': |
| 3940 | First += 2; |
| 3941 | return make<NameType>("char8_t"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3942 | // ::= Da # auto (in dependent new-expressions) |
| 3943 | case 'a': |
| 3944 | First += 2; |
| 3945 | return make<NameType>("auto"); |
| 3946 | // ::= Dc # decltype(auto) |
| 3947 | case 'c': |
| 3948 | First += 2; |
| 3949 | return make<NameType>("decltype(auto)"); |
| 3950 | // ::= Dn # std::nullptr_t (i.e., decltype(nullptr)) |
| 3951 | case 'n': |
| 3952 | First += 2; |
| 3953 | return make<NameType>("std::nullptr_t"); |
| 3954 | |
| 3955 | // ::= <decltype> |
| 3956 | case 't': |
| 3957 | case 'T': { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3958 | Result = getDerived().parseDecltype(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3959 | break; |
| 3960 | } |
| 3961 | // extension ::= <vector-type> # <vector-type> starts with Dv |
| 3962 | case 'v': { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3963 | Result = getDerived().parseVectorType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3964 | break; |
| 3965 | } |
| 3966 | // ::= Dp <type> # pack expansion (C++0x) |
| 3967 | case 'p': { |
| 3968 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3969 | Node *Child = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3970 | if (!Child) |
| 3971 | return nullptr; |
| 3972 | Result = make<ParameterPackExpansion>(Child); |
| 3973 | break; |
| 3974 | } |
| 3975 | // Exception specifier on a function type. |
| 3976 | case 'o': |
| 3977 | case 'O': |
| 3978 | case 'w': |
| 3979 | // Transaction safe function type. |
| 3980 | case 'x': |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3981 | Result = getDerived().parseFunctionType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3982 | break; |
| 3983 | } |
| 3984 | break; |
| 3985 | // ::= <function-type> |
| 3986 | case 'F': { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3987 | Result = getDerived().parseFunctionType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3988 | break; |
| 3989 | } |
| 3990 | // ::= <array-type> |
| 3991 | case 'A': { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3992 | Result = getDerived().parseArrayType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3993 | break; |
| 3994 | } |
| 3995 | // ::= <pointer-to-member-type> |
| 3996 | case 'M': { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 3997 | Result = getDerived().parsePointerToMemberType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 3998 | break; |
| 3999 | } |
| 4000 | // ::= <template-param> |
| 4001 | case 'T': { |
| 4002 | // This could be an elaborate type specifier on a <class-enum-type>. |
| 4003 | if (look(1) == 's' || look(1) == 'u' || look(1) == 'e') { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4004 | Result = getDerived().parseClassEnumType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4005 | break; |
| 4006 | } |
| 4007 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4008 | Result = getDerived().parseTemplateParam(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4009 | if (Result == nullptr) |
| 4010 | return nullptr; |
| 4011 | |
| 4012 | // Result could be either of: |
| 4013 | // <type> ::= <template-param> |
| 4014 | // <type> ::= <template-template-param> <template-args> |
| 4015 | // |
| 4016 | // <template-template-param> ::= <template-param> |
| 4017 | // ::= <substitution> |
| 4018 | // |
| 4019 | // If this is followed by some <template-args>, and we're permitted to |
| 4020 | // parse them, take the second production. |
| 4021 | |
| 4022 | if (TryToParseTemplateArgs && look() == 'I') { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4023 | Node *TA = getDerived().parseTemplateArgs(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4024 | if (TA == nullptr) |
| 4025 | return nullptr; |
| 4026 | Result = make<NameWithTemplateArgs>(Result, TA); |
| 4027 | } |
| 4028 | break; |
| 4029 | } |
| 4030 | // ::= P <type> # pointer |
| 4031 | case 'P': { |
| 4032 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4033 | Node *Ptr = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4034 | if (Ptr == nullptr) |
| 4035 | return nullptr; |
| 4036 | Result = make<PointerType>(Ptr); |
| 4037 | break; |
| 4038 | } |
| 4039 | // ::= R <type> # l-value reference |
| 4040 | case 'R': { |
| 4041 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4042 | Node *Ref = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4043 | if (Ref == nullptr) |
| 4044 | return nullptr; |
| 4045 | Result = make<ReferenceType>(Ref, ReferenceKind::LValue); |
| 4046 | break; |
| 4047 | } |
| 4048 | // ::= O <type> # r-value reference (C++11) |
| 4049 | case 'O': { |
| 4050 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4051 | Node *Ref = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4052 | if (Ref == nullptr) |
| 4053 | return nullptr; |
| 4054 | Result = make<ReferenceType>(Ref, ReferenceKind::RValue); |
| 4055 | break; |
| 4056 | } |
| 4057 | // ::= C <type> # complex pair (C99) |
| 4058 | case 'C': { |
| 4059 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4060 | Node *P = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4061 | if (P == nullptr) |
| 4062 | return nullptr; |
| 4063 | Result = make<PostfixQualifiedType>(P, " complex"); |
| 4064 | break; |
| 4065 | } |
| 4066 | // ::= G <type> # imaginary (C99) |
| 4067 | case 'G': { |
| 4068 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4069 | Node *P = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4070 | if (P == nullptr) |
| 4071 | return P; |
| 4072 | Result = make<PostfixQualifiedType>(P, " imaginary"); |
| 4073 | break; |
| 4074 | } |
| 4075 | // ::= <substitution> # See Compression below |
| 4076 | case 'S': { |
Nathan Sidwell | bbc2443 | 2022-01-24 04:28:09 -0800 | [diff] [blame] | 4077 | if (look(1) != 't') { |
| 4078 | Result = getDerived().parseSubstitution(); |
| 4079 | if (Result == nullptr) |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4080 | return nullptr; |
| 4081 | |
| 4082 | // Sub could be either of: |
| 4083 | // <type> ::= <substitution> |
| 4084 | // <type> ::= <template-template-param> <template-args> |
| 4085 | // |
| 4086 | // <template-template-param> ::= <template-param> |
| 4087 | // ::= <substitution> |
| 4088 | // |
| 4089 | // If this is followed by some <template-args>, and we're permitted to |
| 4090 | // parse them, take the second production. |
| 4091 | |
| 4092 | if (TryToParseTemplateArgs && look() == 'I') { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4093 | Node *TA = getDerived().parseTemplateArgs(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4094 | if (TA == nullptr) |
| 4095 | return nullptr; |
Nathan Sidwell | bbc2443 | 2022-01-24 04:28:09 -0800 | [diff] [blame] | 4096 | Result = make<NameWithTemplateArgs>(Result, TA); |
| 4097 | } else { |
| 4098 | // If all we parsed was a substitution, don't re-insert into the |
| 4099 | // substitution table. |
| 4100 | return Result; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4101 | } |
Nathan Sidwell | bbc2443 | 2022-01-24 04:28:09 -0800 | [diff] [blame] | 4102 | break; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4103 | } |
Erik Pilkington | 870950f | 2019-01-17 20:37:51 +0000 | [diff] [blame] | 4104 | DEMANGLE_FALLTHROUGH; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4105 | } |
| 4106 | // ::= <class-enum-type> |
| 4107 | default: { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4108 | Result = getDerived().parseClassEnumType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4109 | break; |
| 4110 | } |
| 4111 | } |
| 4112 | |
| 4113 | // If we parsed a type, insert it into the substitution table. Note that all |
| 4114 | // <builtin-type>s and <substitution>s have already bailed out, because they |
| 4115 | // don't get substitutions. |
| 4116 | if (Result != nullptr) |
| 4117 | Subs.push_back(Result); |
| 4118 | return Result; |
| 4119 | } |
| 4120 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4121 | template <typename Derived, typename Alloc> |
| 4122 | Node *AbstractManglingParser<Derived, Alloc>::parsePrefixExpr(StringView Kind) { |
| 4123 | Node *E = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4124 | if (E == nullptr) |
| 4125 | return nullptr; |
| 4126 | return make<PrefixExpr>(Kind, E); |
| 4127 | } |
| 4128 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4129 | template <typename Derived, typename Alloc> |
| 4130 | Node *AbstractManglingParser<Derived, Alloc>::parseBinaryExpr(StringView Kind) { |
| 4131 | Node *LHS = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4132 | if (LHS == nullptr) |
| 4133 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4134 | Node *RHS = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4135 | if (RHS == nullptr) |
| 4136 | return nullptr; |
| 4137 | return make<BinaryExpr>(LHS, Kind, RHS); |
| 4138 | } |
| 4139 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4140 | template <typename Derived, typename Alloc> |
| 4141 | Node * |
| 4142 | AbstractManglingParser<Derived, Alloc>::parseIntegerLiteral(StringView Lit) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4143 | StringView Tmp = parseNumber(true); |
| 4144 | if (!Tmp.empty() && consumeIf('E')) |
| 4145 | return make<IntegerLiteral>(Lit, Tmp); |
| 4146 | return nullptr; |
| 4147 | } |
| 4148 | |
| 4149 | // <CV-Qualifiers> ::= [r] [V] [K] |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4150 | template <typename Alloc, typename Derived> |
| 4151 | Qualifiers AbstractManglingParser<Alloc, Derived>::parseCVQualifiers() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4152 | Qualifiers CVR = QualNone; |
| 4153 | if (consumeIf('r')) |
| 4154 | CVR |= QualRestrict; |
| 4155 | if (consumeIf('V')) |
| 4156 | CVR |= QualVolatile; |
| 4157 | if (consumeIf('K')) |
| 4158 | CVR |= QualConst; |
| 4159 | return CVR; |
| 4160 | } |
| 4161 | |
| 4162 | // <function-param> ::= fp <top-level CV-Qualifiers> _ # L == 0, first parameter |
| 4163 | // ::= fp <top-level CV-Qualifiers> <parameter-2 non-negative number> _ # L == 0, second and later parameters |
| 4164 | // ::= fL <L-1 non-negative number> p <top-level CV-Qualifiers> _ # L > 0, first parameter |
| 4165 | // ::= fL <L-1 non-negative number> p <top-level CV-Qualifiers> <parameter-2 non-negative number> _ # L > 0, second and later parameters |
Erik Pilkington | dc9d5ff | 2020-05-13 22:19:45 -0400 | [diff] [blame] | 4166 | // ::= fpT # 'this' expression (not part of standard?) |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4167 | template <typename Derived, typename Alloc> |
| 4168 | Node *AbstractManglingParser<Derived, Alloc>::parseFunctionParam() { |
Erik Pilkington | dc9d5ff | 2020-05-13 22:19:45 -0400 | [diff] [blame] | 4169 | if (consumeIf("fpT")) |
| 4170 | return make<NameType>("this"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4171 | if (consumeIf("fp")) { |
| 4172 | parseCVQualifiers(); |
| 4173 | StringView Num = parseNumber(); |
| 4174 | if (!consumeIf('_')) |
| 4175 | return nullptr; |
| 4176 | return make<FunctionParam>(Num); |
| 4177 | } |
| 4178 | if (consumeIf("fL")) { |
| 4179 | if (parseNumber().empty()) |
| 4180 | return nullptr; |
| 4181 | if (!consumeIf('p')) |
| 4182 | return nullptr; |
| 4183 | parseCVQualifiers(); |
| 4184 | StringView Num = parseNumber(); |
| 4185 | if (!consumeIf('_')) |
| 4186 | return nullptr; |
| 4187 | return make<FunctionParam>(Num); |
| 4188 | } |
| 4189 | return nullptr; |
| 4190 | } |
| 4191 | |
| 4192 | // [gs] nw <expression>* _ <type> E # new (expr-list) type |
| 4193 | // [gs] nw <expression>* _ <type> <initializer> # new (expr-list) type (init) |
| 4194 | // [gs] na <expression>* _ <type> E # new[] (expr-list) type |
| 4195 | // [gs] na <expression>* _ <type> <initializer> # new[] (expr-list) type (init) |
| 4196 | // <initializer> ::= pi <expression>* E # parenthesized initialization |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4197 | template <typename Derived, typename Alloc> |
| 4198 | Node *AbstractManglingParser<Derived, Alloc>::parseNewExpr() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4199 | bool Global = consumeIf("gs"); |
| 4200 | bool IsArray = look(1) == 'a'; |
| 4201 | if (!consumeIf("nw") && !consumeIf("na")) |
| 4202 | return nullptr; |
| 4203 | size_t Exprs = Names.size(); |
| 4204 | while (!consumeIf('_')) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4205 | Node *Ex = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4206 | if (Ex == nullptr) |
| 4207 | return nullptr; |
| 4208 | Names.push_back(Ex); |
| 4209 | } |
| 4210 | NodeArray ExprList = popTrailingNodeArray(Exprs); |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4211 | Node *Ty = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4212 | if (Ty == nullptr) |
| 4213 | return Ty; |
| 4214 | if (consumeIf("pi")) { |
| 4215 | size_t InitsBegin = Names.size(); |
| 4216 | while (!consumeIf('E')) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4217 | Node *Init = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4218 | if (Init == nullptr) |
| 4219 | return Init; |
| 4220 | Names.push_back(Init); |
| 4221 | } |
| 4222 | NodeArray Inits = popTrailingNodeArray(InitsBegin); |
| 4223 | return make<NewExpr>(ExprList, Ty, Inits, Global, IsArray); |
| 4224 | } else if (!consumeIf('E')) |
| 4225 | return nullptr; |
| 4226 | return make<NewExpr>(ExprList, Ty, NodeArray(), Global, IsArray); |
| 4227 | } |
| 4228 | |
| 4229 | // cv <type> <expression> # conversion with one argument |
| 4230 | // cv <type> _ <expression>* E # conversion with a different number of arguments |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4231 | template <typename Derived, typename Alloc> |
| 4232 | Node *AbstractManglingParser<Derived, Alloc>::parseConversionExpr() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4233 | if (!consumeIf("cv")) |
| 4234 | return nullptr; |
| 4235 | Node *Ty; |
| 4236 | { |
| 4237 | SwapAndRestore<bool> SaveTemp(TryToParseTemplateArgs, false); |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4238 | Ty = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4239 | } |
| 4240 | |
| 4241 | if (Ty == nullptr) |
| 4242 | return nullptr; |
| 4243 | |
| 4244 | if (consumeIf('_')) { |
| 4245 | size_t ExprsBegin = Names.size(); |
| 4246 | while (!consumeIf('E')) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4247 | Node *E = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4248 | if (E == nullptr) |
| 4249 | return E; |
| 4250 | Names.push_back(E); |
| 4251 | } |
| 4252 | NodeArray Exprs = popTrailingNodeArray(ExprsBegin); |
| 4253 | return make<ConversionExpr>(Ty, Exprs); |
| 4254 | } |
| 4255 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4256 | Node *E[1] = {getDerived().parseExpr()}; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4257 | if (E[0] == nullptr) |
| 4258 | return nullptr; |
| 4259 | return make<ConversionExpr>(Ty, makeNodeArray(E, E + 1)); |
| 4260 | } |
| 4261 | |
| 4262 | // <expr-primary> ::= L <type> <value number> E # integer literal |
| 4263 | // ::= L <type> <value float> E # floating literal |
| 4264 | // ::= L <string type> E # string literal |
| 4265 | // ::= L <nullptr type> E # nullptr literal (i.e., "LDnE") |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 4266 | // ::= L <lambda type> E # lambda expression |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4267 | // FIXME: ::= L <type> <real-part float> _ <imag-part float> E # complex floating point literal (C 2000) |
| 4268 | // ::= L <mangled-name> E # external name |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4269 | template <typename Derived, typename Alloc> |
| 4270 | Node *AbstractManglingParser<Derived, Alloc>::parseExprPrimary() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4271 | if (!consumeIf('L')) |
| 4272 | return nullptr; |
| 4273 | switch (look()) { |
| 4274 | case 'w': |
| 4275 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4276 | return getDerived().parseIntegerLiteral("wchar_t"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4277 | case 'b': |
| 4278 | if (consumeIf("b0E")) |
| 4279 | return make<BoolExpr>(0); |
| 4280 | if (consumeIf("b1E")) |
| 4281 | return make<BoolExpr>(1); |
| 4282 | return nullptr; |
| 4283 | case 'c': |
| 4284 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4285 | return getDerived().parseIntegerLiteral("char"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4286 | case 'a': |
| 4287 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4288 | return getDerived().parseIntegerLiteral("signed char"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4289 | case 'h': |
| 4290 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4291 | return getDerived().parseIntegerLiteral("unsigned char"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4292 | case 's': |
| 4293 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4294 | return getDerived().parseIntegerLiteral("short"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4295 | case 't': |
| 4296 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4297 | return getDerived().parseIntegerLiteral("unsigned short"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4298 | case 'i': |
| 4299 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4300 | return getDerived().parseIntegerLiteral(""); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4301 | case 'j': |
| 4302 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4303 | return getDerived().parseIntegerLiteral("u"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4304 | case 'l': |
| 4305 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4306 | return getDerived().parseIntegerLiteral("l"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4307 | case 'm': |
| 4308 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4309 | return getDerived().parseIntegerLiteral("ul"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4310 | case 'x': |
| 4311 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4312 | return getDerived().parseIntegerLiteral("ll"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4313 | case 'y': |
| 4314 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4315 | return getDerived().parseIntegerLiteral("ull"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4316 | case 'n': |
| 4317 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4318 | return getDerived().parseIntegerLiteral("__int128"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4319 | case 'o': |
| 4320 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4321 | return getDerived().parseIntegerLiteral("unsigned __int128"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4322 | case 'f': |
| 4323 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4324 | return getDerived().template parseFloatingLiteral<float>(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4325 | case 'd': |
| 4326 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4327 | return getDerived().template parseFloatingLiteral<double>(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4328 | case 'e': |
| 4329 | ++First; |
Xing Xue | be1ae5a | 2020-04-15 09:59:06 -0400 | [diff] [blame] | 4330 | #if defined(__powerpc__) || defined(__s390__) |
| 4331 | // Handle cases where long doubles encoded with e have the same size |
| 4332 | // and representation as doubles. |
| 4333 | return getDerived().template parseFloatingLiteral<double>(); |
| 4334 | #else |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4335 | return getDerived().template parseFloatingLiteral<long double>(); |
Xing Xue | be1ae5a | 2020-04-15 09:59:06 -0400 | [diff] [blame] | 4336 | #endif |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4337 | case '_': |
| 4338 | if (consumeIf("_Z")) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4339 | Node *R = getDerived().parseEncoding(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4340 | if (R != nullptr && consumeIf('E')) |
| 4341 | return R; |
| 4342 | } |
| 4343 | return nullptr; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 4344 | case 'A': { |
| 4345 | Node *T = getDerived().parseType(); |
| 4346 | if (T == nullptr) |
| 4347 | return nullptr; |
| 4348 | // FIXME: We need to include the string contents in the mangling. |
| 4349 | if (consumeIf('E')) |
| 4350 | return make<StringLiteral>(T); |
| 4351 | return nullptr; |
| 4352 | } |
| 4353 | case 'D': |
| 4354 | if (consumeIf("DnE")) |
| 4355 | return make<NameType>("nullptr"); |
| 4356 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4357 | case 'T': |
| 4358 | // Invalid mangled name per |
| 4359 | // http://sourcerytools.com/pipermail/cxx-abi-dev/2011-August/002422.html |
| 4360 | return nullptr; |
Richard Smith | 069f19d | 2019-09-09 22:26:04 +0000 | [diff] [blame] | 4361 | case 'U': { |
| 4362 | // FIXME: Should we support LUb... for block literals? |
| 4363 | if (look(1) != 'l') |
| 4364 | return nullptr; |
| 4365 | Node *T = parseUnnamedTypeName(nullptr); |
| 4366 | if (!T || !consumeIf('E')) |
| 4367 | return nullptr; |
| 4368 | return make<LambdaExpr>(T); |
| 4369 | } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4370 | default: { |
| 4371 | // might be named type |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4372 | Node *T = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4373 | if (T == nullptr) |
| 4374 | return nullptr; |
Erik Pilkington | 27011a8 | 2020-05-13 14:13:37 -0400 | [diff] [blame] | 4375 | StringView N = parseNumber(/*AllowNegative=*/true); |
Richard Smith | 069f19d | 2019-09-09 22:26:04 +0000 | [diff] [blame] | 4376 | if (N.empty()) |
| 4377 | return nullptr; |
| 4378 | if (!consumeIf('E')) |
| 4379 | return nullptr; |
Erik Pilkington | 27011a8 | 2020-05-13 14:13:37 -0400 | [diff] [blame] | 4380 | return make<EnumLiteral>(T, N); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4381 | } |
| 4382 | } |
| 4383 | } |
| 4384 | |
| 4385 | // <braced-expression> ::= <expression> |
| 4386 | // ::= di <field source-name> <braced-expression> # .name = expr |
| 4387 | // ::= dx <index expression> <braced-expression> # [expr] = expr |
| 4388 | // ::= dX <range begin expression> <range end expression> <braced-expression> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4389 | template <typename Derived, typename Alloc> |
| 4390 | Node *AbstractManglingParser<Derived, Alloc>::parseBracedExpr() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4391 | if (look() == 'd') { |
| 4392 | switch (look(1)) { |
| 4393 | case 'i': { |
| 4394 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4395 | Node *Field = getDerived().parseSourceName(/*NameState=*/nullptr); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4396 | if (Field == nullptr) |
| 4397 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4398 | Node *Init = getDerived().parseBracedExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4399 | if (Init == nullptr) |
| 4400 | return nullptr; |
| 4401 | return make<BracedExpr>(Field, Init, /*isArray=*/false); |
| 4402 | } |
| 4403 | case 'x': { |
| 4404 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4405 | Node *Index = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4406 | if (Index == nullptr) |
| 4407 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4408 | Node *Init = getDerived().parseBracedExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4409 | if (Init == nullptr) |
| 4410 | return nullptr; |
| 4411 | return make<BracedExpr>(Index, Init, /*isArray=*/true); |
| 4412 | } |
| 4413 | case 'X': { |
| 4414 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4415 | Node *RangeBegin = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4416 | if (RangeBegin == nullptr) |
| 4417 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4418 | Node *RangeEnd = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4419 | if (RangeEnd == nullptr) |
| 4420 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4421 | Node *Init = getDerived().parseBracedExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4422 | if (Init == nullptr) |
| 4423 | return nullptr; |
| 4424 | return make<BracedRangeExpr>(RangeBegin, RangeEnd, Init); |
| 4425 | } |
| 4426 | } |
| 4427 | } |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4428 | return getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4429 | } |
| 4430 | |
| 4431 | // (not yet in the spec) |
| 4432 | // <fold-expr> ::= fL <binary-operator-name> <expression> <expression> |
| 4433 | // ::= fR <binary-operator-name> <expression> <expression> |
| 4434 | // ::= fl <binary-operator-name> <expression> |
| 4435 | // ::= fr <binary-operator-name> <expression> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4436 | template <typename Derived, typename Alloc> |
| 4437 | Node *AbstractManglingParser<Derived, Alloc>::parseFoldExpr() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4438 | if (!consumeIf('f')) |
| 4439 | return nullptr; |
| 4440 | |
| 4441 | char FoldKind = look(); |
| 4442 | bool IsLeftFold, HasInitializer; |
| 4443 | HasInitializer = FoldKind == 'L' || FoldKind == 'R'; |
| 4444 | if (FoldKind == 'l' || FoldKind == 'L') |
| 4445 | IsLeftFold = true; |
| 4446 | else if (FoldKind == 'r' || FoldKind == 'R') |
| 4447 | IsLeftFold = false; |
| 4448 | else |
| 4449 | return nullptr; |
| 4450 | ++First; |
| 4451 | |
| 4452 | // FIXME: This map is duplicated in parseOperatorName and parseExpr. |
| 4453 | StringView OperatorName; |
| 4454 | if (consumeIf("aa")) OperatorName = "&&"; |
| 4455 | else if (consumeIf("an")) OperatorName = "&"; |
| 4456 | else if (consumeIf("aN")) OperatorName = "&="; |
| 4457 | else if (consumeIf("aS")) OperatorName = "="; |
| 4458 | else if (consumeIf("cm")) OperatorName = ","; |
| 4459 | else if (consumeIf("ds")) OperatorName = ".*"; |
| 4460 | else if (consumeIf("dv")) OperatorName = "/"; |
| 4461 | else if (consumeIf("dV")) OperatorName = "/="; |
| 4462 | else if (consumeIf("eo")) OperatorName = "^"; |
| 4463 | else if (consumeIf("eO")) OperatorName = "^="; |
| 4464 | else if (consumeIf("eq")) OperatorName = "=="; |
| 4465 | else if (consumeIf("ge")) OperatorName = ">="; |
| 4466 | else if (consumeIf("gt")) OperatorName = ">"; |
| 4467 | else if (consumeIf("le")) OperatorName = "<="; |
| 4468 | else if (consumeIf("ls")) OperatorName = "<<"; |
| 4469 | else if (consumeIf("lS")) OperatorName = "<<="; |
| 4470 | else if (consumeIf("lt")) OperatorName = "<"; |
| 4471 | else if (consumeIf("mi")) OperatorName = "-"; |
| 4472 | else if (consumeIf("mI")) OperatorName = "-="; |
| 4473 | else if (consumeIf("ml")) OperatorName = "*"; |
| 4474 | else if (consumeIf("mL")) OperatorName = "*="; |
| 4475 | else if (consumeIf("ne")) OperatorName = "!="; |
| 4476 | else if (consumeIf("oo")) OperatorName = "||"; |
| 4477 | else if (consumeIf("or")) OperatorName = "|"; |
| 4478 | else if (consumeIf("oR")) OperatorName = "|="; |
| 4479 | else if (consumeIf("pl")) OperatorName = "+"; |
| 4480 | else if (consumeIf("pL")) OperatorName = "+="; |
| 4481 | else if (consumeIf("rm")) OperatorName = "%"; |
| 4482 | else if (consumeIf("rM")) OperatorName = "%="; |
| 4483 | else if (consumeIf("rs")) OperatorName = ">>"; |
| 4484 | else if (consumeIf("rS")) OperatorName = ">>="; |
| 4485 | else return nullptr; |
| 4486 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4487 | Node *Pack = getDerived().parseExpr(), *Init = nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4488 | if (Pack == nullptr) |
| 4489 | return nullptr; |
| 4490 | if (HasInitializer) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4491 | Init = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4492 | if (Init == nullptr) |
| 4493 | return nullptr; |
| 4494 | } |
| 4495 | |
| 4496 | if (IsLeftFold && Init) |
| 4497 | std::swap(Pack, Init); |
| 4498 | |
| 4499 | return make<FoldExpr>(IsLeftFold, OperatorName, Pack, Init); |
| 4500 | } |
| 4501 | |
Richard Smith | 2b38a69 | 2020-10-22 19:29:36 -0700 | [diff] [blame] | 4502 | // <expression> ::= mc <parameter type> <expr> [<offset number>] E |
| 4503 | // |
| 4504 | // Not yet in the spec: https://github.com/itanium-cxx-abi/cxx-abi/issues/47 |
| 4505 | template <typename Derived, typename Alloc> |
| 4506 | Node *AbstractManglingParser<Derived, Alloc>::parsePointerToMemberConversionExpr() { |
| 4507 | Node *Ty = getDerived().parseType(); |
| 4508 | if (!Ty) |
| 4509 | return nullptr; |
| 4510 | Node *Expr = getDerived().parseExpr(); |
| 4511 | if (!Expr) |
| 4512 | return nullptr; |
| 4513 | StringView Offset = getDerived().parseNumber(true); |
| 4514 | if (!consumeIf('E')) |
| 4515 | return nullptr; |
| 4516 | return make<PointerToMemberConversionExpr>(Ty, Expr, Offset); |
| 4517 | } |
| 4518 | |
| 4519 | // <expression> ::= so <referent type> <expr> [<offset number>] <union-selector>* [p] E |
| 4520 | // <union-selector> ::= _ [<number>] |
| 4521 | // |
| 4522 | // Not yet in the spec: https://github.com/itanium-cxx-abi/cxx-abi/issues/47 |
| 4523 | template <typename Derived, typename Alloc> |
| 4524 | Node *AbstractManglingParser<Derived, Alloc>::parseSubobjectExpr() { |
| 4525 | Node *Ty = getDerived().parseType(); |
| 4526 | if (!Ty) |
| 4527 | return nullptr; |
| 4528 | Node *Expr = getDerived().parseExpr(); |
| 4529 | if (!Expr) |
| 4530 | return nullptr; |
| 4531 | StringView Offset = getDerived().parseNumber(true); |
| 4532 | size_t SelectorsBegin = Names.size(); |
| 4533 | while (consumeIf('_')) { |
| 4534 | Node *Selector = make<NameType>(parseNumber()); |
| 4535 | if (!Selector) |
| 4536 | return nullptr; |
| 4537 | Names.push_back(Selector); |
| 4538 | } |
| 4539 | bool OnePastTheEnd = consumeIf('p'); |
| 4540 | if (!consumeIf('E')) |
| 4541 | return nullptr; |
| 4542 | return make<SubobjectExpr>( |
| 4543 | Ty, Expr, Offset, popTrailingNodeArray(SelectorsBegin), OnePastTheEnd); |
| 4544 | } |
| 4545 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4546 | // <expression> ::= <unary operator-name> <expression> |
| 4547 | // ::= <binary operator-name> <expression> <expression> |
| 4548 | // ::= <ternary operator-name> <expression> <expression> <expression> |
| 4549 | // ::= cl <expression>+ E # call |
| 4550 | // ::= cv <type> <expression> # conversion with one argument |
| 4551 | // ::= cv <type> _ <expression>* E # conversion with a different number of arguments |
| 4552 | // ::= [gs] nw <expression>* _ <type> E # new (expr-list) type |
| 4553 | // ::= [gs] nw <expression>* _ <type> <initializer> # new (expr-list) type (init) |
| 4554 | // ::= [gs] na <expression>* _ <type> E # new[] (expr-list) type |
| 4555 | // ::= [gs] na <expression>* _ <type> <initializer> # new[] (expr-list) type (init) |
| 4556 | // ::= [gs] dl <expression> # delete expression |
| 4557 | // ::= [gs] da <expression> # delete[] expression |
| 4558 | // ::= pp_ <expression> # prefix ++ |
| 4559 | // ::= mm_ <expression> # prefix -- |
| 4560 | // ::= ti <type> # typeid (type) |
| 4561 | // ::= te <expression> # typeid (expression) |
| 4562 | // ::= dc <type> <expression> # dynamic_cast<type> (expression) |
| 4563 | // ::= sc <type> <expression> # static_cast<type> (expression) |
| 4564 | // ::= cc <type> <expression> # const_cast<type> (expression) |
| 4565 | // ::= rc <type> <expression> # reinterpret_cast<type> (expression) |
| 4566 | // ::= st <type> # sizeof (a type) |
| 4567 | // ::= sz <expression> # sizeof (an expression) |
| 4568 | // ::= at <type> # alignof (a type) |
| 4569 | // ::= az <expression> # alignof (an expression) |
| 4570 | // ::= nx <expression> # noexcept (expression) |
| 4571 | // ::= <template-param> |
| 4572 | // ::= <function-param> |
| 4573 | // ::= dt <expression> <unresolved-name> # expr.name |
| 4574 | // ::= pt <expression> <unresolved-name> # expr->name |
| 4575 | // ::= ds <expression> <expression> # expr.*expr |
| 4576 | // ::= sZ <template-param> # size of a parameter pack |
| 4577 | // ::= sZ <function-param> # size of a function parameter pack |
| 4578 | // ::= sP <template-arg>* E # sizeof...(T), size of a captured template parameter pack from an alias template |
| 4579 | // ::= sp <expression> # pack expansion |
| 4580 | // ::= tw <expression> # throw expression |
| 4581 | // ::= tr # throw with no operand (rethrow) |
| 4582 | // ::= <unresolved-name> # f(p), N::f(p), ::f(p), |
| 4583 | // # freestanding dependent name (e.g., T::x), |
| 4584 | // # objectless nonstatic member reference |
| 4585 | // ::= fL <binary-operator-name> <expression> <expression> |
| 4586 | // ::= fR <binary-operator-name> <expression> <expression> |
| 4587 | // ::= fl <binary-operator-name> <expression> |
| 4588 | // ::= fr <binary-operator-name> <expression> |
| 4589 | // ::= <expr-primary> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4590 | template <typename Derived, typename Alloc> |
| 4591 | Node *AbstractManglingParser<Derived, Alloc>::parseExpr() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4592 | bool Global = consumeIf("gs"); |
| 4593 | if (numLeft() < 2) |
| 4594 | return nullptr; |
| 4595 | |
| 4596 | switch (*First) { |
| 4597 | case 'L': |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4598 | return getDerived().parseExprPrimary(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4599 | case 'T': |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4600 | return getDerived().parseTemplateParam(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4601 | case 'f': { |
| 4602 | // Disambiguate a fold expression from a <function-param>. |
| 4603 | if (look(1) == 'p' || (look(1) == 'L' && std::isdigit(look(2)))) |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4604 | return getDerived().parseFunctionParam(); |
| 4605 | return getDerived().parseFoldExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4606 | } |
| 4607 | case 'a': |
| 4608 | switch (First[1]) { |
| 4609 | case 'a': |
| 4610 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4611 | return getDerived().parseBinaryExpr("&&"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4612 | case 'd': |
| 4613 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4614 | return getDerived().parsePrefixExpr("&"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4615 | case 'n': |
| 4616 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4617 | return getDerived().parseBinaryExpr("&"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4618 | case 'N': |
| 4619 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4620 | return getDerived().parseBinaryExpr("&="); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4621 | case 'S': |
| 4622 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4623 | return getDerived().parseBinaryExpr("="); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4624 | case 't': { |
| 4625 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4626 | Node *Ty = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4627 | if (Ty == nullptr) |
| 4628 | return nullptr; |
| 4629 | return make<EnclosingExpr>("alignof (", Ty, ")"); |
| 4630 | } |
| 4631 | case 'z': { |
| 4632 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4633 | Node *Ty = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4634 | if (Ty == nullptr) |
| 4635 | return nullptr; |
| 4636 | return make<EnclosingExpr>("alignof (", Ty, ")"); |
| 4637 | } |
| 4638 | } |
| 4639 | return nullptr; |
| 4640 | case 'c': |
| 4641 | switch (First[1]) { |
| 4642 | // cc <type> <expression> # const_cast<type>(expression) |
| 4643 | case 'c': { |
| 4644 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4645 | Node *Ty = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4646 | if (Ty == nullptr) |
| 4647 | return Ty; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4648 | Node *Ex = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4649 | if (Ex == nullptr) |
| 4650 | return Ex; |
| 4651 | return make<CastExpr>("const_cast", Ty, Ex); |
| 4652 | } |
| 4653 | // cl <expression>+ E # call |
| 4654 | case 'l': { |
| 4655 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4656 | Node *Callee = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4657 | if (Callee == nullptr) |
| 4658 | return Callee; |
| 4659 | size_t ExprsBegin = Names.size(); |
| 4660 | while (!consumeIf('E')) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4661 | Node *E = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4662 | if (E == nullptr) |
| 4663 | return E; |
| 4664 | Names.push_back(E); |
| 4665 | } |
| 4666 | return make<CallExpr>(Callee, popTrailingNodeArray(ExprsBegin)); |
| 4667 | } |
| 4668 | case 'm': |
| 4669 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4670 | return getDerived().parseBinaryExpr(","); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4671 | case 'o': |
| 4672 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4673 | return getDerived().parsePrefixExpr("~"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4674 | case 'v': |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4675 | return getDerived().parseConversionExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4676 | } |
| 4677 | return nullptr; |
| 4678 | case 'd': |
| 4679 | switch (First[1]) { |
| 4680 | case 'a': { |
| 4681 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4682 | Node *Ex = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4683 | if (Ex == nullptr) |
| 4684 | return Ex; |
| 4685 | return make<DeleteExpr>(Ex, Global, /*is_array=*/true); |
| 4686 | } |
| 4687 | case 'c': { |
| 4688 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4689 | Node *T = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4690 | if (T == nullptr) |
| 4691 | return T; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4692 | Node *Ex = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4693 | if (Ex == nullptr) |
| 4694 | return Ex; |
| 4695 | return make<CastExpr>("dynamic_cast", T, Ex); |
| 4696 | } |
| 4697 | case 'e': |
| 4698 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4699 | return getDerived().parsePrefixExpr("*"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4700 | case 'l': { |
| 4701 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4702 | Node *E = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4703 | if (E == nullptr) |
| 4704 | return E; |
| 4705 | return make<DeleteExpr>(E, Global, /*is_array=*/false); |
| 4706 | } |
| 4707 | case 'n': |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4708 | return getDerived().parseUnresolvedName(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4709 | case 's': { |
| 4710 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4711 | Node *LHS = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4712 | if (LHS == nullptr) |
| 4713 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4714 | Node *RHS = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4715 | if (RHS == nullptr) |
| 4716 | return nullptr; |
| 4717 | return make<MemberExpr>(LHS, ".*", RHS); |
| 4718 | } |
| 4719 | case 't': { |
| 4720 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4721 | Node *LHS = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4722 | if (LHS == nullptr) |
| 4723 | return LHS; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4724 | Node *RHS = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4725 | if (RHS == nullptr) |
| 4726 | return nullptr; |
| 4727 | return make<MemberExpr>(LHS, ".", RHS); |
| 4728 | } |
| 4729 | case 'v': |
| 4730 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4731 | return getDerived().parseBinaryExpr("/"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4732 | case 'V': |
| 4733 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4734 | return getDerived().parseBinaryExpr("/="); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4735 | } |
| 4736 | return nullptr; |
| 4737 | case 'e': |
| 4738 | switch (First[1]) { |
| 4739 | case 'o': |
| 4740 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4741 | return getDerived().parseBinaryExpr("^"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4742 | case 'O': |
| 4743 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4744 | return getDerived().parseBinaryExpr("^="); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4745 | case 'q': |
| 4746 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4747 | return getDerived().parseBinaryExpr("=="); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4748 | } |
| 4749 | return nullptr; |
| 4750 | case 'g': |
| 4751 | switch (First[1]) { |
| 4752 | case 'e': |
| 4753 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4754 | return getDerived().parseBinaryExpr(">="); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4755 | case 't': |
| 4756 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4757 | return getDerived().parseBinaryExpr(">"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4758 | } |
| 4759 | return nullptr; |
| 4760 | case 'i': |
| 4761 | switch (First[1]) { |
| 4762 | case 'x': { |
| 4763 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4764 | Node *Base = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4765 | if (Base == nullptr) |
| 4766 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4767 | Node *Index = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4768 | if (Index == nullptr) |
| 4769 | return Index; |
| 4770 | return make<ArraySubscriptExpr>(Base, Index); |
| 4771 | } |
| 4772 | case 'l': { |
| 4773 | First += 2; |
| 4774 | size_t InitsBegin = Names.size(); |
| 4775 | while (!consumeIf('E')) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4776 | Node *E = getDerived().parseBracedExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4777 | if (E == nullptr) |
| 4778 | return nullptr; |
| 4779 | Names.push_back(E); |
| 4780 | } |
| 4781 | return make<InitListExpr>(nullptr, popTrailingNodeArray(InitsBegin)); |
| 4782 | } |
| 4783 | } |
| 4784 | return nullptr; |
| 4785 | case 'l': |
| 4786 | switch (First[1]) { |
| 4787 | case 'e': |
| 4788 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4789 | return getDerived().parseBinaryExpr("<="); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4790 | case 's': |
| 4791 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4792 | return getDerived().parseBinaryExpr("<<"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4793 | case 'S': |
| 4794 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4795 | return getDerived().parseBinaryExpr("<<="); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4796 | case 't': |
| 4797 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4798 | return getDerived().parseBinaryExpr("<"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4799 | } |
| 4800 | return nullptr; |
| 4801 | case 'm': |
| 4802 | switch (First[1]) { |
Richard Smith | 2b38a69 | 2020-10-22 19:29:36 -0700 | [diff] [blame] | 4803 | case 'c': |
| 4804 | First += 2; |
| 4805 | return parsePointerToMemberConversionExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4806 | case 'i': |
| 4807 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4808 | return getDerived().parseBinaryExpr("-"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4809 | case 'I': |
| 4810 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4811 | return getDerived().parseBinaryExpr("-="); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4812 | case 'l': |
| 4813 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4814 | return getDerived().parseBinaryExpr("*"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4815 | case 'L': |
| 4816 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4817 | return getDerived().parseBinaryExpr("*="); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4818 | case 'm': |
| 4819 | First += 2; |
| 4820 | if (consumeIf('_')) |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4821 | return getDerived().parsePrefixExpr("--"); |
| 4822 | Node *Ex = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4823 | if (Ex == nullptr) |
| 4824 | return nullptr; |
| 4825 | return make<PostfixExpr>(Ex, "--"); |
| 4826 | } |
| 4827 | return nullptr; |
| 4828 | case 'n': |
| 4829 | switch (First[1]) { |
| 4830 | case 'a': |
| 4831 | case 'w': |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4832 | return getDerived().parseNewExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4833 | case 'e': |
| 4834 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4835 | return getDerived().parseBinaryExpr("!="); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4836 | case 'g': |
| 4837 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4838 | return getDerived().parsePrefixExpr("-"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4839 | case 't': |
| 4840 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4841 | return getDerived().parsePrefixExpr("!"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4842 | case 'x': |
| 4843 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4844 | Node *Ex = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4845 | if (Ex == nullptr) |
| 4846 | return Ex; |
| 4847 | return make<EnclosingExpr>("noexcept (", Ex, ")"); |
| 4848 | } |
| 4849 | return nullptr; |
| 4850 | case 'o': |
| 4851 | switch (First[1]) { |
| 4852 | case 'n': |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4853 | return getDerived().parseUnresolvedName(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4854 | case 'o': |
| 4855 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4856 | return getDerived().parseBinaryExpr("||"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4857 | case 'r': |
| 4858 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4859 | return getDerived().parseBinaryExpr("|"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4860 | case 'R': |
| 4861 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4862 | return getDerived().parseBinaryExpr("|="); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4863 | } |
| 4864 | return nullptr; |
| 4865 | case 'p': |
| 4866 | switch (First[1]) { |
| 4867 | case 'm': |
| 4868 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4869 | return getDerived().parseBinaryExpr("->*"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4870 | case 'l': |
| 4871 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4872 | return getDerived().parseBinaryExpr("+"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4873 | case 'L': |
| 4874 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4875 | return getDerived().parseBinaryExpr("+="); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4876 | case 'p': { |
| 4877 | First += 2; |
| 4878 | if (consumeIf('_')) |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4879 | return getDerived().parsePrefixExpr("++"); |
| 4880 | Node *Ex = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4881 | if (Ex == nullptr) |
| 4882 | return Ex; |
| 4883 | return make<PostfixExpr>(Ex, "++"); |
| 4884 | } |
| 4885 | case 's': |
| 4886 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4887 | return getDerived().parsePrefixExpr("+"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4888 | case 't': { |
| 4889 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4890 | Node *L = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4891 | if (L == nullptr) |
| 4892 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4893 | Node *R = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4894 | if (R == nullptr) |
| 4895 | return nullptr; |
| 4896 | return make<MemberExpr>(L, "->", R); |
| 4897 | } |
| 4898 | } |
| 4899 | return nullptr; |
| 4900 | case 'q': |
| 4901 | if (First[1] == 'u') { |
| 4902 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4903 | Node *Cond = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4904 | if (Cond == nullptr) |
| 4905 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4906 | Node *LHS = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4907 | if (LHS == nullptr) |
| 4908 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4909 | Node *RHS = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4910 | if (RHS == nullptr) |
| 4911 | return nullptr; |
| 4912 | return make<ConditionalExpr>(Cond, LHS, RHS); |
| 4913 | } |
| 4914 | return nullptr; |
| 4915 | case 'r': |
| 4916 | switch (First[1]) { |
| 4917 | case 'c': { |
| 4918 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4919 | Node *T = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4920 | if (T == nullptr) |
| 4921 | return T; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4922 | Node *Ex = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4923 | if (Ex == nullptr) |
| 4924 | return Ex; |
| 4925 | return make<CastExpr>("reinterpret_cast", T, Ex); |
| 4926 | } |
| 4927 | case 'm': |
| 4928 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4929 | return getDerived().parseBinaryExpr("%"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4930 | case 'M': |
| 4931 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4932 | return getDerived().parseBinaryExpr("%="); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4933 | case 's': |
| 4934 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4935 | return getDerived().parseBinaryExpr(">>"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4936 | case 'S': |
| 4937 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4938 | return getDerived().parseBinaryExpr(">>="); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4939 | } |
| 4940 | return nullptr; |
| 4941 | case 's': |
| 4942 | switch (First[1]) { |
| 4943 | case 'c': { |
| 4944 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4945 | Node *T = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4946 | if (T == nullptr) |
| 4947 | return T; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4948 | Node *Ex = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4949 | if (Ex == nullptr) |
| 4950 | return Ex; |
| 4951 | return make<CastExpr>("static_cast", T, Ex); |
| 4952 | } |
Richard Smith | 2b38a69 | 2020-10-22 19:29:36 -0700 | [diff] [blame] | 4953 | case 'o': |
| 4954 | First += 2; |
| 4955 | return parseSubobjectExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4956 | case 'p': { |
| 4957 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4958 | Node *Child = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4959 | if (Child == nullptr) |
| 4960 | return nullptr; |
| 4961 | return make<ParameterPackExpansion>(Child); |
| 4962 | } |
| 4963 | case 'r': |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4964 | return getDerived().parseUnresolvedName(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4965 | case 't': { |
| 4966 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4967 | Node *Ty = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4968 | if (Ty == nullptr) |
| 4969 | return Ty; |
| 4970 | return make<EnclosingExpr>("sizeof (", Ty, ")"); |
| 4971 | } |
| 4972 | case 'z': { |
| 4973 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4974 | Node *Ex = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4975 | if (Ex == nullptr) |
| 4976 | return Ex; |
| 4977 | return make<EnclosingExpr>("sizeof (", Ex, ")"); |
| 4978 | } |
| 4979 | case 'Z': |
| 4980 | First += 2; |
| 4981 | if (look() == 'T') { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4982 | Node *R = getDerived().parseTemplateParam(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4983 | if (R == nullptr) |
| 4984 | return nullptr; |
| 4985 | return make<SizeofParamPackExpr>(R); |
| 4986 | } else if (look() == 'f') { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4987 | Node *FP = getDerived().parseFunctionParam(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4988 | if (FP == nullptr) |
| 4989 | return nullptr; |
| 4990 | return make<EnclosingExpr>("sizeof... (", FP, ")"); |
| 4991 | } |
| 4992 | return nullptr; |
| 4993 | case 'P': { |
| 4994 | First += 2; |
| 4995 | size_t ArgsBegin = Names.size(); |
| 4996 | while (!consumeIf('E')) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 4997 | Node *Arg = getDerived().parseTemplateArg(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 4998 | if (Arg == nullptr) |
| 4999 | return nullptr; |
| 5000 | Names.push_back(Arg); |
| 5001 | } |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 5002 | auto *Pack = make<NodeArrayNode>(popTrailingNodeArray(ArgsBegin)); |
| 5003 | if (!Pack) |
| 5004 | return nullptr; |
| 5005 | return make<EnclosingExpr>("sizeof... (", Pack, ")"); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5006 | } |
| 5007 | } |
| 5008 | return nullptr; |
| 5009 | case 't': |
| 5010 | switch (First[1]) { |
| 5011 | case 'e': { |
| 5012 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5013 | Node *Ex = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5014 | if (Ex == nullptr) |
| 5015 | return Ex; |
| 5016 | return make<EnclosingExpr>("typeid (", Ex, ")"); |
| 5017 | } |
| 5018 | case 'i': { |
| 5019 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5020 | Node *Ty = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5021 | if (Ty == nullptr) |
| 5022 | return Ty; |
| 5023 | return make<EnclosingExpr>("typeid (", Ty, ")"); |
| 5024 | } |
| 5025 | case 'l': { |
| 5026 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5027 | Node *Ty = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5028 | if (Ty == nullptr) |
| 5029 | return nullptr; |
| 5030 | size_t InitsBegin = Names.size(); |
| 5031 | while (!consumeIf('E')) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5032 | Node *E = getDerived().parseBracedExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5033 | if (E == nullptr) |
| 5034 | return nullptr; |
| 5035 | Names.push_back(E); |
| 5036 | } |
| 5037 | return make<InitListExpr>(Ty, popTrailingNodeArray(InitsBegin)); |
| 5038 | } |
| 5039 | case 'r': |
| 5040 | First += 2; |
| 5041 | return make<NameType>("throw"); |
| 5042 | case 'w': { |
| 5043 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5044 | Node *Ex = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5045 | if (Ex == nullptr) |
| 5046 | return nullptr; |
| 5047 | return make<ThrowExpr>(Ex); |
| 5048 | } |
| 5049 | } |
| 5050 | return nullptr; |
James Y Knight | 415432d | 2020-12-07 10:26:49 -0500 | [diff] [blame] | 5051 | case 'u': { |
| 5052 | ++First; |
| 5053 | Node *Name = getDerived().parseSourceName(/*NameState=*/nullptr); |
| 5054 | if (!Name) |
| 5055 | return nullptr; |
| 5056 | // Special case legacy __uuidof mangling. The 't' and 'z' appear where the |
| 5057 | // standard encoding expects a <template-arg>, and would be otherwise be |
| 5058 | // interpreted as <type> node 'short' or 'ellipsis'. However, neither |
| 5059 | // __uuidof(short) nor __uuidof(...) can actually appear, so there is no |
| 5060 | // actual conflict here. |
| 5061 | if (Name->getBaseName() == "__uuidof") { |
| 5062 | if (numLeft() < 2) |
| 5063 | return nullptr; |
| 5064 | if (*First == 't') { |
| 5065 | ++First; |
| 5066 | Node *Ty = getDerived().parseType(); |
| 5067 | if (!Ty) |
| 5068 | return nullptr; |
| 5069 | return make<CallExpr>(Name, makeNodeArray(&Ty, &Ty + 1)); |
| 5070 | } |
| 5071 | if (*First == 'z') { |
| 5072 | ++First; |
| 5073 | Node *Ex = getDerived().parseExpr(); |
| 5074 | if (!Ex) |
| 5075 | return nullptr; |
| 5076 | return make<CallExpr>(Name, makeNodeArray(&Ex, &Ex + 1)); |
| 5077 | } |
| 5078 | } |
| 5079 | size_t ExprsBegin = Names.size(); |
| 5080 | while (!consumeIf('E')) { |
| 5081 | Node *E = getDerived().parseTemplateArg(); |
| 5082 | if (E == nullptr) |
| 5083 | return E; |
| 5084 | Names.push_back(E); |
| 5085 | } |
| 5086 | return make<CallExpr>(Name, popTrailingNodeArray(ExprsBegin)); |
| 5087 | } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5088 | case '1': |
| 5089 | case '2': |
| 5090 | case '3': |
| 5091 | case '4': |
| 5092 | case '5': |
| 5093 | case '6': |
| 5094 | case '7': |
| 5095 | case '8': |
| 5096 | case '9': |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5097 | return getDerived().parseUnresolvedName(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5098 | } |
| 5099 | return nullptr; |
| 5100 | } |
| 5101 | |
| 5102 | // <call-offset> ::= h <nv-offset> _ |
| 5103 | // ::= v <v-offset> _ |
| 5104 | // |
| 5105 | // <nv-offset> ::= <offset number> |
| 5106 | // # non-virtual base override |
| 5107 | // |
| 5108 | // <v-offset> ::= <offset number> _ <virtual offset number> |
| 5109 | // # virtual base override, with vcall offset |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5110 | template <typename Alloc, typename Derived> |
| 5111 | bool AbstractManglingParser<Alloc, Derived>::parseCallOffset() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5112 | // Just scan through the call offset, we never add this information into the |
| 5113 | // output. |
| 5114 | if (consumeIf('h')) |
| 5115 | return parseNumber(true).empty() || !consumeIf('_'); |
| 5116 | if (consumeIf('v')) |
| 5117 | return parseNumber(true).empty() || !consumeIf('_') || |
| 5118 | parseNumber(true).empty() || !consumeIf('_'); |
| 5119 | return true; |
| 5120 | } |
| 5121 | |
| 5122 | // <special-name> ::= TV <type> # virtual table |
| 5123 | // ::= TT <type> # VTT structure (construction vtable index) |
| 5124 | // ::= TI <type> # typeinfo structure |
| 5125 | // ::= TS <type> # typeinfo name (null-terminated byte string) |
| 5126 | // ::= Tc <call-offset> <call-offset> <base encoding> |
| 5127 | // # base is the nominal target function of thunk |
| 5128 | // # first call-offset is 'this' adjustment |
| 5129 | // # second call-offset is result adjustment |
| 5130 | // ::= T <call-offset> <base encoding> |
| 5131 | // # base is the nominal target function of thunk |
| 5132 | // ::= GV <object name> # Guard variable for one-time initialization |
| 5133 | // # No <type> |
| 5134 | // ::= TW <object name> # Thread-local wrapper |
| 5135 | // ::= TH <object name> # Thread-local initialization |
| 5136 | // ::= GR <object name> _ # First temporary |
| 5137 | // ::= GR <object name> <seq-id> _ # Subsequent temporaries |
| 5138 | // extension ::= TC <first type> <number> _ <second type> # construction vtable for second-in-first |
| 5139 | // extension ::= GR <object name> # reference temporary for object |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5140 | template <typename Derived, typename Alloc> |
| 5141 | Node *AbstractManglingParser<Derived, Alloc>::parseSpecialName() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5142 | switch (look()) { |
| 5143 | case 'T': |
| 5144 | switch (look(1)) { |
Richard Smith | 2b38a69 | 2020-10-22 19:29:36 -0700 | [diff] [blame] | 5145 | // TA <template-arg> # template parameter object |
| 5146 | // |
| 5147 | // Not yet in the spec: https://github.com/itanium-cxx-abi/cxx-abi/issues/63 |
| 5148 | case 'A': { |
| 5149 | First += 2; |
| 5150 | Node *Arg = getDerived().parseTemplateArg(); |
| 5151 | if (Arg == nullptr) |
| 5152 | return nullptr; |
| 5153 | return make<SpecialName>("template parameter object for ", Arg); |
| 5154 | } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5155 | // TV <type> # virtual table |
| 5156 | case 'V': { |
| 5157 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5158 | Node *Ty = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5159 | if (Ty == nullptr) |
| 5160 | return nullptr; |
| 5161 | return make<SpecialName>("vtable for ", Ty); |
| 5162 | } |
| 5163 | // TT <type> # VTT structure (construction vtable index) |
| 5164 | case 'T': { |
| 5165 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5166 | Node *Ty = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5167 | if (Ty == nullptr) |
| 5168 | return nullptr; |
| 5169 | return make<SpecialName>("VTT for ", Ty); |
| 5170 | } |
| 5171 | // TI <type> # typeinfo structure |
| 5172 | case 'I': { |
| 5173 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5174 | Node *Ty = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5175 | if (Ty == nullptr) |
| 5176 | return nullptr; |
| 5177 | return make<SpecialName>("typeinfo for ", Ty); |
| 5178 | } |
| 5179 | // TS <type> # typeinfo name (null-terminated byte string) |
| 5180 | case 'S': { |
| 5181 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5182 | Node *Ty = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5183 | if (Ty == nullptr) |
| 5184 | return nullptr; |
| 5185 | return make<SpecialName>("typeinfo name for ", Ty); |
| 5186 | } |
| 5187 | // Tc <call-offset> <call-offset> <base encoding> |
| 5188 | case 'c': { |
| 5189 | First += 2; |
| 5190 | if (parseCallOffset() || parseCallOffset()) |
| 5191 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5192 | Node *Encoding = getDerived().parseEncoding(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5193 | if (Encoding == nullptr) |
| 5194 | return nullptr; |
| 5195 | return make<SpecialName>("covariant return thunk to ", Encoding); |
| 5196 | } |
| 5197 | // extension ::= TC <first type> <number> _ <second type> |
| 5198 | // # construction vtable for second-in-first |
| 5199 | case 'C': { |
| 5200 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5201 | Node *FirstType = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5202 | if (FirstType == nullptr) |
| 5203 | return nullptr; |
| 5204 | if (parseNumber(true).empty() || !consumeIf('_')) |
| 5205 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5206 | Node *SecondType = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5207 | if (SecondType == nullptr) |
| 5208 | return nullptr; |
| 5209 | return make<CtorVtableSpecialName>(SecondType, FirstType); |
| 5210 | } |
| 5211 | // TW <object name> # Thread-local wrapper |
| 5212 | case 'W': { |
| 5213 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5214 | Node *Name = getDerived().parseName(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5215 | if (Name == nullptr) |
| 5216 | return nullptr; |
| 5217 | return make<SpecialName>("thread-local wrapper routine for ", Name); |
| 5218 | } |
| 5219 | // TH <object name> # Thread-local initialization |
| 5220 | case 'H': { |
| 5221 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5222 | Node *Name = getDerived().parseName(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5223 | if (Name == nullptr) |
| 5224 | return nullptr; |
| 5225 | return make<SpecialName>("thread-local initialization routine for ", Name); |
| 5226 | } |
| 5227 | // T <call-offset> <base encoding> |
| 5228 | default: { |
| 5229 | ++First; |
| 5230 | bool IsVirt = look() == 'v'; |
| 5231 | if (parseCallOffset()) |
| 5232 | return nullptr; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5233 | Node *BaseEncoding = getDerived().parseEncoding(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5234 | if (BaseEncoding == nullptr) |
| 5235 | return nullptr; |
| 5236 | if (IsVirt) |
| 5237 | return make<SpecialName>("virtual thunk to ", BaseEncoding); |
| 5238 | else |
| 5239 | return make<SpecialName>("non-virtual thunk to ", BaseEncoding); |
| 5240 | } |
| 5241 | } |
| 5242 | case 'G': |
| 5243 | switch (look(1)) { |
| 5244 | // GV <object name> # Guard variable for one-time initialization |
| 5245 | case 'V': { |
| 5246 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5247 | Node *Name = getDerived().parseName(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5248 | if (Name == nullptr) |
| 5249 | return nullptr; |
| 5250 | return make<SpecialName>("guard variable for ", Name); |
| 5251 | } |
| 5252 | // GR <object name> # reference temporary for object |
| 5253 | // GR <object name> _ # First temporary |
| 5254 | // GR <object name> <seq-id> _ # Subsequent temporaries |
| 5255 | case 'R': { |
| 5256 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5257 | Node *Name = getDerived().parseName(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5258 | if (Name == nullptr) |
| 5259 | return nullptr; |
| 5260 | size_t Count; |
| 5261 | bool ParsedSeqId = !parseSeqId(&Count); |
| 5262 | if (!consumeIf('_') && ParsedSeqId) |
| 5263 | return nullptr; |
| 5264 | return make<SpecialName>("reference temporary for ", Name); |
| 5265 | } |
| 5266 | } |
| 5267 | } |
| 5268 | return nullptr; |
| 5269 | } |
| 5270 | |
| 5271 | // <encoding> ::= <function name> <bare-function-type> |
| 5272 | // ::= <data name> |
| 5273 | // ::= <special-name> |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5274 | template <typename Derived, typename Alloc> |
| 5275 | Node *AbstractManglingParser<Derived, Alloc>::parseEncoding() { |
Richard Smith | 252bc9b | 2020-07-09 21:08:39 -0700 | [diff] [blame] | 5276 | // The template parameters of an encoding are unrelated to those of the |
| 5277 | // enclosing context. |
| 5278 | class SaveTemplateParams { |
| 5279 | AbstractManglingParser *Parser; |
| 5280 | decltype(TemplateParams) OldParams; |
Justin Lebar | a3b738a | 2021-06-09 16:57:22 -0700 | [diff] [blame] | 5281 | decltype(OuterTemplateParams) OldOuterParams; |
Richard Smith | 252bc9b | 2020-07-09 21:08:39 -0700 | [diff] [blame] | 5282 | |
| 5283 | public: |
Louis Dionne | 83a7521 | 2020-10-30 17:33:02 -0400 | [diff] [blame] | 5284 | SaveTemplateParams(AbstractManglingParser *TheParser) : Parser(TheParser) { |
Richard Smith | 252bc9b | 2020-07-09 21:08:39 -0700 | [diff] [blame] | 5285 | OldParams = std::move(Parser->TemplateParams); |
Justin Lebar | a3b738a | 2021-06-09 16:57:22 -0700 | [diff] [blame] | 5286 | OldOuterParams = std::move(Parser->OuterTemplateParams); |
Richard Smith | 252bc9b | 2020-07-09 21:08:39 -0700 | [diff] [blame] | 5287 | Parser->TemplateParams.clear(); |
Justin Lebar | a3b738a | 2021-06-09 16:57:22 -0700 | [diff] [blame] | 5288 | Parser->OuterTemplateParams.clear(); |
Richard Smith | 252bc9b | 2020-07-09 21:08:39 -0700 | [diff] [blame] | 5289 | } |
| 5290 | ~SaveTemplateParams() { |
| 5291 | Parser->TemplateParams = std::move(OldParams); |
Justin Lebar | a3b738a | 2021-06-09 16:57:22 -0700 | [diff] [blame] | 5292 | Parser->OuterTemplateParams = std::move(OldOuterParams); |
Richard Smith | 252bc9b | 2020-07-09 21:08:39 -0700 | [diff] [blame] | 5293 | } |
| 5294 | } SaveTemplateParams(this); |
Richard Smith | 95ed96b | 2020-07-09 20:36:04 -0700 | [diff] [blame] | 5295 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5296 | if (look() == 'G' || look() == 'T') |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5297 | return getDerived().parseSpecialName(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5298 | |
| 5299 | auto IsEndOfEncoding = [&] { |
| 5300 | // The set of chars that can potentially follow an <encoding> (none of which |
| 5301 | // can start a <type>). Enumerating these allows us to avoid speculative |
| 5302 | // parsing. |
| 5303 | return numLeft() == 0 || look() == 'E' || look() == '.' || look() == '_'; |
| 5304 | }; |
| 5305 | |
| 5306 | NameState NameInfo(this); |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5307 | Node *Name = getDerived().parseName(&NameInfo); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5308 | if (Name == nullptr) |
| 5309 | return nullptr; |
| 5310 | |
| 5311 | if (resolveForwardTemplateRefs(NameInfo)) |
| 5312 | return nullptr; |
| 5313 | |
| 5314 | if (IsEndOfEncoding()) |
| 5315 | return Name; |
| 5316 | |
| 5317 | Node *Attrs = nullptr; |
| 5318 | if (consumeIf("Ua9enable_ifI")) { |
| 5319 | size_t BeforeArgs = Names.size(); |
| 5320 | while (!consumeIf('E')) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5321 | Node *Arg = getDerived().parseTemplateArg(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5322 | if (Arg == nullptr) |
| 5323 | return nullptr; |
| 5324 | Names.push_back(Arg); |
| 5325 | } |
| 5326 | Attrs = make<EnableIfAttr>(popTrailingNodeArray(BeforeArgs)); |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 5327 | if (!Attrs) |
| 5328 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5329 | } |
| 5330 | |
| 5331 | Node *ReturnType = nullptr; |
| 5332 | if (!NameInfo.CtorDtorConversion && NameInfo.EndsWithTemplateArgs) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5333 | ReturnType = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5334 | if (ReturnType == nullptr) |
| 5335 | return nullptr; |
| 5336 | } |
| 5337 | |
| 5338 | if (consumeIf('v')) |
| 5339 | return make<FunctionEncoding>(ReturnType, Name, NodeArray(), |
| 5340 | Attrs, NameInfo.CVQualifiers, |
| 5341 | NameInfo.ReferenceQualifier); |
| 5342 | |
| 5343 | size_t ParamsBegin = Names.size(); |
| 5344 | do { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5345 | Node *Ty = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5346 | if (Ty == nullptr) |
| 5347 | return nullptr; |
| 5348 | Names.push_back(Ty); |
| 5349 | } while (!IsEndOfEncoding()); |
| 5350 | |
| 5351 | return make<FunctionEncoding>(ReturnType, Name, |
| 5352 | popTrailingNodeArray(ParamsBegin), |
| 5353 | Attrs, NameInfo.CVQualifiers, |
| 5354 | NameInfo.ReferenceQualifier); |
| 5355 | } |
| 5356 | |
| 5357 | template <class Float> |
| 5358 | struct FloatData; |
| 5359 | |
| 5360 | template <> |
| 5361 | struct FloatData<float> |
| 5362 | { |
| 5363 | static const size_t mangled_size = 8; |
| 5364 | static const size_t max_demangled_size = 24; |
| 5365 | static constexpr const char* spec = "%af"; |
| 5366 | }; |
| 5367 | |
| 5368 | template <> |
| 5369 | struct FloatData<double> |
| 5370 | { |
| 5371 | static const size_t mangled_size = 16; |
| 5372 | static const size_t max_demangled_size = 32; |
| 5373 | static constexpr const char* spec = "%a"; |
| 5374 | }; |
| 5375 | |
| 5376 | template <> |
| 5377 | struct FloatData<long double> |
| 5378 | { |
| 5379 | #if defined(__mips__) && defined(__mips_n64) || defined(__aarch64__) || \ |
| 5380 | defined(__wasm__) |
| 5381 | static const size_t mangled_size = 32; |
| 5382 | #elif defined(__arm__) || defined(__mips__) || defined(__hexagon__) |
| 5383 | static const size_t mangled_size = 16; |
| 5384 | #else |
| 5385 | static const size_t mangled_size = 20; // May need to be adjusted to 16 or 24 on other platforms |
| 5386 | #endif |
Elliott Hughes | d77a634 | 2020-04-10 17:42:00 -0700 | [diff] [blame] | 5387 | // `-0x1.ffffffffffffffffffffffffffffp+16383` + 'L' + '\0' == 42 bytes. |
| 5388 | // 28 'f's * 4 bits == 112 bits, which is the number of mantissa bits. |
| 5389 | // Negatives are one character longer than positives. |
| 5390 | // `0x1.` and `p` are constant, and exponents `+16383` and `-16382` are the |
| 5391 | // same length. 1 sign bit, 112 mantissa bits, and 15 exponent bits == 128. |
| 5392 | static const size_t max_demangled_size = 42; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5393 | static constexpr const char *spec = "%LaL"; |
| 5394 | }; |
| 5395 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5396 | template <typename Alloc, typename Derived> |
| 5397 | template <class Float> |
| 5398 | Node *AbstractManglingParser<Alloc, Derived>::parseFloatingLiteral() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5399 | const size_t N = FloatData<Float>::mangled_size; |
| 5400 | if (numLeft() <= N) |
| 5401 | return nullptr; |
| 5402 | StringView Data(First, First + N); |
| 5403 | for (char C : Data) |
| 5404 | if (!std::isxdigit(C)) |
| 5405 | return nullptr; |
| 5406 | First += N; |
| 5407 | if (!consumeIf('E')) |
| 5408 | return nullptr; |
| 5409 | return make<FloatLiteralImpl<Float>>(Data); |
| 5410 | } |
| 5411 | |
| 5412 | // <seq-id> ::= <0-9A-Z>+ |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5413 | template <typename Alloc, typename Derived> |
| 5414 | bool AbstractManglingParser<Alloc, Derived>::parseSeqId(size_t *Out) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5415 | if (!(look() >= '0' && look() <= '9') && |
| 5416 | !(look() >= 'A' && look() <= 'Z')) |
| 5417 | return true; |
| 5418 | |
| 5419 | size_t Id = 0; |
| 5420 | while (true) { |
| 5421 | if (look() >= '0' && look() <= '9') { |
| 5422 | Id *= 36; |
| 5423 | Id += static_cast<size_t>(look() - '0'); |
| 5424 | } else if (look() >= 'A' && look() <= 'Z') { |
| 5425 | Id *= 36; |
| 5426 | Id += static_cast<size_t>(look() - 'A') + 10; |
| 5427 | } else { |
| 5428 | *Out = Id; |
| 5429 | return false; |
| 5430 | } |
| 5431 | ++First; |
| 5432 | } |
| 5433 | } |
| 5434 | |
| 5435 | // <substitution> ::= S <seq-id> _ |
| 5436 | // ::= S_ |
| 5437 | // <substitution> ::= Sa # ::std::allocator |
| 5438 | // <substitution> ::= Sb # ::std::basic_string |
| 5439 | // <substitution> ::= Ss # ::std::basic_string < char, |
| 5440 | // ::std::char_traits<char>, |
| 5441 | // ::std::allocator<char> > |
| 5442 | // <substitution> ::= Si # ::std::basic_istream<char, std::char_traits<char> > |
| 5443 | // <substitution> ::= So # ::std::basic_ostream<char, std::char_traits<char> > |
| 5444 | // <substitution> ::= Sd # ::std::basic_iostream<char, std::char_traits<char> > |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5445 | template <typename Derived, typename Alloc> |
| 5446 | Node *AbstractManglingParser<Derived, Alloc>::parseSubstitution() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5447 | if (!consumeIf('S')) |
| 5448 | return nullptr; |
| 5449 | |
Nathan Sidwell | 64e94ec | 2022-01-20 07:40:12 -0800 | [diff] [blame] | 5450 | if (look() >= 'a' && look() <= 'z') { |
Nathan Sidwell | 02ad874 | 2022-01-24 07:59:57 -0800 | [diff] [blame^] | 5451 | SpecialSubKind Kind; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5452 | switch (look()) { |
| 5453 | case 'a': |
Nathan Sidwell | 02ad874 | 2022-01-24 07:59:57 -0800 | [diff] [blame^] | 5454 | Kind = SpecialSubKind::allocator; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5455 | break; |
| 5456 | case 'b': |
Nathan Sidwell | 02ad874 | 2022-01-24 07:59:57 -0800 | [diff] [blame^] | 5457 | Kind = SpecialSubKind::basic_string; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5458 | break; |
| 5459 | case 'd': |
Nathan Sidwell | 02ad874 | 2022-01-24 07:59:57 -0800 | [diff] [blame^] | 5460 | Kind = SpecialSubKind::iostream; |
| 5461 | break; |
| 5462 | case 'i': |
| 5463 | Kind = SpecialSubKind::istream; |
| 5464 | break; |
| 5465 | case 'o': |
| 5466 | Kind = SpecialSubKind::ostream; |
| 5467 | break; |
| 5468 | case 's': |
| 5469 | Kind = SpecialSubKind::string; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5470 | break; |
| 5471 | default: |
| 5472 | return nullptr; |
| 5473 | } |
Nathan Sidwell | 02ad874 | 2022-01-24 07:59:57 -0800 | [diff] [blame^] | 5474 | ++First; |
| 5475 | auto *SpecialSub = make<SpecialSubstitution>(Kind); |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 5476 | if (!SpecialSub) |
| 5477 | return nullptr; |
Nathan Sidwell | 02ad874 | 2022-01-24 07:59:57 -0800 | [diff] [blame^] | 5478 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5479 | // Itanium C++ ABI 5.1.2: If a name that would use a built-in <substitution> |
| 5480 | // has ABI tags, the tags are appended to the substitution; the result is a |
| 5481 | // substitutable component. |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5482 | Node *WithTags = getDerived().parseAbiTags(SpecialSub); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5483 | if (WithTags != SpecialSub) { |
| 5484 | Subs.push_back(WithTags); |
| 5485 | SpecialSub = WithTags; |
| 5486 | } |
| 5487 | return SpecialSub; |
| 5488 | } |
| 5489 | |
| 5490 | // ::= S_ |
| 5491 | if (consumeIf('_')) { |
| 5492 | if (Subs.empty()) |
| 5493 | return nullptr; |
| 5494 | return Subs[0]; |
| 5495 | } |
| 5496 | |
| 5497 | // ::= S <seq-id> _ |
| 5498 | size_t Index = 0; |
| 5499 | if (parseSeqId(&Index)) |
| 5500 | return nullptr; |
| 5501 | ++Index; |
| 5502 | if (!consumeIf('_') || Index >= Subs.size()) |
| 5503 | return nullptr; |
| 5504 | return Subs[Index]; |
| 5505 | } |
| 5506 | |
| 5507 | // <template-param> ::= T_ # first template parameter |
| 5508 | // ::= T <parameter-2 non-negative number> _ |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 5509 | // ::= TL <level-1> __ |
| 5510 | // ::= TL <level-1> _ <parameter-2 non-negative number> _ |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5511 | template <typename Derived, typename Alloc> |
| 5512 | Node *AbstractManglingParser<Derived, Alloc>::parseTemplateParam() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5513 | if (!consumeIf('T')) |
| 5514 | return nullptr; |
| 5515 | |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 5516 | size_t Level = 0; |
| 5517 | if (consumeIf('L')) { |
| 5518 | if (parsePositiveInteger(&Level)) |
| 5519 | return nullptr; |
| 5520 | ++Level; |
| 5521 | if (!consumeIf('_')) |
| 5522 | return nullptr; |
| 5523 | } |
| 5524 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5525 | size_t Index = 0; |
| 5526 | if (!consumeIf('_')) { |
| 5527 | if (parsePositiveInteger(&Index)) |
| 5528 | return nullptr; |
| 5529 | ++Index; |
| 5530 | if (!consumeIf('_')) |
| 5531 | return nullptr; |
| 5532 | } |
| 5533 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5534 | // If we're in a context where this <template-param> refers to a |
| 5535 | // <template-arg> further ahead in the mangled name (currently just conversion |
| 5536 | // operator types), then we should only look it up in the right context. |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 5537 | // This can only happen at the outermost level. |
| 5538 | if (PermitForwardTemplateReferences && Level == 0) { |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 5539 | Node *ForwardRef = make<ForwardTemplateReference>(Index); |
| 5540 | if (!ForwardRef) |
| 5541 | return nullptr; |
| 5542 | assert(ForwardRef->getKind() == Node::KForwardTemplateReference); |
| 5543 | ForwardTemplateRefs.push_back( |
| 5544 | static_cast<ForwardTemplateReference *>(ForwardRef)); |
| 5545 | return ForwardRef; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5546 | } |
| 5547 | |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 5548 | if (Level >= TemplateParams.size() || !TemplateParams[Level] || |
| 5549 | Index >= TemplateParams[Level]->size()) { |
| 5550 | // Itanium ABI 5.1.8: In a generic lambda, uses of auto in the parameter |
| 5551 | // list are mangled as the corresponding artificial template type parameter. |
| 5552 | if (ParsingLambdaParamsAtLevel == Level && Level <= TemplateParams.size()) { |
| 5553 | // This will be popped by the ScopedTemplateParamList in |
| 5554 | // parseUnnamedTypeName. |
| 5555 | if (Level == TemplateParams.size()) |
| 5556 | TemplateParams.push_back(nullptr); |
| 5557 | return make<NameType>("auto"); |
| 5558 | } |
| 5559 | |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5560 | return nullptr; |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 5561 | } |
| 5562 | |
| 5563 | return (*TemplateParams[Level])[Index]; |
| 5564 | } |
| 5565 | |
| 5566 | // <template-param-decl> ::= Ty # type parameter |
| 5567 | // ::= Tn <type> # non-type parameter |
| 5568 | // ::= Tt <template-param-decl>* E # template parameter |
| 5569 | // ::= Tp <template-param-decl> # parameter pack |
| 5570 | template <typename Derived, typename Alloc> |
| 5571 | Node *AbstractManglingParser<Derived, Alloc>::parseTemplateParamDecl() { |
| 5572 | auto InventTemplateParamName = [&](TemplateParamKind Kind) { |
| 5573 | unsigned Index = NumSyntheticTemplateParameters[(int)Kind]++; |
| 5574 | Node *N = make<SyntheticTemplateParamName>(Kind, Index); |
| 5575 | if (N) TemplateParams.back()->push_back(N); |
| 5576 | return N; |
| 5577 | }; |
| 5578 | |
| 5579 | if (consumeIf("Ty")) { |
| 5580 | Node *Name = InventTemplateParamName(TemplateParamKind::Type); |
| 5581 | if (!Name) |
| 5582 | return nullptr; |
| 5583 | return make<TypeTemplateParamDecl>(Name); |
| 5584 | } |
| 5585 | |
| 5586 | if (consumeIf("Tn")) { |
| 5587 | Node *Name = InventTemplateParamName(TemplateParamKind::NonType); |
| 5588 | if (!Name) |
| 5589 | return nullptr; |
| 5590 | Node *Type = parseType(); |
| 5591 | if (!Type) |
| 5592 | return nullptr; |
| 5593 | return make<NonTypeTemplateParamDecl>(Name, Type); |
| 5594 | } |
| 5595 | |
| 5596 | if (consumeIf("Tt")) { |
| 5597 | Node *Name = InventTemplateParamName(TemplateParamKind::Template); |
| 5598 | if (!Name) |
| 5599 | return nullptr; |
| 5600 | size_t ParamsBegin = Names.size(); |
| 5601 | ScopedTemplateParamList TemplateTemplateParamParams(this); |
| 5602 | while (!consumeIf("E")) { |
| 5603 | Node *P = parseTemplateParamDecl(); |
| 5604 | if (!P) |
| 5605 | return nullptr; |
| 5606 | Names.push_back(P); |
| 5607 | } |
| 5608 | NodeArray Params = popTrailingNodeArray(ParamsBegin); |
| 5609 | return make<TemplateTemplateParamDecl>(Name, Params); |
| 5610 | } |
| 5611 | |
| 5612 | if (consumeIf("Tp")) { |
| 5613 | Node *P = parseTemplateParamDecl(); |
| 5614 | if (!P) |
| 5615 | return nullptr; |
| 5616 | return make<TemplateParamPackDecl>(P); |
| 5617 | } |
| 5618 | |
| 5619 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5620 | } |
| 5621 | |
| 5622 | // <template-arg> ::= <type> # type or template |
| 5623 | // ::= X <expression> E # expression |
| 5624 | // ::= <expr-primary> # simple expressions |
| 5625 | // ::= J <template-arg>* E # argument pack |
| 5626 | // ::= LZ <encoding> E # extension |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5627 | template <typename Derived, typename Alloc> |
| 5628 | Node *AbstractManglingParser<Derived, Alloc>::parseTemplateArg() { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5629 | switch (look()) { |
| 5630 | case 'X': { |
| 5631 | ++First; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5632 | Node *Arg = getDerived().parseExpr(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5633 | if (Arg == nullptr || !consumeIf('E')) |
| 5634 | return nullptr; |
| 5635 | return Arg; |
| 5636 | } |
| 5637 | case 'J': { |
| 5638 | ++First; |
| 5639 | size_t ArgsBegin = Names.size(); |
| 5640 | while (!consumeIf('E')) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5641 | Node *Arg = getDerived().parseTemplateArg(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5642 | if (Arg == nullptr) |
| 5643 | return nullptr; |
| 5644 | Names.push_back(Arg); |
| 5645 | } |
| 5646 | NodeArray Args = popTrailingNodeArray(ArgsBegin); |
| 5647 | return make<TemplateArgumentPack>(Args); |
| 5648 | } |
| 5649 | case 'L': { |
| 5650 | // ::= LZ <encoding> E # extension |
| 5651 | if (look(1) == 'Z') { |
| 5652 | First += 2; |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5653 | Node *Arg = getDerived().parseEncoding(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5654 | if (Arg == nullptr || !consumeIf('E')) |
| 5655 | return nullptr; |
| 5656 | return Arg; |
| 5657 | } |
| 5658 | // ::= <expr-primary> # simple expressions |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5659 | return getDerived().parseExprPrimary(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5660 | } |
| 5661 | default: |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5662 | return getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5663 | } |
| 5664 | } |
| 5665 | |
| 5666 | // <template-args> ::= I <template-arg>* E |
| 5667 | // extension, the abi says <template-arg>+ |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5668 | template <typename Derived, typename Alloc> |
| 5669 | Node * |
| 5670 | AbstractManglingParser<Derived, Alloc>::parseTemplateArgs(bool TagTemplates) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5671 | if (!consumeIf('I')) |
| 5672 | return nullptr; |
| 5673 | |
| 5674 | // <template-params> refer to the innermost <template-args>. Clear out any |
| 5675 | // outer args that we may have inserted into TemplateParams. |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 5676 | if (TagTemplates) { |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5677 | TemplateParams.clear(); |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 5678 | TemplateParams.push_back(&OuterTemplateParams); |
| 5679 | OuterTemplateParams.clear(); |
| 5680 | } |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5681 | |
| 5682 | size_t ArgsBegin = Names.size(); |
| 5683 | while (!consumeIf('E')) { |
| 5684 | if (TagTemplates) { |
| 5685 | auto OldParams = std::move(TemplateParams); |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5686 | Node *Arg = getDerived().parseTemplateArg(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5687 | TemplateParams = std::move(OldParams); |
| 5688 | if (Arg == nullptr) |
| 5689 | return nullptr; |
| 5690 | Names.push_back(Arg); |
| 5691 | Node *TableEntry = Arg; |
| 5692 | if (Arg->getKind() == Node::KTemplateArgumentPack) { |
| 5693 | TableEntry = make<ParameterPack>( |
| 5694 | static_cast<TemplateArgumentPack*>(TableEntry)->getElements()); |
Richard Smith | 7918dea | 2018-08-24 23:30:26 +0000 | [diff] [blame] | 5695 | if (!TableEntry) |
| 5696 | return nullptr; |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5697 | } |
Richard Smith | cbffe54 | 2019-09-06 23:53:21 +0000 | [diff] [blame] | 5698 | TemplateParams.back()->push_back(TableEntry); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5699 | } else { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5700 | Node *Arg = getDerived().parseTemplateArg(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5701 | if (Arg == nullptr) |
| 5702 | return nullptr; |
| 5703 | Names.push_back(Arg); |
| 5704 | } |
| 5705 | } |
| 5706 | return make<TemplateArgs>(popTrailingNodeArray(ArgsBegin)); |
| 5707 | } |
| 5708 | |
| 5709 | // <mangled-name> ::= _Z <encoding> |
| 5710 | // ::= <type> |
| 5711 | // extension ::= ___Z <encoding> _block_invoke |
| 5712 | // extension ::= ___Z <encoding> _block_invoke<decimal-digit>+ |
| 5713 | // extension ::= ___Z <encoding> _block_invoke_<decimal-digit>+ |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5714 | template <typename Derived, typename Alloc> |
| 5715 | Node *AbstractManglingParser<Derived, Alloc>::parse() { |
Erik Pilkington | 18cf198 | 2019-01-17 21:37:36 +0000 | [diff] [blame] | 5716 | if (consumeIf("_Z") || consumeIf("__Z")) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5717 | Node *Encoding = getDerived().parseEncoding(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5718 | if (Encoding == nullptr) |
| 5719 | return nullptr; |
| 5720 | if (look() == '.') { |
| 5721 | Encoding = make<DotSuffix>(Encoding, StringView(First, Last)); |
| 5722 | First = Last; |
| 5723 | } |
| 5724 | if (numLeft() != 0) |
| 5725 | return nullptr; |
| 5726 | return Encoding; |
| 5727 | } |
| 5728 | |
Erik Pilkington | 18cf198 | 2019-01-17 21:37:36 +0000 | [diff] [blame] | 5729 | if (consumeIf("___Z") || consumeIf("____Z")) { |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5730 | Node *Encoding = getDerived().parseEncoding(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5731 | if (Encoding == nullptr || !consumeIf("_block_invoke")) |
| 5732 | return nullptr; |
| 5733 | bool RequireNumber = consumeIf('_'); |
| 5734 | if (parseNumber().empty() && RequireNumber) |
| 5735 | return nullptr; |
| 5736 | if (look() == '.') |
| 5737 | First = Last; |
| 5738 | if (numLeft() != 0) |
| 5739 | return nullptr; |
| 5740 | return make<SpecialName>("invocation function for block in ", Encoding); |
| 5741 | } |
| 5742 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5743 | Node *Ty = getDerived().parseType(); |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5744 | if (numLeft() != 0) |
| 5745 | return nullptr; |
| 5746 | return Ty; |
| 5747 | } |
| 5748 | |
Pavel Labath | b26cabc | 2018-10-16 14:29:14 +0000 | [diff] [blame] | 5749 | template <typename Alloc> |
| 5750 | struct ManglingParser : AbstractManglingParser<ManglingParser<Alloc>, Alloc> { |
| 5751 | using AbstractManglingParser<ManglingParser<Alloc>, |
| 5752 | Alloc>::AbstractManglingParser; |
| 5753 | }; |
| 5754 | |
Erik Pilkington | 870950f | 2019-01-17 20:37:51 +0000 | [diff] [blame] | 5755 | DEMANGLE_NAMESPACE_END |
Richard Smith | 4344cbd | 2018-08-20 20:14:49 +0000 | [diff] [blame] | 5756 | |
Erik Pilkington | 870950f | 2019-01-17 20:37:51 +0000 | [diff] [blame] | 5757 | #endif // DEMANGLE_ITANIUMDEMANGLE_H |