Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h
39644 views
//===-- CPlusPlusLanguage.h -------------------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_CPLUSPLUSLANGUAGE_H9#define LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_CPLUSPLUSLANGUAGE_H1011#include <set>12#include <vector>1314#include "llvm/ADT/StringRef.h"1516#include "Plugins/Language/ClangCommon/ClangHighlighter.h"17#include "lldb/Target/Language.h"18#include "lldb/Utility/ConstString.h"19#include "lldb/lldb-private.h"2021namespace lldb_private {2223class CPlusPlusLanguage : public Language {24ClangHighlighter m_highlighter;2526public:27class MethodName {28public:29MethodName()30: m_full(), m_basename(), m_context(), m_arguments(), m_qualifiers() {}3132MethodName(ConstString s)33: m_full(s), m_basename(), m_context(), m_arguments(), m_qualifiers(),34m_parsed(false), m_parse_error(false) {}3536void Clear();3738bool IsValid() {39if (!m_parsed)40Parse();41if (m_parse_error)42return false;43return (bool)m_full;44}4546ConstString GetFullName() const { return m_full; }4748std::string GetScopeQualifiedName();4950llvm::StringRef GetBasename();5152llvm::StringRef GetContext();5354llvm::StringRef GetArguments();5556llvm::StringRef GetQualifiers();5758/// Returns the methods return-type.59///60/// Currently returns an empty llvm::StringRef61/// if the return-type is a function pointer.62llvm::StringRef GetReturnType();6364bool ContainsPath(llvm::StringRef path);6566private:67/// Returns the Basename of this method without a template parameter68/// list, if any.69///70// Examples:71//72// +--------------------------------+---------+73// | MethodName | Returns |74// +--------------------------------+---------+75// | void func() | func |76// | void func<int>() | func |77// | void func<std::vector<int>>() | func |78// +--------------------------------+---------+79llvm::StringRef GetBasenameNoTemplateParameters();8081protected:82void Parse();83bool TrySimplifiedParse();8485ConstString m_full; // Full name:86// "size_t lldb::SBTarget::GetBreakpointAtIndex(unsigned87// int) const"88llvm::StringRef m_basename; // Basename: "GetBreakpointAtIndex"89llvm::StringRef m_context; // Decl context: "lldb::SBTarget"90llvm::StringRef m_arguments; // Arguments: "(unsigned int)"91llvm::StringRef m_qualifiers; // Qualifiers: "const"92llvm::StringRef m_return_type; // Return type: "size_t"93bool m_parsed = false;94bool m_parse_error = false;95};9697CPlusPlusLanguage() = default;9899~CPlusPlusLanguage() override = default;100101lldb::LanguageType GetLanguageType() const override {102return lldb::eLanguageTypeC_plus_plus;103}104105llvm::StringRef GetUserEntryPointName() const override { return "main"; }106107std::unique_ptr<TypeScavenger> GetTypeScavenger() override;108lldb::TypeCategoryImplSP GetFormatters() override;109110HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries() override;111112HardcodedFormatters::HardcodedSyntheticFinder113GetHardcodedSynthetics() override;114115bool IsNilReference(ValueObject &valobj) override;116117llvm::StringRef GetNilReferenceSummaryString() override { return "nullptr"; }118119bool IsSourceFile(llvm::StringRef file_path) const override;120121const Highlighter *GetHighlighter() const override { return &m_highlighter; }122123// Static Functions124static void Initialize();125126static void Terminate();127128static lldb_private::Language *CreateInstance(lldb::LanguageType language);129130static llvm::StringRef GetPluginNameStatic() { return "cplusplus"; }131132bool SymbolNameFitsToLanguage(Mangled mangled) const override;133134bool DemangledNameContainsPath(llvm::StringRef path,135ConstString demangled) const override;136137ConstString138GetDemangledFunctionNameWithoutArguments(Mangled mangled) const override;139140bool GetFunctionDisplayName(const SymbolContext *sc,141const ExecutionContext *exe_ctx,142FunctionNameRepresentation representation,143Stream &s) override;144145static bool IsCPPMangledName(llvm::StringRef name);146147// Extract C++ context and identifier from a string using heuristic matching148// (as opposed to149// CPlusPlusLanguage::MethodName which has to have a fully qualified C++ name150// with parens and arguments.151// If the name is a lone C identifier (e.g. C) or a qualified C identifier152// (e.g. A::B::C) it will return true,153// and identifier will be the identifier (C and C respectively) and the154// context will be "" and "A::B" respectively.155// If the name fails the heuristic matching for a qualified or unqualified156// C/C++ identifier, then it will return false157// and identifier and context will be unchanged.158159static bool ExtractContextAndIdentifier(const char *name,160llvm::StringRef &context,161llvm::StringRef &identifier);162163std::vector<ConstString>164GenerateAlternateFunctionManglings(const ConstString mangled) const override;165166ConstString FindBestAlternateFunctionMangledName(167const Mangled mangled, const SymbolContext &sym_ctx) const override;168169llvm::StringRef GetInstanceVariableName() override { return "this"; }170171// PluginInterface protocol172llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }173};174175} // namespace lldb_private176177#endif // LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_CPLUSPLUSLANGUAGE_H178179180