widl patch
Ove Kaaven
ovehk at ping.uio.no
Thu Oct 31 17:40:38 CST 2002
Log:
Ove Kaaven <ovek at transgaming.com>
Support for enums, arrays, encapsulated unions, signed/unsigned
qualifiers, and some other improvements.
Index: tools/widl/header.c
===================================================================
RCS file: /cvsroot/rewind/rewind/tools/widl/header.c,v
retrieving revision 1.1
diff -u -r1.1 header.c
--- tools/widl/header.c 8 Jun 2002 13:18:16 -0000 1.1
+++ tools/widl/header.c 31 Oct 2002 23:21:30 -0000
@@ -38,13 +38,13 @@
return 0;
}
-static void write_pident(var_t *v)
+static void write_pident(FILE *h, var_t *v)
{
int c;
for (c=0; c<v->ptr_level; c++) {
- fprintf(header, "*");
+ fprintf(h, "*");
}
- if (v->name) fprintf(header, "%s", v->name);
+ if (v->name) fprintf(h, "%s", v->name);
}
void write_name(FILE *h, var_t *v)
@@ -57,22 +57,66 @@
return v->name;
}
+static void write_array(FILE *h, expr_t *v)
+{
+ if (!v) return;
+ while (NEXT_LINK(v)) v = NEXT_LINK(v);
+ fprintf(h, "[");
+ while (v) {
+ if (v->type == aNUM)
+ fprintf(h, "%ld", v->u.lval); /* statically sized array */
+ else
+ fprintf(h, "1"); /* dynamically sized array */
+ if (PREV_LINK(v))
+ fprintf(h, ", ");
+ v = PREV_LINK(v);
+ }
+ fprintf(h, "]");
+}
+
+static void write_field(FILE *h, var_t *v)
+{
+ if (!v) return;
+ if (v->type) {
+ indent(0);
+ write_type(h, v->type, NULL, v->tname);
+ if (get_name(v)) {
+ fprintf(h, " ");
+ write_pident(h, v);
+ }
+ write_array(h, v->array);
+ fprintf(h, ";\n");
+ }
+}
+
static void write_fields(FILE *h, var_t *v)
{
+ var_t *first = v;
+ if (!v) return;
+ while (NEXT_LINK(v)) v = NEXT_LINK(v);
+ while (v) {
+ write_field(h, v);
+ if (v == first) break;
+ v = PREV_LINK(v);
+ }
+}
+
+static void write_enums(FILE *h, var_t *v)
+{
if (!v) return;
while (NEXT_LINK(v)) v = NEXT_LINK(v);
while (v) {
- if (v->type) {
+ if (get_name(v)) {
indent(0);
- write_type(h, v->type, NULL, v->tname);
- if (get_name(v)) {
- fprintf(header, " ");
- write_pident(v);
- }
- fprintf(header, ";\n");
+ write_name(h, v);
+ if (v->has_val)
+ fprintf(h, " = %ld", v->lval);
}
+ if (PREV_LINK(v))
+ fprintf(h, ",\n");
v = PREV_LINK(v);
}
+ fprintf(h, "\n");
}
void write_type(FILE *h, type_t *t, var_t *v, char *n)
@@ -83,25 +127,52 @@
else {
if (t->is_const) fprintf(h, "const ");
if (t->type) {
+ if (t->sign > 0) fprintf(h, "signed ");
+ else if (t->sign < 0) fprintf(h, "unsigned ");
switch (t->type) {
case RPC_FC_BYTE:
- fprintf(h, "byte");
+ if (t->ref) fprintf(h, t->ref->name);
+ else fprintf(h, "byte");
break;
case RPC_FC_CHAR:
- fprintf(h, "char");
+ if (t->ref) fprintf(h, t->ref->name);
+ else fprintf(h, "char");
+ break;
+ case RPC_FC_WCHAR:
+ fprintf(h, "wchar_t");
break;
case RPC_FC_USHORT:
- fprintf(h, "unsigned ");
case RPC_FC_SHORT:
if (t->ref) fprintf(h, t->ref->name);
- fprintf(h, "short");
+ else fprintf(h, "short");
break;
case RPC_FC_ULONG:
- fprintf(h, "unsigned ");
case RPC_FC_LONG:
if (t->ref) fprintf(h, t->ref->name);
else fprintf(h, "long");
break;
+ case RPC_FC_HYPER:
+ if (t->ref) fprintf(h, t->ref->name);
+ else fprintf(h, "__int64");
+ break;
+ case RPC_FC_FLOAT:
+ fprintf(h, "float");
+ break;
+ case RPC_FC_DOUBLE:
+ fprintf(h, "double");
+ break;
+ case RPC_FC_ENUM16:
+ case RPC_FC_ENUM32:
+ if (t->defined && !t->written) {
+ if (t->name) fprintf(h, "enum %s {\n", t->name);
+ else fprintf(h, "enum {\n");
+ indentation++;
+ write_enums(h, t->fields);
+ indent(-1);
+ fprintf(h, "}");
+ }
+ else fprintf(h, "enum %s", t->name);
+ break;
case RPC_FC_STRUCT:
if (t->defined && !t->written) {
if (t->name) fprintf(h, "struct %s {\n", t->name);
@@ -113,6 +184,24 @@
}
else fprintf(h, "struct %s", t->name);
break;
+ case RPC_FC_ENCAPSULATED_UNION:
+ if (t->defined && !t->written) {
+ var_t *d = t->fields;
+ if (t->name) fprintf(h, "struct %s {\n", t->name);
+ else fprintf(h, "struct {\n");
+ indentation++;
+ write_field(h, d);
+ indent(0);
+ fprintf(h, "union {\n");
+ indentation++;
+ write_fields(h, NEXT_LINK(d));
+ indent(-1);
+ fprintf(h, "} u;\n");
+ indent(-1);
+ fprintf(h, "}");
+ }
+ else fprintf(h, "struct %s", t->name);
+ break;
case RPC_FC_NON_ENCAPSULATED_UNION:
if (t->defined && !t->written) {
if (t->name) fprintf(h, "union %s {\n", t->name);
@@ -150,12 +239,12 @@
write_type(header, type, NULL, tname);
fprintf(header, " ");
while (names) {
- write_pident(names);
+ write_pident(header, names);
if (PREV_LINK(names))
fprintf(header, ", ");
names = PREV_LINK(names);
}
- fprintf(header, ";\n");
+ fprintf(header, ";\n\n");
}
/********** INTERFACES **********/
@@ -349,7 +438,7 @@
void write_forward(type_t *iface)
{
- if (!iface->written) {
+ if (is_object(iface->attrs) && !iface->written) {
fprintf(header, "typedef struct %s %s;\n", iface->name, iface->name);
iface->written = TRUE;
}
Index: tools/widl/parser.l
===================================================================
RCS file: /cvsroot/rewind/rewind/tools/widl/parser.l,v
retrieving revision 1.1
diff -u -r1.1 parser.l
--- tools/widl/parser.l 8 Jun 2002 13:18:16 -0000 1.1
+++ tools/widl/parser.l 31 Oct 2002 23:21:30 -0000
@@ -76,8 +76,11 @@
<QUOTE>\\. addcchar('\\'); addcchar(yytext[1]);
<QUOTE>. addcchar(yytext[0]);
{uuid} return aUUID;
-{hex} return aNUM;
-{int} return aNUM;
+{hex} |
+{int} {
+ yylval.num = strtol(yytext, NULL, 0);
+ return aNUM;
+ }
{cident} return kw_token(yytext);
\n
{ws}
Index: tools/widl/parser.y
===================================================================
RCS file: /cvsroot/rewind/rewind/tools/widl/parser.y,v
retrieving revision 1.1
diff -u -r1.1 parser.y
--- tools/widl/parser.y 8 Jun 2002 13:18:16 -0000 1.1
+++ tools/widl/parser.y 31 Oct 2002 23:21:31 -0000
@@ -49,11 +49,16 @@
static attr_t *make_attr(int type);
static attr_t *make_attrv(int type, DWORD val);
static attr_t *make_attrp(int type, void *val);
+static expr_t *make_expr(int type);
+static expr_t *make_exprl(int type, long val);
+static expr_t *make_exprs(int type, char *val);
+static expr_t *make_expr1(int type, expr_t *expr);
+static expr_t *make_expr2(int type, expr_t *exp1, expr_t *exp2);
static type_t *make_type(BYTE type, type_t *ref);
static typeref_t *make_tref(char *name, type_t *ref);
static typeref_t *uniq_tref(typeref_t *ref);
static type_t *type_ref(typeref_t *ref);
-static void set_type(var_t *v, typeref_t *ref);
+static void set_type(var_t *v, typeref_t *ref, expr_t *arr);
static var_t *make_var(char *name);
static func_t *make_func(var_t *def, var_t *args);
@@ -68,11 +73,13 @@
#define tsSTRUCT 2
#define tsUNION 3
+static type_t std_bool = { "boolean" };
static type_t std_int = { "int" };
%}
%union {
attr_t *attr;
+ expr_t *expr;
type_t *type;
typeref_t *tref;
var_t *var;
@@ -130,14 +137,15 @@
%token tPOINTERTYPE
%type <attr> m_attributes attributes attrib_list attribute
-%type <type> inherit interface interfacedef
+%type <expr> aexprs aexpr_list aexpr array
+%type <type> inherit interface interfacedef lib_statements
%type <type> base_type int_std
%type <type> enumdef structdef typedef uniondef
%type <tref> type
%type <var> m_args no_args args arg
-%type <var> fields field
+%type <var> fields field s_field cases case enums enum_list enum constdef
%type <var> m_ident t_ident ident p_ident pident pident_list
-%type <func> funcdef statements
+%type <func> funcdef int_statements
%type <num> expr pointer_type
%left ','
@@ -152,22 +160,38 @@
%%
-statements: { $$ = NULL; }
- | statements funcdef ';' { LINK($2, $1); $$ = $2; }
- | statements statement
+input: lib_statements { /* FIXME */ }
+ ;
+
+lib_statements: { $$ = NULL; }
+ | lib_statements import
+ | lib_statements interface ';'
+ | lib_statements interfacedef { LINK($2, $1); $$ = $2; }
+/* | lib_statements librarydef (when implemented) */
+ | lib_statements statement
+ ;
+
+/* we can't import from inside interfaces yet
+ * (it's not entirely clear how Microsoft manages that yet,
+ * but in MIDL you can derive a class from a base class and then
+ * import the base class definition from inside the interface,
+ * which I don't quite know how to pull off in yacc/bison yet) */
+int_statements: { $$ = NULL; }
+ | int_statements funcdef ';' { LINK($2, $1); $$ = $2; }
+ | int_statements statement
;
statement: ';' {}
| constdef {}
| cppquote {}
- | enumdef ';' { if (!parse_only) { write_type(header, $1, NULL, NULL); fprintf(header, ";\n"); } }
+ | enumdef ';' { if (!parse_only) { write_type(header, $1, NULL, NULL); fprintf(header, ";\n\n"); } }
| externdef ';' {}
- | import {}
- | interface ';' {}
- | interfacedef {}
- | structdef ';' { if (!parse_only) { write_type(header, $1, NULL, NULL); fprintf(header, ";\n"); } }
+/* | import {} */
+/* | interface ';' {} */
+/* | interfacedef {} */
+ | structdef ';' { if (!parse_only) { write_type(header, $1, NULL, NULL); fprintf(header, ";\n\n"); } }
| typedef ';' {}
- | uniondef ';' { if (!parse_only) { write_type(header, $1, NULL, NULL); fprintf(header, ";\n"); } }
+ | uniondef ';' { if (!parse_only) { write_type(header, $1, NULL, NULL); fprintf(header, ";\n\n"); } }
;
cppquote: tCPPQUOTE '(' aSTRING ')' { if (!parse_only) fprintf(header, "%s\n", $3); }
@@ -189,40 +213,42 @@
/* split into two rules to get bison to resolve a tVOID conflict */
arg: attributes type pident array { $$ = $3;
- set_type($$, $2);
- $$->attrs = $1; /* FIXME: array */
+ set_type($$, $2, $4);
+ $$->attrs = $1;
}
| type pident array { $$ = $2;
- set_type($$, $1); /* FIXME: array */
+ set_type($$, $1, $3);
}
;
-aexprs:
+aexprs: { $$ = make_expr(0); }
| aexpr_list
;
aexpr_list: aexpr
- | aexprs ',' aexpr
+ | aexpr_list ',' aexpr { LINK($3, $1); $$ = $3; }
;
-aexpr: aNUM {}
- | aIDENTIFIER {}
- | aexpr '|' aexpr
- | aexpr '&' aexpr
- | aexpr '+' aexpr
- | aexpr '-' aexpr
- | aexpr '*' aexpr
- | aexpr '/' aexpr
- | '-' aexpr %prec NEG
- | '*' aexpr %prec PPTR
- | '(' type ')' aexpr %prec CAST
- | '(' aexpr ')'
- | tSIZEOF '(' type ')'
- ;
-
-array:
- | '[' aexprs ']'
- | '[' '*' ']'
+aexpr: aNUM { $$ = make_exprl(aNUM, $1); }
+ | aIDENTIFIER { $$ = make_exprs(aIDENTIFIER, $1); }
+ | aexpr '|' aexpr { $$ = make_expr2('|', $1, $3); }
+ | aexpr '&' aexpr { $$ = make_expr2('&', $1, $3); }
+ | aexpr '+' aexpr { $$ = make_expr2('+', $1, $3); }
+ | aexpr '-' aexpr { $$ = make_expr2('-', $1, $3); }
+ | aexpr '*' aexpr { $$ = make_expr2('*', $1, $3); }
+ | aexpr '/' aexpr { $$ = make_expr2('/', $1, $3); }
+ | aexpr SHL aexpr { $$ = make_expr2(SHL, $1, $3); }
+ | aexpr SHR aexpr { $$ = make_expr2(SHR, $1, $3); }
+ | '-' aexpr %prec NEG { $$ = make_expr1(NEG, $2); }
+ | '*' aexpr %prec PPTR { $$ = make_expr1(PPTR, $2); }
+ | '(' type ')' aexpr %prec CAST { $$ = $4; /* FIXME */ free($2); }
+ | '(' aexpr ')' { $$ = $2; }
+ | tSIZEOF '(' type ')' { $$ = make_exprl(aNUM, 0); /* FIXME */ free($3); warning("can't do sizeof() yet\n"); }
+ ;
+
+array: { $$ = NULL; }
+ | '[' aexprs ']' { $$ = $2; }
+ | '[' '*' ']' { $$ = make_expr(0); }
;
m_attributes: { $$ = NULL; }
@@ -268,31 +294,39 @@
| tSTDCALL
;
-cases:
- | cases case
+cases: { $$ = NULL; }
+ | cases case { LINK($2, $1); $$ = $2; }
;
-case: tCASE expr ':' field
- | tDEFAULT ':' field
+case: tCASE expr ':' field { $$ = $4; }
+ | tDEFAULT ':' field { $$ = $3; }
;
-constdef: tCONST type ident '=' expr
+constdef: tCONST type ident '=' expr { $$ = $3;
+ set_type($$, $2, NULL);
+ $$->has_val = TRUE;
+ $$->lval = $5;
+ }
;
-enums:
- | enum_list ','
+enums: { $$ = NULL; }
+ | enum_list ',' { $$ = $1; }
| enum_list
;
enum_list: enum
- | enum_list ',' enum
+ | enum_list ',' enum { LINK($3, $1); $$ = $3; }
;
-enum: ident '=' expr {}
- | ident {}
+enum: ident '=' expr { $$ = $1;
+ $$->has_val = TRUE;
+ $$->lval = $3;
+ }
+ | ident { $$ = $1; }
;
-enumdef: tENUM t_ident '{' enums '}' { $$ = get_typev(RPC_FC_SHORT /* FIXME */, $2, tsENUM);
+enumdef: tENUM t_ident '{' enums '}' { $$ = get_typev(RPC_FC_ENUM16, $2, tsENUM);
+ $$->fields = $4;
$$->defined = TRUE;
}
;
@@ -302,11 +336,12 @@
;
expr: aNUM
- | aIDENTIFIER {}
- | expr '|' expr {}
- | expr SHL expr {}
- | expr SHR expr {}
- | '-' expr %prec NEG {}
+ | aIDENTIFIER { $$ = 0; /* FIXME */ }
+ | expr '|' expr { $$ = $1 | $3; }
+ | expr '&' expr { $$ = $1 & $3; }
+ | expr SHL expr { $$ = $1 << $3; }
+ | expr SHR expr { $$ = $1 >> $3; }
+ | '-' expr %prec NEG { $$ = -$2; }
;
externdef: tEXTERN tCONST type ident
@@ -316,15 +351,18 @@
| fields field { LINK($2, $1); $$ = $2; }
;
-field: m_attributes type pident array ';' { $$ = $3; set_type($$, $2); $$->attrs = $1; /* FIXME: array */ }
+field: s_field ';' { $$ = $1; }
| m_attributes uniondef ';' { $$ = make_var(NULL); $$->type = $2; $$->attrs = $1; }
| attributes ';' { $$ = make_var(NULL); $$->attrs = $1; }
| ';' { $$ = NULL; }
;
+s_field: m_attributes type pident array { $$ = $3; set_type($$, $2, $4); $$->attrs = $1; }
+ ;
+
funcdef:
m_attributes type callconv pident
- '(' m_args ')' { set_type($4, $2);
+ '(' m_args ')' { set_type($4, $2, NULL);
$4->attrs = $1;
$$ = make_func($4, $6);
}
@@ -343,15 +381,20 @@
;
base_type: tBYTE { $$ = make_type(RPC_FC_BYTE, NULL); }
- | tCHAR { $$ = make_type(RPC_FC_CHAR, NULL); }
- | tUNSIGNED tCHAR { $$ = make_type(RPC_FC_CHAR, NULL); }
| tWCHAR { $$ = make_type(RPC_FC_WCHAR, NULL); }
| int_std
- | tSIGNED int_std { $$ = $2; /* FIXME */ }
- | tUNSIGNED int_std { $$ = $2; /* FIXME */ }
+ | tSIGNED int_std { $$ = $2; $$->sign = 1; }
+ | tUNSIGNED int_std { $$ = $2; $$->sign = -1;
+ switch ($$->type) {
+ case RPC_FC_SMALL: $$->type = RPC_FC_USMALL; break;
+ case RPC_FC_SHORT: $$->type = RPC_FC_USHORT; break;
+ case RPC_FC_LONG: $$->type = RPC_FC_ULONG; break;
+ default: break;
+ }
+ }
| tFLOAT { $$ = make_type(RPC_FC_FLOAT, NULL); }
| tDOUBLE { $$ = make_type(RPC_FC_DOUBLE, NULL); }
- | tBOOLEAN { $$ = make_type(RPC_FC_BYTE, NULL); /* ? */ }
+ | tBOOLEAN { $$ = make_type(RPC_FC_BYTE, &std_bool); /* ? */ }
;
m_int:
@@ -363,6 +406,7 @@
| tLONG m_int { $$ = make_type(RPC_FC_LONG, NULL); }
| tHYPER m_int { $$ = make_type(RPC_FC_HYPER, NULL); }
| tINT64 { $$ = make_type(RPC_FC_HYPER, NULL); }
+ | tCHAR { $$ = make_type(RPC_FC_CHAR, NULL); }
;
inherit: { $$ = NULL; }
@@ -374,7 +418,7 @@
;
interfacedef: attributes interface inherit
- '{' statements '}' { $$ = $2;
+ '{' int_statements '}' { $$ = $2;
if ($$->defined) yyerror("multiple definition error\n");
$$->ref = $3;
$$->attrs = $1;
@@ -385,7 +429,7 @@
;
p_ident: '*' pident %prec PPTR { $$ = $2; $$->ptr_level++; }
- | tCONST p_ident { $$ = $2; }
+ | tCONST p_ident { $$ = $2; /* FIXME */ }
;
pident: ident
@@ -436,8 +480,9 @@
$$->defined = TRUE;
}
| tUNION t_ident
- tSWITCH '(' type ident ')'
+ tSWITCH '(' s_field ')'
m_ident '{' cases '}' { $$ = get_typev(RPC_FC_ENCAPSULATED_UNION, $2, tsUNION);
+ LINK($5, $9); $$->fields = $5;
$$->defined = TRUE;
}
;
@@ -454,6 +499,7 @@
attr_t *a = xmalloc(sizeof(attr_t));
a->type = type;
a->u.ival = 0;
+ INIT_LINK(a);
return a;
}
@@ -462,6 +508,7 @@
attr_t *a = xmalloc(sizeof(attr_t));
a->type = type;
a->u.ival = val;
+ INIT_LINK(a);
return a;
}
@@ -470,9 +517,111 @@
attr_t *a = xmalloc(sizeof(attr_t));
a->type = type;
a->u.pval = val;
+ INIT_LINK(a);
return a;
}
+static expr_t *make_expr(int type)
+{
+ expr_t *e = xmalloc(sizeof(expr_t));
+ e->type = type;
+ e->ref = NULL;
+ e->u.lval = 0;
+ INIT_LINK(e);
+ return e;
+}
+
+static expr_t *make_exprl(int type, long val)
+{
+ expr_t *e = xmalloc(sizeof(expr_t));
+ e->type = type;
+ e->ref = NULL;
+ e->u.lval = val;
+ INIT_LINK(e);
+ return e;
+}
+
+static expr_t *make_exprs(int type, char *val)
+{
+ expr_t *e = xmalloc(sizeof(expr_t));
+ /* FIXME: if type is aIDENTIFIER, we could check for match against const
+ * declaration, and change to appropriate type and value if so */
+ e->type = type;
+ e->ref = NULL;
+ e->u.sval = val;
+ INIT_LINK(e);
+ return e;
+}
+
+static expr_t *make_expr1(int type, expr_t *expr)
+{
+ expr_t *e;
+ /* check for compile-time optimization */
+ if (expr->type == aNUM) {
+ switch (type) {
+ case NEG:
+ expr->u.lval = -expr->u.lval;
+ return expr;
+ default:
+ }
+ }
+ e = xmalloc(sizeof(expr_t));
+ e->type = type;
+ e->ref = expr;
+ e->u.lval = 0;
+ INIT_LINK(e);
+ return e;
+}
+
+static expr_t *make_expr2(int type, expr_t *expr1, expr_t *expr2)
+{
+ expr_t *e;
+ /* check for compile-time optimization */
+ if (expr1->type == aNUM && expr2->type == aNUM) {
+ switch (type) {
+ case '+':
+ expr1->u.lval += expr2->u.lval;
+ free(expr2);
+ return expr1;
+ case '-':
+ expr1->u.lval -= expr2->u.lval;
+ free(expr2);
+ return expr1;
+ case '*':
+ expr1->u.lval *= expr2->u.lval;
+ free(expr2);
+ return expr1;
+ case '/':
+ expr1->u.lval /= expr2->u.lval;
+ free(expr2);
+ return expr1;
+ case '|':
+ expr1->u.lval |= expr2->u.lval;
+ free(expr2);
+ return expr1;
+ case '&':
+ expr1->u.lval &= expr2->u.lval;
+ free(expr2);
+ return expr1;
+ case SHL:
+ expr1->u.lval <<= expr2->u.lval;
+ free(expr2);
+ return expr1;
+ case SHR:
+ expr1->u.lval >>= expr2->u.lval;
+ free(expr2);
+ return expr1;
+ default:
+ }
+ }
+ e = xmalloc(sizeof(expr_t));
+ e->type = type;
+ e->ref = expr1;
+ e->u.ext = expr2;
+ INIT_LINK(e);
+ return e;
+}
+
static type_t *make_type(BYTE type, type_t *ref)
{
type_t *t = xmalloc(sizeof(type_t));
@@ -485,6 +634,7 @@
t->fields = NULL;
t->ignore = parse_only;
t->is_const = FALSE;
+ t->sign = 0;
t->defined = FALSE;
t->written = FALSE;
INIT_LINK(t);
@@ -521,12 +671,13 @@
return t;
}
-static void set_type(var_t *v, typeref_t *ref)
+static void set_type(var_t *v, typeref_t *ref, expr_t *arr)
{
v->type = ref->ref;
v->tname = ref->name;
ref->name = NULL;
free(ref);
+ v->array = arr;
}
static var_t *make_var(char *name)
@@ -537,6 +688,9 @@
v->type = NULL;
v->tname = NULL;
v->attrs = NULL;
+ v->array = NULL;
+ v->has_val = FALSE;
+ v->lval = 0;
INIT_LINK(v);
return v;
}
@@ -559,7 +713,7 @@
struct rtype *next;
};
-struct rtype *first;
+struct rtype *first_type;
static type_t *reg_type(type_t *type, char *name, int t)
{
@@ -572,8 +726,8 @@
nt->name = name;
nt->type = type;
nt->t = t;
- nt->next = first;
- first = nt;
+ nt->next = first_type;
+ first_type = nt;
return type;
}
@@ -608,7 +762,7 @@
static type_t *find_type(char *name, int t)
{
- struct rtype *cur = first;
+ struct rtype *cur = first_type;
while (cur && (cur->t != t || strcmp(cur->name, name)))
cur = cur->next;
if (!cur) {
@@ -627,7 +781,7 @@
int is_type(const char *name)
{
- struct rtype *cur = first;
+ struct rtype *cur = first_type;
while (cur && (cur->t || strcmp(cur->name, name)))
cur = cur->next;
if (cur) return TRUE;
@@ -639,7 +793,7 @@
struct rtype *cur = NULL;
type_t *tp;
if (name) {
- cur = first;
+ cur = first_type;
while (cur && (cur->t != t || strcmp(cur->name, name)))
cur = cur->next;
}
@@ -662,4 +816,3 @@
}
return get_type(type, sname, t);
}
-
Index: tools/widl/proxy.c
===================================================================
RCS file: /cvsroot/rewind/rewind/tools/widl/proxy.c,v
retrieving revision 1.1
diff -u -r1.1 proxy.c
--- tools/widl/proxy.c 8 Jun 2002 13:18:16 -0000 1.1
+++ tools/widl/proxy.c 31 Oct 2002 23:21:31 -0000
@@ -287,12 +287,13 @@
{
if_list *lcur = if_first;
if_list *cur;
+ char *file_id = "XXX";
int c;
if (!lcur) return;
while (NEXT_LINK(lcur)) lcur = NEXT_LINK(lcur);
- fprintf(proxy, "const CInterfaceProxyVtbl* _XXX_ProxyVtblList[] = {\n");
+ fprintf(proxy, "const CInterfaceProxyVtbl* _%s_ProxyVtblList[] = {\n", file_id);
cur = lcur;
while (cur) {
fprintf(proxy, " (CInterfaceProxyVtbl*)&%sProxyVtbl,\n", cur->iface->name);
@@ -302,7 +303,7 @@
fprintf(proxy, "};\n");
fprintf(proxy, "\n");
- fprintf(proxy, "const CInterfaceStubVtbl* _XXX_StubVtblList[] = {\n");
+ fprintf(proxy, "const CInterfaceStubVtbl* _%s_StubVtblList[] = {\n", file_id);
cur = lcur;
while (cur) {
fprintf(proxy, " (CInterfaceStubVtbl*)&%sStubVtbl,\n", cur->iface->name);
@@ -312,7 +313,7 @@
fprintf(proxy, "};\n");
fprintf(proxy, "\n");
- fprintf(proxy, "const PCInterfaceName _XXX_InterfaceNamesList[] = {\n");
+ fprintf(proxy, "const PCInterfaceName _%s_InterfaceNamesList[] = {\n", file_id);
cur = lcur;
while (cur) {
fprintf(proxy, " \"%s\",\n", cur->iface->name);
@@ -322,14 +323,14 @@
fprintf(proxy, "};\n");
fprintf(proxy, "\n");
- fprintf(proxy, "#define _XXX_CHECK_IID(n) IID_GENERIC_CHECK_IID(_XXX, pIID, n)\n");
+ fprintf(proxy, "#define _%s_CHECK_IID(n) IID_GENERIC_CHECK_IID(_XXX, pIID, n)\n", file_id);
fprintf(proxy, "\n");
- fprintf(proxy, "int __stdcall _XXX_IID_Lookup(const IID* pIID, int* pIndex)\n");
+ fprintf(proxy, "int __stdcall _%s_IID_Lookup(const IID* pIID, int* pIndex)\n", file_id);
fprintf(proxy, "{\n");
cur = lcur;
c = 0;
while (cur) {
- fprintf(proxy, " if (!_XXX_CHECK_IID(%d)) {\n", c);
+ fprintf(proxy, " if (!_%s_CHECK_IID(%d)) {\n", file_id, c);
fprintf(proxy, " *pIndex = %d\n", c);
fprintf(proxy, " return 1;\n");
fprintf(proxy, " }\n");
@@ -340,12 +341,12 @@
fprintf(proxy, "}\n");
fprintf(proxy, "\n");
- fprintf(proxy, "const ExtendedProxyFileInfo XXX_ProxyFileInfo = {\n");
- fprintf(proxy, " (PCInterfaceProxyVtblList*)&_XXX_ProxyVtblList,\n");
- fprintf(proxy, " (PCInterfaceStubVtblList*)&_XXX_StubVtblList,\n");
- fprintf(proxy, " (const PCInterfaceName*)&_XXX_InterfaceNamesList,\n");
+ fprintf(proxy, "const ExtendedProxyFileInfo %s_ProxyFileInfo = {\n", file_id);
+ fprintf(proxy, " (PCInterfaceProxyVtblList*)&_%s_ProxyVtblList,\n", file_id);
+ fprintf(proxy, " (PCInterfaceStubVtblList*)&_%s_StubVtblList,\n", file_id);
+ fprintf(proxy, " (const PCInterfaceName*)&_%s_InterfaceNamesList,\n", file_id);
fprintf(proxy, " 0,\n");
- fprintf(proxy, " &_XXX_IID_Lookup,\n");
+ fprintf(proxy, " &_%s_IID_Lookup,\n", file_id);
fprintf(proxy, " %d,\n", c);
fprintf(proxy, " 1\n");
fprintf(proxy, "};\n");
Index: tools/widl/widl.c
===================================================================
RCS file: /cvsroot/rewind/rewind/tools/widl/widl.c,v
retrieving revision 1.1
diff -u -r1.1 widl.c
--- tools/widl/widl.c 8 Jun 2002 13:18:16 -0000 1.1
+++ tools/widl/widl.c 31 Oct 2002 23:21:31 -0000
@@ -54,6 +54,7 @@
char *input_name;
char *header_name;
+char *header_token;
char *proxy_name;
char *temp_name;
@@ -69,6 +70,23 @@
static void rm_tempfile(void);
static void segvhandler(int sig);
+static char *make_token(const char *name)
+{
+ char *token;
+ char *slash;
+ int i;
+
+ slash = strrchr(name, '/');
+ if (slash) name = slash + 1;
+
+ token = xstrdup(name);
+ for (i=0; token[i]; i++) {
+ if (!isalnum(token[i])) token[i] = '_';
+ else token[i] = toupper(token[i]);
+ }
+ return token;
+}
+
int main(int argc,char *argv[])
{
extern char* optarg;
@@ -168,12 +186,17 @@
return 1;
}
+ header_token = make_token(header_name);
+
header = fopen(header_name, "w");
- fprintf(header, "/*** Autogenerated by WIDL %s - Do not edit ***/\n", WIDL_FULLVERSION);
+ fprintf(header, "/*** Autogenerated by WIDL %s from %s - Do not edit ***/\n", WIDL_FULLVERSION, input_name);
+ fprintf(header, "#ifndef __WIDL_%s\n", header_token);
+ fprintf(header, "#define __WIDL_%s\n", header_token);
ret = yyparse();
finish_proxy();
+ fprintf(header, "#endif /* __WIDL_%s */\n", header_token);
fclose(header);
fclose(yyin);
Index: tools/widl/widltypes.h
===================================================================
RCS file: /cvsroot/rewind/rewind/tools/widl/widltypes.h,v
retrieving revision 1.1
diff -u -r1.1 widltypes.h
--- tools/widl/widltypes.h 8 Jun 2002 13:18:16 -0000 1.1
+++ tools/widl/widltypes.h 31 Oct 2002 23:21:31 -0000
@@ -12,6 +12,7 @@
#include "wine/rpcfc.h"
typedef struct _attr_t attr_t;
+typedef struct _expr_t expr_t;
typedef struct _type_t type_t;
typedef struct _typeref_t typeref_t;
typedef struct _var_t var_t;
@@ -39,6 +40,18 @@
DECL_LINK(attr_t)
};
+struct _expr_t {
+ int type;
+ expr_t *ref;
+ union {
+ long lval;
+ char *sval;
+ expr_t *ext;
+ } u;
+ /* parser-internal */
+ DECL_LINK(expr_t)
+};
+
struct _type_t {
char *name;
BYTE type;
@@ -47,7 +60,7 @@
attr_t *attrs;
func_t *funcs;
var_t *fields;
- int ignore, is_const;
+ int ignore, is_const, sign;
int defined, written;
/* parser-internal */
@@ -63,9 +76,12 @@
struct _var_t {
char *name;
int ptr_level;
+ expr_t *array;
type_t *type;
char *tname;
attr_t *attrs;
+ int has_val;
+ long lval;
/* parser-internal */
DECL_LINK(var_t)
More information about the wine-patches
mailing list