19#include "clang/Basic/TargetInfo.h"
24static char popChar(llvm::StringRef &str) {
25 const char c = str.front();
27 str = str.drop_front();
33 if (!str.starts_with(c))
36 str = str.drop_front();
50 "AppleObjCTypeEncodingParser ASTContext",
56 while (!type.empty() && type.front() !=
'=')
62std::optional<std::string>
68 while (type.front() !=
'"') {
79 while (!type.empty() && isdigit(type.front()))
80 total = 10 * total + (
popChar(type) -
'0');
93 llvm::StringRef &type,
94 bool for_expression) {
96 if (type.consume_front(
"\"")) {
98 retval.
name = *maybe_name;
102 uint32_t bitfield_size = 0;
103 retval.
type =
BuildType(ast_ctx, type, for_expression, &bitfield_size);
109 TypeSystemClang &ast_ctx, llvm::StringRef &type,
bool for_expression) {
111 llvm::to_underlying(clang::TagTypeKind::Struct));
115 TypeSystemClang &ast_ctx, llvm::StringRef &type,
bool for_expression) {
117 llvm::to_underlying(clang::TagTypeKind::Union));
122 char opener,
char closer, uint32_t kind) {
124 return clang::QualType();
132 const bool is_templated = name.find(
'<') != std::string::npos;
134 if (!type.consume_front(
"="))
135 return clang::QualType();
136 bool in_union =
true;
137 std::vector<StructElement> elements;
138 while (in_union && !type.empty()) {
144 if (element.type.isNull())
147 elements.push_back(element);
151 return clang::QualType();
154 return clang::QualType();
162 unsigned int count = 0;
163 for (
auto element : elements) {
164 if (element.name.empty()) {
166 elem_name.
Printf(
"__unnamed_%u", count);
167 element.name = std::string(elem_name.
GetString());
170 union_type, element.name.c_str(), ast_ctx.
GetType(element.type),
180 TypeSystemClang &ast_ctx, llvm::StringRef &type,
bool for_expression) {
182 return clang::QualType();
185 clang::QualType element_type(
BuildType(ast_ctx, type, for_expression));
187 return clang::QualType();
190 CompilerType(ast_ctx.weak_from_this(), element_type.getAsOpaquePtr()),
202 bool for_expression) {
204 return clang::QualType();
210 if (type.consume_front(
"\"")) {
231 llvm::StringRef backup = type;
235 return clang::QualType();
238 switch (type.front()) {
256 if (for_expression && !name.empty()) {
257 size_t less_than_pos = name.find(
'<');
259 if (less_than_pos != std::string::npos) {
260 if (less_than_pos == 0)
261 return ast_ctx.getObjCIdType();
263 name.erase(less_than_pos);
268 return clang::QualType();
276 assert(
false &&
"forward declaration without definition");
278 "forward declaration without definition: {0}", name);
279 return ast_ctx.getObjCIdType();
285 return ast_ctx.getObjCIdType();
290 TypeSystemClang &clang_ast_ctx, llvm::StringRef &type,
bool for_expression,
291 uint32_t *bitfield_bit_size) {
293 return clang::QualType();
297 switch (type.front()) {
301 return BuildStruct(clang_ast_ctx, type, for_expression);
303 return BuildArray(clang_ast_ctx, type, for_expression);
305 return BuildUnion(clang_ast_ctx, type, for_expression);
311 llvm::StringRef backup = type;
316 return clang::QualType();
318 return ast_ctx.CharTy;
320 return ast_ctx.IntTy;
322 return ast_ctx.ShortTy;
324 return ast_ctx.getIntTypeForBitwidth(32,
true);
330 return ast_ctx.LongLongTy;
332 return ast_ctx.UnsignedCharTy;
334 return ast_ctx.UnsignedIntTy;
336 return ast_ctx.UnsignedShortTy;
338 return ast_ctx.getIntTypeForBitwidth(32,
false);
341 return ast_ctx.UnsignedLongLongTy;
343 return ast_ctx.FloatTy;
345 return ast_ctx.DoubleTy;
347 return ast_ctx.BoolTy;
349 return ast_ctx.VoidTy;
351 return ast_ctx.getPointerType(ast_ctx.CharTy);
353 return ast_ctx.getObjCClassType();
355 return ast_ctx.getObjCSelType();
358 if (bitfield_bit_size) {
359 *bitfield_bit_size = size;
360 return ast_ctx.UnsignedIntTy;
362 return clang::QualType();
365 clang::QualType target_type =
366 BuildType(clang_ast_ctx, type, for_expression);
367 if (target_type.isNull())
368 return clang::QualType();
369 else if (target_type == ast_ctx.UnknownAnyTy)
370 return ast_ctx.UnknownAnyTy;
372 return ast_ctx.getConstType(target_type);
381 return ast_ctx.VoidPtrTy;
383 clang::QualType target_type =
384 BuildType(clang_ast_ctx, type, for_expression);
385 if (target_type.isNull())
386 return clang::QualType();
387 else if (target_type == ast_ctx.UnknownAnyTy)
388 return ast_ctx.UnknownAnyTy;
390 return ast_ctx.getPointerType(target_type);
394 return for_expression ? ast_ctx.UnknownAnyTy : clang::QualType();
400 bool for_expression) {
401 if (name && name[0]) {
402 llvm::StringRef lexer(name);
403 clang::QualType qual_type =
BuildType(ast_ctx, lexer, for_expression);
404 return ast_ctx.
GetType(qual_type);
static bool consumeChar(llvm::StringRef &str, char c)
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)