From 80b325aa40b6001b6e3739470201f6ebdfcce8d9 Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Thu, 17 Mar 2022 02:19:23 -0700 Subject: [PATCH] clang_generator: Emit the correct enum names in SAPI variables This is a follow up to fa9e6e8a5cbf836303bd6b108051181d77b74275. Drive-by: - Replace deprecated calls to `getNameAsString()` PiperOrigin-RevId: 435287759 Change-Id: I81d8c2f93b1ab23c781421b114779b7a241e4a7e --- sandboxed_api/tools/clang_generator/emitter.cc | 9 ++++----- sandboxed_api/tools/clang_generator/types.cc | 10 ++++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/sandboxed_api/tools/clang_generator/emitter.cc b/sandboxed_api/tools/clang_generator/emitter.cc index b01e20f..2b6c644 100644 --- a/sandboxed_api/tools/clang_generator/emitter.cc +++ b/sandboxed_api/tools/clang_generator/emitter.cc @@ -175,7 +175,7 @@ std::vector GetNamespacePath(const clang::TypeDecl* decl) { std::vector comps; for (const auto* ctx = decl->getDeclContext(); ctx; ctx = ctx->getParent()) { if (const auto* nd = llvm::dyn_cast(ctx)) { - comps.push_back(nd->getNameAsString()); + comps.push_back(nd->getName().str()); } } std::reverse(comps.begin(), comps.end()); @@ -255,9 +255,8 @@ std::string GetParamName(const clang::ParmVarDecl* decl, int index) { std::string PrintFunctionPrototype(const clang::FunctionDecl* decl) { // TODO(cblichmann): Fix function pointers and anonymous namespace formatting - std::string out = - absl::StrCat(decl->getDeclaredReturnType().getAsString(), " ", - std::string(decl->getQualifiedNameAsString()), "("); + std::string out = absl::StrCat(decl->getDeclaredReturnType().getAsString(), + " ", decl->getQualifiedNameAsString(), "("); std::string print_separator; for (int i = 0; i < decl->getNumParams(); ++i) { @@ -277,7 +276,7 @@ std::string PrintFunctionPrototype(const clang::FunctionDecl* decl) { absl::StatusOr EmitFunction(const clang::FunctionDecl* decl) { std::string out; absl::StrAppend(&out, "\n// ", PrintFunctionPrototype(decl), "\n"); - const std::string function_name = decl->getNameAsString(); + auto function_name = ToStringView(decl->getName()); const clang::QualType return_type = decl->getDeclaredReturnType(); const bool returns_void = return_type->isVoidType(); diff --git a/sandboxed_api/tools/clang_generator/types.cc b/sandboxed_api/tools/clang_generator/types.cc index a05f9f8..1480c94 100644 --- a/sandboxed_api/tools/clang_generator/types.cc +++ b/sandboxed_api/tools/clang_generator/types.cc @@ -193,8 +193,14 @@ std::string MapQualType(const clang::ASTContext& context, break; } } else if (const auto* enum_type = qual->getAs()) { - return absl::StrCat("::sapi::v::IntBase<", - enum_type->getDecl()->getQualifiedNameAsString(), ">"); + clang::EnumDecl* enum_decl = enum_type->getDecl(); + std::string name; + if (auto* typedef_name = enum_decl->getTypedefNameForAnonDecl()) { + name = typedef_name->getQualifiedNameAsString(); + } else { + name = enum_decl->getQualifiedNameAsString(); + } + return absl::StrCat("::sapi::v::IntBase<", name, ">"); } else if (IsPointerOrReference(qual)) { // Remove "const" qualifier from a pointer or reference type's pointee, as // e.g. const pointers do not work well with SAPI.