blob: 7a5bd4116834afcba47361aeedae64eb5a5c02a0 [file] [log] [blame]
// Part of the Crubit project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "rs_bindings_from_cc/importers/namespace.h"
#include "absl/log/check.h"
#include "absl/strings/match.h"
namespace crubit {
std::optional<IR::Item> NamespaceDeclImporter::Import(
clang::NamespaceDecl* namespace_decl) {
if (namespace_decl->isAnonymousNamespace()) {
return ictx_.ImportUnsupportedItem(
namespace_decl, "Anonymous namespaces are not supported yet");
}
absl::StatusOr<Identifier> identifier =
ictx_.GetTranslatedIdentifier(namespace_decl);
if (!identifier.ok()) {
return ictx_.ImportUnsupportedItem(
namespace_decl, absl::StrCat("Namespace name is not supported: ",
identifier.status().message()));
}
ictx_.ImportDeclsFromDeclContext(namespace_decl);
auto item_ids = ictx_.GetItemIdsInSourceOrder(namespace_decl);
return Namespace{
.name = *identifier,
.id = GenerateItemId(namespace_decl),
.canonical_namespace_id =
GenerateItemId(namespace_decl->getCanonicalDecl()),
.owning_target = ictx_.GetOwningTarget(namespace_decl),
.child_item_ids = std::move(item_ids),
.enclosing_namespace_id = GetEnclosingNamespaceId(namespace_decl),
.is_inline = namespace_decl->isInline()};
}
} // namespace crubit