1 //===-- GoASTContext.h ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_GoASTContext_h_
11 #define liblldb_GoASTContext_h_
21 // Other libraries and framework includes
23 #include "lldb/Symbol/CompilerType.h"
24 #include "lldb/Symbol/TypeSystem.h"
25 #include "lldb/Utility/ConstString.h"
27 namespace lldb_private {
32 class GoASTContext : public TypeSystem {
35 ~GoASTContext() override;
37 //------------------------------------------------------------------
38 // PluginInterface functions
39 //------------------------------------------------------------------
40 ConstString GetPluginName() override;
42 uint32_t GetPluginVersion() override;
44 static ConstString GetPluginNameStatic();
46 static lldb::TypeSystemSP CreateInstance(lldb::LanguageType language,
47 Module *module, Target *target);
49 static void EnumerateSupportedLanguages(
50 std::set<lldb::LanguageType> &languages_for_types,
51 std::set<lldb::LanguageType> &languages_for_expressions);
53 static void Initialize();
55 static void Terminate();
57 DWARFASTParser *GetDWARFParser() override;
59 void SetAddressByteSize(int byte_size) { m_pointer_byte_size = byte_size; }
61 //------------------------------------------------------------------
62 // llvm casting support
63 //------------------------------------------------------------------
64 static bool classof(const TypeSystem *ts) {
65 return ts->getKind() == TypeSystem::eKindGo;
68 //----------------------------------------------------------------------
69 // CompilerDecl functions
70 //----------------------------------------------------------------------
71 ConstString DeclGetName(void *opaque_decl) override { return ConstString(); }
73 //----------------------------------------------------------------------
74 // CompilerDeclContext functions
75 //----------------------------------------------------------------------
77 bool DeclContextIsStructUnionOrClass(void *opaque_decl_ctx) override {
81 ConstString DeclContextGetName(void *opaque_decl_ctx) override {
85 ConstString DeclContextGetScopeQualifiedName(void *opaque_decl_ctx) override {
90 DeclContextIsClassMethod(void *opaque_decl_ctx,
91 lldb::LanguageType *language_ptr,
92 bool *is_instance_method_ptr,
93 ConstString *language_object_name_ptr) override {
97 //----------------------------------------------------------------------
99 //----------------------------------------------------------------------
101 CompilerType CreateArrayType(const ConstString &name,
102 const CompilerType &element_type,
105 CompilerType CreateBaseType(int go_kind,
106 const ConstString &type_name_const_str,
109 // For interface, map, chan.
110 CompilerType CreateTypedefType(int kind, const ConstString &name,
113 CompilerType CreateVoidType(const ConstString &name);
114 CompilerType CreateFunctionType(const lldb_private::ConstString &name,
115 CompilerType *params, size_t params_count,
118 CompilerType CreateStructType(int kind, const ConstString &name,
121 void CompleteStructType(const CompilerType &type);
123 void AddFieldToStruct(const CompilerType &struct_type,
124 const ConstString &name, const CompilerType &field_type,
125 uint32_t byte_offset);
127 //----------------------------------------------------------------------
129 //----------------------------------------------------------------------
131 static bool IsGoString(const CompilerType &type);
132 static bool IsGoSlice(const CompilerType &type);
133 static bool IsGoInterface(const CompilerType &type);
134 static bool IsDirectIface(uint8_t kind);
135 static bool IsPointerKind(uint8_t kind);
137 bool IsArrayType(lldb::opaque_compiler_type_t type,
138 CompilerType *element_type, uint64_t *size,
139 bool *is_incomplete) override;
141 bool IsAggregateType(lldb::opaque_compiler_type_t type) override;
143 bool IsCharType(lldb::opaque_compiler_type_t type) override;
145 bool IsCompleteType(lldb::opaque_compiler_type_t type) override;
147 bool IsDefined(lldb::opaque_compiler_type_t type) override;
149 bool IsFloatingPointType(lldb::opaque_compiler_type_t type, uint32_t &count,
150 bool &is_complex) override;
152 bool IsFunctionType(lldb::opaque_compiler_type_t type,
153 bool *is_variadic_ptr = nullptr) override;
156 GetNumberOfFunctionArguments(lldb::opaque_compiler_type_t type) override;
158 CompilerType GetFunctionArgumentAtIndex(lldb::opaque_compiler_type_t type,
159 const size_t index) override;
161 bool IsFunctionPointerType(lldb::opaque_compiler_type_t type) override;
163 bool IsBlockPointerType(lldb::opaque_compiler_type_t type,
164 CompilerType *function_pointer_type_ptr) override;
166 bool IsIntegerType(lldb::opaque_compiler_type_t type,
167 bool &is_signed) override;
169 bool IsPossibleDynamicType(lldb::opaque_compiler_type_t type,
170 CompilerType *target_type, // Can pass nullptr
171 bool check_cplusplus, bool check_objc) override;
173 bool IsPointerType(lldb::opaque_compiler_type_t type,
174 CompilerType *pointee_type = nullptr) override;
176 bool IsScalarType(lldb::opaque_compiler_type_t type) override;
178 bool IsVoidType(lldb::opaque_compiler_type_t type) override;
180 bool SupportsLanguage(lldb::LanguageType language) override;
182 //----------------------------------------------------------------------
184 //----------------------------------------------------------------------
186 bool GetCompleteType(lldb::opaque_compiler_type_t type) override;
188 //----------------------------------------------------------------------
189 // AST related queries
190 //----------------------------------------------------------------------
192 uint32_t GetPointerByteSize() override;
194 //----------------------------------------------------------------------
196 //----------------------------------------------------------------------
198 ConstString GetTypeName(lldb::opaque_compiler_type_t type) override;
200 uint32_t GetTypeInfo(
201 lldb::opaque_compiler_type_t type,
202 CompilerType *pointee_or_element_compiler_type = nullptr) override;
205 GetMinimumLanguage(lldb::opaque_compiler_type_t type) override;
207 lldb::TypeClass GetTypeClass(lldb::opaque_compiler_type_t type) override;
209 //----------------------------------------------------------------------
210 // Creating related types
211 //----------------------------------------------------------------------
213 CompilerType GetArrayElementType(lldb::opaque_compiler_type_t type,
214 uint64_t *stride = nullptr) override;
216 CompilerType GetCanonicalType(lldb::opaque_compiler_type_t type) override;
218 // Returns -1 if this isn't a function of if the function doesn't have a
220 // Returns a value >= 0 if there is a prototype.
221 int GetFunctionArgumentCount(lldb::opaque_compiler_type_t type) override;
223 CompilerType GetFunctionArgumentTypeAtIndex(lldb::opaque_compiler_type_t type,
224 size_t idx) override;
227 GetFunctionReturnType(lldb::opaque_compiler_type_t type) override;
229 size_t GetNumMemberFunctions(lldb::opaque_compiler_type_t type) override;
231 TypeMemberFunctionImpl
232 GetMemberFunctionAtIndex(lldb::opaque_compiler_type_t type,
233 size_t idx) override;
235 CompilerType GetPointeeType(lldb::opaque_compiler_type_t type) override;
237 CompilerType GetPointerType(lldb::opaque_compiler_type_t type) override;
239 //----------------------------------------------------------------------
240 // Exploring the type
241 //----------------------------------------------------------------------
243 uint64_t GetBitSize(lldb::opaque_compiler_type_t type,
244 ExecutionContextScope *exe_scope) override;
246 lldb::Encoding GetEncoding(lldb::opaque_compiler_type_t type,
247 uint64_t &count) override;
249 lldb::Format GetFormat(lldb::opaque_compiler_type_t type) override;
251 uint32_t GetNumChildren(lldb::opaque_compiler_type_t type,
252 bool omit_empty_base_classes) override;
255 GetBasicTypeEnumeration(lldb::opaque_compiler_type_t type) override;
257 CompilerType GetBuiltinTypeForEncodingAndBitSize(lldb::Encoding encoding,
258 size_t bit_size) override;
260 uint32_t GetNumFields(lldb::opaque_compiler_type_t type) override;
262 CompilerType GetFieldAtIndex(lldb::opaque_compiler_type_t type, size_t idx,
263 std::string &name, uint64_t *bit_offset_ptr,
264 uint32_t *bitfield_bit_size_ptr,
265 bool *is_bitfield_ptr) override;
267 uint32_t GetNumDirectBaseClasses(lldb::opaque_compiler_type_t type) override {
272 GetNumVirtualBaseClasses(lldb::opaque_compiler_type_t type) override {
276 CompilerType GetDirectBaseClassAtIndex(lldb::opaque_compiler_type_t type,
278 uint32_t *bit_offset_ptr) override {
279 return CompilerType();
282 CompilerType GetVirtualBaseClassAtIndex(lldb::opaque_compiler_type_t type,
284 uint32_t *bit_offset_ptr) override {
285 return CompilerType();
288 CompilerType GetChildCompilerTypeAtIndex(
289 lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx, size_t idx,
290 bool transparent_pointers, bool omit_empty_base_classes,
291 bool ignore_array_bounds, std::string &child_name,
292 uint32_t &child_byte_size, int32_t &child_byte_offset,
293 uint32_t &child_bitfield_bit_size, uint32_t &child_bitfield_bit_offset,
294 bool &child_is_base_class, bool &child_is_deref_of_parent,
295 ValueObject *valobj, uint64_t &language_flags) override;
297 // Lookup a child given a name. This function will match base class names
298 // and member member names in "clang_type" only, not descendants.
299 uint32_t GetIndexOfChildWithName(lldb::opaque_compiler_type_t type,
301 bool omit_empty_base_classes) override;
303 // Lookup a child member given a name. This function will match member names
304 // only and will descend into "clang_type" children in search for the first
305 // member in this class, or any base class that matches "name".
306 // TODO: Return all matches for a given name by returning a
307 // vector<vector<uint32_t>>
308 // so we catch all names that match a given child name, not just the first.
310 GetIndexOfChildMemberWithName(lldb::opaque_compiler_type_t type,
311 const char *name, bool omit_empty_base_classes,
312 std::vector<uint32_t> &child_indexes) override;
314 size_t GetNumTemplateArguments(lldb::opaque_compiler_type_t type) override {
318 //----------------------------------------------------------------------
320 //----------------------------------------------------------------------
321 void DumpValue(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
322 Stream *s, lldb::Format format, const DataExtractor &data,
323 lldb::offset_t data_offset, size_t data_byte_size,
324 uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
325 bool show_types, bool show_summary, bool verbose,
326 uint32_t depth) override;
328 bool DumpTypeValue(lldb::opaque_compiler_type_t type, Stream *s,
329 lldb::Format format, const DataExtractor &data,
330 lldb::offset_t data_offset, size_t data_byte_size,
331 uint32_t bitfield_bit_size, uint32_t bitfield_bit_offset,
332 ExecutionContextScope *exe_scope) override;
334 void DumpTypeDescription(
335 lldb::opaque_compiler_type_t type) override; // Dump to stdout
337 void DumpTypeDescription(lldb::opaque_compiler_type_t type,
340 //----------------------------------------------------------------------
341 // TODO: These methods appear unused. Should they be removed?
342 //----------------------------------------------------------------------
344 bool IsRuntimeGeneratedType(lldb::opaque_compiler_type_t type) override;
346 void DumpSummary(lldb::opaque_compiler_type_t type, ExecutionContext *exe_ctx,
347 Stream *s, const DataExtractor &data,
348 lldb::offset_t data_offset, size_t data_byte_size) override;
350 // Converts "s" to a floating point value and place resulting floating
351 // point bytes in the "dst" buffer.
352 size_t ConvertStringToFloatValue(lldb::opaque_compiler_type_t type,
353 const char *s, uint8_t *dst,
354 size_t dst_size) override;
356 //----------------------------------------------------------------------
357 // TODO: Determine if these methods should move to ClangASTContext.
358 //----------------------------------------------------------------------
360 bool IsPointerOrReferenceType(lldb::opaque_compiler_type_t type,
361 CompilerType *pointee_type = nullptr) override;
363 unsigned GetTypeQualifiers(lldb::opaque_compiler_type_t type) override;
365 bool IsCStringType(lldb::opaque_compiler_type_t type,
366 uint32_t &length) override;
368 size_t GetTypeBitAlign(lldb::opaque_compiler_type_t type) override;
370 CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) override;
372 bool IsBeingDefined(lldb::opaque_compiler_type_t type) override;
374 bool IsConst(lldb::opaque_compiler_type_t type) override;
376 uint32_t IsHomogeneousAggregate(lldb::opaque_compiler_type_t type,
377 CompilerType *base_type_ptr) override;
379 bool IsPolymorphicClass(lldb::opaque_compiler_type_t type) override;
381 bool IsTypedefType(lldb::opaque_compiler_type_t type) override;
383 // If the current object represents a typedef type, get the underlying type
384 CompilerType GetTypedefedType(lldb::opaque_compiler_type_t type) override;
386 bool IsVectorType(lldb::opaque_compiler_type_t type,
387 CompilerType *element_type, uint64_t *size) override;
390 GetFullyUnqualifiedType(lldb::opaque_compiler_type_t type) override;
392 CompilerType GetNonReferenceType(lldb::opaque_compiler_type_t type) override;
394 bool IsReferenceType(lldb::opaque_compiler_type_t type,
395 CompilerType *pointee_type = nullptr,
396 bool *is_rvalue = nullptr) override;
399 typedef std::map<ConstString, std::unique_ptr<GoType>> TypeMap;
400 int m_pointer_byte_size;
402 std::unique_ptr<TypeMap> m_types;
403 std::unique_ptr<DWARFASTParser> m_dwarf_ast_parser_ap;
405 GoASTContext(const GoASTContext &) = delete;
406 const GoASTContext &operator=(const GoASTContext &) = delete;
409 class GoASTContextForExpr : public GoASTContext {
411 GoASTContextForExpr(lldb::TargetSP target) : m_target_wp(target) {}
413 GetUserExpression(llvm::StringRef expr, llvm::StringRef prefix,
414 lldb::LanguageType language,
415 Expression::ResultType desired_type,
416 const EvaluateExpressionOptions &options) override;
419 lldb::TargetWP m_target_wp;
422 #endif // liblldb_GoASTContext_h_