clang_generator: Emit the correct enum names in SAPI variables

This is a follow up to fa9e6e8a5c.

Drive-by:
- Replace deprecated calls to `getNameAsString()`
PiperOrigin-RevId: 435287759
Change-Id: I81d8c2f93b1ab23c781421b114779b7a241e4a7e
This commit is contained in:
Christian Blichmann 2022-03-17 02:19:23 -07:00 committed by Copybara-Service
parent dedcdba6ee
commit 80b325aa40
2 changed files with 12 additions and 7 deletions

View File

@ -175,7 +175,7 @@ std::vector<std::string> GetNamespacePath(const clang::TypeDecl* decl) {
std::vector<std::string> comps;
for (const auto* ctx = decl->getDeclContext(); ctx; ctx = ctx->getParent()) {
if (const auto* nd = llvm::dyn_cast<clang::NamespaceDecl>(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<std::string> 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();

View File

@ -193,8 +193,14 @@ std::string MapQualType(const clang::ASTContext& context,
break;
}
} else if (const auto* enum_type = qual->getAs<clang::EnumType>()) {
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.