[eros-cvs] cvs commit: eros/src/base/cross/bin/capidl SymTab.cxx SymTab.hxx gram.y
shap@eros.cs.jhu.edu
shap@eros.cs.jhu.edu
Tue, 23 Jan 2001 16:58:28 -0500
shap 01/01/23 16:58:28
Modified: src/base/cross/bin/capidl SymTab.cxx SymTab.hxx gram.y
Log:
Begin introduction of type support
Revision Changes Path
1.2 +44 -31 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SymTab.cxx 2001/01/23 21:12:27 1.1
+++ SymTab.cxx 2001/01/23 21:58:28 1.2
@@ -24,8 +24,9 @@
#include <erosimg/Diag.hxx>
#include "SymTab.hxx"
-Symbol *GlobalScope = 0;
-Symbol *LiteralScope = 0;
+Symbol *GlobalScope = 0; /* scope for global symbols */
+Symbol *KeywordScope = 0; /* scope for keywords */
+Symbol *LiteralScope = 0; /* quasi-scope for literals */
Symbol **Symbol::scopeStack = 0;
int Symbol::nScopes = 0;
@@ -84,10 +85,11 @@
return 0;
}
-Symbol::Symbol(const InternedString &nm, SymType st)
+Symbol::Symbol(const InternedString &nm, SymClass sc)
{
name = nm;
- ty = st;
+ cls = sc;
+ type = 0; /* unknown type */
v.lty = lt_none;
next = 0;
children = 0;
@@ -95,7 +97,7 @@
}
Symbol *
-Symbol::create(const InternedString &nm, SymType st)
+Symbol::create(const InternedString &nm, SymClass sc)
{
Symbol *scope = CurrentScope();
Symbol *sym;
@@ -107,7 +109,7 @@
return 0;
}
- sym = new Symbol(nm, st);
+ sym = new Symbol(nm, sc);
if (scope) {
sym->parent = scope;
@@ -124,7 +126,7 @@
Symbol *
Symbol::MakeIntLit(const InternedString &nm)
{
- Symbol *sym = new Symbol(nm, st_value);
+ Symbol *sym = new Symbol(nm, sc_value);
sym->parent = LiteralScope;
sym->v.lty = lt_signed;
sym->v.i = strtol(nm.str(), NULL, 0);
@@ -136,7 +138,7 @@
Symbol *
Symbol::MakeStringLit(const InternedString &nm)
{
- Symbol *sym = new Symbol(nm, st_value);
+ Symbol *sym = new Symbol(nm, sc_value);
sym->parent = LiteralScope;
sym->v.lty = lt_string;
LiteralScope->AddChild(sym);
@@ -147,7 +149,7 @@
Symbol *
Symbol::MakeFloatLit(const InternedString &nm)
{
- Symbol *sym = new Symbol(nm, st_value);
+ Symbol *sym = new Symbol(nm, sc_value);
sym->parent = LiteralScope;
sym->v.lty = lt_char;
sym->v.d = strtod(nm.str(), NULL);
@@ -159,7 +161,7 @@
Symbol *
Symbol::MakeCharLit(const InternedString &nm)
{
- Symbol *sym = new Symbol(nm, st_value);
+ Symbol *sym = new Symbol(nm, sc_value);
sym->parent = LiteralScope;
sym->v.lty = lt_char;
sym->v.u = nm.str()[0]; /* FIX: wchar_t! */
@@ -168,24 +170,35 @@
return sym;
}
+Symbol *
+Symbol::MakeKeyword(const char *nm, SymClass sc,
+ LitType lt = lt_none,
+ unsigned value = 0)
+{
+ Symbol *sym = new Symbol(nm, sc);
+ sym->parent = KeywordScope;
+ sym->v.lty = lt;
+ sym->v.u = value;
+ KeywordScope->AddChild(sym);
+
+ return sym;
+}
+
void
Symbol::InitSymtab()
{
Symbol *sym;
- GlobalScope = new Symbol("<GlobalScope>", st_Scope);
- LiteralScope = new Symbol("<LiteralScope>", st_Scope);
+ GlobalScope = new Symbol("<GlobalScope>", sc_Scope);
+ LiteralScope = new Symbol("<LiteralScope>", sc_Scope);
+ KeywordScope = new Symbol("<KeywordScope>", sc_Scope);
- sym = new Symbol("true", st_builtin);
- sym->parent = LiteralScope;
- sym->v.lty = lt_bool;
- sym->v.u = 1;
- LiteralScope->AddChild(sym);
+ Symbol *boolType = MakeKeyword("boolean", sc_primtype);
- sym = new Symbol("false", st_builtin);
- sym->parent = LiteralScope;
- sym->v.lty = lt_bool;
- sym->v.u = 0;
- LiteralScope->AddChild(sym);
+ sym = MakeKeyword("true", sc_builtin, lt_bool, 1);
+ sym->type = boolType;
+
+ sym = MakeKeyword("false", sc_builtin, lt_bool, 0);
+ sym->type = boolType;
}
Symbol *
@@ -217,20 +230,20 @@
void
Symbol::Dump()
{
- switch(ty){
- case st_Scope: /* scope records */
+ switch(cls){
+ case sc_Scope: /* scope records */
{
Diag::printf("<scope \"%s\">", name.str());
break;
}
- case st_builtin: /* builtin constants */
+ case sc_builtin: /* builtin constants */
{
Diag::printf("<builtin \"%s\">", name.str());
break;
}
- case st_value: /* computed constant values */
+ case sc_value: /* computed constant values */
{
switch(v.lty){
case lt_none:
@@ -277,13 +290,13 @@
break;
}
- case st_const: /* constant symbols, including enum values */
+ case sc_const: /* constant symbols, including enum values */
{
Diag::printf("<const \"%s\"> = ", name.str());
value->Dump();
break;
}
- case st_enum: /* enum type name */
+ case sc_enum: /* enum type name */
{
Diag::printf("<enum \"%s\">", name.str());
break;
@@ -306,9 +319,9 @@
Diag::printf("\n");
- switch(ty){
- case st_enum:
- case st_Scope:
+ switch(cls){
+ case sc_enum:
+ case sc_Scope:
{
for(Symbol *child = children; child; child = child->next)
child->DumpTree(indent + 2);
1.2 +16 -10 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SymTab.hxx 2001/01/23 21:12:27 1.1
+++ SymTab.hxx 2001/01/23 21:58:28 1.2
@@ -49,15 +49,16 @@
* which case we may need to do some tail chasing for constants. Thus,
* I consider a computed constant value to be a symbol.
*/
-enum SymType {
+enum SymClass {
/* The following are all rvalues: */
- st_Scope, /* for scope records */
- st_builtin, /* builtin constants */
- st_value, /* computed constant values */
+ sc_Scope, /* for scope records */
+ sc_builtin, /* builtin constants */
+ sc_value, /* computed constant values */
/* The following define new names: */
- st_const, /* constant symbols, including enum values */
- st_enum, /* enum type name */
+ sc_const, /* constant symbols, including enum values */
+ sc_enum, /* enum type name */
+ sc_primtype, /* primtype names */
};
struct Symbol {
@@ -67,21 +68,26 @@
Symbol *next; /* in same scope */
Symbol *children;
- SymType ty;
+ SymClass cls;
+ Symbol * type; /* type of an identifier */
Symbol * value; /* value of a constant */
- LitValue v; /* only for st_value and st_builtin */
+ LitValue v; /* only for sc_value and sc_builtin */
- Symbol(const InternedString& name, SymType);
+ Symbol(const InternedString& name, SymClass);
static void InitSymtab();
/* Creates a new symbol of the specified type in the currently
* active scope. This is not a constructor because it must be able
* to return failure in the event of a symbol name collision. */
- static Symbol *create(const InternedString& nm, SymType);
+ static Symbol *create(const InternedString& nm, SymClass);
+ static Symbol *MakeKeyword(const char *nm, SymClass sc,
+ LitType lt = lt_none,
+ unsigned value = 0);
+
static Symbol *MakeIntLit(const InternedString&);
static Symbol *MakeStringLit(const InternedString&);
static Symbol *MakeCharLit(const InternedString&);
1.2 +1 -1 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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- gram.y 2001/01/23 21:12:27 1.1
+++ gram.y 2001/01/23 21:58:28 1.2
@@ -510,7 +510,7 @@
/********************** Constant Declarations ***************************/
const_dcl:
CONST type name_def '=' const_expr ';' {
- Symbol *sym = Symbol::create($3, st_const);
+ Symbol *sym = Symbol::create($3, sc_const);
if (sym == 0) {
Diag::printf("%s:%d: syntax error -- identifier reused\n",
current_file.str(), current_line);