1 //===-- Language.h ---------------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef liblldb_Language_h_ 11 #define liblldb_Language_h_ 12 13 // C Includes 14 // C++ Includes 15 #include <functional> 16 #include <memory> 17 #include <set> 18 #include <vector> 19 20 // Other libraries and framework includes 21 // Project includes 22 #include "lldb/lldb-public.h" 23 #include "lldb/lldb-private.h" 24 #include "lldb/Core/PluginInterface.h" 25 #include "lldb/DataFormatters/DumpValueObjectOptions.h" 26 #include "lldb/DataFormatters/FormatClasses.h" 27 #include "lldb/DataFormatters/StringPrinter.h" 28 29 namespace lldb_private { 30 31 class Language : 32 public PluginInterface 33 { 34 public: 35 class TypeScavenger 36 { 37 public: 38 class Result 39 { 40 public: 41 virtual bool 42 IsValid () = 0; 43 44 virtual bool 45 DumpToStream (Stream& stream, 46 bool print_help_if_available) = 0; 47 48 virtual ~Result() = default; 49 }; 50 51 typedef std::set<std::unique_ptr<Result>> ResultSet; 52 53 virtual ~TypeScavenger () = default; 54 55 size_t 56 Find (ExecutionContextScope *exe_scope, 57 const char *key, 58 ResultSet &results, 59 bool append = true); 60 61 protected: 62 TypeScavenger () = default; 63 64 virtual bool 65 Find_Impl (ExecutionContextScope *exe_scope, 66 const char *key, 67 ResultSet &results) = 0; 68 }; 69 70 enum class FunctionNameRepresentation 71 { 72 eName, 73 eNameWithArgs, 74 eNameWithNoArgs 75 }; 76 77 ~Language() override; 78 79 static Language* 80 FindPlugin (lldb::LanguageType language); 81 82 // return false from callback to stop iterating 83 static void 84 ForEach (std::function<bool(Language*)> callback); 85 86 virtual lldb::LanguageType 87 GetLanguageType () const = 0; 88 89 virtual bool 90 IsTopLevelFunction (Function& function); 91 92 virtual lldb::TypeCategoryImplSP 93 GetFormatters (); 94 95 virtual HardcodedFormatters::HardcodedFormatFinder 96 GetHardcodedFormats (); 97 98 virtual HardcodedFormatters::HardcodedSummaryFinder 99 GetHardcodedSummaries (); 100 101 virtual HardcodedFormatters::HardcodedSyntheticFinder 102 GetHardcodedSynthetics (); 103 104 virtual HardcodedFormatters::HardcodedValidatorFinder 105 GetHardcodedValidators (); 106 107 virtual std::vector<ConstString> 108 GetPossibleFormattersMatches (ValueObject& valobj, lldb::DynamicValueType use_dynamic); 109 110 virtual lldb_private::formatters::StringPrinter::EscapingHelper 111 GetStringPrinterEscapingHelper (lldb_private::formatters::StringPrinter::GetPrintableElementType); 112 113 virtual std::unique_ptr<TypeScavenger> 114 GetTypeScavenger (); 115 116 virtual const char* 117 GetLanguageSpecificTypeLookupHelp (); 118 119 // if an individual data formatter can apply to several types and cross a language boundary 120 // it makes sense for individual languages to want to customize the printing of values of that 121 // type by appending proper prefix/suffix information in language-specific ways 122 virtual bool 123 GetFormatterPrefixSuffix (ValueObject& valobj, ConstString type_hint, 124 std::string& prefix, std::string& suffix); 125 126 // if a language has a custom format for printing variable declarations that it wants LLDB to honor 127 // it should return an appropriate closure here 128 virtual DumpValueObjectOptions::DeclPrintingHelper 129 GetDeclPrintingHelper (); 130 131 virtual LazyBool 132 IsLogicalTrue (ValueObject& valobj, 133 Error& error); 134 135 // for a ValueObject of some "reference type", if the value points to the 136 // nil/null object, this method returns true 137 virtual bool 138 IsNilReference (ValueObject& valobj); 139 140 // for a ValueObject of some "reference type", if the language provides a technique 141 // to decide whether the reference has ever been assigned to some object, this method 142 // will return true if such detection is possible, and if the reference has never been assigned 143 virtual bool 144 IsUninitializedReference (ValueObject& valobj); 145 146 virtual bool 147 GetFunctionDisplayName (const SymbolContext *sc, 148 const ExecutionContext *exe_ctx, 149 FunctionNameRepresentation representation, 150 Stream& s); 151 152 virtual void 153 GetExceptionResolverDescription(bool catch_on, bool throw_on, Stream &s); 154 155 static void 156 GetDefaultExceptionResolverDescription(bool catch_on, bool throw_on, Stream &s); 157 158 // These are accessors for general information about the Languages lldb knows about: 159 160 static lldb::LanguageType 161 GetLanguageTypeFromString (const char *string); 162 163 static const char * 164 GetNameForLanguageType (lldb::LanguageType language); 165 166 static void 167 PrintAllLanguages (Stream &s, const char *prefix, const char *suffix); 168 169 // return false from callback to stop iterating 170 static void 171 ForAllLanguages (std::function<bool(lldb::LanguageType)> callback); 172 173 static bool 174 LanguageIsCPlusPlus (lldb::LanguageType language); 175 176 static bool 177 LanguageIsObjC (lldb::LanguageType language); 178 179 static bool 180 LanguageIsC (lldb::LanguageType language); 181 182 static bool 183 LanguageIsPascal (lldb::LanguageType language); 184 185 // return the primary language, so if LanguageIsC(l), return eLanguageTypeC, etc. 186 static lldb::LanguageType 187 GetPrimaryLanguage (lldb::LanguageType language); 188 189 static void 190 GetLanguagesSupportingTypeSystems (std::set<lldb::LanguageType> &languages, 191 std::set<lldb::LanguageType> &languages_for_expressions); 192 193 static void 194 GetLanguagesSupportingREPLs (std::set<lldb::LanguageType> &languages); 195 196 protected: 197 //------------------------------------------------------------------ 198 // Classes that inherit from Language can see and modify these 199 //------------------------------------------------------------------ 200 201 Language(); 202 private: 203 204 DISALLOW_COPY_AND_ASSIGN (Language); 205 }; 206 207 } // namespace lldb_private 208 209 #endif // liblldb_Language_h_ 210