|
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" |
| 55 | +#include "Plugins/Language/CPlusPlus/CPlusPlusLanguageMethod.h" |
57 | 56 |
|
58 | 57 | #include "llvm/ADT/STLExtras.h" |
59 | 58 | #include "llvm/Support/Compiler.h" |
@@ -641,98 +640,75 @@ void Module::FindCompileUnits(const FileSpec &path, |
641 | 640 | Module::LookupInfo::LookupInfo(ConstString name, |
642 | 641 | FunctionNameType name_type_mask, |
643 | 642 | LanguageType language) |
644 | | - : m_name(name), m_lookup_name(), m_language(language) { |
645 | | - const char *name_cstr = name.GetCString(); |
| 643 | + : m_name(name), m_lookup_name(name), m_language(language) { |
646 | 644 | llvm::StringRef basename; |
647 | | - llvm::StringRef context; |
| 645 | + |
| 646 | + std::vector<Language *> languages; |
| 647 | + auto collect_language_plugins = [&languages](Language *lang) { |
| 648 | + languages.push_back(lang); |
| 649 | + return true; |
| 650 | + }; |
648 | 651 |
|
649 | 652 | 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; |
| 653 | + if (language == eLanguageTypeUnknown) { |
| 654 | + Language::ForEach(collect_language_plugins); |
| 655 | + for (Language *lang : languages) { |
| 656 | + auto info = lang->GetFunctionNameInfo(name); |
| 657 | + if (info.first != eFunctionNameTypeNone) { |
| 658 | + m_name_type_mask |= info.first; |
| 659 | + basename = info.second; |
| 660 | + break; |
| 661 | + } |
| 662 | + } |
658 | 663 | } 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); |
| 664 | + if (auto *lang = Language::FindPlugin(language)) { |
| 665 | + auto info = lang->GetFunctionNameInfo(name); |
| 666 | + m_name_type_mask = info.first; |
| 667 | + basename = info.second; |
674 | 668 | } |
675 | 669 | } |
| 670 | + |
| 671 | + // NOTE: There are several ways to get here, but this is a fallback path in |
| 672 | + // case the above does not succeed at extracting any useful information from |
| 673 | + // the loaded language plugins. |
| 674 | + if (m_name_type_mask == eFunctionNameTypeNone) |
| 675 | + m_name_type_mask = eFunctionNameTypeFull; |
| 676 | + |
676 | 677 | } else { |
677 | 678 | 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; |
| 679 | + if (language == eLanguageTypeUnknown) { |
| 680 | + Language::ForEach(collect_language_plugins); |
| 681 | + for (Language *lang : languages) { |
| 682 | + auto info = lang->GetFunctionNameInfo(name); |
| 683 | + if (info.first & m_name_type_mask) { |
| 684 | + m_name_type_mask &= info.first; |
| 685 | + basename = info.second; |
| 686 | + break; |
692 | 687 | } |
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 | 688 | } |
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); |
| 689 | + } else { |
| 690 | + if (auto *lang = Language::FindPlugin(language)) { |
| 691 | + auto info = lang->GetFunctionNameInfo(name); |
| 692 | + if (info.first & m_name_type_mask) { |
| 693 | + // If the user asked for FunctionNameTypes that aren't possible, |
| 694 | + // then filter those out. (e.g. asking for Selectors on |
| 695 | + // C++ symbols, or even if the symbol given can't be a selector in |
| 696 | + // ObjC) |
| 697 | + m_name_type_mask &= info.first; |
| 698 | + basename = info.second; |
| 699 | + } |
720 | 700 | } |
721 | 701 | } |
722 | 702 | } |
723 | 703 |
|
724 | 704 | 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 |
| 705 | + // The name supplied was incomplete for lookup purposes. For example, in C++ |
| 706 | + // we may have gotten something like "a::count". In this case, we want to do |
| 707 | + // a lookup on the basename "count" and then make sure any matching results |
| 708 | + // contain "a::count" so that it would match "b::a::count" and "a::count". |
| 709 | + // This is why we set match_name_after_lookup to true. |
729 | 710 | m_lookup_name.SetString(basename); |
730 | 711 | 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 | 712 | } |
737 | 713 | } |
738 | 714 |
|
|
0 commit comments