Commit 25d62868 authored by dcw's avatar dcw
Browse files

finished it!

parent fe189fca
...@@ -2,14 +2,9 @@ ...@@ -2,14 +2,9 @@
#include <dcw.h> #include <dcw.h>
#include <string.h>
#include "struct.h" #include "struct.h"
#include "decs.h" #include "decs.h"
#include <string.h>
typedef declnlist decln; /* JUST THE FIRST */
typedef shapelist shape; /* JUST THE FIRST */
typedef paramlist param; /* JUST THE FIRST */
/* /*
...@@ -36,8 +31,10 @@ static void deconsproc_body( decln , shape ); ...@@ -36,8 +31,10 @@ static void deconsproc_body( decln , shape );
static void writeproc_header( char * ); static void writeproc_header( char * );
static void writeproc_body( decln ); static void writeproc_body( decln );
static void write_using_case( char * , char * , shapelist ); static void write_using_case( char * , char * , shapelist );
static void write_param( char * , param );
static void write_all_params( char * , shape ); static void write_all_params( char * , shape );
static void write_default_printlist( shape );
static void write_printlist( shape , char * );
static void write_param( char * , param );
static void outstring( char * ); static void outstring( char * );
static void write_bool( void ); static void write_bool( void );
static char * lookup_type( char * ); static char * lookup_type( char * );
...@@ -61,8 +58,10 @@ static void deconsproc_body(); ...@@ -61,8 +58,10 @@ static void deconsproc_body();
static void writeproc_header(); static void writeproc_header();
static void writeproc_body(); static void writeproc_body();
static void write_using_case(); static void write_using_case();
static void write_param();
static void write_all_params(); static void write_all_params();
static void write_default_printlist();
static void write_printlist();
static void write_param();
static void outstring(); static void outstring();
static void write_bool(); static void write_bool();
static char * lookup_type(); static char * lookup_type();
...@@ -556,25 +555,41 @@ static void writeproc_header( name ) char *name; ...@@ -556,25 +555,41 @@ static void writeproc_header( name ) char *name;
static void writeproc_body( d ) decln d; static void writeproc_body( d ) decln d;
{ {
shapelist s;
shapelist shapes; shapelist shapes;
writeproc_header( d->name ); writeproc_header( d->name );
nl(); nl();
if( d->PutLoop )
{
line( "VAR over : BOOLEAN;" );
nl();
}
line( "BEGIN" ); line( "BEGIN" );
indent(); indent();
if( d->PutLoop )
{
line( "REPEAT" );
indent();
line( "over := TRUE;" );
nl();
}
shapes = d->shapes; shapes = d->shapes;
if( d->UseNull ) if( d->UseNull )
{ {
line( "IF this = NIL" ); line( "IF this = NIL" );
line( "THEN" ); line( "THEN" );
indent(); indent();
write_all_params( d->name, shapes ); write_all_params( d->name, /* first */ shapes );
line( "RETURN;" );
outdent(); outdent();
line( "END; (* IF *)" ); line( "ELSE" );
indent();
shapes = shapes->next; shapes = shapes->next;
} }
if( d->TagField ) if( d->TagField )
{ {
write_using_case( "this^.tag", d->name, shapes ); write_using_case( "this^.tag", d->name, shapes );
...@@ -588,6 +603,17 @@ static void writeproc_body( d ) decln d; ...@@ -588,6 +603,17 @@ static void writeproc_body( d ) decln d;
sprintf( tag, "VAL(KindOf%s, this)", d->name ); sprintf( tag, "VAL(KindOf%s, this)", d->name );
write_using_case( tag, d->name, shapes ); write_using_case( tag, d->name, shapes );
} }
if( d->UseNull )
{
outdent();
line( "END; (* IF *)" );
}
if( d->PutLoop )
{
outdent();
line( "UNTIL over;" );
}
outdent(); outdent();
line( "END Write%s;", d->name ); line( "END Write%s;", d->name );
nl(); nl();
...@@ -612,57 +638,92 @@ static void write_using_case( tag, dname, s ) char *tag, *dname; shapelist s; ...@@ -612,57 +638,92 @@ static void write_using_case( tag, dname, s ) char *tag, *dname; shapelist s;
} }
static void write_param( sname, p ) char *sname; param p; static void write_all_params( dname, s ) char *dname; shape s;
{ {
line( "%s( f, this^.%s%s );", if( s->pl == NULL )
lookup_write_proc(p->type), sname, p->name ); {
write_default_printlist( s );
} else
{
write_printlist( s, dname );
}
} }
static void write_all_params( dname, s ) char *dname; shape s; static void write_default_printlist( s ) shape s;
{
BOOL first;
paramlist p = s->params;
/* No print items given - use defaults */
if( p )
{
line( "WriteString( f, \"%s(\" );", s->name );
for( first = TRUE; p != NULL; p = p->next )
{
if( ! first ) line( "WriteChar( f, \",\" );" );
first = FALSE;
write_param( s->name, p );
}
line( "WriteChar( f, ')' );" );
} else
{
line( "WriteString( f, \"%s\" );", s->name );
}
}
static void write_printlist( s, dname ) shape s; char *dname;
{ {
/* Some print items given - use them */
printlist pl; printlist pl;
paramlist p; param p;
int n;
if( s->pl == NULL ) /* All but the last item */
for( pl = s->pl; pl->next != NULL; pl = pl->next )
{ {
/* No print items given - use defaults */ if( pl->item->tag == printitem_is_str )
if( s->params )
{ {
line( "WriteString( f, \"%s(\" );", s->name ); outstring( pl->item->str );
for( p = s->params; p != NULL; p = p->next )
{
write_param( s->name, p );
}
line( "WriteChar( f, ')' );" );
} else } else
{ {
line( "WriteString( f, \"%s\" );", s->name ); p = findnthparam( pl->item->num, s->params,
s->name, dname );
write_param( s->name, p );
} }
}
/* Last item */
if( pl->item->tag == printitem_is_str )
{
outstring( pl->item->str );
} else } else
{ {
/* Some print items given - use them */ p = findnthparam( pl->item->num, s->params, s->name, dname );
for( pl = s->pl; pl != NULL; pl = pl->next ) if( streq( p->type, dname ) )
{ {
if( pl->item->tag == printitem_is_str ) line( "this := this^.%s%s;", s->name, p->name );
{ line( "over := FALSE;" );
outstring( pl->item->str ); } else
} else {
{ write_param( s->name, p );
int n = pl->item->num;
for( p = s->params;
p != NULL && --n;
p = p->next );
ASSERT( p != NULL,
("m2datadec: bad printitem number in shape %s of type %s\n", s->name, dname));
write_param( s->name, p );
}
} }
} }
} }
static void write_param( sname, p ) char *sname; param p;
{
line( "%s( f, this^.%s%s );",
lookup_write_proc(p->type), sname, p->name );
}
static void outstring( str ) char *str; static void outstring( str ) char *str;
{ {
char *p; char *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