[Lldb-commits] [lldb] 0a4daff - [lldb][NFC] Remove redundant ClangASTContext constructor that takes ArchSpec

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Wed Jan 8 00:36:58 PST 2020


Author: Raphael Isemann
Date: 2020-01-08T09:35:46+01:00
New Revision: 0a4daff6e26f276dd92e777b597e94e093ae018d

URL: https://github.com/llvm/llvm-project/commit/0a4daff6e26f276dd92e777b597e94e093ae018d
DIFF: https://github.com/llvm/llvm-project/commit/0a4daff6e26f276dd92e777b597e94e093ae018d.diff

LOG: [lldb][NFC] Remove redundant ClangASTContext constructor that takes ArchSpec

ArchSpec has a superset of the information of llvm::Triple but the ClangASTContext
just uses the Triple part of it. This deletes the ArchSpec constructor and all
the code creating ArchSpecs and instead just uses the llvm::Triple constructor
for ClangASTContext.

Added: 
    

Modified: 
    lldb/include/lldb/Symbol/ClangASTContext.h
    lldb/source/Symbol/ClangASTContext.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Symbol/ClangASTContext.h b/lldb/include/lldb/Symbol/ClangASTContext.h
index 9e8d301fd3f7..3cad8414b128 100644
--- a/lldb/include/lldb/Symbol/ClangASTContext.h
+++ b/lldb/include/lldb/Symbol/ClangASTContext.h
@@ -55,9 +55,13 @@ class ClangASTContext : public TypeSystem {
   bool isA(const void *ClassID) const override { return ClassID == &ID; }
   static bool classof(const TypeSystem *ts) { return ts->isA(&ID); }
 
-  // Constructors and Destructors
+  /// Constructs a ClangASTContext with an ASTContext using the given triple.
+  ///
+  /// \param triple The llvm::Triple used for the ASTContext. The triple defines
+  ///               certain characteristics of the ASTContext and its types
+  ///               (e.g., whether certain primitive types exist or what their
+  ///               signedness is).
   explicit ClangASTContext(llvm::Triple triple = llvm::Triple());
-  explicit ClangASTContext(ArchSpec arch);
 
   /// Constructs a ClangASTContext that uses an existing ASTContext internally.
   /// Useful when having an existing ASTContext created by Clang.
@@ -969,7 +973,7 @@ class ClangASTContext : public TypeSystem {
 
 class ClangASTContextForExpressions : public ClangASTContext {
 public:
-  ClangASTContextForExpressions(Target &target, ArchSpec arch);
+  ClangASTContextForExpressions(Target &target, llvm::Triple triple);
 
   ~ClangASTContextForExpressions() override = default;
 

diff  --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp
index 314aaa83d4e6..c846e410acfa 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -507,13 +507,6 @@ ClangASTContext::ClangASTContext(llvm::Triple target_triple) {
   CreateASTContext();
 }
 
-ClangASTContext::ClangASTContext(ArchSpec arch) {
-  SetTargetTriple(arch.GetTriple().str());
-  // The caller didn't pass an ASTContext so create a new one for this
-  // ClangASTContext.
-  CreateASTContext();
-}
-
 ClangASTContext::ClangASTContext(ASTContext &existing_ctxt) {
   SetTargetTriple(existing_ctxt.getTargetInfo().getTriple().str());
 
@@ -548,29 +541,25 @@ lldb::TypeSystemSP ClangASTContext::CreateInstance(lldb::LanguageType language,
   if (!arch.IsValid())
     return lldb::TypeSystemSP();
 
-  ArchSpec fixed_arch = arch;
+  llvm::Triple triple = arch.GetTriple();
   // LLVM wants this to be set to iOS or MacOSX; if we're working on
   // a bare-boards type image, change the triple for llvm's benefit.
-  if (fixed_arch.GetTriple().getVendor() == llvm::Triple::Apple &&
-      fixed_arch.GetTriple().getOS() == llvm::Triple::UnknownOS) {
-    if (fixed_arch.GetTriple().getArch() == llvm::Triple::arm ||
-        fixed_arch.GetTriple().getArch() == llvm::Triple::aarch64 ||
-        fixed_arch.GetTriple().getArch() == llvm::Triple::aarch64_32 ||
-        fixed_arch.GetTriple().getArch() == llvm::Triple::thumb) {
-      fixed_arch.GetTriple().setOS(llvm::Triple::IOS);
+  if (triple.getVendor() == llvm::Triple::Apple &&
+      triple.getOS() == llvm::Triple::UnknownOS) {
+    if (triple.getArch() == llvm::Triple::arm ||
+        triple.getArch() == llvm::Triple::aarch64 ||
+        triple.getArch() == llvm::Triple::aarch64_32 ||
+        triple.getArch() == llvm::Triple::thumb) {
+      triple.setOS(llvm::Triple::IOS);
     } else {
-      fixed_arch.GetTriple().setOS(llvm::Triple::MacOSX);
+      triple.setOS(llvm::Triple::MacOSX);
     }
   }
 
-  if (module) {
-    std::shared_ptr<ClangASTContext> ast_sp(new ClangASTContext(fixed_arch));
-    return ast_sp;
-  } else if (target && target->IsValid()) {
-    std::shared_ptr<ClangASTContextForExpressions> ast_sp(
-        new ClangASTContextForExpressions(*target, fixed_arch));
-    return ast_sp;
-  }
+  if (module)
+    return std::make_shared<ClangASTContext>(triple);
+  else if (target && target->IsValid())
+    return std::make_shared<ClangASTContextForExpressions>(*target, triple);
   return lldb::TypeSystemSP();
 }
 
@@ -9255,9 +9244,9 @@ ClangASTContext::DeclContextGetClangASTContext(const CompilerDeclContext &dc) {
   return nullptr;
 }
 
-ClangASTContextForExpressions::ClangASTContextForExpressions(Target &target,
-                                                             ArchSpec arch)
-    : ClangASTContext(arch), m_target_wp(target.shared_from_this()),
+ClangASTContextForExpressions::ClangASTContextForExpressions(
+    Target &target, llvm::Triple triple)
+    : ClangASTContext(triple), m_target_wp(target.shared_from_this()),
       m_persistent_variables(new ClangPersistentVariables) {
   m_scratch_ast_source_up.reset(new ClangASTSource(
       target.shared_from_this(), target.GetClangASTImporter()));


        


More information about the lldb-commits mailing list