<commit_before>// cc_flags.cc            see license.txt for copyright and terms of use
// code for cc_flags.h

#include "cc_flags.h"     // this module
#include "macros.h"       // STATIC_ASSERT
#include "xassert.h"      // xassert
#include "trace.h"        // tracingSys


// -------------------- TypeIntr -------------------------
char const * const typeIntrNames[NUM_TYPEINTRS] = {
  "struct",
  "class",
  "union",
  "enum"
};

#define MAKE_TOSTRING(T, limit, array)        \
  string toString(T index)                    \
  {                                           \
    xassert((unsigned)index < limit);         \
    return string(array[index]);              \
  }

MAKE_TOSTRING(TypeIntr, NUM_TYPEINTRS, typeIntrNames)


// ---------------- CVFlags -------------
#ifdef MLVALUE
MAKE_ML_TAG(attribute, 0, AId)
MAKE_ML_TAG(attribute, 1, ACons)

MLValue cvToMLAttrs(CVFlags cv)
{
  // AId of string

  MLValue list = mlNil();
  if (cv & CV_CONST) {
    list = mlCons(mlTuple1(attribute_AId, mlString("const")), list);
  }
  if (cv & CV_VOLATILE) {
    list = mlCons(mlTuple1(attribute_AId, mlString("volatile")), list);
  }
  if (cv & CV_OWNER) {
    list = mlCons(mlTuple1(attribute_AId, mlString("owner")), list);
  }
  return list;
}
#endif // MLVALUE


char const * const cvFlagNames[NUM_CVFLAGS] = {
  "const",
  "volatile",
  "owner"
};


string bitmapString(int bitmap, char const * const *names, int numflags)
{
  stringBuilder sb;
  int count=0;
  for (int i=0; i<numflags; i++) {
    if (bitmap & (1 << i)) {
      if (count++) {
        sb << " ";
      }
      sb << names[i];
    }
  }

  return sb;
}

string toString(CVFlags cv)
{
  return bitmapString(cv >> CV_SHIFT_AMOUNT, cvFlagNames, NUM_CVFLAGS);
}


// ------------------- DeclFlags --------------
char const * const declFlagNames[NUM_DECLFLAGS] = {
  "auto",           // 0
  "register",
  "static",
  "extern",
  "mutable",        // 4
  "inline",
  "virtual",
  "explicit",
  "friend",
  "typedef",        // 9

  "<enumerator>",
  "<global>",
  "<initialized>",
  "<builtin>",
  "<logic>",        // 14
  "<addrtaken>",
  "<parameter>",
  "<universal>",
  "<existential>",
  "<member>",       // 19
  "<definition>",
  "<inline_defn>",
  "<implicit>",
  "<forward>",

  "<predicate>",    // 24
};


string toString(DeclFlags df)
{ 
  // make sure I haven't added a flag without adding a string for it
  xassert(declFlagNames[NUM_DECLFLAGS-1] != NULL);

  return bitmapString(df, declFlagNames, NUM_DECLFLAGS);
}


// ---------------------- SimpleTypeId --------------------------
bool isValid(SimpleTypeId id)
{
  return 0 <= id && id <= NUM_SIMPLE_TYPES;
}


static SimpleTypeInfo const simpleTypeInfoArray[] = {
  //name                   size  int?    float?
  { "char",                1,    true,   false, },
  { "unsigned char",       1,    true,   false, },
  { "signed char",         1,    true,   false, },
  { "bool",                4,    false,  false, },
  { "int",                 4,    true,   false, },
  { "unsigned int",        4,    true,   false, },
  { "long int",            4,    true,   false, },
  { "unsigned long int",   4,    true,   false, },
  { "long long",           8,    true,   false, },
  { "unsigned long long",  8,    true,   false, },
  { "short int",           2,    true,   false, },
  { "unsigned short int",  2,    true,   false, },
  { "wchar_t",             2,    true,   false, },
  { "float",               4,    false,  true,  },
  { "double",              8,    false,  true,  },
  { "long double",         10,   false,  true,  },
  { "void",                1,    false,  false, },    // gnu: sizeof(void) is 1
  { "...",                 0,    false,  false, },
  { "/*cdtor*/",           0,    false,  false, },    // dsw: don't want to print <cdtor>
  { "<error>",             0,    false,  false, },
  { "<dependent>",         0,    false,  false, },
};
<commit_msg>In simpleTypeInfoArray changed the name of 'long long' to 'long long int'; similarly for 'unsigned long long'<commit_after>// cc_flags.cc            see license.txt for copyright and terms of use
// code for cc_flags.h

