<commit_before>/* c-index-test.c */

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

static void PrintCursor(CXCursor Cursor) {
  if (clang_isInvalid(Cursor.kind))
    printf("Invalid Cursor => %s\n", clang_getCursorKindSpelling(Cursor.kind));
  else
    printf("%s => %s ", clang_getCursorKindSpelling(Cursor.kind),
                        clang_getCursorSpelling(Cursor));
}

static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter) 
{
  if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
    PrintCursor(Cursor);
    printf("(Context: %s", clang_getDeclSpelling(Dcl));
    printf(" Source:  %s (%d:%d))\n", clang_getCursorSource(Cursor),
                                      clang_getCursorLine(Cursor),
                                      clang_getCursorColumn(Cursor));
  }
}
static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor,
                                   CXClientData Filter) 
{
  if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
    PrintCursor(Cursor);
    printf("(Context: %s", clang_getTranslationUnitSpelling(Unit));
    printf(" Source:  %s (%d:%d))\n", clang_getCursorSource(Cursor),
                                      clang_getCursorLine(Cursor),
                                      clang_getCursorColumn(Cursor));

    if (Cursor.kind == CXCursor_FunctionDefn) {
      const char *startBuf, *endBuf;
      unsigned startLine, startColumn, endLine, endColumn;
      clang_getDefinitionSpellingAndExtent(Cursor, &startBuf, &endBuf,
                                           &startLine, &startColumn,
                                           &endLine, &endColumn);
      /* Probe the entire body, looking for "refs". */
      unsigned curLine = startLine, curColumn = startColumn;
      while (startBuf <= endBuf) {
        if (*startBuf == '\n') {
          startBuf++;
          curLine++;
          curColumn = 1;
        }
        CXCursor Ref = clang_getCursor(Unit, clang_getCursorSource(Cursor), 
                                       curLine, curColumn);
        if (Ref.kind != CXCursor_FunctionDecl) {
          PrintCursor(Ref);
          printf("(Context: %s", clang_getDeclSpelling(Ref.decl));
          printf(" Source:  %s (%d:%d))\n", clang_getCursorSource(Ref),
                                            curLine, curColumn);
        }
        startBuf++;
        curColumn++;
      }
    }
    clang_loadDeclaration(Cursor.decl, DeclVisitor, 0);
  }
}

/*
 * First sign of life:-)
 */
int main(int argc, char **argv) {
  CXIndex Idx = clang_createIndex();
  CXTranslationUnit TU = clang_createTranslationUnit(Idx, argv[1]);

  if (argc == 2) {
    /* malloc - returns a cursor of type CXCursor_FunctionDecl */
    CXCursor C = clang_getCursor(TU, "/usr/include/stdlib.h", 169, 7);
    PrintCursor(C);
    /* methodSignature - returns a cursor of type ObjCInstanceMethodDecl */
    C = clang_getCursor(TU, "/System/Library/Frameworks/Foundation.framework/Headers/NSInvocation.h", 22, 1);
    PrintCursor(C);
    C = clang_getCursor(TU, "Large.m", 5, 18);
    PrintCursor(C);
  } else if (argc == 3) {
    enum CXCursorKind K = CXCursor_NotImplemented;
    
    if (!strcmp(argv[2], "all")) {
      clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
      return 1;
    } 
    if (!strcmp(argv[2], "category")) K = CXCursor_ObjCCategoryDecl;
    else if (!strcmp(argv[2], "interface")) K = CXCursor_ObjCInterfaceDecl;
    else if (!strcmp(argv[2], "protocol")) K = CXCursor_ObjCProtocolDecl;
    else if (!strcmp(argv[2], "function")) K = CXCursor_FunctionDecl;
    else if (!strcmp(argv[2], "typedef")) K = CXCursor_TypedefDecl;
    
    clang_loadTranslationUnit(TU, TranslationUnitVisitor, &K);
  }
  return 1;
}<commit_msg>Some minor cleanups...<commit_after>/* c-index-test.c */

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

