xiaobai created this revision.
xiaobai added reviewers: jingham, clayborg.
Herald added a subscriber: jdoerfert.

When trying to ascertain what language a variable belongs to, just
checking the compilation unit is often not enough. In r364845 I added a way to
check for a variable's language type, but didn't put it in Variable itself.
Let's go ahead and put it in Variable.


https://reviews.llvm.org/D64042

Files:
  source/Core/ValueObject.cpp
  source/Symbol/Variable.cpp


Index: source/Symbol/Variable.cpp
===================================================================
--- source/Symbol/Variable.cpp
+++ source/Symbol/Variable.cpp
@@ -54,10 +54,18 @@
 Variable::~Variable() {}
 
 lldb::LanguageType Variable::GetLanguage() const {
-  SymbolContext variable_sc;
-  m_owner_scope->CalculateSymbolContext(&variable_sc);
-  if (variable_sc.comp_unit)
-    return variable_sc.comp_unit->GetLanguage();
+  lldb::LanguageType lang = m_mangled.GuessLanguage();
+  if (lang != lldb::eLanguageTypeUnknown)
+    return lang;
+
+  if (auto *func = m_owner_scope->CalculateSymbolContextFunction())
+    if ((lang = func->GetLanguage()) && lang != lldb::eLanguageTypeUnknown)
+      return lang;
+    else if (auto *comp_unit =
+                 m_owner_scope->CalculateSymbolContextCompileUnit())
+      if ((lang = func->GetLanguage()) && lang != lldb::eLanguageTypeUnknown)
+        return lang;
+
   return lldb::eLanguageTypeUnknown;
 }
 
Index: source/Core/ValueObject.cpp
===================================================================
--- source/Core/ValueObject.cpp
+++ source/Core/ValueObject.cpp
@@ -1703,16 +1703,7 @@
   if (!GetVariable() || !GetVariable()->IsArtificial())
     return false;
 
-  LanguageType lang = eLanguageTypeUnknown;
-  if (auto *sym_ctx_scope = GetSymbolContextScope()) {
-    if (auto *func = sym_ctx_scope->CalculateSymbolContextFunction())
-      lang = func->GetLanguage();
-    else if (auto *comp_unit =
-                 sym_ctx_scope->CalculateSymbolContextCompileUnit())
-      lang = comp_unit->GetLanguage();
-  }
-
-  if (auto *runtime = process->GetLanguageRuntime(lang))
+  if (auto *runtime = 
process->GetLanguageRuntime(GetVariable()->GetLanguage()))
     if (runtime->IsWhitelistedRuntimeValue(GetName()))
       return false;
 


Index: source/Symbol/Variable.cpp
===================================================================
--- source/Symbol/Variable.cpp
+++ source/Symbol/Variable.cpp
@@ -54,10 +54,18 @@
 Variable::~Variable() {}
 
 lldb::LanguageType Variable::GetLanguage() const {
-  SymbolContext variable_sc;
-  m_owner_scope->CalculateSymbolContext(&variable_sc);
-  if (variable_sc.comp_unit)
-    return variable_sc.comp_unit->GetLanguage();
+  lldb::LanguageType lang = m_mangled.GuessLanguage();
+  if (lang != lldb::eLanguageTypeUnknown)
+    return lang;
+
+  if (auto *func = m_owner_scope->CalculateSymbolContextFunction())
+    if ((lang = func->GetLanguage()) && lang != lldb::eLanguageTypeUnknown)
+      return lang;
+    else if (auto *comp_unit =
+                 m_owner_scope->CalculateSymbolContextCompileUnit())
+      if ((lang = func->GetLanguage()) && lang != lldb::eLanguageTypeUnknown)
+        return lang;
+
   return lldb::eLanguageTypeUnknown;
 }
 
Index: source/Core/ValueObject.cpp
===================================================================
--- source/Core/ValueObject.cpp
+++ source/Core/ValueObject.cpp
@@ -1703,16 +1703,7 @@
   if (!GetVariable() || !GetVariable()->IsArtificial())
     return false;
 
-  LanguageType lang = eLanguageTypeUnknown;
-  if (auto *sym_ctx_scope = GetSymbolContextScope()) {
-    if (auto *func = sym_ctx_scope->CalculateSymbolContextFunction())
-      lang = func->GetLanguage();
-    else if (auto *comp_unit =
-                 sym_ctx_scope->CalculateSymbolContextCompileUnit())
-      lang = comp_unit->GetLanguage();
-  }
-
-  if (auto *runtime = process->GetLanguageRuntime(lang))
+  if (auto *runtime = process->GetLanguageRuntime(GetVariable()->GetLanguage()))
     if (runtime->IsWhitelistedRuntimeValue(GetName()))
       return false;
 
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to