Commit 90adf0ef authored by ees1dw's avatar ees1dw

trashed dcw.h; replaced assertions with if's etc..

parent 91a1b461
......@@ -17,7 +17,8 @@
* which together form a module provided the relevent data types.
*/
#include <dcw.h>
#include <stdio.h>
#include <string.h>
#include "struct.h"
#include "lexer.h"
#include "parser.h"
......@@ -25,7 +26,7 @@
#include "optimize.h"
#define MUSTBE(b) ASSERT(b,("Usage: datadec [-vno] outfile [infile]\n"))
#define MUSTBE(b) {if(!(b)){fprintf(stderr,"Usage: datadec [-vno] outfile [infile]\n");exit(1);}}
#define NEED_ANOTHER_ARG MUSTBE( IS_ANOTHER_ARG )
#define REQUIRE_NO_MORE_ARGS MUSTBE( argc == arg )
......@@ -66,7 +67,9 @@ void main( argc, argv ) int argc; char **argv;
opt = TRUE;
break;
default:
ABORT( ("datadec: illegal option -%c\n",*s) );
fprintf( stderr,
"datadec: illegal option -%c\n", *s );
exit(1);
}
}
arg++;
......@@ -82,8 +85,12 @@ void main( argc, argv ) int argc; char **argv;
if( IS_ANOTHER_ARG ) {
lexfile = fopen( argv[arg], "r" );
ASSERT( lexfile != NULL,
("datadec: can't open '%s'\n",argv[arg]) );
if( lexfile == NULL )
{
fprintf( stderr, "datadec: can't open '%s'\n",
argv[arg] );
exit(1);
}
arg++;
} else {
lexfile = stdin;
......
#include <dcw.h>
#include <stdio.h>
#include "struct.h"
#include "decs.h"
......@@ -99,7 +99,11 @@ static void h_declns( base, exports, init, d ) char *base, *exports; BOOL init;
sprintf( tempname, "%s.h", base );
hfile = fopen( tempname, "w" );
ASSERT( hfile != NULL, ("datadec: can't create '%s'\n",tempname) );
if( hfile == NULL )
{
fprintf( stderr, "datadec: can't create '%s'\n", tempname );
exit(1);
}
usefile( hfile );
......@@ -160,7 +164,11 @@ static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; de
sprintf( tempname, "%s.c", base );
cfile = fopen( tempname, "w" );
ASSERT( cfile != NULL, ("datadec: can't create '%s'\n",tempname) );
if( cfile == NULL )
{
fprintf( stderr, "datadec: can't create '%s'\n", tempname );
exit(1);
}
usefile( cfile );
......@@ -431,7 +439,11 @@ static void cons_fn_proto( d, s, prot ) decln d; shapelist s; BOOL prot;
paramlist p;
BOOL first;
ASSERT( d->Struct, ("cons_fn_proto: d->Struct is false!\n") );
if( ! d->Struct )
{
fprintf( stderr, "cons_fn_proto: d->Struct is false!\n" );
exit(1);
}
fprintf( outfile, "extern %s %s_%s( ", d->name, d->name, s->name );
if( prot )
......@@ -459,7 +471,11 @@ static void cons_fn( d, s ) decln d; shapelist s;
paramlist p;
BOOL first;
ASSERT( d->Struct, ("cons_fn: d->Struct is FALSE!\n") );
if( ! d->Struct )
{
fprintf( stderr, "cons_fn: d->Struct is FALSE!\n" );
exit(1);
}
fprintf( outfile, "%s %s_%s( ", d->name, d->name, s->name );
first = TRUE;
......@@ -530,7 +546,11 @@ static void decons_fns_type( d ) decln d;
{
shapelist s;
ASSERT( d->Struct, ("decons_fns_type: d->Struct is FALSE!\n") );
if( ! d->Struct )
{
fprintf( stderr, "decons_fns_type: d->Struct is FALSE!\n" );
exit(1);
}
if( d->ManyShapes )
{
......@@ -553,9 +573,17 @@ static void decons_fns_type( d ) decln d;
static void deconskind_proto( d, prot ) decln d; BOOL prot;
{
ASSERT( d->ManyShapes,
("deconskind_proto: d->ManyShapes is FALSE!\n") );
ASSERT( d->Struct, ("deconskind_proto: d->Struct is FALSE!\n") );
if( ! d->ManyShapes )
{
fprintf( stderr,
"deconskind_proto: d->ManyShapes is FALSE!\n" );
exit(1);
}
if( ! d->Struct )
{
fprintf( stderr, "deconskind_proto: d->Struct is FALSE!\n" );
exit(1);
}
fprintf( outfile, "extern kind_of_%s %s_kind( ", d->name, d->name );
if( prot )
......@@ -570,8 +598,16 @@ static void deconskind_fn( d ) decln d;
{
shapelist s = d->shapes;
ASSERT( d->ManyShapes, ("deconskind_fn: d->ManyShapes is FALSE!\n") );
ASSERT( d->Struct, ("deconskind_fn: d->Struct is FALSE!\n") );
if( ! d->ManyShapes )
{
fprintf( stderr, "deconskind_fn: d->ManyShapes is FALSE!\n" );
exit(1);
}
if( ! d->Struct )
{
fprintf( stderr, "deconskind_fn: d->Struct is FALSE!\n" );
exit(1);
}
fprintf( outfile, "kind_of_%s %s_kind( this ) %s this;\n",
d->name, d->name, d->name );
......@@ -607,9 +643,16 @@ static void deconskind_fn( d ) decln d;
static void decons_fn_proto( d, s, prot ) decln d; shapelist s; BOOL prot;
{
ASSERT( d->Struct, ("decons_fn_proto: d->Struct is FALSE!\n") );
ASSERT( s->params != NULL,
("decons_fn_proto: no fields in shape!!\n") );
if( ! d->Struct )
{
fprintf( stderr, "decons_fn_proto: d->Struct is FALSE!\n" );
exit(1);
}
if( s->params == NULL )
{
fprintf( stderr, "decons_fn_proto: no fields in shape!!\n" );
exit(1);
}
fprintf( outfile, "extern void get_%s_%s(", d->name, s->name );
if( prot )
......@@ -630,8 +673,16 @@ static void decons_fn( d, s ) decln d; shapelist s;
{
paramlist p;
ASSERT( d->Struct, ("decons_fn: d->Struct is FALSE!\n") );
ASSERT( s->params != NULL, ("decons_fn: no fields in shape!!\n") );
if( ! d->Struct )
{
fprintf( stderr, "decons_fn: d->Struct is FALSE!\n" );
exit(1);
}
if( s->params == NULL )
{
fprintf( stderr, "decons_fn: no fields in shape!!\n" );
exit(1);
}
fprintf( outfile, "void get_%s_%s( this", d->name, s->name );
for( p=s->params; p != NULL; p=p->next )
......@@ -797,8 +848,13 @@ static void print_all_params( d, s ) declnlist d; shapelist s;
n = pl->item->num;
for( p = s->params; --n; p = p->next )
{
ASSERT( p != NULL,
("datadec: bad printitem in shape %s of type %s\n",s->name,d->name));
if( p == NULL )
{
fprintf( stderr,
"datadec: bad printitem in shape %s of type %s\n",
s->name, d->name );
exit(1);
}
}
print_param( s, p, d->Union );
}
......
......@@ -15,8 +15,9 @@
*/
#include <dcw.h>
#include <stdio.h>
#include <ctype.h>
#include "struct.h"
#include "lexer.h"
......@@ -71,7 +72,11 @@ static void white_space()
void ungettok()
{
ASSERT( ! havepushedtok, ("ungettok: can't push 2 tokens\n") );
if( havepushedtok )
{
fprintf( stderr, "ungettok: can't push 2 tokens\n" );
exit(1);
}
havepushedtok = TRUE;
#ifdef DEBUGGING
printf( "lexer: ungot token %s\n", tokenname[ curtok ] );
......
/* optimize.c */
#include <dcw.h>
#include <stdio.h>
#include <string.h>
#include "struct.h"
#include "optimize.h"
BOOL opt; /* opt == perform optimizations */
......@@ -86,16 +87,41 @@ static void optimize_decln( d ) decln d;
#undef XXX
}
ASSERT( implies(d->Union,d->Struct),
("optimizer error: type %s has Union&!Struct\n",d->name) );
ASSERT( implies(d->TagField,d->Struct),
("optimizer error: type %s has TagField&!Struct\n",d->name) );
ASSERT( implies(d->UseNull,d->Struct),
("optimizer error: type %s has UseNull&!Struct\n",d->name) );
ASSERT( implies(d->TagField,d->ManyShapes),
("optimizer error: type %s has TagField&!ManyShapes\n",d->name) );
ASSERT( implies(d->Union,d->TagField),
("optimizer error: type %s has Union&!TagField\n",d->name) );
if( ! implies(d->Union,d->Struct) )
{
fprintf( stderr,
"optimizer error: type %s has Union&!Struct\n",
d->name );
exit(1);
}
if( ! implies(d->TagField,d->Struct) )
{
fprintf( stderr,
"optimizer error: type %s has TagField&!Struct\n",
d->name );
exit(1);
}
if( ! implies(d->UseNull,d->Struct) )
{
fprintf( stderr,
"optimizer error: type %s has UseNull&!Struct\n",
d->name );
exit(1);
}
if( ! implies(d->TagField,d->ManyShapes) )
{
fprintf( stderr,
"optimizer error: type %s has TagField&!ManyShapes\n",
d->name );
exit(1);
}
if( ! implies(d->Union,d->TagField) )
{
fprintf( stderr,
"optimizer error: type %s has Union&!TagField\n",
d->name );
exit(1);
}
}
......
......@@ -25,12 +25,17 @@
*/
#include <dcw.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include "struct.h"
#include "lexer.h"
#include "parser.h"
#define COPYOF(new,old) {new=malloc(1+strlen(old));if(new)strcpy(new,old);}
/*
/^#ifdef HASPROTOS
!/endif$
......
......@@ -15,10 +15,13 @@
*/
#include <dcw.h>
#include <stdio.h>
#include <malloc.h>
#include "struct.h"
#define Puts(s) fputs(s,stdout)
#define NEW(t) (t) malloc( sizeof(struct t) )
#define COPYOF(new,old) {new=malloc(1+strlen(old));if(new)strcpy(new,old);}
declnlist build_declnlist(name,s,next) char *name; shapelist s; declnlist next;
......@@ -142,7 +145,10 @@ void print_printitem(i) printitem i;
printf("\"%s\" ", i->str);
break;
default:
ABORT( ("datadec: print_printitem called with printitem tag = %d\n", i->tag ) );
fprintf( stderr,
"datadec: print_printitem called with tag = %d\n",
i->tag );
exit(1);
}
}
......@@ -172,9 +178,13 @@ param findnthparam( n, p, sname, dname ) int n; paramlist p; char *sname, *dname
for( ; p != NULL && --m; p = p->next );
ASSERT( p != NULL,
("datadec: bad print number %d in shape %s of type %s\n",
m, sname, dname));
if( p == NULL )
{
fprintf( stderr,
"datadec: bad print number %d in shape %s of type %s\n",
m, sname, dname );
exit(1);
}
return p;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment