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();
152 unsigned int count = 0;
153 for (
auto element : elements) {
154 if (element.name.empty()) {
156 elem_name.
Printf(
"__unnamed_%u", count);
157 element.name = std::string(elem_name.
GetString());
170 TypeSystemClang &ast_ctx, llvm::StringRef &type,
bool for_expression) {
172 return clang::QualType();
175 clang::QualType element_type(
BuildType(ast_ctx, type, for_expression));
177 return clang::QualType();
180 CompilerType(ast_ctx.weak_from_this(), element_type.getAsOpaquePtr()),
192 bool for_expression) {
193 if (!type.consume_front(
_C_ID))
194 return clang::QualType();
200 if (type.consume_front(
'"')) {
221 llvm::StringRef backup = type;
225 return clang::QualType();
228 switch (type.front()) {
246 if (for_expression && !name.empty()) {
247 size_t less_than_pos = name.find(
'<');
249 if (less_than_pos != std::string::npos) {
250 if (less_than_pos == 0)
251 return ast_ctx.getObjCIdType();
253 name.erase(less_than_pos);
258 return clang::QualType();
266 assert(
false &&
"forward declaration without definition");
268 "forward declaration without definition: {0}", name);
269 return ast_ctx.getObjCIdType();
275 return ast_ctx.getObjCIdType();
280 TypeSystemClang &clang_ast_ctx, llvm::StringRef &type,
bool for_expression,
281 uint32_t *bitfield_bit_size) {
283 return clang::QualType();
287 switch (type.front()) {
291 return BuildStruct(clang_ast_ctx, type, for_expression);
293 return BuildArray(clang_ast_ctx, type, for_expression);
295 return BuildUnion(clang_ast_ctx, type, for_expression);
301 llvm::StringRef backup = type;
306 return clang::QualType();
308 return ast_ctx.CharTy;
310 return ast_ctx.IntTy;
312 return ast_ctx.ShortTy;
314 return ast_ctx.getIntTypeForBitwidth(32,
true);
320 return ast_ctx.LongLongTy;
322 return ast_ctx.UnsignedCharTy;
324 return ast_ctx.UnsignedIntTy;
326 return ast_ctx.UnsignedShortTy;
328 return ast_ctx.getIntTypeForBitwidth(32,
false);
331 return ast_ctx.UnsignedLongLongTy;
333 return ast_ctx.FloatTy;
335 return ast_ctx.DoubleTy;
337 return ast_ctx.BoolTy;
339 return ast_ctx.VoidTy;
341 return ast_ctx.getPointerType(ast_ctx.CharTy);
343 return ast_ctx.getObjCClassType();
345 return ast_ctx.getObjCSelType();
348 if (bitfield_bit_size) {
349 *bitfield_bit_size = size;
350 return ast_ctx.UnsignedIntTy;
352 return clang::QualType();
355 clang::QualType target_type =
356 BuildType(clang_ast_ctx, type, for_expression);
357 if (target_type.isNull())
358 return clang::QualType();
359 else if (target_type == ast_ctx.UnknownAnyTy)
360 return ast_ctx.UnknownAnyTy;
362 return ast_ctx.getConstType(target_type);
365 if (!for_expression && type.consume_front(
_C_UNDEF)) {
371 return ast_ctx.VoidPtrTy;
373 clang::QualType target_type =
374 BuildType(clang_ast_ctx, type, for_expression);
375 if (target_type.isNull())
376 return clang::QualType();
377 else if (target_type == ast_ctx.UnknownAnyTy)
378 return ast_ctx.UnknownAnyTy;
380 return ast_ctx.getPointerType(target_type);
384 return for_expression ? ast_ctx.UnknownAnyTy : clang::QualType();
390 bool for_expression) {
391 if (name && name[0]) {
392 llvm::StringRef lexer(name);
393 clang::QualType qual_type =
BuildType(ast_ctx, lexer, for_expression);
394 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.
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...
CompilerType CreateRecordType(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, llvm::StringRef name, int kind, lldb::LanguageType language, std::optional< ClangASTMetadata > metadata=std::nullopt, bool exports_symbols=false)
static bool CompleteTagDeclarationDefinition(const CompilerType &type)
static bool StartTagDeclarationDefinition(const CompilerType &type)
static clang::FieldDecl * AddFieldToRecordType(const CompilerType &type, llvm::StringRef name, const CompilerType &field_type, uint32_t bitfield_bit_size)
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)