#define PRIVATE; copyright message
authordick <none@none>
Fri, 2 Sep 1988 12:00:25 +0000 (12:00 +0000)
committerdick <none@none>
Fri, 2 Sep 1988 12:00:25 +0000 (12:00 +0000)
lang/cem/lint/lpass2/ChangeLog
lang/cem/lint/lpass2/Makefile
lang/cem/lint/lpass2/class.c
lang/cem/lint/lpass2/class.h
lang/cem/lint/lpass2/inpdef.str
lang/cem/lint/lpass2/lpass2.c
lang/cem/lint/lpass2/private.h [new file with mode: 0644]
lang/cem/lint/lpass2/read.c
lang/cem/lint/lpass2/report.c

index 23d4f6e..0ce7e64 100644 (file)
@@ -1,3 +1,6 @@
+ 2-Sep-88  Dick Grune (dick) at dick
+       Guided by lint itself, many functions have been declared PRIVATE.
+
  7-Aug-88  Dick Grune (dick) at dick
        About the class of an inpdef, often set-like questions are asked.
        To speed up answering these questions, a mapping has been created
                - external usage
                - static defs
                - static usage
-       This change to a much more natural order has been possible by the
+       This change to a much more natural order has been made possible by the
        introduction of the static file number.  Many pieces of code could
        now be taken together and the program is much cleaner now.
 
  8-Jul-88  Dick Grune (dick) at dick
-       Added a special meta-type (also in lpaas1) for non-negative
+       Added a special meta-type (also in lpass1) for non-negative
        constant actual arguments, because these may match both the signed
        and unsigned versions of the type.
 
@@ -44,3 +47,8 @@
 11-May-88  Dick Grune (dick) at dick
        Received sources from Frans Kunst.
 
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+/* $Header$ */
index 37a5df1..4fbb5c8 100644 (file)
@@ -1,3 +1,8 @@
+# (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+# See the copyright notice in the ACK home directory, in the file "Copyright".
+#
+# $Header$
+
 #      M A K E F I L E   F O R   L P A S S 2
 
 # Machine and environ dependent definitions
@@ -24,13 +29,14 @@ OBJ =       lpass2.o read.o report.o class.o
 
 test:  lpass2
        make lint
+#      lpass2 -xh <.i
 
 lpass2:        $(OBJ) Makefile next.o
        $(CC) $(COPTIONS) $(LDFLAGS) $(OBJ) next.o $(LLIBS) -o lpass2
        size lpass2
 
 lint:
-       ../lint $(CFLAGS) $(SRC) next.c #???
+       ../lint -xh $(CFLAGS) $(SRC) next.c #???
 
 next.c:        $(LPASS1)/make.next inpdef.str
        $(LPASS1)/make.next inpdef.str > next.c
@@ -42,7 +48,7 @@ clean:
        rm -f a.out core next.c inpdef.h $(OBJ) next.o
 
 #----------------------------------------------------------------
-class.o: class.h
-lpass2.o: ../lpass1/l_class.h ../lpass1/l_lint.h class.h inpdef.h
-read.o: ../lpass1/l_class.h class.h inpdef.h
+class.o: ../lpass1/l_class.h class.h
+lpass2.o: ../lpass1/l_class.h ../lpass1/l_lint.h class.h inpdef.h private.h
+read.o: ../lpass1/l_class.h class.h inpdef.h private.h
 report.o: inpdef.h
index b477e48..d740526 100644 (file)
@@ -1,3 +1,9 @@
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+/* $Header$ */
+
 #include       "../lpass1/l_class.h"
 #include       "class.h"
 
index 4c961e6..38c542a 100644 (file)
@@ -1,3 +1,17 @@
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+/* $Header$ */
+
+/*     Bit patterns to allow fast answers to set questions about classes.
+       The classes in the inpdef are given as single letters; the array
+       class[] contains a bit pattern for each letter, with those bits set
+       that correspond to the lint class meaning of the letter.
+
+       This facility is used through the macro  is_class(inpdef_var, CL_???)
+*/
+
 #define        CL_DEF          (1<<0)
 #define        CL_DECL         (1<<1)
 #define        CL_USAGE        (1<<2)
index aa907ac..5df1bcd 100644 (file)
@@ -1,3 +1,9 @@
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+/* $Header$ */
+
 #define NAMESIZE 100
 #define FNAMESIZE 100
 #define ARGTPSSIZE 2000
