[eros-cvs] cvs commit: eros/src/base/cross/bin/capidl SymTab.cxx SymTab.hxx gram.y lex.l test-input
shap@eros.cs.jhu.edu
shap@eros.cs.jhu.edu
Wed, 24 Jan 2001 22:30:20 -0500
shap 01/01/24 22:30:20
Modified: src/base/cross/bin/capidl SymTab.cxx SymTab.hxx gram.y lex.l
test-input
Log:
Beginnings of exception syntax support
Revision Changes Path
1.4 +80 -0 eros/src/base/cross/bin/capidl/SymTab.cxx
Index: SymTab.cxx
===================================================================
RCS file: /cvs/eros/src/base/cross/bin/capidl/SymTab.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SymTab.cxx 2001/01/24 18:26:09 1.3
+++ SymTab.cxx 2001/01/25 03:30:20 1.4
@@ -141,6 +141,60 @@
}
Symbol *
+Symbol::MakeMinLit()
+{
+ assert(cls == sc_primtype);
+ assert(v.lty == lt_integer);
+
+ if ( name == InternedString(".int8") )
+ return LiteralScope->LookupChild(InternedString("-128"));
+ if ( name == InternedString(".int16") )
+ return LiteralScope->LookupChild(InternedString("-32768"));
+ if ( name == InternedString(".int32") )
+ return LiteralScope->LookupChild(InternedString("-2147483648"));
+ if ( name == InternedString(".int64") )
+ return LiteralScope->LookupChild(InternedString("-9223372036854775808"));
+
+ if ( name == InternedString(".uint8") )
+ return LiteralScope->LookupChild(InternedString("0"));
+ if ( name == InternedString(".uint16") )
+ return LiteralScope->LookupChild(InternedString("0"));
+ if ( name == InternedString(".uint32") )
+ return LiteralScope->LookupChild(InternedString("0"));
+ if ( name == InternedString(".uint64") )
+ return LiteralScope->LookupChild(InternedString("0"));
+
+ return 0; /* no min/max */
+}
+
+Symbol *
+Symbol::MakeMaxLit()
+{
+ assert(cls == sc_primtype);
+ assert(v.lty == lt_integer);
+
+ if ( name == InternedString(".int8") )
+ return LiteralScope->LookupChild(InternedString("127"));
+ if ( name == InternedString(".int16") )
+ return LiteralScope->LookupChild(InternedString("32767"));
+ if ( name == InternedString(".int32") )
+ return LiteralScope->LookupChild(InternedString("2147483647"));
+ if ( name == InternedString(".int64") )
+ return LiteralScope->LookupChild(InternedString("9223372036854775807"));
+
+ if ( name == InternedString(".uint8") )
+ return LiteralScope->LookupChild(InternedString("255"));
+ if ( name == InternedString(".uint16") )
+ return LiteralScope->LookupChild(InternedString("65535"));
+ if ( name == InternedString(".uint32") )
+ return LiteralScope->LookupChild(InternedString("4294967295"));
+ if ( name == InternedString(".uint64") )
+ return LiteralScope->LookupChild(InternedString("18446744073709551615"));
+
+ return 0; /* no min/max */
+}
+
+Symbol *
Symbol::MakeIntLitFromMpz(const mpz_t &mp)
{
char *nm = mpz_get_str(NULL, 0, mp);
@@ -263,6 +317,29 @@
MakeKeyword(".int32", sc_primtype, lt_integer, 32);
MakeKeyword(".int64", sc_primtype, lt_integer, 64);
+ MakeKeyword(".uint8", sc_primtype, lt_integer, 8);
+ MakeKeyword(".uint16", sc_primtype, lt_integer, 16);
+ MakeKeyword(".uint32", sc_primtype, lt_integer, 32);
+ MakeKeyword(".uint64", sc_primtype, lt_integer, 64);
+
+ MakeIntLit("0"); /* min unsigned anything */
+
+ MakeIntLit("127"); /* max pos signed 8 bit */
+ MakeIntLit("-128"); /* max neg signed 8 bit */
+ MakeIntLit("255"); /* max unsigned 8 bit */
+
+ MakeIntLit("32767"); /* max pos signed 16 bit */
+ MakeIntLit("-32768"); /* max neg signed 16 bit */
+ MakeIntLit("65535"); /* max unsigned 16 bit */
+
+ MakeIntLit("2147483647"); /* max pos signed 32 bit */
+ MakeIntLit("-2147483648"); /* max neg signed 32 bit */
+ MakeIntLit("4294967295"); /* max unsigned 32 bit */
+
+ MakeIntLit("9223372036854775807"); /* max pos signed 64 bit */
+ MakeIntLit("-9223372036854775808"); /* max neg signed 64 bit */
+ MakeIntLit("18446744073709551615"); /* max unsigned 64 bit */
+
MakeKeyword(".float32", sc_primtype, lt_float, 32);
MakeKeyword(".float64", sc_primtype, lt_float, 64);
MakeKeyword(".float128", sc_primtype, lt_float, 128);
@@ -279,6 +356,9 @@
sym = MakeKeyword("false", sc_builtin, lt_bool, 0);
sym->type = boolType;
+ sym = MakeKeyword("int32_max", sc_builtin, lt_integer, 2147483647);
+ sym = MakeKeyword("int32_min", sc_builtin, lt_integer, -2147483647 - 1);
+ sym->type = boolType;
}
Symbol *
1.4 +5 -0 eros/src/base/cross/bin/capidl/SymTab.hxx
Index: SymTab.hxx
===================================================================
RCS file: /cvs/eros/src/base/cross/bin/capidl/SymTab.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SymTab.hxx 2001/01/24 18:26:09 1.3
+++ SymTab.hxx 2001/01/25 03:30:20 1.4
@@ -95,6 +95,11 @@
static Symbol *MakeCharLit(const InternedString&);
static Symbol *MakeFloatLit(const InternedString&);
+ /* Following, when applied to scalar types (currently only integer
+ * types) will produce min and max values. */
+ Symbol *MakeMaxLit();
+ Symbol *MakeMinLit();
+
/* Using a left-recursive grammar is always really messy, because
* you have to do the scope push/pop by hand, which is at best
* messy. Bother.
1.4 +41 -2 eros/src/base/cross/bin/capidl/gram.y
Index: gram.y
===================================================================
RCS file: /cvs/eros/src/base/cross/bin/capidl/gram.y,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- gram.y 2001/01/24 18:26:09 1.3
+++ gram.y 2001/01/25 03:30:20 1.4
@@ -96,6 +96,8 @@
int current_line = 1;
extern FILE *yyin;
+mpz_t next_exception_value;
+
int num_errors = 0; /* hold the number of syntax errors encountered. */
#define YYSTYPE ParseType
@@ -118,6 +120,7 @@
%token <NONE> BOOLEAN CASE CHAR CONST DEFAULT
%token <NONE> DOUBLE ENUM EXCEPTION FLOAT
%token <tok> tTRUE tFALSE
+%token <tok> tMIN tMAX
%token <NONE> INTERFACE LONG MODULE OBJECT BYTE ONEWAY OUT RAISES
%token <NONE> SHORT STRING STRUCT SWITCH TYPEDEF
%token <NONE> UNSIGNED UNION VOID WCHAR WSTRING
@@ -250,6 +253,10 @@
$$ = GlobalScope->LookupChild($2.is);
}
| scoped_name OPSCOPE ident { /* qualified */
+ /* NOTE that yacc does not deal well with left recursion,
+ * and that in consequence this production causes a
+ * shift/reduce error, however, the parser's error
+ * resolution (reduce) is correct. */
$$ = $1->LookupChild($3.is);
}
;
@@ -534,7 +541,20 @@
Diag::printf("%s:%d: syntax error -- identifier reused\n",
current_file.str(), current_line);
}
- sym->type = KeywordScope->LookupChild(".void");
+ sym->value = Symbol::MakeIntLitFromMpz(next_exception_value);
+ sym->type = KeywordScope->LookupChild(".int");
+
+ /* Bump the "next exception" value */
+ mpz_add_ui(next_exception_value, next_exception_value, 1);
+ }
+ | EXCEPTION name_def '=' const_expr {
+ Symbol *sym = Symbol::create($2.is, sc_exception);
+ if (sym == 0) {
+ Diag::printf("%s:%d: syntax error -- identifier reused\n",
+ current_file.str(), current_line);
+ }
+ sym->value = $4;
+ sym->type = KeywordScope->LookupChild(".int");
}
| EXCEPTION name_def '{' members '}' {
Diag::printf("%s:%d: unimplemented -- exception messages are not supported.\n",
@@ -714,7 +734,7 @@
current_file.str(), current_line);
}
sym->value = $5;
- sym->type = KeywordScope->LookupChild(".int32");
+ sym->type = $2;
}
;
@@ -747,6 +767,22 @@
| StringLiteral { $$ = Symbol::MakeStringLit($1.is); }
| CharLiteral { $$ = Symbol::MakeCharLit($1.is); }
| FloatingPtLiteral { $$ = Symbol::MakeFloatLit($1.is); }
+ | tMIN '(' integer_type ')' {
+ Symbol *sym = $3->MakeMinLit();
+ if (sym == 0) {
+ Diag::printf("%s:%d: syntax error -- infinite integral types have no min/max\n",
+ current_file.str(), current_line);
+ }
+ $$ = sym;
+ }
+ | tMAX '(' integer_type ')' {
+ Symbol *sym = $3->MakeMaxLit();
+ if (sym == 0) {
+ Diag::printf("%s:%d: syntax error -- infinite integral types have no min/max\n",
+ current_file.str(), current_line);
+ }
+ $$ = sym;
+ }
| tTRUE { $$ = GlobalScope->LookupChild($1.is); }
| tFALSE { $$ = GlobalScope->LookupChild($1.is); }
;
@@ -1039,6 +1075,9 @@
bool use_std_inc_path = true;
bool use_std_def_list = true;
+ mpz_init(next_exception_value);
+ mpz_set_ui(next_exception_value, 1);
+
StrBuf cpp_cmd;
StrBuf cpp_cmd_args;
cpp_cmd << "/lib/cpp ";
1.3 +4 -0 eros/src/base/cross/bin/capidl/lex.l
Index: lex.l
===================================================================
RCS file: /cvs/eros/src/base/cross/bin/capidl/lex.l,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- lex.l 2001/01/24 18:26:09 1.2
+++ lex.l 2001/01/25 03:30:20 1.3
@@ -91,6 +91,8 @@
integer { TOK(INTEGER); }
interface { TOK(INTERFACE); }
long { TOK(LONG); }
+max { TOK(tMAX); }
+min { TOK(tMIN); }
module { TOK(MODULE); }
native { TOK(NATIVE); }
object { TOK(OBJECT); }
@@ -178,6 +180,8 @@
when { TOK(WHEN); }
while { TOK(WHILE); }
+\< { TOK('<'); }
+\> { TOK('>'); }
\( { TOK('('); }
\) { TOK(')'); }
, { TOK(','); }
1.3 +8 -1 eros/src/base/cross/bin/capidl/test-input
Index: test-input
===================================================================
RCS file: /cvs/eros/src/base/cross/bin/capidl/test-input,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- test-input 2001/01/24 18:26:09 1.2
+++ test-input 2001/01/25 03:30:20 1.3
@@ -1,4 +1,5 @@
const long a = 5;
+const unsigned short s = 5;
enum full_enum {
x1,
@@ -7,4 +8,10 @@
x16
}
-exception RC_RequestError;
+enum another_enum {
+ y,
+ z
+}
+
+const integer kt = min ( integer<32> );
+exception RC_RequestError ;