CppComprehensionEngine.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. /*
  2. * Copyright (c) 2021, Itamar S. <itamar8910@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "CppComprehensionEngine.h"
  7. #include <AK/Assertions.h>
  8. #include <AK/HashTable.h>
  9. #include <AK/OwnPtr.h>
  10. #include <LibCpp/AST.h>
  11. #include <LibCpp/Lexer.h>
  12. #include <LibCpp/Parser.h>
  13. #include <LibCpp/Preprocessor.h>
  14. #include <LibRegex/Regex.h>
  15. #include <Userland/DevTools/HackStudio/LanguageServers/ClientConnection.h>
  16. namespace LanguageServers::Cpp {
  17. CppComprehensionEngine::CppComprehensionEngine(const FileDB& filedb)
  18. : CodeComprehensionEngine(filedb, true)
  19. {
  20. }
  21. const CppComprehensionEngine::DocumentData* CppComprehensionEngine::get_or_create_document_data(const String& file)
  22. {
  23. auto absolute_path = filedb().to_absolute_path(file);
  24. if (!m_documents.contains(absolute_path)) {
  25. set_document_data(absolute_path, create_document_data_for(absolute_path));
  26. }
  27. return get_document_data(absolute_path);
  28. }
  29. const CppComprehensionEngine::DocumentData* CppComprehensionEngine::get_document_data(const String& file) const
  30. {
  31. auto absolute_path = filedb().to_absolute_path(file);
  32. auto document_data = m_documents.get(absolute_path);
  33. VERIFY(document_data.has_value());
  34. return document_data.value();
  35. }
  36. OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_document_data_for(const String& file)
  37. {
  38. auto document = filedb().get_or_create_from_filesystem(file);
  39. if (!document)
  40. return {};
  41. return create_document_data(document->text(), file);
  42. }
  43. void CppComprehensionEngine::set_document_data(const String& file, OwnPtr<DocumentData>&& data)
  44. {
  45. m_documents.set(filedb().to_absolute_path(file), move(data));
  46. }
  47. Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::get_suggestions(const String& file, const GUI::TextPosition& autocomplete_position)
  48. {
  49. Cpp::Position position { autocomplete_position.line(), autocomplete_position.column() > 0 ? autocomplete_position.column() - 1 : 0 };
  50. dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "CppComprehensionEngine position {}:{}", position.line, position.column);
  51. const auto* document_ptr = get_or_create_document_data(file);
  52. if (!document_ptr)
  53. return {};
  54. const auto& document = *document_ptr;
  55. auto containing_token = document.parser().token_at(position);
  56. auto node = document.parser().node_at(position);
  57. if (!node) {
  58. dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "no node at position {}:{}", position.line, position.column);
  59. return {};
  60. }
  61. if (node->parent() && node->parent()->parent())
  62. dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "node: {}, parent: {}, grandparent: {}", node->class_name(), node->parent()->class_name(), node->parent()->parent()->class_name());
  63. if (!node->parent())
  64. return {};
  65. auto results = autocomplete_property(document, *node, containing_token);
  66. if (results.has_value())
  67. return results.value();
  68. results = autocomplete_name(document, *node, containing_token);
  69. if (results.has_value())
  70. return results.value();
  71. return {};
  72. }
  73. Optional<Vector<GUI::AutocompleteProvider::Entry>> CppComprehensionEngine::autocomplete_name(const DocumentData& document, const ASTNode& node, Optional<Token> containing_token) const
  74. {
  75. auto partial_text = String::empty();
  76. if (containing_token.has_value() && containing_token.value().type() != Token::Type::ColonColon) {
  77. partial_text = containing_token.value().text();
  78. }
  79. return autocomplete_name(document, node, partial_text);
  80. }
  81. Optional<Vector<GUI::AutocompleteProvider::Entry>> CppComprehensionEngine::autocomplete_property(const DocumentData& document, const ASTNode& node, Optional<Token> containing_token) const
  82. {
  83. if (!containing_token.has_value())
  84. return {};
  85. if (!node.parent()->is_member_expression())
  86. return {};
  87. const auto& parent = static_cast<const MemberExpression&>(*node.parent());
  88. auto partial_text = String::empty();
  89. if (containing_token.value().type() != Token::Type::Dot) {
  90. if (&node != parent.m_property)
  91. return {};
  92. partial_text = containing_token.value().text();
  93. }
  94. return autocomplete_property(document, parent, partial_text);
  95. }
  96. NonnullRefPtrVector<Declaration> CppComprehensionEngine::get_available_declarations(const DocumentData& document, const ASTNode& node, RecurseIntoScopes recurse_into_scopes) const
  97. {
  98. const Cpp::ASTNode* current = &node;
  99. NonnullRefPtrVector<Declaration> available_declarations;
  100. while (current) {
  101. available_declarations.append(current->declarations());
  102. current = current->parent();
  103. }
  104. available_declarations.append(get_global_declarations_including_headers(document, recurse_into_scopes));
  105. return available_declarations;
  106. }
  107. Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::autocomplete_name(const DocumentData& document, const ASTNode& node, const String& partial_text) const
  108. {
  109. auto target_scope = scope_of_name_or_identifier(node);
  110. auto available_declarations = get_available_declarations(document, node, RecurseIntoScopes::No);
  111. Vector<StringView> available_names;
  112. auto add_if_valid = [this, &available_names, &target_scope](auto& decl) {
  113. auto name = decl.m_name;
  114. if (name.is_null() || name.is_empty())
  115. return;
  116. auto scope = scope_of_declaration(decl);
  117. if (scope.is_null())
  118. scope = String::empty();
  119. if (scope != target_scope)
  120. return;
  121. if (!available_names.contains_slow(name))
  122. available_names.append(name);
  123. };
  124. for (auto& decl : available_declarations) {
  125. if (decl.filename() == node.filename() && decl.start().line > node.start().line)
  126. continue;
  127. if (decl.is_variable_or_parameter_declaration()) {
  128. add_if_valid(decl);
  129. }
  130. if (decl.is_struct_or_class()) {
  131. add_if_valid(decl);
  132. }
  133. if (decl.is_function()) {
  134. add_if_valid(decl);
  135. }
  136. if (decl.is_namespace()) {
  137. add_if_valid(decl);
  138. }
  139. }
  140. Vector<GUI::AutocompleteProvider::Entry> suggestions;
  141. for (auto& name : available_names) {
  142. if (name.starts_with(partial_text)) {
  143. suggestions.append({ name.to_string(), partial_text.length(), GUI::AutocompleteProvider::CompletionKind::Identifier });
  144. }
  145. }
  146. if (target_scope.is_empty()) {
  147. for (auto& preprocessor_name : document.parser().preprocessor_definitions().keys()) {
  148. if (preprocessor_name.starts_with(partial_text)) {
  149. suggestions.append({ preprocessor_name.to_string(), partial_text.length(), GUI::AutocompleteProvider::CompletionKind::PreprocessorDefinition });
  150. }
  151. }
  152. }
  153. return suggestions;
  154. }
  155. String CppComprehensionEngine::scope_of_name_or_identifier(const ASTNode& node) const
  156. {
  157. const Name* name = nullptr;
  158. if (node.is_name()) {
  159. name = reinterpret_cast<const Name*>(&node);
  160. } else if (node.is_identifier()) {
  161. auto* parent = node.parent();
  162. if (!(parent && parent->is_name()))
  163. return {};
  164. name = reinterpret_cast<const Name*>(parent);
  165. } else {
  166. return String::empty();
  167. }
  168. VERIFY(name->is_name());
  169. Vector<StringView> scope_parts;
  170. for (auto& scope_part : name->m_scope) {
  171. scope_parts.append(scope_part.m_name);
  172. }
  173. return String::join("::", scope_parts);
  174. }
  175. Vector<GUI::AutocompleteProvider::Entry> CppComprehensionEngine::autocomplete_property(const DocumentData& document, const MemberExpression& parent, const String partial_text) const
  176. {
  177. auto type = type_of(document, *parent.m_object);
  178. if (type.is_null()) {
  179. dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "Could not infer type of object");
  180. return {};
  181. }
  182. Vector<GUI::AutocompleteProvider::Entry> suggestions;
  183. for (auto& prop : properties_of_type(document, type)) {
  184. if (prop.name.starts_with(partial_text)) {
  185. suggestions.append({ prop.name, partial_text.length(), GUI::AutocompleteProvider::CompletionKind::Identifier });
  186. }
  187. }
  188. return suggestions;
  189. }
  190. bool CppComprehensionEngine::is_property(const ASTNode& node) const
  191. {
  192. if (!node.parent()->is_member_expression())
  193. return false;
  194. auto& parent = (MemberExpression&)(*node.parent());
  195. return parent.m_property.ptr() == &node;
  196. }
  197. bool CppComprehensionEngine::is_empty_property(const DocumentData& document, const ASTNode& node, const Position& autocomplete_position) const
  198. {
  199. if (node.parent() == nullptr)
  200. return false;
  201. if (!node.parent()->is_member_expression())
  202. return false;
  203. auto previous_token = document.parser().token_at(autocomplete_position);
  204. if (!previous_token.has_value())
  205. return false;
  206. return previous_token.value().type() == Token::Type::Dot;
  207. }
  208. String CppComprehensionEngine::type_of_property(const DocumentData& document, const Identifier& identifier) const
  209. {
  210. auto& parent = (const MemberExpression&)(*identifier.parent());
  211. auto properties = properties_of_type(document, type_of(document, *parent.m_object));
  212. for (auto& prop : properties) {
  213. if (prop.name == identifier.m_name)
  214. return prop.type->m_name->full_name();
  215. }
  216. return {};
  217. }
  218. String CppComprehensionEngine::type_of_variable(const Identifier& identifier) const
  219. {
  220. const ASTNode* current = &identifier;
  221. while (current) {
  222. for (auto& decl : current->declarations()) {
  223. if (decl.is_variable_or_parameter_declaration()) {
  224. auto& var_or_param = (VariableOrParameterDeclaration&)decl;
  225. if (var_or_param.m_name == identifier.m_name) {
  226. return var_or_param.m_type->m_name->full_name();
  227. }
  228. }
  229. }
  230. current = current->parent();
  231. }
  232. return {};
  233. }
  234. String CppComprehensionEngine::type_of(const DocumentData& document, const Expression& expression) const
  235. {
  236. if (expression.is_member_expression()) {
  237. auto& member_expression = (const MemberExpression&)expression;
  238. if (member_expression.m_property->is_identifier())
  239. return type_of_property(document, static_cast<const Identifier&>(*member_expression.m_property));
  240. return {};
  241. }
  242. const Identifier* identifier { nullptr };
  243. if (expression.is_name()) {
  244. identifier = static_cast<const Name&>(expression).m_name.ptr();
  245. } else if (expression.is_identifier()) {
  246. identifier = &static_cast<const Identifier&>(expression);
  247. } else {
  248. dbgln("expected identifier or name, got: {}", expression.class_name());
  249. VERIFY_NOT_REACHED(); // TODO
  250. }
  251. VERIFY(identifier);
  252. if (is_property(*identifier))
  253. return type_of_property(document, *identifier);
  254. return type_of_variable(*identifier);
  255. }
  256. Vector<CppComprehensionEngine::PropertyInfo> CppComprehensionEngine::properties_of_type(const DocumentData& document, const String& type) const
  257. {
  258. auto declarations = get_global_declarations_including_headers(document, RecurseIntoScopes::Yes);
  259. Vector<PropertyInfo> properties;
  260. for (auto& decl : declarations) {
  261. if (!decl.is_struct_or_class())
  262. continue;
  263. auto& struct_or_class = (StructOrClassDeclaration&)decl;
  264. if (struct_or_class.m_name != type)
  265. continue;
  266. for (auto& member : struct_or_class.m_members) {
  267. properties.append({ member.m_name, member.m_type });
  268. }
  269. }
  270. return properties;
  271. }
  272. NonnullRefPtrVector<Declaration> CppComprehensionEngine::get_global_declarations_including_headers(const DocumentData& document, RecurseIntoScopes recurse_into_scopes) const
  273. {
  274. NonnullRefPtrVector<Declaration> declarations;
  275. for (auto& decl : document.m_declarations_from_headers)
  276. declarations.append(*decl);
  277. declarations.append(get_global_declarations(document, recurse_into_scopes));
  278. return declarations;
  279. }
  280. NonnullRefPtrVector<Declaration> CppComprehensionEngine::get_global_declarations(const DocumentData& document, RecurseIntoScopes recurse_into_scopes) const
  281. {
  282. if (recurse_into_scopes == RecurseIntoScopes::Yes)
  283. return get_declarations_recursive(*document.parser().root_node());
  284. return document.parser().root_node()->declarations();
  285. }
  286. NonnullRefPtrVector<Declaration> CppComprehensionEngine::get_declarations_recursive(const ASTNode& node) const
  287. {
  288. NonnullRefPtrVector<Declaration> declarations;
  289. for (auto& decl : node.declarations()) {
  290. declarations.append(decl);
  291. if (decl.is_namespace()) {
  292. declarations.append(get_declarations_recursive(decl));
  293. }
  294. if (decl.is_struct_or_class()) {
  295. for (auto& member_decl : static_cast<StructOrClassDeclaration&>(decl).declarations()) {
  296. declarations.append(member_decl);
  297. }
  298. }
  299. }
  300. return declarations;
  301. }
  302. String CppComprehensionEngine::document_path_from_include_path(const StringView& include_path) const
  303. {
  304. static Regex<PosixExtended> library_include("<(.+)>");
  305. static Regex<PosixExtended> user_defined_include("\"(.+)\"");
  306. auto document_path_for_library_include = [&](const StringView& include_path) -> String {
  307. RegexResult result;
  308. if (!library_include.search(include_path, result))
  309. return {};
  310. auto path = result.capture_group_matches.at(0).at(0).view.u8view();
  311. return String::formatted("/usr/include/{}", path);
  312. };
  313. auto document_path_for_user_defined_include = [&](const StringView& include_path) -> String {
  314. RegexResult result;
  315. if (!user_defined_include.search(include_path, result))
  316. return {};
  317. return result.capture_group_matches.at(0).at(0).view.u8view();
  318. };
  319. auto result = document_path_for_library_include(include_path);
  320. if (result.is_null())
  321. result = document_path_for_user_defined_include(include_path);
  322. return result;
  323. }
  324. void CppComprehensionEngine::on_edit(const String& file)
  325. {
  326. set_document_data(file, create_document_data_for(file));
  327. }
  328. void CppComprehensionEngine::file_opened([[maybe_unused]] const String& file)
  329. {
  330. get_or_create_document_data(file);
  331. }
  332. Optional<GUI::AutocompleteProvider::ProjectLocation> CppComprehensionEngine::find_declaration_of(const String& filename, const GUI::TextPosition& identifier_position)
  333. {
  334. const auto* document_ptr = get_or_create_document_data(filename);
  335. if (!document_ptr)
  336. return {};
  337. const auto& document = *document_ptr;
  338. auto node = document.parser().node_at(Cpp::Position { identifier_position.line(), identifier_position.column() });
  339. if (!node) {
  340. dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "no node at position {}:{}", identifier_position.line(), identifier_position.column());
  341. return {};
  342. }
  343. auto decl = find_declaration_of(document, *node);
  344. if (decl)
  345. return GUI::AutocompleteProvider::ProjectLocation { decl->filename(), decl->start().line, decl->start().column };
  346. return find_preprocessor_definition(document, identifier_position);
  347. }
  348. Optional<GUI::AutocompleteProvider::ProjectLocation> CppComprehensionEngine::find_preprocessor_definition(const DocumentData& document, const GUI::TextPosition& text_position)
  349. {
  350. Position cpp_position { text_position.line(), text_position.column() };
  351. // Search for a replaced preprocessor token that intersects with text_position
  352. for (auto& replaced_token : document.parser().replaced_preprocessor_tokens()) {
  353. if (replaced_token.token.start() > cpp_position)
  354. continue;
  355. if (replaced_token.token.end() < cpp_position)
  356. continue;
  357. return GUI::AutocompleteProvider::ProjectLocation { replaced_token.preprocessor_value.filename, replaced_token.preprocessor_value.line, replaced_token.preprocessor_value.column };
  358. }
  359. return {};
  360. }
  361. struct TargetDeclaration {
  362. enum Type {
  363. Variable,
  364. Type,
  365. Function,
  366. Property
  367. } type;
  368. String name;
  369. };
  370. static Optional<TargetDeclaration> get_target_declaration(const ASTNode& node)
  371. {
  372. if (!node.is_identifier()) {
  373. dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "node is not an identifier");
  374. return {};
  375. }
  376. String name = static_cast<const Identifier&>(node).m_name;
  377. if ((node.parent() && node.parent()->is_function_call()) || (node.parent()->is_name() && node.parent()->parent() && node.parent()->parent()->is_function_call())) {
  378. return TargetDeclaration { TargetDeclaration::Type::Function, name };
  379. }
  380. if ((node.parent() && node.parent()->is_type()) || (node.parent()->is_name() && node.parent()->parent() && node.parent()->parent()->is_type()))
  381. return TargetDeclaration { TargetDeclaration::Type::Type, name };
  382. if ((node.parent() && node.parent()->is_member_expression()))
  383. return TargetDeclaration { TargetDeclaration::Type::Property, name };
  384. return TargetDeclaration { TargetDeclaration::Type::Variable, name };
  385. }
  386. RefPtr<Declaration> CppComprehensionEngine::find_declaration_of(const DocumentData& document_data, const ASTNode& node) const
  387. {
  388. dbgln_if(CPP_LANGUAGE_SERVER_DEBUG, "find_declaration_of: {} ({})", document_data.parser().text_of_node(node), node.class_name());
  389. auto target_decl = get_target_declaration(node);
  390. if (!target_decl.has_value())
  391. return {};
  392. auto declarations = get_available_declarations(document_data, node, RecurseIntoScopes::Yes);
  393. for (auto& decl : declarations) {
  394. if (decl.is_function() && target_decl.value().type == TargetDeclaration::Function) {
  395. if (((Cpp::FunctionDeclaration&)decl).m_name == target_decl.value().name)
  396. return decl;
  397. }
  398. if (decl.is_variable_or_parameter_declaration() && target_decl.value().type == TargetDeclaration::Variable) {
  399. if (((Cpp::VariableOrParameterDeclaration&)decl).m_name == target_decl.value().name)
  400. return decl;
  401. }
  402. if (decl.is_struct_or_class() && target_decl.value().type == TargetDeclaration::Property) {
  403. // TODO: Also check that the type of the struct/class matches (not just the property name)
  404. for (auto& member : ((Cpp::StructOrClassDeclaration&)decl).m_members) {
  405. VERIFY(node.is_identifier());
  406. if (member.m_name == target_decl.value().name) {
  407. return member;
  408. }
  409. }
  410. }
  411. if (decl.is_struct_or_class() && target_decl.value().type == TargetDeclaration::Type) {
  412. if (((Cpp::StructOrClassDeclaration&)decl).m_name == target_decl.value().name)
  413. return decl;
  414. }
  415. }
  416. return {};
  417. }
  418. void CppComprehensionEngine::update_declared_symbols(DocumentData& document)
  419. {
  420. for (auto& include : document.preprocessor().included_paths()) {
  421. auto included_document = get_or_create_document_data(document_path_from_include_path(include));
  422. if (!included_document)
  423. continue;
  424. for (auto&& decl : get_global_declarations_including_headers(*included_document, RecurseIntoScopes::Yes))
  425. document.m_declarations_from_headers.set(move(decl));
  426. }
  427. Vector<GUI::AutocompleteProvider::Declaration> declarations;
  428. for (auto& decl : get_declarations_recursive(*document.parser().root_node())) {
  429. declarations.append({ decl.name(), { document.filename(), decl.start().line, decl.start().column }, type_of_declaration(decl), scope_of_declaration(decl) });
  430. }
  431. for (auto& definition : document.preprocessor().definitions()) {
  432. declarations.append({ definition.key, { document.filename(), definition.value.line, definition.value.column }, GUI::AutocompleteProvider::DeclarationType::PreprocessorDefinition, {} });
  433. }
  434. set_declarations_of_document(document.filename(), move(declarations));
  435. }
  436. GUI::AutocompleteProvider::DeclarationType CppComprehensionEngine::type_of_declaration(const Declaration& decl)
  437. {
  438. if (decl.is_struct())
  439. return GUI::AutocompleteProvider::DeclarationType::Struct;
  440. if (decl.is_class())
  441. return GUI::AutocompleteProvider::DeclarationType::Class;
  442. if (decl.is_function())
  443. return GUI::AutocompleteProvider::DeclarationType::Function;
  444. if (decl.is_variable_declaration())
  445. return GUI::AutocompleteProvider::DeclarationType::Variable;
  446. if (decl.is_namespace())
  447. return GUI::AutocompleteProvider::DeclarationType::Namespace;
  448. if (decl.is_member())
  449. return GUI::AutocompleteProvider::DeclarationType::Member;
  450. return GUI::AutocompleteProvider::DeclarationType::Variable;
  451. }
  452. OwnPtr<CppComprehensionEngine::DocumentData> CppComprehensionEngine::create_document_data(String&& text, const String& filename)
  453. {
  454. auto document_data = make<DocumentData>();
  455. document_data->m_filename = filename;
  456. document_data->m_text = move(text);
  457. document_data->m_preprocessor = make<Preprocessor>(document_data->m_filename, document_data->text());
  458. document_data->preprocessor().set_ignore_unsupported_keywords(true);
  459. document_data->preprocessor().process();
  460. Preprocessor::Definitions all_definitions;
  461. for (auto item : document_data->preprocessor().definitions())
  462. all_definitions.set(move(item.key), move(item.value));
  463. for (auto include : document_data->preprocessor().included_paths()) {
  464. auto included_document = get_or_create_document_data(document_path_from_include_path(include));
  465. if (!included_document)
  466. continue;
  467. for (auto item : included_document->parser().preprocessor_definitions())
  468. all_definitions.set(move(item.key), move(item.value));
  469. }
  470. document_data->m_parser = make<Parser>(document_data->preprocessor().processed_text(), filename, move(all_definitions));
  471. auto root = document_data->parser().parse();
  472. if constexpr (CPP_LANGUAGE_SERVER_DEBUG)
  473. root->dump();
  474. update_declared_symbols(*document_data);
  475. return document_data;
  476. }
  477. String CppComprehensionEngine::scope_of_declaration(const Declaration& decl) const
  478. {
  479. auto parent = decl.parent();
  480. if (!parent)
  481. return {};
  482. if (!parent->is_declaration())
  483. return {};
  484. auto& parent_decl = static_cast<Declaration&>(*parent);
  485. auto parent_scope = scope_of_declaration(parent_decl);
  486. String containing_scope;
  487. if (parent_decl.is_namespace())
  488. containing_scope = static_cast<NamespaceDeclaration&>(parent_decl).m_name;
  489. if (parent_decl.is_struct_or_class())
  490. containing_scope = static_cast<StructOrClassDeclaration&>(parent_decl).name();
  491. if (parent_scope.is_null())
  492. return containing_scope;
  493. return String::formatted("{}::{}", parent_scope, containing_scope);
  494. }
  495. }