MicrosoftDemangleNodes.cpp 22 KB

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