Skip to content

Commit

Permalink
[lldb][NFC] Simplify ClangASTContext::GetTranslationUnitDecl
Browse files Browse the repository at this point in the history
These two functions are just calling their equivalent function
in ASTContext and implicitly convert the result to a
DeclContext* (a parent class of TranslationUnitDecl). This leads
to the absurd situation that we had to cast the result of
GetTranslationUnitDecl to a TranslationUnitDecl*. The only reason
we did this implicit conversion to the parent class
was that the void* conversion for the CompilerDeclContext constructor
was sound (which otherwise would receive a Decl* pointer when
called with a TranslationUnitDecl*).

Now that the CompilerDeclContext constructor is type safe we can
properly implement these functions by actually returning the
right type. Also deletes the static inconvenience method that was
not used anywhere.
  • Loading branch information
Teemperor committed Dec 23, 2019
1 parent 5dca059 commit fecb122
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
6 changes: 2 additions & 4 deletions lldb/include/lldb/Symbol/ClangASTContext.h
Expand Up @@ -167,10 +167,8 @@ class ClangASTContext : public TypeSystem {

uint32_t GetPointerByteSize() override;

static clang::DeclContext *GetTranslationUnitDecl(clang::ASTContext *ast);

clang::DeclContext *GetTranslationUnitDecl() {
return GetTranslationUnitDecl(&getASTContext());
clang::TranslationUnitDecl *GetTranslationUnitDecl() {
return getASTContext().getTranslationUnitDecl();
}

static clang::Decl *CopyDecl(clang::ASTContext *dest_context,
Expand Down
8 changes: 1 addition & 7 deletions lldb/source/Symbol/ClangASTContext.cpp
Expand Up @@ -1153,11 +1153,6 @@ CompilerType ClangASTContext::GetCStringType(bool is_const) {
return CompilerType(this, ast.getPointerType(char_type).getAsOpaquePtr());
}

clang::DeclContext *
ClangASTContext::GetTranslationUnitDecl(clang::ASTContext *ast) {
return ast->getTranslationUnitDecl();
}

clang::Decl *ClangASTContext::CopyDecl(ASTContext *dst_ast, ASTContext *src_ast,
clang::Decl *source_decl) {
FileSystemOptions file_system_options;
Expand Down Expand Up @@ -1782,8 +1777,7 @@ clang::DeclContext *FindLCABetweenDecls(clang::DeclContext *left,
clang::UsingDirectiveDecl *ClangASTContext::CreateUsingDirectiveDeclaration(
clang::DeclContext *decl_ctx, clang::NamespaceDecl *ns_decl) {
if (decl_ctx != nullptr && ns_decl != nullptr) {
clang::TranslationUnitDecl *translation_unit =
(clang::TranslationUnitDecl *)GetTranslationUnitDecl(&getASTContext());
auto *translation_unit = getASTContext().getTranslationUnitDecl();
clang::UsingDirectiveDecl *using_decl = clang::UsingDirectiveDecl::Create(
getASTContext(), decl_ctx, clang::SourceLocation(),
clang::SourceLocation(), clang::NestedNameSpecifierLoc(),
Expand Down

0 comments on commit fecb122

Please sign in to comment.