#include <stdio.h>
#include <clang-c/Index.h>


const char* cursorSymbol(int cursorKind){
    switch(cursorKind){
    case CXCursor_UnexposedDecl:                      return ":unexposed-decl";
    case CXCursor_StructDecl:                         return ":struct-decl";
    case CXCursor_UnionDecl:                          return ":union-decl";
    case CXCursor_ClassDecl:                          return ":class-decl";
    case CXCursor_EnumDecl:                           return ":enum-decl";
    case CXCursor_FieldDecl:                          return ":field-decl";
    case CXCursor_EnumConstantDecl:                   return ":enum-constant-decl";
    case CXCursor_FunctionDecl:                       return ":function-decl";
    case CXCursor_VarDecl:                            return ":var-decl";
    case CXCursor_ParmDecl:                           return ":parm-decl";
    case CXCursor_ObjCInterfaceDecl:                  return ":objc-interface-decl";
    case CXCursor_ObjCCategoryDecl:                   return ":objc-category-decl";
    case CXCursor_ObjCProtocolDecl:                   return ":objc-protocol-decl";
    case CXCursor_ObjCPropertyDecl:                   return ":objc-property-decl";
    case CXCursor_ObjCIvarDecl:                       return ":objc-ivar-decl";
    case CXCursor_ObjCInstanceMethodDecl:             return ":objc-instance-method-decl";
    case CXCursor_ObjCClassMethodDecl:                return ":objc-class-method-decl";
    case CXCursor_ObjCImplementationDecl:             return ":objc-implementation-decl";
    case CXCursor_ObjCCategoryImplDecl:               return ":objc-category-impl-decl";
    case CXCursor_TypedefDecl:                        return ":typedef-decl";
    case CXCursor_CXXMethod:                          return ":cxx-method";
    case CXCursor_Namespace:                          return ":namespace";
    case CXCursor_LinkageSpec:                        return ":linkage-spec";
    case CXCursor_Constructor:                        return ":constructor";
    case CXCursor_Destructor:                         return ":destructor";
    case CXCursor_ConversionFunction:                 return ":conversion-function";
    case CXCursor_TemplateTypeParameter:              return ":template-type-parameter";
    case CXCursor_NonTypeTemplateParameter:           return ":non-type-template-parameter";
    case CXCursor_TemplateTemplateParameter:          return ":template-template-parameter";
    case CXCursor_FunctionTemplate:                   return ":function-template";
    case CXCursor_ClassTemplate:                      return ":class-template";
    case CXCursor_ClassTemplatePartialSpecialization: return ":class-template-partial-specialization";
    case CXCursor_NamespaceAlias:                     return ":namespace-alias";
    case CXCursor_UsingDirective:                     return ":using-directive";
    case CXCursor_UsingDeclaration:                   return ":using-declaration";
    case CXCursor_TypeAliasDecl:                      return ":type-alias-decl";
    case CXCursor_ObjCSynthesizeDecl:                 return ":objc-synthesize-decl";
    case CXCursor_ObjCDynamicDecl:                    return ":objc-dynamic-decl";
    case CXCursor_CXXAccessSpecifier:                 return ":cxx-access-specifier";
    case CXCursor_ObjCSuperClassRef:                  return ":objc-super-class-ref";
    case CXCursor_ObjCProtocolRef:                    return ":objc-protocol-ref";
    case CXCursor_ObjCClassRef:                       return ":objc-class-ref";
    case CXCursor_TypeRef:                            return ":type-ref";
    case CXCursor_CXXBaseSpecifier:                   return ":cxx-base-specifier";
    case CXCursor_TemplateRef:                        return ":template-ref";
    case CXCursor_NamespaceRef:                       return ":namespace-ref";
    case CXCursor_MemberRef:                          return ":member-ref";
    case CXCursor_LabelRef:                           return ":label-ref";
    case CXCursor_OverloadedDeclRef:                  return ":overloaded-decl-ref";
    case CXCursor_VariableRef:                        return ":variable-ref";
    case CXCursor_InvalidFile:                        return ":invalid-file";
    case CXCursor_NoDeclFound:                        return ":no-decl-found";
    case CXCursor_NotImplemented:                     return ":not-implemented";
    case CXCursor_InvalidCode:                        return ":invalid-code";
    case CXCursor_UnexposedExpr:                      return ":unexposed-expr";
    case CXCursor_DeclRefExpr:                        return ":decl-ref-expr";
    case CXCursor_MemberRefExpr:                      return ":member-ref-expr";
    case CXCursor_CallExpr:                           return ":call-expr";
    case CXCursor_ObjCMessageExpr:                    return ":objc-message-expr";
    case CXCursor_BlockExpr:                          return ":block-expr";
    case CXCursor_IntegerLiteral:                     return ":integer-literal";
    case CXCursor_FloatingLiteral:                    return ":floating-literal";
    case CXCursor_ImaginaryLiteral:                   return ":imaginary-literal";
    case CXCursor_StringLiteral:                      return ":string-literal";
    case CXCursor_CharacterLiteral:                   return ":character-literal";
    case CXCursor_ParenExpr:                          return ":paren-expr";
    case CXCursor_UnaryOperator:                      return ":unary-operator";
    case CXCursor_ArraySubscriptExpr:                 return ":array-subscript-expr";
    case CXCursor_BinaryOperator:                     return ":binary-operator";
    case CXCursor_CompoundAssignOperator:             return ":compound-assign-operator";
    case CXCursor_ConditionalOperator:                return ":conditional-operator";
    case CXCursor_CStyleCastExpr:                     return ":cstyle-cast-expr";
    case CXCursor_CompoundLiteralExpr:                return ":compound-literal-expr";
    case CXCursor_InitListExpr:                       return ":init-list-expr";
    case CXCursor_AddrLabelExpr:                      return ":addr-label-expr";
    case CXCursor_StmtExpr:                           return ":stmt-expr";
    case CXCursor_GenericSelectionExpr:               return ":generic-selection-expr";
    case CXCursor_GNUNullExpr:                        return ":gnunull-expr";
    case CXCursor_CXXStaticCastExpr:                  return ":cxx-static-cast-expr";
    case CXCursor_CXXDynamicCastExpr:                 return ":cxx-dynamic-cast-expr";
    case CXCursor_CXXReinterpretCastExpr:             return ":cxx-reinterpret-cast-expr";
    case CXCursor_CXXConstCastExpr:                   return ":cxx-const-cast-expr";
    case CXCursor_CXXFunctionalCastExpr:              return ":cxx-functional-cast-expr";
    case CXCursor_CXXTypeidExpr:                      return ":cxx-typeid-expr";
    case CXCursor_CXXBoolLiteralExpr:                 return ":cxx-bool-literal-expr";
    case CXCursor_CXXNullPtrLiteralExpr:              return ":cxx-null-ptr-literal-expr";
    case CXCursor_CXXThisExpr:                        return ":cxx-this-expr";
    case CXCursor_CXXThrowExpr:                       return ":cxx-throw-expr";
    case CXCursor_CXXNewExpr:                         return ":cxx-new-expr";
    case CXCursor_CXXDeleteExpr:                      return ":cxx-delete-expr";
    case CXCursor_UnaryExpr:                          return ":unary-expr";
    case CXCursor_ObjCStringLiteral:                  return ":objc-string-literal";
    case CXCursor_ObjCEncodeExpr:                     return ":objc-encode-expr";
    case CXCursor_ObjCSelectorExpr:                   return ":objc-selector-expr";
    case CXCursor_ObjCProtocolExpr:                   return ":objc-protocol-expr";
    case CXCursor_ObjCBridgedCastExpr:                return ":objc-bridged-cast-expr";
    case CXCursor_PackExpansionExpr:                  return ":pack-expansion-expr";
    case CXCursor_SizeOfPackExpr:                     return ":size-of-pack-expr";
    case CXCursor_LambdaExpr:                         return ":lambda-expr";
    case CXCursor_ObjCBoolLiteralExpr:                return ":objc-bool-literal-expr";
    case CXCursor_UnexposedStmt:                      return ":unexposed-stmt";
    case CXCursor_LabelStmt:                          return ":label-stmt";
    case CXCursor_CompoundStmt:                       return ":compound-stmt";
    case CXCursor_CaseStmt:                           return ":case-stmt";
    case CXCursor_DefaultStmt:                        return ":default-stmt";
    case CXCursor_IfStmt:                             return ":if-stmt";
    case CXCursor_SwitchStmt:                         return ":switch-stmt";
    case CXCursor_WhileStmt:                          return ":while-stmt";
    case CXCursor_DoStmt:                             return ":do-stmt";
    case CXCursor_ForStmt:                            return ":for-stmt";
    case CXCursor_GotoStmt:                           return ":goto-stmt";
    case CXCursor_IndirectGotoStmt:                   return ":indirect-goto-stmt";
    case CXCursor_ContinueStmt:                       return ":continue-stmt";
    case CXCursor_BreakStmt:                          return ":break-stmt";
    case CXCursor_ReturnStmt:                         return ":return-stmt";
    case CXCursor_GCCAsmStmt:                         return ":gccasm-stmt";
    case CXCursor_ObjCAtTryStmt:                      return ":objc-at-try-stmt";
    case CXCursor_ObjCAtCatchStmt:                    return ":objc-at-catch-stmt";
    case CXCursor_ObjCAtFinallyStmt:                  return ":objc-at-finally-stmt";
    case CXCursor_ObjCAtThrowStmt:                    return ":objc-at-throw-stmt";
    case CXCursor_ObjCAtSynchronizedStmt:             return ":objc-at-synchronized-stmt";
    case CXCursor_ObjCAutoreleasePoolStmt:            return ":objc-autorelease-pool-stmt";
    case CXCursor_ObjCForCollectionStmt:              return ":objc-for-collection-stmt";
    case CXCursor_CXXCatchStmt:                       return ":cxx-catch-stmt";
    case CXCursor_CXXTryStmt:                         return ":cxx-try-stmt";
    case CXCursor_CXXForRangeStmt:                    return ":cxx-for-range-stmt";
    case CXCursor_SEHTryStmt:                         return ":seh-try-stmt";
    case CXCursor_SEHExceptStmt:                      return ":seh-except-stmt";
    case CXCursor_SEHFinallyStmt:                     return ":seh-finally-stmt";
    case CXCursor_MSAsmStmt:                          return ":msasm-stmt";
    case CXCursor_NullStmt:                           return ":null-stmt";
    case CXCursor_DeclStmt:                           return ":decl-stmt";
    case CXCursor_TranslationUnit:                    return ":translation-unit";
    case CXCursor_UnexposedAttr:                      return ":unexposed-attr";
    case CXCursor_IBActionAttr:                       return ":ibaction-attr";
    case CXCursor_IBOutletAttr:                       return ":iboutlet-attr";
    case CXCursor_IBOutletCollectionAttr:             return ":iboutlet-collection-attr";
    case CXCursor_CXXFinalAttr:                       return ":cxx-final-attr";
    case CXCursor_CXXOverrideAttr:                    return ":cxx-override-attr";
    case CXCursor_AnnotateAttr:                       return ":annotate-attr";
    case CXCursor_AsmLabelAttr:                       return ":asm-label-attr";
    case CXCursor_PreprocessingDirective:             return ":preprocessing-directive";
    case CXCursor_MacroDefinition:                    return ":macro-definition";
    case CXCursor_MacroExpansion:                     return ":macro-expansion";
    case CXCursor_InclusionDirective:                 return ":inclusion-directive";
    case CXCursor_ModuleImportDecl:                   return ":module-import-decl";
    default:                                          return ":invalid";}}


