Annotation of gcc/cp/errfn.c, revision 1.1.1.1

1.1       root        1: /* Provide a call-back mechanism for handling error output.
                      2:    Copyright (C) 1993 Free Software Foundation, Inc.
                      3:    Contributed by Jason Merrill ([email protected])
                      4: 
                      5:    This file is part of GNU CC.
                      6: 
                      7: GNU CC is free software; you can redistribute it and/or modify
                      8: it under the terms of the GNU General Public License as published by
                      9: the Free Software Foundation; either version 2, or (at your option)
                     10: any later version.
                     11: 
                     12: GNU CC is distributed in the hope that it will be useful,
                     13: but WITHOUT ANY WARRANTY; without even the implied warranty of
                     14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     15: GNU General Public License for more details.
                     16: 
                     17: You should have received a copy of the GNU General Public License
                     18: along with GNU CC; see the file COPYING.  If not, write to
                     19: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
                     20:    
                     21: #include "config.h"
                     22: #include "tree.h"
                     23: #include <ctype.h>
                     24: 
                     25: /* cp_printer is the type of a function which converts an argument into
                     26:    a string for digestion by printf.  The cp_printer function should deal
                     27:    with all memory management; the functions in this file will not free
                     28:    the char*s returned.  See error.c for an example use of this code.  */
                     29: 
                     30: typedef char* cp_printer PROTO((HOST_WIDE_INT, int));
                     31: extern cp_printer * cp_printers[256];
                     32: 
                     33: /* Whether or not we should try to be quiet for errors and warnings; this is
                     34:    used to avoid being too talkative about problems with tentative choices
                     35:    when we're computing the conversion costs for a method call.  */
                     36: int cp_silent = 0;
                     37: 
                     38: typedef void errorfn ();       /* deliberately vague */
                     39: 
                     40: extern char* cp_file_of PROTO((tree));
                     41: extern int   cp_line_of PROTO((tree));
                     42: 
                     43: #define STRDUP(f) (ap = (char *) alloca (strlen (f) +1), strcpy (ap, (f)), ap)
                     44: 
                     45: #define NARGS 3
                     46: #define arglist a1, a2, a3
                     47: #define arglist_dcl HOST_WIDE_INT a1, a2, a3;
                     48: #define ARGSINIT args[0] = a1; args[1] = a2; args[2] = a3;
                     49: #define ARGSLIST args[0], args[1], args[2]
                     50: 
                     51: static void
                     52: cp_thing (errfn, atarg1, format, arglist)
                     53:      errorfn *errfn;
                     54:      int atarg1;
                     55:      char *format;
                     56:      arglist_dcl
                     57: {
                     58:   char *fmt;
                     59:   char *f;
                     60:   char *ap;
                     61:   int arg;
                     62:   HOST_WIDE_INT atarg = atarg1 ? a1 : 0;
                     63:   HOST_WIDE_INT args[NARGS];
                     64:   ARGSINIT
                     65: 
                     66:   fmt = STRDUP(format);
                     67:   
                     68:   for (f = fmt, arg = 0; *f; ++f)
                     69:     {
                     70:       cp_printer * function;
                     71:       int alternate;
                     72:       int maybe_here;
                     73:       
                     74:       /* ignore text */
                     75:       if (*f != '%') continue;
                     76: 
                     77:       ++f;
                     78: 
                     79:       alternate = 0;
                     80:       maybe_here = 0;
                     81: 
                     82:       /* ignore most flags */
                     83:       while (*f == ' ' || *f == '-' || *f == '+' || *f == '#')
                     84:        {
                     85:          if (*f == '+')
                     86:            maybe_here = 1;
                     87:          else if (*f == '#')
                     88:            alternate = 1;
                     89:          ++f;
                     90:        }
                     91: 
                     92:       /* ignore field width */
                     93:       if (*f == '*')
                     94:        {
                     95:          ++f;
                     96:          ++arg;
                     97:        }
                     98:       else
                     99:        while (isdigit (*f))
                    100:          ++f;
                    101: 
                    102:       /* ignore precision */
                    103:       if (*f == '.')
                    104:        {
                    105:          ++f;
                    106:          if (*f == '*')
                    107:            {
                    108:              ++f;
                    109:              ++arg;
                    110:            }
                    111:          else
                    112:            while (isdigit (*f))
                    113:              ++f;
                    114:        }
                    115: 
                    116:       /* ignore "long" */
                    117:       if (*f == 'l')
                    118:        ++f;
                    119: 
                    120:       function = cp_printers[(int)*f];
                    121: 
                    122:       if (function)
                    123:        {
                    124:          char *p;
                    125: 
                    126:          if (arg >= NARGS) abort ();
                    127:          
                    128:          if (maybe_here && atarg1)
                    129:            atarg = args[arg];
                    130: 
                    131:          /* Must use a temporary to avoid calling *function twice */
                    132:          p = (*function) (args[arg], alternate);
                    133:          args[arg] = (HOST_WIDE_INT) STRDUP(p);
                    134:          *f = 's';
                    135:        }
                    136: 
                    137:       ++arg;                   /* Assume valid format string */
                    138: 
                    139:     }
                    140: 
                    141:   if (atarg)
                    142:     {
                    143:       char *file = cp_file_of ((tree) atarg);
                    144:       int   line = cp_line_of ((tree) atarg);
                    145:       (*errfn) (file, line, fmt, ARGSLIST);
                    146:     }
                    147:   else
                    148:     (*errfn) (fmt, ARGSLIST);
                    149: 
                    150: }
                    151: 
                    152: void
                    153: cp_error (format, arglist)
                    154:      char *format;
                    155:      arglist_dcl
                    156: {
                    157:   extern errorfn error;
                    158:   if (! cp_silent)
                    159:     cp_thing (error, 0, format, arglist);
                    160: }
                    161: 
                    162: void
                    163: cp_warning (format, arglist)
                    164:      char *format;
                    165:      arglist_dcl
                    166: {
                    167:   extern errorfn warning;
                    168:   if (! cp_silent)
                    169:     cp_thing (warning, 0, format, arglist);
                    170: }
                    171: 
                    172: void
                    173: cp_pedwarn (format, arglist)
                    174:      char *format;
                    175:      arglist_dcl
                    176: {
                    177:   extern errorfn pedwarn;
                    178:   if (! cp_silent)
                    179:     cp_thing (pedwarn, 0, format, arglist);
                    180: }
                    181: 
                    182: void
                    183: cp_compiler_error (format, arglist)
                    184:      char *format;
                    185:      arglist_dcl
                    186: {
                    187:   extern errorfn compiler_error;
                    188:   if (! cp_silent)
                    189:     cp_thing (compiler_error, 0, format, arglist);
                    190: }
                    191: 
                    192: void
                    193: cp_sprintf (format, arglist)
                    194:      char *format;
                    195:      arglist_dcl
                    196: {
                    197:   extern errorfn sprintf;
                    198:   cp_thing (sprintf, 0, format, arglist);
                    199: }
                    200: 
                    201: void
                    202: cp_error_at (format, arglist)
                    203:      char *format;
                    204:      arglist_dcl
                    205: {
                    206:   extern errorfn error_with_file_and_line;
                    207:   if (! cp_silent)
                    208:     cp_thing (error_with_file_and_line, 1, format, arglist);
                    209: }
                    210: 
                    211: void
                    212: cp_warning_at (format, arglist)
                    213:      char *format;
                    214:      arglist_dcl
                    215: {
                    216:   extern errorfn warning_with_file_and_line;
                    217:   if (! cp_silent)
                    218:     cp_thing (warning_with_file_and_line, 1, format, arglist);
                    219: }
                    220: 
                    221: void
                    222: cp_pedwarn_at (format, arglist)
                    223:      char *format;
                    224:      arglist_dcl
                    225: {
                    226:   extern errorfn pedwarn_with_file_and_line;
                    227:   if (! cp_silent)
                    228:     cp_thing (pedwarn_with_file_and_line, 1, format, arglist);
                    229: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.