/************************************************
  Team: Jon Gregory, Gor Nishanov
  Project #2 Part 2
    for RPI course 66-648 Compiler Design Theory

  consts.h -- Here we declared a lot of constants;

  Also here there is a useful functions that
  print modifiers from a modifier mask:

    ostream& printMod(ostream& o, int modifiers);

    */  


const int TYPE_HASH_SIZE = 193;
const int NAME_HASH_SIZE = 389;
const int LOCL_HEAP_SIZE = 128; // SymbolTable size in Kbytes

const char SIG_BYTE     = 'B', *SIG_BYTE_S   = "B";
const char SIG_CHAR     = 'C', *SIG_CHAR_S   = "C";
const char SIG_DOUBLE   = 'D', *SIG_DOUBLE_S = "D";
const char SIG_FLOAT    = 'F', *SIG_FLOAT_S  = "F";
const char SIG_INT      = 'I', *SIG_INT_S    = "I";
const char SIG_LONG     = 'J', *SIG_LONG_S   = "J";
const char SIG_CLASSBEG = 'L';
const char SIG_CLASSEND = ';';
const char SIG_SHORT    = 'S', *SIG_SHORT_S  = "S";
const char SIG_BOOL     = 'Z', *SIG_BOOL_S   = "Z";
const char SIG_VOID     = 'V', *SIG_VOID_S   = "V";
const char SIG_ARRAY    = '[';
const char SIG_PARBEG   = '(';
const char SIG_PAREND   = ')';
 // double d[][][] == [[[D
 // Object mymethod(int i, double d, Thread t)
 // == (IDLjava/lang/Thread;)Ljava/lang/Object

const int ACC_PUBLIC    = 0x0001;
const int ACC_PRIVATE   = 0x0002;
const int ACC_PROTECTED = 0x0004;
const int ACC_STATIC    = 0x0008;
const int ACC_FINAL     = 0x0010;
const int ACC_SUPER     = 0x0020;
const int ACC_VOLATILE  = 0x0040;
const int ACC_TRANSIENT = 0x0080;
const int ACC_NATIVE    = 0x0100;
const int ACC_INTERFACE = 0x0200;
const int ACC_ABSTRACT  = 0x0400;
const int ACC_SYNCHRONIZED = 0x0800;
//const int ACC_CTOR      = 0x1000;

ostream& printMod(ostream& o, int m) {
  if(m & ACC_PUBLIC)    o << "public ";
  if(m & ACC_PRIVATE)   o << "private ";
  if(m & ACC_PROTECTED) o << "protected ";
  if(m & ACC_STATIC   ) o << "static ";
  if(m & ACC_FINAL    ) o << "final ";
  if(m & ACC_SUPER    ) o << "super ";
  if(m & ACC_VOLATILE ) o << "volatile ";
  if(m & ACC_TRANSIENT) o << "transient ";
  if(m & ACC_NATIVE   ) o << "native ";
  if(m & ACC_INTERFACE) o << "interface ";
  if(m & ACC_ABSTRACT ) o << "abstract ";
  if(m & ACC_SYNCHRONIZED) o << "sync ";
  return o;
}

const int CONSTANT_Class    = 7;
const int CONSTANT_Fieldref = 9;
const int CONSTANT_Methodref = 10;
const int CONSTANT_InterfaceMethodref = 11;
const int CONSTANT_String = 8;
const int CONSTANT_Integer = 3;
const int CONSTANT_Float = 4;
const int CONSTANT_Long = 5;
const int CONSTANT_Double = 6;
const int CONSTANT_NameAndType = 12;
const int CONSTANT_Utf8 = 1;

const int TC_BOOL      = 0;
const int TC_BYTE      = 1;
const int TC_CHAR      = 2;
const int TC_SHORT     = 3;
const int TC_INT       = 4;
const int TC_LONG      = 5;
const int TC_FLOAT     = 6;
const int TC_DOUBLE    = 7;
const int TC_NULL      = 8;
const int TC_ARRAY     = 9;
const int TC_CLASS     = 10;
const int TC_VOID      = 11;
const int TC_METHOD    = 12;
const int TC_ERROR     = 13;

