52
52
#include " lldb/Host/windows/PosixApi.h"
53
53
#endif
54
54
55
- #include " Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
56
- #include " Plugins/Language/ObjC/ObjCLanguage.h"
57
-
58
55
#include " llvm/ADT/STLExtras.h"
59
56
#include " llvm/Support/Compiler.h"
60
57
#include " llvm/Support/DJB.h"
@@ -641,98 +638,75 @@ void Module::FindCompileUnits(const FileSpec &path,
641
638
Module::LookupInfo::LookupInfo (ConstString name,
642
639
FunctionNameType name_type_mask,
643
640
LanguageType language)
644
- : m_name(name), m_lookup_name(), m_language(language) {
645
- const char *name_cstr = name.GetCString ();
641
+ : m_name(name), m_lookup_name(name), m_language(language) {
646
642
llvm::StringRef basename;
647
- llvm::StringRef context;
643
+
644
+ std::vector<Language *> languages;
645
+ auto collect_language_plugins = [&languages](Language *lang) {
646
+ languages.push_back (lang);
647
+ return true ;
648
+ };
648
649
649
650
if (name_type_mask & eFunctionNameTypeAuto) {
650
- if (CPlusPlusLanguage::IsCPPMangledName (name_cstr))
651
- m_name_type_mask = eFunctionNameTypeFull;
652
- else if ((language == eLanguageTypeUnknown ||
653
- Language::LanguageIsObjC (language)) &&
654
- ObjCLanguage::IsPossibleObjCMethodName (name_cstr))
655
- m_name_type_mask = eFunctionNameTypeFull;
656
- else if (Language::LanguageIsC (language)) {
657
- m_name_type_mask = eFunctionNameTypeFull;
651
+ if (language == eLanguageTypeUnknown) {
652
+ Language::ForEach (collect_language_plugins);
653
+ for (Language *lang : languages) {
654
+ auto info = lang->GetFunctionNameInfo (name);
655
+ if (info.first != eFunctionNameTypeNone) {
656
+ m_name_type_mask |= info.first ;
657
+ basename = info.second ;
658
+ break ;
659
+ }
660
+ }
658
661
} else {
659
- if ((language == eLanguageTypeUnknown ||
660
- Language::LanguageIsObjC (language)) &&
661
- ObjCLanguage::IsPossibleObjCSelector (name_cstr))
662
- m_name_type_mask |= eFunctionNameTypeSelector;
663
-
664
- CPlusPlusLanguage::MethodName cpp_method (name);
665
- basename = cpp_method.GetBasename ();
666
- if (basename.empty ()) {
667
- if (CPlusPlusLanguage::ExtractContextAndIdentifier (name_cstr, context,
668
- basename))
669
- m_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
670
- else
671
- m_name_type_mask |= eFunctionNameTypeFull;
672
- } else {
673
- m_name_type_mask |= (eFunctionNameTypeMethod | eFunctionNameTypeBase);
662
+ if (auto *lang = Language::FindPlugin (language)) {
663
+ auto info = lang->GetFunctionNameInfo (name);
664
+ m_name_type_mask = info.first ;
665
+ basename = info.second ;
674
666
}
675
667
}
668
+
669
+ // NOTE: There are several ways to get here, but this is a fallback path in
670
+ // case the above does not succeed at extracting any useful information from
671
+ // the loaded language plugins.
672
+ if (m_name_type_mask == eFunctionNameTypeNone)
673
+ m_name_type_mask = eFunctionNameTypeFull;
674
+
676
675
} else {
677
676
m_name_type_mask = name_type_mask;
678
- if (name_type_mask & eFunctionNameTypeMethod ||
679
- name_type_mask & eFunctionNameTypeBase) {
680
- // If they've asked for a CPP method or function name and it can't be
681
- // that, we don't even need to search for CPP methods or names.
682
- CPlusPlusLanguage::MethodName cpp_method (name);
683
- if (cpp_method.IsValid ()) {
684
- basename = cpp_method.GetBasename ();
685
-
686
- if (!cpp_method.GetQualifiers ().empty ()) {
687
- // There is a "const" or other qualifier following the end of the
688
- // function parens, this can't be a eFunctionNameTypeBase
689
- m_name_type_mask &= ~(eFunctionNameTypeBase);
690
- if (m_name_type_mask == eFunctionNameTypeNone)
691
- return ;
677
+ if (language == eLanguageTypeUnknown) {
678
+ Language::ForEach (collect_language_plugins);
679
+ for (Language *lang : languages) {
680
+ auto info = lang->GetFunctionNameInfo (name);
681
+ if (info.first & m_name_type_mask) {
682
+ m_name_type_mask &= info.first ;
683
+ basename = info.second ;
684
+ break ;
692
685
}
693
- } else {
694
- // If the CPP method parser didn't manage to chop this up, try to fill
695
- // in the base name if we can. If a::b::c is passed in, we need to just
696
- // look up "c", and then we'll filter the result later.
697
- CPlusPlusLanguage::ExtractContextAndIdentifier (name_cstr, context,
698
- basename);
699
- }
700
- }
701
-
702
- if (name_type_mask & eFunctionNameTypeSelector) {
703
- if (!ObjCLanguage::IsPossibleObjCSelector (name_cstr)) {
704
- m_name_type_mask &= ~(eFunctionNameTypeSelector);
705
- if (m_name_type_mask == eFunctionNameTypeNone)
706
- return ;
707
686
}
708
- }
709
-
710
- // Still try and get a basename in case someone specifies a name type mask
711
- // of eFunctionNameTypeFull and a name like "A::func"
712
- if (basename.empty ()) {
713
- if (name_type_mask & eFunctionNameTypeFull &&
714
- !CPlusPlusLanguage::IsCPPMangledName (name_cstr)) {
715
- CPlusPlusLanguage::MethodName cpp_method (name);
716
- basename = cpp_method.GetBasename ();
717
- if (basename.empty ())
718
- CPlusPlusLanguage::ExtractContextAndIdentifier (name_cstr, context,
719
- basename);
687
+ } else {
688
+ if (auto *lang = Language::FindPlugin (language)) {
689
+ auto info = lang->GetFunctionNameInfo (name);
690
+ if (info.first & m_name_type_mask) {
691
+ // If the user asked for FunctionNameTypes that aren't possible,
692
+ // then filter those out. (e.g. asking for Selectors on
693
+ // C++ symbols, or even if the symbol given can't be a selector in
694
+ // ObjC)
695
+ m_name_type_mask &= info.first ;
696
+ basename = info.second ;
697
+ }
720
698
}
721
699
}
722
700
}
723
701
724
702
if (!basename.empty ()) {
725
- // The name supplied was a partial C++ path like "a::count". In this case
726
- // we want to do a lookup on the basename "count" and then make sure any
727
- // matching results contain "a::count" so that it would match "b::a::count"
728
- // and "a::count". This is why we set "match_name_after_lookup" to true
703
+ // The name supplied was incomplete for lookup purposes. For example, in C++
704
+ // we may have gotten something like "a::count". In this case, we want to do
705
+ // a lookup on the basename "count" and then make sure any matching results
706
+ // contain "a::count" so that it would match "b::a::count" and "a::count".
707
+ // This is why we set match_name_after_lookup to true.
729
708
m_lookup_name.SetString (basename);
730
709
m_match_name_after_lookup = true ;
731
- } else {
732
- // The name is already correct, just use the exact name as supplied, and we
733
- // won't need to check if any matches contain "name"
734
- m_lookup_name = name;
735
- m_match_name_after_lookup = false ;
736
710
}
737
711
}
738
712
@@ -791,7 +765,8 @@ void Module::LookupInfo::Prune(SymbolContextList &sc_list,
791
765
// "func" and specified eFunctionNameTypeFull, but we might have found
792
766
// "a::func()", "a::b::func()", "c::func()", "func()" and "func". Only
793
767
// "func()" and "func" should end up matching.
794
- if (m_name_type_mask == eFunctionNameTypeFull) {
768
+ auto *lang = Language::FindPlugin (eLanguageTypeC_plus_plus);
769
+ if (lang && m_name_type_mask == eFunctionNameTypeFull) {
795
770
SymbolContext sc;
796
771
size_t i = start_idx;
797
772
while (i < sc_list.GetSize ()) {
@@ -802,20 +777,21 @@ void Module::LookupInfo::Prune(SymbolContextList &sc_list,
802
777
ConstString mangled_name (sc.GetFunctionName (Mangled::ePreferMangled));
803
778
ConstString full_name (sc.GetFunctionName ());
804
779
if (mangled_name != m_name && full_name != m_name) {
805
- CPlusPlusLanguage::MethodName cpp_method (full_name);
806
- if (cpp_method.IsValid ()) {
807
- if (cpp_method.GetContext ().empty ()) {
808
- if (cpp_method.GetBasename ().compare (m_name) != 0 ) {
780
+ std::unique_ptr<Language::MethodName> cpp_method =
781
+ lang->GetMethodName (full_name);
782
+ if (cpp_method->IsValid ()) {
783
+ if (cpp_method->GetContext ().empty ()) {
784
+ if (cpp_method->GetBasename ().compare (m_name) != 0 ) {
809
785
sc_list.RemoveContextAtIndex (i);
810
786
continue ;
811
787
}
812
788
} else {
813
789
std::string qualified_name;
814
790
llvm::StringRef anon_prefix (" (anonymous namespace)" );
815
- if (cpp_method. GetContext () == anon_prefix)
816
- qualified_name = cpp_method. GetBasename ().str ();
791
+ if (cpp_method-> GetContext () == anon_prefix)
792
+ qualified_name = cpp_method-> GetBasename ().str ();
817
793
else
818
- qualified_name = cpp_method. GetScopeQualifiedName ();
794
+ qualified_name = cpp_method-> GetScopeQualifiedName ();
819
795
if (qualified_name != m_name.GetCString ()) {
820
796
sc_list.RemoveContextAtIndex (i);
821
797
continue ;
@@ -988,8 +964,7 @@ DebuggersOwningModuleRequestingInterruption(Module &module) {
988
964
for (auto debugger_sp : requestors) {
989
965
if (!debugger_sp->InterruptRequested ())
990
966
continue ;
991
- if (debugger_sp->GetTargetList ()
992
- .AnyTargetContainsModule (module ))
967
+ if (debugger_sp->GetTargetList ().AnyTargetContainsModule (module ))
993
968
interruptors.push_back (debugger_sp);
994
969
}
995
970
return interruptors;
0 commit comments