const char* cursorLinkage(int linkageKind){
    switch(linkageKind){
    case CXLinkage_NoLinkage:      return ":no-linkage";
    case CXLinkage_Internal:       return ":internal";
    case CXLinkage_UniqueExternal: return ":unique-external";
    case CXLinkage_External:       return ":external";
    default:                       return ":invalid";}}


const char* cursorLanguageKind(int languageKind){
    switch(languageKind){
    case CXLanguage_Invalid:   return ":invalid";
    case CXLanguage_C:         return ":c";
    case CXLanguage_ObjC:      return ":objc";
    case CXLanguage_CPlusPlus: return ":cxx"
    default:                   return ":invalid";}}


int main(int argc,char** argv){
    printf("%d argc\n",argc);
    return(0);
    if(argc<2){
        fprintf(stderr,"Missing source file argument.\n");
        return(1);}

    const char* sourceFile=argv[1];
    argv+=2;
    argc-=2;

    CXIndex idx=clang_createIndex(0,1);
    CXTranslationUnit tu=clang_createTranslationUnitFromSourceFile(idx,sourceFile,argc,argv,0,0);
    if(0==tu){
        fprintf(stderr,"Cannot create the translation unit.");
        return(1);}

    CXCursor cursor=clang_getTranslationUnitCursor(tu);
    if(clang_Cursor_isNull(cursor)){
        printf("nil\n");
    }else{
        printf("(%s",cursorSymbol(clang_getCursorKind(cursor)));
        printf("\n :linkage %s",cursorLinkage(clang_getCursorLinkage(cursor)));
        printf("\n :language-kind %s",cursorLanguageKind(clang_getCursorLanguage(cursor)));

        CXSourceLocation location=clang_getCursorLocation(cursor);
        CXFile file;
        unsigned line;
        unsigned column;
        unsigned offset;

        clang_getSpellingLocation(location,&file,&line,&column,&offset)
        CXString fileName=clang_getFileName(file);
        printf("\n :location (location :file \"%s\" :line %u :column %u :offset %u)",clang_getCString(fileName),line,column,offset);
        clang_disposeString(fileName);

        CXSourceRange range=clang_getCursorExtent(cursor);
        CXSourceLocation start=clang_getRangeStart(range);
        CXSourceLocation end=clang_getRangeEnd(range);

        clang_getSpellingLocation(start,&file,&line,&column,&offset)
        CXString fileName=clang_getFileName(file);
        printf("\n :range (range :start (location :file \"%s\" :line %u :column %u :offset %u)",clang_getCString(fileName),line,column,offset);
        clang_disposeString(fileName);

        clang_getSpellingLocation(end,&file,&line,&column,&offset)
        CXString fileName=clang_getFileName(file);
        printf("\n                :end (location :file \"%s\" :line %u :column %u :offset %u))",clang_getCString(fileName),line,column,offset);
        clang_disposeString(fileName);




        printf(")\n");
    }
    clang_disposeTranslationUnit(tu);
    return(0);}
ViewGit