#define null NULL
const char* opNames[] = {
	",",		"=",		"*=",		"/=",		"%=",
	"+=",		"-=",		"<<=",		">>=",		"<<<=",
	"&=",		"|=",		"^=",		"?:",		"||",
	"&&",		"|",		"^",		"&",		"!=",
	"==", 		">=",		">",		"<=",		"<",
	"instanceof",	"<<",		">>",		"<<<",		"+",
	"-",		"/",		"%",		"*",		"cast",
	"+",		"-",		"!",		"~",		"++",
	"--",		"new",		"new",		"new",		"++",
	"--",		"field",	"method",	"[]",		"new",
	"++",		"--",		null,		null,		null,

	"convert",	"expr",		"array",	"goto",		null,

	"Identifier",	"boolean",	"byte",		"char",		"short",
	"int",		"long",		"float",	"double",	"string",

	"byte",		"char",		"short",	"int",		"long",
	"float",	"double",	"void",		"boolean",	null,

	"true",		"false",	"this",		"super",	"null",
	null,		null,		null,		null,		null,

	"if",		"else",		"for",		"while",	"do",
	"switch",	"case",		"default",	"break",	"continue",
	"return",	"try",		"catch",	"finally",	"throw",
	"stat",		"expression",	"declaration",	"declaration",  null,

	"import",	"class",	"extends",	"implements",	"interface",
	"package",	null,		null,		null,		null,

	"private",	"public",	"protected",	"const",	"static",
	"transient",	"synchronized",	"native",	"final",	"volatile",
	"abstract",	null,		null,		null,		null,

	";",		":",		"?",		"{",		"}",
	"(",		")",		"[",		"]",		"throws",
	"error",	"comment",	"type",		"length",	"inline-return",
	"inline-method","inline-new"
    };


const int TM_NULL      = 1 << TC_NULL;
const int TM_VOID      = 1 << TC_VOID;
const int TM_BOOL      = 1 << TC_BOOL;
const int TM_BYTE      = 1 << TC_BYTE;
const int TM_CHAR      = 1 << TC_CHAR;
const int TM_SHORT     = 1 << TC_SHORT;
const int TM_INT       = 1 << TC_INT;
const int TM_LONG      = 1 << TC_LONG;
const int TM_FLOAT     = 1 << TC_FLOAT;
const int TM_DOUBLE    = 1 << TC_DOUBLE;
const int TM_ARRAY     = 1 << TC_ARRAY;
const int TM_CLASS     = 1 << TC_CLASS;
const int TM_METHOD    = 1 << TC_METHOD;
const int TM_ERROR     = 1 << TC_ERROR;

const int TM_INT32     = TM_BYTE | TM_SHORT | TM_CHAR | TM_INT;
const int TM_NUM32     = TM_INT32 | TM_FLOAT;
const int TM_NUM64     = TM_LONG | TM_DOUBLE;
const int TM_INTEGER   = TM_INT32 | TM_LONG;
const int TM_REAL      = TM_FLOAT | TM_DOUBLE;
const int TM_NUMBER    = TM_INTEGER | TM_REAL;
const int TM_REFERENCE = TM_ARRAY | TM_CLASS | TM_NULL;

const int CS_UNDEFINED        = 0;
const int CS_UNDECIDED        = 1;
const int CS_BINARY           = 2;
const int CS_SOURCE           = 3;
const int CS_PARSED           = 4;
const int CS_COMPILED         = 5;
const int CS_NOTFOUND         = 6;

const int COMMA              = 0;
const int ASSIGN             = 1;

const int ASGMUL             = 2;
const int ASGDIV             = 3;
const int ASGREM             = 4;
const int ASGADD             = 5;
const int ASGSUB             = 6;
const int ASGLSHIFT          = 7;
const int ASGRSHIFT          = 8;
const int ASGURSHIFT         = 9;
const int ASGBITAND          = 10;
const int ASGBITOR           = 11;
const int ASGBITXOR          = 12;

const int COND               = 13;
const int OR                 = 14;
const int AND                = 15;
const int BITOR              = 16;
const int BITXOR             = 17;
const int BITAND             = 18;
const int NE                 = 19;
const int EQ                 = 20;
const int GE                 = 21;
const int GT                 = 22;
const int LE                 = 23;
const int LT                 = 24;
const int INSTANCEOF         = 25;
const int LSHIFT             = 26;
const int RSHIFT             = 27;
const int URSHIFT            = 28;
const int ADD                = 29;
const int SUB                = 30;
const int DIV                = 31;
const int REM                = 32;
const int MUL                = 33;
const int CAST               = 34;           // (x)y
const int POS                = 35;           // +x
const int NEG                = 36;           // -x
const int NOT                = 37;
const int BITNOT             = 38;
const int PREINC             = 39;           // ++x
const int PREDEC             = 40;           // --x
const int NEWARRAY           = 41;
const int NEWINSTANCE        = 42;
const int NEWFROMNAME        = 43;
const int POSTINC            = 44;           // x++
const int POSTDEC            = 45;           // x--
const int FIELD              = 46;
const int METHOD             = 47;           // x(y)
const int ARRAYACCESS        = 48;           // x[y]
const int NEW                = 49;
const int INC                = 50;
const int DEC                = 51;

