[Lldb-commits] [lldb] r247085 - ExpressionVariable now uses llvm::cast() instead of As...() for RTTI.

Sean Callanan via lldb-commits lldb-commits at lists.llvm.org
Tue Sep 8 15:23:39 PDT 2015


Author: spyffe
Date: Tue Sep  8 17:23:39 2015
New Revision: 247085

URL: http://llvm.org/viewvc/llvm-project?rev=247085&view=rev
Log:
ExpressionVariable now uses llvm::cast() instead of As...() for RTTI.
As part of our overall switch from hand-rolling RTTI to using LLVM-compatible
methods, I've done the same for ExpressionVariable.  The main documentation for
how to do this is in TypeSystem.h, so I've simply referred to that.

Modified:
    lldb/trunk/include/lldb/Expression/ExpressionVariable.h
    lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
    lldb/trunk/source/Expression/Materializer.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp
    lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h

Modified: lldb/trunk/include/lldb/Expression/ExpressionVariable.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Expression/ExpressionVariable.h?rev=247085&r1=247084&r2=247085&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Expression/ExpressionVariable.h (original)
+++ lldb/trunk/include/lldb/Expression/ExpressionVariable.h Tue Sep  8 17:23:39 2015
@@ -33,6 +33,23 @@ class ExpressionVariable :
     public std::enable_shared_from_this<ExpressionVariable>
 {
 public:
+    //----------------------------------------------------------------------
+    // See TypeSystem.h for how to add subclasses to this.
+    //----------------------------------------------------------------------
+    enum LLVMCastKind {
+        eKindClang,
+        eKindSwift,
+        eKindGo,
+        kNumKinds
+    };
+    
+    LLVMCastKind getKind() const { return m_kind; }
+    
+    ExpressionVariable(LLVMCastKind kind) :
+        m_kind(kind)
+    {
+    }
+    
     size_t
     GetByteSize ()
     {
@@ -51,10 +68,6 @@ public:
         return m_frozen_sp;
     }
     
-    virtual ClangExpressionVariable *AsClangExpressionVariable() {
-        return nullptr;
-    }
-    
     uint8_t *GetValueBytes();
     
     void
@@ -135,6 +148,7 @@ public:
     // these should be private
     lldb::ValueObjectSP m_frozen_sp;
     lldb::ValueObjectSP m_live_sp;
+    LLVMCastKind        m_kind;
 };
     
 //----------------------------------------------------------------------