@@ -17,7 +23,7 @@ struct inpdef {
        int id_args;                    /* set if arguments given */
        int id_nrargs;                  /* number of args, neg. for varargs */
        char id_argtps[ARGTPSSIZE];     /* argument types, colon separated */
-       int id_valreturned;             /* for def/decl, set if val returned */
+       int id_valreturned;             /* for def/decl, see ../lpass1/l_lint.h */
        int id_valused;                 /* for FC, see ../lpass1/l_lint.h */
 
        /* not filled by get_id() */
index 92a0f56..96ba591 100644 (file)
@@ -1,20 +1,46 @@
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+/* $Header$ */
+
 #include       <alloc.h>
 
+#include       "private.h"
 #include       "../lpass1/l_lint.h"
 #include       "../lpass1/l_class.h"
 #include       "class.h"
 #include       "inpdef.h"
 
+extern char *strcpy();
+
 #define        streq(s1,s2)    (strcmp(s1, s2) == 0)
 #define        min(a,b)        ((a) <= (b) ? (a) : (b))
 
-char cur_name[NAMESIZE];
-struct inpdef *dot, *lib, *ext, *sta;
+PRIVATE char cur_name[NAMESIZE];
+PRIVATE struct inpdef *dot, *lib, *ext, *sta;
+
+PRIVATE check_args();
+PRIVATE check_def();
+PRIVATE ext_decls();
+PRIVATE ext_def();
+PRIVATE get_dot();
+PRIVATE init();
+PRIVATE lib_def();
+PRIVATE one_ext_decl();
+PRIVATE one_func_call();
+PRIVATE one_var_usage();
+PRIVATE stat_def();
+PRIVATE statics();
+PRIVATE int type_equal();
+PRIVATE int type_match();
+PRIVATE usage();
 
 #define        same_name()     (dot && streq(cur_name, dot->id_name))
 #define        same_obj(stnr)  (same_name() && dot->id_statnr == stnr)
 
 #define        defdec(id)      (is_class(id, CL_DEF) ? "defined" : "declared")
+#define        funvar(id)      (is_class(id, CL_FUNC) ? "function" : "variable")
 
 
 /******** M A I N ********/
@@ -43,7 +69,6 @@ main(argc, argv)
                if (ext)
                        check_def(ext);
                statics();
-               /* inpdefs of class ERRCL are never generated */
                if (same_name()) {
                        /*      there are more lines for this name that have
                                not been absorbed
@@ -53,10 +78,10 @@ main(argc, argv)
        }
 }
 
-char options[128];
+char loptions[128];
 static char *table[] = {0};
 
-init(argc, argv)
+PRIVATE init(argc, argv)
        char *argv[];
 {
 /*
@@ -67,18 +92,21 @@ init(argc, argv)
 
        init_class();
 
-       while (argc > 1 && *argv[1] == '-') {
-               switch (argv[1][1]) {
-               case 'u':
-               /* don't report situations like "used but not defined"
-                * and "defined but never used"
-                */
-               case 'X':               /* ??? prints incoming inpdefs */
-                       options[argv[1][1]] = 1;
-                       break;
-               default:
-                       /* ready to be extended */
-                       break;
+       while (argc > 1 && argv[1][0] == '-') {
+               register char *arg = &argv[1][1];
+               register char ch;
+
+               while (ch = *arg++) {
+                       switch (ch) {
+                       case 'u':
+                               /*      don't report situations like
+                                       "defined/declared but not used"
+                               */
+                       case 'X':       /* ??? prints incoming inpdefs */
+                       default:        /* and any other */
+                               loptions[ch] = 1;
+                               break;
+                       }
                }
                argc--, argv++;
        }
@@ -87,7 +115,7 @@ init(argc, argv)
                panic("InsertFile() fails");
 }
 
-get_dot()
+PRIVATE get_dot()
 {
        if (!get_id(dot)) {
                free_inpdef(dot);
@@ -99,7 +127,7 @@ get_dot()
 
 /******** L I B R A R Y ********/
 
-lib_def()
+PRIVATE lib_def()
 {
        if (same_obj(0) && is_class(dot, CL_LIB)) {
                lib = dot;
@@ -108,7 +136,7 @@ lib_def()
        }
 
        while (same_obj(0) && is_class(dot, CL_LIB)) {
-               report("%L: multiple definition of %s in library",
+               report(">%L: multiple definition of %s in library",
                        dot, dot->id_name);
                get_dot();
        }
@@ -117,12 +145,12 @@ lib_def()
 
 /******** E X T E R N ********/
 
-ext_def()
+PRIVATE ext_def()
 {
        if (same_obj(0) && is_class(dot, CL_EXT|CL_DEF)) {
                if (lib) {
-                       report("%L: %s also defined in library %L",
-                               dot, dot->id_name, lib);
+                       report("%L: %s %s also defined in library %L",
+                               dot, funvar(dot), dot->id_name, lib);
                }
                ext = dot;
                dot = new_inpdef();
@@ -130,13 +158,13 @@ ext_def()
        }
 
        while (same_obj(0) && is_class(dot, CL_EXT|CL_DEF)) {
-               report("%L: %s also defined at %L",
-                       dot, dot->id_name, ext);
+               report("%L: %s %s also defined at %L",
+                       dot, funvar(dot), dot->id_name, ext);
                get_dot();
        }
 }
 
-ext_decls()
+PRIVATE ext_decls()
 {
        while (same_obj(0) && dot->id_class == EFDC) {
                one_ext_decl("function", "variable", CL_VAR);
@@ -151,7 +179,7 @@ ext_decls()
        }
 }
 
-one_ext_decl(kind, other_kind, other_class)
+PRIVATE one_ext_decl(kind, other_kind, other_class)
        char *kind;
        char *other_kind;
        int other_class;
@@ -160,10 +188,6 @@ one_ext_decl(kind, other_kind, other_class)
 
        if (!def) {
                /* the declaration will have to serve */
-               if (!is_class(dot, CL_IMPL) && !options['u']) {
-                       report("%L: %s %s declared but never defined",
-                               dot, dot->id_name, kind);
-               }
                ext = dot;
                dot = new_inpdef();
                get_dot();
@@ -190,25 +214,46 @@ one_ext_decl(kind, other_kind, other_class)
 
 /******** U S A G E ********/
 
-usage(stnr)
+PRIVATE usage(stnr)
        int stnr;
 {
-       struct inpdef *def = stnr ? sta : ext ? ext : lib ? lib : 0;
+       register struct inpdef *def = stnr ? sta : ext ? ext : lib ? lib : 0;
+       register int VU_count = 0;
+       register int VU_samefile = 0;
 
        while (same_obj(stnr) && dot->id_class == FC) {
                one_func_call(def);
        }
 
        while (same_obj(stnr) && dot->id_class == VU) {
+               VU_count++;
+               if (def && streq(def->id_file, dot->id_file)) {
+                       VU_samefile++;
+               }
                one_var_usage(def);
        }
+
+       if (def && loptions['h']) {
+               register char *fn = def->id_file;
+
+               if (    stnr == 0
+               &&      VU_count == 1
+               &&      VU_samefile == 1
+               &&      def == ext
+               &&      !is_class(ext, CL_IMPL)
+               &&      streq(&fn[strlen(fn)-2], ".c")
+               ) {
+                       report("%L: extern %s could be declared static",
+                               def, def->id_name);
+               }
+       }
 }
 
-one_func_call(def)
+PRIVATE one_func_call(def)
        struct inpdef *def;
 {
        if (!def) {
-               if (!options['u']) {
+               if (!loptions['u']) {
                        report("%L: function %s used but not defined",
                                dot, dot->id_name);
                }
@@ -220,7 +265,9 @@ one_func_call(def)
 
        if (def->id_args) {
                check_args(dot, def);
-               if (dot->id_valused == USED && !def->id_valreturned) {
+               if (    dot->id_valused == USED
+               &&      def->id_valreturned == NOVALRETURNED
+               ) {
                        report("%L: value of %s is used, but none is returned at %L",
                                dot, dot->id_name, def);
                }
@@ -244,11 +291,11 @@ one_func_call(def)
        get_dot();
 }
 
-one_var_usage(def)
+PRIVATE one_var_usage(def)
        struct inpdef *def;
 {
        if (!def) {
-               if (!options['u']) {
+               if (!loptions['u']) {
                        report("%L: variable %s used but not defined",
                                dot, dot->id_name);
                }
@@ -264,17 +311,14 @@ one_var_usage(def)
 
 /******** S T A T I C ********/
 
-statics()
+PRIVATE statics()
 {
-       while (same_name() && dot->id_statnr != 0) {
-               one_static(dot->id_statnr);
-       }
-}
+       while (same_name()) {
+               int stnr = dot->id_statnr;
+
+               if (stnr == 0)
+                       panic("sequence error in input");
 
-one_static(stnr)
-       int stnr;
-{
-       while (same_obj(stnr)) {
                if (sta) {
                        free_inpdef(sta);
                        sta = 0;
@@ -283,21 +327,24 @@ one_static(stnr)
                usage(stnr);
                if (sta)
                        check_def(sta);
-               get_dot();
+
+               if (same_obj(stnr))
+                       panic("sequence error in input");
        }
 }
 
-stat_def(stnr)
+PRIVATE stat_def(stnr)
        int stnr;
 {
        if (same_obj(stnr) && is_class(dot, CL_STAT|CL_DEF)) {
                if (lib) {
-                       report("%L: %s also defined in library %L",
-                               dot, dot->id_name, lib);
+                       report("%L: %s %s also defined in library %L",
+                               dot, funvar(dot), dot->id_name, lib);
                }
                if (ext) {
-                       report("%L: %s also %s at %L",
-                               dot, dot->id_name, defdec(ext), ext);
+                       report("%L: %s %s also %s at %L",
+                               dot, funvar(dot), dot->id_name,
+                               defdec(ext), ext);
                }
                sta = dot;
                dot = new_inpdef();
@@ -305,13 +352,13 @@ stat_def(stnr)
        }
 
        while (same_obj(stnr) && is_class(dot, CL_STAT|CL_DEF)) {
-               report("%L: %s also defined at %L",
-                       dot, dot->id_name, sta);
+               report("%L: %s %s also defined at %L",
+                       dot, funvar(dot), dot->id_name, sta);
                get_dot();
        }
 }
 
-check_def(def)
+PRIVATE check_def(def)
        struct inpdef *def;
 {
        if (!def)
@@ -325,15 +372,19 @@ check_def(def)
                        /* silent */
                }
                else {
-                       if (!options['u']) {
-                               report("%L: %s %s but never used",
-                                       def, def->id_name, defdec(def));
+                       if (!loptions['u']) {
+                               report("%L: %s %s %s but not used",
+                                       def, funvar(def), def->id_name,
+                                       defdec(def));
                        }
                }
        }
 
        if (is_class(def, CL_DEF|CL_FUNC)) {
-               if (def->id_valreturned && def->id_called && def->id_ignored) {
+               if (    def->id_valreturned == VALRETURNED
+               &&      def->id_called
+               &&      def->id_ignored
+               ) {
                        report("%L: %s returns value which is %s ignored",
                                def, def->id_name,
                                (def->id_used || def->id_voided) ?
@@ -345,7 +396,7 @@ check_def(def)
 
 /******** T Y P E   C H E C K I N G ********/
 
-check_args(id, def)
+PRIVATE check_args(id, def)
        struct inpdef *id, *def;
 {
        register char *act_tp = id->id_argtps;
@@ -381,8 +432,8 @@ check_args(id, def)
        }
 
        for (i = 1; i <= nrargs; i++) {
-               register char *act = act_tp;
-               register char *def = def_tp;
+               register char *act_par = act_tp;
+               register char *def_par = def_tp;
 
                /* isolate actual argument type */
                while (*act_tp) {
@@ -401,7 +452,7 @@ check_args(id, def)
                        def_tp++;
                }
 
-               if (!type_match(act, def)) {
+               if (!type_match(act_par, def_par)) {
                        report("%L: arg %d of %s differs from that at %L",
                                id, i, id->id_name, def);
                }
@@ -411,14 +462,16 @@ check_args(id, def)
 }
 
 int
-type_equal(act, def)
+PRIVATE type_equal(act, def)
        char *act, *def;
 {
-       return streq(act, def);
+       return  streq(act, def)
+       ||      streq(act, "erroneous")
+       ||      streq(def, "erroneous");
 }
 
 int
-type_match(act, def)
+PRIVATE type_match(act, def)
        char *act, *def;
 {
        if (type_equal(act, def))
@@ -429,8 +482,8 @@ type_match(act, def)
                /* might be signed or unsigned */
                if (type_equal(&act[1], def))
                        return 1;
-               if (    strncmp(def, "unsigned ", 9)
-               &&      type_equal(&act[1], &def[10])
+               if (    strncmp(def, "unsigned ", strlen("unsigned ")) == 0
+               &&      type_equal(&act[1], &def[strlen("unsigned ")])
                ) {
                        return 1;
                }
@@ -441,10 +494,11 @@ type_match(act, def)
 
 /******** D E B U G G I N G ********/
 
-print_id(id)
+print_id(name, id)
+       char *name;
        struct inpdef *id;
 {
-       print("inpdef: %s, %s, %04d, \"%s\", %d, %s",
+       print("%s: %s, %s, %04d, \"%s\", %d, %s", name,
                id->id_class == LFDF ? "LFDF" :
                id->id_class == LVDF ? "LVDF" :
                id->id_class == EFDF ? "EFDF" :
@@ -455,8 +509,7 @@ print_id(id)
                id->id_class == SFDF ? "SFDF" :
                id->id_class == SVDF ? "SVDF" :
                id->id_class == FC ? "FC" :
-               id->id_class == VU ? "VU" :
-               id->id_class == ERRCL ? "ERRCL" : "<BADCLASS>",
+               id->id_class == VU ? "VU" : "<BADCLASS>",
                id->id_name,
                id->id_statnr,
                id->id_file,
@@ -472,8 +525,13 @@ print_id(id)
                                id->id_valused == IGNORED ? "IGNORED" :
                                id->id_valused == VOIDED ? "VOIDED" :
                                "<BAD VALUSED>")
-                       :       (id->id_valreturned ? "VALRETURNED" :
-                               "NOVALRETURNED")
+                       :       (id->id_valreturned == NOVALRETURNED ?
+                                       "NOVALRETURNED" :
+                               id->id_valreturned == VALRETURNED ?
+                                       "VALRETURNED" :
+                               id->id_valreturned == NORETURN ?
+                                       "NORETURN" : "<BAD VALRETURNED>"
+                               )
                );
        }
        print("\n");
diff --git a/lang/cem/lint/lpass2/private.h b/lang/cem/lint/lpass2/private.h
new file mode 100644 (file)
index 0000000..a668dbd
--- /dev/null
@@ -0,0 +1,7 @@
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+/* $Header$ */
+
+#define        PRIVATE         static          /* or empty, for adb and profile */
index e97a0ca..435f2bc 100644 (file)
@@ -1,3 +1,9 @@
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+/* $Header$ */
+
 #include       "../lpass1/l_class.h"
 #include       "class.h"
 #include       "inpdef.h"
@@ -9,6 +15,8 @@
 #include       <inp_pkg.spec>
 #include       <inp_pkg.body>
 
+#include       "private.h"
+
 PRIVATE int LineNr = 1;
 
 /* Two dangerous macro's. They replace a single statement by
@@ -71,9 +79,9 @@ get_id(id)
 
        if (!ReadString(id->id_file, '\n', FNAMESIZE))
                return 0;
-       {       extern char options[];
-               if (options['X'])
-                       print_id(id);/*???*/
+       {       extern char loptions[];
+               if (loptions['X'])
+                       print_id("read", id);/*???*/
        }
        return (1);
 }
@@ -160,8 +168,10 @@ PRIVATE int
 ReadArgs(nrargs, buf)
        char *buf;
 {
-/* Reads a string into buf with format <type1>:<type2>: ... :<typeN>: */
-
+       /*      Reads a string into buf with format
+                       <type1>:<type2>: ... :<typeN>:
+               Note: format must include the final colon.
+       */
        int i;
        int charcount = 1;
        int n;
index 14f54ba..557260b 100644 (file)
@@ -1,3 +1,9 @@
+/*
+ * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
+ * See the copyright notice in the ACK home directory, in the file "Copyright".
+ */
+/* $Header$ */
+
 #include       <varargs.h>
 
 #include       <system.h>
@@ -25,16 +31,23 @@ report(va_alist)
                        /* it is an inpdef */
                        register struct inpdef *id =
                                va_arg(ap, struct inpdef *);
+                       register char *fn = id->id_file;
 
                        f += 2;
-                       /* is the file name global? */
-                       if (id->id_file[0] == '/')
+                       
+                       if (    /* the file name global */
+                               fn[0] == '/'
+                       &&      /* it is not a .c file */
+                               strcmp(&fn[strlen(fn)-2], ".c") != 0
+                       ) {
+                               /* we skip this message */
                                return;
-                       /*      if no, we have used up the argument,
+                       }
+                       /*      otherwise, we have used up the argument,
                                so print it here
                        */
                        fprint(MSGOUT, "\"%s\", line %d",
-                               id->id_file, id->id_line);
+                               fn, id->id_line);
                }
                while ((fc = *f++)) {
                        if (fc == '%') {