const int CONVERT            = 55;           // implicit conversion
const int EXPR               = 56;           // (x)
const int ARRAY              = 57;           // {x, y, ...}
const int GOTO               = 58;

const int IDENT              = 60;
const int BOOLEANVAL         = 61;
const int BYTEVAL            = 62;
const int CHARVAL            = 63;
const int SHORTVAL           = 64;
const int INTVAL             = 65;
const int LONGVAL            = 66;
const int FLOATVAL           = 67;
const int DOUBLEVAL          = 68;
const int STRINGVAL          = 69;

const int BYTE		= 70;
const int CHAR		= 71;
const int SHORT		= 72;
const int INT		= 73;
const int LONG		= 74;
const int FLOAT		= 75;
const int DOUBLE		= 76;
const int VOID		= 77;
const int BOOLEAN		= 78;

//		 * Expression keywords
const int TRUE		= 80;
const int FALSE		= 81;
const int THIS		= 82;
const int SUPER		= 83;
const int NULL_E		= 84;

//		 * Statement keywords
const int IF			= 90;
const int ELSE		= 91;
const int FOR		= 92;
const int WHILE		= 93;
const int DO			= 94;
const int SWITCH		= 95;
const int CASE		= 96;
const int DEFAULT		= 97;
const int BREAK		= 98;
const int CONTINUE		= 99;
const int RETURN		= 100;
const int TRY		= 101;
const int CATCH		= 102;
const int FINALLY		= 103;
const int THROW		= 104;
const int STAT		= 105;
const int EXPRESSION		= 106;
const int DECLARATION	= 107;
const int VARDECLARATION	= 108;

const int SYNCHRONIZED	= 126;

const int ERROR		= 145;
const int TYPE		= 147;
const int LENGTH		= 148;

/*  Class File {
 *    u4 magic;
 *    u2 minor_version;
 *    u2 major_version;
 *    u2 constant_pool_count;
 *    cp_info constant_pool[ constant_pool_count - 1 ];
 *    u2 access_flags;
 *    u2 this_class;
 *    u2 super_class;
 *    u2 interfaces_count;
 *    u2 interfaces[ interfaces_count ];
 *    u2 fields_count;
 *    field_info fields;
 *    u2 methods_count;   
 *    method_info methods[ methods_count ];
 *    u2 attributes_count;
 *    attribute_info attributes[ attributes_count ];
 *  }
 */


/*
  CONSTANT_Fieldref_info { // Methodref / Interfaceref
    u1 tag;
		u2 class_index;
    u2 name_and_type_index;
  }
	CONSTANT_NameAndType {
    u1 tag;
    u2 name_index;       // simple identifier -> CONSTANT_Utf8_info
    u2 descriptor_index; // -> CONSTANT_Utf8_info
  }
  CONSTANT_String_info {
    u1 tag;
		u2 string_index; // -> CONSTANT_Utf8_info
  }
  CONSTANT_Utf8_info {
    u1 tag;
    u2 length;
    u1 bytes[];
  }
-----------
	field_info = method_info {
    u2 access_flags;
    u2 name_index;        // -> Utf8_info
		u2 descriptor_index;  // -> Ut8
    u2 attributes_count;
    attribute_info attributes[ attributes_count ];
  }
-----------
*/
//

const int M_PUBLIC           = ACC_PUBLIC;
const int M_PRIVATE          = ACC_PRIVATE;
const int M_PROTECTED        = ACC_PROTECTED;
const int M_STATIC           = ACC_STATIC;
const int M_TRANSIENT        = ACC_TRANSIENT;
const int M_SYNCHRONIZED     = ACC_SYNCHRONIZED;
const int M_ABSTRACT         = ACC_ABSTRACT;
const int M_NATIVE           = ACC_NATIVE;
const int M_FINAL            = ACC_FINAL;
const int M_VOLATILE         = ACC_VOLATILE;
const int M_INTERFACE        = ACC_INTERFACE;

//    Modifier masks

const int MM_CLASS  = M_PUBLIC | M_INTERFACE | M_FINAL | M_ABSTRACT;
const int MM_FIELD  = M_PUBLIC | M_PRIVATE | M_PROTECTED |
		      M_FINAL  | M_STATIC | M_TRANSIENT | M_VOLATILE;
const int MM_METHOD = M_PUBLIC | M_PRIVATE | M_PROTECTED |
		      M_FINAL | M_STATIC | M_SYNCHRONIZED |
		      M_ABSTRACT | M_NATIVE;
