Michael Forster | 284fb5a | 2022-04-25 00:41:14 -0700 | [diff] [blame] | 1 | // 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 Anforowicz | cec7a8a | 2022-04-27 10:24:51 -0700 | [diff] [blame] | 7 | #include "absl/strings/match.h" |
Michael Forster | 284fb5a | 2022-04-25 00:41:14 -0700 | [diff] [blame] | 8 | |
| 9 | namespace crubit { |
| 10 | |
| 11 | std::optional<IR::Item> NamespaceDeclImporter::Import( |
| 12 | clang::NamespaceDecl* namespace_decl) { |
Michael Forster | 284fb5a | 2022-04-25 00:41:14 -0700 | [diff] [blame] | 13 | |
| 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 Forster | 284fb5a | 2022-04-25 00:41:14 -0700 | [diff] [blame] | 22 | 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 Dejanovska | 6efd17f | 2022-05-11 08:09:57 -0700 | [diff] [blame] | 34 | .canonical_namespace_id = |
| 35 | GenerateItemId(namespace_decl->getCanonicalDecl()), |
Michael Forster | 284fb5a | 2022-04-25 00:41:14 -0700 | [diff] [blame] | 36 | .owning_target = ictx_.GetOwningTarget(namespace_decl), |
| 37 | .child_item_ids = std::move(item_ids), |
Rosica Dejanovska | e91d299 | 2022-05-05 05:31:39 -0700 | [diff] [blame] | 38 | .enclosing_namespace_id = GetEnclosingNamespaceId(namespace_decl), |
Michael Forster | 284fb5a | 2022-04-25 00:41:14 -0700 | [diff] [blame] | 39 | }; |
| 40 | } |
| 41 | |
| 42 | } // namespace crubit |