[Lldb-commits] [lldb] r349360 - [Clang AST Context] Add a few helper functions.

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Mon Dec 17 08:15:13 PST 2018


Author: zturner
Date: Mon Dec 17 08:15:13 2018
New Revision: 349360

URL: http://llvm.org/viewvc/llvm-project?rev=349360&view=rev
Log:
[Clang AST Context] Add a few helper functions.

The first one allows us to add an enumerator to an enum if we
already have an APSInt, since ultimately the implementation just
constructs one anyway.  The second is just a general utility
function to covert a CompilerType to a clang::TagDecl.

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

Modified: lldb/trunk/include/lldb/Symbol/ClangASTContext.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTContext.h?rev=349360&r1=349359&r2=349360&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTContext.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTContext.h Mon Dec 17 08:15:13 2018
@@ -24,6 +24,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/ExternalASTMerger.h"
 #include "clang/AST/TemplateBase.h"
+#include "llvm/ADT/APSInt.h"
 #include "llvm/ADT/SmallVector.h"
 
 #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
@@ -902,6 +903,9 @@ public:
   clang::EnumConstantDecl *AddEnumerationValueToEnumerationType(
       const CompilerType &enum_type, const Declaration &decl, const char *name,
       int64_t enum_value, uint32_t enum_value_bit_size);
+  clang::EnumConstantDecl *AddEnumerationValueToEnumerationType(
+      const CompilerType &enum_type, const Declaration &decl, const char *name,
+      const llvm::APSInt &value);
 
   CompilerType GetEnumerationIntegerType(lldb::opaque_compiler_type_t type);
 

Modified: lldb/trunk/include/lldb/Symbol/ClangUtil.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangUtil.h?rev=349360&r1=349359&r2=349360&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangUtil.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangUtil.h Mon Dec 17 08:15:13 2018
@@ -16,6 +16,10 @@
 
 #include "lldb/Symbol/CompilerType.h"
 
+namespace clang {
+class TagDecl;
+}
+
 namespace lldb_private {
 struct ClangUtil {
   static bool IsClangType(const CompilerType &ct);
@@ -25,6 +29,8 @@ struct ClangUtil {
   static clang::QualType GetCanonicalQualType(const CompilerType &ct);
 
   static CompilerType RemoveFastQualifiers(const CompilerType &ct);
+
+  static clang::TagDecl *GetAsTagDecl(const CompilerType &type);
 };
 }
 

Modified: lldb/trunk/source/Symbol/ClangASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTContext.cpp?rev=349360&r1=349359&r2=349360&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTContext.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTContext.cpp Mon Dec 17 08:15:13 2018
@@ -7827,11 +7827,7 @@ clang::RecordDecl *ClangASTContext::GetA
 }
 
 clang::TagDecl *ClangASTContext::GetAsTagDecl(const CompilerType &type) {
-  clang::QualType qual_type = ClangUtil::GetCanonicalQualType(type);
-  if (qual_type.isNull())
-    return nullptr;
-  else
-    return qual_type->getAsTagDecl();
+  return ClangUtil::GetAsTagDecl(type);
 }
 
 clang::TypedefNameDecl *
@@ -8937,7 +8933,7 @@ bool ClangASTContext::CompleteTagDeclara
 
 clang::EnumConstantDecl *ClangASTContext::AddEnumerationValueToEnumerationType(
     const CompilerType &enum_type, const Declaration &decl, const char *name,
-    int64_t enum_value, uint32_t enum_value_bit_size) {
+    const llvm::APSInt &value) {
 
   if (!enum_type || ConstString(name).IsEmpty())
     return nullptr;
@@ -8950,14 +8946,9 @@ clang::EnumConstantDecl *ClangASTContext
   if (!enum_opaque_compiler_type)
     return nullptr;
 
-  CompilerType underlying_type =
-      GetEnumerationIntegerType(enum_type.GetOpaqueQualType());
-
   clang::QualType enum_qual_type(
       GetCanonicalQualType(enum_opaque_compiler_type));
 
-  bool is_signed = false;
-  underlying_type.IsIntegerType(is_signed);
   const clang::Type *clang_type = enum_qual_type.getTypePtr();
 
   if (!clang_type)
@@ -8968,12 +8959,10 @@ clang::EnumConstantDecl *ClangASTContext
   if (!enutype)
     return nullptr;
 
-  llvm::APSInt enum_llvm_apsint(enum_value_bit_size, is_signed);
-  enum_llvm_apsint = enum_value;
   clang::EnumConstantDecl *enumerator_decl = clang::EnumConstantDecl::Create(
       *getASTContext(), enutype->getDecl(), clang::SourceLocation(),
       name ? &getASTContext()->Idents.get(name) : nullptr, // Identifier
-      clang::QualType(enutype, 0), nullptr, enum_llvm_apsint);
+      clang::QualType(enutype, 0), nullptr, value);
 
   if (!enumerator_decl)
     return nullptr;
@@ -8987,6 +8976,20 @@ clang::EnumConstantDecl *ClangASTContext
   return enumerator_decl;
 }
 
+clang::EnumConstantDecl *ClangASTContext::AddEnumerationValueToEnumerationType(
+    const CompilerType &enum_type, const Declaration &decl, const char *name,
+    int64_t enum_value, uint32_t enum_value_bit_size) {
+  CompilerType underlying_type =
+      GetEnumerationIntegerType(enum_type.GetOpaqueQualType());
+  bool is_signed = false;
+  underlying_type.IsIntegerType(is_signed);
+
+  llvm::APSInt value(enum_value_bit_size, is_signed);
+  value = enum_value;
+
+  return AddEnumerationValueToEnumerationType(enum_type, decl, name, value);
+}
+
 CompilerType
 ClangASTContext::GetEnumerationIntegerType(lldb::opaque_compiler_type_t type) {
   clang::QualType enum_qual_type(GetCanonicalQualType(type));

Modified: lldb/trunk/source/Symbol/ClangUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangUtil.cpp?rev=349360&r1=349359&r2=349360&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangUtil.cpp (original)
+++ lldb/trunk/source/Symbol/ClangUtil.cpp Mon Dec 17 08:15:13 2018
@@ -48,3 +48,11 @@ CompilerType ClangUtil::RemoveFastQualif
   qual_type.removeLocalFastQualifiers();
   return CompilerType(ct.GetTypeSystem(), qual_type.getAsOpaquePtr());
 }
+
+clang::TagDecl *ClangUtil::GetAsTagDecl(const CompilerType &type) {
+  clang::QualType qual_type = ClangUtil::GetCanonicalQualType(type);
+  if (qual_type.isNull())
+    return nullptr;
+
+  return qual_type->getAsTagDecl();
+}




More information about the lldb-commits mailing list