static void PrintCursor(CXCursor Cursor) {
  if (clang_isInvalid(Cursor.kind))
    printf("Invalid Cursor => %s\n", clang_getCursorKindSpelling(Cursor.kind));
  else
    printf("%s => %s ", clang_getCursorKindSpelling(Cursor.kind),
                        clang_getCursorSpelling(Cursor));
}

static void DeclVisitor(CXDecl Dcl, CXCursor Cursor, CXClientData Filter) 
{
  if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
    PrintCursor(Cursor);
    printf("(Context: %s", clang_getDeclSpelling(Dcl));
    printf(" Source:  %s (%d:%d))\n", clang_getCursorSource(Cursor),
                                      clang_getCursorLine(Cursor),
                                      clang_getCursorColumn(Cursor));
  }
}
static void TranslationUnitVisitor(CXTranslationUnit Unit, CXCursor Cursor,
                                   CXClientData Filter) 
{
  if (!Filter || (Cursor.kind == *(enum CXCursorKind *)Filter)) {
    PrintCursor(Cursor);
    printf("(Context: %s", clang_getTranslationUnitSpelling(Unit));
    printf(" Source:  %s (%d:%d))\n", clang_getCursorSource(Cursor),
                                      clang_getCursorLine(Cursor),
                                      clang_getCursorColumn(Cursor));

    if (Cursor.kind == CXCursor_FunctionDefn) {
      const char *startBuf, *endBuf;
      unsigned startLine, startColumn, endLine, endColumn;
      clang_getDefinitionSpellingAndExtent(Cursor, &startBuf, &endBuf,
                                           &startLine, &startColumn,
                                           &endLine, &endColumn);
      {
        /* Probe the entire body, looking for both decls and refs. */
        unsigned curLine = startLine, curColumn = startColumn;
        CXCursor Ref;
        
        while (startBuf <= endBuf) {
          if (*startBuf == '\n') {
            startBuf++;
            curLine++;
            curColumn = 1;
          } else if (*startBuf != '\t')
            curColumn++;
        
          Ref = clang_getCursor(Unit, clang_getCursorSource(Cursor), 
                                curLine, curColumn);
          if (Ref.kind != CXCursor_FunctionDecl) {
            PrintCursor(Ref);
            printf("(Context: %s", clang_getDeclSpelling(Ref.decl));
            printf(" Source:  %s (%d:%d))\n", clang_getCursorSource(Ref),
                                              curLine, curColumn);
          }
          startBuf++;
        }
      }
    }
    clang_loadDeclaration(Cursor.decl, DeclVisitor, 0);
  }
}

/*
 * First sign of life:-)
 */
int main(int argc, char **argv) {
  if (argc != 3) {
    printf("Incorrect usage of c-index-test (requires 3 arguments)\n");
    return 0;
  }
  {
  CXIndex Idx = clang_createIndex();
  CXTranslationUnit TU = clang_createTranslationUnit(Idx, argv[1]);
  enum CXCursorKind K = CXCursor_NotImplemented;
  
  if (!strcmp(argv[2], "all")) {
    clang_loadTranslationUnit(TU, TranslationUnitVisitor, 0);
    return 1;
  } 
  /* Perform some simple filtering. */
  if (!strcmp(argv[2], "category")) K = CXCursor_ObjCCategoryDecl;
  else if (!strcmp(argv[2], "interface")) K = CXCursor_ObjCInterfaceDecl;
  else if (!strcmp(argv[2], "protocol")) K = CXCursor_ObjCProtocolDecl;
  else if (!strcmp(argv[2], "function")) K = CXCursor_FunctionDecl;
  else if (!strcmp(argv[2], "typedef")) K = CXCursor_TypedefDecl;
  
  clang_loadTranslationUnit(TU, TranslationUnitVisitor, &K);
  return 1;
  }
}
{'fraction_non_alphanumeric': 0.1296448087431694, 'fraction_numerical': 0.005327868852459016, 'mean_word_length': 2.441937000470146, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 23, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4533880', 'n_tokens_mistral': 2275, 'n_tokens_neox': 2168, 'n_words': 468}