Commit 25d62868 authored by dcw's avatar dcw

finished it!

parent fe189fca
......@@ -2,14 +2,9 @@
#include <dcw.h>
#include <string.h>
#include "struct.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 );
static void writeproc_header( char * );
static void writeproc_body( decln );
static void write_using_case( char * , char * , shapelist );
static void write_param( char * , param );
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 write_bool( void );
static char * lookup_type( char * );
......@@ -61,8 +58,10 @@ static void deconsproc_body();
static void writeproc_header();
static void writeproc_body();
static void write_using_case();
static void write_param();
static void write_all_params();
static void write_default_printlist();
static void write_printlist();
static void write_param();
static void outstring();
static void write_bool();
static char * lookup_type();
......@@ -556,25 +555,41 @@ static void writeproc_header( name ) char *name;
static void writeproc_body( d ) decln d;
{
shapelist s;
shapelist shapes;
writeproc_header( d->name );
nl();
if( d->PutLoop )
{
line( "VAR over : BOOLEAN;" );
nl();
}
line( "BEGIN" );
indent();
if( d->PutLoop )
{
line( "REPEAT" );
indent();
line( "over := TRUE;" );
nl();
}
shapes = d->shapes;
if( d->UseNull )
{
line( "IF this = NIL" );
line( "THEN" );
indent();
write_all_params( d->name, shapes );
line( "RETURN;" );
write_all_params( d->name, /* first */ shapes );
outdent();
line( "END; (* IF *)" );
line( "ELSE" );
indent();
shapes = shapes->next;
}
if( d->TagField )
{
write_using_case( "this^.tag", d->name, shapes );
......@@ -588,6 +603,17 @@ static void writeproc_body( d ) decln d;
sprintf( tag, "VAL(KindOf%s, this)", d->name );
write_using_case( tag, d->name, shapes );
}
if( d->UseNull )
{
outdent();
line( "END; (* IF *)" );
}
if( d->PutLoop )
{
outdent();
line( "UNTIL over;" );
}
outdent();
line( "END Write%s;", d->name );
nl();
......@@ -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 );",
lookup_write_proc(p->type), sname, p->name );
if( s->pl == NULL )
{
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;
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( s->params )
if( pl->item->tag == printitem_is_str )
{
line( "WriteString( f, \"%s(\" );", s->name );
for( p = s->params; p != NULL; p = p->next )
{
write_param( s->name, p );
}
line( "WriteChar( f, ')' );" );
outstring( pl->item->str );
} 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
{
/* Some print items given - use them */
for( pl = s->pl; pl != NULL; pl = pl->next )
p = findnthparam( pl->item->num, s->params, s->name, dname );
if( streq( p->type, dname ) )
{
if( pl->item->tag == printitem_is_str )
{
outstring( pl->item->str );
} else
{
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 );
}
line( "this := this^.%s%s;", s->name, p->name );
line( "over := FALSE;" );
} else
{
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;
{
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