rpc_parse.c revision a2f144d1eca25f33af1e19affd8eda208f547108
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
/*
* rpc_parse.c, Parser for the RPC protocol compiler
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "rpc_scan.h"
#include "rpc_parse.h"
#include "rpc_util.h"
#define ARGNAME "arg"
extern char *make_argname(char *, char *);
static void isdefined(definition *);
static void def_struct(definition *);
static void def_program(definition *);
static void def_enum(definition *);
static void def_const(definition *);
static void def_union(definition *);
static void def_typedef(definition *);
static void unsigned_dec(char **);
/*
* return the next definition you see
*/
get_definition(void)
{
case TOK_STRUCT:
break;
case TOK_UNION:
break;
case TOK_TYPEDEF:
break;
case TOK_ENUM:
break;
case TOK_PROGRAM:
break;
case TOK_CONST:
break;
case TOK_EOF:
return (NULL);
default:
error("definition keyword expected");
}
return (defp);
}
static void
{
}
/*
* We treat s == NULL the same as *s == '\0'
*/
static int
{
s1 = "";
s2 = "";
return (1);
}
static int
{
/* We only want typedef definitions */
return (1);
return (0);
}
static int
{
/*
* Now check for the following special case if first is true:
*
* struct foo {
* ...
* foo *next;
* };
*
*
* In the above cases foo has not yet been entered in the type list,
* defined. So there is no typedef entry. The prefix in that case
* could be empty.
*/
return (1);
return (0);
}
static int
{
definition *dp;
return (1);
/*
* Check for valid declaration:
* Only prefixes allowed are none and struct.
* Only relations allowed are pointer or alias.
*/
return (0);
return (0);
/*
* Check if we found a definition.
*/
return (0);
/*
* Check for valid prefix. We eventually need to see one
* and only one struct.
*/
/*
* If the current declaration prefix in empty
* then the definition found must have an empty
* prefix or a struct prefix
*/
return (0);
/*
* if the current prefix is struct tne new prefix
* must be empty
*/
return (0);
/* Should never get here */
return (0);
/*
* Check for valid relation. We need to see one and
* only one REL_POINTER. The only valid relation types
* are REL_POINTER and REL_ALIAS.
*/
return (0);
return (0);
/* Should never get here */
return (0);
/* Set up the current declaration */
}
/* We have a self reference type */
return (1);
}
static void
{
do {
/*
* Keep a referenct to the last declaration to check for
* tail recurrsion.
*/
/*
* Check for tail recurse. If the last declaration refers to this
* structure then mark this stucture to convert the tail recursion
* to itteration.
*/
}
static void
{
int num_args;
do {
do {
/* get result type */
error("illegal result type");
}
/* get args - first one */
num_args = 1;
/*
* type of DEF_PROGRAM in the first
* get_prog_declaration and DEF_STURCT in the next
* allows void as argument if it is the only argument
*/
/* get args */
num_args++;
num_args);
}
/* multiple arguments are only allowed in newstyle */
error("only one argument is allowed");
}
error("illegal use of void "
"in program definition");
}
/* make the argument structure name for each arg */
/* free the memory ?? */
}
}
static void
{
do {
}
}
static void
{
}
static void
{
int flag;
/* now peek at next token */
flag = 0;
do {
/* continued case statement */
} else if (flag) {
}
}
} else {
}
}
static char *reserved_words[] = {
"array",
"bytes",
"destroy",
"free",
"getpos",
"inline",
"pointer",
"reference",
"setpos",
"sizeof",
"union",
"vector",
};
static char *reserved_types[] = {
"opaque",
"string",
};
/*
* check that the given name is not one that would eventually result in
* xdr routines that would conflict with internal XDR routines.
*/
static void
{
int i;
char tmp[100];
for (i = 0; reserved_words[i] != NULL; i++) {
"illegal (reserved) name :\'%s\' "
"in type definition",
name);
}
}
if (new_type) {
for (i = 0; reserved_types[i] != NULL; i++) {
"illegal (reserved) name :\'%s\' "
"in type definition",
name);
}
}
}
}
static void
{
}
static void
{
return;
}
error("no array-of-pointer declarations "
"-- use typedef");
error("no array-of-pointer declarations "
"-- use typedef");
} else {
}
}
error("array declaration expected");
}
error("variable-length array declaration expected");
}
}
}
static void
{
if (dkind == DEF_PROGRAM) {
return;
}
}
else {
/* default name of argument */
}
error("internal error -- out of memory");
return;
error("opaque -- illegal argument type");
error("pointer to string not allowed "
"in program arguments\n");
}
/* optional name of argument */
}
error("arrays cannot be declared as arguments "
"to procedures -- use typedef");
}
/* unspecified size, use max */
} else {
}
}
/*
* .x specifies just string as
* type of argument
* - make it string<>
*/
}
}
}
static void
{
case TOK_IDENT:
break;
case TOK_STRUCT:
case TOK_ENUM:
case TOK_UNION:
break;
case TOK_UNSIGNED:
break;
case TOK_SHORT:
*typep = "short";
break;
case TOK_LONG:
*typep = "long";
break;
case TOK_HYPER:
*typep = "longlong_t";
break;
case TOK_VOID:
dkind != DEF_RESULT) {
error("voids allowed only inside union and "
"program definitions with one argument");
}
break;
case TOK_ONEWAY:
if (dkind != DEF_RESULT) {
error("oneways allowed only inside result definitions");
}
break;
case TOK_STRING:
case TOK_OPAQUE:
case TOK_CHAR:
case TOK_INT:
case TOK_FLOAT:
case TOK_DOUBLE:
case TOK_BOOL:
case TOK_QUAD:
break;
default:
error("expected type specifier");
}
}
static void
unsigned_dec(char **typep)
{
case TOK_CHAR:
*typep = "u_char";
break;
case TOK_SHORT:
*typep = "u_short";
break;
case TOK_LONG:
*typep = "u_long";
break;
case TOK_HYPER:
*typep = "u_longlong_t";
break;
case TOK_INT:
*typep = "u_int";
break;
default:
*typep = "u_int";
break;
}
}