protect against conflicts with library routines and data.
authorPeter B. Kessler <peter@ucbvax.Berkeley.EDU>
Fri, 30 Jul 1982 10:17:28 +0000 (02:17 -0800)
committerPeter B. Kessler <peter@ucbvax.Berkeley.EDU>
Fri, 30 Jul 1982 10:17:28 +0000 (02:17 -0800)
SCCS-vsn: usr.bin/pascal/pc3/pc3.h 1.5
SCCS-vsn: usr.bin/pascal/pc3/pc3.c 1.9
SCCS-vsn: usr.bin/pascal/src/pstab.h 1.3

usr/src/usr.bin/pascal/pc3/pc3.c
usr/src/usr.bin/pascal/pc3/pc3.h
usr/src/usr.bin/pascal/src/pstab.h

index 029ac2a..0e4b980 100644 (file)
@@ -1,6 +1,6 @@
     /* Copyright (c) 1980 Regents of the University of California */
 
     /* Copyright (c) 1980 Regents of the University of California */
 
-static char sccsid[] = "@(#)pc3.c 1.8 %G%";
+static char sccsid[] = "@(#)pc3.c 1.9 %G%";
 
     /*
      *      Pc3 is a pass in the Berkeley Pascal compilation
 
     /*
      *      Pc3 is a pass in the Berkeley Pascal compilation
@@ -258,6 +258,7 @@ checksymbol( nlp , ofilep )
        static struct symbol    *pfilep = NIL;
        static struct symbol    *ifilep = NIL;
        register struct symbol  *symbolp;
        static struct symbol    *pfilep = NIL;
        static struct symbol    *ifilep = NIL;
        register struct symbol  *symbolp;
+       int                     errtype;
 
 #      ifdef DEBUG
            if ( pfilep && ifilep ) {
 
 #      ifdef DEBUG
            if ( pfilep && ifilep ) {
@@ -288,6 +289,8 @@ checksymbol( nlp , ofilep )
                case N_PGVAR:
                case N_PGFUNC:
                case N_PGPROC:
                case N_PGVAR:
                case N_PGFUNC:
                case N_PGPROC:
+               case N_PLDATA:
+               case N_PLTEXT:
                        symbolp -> sym_un.sym_str.rfilep = ifilep;
                        symbolp -> sym_un.sym_str.rline = nlp -> n_value;
                        symbolp -> sym_un.sym_str.fromp = pfilep;
                        symbolp -> sym_un.sym_str.rfilep = ifilep;
                        symbolp -> sym_un.sym_str.rline = nlp -> n_value;
                        symbolp -> sym_un.sym_str.fromp = pfilep;
@@ -330,6 +333,7 @@ checksymbol( nlp , ofilep )
                fprintf( stderr , "[checksymbol] ->name %s is OLD\n"
                        , symbolp -> name );
 #          endif DEBUG
                fprintf( stderr , "[checksymbol] ->name %s is OLD\n"
                        , symbolp -> name );
 #          endif DEBUG
+           errtype = ERROR;
            switch ( symbolp -> desc ) {
                default:
                        error( FATAL , "panic [checksymbol] OLD" );
            switch ( symbolp -> desc ) {
                default:
                        error( FATAL , "panic [checksymbol] OLD" );
@@ -405,7 +409,7 @@ checksymbol( nlp , ofilep )
                             */
                        if ( symbolp -> sym_un.sym_str.rfilep == NIL ) {
                            error( ERROR ,
                             */
                        if ( symbolp -> sym_un.sym_str.rfilep == NIL ) {
                            error( ERROR ,
-                           "%s, line %d: %s already defined (%s, line %d)." ,
+                   "%s, line %d: %s is already defined\n\t(%s, line %d)." ,
                                ifilep -> name , nlp -> n_value , 
                                nlp -> n_un.n_name , 
                                symbolp -> sym_un.sym_str.fromi -> name ,
                                ifilep -> name , nlp -> n_value , 
                                nlp -> n_un.n_name , 
                                symbolp -> sym_un.sym_str.fromi -> name ,
@@ -439,14 +443,46 @@ included:
                        }
                        symbolp -> sym_un.sym_str.fromp = pfilep;
                        return;
                        }
                        symbolp -> sym_un.sym_str.fromp = pfilep;
                        return;
+               case N_PLDATA:
+               case N_PLTEXT:
+                       switch ( nlp -> n_desc ) {
+                           default:
+                               error( FATAL , "pc3: unknown stab 0x%x"
+                                       , nlp -> n_desc );
+                               return;
+                           case N_PSO:
+                           case N_PSOL:
+                           case N_PGCONST:
+                           case N_PGTYPE:
+                               /* these won't conflict with library */
+                               return;
+                           case N_PGLABEL:
+                           case N_PGVAR:
+                           case N_PGFUNC:
+                           case N_PGPROC:
+                           case N_PEFUNC:
+                           case N_PEPROC:
+                           case N_PLDATA:
+                           case N_PLTEXT:
+                               errtype = WARNING;
+                               break;
+                       }
+                       break;
            }
                /*
                 *      this is the breaks
                 */
            }
                /*
                 *      this is the breaks
                 */
-           error( ERROR , "%s, line %d: %s already defined (%s, line %d)."
-                   , ifilep -> name , nlp -> n_value , nlp -> n_un.n_name
-                   , symbolp -> sym_un.sym_str.rfilep -> name
-                   , symbolp -> sym_un.sym_str.rline );
+           error( errtype
+               , "%s, line %d: %s %s is already defined\n\t%s%s (%s, line %d)."
+               , ifilep -> name
+               , nlp -> n_value
+               , classify( nlp -> n_desc )
+               , nlp -> n_un.n_name
+               , ( symbolp -> desc == nlp -> n_desc ? "" : " as " )
+               , ( symbolp -> desc == nlp -> n_desc
+                       ? "" : article( symbolp -> desc ) )
+               , symbolp -> sym_un.sym_str.rfilep -> name
+               , symbolp -> sym_un.sym_str.rline );
        }
     }
 
        }
     }
 
@@ -714,7 +750,7 @@ nextelement( ofilep )
     /*
      * variable number of arguments to error, like printf.
      */
     /*
      * variable number of arguments to error, like printf.
      */
-error( type , message , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 )
+error( type , message , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , arg7 , arg8 )
     int                type;
     char       *message;
     {
     int                type;
     char       *message;
     {
@@ -737,7 +773,7 @@ error( type , message , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 )
                    fprintf( stderr , "Ooops: " );
                    break;
        }
                    fprintf( stderr , "Ooops: " );
                    break;
        }
-       fprintf( stderr , message , arg1,arg2,arg3,arg4,arg5,arg6 );
+       fprintf( stderr , message , arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8 );
        fprintf( stderr , "\n" );
        if ( type == FATAL ) {
            exit( FATAL );
        fprintf( stderr , "\n" );
        if ( type == FATAL ) {
            exit( FATAL );
@@ -790,7 +826,45 @@ classify( type )
                return "external function";
            case N_PEPROC:
                return "external procedure";
                return "external function";
            case N_PEPROC:
                return "external procedure";
+           case N_PLDATA:
+               return "library variable";
+           case N_PLTEXT:
+               return "library routine";
            default:
                return "unknown symbol";
        }
     }
            default:
                return "unknown symbol";
        }
     }
+
+char *
+article( type )
+    unsigned char      type;
+    {
+       switch ( type ) {
+           case N_PSO:
+               return "a source file";
+           case N_PSOL:
+               return "an include file";
+           case N_PGLABEL:
+               return "a label";
+           case N_PGCONST:
+               return "a constant";
+           case N_PGTYPE:
+               return "a type";
+           case N_PGVAR:
+               return "a variable";
+           case N_PGFUNC:
+               return "a function";
+           case N_PGPROC:
+               return "a procedure";
+           case N_PEFUNC:
+               return "an external function";
+           case N_PEPROC:
+               return "an external procedure";
+           case N_PLDATA:
+               return "a library variable";
+           case N_PLTEXT:
+               return "a library routine";
+           default:
+               return "an unknown symbol";
+       }
+    }
index fd0dcef..4e69b2f 100644 (file)
@@ -1,6 +1,6 @@
     /* Copyright (c) 1980 Regents of the University of California */
 
     /* Copyright (c) 1980 Regents of the University of California */
 
-    /* static  char sccsid[] = "@(#)pc3.h 1.4 %G%"; */
+    /* static  char sccsid[] = "@(#)pc3.h 1.5 %G%"; */
 
     /*
      * a symbol table entry.
 
     /*
      * a symbol table entry.
@@ -124,3 +124,4 @@ char                *charalloc();
 BOOL           nextelement();
 time_t         mtime();
 char           *classify();
 BOOL           nextelement();
 time_t         mtime();
 char           *classify();
+char           *article();
index c4556d4..fa4e9e7 100644 (file)
@@ -1,4 +1,4 @@
-    /* static  char sccsid[] = "@(#)pstab.h 1.2 %G%"; */
+    /* static  char sccsid[] = "@(#)pstab.h 1.3 %G%"; */
 
     /*
      * subtypes within the above type
 
     /*
      * subtypes within the above type
@@ -15,3 +15,5 @@
 #define        N_PGPROC        0x8     /* global procedure */
 #define        N_PEFUNC        0x9     /* external function */
 #define        N_PEPROC        0xa     /* external procedure */
 #define        N_PGPROC        0x8     /* global procedure */
 #define        N_PEFUNC        0x9     /* external function */
 #define        N_PEPROC        0xa     /* external procedure */
+#define        N_PLDATA        0xb     /* library variable */
+#define        N_PLTEXT        0xc     /* library routine */