19#include "clang/Basic/TargetInfo.h"
24static char popChar(llvm::StringRef &str) {
25 const char c = str.front();
27 str = str.drop_front();
41 "AppleObjCTypeEncodingParser ASTContext",
47 while (!type.empty() && type.front() !=
'=')
53std::optional<std::string>
59 while (type.front() !=
'"') {
70 while (!type.empty() && isdigit(type.front()))
71 total = 10 * total + (
popChar(type) -
'0');
84 llvm::StringRef &type,
85 bool for_expression) {
87 if (type.consume_front(
'"')) {
89 retval.
name = *maybe_name;
93 uint32_t bitfield_size = 0;
94 retval.
type =
BuildType(ast_ctx, type, for_expression, &bitfield_size);
100 TypeSystemClang &ast_ctx, llvm::StringRef &type,
bool for_expression) {
102 llvm::to_underlying(clang::TagTypeKind::Struct));
106 TypeSystemClang &ast_ctx, llvm::StringRef &type,
bool for_expression) {
108 llvm::to_underlying(clang::TagTypeKind::Union));
113 char opener,
char closer, uint32_t kind) {
114 if (!type.consume_front(opener))
115 return clang::QualType();
123 const bool is_templated = name.find(
'<') != std::string::npos;
125 if (!type.consume_front(
'='))
126 return clang::QualType();
127 bool in_union =
true;
128 std::vector<StructElement> elements;
129 while (in_union && !type.empty()) {
130 if (type.consume_front(closer)) {
135 if (element.type.isNull())
138 elements.push_back(element);
142 return clang::QualType();
145 return clang::QualType();
153 unsigned int count = 0;
154 for (
auto element : elements) {
155 if (element.name.empty()) {
157 elem_name.
Printf(
"__unnamed_%u", count);
158 element.name = std::string(elem_name.
GetString());
161 union_type, element.name.c_str(), ast_ctx.
GetType(element.type),
171 TypeSystemClang &ast_ctx, llvm::StringRef &type,
bool for_expression) {
173 return clang::QualType();
176 clang::QualType element_type(
BuildType(ast_ctx, type, for_expression));
178 return clang::QualType();
181 CompilerType(ast_ctx.weak_from_this(), element_type.getAsOpaquePtr()),
193 bool for_expression) {
194 if (!type.consume_front(
_C_ID))
195 return clang::QualType();
201 if (type.consume_front(
'"')) {
222 llvm::StringRef backup = type;
226 return clang::QualType();
229 switch (type.front()) {
247 if (for_expression && !name.empty()) {
248 size_t less_than_pos = name.find(
'<');
250 if (less_than_pos != std::string::npos) {
251 if (less_than_pos == 0)
252 return ast_ctx.getObjCIdType();
254 name.erase(less_than_pos);
259 return clang::QualType();
267 assert(
false &&
"forward declaration without definition");
269 "forward declaration without definition: {0}", name);
270 return ast_ctx.getObjCIdType();
276 return ast_ctx.getObjCIdType();
281 TypeSystemClang &clang_ast_ctx, llvm::StringRef &type,
bool for_expression,
282 uint32_t *bitfield_bit_size) {
284 return clang::QualType();
288 switch (type.front()) {
292 return BuildStruct(clang_ast_ctx, type, for_expression);
294 return BuildArray(clang_ast_ctx, type, for_expression);
296 return BuildUnion(clang_ast_ctx, type, for_expression);
302 llvm::StringRef backup = type;
307 return clang::QualType();
309 return ast_ctx.CharTy;
311 return ast_ctx.IntTy;
313 return ast_ctx.ShortTy;
315 return ast_ctx.getIntTypeForBitwidth(32,
true);
321 return ast_ctx.LongLongTy;
323 return ast_ctx.UnsignedCharTy;
325 return ast_ctx.UnsignedIntTy;
327 return ast_ctx.UnsignedShortTy;
329 return ast_ctx.getIntTypeForBitwidth(32,
false);
332 return ast_ctx.UnsignedLongLongTy;
334 return ast_ctx.FloatTy;
336 return ast_ctx.DoubleTy;
338 return ast_ctx.BoolTy;
340 return ast_ctx.VoidTy;
342 return ast_ctx.getPointerType(ast_ctx.CharTy);
344 return ast_ctx.getObjCClassType();
346 return ast_ctx.getObjCSelType();
349 if (bitfield_bit_size) {
350 *bitfield_bit_size = size;
351 return ast_ctx.UnsignedIntTy;
353 return clang::QualType();
356 clang::QualType target_type =
357 BuildType(clang_ast_ctx, type, for_expression);
358 if (target_type.isNull())
359 return clang::QualType();
360 else if (target_type == ast_ctx.UnknownAnyTy)
361 return ast_ctx.UnknownAnyTy;
363 return ast_ctx.getConstType(target_type);
366 if (!for_expression && type.consume_front(
_C_UNDEF)) {
372 return ast_ctx.VoidPtrTy;
374 clang::QualType target_type =
375 BuildType(clang_ast_ctx, type, for_expression);
376 if (target_type.isNull())
377 return clang::QualType();
378 else if (target_type == ast_ctx.UnknownAnyTy)
379 return ast_ctx.UnknownAnyTy;
381 return ast_ctx.getPointerType(target_type);
385 return for_expression ? ast_ctx.UnknownAnyTy : clang::QualType();
391 bool for_expression) {
392 if (name && name[0]) {
393 llvm::StringRef lexer(name);
394 clang::QualType qual_type =
BuildType(ast_ctx, lexer, for_expression);
395 return ast_ctx.
GetType(qual_type);
static char popChar(llvm::StringRef &str)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
clang::QualType BuildArray(TypeSystemClang &ast_ctx, llvm::StringRef &type, bool for_expression)
clang::QualType BuildAggregate(TypeSystemClang &clang_ast_ctx, llvm::StringRef &type, bool for_expression, char opener, char closer, uint32_t kind)
clang::QualType BuildObjCObjectPointerType(TypeSystemClang &clang_ast_ctx, llvm::StringRef &type, bool for_expression)
std::optional< std::string > ReadQuotedString(llvm::StringRef &type)
clang::QualType BuildStruct(TypeSystemClang &ast_ctx, llvm::StringRef &type, bool for_expression)
CompilerType RealizeType(TypeSystemClang &ast_ctx, const char *name, bool for_expression) override
StructElement ReadStructElement(TypeSystemClang &ast_ctx, llvm::StringRef &type, bool for_expression)
ObjCLanguageRuntime & m_runtime
std::string ReadStructName(llvm::StringRef &type)
AppleObjCTypeEncodingParser(ObjCLanguageRuntime &runtime)
uint32_t ReadNumber(llvm::StringRef &type)
clang::QualType BuildUnion(TypeSystemClang &ast_ctx, llvm::StringRef &type, bool for_expression)
clang::QualType BuildType(TypeSystemClang &clang_ast_ctx, llvm::StringRef &type, bool for_expression, uint32_t *bitfield_bit_size=nullptr)
llvm::Triple & GetTriple()
Architecture triple accessor.
Generic representation of a type in a programming language.
A uniqued constant string class.
std::vector< CompilerType > FindTypes(ConstString name, uint32_t max_matches)
Look up the types that the DeclVendor currently knows about matching a given name.
std::shared_ptr< TypeSystemClang > m_scratch_ast_ctx_sp
Target & GetTarget()
Get the target object pointer for this module.
llvm::StringRef GetString() const
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
const ArchSpec & GetArchitecture() const
A TypeSystem implementation based on Clang.
static clang::FieldDecl * AddFieldToRecordType(const CompilerType &type, llvm::StringRef name, const CompilerType &field_type, lldb::AccessType access, uint32_t bitfield_bit_size)
CompilerType CreateArrayType(const CompilerType &element_type, std::optional< size_t > element_count, bool is_vector)
CompilerType GetType(clang::QualType qt)
Creates a CompilerType from the given QualType with the current TypeSystemClang instance as the Compi...
static bool CompleteTagDeclarationDefinition(const CompilerType &type)
CompilerType CreateRecordType(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, lldb::AccessType access_type, llvm::StringRef name, int kind, lldb::LanguageType language, std::optional< ClangASTMetadata > metadata=std::nullopt, bool exports_symbols=false)
static bool StartTagDeclarationDefinition(const CompilerType &type)
clang::ASTContext & getASTContext() const
Returns the clang::ASTContext instance managed by this TypeSystemClang.
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
@ eLanguageTypeC
Non-standardized C, such as K&R.
static clang::QualType GetQualType(const CompilerType &ct)