diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-01-29 17:22:53 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-01-29 17:22:53 +0000 |
commit | 4779beea00d6c131705d6fbbc72d907433049e90 (patch) | |
tree | fad31e06ffc27fde3f79abae21956563dc73941c /tools | |
parent | 07119f2310c40b689659642eb80f83cba0b5b1d2 (diff) | |
download | clang-4779beea00d6c131705d6fbbc72d907433049e90.tar.gz |
This reverts commit r227432, r227438 and r227448.
It should bring the bots back.
Original messagses:
r227448:
Remove unnecessary default.
r227438:
Fix Index/print-type.cpp test following r227432.
r227432:
libclang: Add three functions useful for dealing with anonymous fields:
clang_Cursor_getOffsetOfField
clang_Cursor_isAnonymous
clang_Type_visitFields
Python: Add corresponding methods for dealing with anonymous fields.
Patch by Loïc Jaquemet
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@227472 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/c-index-test/c-index-test.c | 59 | ||||
-rw-r--r-- | tools/libclang/CXType.cpp | 75 | ||||
-rw-r--r-- | tools/libclang/libclang.exports | 3 |
3 files changed, 21 insertions, 116 deletions
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index a49f758e8e..56e4101399 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -1250,12 +1250,6 @@ static void PrintTypeAndTypeKind(CXType T, const char *Format) { clang_disposeString(TypeKindSpelling); } -static enum CXVisitorResult FieldVisitor(CXCursor C, - CXClientData client_data) { - (*(int *) client_data)+=1; - return CXVisit_Continue; -} - static enum CXChildVisitResult PrintType(CXCursor cursor, CXCursor p, CXClientData d) { if (!clang_isInvalid(clang_getCursorKind(cursor))) { @@ -1326,22 +1320,6 @@ static enum CXChildVisitResult PrintType(CXCursor cursor, CXCursor p, PrintTypeAndTypeKind(PT, " [pointeetype=%s] [pointeekind=%s]"); } } - /* Print the number of fields if they exist. */ - { - int numFields = 0; - if (clang_Type_visitFields(T, FieldVisitor, &numFields)){ - if (numFields != 0) { - printf(" [nbFields=%d]", numFields); - } - /* Print if it is an anonymous record. */ - { - unsigned isAnon = clang_Cursor_isAnonymous(cursor); - if (isAnon != 0) { - printf(" [isAnon=%d]", isAnon); - } - } - } - } printf("\n"); } @@ -1375,29 +1353,28 @@ static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p, { CXString FieldSpelling = clang_getCursorSpelling(cursor); const char *FieldName = clang_getCString(FieldSpelling); - /* recurse to get the first parent record that is not anonymous. */ - CXCursor Parent, Record; - unsigned RecordIsAnonymous = 0; + /* recurse to get the root anonymous record parent */ + CXCursor Parent, Root; if (clang_getCursorKind(cursor) == CXCursor_FieldDecl) { - Record = Parent = p; + CXString RootParentSpelling; + const char *RootParentName = 0; + Parent = p; do { - Record = Parent; - Parent = clang_getCursorSemanticParent(Record); - RecordIsAnonymous = clang_Cursor_isAnonymous(Record); - /* Recurse as long as the parent is a CXType_Record and the Record - is anonymous */ - } while ( clang_getCursorType(Parent).kind == CXType_Record && - RecordIsAnonymous > 0); + if (RootParentName != 0) + clang_disposeString(RootParentSpelling); + + Root = Parent; + RootParentSpelling = clang_getCursorSpelling(Root); + RootParentName = clang_getCString(RootParentSpelling); + Parent = clang_getCursorSemanticParent(Root); + } while (clang_getCursorType(Parent).kind == CXType_Record && + !strcmp(RootParentName, "")); + clang_disposeString(RootParentSpelling); + /* if RootParentName is "", record is anonymous. */ { - long long Offset = clang_Type_getOffsetOf(clang_getCursorType(Record), + long long Offset = clang_Type_getOffsetOf(clang_getCursorType(Root), FieldName); - long long Offset2 = clang_Cursor_getOffsetOfField(cursor); - if (Offset == Offset2){ - printf(" [offsetof=%lld]", Offset); - } else { - /* Offsets will be different in anonymous records. */ - printf(" [offsetof=%lld/%lld]", Offset, Offset2); - } + printf(" [offsetof=%lld]", Offset); } } clang_disposeString(FieldSpelling); diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp index 94f770c34b..4d526fbd59 100644 --- a/tools/libclang/CXType.cpp +++ b/tools/libclang/CXType.cpp @@ -775,12 +775,13 @@ static long long visitRecordForValidation(const RecordDecl *RD) { return 0; } -static long long validateFieldParentType(CXCursor PC, CXType PT){ +long long clang_Type_getOffsetOf(CXType PT, const char *S) { + // check that PT is not incomplete/dependent + CXCursor PC = clang_getTypeDeclaration(PT); if (clang_isInvalid(PC.kind)) return CXTypeLayoutError_Invalid; const RecordDecl *RD = dyn_cast_or_null<RecordDecl>(cxcursor::getCursorDecl(PC)); - // validate parent declaration if (!RD || RD->isInvalidDecl()) return CXTypeLayoutError_Invalid; RD = RD->getDefinition(); @@ -788,7 +789,6 @@ static long long validateFieldParentType(CXCursor PC, CXType PT){ return CXTypeLayoutError_Incomplete; if (RD->isInvalidDecl()) return CXTypeLayoutError_Invalid; - // validate parent type QualType RT = GetQualType(PT); if (RT->isIncompleteType()) return CXTypeLayoutError_Incomplete; @@ -798,25 +798,12 @@ static long long validateFieldParentType(CXCursor PC, CXType PT){ long long Error = visitRecordForValidation(RD); if (Error < 0) return Error; - return 0; -} - -long long clang_Type_getOffsetOf(CXType PT, const char *S) { - // check that PT is not incomplete/dependent - CXCursor PC = clang_getTypeDeclaration(PT); - long long Error = validateFieldParentType(PC,PT); - if (Error < 0) - return Error; if (!S) return CXTypeLayoutError_InvalidFieldName; // lookup field ASTContext &Ctx = cxtu::getASTUnit(GetTU(PT))->getASTContext(); IdentifierInfo *II = &Ctx.Idents.get(S); DeclarationName FieldName(II); - const RecordDecl *RD = - dyn_cast_or_null<RecordDecl>(cxcursor::getCursorDecl(PC)); - // verified in validateFieldParentType - RD = RD->getDefinition(); RecordDecl::lookup_const_result Res = RD->lookup(FieldName); // If a field of the parent record is incomplete, lookup will fail. // and we would return InvalidFieldName instead of Incomplete. @@ -832,25 +819,6 @@ long long clang_Type_getOffsetOf(CXType PT, const char *S) { return CXTypeLayoutError_InvalidFieldName; } -long long clang_Cursor_getOffsetOfField(CXCursor C) { - if (clang_isDeclaration(C.kind)) { - // we need to validate the parent type - CXCursor PC = clang_getCursorSemanticParent(C); - CXType PT = clang_getCursorType(PC); - long long Error = validateFieldParentType(PC,PT); - if (Error < 0) - return Error; - // proceed with the offset calculation - const Decl *D = cxcursor::getCursorDecl(C); - ASTContext &Ctx = cxcursor::getCursorContext(C); - if (const FieldDecl *FD = dyn_cast_or_null<FieldDecl>(D)) - return Ctx.getFieldOffset(FD); - if (const IndirectFieldDecl *IFD = dyn_cast_or_null<IndirectFieldDecl>(D)) - return Ctx.getFieldOffset(IFD); - } - return -1; -} - enum CXRefQualifierKind clang_Type_getCXXRefQualifier(CXType T) { QualType QT = GetQualType(T); if (QT.isNull()) @@ -940,41 +908,4 @@ CXType clang_Type_getTemplateArgumentAsType(CXType CT, unsigned i) { return MakeCXType(A.getAsType(), GetTU(CT)); } -unsigned clang_Type_visitFields(CXType PT, - CXFieldVisitor visitor, - CXClientData client_data){ - CXCursor PC = clang_getTypeDeclaration(PT); - if (clang_isInvalid(PC.kind)) - return false; - const RecordDecl *RD = - dyn_cast_or_null<RecordDecl>(cxcursor::getCursorDecl(PC)); - if (!RD || RD->isInvalidDecl()) - return false; - RD = RD->getDefinition(); - if (!RD || RD->isInvalidDecl()) - return false; - - for (RecordDecl::field_iterator I = RD->field_begin(), E = RD->field_end(); - I != E; ++I){ - const FieldDecl *FD = dyn_cast_or_null<FieldDecl>((*I)); - // Callback to the client. - switch (visitor(cxcursor::MakeCXCursor(FD, GetTU(PT)), client_data)){ - case CXVisit_Break: - return true; - case CXVisit_Continue: - break; - } - } - return true; -} - -unsigned clang_Cursor_isAnonymous(CXCursor C){ - if (!clang_isDeclaration(C.kind)) - return 0; - const Decl *D = cxcursor::getCursorDecl(C); - if (const RecordDecl *FD = dyn_cast_or_null<RecordDecl>(D)) - return FD->isAnonymousStructOrUnion(); - return 0; -} - } // end: extern "C" diff --git a/tools/libclang/libclang.exports b/tools/libclang/libclang.exports index f78f9981a9..fa2c0e70bf 100644 --- a/tools/libclang/libclang.exports +++ b/tools/libclang/libclang.exports @@ -21,11 +21,9 @@ clang_Cursor_getNumArguments clang_Cursor_getObjCDeclQualifiers clang_Cursor_getObjCPropertyAttributes clang_Cursor_getObjCSelectorIndex -clang_Cursor_getOffsetOfField clang_Cursor_getSpellingNameRange clang_Cursor_getTranslationUnit clang_Cursor_getReceiverType -clang_Cursor_isAnonymous clang_Cursor_isBitField clang_Cursor_isDynamicCall clang_Cursor_isNull @@ -79,7 +77,6 @@ clang_Type_getOffsetOf clang_Type_getNumTemplateArguments clang_Type_getTemplateArgumentAsType clang_Type_getCXXRefQualifier -clang_Type_visitFields clang_VerbatimBlockLineComment_getText clang_VerbatimLineComment_getText clang_HTMLTagComment_getAsString |