#include "cc_flags.h"     // this module
#include "macros.h"       // STATIC_ASSERT
#include "xassert.h"      // xassert
#include "trace.h"        // tracingSys


// -------------------- TypeIntr -------------------------
char const * const typeIntrNames[NUM_TYPEINTRS] = {
  "struct",
  "class",
  "union",
  "enum"
};

#define MAKE_TOSTRING(T, limit, array)        \
  string toString(T index)                    \
  {                                           \
    xassert((unsigned)index < limit);         \
    return string(array[index]);              \
  }

MAKE_TOSTRING(TypeIntr, NUM_TYPEINTRS, typeIntrNames)


// ---------------- CVFlags -------------
#ifdef MLVALUE
MAKE_ML_TAG(attribute, 0, AId)
MAKE_ML_TAG(attribute, 1, ACons)

MLValue cvToMLAttrs(CVFlags cv)
{
  // AId of string

  MLValue list = mlNil();
  if (cv & CV_CONST) {
    list = mlCons(mlTuple1(attribute_AId, mlString("const")), list);
  }
  if (cv & CV_VOLATILE) {
    list = mlCons(mlTuple1(attribute_AId, mlString("volatile")), list);
  }
  if (cv & CV_OWNER) {
    list = mlCons(mlTuple1(attribute_AId, mlString("owner")), list);
  }
  return list;
}
#endif // MLVALUE


char const * const cvFlagNames[NUM_CVFLAGS] = {
  "const",
  "volatile",
  "owner"
};


string bitmapString(int bitmap, char const * const *names, int numflags)
{
  stringBuilder sb;
  int count=0;
  for (int i=0; i<numflags; i++) {
    if (bitmap & (1 << i)) {
      if (count++) {
        sb << " ";
      }
      sb << names[i];
    }
  }

  return sb;
}

string toString(CVFlags cv)
{
  return bitmapString(cv >> CV_SHIFT_AMOUNT, cvFlagNames, NUM_CVFLAGS);
}


// ------------------- DeclFlags --------------
char const * const declFlagNames[NUM_DECLFLAGS] = {
  "auto",           // 0
  "register",
  "static",
  "extern",
  "mutable",        // 4
  "inline",
  "virtual",
  "explicit",
  "friend",
  "typedef",        // 9

  "<enumerator>",
  "<global>",
  "<initialized>",
  "<builtin>",
  "<logic>",        // 14
  "<addrtaken>",
  "<parameter>",
  "<universal>",
  "<existential>",
  "<member>",       // 19
  "<definition>",
  "<inline_defn>",
  "<implicit>",
  "<forward>",

  "<predicate>",    // 24
};


string toString(DeclFlags df)
{ 
  // make sure I haven't added a flag without adding a string for it
  xassert(declFlagNames[NUM_DECLFLAGS-1] != NULL);

  return bitmapString(df, declFlagNames, NUM_DECLFLAGS);
}


// ---------------------- SimpleTypeId --------------------------
bool isValid(SimpleTypeId id)
{
  return 0 <= id && id <= NUM_SIMPLE_TYPES;
}


static SimpleTypeInfo const simpleTypeInfoArray[] = {
  //name                   size,    int?,  float?,
  { "char",                   1,    true,   false, },
  { "unsigned char",          1,    true,   false, },
  { "signed char",            1,    true,   false, },
  { "bool",                   4,    false,  false, },
  { "int",                    4,    true,   false, },
  { "unsigned int",           4,    true,   false, },
  { "long int",               4,    true,   false, },
  { "unsigned long int",      4,    true,   false, },
  { "long long int",          8,    true,   false, }, // dsw: added "int" suffix
  { "unsigned long long int", 8,    true,   false, }, // dsw: added "int" suffix
  { "short int",              2,    true,   false, },
  { "unsigned short int",     2,    true,   false, },
  { "wchar_t",                2,    true,   false, },
  { "float",                  4,    false,  true,  },
  { "double",                 8,    false,  true,  },
  { "long double",           10,    false,  true,  },
  { "void",                   1,    false,  false, },    // gnu: sizeof(void) is 1
  { "...",                    0,    false,  false, },
  { "/*cdtor*/",              0,    false,  false, },    // dsw: don't want to print <cdtor>
  { "<error>",                0,    false,  false, },
  { "<dependent>",            0,    false,  false, },
};

{'fraction_non_alphanumeric': 0.19376558603491273, 'fraction_numerical': 0.010473815461346634, 'mean_word_length': 1.7773545706371192, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3343915', 'n_tokens_mistral': 2731, 'n_tokens_neox': 2657, 'n_words': 660}