/[radius]/radius/radiusd/rewrite.y
ViewVC logotype

Diff of /radius/radiusd/rewrite.y

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.62 by gray, Wed Oct 1 19:53:02 2003 UTC revision 1.63 by gray, Tue Oct 14 07:10:43 2003 UTC
# Line 220  typedef struct function_def { Line 220  typedef struct function_def {
220          int        nparm;        /* Number of parameters */          int        nparm;        /* Number of parameters */
221          PARAMETER  *parm;        /* List of parameters */          PARAMETER  *parm;        /* List of parameters */
222          stkoff_t   stack_alloc;  /* required stack allocation */          stkoff_t   stack_alloc;  /* required stack allocation */
223          char       *source_file; /* Source file where the function          LOCUS      loc;          /* source location where the function
                                     was declared */  
         int        line;         /* source line where the function  
224                                    * was declared                                    * was declared
225                                    */                                    */
226  } FUNCTION;  } FUNCTION;
# Line 257  typedef union mtx MTX; Line 255  typedef union mtx MTX;
255  # define COMMON_MTX \  # define COMMON_MTX \
256          OBJ(MTX);\          OBJ(MTX);\
257          int      id;\          int      id;\
258          int      line;\          LOCUS    loc;\
259          Mtxtype  type;          Mtxtype  type;
260  #else  #else
261  # define COMMON_MTX \  # define COMMON_MTX \
# Line 526  void loop_unwind_all(); Line 524  void loop_unwind_all();
524   * Lexical analyzer stuff   * Lexical analyzer stuff
525   */   */
526  static FILE *infile;               /* Input file */  static FILE *infile;               /* Input file */
527  static char *input_filename;       /* Input location: file */  static LOCUS locus;                /* Input location */
 static int   input_line;           /* ------------- : line */  
