diff options
Diffstat (limited to 'tools/c-index-test')
-rw-r--r-- | tools/c-index-test/c-index-test.c | 130 | ||||
-rw-r--r-- | tools/c-index-test/core_main.cpp | 30 |
2 files changed, 144 insertions, 16 deletions
diff --git a/tools/c-index-test/c-index-test.c b/tools/c-index-test/c-index-test.c index 70ab11866edd5..fc6ba46fd6f2a 100644 --- a/tools/c-index-test/c-index-test.c +++ b/tools/c-index-test/c-index-test.c @@ -84,6 +84,10 @@ static unsigned getDefaultParsingOptions() { options |= CXTranslationUnit_KeepGoing; if (getenv("CINDEXTEST_LIMIT_SKIP_FUNCTION_BODIES_TO_PREAMBLE")) options |= CXTranslationUnit_LimitSkipFunctionBodiesToPreamble; + if (getenv("CINDEXTEST_INCLUDE_ATTRIBUTED_TYPES")) + options |= CXTranslationUnit_IncludeAttributedTypes; + if (getenv("CINDEXTEST_VISIT_IMPLICIT_ATTRIBUTES")) + options |= CXTranslationUnit_VisitImplicitAttributes; return options; } @@ -1099,6 +1103,34 @@ static void PrintCursor(CXCursor Cursor, const char *CommentSchemaFile) { } } + if (Cursor.kind == CXCursor_ObjCPropertyDecl) { + CXString Name = clang_Cursor_getObjCPropertyGetterName(Cursor); + CXString Spelling = clang_getCursorSpelling(Cursor); + const char *CName = clang_getCString(Name); + const char *CSpelling = clang_getCString(Spelling); + if (CName && strcmp(CName, CSpelling)) { + printf(" (getter=%s)", CName); + } + clang_disposeString(Spelling); + clang_disposeString(Name); + } + + if (Cursor.kind == CXCursor_ObjCPropertyDecl) { + CXString Name = clang_Cursor_getObjCPropertySetterName(Cursor); + CXString Spelling = clang_getCursorSpelling(Cursor); + const char *CName = clang_getCString(Name); + const char *CSpelling = clang_getCString(Spelling); + char *DefaultSetter = malloc(strlen(CSpelling) + 5); + sprintf(DefaultSetter, "set%s:", CSpelling); + DefaultSetter[3] &= ~(1 << 5); /* Make uppercase */ + if (CName && strcmp(CName, DefaultSetter)) { + printf(" (setter=%s)", CName); + } + free(DefaultSetter); + clang_disposeString(Spelling); + clang_disposeString(Name); + } + { unsigned QT = clang_Cursor_getObjCDeclQualifiers(Cursor); if (QT != CXObjCDeclQualifier_None) { @@ -1496,13 +1528,31 @@ static void PrintTypeTemplateArgs(CXType T, const char *Format) { } } +static void PrintNullabilityKind(CXType T, const char *Format) { + enum CXTypeNullabilityKind N = clang_Type_getNullability(T); + + const char *nullability = 0; + switch (N) { + case CXTypeNullability_NonNull: nullability = "nonnull"; break; + case CXTypeNullability_Nullable: nullability = "nullable"; break; + case CXTypeNullability_Unspecified: nullability = "unspecified"; break; + case CXTypeNullability_Invalid: break; + } + + if (nullability) { + printf(Format, nullability); + } +} + static enum CXChildVisitResult PrintType(CXCursor cursor, CXCursor p, CXClientData d) { if (!clang_isInvalid(clang_getCursorKind(cursor))) { CXType T = clang_getCursorType(cursor); + CXType PT = clang_getPointeeType(T); enum CXRefQualifierKind RQ = clang_Type_getCXXRefQualifier(T); PrintCursor(cursor, NULL); PrintTypeAndTypeKind(T, " [type=%s] [typekind=%s]"); + PrintNullabilityKind(T, " [nullability=%s]"); if (clang_isConstQualifiedType(T)) printf(" const"); if (clang_isVolatileQualifiedType(T)) @@ -1523,12 +1573,20 @@ static enum CXChildVisitResult PrintType(CXCursor cursor, CXCursor p, PrintTypeTemplateArgs(CT, " [canonicaltemplateargs/%d="); } } + /* Print the modified type if it exists. */ + { + CXType MT = clang_Type_getModifiedType(T); + if (MT.kind != CXType_Invalid) { + PrintTypeAndTypeKind(MT, " [modifiedtype=%s] [modifiedtypekind=%s]"); + } + } /* Print the return type if it exists. */ { CXType RT = clang_getCursorResultType(cursor); if (RT.kind != CXType_Invalid) { PrintTypeAndTypeKind(RT, " [resulttype=%s] [resulttypekind=%s]"); } + PrintNullabilityKind(RT, " [resultnullability=%s]"); } /* Print the argument types if they exist. */ { @@ -1540,6 +1598,42 @@ static enum CXChildVisitResult PrintType(CXCursor cursor, CXCursor p, CXType T = clang_getCursorType(clang_Cursor_getArgument(cursor, i)); if (T.kind != CXType_Invalid) { PrintTypeAndTypeKind(T, " [%s] [%s]"); + PrintNullabilityKind(T, " [%s]"); + } + } + printf("]"); + } + } + /* Print ObjC base types, type arguments, and protocol list if available. */ + { + CXType BT = clang_Type_getObjCObjectBaseType(PT); + if (BT.kind != CXType_Invalid) { + PrintTypeAndTypeKind(BT, " [basetype=%s] [basekind=%s]"); + } + } + { + unsigned NumTypeArgs = clang_Type_getNumObjCTypeArgs(PT); + if (NumTypeArgs > 0) { + unsigned i; + printf(" [typeargs="); + for (i = 0; i < NumTypeArgs; ++i) { + CXType TA = clang_Type_getObjCTypeArg(PT, i); + if (TA.kind != CXType_Invalid) { + PrintTypeAndTypeKind(TA, " [%s] [%s]"); + } + } + printf("]"); + } + } + { + unsigned NumProtocols = clang_Type_getNumObjCProtocolRefs(PT); + if (NumProtocols > 0) { + unsigned i; + printf(" [protocols="); + for (i = 0; i < NumProtocols; ++i) { + CXCursor P = clang_Type_getObjCProtocolDecl(PT, i); + if (!clang_isInvalid(clang_getCursorKind(P))) { + PrintCursor(P, NULL); } } printf("]"); @@ -1549,7 +1643,6 @@ static enum CXChildVisitResult PrintType(CXCursor cursor, CXCursor p, printf(" [isPOD=%d]", clang_isPODType(T)); /* Print the pointee type. */ { - CXType PT = clang_getPointeeType(T); if (PT.kind != CXType_Invalid) { PrintTypeAndTypeKind(PT, " [pointeetype=%s] [pointeekind=%s]"); } @@ -1561,13 +1654,14 @@ static enum CXChildVisitResult PrintType(CXCursor cursor, CXCursor p, 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); - } - } + } + } + + /* Print if it is an anonymous record or namespace. */ + { + unsigned isAnon = clang_Cursor_isAnonymous(cursor); + if (isAnon != 0) { + printf(" [isAnon=%d]", isAnon); } } @@ -1720,6 +1814,23 @@ static enum CXChildVisitResult PrintTypeDeclaration(CXCursor cursor, CXCursor p, } /******************************************************************************/ +/* Declaration attributes testing */ +/******************************************************************************/ + +static enum CXChildVisitResult PrintDeclAttributes(CXCursor cursor, CXCursor p, + CXClientData d) { + if (clang_isDeclaration(cursor.kind)) { + printf("\n"); + PrintCursor(cursor, NULL); + return CXChildVisit_Recurse; + } else if (clang_isAttribute(cursor.kind)) { + printf(" "); + PrintCursor(cursor, NULL); + } + return CXChildVisit_Continue; +} + +/******************************************************************************/ /* Target information testing. */ /******************************************************************************/ @@ -4730,6 +4841,9 @@ int cindextest_main(int argc, const char **argv) { else if (argc > 2 && strcmp(argv[1], "-test-print-type-declaration") == 0) return perform_test_load_source(argc - 2, argv + 2, "all", PrintTypeDeclaration, 0); + else if (argc > 2 && strcmp(argv[1], "-test-print-decl-attributes") == 0) + return perform_test_load_source(argc - 2, argv + 2, "all", + PrintDeclAttributes, 0); else if (argc > 2 && strcmp(argv[1], "-test-print-bitwidth") == 0) return perform_test_load_source(argc - 2, argv + 2, "all", PrintBitWidth, 0); diff --git a/tools/c-index-test/core_main.cpp b/tools/c-index-test/core_main.cpp index a7732c09d5b08..b9c0f19a7fccb 100644 --- a/tools/c-index-test/core_main.cpp +++ b/tools/c-index-test/core_main.cpp @@ -20,6 +20,7 @@ #include "clang/Lex/Preprocessor.h" #include "clang/Serialization/ASTReader.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Signals.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/PrettyStackTrace.h" @@ -73,6 +74,7 @@ static cl::opt<std::string> static void printSymbolInfo(SymbolInfo SymInfo, raw_ostream &OS); static void printSymbolNameAndUSR(const Decl *D, ASTContext &Ctx, raw_ostream &OS); +static void printSymbolNameAndUSR(const clang::Module *Mod, raw_ostream &OS); namespace { @@ -131,8 +133,9 @@ public: return true; } - bool handleModuleOccurence(const ImportDecl *ImportD, SymbolRoleSet Roles, - SourceLocation Loc) override { + bool handleModuleOccurence(const ImportDecl *ImportD, + const clang::Module *Mod, + SymbolRoleSet Roles, SourceLocation Loc) override { ASTContext &Ctx = ImportD->getASTContext(); SourceManager &SM = Ctx.getSourceManager(); @@ -145,7 +148,8 @@ public: printSymbolInfo(getSymbolInfo(ImportD), OS); OS << " | "; - OS << ImportD->getImportedModule()->getFullModuleName() << " | "; + printSymbolNameAndUSR(Mod, OS); + OS << " | "; printSymbolRoles(Roles, OS); OS << " |\n"; @@ -202,11 +206,11 @@ static void dumpModuleFileInputs(serialization::ModuleFile &Mod, }); } -static bool printSourceSymbols(ArrayRef<const char *> Args, - bool dumpModuleImports, - bool indexLocals) { +static bool printSourceSymbols(const char *Executable, + ArrayRef<const char *> Args, + bool dumpModuleImports, bool indexLocals) { SmallVector<const char *, 4> ArgsWithProgName; - ArgsWithProgName.push_back("clang"); + ArgsWithProgName.push_back(Executable); ArgsWithProgName.append(Args.begin(), Args.end()); IntrusiveRefCntPtr<DiagnosticsEngine> Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions)); @@ -307,6 +311,12 @@ static void printSymbolNameAndUSR(const Decl *D, ASTContext &Ctx, } } +static void printSymbolNameAndUSR(const clang::Module *Mod, raw_ostream &OS) { + assert(Mod); + OS << Mod->getFullModuleName() << " | "; + generateFullUSRForModule(Mod, OS); +} + //===----------------------------------------------------------------------===// // Command line processing. //===----------------------------------------------------------------------===// @@ -314,6 +324,8 @@ static void printSymbolNameAndUSR(const Decl *D, ASTContext &Ctx, int indextest_core_main(int argc, const char **argv) { sys::PrintStackTraceOnErrorSignal(argv[0]); PrettyStackTraceProgram X(argc, argv); + void *MainAddr = (void*) (intptr_t) indextest_core_main; + std::string Executable = llvm::sys::fs::getMainExecutable(argv[0], MainAddr); assert(argv[1] == StringRef("core")); ++argv; @@ -343,7 +355,9 @@ int indextest_core_main(int argc, const char **argv) { errs() << "error: missing compiler args; pass '-- <compiler arguments>'\n"; return 1; } - return printSourceSymbols(CompArgs, options::DumpModuleImports, options::IncludeLocals); + return printSourceSymbols(Executable.c_str(), CompArgs, + options::DumpModuleImports, + options::IncludeLocals); } return 0; |