Ejemplo n.º 1
0
static ClangASTType
GetLLDBNSPairType (TargetSP target_sp)
{
    ClangASTType clang_type;

    ClangASTContext *target_ast_context = target_sp->GetScratchClangASTContext();

    if (target_ast_context)
    {
        ConstString g___lldb_autogen_nspair("__lldb_autogen_nspair");

        clang_type = target_ast_context->GetTypeForIdentifier<clang::CXXRecordDecl>(g___lldb_autogen_nspair);
        
        if (!clang_type)
        {
            clang_type = target_ast_context->CreateRecordType(NULL, lldb::eAccessPublic, g___lldb_autogen_nspair.GetCString(), clang::TTK_Struct, lldb::eLanguageTypeC);
            
            if (clang_type)
            {
                clang_type.StartTagDeclarationDefinition();
                ClangASTType id_clang_type = target_ast_context->GetBasicType (eBasicTypeObjCID);
                clang_type.AddFieldToRecordType("key", id_clang_type, lldb::eAccessPublic, 0);
                clang_type.AddFieldToRecordType("value", id_clang_type, lldb::eAccessPublic, 0);
                clang_type.CompleteTagDeclarationDefinition();
            }
        }
    }
    return clang_type;
}
Ejemplo n.º 2
0
static ClangASTType
GetLLDBNSPairType (TargetSP target_sp)
{
    ClangASTType clang_type;

    ClangASTContext *target_ast_context = target_sp->GetScratchClangASTContext();

    if (target_ast_context)
    {
        clang::ASTContext *ast = target_ast_context->getASTContext();

        if (ast)
        {
            const char* type_name = "__lldb_autogen_nspair";
            
            clang::IdentifierInfo &myIdent = ast->Idents.get(type_name);
            clang::DeclarationName myName = ast->DeclarationNames.getIdentifier(&myIdent);

            clang::DeclContext::lookup_const_result result = ast->getTranslationUnitDecl()->lookup(myName);

            for (clang::NamedDecl *named_decl : result)
            {
                if (const clang::CXXRecordDecl *record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(named_decl))
                {
                    clang_type.SetClangType(ast, clang::QualType(record_decl->getTypeForDecl(), 0));
                    break;
                }
                else
                {
                    // somebody else (the user?) has defined a type with the magic name already - fail!!!
                    return clang_type;
                }
            }

            if (!clang_type)
            {
                clang_type = target_ast_context->CreateRecordType(NULL, lldb::eAccessPublic, type_name, clang::TTK_Struct, lldb::eLanguageTypeC);
                
                if (clang_type)
                {
                    clang_type.StartTagDeclarationDefinition();
                    ClangASTType id_clang_type = target_ast_context->GetBasicType (eBasicTypeObjCID);
                    clang_type.AddFieldToRecordType("key", id_clang_type, lldb::eAccessPublic, 0);
                    clang_type.AddFieldToRecordType("value", id_clang_type, lldb::eAccessPublic, 0);
                    clang_type.CompleteTagDeclarationDefinition();
                }
            }
        }
    }
    return clang_type;
}