version 1.7, 2001/11/24 19:19:59 |
version 1.8, 2001/12/05 09:50:31 |
|
|
#endif |
#endif |
|
|
/* |
/* |
* rpc_parse.c, Parser for the RPC protocol compiler |
* rpc_parse.c, Parser for the RPC protocol compiler |
* Copyright (C) 1987 Sun Microsystems, Inc. |
* Copyright (C) 1987 Sun Microsystems, Inc. |
*/ |
*/ |
#include <stdio.h> |
#include <stdio.h> |
|
|
do { |
do { |
/* get result type */ |
/* get result type */ |
plist = ALLOC(proc_list); |
plist = ALLOC(proc_list); |
get_type(&plist->res_prefix, &plist->res_type, |
get_type(&plist->res_prefix, &plist->res_type, |
DEF_PROGRAM); |
DEF_PROGRAM); |
if (streq(plist->res_type, "opaque")) { |
if (streq(plist->res_type, "opaque")) { |
error("illegal result type"); |
error("illegal result type"); |
|
|
/* get args - first one*/ |
/* get args - first one*/ |
num_args = 1; |
num_args = 1; |
isvoid = FALSE; |
isvoid = FALSE; |
/* type of DEF_PROGRAM in the first |
/* type of DEF_PROGRAM in the first |
* get_prog_declaration and DEF_STURCT in the next |
* get_prog_declaration and DEF_STURCT in the next |
* allows void as argument if it is the only argument |
* allows void as argument if it is the only argument |
*/ |
*/ |
|
|
decls->decl = dec; |
decls->decl = dec; |
tailp = &decls->next; |
tailp = &decls->next; |
/* get args */ |
/* get args */ |
while(peekscan(TOK_COMMA, &tok)) { |
while (peekscan(TOK_COMMA, &tok)) { |
num_args++; |
num_args++; |
get_prog_declaration(&dec, DEF_STRUCT, |
get_prog_declaration(&dec, DEF_STRUCT, |
num_args); |
num_args); |
decls = ALLOC(decl_list); |
decls = ALLOC(decl_list); |
decls->decl = dec; |
decls->decl = dec; |
|
|
if( !newstyle && num_args > 1 ) { |
if( !newstyle && num_args > 1 ) { |
error("only one argument is allowed" ); |
error("only one argument is allowed" ); |
} |
} |
if (isvoid && num_args > 1) { |
if (isvoid && num_args > 1) { |
error("illegal use of void in program definition"); |
error("illegal use of void in program definition"); |
} |
} |
*tailp = NULL; |
*tailp = NULL; |
|
|
scan_num(&tok); |
scan_num(&tok); |
vlist->vers_num = tok.str; |
vlist->vers_num = tok.str; |
/* make the argument structure name for each arg*/ |
/* make the argument structure name for each arg*/ |
for(plist = vlist->procs; plist != NULL; |
for(plist = vlist->procs; plist != NULL; |
plist = plist->next) { |
plist = plist->next) { |
plist->args.argname = make_argname(plist->proc_name, |
plist->args.argname = make_argname(plist->proc_name, |
vlist->vers_num); |
vlist->vers_num); |
/* free the memory ??*/ |
/* free the memory ??*/ |
} |
} |
scan(TOK_SEMICOLON, &tok); |
scan(TOK_SEMICOLON, &tok); |
|
|
if(peekscan(TOK_CASE,&tok)) |
if(peekscan(TOK_CASE,&tok)) |
{ |
{ |
|
|
do |
do |
{ |
{ |
scan2(TOK_IDENT, TOK_CHARCONST, &tok); |
scan2(TOK_IDENT, TOK_CHARCONST, &tok); |
cases->contflag=1; /* continued case statement */ |
cases->contflag=1; /* continued case statement */ |
|
|
cases = ALLOC(case_list); |
cases = ALLOC(case_list); |
cases->case_name = tok.str; |
cases->case_name = tok.str; |
scan(TOK_COLON, &tok); |
scan(TOK_COLON, &tok); |
|
|
}while(peekscan(TOK_CASE,&tok)); |
} while (peekscan(TOK_CASE,&tok)); |
} |
} |
else |
else |
if(flag) |
if(flag) |
|
|
} |
} |
} |
} |
|
|
static char* reserved_words[] = { |
static char *reserved_words[] = { |
"array", |
"array", |
"bytes", |
"bytes", |
"destroy", |
"destroy", |
|
|
NULL |
NULL |
}; |
}; |
|
|
static char* reserved_types[] = { |
static char *reserved_types[] = { |
"opaque", |
"opaque", |
"string", |
"string", |
NULL |
NULL |
|
|
xdr routines that would conflict with internal XDR routines. */ |
xdr routines that would conflict with internal XDR routines. */ |
static check_type_name( name, new_type ) |
static check_type_name( name, new_type ) |
int new_type; |
int new_type; |
char* name; |
char *name; |
{ |
{ |
int i; |
int i; |
char tmp[100]; |
char tmp[100]; |
|
|
for( i = 0; reserved_words[i] != NULL; i++ ) { |
for( i = 0; reserved_words[i] != NULL; i++ ) { |
if( strcmp( name, reserved_words[i] ) == 0 ) { |
if( strcmp( name, reserved_words[i] ) == 0 ) { |
sprintf(tmp, |
sprintf(tmp, |
"illegal (reserved) name :\'%s\' in type definition", name ); |
"illegal (reserved) name :\'%s\' in type definition", name ); |
error(tmp); |
error(tmp); |
} |
} |
|
|
if( new_type ) { |
if( new_type ) { |
for( i = 0; reserved_types[i] != NULL; i++ ) { |
for( i = 0; reserved_types[i] != NULL; i++ ) { |
if( strcmp( name, reserved_types[i] ) == 0 ) { |
if( strcmp( name, reserved_types[i] ) == 0 ) { |
sprintf(tmp, |
sprintf(tmp, |
"illegal (reserved) name :\'%s\' in type definition", name ); |
"illegal (reserved) name :\'%s\' in type definition", name ); |
error(tmp); |
error(tmp); |
} |
} |
|
|
token tok; |
token tok; |
char name[10]; /* argument name */ |
char name[10]; /* argument name */ |
|
|
if (dkind == DEF_PROGRAM) { |
if (dkind == DEF_PROGRAM) { |
peek(&tok); |
peek(&tok); |
if (tok.kind == TOK_RPAREN) { /* no arguments */ |
if (tok.kind == TOK_RPAREN) { /* no arguments */ |
dec->rel = REL_ALIAS; |
dec->rel = REL_ALIAS; |
|
|
dec->rel = REL_ALIAS; |
dec->rel = REL_ALIAS; |
if (peekscan(TOK_IDENT, &tok)) /* optional name of argument */ |
if (peekscan(TOK_IDENT, &tok)) /* optional name of argument */ |
strcpy(name, tok.str); |
strcpy(name, tok.str); |
else |
else |
sprintf(name, "%s%d", ARGNAME, num); /* default name of argument */ |
sprintf(name, "%s%d", ARGNAME, num); /* default name of argument */ |
|
|
dec->name = (char *)strdup(name); |
dec->name = (char *)strdup(name); |
|
|
if (streq(dec->type, "void")) { |
if (streq(dec->type, "void")) { |
return; |
return; |
} |
} |
|
|
if (streq(dec->type, "opaque")) { |
if (streq(dec->type, "opaque")) { |
error("opaque -- illegal argument type"); |
error("opaque -- illegal argument type"); |
} |
} |
if (peekscan(TOK_STAR, &tok)) { |
if (peekscan(TOK_STAR, &tok)) { |
if (streq(dec->type, "string")) { |
if (streq(dec->type, "string")) { |
error("pointer to string not allowed in program arguments\n"); |
error("pointer to string not allowed in program arguments\n"); |
} |
} |
|
|
} |
} |
if (streq(dec->type, "string")) { |
if (streq(dec->type, "string")) { |
if (dec->rel != REL_ARRAY) { /* .x specifies just string as |
if (dec->rel != REL_ARRAY) { /* .x specifies just string as |
* type of argument |
* type of argument |
* - make it string<> |
* - make it string<> |
*/ |
*/ |
dec->rel = REL_ARRAY; |
dec->rel = REL_ARRAY; |