Modified: lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp?rev=247085&r1=247084&r2=247085&view=diff
==============================================================================
--- lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp (original)
+++ lldb/trunk/source/Expression/ClangExpressionDeclMap.cpp Tue Sep  8 17:23:39 2015
@@ -136,7 +136,7 @@ ClangExpressionDeclMap::DidParse()
         {
             ExpressionVariableSP var_sp(m_found_entities.GetVariableAtIndex(entity_index));
             if (var_sp)
-                var_sp->AsClangExpressionVariable()->DisableParserVars(GetParserID());
+                llvm::cast<ClangExpressionVariable>(var_sp.get())->DisableParserVars(GetParserID());
         }
 
         for (size_t pvar_index = 0, num_pvars = m_parser_vars->m_persistent_vars->GetSize();
@@ -145,7 +145,7 @@ ClangExpressionDeclMap::DidParse()
         {
             ExpressionVariableSP pvar_sp(m_parser_vars->m_persistent_vars->GetVariableAtIndex(pvar_index));
             if (pvar_sp)
-                pvar_sp->AsClangExpressionVariable()->DisableParserVars(GetParserID());
+                llvm::cast<ClangExpressionVariable>(pvar_sp.get())->DisableParserVars(GetParserID());
         }
 
         DisableParserVars();
@@ -350,11 +350,11 @@ ClangExpressionDeclMap::AddValueToStruct
     // We know entity->m_parser_vars is valid because we used a parser variable
     // to find it
 
-    ClangExpressionVariable::ParserVars *parser_vars = var->AsClangExpressionVariable()->GetParserVars(GetParserID());
+    ClangExpressionVariable::ParserVars *parser_vars = llvm::cast<ClangExpressionVariable>(var)->GetParserVars(GetParserID());
 
     parser_vars->m_llvm_value = value;
 
-    if (ClangExpressionVariable::JITVars *jit_vars = var->AsClangExpressionVariable()->GetJITVars(GetParserID()))
+    if (ClangExpressionVariable::JITVars *jit_vars = llvm::cast<ClangExpressionVariable>(var)->GetJITVars(GetParserID()))
     {
         // We already laid this out; do not touch
 
@@ -362,9 +362,9 @@ ClangExpressionDeclMap::AddValueToStruct
             log->Printf("Already placed at 0x%llx", (unsigned long long)jit_vars->m_offset);
     }
 
-    var->AsClangExpressionVariable()->EnableJITVars(GetParserID());
+    llvm::cast<ClangExpressionVariable>(var)->EnableJITVars(GetParserID());
 
-    ClangExpressionVariable::JITVars *jit_vars = var->AsClangExpressionVariable()->GetJITVars(GetParserID());
+    ClangExpressionVariable::JITVars *jit_vars = llvm::cast<ClangExpressionVariable>(var)->GetJITVars(GetParserID());
 
     jit_vars->m_alignment = alignment;
     jit_vars->m_size = size;
@@ -463,8 +463,8 @@ ClangExpressionDeclMap::GetStructElement
     if (!member_sp)
         return false;
 
-    ClangExpressionVariable::ParserVars *parser_vars = member_sp->AsClangExpressionVariable()->GetParserVars(GetParserID());
-    ClangExpressionVariable::JITVars *jit_vars = member_sp->AsClangExpressionVariable()->GetJITVars(GetParserID());
+    ClangExpressionVariable::ParserVars *parser_vars = llvm::cast<ClangExpressionVariable>(member_sp.get())->GetParserVars(GetParserID());
+    ClangExpressionVariable::JITVars *jit_vars = llvm::cast<ClangExpressionVariable>(member_sp.get())->GetJITVars(GetParserID());
 
     if (!parser_vars ||
         !jit_vars ||
@@ -1806,7 +1806,7 @@ ClangExpressionDeclMap::AddOneVariable(N
 {
     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS));
 
-    TypeFromUser user_type (pvar_sp->AsClangExpressionVariable()->GetTypeFromUser());
+    TypeFromUser user_type (llvm::cast<ClangExpressionVariable>(pvar_sp.get())->GetTypeFromUser());
 
     TypeFromParser parser_type (GuardedCopyType(user_type));
 
@@ -1819,8 +1819,8 @@ ClangExpressionDeclMap::AddOneVariable(N
 
     NamedDecl *var_decl = context.AddVarDecl(ClangASTContext::GetLValueReferenceType(parser_type));
 
-    pvar_sp->AsClangExpressionVariable()->EnableParserVars(GetParserID());
-    ClangExpressionVariable::ParserVars *parser_vars = pvar_sp->AsClangExpressionVariable()->GetParserVars(GetParserID());
+    llvm::cast<ClangExpressionVariable>(pvar_sp.get())->EnableParserVars(GetParserID());
+    ClangExpressionVariable::ParserVars *parser_vars = llvm::cast<ClangExpressionVariable>(pvar_sp.get())->GetParserVars(GetParserID());
     parser_vars->m_parser_type = parser_type;
     parser_vars->m_named_decl = var_decl;
     parser_vars->m_llvm_value = NULL;
@@ -1901,7 +1901,7 @@ ClangExpressionDeclMap::ResolveUnknownTy
     {
         ExpressionVariableSP entity = m_found_entities.GetVariableAtIndex(index);
 
-        ClangExpressionVariable::ParserVars *parser_vars = entity->AsClangExpressionVariable()->GetParserVars(GetParserID());
+        ClangExpressionVariable::ParserVars *parser_vars = llvm::cast<ClangExpressionVariable>(entity.get())->GetParserVars(GetParserID());
 
         if (entity->m_flags & ClangExpressionVariable::EVUnknownType)
         {

Modified: lldb/trunk/source/Expression/Materializer.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Expression/Materializer.cpp?rev=247085&r1=247084&r2=247085&view=diff
==============================================================================
--- lldb/trunk/source/Expression/Materializer.cpp (original)
+++ lldb/trunk/source/Expression/Materializer.cpp Tue Sep  8 17:23:39 2015
@@ -101,7 +101,7 @@ public:
         // Put the location of the spare memory into the live data of the ValueObject.
         
         m_persistent_variable_sp->m_live_sp = ValueObjectConstResult::Create (map.GetBestExecutionContextScope(),
-                                                                              m_persistent_variable_sp->AsClangExpressionVariable()->GetTypeFromUser(),
+                                                                              llvm::cast<ClangExpressionVariable>(m_persistent_variable_sp.get())->GetTypeFromUser(),
                                                                               m_persistent_variable_sp->GetName(),
                                                                               mem,
                                                                               eAddressTypeLoad,
@@ -232,7 +232,7 @@ public:
                 }
                 
                 m_persistent_variable_sp->m_live_sp = ValueObjectConstResult::Create (map.GetBestExecutionContextScope (),
-                                                                                      m_persistent_variable_sp->AsClangExpressionVariable()->GetTypeFromUser(),
+                                                                                      llvm::cast<ClangExpressionVariable>(m_persistent_variable_sp.get())->GetTypeFromUser(),
                                                                                       m_persistent_variable_sp->GetName(),
                                                                                       location,
                                                                                       eAddressTypeLoad,

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp?rev=247085&r1=247084&r2=247085&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.cpp Tue Sep  8 17:23:39 2015
@@ -24,7 +24,7 @@ using namespace clang;
 const char *g_clang_expression_variable_kind_name = "ClangExpressionVariable";
 
 ClangExpressionVariable::ClangExpressionVariable(ExecutionContextScope *exe_scope, lldb::ByteOrder byte_order, uint32_t addr_byte_size) :
-    ExpressionVariable(),
+    ExpressionVariable(LLVMCastKind::eKindClang),
     m_parser_vars(),
     m_jit_vars ()
 {
@@ -36,7 +36,7 @@ ClangExpressionVariable::ClangExpression
                                                   Value &value,
                                                   const ConstString &name,
                                                   uint16_t flags) :
-    ExpressionVariable(),
+    ExpressionVariable(LLVMCastKind::eKindClang),
     m_parser_vars(),
     m_jit_vars ()
 {
@@ -45,7 +45,7 @@ ClangExpressionVariable::ClangExpression
 }
 
 ClangExpressionVariable::ClangExpressionVariable (const lldb::ValueObjectSP &valobj_sp) :
-    ExpressionVariable(),
+    ExpressionVariable(LLVMCastKind::eKindClang),
     m_parser_vars(),
     m_jit_vars ()
 {

Modified: lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h?rev=247085&r1=247084&r2=247085&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h (original)
+++ lldb/trunk/source/Plugins/ExpressionParser/Clang/ClangExpressionVariable.h Tue Sep  8 17:23:39 2015
@@ -21,6 +21,8 @@
 #include <vector>
 
 // Other libraries and framework includes
+#include "llvm/Support/Casting.h"
+
 // Project includes
 #include "lldb/lldb-public.h"
 #include "lldb/Core/ClangForward.h"
@@ -71,12 +73,7 @@ public:
                              uint16_t flags = EVNone);
     
     ClangExpressionVariable(const lldb::ValueObjectSP &valobj_sp);
-    
-    ClangExpressionVariable *AsClangExpressionVariable() override
-    {
-        return this;
-    }
-    
+        
     //----------------------------------------------------------------------
     /// Utility functions for dealing with ExpressionVariableLists in Clang-specific ways
     //----------------------------------------------------------------------
@@ -98,7 +95,7 @@ public:
         {
             var_sp = list.GetVariableAtIndex(index);
             
-            if (ClangExpressionVariable *clang_var = var_sp->AsClangExpressionVariable())
+            if (ClangExpressionVariable *clang_var = llvm::dyn_cast<ClangExpressionVariable>(var_sp.get()))
             {
                 ClangExpressionVariable::ParserVars *parser_vars = clang_var->GetParserVars(parser_id);
                 
@@ -277,6 +274,14 @@ public:
     TypeFromUser
     GetTypeFromUser ();
     
+    //------------------------------------------------------------------
+    // llvm casting support
+    //------------------------------------------------------------------
+    static bool classof(const ExpressionVariable *ev)
+    {
+        return ev->getKind() == ExpressionVariable::eKindClang;
+    }
+    
     //----------------------------------------------------------------------
     /// Members
     //----------------------------------------------------------------------        




More information about the lldb-commits mailing list