MicrosoftDemangleNodes.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659
  1. //===- MicrosoftDemangle.cpp ----------------------------------------------===//
  2. //
  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
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines a demangler for MSVC-style mangled symbols.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "llvm/Demangle/MicrosoftDemangleNodes.h"
  13. #include "llvm/Demangle/Utility.h"
  14. #include <cctype>
  15. #include <string>
  16. using namespace llvm;
  17. using namespace ms_demangle;
  18. #define OUTPUT_ENUM_CLASS_VALUE(Enum, Value, Desc) \
  19. case Enum::Value: \
  20. OB << Desc; \
  21. break;
  22. // Writes a space if the last token does not end with a punctuation.
  23. static void outputSpaceIfNecessary(OutputBuffer &OB) {
  24. if (OB.empty())
  25. return;
  26. char C = OB.back();
  27. if (std::isalnum(C) || C == '>')
  28. OB << " ";
  29. }
  30. static void outputSingleQualifier(OutputBuffer &OB, Qualifiers Q) {
  31. switch (Q) {
  32. case Q_Const:
  33. OB << "const";
  34. break;
  35. case Q_Volatile:
  36. OB << "volatile";
  37. break;
  38. case Q_Restrict:
  39. OB << "__restrict";
  40. break;
  41. default:
  42. break;
  43. }
  44. }
  45. static bool outputQualifierIfPresent(OutputBuffer &OB, Qualifiers Q,
  46. Qualifiers Mask, bool NeedSpace) {
  47. if (!(Q & Mask))
  48. return NeedSpace;
  49. if (NeedSpace)
  50. OB << " ";
  51. outputSingleQualifier(OB, Mask);
  52. return true;
  53. }
  54. static void outputQualifiers(OutputBuffer &OB, Qualifiers Q, bool SpaceBefore,
  55. bool SpaceAfter) {
  56. if (Q == Q_None)
  57. return;
  58. size_t Pos1 = OB.getCurrentPosition();
  59. SpaceBefore = outputQualifierIfPresent(OB, Q, Q_Const, SpaceBefore);
  60. SpaceBefore = outputQualifierIfPresent(OB, Q, Q_Volatile, SpaceBefore);
  61. SpaceBefore = outputQualifierIfPresent(OB, Q, Q_Restrict, SpaceBefore);
  62. size_t Pos2 = OB.getCurrentPosition();
  63. if (SpaceAfter && Pos2 > Pos1)
  64. OB << " ";
  65. }
  66. static void outputCallingConvention(OutputBuffer &OB, CallingConv CC) {
  67. outputSpaceIfNecessary(OB);
  68. switch (CC) {
  69. case CallingConv::Cdecl:
  70. OB << "__cdecl";
  71. break;
  72. case CallingConv::Fastcall:
  73. OB << "__fastcall";
  74. break;
  75. case CallingConv::Pascal:
  76. OB << "__pascal";
  77. break;
  78. case CallingConv::Regcall:
  79. OB << "__regcall";
  80. break;
  81. case CallingConv::Stdcall:
  82. OB << "__stdcall";
  83. break;
  84. case CallingConv::Thiscall:
  85. OB << "__thiscall";
  86. break;
  87. case CallingConv::Eabi:
  88. OB << "__eabi";
  89. break;
  90. case CallingConv::Vectorcall:
  91. OB << "__vectorcall";
  92. break;
  93. case CallingConv::Clrcall:
  94. OB << "__clrcall";
  95. break;
  96. case CallingConv::Swift:
  97. OB << "__attribute__((__swiftcall__)) ";
  98. break;
  99. case CallingConv::SwiftAsync:
  100. OB << "__attribute__((__swiftasynccall__)) ";
  101. break;
  102. default:
  103. break;
  104. }
  105. }
  106. std::string Node::toString(OutputFlags Flags) const {
  107. OutputBuffer OB;
  108. initializeOutputBuffer(nullptr, nullptr, OB, 1024);
  109. this->output(OB, Flags);
  110. OB << '\0';
  111. std::string Owned(OB.getBuffer());
  112. std::free(OB.getBuffer());
  113. return Owned;
  114. }
  115. void PrimitiveTypeNode::outputPre(OutputBuffer &OB, OutputFlags Flags) const {
  116. switch (PrimKind) {
  117. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Void, "void");
  118. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Bool, "bool");
  119. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Char, "char");
  120. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Schar, "signed char");
  121. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Uchar, "unsigned char");
  122. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Char8, "char8_t");
  123. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Char16, "char16_t");
  124. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Char32, "char32_t");
  125. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Short, "short");
  126. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Ushort, "unsigned short");
  127. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Int, "int");
  128. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Uint, "unsigned int");
  129. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Long, "long");
  130. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Ulong, "unsigned long");
  131. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Int64, "__int64");
  132. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Uint64, "unsigned __int64");
  133. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Wchar, "wchar_t");
  134. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Float, "float");
  135. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Double, "double");
  136. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Ldouble, "long double");
  137. OUTPUT_ENUM_CLASS_VALUE(PrimitiveKind, Nullptr, "std::nullptr_t");
  138. }
  139. outputQualifiers(OB, Quals, true, false);
  140. }
  141. void NodeArrayNode::output(OutputBuffer &OB, OutputFlags Flags) const {
  142. output(OB, Flags, ", ");
  143. }
  144. void NodeArrayNode::output(OutputBuffer &OB, OutputFlags Flags,
  145. StringView Separator) const {
  146. if (Count == 0)
  147. return;
  148. if (Nodes[0])
  149. Nodes[0]->output(OB, Flags);
  150. for (size_t I = 1; I < Count; ++I) {
  151. OB << Separator;
  152. Nodes[I]->output(OB, Flags);
  153. }
  154. }
  155. void EncodedStringLiteralNode::output(OutputBuffer &OB,
  156. OutputFlags Flags) const {
  157. switch (Char) {
  158. case CharKind::Wchar:
  159. OB << "L\"";
  160. break;
  161. case CharKind::Char:
  162. OB << "\"";
  163. break;
  164. case CharKind::Char16:
  165. OB << "u\"";
  166. break;
  167. case CharKind::Char32:
  168. OB << "U\"";
  169. break;
  170. }
  171. OB << DecodedString << "\"";
  172. if (IsTruncated)
  173. OB << "...";
  174. }
  175. void IntegerLiteralNode::output(OutputBuffer &OB, OutputFlags Flags) const {
  176. if (IsNegative)
  177. OB << '-';
  178. OB << Value;
  179. }
  180. void TemplateParameterReferenceNode::output(OutputBuffer &OB,
  181. OutputFlags Flags) const {
  182. if (ThunkOffsetCount > 0)
  183. OB << "{";
  184. else if (Affinity == PointerAffinity::Pointer)
  185. OB << "&";
  186. if (Symbol) {
  187. Symbol->output(OB, Flags);
  188. if (ThunkOffsetCount > 0)
  189. OB << ", ";
  190. }
  191. if (ThunkOffsetCount > 0)
  192. OB << ThunkOffsets[0];
  193. for (int I = 1; I < ThunkOffsetCount; ++I) {
  194. OB << ", " << ThunkOffsets[I];
  195. }
  196. if (ThunkOffsetCount > 0)
  197. OB << "}";
  198. }
  199. void IdentifierNode::outputTemplateParameters(OutputBuffer &OB,
  200. OutputFlags Flags) const {
  201. if (!TemplateParams)
  202. return;
  203. OB << "<";
  204. TemplateParams->output(OB, Flags);
  205. OB << ">";
  206. }
  207. void DynamicStructorIdentifierNode::output(OutputBuffer &OB,
  208. OutputFlags Flags) const {
  209. if (IsDestructor)
  210. OB << "`dynamic atexit destructor for ";
  211. else
  212. OB << "`dynamic initializer for ";
  213. if (Variable) {
  214. OB << "`";
  215. Variable->output(OB, Flags);
  216. OB << "''";
  217. } else {
  218. OB << "'";
  219. Name->output(OB, Flags);
  220. OB << "''";
  221. }
  222. }
  223. void NamedIdentifierNode::output(OutputBuffer &OB, OutputFlags Flags) const {
  224. OB << Name;
  225. outputTemplateParameters(OB, Flags);
  226. }
  227. void IntrinsicFunctionIdentifierNode::output(OutputBuffer &OB,
  228. OutputFlags Flags) const {
  229. switch (Operator) {
  230. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, New, "operator new");
  231. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Delete, "operator delete");
  232. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Assign, "operator=");
  233. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, RightShift, "operator>>");
  234. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, LeftShift, "operator<<");
  235. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, LogicalNot, "operator!");
  236. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Equals, "operator==");
  237. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, NotEquals, "operator!=");
  238. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, ArraySubscript,
  239. "operator[]");
  240. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Pointer, "operator->");
  241. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Increment, "operator++");
  242. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Decrement, "operator--");
  243. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Minus, "operator-");
  244. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Plus, "operator+");
  245. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Dereference, "operator*");
  246. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, BitwiseAnd, "operator&");
  247. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, MemberPointer,
  248. "operator->*");
  249. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Divide, "operator/");
  250. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Modulus, "operator%");
  251. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, LessThan, "operator<");
  252. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, LessThanEqual, "operator<=");
  253. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, GreaterThan, "operator>");
  254. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, GreaterThanEqual,
  255. "operator>=");
  256. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Comma, "operator,");
  257. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Parens, "operator()");
  258. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, BitwiseNot, "operator~");
  259. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, BitwiseXor, "operator^");
  260. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, BitwiseOr, "operator|");
  261. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, LogicalAnd, "operator&&");
  262. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, LogicalOr, "operator||");
  263. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, TimesEqual, "operator*=");
  264. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, PlusEqual, "operator+=");
  265. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, MinusEqual, "operator-=");
  266. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, DivEqual, "operator/=");
  267. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, ModEqual, "operator%=");
  268. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, RshEqual, "operator>>=");
  269. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, LshEqual, "operator<<=");
  270. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, BitwiseAndEqual,
  271. "operator&=");
  272. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, BitwiseOrEqual,
  273. "operator|=");
  274. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, BitwiseXorEqual,
  275. "operator^=");
  276. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, VbaseDtor, "`vbase dtor'");
  277. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, VecDelDtor,
  278. "`vector deleting dtor'");
  279. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, DefaultCtorClosure,
  280. "`default ctor closure'");
  281. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, ScalarDelDtor,
  282. "`scalar deleting dtor'");
  283. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, VecCtorIter,
  284. "`vector ctor iterator'");
  285. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, VecDtorIter,
  286. "`vector dtor iterator'");
  287. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, VecVbaseCtorIter,
  288. "`vector vbase ctor iterator'");
  289. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, VdispMap,
  290. "`virtual displacement map'");
  291. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, EHVecCtorIter,
  292. "`eh vector ctor iterator'");
  293. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, EHVecDtorIter,
  294. "`eh vector dtor iterator'");
  295. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, EHVecVbaseCtorIter,
  296. "`eh vector vbase ctor iterator'");
  297. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, CopyCtorClosure,
  298. "`copy ctor closure'");
  299. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, LocalVftableCtorClosure,
  300. "`local vftable ctor closure'");
  301. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, ArrayNew, "operator new[]");
  302. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, ArrayDelete,
  303. "operator delete[]");
  304. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, ManVectorCtorIter,
  305. "`managed vector ctor iterator'");
  306. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, ManVectorDtorIter,
  307. "`managed vector dtor iterator'");
  308. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, EHVectorCopyCtorIter,
  309. "`EH vector copy ctor iterator'");
  310. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, EHVectorVbaseCopyCtorIter,
  311. "`EH vector vbase copy ctor iterator'");
  312. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, VectorCopyCtorIter,
  313. "`vector copy ctor iterator'");
  314. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, VectorVbaseCopyCtorIter,
  315. "`vector vbase copy constructor iterator'");
  316. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, ManVectorVbaseCopyCtorIter,
  317. "`managed vector vbase copy constructor iterator'");
  318. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, CoAwait,
  319. "operator co_await");
  320. OUTPUT_ENUM_CLASS_VALUE(IntrinsicFunctionKind, Spaceship, "operator<=>");
  321. case IntrinsicFunctionKind::MaxIntrinsic:
  322. case IntrinsicFunctionKind::None:
  323. break;
  324. }
  325. outputTemplateParameters(OB, Flags);
  326. }
  327. void LocalStaticGuardIdentifierNode::output(OutputBuffer &OB,
  328. OutputFlags Flags) const {
  329. if (IsThread)
  330. OB << "`local static thread guard'";
  331. else
  332. OB << "`local static guard'";
  333. if (ScopeIndex > 0)
  334. OB << "{" << ScopeIndex << "}";
  335. }
  336. void ConversionOperatorIdentifierNode::output(OutputBuffer &OB,
  337. OutputFlags Flags) const {
  338. OB << "operator";
  339. outputTemplateParameters(OB, Flags);
  340. OB << " ";
  341. TargetType->output(OB, Flags);
  342. }
  343. void StructorIdentifierNode::output(OutputBuffer &OB, OutputFlags Flags) const {
  344. if (IsDestructor)
  345. OB << "~";
  346. Class->output(OB, Flags);
  347. outputTemplateParameters(OB, Flags);
  348. }
  349. void LiteralOperatorIdentifierNode::output(OutputBuffer &OB,
  350. OutputFlags Flags) const {
  351. OB << "operator \"\"" << Name;
  352. outputTemplateParameters(OB, Flags);
  353. }
  354. void FunctionSignatureNode::outputPre(OutputBuffer &OB,
  355. OutputFlags Flags) const {
  356. if (!(Flags & OF_NoAccessSpecifier)) {
  357. if (FunctionClass & FC_Public)
  358. OB << "public: ";
  359. if (FunctionClass & FC_Protected)
  360. OB << "protected: ";
  361. if (FunctionClass & FC_Private)
  362. OB << "private: ";
  363. }
  364. if (!(Flags & OF_NoMemberType)) {
  365. if (!(FunctionClass & FC_Global)) {
  366. if (FunctionClass & FC_Static)
  367. OB << "static ";
  368. }
  369. if (FunctionClass & FC_Virtual)
  370. OB << "virtual ";
  371. if (FunctionClass & FC_ExternC)
  372. OB << "extern \"C\" ";
  373. }
  374. if (!(Flags & OF_NoReturnType) && ReturnType) {
  375. ReturnType->outputPre(OB, Flags);
  376. OB << " ";
  377. }
  378. if (!(Flags & OF_NoCallingConvention))
  379. outputCallingConvention(OB, CallConvention);
  380. }
  381. void FunctionSignatureNode::outputPost(OutputBuffer &OB,
  382. OutputFlags Flags) const {
  383. if (!(FunctionClass & FC_NoParameterList)) {
  384. OB << "(";
  385. if (Params)
  386. Params->output(OB, Flags);
  387. else
  388. OB << "void";
  389. if (IsVariadic) {
  390. if (OB.back() != '(')
  391. OB << ", ";
  392. OB << "...";
  393. }
  394. OB << ")";
  395. }
  396. if (Quals & Q_Const)
  397. OB << " const";
  398. if (Quals & Q_Volatile)
  399. OB << " volatile";
  400. if (Quals & Q_Restrict)
  401. OB << " __restrict";
  402. if (Quals & Q_Unaligned)
  403. OB << " __unaligned";
  404. if (IsNoexcept)
  405. OB << " noexcept";
  406. if (RefQualifier == FunctionRefQualifier::Reference)
  407. OB << " &";
  408. else if (RefQualifier == FunctionRefQualifier::RValueReference)
  409. OB << " &&";
  410. if (!(Flags & OF_NoReturnType) && ReturnType)
  411. ReturnType->outputPost(OB, Flags);
  412. }
  413. void ThunkSignatureNode::outputPre(OutputBuffer &OB, OutputFlags Flags) const {
  414. OB << "[thunk]: ";
  415. FunctionSignatureNode::outputPre(OB, Flags);
  416. }
  417. void ThunkSignatureNode::outputPost(OutputBuffer &OB, OutputFlags Flags) const {
  418. if (FunctionClass & FC_StaticThisAdjust) {
  419. OB << "`adjustor{" << ThisAdjust.StaticOffset << "}'";
  420. } else if (FunctionClass & FC_VirtualThisAdjust) {
  421. if (FunctionClass & FC_VirtualThisAdjustEx) {
  422. OB << "`vtordispex{" << ThisAdjust.VBPtrOffset << ", "
  423. << ThisAdjust.VBOffsetOffset << ", " << ThisAdjust.VtordispOffset
  424. << ", " << ThisAdjust.StaticOffset << "}'";
  425. } else {
  426. OB << "`vtordisp{" << ThisAdjust.VtordispOffset << ", "
  427. << ThisAdjust.StaticOffset << "}'";
  428. }
  429. }
  430. FunctionSignatureNode::outputPost(OB, Flags);
  431. }
  432. void PointerTypeNode::outputPre(OutputBuffer &OB, OutputFlags Flags) const {
  433. if (Pointee->kind() == NodeKind::FunctionSignature) {
  434. // If this is a pointer to a function, don't output the calling convention.
  435. // It needs to go inside the parentheses.
  436. const FunctionSignatureNode *Sig =
  437. static_cast<const FunctionSignatureNode *>(Pointee);
  438. Sig->outputPre(OB, OF_NoCallingConvention);
  439. } else
  440. Pointee->outputPre(OB, Flags);
  441. outputSpaceIfNecessary(OB);
  442. if (Quals & Q_Unaligned)
  443. OB << "__unaligned ";
  444. if (Pointee->kind() == NodeKind::ArrayType) {
  445. OB << "(";
  446. } else if (Pointee->kind() == NodeKind::FunctionSignature) {
  447. OB << "(";
  448. const FunctionSignatureNode *Sig =
  449. static_cast<const FunctionSignatureNode *>(Pointee);
  450. outputCallingConvention(OB, Sig->CallConvention);
  451. OB << " ";
  452. }
  453. if (ClassParent) {
  454. ClassParent->output(OB, Flags);
  455. OB << "::";
  456. }
  457. switch (Affinity) {
  458. case PointerAffinity::Pointer:
  459. OB << "*";
  460. break;
  461. case PointerAffinity::Reference:
  462. OB << "&";
  463. break;
  464. case PointerAffinity::RValueReference:
  465. OB << "&&";
  466. break;
  467. default:
  468. assert(false);
  469. }
  470. outputQualifiers(OB, Quals, false, false);
  471. }
  472. void PointerTypeNode::outputPost(OutputBuffer &OB, OutputFlags Flags) const {
  473. if (Pointee->kind() == NodeKind::ArrayType ||
  474. Pointee->kind() == NodeKind::FunctionSignature)
  475. OB << ")";
  476. Pointee->outputPost(OB, Flags);
  477. }
  478. void TagTypeNode::outputPre(OutputBuffer &OB, OutputFlags Flags) const {
  479. if (!(Flags & OF_NoTagSpecifier)) {
  480. switch (Tag) {
  481. OUTPUT_ENUM_CLASS_VALUE(TagKind, Class, "class");
  482. OUTPUT_ENUM_CLASS_VALUE(TagKind, Struct, "struct");
  483. OUTPUT_ENUM_CLASS_VALUE(TagKind, Union, "union");
  484. OUTPUT_ENUM_CLASS_VALUE(TagKind, Enum, "enum");
  485. }
  486. OB << " ";
  487. }
  488. QualifiedName->output(OB, Flags);
  489. outputQualifiers(OB, Quals, true, false);
  490. }
  491. void TagTypeNode::outputPost(OutputBuffer &OB, OutputFlags Flags) const {}
  492. void ArrayTypeNode::outputPre(OutputBuffer &OB, OutputFlags Flags) const {
  493. ElementType->outputPre(OB, Flags);
  494. outputQualifiers(OB, Quals, true, false);
  495. }
  496. void ArrayTypeNode::outputOneDimension(OutputBuffer &OB, OutputFlags Flags,
  497. Node *N) const {
  498. assert(N->kind() == NodeKind::IntegerLiteral);
  499. IntegerLiteralNode *ILN = static_cast<IntegerLiteralNode *>(N);
  500. if (ILN->Value != 0)
  501. ILN->output(OB, Flags);
  502. }
  503. void ArrayTypeNode::outputDimensionsImpl(OutputBuffer &OB,
  504. OutputFlags Flags) const {
  505. if (Dimensions->Count == 0)
  506. return;
  507. outputOneDimension(OB, Flags, Dimensions->Nodes[0]);
  508. for (size_t I = 1; I < Dimensions->Count; ++I) {
  509. OB << "][";
  510. outputOneDimension(OB, Flags, Dimensions->Nodes[I]);
  511. }
  512. }
  513. void ArrayTypeNode::outputPost(OutputBuffer &OB, OutputFlags Flags) const {
  514. OB << "[";
  515. outputDimensionsImpl(OB, Flags);
  516. OB << "]";
  517. ElementType->outputPost(OB, Flags);
  518. }
  519. void SymbolNode::output(OutputBuffer &OB, OutputFlags Flags) const {
  520. Name->output(OB, Flags);
  521. }
  522. void FunctionSymbolNode::output(OutputBuffer &OB, OutputFlags Flags) const {
  523. Signature->outputPre(OB, Flags);
  524. outputSpaceIfNecessary(OB);
  525. Name->output(OB, Flags);
  526. Signature->outputPost(OB, Flags);
  527. }
  528. void VariableSymbolNode::output(OutputBuffer &OB, OutputFlags Flags) const {
  529. const char *AccessSpec = nullptr;
  530. bool IsStatic = true;
  531. switch (SC) {
  532. case StorageClass::PrivateStatic:
  533. AccessSpec = "private";
  534. break;
  535. case StorageClass::PublicStatic:
  536. AccessSpec = "public";
  537. break;
  538. case StorageClass::ProtectedStatic:
  539. AccessSpec = "protected";
  540. break;
  541. default:
  542. IsStatic = false;
  543. break;
  544. }
  545. if (!(Flags & OF_NoAccessSpecifier) && AccessSpec)
  546. OB << AccessSpec << ": ";
  547. if (!(Flags & OF_NoMemberType) && IsStatic)
  548. OB << "static ";
  549. if (!(Flags & OF_NoVariableType) && Type) {
  550. Type->outputPre(OB, Flags);
  551. outputSpaceIfNecessary(OB);
  552. }
  553. Name->output(OB, Flags);
  554. if (!(Flags & OF_NoVariableType) && Type)
  555. Type->outputPost(OB, Flags);
  556. }
  557. void CustomTypeNode::outputPre(OutputBuffer &OB, OutputFlags Flags) const {
  558. Identifier->output(OB, Flags);
  559. }
  560. void CustomTypeNode::outputPost(OutputBuffer &OB, OutputFlags Flags) const {}
  561. void QualifiedNameNode::output(OutputBuffer &OB, OutputFlags Flags) const {
  562. Components->output(OB, Flags, "::");
  563. }
  564. void RttiBaseClassDescriptorNode::output(OutputBuffer &OB,
  565. OutputFlags Flags) const {
  566. OB << "`RTTI Base Class Descriptor at (";
  567. OB << NVOffset << ", " << VBPtrOffset << ", " << VBTableOffset << ", "
  568. << this->Flags;
  569. OB << ")'";
  570. }
  571. void LocalStaticGuardVariableNode::output(OutputBuffer &OB,
  572. OutputFlags Flags) const {
  573. Name->output(OB, Flags);
  574. }
  575. void VcallThunkIdentifierNode::output(OutputBuffer &OB,
  576. OutputFlags Flags) const {
  577. OB << "`vcall'{" << OffsetInVTable << ", {flat}}";
  578. }
  579. void SpecialTableSymbolNode::output(OutputBuffer &OB, OutputFlags Flags) const {
  580. outputQualifiers(OB, Quals, false, true);
  581. Name->output(OB, Flags);
  582. if (TargetName) {
  583. OB << "{for `";
  584. TargetName->output(OB, Flags);
  585. OB << "'}";
  586. }
  587. }