BSD 4 release
[unix-history] / usr / src / cmd / pi / rec.c
index a281f63..bdb8fad 100644 (file)
@@ -1,13 +1,8 @@
 /* Copyright (c) 1979 Regents of the University of California */
 /* Copyright (c) 1979 Regents of the University of California */
-#
-/*
- * pi - Pascal interpreter code translator
- *
- * Charles Haley, Bill Joy UCB
- * Version 1.2 Novmeber 1978
- */
 
 
-#include "whoami"
+static char sccsid[] = "@(#)rec.c 1.2 9/22/80";
+
+#include "whoami.h"
 #include "0.h"
 #include "tree.h"
 #include "opcode.h"
 #include "0.h"
 #include "tree.h"
 #include "opcode.h"
@@ -78,6 +73,10 @@ tyrec1(r, off, first)
                fields(p, r[2]);
                variants(p, r[3]);
        }
                fields(p, r[2]);
                variants(p, r[3]);
        }
+           /*
+            *  round the lengths of records up to their alignments
+            */
+       p -> value[ NL_OFFS ] = roundup( p -> value[ NL_OFFS ] , align( p ) );
        P0 = P0was;
        return (p);
 }
        P0 = P0was;
        return (p);
 }
@@ -119,6 +118,9 @@ variants(p, r)
        if (r == NIL)
                return;
        ct = gtype(r[3]);
        if (r == NIL)
                return;
        ct = gtype(r[3]);
+       if ( isnta( ct , "bcsi" ) ) {
+           error("Tag fields cannot be %ss" , nameof( ct ) );
+       }
        line = r[1];
        /*
         * Want it even if r[2] is NIL so
        line = r[1];
        /*
         * Want it even if r[2] is NIL so
@@ -160,7 +162,16 @@ deffld(p, s, t)
                s = NIL;
        }
 #ifndef PI0
                s = NIL;
        }
 #ifndef PI0
-       fp = enter(defnl(s, FIELD, t, p->value[NL_OFFS]));
+           /*
+            * it used to be easy to keep track of offsets of fields
+            * and total sizes of records.
+            * but now, the offset of the field is aligned
+            * so only it knows it's offset, and calculating 
+            * the total size of the record is based on it,
+            * rather than just the width of the field.
+            */
+       fp = enter( defnl( s , FIELD , t , roundup( p -> value[ NL_OFFS ]
+                                                   , align( t ) ) ) );
 #else
        fp = enter(defnl(s, FIELD, t, 0));
 #endif
 #else
        fp = enter(defnl(s, FIELD, t, 0));
 #endif
@@ -168,12 +179,20 @@ deffld(p, s, t)
                fp->chain = P0->chain;
                P0->chain = fp;
 #ifndef PI0
                fp->chain = P0->chain;
                P0->chain = fp;
 #ifndef PI0
-               p->value[NL_FLDSZ] = p->value[NL_OFFS] += even(width(t));
+                   /*
+                    * and the size of the record is incremented.
+                    */
+               p -> value[ NL_OFFS ] = fp -> value[ NL_OFFS ] + width( t );
+               p -> value[ NL_FLDSZ ] = p -> value[ NL_OFFS ];
 #endif
                if (t != NIL) {
                        P0->nl_flags |= t->nl_flags & NFILES;
                        p->nl_flags |= t->nl_flags & NFILES;
                }
 #endif
                if (t != NIL) {
                        P0->nl_flags |= t->nl_flags & NFILES;
                        p->nl_flags |= t->nl_flags & NFILES;
                }
+#              ifdef PC
+                   stabfield( s , p2type( t ) , fp -> value[ NL_OFFS ]
+                               , lwidth( t ) );
+#              endif PC
        }
        return (fp);
 }
        }
        return (fp);
 }
@@ -192,7 +211,7 @@ defvnt(p, t, vr, ct)
        register struct nl *av;
 
        gconst(t);
        register struct nl *av;
 
        gconst(t);
-       if (ct != NIL && incompat(con.ctype, ct)) {
+       if (ct != NIL && incompat(con.ctype, ct , t )) {
 #ifndef PI1
                cerror("Variant label type incompatible with selector type");
 #endif
 #ifndef PI1
                cerror("Variant label type incompatible with selector type");
 #endif