Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ClangASTContext.cpp -------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Eli Friedman | 932197d | 2010-06-13 19:06:42 +0000 | [diff] [blame] | 10 | #include "lldb/Symbol/ClangASTContext.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | #include <string> |
| 15 | |
| 16 | // Other libraries and framework includes |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 17 | |
| 18 | // Clang headers like to use NDEBUG inside of them to enable/disable debug |
| 19 | // releated features using "#ifndef NDEBUG" preprocessor blocks to do one thing |
| 20 | // or another. This is bad because it means that if clang was built in release |
| 21 | // mode, it assumes that you are building in release mode which is not always |
| 22 | // the case. You can end up with functions that are defined as empty in header |
| 23 | // files when NDEBUG is not defined, and this can cause link errors with the |
| 24 | // clang .a files that you have since you might be missing functions in the .a |
| 25 | // file. So we have to define NDEBUG when including clang headers to avoid any |
| 26 | // mismatches. This is covered by rdar://problem/8691220 |
| 27 | |
Sean Callanan | 3b1d4f6 | 2011-10-26 17:46:51 +0000 | [diff] [blame] | 28 | #if !defined(NDEBUG) && !defined(LLVM_NDEBUG_OFF) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 29 | #define LLDB_DEFINED_NDEBUG_FOR_CLANG |
Sean Callanan | 246549c | 2010-07-08 18:16:16 +0000 | [diff] [blame] | 30 | #define NDEBUG |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 31 | // Need to include assert.h so it is as clang would expect it to be (disabled) |
| 32 | #include <assert.h> |
| 33 | #endif |
| 34 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | #include "clang/AST/ASTContext.h" |
| 36 | #include "clang/AST/ASTImporter.h" |
Greg Clayton | f74c403 | 2012-12-03 18:29:55 +0000 | [diff] [blame] | 37 | #include "clang/AST/Attr.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 38 | #include "clang/AST/CXXInheritance.h" |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 39 | #include "clang/AST/DeclObjC.h" |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 40 | #include "clang/AST/DeclTemplate.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 41 | #include "clang/AST/RecordLayout.h" |
| 42 | #include "clang/AST/Type.h" |
| 43 | #include "clang/Basic/Builtins.h" |
Sean Callanan | 7e2863b | 2012-02-06 21:28:03 +0000 | [diff] [blame] | 44 | #include "clang/Basic/Diagnostic.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | #include "clang/Basic/FileManager.h" |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 46 | #include "clang/Basic/FileSystemOptions.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | #include "clang/Basic/SourceManager.h" |
| 48 | #include "clang/Basic/TargetInfo.h" |
| 49 | #include "clang/Basic/TargetOptions.h" |
| 50 | #include "clang/Frontend/FrontendOptions.h" |
| 51 | #include "clang/Frontend/LangStandard.h" |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 52 | |
| 53 | #ifdef LLDB_DEFINED_NDEBUG_FOR_CLANG |
Sean Callanan | 246549c | 2010-07-08 18:16:16 +0000 | [diff] [blame] | 54 | #undef NDEBUG |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 55 | #undef LLDB_DEFINED_NDEBUG_FOR_CLANG |
| 56 | // Need to re-include assert.h so it is as _we_ would expect it to be (enabled) |
| 57 | #include <assert.h> |
| 58 | #endif |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 60 | #include "lldb/Core/ArchSpec.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | #include "lldb/Core/dwarf.h" |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 62 | #include "lldb/Core/Flags.h" |
Sean Callanan | fb8b709 | 2010-10-28 18:19:36 +0000 | [diff] [blame] | 63 | #include "lldb/Core/Log.h" |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 64 | #include "lldb/Core/RegularExpression.h" |
| 65 | #include "lldb/Expression/ASTDumper.h" |
Sean Callanan | 3b107b1 | 2011-12-03 03:15:28 +0000 | [diff] [blame] | 66 | #include "lldb/Symbol/ClangExternalASTSourceCommon.h" |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 67 | #include "lldb/Symbol/VerifyDecl.h" |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 68 | #include "lldb/Target/ExecutionContext.h" |
| 69 | #include "lldb/Target/Process.h" |
| 70 | #include "lldb/Target/ObjCLanguageRuntime.h" |
| 71 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | |
Eli Friedman | 932197d | 2010-06-13 19:06:42 +0000 | [diff] [blame] | 73 | #include <stdio.h> |
| 74 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 75 | using namespace lldb; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 76 | using namespace lldb_private; |
| 77 | using namespace llvm; |
| 78 | using namespace clang; |
| 79 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 80 | |
| 81 | static bool |
Enrico Granata | 86027e9 | 2012-03-24 01:11:14 +0000 | [diff] [blame] | 82 | GetCompleteQualType (clang::ASTContext *ast, clang::QualType qual_type, bool allow_completion = true) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 83 | { |
| 84 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 85 | switch (type_class) |
| 86 | { |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 87 | case clang::Type::ConstantArray: |
| 88 | { |
| 89 | const clang::ArrayType *array_type = dyn_cast<clang::ArrayType>(qual_type.getTypePtr()); |
| 90 | |
| 91 | if (array_type) |
Enrico Granata | 86027e9 | 2012-03-24 01:11:14 +0000 | [diff] [blame] | 92 | return GetCompleteQualType (ast, array_type->getElementType(), allow_completion); |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 93 | } |
| 94 | break; |
| 95 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 96 | case clang::Type::Record: |
| 97 | case clang::Type::Enum: |
| 98 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 99 | const clang::TagType *tag_type = dyn_cast<clang::TagType>(qual_type.getTypePtr()); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 100 | if (tag_type) |
| 101 | { |
| 102 | clang::TagDecl *tag_decl = tag_type->getDecl(); |
| 103 | if (tag_decl) |
| 104 | { |
Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 105 | if (tag_decl->isCompleteDefinition()) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 106 | return true; |
Enrico Granata | 86027e9 | 2012-03-24 01:11:14 +0000 | [diff] [blame] | 107 | |
| 108 | if (!allow_completion) |
| 109 | return false; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 110 | |
| 111 | if (tag_decl->hasExternalLexicalStorage()) |
| 112 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 113 | if (ast) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 114 | { |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 115 | ExternalASTSource *external_ast_source = ast->getExternalSource(); |
| 116 | if (external_ast_source) |
| 117 | { |
| 118 | external_ast_source->CompleteType(tag_decl); |
| 119 | return !tag_type->isIncompleteType(); |
| 120 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | return false; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | } |
| 128 | break; |
| 129 | |
| 130 | case clang::Type::ObjCObject: |
| 131 | case clang::Type::ObjCInterface: |
| 132 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 133 | const clang::ObjCObjectType *objc_class_type = dyn_cast<clang::ObjCObjectType>(qual_type); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 134 | if (objc_class_type) |
| 135 | { |
| 136 | clang::ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 137 | // We currently can't complete objective C types through the newly added ASTContext |
| 138 | // because it only supports TagDecl objects right now... |
Enrico Granata | 9dd75c8 | 2011-07-15 23:30:15 +0000 | [diff] [blame] | 139 | if (class_interface_decl) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 140 | { |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 141 | if (class_interface_decl->getDefinition()) |
| 142 | return true; |
| 143 | |
Enrico Granata | 86027e9 | 2012-03-24 01:11:14 +0000 | [diff] [blame] | 144 | if (!allow_completion) |
| 145 | return false; |
Greg Clayton | 2053398 | 2012-03-30 23:48:28 +0000 | [diff] [blame] | 146 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 147 | if (class_interface_decl->hasExternalLexicalStorage()) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 148 | { |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 149 | if (ast) |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 150 | { |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 151 | ExternalASTSource *external_ast_source = ast->getExternalSource(); |
| 152 | if (external_ast_source) |
| 153 | { |
| 154 | external_ast_source->CompleteType (class_interface_decl); |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 155 | return !objc_class_type->isIncompleteType(); |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 156 | } |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 157 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 158 | } |
Enrico Granata | 0a3958e | 2011-07-02 00:25:22 +0000 | [diff] [blame] | 159 | return false; |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 160 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 161 | } |
| 162 | } |
| 163 | break; |
| 164 | |
| 165 | case clang::Type::Typedef: |
Enrico Granata | 86027e9 | 2012-03-24 01:11:14 +0000 | [diff] [blame] | 166 | return GetCompleteQualType (ast, cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType(), allow_completion); |
Sean Callanan | 912855f | 2011-08-11 23:56:13 +0000 | [diff] [blame] | 167 | |
| 168 | case clang::Type::Elaborated: |
Enrico Granata | 86027e9 | 2012-03-24 01:11:14 +0000 | [diff] [blame] | 169 | return GetCompleteQualType (ast, cast<ElaboratedType>(qual_type)->getNamedType(), allow_completion); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 170 | |
| 171 | default: |
| 172 | break; |
| 173 | } |
| 174 | |
| 175 | return true; |
| 176 | } |
| 177 | |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 178 | static AccessSpecifier |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 179 | ConvertAccessTypeToAccessSpecifier (AccessType access) |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 180 | { |
| 181 | switch (access) |
| 182 | { |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 183 | default: break; |
| 184 | case eAccessNone: return AS_none; |
| 185 | case eAccessPublic: return AS_public; |
| 186 | case eAccessPrivate: return AS_private; |
| 187 | case eAccessProtected: return AS_protected; |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 188 | } |
| 189 | return AS_none; |
| 190 | } |
| 191 | |
| 192 | static ObjCIvarDecl::AccessControl |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 193 | ConvertAccessTypeToObjCIvarAccessControl (AccessType access) |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 194 | { |
| 195 | switch (access) |
| 196 | { |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 197 | case eAccessNone: return ObjCIvarDecl::None; |
| 198 | case eAccessPublic: return ObjCIvarDecl::Public; |
| 199 | case eAccessPrivate: return ObjCIvarDecl::Private; |
| 200 | case eAccessProtected: return ObjCIvarDecl::Protected; |
| 201 | case eAccessPackage: return ObjCIvarDecl::Package; |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 202 | } |
| 203 | return ObjCIvarDecl::None; |
| 204 | } |
| 205 | |
| 206 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 207 | static void |
| 208 | ParseLangArgs |
| 209 | ( |
| 210 | LangOptions &Opts, |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 211 | InputKind IK |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 212 | ) |
| 213 | { |
| 214 | // FIXME: Cleanup per-file based stuff. |
| 215 | |
| 216 | // Set some properties which depend soley on the input kind; it would be nice |
| 217 | // to move these to the language standard, and have the driver resolve the |
| 218 | // input kind + language standard. |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 219 | if (IK == IK_Asm) { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 220 | Opts.AsmPreprocessor = 1; |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 221 | } else if (IK == IK_ObjC || |
| 222 | IK == IK_ObjCXX || |
| 223 | IK == IK_PreprocessedObjC || |
| 224 | IK == IK_PreprocessedObjCXX) { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 225 | Opts.ObjC1 = Opts.ObjC2 = 1; |
| 226 | } |
| 227 | |
| 228 | LangStandard::Kind LangStd = LangStandard::lang_unspecified; |
| 229 | |
| 230 | if (LangStd == LangStandard::lang_unspecified) { |
| 231 | // Based on the base language, pick one. |
| 232 | switch (IK) { |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 233 | case IK_None: |
| 234 | case IK_AST: |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 235 | case IK_LLVM_IR: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 236 | assert (!"Invalid input kind!"); |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 237 | case IK_OpenCL: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 238 | LangStd = LangStandard::lang_opencl; |
| 239 | break; |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 240 | case IK_CUDA: |
| 241 | LangStd = LangStandard::lang_cuda; |
| 242 | break; |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 243 | case IK_Asm: |
| 244 | case IK_C: |
| 245 | case IK_PreprocessedC: |
| 246 | case IK_ObjC: |
| 247 | case IK_PreprocessedObjC: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 248 | LangStd = LangStandard::lang_gnu99; |
| 249 | break; |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 250 | case IK_CXX: |
| 251 | case IK_PreprocessedCXX: |
| 252 | case IK_ObjCXX: |
| 253 | case IK_PreprocessedObjCXX: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 254 | LangStd = LangStandard::lang_gnucxx98; |
| 255 | break; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | const LangStandard &Std = LangStandard::getLangStandardForKind(LangStd); |
Filipe Cabecinhas | e818ca2 | 2012-11-12 21:26:32 +0000 | [diff] [blame] | 260 | Opts.LineComment = Std.hasLineComments(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 261 | Opts.C99 = Std.isC99(); |
| 262 | Opts.CPlusPlus = Std.isCPlusPlus(); |
Chandler Carruth | 38336a1 | 2013-01-02 12:55:00 +0000 | [diff] [blame] | 263 | Opts.CPlusPlus11 = Std.isCPlusPlus11(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 264 | Opts.Digraphs = Std.hasDigraphs(); |
| 265 | Opts.GNUMode = Std.isGNUMode(); |
| 266 | Opts.GNUInline = !Std.isC99(); |
| 267 | Opts.HexFloats = Std.hasHexFloats(); |
| 268 | Opts.ImplicitInt = Std.hasImplicitInt(); |
Enrico Granata | c921e34 | 2013-01-10 02:37:22 +0000 | [diff] [blame] | 269 | |
| 270 | Opts.WChar = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 271 | |
| 272 | // OpenCL has some additional defaults. |
| 273 | if (LangStd == LangStandard::lang_opencl) { |
| 274 | Opts.OpenCL = 1; |
| 275 | Opts.AltiVec = 1; |
| 276 | Opts.CXXOperatorNames = 1; |
| 277 | Opts.LaxVectorConversions = 1; |
| 278 | } |
| 279 | |
| 280 | // OpenCL and C++ both have bool, true, false keywords. |
| 281 | Opts.Bool = Opts.OpenCL || Opts.CPlusPlus; |
| 282 | |
| 283 | // if (Opts.CPlusPlus) |
| 284 | // Opts.CXXOperatorNames = !Args.hasArg(OPT_fno_operator_names); |
| 285 | // |
| 286 | // if (Args.hasArg(OPT_fobjc_gc_only)) |
| 287 | // Opts.setGCMode(LangOptions::GCOnly); |
| 288 | // else if (Args.hasArg(OPT_fobjc_gc)) |
| 289 | // Opts.setGCMode(LangOptions::HybridGC); |
| 290 | // |
| 291 | // if (Args.hasArg(OPT_print_ivar_layout)) |
| 292 | // Opts.ObjCGCBitmapPrint = 1; |
| 293 | // |
| 294 | // if (Args.hasArg(OPT_faltivec)) |
| 295 | // Opts.AltiVec = 1; |
| 296 | // |
| 297 | // if (Args.hasArg(OPT_pthread)) |
| 298 | // Opts.POSIXThreads = 1; |
| 299 | // |
| 300 | // llvm::StringRef Vis = getLastArgValue(Args, OPT_fvisibility, |
| 301 | // "default"); |
| 302 | // if (Vis == "default") |
Sean Callanan | 31e851c | 2010-10-29 18:38:40 +0000 | [diff] [blame] | 303 | Opts.setVisibilityMode(DefaultVisibility); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 304 | // else if (Vis == "hidden") |
| 305 | // Opts.setVisibilityMode(LangOptions::Hidden); |
| 306 | // else if (Vis == "protected") |
| 307 | // Opts.setVisibilityMode(LangOptions::Protected); |
| 308 | // else |
| 309 | // Diags.Report(diag::err_drv_invalid_value) |
| 310 | // << Args.getLastArg(OPT_fvisibility)->getAsString(Args) << Vis; |
| 311 | |
| 312 | // Opts.OverflowChecking = Args.hasArg(OPT_ftrapv); |
| 313 | |
| 314 | // Mimicing gcc's behavior, trigraphs are only enabled if -trigraphs |
| 315 | // is specified, or -std is set to a conforming mode. |
| 316 | Opts.Trigraphs = !Opts.GNUMode; |
| 317 | // if (Args.hasArg(OPT_trigraphs)) |
| 318 | // Opts.Trigraphs = 1; |
| 319 | // |
| 320 | // Opts.DollarIdents = Args.hasFlag(OPT_fdollars_in_identifiers, |
| 321 | // OPT_fno_dollars_in_identifiers, |
| 322 | // !Opts.AsmPreprocessor); |
| 323 | // Opts.PascalStrings = Args.hasArg(OPT_fpascal_strings); |
| 324 | // Opts.Microsoft = Args.hasArg(OPT_fms_extensions); |
| 325 | // Opts.WritableStrings = Args.hasArg(OPT_fwritable_strings); |
| 326 | // if (Args.hasArg(OPT_fno_lax_vector_conversions)) |
| 327 | // Opts.LaxVectorConversions = 0; |
| 328 | // Opts.Exceptions = Args.hasArg(OPT_fexceptions); |
| 329 | // Opts.RTTI = !Args.hasArg(OPT_fno_rtti); |
| 330 | // Opts.Blocks = Args.hasArg(OPT_fblocks); |
| 331 | // Opts.CharIsSigned = !Args.hasArg(OPT_fno_signed_char); |
| 332 | // Opts.ShortWChar = Args.hasArg(OPT_fshort_wchar); |
| 333 | // Opts.Freestanding = Args.hasArg(OPT_ffreestanding); |
| 334 | // Opts.NoBuiltin = Args.hasArg(OPT_fno_builtin) || Opts.Freestanding; |
| 335 | // Opts.AssumeSaneOperatorNew = !Args.hasArg(OPT_fno_assume_sane_operator_new); |
| 336 | // Opts.HeinousExtensions = Args.hasArg(OPT_fheinous_gnu_extensions); |
| 337 | // Opts.AccessControl = Args.hasArg(OPT_faccess_control); |
| 338 | // Opts.ElideConstructors = !Args.hasArg(OPT_fno_elide_constructors); |
| 339 | // Opts.MathErrno = !Args.hasArg(OPT_fno_math_errno); |
| 340 | // Opts.InstantiationDepth = getLastArgIntValue(Args, OPT_ftemplate_depth, 99, |
| 341 | // Diags); |
| 342 | // Opts.NeXTRuntime = !Args.hasArg(OPT_fgnu_runtime); |
| 343 | // Opts.ObjCConstantStringClass = getLastArgValue(Args, |
| 344 | // OPT_fconstant_string_class); |
| 345 | // Opts.ObjCNonFragileABI = Args.hasArg(OPT_fobjc_nonfragile_abi); |
| 346 | // Opts.CatchUndefined = Args.hasArg(OPT_fcatch_undefined_behavior); |
| 347 | // Opts.EmitAllDecls = Args.hasArg(OPT_femit_all_decls); |
| 348 | // Opts.PICLevel = getLastArgIntValue(Args, OPT_pic_level, 0, Diags); |
| 349 | // Opts.Static = Args.hasArg(OPT_static_define); |
| 350 | Opts.OptimizeSize = 0; |
| 351 | |
| 352 | // FIXME: Eliminate this dependency. |
| 353 | // unsigned Opt = |
| 354 | // Args.hasArg(OPT_Os) ? 2 : getLastArgIntValue(Args, OPT_O, 0, Diags); |
| 355 | // Opts.Optimize = Opt != 0; |
| 356 | unsigned Opt = 0; |
| 357 | |
| 358 | // This is the __NO_INLINE__ define, which just depends on things like the |
| 359 | // optimization level and -fno-inline, not actually whether the backend has |
| 360 | // inlining enabled. |
| 361 | // |
| 362 | // FIXME: This is affected by other options (-fno-inline). |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 363 | Opts.NoInlineDefine = !Opt; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 364 | |
| 365 | // unsigned SSP = getLastArgIntValue(Args, OPT_stack_protector, 0, Diags); |
| 366 | // switch (SSP) { |
| 367 | // default: |
| 368 | // Diags.Report(diag::err_drv_invalid_value) |
| 369 | // << Args.getLastArg(OPT_stack_protector)->getAsString(Args) << SSP; |
| 370 | // break; |
| 371 | // case 0: Opts.setStackProtectorMode(LangOptions::SSPOff); break; |
| 372 | // case 1: Opts.setStackProtectorMode(LangOptions::SSPOn); break; |
| 373 | // case 2: Opts.setStackProtectorMode(LangOptions::SSPReq); break; |
| 374 | // } |
| 375 | } |
| 376 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 377 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 378 | ClangASTContext::ClangASTContext (const char *target_triple) : |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 379 | m_target_triple(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 380 | m_ast_ap(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 381 | m_language_options_ap(), |
| 382 | m_source_manager_ap(), |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 383 | m_diagnostics_engine_ap(), |
Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 384 | m_target_options_rp(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 385 | m_target_info_ap(), |
| 386 | m_identifier_table_ap(), |
| 387 | m_selector_table_ap(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 388 | m_builtins_ap(), |
| 389 | m_callback_tag_decl (NULL), |
| 390 | m_callback_objc_decl (NULL), |
| 391 | m_callback_baton (NULL) |
| 392 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 393 | { |
| 394 | if (target_triple && target_triple[0]) |
Greg Clayton | 880cbb0 | 2011-07-30 01:26:02 +0000 | [diff] [blame] | 395 | SetTargetTriple (target_triple); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | //---------------------------------------------------------------------- |
| 399 | // Destructor |
| 400 | //---------------------------------------------------------------------- |
| 401 | ClangASTContext::~ClangASTContext() |
| 402 | { |
| 403 | m_builtins_ap.reset(); |
| 404 | m_selector_table_ap.reset(); |
| 405 | m_identifier_table_ap.reset(); |
| 406 | m_target_info_ap.reset(); |
Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 407 | m_target_options_rp.reset(); |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 408 | m_diagnostics_engine_ap.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 409 | m_source_manager_ap.reset(); |
| 410 | m_language_options_ap.reset(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 411 | m_ast_ap.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | |
| 415 | void |
| 416 | ClangASTContext::Clear() |
| 417 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 418 | m_ast_ap.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 419 | m_language_options_ap.reset(); |
| 420 | m_source_manager_ap.reset(); |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 421 | m_diagnostics_engine_ap.reset(); |
Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 422 | m_target_options_rp.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 423 | m_target_info_ap.reset(); |
| 424 | m_identifier_table_ap.reset(); |
| 425 | m_selector_table_ap.reset(); |
| 426 | m_builtins_ap.reset(); |
| 427 | } |
| 428 | |
| 429 | const char * |
| 430 | ClangASTContext::GetTargetTriple () |
| 431 | { |
| 432 | return m_target_triple.c_str(); |
| 433 | } |
| 434 | |
| 435 | void |
| 436 | ClangASTContext::SetTargetTriple (const char *target_triple) |
| 437 | { |
| 438 | Clear(); |
| 439 | m_target_triple.assign(target_triple); |
| 440 | } |
| 441 | |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 442 | void |
| 443 | ClangASTContext::SetArchitecture (const ArchSpec &arch) |
| 444 | { |
Greg Clayton | 880cbb0 | 2011-07-30 01:26:02 +0000 | [diff] [blame] | 445 | SetTargetTriple(arch.GetTriple().str().c_str()); |
Greg Clayton | 514487e | 2011-02-15 21:59:32 +0000 | [diff] [blame] | 446 | } |
| 447 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 448 | bool |
| 449 | ClangASTContext::HasExternalSource () |
| 450 | { |
| 451 | ASTContext *ast = getASTContext(); |
| 452 | if (ast) |
| 453 | return ast->getExternalSource () != NULL; |
| 454 | return false; |
| 455 | } |
| 456 | |
| 457 | void |
| 458 | ClangASTContext::SetExternalSource (llvm::OwningPtr<ExternalASTSource> &ast_source_ap) |
| 459 | { |
| 460 | ASTContext *ast = getASTContext(); |
| 461 | if (ast) |
| 462 | { |
| 463 | ast->setExternalSource (ast_source_ap); |
| 464 | ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(true); |
| 465 | //ast->getTranslationUnitDecl()->setHasExternalVisibleStorage(true); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | void |
| 470 | ClangASTContext::RemoveExternalSource () |
| 471 | { |
| 472 | ASTContext *ast = getASTContext(); |
| 473 | |
| 474 | if (ast) |
| 475 | { |
| 476 | llvm::OwningPtr<ExternalASTSource> empty_ast_source_ap; |
| 477 | ast->setExternalSource (empty_ast_source_ap); |
| 478 | ast->getTranslationUnitDecl()->setHasExternalLexicalStorage(false); |
| 479 | //ast->getTranslationUnitDecl()->setHasExternalVisibleStorage(false); |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 484 | |
| 485 | ASTContext * |
| 486 | ClangASTContext::getASTContext() |
| 487 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 488 | if (m_ast_ap.get() == NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 489 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 490 | m_ast_ap.reset(new ASTContext (*getLanguageOptions(), |
| 491 | *getSourceManager(), |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 492 | getTargetInfo(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 493 | *getIdentifierTable(), |
| 494 | *getSelectorTable(), |
| 495 | *getBuiltinContext(), |
| 496 | 0)); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 497 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 498 | if ((m_callback_tag_decl || m_callback_objc_decl) && m_callback_baton) |
| 499 | { |
| 500 | m_ast_ap->getTranslationUnitDecl()->setHasExternalLexicalStorage(); |
| 501 | //m_ast_ap->getTranslationUnitDecl()->setHasExternalVisibleStorage(); |
| 502 | } |
| 503 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 504 | m_ast_ap->getDiagnostics().setClient(getDiagnosticConsumer(), false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 505 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 506 | return m_ast_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | Builtin::Context * |
| 510 | ClangASTContext::getBuiltinContext() |
| 511 | { |
| 512 | if (m_builtins_ap.get() == NULL) |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 513 | m_builtins_ap.reset (new Builtin::Context()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 514 | return m_builtins_ap.get(); |
| 515 | } |
| 516 | |
| 517 | IdentifierTable * |
| 518 | ClangASTContext::getIdentifierTable() |
| 519 | { |
| 520 | if (m_identifier_table_ap.get() == NULL) |
| 521 | m_identifier_table_ap.reset(new IdentifierTable (*ClangASTContext::getLanguageOptions(), NULL)); |
| 522 | return m_identifier_table_ap.get(); |
| 523 | } |
| 524 | |
| 525 | LangOptions * |
| 526 | ClangASTContext::getLanguageOptions() |
| 527 | { |
| 528 | if (m_language_options_ap.get() == NULL) |
| 529 | { |
| 530 | m_language_options_ap.reset(new LangOptions()); |
Greg Clayton | 94e5d78 | 2010-06-13 17:34:29 +0000 | [diff] [blame] | 531 | ParseLangArgs(*m_language_options_ap, IK_ObjCXX); |
| 532 | // InitializeLangOptions(*m_language_options_ap, IK_ObjCXX); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 533 | } |
| 534 | return m_language_options_ap.get(); |
| 535 | } |
| 536 | |
| 537 | SelectorTable * |
| 538 | ClangASTContext::getSelectorTable() |
| 539 | { |
| 540 | if (m_selector_table_ap.get() == NULL) |
| 541 | m_selector_table_ap.reset (new SelectorTable()); |
| 542 | return m_selector_table_ap.get(); |
| 543 | } |
| 544 | |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 545 | clang::FileManager * |
| 546 | ClangASTContext::getFileManager() |
| 547 | { |
| 548 | if (m_file_manager_ap.get() == NULL) |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 549 | { |
| 550 | clang::FileSystemOptions file_system_options; |
| 551 | m_file_manager_ap.reset(new clang::FileManager(file_system_options)); |
| 552 | } |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 553 | return m_file_manager_ap.get(); |
| 554 | } |
| 555 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 556 | clang::SourceManager * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 557 | ClangASTContext::getSourceManager() |
| 558 | { |
| 559 | if (m_source_manager_ap.get() == NULL) |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 560 | m_source_manager_ap.reset(new clang::SourceManager(*getDiagnosticsEngine(), *getFileManager())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 561 | return m_source_manager_ap.get(); |
| 562 | } |
| 563 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 564 | clang::DiagnosticsEngine * |
| 565 | ClangASTContext::getDiagnosticsEngine() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 566 | { |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 567 | if (m_diagnostics_engine_ap.get() == NULL) |
Greg Clayton | a651b53 | 2010-11-19 21:46:54 +0000 | [diff] [blame] | 568 | { |
| 569 | llvm::IntrusiveRefCntPtr<DiagnosticIDs> diag_id_sp(new DiagnosticIDs()); |
Sean Callanan | ec8f1ef | 2012-10-25 01:00:25 +0000 | [diff] [blame] | 570 | m_diagnostics_engine_ap.reset(new DiagnosticsEngine(diag_id_sp, new DiagnosticOptions())); |
Greg Clayton | a651b53 | 2010-11-19 21:46:54 +0000 | [diff] [blame] | 571 | } |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 572 | return m_diagnostics_engine_ap.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 573 | } |
| 574 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 575 | class NullDiagnosticConsumer : public DiagnosticConsumer |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 576 | { |
| 577 | public: |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 578 | NullDiagnosticConsumer () |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 579 | { |
| 580 | m_log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS); |
| 581 | } |
| 582 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 583 | void HandleDiagnostic (DiagnosticsEngine::Level DiagLevel, const Diagnostic &info) |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 584 | { |
| 585 | if (m_log) |
| 586 | { |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 587 | llvm::SmallVector<char, 32> diag_str(10); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 588 | info.FormatDiagnostic(diag_str); |
| 589 | diag_str.push_back('\0'); |
| 590 | m_log->Printf("Compiler diagnostic: %s\n", diag_str.data()); |
| 591 | } |
| 592 | } |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 593 | |
| 594 | DiagnosticConsumer *clone (DiagnosticsEngine &Diags) const |
| 595 | { |
| 596 | return new NullDiagnosticConsumer (); |
| 597 | } |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 598 | private: |
| 599 | LogSP m_log; |
| 600 | }; |
| 601 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 602 | DiagnosticConsumer * |
| 603 | ClangASTContext::getDiagnosticConsumer() |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 604 | { |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 605 | if (m_diagnostic_consumer_ap.get() == NULL) |
| 606 | m_diagnostic_consumer_ap.reset(new NullDiagnosticConsumer); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 607 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 608 | return m_diagnostic_consumer_ap.get(); |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 611 | TargetOptions * |
| 612 | ClangASTContext::getTargetOptions() |
| 613 | { |
Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 614 | if (m_target_options_rp.getPtr() == NULL && !m_target_triple.empty()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 615 | { |
Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 616 | m_target_options_rp.reset (); |
| 617 | m_target_options_rp = new TargetOptions(); |
| 618 | if (m_target_options_rp.getPtr() != NULL) |
| 619 | m_target_options_rp->Triple = m_target_triple; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 620 | } |
Sean Callanan | c5069ad | 2012-10-17 22:11:14 +0000 | [diff] [blame] | 621 | return m_target_options_rp.getPtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | |
| 625 | TargetInfo * |
| 626 | ClangASTContext::getTargetInfo() |
| 627 | { |
Greg Clayton | 7051231 | 2012-05-08 01:45:38 +0000 | [diff] [blame] | 628 | // target_triple should be something like "x86_64-apple-macosx" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 629 | if (m_target_info_ap.get() == NULL && !m_target_triple.empty()) |
Greg Clayton | 38d880a | 2012-11-16 21:35:22 +0000 | [diff] [blame] | 630 | m_target_info_ap.reset (TargetInfo::CreateTargetInfo(*getDiagnosticsEngine(), getTargetOptions())); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 631 | return m_target_info_ap.get(); |
| 632 | } |
| 633 | |
| 634 | #pragma mark Basic Types |
| 635 | |
| 636 | static inline bool |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 637 | QualTypeMatchesBitSize(const uint64_t bit_size, ASTContext *ast, QualType qual_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 638 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 639 | uint64_t qual_type_bit_size = ast->getTypeSize(qual_type); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 640 | if (qual_type_bit_size == bit_size) |
| 641 | return true; |
| 642 | return false; |
| 643 | } |
| 644 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 645 | clang_type_t |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 646 | ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (Encoding encoding, uint32_t bit_size) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 647 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 648 | ASTContext *ast = getASTContext(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 649 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 650 | assert (ast != NULL); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 651 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 652 | return GetBuiltinTypeForEncodingAndBitSize (ast, encoding, bit_size); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 655 | clang_type_t |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 656 | ClangASTContext::GetBuiltinTypeForEncodingAndBitSize (ASTContext *ast, Encoding encoding, uint32_t bit_size) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 657 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 658 | if (!ast) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 659 | return NULL; |
| 660 | |
| 661 | switch (encoding) |
| 662 | { |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 663 | case eEncodingInvalid: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 664 | if (QualTypeMatchesBitSize (bit_size, ast, ast->VoidPtrTy)) |
| 665 | return ast->VoidPtrTy.getAsOpaquePtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 666 | break; |
| 667 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 668 | case eEncodingUint: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 669 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
| 670 | return ast->UnsignedCharTy.getAsOpaquePtr(); |
| 671 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
| 672 | return ast->UnsignedShortTy.getAsOpaquePtr(); |
| 673 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) |
| 674 | return ast->UnsignedIntTy.getAsOpaquePtr(); |
| 675 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy)) |
| 676 | return ast->UnsignedLongTy.getAsOpaquePtr(); |
| 677 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy)) |
| 678 | return ast->UnsignedLongLongTy.getAsOpaquePtr(); |
| 679 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty)) |
| 680 | return ast->UnsignedInt128Ty.getAsOpaquePtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 681 | break; |
| 682 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 683 | case eEncodingSint: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 684 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
| 685 | return ast->CharTy.getAsOpaquePtr(); |
| 686 | if (QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy)) |
| 687 | return ast->ShortTy.getAsOpaquePtr(); |
| 688 | if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy)) |
| 689 | return ast->IntTy.getAsOpaquePtr(); |
| 690 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongTy)) |
| 691 | return ast->LongTy.getAsOpaquePtr(); |
| 692 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy)) |
| 693 | return ast->LongLongTy.getAsOpaquePtr(); |
| 694 | if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty)) |
| 695 | return ast->Int128Ty.getAsOpaquePtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 696 | break; |
| 697 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 698 | case eEncodingIEEE754: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 699 | if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy)) |
| 700 | return ast->FloatTy.getAsOpaquePtr(); |
| 701 | if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy)) |
| 702 | return ast->DoubleTy.getAsOpaquePtr(); |
| 703 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy)) |
| 704 | return ast->LongDoubleTy.getAsOpaquePtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 705 | break; |
| 706 | |
Greg Clayton | c86103d | 2010-08-05 01:57:25 +0000 | [diff] [blame] | 707 | case eEncodingVector: |
Johnny Chen | c79c93a | 2012-03-07 01:12:24 +0000 | [diff] [blame] | 708 | // Sanity check that bit_size is a multiple of 8's. |
| 709 | if (bit_size && !(bit_size & 0x7u)) |
| 710 | return ast->getExtVectorType (ast->UnsignedCharTy, bit_size/8).getAsOpaquePtr(); |
| 711 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | return NULL; |
| 715 | } |
| 716 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 717 | clang_type_t |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 718 | ClangASTContext::GetBuiltinTypeForDWARFEncodingAndBitSize (const char *type_name, uint32_t dw_ate, uint32_t bit_size) |
| 719 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 720 | ASTContext *ast = getASTContext(); |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 721 | |
| 722 | #define streq(a,b) strcmp(a,b) == 0 |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 723 | assert (ast != NULL); |
| 724 | if (ast) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 725 | { |
| 726 | switch (dw_ate) |
| 727 | { |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 728 | default: |
| 729 | break; |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 730 | |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 731 | case DW_ATE_address: |
| 732 | if (QualTypeMatchesBitSize (bit_size, ast, ast->VoidPtrTy)) |
| 733 | return ast->VoidPtrTy.getAsOpaquePtr(); |
| 734 | break; |
| 735 | |
| 736 | case DW_ATE_boolean: |
| 737 | if (QualTypeMatchesBitSize (bit_size, ast, ast->BoolTy)) |
| 738 | return ast->BoolTy.getAsOpaquePtr(); |
| 739 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
| 740 | return ast->UnsignedCharTy.getAsOpaquePtr(); |
| 741 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
| 742 | return ast->UnsignedShortTy.getAsOpaquePtr(); |
| 743 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) |
| 744 | return ast->UnsignedIntTy.getAsOpaquePtr(); |
| 745 | break; |
| 746 | |
| 747 | case DW_ATE_lo_user: |
| 748 | // This has been seen to mean DW_AT_complex_integer |
| 749 | if (type_name) |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 750 | { |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 751 | if (::strstr(type_name, "complex")) |
| 752 | { |
| 753 | clang_type_t complex_int_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ("int", DW_ATE_signed, bit_size/2); |
| 754 | return ast->getComplexType (QualType::getFromOpaquePtr(complex_int_clang_type)).getAsOpaquePtr(); |
| 755 | } |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 756 | } |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 757 | break; |
| 758 | |
| 759 | case DW_ATE_complex_float: |
| 760 | if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatComplexTy)) |
| 761 | return ast->FloatComplexTy.getAsOpaquePtr(); |
| 762 | else if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleComplexTy)) |
| 763 | return ast->DoubleComplexTy.getAsOpaquePtr(); |
| 764 | else if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleComplexTy)) |
| 765 | return ast->LongDoubleComplexTy.getAsOpaquePtr(); |
| 766 | else |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 767 | { |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 768 | clang_type_t complex_float_clang_type = GetBuiltinTypeForDWARFEncodingAndBitSize ("float", DW_ATE_float, bit_size/2); |
| 769 | return ast->getComplexType (QualType::getFromOpaquePtr(complex_float_clang_type)).getAsOpaquePtr(); |
Greg Clayton | 605684e | 2011-10-28 23:06:08 +0000 | [diff] [blame] | 770 | } |
Sean Callanan | 38d4df5 | 2012-04-03 01:10:10 +0000 | [diff] [blame] | 771 | break; |
| 772 | |
| 773 | case DW_ATE_float: |
| 774 | if (QualTypeMatchesBitSize (bit_size, ast, ast->FloatTy)) |
| 775 | return ast->FloatTy.getAsOpaquePtr(); |
| 776 | if (QualTypeMatchesBitSize (bit_size, ast, ast->DoubleTy)) |
| 777 | return ast->DoubleTy.getAsOpaquePtr(); |
| 778 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongDoubleTy)) |
| 779 | return ast->LongDoubleTy.getAsOpaquePtr(); |
| 780 | break; |
| 781 | |
| 782 | case DW_ATE_signed: |
| 783 | if (type_name) |
| 784 | { |
| 785 | if (streq(type_name, "wchar_t") && |
| 786 | QualTypeMatchesBitSize (bit_size, ast, ast->WCharTy)) |
| 787 | return ast->WCharTy.getAsOpaquePtr(); |
| 788 | if (streq(type_name, "void") && |
| 789 | QualTypeMatchesBitSize (bit_size, ast, ast->VoidTy)) |
| 790 | return ast->VoidTy.getAsOpaquePtr(); |
| 791 | if (strstr(type_name, "long long") && |
| 792 | QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy)) |
| 793 | return ast->LongLongTy.getAsOpaquePtr(); |
| 794 | if (strstr(type_name, "long") && |
| 795 | QualTypeMatchesBitSize (bit_size, ast, ast->LongTy)) |
| 796 | return ast->LongTy.getAsOpaquePtr(); |
| 797 | if (strstr(type_name, "short") && |
| 798 | QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy)) |
| 799 | return ast->ShortTy.getAsOpaquePtr(); |
| 800 | if (strstr(type_name, "char")) |
| 801 | { |
| 802 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
| 803 | return ast->CharTy.getAsOpaquePtr(); |
| 804 | if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy)) |
| 805 | return ast->SignedCharTy.getAsOpaquePtr(); |
| 806 | } |
| 807 | if (strstr(type_name, "int")) |
| 808 | { |
| 809 | if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy)) |
| 810 | return ast->IntTy.getAsOpaquePtr(); |
| 811 | if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty)) |
| 812 | return ast->Int128Ty.getAsOpaquePtr(); |
| 813 | } |
| 814 | } |
| 815 | // We weren't able to match up a type name, just search by size |
| 816 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
| 817 | return ast->CharTy.getAsOpaquePtr(); |
| 818 | if (QualTypeMatchesBitSize (bit_size, ast, ast->ShortTy)) |
| 819 | return ast->ShortTy.getAsOpaquePtr(); |
| 820 | if (QualTypeMatchesBitSize (bit_size, ast, ast->IntTy)) |
| 821 | return ast->IntTy.getAsOpaquePtr(); |
| 822 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongTy)) |
| 823 | return ast->LongTy.getAsOpaquePtr(); |
| 824 | if (QualTypeMatchesBitSize (bit_size, ast, ast->LongLongTy)) |
| 825 | return ast->LongLongTy.getAsOpaquePtr(); |
| 826 | if (QualTypeMatchesBitSize (bit_size, ast, ast->Int128Ty)) |
| 827 | return ast->Int128Ty.getAsOpaquePtr(); |
| 828 | break; |
| 829 | |
| 830 | case DW_ATE_signed_char: |
| 831 | if (type_name) |
| 832 | { |
| 833 | if (streq(type_name, "signed char")) |
| 834 | { |
| 835 | if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy)) |
| 836 | return ast->SignedCharTy.getAsOpaquePtr(); |
| 837 | } |
| 838 | } |
| 839 | if (QualTypeMatchesBitSize (bit_size, ast, ast->CharTy)) |
| 840 | return ast->CharTy.getAsOpaquePtr(); |
| 841 | if (QualTypeMatchesBitSize (bit_size, ast, ast->SignedCharTy)) |
| 842 | return ast->SignedCharTy.getAsOpaquePtr(); |
| 843 | break; |
| 844 | |
| 845 | case DW_ATE_unsigned: |
| 846 | if (type_name) |
| 847 | { |
| 848 | if (strstr(type_name, "long long")) |
| 849 | { |
| 850 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy)) |
| 851 | return ast->UnsignedLongLongTy.getAsOpaquePtr(); |
| 852 | } |
| 853 | else if (strstr(type_name, "long")) |
| 854 | { |
| 855 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy)) |
| 856 | return ast->UnsignedLongTy.getAsOpaquePtr(); |
| 857 | } |
| 858 | else if (strstr(type_name, "short")) |
| 859 | { |
| 860 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
| 861 | return ast->UnsignedShortTy.getAsOpaquePtr(); |
| 862 | } |
| 863 | else if (strstr(type_name, "char")) |
| 864 | { |
| 865 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
| 866 | return ast->UnsignedCharTy.getAsOpaquePtr(); |
| 867 | } |
| 868 | else if (strstr(type_name, "int")) |
| 869 | { |
| 870 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) |
| 871 | return ast->UnsignedIntTy.getAsOpaquePtr(); |
| 872 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty)) |
| 873 | return ast->UnsignedInt128Ty.getAsOpaquePtr(); |
| 874 | } |
| 875 | } |
| 876 | // We weren't able to match up a type name, just search by size |
| 877 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
| 878 | return ast->UnsignedCharTy.getAsOpaquePtr(); |
| 879 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
| 880 | return ast->UnsignedShortTy.getAsOpaquePtr(); |
| 881 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedIntTy)) |
| 882 | return ast->UnsignedIntTy.getAsOpaquePtr(); |
| 883 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongTy)) |
| 884 | return ast->UnsignedLongTy.getAsOpaquePtr(); |
| 885 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedLongLongTy)) |
| 886 | return ast->UnsignedLongLongTy.getAsOpaquePtr(); |
| 887 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedInt128Ty)) |
| 888 | return ast->UnsignedInt128Ty.getAsOpaquePtr(); |
| 889 | break; |
| 890 | |
| 891 | case DW_ATE_unsigned_char: |
| 892 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedCharTy)) |
| 893 | return ast->UnsignedCharTy.getAsOpaquePtr(); |
| 894 | if (QualTypeMatchesBitSize (bit_size, ast, ast->UnsignedShortTy)) |
| 895 | return ast->UnsignedShortTy.getAsOpaquePtr(); |
| 896 | break; |
| 897 | |
| 898 | case DW_ATE_imaginary_float: |
| 899 | break; |
| 900 | |
| 901 | case DW_ATE_UTF: |
| 902 | if (type_name) |
| 903 | { |
| 904 | if (streq(type_name, "char16_t")) |
| 905 | { |
| 906 | return ast->Char16Ty.getAsOpaquePtr(); |
| 907 | } |
| 908 | else if (streq(type_name, "char32_t")) |
| 909 | { |
| 910 | return ast->Char32Ty.getAsOpaquePtr(); |
| 911 | } |
| 912 | } |
| 913 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | // This assert should fire for anything that we don't catch above so we know |
| 917 | // to fix any issues we run into. |
Greg Clayton | dc968d1 | 2011-05-17 18:15:05 +0000 | [diff] [blame] | 918 | if (type_name) |
| 919 | { |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 920 | Host::SystemLog (Host::eSystemLogError, "error: need to add support for DW_TAG_base_type '%s' encoded with DW_ATE = 0x%x, bit_size = %u\n", type_name, dw_ate, bit_size); |
Greg Clayton | dc968d1 | 2011-05-17 18:15:05 +0000 | [diff] [blame] | 921 | } |
| 922 | else |
| 923 | { |
Greg Clayton | e38a5ed | 2012-01-05 03:57:59 +0000 | [diff] [blame] | 924 | Host::SystemLog (Host::eSystemLogError, "error: need to add support for DW_TAG_base_type encoded with DW_ATE = 0x%x, bit_size = %u\n", dw_ate, bit_size); |
Greg Clayton | dc968d1 | 2011-05-17 18:15:05 +0000 | [diff] [blame] | 925 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 926 | return NULL; |
| 927 | } |
| 928 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 929 | clang_type_t |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 930 | ClangASTContext::GetBuiltInType_void(ASTContext *ast) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 931 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 932 | return ast->VoidTy.getAsOpaquePtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 933 | } |
| 934 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 935 | clang_type_t |
Sean Callanan | f7c3e27 | 2010-11-19 02:52:21 +0000 | [diff] [blame] | 936 | ClangASTContext::GetBuiltInType_bool() |
| 937 | { |
| 938 | return getASTContext()->BoolTy.getAsOpaquePtr(); |
| 939 | } |
| 940 | |
| 941 | clang_type_t |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 942 | ClangASTContext::GetBuiltInType_objc_id() |
| 943 | { |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 944 | return getASTContext()->getObjCIdType().getAsOpaquePtr(); |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 945 | } |
| 946 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 947 | clang_type_t |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 948 | ClangASTContext::GetBuiltInType_objc_Class() |
| 949 | { |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 950 | return getASTContext()->getObjCClassType().getAsOpaquePtr(); |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 951 | } |
| 952 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 953 | clang_type_t |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 954 | ClangASTContext::GetBuiltInType_objc_selector() |
| 955 | { |
Sean Callanan | d5c17ed | 2011-11-15 02:11:17 +0000 | [diff] [blame] | 956 | return getASTContext()->getObjCSelType().getAsOpaquePtr(); |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 957 | } |
| 958 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 959 | clang_type_t |
Sean Callanan | 7750226 | 2011-05-12 23:54:16 +0000 | [diff] [blame] | 960 | ClangASTContext::GetUnknownAnyType(clang::ASTContext *ast) |
| 961 | { |
| 962 | return ast->UnknownAnyTy.getAsOpaquePtr(); |
| 963 | } |
| 964 | |
| 965 | clang_type_t |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 966 | ClangASTContext::GetCStringType (bool is_const) |
| 967 | { |
| 968 | QualType char_type(getASTContext()->CharTy); |
| 969 | |
| 970 | if (is_const) |
| 971 | char_type.addConst(); |
| 972 | |
| 973 | return getASTContext()->getPointerType(char_type).getAsOpaquePtr(); |
| 974 | } |
| 975 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 976 | clang_type_t |
Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 977 | ClangASTContext::GetVoidType() |
| 978 | { |
| 979 | return GetVoidType(getASTContext()); |
| 980 | } |
| 981 | |
| 982 | clang_type_t |
| 983 | ClangASTContext::GetVoidType(ASTContext *ast) |
| 984 | { |
| 985 | return ast->VoidTy.getAsOpaquePtr(); |
| 986 | } |
| 987 | |
| 988 | clang_type_t |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 989 | ClangASTContext::GetVoidPtrType (bool is_const) |
| 990 | { |
| 991 | return GetVoidPtrType(getASTContext(), is_const); |
| 992 | } |
| 993 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 994 | clang_type_t |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 995 | ClangASTContext::GetVoidPtrType (ASTContext *ast, bool is_const) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 996 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 997 | QualType void_ptr_type(ast->VoidPtrTy); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 998 | |
| 999 | if (is_const) |
| 1000 | void_ptr_type.addConst(); |
| 1001 | |
| 1002 | return void_ptr_type.getAsOpaquePtr(); |
| 1003 | } |
| 1004 | |
Sean Callanan | 09ab4b7 | 2011-11-30 22:11:59 +0000 | [diff] [blame] | 1005 | clang::DeclContext * |
| 1006 | ClangASTContext::GetTranslationUnitDecl (clang::ASTContext *ast) |
| 1007 | { |
| 1008 | return ast->getTranslationUnitDecl(); |
| 1009 | } |
| 1010 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1011 | clang_type_t |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 1012 | ClangASTContext::CopyType (ASTContext *dst_ast, |
| 1013 | ASTContext *src_ast, |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1014 | clang_type_t clang_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1015 | { |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 1016 | FileSystemOptions file_system_options; |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 1017 | FileManager file_manager (file_system_options); |
| 1018 | ASTImporter importer(*dst_ast, file_manager, |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 1019 | *src_ast, file_manager, |
| 1020 | false); |
Sean Callanan | 0617fcb | 2010-11-09 22:37:10 +0000 | [diff] [blame] | 1021 | |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 1022 | QualType src (QualType::getFromOpaquePtr(clang_type)); |
| 1023 | QualType dst (importer.Import(src)); |
Sean Callanan | 0617fcb | 2010-11-09 22:37:10 +0000 | [diff] [blame] | 1024 | |
| 1025 | return dst.getAsOpaquePtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1028 | |
| 1029 | clang::Decl * |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 1030 | ClangASTContext::CopyDecl (ASTContext *dst_ast, |
| 1031 | ASTContext *src_ast, |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1032 | clang::Decl *source_decl) |
Sean Callanan | 7fddd4c | 2010-12-11 00:08:56 +0000 | [diff] [blame] | 1033 | { |
Sean Callanan | 79439e8 | 2010-11-18 02:56:27 +0000 | [diff] [blame] | 1034 | FileSystemOptions file_system_options; |
Greg Clayton | 38a6140 | 2010-12-02 23:20:03 +0000 | [diff] [blame] | 1035 | FileManager file_manager (file_system_options); |
| 1036 | ASTImporter importer(*dst_ast, file_manager, |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 1037 | *src_ast, file_manager, |
| 1038 | false); |
Greg Clayton | 526e5af | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 1039 | |
| 1040 | return importer.Import(source_decl); |
| 1041 | } |
| 1042 | |
Sean Callanan | 23a3027 | 2010-07-16 00:00:27 +0000 | [diff] [blame] | 1043 | bool |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 1044 | ClangASTContext::AreTypesSame (ASTContext *ast, |
| 1045 | clang_type_t type1, |
| 1046 | clang_type_t type2, |
| 1047 | bool ignore_qualifiers) |
Sean Callanan | 4dcca262 | 2010-07-15 22:30:52 +0000 | [diff] [blame] | 1048 | { |
Greg Clayton | 55995eb | 2012-04-06 17:38:55 +0000 | [diff] [blame] | 1049 | if (type1 == type2) |
| 1050 | return true; |
| 1051 | |
Sean Callanan | 5056ab0 | 2012-02-18 02:01:03 +0000 | [diff] [blame] | 1052 | QualType type1_qual = QualType::getFromOpaquePtr(type1); |
| 1053 | QualType type2_qual = QualType::getFromOpaquePtr(type2); |
| 1054 | |
| 1055 | if (ignore_qualifiers) |
| 1056 | { |
| 1057 | type1_qual = type1_qual.getUnqualifiedType(); |
| 1058 | type2_qual = type2_qual.getUnqualifiedType(); |
| 1059 | } |
| 1060 | |
| 1061 | return ast->hasSameType (type1_qual, |
| 1062 | type2_qual); |
Sean Callanan | 4dcca262 | 2010-07-15 22:30:52 +0000 | [diff] [blame] | 1063 | } |
| 1064 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1065 | #pragma mark CVR modifiers |
| 1066 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1067 | clang_type_t |
| 1068 | ClangASTContext::AddConstModifier (clang_type_t clang_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1069 | { |
| 1070 | if (clang_type) |
| 1071 | { |
| 1072 | QualType result(QualType::getFromOpaquePtr(clang_type)); |
| 1073 | result.addConst(); |
| 1074 | return result.getAsOpaquePtr(); |
| 1075 | } |
| 1076 | return NULL; |
| 1077 | } |
| 1078 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1079 | clang_type_t |
| 1080 | ClangASTContext::AddRestrictModifier (clang_type_t clang_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1081 | { |
| 1082 | if (clang_type) |
| 1083 | { |
| 1084 | QualType result(QualType::getFromOpaquePtr(clang_type)); |
| 1085 | result.getQualifiers().setRestrict (true); |
| 1086 | return result.getAsOpaquePtr(); |
| 1087 | } |
| 1088 | return NULL; |
| 1089 | } |
| 1090 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1091 | clang_type_t |
| 1092 | ClangASTContext::AddVolatileModifier (clang_type_t clang_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1093 | { |
| 1094 | if (clang_type) |
| 1095 | { |
| 1096 | QualType result(QualType::getFromOpaquePtr(clang_type)); |
| 1097 | result.getQualifiers().setVolatile (true); |
| 1098 | return result.getAsOpaquePtr(); |
| 1099 | } |
| 1100 | return NULL; |
| 1101 | } |
| 1102 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1103 | |
| 1104 | clang_type_t |
| 1105 | ClangASTContext::GetTypeForDecl (TagDecl *decl) |
| 1106 | { |
| 1107 | // No need to call the getASTContext() accessor (which can create the AST |
| 1108 | // if it isn't created yet, because we can't have created a decl in this |
| 1109 | // AST if our AST didn't already exist... |
| 1110 | if (m_ast_ap.get()) |
| 1111 | return m_ast_ap->getTagDeclType(decl).getAsOpaquePtr(); |
| 1112 | return NULL; |
| 1113 | } |
| 1114 | |
| 1115 | clang_type_t |
| 1116 | ClangASTContext::GetTypeForDecl (ObjCInterfaceDecl *decl) |
| 1117 | { |
| 1118 | // No need to call the getASTContext() accessor (which can create the AST |
| 1119 | // if it isn't created yet, because we can't have created a decl in this |
| 1120 | // AST if our AST didn't already exist... |
| 1121 | if (m_ast_ap.get()) |
| 1122 | return m_ast_ap->getObjCInterfaceType(decl).getAsOpaquePtr(); |
| 1123 | return NULL; |
| 1124 | } |
| 1125 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1126 | #pragma mark Structure, Unions, Classes |
| 1127 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1128 | clang_type_t |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1129 | ClangASTContext::CreateRecordType (DeclContext *decl_ctx, AccessType access_type, const char *name, int kind, LanguageType language, ClangASTMetadata *metadata) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1130 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1131 | ASTContext *ast = getASTContext(); |
| 1132 | assert (ast != NULL); |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1133 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1134 | if (decl_ctx == NULL) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1135 | decl_ctx = ast->getTranslationUnitDecl(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1136 | |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1137 | |
Greg Clayton | e1be996 | 2011-08-24 23:50:00 +0000 | [diff] [blame] | 1138 | if (language == eLanguageTypeObjC || language == eLanguageTypeObjC_plus_plus) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1139 | { |
Greg Clayton | aaf99e0 | 2010-10-11 02:25:34 +0000 | [diff] [blame] | 1140 | bool isForwardDecl = true; |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1141 | bool isInternal = false; |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 1142 | return CreateObjCClass (name, decl_ctx, isForwardDecl, isInternal, metadata); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1145 | // NOTE: Eventually CXXRecordDecl will be merged back into RecordDecl and |
| 1146 | // we will need to update this code. I was told to currently always use |
| 1147 | // the CXXRecordDecl class since we often don't know from debug information |
| 1148 | // if something is struct or a class, so we default to always use the more |
| 1149 | // complete definition just in case. |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1150 | CXXRecordDecl *decl = CXXRecordDecl::Create (*ast, |
| 1151 | (TagDecl::TagKind)kind, |
| 1152 | decl_ctx, |
| 1153 | SourceLocation(), |
| 1154 | SourceLocation(), |
| 1155 | name && name[0] ? &ast->Idents.get(name) : NULL); |
Sean Callanan | 7282e2a | 2012-01-13 22:10:18 +0000 | [diff] [blame] | 1156 | |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 1157 | if (decl && metadata) |
| 1158 | SetMetadata(ast, (uintptr_t)decl, *metadata); |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 1159 | |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1160 | if (decl_ctx) |
| 1161 | { |
| 1162 | if (access_type != eAccessNone) |
| 1163 | decl->setAccess (ConvertAccessTypeToAccessSpecifier (access_type)); |
| 1164 | decl_ctx->addDecl (decl); |
| 1165 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1166 | return ast->getTagDeclType(decl).getAsOpaquePtr(); |
| 1167 | } |
| 1168 | |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1169 | static TemplateParameterList * |
| 1170 | CreateTemplateParameterList (ASTContext *ast, |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1171 | const ClangASTContext::TemplateParameterInfos &template_param_infos, |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1172 | llvm::SmallVector<NamedDecl *, 8> &template_param_decls) |
| 1173 | { |
| 1174 | const bool parameter_pack = false; |
| 1175 | const bool is_typename = false; |
| 1176 | const unsigned depth = 0; |
| 1177 | const size_t num_template_params = template_param_infos.GetSize(); |
| 1178 | for (size_t i=0; i<num_template_params; ++i) |
| 1179 | { |
| 1180 | const char *name = template_param_infos.names[i]; |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1181 | if (template_param_infos.args[i].getKind() == TemplateArgument::Integral) |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1182 | { |
| 1183 | template_param_decls.push_back (NonTypeTemplateParmDecl::Create (*ast, |
| 1184 | ast->getTranslationUnitDecl(), // Is this the right decl context?, SourceLocation StartLoc, |
| 1185 | SourceLocation(), |
| 1186 | SourceLocation(), |
| 1187 | depth, |
| 1188 | i, |
| 1189 | &ast->Idents.get(name), |
| 1190 | template_param_infos.args[i].getIntegralType(), |
| 1191 | parameter_pack, |
| 1192 | NULL)); |
| 1193 | |
| 1194 | } |
| 1195 | else |
| 1196 | { |
| 1197 | template_param_decls.push_back (TemplateTypeParmDecl::Create (*ast, |
| 1198 | ast->getTranslationUnitDecl(), // Is this the right decl context? |
| 1199 | SourceLocation(), |
| 1200 | SourceLocation(), |
| 1201 | depth, |
| 1202 | i, |
| 1203 | &ast->Idents.get(name), |
| 1204 | is_typename, |
| 1205 | parameter_pack)); |
| 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | TemplateParameterList *template_param_list = TemplateParameterList::Create (*ast, |
| 1210 | SourceLocation(), |
| 1211 | SourceLocation(), |
| 1212 | &template_param_decls.front(), |
| 1213 | template_param_decls.size(), |
| 1214 | SourceLocation()); |
| 1215 | return template_param_list; |
| 1216 | } |
| 1217 | |
| 1218 | clang::FunctionTemplateDecl * |
| 1219 | ClangASTContext::CreateFunctionTemplateDecl (clang::DeclContext *decl_ctx, |
| 1220 | clang::FunctionDecl *func_decl, |
| 1221 | const char *name, |
| 1222 | const TemplateParameterInfos &template_param_infos) |
| 1223 | { |
| 1224 | // /// \brief Create a function template node. |
| 1225 | ASTContext *ast = getASTContext(); |
| 1226 | |
| 1227 | llvm::SmallVector<NamedDecl *, 8> template_param_decls; |
| 1228 | |
| 1229 | TemplateParameterList *template_param_list = CreateTemplateParameterList (ast, |
| 1230 | template_param_infos, |
| 1231 | template_param_decls); |
| 1232 | FunctionTemplateDecl *func_tmpl_decl = FunctionTemplateDecl::Create (*ast, |
| 1233 | decl_ctx, |
| 1234 | func_decl->getLocation(), |
| 1235 | func_decl->getDeclName(), |
| 1236 | template_param_list, |
| 1237 | func_decl); |
| 1238 | |
| 1239 | for (size_t i=0, template_param_decl_count = template_param_decls.size(); |
| 1240 | i < template_param_decl_count; |
| 1241 | ++i) |
| 1242 | { |
| 1243 | // TODO: verify which decl context we should put template_param_decls into.. |
| 1244 | template_param_decls[i]->setDeclContext (func_decl); |
| 1245 | } |
| 1246 | |
| 1247 | return func_tmpl_decl; |
| 1248 | } |
| 1249 | |
| 1250 | void |
| 1251 | ClangASTContext::CreateFunctionTemplateSpecializationInfo (FunctionDecl *func_decl, |
| 1252 | clang::FunctionTemplateDecl *func_tmpl_decl, |
| 1253 | const TemplateParameterInfos &infos) |
| 1254 | { |
| 1255 | TemplateArgumentList template_args (TemplateArgumentList::OnStack, |
| 1256 | infos.args.data(), |
| 1257 | infos.args.size()); |
| 1258 | |
| 1259 | func_decl->setFunctionTemplateSpecialization (func_tmpl_decl, |
| 1260 | &template_args, |
| 1261 | NULL); |
| 1262 | } |
| 1263 | |
| 1264 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1265 | ClassTemplateDecl * |
| 1266 | ClangASTContext::CreateClassTemplateDecl (DeclContext *decl_ctx, |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1267 | lldb::AccessType access_type, |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1268 | const char *class_name, |
| 1269 | int kind, |
| 1270 | const TemplateParameterInfos &template_param_infos) |
| 1271 | { |
| 1272 | ASTContext *ast = getASTContext(); |
| 1273 | |
| 1274 | ClassTemplateDecl *class_template_decl = NULL; |
| 1275 | if (decl_ctx == NULL) |
| 1276 | decl_ctx = ast->getTranslationUnitDecl(); |
| 1277 | |
| 1278 | IdentifierInfo &identifier_info = ast->Idents.get(class_name); |
| 1279 | DeclarationName decl_name (&identifier_info); |
| 1280 | |
| 1281 | clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name); |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1282 | |
| 1283 | for (NamedDecl *decl : result) |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1284 | { |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 1285 | class_template_decl = dyn_cast<clang::ClassTemplateDecl>(decl); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1286 | if (class_template_decl) |
| 1287 | return class_template_decl; |
| 1288 | } |
| 1289 | |
| 1290 | llvm::SmallVector<NamedDecl *, 8> template_param_decls; |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1291 | |
Greg Clayton | 3c2e3ae | 2012-02-06 06:42:51 +0000 | [diff] [blame] | 1292 | TemplateParameterList *template_param_list = CreateTemplateParameterList (ast, |
| 1293 | template_param_infos, |
| 1294 | template_param_decls); |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1295 | |
| 1296 | CXXRecordDecl *template_cxx_decl = CXXRecordDecl::Create (*ast, |
| 1297 | (TagDecl::TagKind)kind, |
| 1298 | decl_ctx, // What decl context do we use here? TU? The actual decl context? |
| 1299 | SourceLocation(), |
| 1300 | SourceLocation(), |
| 1301 | &identifier_info); |
Greg Clayton | e04741d | 2011-12-02 02:09:28 +0000 | [diff] [blame] | 1302 | |
| 1303 | for (size_t i=0, template_param_decl_count = template_param_decls.size(); |
| 1304 | i < template_param_decl_count; |
| 1305 | ++i) |
| 1306 | { |
| 1307 | template_param_decls[i]->setDeclContext (template_cxx_decl); |
| 1308 | } |
| 1309 | |
Sean Callanan | b5c7962 | 2011-11-19 01:35:08 +0000 | [diff] [blame] | 1310 | // With templated classes, we say that a class is templated with |
| 1311 | // specializations, but that the bare class has no functions. |
Sean Callanan | fa4fab7 | 2013-02-01 06:55:48 +0000 | [diff] [blame^] | 1312 | //template_cxx_decl->startDefinition(); |
| 1313 | //template_cxx_decl->completeDefinition(); |
Sean Callanan | b5c7962 | 2011-11-19 01:35:08 +0000 | [diff] [blame] | 1314 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1315 | class_template_decl = ClassTemplateDecl::Create (*ast, |
| 1316 | decl_ctx, // What decl context do we use here? TU? The actual decl context? |
| 1317 | SourceLocation(), |
| 1318 | decl_name, |
| 1319 | template_param_list, |
| 1320 | template_cxx_decl, |
| 1321 | NULL); |
| 1322 | |
| 1323 | if (class_template_decl) |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1324 | { |
Greg Clayton | 55561e9 | 2011-10-26 03:31:36 +0000 | [diff] [blame] | 1325 | if (access_type != eAccessNone) |
| 1326 | class_template_decl->setAccess (ConvertAccessTypeToAccessSpecifier (access_type)); |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1327 | |
| 1328 | //if (TagDecl *ctx_tag_decl = dyn_cast<TagDecl>(decl_ctx)) |
| 1329 | // CompleteTagDeclarationDefinition(GetTypeForDecl(ctx_tag_decl)); |
| 1330 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1331 | decl_ctx->addDecl (class_template_decl); |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1332 | |
| 1333 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 1334 | VerifyDecl(class_template_decl); |
| 1335 | #endif |
| 1336 | } |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1337 | |
| 1338 | return class_template_decl; |
| 1339 | } |
| 1340 | |
| 1341 | |
| 1342 | ClassTemplateSpecializationDecl * |
| 1343 | ClangASTContext::CreateClassTemplateSpecializationDecl (DeclContext *decl_ctx, |
| 1344 | ClassTemplateDecl *class_template_decl, |
| 1345 | int kind, |
| 1346 | const TemplateParameterInfos &template_param_infos) |
| 1347 | { |
| 1348 | ASTContext *ast = getASTContext(); |
| 1349 | ClassTemplateSpecializationDecl *class_template_specialization_decl = ClassTemplateSpecializationDecl::Create (*ast, |
| 1350 | (TagDecl::TagKind)kind, |
| 1351 | decl_ctx, |
| 1352 | SourceLocation(), |
| 1353 | SourceLocation(), |
| 1354 | class_template_decl, |
| 1355 | &template_param_infos.args.front(), |
| 1356 | template_param_infos.args.size(), |
| 1357 | NULL); |
| 1358 | |
Sean Callanan | fa4fab7 | 2013-02-01 06:55:48 +0000 | [diff] [blame^] | 1359 | class_template_specialization_decl->setSpecializationKind(TSK_ExplicitSpecialization); |
| 1360 | |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 1361 | return class_template_specialization_decl; |
| 1362 | } |
| 1363 | |
| 1364 | lldb::clang_type_t |
| 1365 | ClangASTContext::CreateClassTemplateSpecializationType (ClassTemplateSpecializationDecl *class_template_specialization_decl) |
| 1366 | { |
| 1367 | if (class_template_specialization_decl) |
| 1368 | { |
| 1369 | ASTContext *ast = getASTContext(); |
| 1370 | if (ast) |
| 1371 | return ast->getTagDeclType(class_template_specialization_decl).getAsOpaquePtr(); |
| 1372 | } |
| 1373 | return NULL; |
| 1374 | } |
| 1375 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1376 | bool |
| 1377 | ClangASTContext::SetHasExternalStorage (clang_type_t clang_type, bool has_extern) |
| 1378 | { |
| 1379 | if (clang_type == NULL) |
| 1380 | return false; |
| 1381 | |
| 1382 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 1383 | |
| 1384 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 1385 | switch (type_class) |
| 1386 | { |
| 1387 | case clang::Type::Record: |
| 1388 | { |
| 1389 | CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 1390 | if (cxx_record_decl) |
| 1391 | { |
| 1392 | cxx_record_decl->setHasExternalLexicalStorage (has_extern); |
Greg Clayton | c432c19 | 2011-01-20 04:18:48 +0000 | [diff] [blame] | 1393 | cxx_record_decl->setHasExternalVisibleStorage (has_extern); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1394 | return true; |
| 1395 | } |
| 1396 | } |
| 1397 | break; |
| 1398 | |
| 1399 | case clang::Type::Enum: |
| 1400 | { |
| 1401 | EnumDecl *enum_decl = cast<EnumType>(qual_type)->getDecl(); |
| 1402 | if (enum_decl) |
| 1403 | { |
| 1404 | enum_decl->setHasExternalLexicalStorage (has_extern); |
Greg Clayton | c432c19 | 2011-01-20 04:18:48 +0000 | [diff] [blame] | 1405 | enum_decl->setHasExternalVisibleStorage (has_extern); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1406 | return true; |
| 1407 | } |
| 1408 | } |
| 1409 | break; |
| 1410 | |
| 1411 | case clang::Type::ObjCObject: |
| 1412 | case clang::Type::ObjCInterface: |
| 1413 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 1414 | const ObjCObjectType *objc_class_type = dyn_cast<ObjCObjectType>(qual_type.getTypePtr()); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1415 | assert (objc_class_type); |
| 1416 | if (objc_class_type) |
| 1417 | { |
| 1418 | ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 1419 | |
| 1420 | if (class_interface_decl) |
| 1421 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1422 | class_interface_decl->setHasExternalLexicalStorage (has_extern); |
Greg Clayton | c432c19 | 2011-01-20 04:18:48 +0000 | [diff] [blame] | 1423 | class_interface_decl->setHasExternalVisibleStorage (has_extern); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1424 | return true; |
| 1425 | } |
| 1426 | } |
| 1427 | } |
| 1428 | break; |
| 1429 | |
| 1430 | case clang::Type::Typedef: |
| 1431 | return ClangASTContext::SetHasExternalStorage (cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), has_extern); |
Sean Callanan | 912855f | 2011-08-11 23:56:13 +0000 | [diff] [blame] | 1432 | |
| 1433 | case clang::Type::Elaborated: |
| 1434 | return ClangASTContext::SetHasExternalStorage (cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), has_extern); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1435 | |
| 1436 | default: |
| 1437 | break; |
| 1438 | } |
| 1439 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1440 | } |
| 1441 | |
Greg Clayton | a3c444a | 2010-10-01 23:13:49 +0000 | [diff] [blame] | 1442 | static bool |
| 1443 | IsOperator (const char *name, OverloadedOperatorKind &op_kind) |
| 1444 | { |
| 1445 | if (name == NULL || name[0] == '\0') |
| 1446 | return false; |
| 1447 | |
Sean Callanan | a43f20d | 2010-12-10 19:51:54 +0000 | [diff] [blame] | 1448 | #define OPERATOR_PREFIX "operator" |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1449 | #define OPERATOR_PREFIX_LENGTH (sizeof (OPERATOR_PREFIX) - 1) |
Sean Callanan | bfeff8c | 2010-12-10 02:15:55 +0000 | [diff] [blame] | 1450 | |
| 1451 | const char *post_op_name = NULL; |
| 1452 | |
Sean Callanan | a43f20d | 2010-12-10 19:51:54 +0000 | [diff] [blame] | 1453 | bool no_space = true; |
Sean Callanan | bfeff8c | 2010-12-10 02:15:55 +0000 | [diff] [blame] | 1454 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1455 | if (::strncmp(name, OPERATOR_PREFIX, OPERATOR_PREFIX_LENGTH)) |
Greg Clayton | a3c444a | 2010-10-01 23:13:49 +0000 | [diff] [blame] | 1456 | return false; |
| 1457 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1458 | post_op_name = name + OPERATOR_PREFIX_LENGTH; |
| 1459 | |
Sean Callanan | a43f20d | 2010-12-10 19:51:54 +0000 | [diff] [blame] | 1460 | if (post_op_name[0] == ' ') |
| 1461 | { |
| 1462 | post_op_name++; |
| 1463 | no_space = false; |
| 1464 | } |
| 1465 | |
| 1466 | #undef OPERATOR_PREFIX |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1467 | #undef OPERATOR_PREFIX_LENGTH |
Sean Callanan | a43f20d | 2010-12-10 19:51:54 +0000 | [diff] [blame] | 1468 | |
Greg Clayton | a3c444a | 2010-10-01 23:13:49 +0000 | [diff] [blame] | 1469 | // This is an operator, set the overloaded operator kind to invalid |
| 1470 | // in case this is a conversion operator... |
| 1471 | op_kind = NUM_OVERLOADED_OPERATORS; |
| 1472 | |
| 1473 | switch (post_op_name[0]) |
| 1474 | { |
Sean Callanan | bfeff8c | 2010-12-10 02:15:55 +0000 | [diff] [blame] | 1475 | default: |
| 1476 | if (no_space) |
| 1477 | return false; |
| 1478 | break; |
Greg Clayton | a3c444a | 2010-10-01 23:13:49 +0000 | [diff] [blame] | 1479 | case 'n': |
Sean Callanan | bfeff8c | 2010-12-10 02:15:55 +0000 | [diff] [blame] | 1480 | if (no_space) |
| 1481 | return false; |
Greg Clayton | a3c444a | 2010-10-01 23:13:49 +0000 | [diff] [blame] | 1482 | if (strcmp (post_op_name, "new") == 0) |
| 1483 | op_kind = OO_New; |
| 1484 | else if (strcmp (post_op_name, "new[]") == 0) |
| 1485 | op_kind = OO_Array_New; |
| 1486 | break; |
| 1487 | |
| 1488 | case 'd': |
Sean Callanan | bfeff8c | 2010-12-10 02:15:55 +0000 | [diff] [blame] | 1489 | if (no_space) |
| 1490 | return false; |
Greg Clayton | a3c444a | 2010-10-01 23:13:49 +0000 | [diff] [blame] | 1491 | if (strcmp (post_op_name, "delete") == 0) |
| 1492 | op_kind = OO_Delete; |
| 1493 | else if (strcmp (post_op_name, "delete[]") == 0) |
| 1494 | op_kind = OO_Array_Delete; |
| 1495 | break; |
| 1496 | |
| 1497 | case '+': |
| 1498 | if (post_op_name[1] == '\0') |
| 1499 | op_kind = OO_Plus; |
| 1500 | else if (post_op_name[2] == '\0') |
| 1501 | { |
| 1502 | if (post_op_name[1] == '=') |
| 1503 | op_kind = OO_PlusEqual; |
| 1504 | else if (post_op_name[1] == '+') |
| 1505 | op_kind = OO_PlusPlus; |
| 1506 | } |
| 1507 | break; |
| 1508 | |
| 1509 | case '-': |
| 1510 | if (post_op_name[1] == '\0') |
| 1511 | op_kind = OO_Minus; |
| 1512 | else if (post_op_name[2] == '\0') |
| 1513 | { |
| 1514 | switch (post_op_name[1]) |
| 1515 | { |
| 1516 | case '=': op_kind = OO_MinusEqual; break; |
| 1517 | case '-': op_kind = OO_MinusMinus; break; |
| 1518 | case '>': op_kind = OO_Arrow; break; |
| 1519 | } |
| 1520 | } |
| 1521 | else if (post_op_name[3] == '\0') |
| 1522 | { |
| 1523 | if (post_op_name[2] == '*') |
| 1524 | op_kind = OO_ArrowStar; break; |
| 1525 | } |
| 1526 | break; |
| 1527 | |
| 1528 | case '*': |
| 1529 | if (post_op_name[1] == '\0') |
| 1530 | op_kind = OO_Star; |
| 1531 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 1532 | op_kind = OO_StarEqual; |
| 1533 | break; |
| 1534 | |
| 1535 | case '/': |
| 1536 | if (post_op_name[1] == '\0') |
| 1537 | op_kind = OO_Slash; |
| 1538 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 1539 | op_kind = OO_SlashEqual; |
| 1540 | break; |
| 1541 | |
| 1542 | case '%': |
| 1543 | if (post_op_name[1] == '\0') |
| 1544 | op_kind = OO_Percent; |
| 1545 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 1546 | op_kind = OO_PercentEqual; |
| 1547 | break; |
| 1548 | |
| 1549 | |
| 1550 | case '^': |
| 1551 | if (post_op_name[1] == '\0') |
| 1552 | op_kind = OO_Caret; |
| 1553 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 1554 | op_kind = OO_CaretEqual; |
| 1555 | break; |
| 1556 | |
| 1557 | case '&': |
| 1558 | if (post_op_name[1] == '\0') |
| 1559 | op_kind = OO_Amp; |
| 1560 | else if (post_op_name[2] == '\0') |
| 1561 | { |
| 1562 | switch (post_op_name[1]) |
| 1563 | { |
| 1564 | case '=': op_kind = OO_AmpEqual; break; |
| 1565 | case '&': op_kind = OO_AmpAmp; break; |
| 1566 | } |
| 1567 | } |
| 1568 | break; |
| 1569 | |
| 1570 | case '|': |
| 1571 | if (post_op_name[1] == '\0') |
| 1572 | op_kind = OO_Pipe; |
| 1573 | else if (post_op_name[2] == '\0') |
| 1574 | { |
| 1575 | switch (post_op_name[1]) |
| 1576 | { |
| 1577 | case '=': op_kind = OO_PipeEqual; break; |
| 1578 | case '|': op_kind = OO_PipePipe; break; |
| 1579 | } |
| 1580 | } |
| 1581 | break; |
| 1582 | |
| 1583 | case '~': |
| 1584 | if (post_op_name[1] == '\0') |
| 1585 | op_kind = OO_Tilde; |
| 1586 | break; |
| 1587 | |
| 1588 | case '!': |
| 1589 | if (post_op_name[1] == '\0') |
| 1590 | op_kind = OO_Exclaim; |
| 1591 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 1592 | op_kind = OO_ExclaimEqual; |
| 1593 | break; |
| 1594 | |
| 1595 | case '=': |
| 1596 | if (post_op_name[1] == '\0') |
| 1597 | op_kind = OO_Equal; |
| 1598 | else if (post_op_name[1] == '=' && post_op_name[2] == '\0') |
| 1599 | op_kind = OO_EqualEqual; |
| 1600 | break; |
| 1601 | |
| 1602 | case '<': |
| 1603 | if (post_op_name[1] == '\0') |
| 1604 | op_kind = OO_Less; |
| 1605 | else if (post_op_name[2] == '\0') |
| 1606 | { |
| 1607 | switch (post_op_name[1]) |
| 1608 | { |
| 1609 | case '<': op_kind = OO_LessLess; break; |
| 1610 | case '=': op_kind = OO_LessEqual; break; |
| 1611 | } |
| 1612 | } |
| 1613 | else if (post_op_name[3] == '\0') |
| 1614 | { |
| 1615 | if (post_op_name[2] == '=') |
| 1616 | op_kind = OO_LessLessEqual; |
| 1617 | } |
| 1618 | break; |
| 1619 | |
| 1620 | case '>': |
| 1621 | if (post_op_name[1] == '\0') |
| 1622 | op_kind = OO_Greater; |
| 1623 | else if (post_op_name[2] == '\0') |
| 1624 | { |
| 1625 | switch (post_op_name[1]) |
| 1626 | { |
| 1627 | case '>': op_kind = OO_GreaterGreater; break; |
| 1628 | case '=': op_kind = OO_GreaterEqual; break; |
| 1629 | } |
| 1630 | } |
| 1631 | else if (post_op_name[1] == '>' && |
| 1632 | post_op_name[2] == '=' && |
| 1633 | post_op_name[3] == '\0') |
| 1634 | { |
| 1635 | op_kind = OO_GreaterGreaterEqual; |
| 1636 | } |
| 1637 | break; |
| 1638 | |
| 1639 | case ',': |
| 1640 | if (post_op_name[1] == '\0') |
| 1641 | op_kind = OO_Comma; |
| 1642 | break; |
| 1643 | |
| 1644 | case '(': |
| 1645 | if (post_op_name[1] == ')' && post_op_name[2] == '\0') |
| 1646 | op_kind = OO_Call; |
| 1647 | break; |
| 1648 | |
| 1649 | case '[': |
| 1650 | if (post_op_name[1] == ']' && post_op_name[2] == '\0') |
| 1651 | op_kind = OO_Subscript; |
| 1652 | break; |
| 1653 | } |
| 1654 | |
| 1655 | return true; |
| 1656 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1657 | |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1658 | static inline bool |
Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1659 | check_op_param (uint32_t op_kind, bool unary, bool binary, uint32_t num_params) |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1660 | { |
Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1661 | // Special-case call since it can take any number of operands |
| 1662 | if(op_kind == OO_Call) |
| 1663 | return true; |
| 1664 | |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1665 | // The parameter count doens't include "this" |
| 1666 | if (num_params == 0) |
| 1667 | return unary; |
| 1668 | if (num_params == 1) |
| 1669 | return binary; |
Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1670 | else |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1671 | return false; |
| 1672 | } |
Daniel Dunbar | dacdfb5 | 2011-10-31 22:50:57 +0000 | [diff] [blame] | 1673 | |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1674 | bool |
| 1675 | ClangASTContext::CheckOverloadedOperatorKindParameterCount (uint32_t op_kind, uint32_t num_params) |
| 1676 | { |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 1677 | switch (op_kind) |
| 1678 | { |
| 1679 | default: |
| 1680 | break; |
| 1681 | // C++ standard allows any number of arguments to new/delete |
| 1682 | case OO_New: |
| 1683 | case OO_Array_New: |
| 1684 | case OO_Delete: |
| 1685 | case OO_Array_Delete: |
| 1686 | return true; |
| 1687 | } |
| 1688 | |
Sean Callanan | 6d9f5db | 2011-10-15 01:15:07 +0000 | [diff] [blame] | 1689 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) case OO_##Name: return check_op_param (op_kind, Unary, Binary, num_params); |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1690 | switch (op_kind) |
| 1691 | { |
| 1692 | #include "clang/Basic/OperatorKinds.def" |
| 1693 | default: break; |
| 1694 | } |
| 1695 | return false; |
| 1696 | } |
| 1697 | |
Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 1698 | CXXMethodDecl * |
Sean Callanan | 61da09b | 2010-09-17 02:58:26 +0000 | [diff] [blame] | 1699 | ClangASTContext::AddMethodToCXXRecordType |
| 1700 | ( |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1701 | ASTContext *ast, |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1702 | clang_type_t record_opaque_type, |
Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 1703 | const char *name, |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1704 | clang_type_t method_opaque_type, |
Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 1705 | lldb::AccessType access, |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1706 | bool is_virtual, |
| 1707 | bool is_static, |
Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 1708 | bool is_inline, |
Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 1709 | bool is_explicit, |
Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 1710 | bool is_attr_used, |
| 1711 | bool is_artificial |
Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 1712 | ) |
Sean Callanan | 61da09b | 2010-09-17 02:58:26 +0000 | [diff] [blame] | 1713 | { |
Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 1714 | if (!record_opaque_type || !method_opaque_type || !name) |
Johnny Chen | d440bcc | 2010-09-28 16:10:54 +0000 | [diff] [blame] | 1715 | return NULL; |
Sean Callanan | 61da09b | 2010-09-17 02:58:26 +0000 | [diff] [blame] | 1716 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1717 | assert(ast); |
Sean Callanan | 61da09b | 2010-09-17 02:58:26 +0000 | [diff] [blame] | 1718 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1719 | IdentifierTable *identifier_table = &ast->Idents; |
Sean Callanan | 61da09b | 2010-09-17 02:58:26 +0000 | [diff] [blame] | 1720 | |
| 1721 | assert(identifier_table); |
| 1722 | |
Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 1723 | QualType record_qual_type(QualType::getFromOpaquePtr(record_opaque_type)); |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1724 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1725 | CXXRecordDecl *cxx_record_decl = record_qual_type->getAsCXXRecordDecl(); |
Sean Callanan | 61da09b | 2010-09-17 02:58:26 +0000 | [diff] [blame] | 1726 | |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1727 | if (cxx_record_decl == NULL) |
Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 1728 | return NULL; |
Sean Callanan | 61da09b | 2010-09-17 02:58:26 +0000 | [diff] [blame] | 1729 | |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1730 | QualType method_qual_type (QualType::getFromOpaquePtr (method_opaque_type)); |
Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 1731 | |
Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 1732 | CXXMethodDecl *cxx_method_decl = NULL; |
Sean Callanan | 61da09b | 2010-09-17 02:58:26 +0000 | [diff] [blame] | 1733 | |
Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 1734 | DeclarationName decl_name (&identifier_table->get(name)); |
Greg Clayton | 878eaf1 | 2010-10-01 03:45:20 +0000 | [diff] [blame] | 1735 | |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 1736 | const clang::FunctionType *function_Type = dyn_cast<FunctionType>(method_qual_type.getTypePtr()); |
Greg Clayton | 878eaf1 | 2010-10-01 03:45:20 +0000 | [diff] [blame] | 1737 | |
Greg Clayton | 90a2acd | 2010-10-02 01:40:05 +0000 | [diff] [blame] | 1738 | if (function_Type == NULL) |
Greg Clayton | 878eaf1 | 2010-10-01 03:45:20 +0000 | [diff] [blame] | 1739 | return NULL; |
| 1740 | |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 1741 | const FunctionProtoType *method_function_prototype (dyn_cast<FunctionProtoType>(function_Type)); |
Greg Clayton | 878eaf1 | 2010-10-01 03:45:20 +0000 | [diff] [blame] | 1742 | |
| 1743 | if (!method_function_prototype) |
| 1744 | return NULL; |
| 1745 | |
| 1746 | unsigned int num_params = method_function_prototype->getNumArgs(); |
| 1747 | |
Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 1748 | CXXDestructorDecl *cxx_dtor_decl(NULL); |
| 1749 | CXXConstructorDecl *cxx_ctor_decl(NULL); |
| 1750 | |
Greg Clayton | 878eaf1 | 2010-10-01 03:45:20 +0000 | [diff] [blame] | 1751 | if (name[0] == '~') |
Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 1752 | { |
Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 1753 | cxx_dtor_decl = CXXDestructorDecl::Create (*ast, |
| 1754 | cxx_record_decl, |
| 1755 | SourceLocation(), |
| 1756 | DeclarationNameInfo (ast->DeclarationNames.getCXXDestructorName (ast->getCanonicalType (record_qual_type)), SourceLocation()), |
| 1757 | method_qual_type, |
| 1758 | NULL, |
| 1759 | is_inline, |
| 1760 | is_artificial); |
| 1761 | cxx_method_decl = cxx_dtor_decl; |
Greg Clayton | 878eaf1 | 2010-10-01 03:45:20 +0000 | [diff] [blame] | 1762 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1763 | else if (decl_name == cxx_record_decl->getDeclName()) |
Greg Clayton | 878eaf1 | 2010-10-01 03:45:20 +0000 | [diff] [blame] | 1764 | { |
Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 1765 | cxx_ctor_decl = CXXConstructorDecl::Create (*ast, |
| 1766 | cxx_record_decl, |
| 1767 | SourceLocation(), |
| 1768 | DeclarationNameInfo (ast->DeclarationNames.getCXXConstructorName (ast->getCanonicalType (record_qual_type)), SourceLocation()), |
| 1769 | method_qual_type, |
| 1770 | NULL, // TypeSourceInfo * |
| 1771 | is_explicit, |
| 1772 | is_inline, |
| 1773 | is_artificial, |
| 1774 | false /*is_constexpr*/); |
| 1775 | cxx_method_decl = cxx_ctor_decl; |
Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 1776 | } |
| 1777 | else |
Greg Clayton | 878eaf1 | 2010-10-01 03:45:20 +0000 | [diff] [blame] | 1778 | { |
Greg Clayton | a3c444a | 2010-10-01 23:13:49 +0000 | [diff] [blame] | 1779 | |
| 1780 | OverloadedOperatorKind op_kind = NUM_OVERLOADED_OPERATORS; |
| 1781 | if (IsOperator (name, op_kind)) |
Greg Clayton | 878eaf1 | 2010-10-01 03:45:20 +0000 | [diff] [blame] | 1782 | { |
Greg Clayton | a3c444a | 2010-10-01 23:13:49 +0000 | [diff] [blame] | 1783 | if (op_kind != NUM_OVERLOADED_OPERATORS) |
| 1784 | { |
Greg Clayton | 090d098 | 2011-06-19 03:43:27 +0000 | [diff] [blame] | 1785 | // Check the number of operator parameters. Sometimes we have |
| 1786 | // seen bad DWARF that doesn't correctly describe operators and |
| 1787 | // if we try to create a methed and add it to the class, clang |
| 1788 | // will assert and crash, so we need to make sure things are |
| 1789 | // acceptable. |
| 1790 | if (!ClangASTContext::CheckOverloadedOperatorKindParameterCount (op_kind, num_params)) |
| 1791 | return NULL; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1792 | cxx_method_decl = CXXMethodDecl::Create (*ast, |
Greg Clayton | 878eaf1 | 2010-10-01 03:45:20 +0000 | [diff] [blame] | 1793 | cxx_record_decl, |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1794 | SourceLocation(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1795 | DeclarationNameInfo (ast->DeclarationNames.getCXXOperatorName (op_kind), SourceLocation()), |
Greg Clayton | 878eaf1 | 2010-10-01 03:45:20 +0000 | [diff] [blame] | 1796 | method_qual_type, |
| 1797 | NULL, // TypeSourceInfo * |
Greg Clayton | a3c444a | 2010-10-01 23:13:49 +0000 | [diff] [blame] | 1798 | is_static, |
| 1799 | SC_None, |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1800 | is_inline, |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 1801 | false /*is_constexpr*/, |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1802 | SourceLocation()); |
Greg Clayton | a3c444a | 2010-10-01 23:13:49 +0000 | [diff] [blame] | 1803 | } |
| 1804 | else if (num_params == 0) |
| 1805 | { |
| 1806 | // Conversion operators don't take params... |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1807 | cxx_method_decl = CXXConversionDecl::Create (*ast, |
Greg Clayton | a3c444a | 2010-10-01 23:13:49 +0000 | [diff] [blame] | 1808 | cxx_record_decl, |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1809 | SourceLocation(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1810 | DeclarationNameInfo (ast->DeclarationNames.getCXXConversionFunctionName (ast->getCanonicalType (function_Type->getResultType())), SourceLocation()), |
Greg Clayton | a3c444a | 2010-10-01 23:13:49 +0000 | [diff] [blame] | 1811 | method_qual_type, |
| 1812 | NULL, // TypeSourceInfo * |
| 1813 | is_inline, |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1814 | is_explicit, |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 1815 | false /*is_constexpr*/, |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1816 | SourceLocation()); |
Greg Clayton | a3c444a | 2010-10-01 23:13:49 +0000 | [diff] [blame] | 1817 | } |
Greg Clayton | 878eaf1 | 2010-10-01 03:45:20 +0000 | [diff] [blame] | 1818 | } |
Greg Clayton | a3c444a | 2010-10-01 23:13:49 +0000 | [diff] [blame] | 1819 | |
| 1820 | if (cxx_method_decl == NULL) |
Greg Clayton | 878eaf1 | 2010-10-01 03:45:20 +0000 | [diff] [blame] | 1821 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1822 | cxx_method_decl = CXXMethodDecl::Create (*ast, |
Greg Clayton | 878eaf1 | 2010-10-01 03:45:20 +0000 | [diff] [blame] | 1823 | cxx_record_decl, |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1824 | SourceLocation(), |
Greg Clayton | a3c444a | 2010-10-01 23:13:49 +0000 | [diff] [blame] | 1825 | DeclarationNameInfo (decl_name, SourceLocation()), |
Greg Clayton | 878eaf1 | 2010-10-01 03:45:20 +0000 | [diff] [blame] | 1826 | method_qual_type, |
| 1827 | NULL, // TypeSourceInfo * |
| 1828 | is_static, |
| 1829 | SC_None, |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1830 | is_inline, |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 1831 | false /*is_constexpr*/, |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 1832 | SourceLocation()); |
Greg Clayton | 878eaf1 | 2010-10-01 03:45:20 +0000 | [diff] [blame] | 1833 | } |
Greg Clayton | f51de67 | 2010-10-01 02:31:07 +0000 | [diff] [blame] | 1834 | } |
Greg Clayton | a3c444a | 2010-10-01 23:13:49 +0000 | [diff] [blame] | 1835 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1836 | AccessSpecifier access_specifier = ConvertAccessTypeToAccessSpecifier (access); |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1837 | |
| 1838 | cxx_method_decl->setAccess (access_specifier); |
| 1839 | cxx_method_decl->setVirtualAsWritten (is_virtual); |
Sean Callanan | e2ef6e3 | 2010-09-23 03:01:22 +0000 | [diff] [blame] | 1840 | |
Sean Callanan | c1b732d | 2011-11-01 18:07:13 +0000 | [diff] [blame] | 1841 | if (is_attr_used) |
| 1842 | cxx_method_decl->addAttr(::new (*ast) UsedAttr(SourceRange(), *ast)); |
| 1843 | |
Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 1844 | // Populate the method decl with parameter decls |
Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 1845 | |
Charles Davis | 8c444c4 | 2011-05-19 23:33:46 +0000 | [diff] [blame] | 1846 | llvm::SmallVector<ParmVarDecl *, 12> params; |
Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 1847 | |
| 1848 | for (int param_index = 0; |
| 1849 | param_index < num_params; |
| 1850 | ++param_index) |
| 1851 | { |
Charles Davis | 8c444c4 | 2011-05-19 23:33:46 +0000 | [diff] [blame] | 1852 | params.push_back (ParmVarDecl::Create (*ast, |
| 1853 | cxx_method_decl, |
| 1854 | SourceLocation(), |
| 1855 | SourceLocation(), |
| 1856 | NULL, // anonymous |
| 1857 | method_function_prototype->getArgType(param_index), |
| 1858 | NULL, |
| 1859 | SC_None, |
| 1860 | SC_None, |
| 1861 | NULL)); |
Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 1862 | } |
| 1863 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 1864 | cxx_method_decl->setParams (ArrayRef<ParmVarDecl*>(params)); |
Sean Callanan | fc55f5d | 2010-09-21 00:44:12 +0000 | [diff] [blame] | 1865 | |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1866 | cxx_record_decl->addDecl (cxx_method_decl); |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1867 | |
Greg Clayton | 8b867b4 | 2011-11-02 02:06:20 +0000 | [diff] [blame] | 1868 | // Sometimes the debug info will mention a constructor (default/copy/move), |
| 1869 | // destructor, or assignment operator (copy/move) but there won't be any |
| 1870 | // version of this in the code. So we check if the function was artificially |
| 1871 | // generated and if it is trivial and this lets the compiler/backend know |
| 1872 | // that it can inline the IR for these when it needs to and we can avoid a |
| 1873 | // "missing function" error when running expressions. |
| 1874 | |
Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 1875 | if (is_artificial) |
| 1876 | { |
Greg Clayton | 8b867b4 | 2011-11-02 02:06:20 +0000 | [diff] [blame] | 1877 | if (cxx_ctor_decl && |
| 1878 | ((cxx_ctor_decl->isDefaultConstructor() && cxx_record_decl->hasTrivialDefaultConstructor ()) || |
| 1879 | (cxx_ctor_decl->isCopyConstructor() && cxx_record_decl->hasTrivialCopyConstructor ()) || |
| 1880 | (cxx_ctor_decl->isMoveConstructor() && cxx_record_decl->hasTrivialMoveConstructor ()) )) |
Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 1881 | { |
| 1882 | cxx_ctor_decl->setDefaulted(); |
| 1883 | cxx_ctor_decl->setTrivial(true); |
| 1884 | } |
Greg Clayton | 8b867b4 | 2011-11-02 02:06:20 +0000 | [diff] [blame] | 1885 | else if (cxx_dtor_decl) |
Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 1886 | { |
Greg Clayton | 8b867b4 | 2011-11-02 02:06:20 +0000 | [diff] [blame] | 1887 | if (cxx_record_decl->hasTrivialDestructor()) |
| 1888 | { |
| 1889 | cxx_dtor_decl->setDefaulted(); |
| 1890 | cxx_dtor_decl->setTrivial(true); |
| 1891 | } |
| 1892 | } |
| 1893 | else if ((cxx_method_decl->isCopyAssignmentOperator() && cxx_record_decl->hasTrivialCopyAssignment()) || |
| 1894 | (cxx_method_decl->isMoveAssignmentOperator() && cxx_record_decl->hasTrivialMoveAssignment())) |
| 1895 | { |
| 1896 | cxx_method_decl->setDefaulted(); |
| 1897 | cxx_method_decl->setTrivial(true); |
Sean Callanan | dbb5839 | 2011-11-02 01:38:59 +0000 | [diff] [blame] | 1898 | } |
| 1899 | } |
| 1900 | |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1901 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 1902 | VerifyDecl(cxx_method_decl); |
| 1903 | #endif |
Greg Clayton | c432c19 | 2011-01-20 04:18:48 +0000 | [diff] [blame] | 1904 | |
| 1905 | // printf ("decl->isPolymorphic() = %i\n", cxx_record_decl->isPolymorphic()); |
| 1906 | // printf ("decl->isAggregate() = %i\n", cxx_record_decl->isAggregate()); |
| 1907 | // printf ("decl->isPOD() = %i\n", cxx_record_decl->isPOD()); |
| 1908 | // printf ("decl->isEmpty() = %i\n", cxx_record_decl->isEmpty()); |
| 1909 | // printf ("decl->isAbstract() = %i\n", cxx_record_decl->isAbstract()); |
| 1910 | // printf ("decl->hasTrivialConstructor() = %i\n", cxx_record_decl->hasTrivialConstructor()); |
| 1911 | // printf ("decl->hasTrivialCopyConstructor() = %i\n", cxx_record_decl->hasTrivialCopyConstructor()); |
| 1912 | // printf ("decl->hasTrivialCopyAssignment() = %i\n", cxx_record_decl->hasTrivialCopyAssignment()); |
| 1913 | // printf ("decl->hasTrivialDestructor() = %i\n", cxx_record_decl->hasTrivialDestructor()); |
Greg Clayton | a51ed9b | 2010-09-23 01:09:21 +0000 | [diff] [blame] | 1914 | return cxx_method_decl; |
Sean Callanan | 61da09b | 2010-09-17 02:58:26 +0000 | [diff] [blame] | 1915 | } |
| 1916 | |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1917 | clang::FieldDecl * |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1918 | ClangASTContext::AddFieldToRecordType |
| 1919 | ( |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1920 | ASTContext *ast, |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1921 | clang_type_t record_clang_type, |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1922 | const char *name, |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 1923 | clang_type_t field_type, |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1924 | AccessType access, |
| 1925 | uint32_t bitfield_bit_size |
| 1926 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1927 | { |
| 1928 | if (record_clang_type == NULL || field_type == NULL) |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1929 | return NULL; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1930 | |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1931 | FieldDecl *field = NULL; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1932 | IdentifierTable *identifier_table = &ast->Idents; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1933 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1934 | assert (ast != NULL); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1935 | assert (identifier_table != NULL); |
| 1936 | |
| 1937 | QualType record_qual_type(QualType::getFromOpaquePtr(record_clang_type)); |
| 1938 | |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 1939 | const clang::Type *clang_type = record_qual_type.getTypePtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1940 | if (clang_type) |
| 1941 | { |
| 1942 | const RecordType *record_type = dyn_cast<RecordType>(clang_type); |
| 1943 | |
| 1944 | if (record_type) |
| 1945 | { |
| 1946 | RecordDecl *record_decl = record_type->getDecl(); |
| 1947 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1948 | clang::Expr *bit_width = NULL; |
| 1949 | if (bitfield_bit_size != 0) |
| 1950 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1951 | APInt bitfield_bit_size_apint(ast->getTypeSize(ast->IntTy), bitfield_bit_size); |
| 1952 | bit_width = new (*ast)IntegerLiteral (*ast, bitfield_bit_size_apint, ast->IntTy, SourceLocation()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1953 | } |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1954 | field = FieldDecl::Create (*ast, |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 1955 | record_decl, |
| 1956 | SourceLocation(), |
| 1957 | SourceLocation(), |
| 1958 | name ? &identifier_table->get(name) : NULL, // Identifier |
| 1959 | QualType::getFromOpaquePtr(field_type), // Field type |
| 1960 | NULL, // TInfo * |
| 1961 | bit_width, // BitWidth |
| 1962 | false, // Mutable |
| 1963 | ICIS_NoInit); // HasInit |
Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 1964 | |
Sean Callanan | 5ed3ac1 | 2012-07-13 20:01:02 +0000 | [diff] [blame] | 1965 | if (!name) { |
| 1966 | // Determine whether this field corresponds to an anonymous |
| 1967 | // struct or union. |
| 1968 | if (const TagType *TagT = field->getType()->getAs<TagType>()) { |
| 1969 | if (RecordDecl *Rec = dyn_cast<RecordDecl>(TagT->getDecl())) |
| 1970 | if (!Rec->getDeclName()) { |
| 1971 | Rec->setAnonymousStructOrUnion(true); |
| 1972 | field->setImplicit(); |
| 1973 | |
| 1974 | } |
| 1975 | } |
| 1976 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1977 | |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 1978 | field->setAccess (ConvertAccessTypeToAccessSpecifier (access)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1979 | |
| 1980 | if (field) |
| 1981 | { |
| 1982 | record_decl->addDecl(field); |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 1983 | |
| 1984 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 1985 | VerifyDecl(field); |
| 1986 | #endif |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1987 | } |
| 1988 | } |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1989 | else |
| 1990 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 1991 | const ObjCObjectType *objc_class_type = dyn_cast<ObjCObjectType>(clang_type); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1992 | if (objc_class_type) |
| 1993 | { |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 1994 | bool is_synthesized = false; |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 1995 | field = ClangASTContext::AddObjCClassIVar (ast, |
Sean Callanan | 6e6a7c7 | 2010-09-16 20:01:08 +0000 | [diff] [blame] | 1996 | record_clang_type, |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 1997 | name, |
| 1998 | field_type, |
| 1999 | access, |
| 2000 | bitfield_bit_size, |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2001 | is_synthesized); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2002 | } |
| 2003 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2004 | } |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2005 | return field; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2006 | } |
| 2007 | |
Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 2008 | static clang::AccessSpecifier UnifyAccessSpecifiers (clang::AccessSpecifier lhs, |
| 2009 | clang::AccessSpecifier rhs) |
| 2010 | { |
| 2011 | clang::AccessSpecifier ret = lhs; |
| 2012 | |
| 2013 | // Make the access equal to the stricter of the field and the nested field's access |
| 2014 | switch (ret) |
| 2015 | { |
| 2016 | case clang::AS_none: |
| 2017 | break; |
| 2018 | case clang::AS_private: |
| 2019 | break; |
| 2020 | case clang::AS_protected: |
| 2021 | if (rhs == AS_private) |
| 2022 | ret = AS_private; |
| 2023 | break; |
| 2024 | case clang::AS_public: |
| 2025 | ret = rhs; |
| 2026 | break; |
| 2027 | } |
| 2028 | |
| 2029 | return ret; |
| 2030 | } |
| 2031 | |
| 2032 | void |
| 2033 | ClangASTContext::BuildIndirectFields (clang::ASTContext *ast, |
| 2034 | lldb::clang_type_t record_clang_type) |
| 2035 | { |
| 2036 | QualType record_qual_type(QualType::getFromOpaquePtr(record_clang_type)); |
| 2037 | |
| 2038 | const RecordType *record_type = record_qual_type->getAs<RecordType>(); |
| 2039 | |
| 2040 | if (!record_type) |
| 2041 | return; |
| 2042 | |
| 2043 | RecordDecl *record_decl = record_type->getDecl(); |
| 2044 | |
| 2045 | if (!record_decl) |
| 2046 | return; |
| 2047 | |
| 2048 | typedef llvm::SmallVector <IndirectFieldDecl *, 1> IndirectFieldVector; |
| 2049 | |
| 2050 | IndirectFieldVector indirect_fields; |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2051 | RecordDecl::field_iterator field_pos; |
| 2052 | RecordDecl::field_iterator field_end_pos = record_decl->field_end(); |
| 2053 | RecordDecl::field_iterator last_field_pos = field_end_pos; |
| 2054 | for (field_pos = record_decl->field_begin(); field_pos != field_end_pos; last_field_pos = field_pos++) |
Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 2055 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2056 | if (field_pos->isAnonymousStructOrUnion()) |
Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 2057 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2058 | QualType field_qual_type = field_pos->getType(); |
Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 2059 | |
| 2060 | const RecordType *field_record_type = field_qual_type->getAs<RecordType>(); |
| 2061 | |
| 2062 | if (!field_record_type) |
| 2063 | continue; |
| 2064 | |
| 2065 | RecordDecl *field_record_decl = field_record_type->getDecl(); |
| 2066 | |
| 2067 | if (!field_record_decl) |
| 2068 | continue; |
| 2069 | |
| 2070 | for (RecordDecl::decl_iterator di = field_record_decl->decls_begin(), de = field_record_decl->decls_end(); |
| 2071 | di != de; |
| 2072 | ++di) |
| 2073 | { |
| 2074 | if (FieldDecl *nested_field_decl = dyn_cast<FieldDecl>(*di)) |
| 2075 | { |
| 2076 | NamedDecl **chain = new (*ast) NamedDecl*[2]; |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2077 | chain[0] = *field_pos; |
Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 2078 | chain[1] = nested_field_decl; |
| 2079 | IndirectFieldDecl *indirect_field = IndirectFieldDecl::Create(*ast, |
| 2080 | record_decl, |
| 2081 | SourceLocation(), |
| 2082 | nested_field_decl->getIdentifier(), |
| 2083 | nested_field_decl->getType(), |
| 2084 | chain, |
| 2085 | 2); |
| 2086 | |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2087 | indirect_field->setAccess(UnifyAccessSpecifiers(field_pos->getAccess(), |
Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 2088 | nested_field_decl->getAccess())); |
| 2089 | |
| 2090 | indirect_fields.push_back(indirect_field); |
| 2091 | } |
| 2092 | else if (IndirectFieldDecl *nested_indirect_field_decl = dyn_cast<IndirectFieldDecl>(*di)) |
| 2093 | { |
| 2094 | int nested_chain_size = nested_indirect_field_decl->getChainingSize(); |
| 2095 | NamedDecl **chain = new (*ast) NamedDecl*[nested_chain_size + 1]; |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2096 | chain[0] = *field_pos; |
Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 2097 | |
| 2098 | int chain_index = 1; |
| 2099 | for (IndirectFieldDecl::chain_iterator nci = nested_indirect_field_decl->chain_begin(), |
| 2100 | nce = nested_indirect_field_decl->chain_end(); |
| 2101 | nci < nce; |
| 2102 | ++nci) |
| 2103 | { |
| 2104 | chain[chain_index] = *nci; |
| 2105 | chain_index++; |
| 2106 | } |
| 2107 | |
| 2108 | IndirectFieldDecl *indirect_field = IndirectFieldDecl::Create(*ast, |
| 2109 | record_decl, |
| 2110 | SourceLocation(), |
| 2111 | nested_indirect_field_decl->getIdentifier(), |
| 2112 | nested_indirect_field_decl->getType(), |
| 2113 | chain, |
| 2114 | nested_chain_size + 1); |
| 2115 | |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2116 | indirect_field->setAccess(UnifyAccessSpecifiers(field_pos->getAccess(), |
Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 2117 | nested_indirect_field_decl->getAccess())); |
| 2118 | |
| 2119 | indirect_fields.push_back(indirect_field); |
| 2120 | } |
| 2121 | } |
| 2122 | } |
| 2123 | } |
| 2124 | |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 2125 | // Check the last field to see if it has an incomplete array type as its |
| 2126 | // last member and if it does, the tell the record decl about it |
| 2127 | if (last_field_pos != field_end_pos) |
| 2128 | { |
| 2129 | if (last_field_pos->getType()->isIncompleteArrayType()) |
| 2130 | record_decl->hasFlexibleArrayMember(); |
| 2131 | } |
| 2132 | |
Sean Callanan | e8c0cfb | 2012-03-02 01:03:45 +0000 | [diff] [blame] | 2133 | for (IndirectFieldVector::iterator ifi = indirect_fields.begin(), ife = indirect_fields.end(); |
| 2134 | ifi < ife; |
| 2135 | ++ifi) |
| 2136 | { |
| 2137 | record_decl->addDecl(*ifi); |
| 2138 | } |
| 2139 | } |
| 2140 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2141 | bool |
| 2142 | ClangASTContext::FieldIsBitfield (FieldDecl* field, uint32_t& bitfield_bit_size) |
| 2143 | { |
| 2144 | return FieldIsBitfield(getASTContext(), field, bitfield_bit_size); |
| 2145 | } |
| 2146 | |
| 2147 | bool |
| 2148 | ClangASTContext::FieldIsBitfield |
| 2149 | ( |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2150 | ASTContext *ast, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2151 | FieldDecl* field, |
| 2152 | uint32_t& bitfield_bit_size |
| 2153 | ) |
| 2154 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2155 | if (ast == NULL || field == NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2156 | return false; |
| 2157 | |
| 2158 | if (field->isBitField()) |
| 2159 | { |
| 2160 | Expr* bit_width_expr = field->getBitWidth(); |
| 2161 | if (bit_width_expr) |
| 2162 | { |
| 2163 | llvm::APSInt bit_width_apsint; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2164 | if (bit_width_expr->isIntegerConstantExpr(bit_width_apsint, *ast)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2165 | { |
| 2166 | bitfield_bit_size = bit_width_apsint.getLimitedValue(UINT32_MAX); |
| 2167 | return true; |
| 2168 | } |
| 2169 | } |
| 2170 | } |
| 2171 | return false; |
| 2172 | } |
| 2173 | |
| 2174 | bool |
| 2175 | ClangASTContext::RecordHasFields (const RecordDecl *record_decl) |
| 2176 | { |
| 2177 | if (record_decl == NULL) |
| 2178 | return false; |
| 2179 | |
| 2180 | if (!record_decl->field_empty()) |
| 2181 | return true; |
| 2182 | |
| 2183 | // No fields, lets check this is a CXX record and check the base classes |
| 2184 | const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl); |
| 2185 | if (cxx_record_decl) |
| 2186 | { |
| 2187 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 2188 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 2189 | base_class != base_class_end; |
| 2190 | ++base_class) |
| 2191 | { |
| 2192 | const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(base_class->getType()->getAs<RecordType>()->getDecl()); |
| 2193 | if (RecordHasFields(base_class_decl)) |
| 2194 | return true; |
| 2195 | } |
| 2196 | } |
| 2197 | return false; |
| 2198 | } |
| 2199 | |
| 2200 | void |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2201 | ClangASTContext::SetDefaultAccessForRecordFields (clang_type_t clang_type, int default_accessibility, int *assigned_accessibilities, size_t num_assigned_accessibilities) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2202 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2203 | if (clang_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2204 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2205 | QualType qual_type(QualType::getFromOpaquePtr(clang_type)); |
| 2206 | |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 2207 | const RecordType *record_type = dyn_cast<RecordType>(qual_type.getTypePtr()); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2208 | if (record_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2209 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2210 | RecordDecl *record_decl = record_type->getDecl(); |
| 2211 | if (record_decl) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2212 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2213 | uint32_t field_idx; |
| 2214 | RecordDecl::field_iterator field, field_end; |
| 2215 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(), field_idx = 0; |
| 2216 | field != field_end; |
| 2217 | ++field, ++field_idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2218 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2219 | // If no accessibility was assigned, assign the correct one |
| 2220 | if (field_idx < num_assigned_accessibilities && assigned_accessibilities[field_idx] == clang::AS_none) |
| 2221 | field->setAccess ((AccessSpecifier)default_accessibility); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2222 | } |
| 2223 | } |
| 2224 | } |
| 2225 | } |
| 2226 | } |
| 2227 | |
| 2228 | #pragma mark C++ Base Classes |
| 2229 | |
| 2230 | CXXBaseSpecifier * |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2231 | ClangASTContext::CreateBaseClassSpecifier (clang_type_t base_class_type, AccessType access, bool is_virtual, bool base_of_class) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2232 | { |
| 2233 | if (base_class_type) |
Greg Clayton | e637112 | 2010-07-30 20:30:44 +0000 | [diff] [blame] | 2234 | return new CXXBaseSpecifier (SourceRange(), |
| 2235 | is_virtual, |
| 2236 | base_of_class, |
| 2237 | ConvertAccessTypeToAccessSpecifier (access), |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 2238 | getASTContext()->CreateTypeSourceInfo (QualType::getFromOpaquePtr(base_class_type)), |
| 2239 | SourceLocation()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2240 | return NULL; |
| 2241 | } |
| 2242 | |
Greg Clayton | 0b42ac3 | 2010-07-02 01:29:13 +0000 | [diff] [blame] | 2243 | void |
| 2244 | ClangASTContext::DeleteBaseClassSpecifiers (CXXBaseSpecifier **base_classes, unsigned num_base_classes) |
| 2245 | { |
| 2246 | for (unsigned i=0; i<num_base_classes; ++i) |
| 2247 | { |
| 2248 | delete base_classes[i]; |
| 2249 | base_classes[i] = NULL; |
| 2250 | } |
| 2251 | } |
| 2252 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2253 | bool |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2254 | ClangASTContext::SetBaseClassesForClassType (clang_type_t class_clang_type, CXXBaseSpecifier const * const *base_classes, unsigned num_base_classes) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2255 | { |
| 2256 | if (class_clang_type) |
| 2257 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2258 | CXXRecordDecl *cxx_record_decl = QualType::getFromOpaquePtr(class_clang_type)->getAsCXXRecordDecl(); |
| 2259 | if (cxx_record_decl) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2260 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2261 | cxx_record_decl->setBases(base_classes, num_base_classes); |
| 2262 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2263 | } |
| 2264 | } |
| 2265 | return false; |
| 2266 | } |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2267 | #pragma mark Objective C Classes |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2268 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2269 | clang_type_t |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 2270 | ClangASTContext::CreateObjCClass |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2271 | ( |
| 2272 | const char *name, |
| 2273 | DeclContext *decl_ctx, |
| 2274 | bool isForwardDecl, |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 2275 | bool isInternal, |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2276 | ClangASTMetadata *metadata |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2277 | ) |
| 2278 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2279 | ASTContext *ast = getASTContext(); |
| 2280 | assert (ast != NULL); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2281 | assert (name && name[0]); |
| 2282 | if (decl_ctx == NULL) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2283 | decl_ctx = ast->getTranslationUnitDecl(); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2284 | |
| 2285 | // NOTE: Eventually CXXRecordDecl will be merged back into RecordDecl and |
| 2286 | // we will need to update this code. I was told to currently always use |
| 2287 | // the CXXRecordDecl class since we often don't know from debug information |
| 2288 | // if something is struct or a class, so we default to always use the more |
| 2289 | // complete definition just in case. |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2290 | ObjCInterfaceDecl *decl = ObjCInterfaceDecl::Create (*ast, |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2291 | decl_ctx, |
| 2292 | SourceLocation(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2293 | &ast->Idents.get(name), |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2294 | NULL, |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2295 | SourceLocation(), |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 2296 | /*isForwardDecl,*/ |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2297 | isInternal); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2298 | |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2299 | if (decl && metadata) |
| 2300 | SetMetadata(ast, (uintptr_t)decl, *metadata); |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 2301 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2302 | return ast->getObjCInterfaceType(decl).getAsOpaquePtr(); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | bool |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2306 | ClangASTContext::SetObjCSuperClass (clang_type_t class_opaque_type, clang_type_t super_opaque_type) |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2307 | { |
| 2308 | if (class_opaque_type && super_opaque_type) |
| 2309 | { |
| 2310 | QualType class_qual_type(QualType::getFromOpaquePtr(class_opaque_type)); |
| 2311 | QualType super_qual_type(QualType::getFromOpaquePtr(super_opaque_type)); |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 2312 | const clang::Type *class_type = class_qual_type.getTypePtr(); |
| 2313 | const clang::Type *super_type = super_qual_type.getTypePtr(); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2314 | if (class_type && super_type) |
| 2315 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 2316 | const ObjCObjectType *objc_class_type = dyn_cast<ObjCObjectType>(class_type); |
| 2317 | const ObjCObjectType *objc_super_type = dyn_cast<ObjCObjectType>(super_type); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2318 | if (objc_class_type && objc_super_type) |
| 2319 | { |
| 2320 | ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 2321 | ObjCInterfaceDecl *super_interface_decl = objc_super_type->getInterface(); |
| 2322 | if (class_interface_decl && super_interface_decl) |
| 2323 | { |
| 2324 | class_interface_decl->setSuperClass(super_interface_decl); |
| 2325 | return true; |
| 2326 | } |
| 2327 | } |
| 2328 | } |
| 2329 | } |
| 2330 | return false; |
| 2331 | } |
| 2332 | |
| 2333 | |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2334 | FieldDecl * |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2335 | ClangASTContext::AddObjCClassIVar |
| 2336 | ( |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2337 | ASTContext *ast, |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2338 | clang_type_t class_opaque_type, |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2339 | const char *name, |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2340 | clang_type_t ivar_opaque_type, |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2341 | AccessType access, |
| 2342 | uint32_t bitfield_bit_size, |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2343 | bool is_synthesized |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2344 | ) |
| 2345 | { |
| 2346 | if (class_opaque_type == NULL || ivar_opaque_type == NULL) |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2347 | return NULL; |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2348 | |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2349 | ObjCIvarDecl *field = NULL; |
| 2350 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2351 | IdentifierTable *identifier_table = &ast->Idents; |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2352 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2353 | assert (ast != NULL); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2354 | assert (identifier_table != NULL); |
| 2355 | |
| 2356 | QualType class_qual_type(QualType::getFromOpaquePtr(class_opaque_type)); |
| 2357 | |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 2358 | const clang::Type *class_type = class_qual_type.getTypePtr(); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2359 | if (class_type) |
| 2360 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 2361 | const ObjCObjectType *objc_class_type = dyn_cast<ObjCObjectType>(class_type); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2362 | |
| 2363 | if (objc_class_type) |
| 2364 | { |
| 2365 | ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 2366 | |
| 2367 | if (class_interface_decl) |
| 2368 | { |
| 2369 | clang::Expr *bit_width = NULL; |
| 2370 | if (bitfield_bit_size != 0) |
| 2371 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2372 | APInt bitfield_bit_size_apint(ast->getTypeSize(ast->IntTy), bitfield_bit_size); |
| 2373 | bit_width = new (*ast)IntegerLiteral (*ast, bitfield_bit_size_apint, ast->IntTy, SourceLocation()); |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2374 | } |
| 2375 | |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2376 | field = ObjCIvarDecl::Create (*ast, |
| 2377 | class_interface_decl, |
| 2378 | SourceLocation(), |
| 2379 | SourceLocation(), |
Greg Clayton | 88bc7f3 | 2012-11-06 00:20:41 +0000 | [diff] [blame] | 2380 | name ? &identifier_table->get(name) : NULL, // Identifier |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2381 | QualType::getFromOpaquePtr(ivar_opaque_type), // Field type |
| 2382 | NULL, // TypeSourceInfo * |
| 2383 | ConvertAccessTypeToObjCIvarAccessControl (access), |
| 2384 | bit_width, |
| 2385 | is_synthesized); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2386 | |
| 2387 | if (field) |
| 2388 | { |
| 2389 | class_interface_decl->addDecl(field); |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 2390 | |
| 2391 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 2392 | VerifyDecl(field); |
| 2393 | #endif |
| 2394 | |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2395 | return field; |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2396 | } |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2397 | } |
| 2398 | } |
| 2399 | } |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2400 | return NULL; |
| 2401 | } |
| 2402 | |
| 2403 | bool |
| 2404 | ClangASTContext::AddObjCClassProperty |
| 2405 | ( |
| 2406 | ASTContext *ast, |
| 2407 | clang_type_t class_opaque_type, |
| 2408 | const char *property_name, |
| 2409 | clang_type_t property_opaque_type, |
| 2410 | ObjCIvarDecl *ivar_decl, |
| 2411 | const char *property_setter_name, |
| 2412 | const char *property_getter_name, |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 2413 | uint32_t property_attributes, |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2414 | ClangASTMetadata *metadata |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2415 | ) |
| 2416 | { |
Sean Callanan | 8a6a6ac | 2011-12-09 23:24:26 +0000 | [diff] [blame] | 2417 | if (class_opaque_type == NULL || property_name == NULL || property_name[0] == '\0') |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2418 | return false; |
| 2419 | |
| 2420 | IdentifierTable *identifier_table = &ast->Idents; |
| 2421 | |
| 2422 | assert (ast != NULL); |
| 2423 | assert (identifier_table != NULL); |
| 2424 | |
| 2425 | QualType class_qual_type(QualType::getFromOpaquePtr(class_opaque_type)); |
| 2426 | const clang::Type *class_type = class_qual_type.getTypePtr(); |
| 2427 | if (class_type) |
| 2428 | { |
| 2429 | const ObjCObjectType *objc_class_type = dyn_cast<ObjCObjectType>(class_type); |
| 2430 | |
| 2431 | if (objc_class_type) |
| 2432 | { |
| 2433 | ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 2434 | |
Greg Clayton | 23f5950 | 2012-07-17 03:23:13 +0000 | [diff] [blame] | 2435 | clang_type_t property_opaque_type_to_access = NULL; |
Sean Callanan | 8a6a6ac | 2011-12-09 23:24:26 +0000 | [diff] [blame] | 2436 | |
| 2437 | if (property_opaque_type) |
| 2438 | property_opaque_type_to_access = property_opaque_type; |
| 2439 | else if (ivar_decl) |
| 2440 | property_opaque_type_to_access = ivar_decl->getType().getAsOpaquePtr(); |
| 2441 | |
Sean Callanan | 8a6a6ac | 2011-12-09 23:24:26 +0000 | [diff] [blame] | 2442 | if (class_interface_decl && property_opaque_type_to_access) |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2443 | { |
| 2444 | clang::TypeSourceInfo *prop_type_source; |
| 2445 | if (ivar_decl) |
| 2446 | prop_type_source = ast->CreateTypeSourceInfo (ivar_decl->getType()); |
| 2447 | else |
| 2448 | prop_type_source = ast->CreateTypeSourceInfo (QualType::getFromOpaquePtr(property_opaque_type)); |
| 2449 | |
| 2450 | ObjCPropertyDecl *property_decl = ObjCPropertyDecl::Create(*ast, |
| 2451 | class_interface_decl, |
| 2452 | SourceLocation(), // Source Location |
| 2453 | &identifier_table->get(property_name), |
| 2454 | SourceLocation(), //Source Location for AT |
Sean Callanan | d5f33a8 | 2012-03-01 02:03:47 +0000 | [diff] [blame] | 2455 | SourceLocation(), //Source location for ( |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2456 | prop_type_source |
| 2457 | ); |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 2458 | |
Sean Callanan | 8a6a6ac | 2011-12-09 23:24:26 +0000 | [diff] [blame] | 2459 | if (property_decl) |
| 2460 | { |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2461 | if (metadata) |
| 2462 | SetMetadata(ast, (uintptr_t)property_decl, *metadata); |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 2463 | |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2464 | class_interface_decl->addDecl (property_decl); |
Sean Callanan | 8a6a6ac | 2011-12-09 23:24:26 +0000 | [diff] [blame] | 2465 | |
| 2466 | Selector setter_sel, getter_sel; |
| 2467 | |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2468 | if (property_setter_name != NULL) |
| 2469 | { |
| 2470 | std::string property_setter_no_colon(property_setter_name, strlen(property_setter_name) - 1); |
| 2471 | clang::IdentifierInfo *setter_ident = &identifier_table->get(property_setter_no_colon.c_str()); |
Sean Callanan | 8a6a6ac | 2011-12-09 23:24:26 +0000 | [diff] [blame] | 2472 | setter_sel = ast->Selectors.getSelector(1, &setter_ident); |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2473 | } |
Sean Callanan | 8a6a6ac | 2011-12-09 23:24:26 +0000 | [diff] [blame] | 2474 | else if (!(property_attributes & DW_APPLE_PROPERTY_readonly)) |
| 2475 | { |
| 2476 | std::string setter_sel_string("set"); |
| 2477 | setter_sel_string.push_back(::toupper(property_name[0])); |
| 2478 | setter_sel_string.append(&property_name[1]); |
| 2479 | clang::IdentifierInfo *setter_ident = &identifier_table->get(setter_sel_string.c_str()); |
| 2480 | setter_sel = ast->Selectors.getSelector(1, &setter_ident); |
| 2481 | } |
Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 2482 | property_decl->setSetterName(setter_sel); |
| 2483 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_setter); |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2484 | |
| 2485 | if (property_getter_name != NULL) |
| 2486 | { |
| 2487 | clang::IdentifierInfo *getter_ident = &identifier_table->get(property_getter_name); |
Sean Callanan | 8a6a6ac | 2011-12-09 23:24:26 +0000 | [diff] [blame] | 2488 | getter_sel = ast->Selectors.getSelector(0, &getter_ident); |
Sean Callanan | 8a6a6ac | 2011-12-09 23:24:26 +0000 | [diff] [blame] | 2489 | } |
| 2490 | else |
| 2491 | { |
| 2492 | clang::IdentifierInfo *getter_ident = &identifier_table->get(property_name); |
| 2493 | getter_sel = ast->Selectors.getSelector(0, &getter_ident); |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2494 | } |
Sean Callanan | a658226 | 2012-04-05 00:12:52 +0000 | [diff] [blame] | 2495 | property_decl->setGetterName(getter_sel); |
| 2496 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_getter); |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2497 | |
| 2498 | if (ivar_decl) |
| 2499 | property_decl->setPropertyIvarDecl (ivar_decl); |
| 2500 | |
| 2501 | if (property_attributes & DW_APPLE_PROPERTY_readonly) |
| 2502 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_readonly); |
| 2503 | if (property_attributes & DW_APPLE_PROPERTY_readwrite) |
| 2504 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_readwrite); |
| 2505 | if (property_attributes & DW_APPLE_PROPERTY_assign) |
| 2506 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_assign); |
| 2507 | if (property_attributes & DW_APPLE_PROPERTY_retain) |
| 2508 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_retain); |
| 2509 | if (property_attributes & DW_APPLE_PROPERTY_copy) |
| 2510 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_copy); |
| 2511 | if (property_attributes & DW_APPLE_PROPERTY_nonatomic) |
| 2512 | property_decl->setPropertyAttributes (clang::ObjCPropertyDecl::OBJC_PR_nonatomic); |
Sean Callanan | 8a6a6ac | 2011-12-09 23:24:26 +0000 | [diff] [blame] | 2513 | |
| 2514 | if (!getter_sel.isNull() && !class_interface_decl->lookupInstanceMethod(getter_sel)) |
| 2515 | { |
| 2516 | QualType result_type = QualType::getFromOpaquePtr(property_opaque_type_to_access); |
| 2517 | |
| 2518 | const bool isInstance = true; |
| 2519 | const bool isVariadic = false; |
| 2520 | const bool isSynthesized = false; |
| 2521 | const bool isImplicitlyDeclared = true; |
| 2522 | const bool isDefined = false; |
| 2523 | const ObjCMethodDecl::ImplementationControl impControl = ObjCMethodDecl::None; |
| 2524 | const bool HasRelatedResultType = false; |
| 2525 | |
| 2526 | ObjCMethodDecl *getter = ObjCMethodDecl::Create(*ast, |
| 2527 | SourceLocation(), |
| 2528 | SourceLocation(), |
| 2529 | getter_sel, |
| 2530 | result_type, |
| 2531 | NULL, |
| 2532 | class_interface_decl, |
| 2533 | isInstance, |
| 2534 | isVariadic, |
| 2535 | isSynthesized, |
| 2536 | isImplicitlyDeclared, |
| 2537 | isDefined, |
| 2538 | impControl, |
| 2539 | HasRelatedResultType); |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 2540 | |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2541 | if (getter && metadata) |
| 2542 | SetMetadata(ast, (uintptr_t)getter, *metadata); |
Sean Callanan | 8a6a6ac | 2011-12-09 23:24:26 +0000 | [diff] [blame] | 2543 | |
| 2544 | getter->setMethodParams(*ast, ArrayRef<ParmVarDecl*>(), ArrayRef<SourceLocation>()); |
| 2545 | |
| 2546 | class_interface_decl->addDecl(getter); |
| 2547 | } |
| 2548 | |
| 2549 | if (!setter_sel.isNull() && !class_interface_decl->lookupInstanceMethod(setter_sel)) |
| 2550 | { |
| 2551 | QualType result_type = ast->VoidTy; |
| 2552 | |
| 2553 | const bool isInstance = true; |
| 2554 | const bool isVariadic = false; |
| 2555 | const bool isSynthesized = false; |
| 2556 | const bool isImplicitlyDeclared = true; |
| 2557 | const bool isDefined = false; |
| 2558 | const ObjCMethodDecl::ImplementationControl impControl = ObjCMethodDecl::None; |
| 2559 | const bool HasRelatedResultType = false; |
| 2560 | |
| 2561 | ObjCMethodDecl *setter = ObjCMethodDecl::Create(*ast, |
| 2562 | SourceLocation(), |
| 2563 | SourceLocation(), |
| 2564 | setter_sel, |
| 2565 | result_type, |
| 2566 | NULL, |
| 2567 | class_interface_decl, |
| 2568 | isInstance, |
| 2569 | isVariadic, |
| 2570 | isSynthesized, |
| 2571 | isImplicitlyDeclared, |
| 2572 | isDefined, |
| 2573 | impControl, |
| 2574 | HasRelatedResultType); |
| 2575 | |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 2576 | if (setter && metadata) |
| 2577 | SetMetadata(ast, (uintptr_t)setter, *metadata); |
Sean Callanan | ad88076 | 2012-04-18 01:06:17 +0000 | [diff] [blame] | 2578 | |
Sean Callanan | 8a6a6ac | 2011-12-09 23:24:26 +0000 | [diff] [blame] | 2579 | llvm::SmallVector<ParmVarDecl *, 1> params; |
| 2580 | |
| 2581 | params.push_back (ParmVarDecl::Create (*ast, |
| 2582 | setter, |
| 2583 | SourceLocation(), |
| 2584 | SourceLocation(), |
| 2585 | NULL, // anonymous |
| 2586 | QualType::getFromOpaquePtr(property_opaque_type_to_access), |
| 2587 | NULL, |
| 2588 | SC_Auto, |
| 2589 | SC_Auto, |
| 2590 | NULL)); |
| 2591 | |
| 2592 | setter->setMethodParams(*ast, ArrayRef<ParmVarDecl*>(params), ArrayRef<SourceLocation>()); |
| 2593 | |
| 2594 | class_interface_decl->addDecl(setter); |
| 2595 | } |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2596 | |
| 2597 | return true; |
Sean Callanan | 8a6a6ac | 2011-12-09 23:24:26 +0000 | [diff] [blame] | 2598 | } |
Jim Ingham | e3ae82a | 2011-11-12 01:36:43 +0000 | [diff] [blame] | 2599 | } |
| 2600 | } |
| 2601 | } |
Greg Clayton | 8cf0593 | 2010-07-22 18:30:50 +0000 | [diff] [blame] | 2602 | return false; |
| 2603 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2604 | |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2605 | bool |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2606 | ClangASTContext::ObjCTypeHasIVars (clang_type_t class_opaque_type, bool check_superclass) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2607 | { |
| 2608 | QualType class_qual_type(QualType::getFromOpaquePtr(class_opaque_type)); |
| 2609 | |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 2610 | const clang::Type *class_type = class_qual_type.getTypePtr(); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2611 | if (class_type) |
| 2612 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 2613 | const ObjCObjectType *objc_class_type = dyn_cast<ObjCObjectType>(class_type); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2614 | |
| 2615 | if (objc_class_type) |
| 2616 | return ObjCDeclHasIVars (objc_class_type->getInterface(), check_superclass); |
| 2617 | } |
| 2618 | return false; |
| 2619 | } |
| 2620 | |
| 2621 | bool |
| 2622 | ClangASTContext::ObjCDeclHasIVars (ObjCInterfaceDecl *class_interface_decl, bool check_superclass) |
| 2623 | { |
| 2624 | while (class_interface_decl) |
| 2625 | { |
| 2626 | if (class_interface_decl->ivar_size() > 0) |
| 2627 | return true; |
| 2628 | |
| 2629 | if (check_superclass) |
| 2630 | class_interface_decl = class_interface_decl->getSuperClass(); |
| 2631 | else |
| 2632 | break; |
| 2633 | } |
| 2634 | return false; |
| 2635 | } |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2636 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2637 | ObjCMethodDecl * |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2638 | ClangASTContext::AddMethodToObjCObjectType |
| 2639 | ( |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2640 | ASTContext *ast, |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2641 | clang_type_t class_opaque_type, |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2642 | const char *name, // the full symbol name as seen in the symbol table ("-[NString stringWithCString:]") |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 2643 | clang_type_t method_opaque_type, |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2644 | lldb::AccessType access |
| 2645 | ) |
| 2646 | { |
| 2647 | if (class_opaque_type == NULL || method_opaque_type == NULL) |
| 2648 | return NULL; |
| 2649 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2650 | IdentifierTable *identifier_table = &ast->Idents; |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2651 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2652 | assert (ast != NULL); |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2653 | assert (identifier_table != NULL); |
| 2654 | |
| 2655 | QualType class_qual_type(QualType::getFromOpaquePtr(class_opaque_type)); |
| 2656 | |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 2657 | const clang::Type *class_type = class_qual_type.getTypePtr(); |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2658 | if (class_type == NULL) |
| 2659 | return NULL; |
| 2660 | |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 2661 | const ObjCObjectType *objc_class_type = dyn_cast<ObjCObjectType>(class_type); |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2662 | |
| 2663 | if (objc_class_type == NULL) |
| 2664 | return NULL; |
| 2665 | |
| 2666 | ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 2667 | |
| 2668 | if (class_interface_decl == NULL) |
| 2669 | return NULL; |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 2670 | |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2671 | const char *selector_start = ::strchr (name, ' '); |
| 2672 | if (selector_start == NULL) |
| 2673 | return NULL; |
| 2674 | |
| 2675 | selector_start++; |
| 2676 | if (!(::isalpha (selector_start[0]) || selector_start[0] == '_')) |
| 2677 | return NULL; |
| 2678 | llvm::SmallVector<IdentifierInfo *, 12> selector_idents; |
| 2679 | |
Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2680 | size_t len = 0; |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2681 | const char *start; |
Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2682 | //printf ("name = '%s'\n", name); |
| 2683 | |
| 2684 | unsigned num_selectors_with_args = 0; |
| 2685 | for (start = selector_start; |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2686 | start && *start != '\0' && *start != ']'; |
Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2687 | start += len) |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2688 | { |
Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2689 | len = ::strcspn(start, ":]"); |
Greg Clayton | 90f90cd | 2010-10-27 04:01:14 +0000 | [diff] [blame] | 2690 | bool has_arg = (start[len] == ':'); |
| 2691 | if (has_arg) |
Greg Clayton | 450e3f3 | 2010-10-12 02:24:53 +0000 | [diff] [blame] | 2692 | ++num_selectors_with_args; |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2693 | selector_idents.push_back (&identifier_table->get (StringRef (start, len))); |
Greg Clayton | 90f90cd | 2010-10-27 04:01:14 +0000 | [diff] [blame] | 2694 | if (has_arg) |
| 2695 | len += 1; |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | |
| 2699 | if (selector_idents.size() == 0) |
| 2700 | return 0; |
| 2701 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2702 | clang::Selector method_selector = ast->Selectors.getSelector (num_selectors_with_args ? selector_idents.size() : 0, |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2703 | selector_idents.data()); |
| 2704 | |
| 2705 | QualType method_qual_type (QualType::getFromOpaquePtr (method_opaque_type)); |
| 2706 | |
| 2707 | // Populate the method decl with parameter decls |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 2708 | const clang::Type *method_type(method_qual_type.getTypePtr()); |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2709 | |
| 2710 | if (method_type == NULL) |
| 2711 | return NULL; |
| 2712 | |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 2713 | const FunctionProtoType *method_function_prototype (dyn_cast<FunctionProtoType>(method_type)); |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2714 | |
| 2715 | if (!method_function_prototype) |
| 2716 | return NULL; |
| 2717 | |
| 2718 | |
| 2719 | bool is_variadic = false; |
| 2720 | bool is_synthesized = false; |
| 2721 | bool is_defined = false; |
| 2722 | ObjCMethodDecl::ImplementationControl imp_control = ObjCMethodDecl::None; |
| 2723 | |
| 2724 | const unsigned num_args = method_function_prototype->getNumArgs(); |
| 2725 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2726 | ObjCMethodDecl *objc_method_decl = ObjCMethodDecl::Create (*ast, |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2727 | SourceLocation(), // beginLoc, |
| 2728 | SourceLocation(), // endLoc, |
| 2729 | method_selector, |
| 2730 | method_function_prototype->getResultType(), |
| 2731 | NULL, // TypeSourceInfo *ResultTInfo, |
| 2732 | GetDeclContextForType (class_opaque_type), |
| 2733 | name[0] == '-', |
| 2734 | is_variadic, |
| 2735 | is_synthesized, |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 2736 | true, // is_implicitly_declared |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2737 | is_defined, |
| 2738 | imp_control, |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 2739 | false /*has_related_result_type*/); |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2740 | |
| 2741 | |
| 2742 | if (objc_method_decl == NULL) |
| 2743 | return NULL; |
| 2744 | |
| 2745 | if (num_args > 0) |
| 2746 | { |
| 2747 | llvm::SmallVector<ParmVarDecl *, 12> params; |
| 2748 | |
| 2749 | for (int param_index = 0; param_index < num_args; ++param_index) |
| 2750 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2751 | params.push_back (ParmVarDecl::Create (*ast, |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2752 | objc_method_decl, |
| 2753 | SourceLocation(), |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 2754 | SourceLocation(), |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2755 | NULL, // anonymous |
| 2756 | method_function_prototype->getArgType(param_index), |
| 2757 | NULL, |
| 2758 | SC_Auto, |
| 2759 | SC_Auto, |
| 2760 | NULL)); |
| 2761 | } |
| 2762 | |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 2763 | objc_method_decl->setMethodParams(*ast, ArrayRef<ParmVarDecl*>(params), ArrayRef<SourceLocation>()); |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | class_interface_decl->addDecl (objc_method_decl); |
| 2767 | |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 2768 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 2769 | VerifyDecl(objc_method_decl); |
| 2770 | #endif |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2771 | |
| 2772 | return objc_method_decl; |
| 2773 | } |
| 2774 | |
Greg Clayton | 402230e | 2012-02-03 01:30:30 +0000 | [diff] [blame] | 2775 | size_t |
| 2776 | ClangASTContext::GetNumTemplateArguments (clang::ASTContext *ast, clang_type_t clang_type) |
| 2777 | { |
| 2778 | if (clang_type) |
| 2779 | { |
| 2780 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 2781 | |
| 2782 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2783 | switch (type_class) |
| 2784 | { |
| 2785 | case clang::Type::Record: |
| 2786 | if (GetCompleteQualType (ast, qual_type)) |
| 2787 | { |
| 2788 | const CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 2789 | if (cxx_record_decl) |
| 2790 | { |
| 2791 | const ClassTemplateSpecializationDecl *template_decl = dyn_cast<ClassTemplateSpecializationDecl>(cxx_record_decl); |
| 2792 | if (template_decl) |
| 2793 | return template_decl->getTemplateArgs().size(); |
| 2794 | } |
| 2795 | } |
| 2796 | break; |
| 2797 | |
| 2798 | case clang::Type::Typedef: |
| 2799 | return ClangASTContext::GetNumTemplateArguments (ast, cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
Greg Clayton | 4b63a5c | 2013-01-04 18:10:18 +0000 | [diff] [blame] | 2800 | |
| 2801 | case clang::Type::Elaborated: |
| 2802 | return ClangASTContext::GetNumTemplateArguments (ast, cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
| 2803 | |
Greg Clayton | 402230e | 2012-02-03 01:30:30 +0000 | [diff] [blame] | 2804 | default: |
| 2805 | break; |
| 2806 | } |
| 2807 | } |
| 2808 | return 0; |
| 2809 | } |
| 2810 | |
| 2811 | clang_type_t |
| 2812 | ClangASTContext::GetTemplateArgument (clang::ASTContext *ast, clang_type_t clang_type, size_t arg_idx, lldb::TemplateArgumentKind &kind) |
| 2813 | { |
| 2814 | if (clang_type) |
| 2815 | { |
| 2816 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 2817 | |
| 2818 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2819 | switch (type_class) |
| 2820 | { |
| 2821 | case clang::Type::Record: |
| 2822 | if (GetCompleteQualType (ast, qual_type)) |
| 2823 | { |
| 2824 | const CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 2825 | if (cxx_record_decl) |
| 2826 | { |
| 2827 | const ClassTemplateSpecializationDecl *template_decl = dyn_cast<ClassTemplateSpecializationDecl>(cxx_record_decl); |
| 2828 | if (template_decl && arg_idx < template_decl->getTemplateArgs().size()) |
| 2829 | { |
| 2830 | const TemplateArgument &template_arg = template_decl->getTemplateArgs()[arg_idx]; |
| 2831 | switch (template_arg.getKind()) |
| 2832 | { |
| 2833 | case clang::TemplateArgument::Null: |
| 2834 | kind = eTemplateArgumentKindNull; |
| 2835 | return NULL; |
| 2836 | |
| 2837 | case clang::TemplateArgument::Type: |
| 2838 | kind = eTemplateArgumentKindType; |
| 2839 | return template_arg.getAsType().getAsOpaquePtr(); |
| 2840 | |
| 2841 | case clang::TemplateArgument::Declaration: |
| 2842 | kind = eTemplateArgumentKindDeclaration; |
| 2843 | return NULL; |
| 2844 | |
| 2845 | case clang::TemplateArgument::Integral: |
| 2846 | kind = eTemplateArgumentKindIntegral; |
| 2847 | return template_arg.getIntegralType().getAsOpaquePtr(); |
| 2848 | |
| 2849 | case clang::TemplateArgument::Template: |
| 2850 | kind = eTemplateArgumentKindTemplate; |
| 2851 | return NULL; |
| 2852 | |
| 2853 | case clang::TemplateArgument::TemplateExpansion: |
| 2854 | kind = eTemplateArgumentKindTemplateExpansion; |
| 2855 | return NULL; |
| 2856 | |
| 2857 | case clang::TemplateArgument::Expression: |
| 2858 | kind = eTemplateArgumentKindExpression; |
| 2859 | return NULL; |
| 2860 | |
| 2861 | case clang::TemplateArgument::Pack: |
| 2862 | kind = eTemplateArgumentKindPack; |
| 2863 | return NULL; |
| 2864 | |
| 2865 | default: |
| 2866 | assert (!"Unhandled TemplateArgument::ArgKind"); |
| 2867 | kind = eTemplateArgumentKindNull; |
| 2868 | return NULL; |
| 2869 | } |
| 2870 | } |
| 2871 | } |
| 2872 | } |
| 2873 | break; |
| 2874 | |
| 2875 | case clang::Type::Typedef: |
| 2876 | return ClangASTContext::GetTemplateArgument (ast, cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), arg_idx, kind); |
Greg Clayton | 4b63a5c | 2013-01-04 18:10:18 +0000 | [diff] [blame] | 2877 | |
| 2878 | case clang::Type::Elaborated: |
| 2879 | return ClangASTContext::GetTemplateArgument (ast, cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), arg_idx, kind); |
| 2880 | |
Greg Clayton | 402230e | 2012-02-03 01:30:30 +0000 | [diff] [blame] | 2881 | default: |
| 2882 | break; |
| 2883 | } |
| 2884 | } |
| 2885 | kind = eTemplateArgumentKindNull; |
| 2886 | return NULL; |
| 2887 | } |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 2888 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2889 | uint32_t |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2890 | ClangASTContext::GetTypeInfo |
| 2891 | ( |
| 2892 | clang_type_t clang_type, |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2893 | clang::ASTContext *ast, |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2894 | clang_type_t *pointee_or_element_clang_type |
| 2895 | ) |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2896 | { |
| 2897 | if (clang_type == NULL) |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2898 | return 0; |
| 2899 | |
| 2900 | if (pointee_or_element_clang_type) |
| 2901 | *pointee_or_element_clang_type = NULL; |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2902 | |
| 2903 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 2904 | |
| 2905 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 2906 | switch (type_class) |
| 2907 | { |
Sean Callanan | a242417 | 2010-10-25 00:29:48 +0000 | [diff] [blame] | 2908 | case clang::Type::Builtin: |
| 2909 | switch (cast<clang::BuiltinType>(qual_type)->getKind()) |
| 2910 | { |
Sean Callanan | a242417 | 2010-10-25 00:29:48 +0000 | [diff] [blame] | 2911 | case clang::BuiltinType::ObjCId: |
| 2912 | case clang::BuiltinType::ObjCClass: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 2913 | if (ast && pointee_or_element_clang_type) |
| 2914 | *pointee_or_element_clang_type = ast->ObjCBuiltinClassTy.getAsOpaquePtr(); |
Sean Callanan | a242417 | 2010-10-25 00:29:48 +0000 | [diff] [blame] | 2915 | return eTypeIsBuiltIn | eTypeIsPointer | eTypeHasValue; |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 2916 | break; |
| 2917 | case clang::BuiltinType::Bool: |
| 2918 | case clang::BuiltinType::Char_U: |
| 2919 | case clang::BuiltinType::UChar: |
| 2920 | case clang::BuiltinType::WChar_U: |
| 2921 | case clang::BuiltinType::Char16: |
| 2922 | case clang::BuiltinType::Char32: |
| 2923 | case clang::BuiltinType::UShort: |
| 2924 | case clang::BuiltinType::UInt: |
| 2925 | case clang::BuiltinType::ULong: |
| 2926 | case clang::BuiltinType::ULongLong: |
| 2927 | case clang::BuiltinType::UInt128: |
| 2928 | case clang::BuiltinType::Char_S: |
| 2929 | case clang::BuiltinType::SChar: |
| 2930 | case clang::BuiltinType::WChar_S: |
| 2931 | case clang::BuiltinType::Short: |
| 2932 | case clang::BuiltinType::Int: |
| 2933 | case clang::BuiltinType::Long: |
| 2934 | case clang::BuiltinType::LongLong: |
| 2935 | case clang::BuiltinType::Int128: |
| 2936 | case clang::BuiltinType::Float: |
| 2937 | case clang::BuiltinType::Double: |
| 2938 | case clang::BuiltinType::LongDouble: |
| 2939 | return eTypeIsBuiltIn | eTypeHasValue | eTypeIsScalar; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2940 | default: |
| 2941 | break; |
Sean Callanan | a242417 | 2010-10-25 00:29:48 +0000 | [diff] [blame] | 2942 | } |
| 2943 | return eTypeIsBuiltIn | eTypeHasValue; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2944 | |
| 2945 | case clang::Type::BlockPointer: |
| 2946 | if (pointee_or_element_clang_type) |
| 2947 | *pointee_or_element_clang_type = qual_type->getPointeeType().getAsOpaquePtr(); |
| 2948 | return eTypeIsPointer | eTypeHasChildren | eTypeIsBlock; |
| 2949 | |
Greg Clayton | 49462ea | 2011-01-15 02:52:14 +0000 | [diff] [blame] | 2950 | case clang::Type::Complex: return eTypeIsBuiltIn | eTypeHasValue; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2951 | |
| 2952 | case clang::Type::ConstantArray: |
| 2953 | case clang::Type::DependentSizedArray: |
| 2954 | case clang::Type::IncompleteArray: |
| 2955 | case clang::Type::VariableArray: |
| 2956 | if (pointee_or_element_clang_type) |
| 2957 | *pointee_or_element_clang_type = cast<ArrayType>(qual_type.getTypePtr())->getElementType().getAsOpaquePtr(); |
| 2958 | return eTypeHasChildren | eTypeIsArray; |
| 2959 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2960 | case clang::Type::DependentName: return 0; |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2961 | case clang::Type::DependentSizedExtVector: return eTypeHasChildren | eTypeIsVector; |
| 2962 | case clang::Type::DependentTemplateSpecialization: return eTypeIsTemplate; |
| 2963 | case clang::Type::Decltype: return 0; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2964 | |
| 2965 | case clang::Type::Enum: |
| 2966 | if (pointee_or_element_clang_type) |
| 2967 | *pointee_or_element_clang_type = cast<EnumType>(qual_type)->getDecl()->getIntegerType().getAsOpaquePtr(); |
| 2968 | return eTypeIsEnumeration | eTypeHasValue; |
| 2969 | |
Sean Callanan | 912855f | 2011-08-11 23:56:13 +0000 | [diff] [blame] | 2970 | case clang::Type::Elaborated: |
| 2971 | return ClangASTContext::GetTypeInfo (cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), |
| 2972 | ast, |
| 2973 | pointee_or_element_clang_type); |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2974 | case clang::Type::ExtVector: return eTypeHasChildren | eTypeIsVector; |
| 2975 | case clang::Type::FunctionProto: return eTypeIsFuncPrototype | eTypeHasValue; |
| 2976 | case clang::Type::FunctionNoProto: return eTypeIsFuncPrototype | eTypeHasValue; |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2977 | case clang::Type::InjectedClassName: return 0; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2978 | |
| 2979 | case clang::Type::LValueReference: |
| 2980 | case clang::Type::RValueReference: |
| 2981 | if (pointee_or_element_clang_type) |
| 2982 | *pointee_or_element_clang_type = cast<ReferenceType>(qual_type.getTypePtr())->getPointeeType().getAsOpaquePtr(); |
| 2983 | return eTypeHasChildren | eTypeIsReference | eTypeHasValue; |
| 2984 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2985 | case clang::Type::MemberPointer: return eTypeIsPointer | eTypeIsMember | eTypeHasValue; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2986 | |
| 2987 | case clang::Type::ObjCObjectPointer: |
| 2988 | if (pointee_or_element_clang_type) |
| 2989 | *pointee_or_element_clang_type = qual_type->getPointeeType().getAsOpaquePtr(); |
| 2990 | return eTypeHasChildren | eTypeIsObjC | eTypeIsClass | eTypeIsPointer | eTypeHasValue; |
| 2991 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 2992 | case clang::Type::ObjCObject: return eTypeHasChildren | eTypeIsObjC | eTypeIsClass; |
| 2993 | case clang::Type::ObjCInterface: return eTypeHasChildren | eTypeIsObjC | eTypeIsClass; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 2994 | |
| 2995 | case clang::Type::Pointer: |
| 2996 | if (pointee_or_element_clang_type) |
| 2997 | *pointee_or_element_clang_type = qual_type->getPointeeType().getAsOpaquePtr(); |
| 2998 | return eTypeHasChildren | eTypeIsPointer | eTypeHasValue; |
| 2999 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3000 | case clang::Type::Record: |
| 3001 | if (qual_type->getAsCXXRecordDecl()) |
| 3002 | return eTypeHasChildren | eTypeIsClass | eTypeIsCPlusPlus; |
| 3003 | else |
| 3004 | return eTypeHasChildren | eTypeIsStructUnion; |
| 3005 | break; |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3006 | case clang::Type::SubstTemplateTypeParm: return eTypeIsTemplate; |
| 3007 | case clang::Type::TemplateTypeParm: return eTypeIsTemplate; |
| 3008 | case clang::Type::TemplateSpecialization: return eTypeIsTemplate; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 3009 | |
| 3010 | case clang::Type::Typedef: |
Sean Callanan | 4811447 | 2010-12-13 01:26:27 +0000 | [diff] [blame] | 3011 | return eTypeIsTypedef | ClangASTContext::GetTypeInfo (cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3012 | ast, |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 3013 | pointee_or_element_clang_type); |
| 3014 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3015 | case clang::Type::TypeOfExpr: return 0; |
| 3016 | case clang::Type::TypeOf: return 0; |
| 3017 | case clang::Type::UnresolvedUsing: return 0; |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3018 | case clang::Type::Vector: return eTypeHasChildren | eTypeIsVector; |
| 3019 | default: return 0; |
| 3020 | } |
| 3021 | return 0; |
| 3022 | } |
| 3023 | |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 3024 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3025 | #pragma mark Aggregate Types |
| 3026 | |
| 3027 | bool |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3028 | ClangASTContext::IsAggregateType (clang_type_t clang_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3029 | { |
| 3030 | if (clang_type == NULL) |
| 3031 | return false; |
| 3032 | |
| 3033 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 3034 | |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 3035 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3036 | switch (type_class) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3037 | { |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 3038 | case clang::Type::IncompleteArray: |
| 3039 | case clang::Type::VariableArray: |
| 3040 | case clang::Type::ConstantArray: |
| 3041 | case clang::Type::ExtVector: |
| 3042 | case clang::Type::Vector: |
| 3043 | case clang::Type::Record: |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 3044 | case clang::Type::ObjCObject: |
| 3045 | case clang::Type::ObjCInterface: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3046 | return true; |
Sean Callanan | 912855f | 2011-08-11 23:56:13 +0000 | [diff] [blame] | 3047 | case clang::Type::Elaborated: |
| 3048 | return ClangASTContext::IsAggregateType (cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 3049 | case clang::Type::Typedef: |
Sean Callanan | 4811447 | 2010-12-13 01:26:27 +0000 | [diff] [blame] | 3050 | return ClangASTContext::IsAggregateType (cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3051 | |
| 3052 | default: |
| 3053 | break; |
| 3054 | } |
| 3055 | // The clang type does have a value |
| 3056 | return false; |
| 3057 | } |
| 3058 | |
| 3059 | uint32_t |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3060 | ClangASTContext::GetNumChildren (clang::ASTContext *ast, clang_type_t clang_type, bool omit_empty_base_classes) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3061 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3062 | if (clang_type == NULL) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3063 | return 0; |
| 3064 | |
| 3065 | uint32_t num_children = 0; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3066 | QualType qual_type(QualType::getFromOpaquePtr(clang_type)); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 3067 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3068 | switch (type_class) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3069 | { |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3070 | case clang::Type::Builtin: |
| 3071 | switch (cast<clang::BuiltinType>(qual_type)->getKind()) |
| 3072 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 3073 | case clang::BuiltinType::ObjCId: // child is Class |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3074 | case clang::BuiltinType::ObjCClass: // child is Class |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3075 | num_children = 1; |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 3076 | break; |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3077 | |
| 3078 | default: |
| 3079 | break; |
| 3080 | } |
| 3081 | break; |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3082 | |
Greg Clayton | 49462ea | 2011-01-15 02:52:14 +0000 | [diff] [blame] | 3083 | case clang::Type::Complex: return 0; |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3084 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 3085 | case clang::Type::Record: |
Greg Clayton | c432c19 | 2011-01-20 04:18:48 +0000 | [diff] [blame] | 3086 | if (GetCompleteQualType (ast, qual_type)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3087 | { |
| 3088 | const RecordType *record_type = cast<RecordType>(qual_type.getTypePtr()); |
| 3089 | const RecordDecl *record_decl = record_type->getDecl(); |
| 3090 | assert(record_decl); |
| 3091 | const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl); |
| 3092 | if (cxx_record_decl) |
| 3093 | { |
| 3094 | if (omit_empty_base_classes) |
| 3095 | { |
| 3096 | // Check each base classes to see if it or any of its |
| 3097 | // base classes contain any fields. This can help |
| 3098 | // limit the noise in variable views by not having to |
| 3099 | // show base classes that contain no members. |
| 3100 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 3101 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 3102 | base_class != base_class_end; |
| 3103 | ++base_class) |
| 3104 | { |
| 3105 | const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(base_class->getType()->getAs<RecordType>()->getDecl()); |
| 3106 | |
| 3107 | // Skip empty base classes |
| 3108 | if (RecordHasFields(base_class_decl) == false) |
| 3109 | continue; |
| 3110 | |
| 3111 | num_children++; |
| 3112 | } |
| 3113 | } |
| 3114 | else |
| 3115 | { |
| 3116 | // Include all base classes |
| 3117 | num_children += cxx_record_decl->getNumBases(); |
| 3118 | } |
| 3119 | |
| 3120 | } |
| 3121 | RecordDecl::field_iterator field, field_end; |
| 3122 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field) |
| 3123 | ++num_children; |
| 3124 | } |
| 3125 | break; |
| 3126 | |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 3127 | case clang::Type::ObjCObject: |
| 3128 | case clang::Type::ObjCInterface: |
Greg Clayton | c432c19 | 2011-01-20 04:18:48 +0000 | [diff] [blame] | 3129 | if (GetCompleteQualType (ast, qual_type)) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 3130 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 3131 | const ObjCObjectType *objc_class_type = dyn_cast<ObjCObjectType>(qual_type.getTypePtr()); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 3132 | assert (objc_class_type); |
| 3133 | if (objc_class_type) |
| 3134 | { |
| 3135 | ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 3136 | |
| 3137 | if (class_interface_decl) |
| 3138 | { |
| 3139 | |
| 3140 | ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 3141 | if (superclass_interface_decl) |
| 3142 | { |
| 3143 | if (omit_empty_base_classes) |
| 3144 | { |
| 3145 | if (ClangASTContext::ObjCDeclHasIVars (superclass_interface_decl, true)) |
| 3146 | ++num_children; |
| 3147 | } |
| 3148 | else |
| 3149 | ++num_children; |
| 3150 | } |
| 3151 | |
| 3152 | num_children += class_interface_decl->ivar_size(); |
| 3153 | } |
| 3154 | } |
| 3155 | } |
| 3156 | break; |
| 3157 | |
| 3158 | case clang::Type::ObjCObjectPointer: |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3159 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 3160 | const ObjCObjectPointerType *pointer_type = cast<ObjCObjectPointerType>(qual_type.getTypePtr()); |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3161 | QualType pointee_type = pointer_type->getPointeeType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3162 | uint32_t num_pointee_children = ClangASTContext::GetNumChildren (ast, |
| 3163 | pointee_type.getAsOpaquePtr(), |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3164 | omit_empty_base_classes); |
| 3165 | // If this type points to a simple type, then it has 1 child |
| 3166 | if (num_pointee_children == 0) |
| 3167 | num_children = 1; |
| 3168 | else |
| 3169 | num_children = num_pointee_children; |
| 3170 | } |
| 3171 | break; |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 3172 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 3173 | case clang::Type::ConstantArray: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3174 | num_children = cast<ConstantArrayType>(qual_type.getTypePtr())->getSize().getLimitedValue(); |
| 3175 | break; |
| 3176 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 3177 | case clang::Type::Pointer: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3178 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 3179 | const PointerType *pointer_type = cast<PointerType>(qual_type.getTypePtr()); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3180 | QualType pointee_type (pointer_type->getPointeeType()); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3181 | uint32_t num_pointee_children = ClangASTContext::GetNumChildren (ast, |
| 3182 | pointee_type.getAsOpaquePtr(), |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 3183 | omit_empty_base_classes); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3184 | if (num_pointee_children == 0) |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3185 | { |
| 3186 | // We have a pointer to a pointee type that claims it has no children. |
| 3187 | // We will want to look at |
| 3188 | num_children = ClangASTContext::GetNumPointeeChildren (pointee_type.getAsOpaquePtr()); |
| 3189 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3190 | else |
| 3191 | num_children = num_pointee_children; |
| 3192 | } |
| 3193 | break; |
| 3194 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 3195 | case clang::Type::LValueReference: |
| 3196 | case clang::Type::RValueReference: |
| 3197 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 3198 | const ReferenceType *reference_type = cast<ReferenceType>(qual_type.getTypePtr()); |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 3199 | QualType pointee_type = reference_type->getPointeeType(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3200 | uint32_t num_pointee_children = ClangASTContext::GetNumChildren (ast, |
| 3201 | pointee_type.getAsOpaquePtr(), |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 3202 | omit_empty_base_classes); |
| 3203 | // If this type points to a simple type, then it has 1 child |
| 3204 | if (num_pointee_children == 0) |
| 3205 | num_children = 1; |
| 3206 | else |
| 3207 | num_children = num_pointee_children; |
| 3208 | } |
| 3209 | break; |
| 3210 | |
| 3211 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 3212 | case clang::Type::Typedef: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3213 | num_children = ClangASTContext::GetNumChildren (ast, |
| 3214 | cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), |
| 3215 | omit_empty_base_classes); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3216 | break; |
Sean Callanan | 912855f | 2011-08-11 23:56:13 +0000 | [diff] [blame] | 3217 | |
| 3218 | case clang::Type::Elaborated: |
| 3219 | num_children = ClangASTContext::GetNumChildren (ast, |
| 3220 | cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), |
| 3221 | omit_empty_base_classes); |
| 3222 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3223 | |
| 3224 | default: |
| 3225 | break; |
| 3226 | } |
| 3227 | return num_children; |
| 3228 | } |
| 3229 | |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3230 | uint32_t |
| 3231 | ClangASTContext::GetNumDirectBaseClasses (clang::ASTContext *ast, clang_type_t clang_type) |
| 3232 | { |
| 3233 | if (clang_type == NULL) |
| 3234 | return 0; |
| 3235 | |
| 3236 | uint32_t count = 0; |
| 3237 | QualType qual_type(QualType::getFromOpaquePtr(clang_type)); |
| 3238 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3239 | switch (type_class) |
| 3240 | { |
| 3241 | case clang::Type::Record: |
| 3242 | if (GetCompleteQualType (ast, qual_type)) |
| 3243 | { |
| 3244 | const CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 3245 | if (cxx_record_decl) |
| 3246 | count = cxx_record_decl->getNumBases(); |
| 3247 | } |
| 3248 | break; |
| 3249 | |
| 3250 | case clang::Type::ObjCObject: |
| 3251 | case clang::Type::ObjCInterface: |
| 3252 | if (GetCompleteQualType (ast, qual_type)) |
| 3253 | { |
| 3254 | const ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType(); |
| 3255 | if (objc_class_type) |
| 3256 | { |
| 3257 | ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 3258 | |
| 3259 | if (class_interface_decl && class_interface_decl->getSuperClass()) |
| 3260 | count = 1; |
| 3261 | } |
| 3262 | } |
| 3263 | break; |
| 3264 | |
| 3265 | |
| 3266 | case clang::Type::Typedef: |
| 3267 | count = ClangASTContext::GetNumDirectBaseClasses (ast, cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
| 3268 | break; |
| 3269 | |
| 3270 | case clang::Type::Elaborated: |
| 3271 | count = ClangASTContext::GetNumDirectBaseClasses (ast, cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
| 3272 | break; |
| 3273 | |
| 3274 | default: |
| 3275 | break; |
| 3276 | } |
| 3277 | return count; |
| 3278 | } |
| 3279 | |
| 3280 | uint32_t |
| 3281 | ClangASTContext::GetNumVirtualBaseClasses (clang::ASTContext *ast, |
| 3282 | clang_type_t clang_type) |
| 3283 | { |
| 3284 | if (clang_type == NULL) |
| 3285 | return 0; |
| 3286 | |
| 3287 | uint32_t count = 0; |
| 3288 | QualType qual_type(QualType::getFromOpaquePtr(clang_type)); |
| 3289 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3290 | switch (type_class) |
| 3291 | { |
| 3292 | case clang::Type::Record: |
| 3293 | if (GetCompleteQualType (ast, qual_type)) |
| 3294 | { |
| 3295 | const CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 3296 | if (cxx_record_decl) |
| 3297 | count = cxx_record_decl->getNumVBases(); |
| 3298 | } |
| 3299 | break; |
| 3300 | |
| 3301 | case clang::Type::Typedef: |
| 3302 | count = ClangASTContext::GetNumVirtualBaseClasses (ast, cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
| 3303 | break; |
| 3304 | |
| 3305 | case clang::Type::Elaborated: |
| 3306 | count = ClangASTContext::GetNumVirtualBaseClasses (ast, cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
| 3307 | break; |
| 3308 | |
| 3309 | default: |
| 3310 | break; |
| 3311 | } |
| 3312 | return count; |
| 3313 | } |
| 3314 | |
| 3315 | uint32_t |
| 3316 | ClangASTContext::GetNumFields (clang::ASTContext *ast, clang_type_t clang_type) |
| 3317 | { |
| 3318 | if (clang_type == NULL) |
| 3319 | return 0; |
| 3320 | |
| 3321 | uint32_t count = 0; |
| 3322 | QualType qual_type(QualType::getFromOpaquePtr(clang_type)); |
| 3323 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3324 | switch (type_class) |
| 3325 | { |
| 3326 | case clang::Type::Record: |
| 3327 | if (GetCompleteQualType (ast, qual_type)) |
| 3328 | { |
| 3329 | const RecordType *record_type = dyn_cast<RecordType>(qual_type.getTypePtr()); |
| 3330 | if (record_type) |
| 3331 | { |
| 3332 | RecordDecl *record_decl = record_type->getDecl(); |
| 3333 | if (record_decl) |
| 3334 | { |
| 3335 | uint32_t field_idx = 0; |
| 3336 | RecordDecl::field_iterator field, field_end; |
| 3337 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field) |
| 3338 | ++field_idx; |
| 3339 | count = field_idx; |
| 3340 | } |
| 3341 | } |
| 3342 | } |
| 3343 | break; |
| 3344 | |
| 3345 | case clang::Type::Typedef: |
| 3346 | count = ClangASTContext::GetNumFields (ast, cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
| 3347 | break; |
| 3348 | |
| 3349 | case clang::Type::Elaborated: |
| 3350 | count = ClangASTContext::GetNumFields (ast, cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
| 3351 | break; |
| 3352 | |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3353 | case clang::Type::ObjCObject: |
| 3354 | case clang::Type::ObjCInterface: |
| 3355 | if (GetCompleteQualType (ast, qual_type)) |
| 3356 | { |
| 3357 | const ObjCObjectType *objc_class_type = dyn_cast<ObjCObjectType>(qual_type.getTypePtr()); |
| 3358 | if (objc_class_type) |
| 3359 | { |
| 3360 | ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 3361 | |
| 3362 | if (class_interface_decl) |
| 3363 | count = class_interface_decl->ivar_size(); |
| 3364 | } |
| 3365 | } |
| 3366 | break; |
| 3367 | |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3368 | default: |
| 3369 | break; |
| 3370 | } |
| 3371 | return count; |
| 3372 | } |
| 3373 | |
| 3374 | clang_type_t |
| 3375 | ClangASTContext::GetDirectBaseClassAtIndex (clang::ASTContext *ast, |
| 3376 | clang_type_t clang_type, |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3377 | size_t idx, |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3378 | uint32_t *bit_offset_ptr) |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3379 | { |
| 3380 | if (clang_type == NULL) |
| 3381 | return 0; |
| 3382 | |
| 3383 | QualType qual_type(QualType::getFromOpaquePtr(clang_type)); |
| 3384 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3385 | switch (type_class) |
| 3386 | { |
| 3387 | case clang::Type::Record: |
| 3388 | if (GetCompleteQualType (ast, qual_type)) |
| 3389 | { |
| 3390 | const CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 3391 | if (cxx_record_decl) |
| 3392 | { |
| 3393 | uint32_t curr_idx = 0; |
| 3394 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 3395 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 3396 | base_class != base_class_end; |
| 3397 | ++base_class, ++curr_idx) |
| 3398 | { |
| 3399 | if (curr_idx == idx) |
| 3400 | { |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3401 | if (bit_offset_ptr) |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3402 | { |
| 3403 | const ASTRecordLayout &record_layout = ast->getASTRecordLayout(cxx_record_decl); |
| 3404 | const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(base_class->getType()->getAs<RecordType>()->getDecl()); |
| 3405 | // if (base_class->isVirtual()) |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3406 | // *bit_offset_ptr = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3407 | // else |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3408 | *bit_offset_ptr = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8; |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3409 | } |
| 3410 | return base_class->getType().getAsOpaquePtr(); |
| 3411 | } |
| 3412 | } |
| 3413 | } |
| 3414 | } |
| 3415 | break; |
| 3416 | |
| 3417 | case clang::Type::ObjCObject: |
| 3418 | case clang::Type::ObjCInterface: |
| 3419 | if (idx == 0 && GetCompleteQualType (ast, qual_type)) |
| 3420 | { |
| 3421 | const ObjCObjectType *objc_class_type = qual_type->getAsObjCQualifiedInterfaceType(); |
| 3422 | if (objc_class_type) |
| 3423 | { |
| 3424 | ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 3425 | |
| 3426 | if (class_interface_decl) |
| 3427 | { |
| 3428 | ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 3429 | if (superclass_interface_decl) |
| 3430 | { |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3431 | if (bit_offset_ptr) |
| 3432 | *bit_offset_ptr = 0; |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3433 | return ast->getObjCInterfaceType(superclass_interface_decl).getAsOpaquePtr(); |
| 3434 | } |
| 3435 | } |
| 3436 | } |
| 3437 | } |
| 3438 | break; |
| 3439 | |
| 3440 | |
| 3441 | case clang::Type::Typedef: |
| 3442 | return ClangASTContext::GetDirectBaseClassAtIndex (ast, |
| 3443 | cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), |
| 3444 | idx, |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3445 | bit_offset_ptr); |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3446 | |
| 3447 | case clang::Type::Elaborated: |
| 3448 | return ClangASTContext::GetDirectBaseClassAtIndex (ast, |
| 3449 | cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), |
| 3450 | idx, |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3451 | bit_offset_ptr); |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3452 | |
| 3453 | default: |
| 3454 | break; |
| 3455 | } |
| 3456 | return NULL; |
| 3457 | } |
| 3458 | |
| 3459 | clang_type_t |
| 3460 | ClangASTContext::GetVirtualBaseClassAtIndex (clang::ASTContext *ast, |
| 3461 | clang_type_t clang_type, |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3462 | size_t idx, |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3463 | uint32_t *bit_offset_ptr) |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3464 | { |
| 3465 | if (clang_type == NULL) |
| 3466 | return 0; |
| 3467 | |
| 3468 | QualType qual_type(QualType::getFromOpaquePtr(clang_type)); |
| 3469 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3470 | switch (type_class) |
| 3471 | { |
| 3472 | case clang::Type::Record: |
| 3473 | if (GetCompleteQualType (ast, qual_type)) |
| 3474 | { |
| 3475 | const CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 3476 | if (cxx_record_decl) |
| 3477 | { |
| 3478 | uint32_t curr_idx = 0; |
| 3479 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 3480 | for (base_class = cxx_record_decl->vbases_begin(), base_class_end = cxx_record_decl->vbases_end(); |
| 3481 | base_class != base_class_end; |
| 3482 | ++base_class, ++curr_idx) |
| 3483 | { |
| 3484 | if (curr_idx == idx) |
| 3485 | { |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3486 | if (bit_offset_ptr) |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3487 | { |
| 3488 | const ASTRecordLayout &record_layout = ast->getASTRecordLayout(cxx_record_decl); |
| 3489 | const CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(base_class->getType()->getAs<RecordType>()->getDecl()); |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3490 | *bit_offset_ptr = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3491 | |
| 3492 | } |
| 3493 | return base_class->getType().getAsOpaquePtr(); |
| 3494 | } |
| 3495 | } |
| 3496 | } |
| 3497 | } |
| 3498 | break; |
| 3499 | |
| 3500 | case clang::Type::Typedef: |
| 3501 | return ClangASTContext::GetVirtualBaseClassAtIndex (ast, |
| 3502 | cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), |
| 3503 | idx, |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3504 | bit_offset_ptr); |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3505 | |
| 3506 | case clang::Type::Elaborated: |
| 3507 | return ClangASTContext::GetVirtualBaseClassAtIndex (ast, |
| 3508 | cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), |
| 3509 | idx, |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3510 | bit_offset_ptr); |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3511 | |
| 3512 | default: |
| 3513 | break; |
| 3514 | } |
| 3515 | return NULL; |
| 3516 | } |
| 3517 | |
| 3518 | clang_type_t |
| 3519 | ClangASTContext::GetFieldAtIndex (clang::ASTContext *ast, |
| 3520 | clang_type_t clang_type, |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3521 | size_t idx, |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3522 | std::string& name, |
Greg Clayton | 1811b4f | 2012-07-31 23:39:10 +0000 | [diff] [blame] | 3523 | uint64_t *bit_offset_ptr, |
| 3524 | uint32_t *bitfield_bit_size_ptr, |
| 3525 | bool *is_bitfield_ptr) |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3526 | { |
| 3527 | if (clang_type == NULL) |
| 3528 | return 0; |
| 3529 | |
| 3530 | QualType qual_type(QualType::getFromOpaquePtr(clang_type)); |
| 3531 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3532 | switch (type_class) |
| 3533 | { |
| 3534 | case clang::Type::Record: |
| 3535 | if (GetCompleteQualType (ast, qual_type)) |
| 3536 | { |
| 3537 | const RecordType *record_type = cast<RecordType>(qual_type.getTypePtr()); |
| 3538 | const RecordDecl *record_decl = record_type->getDecl(); |
| 3539 | uint32_t field_idx = 0; |
| 3540 | RecordDecl::field_iterator field, field_end; |
| 3541 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx) |
| 3542 | { |
| 3543 | if (idx == field_idx) |
| 3544 | { |
| 3545 | // Print the member type if requested |
| 3546 | // Print the member name and equal sign |
| 3547 | name.assign(field->getNameAsString()); |
| 3548 | |
| 3549 | // Figure out the type byte size (field_type_info.first) and |
| 3550 | // alignment (field_type_info.second) from the AST context. |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3551 | if (bit_offset_ptr) |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3552 | { |
| 3553 | const ASTRecordLayout &record_layout = ast->getASTRecordLayout(record_decl); |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3554 | *bit_offset_ptr = record_layout.getFieldOffset (field_idx); |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3555 | } |
| 3556 | |
Greg Clayton | 1811b4f | 2012-07-31 23:39:10 +0000 | [diff] [blame] | 3557 | const bool is_bitfield = field->isBitField(); |
| 3558 | |
| 3559 | if (bitfield_bit_size_ptr) |
| 3560 | { |
| 3561 | *bitfield_bit_size_ptr = 0; |
| 3562 | |
| 3563 | if (is_bitfield && ast) |
| 3564 | { |
| 3565 | Expr *bitfield_bit_size_expr = field->getBitWidth(); |
| 3566 | llvm::APSInt bitfield_apsint; |
| 3567 | if (bitfield_bit_size_expr && bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint, *ast)) |
| 3568 | { |
| 3569 | *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue(); |
| 3570 | } |
| 3571 | } |
| 3572 | } |
| 3573 | if (is_bitfield_ptr) |
| 3574 | *is_bitfield_ptr = is_bitfield; |
| 3575 | |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3576 | return field->getType().getAsOpaquePtr(); |
| 3577 | } |
| 3578 | } |
| 3579 | } |
| 3580 | break; |
| 3581 | |
| 3582 | case clang::Type::ObjCObject: |
| 3583 | case clang::Type::ObjCInterface: |
| 3584 | if (GetCompleteQualType (ast, qual_type)) |
| 3585 | { |
| 3586 | const ObjCObjectType *objc_class_type = dyn_cast<ObjCObjectType>(qual_type.getTypePtr()); |
| 3587 | assert (objc_class_type); |
| 3588 | if (objc_class_type) |
| 3589 | { |
| 3590 | ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 3591 | |
| 3592 | if (class_interface_decl) |
| 3593 | { |
| 3594 | if (idx < (class_interface_decl->ivar_size())) |
| 3595 | { |
| 3596 | ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end(); |
| 3597 | uint32_t ivar_idx = 0; |
| 3598 | |
| 3599 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++ivar_idx) |
| 3600 | { |
| 3601 | if (ivar_idx == idx) |
| 3602 | { |
| 3603 | const ObjCIvarDecl* ivar_decl = *ivar_pos; |
| 3604 | |
| 3605 | QualType ivar_qual_type(ivar_decl->getType()); |
| 3606 | |
| 3607 | name.assign(ivar_decl->getNameAsString()); |
| 3608 | |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3609 | if (bit_offset_ptr) |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3610 | { |
| 3611 | const ASTRecordLayout &interface_layout = ast->getASTObjCInterfaceLayout(class_interface_decl); |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 3612 | *bit_offset_ptr = interface_layout.getFieldOffset (ivar_idx); |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3613 | } |
| 3614 | |
Greg Clayton | 1811b4f | 2012-07-31 23:39:10 +0000 | [diff] [blame] | 3615 | const bool is_bitfield = ivar_pos->isBitField(); |
| 3616 | |
| 3617 | if (bitfield_bit_size_ptr) |
| 3618 | { |
| 3619 | *bitfield_bit_size_ptr = 0; |
| 3620 | |
| 3621 | if (is_bitfield && ast) |
| 3622 | { |
| 3623 | Expr *bitfield_bit_size_expr = ivar_pos->getBitWidth(); |
| 3624 | llvm::APSInt bitfield_apsint; |
| 3625 | if (bitfield_bit_size_expr && bitfield_bit_size_expr->EvaluateAsInt(bitfield_apsint, *ast)) |
| 3626 | { |
| 3627 | *bitfield_bit_size_ptr = bitfield_apsint.getLimitedValue(); |
| 3628 | } |
| 3629 | } |
| 3630 | } |
| 3631 | if (is_bitfield_ptr) |
| 3632 | *is_bitfield_ptr = is_bitfield; |
| 3633 | |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3634 | return ivar_qual_type.getAsOpaquePtr(); |
| 3635 | } |
| 3636 | } |
| 3637 | } |
| 3638 | } |
| 3639 | } |
| 3640 | } |
| 3641 | break; |
| 3642 | |
| 3643 | |
| 3644 | case clang::Type::Typedef: |
| 3645 | return ClangASTContext::GetFieldAtIndex (ast, |
| 3646 | cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), |
| 3647 | idx, |
| 3648 | name, |
Greg Clayton | 1811b4f | 2012-07-31 23:39:10 +0000 | [diff] [blame] | 3649 | bit_offset_ptr, |
| 3650 | bitfield_bit_size_ptr, |
| 3651 | is_bitfield_ptr); |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3652 | |
| 3653 | case clang::Type::Elaborated: |
| 3654 | return ClangASTContext::GetFieldAtIndex (ast, |
| 3655 | cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), |
| 3656 | idx, |
| 3657 | name, |
Greg Clayton | 1811b4f | 2012-07-31 23:39:10 +0000 | [diff] [blame] | 3658 | bit_offset_ptr, |
| 3659 | bitfield_bit_size_ptr, |
| 3660 | is_bitfield_ptr); |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3661 | |
| 3662 | default: |
| 3663 | break; |
| 3664 | } |
| 3665 | return NULL; |
| 3666 | } |
| 3667 | |
Greg Clayton | eaafa73 | 2012-10-13 00:20:27 +0000 | [diff] [blame] | 3668 | lldb::BasicType |
| 3669 | ClangASTContext::GetLLDBBasicTypeEnumeration (clang_type_t clang_type) |
| 3670 | { |
| 3671 | if (clang_type) |
| 3672 | { |
| 3673 | QualType qual_type(QualType::getFromOpaquePtr(clang_type)); |
| 3674 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
Greg Clayton | c4c5e89 | 2012-10-15 21:16:43 +0000 | [diff] [blame] | 3675 | if (type_class == clang::Type::Builtin) |
Greg Clayton | eaafa73 | 2012-10-13 00:20:27 +0000 | [diff] [blame] | 3676 | { |
Greg Clayton | eaafa73 | 2012-10-13 00:20:27 +0000 | [diff] [blame] | 3677 | switch (cast<clang::BuiltinType>(qual_type)->getKind()) |
Greg Clayton | c4c5e89 | 2012-10-15 21:16:43 +0000 | [diff] [blame] | 3678 | { |
Greg Clayton | eaafa73 | 2012-10-13 00:20:27 +0000 | [diff] [blame] | 3679 | case clang::BuiltinType::Void: return eBasicTypeVoid; |
| 3680 | case clang::BuiltinType::Bool: return eBasicTypeBool; |
| 3681 | case clang::BuiltinType::Char_S: return eBasicTypeSignedChar; |
| 3682 | case clang::BuiltinType::Char_U: return eBasicTypeUnsignedChar; |
| 3683 | case clang::BuiltinType::Char16: return eBasicTypeChar16; |
| 3684 | case clang::BuiltinType::Char32: return eBasicTypeChar32; |
| 3685 | case clang::BuiltinType::UChar: return eBasicTypeUnsignedChar; |
| 3686 | case clang::BuiltinType::SChar: return eBasicTypeSignedChar; |
| 3687 | case clang::BuiltinType::WChar_S: return eBasicTypeSignedWChar; |
| 3688 | case clang::BuiltinType::WChar_U: return eBasicTypeUnsignedWChar; |
| 3689 | case clang::BuiltinType::Short: return eBasicTypeShort; |
| 3690 | case clang::BuiltinType::UShort: return eBasicTypeUnsignedShort; |
| 3691 | case clang::BuiltinType::Int: return eBasicTypeInt; |
| 3692 | case clang::BuiltinType::UInt: return eBasicTypeUnsignedInt; |
| 3693 | case clang::BuiltinType::Long: return eBasicTypeLong; |
| 3694 | case clang::BuiltinType::ULong: return eBasicTypeUnsignedLong; |
| 3695 | case clang::BuiltinType::LongLong: return eBasicTypeLongLong; |
| 3696 | case clang::BuiltinType::ULongLong: return eBasicTypeUnsignedLongLong; |
| 3697 | case clang::BuiltinType::Int128: return eBasicTypeInt128; |
| 3698 | case clang::BuiltinType::UInt128: return eBasicTypeUnsignedInt128; |
| 3699 | |
| 3700 | case clang::BuiltinType::Half: return eBasicTypeHalf; |
| 3701 | case clang::BuiltinType::Float: return eBasicTypeFloat; |
| 3702 | case clang::BuiltinType::Double: return eBasicTypeDouble; |
| 3703 | case clang::BuiltinType::LongDouble:return eBasicTypeLongDouble; |
| 3704 | |
| 3705 | case clang::BuiltinType::NullPtr: return eBasicTypeNullPtr; |
| 3706 | case clang::BuiltinType::ObjCId: return eBasicTypeObjCID; |
| 3707 | case clang::BuiltinType::ObjCClass: return eBasicTypeObjCClass; |
| 3708 | case clang::BuiltinType::ObjCSel: return eBasicTypeObjCSel; |
| 3709 | case clang::BuiltinType::Dependent: |
| 3710 | case clang::BuiltinType::Overload: |
| 3711 | case clang::BuiltinType::BoundMember: |
| 3712 | case clang::BuiltinType::PseudoObject: |
| 3713 | case clang::BuiltinType::UnknownAny: |
| 3714 | case clang::BuiltinType::BuiltinFn: |
| 3715 | case clang::BuiltinType::ARCUnbridgedCast: |
Greg Clayton | 3dcaa2c | 2013-02-01 00:46:49 +0000 | [diff] [blame] | 3716 | case clang::BuiltinType::OCLEvent: |
| 3717 | case clang::BuiltinType::OCLImage1d: |
| 3718 | case clang::BuiltinType::OCLImage1dArray: |
| 3719 | case clang::BuiltinType::OCLImage1dBuffer: |
| 3720 | case clang::BuiltinType::OCLImage2d: |
| 3721 | case clang::BuiltinType::OCLImage2dArray: |
| 3722 | case clang::BuiltinType::OCLImage3d: |
Greg Clayton | eaafa73 | 2012-10-13 00:20:27 +0000 | [diff] [blame] | 3723 | return eBasicTypeOther; |
Greg Clayton | c4c5e89 | 2012-10-15 21:16:43 +0000 | [diff] [blame] | 3724 | } |
Greg Clayton | eaafa73 | 2012-10-13 00:20:27 +0000 | [diff] [blame] | 3725 | } |
| 3726 | } |
| 3727 | |
| 3728 | return eBasicTypeInvalid; |
| 3729 | } |
| 3730 | |
| 3731 | |
Greg Clayton | bf2331c | 2011-09-09 23:04:00 +0000 | [diff] [blame] | 3732 | |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3733 | // If a pointer to a pointee type (the clang_type arg) says that it has no |
| 3734 | // children, then we either need to trust it, or override it and return a |
| 3735 | // different result. For example, an "int *" has one child that is an integer, |
| 3736 | // but a function pointer doesn't have any children. Likewise if a Record type |
| 3737 | // claims it has no children, then there really is nothing to show. |
| 3738 | uint32_t |
| 3739 | ClangASTContext::GetNumPointeeChildren (clang_type_t clang_type) |
| 3740 | { |
| 3741 | if (clang_type == NULL) |
| 3742 | return 0; |
| 3743 | |
| 3744 | QualType qual_type(QualType::getFromOpaquePtr(clang_type)); |
| 3745 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 3746 | switch (type_class) |
| 3747 | { |
Greg Clayton | 97a4371 | 2011-01-08 22:26:47 +0000 | [diff] [blame] | 3748 | case clang::Type::Builtin: |
| 3749 | switch (cast<clang::BuiltinType>(qual_type)->getKind()) |
| 3750 | { |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 3751 | case clang::BuiltinType::UnknownAny: |
Greg Clayton | 97a4371 | 2011-01-08 22:26:47 +0000 | [diff] [blame] | 3752 | case clang::BuiltinType::Void: |
| 3753 | case clang::BuiltinType::NullPtr: |
Greg Clayton | 3dcaa2c | 2013-02-01 00:46:49 +0000 | [diff] [blame] | 3754 | case clang::BuiltinType::OCLEvent: |
| 3755 | case clang::BuiltinType::OCLImage1d: |
| 3756 | case clang::BuiltinType::OCLImage1dArray: |
| 3757 | case clang::BuiltinType::OCLImage1dBuffer: |
| 3758 | case clang::BuiltinType::OCLImage2d: |
| 3759 | case clang::BuiltinType::OCLImage2dArray: |
| 3760 | case clang::BuiltinType::OCLImage3d: |
Greg Clayton | 97a4371 | 2011-01-08 22:26:47 +0000 | [diff] [blame] | 3761 | return 0; |
| 3762 | case clang::BuiltinType::Bool: |
| 3763 | case clang::BuiltinType::Char_U: |
| 3764 | case clang::BuiltinType::UChar: |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 3765 | case clang::BuiltinType::WChar_U: |
Greg Clayton | 97a4371 | 2011-01-08 22:26:47 +0000 | [diff] [blame] | 3766 | case clang::BuiltinType::Char16: |
| 3767 | case clang::BuiltinType::Char32: |
| 3768 | case clang::BuiltinType::UShort: |
| 3769 | case clang::BuiltinType::UInt: |
| 3770 | case clang::BuiltinType::ULong: |
| 3771 | case clang::BuiltinType::ULongLong: |
| 3772 | case clang::BuiltinType::UInt128: |
| 3773 | case clang::BuiltinType::Char_S: |
| 3774 | case clang::BuiltinType::SChar: |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 3775 | case clang::BuiltinType::WChar_S: |
Greg Clayton | 97a4371 | 2011-01-08 22:26:47 +0000 | [diff] [blame] | 3776 | case clang::BuiltinType::Short: |
| 3777 | case clang::BuiltinType::Int: |
| 3778 | case clang::BuiltinType::Long: |
| 3779 | case clang::BuiltinType::LongLong: |
| 3780 | case clang::BuiltinType::Int128: |
| 3781 | case clang::BuiltinType::Float: |
| 3782 | case clang::BuiltinType::Double: |
| 3783 | case clang::BuiltinType::LongDouble: |
| 3784 | case clang::BuiltinType::Dependent: |
| 3785 | case clang::BuiltinType::Overload: |
Greg Clayton | 97a4371 | 2011-01-08 22:26:47 +0000 | [diff] [blame] | 3786 | case clang::BuiltinType::ObjCId: |
| 3787 | case clang::BuiltinType::ObjCClass: |
| 3788 | case clang::BuiltinType::ObjCSel: |
Sean Callanan | d12cf8bb | 2011-05-15 22:34:38 +0000 | [diff] [blame] | 3789 | case clang::BuiltinType::BoundMember: |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 3790 | case clang::BuiltinType::Half: |
| 3791 | case clang::BuiltinType::ARCUnbridgedCast: |
Greg Clayton | ed3ae70 | 2011-11-09 19:04:58 +0000 | [diff] [blame] | 3792 | case clang::BuiltinType::PseudoObject: |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 3793 | case clang::BuiltinType::BuiltinFn: |
Greg Clayton | 97a4371 | 2011-01-08 22:26:47 +0000 | [diff] [blame] | 3794 | return 1; |
| 3795 | } |
| 3796 | break; |
| 3797 | |
Greg Clayton | 49462ea | 2011-01-15 02:52:14 +0000 | [diff] [blame] | 3798 | case clang::Type::Complex: return 1; |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3799 | case clang::Type::Pointer: return 1; |
| 3800 | case clang::Type::BlockPointer: return 0; // If block pointers don't have debug info, then no children for them |
| 3801 | case clang::Type::LValueReference: return 1; |
| 3802 | case clang::Type::RValueReference: return 1; |
| 3803 | case clang::Type::MemberPointer: return 0; |
| 3804 | case clang::Type::ConstantArray: return 0; |
| 3805 | case clang::Type::IncompleteArray: return 0; |
| 3806 | case clang::Type::VariableArray: return 0; |
| 3807 | case clang::Type::DependentSizedArray: return 0; |
| 3808 | case clang::Type::DependentSizedExtVector: return 0; |
| 3809 | case clang::Type::Vector: return 0; |
| 3810 | case clang::Type::ExtVector: return 0; |
| 3811 | case clang::Type::FunctionProto: return 0; // When we function pointers, they have no children... |
| 3812 | case clang::Type::FunctionNoProto: return 0; // When we function pointers, they have no children... |
| 3813 | case clang::Type::UnresolvedUsing: return 0; |
| 3814 | case clang::Type::Paren: return 0; |
| 3815 | case clang::Type::Typedef: return ClangASTContext::GetNumPointeeChildren (cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
Sean Callanan | 912855f | 2011-08-11 23:56:13 +0000 | [diff] [blame] | 3816 | case clang::Type::Elaborated: return ClangASTContext::GetNumPointeeChildren (cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3817 | case clang::Type::TypeOfExpr: return 0; |
| 3818 | case clang::Type::TypeOf: return 0; |
| 3819 | case clang::Type::Decltype: return 0; |
| 3820 | case clang::Type::Record: return 0; |
| 3821 | case clang::Type::Enum: return 1; |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 3822 | case clang::Type::TemplateTypeParm: return 1; |
| 3823 | case clang::Type::SubstTemplateTypeParm: return 1; |
| 3824 | case clang::Type::TemplateSpecialization: return 1; |
| 3825 | case clang::Type::InjectedClassName: return 0; |
| 3826 | case clang::Type::DependentName: return 1; |
| 3827 | case clang::Type::DependentTemplateSpecialization: return 1; |
| 3828 | case clang::Type::ObjCObject: return 0; |
| 3829 | case clang::Type::ObjCInterface: return 0; |
| 3830 | case clang::Type::ObjCObjectPointer: return 1; |
| 3831 | default: |
| 3832 | break; |
| 3833 | } |
| 3834 | return 0; |
| 3835 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3836 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3837 | clang_type_t |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3838 | ClangASTContext::GetChildClangTypeAtIndex |
| 3839 | ( |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 3840 | ExecutionContext *exe_ctx, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3841 | const char *parent_name, |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3842 | clang_type_t parent_clang_type, |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3843 | size_t idx, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3844 | bool transparent_pointers, |
| 3845 | bool omit_empty_base_classes, |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 3846 | bool ignore_array_bounds, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3847 | std::string& child_name, |
| 3848 | uint32_t &child_byte_size, |
| 3849 | int32_t &child_byte_offset, |
| 3850 | uint32_t &child_bitfield_bit_size, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3851 | uint32_t &child_bitfield_bit_offset, |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 3852 | bool &child_is_base_class, |
| 3853 | bool &child_is_deref_of_parent |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3854 | ) |
| 3855 | { |
| 3856 | if (parent_clang_type) |
| 3857 | |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 3858 | return GetChildClangTypeAtIndex (exe_ctx, |
| 3859 | getASTContext(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3860 | parent_name, |
| 3861 | parent_clang_type, |
| 3862 | idx, |
| 3863 | transparent_pointers, |
| 3864 | omit_empty_base_classes, |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 3865 | ignore_array_bounds, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3866 | child_name, |
| 3867 | child_byte_size, |
| 3868 | child_byte_offset, |
| 3869 | child_bitfield_bit_size, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3870 | child_bitfield_bit_offset, |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 3871 | child_is_base_class, |
| 3872 | child_is_deref_of_parent); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3873 | return NULL; |
| 3874 | } |
| 3875 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3876 | clang_type_t |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3877 | ClangASTContext::GetChildClangTypeAtIndex |
| 3878 | ( |
Jim Ingham | d555bac | 2011-06-24 22:03:24 +0000 | [diff] [blame] | 3879 | ExecutionContext *exe_ctx, |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3880 | ASTContext *ast, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3881 | const char *parent_name, |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 3882 | clang_type_t parent_clang_type, |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 3883 | size_t idx, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3884 | bool transparent_pointers, |
| 3885 | bool omit_empty_base_classes, |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 3886 | bool ignore_array_bounds, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3887 | std::string& child_name, |
| 3888 | uint32_t &child_byte_size, |
| 3889 | int32_t &child_byte_offset, |
| 3890 | uint32_t &child_bitfield_bit_size, |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 3891 | uint32_t &child_bitfield_bit_offset, |
Greg Clayton | e221f82 | 2011-01-21 01:59:00 +0000 | [diff] [blame] | 3892 | bool &child_is_base_class, |
| 3893 | bool &child_is_deref_of_parent |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3894 | ) |
| 3895 | { |
| 3896 | if (parent_clang_type == NULL) |
| 3897 | return NULL; |
| 3898 | |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 3899 | QualType parent_qual_type(QualType::getFromOpaquePtr(parent_clang_type)); |
| 3900 | const clang::Type::TypeClass parent_type_class = parent_qual_type->getTypeClass(); |
| 3901 | child_bitfield_bit_size = 0; |
| 3902 | child_bitfield_bit_offset = 0; |
| 3903 | child_is_base_class = false; |
| 3904 | |
| 3905 | const bool idx_is_valid = idx < ClangASTContext::GetNumChildren (ast, parent_clang_type, omit_empty_base_classes); |
| 3906 | uint32_t bit_offset; |
| 3907 | switch (parent_type_class) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3908 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 3909 | case clang::Type::Builtin: |
| 3910 | if (idx_is_valid) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3911 | { |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3912 | switch (cast<clang::BuiltinType>(parent_qual_type)->getKind()) |
| 3913 | { |
| 3914 | case clang::BuiltinType::ObjCId: |
| 3915 | case clang::BuiltinType::ObjCClass: |
Sean Callanan | a242417 | 2010-10-25 00:29:48 +0000 | [diff] [blame] | 3916 | child_name = "isa"; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 3917 | child_byte_size = ast->getTypeSize(ast->ObjCBuiltinClassTy) / CHAR_BIT; |
| 3918 | return ast->ObjCBuiltinClassTy.getAsOpaquePtr(); |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3919 | |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3920 | default: |
| 3921 | break; |
| 3922 | } |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 3923 | } |
| 3924 | break; |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 3925 | |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 3926 | case clang::Type::Record: |
| 3927 | if (idx_is_valid && GetCompleteQualType (ast, parent_qual_type)) |
| 3928 | { |
| 3929 | const RecordType *record_type = cast<RecordType>(parent_qual_type.getTypePtr()); |
| 3930 | const RecordDecl *record_decl = record_type->getDecl(); |
| 3931 | assert(record_decl); |
| 3932 | const ASTRecordLayout &record_layout = ast->getASTRecordLayout(record_decl); |
| 3933 | uint32_t child_idx = 0; |
| 3934 | |
| 3935 | const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl); |
| 3936 | if (cxx_record_decl) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3937 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 3938 | // We might have base classes to print out first |
| 3939 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 3940 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 3941 | base_class != base_class_end; |
| 3942 | ++base_class) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3943 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 3944 | const CXXRecordDecl *base_class_decl = NULL; |
| 3945 | |
| 3946 | // Skip empty base classes |
| 3947 | if (omit_empty_base_classes) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3948 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 3949 | base_class_decl = cast<CXXRecordDecl>(base_class->getType()->getAs<RecordType>()->getDecl()); |
| 3950 | if (RecordHasFields(base_class_decl) == false) |
| 3951 | continue; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3952 | } |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 3953 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3954 | if (idx == child_idx) |
| 3955 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 3956 | if (base_class_decl == NULL) |
| 3957 | base_class_decl = cast<CXXRecordDecl>(base_class->getType()->getAs<RecordType>()->getDecl()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3958 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3959 | |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 3960 | if (base_class->isVirtual()) |
| 3961 | bit_offset = record_layout.getVBaseClassOffset(base_class_decl).getQuantity() * 8; |
| 3962 | else |
| 3963 | bit_offset = record_layout.getBaseClassOffset(base_class_decl).getQuantity() * 8; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3964 | |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 3965 | // Base classes should be a multiple of 8 bits in size |
| 3966 | child_byte_offset = bit_offset/8; |
| 3967 | |
| 3968 | child_name = ClangASTType::GetTypeNameForQualType(ast, base_class->getType()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3969 | |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 3970 | uint64_t clang_type_info_bit_size = ast->getTypeSize(base_class->getType()); |
| 3971 | |
| 3972 | // Base classes bit sizes should be a multiple of 8 bits in size |
| 3973 | assert (clang_type_info_bit_size % 8 == 0); |
| 3974 | child_byte_size = clang_type_info_bit_size / 8; |
| 3975 | child_is_base_class = true; |
| 3976 | return base_class->getType().getAsOpaquePtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3977 | } |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 3978 | // We don't increment the child index in the for loop since we might |
| 3979 | // be skipping empty base classes |
| 3980 | ++child_idx; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 3981 | } |
| 3982 | } |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 3983 | // Make sure index is in range... |
| 3984 | uint32_t field_idx = 0; |
| 3985 | RecordDecl::field_iterator field, field_end; |
| 3986 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); field != field_end; ++field, ++field_idx, ++child_idx) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 3987 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 3988 | if (idx == child_idx) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 3989 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 3990 | // Print the member type if requested |
| 3991 | // Print the member name and equal sign |
| 3992 | child_name.assign(field->getNameAsString().c_str()); |
| 3993 | |
| 3994 | // Figure out the type byte size (field_type_info.first) and |
| 3995 | // alignment (field_type_info.second) from the AST context. |
| 3996 | std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(field->getType()); |
| 3997 | assert(field_idx < record_layout.getFieldCount()); |
| 3998 | |
| 3999 | child_byte_size = field_type_info.first / 8; |
| 4000 | |
| 4001 | // Figure out the field offset within the current struct/union/class type |
| 4002 | bit_offset = record_layout.getFieldOffset (field_idx); |
| 4003 | child_byte_offset = bit_offset / 8; |
| 4004 | if (ClangASTContext::FieldIsBitfield (ast, *field, child_bitfield_bit_size)) |
| 4005 | child_bitfield_bit_offset = bit_offset % 8; |
| 4006 | |
| 4007 | return field->getType().getAsOpaquePtr(); |
| 4008 | } |
| 4009 | } |
| 4010 | } |
| 4011 | break; |
| 4012 | |
| 4013 | case clang::Type::ObjCObject: |
| 4014 | case clang::Type::ObjCInterface: |
| 4015 | if (idx_is_valid && GetCompleteQualType (ast, parent_qual_type)) |
| 4016 | { |
| 4017 | const ObjCObjectType *objc_class_type = dyn_cast<ObjCObjectType>(parent_qual_type.getTypePtr()); |
| 4018 | assert (objc_class_type); |
| 4019 | if (objc_class_type) |
| 4020 | { |
| 4021 | uint32_t child_idx = 0; |
| 4022 | ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 4023 | |
| 4024 | if (class_interface_decl) |
| 4025 | { |
| 4026 | |
| 4027 | const ASTRecordLayout &interface_layout = ast->getASTObjCInterfaceLayout(class_interface_decl); |
| 4028 | ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 4029 | if (superclass_interface_decl) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4030 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4031 | if (omit_empty_base_classes) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4032 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4033 | if (ClangASTContext::GetNumChildren(ast, ast->getObjCInterfaceType(superclass_interface_decl).getAsOpaquePtr(), omit_empty_base_classes) > 0) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4034 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4035 | if (idx == 0) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4036 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4037 | QualType ivar_qual_type(ast->getObjCInterfaceType(superclass_interface_decl)); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4038 | |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4039 | |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4040 | child_name.assign(superclass_interface_decl->getNameAsString().c_str()); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4041 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4042 | std::pair<uint64_t, unsigned> ivar_type_info = ast->getTypeInfo(ivar_qual_type.getTypePtr()); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4043 | |
| 4044 | child_byte_size = ivar_type_info.first / 8; |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4045 | child_byte_offset = 0; |
| 4046 | child_is_base_class = true; |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4047 | |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4048 | return ivar_qual_type.getAsOpaquePtr(); |
| 4049 | } |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4050 | |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4051 | ++child_idx; |
| 4052 | } |
| 4053 | } |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4054 | else |
| 4055 | ++child_idx; |
| 4056 | } |
| 4057 | |
| 4058 | const uint32_t superclass_idx = child_idx; |
| 4059 | |
| 4060 | if (idx < (child_idx + class_interface_decl->ivar_size())) |
| 4061 | { |
| 4062 | ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end(); |
| 4063 | |
| 4064 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos) |
| 4065 | { |
| 4066 | if (child_idx == idx) |
| 4067 | { |
| 4068 | ObjCIvarDecl* ivar_decl = *ivar_pos; |
| 4069 | |
| 4070 | QualType ivar_qual_type(ivar_decl->getType()); |
| 4071 | |
| 4072 | child_name.assign(ivar_decl->getNameAsString().c_str()); |
| 4073 | |
| 4074 | std::pair<uint64_t, unsigned> ivar_type_info = ast->getTypeInfo(ivar_qual_type.getTypePtr()); |
| 4075 | |
| 4076 | child_byte_size = ivar_type_info.first / 8; |
| 4077 | |
| 4078 | // Figure out the field offset within the current struct/union/class type |
| 4079 | // For ObjC objects, we can't trust the bit offset we get from the Clang AST, since |
| 4080 | // that doesn't account for the space taken up by unbacked properties, or from |
| 4081 | // the changing size of base classes that are newer than this class. |
| 4082 | // So if we have a process around that we can ask about this object, do so. |
| 4083 | child_byte_offset = LLDB_INVALID_IVAR_OFFSET; |
| 4084 | Process *process = NULL; |
| 4085 | if (exe_ctx) |
| 4086 | process = exe_ctx->GetProcessPtr(); |
| 4087 | if (process) |
| 4088 | { |
| 4089 | ObjCLanguageRuntime *objc_runtime = process->GetObjCLanguageRuntime(); |
| 4090 | if (objc_runtime != NULL) |
| 4091 | { |
| 4092 | ClangASTType parent_ast_type (ast, parent_qual_type.getAsOpaquePtr()); |
| 4093 | child_byte_offset = objc_runtime->GetByteOffsetForIvar (parent_ast_type, ivar_decl->getNameAsString().c_str()); |
| 4094 | } |
| 4095 | } |
| 4096 | |
| 4097 | // Setting this to UINT32_MAX to make sure we don't compute it twice... |
| 4098 | bit_offset = UINT32_MAX; |
| 4099 | |
| 4100 | if (child_byte_offset == LLDB_INVALID_IVAR_OFFSET) |
| 4101 | { |
| 4102 | bit_offset = interface_layout.getFieldOffset (child_idx - superclass_idx); |
| 4103 | child_byte_offset = bit_offset / 8; |
| 4104 | } |
| 4105 | |
| 4106 | // Note, the ObjC Ivar Byte offset is just that, it doesn't account for the bit offset |
| 4107 | // of a bitfield within its containing object. So regardless of where we get the byte |
| 4108 | // offset from, we still need to get the bit offset for bitfields from the layout. |
| 4109 | |
| 4110 | if (ClangASTContext::FieldIsBitfield (ast, ivar_decl, child_bitfield_bit_size)) |
| 4111 | { |
| 4112 | if (bit_offset == UINT32_MAX) |
| 4113 | bit_offset = interface_layout.getFieldOffset (child_idx - superclass_idx); |
| 4114 | |
| 4115 | child_bitfield_bit_offset = bit_offset % 8; |
| 4116 | } |
| 4117 | return ivar_qual_type.getAsOpaquePtr(); |
| 4118 | } |
| 4119 | ++child_idx; |
| 4120 | } |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4121 | } |
| 4122 | } |
| 4123 | } |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4124 | } |
| 4125 | break; |
| 4126 | |
| 4127 | case clang::Type::ObjCObjectPointer: |
| 4128 | if (idx_is_valid) |
| 4129 | { |
| 4130 | const ObjCObjectPointerType *pointer_type = cast<ObjCObjectPointerType>(parent_qual_type.getTypePtr()); |
| 4131 | QualType pointee_type = pointer_type->getPointeeType(); |
| 4132 | |
| 4133 | if (transparent_pointers && ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr())) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4134 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4135 | child_is_deref_of_parent = false; |
| 4136 | bool tmp_child_is_deref_of_parent = false; |
| 4137 | return GetChildClangTypeAtIndex (exe_ctx, |
| 4138 | ast, |
| 4139 | parent_name, |
| 4140 | pointer_type->getPointeeType().getAsOpaquePtr(), |
| 4141 | idx, |
| 4142 | transparent_pointers, |
| 4143 | omit_empty_base_classes, |
| 4144 | ignore_array_bounds, |
| 4145 | child_name, |
| 4146 | child_byte_size, |
| 4147 | child_byte_offset, |
| 4148 | child_bitfield_bit_size, |
| 4149 | child_bitfield_bit_offset, |
| 4150 | child_is_base_class, |
| 4151 | tmp_child_is_deref_of_parent); |
| 4152 | } |
| 4153 | else |
| 4154 | { |
| 4155 | child_is_deref_of_parent = true; |
| 4156 | if (parent_name) |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4157 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4158 | child_name.assign(1, '*'); |
| 4159 | child_name += parent_name; |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4160 | } |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4161 | |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4162 | // We have a pointer to an simple type |
| 4163 | if (idx == 0 && GetCompleteQualType(ast, pointee_type)) |
| 4164 | { |
| 4165 | std::pair<uint64_t, unsigned> clang_type_info = ast->getTypeInfo(pointee_type); |
| 4166 | assert(clang_type_info.first % 8 == 0); |
| 4167 | child_byte_size = clang_type_info.first / 8; |
| 4168 | child_byte_offset = 0; |
| 4169 | return pointee_type.getAsOpaquePtr(); |
Greg Clayton | b0b9fe6 | 2010-08-03 00:35:52 +0000 | [diff] [blame] | 4170 | } |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4171 | } |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4172 | } |
| 4173 | break; |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4174 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 4175 | case clang::Type::ConstantArray: |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4176 | case clang::Type::IncompleteArray: |
| 4177 | if (ignore_array_bounds || idx_is_valid) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4178 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4179 | const ArrayType *array = cast<ArrayType>(parent_qual_type.getTypePtr()); |
| 4180 | if (array) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4181 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4182 | if (GetCompleteQualType (ast, array->getElementType())) |
| 4183 | { |
| 4184 | std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType()); |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4185 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4186 | char element_name[64]; |
Greg Clayton | c7bece56 | 2013-01-25 18:06:21 +0000 | [diff] [blame] | 4187 | ::snprintf (element_name, sizeof (element_name), "[%zu]", idx); |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4188 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4189 | child_name.assign(element_name); |
| 4190 | assert(field_type_info.first % 8 == 0); |
| 4191 | child_byte_size = field_type_info.first / 8; |
Greg Clayton | daf515f | 2011-07-09 20:12:33 +0000 | [diff] [blame] | 4192 | child_byte_offset = (int32_t)idx * (int32_t)child_byte_size; |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4193 | return array->getElementType().getAsOpaquePtr(); |
| 4194 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4195 | } |
| 4196 | } |
| 4197 | break; |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4198 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4199 | |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4200 | case clang::Type::Pointer: |
| 4201 | if (idx_is_valid) |
| 4202 | { |
| 4203 | const PointerType *pointer_type = cast<PointerType>(parent_qual_type.getTypePtr()); |
| 4204 | QualType pointee_type = pointer_type->getPointeeType(); |
| 4205 | |
| 4206 | // Don't dereference "void *" pointers |
| 4207 | if (pointee_type->isVoidType()) |
| 4208 | return NULL; |
| 4209 | |
| 4210 | if (transparent_pointers && ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr())) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4211 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4212 | child_is_deref_of_parent = false; |
| 4213 | bool tmp_child_is_deref_of_parent = false; |
| 4214 | return GetChildClangTypeAtIndex (exe_ctx, |
| 4215 | ast, |
| 4216 | parent_name, |
| 4217 | pointer_type->getPointeeType().getAsOpaquePtr(), |
| 4218 | idx, |
| 4219 | transparent_pointers, |
| 4220 | omit_empty_base_classes, |
| 4221 | ignore_array_bounds, |
| 4222 | child_name, |
| 4223 | child_byte_size, |
| 4224 | child_byte_offset, |
| 4225 | child_bitfield_bit_size, |
| 4226 | child_bitfield_bit_offset, |
| 4227 | child_is_base_class, |
| 4228 | tmp_child_is_deref_of_parent); |
| 4229 | } |
| 4230 | else |
| 4231 | { |
| 4232 | child_is_deref_of_parent = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4233 | |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4234 | if (parent_name) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4235 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4236 | child_name.assign(1, '*'); |
| 4237 | child_name += parent_name; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4238 | } |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4239 | |
| 4240 | // We have a pointer to an simple type |
| 4241 | if (idx == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4242 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4243 | std::pair<uint64_t, unsigned> clang_type_info = ast->getTypeInfo(pointee_type); |
| 4244 | assert(clang_type_info.first % 8 == 0); |
| 4245 | child_byte_size = clang_type_info.first / 8; |
| 4246 | child_byte_offset = 0; |
| 4247 | return pointee_type.getAsOpaquePtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4248 | } |
| 4249 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4250 | } |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 4251 | break; |
| 4252 | |
| 4253 | case clang::Type::LValueReference: |
| 4254 | case clang::Type::RValueReference: |
| 4255 | if (idx_is_valid) |
| 4256 | { |
| 4257 | const ReferenceType *reference_type = cast<ReferenceType>(parent_qual_type.getTypePtr()); |
| 4258 | QualType pointee_type(reference_type->getPointeeType()); |
| 4259 | clang_type_t pointee_clang_type = pointee_type.getAsOpaquePtr(); |
| 4260 | if (transparent_pointers && ClangASTContext::IsAggregateType (pointee_clang_type)) |
| 4261 | { |
| 4262 | child_is_deref_of_parent = false; |
| 4263 | bool tmp_child_is_deref_of_parent = false; |
| 4264 | return GetChildClangTypeAtIndex (exe_ctx, |
| 4265 | ast, |
| 4266 | parent_name, |
| 4267 | pointee_clang_type, |
| 4268 | idx, |
| 4269 | transparent_pointers, |
| 4270 | omit_empty_base_classes, |
| 4271 | ignore_array_bounds, |
| 4272 | child_name, |
| 4273 | child_byte_size, |
| 4274 | child_byte_offset, |
| 4275 | child_bitfield_bit_size, |
| 4276 | child_bitfield_bit_offset, |
| 4277 | child_is_base_class, |
| 4278 | tmp_child_is_deref_of_parent); |
| 4279 | } |
| 4280 | else |
| 4281 | { |
| 4282 | if (parent_name) |
| 4283 | { |
| 4284 | child_name.assign(1, '&'); |
| 4285 | child_name += parent_name; |
| 4286 | } |
| 4287 | |
| 4288 | // We have a pointer to an simple type |
| 4289 | if (idx == 0) |
| 4290 | { |
| 4291 | std::pair<uint64_t, unsigned> clang_type_info = ast->getTypeInfo(pointee_type); |
| 4292 | assert(clang_type_info.first % 8 == 0); |
| 4293 | child_byte_size = clang_type_info.first / 8; |
| 4294 | child_byte_offset = 0; |
| 4295 | return pointee_type.getAsOpaquePtr(); |
| 4296 | } |
| 4297 | } |
| 4298 | } |
| 4299 | break; |
| 4300 | |
| 4301 | case clang::Type::Typedef: |
| 4302 | return GetChildClangTypeAtIndex (exe_ctx, |
| 4303 | ast, |
| 4304 | parent_name, |
| 4305 | cast<TypedefType>(parent_qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), |
| 4306 | idx, |
| 4307 | transparent_pointers, |
| 4308 | omit_empty_base_classes, |
| 4309 | ignore_array_bounds, |
| 4310 | child_name, |
| 4311 | child_byte_size, |
| 4312 | child_byte_offset, |
| 4313 | child_bitfield_bit_size, |
| 4314 | child_bitfield_bit_offset, |
| 4315 | child_is_base_class, |
| 4316 | child_is_deref_of_parent); |
| 4317 | break; |
| 4318 | |
| 4319 | case clang::Type::Elaborated: |
| 4320 | return GetChildClangTypeAtIndex (exe_ctx, |
| 4321 | ast, |
| 4322 | parent_name, |
| 4323 | cast<ElaboratedType>(parent_qual_type)->getNamedType().getAsOpaquePtr(), |
| 4324 | idx, |
| 4325 | transparent_pointers, |
| 4326 | omit_empty_base_classes, |
| 4327 | ignore_array_bounds, |
| 4328 | child_name, |
| 4329 | child_byte_size, |
| 4330 | child_byte_offset, |
| 4331 | child_bitfield_bit_size, |
| 4332 | child_bitfield_bit_offset, |
| 4333 | child_is_base_class, |
| 4334 | child_is_deref_of_parent); |
| 4335 | |
| 4336 | default: |
| 4337 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4338 | } |
Greg Clayton | 19503a2 | 2010-07-23 15:37:46 +0000 | [diff] [blame] | 4339 | return NULL; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4340 | } |
| 4341 | |
| 4342 | static inline bool |
| 4343 | BaseSpecifierIsEmpty (const CXXBaseSpecifier *b) |
| 4344 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4345 | return ClangASTContext::RecordHasFields(b->getType()->getAsCXXRecordDecl()) == false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4346 | } |
| 4347 | |
| 4348 | static uint32_t |
| 4349 | GetNumBaseClasses (const CXXRecordDecl *cxx_record_decl, bool omit_empty_base_classes) |
| 4350 | { |
| 4351 | uint32_t num_bases = 0; |
| 4352 | if (cxx_record_decl) |
| 4353 | { |
| 4354 | if (omit_empty_base_classes) |
| 4355 | { |
| 4356 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 4357 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 4358 | base_class != base_class_end; |
| 4359 | ++base_class) |
| 4360 | { |
| 4361 | // Skip empty base classes |
| 4362 | if (omit_empty_base_classes) |
| 4363 | { |
| 4364 | if (BaseSpecifierIsEmpty (base_class)) |
| 4365 | continue; |
| 4366 | } |
| 4367 | ++num_bases; |
| 4368 | } |
| 4369 | } |
| 4370 | else |
| 4371 | num_bases = cxx_record_decl->getNumBases(); |
| 4372 | } |
| 4373 | return num_bases; |
| 4374 | } |
| 4375 | |
| 4376 | |
| 4377 | static uint32_t |
| 4378 | GetIndexForRecordBase |
| 4379 | ( |
| 4380 | const RecordDecl *record_decl, |
| 4381 | const CXXBaseSpecifier *base_spec, |
| 4382 | bool omit_empty_base_classes |
| 4383 | ) |
| 4384 | { |
| 4385 | uint32_t child_idx = 0; |
| 4386 | |
| 4387 | const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl); |
| 4388 | |
| 4389 | // const char *super_name = record_decl->getNameAsCString(); |
| 4390 | // const char *base_name = base_spec->getType()->getAs<RecordType>()->getDecl()->getNameAsCString(); |
| 4391 | // printf ("GetIndexForRecordChild (%s, %s)\n", super_name, base_name); |
| 4392 | // |
| 4393 | if (cxx_record_decl) |
| 4394 | { |
| 4395 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 4396 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 4397 | base_class != base_class_end; |
| 4398 | ++base_class) |
| 4399 | { |
| 4400 | if (omit_empty_base_classes) |
| 4401 | { |
| 4402 | if (BaseSpecifierIsEmpty (base_class)) |
| 4403 | continue; |
| 4404 | } |
| 4405 | |
| 4406 | // printf ("GetIndexForRecordChild (%s, %s) base[%u] = %s\n", super_name, base_name, |
| 4407 | // child_idx, |
| 4408 | // base_class->getType()->getAs<RecordType>()->getDecl()->getNameAsCString()); |
| 4409 | // |
| 4410 | // |
| 4411 | if (base_class == base_spec) |
| 4412 | return child_idx; |
| 4413 | ++child_idx; |
| 4414 | } |
| 4415 | } |
| 4416 | |
| 4417 | return UINT32_MAX; |
| 4418 | } |
| 4419 | |
| 4420 | |
| 4421 | static uint32_t |
| 4422 | GetIndexForRecordChild |
| 4423 | ( |
| 4424 | const RecordDecl *record_decl, |
| 4425 | NamedDecl *canonical_decl, |
| 4426 | bool omit_empty_base_classes |
| 4427 | ) |
| 4428 | { |
| 4429 | uint32_t child_idx = GetNumBaseClasses (dyn_cast<CXXRecordDecl>(record_decl), omit_empty_base_classes); |
| 4430 | |
| 4431 | // const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl); |
| 4432 | // |
| 4433 | //// printf ("GetIndexForRecordChild (%s, %s)\n", record_decl->getNameAsCString(), canonical_decl->getNameAsCString()); |
| 4434 | // if (cxx_record_decl) |
| 4435 | // { |
| 4436 | // CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 4437 | // for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 4438 | // base_class != base_class_end; |
| 4439 | // ++base_class) |
| 4440 | // { |
| 4441 | // if (omit_empty_base_classes) |
| 4442 | // { |
| 4443 | // if (BaseSpecifierIsEmpty (base_class)) |
| 4444 | // continue; |
| 4445 | // } |
| 4446 | // |
| 4447 | //// printf ("GetIndexForRecordChild (%s, %s) base[%u] = %s\n", |
| 4448 | //// record_decl->getNameAsCString(), |
| 4449 | //// canonical_decl->getNameAsCString(), |
| 4450 | //// child_idx, |
| 4451 | //// base_class->getType()->getAs<RecordType>()->getDecl()->getNameAsCString()); |
| 4452 | // |
| 4453 | // |
| 4454 | // CXXRecordDecl *curr_base_class_decl = cast<CXXRecordDecl>(base_class->getType()->getAs<RecordType>()->getDecl()); |
| 4455 | // if (curr_base_class_decl == canonical_decl) |
| 4456 | // { |
| 4457 | // return child_idx; |
| 4458 | // } |
| 4459 | // ++child_idx; |
| 4460 | // } |
| 4461 | // } |
| 4462 | // |
| 4463 | // const uint32_t num_bases = child_idx; |
| 4464 | RecordDecl::field_iterator field, field_end; |
| 4465 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); |
| 4466 | field != field_end; |
| 4467 | ++field, ++child_idx) |
| 4468 | { |
| 4469 | // printf ("GetIndexForRecordChild (%s, %s) field[%u] = %s\n", |
| 4470 | // record_decl->getNameAsCString(), |
| 4471 | // canonical_decl->getNameAsCString(), |
| 4472 | // child_idx - num_bases, |
| 4473 | // field->getNameAsCString()); |
| 4474 | |
| 4475 | if (field->getCanonicalDecl() == canonical_decl) |
| 4476 | return child_idx; |
| 4477 | } |
| 4478 | |
| 4479 | return UINT32_MAX; |
| 4480 | } |
| 4481 | |
| 4482 | // Look for a child member (doesn't include base classes, but it does include |
| 4483 | // their members) in the type hierarchy. Returns an index path into "clang_type" |
| 4484 | // on how to reach the appropriate member. |
| 4485 | // |
| 4486 | // class A |
| 4487 | // { |
| 4488 | // public: |
| 4489 | // int m_a; |
| 4490 | // int m_b; |
| 4491 | // }; |
| 4492 | // |
| 4493 | // class B |
| 4494 | // { |
| 4495 | // }; |
| 4496 | // |
| 4497 | // class C : |
| 4498 | // public B, |
| 4499 | // public A |
| 4500 | // { |
| 4501 | // }; |
| 4502 | // |
| 4503 | // If we have a clang type that describes "class C", and we wanted to looked |
| 4504 | // "m_b" in it: |
| 4505 | // |
| 4506 | // With omit_empty_base_classes == false we would get an integer array back with: |
| 4507 | // { 1, 1 } |
| 4508 | // The first index 1 is the child index for "class A" within class C |
| 4509 | // The second index 1 is the child index for "m_b" within class A |
| 4510 | // |
| 4511 | // With omit_empty_base_classes == true we would get an integer array back with: |
| 4512 | // { 0, 1 } |
| 4513 | // The first index 0 is the child index for "class A" within class C (since class B doesn't have any members it doesn't count) |
| 4514 | // The second index 1 is the child index for "m_b" within class A |
| 4515 | |
| 4516 | size_t |
| 4517 | ClangASTContext::GetIndexOfChildMemberWithName |
| 4518 | ( |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4519 | ASTContext *ast, |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4520 | clang_type_t clang_type, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4521 | const char *name, |
| 4522 | bool omit_empty_base_classes, |
| 4523 | std::vector<uint32_t>& child_indexes |
| 4524 | ) |
| 4525 | { |
| 4526 | if (clang_type && name && name[0]) |
| 4527 | { |
| 4528 | QualType qual_type(QualType::getFromOpaquePtr(clang_type)); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 4529 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 4530 | switch (type_class) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4531 | { |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 4532 | case clang::Type::Record: |
Greg Clayton | c432c19 | 2011-01-20 04:18:48 +0000 | [diff] [blame] | 4533 | if (GetCompleteQualType (ast, qual_type)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4534 | { |
| 4535 | const RecordType *record_type = cast<RecordType>(qual_type.getTypePtr()); |
| 4536 | const RecordDecl *record_decl = record_type->getDecl(); |
| 4537 | |
| 4538 | assert(record_decl); |
| 4539 | uint32_t child_idx = 0; |
| 4540 | |
| 4541 | const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl); |
| 4542 | |
| 4543 | // Try and find a field that matches NAME |
| 4544 | RecordDecl::field_iterator field, field_end; |
| 4545 | StringRef name_sref(name); |
| 4546 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); |
| 4547 | field != field_end; |
| 4548 | ++field, ++child_idx) |
| 4549 | { |
| 4550 | if (field->getName().equals (name_sref)) |
| 4551 | { |
| 4552 | // We have to add on the number of base classes to this index! |
| 4553 | child_indexes.push_back (child_idx + GetNumBaseClasses (cxx_record_decl, omit_empty_base_classes)); |
| 4554 | return child_indexes.size(); |
| 4555 | } |
| 4556 | } |
| 4557 | |
| 4558 | if (cxx_record_decl) |
| 4559 | { |
| 4560 | const RecordDecl *parent_record_decl = cxx_record_decl; |
| 4561 | |
| 4562 | //printf ("parent = %s\n", parent_record_decl->getNameAsCString()); |
| 4563 | |
| 4564 | //const Decl *root_cdecl = cxx_record_decl->getCanonicalDecl(); |
| 4565 | // Didn't find things easily, lets let clang do its thang... |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 4566 | IdentifierInfo & ident_ref = ast->Idents.get(name_sref); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4567 | DeclarationName decl_name(&ident_ref); |
| 4568 | |
| 4569 | CXXBasePaths paths; |
| 4570 | if (cxx_record_decl->lookupInBases(CXXRecordDecl::FindOrdinaryMember, |
| 4571 | decl_name.getAsOpaquePtr(), |
| 4572 | paths)) |
| 4573 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4574 | CXXBasePaths::const_paths_iterator path, path_end = paths.end(); |
| 4575 | for (path = paths.begin(); path != path_end; ++path) |
| 4576 | { |
| 4577 | const size_t num_path_elements = path->size(); |
| 4578 | for (size_t e=0; e<num_path_elements; ++e) |
| 4579 | { |
| 4580 | CXXBasePathElement elem = (*path)[e]; |
| 4581 | |
| 4582 | child_idx = GetIndexForRecordBase (parent_record_decl, elem.Base, omit_empty_base_classes); |
| 4583 | if (child_idx == UINT32_MAX) |
| 4584 | { |
| 4585 | child_indexes.clear(); |
| 4586 | return 0; |
| 4587 | } |
| 4588 | else |
| 4589 | { |
| 4590 | child_indexes.push_back (child_idx); |
| 4591 | parent_record_decl = cast<RecordDecl>(elem.Base->getType()->getAs<RecordType>()->getDecl()); |
| 4592 | } |
| 4593 | } |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 4594 | for (NamedDecl *path_decl : path->Decls) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4595 | { |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 4596 | child_idx = GetIndexForRecordChild (parent_record_decl, path_decl, omit_empty_base_classes); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4597 | if (child_idx == UINT32_MAX) |
| 4598 | { |
| 4599 | child_indexes.clear(); |
| 4600 | return 0; |
| 4601 | } |
| 4602 | else |
| 4603 | { |
| 4604 | child_indexes.push_back (child_idx); |
| 4605 | } |
| 4606 | } |
| 4607 | } |
| 4608 | return child_indexes.size(); |
| 4609 | } |
| 4610 | } |
| 4611 | |
| 4612 | } |
| 4613 | break; |
| 4614 | |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4615 | case clang::Type::ObjCObject: |
| 4616 | case clang::Type::ObjCInterface: |
Greg Clayton | c432c19 | 2011-01-20 04:18:48 +0000 | [diff] [blame] | 4617 | if (GetCompleteQualType (ast, qual_type)) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4618 | { |
| 4619 | StringRef name_sref(name); |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 4620 | const ObjCObjectType *objc_class_type = dyn_cast<ObjCObjectType>(qual_type.getTypePtr()); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4621 | assert (objc_class_type); |
| 4622 | if (objc_class_type) |
| 4623 | { |
| 4624 | uint32_t child_idx = 0; |
| 4625 | ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 4626 | |
| 4627 | if (class_interface_decl) |
| 4628 | { |
| 4629 | ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end(); |
| 4630 | ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 4631 | |
Greg Clayton | 6ba7815 | 2010-09-18 02:11:07 +0000 | [diff] [blame] | 4632 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++child_idx) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4633 | { |
| 4634 | const ObjCIvarDecl* ivar_decl = *ivar_pos; |
| 4635 | |
| 4636 | if (ivar_decl->getName().equals (name_sref)) |
| 4637 | { |
| 4638 | if ((!omit_empty_base_classes && superclass_interface_decl) || |
| 4639 | ( omit_empty_base_classes && ObjCDeclHasIVars (superclass_interface_decl, true))) |
| 4640 | ++child_idx; |
| 4641 | |
| 4642 | child_indexes.push_back (child_idx); |
| 4643 | return child_indexes.size(); |
| 4644 | } |
| 4645 | } |
| 4646 | |
| 4647 | if (superclass_interface_decl) |
| 4648 | { |
| 4649 | // The super class index is always zero for ObjC classes, |
| 4650 | // so we push it onto the child indexes in case we find |
| 4651 | // an ivar in our superclass... |
| 4652 | child_indexes.push_back (0); |
| 4653 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4654 | if (GetIndexOfChildMemberWithName (ast, |
| 4655 | ast->getObjCInterfaceType(superclass_interface_decl).getAsOpaquePtr(), |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4656 | name, |
| 4657 | omit_empty_base_classes, |
| 4658 | child_indexes)) |
| 4659 | { |
| 4660 | // We did find an ivar in a superclass so just |
| 4661 | // return the results! |
| 4662 | return child_indexes.size(); |
| 4663 | } |
| 4664 | |
| 4665 | // We didn't find an ivar matching "name" in our |
| 4666 | // superclass, pop the superclass zero index that |
| 4667 | // we pushed on above. |
| 4668 | child_indexes.pop_back(); |
| 4669 | } |
| 4670 | } |
| 4671 | } |
| 4672 | } |
| 4673 | break; |
| 4674 | |
| 4675 | case clang::Type::ObjCObjectPointer: |
| 4676 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4677 | return GetIndexOfChildMemberWithName (ast, |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4678 | cast<ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType().getAsOpaquePtr(), |
| 4679 | name, |
| 4680 | omit_empty_base_classes, |
| 4681 | child_indexes); |
| 4682 | } |
| 4683 | break; |
| 4684 | |
| 4685 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 4686 | case clang::Type::ConstantArray: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4687 | { |
| 4688 | // const ConstantArrayType *array = cast<ConstantArrayType>(parent_qual_type.getTypePtr()); |
| 4689 | // const uint64_t element_count = array->getSize().getLimitedValue(); |
| 4690 | // |
| 4691 | // if (idx < element_count) |
| 4692 | // { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4693 | // std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4694 | // |
| 4695 | // char element_name[32]; |
| 4696 | // ::snprintf (element_name, sizeof (element_name), "%s[%u]", parent_name ? parent_name : "", idx); |
| 4697 | // |
| 4698 | // child_name.assign(element_name); |
| 4699 | // assert(field_type_info.first % 8 == 0); |
| 4700 | // child_byte_size = field_type_info.first / 8; |
| 4701 | // child_byte_offset = idx * child_byte_size; |
| 4702 | // return array->getElementType().getAsOpaquePtr(); |
| 4703 | // } |
| 4704 | } |
| 4705 | break; |
| 4706 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 4707 | // case clang::Type::MemberPointerType: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4708 | // { |
| 4709 | // MemberPointerType *mem_ptr_type = cast<MemberPointerType>(qual_type.getTypePtr()); |
| 4710 | // QualType pointee_type = mem_ptr_type->getPointeeType(); |
| 4711 | // |
| 4712 | // if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr())) |
| 4713 | // { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4714 | // return GetIndexOfChildWithName (ast, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4715 | // mem_ptr_type->getPointeeType().getAsOpaquePtr(), |
| 4716 | // name); |
| 4717 | // } |
| 4718 | // } |
| 4719 | // break; |
| 4720 | // |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 4721 | case clang::Type::LValueReference: |
| 4722 | case clang::Type::RValueReference: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4723 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 4724 | const ReferenceType *reference_type = cast<ReferenceType>(qual_type.getTypePtr()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4725 | QualType pointee_type = reference_type->getPointeeType(); |
| 4726 | |
| 4727 | if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr())) |
| 4728 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4729 | return GetIndexOfChildMemberWithName (ast, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4730 | reference_type->getPointeeType().getAsOpaquePtr(), |
| 4731 | name, |
| 4732 | omit_empty_base_classes, |
| 4733 | child_indexes); |
| 4734 | } |
| 4735 | } |
| 4736 | break; |
| 4737 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 4738 | case clang::Type::Pointer: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4739 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 4740 | const PointerType *pointer_type = cast<PointerType>(qual_type.getTypePtr()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4741 | QualType pointee_type = pointer_type->getPointeeType(); |
| 4742 | |
| 4743 | if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr())) |
| 4744 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4745 | return GetIndexOfChildMemberWithName (ast, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4746 | pointer_type->getPointeeType().getAsOpaquePtr(), |
| 4747 | name, |
| 4748 | omit_empty_base_classes, |
| 4749 | child_indexes); |
| 4750 | } |
| 4751 | else |
| 4752 | { |
| 4753 | // if (parent_name) |
| 4754 | // { |
| 4755 | // child_name.assign(1, '*'); |
| 4756 | // child_name += parent_name; |
| 4757 | // } |
| 4758 | // |
| 4759 | // // We have a pointer to an simple type |
| 4760 | // if (idx == 0) |
| 4761 | // { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4762 | // std::pair<uint64_t, unsigned> clang_type_info = ast->getTypeInfo(pointee_type); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4763 | // assert(clang_type_info.first % 8 == 0); |
| 4764 | // child_byte_size = clang_type_info.first / 8; |
| 4765 | // child_byte_offset = 0; |
| 4766 | // return pointee_type.getAsOpaquePtr(); |
| 4767 | // } |
| 4768 | } |
| 4769 | } |
| 4770 | break; |
| 4771 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 4772 | case clang::Type::Typedef: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4773 | return GetIndexOfChildMemberWithName (ast, |
Sean Callanan | 4811447 | 2010-12-13 01:26:27 +0000 | [diff] [blame] | 4774 | cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4775 | name, |
| 4776 | omit_empty_base_classes, |
| 4777 | child_indexes); |
| 4778 | |
Greg Clayton | 4b63a5c | 2013-01-04 18:10:18 +0000 | [diff] [blame] | 4779 | case clang::Type::Elaborated: |
| 4780 | return GetIndexOfChildMemberWithName (ast, |
| 4781 | cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), |
| 4782 | name, |
| 4783 | omit_empty_base_classes, |
| 4784 | child_indexes); |
| 4785 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4786 | default: |
| 4787 | break; |
| 4788 | } |
| 4789 | } |
| 4790 | return 0; |
| 4791 | } |
| 4792 | |
| 4793 | |
| 4794 | // Get the index of the child of "clang_type" whose name matches. This function |
| 4795 | // doesn't descend into the children, but only looks one level deep and name |
| 4796 | // matches can include base class names. |
| 4797 | |
| 4798 | uint32_t |
| 4799 | ClangASTContext::GetIndexOfChildWithName |
| 4800 | ( |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4801 | ASTContext *ast, |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 4802 | clang_type_t clang_type, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4803 | const char *name, |
| 4804 | bool omit_empty_base_classes |
| 4805 | ) |
| 4806 | { |
| 4807 | if (clang_type && name && name[0]) |
| 4808 | { |
| 4809 | QualType qual_type(QualType::getFromOpaquePtr(clang_type)); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4810 | |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 4811 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4812 | |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 4813 | switch (type_class) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4814 | { |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 4815 | case clang::Type::Record: |
Greg Clayton | c432c19 | 2011-01-20 04:18:48 +0000 | [diff] [blame] | 4816 | if (GetCompleteQualType (ast, qual_type)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4817 | { |
| 4818 | const RecordType *record_type = cast<RecordType>(qual_type.getTypePtr()); |
| 4819 | const RecordDecl *record_decl = record_type->getDecl(); |
| 4820 | |
| 4821 | assert(record_decl); |
| 4822 | uint32_t child_idx = 0; |
| 4823 | |
| 4824 | const CXXRecordDecl *cxx_record_decl = dyn_cast<CXXRecordDecl>(record_decl); |
| 4825 | |
| 4826 | if (cxx_record_decl) |
| 4827 | { |
| 4828 | CXXRecordDecl::base_class_const_iterator base_class, base_class_end; |
| 4829 | for (base_class = cxx_record_decl->bases_begin(), base_class_end = cxx_record_decl->bases_end(); |
| 4830 | base_class != base_class_end; |
| 4831 | ++base_class) |
| 4832 | { |
| 4833 | // Skip empty base classes |
| 4834 | CXXRecordDecl *base_class_decl = cast<CXXRecordDecl>(base_class->getType()->getAs<RecordType>()->getDecl()); |
| 4835 | if (omit_empty_base_classes && RecordHasFields(base_class_decl) == false) |
| 4836 | continue; |
| 4837 | |
Greg Clayton | 84db910 | 2012-03-26 23:03:23 +0000 | [diff] [blame] | 4838 | std::string base_class_type_name (ClangASTType::GetTypeNameForQualType(ast, base_class->getType())); |
Greg Clayton | e305594 | 2011-06-30 02:28:26 +0000 | [diff] [blame] | 4839 | if (base_class_type_name.compare (name) == 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4840 | return child_idx; |
| 4841 | ++child_idx; |
| 4842 | } |
| 4843 | } |
| 4844 | |
| 4845 | // Try and find a field that matches NAME |
| 4846 | RecordDecl::field_iterator field, field_end; |
| 4847 | StringRef name_sref(name); |
| 4848 | for (field = record_decl->field_begin(), field_end = record_decl->field_end(); |
| 4849 | field != field_end; |
| 4850 | ++field, ++child_idx) |
| 4851 | { |
| 4852 | if (field->getName().equals (name_sref)) |
| 4853 | return child_idx; |
| 4854 | } |
| 4855 | |
| 4856 | } |
| 4857 | break; |
| 4858 | |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4859 | case clang::Type::ObjCObject: |
| 4860 | case clang::Type::ObjCInterface: |
Greg Clayton | c432c19 | 2011-01-20 04:18:48 +0000 | [diff] [blame] | 4861 | if (GetCompleteQualType (ast, qual_type)) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4862 | { |
| 4863 | StringRef name_sref(name); |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 4864 | const ObjCObjectType *objc_class_type = dyn_cast<ObjCObjectType>(qual_type.getTypePtr()); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4865 | assert (objc_class_type); |
| 4866 | if (objc_class_type) |
| 4867 | { |
| 4868 | uint32_t child_idx = 0; |
| 4869 | ObjCInterfaceDecl *class_interface_decl = objc_class_type->getInterface(); |
| 4870 | |
| 4871 | if (class_interface_decl) |
| 4872 | { |
| 4873 | ObjCInterfaceDecl::ivar_iterator ivar_pos, ivar_end = class_interface_decl->ivar_end(); |
| 4874 | ObjCInterfaceDecl *superclass_interface_decl = class_interface_decl->getSuperClass(); |
| 4875 | |
Jim Ingham | 2f355a7 | 2012-10-04 22:22:16 +0000 | [diff] [blame] | 4876 | for (ivar_pos = class_interface_decl->ivar_begin(); ivar_pos != ivar_end; ++ivar_pos, ++child_idx) |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4877 | { |
| 4878 | const ObjCIvarDecl* ivar_decl = *ivar_pos; |
| 4879 | |
| 4880 | if (ivar_decl->getName().equals (name_sref)) |
| 4881 | { |
| 4882 | if ((!omit_empty_base_classes && superclass_interface_decl) || |
| 4883 | ( omit_empty_base_classes && ObjCDeclHasIVars (superclass_interface_decl, true))) |
| 4884 | ++child_idx; |
| 4885 | |
| 4886 | return child_idx; |
| 4887 | } |
| 4888 | } |
| 4889 | |
| 4890 | if (superclass_interface_decl) |
| 4891 | { |
| 4892 | if (superclass_interface_decl->getName().equals (name_sref)) |
| 4893 | return 0; |
| 4894 | } |
| 4895 | } |
| 4896 | } |
| 4897 | } |
| 4898 | break; |
| 4899 | |
| 4900 | case clang::Type::ObjCObjectPointer: |
| 4901 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4902 | return GetIndexOfChildWithName (ast, |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 4903 | cast<ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType().getAsOpaquePtr(), |
| 4904 | name, |
| 4905 | omit_empty_base_classes); |
| 4906 | } |
| 4907 | break; |
| 4908 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 4909 | case clang::Type::ConstantArray: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4910 | { |
| 4911 | // const ConstantArrayType *array = cast<ConstantArrayType>(parent_qual_type.getTypePtr()); |
| 4912 | // const uint64_t element_count = array->getSize().getLimitedValue(); |
| 4913 | // |
| 4914 | // if (idx < element_count) |
| 4915 | // { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4916 | // std::pair<uint64_t, unsigned> field_type_info = ast->getTypeInfo(array->getElementType()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4917 | // |
| 4918 | // char element_name[32]; |
| 4919 | // ::snprintf (element_name, sizeof (element_name), "%s[%u]", parent_name ? parent_name : "", idx); |
| 4920 | // |
| 4921 | // child_name.assign(element_name); |
| 4922 | // assert(field_type_info.first % 8 == 0); |
| 4923 | // child_byte_size = field_type_info.first / 8; |
| 4924 | // child_byte_offset = idx * child_byte_size; |
| 4925 | // return array->getElementType().getAsOpaquePtr(); |
| 4926 | // } |
| 4927 | } |
| 4928 | break; |
| 4929 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 4930 | // case clang::Type::MemberPointerType: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4931 | // { |
| 4932 | // MemberPointerType *mem_ptr_type = cast<MemberPointerType>(qual_type.getTypePtr()); |
| 4933 | // QualType pointee_type = mem_ptr_type->getPointeeType(); |
| 4934 | // |
| 4935 | // if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr())) |
| 4936 | // { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4937 | // return GetIndexOfChildWithName (ast, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4938 | // mem_ptr_type->getPointeeType().getAsOpaquePtr(), |
| 4939 | // name); |
| 4940 | // } |
| 4941 | // } |
| 4942 | // break; |
| 4943 | // |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 4944 | case clang::Type::LValueReference: |
| 4945 | case clang::Type::RValueReference: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4946 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 4947 | const ReferenceType *reference_type = cast<ReferenceType>(qual_type.getTypePtr()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4948 | QualType pointee_type = reference_type->getPointeeType(); |
| 4949 | |
| 4950 | if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr())) |
| 4951 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4952 | return GetIndexOfChildWithName (ast, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4953 | reference_type->getPointeeType().getAsOpaquePtr(), |
| 4954 | name, |
| 4955 | omit_empty_base_classes); |
| 4956 | } |
| 4957 | } |
| 4958 | break; |
| 4959 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 4960 | case clang::Type::Pointer: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4961 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 4962 | const PointerType *pointer_type = cast<PointerType>(qual_type.getTypePtr()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4963 | QualType pointee_type = pointer_type->getPointeeType(); |
| 4964 | |
| 4965 | if (ClangASTContext::IsAggregateType (pointee_type.getAsOpaquePtr())) |
| 4966 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4967 | return GetIndexOfChildWithName (ast, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4968 | pointer_type->getPointeeType().getAsOpaquePtr(), |
| 4969 | name, |
| 4970 | omit_empty_base_classes); |
| 4971 | } |
| 4972 | else |
| 4973 | { |
| 4974 | // if (parent_name) |
| 4975 | // { |
| 4976 | // child_name.assign(1, '*'); |
| 4977 | // child_name += parent_name; |
| 4978 | // } |
| 4979 | // |
| 4980 | // // We have a pointer to an simple type |
| 4981 | // if (idx == 0) |
| 4982 | // { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 4983 | // std::pair<uint64_t, unsigned> clang_type_info = ast->getTypeInfo(pointee_type); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 4984 | // assert(clang_type_info.first % 8 == 0); |
| 4985 | // child_byte_size = clang_type_info.first / 8; |
| 4986 | // child_byte_offset = 0; |
| 4987 | // return pointee_type.getAsOpaquePtr(); |
| 4988 | // } |
| 4989 | } |
| 4990 | } |
| 4991 | break; |
| 4992 | |
Greg Clayton | 4b63a5c | 2013-01-04 18:10:18 +0000 | [diff] [blame] | 4993 | case clang::Type::Elaborated: |
| 4994 | return GetIndexOfChildWithName (ast, |
| 4995 | cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), |
| 4996 | name, |
| 4997 | omit_empty_base_classes); |
| 4998 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 4999 | case clang::Type::Typedef: |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5000 | return GetIndexOfChildWithName (ast, |
Sean Callanan | 4811447 | 2010-12-13 01:26:27 +0000 | [diff] [blame] | 5001 | cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5002 | name, |
| 5003 | omit_empty_base_classes); |
| 5004 | |
| 5005 | default: |
| 5006 | break; |
| 5007 | } |
| 5008 | } |
| 5009 | return UINT32_MAX; |
| 5010 | } |
| 5011 | |
| 5012 | #pragma mark TagType |
| 5013 | |
| 5014 | bool |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5015 | ClangASTContext::SetTagTypeKind (clang_type_t tag_clang_type, int kind) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5016 | { |
| 5017 | if (tag_clang_type) |
| 5018 | { |
| 5019 | QualType tag_qual_type(QualType::getFromOpaquePtr(tag_clang_type)); |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 5020 | const clang::Type *clang_type = tag_qual_type.getTypePtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5021 | if (clang_type) |
| 5022 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 5023 | const TagType *tag_type = dyn_cast<TagType>(clang_type); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5024 | if (tag_type) |
| 5025 | { |
| 5026 | TagDecl *tag_decl = dyn_cast<TagDecl>(tag_type->getDecl()); |
| 5027 | if (tag_decl) |
| 5028 | { |
| 5029 | tag_decl->setTagKind ((TagDecl::TagKind)kind); |
| 5030 | return true; |
| 5031 | } |
| 5032 | } |
| 5033 | } |
| 5034 | } |
| 5035 | return false; |
| 5036 | } |
| 5037 | |
| 5038 | |
| 5039 | #pragma mark DeclContext Functions |
| 5040 | |
| 5041 | DeclContext * |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5042 | ClangASTContext::GetDeclContextForType (clang_type_t clang_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5043 | { |
| 5044 | if (clang_type == NULL) |
| 5045 | return NULL; |
| 5046 | |
| 5047 | QualType qual_type(QualType::getFromOpaquePtr(clang_type)); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 5048 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5049 | switch (type_class) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5050 | { |
Sean Callanan | cc427fa | 2011-07-30 02:42:06 +0000 | [diff] [blame] | 5051 | case clang::Type::UnaryTransform: break; |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5052 | case clang::Type::FunctionNoProto: break; |
| 5053 | case clang::Type::FunctionProto: break; |
| 5054 | case clang::Type::IncompleteArray: break; |
| 5055 | case clang::Type::VariableArray: break; |
| 5056 | case clang::Type::ConstantArray: break; |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 5057 | case clang::Type::DependentSizedArray: break; |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5058 | case clang::Type::ExtVector: break; |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 5059 | case clang::Type::DependentSizedExtVector: break; |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5060 | case clang::Type::Vector: break; |
| 5061 | case clang::Type::Builtin: break; |
| 5062 | case clang::Type::BlockPointer: break; |
| 5063 | case clang::Type::Pointer: break; |
| 5064 | case clang::Type::LValueReference: break; |
| 5065 | case clang::Type::RValueReference: break; |
| 5066 | case clang::Type::MemberPointer: break; |
| 5067 | case clang::Type::Complex: break; |
| 5068 | case clang::Type::ObjCObject: break; |
| 5069 | case clang::Type::ObjCInterface: return cast<ObjCObjectType>(qual_type.getTypePtr())->getInterface(); |
| 5070 | case clang::Type::ObjCObjectPointer: return ClangASTContext::GetDeclContextForType (cast<ObjCObjectPointerType>(qual_type.getTypePtr())->getPointeeType().getAsOpaquePtr()); |
| 5071 | case clang::Type::Record: return cast<RecordType>(qual_type)->getDecl(); |
| 5072 | case clang::Type::Enum: return cast<EnumType>(qual_type)->getDecl(); |
Sean Callanan | 4811447 | 2010-12-13 01:26:27 +0000 | [diff] [blame] | 5073 | case clang::Type::Typedef: return ClangASTContext::GetDeclContextForType (cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
Sean Callanan | 912855f | 2011-08-11 23:56:13 +0000 | [diff] [blame] | 5074 | case clang::Type::Elaborated: return ClangASTContext::GetDeclContextForType (cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
Greg Clayton | 9e40956 | 2010-07-28 02:04:09 +0000 | [diff] [blame] | 5075 | case clang::Type::TypeOfExpr: break; |
| 5076 | case clang::Type::TypeOf: break; |
| 5077 | case clang::Type::Decltype: break; |
| 5078 | //case clang::Type::QualifiedName: break; |
| 5079 | case clang::Type::TemplateSpecialization: break; |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 5080 | case clang::Type::DependentTemplateSpecialization: break; |
| 5081 | case clang::Type::TemplateTypeParm: break; |
| 5082 | case clang::Type::SubstTemplateTypeParm: break; |
| 5083 | case clang::Type::SubstTemplateTypeParmPack:break; |
| 5084 | case clang::Type::PackExpansion: break; |
| 5085 | case clang::Type::UnresolvedUsing: break; |
| 5086 | case clang::Type::Paren: break; |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 5087 | case clang::Type::Attributed: break; |
| 5088 | case clang::Type::Auto: break; |
| 5089 | case clang::Type::InjectedClassName: break; |
| 5090 | case clang::Type::DependentName: break; |
Greg Clayton | ea3e7d5 | 2011-10-08 00:49:15 +0000 | [diff] [blame] | 5091 | case clang::Type::Atomic: break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5092 | } |
| 5093 | // No DeclContext in this type... |
| 5094 | return NULL; |
| 5095 | } |
| 5096 | |
| 5097 | #pragma mark Namespace Declarations |
| 5098 | |
| 5099 | NamespaceDecl * |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 5100 | ClangASTContext::GetUniqueNamespaceDeclaration (const char *name, DeclContext *decl_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5101 | { |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 5102 | NamespaceDecl *namespace_decl = NULL; |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 5103 | ASTContext *ast = getASTContext(); |
| 5104 | TranslationUnitDecl *translation_unit_decl = ast->getTranslationUnitDecl (); |
| 5105 | if (decl_ctx == NULL) |
| 5106 | decl_ctx = translation_unit_decl; |
| 5107 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5108 | if (name) |
| 5109 | { |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 5110 | IdentifierInfo &identifier_info = ast->Idents.get(name); |
| 5111 | DeclarationName decl_name (&identifier_info); |
| 5112 | clang::DeclContext::lookup_result result = decl_ctx->lookup(decl_name); |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 5113 | for (NamedDecl *decl : result) |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 5114 | { |
Sean Callanan | 5deaa4c | 2012-12-21 21:34:42 +0000 | [diff] [blame] | 5115 | namespace_decl = dyn_cast<clang::NamespaceDecl>(decl); |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 5116 | if (namespace_decl) |
| 5117 | return namespace_decl; |
| 5118 | } |
| 5119 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5120 | namespace_decl = NamespaceDecl::Create(*ast, |
| 5121 | decl_ctx, |
| 5122 | false, |
| 5123 | SourceLocation(), |
| 5124 | SourceLocation(), |
| 5125 | &identifier_info, |
| 5126 | NULL); |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 5127 | |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 5128 | decl_ctx->addDecl (namespace_decl); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5129 | } |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 5130 | else |
| 5131 | { |
| 5132 | if (decl_ctx == translation_unit_decl) |
| 5133 | { |
| 5134 | namespace_decl = translation_unit_decl->getAnonymousNamespace(); |
| 5135 | if (namespace_decl) |
| 5136 | return namespace_decl; |
| 5137 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5138 | namespace_decl = NamespaceDecl::Create(*ast, |
| 5139 | decl_ctx, |
| 5140 | false, |
| 5141 | SourceLocation(), |
| 5142 | SourceLocation(), |
| 5143 | NULL, |
| 5144 | NULL); |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 5145 | translation_unit_decl->setAnonymousNamespace (namespace_decl); |
| 5146 | translation_unit_decl->addDecl (namespace_decl); |
| 5147 | assert (namespace_decl == translation_unit_decl->getAnonymousNamespace()); |
| 5148 | } |
| 5149 | else |
| 5150 | { |
| 5151 | NamespaceDecl *parent_namespace_decl = cast<NamespaceDecl>(decl_ctx); |
| 5152 | if (parent_namespace_decl) |
| 5153 | { |
| 5154 | namespace_decl = parent_namespace_decl->getAnonymousNamespace(); |
| 5155 | if (namespace_decl) |
| 5156 | return namespace_decl; |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5157 | namespace_decl = NamespaceDecl::Create(*ast, |
| 5158 | decl_ctx, |
| 5159 | false, |
| 5160 | SourceLocation(), |
| 5161 | SourceLocation(), |
| 5162 | NULL, |
| 5163 | NULL); |
Greg Clayton | 9d3d688 | 2011-10-31 23:51:19 +0000 | [diff] [blame] | 5164 | parent_namespace_decl->setAnonymousNamespace (namespace_decl); |
| 5165 | parent_namespace_decl->addDecl (namespace_decl); |
| 5166 | assert (namespace_decl == parent_namespace_decl->getAnonymousNamespace()); |
| 5167 | } |
| 5168 | else |
| 5169 | { |
| 5170 | // BAD!!! |
| 5171 | } |
| 5172 | } |
| 5173 | |
| 5174 | |
| 5175 | if (namespace_decl) |
| 5176 | { |
| 5177 | // If we make it here, we are creating the anonymous namespace decl |
| 5178 | // for the first time, so we need to do the using directive magic |
| 5179 | // like SEMA does |
| 5180 | UsingDirectiveDecl* using_directive_decl = UsingDirectiveDecl::Create (*ast, |
| 5181 | decl_ctx, |
| 5182 | SourceLocation(), |
| 5183 | SourceLocation(), |
| 5184 | NestedNameSpecifierLoc(), |
| 5185 | SourceLocation(), |
| 5186 | namespace_decl, |
| 5187 | decl_ctx); |
| 5188 | using_directive_decl->setImplicit(); |
| 5189 | decl_ctx->addDecl(using_directive_decl); |
| 5190 | } |
| 5191 | } |
| 5192 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 5193 | VerifyDecl(namespace_decl); |
| 5194 | #endif |
Greg Clayton | 030a204 | 2011-10-14 21:34:45 +0000 | [diff] [blame] | 5195 | return namespace_decl; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5196 | } |
| 5197 | |
| 5198 | |
| 5199 | #pragma mark Function Types |
| 5200 | |
| 5201 | FunctionDecl * |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 5202 | ClangASTContext::CreateFunctionDeclaration (DeclContext *decl_ctx, const char *name, clang_type_t function_clang_type, int storage, bool is_inline) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5203 | { |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 5204 | FunctionDecl *func_decl = NULL; |
| 5205 | ASTContext *ast = getASTContext(); |
| 5206 | if (decl_ctx == NULL) |
| 5207 | decl_ctx = ast->getTranslationUnitDecl(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5208 | |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 5209 | if (name && name[0]) |
| 5210 | { |
| 5211 | func_decl = FunctionDecl::Create (*ast, |
| 5212 | decl_ctx, |
| 5213 | SourceLocation(), |
| 5214 | SourceLocation(), |
| 5215 | DeclarationName (&ast->Idents.get(name)), |
| 5216 | QualType::getFromOpaquePtr(function_clang_type), |
| 5217 | NULL, |
| 5218 | (FunctionDecl::StorageClass)storage, |
| 5219 | (FunctionDecl::StorageClass)storage, |
| 5220 | is_inline); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5221 | } |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 5222 | else |
| 5223 | { |
| 5224 | func_decl = FunctionDecl::Create (*ast, |
| 5225 | decl_ctx, |
| 5226 | SourceLocation(), |
| 5227 | SourceLocation(), |
| 5228 | DeclarationName (), |
| 5229 | QualType::getFromOpaquePtr(function_clang_type), |
| 5230 | NULL, |
| 5231 | (FunctionDecl::StorageClass)storage, |
| 5232 | (FunctionDecl::StorageClass)storage, |
| 5233 | is_inline); |
| 5234 | } |
| 5235 | if (func_decl) |
| 5236 | decl_ctx->addDecl (func_decl); |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 5237 | |
| 5238 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 5239 | VerifyDecl(func_decl); |
| 5240 | #endif |
| 5241 | |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 5242 | return func_decl; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5243 | } |
| 5244 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5245 | clang_type_t |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5246 | ClangASTContext::CreateFunctionType (ASTContext *ast, |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5247 | clang_type_t result_type, |
| 5248 | clang_type_t *args, |
Sean Callanan | c81256a | 2010-09-16 20:40:25 +0000 | [diff] [blame] | 5249 | unsigned num_args, |
| 5250 | bool is_variadic, |
| 5251 | unsigned type_quals) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5252 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5253 | assert (ast != NULL); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5254 | std::vector<QualType> qual_type_args; |
| 5255 | for (unsigned i=0; i<num_args; ++i) |
| 5256 | qual_type_args.push_back (QualType::getFromOpaquePtr(args[i])); |
| 5257 | |
| 5258 | // TODO: Detect calling convention in DWARF? |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 5259 | FunctionProtoType::ExtProtoInfo proto_info; |
| 5260 | proto_info.Variadic = is_variadic; |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 5261 | proto_info.ExceptionSpecType = EST_None; |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 5262 | proto_info.TypeQuals = type_quals; |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 5263 | proto_info.RefQualifier = RQ_None; |
Sean Callanan | 2c777c4 | 2011-01-18 23:32:05 +0000 | [diff] [blame] | 5264 | proto_info.NumExceptions = 0; |
| 5265 | proto_info.Exceptions = NULL; |
| 5266 | |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 5267 | return ast->getFunctionType (QualType::getFromOpaquePtr(result_type), |
| 5268 | qual_type_args.empty() ? NULL : &qual_type_args.front(), |
| 5269 | qual_type_args.size(), |
| 5270 | proto_info).getAsOpaquePtr(); // NoReturn); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5271 | } |
| 5272 | |
| 5273 | ParmVarDecl * |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5274 | ClangASTContext::CreateParameterDeclaration (const char *name, clang_type_t param_type, int storage) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5275 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5276 | ASTContext *ast = getASTContext(); |
| 5277 | assert (ast != NULL); |
| 5278 | return ParmVarDecl::Create(*ast, |
| 5279 | ast->getTranslationUnitDecl(), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5280 | SourceLocation(), |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 5281 | SourceLocation(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5282 | name && name[0] ? &ast->Idents.get(name) : NULL, |
Sean Callanan | c81256a | 2010-09-16 20:40:25 +0000 | [diff] [blame] | 5283 | QualType::getFromOpaquePtr(param_type), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5284 | NULL, |
| 5285 | (VarDecl::StorageClass)storage, |
| 5286 | (VarDecl::StorageClass)storage, |
| 5287 | 0); |
| 5288 | } |
| 5289 | |
| 5290 | void |
| 5291 | ClangASTContext::SetFunctionParameters (FunctionDecl *function_decl, ParmVarDecl **params, unsigned num_params) |
| 5292 | { |
| 5293 | if (function_decl) |
Sean Callanan | 880e680 | 2011-10-07 23:18:13 +0000 | [diff] [blame] | 5294 | function_decl->setParams (ArrayRef<ParmVarDecl*>(params, num_params)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5295 | } |
| 5296 | |
| 5297 | |
| 5298 | #pragma mark Array Types |
| 5299 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5300 | clang_type_t |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 5301 | ClangASTContext::CreateArrayType (clang_type_t element_type, size_t element_count) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5302 | { |
| 5303 | if (element_type) |
| 5304 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5305 | ASTContext *ast = getASTContext(); |
| 5306 | assert (ast != NULL); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5307 | llvm::APInt ap_element_count (64, element_count); |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 5308 | if (element_count == 0) |
| 5309 | { |
| 5310 | return ast->getIncompleteArrayType(QualType::getFromOpaquePtr(element_type), |
| 5311 | ArrayType::Normal, |
| 5312 | 0).getAsOpaquePtr(); |
| 5313 | |
| 5314 | } |
| 5315 | else |
| 5316 | { |
| 5317 | return ast->getConstantArrayType(QualType::getFromOpaquePtr(element_type), |
| 5318 | ap_element_count, |
| 5319 | ArrayType::Normal, |
| 5320 | 0).getAsOpaquePtr(); // ElemQuals |
| 5321 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5322 | } |
| 5323 | return NULL; |
| 5324 | } |
| 5325 | |
| 5326 | |
| 5327 | #pragma mark TagDecl |
| 5328 | |
| 5329 | bool |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5330 | ClangASTContext::StartTagDeclarationDefinition (clang_type_t clang_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5331 | { |
| 5332 | if (clang_type) |
| 5333 | { |
| 5334 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 5335 | const clang::Type *t = qual_type.getTypePtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5336 | if (t) |
| 5337 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 5338 | const TagType *tag_type = dyn_cast<TagType>(t); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5339 | if (tag_type) |
| 5340 | { |
| 5341 | TagDecl *tag_decl = tag_type->getDecl(); |
| 5342 | if (tag_decl) |
| 5343 | { |
| 5344 | tag_decl->startDefinition(); |
| 5345 | return true; |
| 5346 | } |
| 5347 | } |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 5348 | |
| 5349 | const ObjCObjectType *object_type = dyn_cast<ObjCObjectType>(t); |
| 5350 | if (object_type) |
| 5351 | { |
| 5352 | ObjCInterfaceDecl *interface_decl = object_type->getInterface(); |
| 5353 | if (interface_decl) |
| 5354 | { |
| 5355 | interface_decl->startDefinition(); |
| 5356 | return true; |
| 5357 | } |
| 5358 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5359 | } |
| 5360 | } |
| 5361 | return false; |
| 5362 | } |
| 5363 | |
| 5364 | bool |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5365 | ClangASTContext::CompleteTagDeclarationDefinition (clang_type_t clang_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5366 | { |
| 5367 | if (clang_type) |
| 5368 | { |
| 5369 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
Greg Clayton | 1437224 | 2010-09-29 03:44:17 +0000 | [diff] [blame] | 5370 | |
| 5371 | CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 5372 | |
| 5373 | if (cxx_record_decl) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5374 | { |
Greg Clayton | 1437224 | 2010-09-29 03:44:17 +0000 | [diff] [blame] | 5375 | cxx_record_decl->completeDefinition(); |
| 5376 | |
| 5377 | return true; |
| 5378 | } |
| 5379 | |
| 5380 | const EnumType *enum_type = dyn_cast<EnumType>(qual_type.getTypePtr()); |
| 5381 | |
| 5382 | if (enum_type) |
| 5383 | { |
| 5384 | EnumDecl *enum_decl = enum_type->getDecl(); |
| 5385 | |
| 5386 | if (enum_decl) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5387 | { |
Greg Clayton | 1437224 | 2010-09-29 03:44:17 +0000 | [diff] [blame] | 5388 | /// TODO This really needs to be fixed. |
| 5389 | |
| 5390 | unsigned NumPositiveBits = 1; |
| 5391 | unsigned NumNegativeBits = 0; |
| 5392 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5393 | ASTContext *ast = getASTContext(); |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 5394 | |
| 5395 | QualType promotion_qual_type; |
| 5396 | // If the enum integer type is less than an integer in bit width, |
| 5397 | // then we must promote it to an integer size. |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5398 | if (ast->getTypeSize(enum_decl->getIntegerType()) < ast->getTypeSize(ast->IntTy)) |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 5399 | { |
| 5400 | if (enum_decl->getIntegerType()->isSignedIntegerType()) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5401 | promotion_qual_type = ast->IntTy; |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 5402 | else |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5403 | promotion_qual_type = ast->UnsignedIntTy; |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 5404 | } |
| 5405 | else |
| 5406 | promotion_qual_type = enum_decl->getIntegerType(); |
| 5407 | |
| 5408 | enum_decl->completeDefinition(enum_decl->getIntegerType(), promotion_qual_type, NumPositiveBits, NumNegativeBits); |
Greg Clayton | 1437224 | 2010-09-29 03:44:17 +0000 | [diff] [blame] | 5409 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5410 | } |
| 5411 | } |
| 5412 | } |
| 5413 | return false; |
| 5414 | } |
| 5415 | |
| 5416 | |
| 5417 | #pragma mark Enumeration Types |
| 5418 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5419 | clang_type_t |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 5420 | ClangASTContext::CreateEnumerationType |
| 5421 | ( |
| 5422 | const char *name, |
| 5423 | DeclContext *decl_ctx, |
| 5424 | const Declaration &decl, |
| 5425 | clang_type_t integer_qual_type |
| 5426 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5427 | { |
| 5428 | // TODO: Do something intelligent with the Declaration object passed in |
| 5429 | // like maybe filling in the SourceLocation with it... |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5430 | ASTContext *ast = getASTContext(); |
| 5431 | assert (ast != NULL); |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 5432 | |
| 5433 | // TODO: ask about these... |
| 5434 | // const bool IsScoped = false; |
| 5435 | // const bool IsFixed = false; |
| 5436 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5437 | EnumDecl *enum_decl = EnumDecl::Create (*ast, |
Greg Clayton | ca512b3 | 2011-01-14 04:54:56 +0000 | [diff] [blame] | 5438 | decl_ctx, |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 5439 | SourceLocation(), |
Greg Clayton | e02b850 | 2010-10-12 04:29:14 +0000 | [diff] [blame] | 5440 | SourceLocation(), |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 5441 | name && name[0] ? &ast->Idents.get(name) : NULL, |
Sean Callanan | 4811447 | 2010-12-13 01:26:27 +0000 | [diff] [blame] | 5442 | NULL, |
| 5443 | false, // IsScoped |
| 5444 | false, // IsScopedUsingClassTag |
| 5445 | false); // IsFixed |
Sean Callanan | 2652ad2 | 2011-01-18 01:03:44 +0000 | [diff] [blame] | 5446 | |
| 5447 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5448 | if (enum_decl) |
Greg Clayton | 83ff389 | 2010-09-12 23:17:56 +0000 | [diff] [blame] | 5449 | { |
| 5450 | // TODO: check if we should be setting the promotion type too? |
| 5451 | enum_decl->setIntegerType(QualType::getFromOpaquePtr (integer_qual_type)); |
Sean Callanan | 2652ad2 | 2011-01-18 01:03:44 +0000 | [diff] [blame] | 5452 | |
| 5453 | enum_decl->setAccess(AS_public); // TODO respect what's in the debug info |
| 5454 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5455 | return ast->getTagDeclType(enum_decl).getAsOpaquePtr(); |
Greg Clayton | 83ff389 | 2010-09-12 23:17:56 +0000 | [diff] [blame] | 5456 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5457 | return NULL; |
| 5458 | } |
| 5459 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5460 | clang_type_t |
| 5461 | ClangASTContext::GetEnumerationIntegerType (clang_type_t enum_clang_type) |
| 5462 | { |
| 5463 | QualType enum_qual_type (QualType::getFromOpaquePtr(enum_clang_type)); |
| 5464 | |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 5465 | const clang::Type *clang_type = enum_qual_type.getTypePtr(); |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5466 | if (clang_type) |
| 5467 | { |
| 5468 | const EnumType *enum_type = dyn_cast<EnumType>(clang_type); |
| 5469 | if (enum_type) |
| 5470 | { |
| 5471 | EnumDecl *enum_decl = enum_type->getDecl(); |
| 5472 | if (enum_decl) |
| 5473 | return enum_decl->getIntegerType().getAsOpaquePtr(); |
| 5474 | } |
| 5475 | } |
| 5476 | return NULL; |
| 5477 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5478 | bool |
| 5479 | ClangASTContext::AddEnumerationValueToEnumerationType |
| 5480 | ( |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5481 | clang_type_t enum_clang_type, |
| 5482 | clang_type_t enumerator_clang_type, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5483 | const Declaration &decl, |
| 5484 | const char *name, |
| 5485 | int64_t enum_value, |
| 5486 | uint32_t enum_value_bit_size |
| 5487 | ) |
| 5488 | { |
| 5489 | if (enum_clang_type && enumerator_clang_type && name) |
| 5490 | { |
| 5491 | // TODO: Do something intelligent with the Declaration object passed in |
| 5492 | // like maybe filling in the SourceLocation with it... |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5493 | ASTContext *ast = getASTContext(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5494 | IdentifierTable *identifier_table = getIdentifierTable(); |
| 5495 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5496 | assert (ast != NULL); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5497 | assert (identifier_table != NULL); |
| 5498 | QualType enum_qual_type (QualType::getFromOpaquePtr(enum_clang_type)); |
| 5499 | |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 5500 | const clang::Type *clang_type = enum_qual_type.getTypePtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5501 | if (clang_type) |
| 5502 | { |
| 5503 | const EnumType *enum_type = dyn_cast<EnumType>(clang_type); |
| 5504 | |
| 5505 | if (enum_type) |
| 5506 | { |
| 5507 | llvm::APSInt enum_llvm_apsint(enum_value_bit_size, false); |
| 5508 | enum_llvm_apsint = enum_value; |
| 5509 | EnumConstantDecl *enumerator_decl = |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5510 | EnumConstantDecl::Create (*ast, |
| 5511 | enum_type->getDecl(), |
| 5512 | SourceLocation(), |
| 5513 | name ? &identifier_table->get(name) : NULL, // Identifier |
| 5514 | QualType::getFromOpaquePtr(enumerator_clang_type), |
| 5515 | NULL, |
| 5516 | enum_llvm_apsint); |
| 5517 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5518 | if (enumerator_decl) |
| 5519 | { |
| 5520 | enum_type->getDecl()->addDecl(enumerator_decl); |
Sean Callanan | 5e9e199 | 2011-10-26 01:06:27 +0000 | [diff] [blame] | 5521 | |
| 5522 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 5523 | VerifyDecl(enumerator_decl); |
| 5524 | #endif |
| 5525 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5526 | return true; |
| 5527 | } |
| 5528 | } |
| 5529 | } |
| 5530 | } |
| 5531 | return false; |
| 5532 | } |
| 5533 | |
| 5534 | #pragma mark Pointers & References |
| 5535 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5536 | clang_type_t |
| 5537 | ClangASTContext::CreatePointerType (clang_type_t clang_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5538 | { |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 5539 | return CreatePointerType (getASTContext(), clang_type); |
| 5540 | } |
| 5541 | |
| 5542 | clang_type_t |
| 5543 | ClangASTContext::CreatePointerType (clang::ASTContext *ast, clang_type_t clang_type) |
| 5544 | { |
| 5545 | if (ast && clang_type) |
Greg Clayton | 5fb47cd | 2010-07-29 20:06:32 +0000 | [diff] [blame] | 5546 | { |
| 5547 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 5548 | |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 5549 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5550 | switch (type_class) |
Greg Clayton | 5fb47cd | 2010-07-29 20:06:32 +0000 | [diff] [blame] | 5551 | { |
| 5552 | case clang::Type::ObjCObject: |
| 5553 | case clang::Type::ObjCInterface: |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 5554 | return ast->getObjCObjectPointerType(qual_type).getAsOpaquePtr(); |
Greg Clayton | 5fb47cd | 2010-07-29 20:06:32 +0000 | [diff] [blame] | 5555 | |
Greg Clayton | 5fb47cd | 2010-07-29 20:06:32 +0000 | [diff] [blame] | 5556 | default: |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 5557 | return ast->getPointerType(qual_type).getAsOpaquePtr(); |
Greg Clayton | 5fb47cd | 2010-07-29 20:06:32 +0000 | [diff] [blame] | 5558 | } |
| 5559 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5560 | return NULL; |
| 5561 | } |
| 5562 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5563 | clang_type_t |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 +0000 | [diff] [blame] | 5564 | ClangASTContext::CreateLValueReferenceType (clang::ASTContext *ast, |
| 5565 | clang_type_t clang_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5566 | { |
| 5567 | if (clang_type) |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 +0000 | [diff] [blame] | 5568 | return ast->getLValueReferenceType (QualType::getFromOpaquePtr(clang_type)).getAsOpaquePtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5569 | return NULL; |
| 5570 | } |
| 5571 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5572 | clang_type_t |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 +0000 | [diff] [blame] | 5573 | ClangASTContext::CreateRValueReferenceType (clang::ASTContext *ast, |
| 5574 | clang_type_t clang_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5575 | { |
| 5576 | if (clang_type) |
Sean Callanan | 92adcac | 2011-01-13 08:53:35 +0000 | [diff] [blame] | 5577 | return ast->getRValueReferenceType (QualType::getFromOpaquePtr(clang_type)).getAsOpaquePtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5578 | return NULL; |
| 5579 | } |
| 5580 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5581 | clang_type_t |
| 5582 | ClangASTContext::CreateMemberPointerType (clang_type_t clang_pointee_type, clang_type_t clang_class_type) |
Greg Clayton | 9b81a31 | 2010-06-12 01:20:30 +0000 | [diff] [blame] | 5583 | { |
| 5584 | if (clang_pointee_type && clang_pointee_type) |
| 5585 | return getASTContext()->getMemberPointerType(QualType::getFromOpaquePtr(clang_pointee_type), |
| 5586 | QualType::getFromOpaquePtr(clang_class_type).getTypePtr()).getAsOpaquePtr(); |
| 5587 | return NULL; |
| 5588 | } |
| 5589 | |
Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 5590 | uint32_t |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5591 | ClangASTContext::GetPointerBitSize () |
| 5592 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 5593 | ASTContext *ast = getASTContext(); |
| 5594 | return ast->getTypeSize(ast->VoidPtrTy); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5595 | } |
| 5596 | |
| 5597 | bool |
Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 5598 | ClangASTContext::IsPossibleDynamicType (clang::ASTContext *ast, |
| 5599 | clang_type_t clang_type, |
| 5600 | clang_type_t *dynamic_pointee_type, |
| 5601 | bool check_cplusplus, |
| 5602 | bool check_objc) |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 5603 | { |
| 5604 | QualType pointee_qual_type; |
| 5605 | if (clang_type) |
| 5606 | { |
| 5607 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 5608 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5609 | bool success = false; |
| 5610 | switch (type_class) |
| 5611 | { |
| 5612 | case clang::Type::Builtin: |
Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 5613 | if (check_objc && cast<clang::BuiltinType>(qual_type)->getKind() == clang::BuiltinType::ObjCId) |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 5614 | { |
| 5615 | if (dynamic_pointee_type) |
| 5616 | *dynamic_pointee_type = clang_type; |
| 5617 | return true; |
| 5618 | } |
| 5619 | break; |
| 5620 | |
| 5621 | case clang::Type::ObjCObjectPointer: |
Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 5622 | if (check_objc) |
| 5623 | { |
| 5624 | if (dynamic_pointee_type) |
| 5625 | *dynamic_pointee_type = cast<ObjCObjectPointerType>(qual_type)->getPointeeType().getAsOpaquePtr(); |
| 5626 | return true; |
| 5627 | } |
| 5628 | break; |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 5629 | |
| 5630 | case clang::Type::Pointer: |
| 5631 | pointee_qual_type = cast<PointerType>(qual_type)->getPointeeType(); |
| 5632 | success = true; |
| 5633 | break; |
| 5634 | |
| 5635 | case clang::Type::LValueReference: |
| 5636 | case clang::Type::RValueReference: |
| 5637 | pointee_qual_type = cast<ReferenceType>(qual_type)->getPointeeType(); |
| 5638 | success = true; |
| 5639 | break; |
| 5640 | |
| 5641 | case clang::Type::Typedef: |
Greg Clayton | 7036425 | 2012-08-31 18:56:24 +0000 | [diff] [blame] | 5642 | return ClangASTContext::IsPossibleDynamicType (ast, |
| 5643 | cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), |
| 5644 | dynamic_pointee_type, |
| 5645 | check_cplusplus, |
| 5646 | check_objc); |
Sean Callanan | 912855f | 2011-08-11 23:56:13 +0000 | [diff] [blame] | 5647 | |
| 5648 | case clang::Type::Elaborated: |
Greg Clayton | 7036425 | 2012-08-31 18:56:24 +0000 | [diff] [blame] | 5649 | return ClangASTContext::IsPossibleDynamicType (ast, |
| 5650 | cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), |
| 5651 | dynamic_pointee_type, |
| 5652 | check_cplusplus, |
| 5653 | check_objc); |
Sean Callanan | 912855f | 2011-08-11 23:56:13 +0000 | [diff] [blame] | 5654 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 5655 | default: |
| 5656 | break; |
| 5657 | } |
| 5658 | |
| 5659 | if (success) |
| 5660 | { |
| 5661 | // Check to make sure what we are pointing too is a possible dynamic C++ type |
| 5662 | // We currently accept any "void *" (in case we have a class that has been |
| 5663 | // watered down to an opaque pointer) and virtual C++ classes. |
| 5664 | const clang::Type::TypeClass pointee_type_class = pointee_qual_type->getTypeClass(); |
| 5665 | switch (pointee_type_class) |
| 5666 | { |
| 5667 | case clang::Type::Builtin: |
| 5668 | switch (cast<clang::BuiltinType>(pointee_qual_type)->getKind()) |
| 5669 | { |
| 5670 | case clang::BuiltinType::UnknownAny: |
| 5671 | case clang::BuiltinType::Void: |
| 5672 | if (dynamic_pointee_type) |
| 5673 | *dynamic_pointee_type = pointee_qual_type.getAsOpaquePtr(); |
| 5674 | return true; |
| 5675 | |
| 5676 | case clang::BuiltinType::NullPtr: |
| 5677 | case clang::BuiltinType::Bool: |
| 5678 | case clang::BuiltinType::Char_U: |
| 5679 | case clang::BuiltinType::UChar: |
| 5680 | case clang::BuiltinType::WChar_U: |
| 5681 | case clang::BuiltinType::Char16: |
| 5682 | case clang::BuiltinType::Char32: |
| 5683 | case clang::BuiltinType::UShort: |
| 5684 | case clang::BuiltinType::UInt: |
| 5685 | case clang::BuiltinType::ULong: |
| 5686 | case clang::BuiltinType::ULongLong: |
| 5687 | case clang::BuiltinType::UInt128: |
| 5688 | case clang::BuiltinType::Char_S: |
| 5689 | case clang::BuiltinType::SChar: |
| 5690 | case clang::BuiltinType::WChar_S: |
| 5691 | case clang::BuiltinType::Short: |
| 5692 | case clang::BuiltinType::Int: |
| 5693 | case clang::BuiltinType::Long: |
| 5694 | case clang::BuiltinType::LongLong: |
| 5695 | case clang::BuiltinType::Int128: |
| 5696 | case clang::BuiltinType::Float: |
| 5697 | case clang::BuiltinType::Double: |
| 5698 | case clang::BuiltinType::LongDouble: |
| 5699 | case clang::BuiltinType::Dependent: |
| 5700 | case clang::BuiltinType::Overload: |
| 5701 | case clang::BuiltinType::ObjCId: |
| 5702 | case clang::BuiltinType::ObjCClass: |
| 5703 | case clang::BuiltinType::ObjCSel: |
| 5704 | case clang::BuiltinType::BoundMember: |
Greg Clayton | f0705c8 | 2011-10-22 03:33:13 +0000 | [diff] [blame] | 5705 | case clang::BuiltinType::Half: |
| 5706 | case clang::BuiltinType::ARCUnbridgedCast: |
Greg Clayton | ed3ae70 | 2011-11-09 19:04:58 +0000 | [diff] [blame] | 5707 | case clang::BuiltinType::PseudoObject: |
Sean Callanan | 3d654b3 | 2012-09-24 22:25:51 +0000 | [diff] [blame] | 5708 | case clang::BuiltinType::BuiltinFn: |
Greg Clayton | 3dcaa2c | 2013-02-01 00:46:49 +0000 | [diff] [blame] | 5709 | case clang::BuiltinType::OCLEvent: |
| 5710 | case clang::BuiltinType::OCLImage1d: |
| 5711 | case clang::BuiltinType::OCLImage1dArray: |
| 5712 | case clang::BuiltinType::OCLImage1dBuffer: |
| 5713 | case clang::BuiltinType::OCLImage2d: |
| 5714 | case clang::BuiltinType::OCLImage2dArray: |
| 5715 | case clang::BuiltinType::OCLImage3d: |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 5716 | break; |
| 5717 | } |
| 5718 | break; |
| 5719 | |
| 5720 | case clang::Type::Record: |
Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 5721 | if (check_cplusplus) |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 5722 | { |
| 5723 | CXXRecordDecl *cxx_record_decl = pointee_qual_type->getAsCXXRecordDecl(); |
| 5724 | if (cxx_record_decl) |
| 5725 | { |
Greg Clayton | 7036425 | 2012-08-31 18:56:24 +0000 | [diff] [blame] | 5726 | bool is_complete = cxx_record_decl->isCompleteDefinition(); |
| 5727 | if (!is_complete) |
Sean Callanan | 6e4100ea | 2012-09-08 00:49:45 +0000 | [diff] [blame] | 5728 | is_complete = ClangASTContext::GetCompleteType (ast, pointee_qual_type.getAsOpaquePtr()); |
Greg Clayton | 7036425 | 2012-08-31 18:56:24 +0000 | [diff] [blame] | 5729 | |
| 5730 | if (is_complete) |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 5731 | { |
| 5732 | success = cxx_record_decl->isDynamicClass(); |
| 5733 | } |
| 5734 | else |
| 5735 | { |
Greg Clayton | 7036425 | 2012-08-31 18:56:24 +0000 | [diff] [blame] | 5736 | success = false; |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 5737 | } |
Greg Clayton | 7036425 | 2012-08-31 18:56:24 +0000 | [diff] [blame] | 5738 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 5739 | if (success) |
| 5740 | { |
| 5741 | if (dynamic_pointee_type) |
| 5742 | *dynamic_pointee_type = pointee_qual_type.getAsOpaquePtr(); |
| 5743 | return true; |
| 5744 | } |
| 5745 | } |
| 5746 | } |
| 5747 | break; |
| 5748 | |
| 5749 | case clang::Type::ObjCObject: |
| 5750 | case clang::Type::ObjCInterface: |
Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 5751 | if (check_objc) |
| 5752 | { |
| 5753 | if (dynamic_pointee_type) |
| 5754 | *dynamic_pointee_type = pointee_qual_type.getAsOpaquePtr(); |
| 5755 | return true; |
| 5756 | } |
| 5757 | break; |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 5758 | |
| 5759 | default: |
| 5760 | break; |
| 5761 | } |
| 5762 | } |
| 5763 | } |
| 5764 | if (dynamic_pointee_type) |
| 5765 | *dynamic_pointee_type = NULL; |
| 5766 | return false; |
| 5767 | } |
| 5768 | |
| 5769 | |
| 5770 | bool |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 5771 | ClangASTContext::IsPossibleCPlusPlusDynamicType (clang::ASTContext *ast, clang_type_t clang_type, clang_type_t *dynamic_pointee_type) |
| 5772 | { |
Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 5773 | return IsPossibleDynamicType (ast, |
| 5774 | clang_type, |
| 5775 | dynamic_pointee_type, |
| 5776 | true, // Check for dynamic C++ types |
| 5777 | false); // Check for dynamic ObjC types |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 5778 | } |
| 5779 | |
Sean Callanan | 9829801 | 2011-10-27 19:41:13 +0000 | [diff] [blame] | 5780 | bool |
| 5781 | ClangASTContext::IsReferenceType (clang_type_t clang_type, clang_type_t *target_type) |
| 5782 | { |
| 5783 | if (clang_type == NULL) |
| 5784 | return false; |
| 5785 | |
| 5786 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 5787 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5788 | |
| 5789 | switch (type_class) |
| 5790 | { |
| 5791 | case clang::Type::LValueReference: |
| 5792 | if (target_type) |
| 5793 | *target_type = cast<LValueReferenceType>(qual_type)->desugar().getAsOpaquePtr(); |
| 5794 | return true; |
| 5795 | case clang::Type::RValueReference: |
| 5796 | if (target_type) |
| 5797 | *target_type = cast<LValueReferenceType>(qual_type)->desugar().getAsOpaquePtr(); |
| 5798 | return true; |
| 5799 | case clang::Type::Typedef: |
| 5800 | return ClangASTContext::IsReferenceType (cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
| 5801 | case clang::Type::Elaborated: |
| 5802 | return ClangASTContext::IsReferenceType (cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
| 5803 | default: |
| 5804 | break; |
| 5805 | } |
| 5806 | |
| 5807 | return false; |
| 5808 | } |
Greg Clayton | 007d5be | 2011-05-30 00:49:24 +0000 | [diff] [blame] | 5809 | |
| 5810 | bool |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5811 | ClangASTContext::IsPointerOrReferenceType (clang_type_t clang_type, clang_type_t*target_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5812 | { |
| 5813 | if (clang_type == NULL) |
| 5814 | return false; |
| 5815 | |
| 5816 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 5817 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5818 | switch (type_class) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5819 | { |
Sean Callanan | a242417 | 2010-10-25 00:29:48 +0000 | [diff] [blame] | 5820 | case clang::Type::Builtin: |
| 5821 | switch (cast<clang::BuiltinType>(qual_type)->getKind()) |
| 5822 | { |
| 5823 | default: |
| 5824 | break; |
| 5825 | case clang::BuiltinType::ObjCId: |
| 5826 | case clang::BuiltinType::ObjCClass: |
Sean Callanan | a242417 | 2010-10-25 00:29:48 +0000 | [diff] [blame] | 5827 | return true; |
| 5828 | } |
| 5829 | return false; |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 5830 | case clang::Type::ObjCObjectPointer: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5831 | if (target_type) |
| 5832 | *target_type = cast<ObjCObjectPointerType>(qual_type)->getPointeeType().getAsOpaquePtr(); |
| 5833 | return true; |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 5834 | case clang::Type::BlockPointer: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5835 | if (target_type) |
| 5836 | *target_type = cast<BlockPointerType>(qual_type)->getPointeeType().getAsOpaquePtr(); |
| 5837 | return true; |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 5838 | case clang::Type::Pointer: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5839 | if (target_type) |
| 5840 | *target_type = cast<PointerType>(qual_type)->getPointeeType().getAsOpaquePtr(); |
| 5841 | return true; |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 5842 | case clang::Type::MemberPointer: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5843 | if (target_type) |
| 5844 | *target_type = cast<MemberPointerType>(qual_type)->getPointeeType().getAsOpaquePtr(); |
| 5845 | return true; |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 5846 | case clang::Type::LValueReference: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5847 | if (target_type) |
| 5848 | *target_type = cast<LValueReferenceType>(qual_type)->desugar().getAsOpaquePtr(); |
| 5849 | return true; |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 5850 | case clang::Type::RValueReference: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5851 | if (target_type) |
| 5852 | *target_type = cast<LValueReferenceType>(qual_type)->desugar().getAsOpaquePtr(); |
| 5853 | return true; |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 5854 | case clang::Type::Typedef: |
Sean Callanan | 4811447 | 2010-12-13 01:26:27 +0000 | [diff] [blame] | 5855 | return ClangASTContext::IsPointerOrReferenceType (cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
Sean Callanan | 912855f | 2011-08-11 23:56:13 +0000 | [diff] [blame] | 5856 | case clang::Type::Elaborated: |
| 5857 | return ClangASTContext::IsPointerOrReferenceType (cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5858 | default: |
| 5859 | break; |
| 5860 | } |
| 5861 | return false; |
| 5862 | } |
| 5863 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5864 | bool |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5865 | ClangASTContext::IsIntegerType (clang_type_t clang_type, bool &is_signed) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5866 | { |
| 5867 | if (!clang_type) |
| 5868 | return false; |
| 5869 | |
| 5870 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 5871 | const BuiltinType *builtin_type = dyn_cast<BuiltinType>(qual_type->getCanonicalTypeInternal()); |
| 5872 | |
| 5873 | if (builtin_type) |
| 5874 | { |
| 5875 | if (builtin_type->isInteger()) |
Jim Ingham | ef65160 | 2011-12-22 19:12:40 +0000 | [diff] [blame] | 5876 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5877 | is_signed = builtin_type->isSignedInteger(); |
Jim Ingham | ef65160 | 2011-12-22 19:12:40 +0000 | [diff] [blame] | 5878 | return true; |
| 5879 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5880 | } |
| 5881 | |
| 5882 | return false; |
| 5883 | } |
| 5884 | |
| 5885 | bool |
Greg Clayton | affb03b | 2011-07-08 18:27:39 +0000 | [diff] [blame] | 5886 | ClangASTContext::IsPointerType (clang_type_t clang_type, clang_type_t *target_type) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5887 | { |
Greg Clayton | affb03b | 2011-07-08 18:27:39 +0000 | [diff] [blame] | 5888 | if (target_type) |
| 5889 | *target_type = NULL; |
| 5890 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5891 | if (clang_type) |
| 5892 | { |
| 5893 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 5894 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 5895 | switch (type_class) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5896 | { |
Sean Callanan | a242417 | 2010-10-25 00:29:48 +0000 | [diff] [blame] | 5897 | case clang::Type::Builtin: |
| 5898 | switch (cast<clang::BuiltinType>(qual_type)->getKind()) |
| 5899 | { |
| 5900 | default: |
| 5901 | break; |
| 5902 | case clang::BuiltinType::ObjCId: |
| 5903 | case clang::BuiltinType::ObjCClass: |
Sean Callanan | a242417 | 2010-10-25 00:29:48 +0000 | [diff] [blame] | 5904 | return true; |
| 5905 | } |
| 5906 | return false; |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 5907 | case clang::Type::ObjCObjectPointer: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5908 | if (target_type) |
| 5909 | *target_type = cast<ObjCObjectPointerType>(qual_type)->getPointeeType().getAsOpaquePtr(); |
| 5910 | return true; |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 5911 | case clang::Type::BlockPointer: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5912 | if (target_type) |
| 5913 | *target_type = cast<BlockPointerType>(qual_type)->getPointeeType().getAsOpaquePtr(); |
| 5914 | return true; |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 5915 | case clang::Type::Pointer: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5916 | if (target_type) |
| 5917 | *target_type = cast<PointerType>(qual_type)->getPointeeType().getAsOpaquePtr(); |
| 5918 | return true; |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 5919 | case clang::Type::MemberPointer: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5920 | if (target_type) |
| 5921 | *target_type = cast<MemberPointerType>(qual_type)->getPointeeType().getAsOpaquePtr(); |
| 5922 | return true; |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 5923 | case clang::Type::Typedef: |
Greg Clayton | affb03b | 2011-07-08 18:27:39 +0000 | [diff] [blame] | 5924 | return ClangASTContext::IsPointerType (cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), target_type); |
Sean Callanan | 912855f | 2011-08-11 23:56:13 +0000 | [diff] [blame] | 5925 | case clang::Type::Elaborated: |
| 5926 | return ClangASTContext::IsPointerType (cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), target_type); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5927 | default: |
| 5928 | break; |
| 5929 | } |
| 5930 | } |
| 5931 | return false; |
| 5932 | } |
| 5933 | |
| 5934 | bool |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 5935 | ClangASTContext::IsFloatingPointType (clang_type_t clang_type, uint32_t &count, bool &is_complex) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 5936 | { |
| 5937 | if (clang_type) |
| 5938 | { |
| 5939 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 5940 | |
| 5941 | if (const BuiltinType *BT = dyn_cast<BuiltinType>(qual_type->getCanonicalTypeInternal())) |
| 5942 | { |
| 5943 | clang::BuiltinType::Kind kind = BT->getKind(); |
| 5944 | if (kind >= BuiltinType::Float && kind <= BuiltinType::LongDouble) |
| 5945 | { |
| 5946 | count = 1; |
| 5947 | is_complex = false; |
| 5948 | return true; |
| 5949 | } |
| 5950 | } |
| 5951 | else if (const ComplexType *CT = dyn_cast<ComplexType>(qual_type->getCanonicalTypeInternal())) |
| 5952 | { |
| 5953 | if (IsFloatingPointType(CT->getElementType().getAsOpaquePtr(), count, is_complex)) |
| 5954 | { |
| 5955 | count = 2; |
| 5956 | is_complex = true; |
| 5957 | return true; |
| 5958 | } |
| 5959 | } |
| 5960 | else if (const VectorType *VT = dyn_cast<VectorType>(qual_type->getCanonicalTypeInternal())) |
| 5961 | { |
| 5962 | if (IsFloatingPointType(VT->getElementType().getAsOpaquePtr(), count, is_complex)) |
| 5963 | { |
| 5964 | count = VT->getNumElements(); |
| 5965 | is_complex = false; |
| 5966 | return true; |
| 5967 | } |
| 5968 | } |
| 5969 | } |
| 5970 | return false; |
| 5971 | } |
| 5972 | |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 5973 | bool |
| 5974 | ClangASTContext::IsScalarType (lldb::clang_type_t clang_type) |
| 5975 | { |
| 5976 | bool is_signed; |
| 5977 | if (ClangASTContext::IsIntegerType(clang_type, is_signed)) |
| 5978 | return true; |
| 5979 | |
| 5980 | uint32_t count; |
| 5981 | bool is_complex; |
| 5982 | return ClangASTContext::IsFloatingPointType(clang_type, count, is_complex) && !is_complex; |
| 5983 | } |
| 5984 | |
| 5985 | bool |
| 5986 | ClangASTContext::IsPointerToScalarType (lldb::clang_type_t clang_type) |
| 5987 | { |
| 5988 | if (!IsPointerType(clang_type)) |
| 5989 | return false; |
| 5990 | |
| 5991 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 5992 | lldb::clang_type_t pointee_type = qual_type.getTypePtr()->getPointeeType().getAsOpaquePtr(); |
| 5993 | return IsScalarType(pointee_type); |
| 5994 | } |
| 5995 | |
| 5996 | bool |
| 5997 | ClangASTContext::IsArrayOfScalarType (lldb::clang_type_t clang_type) |
| 5998 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 5999 | clang_type = GetAsArrayType(clang_type, NULL, NULL, NULL); |
Sean Callanan | 0caa21c | 2012-01-19 23:54:24 +0000 | [diff] [blame] | 6000 | |
| 6001 | if (clang_type == 0) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 6002 | return false; |
| 6003 | |
| 6004 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 6005 | lldb::clang_type_t item_type = cast<ArrayType>(qual_type.getTypePtr())->getElementType().getAsOpaquePtr(); |
| 6006 | return IsScalarType(item_type); |
| 6007 | } |
| 6008 | |
Greg Clayton | 8f92f0a | 2010-10-14 22:52:14 +0000 | [diff] [blame] | 6009 | |
| 6010 | bool |
| 6011 | ClangASTContext::GetCXXClassName (clang_type_t clang_type, std::string &class_name) |
| 6012 | { |
| 6013 | if (clang_type) |
| 6014 | { |
| 6015 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 6016 | |
| 6017 | CXXRecordDecl *cxx_record_decl = qual_type->getAsCXXRecordDecl(); |
| 6018 | if (cxx_record_decl) |
| 6019 | { |
| 6020 | class_name.assign (cxx_record_decl->getIdentifier()->getNameStart()); |
| 6021 | return true; |
| 6022 | } |
| 6023 | } |
| 6024 | class_name.clear(); |
| 6025 | return false; |
| 6026 | } |
| 6027 | |
| 6028 | |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6029 | bool |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6030 | ClangASTContext::IsCXXClassType (clang_type_t clang_type) |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6031 | { |
| 6032 | if (clang_type) |
| 6033 | { |
| 6034 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 6035 | if (qual_type->getAsCXXRecordDecl() != NULL) |
| 6036 | return true; |
| 6037 | } |
| 6038 | return false; |
| 6039 | } |
| 6040 | |
Greg Clayton | 20568dd | 2011-10-13 23:13:20 +0000 | [diff] [blame] | 6041 | bool |
| 6042 | ClangASTContext::IsBeingDefined (lldb::clang_type_t clang_type) |
| 6043 | { |
| 6044 | if (clang_type) |
| 6045 | { |
| 6046 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 6047 | const clang::TagType *tag_type = dyn_cast<clang::TagType>(qual_type); |
| 6048 | if (tag_type) |
| 6049 | return tag_type->isBeingDefined(); |
| 6050 | } |
| 6051 | return false; |
| 6052 | } |
| 6053 | |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6054 | bool |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6055 | ClangASTContext::IsObjCClassType (clang_type_t clang_type) |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6056 | { |
| 6057 | if (clang_type) |
| 6058 | { |
| 6059 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 6060 | if (qual_type->isObjCObjectOrInterfaceType()) |
| 6061 | return true; |
| 6062 | } |
| 6063 | return false; |
| 6064 | } |
| 6065 | |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 6066 | bool |
| 6067 | ClangASTContext::IsObjCObjectPointerType (lldb::clang_type_t clang_type, clang_type_t *class_type) |
| 6068 | { |
| 6069 | if (clang_type) |
| 6070 | { |
| 6071 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 6072 | if (qual_type->isObjCObjectPointerType()) |
| 6073 | { |
| 6074 | if (class_type) |
| 6075 | { |
| 6076 | *class_type = NULL; |
| 6077 | |
| 6078 | if (!qual_type->isObjCClassType() && |
| 6079 | !qual_type->isObjCIdType()) |
| 6080 | { |
| 6081 | const ObjCObjectPointerType *obj_pointer_type = dyn_cast<ObjCObjectPointerType>(qual_type); |
Sean Callanan | d7dabe2 | 2012-03-10 01:59:11 +0000 | [diff] [blame] | 6082 | if (!obj_pointer_type) |
| 6083 | *class_type = NULL; |
Sean Callanan | 1fc91ad | 2012-03-10 02:00:32 +0000 | [diff] [blame] | 6084 | else |
| 6085 | *class_type = QualType(obj_pointer_type->getInterfaceType(), 0).getAsOpaquePtr(); |
Sean Callanan | 7277284 | 2012-02-22 23:57:45 +0000 | [diff] [blame] | 6086 | } |
| 6087 | } |
| 6088 | return true; |
| 6089 | } |
| 6090 | } |
| 6091 | return false; |
| 6092 | } |
| 6093 | |
| 6094 | bool |
| 6095 | ClangASTContext::GetObjCClassName (lldb::clang_type_t clang_type, |
| 6096 | std::string &class_name) |
| 6097 | { |
| 6098 | if (!clang_type) |
| 6099 | return false; |
| 6100 | |
| 6101 | const ObjCObjectType *object_type = dyn_cast<ObjCObjectType>(QualType::getFromOpaquePtr(clang_type)); |
| 6102 | if (!object_type) |
| 6103 | return false; |
| 6104 | |
| 6105 | const ObjCInterfaceDecl *interface = object_type->getInterface(); |
| 6106 | if (!interface) |
| 6107 | return false; |
| 6108 | |
| 6109 | class_name = interface->getNameAsString(); |
| 6110 | return true; |
| 6111 | } |
Greg Clayton | 0fffff5 | 2010-09-24 05:15:53 +0000 | [diff] [blame] | 6112 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 6113 | bool |
| 6114 | ClangASTContext::IsCharType (clang_type_t clang_type) |
| 6115 | { |
| 6116 | if (clang_type) |
| 6117 | return QualType::getFromOpaquePtr(clang_type)->isCharType(); |
| 6118 | return false; |
| 6119 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6120 | |
| 6121 | bool |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6122 | ClangASTContext::IsCStringType (clang_type_t clang_type, uint32_t &length) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6123 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 6124 | clang_type_t pointee_or_element_clang_type = NULL; |
| 6125 | Flags type_flags (ClangASTContext::GetTypeInfo (clang_type, NULL, &pointee_or_element_clang_type)); |
| 6126 | |
| 6127 | if (pointee_or_element_clang_type == NULL) |
| 6128 | return false; |
| 6129 | |
| 6130 | if (type_flags.AnySet (eTypeIsArray | eTypeIsPointer)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6131 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 6132 | QualType pointee_or_element_qual_type (QualType::getFromOpaquePtr (pointee_or_element_clang_type)); |
| 6133 | |
| 6134 | if (pointee_or_element_qual_type.getUnqualifiedType()->isCharType()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6135 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 6136 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 6137 | if (type_flags.Test (eTypeIsArray)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6138 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 6139 | // We know the size of the array and it could be a C string |
| 6140 | // since it is an array of characters |
| 6141 | length = cast<ConstantArrayType>(qual_type.getTypePtr())->getSize().getLimitedValue(); |
| 6142 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6143 | } |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 6144 | else |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6145 | { |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 6146 | length = 0; |
| 6147 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6148 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6149 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6150 | } |
| 6151 | } |
| 6152 | return false; |
| 6153 | } |
| 6154 | |
| 6155 | bool |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6156 | ClangASTContext::IsFunctionPointerType (clang_type_t clang_type) |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 6157 | { |
| 6158 | if (clang_type) |
| 6159 | { |
| 6160 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 6161 | |
| 6162 | if (qual_type->isFunctionPointerType()) |
| 6163 | return true; |
| 6164 | |
| 6165 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6166 | switch (type_class) |
| 6167 | { |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 6168 | default: |
| 6169 | break; |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 6170 | case clang::Type::Typedef: |
Sean Callanan | 4811447 | 2010-12-13 01:26:27 +0000 | [diff] [blame] | 6171 | return ClangASTContext::IsFunctionPointerType (cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
Sean Callanan | 912855f | 2011-08-11 23:56:13 +0000 | [diff] [blame] | 6172 | case clang::Type::Elaborated: |
| 6173 | return ClangASTContext::IsFunctionPointerType (cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 6174 | |
| 6175 | case clang::Type::LValueReference: |
| 6176 | case clang::Type::RValueReference: |
| 6177 | { |
Sean Callanan | 78e3760 | 2011-01-27 04:42:51 +0000 | [diff] [blame] | 6178 | const ReferenceType *reference_type = cast<ReferenceType>(qual_type.getTypePtr()); |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 6179 | if (reference_type) |
| 6180 | return ClangASTContext::IsFunctionPointerType (reference_type->getPointeeType().getAsOpaquePtr()); |
| 6181 | } |
| 6182 | break; |
| 6183 | } |
| 6184 | } |
| 6185 | return false; |
| 6186 | } |
| 6187 | |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 6188 | size_t |
| 6189 | ClangASTContext::GetArraySize (clang_type_t clang_type) |
| 6190 | { |
| 6191 | if (clang_type) |
| 6192 | { |
Greg Clayton | ef37d68a | 2011-07-09 17:12:27 +0000 | [diff] [blame] | 6193 | QualType qual_type(QualType::getFromOpaquePtr(clang_type)); |
| 6194 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6195 | switch (type_class) |
| 6196 | { |
| 6197 | case clang::Type::ConstantArray: |
| 6198 | { |
| 6199 | const ConstantArrayType *array = cast<ConstantArrayType>(QualType::getFromOpaquePtr(clang_type).getTypePtr()); |
| 6200 | if (array) |
| 6201 | return array->getSize().getLimitedValue(); |
| 6202 | } |
| 6203 | break; |
| 6204 | |
| 6205 | case clang::Type::Typedef: |
| 6206 | return ClangASTContext::GetArraySize(cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr()); |
Sean Callanan | 912855f | 2011-08-11 23:56:13 +0000 | [diff] [blame] | 6207 | |
| 6208 | case clang::Type::Elaborated: |
| 6209 | return ClangASTContext::GetArraySize(cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr()); |
Enrico Granata | f9fa6ee | 2011-07-12 00:18:11 +0000 | [diff] [blame] | 6210 | |
| 6211 | default: |
| 6212 | break; |
Greg Clayton | ef37d68a | 2011-07-09 17:12:27 +0000 | [diff] [blame] | 6213 | } |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 6214 | } |
| 6215 | return 0; |
| 6216 | } |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 6217 | |
Sean Callanan | 0caa21c | 2012-01-19 23:54:24 +0000 | [diff] [blame] | 6218 | clang_type_t |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 6219 | ClangASTContext::GetAsArrayType (clang_type_t clang_type, clang_type_t*member_type, uint64_t *size, bool *is_incomplete) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6220 | { |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 6221 | if (is_incomplete) |
| 6222 | *is_incomplete = false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6223 | if (!clang_type) |
Sean Callanan | 0caa21c | 2012-01-19 23:54:24 +0000 | [diff] [blame] | 6224 | return 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6225 | |
| 6226 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 6227 | |
Greg Clayton | 737b932 | 2010-09-13 03:32:57 +0000 | [diff] [blame] | 6228 | const clang::Type::TypeClass type_class = qual_type->getTypeClass(); |
| 6229 | switch (type_class) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6230 | { |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 6231 | default: |
| 6232 | break; |
Greg Clayton | ef37d68a | 2011-07-09 17:12:27 +0000 | [diff] [blame] | 6233 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 6234 | case clang::Type::ConstantArray: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6235 | if (member_type) |
| 6236 | *member_type = cast<ConstantArrayType>(qual_type)->getElementType().getAsOpaquePtr(); |
| 6237 | if (size) |
Greg Clayton | ac4827f | 2011-04-01 18:14:08 +0000 | [diff] [blame] | 6238 | *size = cast<ConstantArrayType>(qual_type)->getSize().getLimitedValue(ULLONG_MAX); |
Sean Callanan | 0caa21c | 2012-01-19 23:54:24 +0000 | [diff] [blame] | 6239 | return clang_type; |
Greg Clayton | ef37d68a | 2011-07-09 17:12:27 +0000 | [diff] [blame] | 6240 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 6241 | case clang::Type::IncompleteArray: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6242 | if (member_type) |
| 6243 | *member_type = cast<IncompleteArrayType>(qual_type)->getElementType().getAsOpaquePtr(); |
| 6244 | if (size) |
| 6245 | *size = 0; |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 6246 | if (is_incomplete) |
| 6247 | *is_incomplete = true; |
Sean Callanan | 0caa21c | 2012-01-19 23:54:24 +0000 | [diff] [blame] | 6248 | return clang_type; |
Greg Clayton | ef37d68a | 2011-07-09 17:12:27 +0000 | [diff] [blame] | 6249 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 6250 | case clang::Type::VariableArray: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6251 | if (member_type) |
| 6252 | *member_type = cast<VariableArrayType>(qual_type)->getElementType().getAsOpaquePtr(); |
| 6253 | if (size) |
| 6254 | *size = 0; |
Sean Callanan | 0caa21c | 2012-01-19 23:54:24 +0000 | [diff] [blame] | 6255 | return clang_type; |
Greg Clayton | ef37d68a | 2011-07-09 17:12:27 +0000 | [diff] [blame] | 6256 | |
Greg Clayton | e1a916a | 2010-07-21 22:12:05 +0000 | [diff] [blame] | 6257 | case clang::Type::DependentSizedArray: |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6258 | if (member_type) |
| 6259 | *member_type = cast<DependentSizedArrayType>(qual_type)->getElementType().getAsOpaquePtr(); |
| 6260 | if (size) |
| 6261 | *size = 0; |
Sean Callanan | 0caa21c | 2012-01-19 23:54:24 +0000 | [diff] [blame] | 6262 | return clang_type; |
Greg Clayton | ef37d68a | 2011-07-09 17:12:27 +0000 | [diff] [blame] | 6263 | |
| 6264 | case clang::Type::Typedef: |
Sean Callanan | 0caa21c | 2012-01-19 23:54:24 +0000 | [diff] [blame] | 6265 | return ClangASTContext::GetAsArrayType (cast<TypedefType>(qual_type)->getDecl()->getUnderlyingType().getAsOpaquePtr(), |
| 6266 | member_type, |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 6267 | size, |
| 6268 | is_incomplete); |
Sean Callanan | 912855f | 2011-08-11 23:56:13 +0000 | [diff] [blame] | 6269 | |
| 6270 | case clang::Type::Elaborated: |
Sean Callanan | 0caa21c | 2012-01-19 23:54:24 +0000 | [diff] [blame] | 6271 | return ClangASTContext::GetAsArrayType (cast<ElaboratedType>(qual_type)->getNamedType().getAsOpaquePtr(), |
| 6272 | member_type, |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 6273 | size, |
| 6274 | is_incomplete); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6275 | } |
Sean Callanan | 0caa21c | 2012-01-19 23:54:24 +0000 | [diff] [blame] | 6276 | return 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6277 | } |
| 6278 | |
| 6279 | |
| 6280 | #pragma mark Typedefs |
| 6281 | |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6282 | clang_type_t |
| 6283 | ClangASTContext::CreateTypedefType (const char *name, clang_type_t clang_type, DeclContext *decl_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6284 | { |
| 6285 | if (clang_type) |
| 6286 | { |
| 6287 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6288 | ASTContext *ast = getASTContext(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6289 | IdentifierTable *identifier_table = getIdentifierTable(); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6290 | assert (ast != NULL); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6291 | assert (identifier_table != NULL); |
| 6292 | if (decl_ctx == NULL) |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6293 | decl_ctx = ast->getTranslationUnitDecl(); |
| 6294 | TypedefDecl *decl = TypedefDecl::Create (*ast, |
| 6295 | decl_ctx, |
| 6296 | SourceLocation(), |
Sean Callanan | fb0b758 | 2011-03-15 00:17:19 +0000 | [diff] [blame] | 6297 | SourceLocation(), |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6298 | name ? &identifier_table->get(name) : NULL, // Identifier |
| 6299 | ast->CreateTypeSourceInfo(qual_type)); |
Sean Callanan | 2652ad2 | 2011-01-18 01:03:44 +0000 | [diff] [blame] | 6300 | |
Greg Clayton | 147e1fa | 2011-10-14 22:47:18 +0000 | [diff] [blame] | 6301 | //decl_ctx->addDecl (decl); |
| 6302 | |
Sean Callanan | 2652ad2 | 2011-01-18 01:03:44 +0000 | [diff] [blame] | 6303 | decl->setAccess(AS_public); // TODO respect proper access specifier |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6304 | |
| 6305 | // Get a uniqued QualType for the typedef decl type |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6306 | return ast->getTypedefType (decl).getAsOpaquePtr(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6307 | } |
| 6308 | return NULL; |
| 6309 | } |
| 6310 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6311 | // Disable this for now since I can't seem to get a nicely formatted float |
| 6312 | // out of the APFloat class without just getting the float, double or quad |
| 6313 | // and then using a formatted print on it which defeats the purpose. We ideally |
| 6314 | // would like to get perfect string values for any kind of float semantics |
| 6315 | // so we can support remote targets. The code below also requires a patch to |
| 6316 | // llvm::APInt. |
| 6317 | //bool |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6318 | //ClangASTContext::ConvertFloatValueToString (ASTContext *ast, clang_type_t clang_type, const uint8_t* bytes, size_t byte_size, int apint_byte_order, std::string &float_str) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6319 | //{ |
| 6320 | // uint32_t count = 0; |
| 6321 | // bool is_complex = false; |
| 6322 | // if (ClangASTContext::IsFloatingPointType (clang_type, count, is_complex)) |
| 6323 | // { |
| 6324 | // unsigned num_bytes_per_float = byte_size / count; |
| 6325 | // unsigned num_bits_per_float = num_bytes_per_float * 8; |
| 6326 | // |
| 6327 | // float_str.clear(); |
| 6328 | // uint32_t i; |
| 6329 | // for (i=0; i<count; i++) |
| 6330 | // { |
| 6331 | // APInt ap_int(num_bits_per_float, bytes + i * num_bytes_per_float, (APInt::ByteOrder)apint_byte_order); |
| 6332 | // bool is_ieee = false; |
| 6333 | // APFloat ap_float(ap_int, is_ieee); |
| 6334 | // char s[1024]; |
| 6335 | // unsigned int hex_digits = 0; |
| 6336 | // bool upper_case = false; |
| 6337 | // |
| 6338 | // if (ap_float.convertToHexString(s, hex_digits, upper_case, APFloat::rmNearestTiesToEven) > 0) |
| 6339 | // { |
| 6340 | // if (i > 0) |
| 6341 | // float_str.append(", "); |
| 6342 | // float_str.append(s); |
| 6343 | // if (i == 1 && is_complex) |
| 6344 | // float_str.append(1, 'i'); |
| 6345 | // } |
| 6346 | // } |
| 6347 | // return !float_str.empty(); |
| 6348 | // } |
| 6349 | // return false; |
| 6350 | //} |
| 6351 | |
| 6352 | size_t |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6353 | ClangASTContext::ConvertStringToFloatValue (ASTContext *ast, clang_type_t clang_type, const char *s, uint8_t *dst, size_t dst_size) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6354 | { |
| 6355 | if (clang_type) |
| 6356 | { |
| 6357 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 6358 | uint32_t count = 0; |
| 6359 | bool is_complex = false; |
| 6360 | if (ClangASTContext::IsFloatingPointType (clang_type, count, is_complex)) |
| 6361 | { |
| 6362 | // TODO: handle complex and vector types |
| 6363 | if (count != 1) |
| 6364 | return false; |
| 6365 | |
| 6366 | StringRef s_sref(s); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6367 | APFloat ap_float(ast->getFloatTypeSemantics(qual_type), s_sref); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6368 | |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6369 | const uint64_t bit_size = ast->getTypeSize (qual_type); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6370 | const uint64_t byte_size = bit_size / 8; |
| 6371 | if (dst_size >= byte_size) |
| 6372 | { |
| 6373 | if (bit_size == sizeof(float)*8) |
| 6374 | { |
| 6375 | float float32 = ap_float.convertToFloat(); |
| 6376 | ::memcpy (dst, &float32, byte_size); |
| 6377 | return byte_size; |
| 6378 | } |
| 6379 | else if (bit_size >= 64) |
| 6380 | { |
| 6381 | llvm::APInt ap_int(ap_float.bitcastToAPInt()); |
| 6382 | ::memcpy (dst, ap_int.getRawData(), byte_size); |
| 6383 | return byte_size; |
| 6384 | } |
| 6385 | } |
| 6386 | } |
| 6387 | } |
| 6388 | return 0; |
| 6389 | } |
Sean Callanan | 6fe64b5 | 2010-09-17 02:24:29 +0000 | [diff] [blame] | 6390 | |
| 6391 | unsigned |
Greg Clayton | 1be10fc | 2010-09-29 01:12:09 +0000 | [diff] [blame] | 6392 | ClangASTContext::GetTypeQualifiers(clang_type_t clang_type) |
Sean Callanan | 6fe64b5 | 2010-09-17 02:24:29 +0000 | [diff] [blame] | 6393 | { |
| 6394 | assert (clang_type); |
| 6395 | |
| 6396 | QualType qual_type (QualType::getFromOpaquePtr(clang_type)); |
| 6397 | |
| 6398 | return qual_type.getQualifiers().getCVRQualifiers(); |
| 6399 | } |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6400 | |
| 6401 | bool |
| 6402 | ClangASTContext::GetCompleteType (clang::ASTContext *ast, lldb::clang_type_t clang_type) |
| 6403 | { |
| 6404 | if (clang_type == NULL) |
| 6405 | return false; |
| 6406 | |
Greg Clayton | c432c19 | 2011-01-20 04:18:48 +0000 | [diff] [blame] | 6407 | return GetCompleteQualType (ast, clang::QualType::getFromOpaquePtr(clang_type)); |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 6408 | } |
| 6409 | |
| 6410 | |
| 6411 | bool |
| 6412 | ClangASTContext::GetCompleteType (clang_type_t clang_type) |
| 6413 | { |
| 6414 | return ClangASTContext::GetCompleteType (getASTContext(), clang_type); |
| 6415 | } |
| 6416 | |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6417 | bool |
Enrico Granata | 86027e9 | 2012-03-24 01:11:14 +0000 | [diff] [blame] | 6418 | ClangASTContext::IsCompleteType (clang::ASTContext *ast, lldb::clang_type_t clang_type) |
| 6419 | { |
| 6420 | if (clang_type == NULL) |
| 6421 | return false; |
| 6422 | |
| 6423 | return GetCompleteQualType (ast, clang::QualType::getFromOpaquePtr(clang_type), false); // just check but don't let it actually complete |
| 6424 | } |
| 6425 | |
| 6426 | |
| 6427 | bool |
| 6428 | ClangASTContext::IsCompleteType (clang_type_t clang_type) |
| 6429 | { |
| 6430 | return ClangASTContext::IsCompleteType (getASTContext(), clang_type); |
| 6431 | } |
| 6432 | |
| 6433 | bool |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6434 | ClangASTContext::GetCompleteDecl (clang::ASTContext *ast, |
| 6435 | clang::Decl *decl) |
| 6436 | { |
| 6437 | if (!decl) |
| 6438 | return false; |
| 6439 | |
| 6440 | ExternalASTSource *ast_source = ast->getExternalSource(); |
| 6441 | |
| 6442 | if (!ast_source) |
| 6443 | return false; |
| 6444 | |
| 6445 | if (clang::TagDecl *tag_decl = llvm::dyn_cast<clang::TagDecl>(decl)) |
| 6446 | { |
Greg Clayton | 219cf31 | 2012-03-30 00:51:13 +0000 | [diff] [blame] | 6447 | if (tag_decl->isCompleteDefinition()) |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6448 | return true; |
| 6449 | |
| 6450 | if (!tag_decl->hasExternalLexicalStorage()) |
| 6451 | return false; |
| 6452 | |
| 6453 | ast_source->CompleteType(tag_decl); |
| 6454 | |
| 6455 | return !tag_decl->getTypeForDecl()->isIncompleteType(); |
| 6456 | } |
| 6457 | else if (clang::ObjCInterfaceDecl *objc_interface_decl = llvm::dyn_cast<clang::ObjCInterfaceDecl>(decl)) |
| 6458 | { |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 6459 | if (objc_interface_decl->getDefinition()) |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6460 | return true; |
| 6461 | |
| 6462 | if (!objc_interface_decl->hasExternalLexicalStorage()) |
| 6463 | return false; |
| 6464 | |
| 6465 | ast_source->CompleteType(objc_interface_decl); |
| 6466 | |
Sean Callanan | 5b26f27 | 2012-02-04 08:49:35 +0000 | [diff] [blame] | 6467 | return !objc_interface_decl->getTypeForDecl()->isIncompleteType(); |
Greg Clayton | a272147 | 2011-06-25 00:44:06 +0000 | [diff] [blame] | 6468 | } |
| 6469 | else |
| 6470 | { |
| 6471 | return false; |
| 6472 | } |
| 6473 | } |
| 6474 | |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6475 | void |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6476 | ClangASTContext::SetMetadataAsUserID (uintptr_t object, |
| 6477 | user_id_t user_id) |
| 6478 | { |
| 6479 | ClangASTMetadata meta_data; |
| 6480 | meta_data.SetUserID (user_id); |
| 6481 | SetMetadata (object, meta_data); |
| 6482 | } |
| 6483 | |
| 6484 | void |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6485 | ClangASTContext::SetMetadata (clang::ASTContext *ast, |
| 6486 | uintptr_t object, |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6487 | ClangASTMetadata &metadata) |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6488 | { |
| 6489 | ClangExternalASTSourceCommon *external_source = |
| 6490 | static_cast<ClangExternalASTSourceCommon*>(ast->getExternalSource()); |
| 6491 | |
| 6492 | if (external_source) |
| 6493 | external_source->SetMetadata(object, metadata); |
| 6494 | } |
| 6495 | |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6496 | ClangASTMetadata * |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6497 | ClangASTContext::GetMetadata (clang::ASTContext *ast, |
| 6498 | uintptr_t object) |
| 6499 | { |
| 6500 | ClangExternalASTSourceCommon *external_source = |
| 6501 | static_cast<ClangExternalASTSourceCommon*>(ast->getExternalSource()); |
| 6502 | |
| 6503 | if (external_source && external_source->HasMetadata(object)) |
| 6504 | return external_source->GetMetadata(object); |
| 6505 | else |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6506 | return NULL; |
Sean Callanan | 6021712 | 2012-04-13 00:10:03 +0000 | [diff] [blame] | 6507 | } |
| 6508 | |
Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 6509 | clang::DeclContext * |
| 6510 | ClangASTContext::GetAsDeclContext (clang::CXXMethodDecl *cxx_method_decl) |
| 6511 | { |
Sean Callanan | a87bee8 | 2011-08-19 06:19:25 +0000 | [diff] [blame] | 6512 | return llvm::dyn_cast<clang::DeclContext>(cxx_method_decl); |
Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 6513 | } |
| 6514 | |
| 6515 | clang::DeclContext * |
| 6516 | ClangASTContext::GetAsDeclContext (clang::ObjCMethodDecl *objc_method_decl) |
| 6517 | { |
Sean Callanan | a87bee8 | 2011-08-19 06:19:25 +0000 | [diff] [blame] | 6518 | return llvm::dyn_cast<clang::DeclContext>(objc_method_decl); |
Greg Clayton | 2c5f0e9 | 2011-08-04 21:02:57 +0000 | [diff] [blame] | 6519 | } |
| 6520 | |
Greg Clayton | 685c88c | 2012-07-14 00:53:55 +0000 | [diff] [blame] | 6521 | |
| 6522 | bool |
| 6523 | ClangASTContext::GetClassMethodInfoForDeclContext (clang::DeclContext *decl_ctx, |
| 6524 | lldb::LanguageType &language, |
| 6525 | bool &is_instance_method, |
| 6526 | ConstString &language_object_name) |
| 6527 | { |
| 6528 | language_object_name.Clear(); |
| 6529 | language = eLanguageTypeUnknown; |
| 6530 | is_instance_method = false; |
| 6531 | |
| 6532 | if (decl_ctx) |
| 6533 | { |
| 6534 | if (clang::CXXMethodDecl *method_decl = llvm::dyn_cast<clang::CXXMethodDecl>(decl_ctx)) |
| 6535 | { |
| 6536 | if (method_decl->isStatic()) |
| 6537 | { |
| 6538 | is_instance_method = false; |
| 6539 | } |
| 6540 | else |
| 6541 | { |
| 6542 | language_object_name.SetCString("this"); |
| 6543 | is_instance_method = true; |
| 6544 | } |
| 6545 | language = eLanguageTypeC_plus_plus; |
| 6546 | return true; |
| 6547 | } |
| 6548 | else if (clang::ObjCMethodDecl *method_decl = llvm::dyn_cast<clang::ObjCMethodDecl>(decl_ctx)) |
| 6549 | { |
| 6550 | // Both static and instance methods have a "self" object in objective C |
| 6551 | language_object_name.SetCString("self"); |
| 6552 | if (method_decl->isInstanceMethod()) |
| 6553 | { |
| 6554 | is_instance_method = true; |
| 6555 | } |
| 6556 | else |
| 6557 | { |
| 6558 | is_instance_method = false; |
| 6559 | } |
| 6560 | language = eLanguageTypeObjC; |
| 6561 | return true; |
| 6562 | } |
Jim Ingham | 37939763 | 2012-10-27 02:54:13 +0000 | [diff] [blame] | 6563 | else if (clang::FunctionDecl *function_decl = llvm::dyn_cast<clang::FunctionDecl>(decl_ctx)) |
| 6564 | { |
| 6565 | ClangASTMetadata *metadata = GetMetadata (&decl_ctx->getParentASTContext(), (uintptr_t) function_decl); |
| 6566 | if (metadata && metadata->HasObjectPtr()) |
| 6567 | { |
| 6568 | language_object_name.SetCString (metadata->GetObjectPtrName()); |
| 6569 | language = eLanguageTypeObjC; |
| 6570 | is_instance_method = true; |
| 6571 | } |
| 6572 | return true; |
| 6573 | } |
Greg Clayton | 685c88c | 2012-07-14 00:53:55 +0000 | [diff] [blame] | 6574 | } |
| 6575 | return false; |
| 6576 | } |
| 6577 | |