blob: 130fa6c5469a527d070147a532584bd47e99085b [file] [log] [blame]
Michael Forster284fb5a2022-04-25 00:41:14 -07001// Part of the Crubit project, under the Apache License v2.0 with LLVM
2// Exceptions. See /LICENSE for license information.
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#include "rs_bindings_from_cc/importers/namespace.h"
6
Lukasz Anforowiczcec7a8a2022-04-27 10:24:51 -07007#include "absl/strings/match.h"
Michael Forster284fb5a2022-04-25 00:41:14 -07008
9namespace crubit {
10
11std::optional<IR::Item> NamespaceDeclImporter::Import(
12 clang::NamespaceDecl* namespace_decl) {
Michael Forster284fb5a2022-04-25 00:41:14 -070013
14 // TODO(rosica) In order to fully enable namespaces we first need to ensure
15 // that each decl Item contains information on its namespace parents.
16 if (!absl::StrContains(namespace_decl->getQualifiedNameAsString(),
17 "test_namespace_bindings")) {
18 return ictx_.ImportUnsupportedItem(namespace_decl,
19 "Namespaces are not supported yet");
20 }
21
Michael Forster284fb5a2022-04-25 00:41:14 -070022 if (namespace_decl->isAnonymousNamespace()) {
23 return ictx_.ImportUnsupportedItem(
24 namespace_decl, "Anonymous namespaces are not supported yet");
25 }
26
27 ictx_.ImportDeclsFromDeclContext(namespace_decl);
28 auto identifier = ictx_.GetTranslatedIdentifier(namespace_decl);
29 CRUBIT_CHECK(identifier.has_value());
30 auto item_ids = ictx_.GetItemIdsInSourceOrder(namespace_decl);
31 return Namespace{
32 .name = *identifier,
33 .id = GenerateItemId(namespace_decl),
Rosica Dejanovska6efd17f2022-05-11 08:09:57 -070034 .canonical_namespace_id =
35 GenerateItemId(namespace_decl->getCanonicalDecl()),
Michael Forster284fb5a2022-04-25 00:41:14 -070036 .owning_target = ictx_.GetOwningTarget(namespace_decl),
37 .child_item_ids = std::move(item_ids),
Rosica Dejanovskae91d2992022-05-05 05:31:39 -070038 .enclosing_namespace_id = GetEnclosingNamespaceId(namespace_decl),
Michael Forster284fb5a2022-04-25 00:41:14 -070039 };
40}
41
42} // namespace crubit