1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
// java_flags.cc see license.txt for copyright and terms of use
// code for java_flags.h
#include "java_flags.h" // this module
#include "xassert.h" // xassert
// the check for array[limit-1] is meant to ensure that there
// are as many specified entries as there are total entries
#define MAKE_TOSTRING(T, limit, array) \
char const *toString(T index) \
{ \
xassert((unsigned)index < limit); \
xassert(array[limit-1] != NULL); \
return array[index]; \
}
char const * const modifierNames[NUM_MODIFIERS] = {
"public",
"protected",
"private",
"static",
"abstract",
"final",
"native",
"synchronized",
"transient",
"volatile",
"strictfp"
};
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(Modifiers m) {
xassert(modifierNames[NUM_MODIFIERS-1] != NULL);
return bitmapString(m, modifierNames, NUM_MODIFIERS);
}
char const * const binaryOpNames[NUM_BINARY_OPS] = {
"*",
"/",
"%",
"+",
"-",
"<<",
">>",
">>>",
"<",
">",
"<=",
">=",
"instanceof",
"==",
"!=",
"&",
"^",
"|",
"&&",
"||",
"="
};
MAKE_TOSTRING(BinaryOperator, NUM_BINARY_OPS, binaryOpNames)
char const * const unaryOpNames[NUM_UNARY_OPS] = {
"+",
"-",
"++",
"--",
"++",
"--",
"~",
"!"
};
MAKE_TOSTRING(UnaryOperator, NUM_UNARY_OPS, unaryOpNames)
char const * const basicTypeNames[NUM_TYPES] = {
"void",
"byte",
"short",
"char",
"int",
"long",
"float",
"double",
"boolean"
};
MAKE_TOSTRING(BasicType, NUM_TYPES, basicTypeNames)
|