528    
529  static char *inbuf;                /* Input string */  static char *inbuf;                /* Input string */
530  static char *curp;                 /* Current pointer */  static char *curp;                 /* Current pointer */
# Line 801  fundecl : TYPE IDENT dclparm Line 798  fundecl : TYPE IDENT dclparm
798                    f.name    = $2;                    f.name    = $2;
799                    f.rettype = $1;                    f.rettype = $1;
800                    f.entry   = 0;                    f.entry   = 0;
801                    f.line    = input_line;                    f.loc     = locus;
802                                        
803                    f.nparm   = 0;                    f.nparm   = 0;
804                    f.parm    = NULL;                    f.parm    = NULL;
# Line 827  fundecl : TYPE IDENT dclparm Line 824  fundecl : TYPE IDENT dclparm
824                    }                    }
825                    function = function_install(&f);                    function = function_install(&f);
826            }            }
827            | TYPE FUN dclparm
828              {
829                      radlog_loc(L_ERR, &locus,
830                                 _("redefinition of function `%s'"), $2->name);
831                      radlog_loc(L_ERR, &$2->loc,
832                                 _("previously defined here"));
833                      errcnt++;
834                      YYERROR;
835              }
836          ;          ;
837    
838  begin   : obrace  begin   : obrace
# Line 1007  stmt    : begin list end Line 1013  stmt    : begin list end
1013          | BREAK ';'          | BREAK ';'
1014            {            {
1015                    if (!loop_last) {                    if (!loop_last) {
1016                            radlog(L_ERR,                            radlog_loc(L_ERR, &locus,
1017                                   "%s:%d: %s",                                       "%s",
1018                                   input_filename, input_line,                                       _("nothing to break from"));
                                  _("nothing to break from"));  
1019                            errcnt++;                            errcnt++;
1020                            YYERROR;                            YYERROR;
1021                    }                    }
# Line 1022  stmt    : begin list end Line 1027  stmt    : begin list end
1027          | CONTINUE ';'          | CONTINUE ';'
1028            {            {
1029                    if (!loop_last) {                    if (!loop_last) {
1030                            radlog(L_ERR,                            radlog_loc(L_ERR, &locus,
1031                                   "%s:%d: %s",                                       "%s",
1032                                   input_filename, input_line,                                       _("nothing to continue"));
                                  _("nothing to continue"));  
1033                            errcnt++;                            errcnt++;
1034                            YYERROR;                            YYERROR;
1035                    }                    }
# Line 1094  expr    : NUMBER Line 1098  expr    : NUMBER
1098            }            }
1099          | IDENT          | IDENT
1100            {            {
1101                    radlog(L_ERR, _("%s:%d: undefined variable: %s"),                    radlog_loc(L_ERR, &locus, _("undefined variable: %s"), $1);
                          input_filename, input_line, $1);  
1102                    errcnt++;                    errcnt++;
1103                    YYERROR;                    YYERROR;
1104            }            }
# Line 1252  expr    : NUMBER Line 1255  expr    : NUMBER
1255  int  int
1256  yyerror(char *s)  yyerror(char *s)
1257  {  {
1258          radlog(L_ERR, "%s:%d: %s",          radlog_loc(L_ERR, &locus, "%s", s);
                input_filename, input_line, s);  
1259          errcnt++;          errcnt++;
1260          return 0;          return 0;
1261  }  }
# Line 1265  yyerror(char *s) Line 1267  yyerror(char *s)
1267  int  int
1268  parse_rewrite(char *path)  parse_rewrite(char *path)
1269  {  {
1270          input_filename = path;          locus.file = path;
1271          infile = fopen(input_filename, "r");          infile = fopen(locus.file, "r");
1272          if (!infile) {          if (!infile) {
1273                  if (errno != ENOENT) {                  if (errno != ENOENT) {
1274                          radlog(L_ERR|L_PERROR,                          radlog(L_ERR|L_PERROR,
1275                                 _("can't open file `%s'"),                                 _("can't open file `%s'"),
1276                                 input_filename);                                 locus.file);
1277                          return -1;                          return -1;
1278                  }                  }
1279                  return -2;                  return -2;
1280          }          }
1281    
1282          debug(1,("Loading file %s", input_filename));          debug(1,("Loading file %s", locus.file));
1283          rw_code_lock();          rw_code_lock();
1284          yyeof = 0;          yyeof = 0;
1285          input_line = 1;          locus.line = 1;
1286          errcnt = 0;          errcnt = 0;
1287          obstack_init(&input_stk);          obstack_init(&input_stk);
1288    
# Line 1300  parse_rewrite(char *path) Line 1302  parse_rewrite(char *path)
1302          fclose(infile);          fclose(infile);
1303          obstack_free(&input_stk, NULL);          obstack_free(&input_stk, NULL);
1304          rw_code_unlock();          rw_code_unlock();
1305          return 0;          return errcnt;
1306  }  }
1307    
1308  static int  static int
# Line 1309  parse_rewrite_string(char *str) Line 1311  parse_rewrite_string(char *str)
1311          rw_code_lock();          rw_code_lock();
1312          code_check();          code_check();
1313          yyeof = 0;          yyeof = 0;
1314          input_filename = "<string>";          locus.file = "<string>";
1315          input_line = 1;          locus.line = 1;
1316          errcnt = 0;          errcnt = 0;
1317          obstack_init(&input_stk);          obstack_init(&input_stk);
1318    
# Line 1574  c_comment() Line 1576  c_comment()
1576          if (yychar != '/')          if (yychar != '/')
1577                  return 0;                  return 0;
1578          if (input() == '*') {          if (input() == '*') {
1579                  int keep_line = input_line;                  size_t keep_line = locus.line;
1580    
1581                  do {                  do {
1582                          while (input() != '*') {                          while (input() != '*') {
1583                                  if (yychar == 0) {                                  if (yychar == 0) {
1584                                          radlog(L_ERR,                                          radlog_loc(L_ERR, &locus,
1585                                                 _("%s:%d: unexpected EOF in comment started at line %d"),                         _("unexpected EOF in comment started at line %lu"),
1586                                                 input_filename,                                                     (unsigned long) keep_line);
                                                input_line, keep_line);  
1587                                          return 0;                                          return 0;
1588                                  } else if (yychar == '\n')                                  } else if (yychar == '\n')
1589                                          input_line++;                                          locus.line++;
1590                          }                          }
1591                  } while (input() != '/');                  } while (input() != '/');
1592                  return 1;                  return 1;
# Line 1630  yylex() Line 1631  yylex()
1631                  nl = 0;                  nl = 0;
1632                  while (input() && isspace(yychar))                  while (input() && isspace(yychar))
1633                          if (yychar == '\n')                          if (yychar == '\n')
1634                                  input_line++;                                  locus.line++;
1635                    
1636                  if (!yychar)                  if (!yychar)
1637                          return 0;                          return 0;
# Line 1660  yylex() Line 1661  yylex()
1661                  else                  else
1662                          c = yychar;                          c = yychar;
1663                  if (input() != '\'') {                  if (input() != '\'') {
1664                          radlog(L_ERR,                          radlog_loc(L_ERR, &locus,
1665                                 "%s:%d: %s",                                     "%s",
1666                                 input_filename, input_line,                                     _("unterminated character constant"));
                                _("unterminated character constant"));  
1667                          errcnt++;                          errcnt++;
1668                  }                  }
1669                  yylval.number = c;                  yylval.number = c;
# Line 1706  yylex() Line 1706  yylex()
1706                          return '%';                          return '%';
1707                  }                  }
1708                  if (!attr) {                  if (!attr) {
1709                          radlog(L_ERR,                          radlog_loc(L_ERR, &locus,
1710                                 _("%s:%d: unknown attribute %s"),                                     _("unknown attribute %s"),
1711                                 input_filename, input_line, attr_name);                                     attr_name);
1712                          errcnt++;                          errcnt++;
1713                          return BOGUS;                          return BOGUS;
1714                  }                  }
# Line 1842  void Line 1842  void
1842  yysync()  yysync()
1843  {  {
1844          while (skip_to_nl() == '\n' && !isalpha(input()))          while (skip_to_nl() == '\n' && !isalpha(input()))
1845                  input_line++;                  locus.line++;
1846          unput(yychar);          unput(yychar);
1847  }  }
1848    
# Line 2289  mtx_alloc(Mtxtype type) Line 2289  mtx_alloc(Mtxtype type)
2289          MTX *mtx = obj_alloc(&mtx_bucket);          MTX *mtx = obj_alloc(&mtx_bucket);
2290    
2291          mtx->gen.type  = type;          mtx->gen.type  = type;
2292          mtx->gen.line  = input_line;          mtx->gen.loc   = locus;
2293  #if defined(MAINTAINER_MODE)  #if defined(MAINTAINER_MODE)
2294          mtx->gen.id    = mtx_current_id++;          mtx->gen.id    = mtx_current_id++;
2295  #endif  #endif
# Line 2401  mtx_attr_check(DICT_ATTR *attr,        MTX *ind Line 2401  mtx_attr_check(DICT_ATTR *attr,        MTX *ind
2401  void  void
2402  rw_coercion_warning(Datatype from, Datatype to, char *pref)  rw_coercion_warning(Datatype from, Datatype to, char *pref)
2403  {  {
2404          radlog(L_WARN,          radlog_loc(L_WARN, &locus,
2405                 _("%s:%d: %s implicit coercion %s %s"),                     _("%s implicit coercion %s %s"),
2406                 input_filename, input_line,                     pref ? pref : "",
2407                 pref ? pref : "",                     datatype_str_abl(from),
2408                 datatype_str_abl(from),                     datatype_str_acc(to));
                datatype_str_acc(to));  
2409  }  }
2410    
2411    
# Line 2466  mtx_bin(Bopcode opcode, MTX *arg1, MTX * Line 2465  mtx_bin(Bopcode opcode, MTX *arg1, MTX *
2465                          mtx->datatype = Integer;                          mtx->datatype = Integer;
2466                          break;                          break;
2467                  default:                  default:
2468                          radlog(L_ERR,                          radlog_loc(L_ERR, &locus,
2469                                 "%s:%d: %s",                                     "%s",
2470                                 input_filename, input_line,                                     _("operation not applicable to strings"));
                                _("operation not applicable for strings"));  
2471                          errcnt++;                          errcnt++;
2472                          return (MTX*)mtx;                          return (MTX*)mtx;
2473                  }                  }
# Line 2587  mtx_call(FUNCTION *fun, MTX *args) Line 2585  mtx_call(FUNCTION *fun, MTX *args)
2585           * Note that the argument count mismatch is not an error!           * Note that the argument count mismatch is not an error!
2586           */           */
2587          if (argp) {          if (argp) {
2588                  radlog(L_WARN,                  radlog_loc(L_WARN, &locus,
2589                         _("%s:%d: too many arguments in call to %s"),                             _("too many arguments in call to %s"),
2590                         input_filename, input_line,                             fun->name);
                        fun->name);  
2591          } else if (parmp) {          } else if (parmp) {
2592                  radlog(L_WARN,                  radlog_loc(L_WARN, &locus,
2593                         _("%s:%d: too few arguments in call to %s"),                             _("too few arguments in call to %s"),
2594                         input_filename, input_line,                             fun->name);
                        fun->name);  
2595          }          }
2596    
2597          call = (CALL_MTX*) mtx_alloc(Call);          call = (CALL_MTX*) mtx_alloc(Call);
# Line 2649  mtx_builtin(builtin_t *bin, MTX *args) Line 2645  mtx_builtin(builtin_t *bin, MTX *args)
2645          }          }
2646    
2647          if (argp) {          if (argp) {
2648                  radlog(L_ERR,                  radlog_loc(L_ERR, &locus,
2649                         _("%s:%d: too many arguments in call to %s"),                             _("too many arguments in call to %s"),
2650                         input_filename, input_line,                             bin->name);
                        bin->name);  
2651                  errcnt++;                  errcnt++;
2652          } else if (*parmp) {          } else if (*parmp) {
2653                  radlog(L_ERR,                  radlog_loc(L_ERR, &locus,
2654                         _("%s:%d: too few arguments in call to %s"),                             _("too few arguments in call to %s"),
2655                         input_filename, input_line,                             bin->name);
                        bin->name);  
2656                  errcnt++;                  errcnt++;
2657          }          }
2658    
# Line 3040  pass1() Line 3034  pass1()
3034           */           */
3035          if (mtx_last->gen.type != Return) {          if (mtx_last->gen.type != Return) {
3036                  Datum datum;                  Datum datum;
3037                  radlog(L_WARN,                  radlog_loc(L_WARN, &mtx_last->gen.loc,
3038                         _("%s:%d: missing return statement"),                             _("missing return statement"));
3039                         input_filename, mtx_last->gen.line);  
3040                  switch (function->rettype) {                  switch (function->rettype) {
3041                  case Integer:                  case Integer:
3042                          datum.ival = 0;                          datum.ival = 0;
# Line 3189  pass2_binary(MTX *mtx) Line 3183  pass2_binary(MTX *mtx)
3183                                    
3184          case Div:          case Div:
3185                  if (arg1->cnst.datum.ival == 0) {                  if (arg1->cnst.datum.ival == 0) {
3186                          radlog(L_ERR,                          radlog_loc(L_ERR, &arg1->cnst.loc,
3187                                 _("%s:%d: divide by zero"),                                     _("divide by zero"));
                                input_filename,  
                                arg1->cnst.line);  
3188                          errcnt++;                          errcnt++;
3189                  } else                  } else
3190                          dat.ival =                          dat.ival =
# Line 3201  pass2_binary(MTX *mtx) Line 3193  pass2_binary(MTX *mtx)
3193                                    
3194          case Rem:          case Rem:
3195                  if (arg1->cnst.datum.ival == 0) {                  if (arg1->cnst.datum.ival == 0) {
3196                          radlog(L_ERR,                          radlog_loc(L_ERR, &arg1->cnst.loc,
3197                                 _("%s:%d: divide by zero"),                                     _("divide by zero"));
                                input_filename,  
                                arg1->cnst.line);  
3198                          errcnt++;                          errcnt++;
3199                  } else                  } else
3200                          dat.ival =                          dat.ival =
# Line 3826  compile_regexp(char *str) Line 3816  compile_regexp(char *str)
3816          if (rc) {          if (rc) {
3817                  char errbuf[512];                  char errbuf[512];
3818                  regerror(rc, &regex, errbuf, sizeof(errbuf));                  regerror(rc, &regex, errbuf, sizeof(errbuf));
3819                  radlog(L_ERR,                  radlog_loc(L_ERR, &locus,
3820                         _("%s:%d: regexp error: %s"),                             _("regexp error: %s"),
3821                         input_filename, input_line, errbuf);                             errbuf);
3822                  return NULL;                  return NULL;
3823          }          }
3824          /* count the number of matches */          /* count the number of matches */
# Line 5168  function_install(FUNCTION *fun) Line 5158  function_install(FUNCTION *fun)
5158          FUNCTION *fp;          FUNCTION *fp;
5159    
5160          if (fp = (FUNCTION *)sym_lookup(rewrite_tab, fun->name)) {          if (fp = (FUNCTION *)sym_lookup(rewrite_tab, fun->name)) {
5161                  radlog(L_ERR,                  radlog_loc(L_ERR, &fun->loc,
5162                         _("%s:%d: redefinition of function %s"),                             _("redefinition of function %s"));
5163                         input_filename, fun->line, fun->name);                  radlog_loc(L_ERR, &fp->loc,
5164                  radlog(L_ERR,                             _("previously defined here"));
                        _("%s:%d: previously defined here"),  
                        fun->source_file, fun->line);  
5165                  errcnt++;                  errcnt++;
5166                  return fp;                  return fp;
5167          }            }  
# Line 5185  function_install(FUNCTION *fun) Line 5173  function_install(FUNCTION *fun)
5173          fp->nparm   = fun->nparm;                  fp->nparm   = fun->nparm;        
5174          fp->parm    = fun->parm;          fp->parm    = fun->parm;
5175          fp->stack_alloc = fun->stack_alloc;          fp->stack_alloc = fun->stack_alloc;
5176            fp->loc     = fun->loc;
5177          return fp;          return fp;
5178  }  }
5179    

Legend:
Removed from v.1.62  
changed lines
  Added in v.1.63

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26