scan.l (80284) | scan.l (91592) |
---|---|
1%{ | 1%{ |
2/* $NetBSD: scan.l,v 1.8 1995/10/23 13:38:51 jpo Exp $ */ | 2/* $NetBSD: scan.l,v 1.26 2002/01/31 22:30:21 tv Exp $ */ |
3 4/* | 3 4/* |
5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. |
|
5 * Copyright (c) 1994, 1995 Jochen Pohl 6 * All Rights Reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. --- 14 unchanged lines hidden (view full) --- 27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 | 6 * Copyright (c) 1994, 1995 Jochen Pohl 7 * All Rights Reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. --- 14 unchanged lines hidden (view full) --- 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 |
35#ifndef lint 36static char rcsid[] = "$FreeBSD: head/usr.bin/xlint/lint1/scan.l 80284 2001-07-24 14:02:07Z obrien $"; | 36#include <sys/cdefs.h> 37#if defined(__RCSID) && !defined(lint) 38__RCSID("$NetBSD: scan.l,v 1.26 2002/01/31 22:30:21 tv Exp $"); |
37#endif | 39#endif |
40__FBSDID("$FreeBSD: head/usr.bin/xlint/lint1/scan.l 91592 2002-03-03 15:12:50Z markm $"); |
|
38 39#include <stdlib.h> 40#include <string.h> 41#include <limits.h> 42#include <float.h> 43#include <ctype.h> 44#include <errno.h> 45#include <err.h> 46#include <math.h> 47 48#include "lint1.h" | 41 42#include <stdlib.h> 43#include <string.h> 44#include <limits.h> 45#include <float.h> 46#include <ctype.h> 47#include <errno.h> 48#include <err.h> 49#include <math.h> 50 51#include "lint1.h" |
49#include "y.tab.h" | 52#include "cgram.h" |
50 51#define CHAR_MASK (~(~0 << CHAR_BIT)) | 53 54#define CHAR_MASK (~(~0 << CHAR_BIT)) |
55#define YY_NO_UNPUT |
|
52 53/* Current position (its also updated when an included file is parsed) */ | 56 57/* Current position (its also updated when an included file is parsed) */ |
54pos_t curr_pos = { 1, "" }; | 58pos_t curr_pos = { 1, "", 0 }; |
55 56/* 57 * Current position in C source (not updated when an included file is 58 * parsed). 59 */ | 59 60/* 61 * Current position in C source (not updated when an included file is 62 * parsed). 63 */ |
60pos_t csrc_pos = { 1, "" }; | 64pos_t csrc_pos = { 1, "", 0 }; |
61 | 65 |
62static void incline __P((void)); 63static void badchar __P((int)); 64static sbuf_t *allocsb __P((void)); 65static void freesb __P((sbuf_t *)); 66static int inpc __P((void)); 67static int hash __P((const char *)); 68static sym_t *search __P((sbuf_t *)); 69static int name __P((void)); 70static int keyw __P((sym_t *)); 71static int icon __P((int)); 72static int fcon __P((void)); 73static int operator __P((int, op_t)); 74static int ccon __P((void)); 75static int wccon __P((void)); 76static int getescc __P((int)); 77static void directive __P((void)); 78static void comment __P((void)); 79static int string __P((void)); 80static int wcstrg __P((void)); | 66static void incline(void); 67static void badchar(int); 68static sbuf_t *allocsb(void); 69static void freesb(sbuf_t *); 70static int inpc(void); 71static int hash(const char *); 72static sym_t *search(sbuf_t *); 73static int name(void); 74static int keyw(sym_t *); 75static int icon(int); 76static int fcon(void); 77static int operator(int, op_t); 78static int ccon(void); 79static int wccon(void); 80static int getescc(int); 81static void directive(void); 82static void comment(void); 83static void slashslashcomment(void); 84static int string(void); 85static int wcstrg(void); |
81 82%} 83 84L [_A-Za-z] 85D [0-9] 86NZD [1-9] 87OD [0-7] 88HD [0-9A-Fa-f] --- 57 unchanged lines hidden (view full) --- 146")" return (T_RPARN); 147"..." return (T_ELLIPSE); 148"'" return (ccon()); 149"L'" return (wccon()); 150^#.*$ directive(); 151\n incline(); 152\t|" "|\f|\v ; 153"/*" comment(); | 86 87%} 88 89L [_A-Za-z] 90D [0-9] 91NZD [1-9] 92OD [0-7] 93HD [0-9A-Fa-f] --- 57 unchanged lines hidden (view full) --- 151")" return (T_RPARN); 152"..." return (T_ELLIPSE); 153"'" return (ccon()); 154"L'" return (wccon()); 155^#.*$ directive(); 156\n incline(); 157\t|" "|\f|\v ; 158"/*" comment(); |
159"//" slashslashcomment(); |
|
154. badchar(yytext[0]); 155 156%% 157 158static void | 160. badchar(yytext[0]); 161 162%% 163 164static void |
159incline() | 165incline(void) |
160{ 161 curr_pos.p_line++; | 166{ 167 curr_pos.p_line++; |
162 if (curr_pos.p_file == csrc_pos.p_file) | 168 curr_pos.p_uniq = 0; 169 if (curr_pos.p_file == csrc_pos.p_file) { |
163 csrc_pos.p_line++; | 170 csrc_pos.p_line++; |
171 csrc_pos.p_uniq = 0; 172 } |
|
164} 165 166static void | 173} 174 175static void |
167badchar(c) 168 int c; | 176badchar(int c) |
169{ | 177{ |
178 |
|
170 /* unknown character \%o */ 171 error(250, c); 172} 173 174/* 175 * Keywords. 176 * During initialisation they are written to the symbol table. 177 */ --- 26 unchanged lines hidden (view full) --- 204 { "float", T_TYPE, 0, FLOAT, 0, 0, 0 }, 205 { "for", T_FOR, 0, 0, 0, 0, 0 }, 206 { "goto", T_GOTO, 0, 0, 0, 0, 0 }, 207 { "if", T_IF, 0, 0, 0, 0, 0 }, 208 { "inline", T_SCLASS, INLINE, 0, 0, 0, 1 }, 209 { "__inline__", T_SCLASS, INLINE, 0, 0, 0, 0 }, 210 { "__inline", T_SCLASS, INLINE, 0, 0, 0, 0 }, 211 { "int", T_TYPE, 0, INT, 0, 0, 0 }, | 179 /* unknown character \%o */ 180 error(250, c); 181} 182 183/* 184 * Keywords. 185 * During initialisation they are written to the symbol table. 186 */ --- 26 unchanged lines hidden (view full) --- 213 { "float", T_TYPE, 0, FLOAT, 0, 0, 0 }, 214 { "for", T_FOR, 0, 0, 0, 0, 0 }, 215 { "goto", T_GOTO, 0, 0, 0, 0, 0 }, 216 { "if", T_IF, 0, 0, 0, 0, 0 }, 217 { "inline", T_SCLASS, INLINE, 0, 0, 0, 1 }, 218 { "__inline__", T_SCLASS, INLINE, 0, 0, 0, 0 }, 219 { "__inline", T_SCLASS, INLINE, 0, 0, 0, 0 }, 220 { "int", T_TYPE, 0, INT, 0, 0, 0 }, |
221 { "__symbolrename", T_SYMBOLRENAME, 0, 0, 0, 0, 0 }, |
|
212 { "long", T_TYPE, 0, LONG, 0, 0, 0 }, 213 { "register", T_SCLASS, REG, 0, 0, 0, 0 }, 214 { "return", T_RETURN, 0, 0, 0, 0, 0 }, 215 { "short", T_TYPE, 0, SHORT, 0, 0, 0 }, 216 { "signed", T_TYPE, 0, SIGNED, 0, 1, 0 }, 217 { "__signed__", T_TYPE, 0, SIGNED, 0, 0, 0 }, 218 { "__signed", T_TYPE, 0, SIGNED, 0, 0, 0 }, 219 { "sizeof", T_SIZEOF, 0, 0, 0, 0, 0 }, --- 10 unchanged lines hidden (view full) --- 230 { "while", T_WHILE, 0, 0, 0, 0, 0 }, 231 { NULL, 0, 0, 0, 0, 0, 0 } 232}; 233 234/* Symbol table */ 235static sym_t *symtab[HSHSIZ1]; 236 237/* bit i of the entry with index i is set */ | 222 { "long", T_TYPE, 0, LONG, 0, 0, 0 }, 223 { "register", T_SCLASS, REG, 0, 0, 0, 0 }, 224 { "return", T_RETURN, 0, 0, 0, 0, 0 }, 225 { "short", T_TYPE, 0, SHORT, 0, 0, 0 }, 226 { "signed", T_TYPE, 0, SIGNED, 0, 1, 0 }, 227 { "__signed__", T_TYPE, 0, SIGNED, 0, 0, 0 }, 228 { "__signed", T_TYPE, 0, SIGNED, 0, 0, 0 }, 229 { "sizeof", T_SIZEOF, 0, 0, 0, 0, 0 }, --- 10 unchanged lines hidden (view full) --- 240 { "while", T_WHILE, 0, 0, 0, 0, 0 }, 241 { NULL, 0, 0, 0, 0, 0, 0 } 242}; 243 244/* Symbol table */ 245static sym_t *symtab[HSHSIZ1]; 246 247/* bit i of the entry with index i is set */ |
238u_quad_t qbmasks[sizeof(u_quad_t) * CHAR_BIT]; | 248uint64_t qbmasks[sizeof(uint64_t) * CHAR_BIT]; |
239 240/* least significant i bits are set in the entry with index i */ | 249 250/* least significant i bits are set in the entry with index i */ |
241u_quad_t qlmasks[sizeof(u_quad_t) * CHAR_BIT + 1]; | 251uint64_t qlmasks[sizeof(uint64_t) * CHAR_BIT + 1]; |
242 243/* least significant i bits are not set in the entry with index i */ | 252 253/* least significant i bits are not set in the entry with index i */ |
244u_quad_t qumasks[sizeof(u_quad_t) * CHAR_BIT + 1]; | 254uint64_t qumasks[sizeof(uint64_t) * CHAR_BIT + 1]; |
245 246/* free list for sbuf structures */ 247static sbuf_t *sbfrlst; 248 249/* Typ of next expected symbol */ 250symt_t symtyp; 251 252 253/* 254 * All keywords are written to the symbol table. This saves us looking 255 * in a extra table for each name we found. 256 */ 257void | 255 256/* free list for sbuf structures */ 257static sbuf_t *sbfrlst; 258 259/* Typ of next expected symbol */ 260symt_t symtyp; 261 262 263/* 264 * All keywords are written to the symbol table. This saves us looking 265 * in a extra table for each name we found. 266 */ 267void |
258initscan() | 268initscan(void) |
259{ 260 struct kwtab *kw; 261 sym_t *sym; 262 int h, i; | 269{ 270 struct kwtab *kw; 271 sym_t *sym; 272 int h, i; |
263 u_quad_t uq; | 273 uint64_t uq; |
264 265 for (kw = kwtab; kw->kw_name != NULL; kw++) { 266 if (kw->kw_stdc && tflag) 267 continue; 268 if (kw->kw_gcc && !gflag) 269 continue; 270 sym = getblk(sizeof (sym_t)); 271 sym->s_name = kw->kw_name; --- 8 unchanged lines hidden (view full) --- 280 } 281 h = hash(sym->s_name); 282 if ((sym->s_link = symtab[h]) != NULL) 283 symtab[h]->s_rlink = &sym->s_link; 284 (symtab[h] = sym)->s_rlink = &symtab[h]; 285 } 286 287 /* initialize bit-masks for quads */ | 274 275 for (kw = kwtab; kw->kw_name != NULL; kw++) { 276 if (kw->kw_stdc && tflag) 277 continue; 278 if (kw->kw_gcc && !gflag) 279 continue; 280 sym = getblk(sizeof (sym_t)); 281 sym->s_name = kw->kw_name; --- 8 unchanged lines hidden (view full) --- 290 } 291 h = hash(sym->s_name); 292 if ((sym->s_link = symtab[h]) != NULL) 293 symtab[h]->s_rlink = &sym->s_link; 294 (symtab[h] = sym)->s_rlink = &symtab[h]; 295 } 296 297 /* initialize bit-masks for quads */ |
288 for (i = 0; i < sizeof (u_quad_t) * CHAR_BIT; i++) { 289 qbmasks[i] = (u_quad_t)1 << i; 290 uq = ~(u_quad_t)0 << i; | 298 for (i = 0; i < sizeof (uint64_t) * CHAR_BIT; i++) { 299 qbmasks[i] = (uint64_t)1 << i; 300 uq = ~(uint64_t)0 << i; |
291 qumasks[i] = uq; 292 qlmasks[i] = ~uq; 293 } 294 qumasks[i] = 0; | 301 qumasks[i] = uq; 302 qlmasks[i] = ~uq; 303 } 304 qumasks[i] = 0; |
295 qlmasks[i] = ~(u_quad_t)0; | 305 qlmasks[i] = ~(uint64_t)0; |
296} 297 298/* 299 * Get a free sbuf structure, if possible from the free list 300 */ 301static sbuf_t * | 306} 307 308/* 309 * Get a free sbuf structure, if possible from the free list 310 */ 311static sbuf_t * |
302allocsb() | 312allocsb(void) |
303{ 304 sbuf_t *sb; 305 306 if ((sb = sbfrlst) != NULL) { 307 sbfrlst = sb->sb_nxt; 308 } else { 309 if ((sb = malloc(sizeof (sbuf_t))) == NULL) 310 nomem(); 311 } 312 (void)memset(sb, 0, sizeof (sb)); 313 return (sb); 314} 315 316/* 317 * Put a sbuf structure to the free list 318 */ 319static void | 313{ 314 sbuf_t *sb; 315 316 if ((sb = sbfrlst) != NULL) { 317 sbfrlst = sb->sb_nxt; 318 } else { 319 if ((sb = malloc(sizeof (sbuf_t))) == NULL) 320 nomem(); 321 } 322 (void)memset(sb, 0, sizeof (sb)); 323 return (sb); 324} 325 326/* 327 * Put a sbuf structure to the free list 328 */ 329static void |
320freesb(sb) 321 sbuf_t *sb; | 330freesb(sbuf_t *sb) |
322{ | 331{ |
332 |
|
323 sb->sb_nxt = sbfrlst; 324 sbfrlst = sb; 325} 326 327/* 328 * Read a character and ensure that it is positive (except EOF). 329 * Increment line count(s) if necessary. 330 */ 331static int | 333 sb->sb_nxt = sbfrlst; 334 sbfrlst = sb; 335} 336 337/* 338 * Read a character and ensure that it is positive (except EOF). 339 * Increment line count(s) if necessary. 340 */ 341static int |
332inpc() | 342inpc(void) |
333{ 334 int c; 335 336 if ((c = input()) != EOF && (c &= CHAR_MASK) == '\n') 337 incline(); 338 return (c); 339} 340 341static int | 343{ 344 int c; 345 346 if ((c = input()) != EOF && (c &= CHAR_MASK) == '\n') 347 incline(); 348 return (c); 349} 350 351static int |
342hash(s) 343 const char *s; | 352hash(const char *s) |
344{ 345 u_int v; 346 const u_char *us; 347 348 v = 0; 349 for (us = (const u_char *)s; *us != '\0'; us++) { 350 v = (v << sizeof (v)) + *us; 351 v ^= v >> (sizeof (v) * CHAR_BIT - sizeof (v)); --- 12 unchanged lines hidden (view full) --- 364 * 365 * If it is a symbol, T_NAME is returned and the pointer to a sbuf struct 366 * is stored in yylval. This struct contains the name of the symbol, it's 367 * length and hash value. If there is already a symbol of the same name 368 * and type in the symbol table, the sbuf struct also contains a pointer 369 * to the symbol table entry. 370 */ 371static int | 353{ 354 u_int v; 355 const u_char *us; 356 357 v = 0; 358 for (us = (const u_char *)s; *us != '\0'; us++) { 359 v = (v << sizeof (v)) + *us; 360 v ^= v >> (sizeof (v) * CHAR_BIT - sizeof (v)); --- 12 unchanged lines hidden (view full) --- 373 * 374 * If it is a symbol, T_NAME is returned and the pointer to a sbuf struct 375 * is stored in yylval. This struct contains the name of the symbol, it's 376 * length and hash value. If there is already a symbol of the same name 377 * and type in the symbol table, the sbuf struct also contains a pointer 378 * to the symbol table entry. 379 */ 380static int |
372name() | 381name(void) |
373{ 374 char *s; 375 sbuf_t *sb; 376 sym_t *sym; 377 int tok; 378 379 sb = allocsb(); 380 sb->sb_name = yytext; --- 21 unchanged lines hidden (view full) --- 402 tok = T_NAME; 403 } 404 405 yylval.y_sb = sb; 406 return (tok); 407} 408 409static sym_t * | 382{ 383 char *s; 384 sbuf_t *sb; 385 sym_t *sym; 386 int tok; 387 388 sb = allocsb(); 389 sb->sb_name = yytext; --- 21 unchanged lines hidden (view full) --- 411 tok = T_NAME; 412 } 413 414 yylval.y_sb = sb; 415 return (tok); 416} 417 418static sym_t * |
410search(sb) 411 sbuf_t *sb; | 419search(sbuf_t *sb) |
412{ 413 sym_t *sym; 414 415 for (sym = symtab[sb->sb_hash]; sym != NULL; sym = sym->s_link) { 416 if (strcmp(sym->s_name, sb->sb_name) == 0) { 417 if (sym->s_keyw || sym->s_kind == symtyp) 418 return (sym); 419 } 420 } 421 422 return (NULL); 423} | 420{ 421 sym_t *sym; 422 423 for (sym = symtab[sb->sb_hash]; sym != NULL; sym = sym->s_link) { 424 if (strcmp(sym->s_name, sb->sb_name) == 0) { 425 if (sym->s_keyw || sym->s_kind == symtyp) 426 return (sym); 427 } 428 } 429 430 return (NULL); 431} |
424 | 432 |
425static int | 433static int |
426keyw(sym) 427 sym_t *sym; | 434keyw(sym_t *sym) |
428{ 429 int t; 430 431 if ((t = (int)sym->s_value.v_quad) == T_SCLASS) { 432 yylval.y_scl = sym->s_scl; 433 } else if (t == T_TYPE || t == T_SOU) { 434 yylval.y_tspec = sym->s_tspec; 435 } else if (t == T_QUAL) { 436 yylval.y_tqual = sym->s_tqual; 437 } 438 return (t); 439} 440 441/* 442 * Convert a string representing an integer into internal representation. 443 * The value is returned in yylval. icon() (and yylex()) returns T_CON. 444 */ 445static int | 435{ 436 int t; 437 438 if ((t = (int)sym->s_value.v_quad) == T_SCLASS) { 439 yylval.y_scl = sym->s_scl; 440 } else if (t == T_TYPE || t == T_SOU) { 441 yylval.y_tspec = sym->s_tspec; 442 } else if (t == T_QUAL) { 443 yylval.y_tqual = sym->s_tqual; 444 } 445 return (t); 446} 447 448/* 449 * Convert a string representing an integer into internal representation. 450 * The value is returned in yylval. icon() (and yylex()) returns T_CON. 451 */ 452static int |
446icon(base) 447 int base; | 453icon(int base) |
448{ 449 int l_suffix, u_suffix; 450 int len; 451 const char *cp; 452 char c, *eptr; 453 tspec_t typ; | 454{ 455 int l_suffix, u_suffix; 456 int len; 457 const char *cp; 458 char c, *eptr; 459 tspec_t typ; |
454 u_long ul; 455 u_quad_t uq; | 460 u_long ul = 0; 461 uint64_t uq = 0; |
456 int ansiu; 457 static tspec_t contypes[2][3] = { 458 { INT, LONG, QUAD }, 459 { UINT, ULONG, UQUAD } 460 }; 461 462 cp = yytext; 463 len = yyleng; --- 38 unchanged lines hidden (view full) --- 502 } 503 if (eptr != cp + len) 504 lerror("icon() 1"); 505 if (errno != 0) 506 /* integer constant out of range */ 507 warning(252); 508 509 /* | 462 int ansiu; 463 static tspec_t contypes[2][3] = { 464 { INT, LONG, QUAD }, 465 { UINT, ULONG, UQUAD } 466 }; 467 468 cp = yytext; 469 len = yyleng; --- 38 unchanged lines hidden (view full) --- 508 } 509 if (eptr != cp + len) 510 lerror("icon() 1"); 511 if (errno != 0) 512 /* integer constant out of range */ 513 warning(252); 514 515 /* |
510 * If the value is to big for the current type, we must choose | 516 * If the value is to big for the current type, we must choose |
511 * another type. 512 */ 513 ansiu = 0; 514 switch (typ) { 515 case INT: 516 if (ul <= INT_MAX) { 517 /* ok */ 518 } else if (ul <= (unsigned)UINT_MAX && base != 10) { --- 29 unchanged lines hidden (view full) --- 548 case QUAD: 549 if (uq > QUAD_MAX && !tflag) { 550 typ = UQUAD; 551 if (!sflag) 552 ansiu = 1; 553 } 554 break; 555 /* LINTED (enumeration values not handled in switch) */ | 517 * another type. 518 */ 519 ansiu = 0; 520 switch (typ) { 521 case INT: 522 if (ul <= INT_MAX) { 523 /* ok */ 524 } else if (ul <= (unsigned)UINT_MAX && base != 10) { --- 29 unchanged lines hidden (view full) --- 554 case QUAD: 555 if (uq > QUAD_MAX && !tflag) { 556 typ = UQUAD; 557 if (!sflag) 558 ansiu = 1; 559 } 560 break; 561 /* LINTED (enumeration values not handled in switch) */ |
556 default: | 562 case STRUCT: 563 case VOID: 564 case LDOUBLE: 565 case FUNC: 566 case ARRAY: 567 case PTR: 568 case ENUM: 569 case UNION: 570 case SIGNED: 571 case NOTSPEC: 572 case DOUBLE: 573 case FLOAT: 574 case UQUAD: 575 case ULONG: 576 case USHORT: 577 case SHORT: 578 case UCHAR: 579 case SCHAR: 580 case CHAR: 581 case UNSIGN: 582 break; 583 584 case NTSPEC: /* this value unused */ 585 break; |
557 } 558 559 if (typ != QUAD && typ != UQUAD) { 560 if (isutyp(typ)) { 561 uq = ul; 562 } else { | 586 } 587 588 if (typ != QUAD && typ != UQUAD) { 589 if (isutyp(typ)) { 590 uq = ul; 591 } else { |
563 uq = (quad_t)(long)ul; | 592 uq = (int64_t)(long)ul; |
564 } 565 } 566 | 593 } 594 } 595 |
567 uq = (u_quad_t)xsign((quad_t)uq, typ, -1); | 596 uq = (uint64_t)xsign((int64_t)uq, typ, -1); |
568 569 if ((yylval.y_val = calloc(1, sizeof(val_t))) == NULL) 570 nomem(); 571 yylval.y_val->v_tspec = typ; 572 yylval.y_val->v_ansiu = ansiu; | 597 598 if ((yylval.y_val = calloc(1, sizeof(val_t))) == NULL) 599 nomem(); 600 yylval.y_val->v_tspec = typ; 601 yylval.y_val->v_ansiu = ansiu; |
573 yylval.y_val->v_quad = (quad_t)uq; | 602 yylval.y_val->v_quad = (int64_t)uq; |
574 575 return (T_CON); 576} 577 578/* 579 * Returns 1 if t is a signed type and the value is negative. 580 * 581 * len is the number of significant bits. If len is -1, len is set 582 * to the width of type t. 583 */ 584int | 603 604 return (T_CON); 605} 606 607/* 608 * Returns 1 if t is a signed type and the value is negative. 609 * 610 * len is the number of significant bits. If len is -1, len is set 611 * to the width of type t. 612 */ 613int |
585sign(q, t, len) 586 quad_t q; 587 tspec_t t; 588 int len; | 614sign(int64_t q, tspec_t t, int len) |
589{ | 615{ |
616 |
|
590 if (t == PTR || isutyp(t)) 591 return (0); 592 return (msb(q, t, len)); 593} 594 595int | 617 if (t == PTR || isutyp(t)) 618 return (0); 619 return (msb(q, t, len)); 620} 621 622int |
596msb(q, t, len) 597 quad_t q; 598 tspec_t t; 599 int len; | 623msb(int64_t q, tspec_t t, int len) |
600{ | 624{ |
625 |
|
601 if (len <= 0) 602 len = size(t); 603 return ((q & qbmasks[len - 1]) != 0); 604} 605 606/* 607 * Extends the sign of q. 608 */ | 626 if (len <= 0) 627 len = size(t); 628 return ((q & qbmasks[len - 1]) != 0); 629} 630 631/* 632 * Extends the sign of q. 633 */ |
609quad_t 610xsign(q, t, len) 611 quad_t q; 612 tspec_t t; 613 int len; | 634int64_t 635xsign(int64_t q, tspec_t t, int len) |
614{ | 636{ |
637 |
|
615 if (len <= 0) 616 len = size(t); 617 618 if (t == PTR || isutyp(t) || !sign(q, t, len)) { 619 q &= qlmasks[len]; 620 } else { 621 q |= qumasks[len]; 622 } 623 return (q); 624} 625 626/* 627 * Convert a string representing a floating point value into its interal 628 * representation. Type and value are returned in yylval. fcon() 629 * (and yylex()) returns T_CON. 630 * XXX Currently it is not possible to convert constants of type | 638 if (len <= 0) 639 len = size(t); 640 641 if (t == PTR || isutyp(t) || !sign(q, t, len)) { 642 q &= qlmasks[len]; 643 } else { 644 q |= qumasks[len]; 645 } 646 return (q); 647} 648 649/* 650 * Convert a string representing a floating point value into its interal 651 * representation. Type and value are returned in yylval. fcon() 652 * (and yylex()) returns T_CON. 653 * XXX Currently it is not possible to convert constants of type |
631 * long double which are greater then DBL_MAX. | 654 * long double which are greater than DBL_MAX. |
632 */ 633static int | 655 */ 656static int |
634fcon() | 657fcon(void) |
635{ 636 const char *cp; 637 int len; 638 tspec_t typ; 639 char c, *eptr; 640 double d; | 658{ 659 const char *cp; 660 int len; 661 tspec_t typ; 662 char c, *eptr; 663 double d; |
641 float f; | 664 float f = 0; |
642 643 cp = yytext; 644 len = yyleng; 645 646 if ((c = cp[len - 1]) == 'f' || c == 'F') { 647 typ = FLOAT; 648 len--; 649 } else if (c == 'l' || c == 'L') { --- 13 unchanged lines hidden (view full) --- 663 if (eptr != cp + len) 664 lerror("fcon() 1"); 665 if (errno != 0) 666 /* floating-point constant out of range */ 667 warning(248); 668 669 if (typ == FLOAT) { 670 f = (float)d; | 665 666 cp = yytext; 667 len = yyleng; 668 669 if ((c = cp[len - 1]) == 'f' || c == 'F') { 670 typ = FLOAT; 671 len--; 672 } else if (c == 'l' || c == 'L') { --- 13 unchanged lines hidden (view full) --- 686 if (eptr != cp + len) 687 lerror("fcon() 1"); 688 if (errno != 0) 689 /* floating-point constant out of range */ 690 warning(248); 691 692 if (typ == FLOAT) { 693 f = (float)d; |
671 if (isinf(f)) { | 694 if (!finite(f)) { |
672 /* floating-point constant out of range */ 673 warning(248); 674 f = f > 0 ? FLT_MAX : -FLT_MAX; 675 } 676 } 677 678 if ((yylval.y_val = calloc(1, sizeof (val_t))) == NULL) 679 nomem(); 680 yylval.y_val->v_tspec = typ; 681 if (typ == FLOAT) { 682 yylval.y_val->v_ldbl = f; 683 } else { 684 yylval.y_val->v_ldbl = d; 685 } 686 687 return (T_CON); 688} 689 690static int | 695 /* floating-point constant out of range */ 696 warning(248); 697 f = f > 0 ? FLT_MAX : -FLT_MAX; 698 } 699 } 700 701 if ((yylval.y_val = calloc(1, sizeof (val_t))) == NULL) 702 nomem(); 703 yylval.y_val->v_tspec = typ; 704 if (typ == FLOAT) { 705 yylval.y_val->v_ldbl = f; 706 } else { 707 yylval.y_val->v_ldbl = d; 708 } 709 710 return (T_CON); 711} 712 713static int |
691operator(t, o) 692 int t; 693 op_t o; | 714operator(int t, op_t o) |
694{ | 715{ |
716 |
|
695 yylval.y_op = o; 696 return (t); 697} 698 699/* 700 * Called if lex found a leading \'. 701 */ 702static int | 717 yylval.y_op = o; 718 return (t); 719} 720 721/* 722 * Called if lex found a leading \'. 723 */ 724static int |
703ccon() | 725ccon(void) |
704{ 705 int n, val, c; 706 char cv; 707 708 n = 0; 709 val = 0; 710 while ((c = getescc('\'')) >= 0) { 711 val = (val << CHAR_BIT) + c; --- 13 unchanged lines hidden (view full) --- 725 /* empty character constant */ 726 error(73); 727 } 728 } 729 if (n == 1) { 730 cv = (char)val; 731 val = cv; 732 } | 726{ 727 int n, val, c; 728 char cv; 729 730 n = 0; 731 val = 0; 732 while ((c = getescc('\'')) >= 0) { 733 val = (val << CHAR_BIT) + c; --- 13 unchanged lines hidden (view full) --- 747 /* empty character constant */ 748 error(73); 749 } 750 } 751 if (n == 1) { 752 cv = (char)val; 753 val = cv; 754 } |
733 734 if ((yylval.y_val = calloc(1, sizeof (val_t))) == NULL) 735 nomem(); | 755 756 yylval.y_val = xcalloc(1, sizeof (val_t)); |
736 yylval.y_val->v_tspec = INT; 737 yylval.y_val->v_quad = val; 738 739 return (T_CON); 740} 741 742/* 743 * Called if lex found a leading L\' 744 */ 745static int | 757 yylval.y_val->v_tspec = INT; 758 yylval.y_val->v_quad = val; 759 760 return (T_CON); 761} 762 763/* 764 * Called if lex found a leading L\' 765 */ 766static int |
746wccon() | 767wccon(void) |
747{ 748 static char buf[MB_LEN_MAX + 1]; 749 int i, c; 750 wchar_t wc; 751 752 i = 0; 753 while ((c = getescc('\'')) >= 0) { 754 if (i < MB_CUR_MAX) --- 34 unchanged lines hidden (view full) --- 789/* 790 * Read a character which is part of a character constant or of a string 791 * and handle escapes. 792 * 793 * The Argument is the character which delimits the character constant or 794 * string. 795 * 796 * Returns -1 if the end of the character constant or string is reached, | 768{ 769 static char buf[MB_LEN_MAX + 1]; 770 int i, c; 771 wchar_t wc; 772 773 i = 0; 774 while ((c = getescc('\'')) >= 0) { 775 if (i < MB_CUR_MAX) --- 34 unchanged lines hidden (view full) --- 810/* 811 * Read a character which is part of a character constant or of a string 812 * and handle escapes. 813 * 814 * The Argument is the character which delimits the character constant or 815 * string. 816 * 817 * Returns -1 if the end of the character constant or string is reached, |
797 * -2 if the EOF is reached, and the charachter otherwise. | 818 * -2 if the EOF is reached, and the character otherwise. |
798 */ 799static int | 819 */ 820static int |
800getescc(d) 801 int d; | 821getescc(int d) |
802{ 803 static int pbc = -1; 804 int n, c, v; 805 806 if (pbc == -1) { 807 c = inpc(); 808 } else { 809 c = pbc; 810 pbc = -1; 811 } 812 if (c == d) 813 return (-1); 814 switch (c) { 815 case '\n': | 822{ 823 static int pbc = -1; 824 int n, c, v; 825 826 if (pbc == -1) { 827 c = inpc(); 828 } else { 829 c = pbc; 830 pbc = -1; 831 } 832 if (c == d) 833 return (-1); 834 switch (c) { 835 case '\n': |
816 /* newline in string or char constant */ 817 error(254); 818 return (-2); | 836 if (tflag) { 837 /* newline in string or char constant */ 838 error(254); 839 return (-2); 840 } 841 return (c); |
819 case EOF: 820 return (-2); 821 case '\\': 822 switch (c = inpc()) { 823 case '"': 824 if (tflag && d == '\'') 825 /* \" inside character constant undef. ... */ 826 warning(262); --- 6 unchanged lines hidden (view full) --- 833 warning(263); 834 return ('?'); 835 case '\\': 836 return ('\\'); 837 case 'a': 838 if (tflag) 839 /* \a undefined in traditional C */ 840 warning(81); | 842 case EOF: 843 return (-2); 844 case '\\': 845 switch (c = inpc()) { 846 case '"': 847 if (tflag && d == '\'') 848 /* \" inside character constant undef. ... */ 849 warning(262); --- 6 unchanged lines hidden (view full) --- 856 warning(263); 857 return ('?'); 858 case '\\': 859 return ('\\'); 860 case 'a': 861 if (tflag) 862 /* \a undefined in traditional C */ 863 warning(81); |
841#ifdef __STDC__ | |
842 return ('\a'); | 864 return ('\a'); |
843#else 844 return ('\007'); 845#endif | |
846 case 'b': 847 return ('\b'); 848 case 'f': 849 return ('\f'); 850 case 'n': 851 return ('\n'); 852 case 'r': 853 return ('\r'); 854 case 't': 855 return ('\t'); 856 case 'v': 857 if (tflag) 858 /* \v undefined in traditional C */ 859 warning(264); | 865 case 'b': 866 return ('\b'); 867 case 'f': 868 return ('\f'); 869 case 'n': 870 return ('\n'); 871 case 'r': 872 return ('\r'); 873 case 't': 874 return ('\t'); 875 case 'v': 876 if (tflag) 877 /* \v undefined in traditional C */ 878 warning(264); |
860#ifdef __STDC__ | |
861 return ('\v'); | 879 return ('\v'); |
862#else 863 return ('\013'); 864#endif | |
865 case '8': case '9': 866 /* bad octal digit %c */ 867 warning(77, c); 868 /* FALLTHROUGH */ 869 case '0': case '1': case '2': case '3': 870 case '4': case '5': case '6': case '7': 871 n = 3; 872 v = 0; --- 57 unchanged lines hidden (view full) --- 930} 931 932/* 933 * Called for preprocessor directives. Currently implemented are: 934 * # lineno 935 * # lineno "filename" 936 */ 937static void | 880 case '8': case '9': 881 /* bad octal digit %c */ 882 warning(77, c); 883 /* FALLTHROUGH */ 884 case '0': case '1': case '2': case '3': 885 case '4': case '5': case '6': case '7': 886 n = 3; 887 v = 0; --- 57 unchanged lines hidden (view full) --- 945} 946 947/* 948 * Called for preprocessor directives. Currently implemented are: 949 * # lineno 950 * # lineno "filename" 951 */ 952static void |
938directive() | 953directive(void) |
939{ 940 const char *cp, *fn; 941 char c, *eptr; 942 size_t fnl; 943 long ln; 944 static int first = 1; 945 946 /* Go to first non-whitespace after # */ | 954{ 955 const char *cp, *fn; 956 char c, *eptr; 957 size_t fnl; 958 long ln; 959 static int first = 1; 960 961 /* Go to first non-whitespace after # */ |
947 for (cp = yytext + 1; (c = *cp) == ' ' || c == '\t'; cp++) ; | 962 for (cp = yytext + 1; (c = *cp) == ' ' || c == '\t'; cp++) 963 continue; |
948 | 964 |
949 if (!isdigit(c)) { | 965 if (!isdigit((unsigned char)c)) { |
950 error: 951 /* undefined or invalid # directive */ 952 warning(255); 953 return; 954 } 955 ln = strtol(--cp, &eptr, 10); 956 if (cp == eptr) 957 goto error; 958 if ((c = *(cp = eptr)) != ' ' && c != '\t' && c != '\0') 959 goto error; | 966 error: 967 /* undefined or invalid # directive */ 968 warning(255); 969 return; 970 } 971 ln = strtol(--cp, &eptr, 10); 972 if (cp == eptr) 973 goto error; 974 if ((c = *(cp = eptr)) != ' ' && c != '\t' && c != '\0') 975 goto error; |
960 while ((c = *cp++) == ' ' || c == '\t') ; | 976 while ((c = *cp++) == ' ' || c == '\t') 977 continue; |
961 if (c != '\0') { 962 if (c != '"') 963 goto error; 964 fn = cp; 965 while ((c = *cp) != '"' && c != '\0') 966 cp++; 967 if (c != '"') 968 goto error; 969 if ((fnl = cp++ - fn) > PATH_MAX) 970 goto error; | 978 if (c != '\0') { 979 if (c != '"') 980 goto error; 981 fn = cp; 982 while ((c = *cp) != '"' && c != '\0') 983 cp++; 984 if (c != '"') 985 goto error; 986 if ((fnl = cp++ - fn) > PATH_MAX) 987 goto error; |
971 while ((c = *cp++) == ' ' || c == '\t') ; | 988 while ((c = *cp++) == ' ' || c == '\t') 989 continue; |
972#if 0 973 if (c != '\0') 974 warning("extra character(s) after directive"); 975#endif | 990#if 0 991 if (c != '\0') 992 warning("extra character(s) after directive"); 993#endif |
994 995 /* empty string means stdin */ 996 if (fnl == 0) { 997 fn = "{standard input}"; 998 fnl = 16; /* strlen (fn) */ 999 } |
|
976 curr_pos.p_file = fnnalloc(fn, fnl); 977 /* 978 * If this is the first directive, the name is the name 979 * of the C source file as specified at the command line. 980 * It is written to the output file. 981 */ 982 if (first) { 983 csrc_pos.p_file = curr_pos.p_file; 984 outsrc(curr_pos.p_file); 985 first = 0; 986 } 987 } 988 curr_pos.p_line = (int)ln - 1; | 1000 curr_pos.p_file = fnnalloc(fn, fnl); 1001 /* 1002 * If this is the first directive, the name is the name 1003 * of the C source file as specified at the command line. 1004 * It is written to the output file. 1005 */ 1006 if (first) { 1007 csrc_pos.p_file = curr_pos.p_file; 1008 outsrc(curr_pos.p_file); 1009 first = 0; 1010 } 1011 } 1012 curr_pos.p_line = (int)ln - 1; |
989 if (curr_pos.p_file == csrc_pos.p_file) | 1013 curr_pos.p_uniq = 0; 1014 if (curr_pos.p_file == csrc_pos.p_file) { |
990 csrc_pos.p_line = (int)ln - 1; | 1015 csrc_pos.p_line = (int)ln - 1; |
1016 csrc_pos.p_uniq = 0; 1017 } |
|
991} 992 993/* 994 * Handle lint comments. Following comments are currently understood: 995 * ARGSUSEDn | 1018} 1019 1020/* 1021 * Handle lint comments. Following comments are currently understood: 1022 * ARGSUSEDn |
1023 * BITFIELDTYPE |
|
996 * CONSTCOND CONSTANTCOND CONSTANTCONDITION 997 * FALLTHRU FALLTHROUGH 998 * LINTLIBRARY 999 * LINTED NOSTRICT 1000 * LONGLONG 1001 * NOTREACHED 1002 * PRINTFLIKEn 1003 * PROTOLIB 1004 * SCANFLIKEn 1005 * VARARGSn 1006 * If one of this comments is recognized, the arguments, if any, are 1007 * parsed and a function which handles this comment is called. 1008 */ 1009static void | 1024 * CONSTCOND CONSTANTCOND CONSTANTCONDITION 1025 * FALLTHRU FALLTHROUGH 1026 * LINTLIBRARY 1027 * LINTED NOSTRICT 1028 * LONGLONG 1029 * NOTREACHED 1030 * PRINTFLIKEn 1031 * PROTOLIB 1032 * SCANFLIKEn 1033 * VARARGSn 1034 * If one of this comments is recognized, the arguments, if any, are 1035 * parsed and a function which handles this comment is called. 1036 */ 1037static void |
1010comment() | 1038comment(void) |
1011{ 1012 int c, lc; 1013 static struct { 1014 const char *keywd; 1015 int arg; | 1039{ 1040 int c, lc; 1041 static struct { 1042 const char *keywd; 1043 int arg; |
1016 void (*func) __P((int)); | 1044 void (*func)(int); |
1017 } keywtab[] = { 1018 { "ARGSUSED", 1, argsused }, | 1045 } keywtab[] = { 1046 { "ARGSUSED", 1, argsused }, |
1047 { "BITFIELDTYPE", 0, bitfieldtype }, |
|
1019 { "CONSTCOND", 0, constcond }, 1020 { "CONSTANTCOND", 0, constcond }, 1021 { "CONSTANTCONDITION", 0, constcond }, 1022 { "FALLTHRU", 0, fallthru }, 1023 { "FALLTHROUGH", 0, fallthru }, 1024 { "LINTLIBRARY", 0, lintlib }, 1025 { "LINTED", 0, linted }, 1026 { "LONGLONG", 0, longlong }, --- 7 unchanged lines hidden (view full) --- 1034 char keywd[32]; 1035 char arg[32]; 1036 int l, i, a; 1037 int eoc; 1038 1039 eoc = 0; 1040 1041 /* Skip white spaces after the start of the comment */ | 1048 { "CONSTCOND", 0, constcond }, 1049 { "CONSTANTCOND", 0, constcond }, 1050 { "CONSTANTCONDITION", 0, constcond }, 1051 { "FALLTHRU", 0, fallthru }, 1052 { "FALLTHROUGH", 0, fallthru }, 1053 { "LINTLIBRARY", 0, lintlib }, 1054 { "LINTED", 0, linted }, 1055 { "LONGLONG", 0, longlong }, --- 7 unchanged lines hidden (view full) --- 1063 char keywd[32]; 1064 char arg[32]; 1065 int l, i, a; 1066 int eoc; 1067 1068 eoc = 0; 1069 1070 /* Skip white spaces after the start of the comment */ |
1042 while ((c = inpc()) != EOF && isspace(c)) ; | 1071 while ((c = inpc()) != EOF && isspace(c)) 1072 continue; |
1043 1044 /* Read the potential keyword to keywd */ 1045 l = 0; 1046 while (c != EOF && isupper(c) && l < sizeof (keywd) - 1) { 1047 keywd[l++] = (char)c; 1048 c = inpc(); 1049 } 1050 keywd[l] = '\0'; --- 49 unchanged lines hidden (view full) --- 1100 break; 1101 } 1102 if (lc == '*' && c == '/') 1103 eoc = 1; 1104 } 1105} 1106 1107/* | 1073 1074 /* Read the potential keyword to keywd */ 1075 l = 0; 1076 while (c != EOF && isupper(c) && l < sizeof (keywd) - 1) { 1077 keywd[l++] = (char)c; 1078 c = inpc(); 1079 } 1080 keywd[l] = '\0'; --- 49 unchanged lines hidden (view full) --- 1130 break; 1131 } 1132 if (lc == '*' && c == '/') 1133 eoc = 1; 1134 } 1135} 1136 1137/* |
1138 * Handle // style comments 1139 */ 1140static void 1141slashslashcomment(void) 1142{ 1143 int c; 1144 1145 if (sflag < 2 && !gflag) 1146 /* // comments only supported in C99 */ 1147 (void)gnuism(312, tflag ? "traditional" : "ANSI"); 1148 1149 while ((c = inpc()) != EOF && c != '\n') 1150 continue; 1151} 1152 1153/* |
|
1108 * Clear flags for lint comments LINTED, LONGLONG and CONSTCOND. 1109 * clrwflgs() is called after function definitions and global and 1110 * local declarations and definitions. It is also called between 1111 * the controlling expression and the body of control statements 1112 * (if, switch, for, while). 1113 */ 1114void | 1154 * Clear flags for lint comments LINTED, LONGLONG and CONSTCOND. 1155 * clrwflgs() is called after function definitions and global and 1156 * local declarations and definitions. It is also called between 1157 * the controlling expression and the body of control statements 1158 * (if, switch, for, while). 1159 */ 1160void |
1115clrwflgs() | 1161clrwflgs(void) |
1116{ | 1162{ |
1163 |
|
1117 nowarn = 0; 1118 quadflg = 0; 1119 ccflg = 0; 1120} 1121 1122/* 1123 * Strings are stored in a dynamically alloceted buffer and passed 1124 * in yylval.y_xstrg to the parser. The parser or the routines called 1125 * by the parser are responsible for freeing this buffer. 1126 */ 1127static int | 1164 nowarn = 0; 1165 quadflg = 0; 1166 ccflg = 0; 1167} 1168 1169/* 1170 * Strings are stored in a dynamically alloceted buffer and passed 1171 * in yylval.y_xstrg to the parser. The parser or the routines called 1172 * by the parser are responsible for freeing this buffer. 1173 */ 1174static int |
1128string() | 1175string(void) |
1129{ 1130 u_char *s; 1131 int c; 1132 size_t len, max; 1133 strg_t *strg; 1134 1135 if ((s = malloc(max = 64)) == NULL) 1136 nomem(); --- 17 unchanged lines hidden (view full) --- 1154 strg->st_len = len; 1155 strg->st_cp = s; 1156 1157 yylval.y_strg = strg; 1158 return (T_STRING); 1159} 1160 1161static int | 1176{ 1177 u_char *s; 1178 int c; 1179 size_t len, max; 1180 strg_t *strg; 1181 1182 if ((s = malloc(max = 64)) == NULL) 1183 nomem(); --- 17 unchanged lines hidden (view full) --- 1201 strg->st_len = len; 1202 strg->st_cp = s; 1203 1204 yylval.y_strg = strg; 1205 return (T_STRING); 1206} 1207 1208static int |
1162wcstrg() | 1209wcstrg(void) |
1163{ 1164 char *s; 1165 int c, i, n, wi; 1166 size_t len, max, wlen; 1167 wchar_t *ws; 1168 strg_t *strg; 1169 1170 if ((s = malloc(max = 64)) == NULL) --- 57 unchanged lines hidden (view full) --- 1228 * the symbol table. This does not mean that it is not possible that 1229 * symbols are put to the symbol table which are than not completely 1230 * declared due to syntax errors. To avoid too many problems in this 1231 * case symbols get type int in getsym(). 1232 * 1233 * XXX calls to getsym() should be delayed until decl1*() is called 1234 */ 1235sym_t * | 1210{ 1211 char *s; 1212 int c, i, n, wi; 1213 size_t len, max, wlen; 1214 wchar_t *ws; 1215 strg_t *strg; 1216 1217 if ((s = malloc(max = 64)) == NULL) --- 57 unchanged lines hidden (view full) --- 1275 * the symbol table. This does not mean that it is not possible that 1276 * symbols are put to the symbol table which are than not completely 1277 * declared due to syntax errors. To avoid too many problems in this 1278 * case symbols get type int in getsym(). 1279 * 1280 * XXX calls to getsym() should be delayed until decl1*() is called 1281 */ 1282sym_t * |
1236getsym(sb) 1237 sbuf_t *sb; | 1283getsym(sbuf_t *sb) |
1238{ 1239 dinfo_t *di; 1240 char *s; 1241 sym_t *sym; 1242 1243 sym = sb->sb_sym; 1244 1245 /* --- 31 unchanged lines hidden (view full) --- 1277 lerror("storesym() 2"); 1278 } else { 1279 sym = getblk(sizeof (sym_t)); 1280 sym->s_name = sb->sb_name; 1281 sym->s_blklev = blklev; 1282 di = dcs; 1283 } 1284 | 1284{ 1285 dinfo_t *di; 1286 char *s; 1287 sym_t *sym; 1288 1289 sym = sb->sb_sym; 1290 1291 /* --- 31 unchanged lines hidden (view full) --- 1323 lerror("storesym() 2"); 1324 } else { 1325 sym = getblk(sizeof (sym_t)); 1326 sym->s_name = sb->sb_name; 1327 sym->s_blklev = blklev; 1328 di = dcs; 1329 } 1330 |
1285 STRUCT_ASSIGN(sym->s_dpos, curr_pos); | 1331 UNIQUE_CURR_POS(sym->s_dpos); |
1286 if ((sym->s_kind = symtyp) != FLAB) 1287 sym->s_type = gettyp(INT); 1288 1289 symtyp = FVFT; 1290 1291 if ((sym->s_link = symtab[sb->sb_hash]) != NULL) 1292 symtab[sb->sb_hash]->s_rlink = &sym->s_link; 1293 (symtab[sb->sb_hash] = sym)->s_rlink = &symtab[sb->sb_hash]; --- 6 unchanged lines hidden (view full) --- 1300} 1301 1302/* 1303 * Remove a symbol forever from the symbol table. s_blklev 1304 * is set to -1 to avoid that the symbol will later be put 1305 * back to the symbol table. 1306 */ 1307void | 1332 if ((sym->s_kind = symtyp) != FLAB) 1333 sym->s_type = gettyp(INT); 1334 1335 symtyp = FVFT; 1336 1337 if ((sym->s_link = symtab[sb->sb_hash]) != NULL) 1338 symtab[sb->sb_hash]->s_rlink = &sym->s_link; 1339 (symtab[sb->sb_hash] = sym)->s_rlink = &symtab[sb->sb_hash]; --- 6 unchanged lines hidden (view full) --- 1346} 1347 1348/* 1349 * Remove a symbol forever from the symbol table. s_blklev 1350 * is set to -1 to avoid that the symbol will later be put 1351 * back to the symbol table. 1352 */ 1353void |
1308rmsym(sym) 1309 sym_t *sym; | 1354rmsym(sym_t *sym) |
1310{ | 1355{ |
1356 |
|
1311 if ((*sym->s_rlink = sym->s_link) != NULL) 1312 sym->s_link->s_rlink = sym->s_rlink; 1313 sym->s_blklev = -1; 1314 sym->s_link = NULL; 1315} 1316 1317/* 1318 * Remove a list of symbols declared at one level from the symbol 1319 * table. 1320 */ 1321void | 1357 if ((*sym->s_rlink = sym->s_link) != NULL) 1358 sym->s_link->s_rlink = sym->s_rlink; 1359 sym->s_blklev = -1; 1360 sym->s_link = NULL; 1361} 1362 1363/* 1364 * Remove a list of symbols declared at one level from the symbol 1365 * table. 1366 */ 1367void |
1322rmsyms(syms) 1323 sym_t *syms; | 1368rmsyms(sym_t *syms) |
1324{ 1325 sym_t *sym; 1326 1327 for (sym = syms; sym != NULL; sym = sym->s_dlnxt) { 1328 if (sym->s_blklev != -1) { 1329 if ((*sym->s_rlink = sym->s_link) != NULL) 1330 sym->s_link->s_rlink = sym->s_rlink; 1331 sym->s_link = NULL; 1332 sym->s_rlink = NULL; 1333 } 1334 } 1335} 1336 1337/* 1338 * Put a symbol into the symbol table 1339 */ 1340void | 1369{ 1370 sym_t *sym; 1371 1372 for (sym = syms; sym != NULL; sym = sym->s_dlnxt) { 1373 if (sym->s_blklev != -1) { 1374 if ((*sym->s_rlink = sym->s_link) != NULL) 1375 sym->s_link->s_rlink = sym->s_rlink; 1376 sym->s_link = NULL; 1377 sym->s_rlink = NULL; 1378 } 1379 } 1380} 1381 1382/* 1383 * Put a symbol into the symbol table 1384 */ 1385void |
1341inssym(bl, sym) 1342 int bl; 1343 sym_t *sym; | 1386inssym(int bl, sym_t *sym) |
1344{ 1345 int h; 1346 1347 h = hash(sym->s_name); 1348 if ((sym->s_link = symtab[h]) != NULL) 1349 symtab[h]->s_rlink = &sym->s_link; 1350 (symtab[h] = sym)->s_rlink = &symtab[h]; 1351 sym->s_blklev = bl; 1352 if (sym->s_link != NULL && sym->s_blklev < sym->s_link->s_blklev) 1353 lerror("inssym()"); 1354} 1355 1356/* 1357 * Called at level 0 after syntax errors 1358 * Removes all symbols which are not declared at level 0 from the 1359 * symbol table. Also frees all memory which is not associated with 1360 * level 0. 1361 */ 1362void | 1387{ 1388 int h; 1389 1390 h = hash(sym->s_name); 1391 if ((sym->s_link = symtab[h]) != NULL) 1392 symtab[h]->s_rlink = &sym->s_link; 1393 (symtab[h] = sym)->s_rlink = &symtab[h]; 1394 sym->s_blklev = bl; 1395 if (sym->s_link != NULL && sym->s_blklev < sym->s_link->s_blklev) 1396 lerror("inssym()"); 1397} 1398 1399/* 1400 * Called at level 0 after syntax errors 1401 * Removes all symbols which are not declared at level 0 from the 1402 * symbol table. Also frees all memory which is not associated with 1403 * level 0. 1404 */ 1405void |
1363cleanup() | 1406cleanup(void) |
1364{ 1365 sym_t *sym, *nsym; 1366 int i; 1367 1368 for (i = 0; i < HSHSIZ1; i++) { 1369 for (sym = symtab[i]; sym != NULL; sym = nsym) { 1370 nsym = sym->s_link; 1371 if (sym->s_blklev >= 1) { --- 6 unchanged lines hidden (view full) --- 1378 for (i = mblklev; i > 0; i--) 1379 freelblk(i); 1380} 1381 1382/* 1383 * Create a new symbol with the name of an existing symbol. 1384 */ 1385sym_t * | 1407{ 1408 sym_t *sym, *nsym; 1409 int i; 1410 1411 for (i = 0; i < HSHSIZ1; i++) { 1412 for (sym = symtab[i]; sym != NULL; sym = nsym) { 1413 nsym = sym->s_link; 1414 if (sym->s_blklev >= 1) { --- 6 unchanged lines hidden (view full) --- 1421 for (i = mblklev; i > 0; i--) 1422 freelblk(i); 1423} 1424 1425/* 1426 * Create a new symbol with the name of an existing symbol. 1427 */ 1428sym_t * |
1386pushdown(sym) 1387 sym_t *sym; | 1429pushdown(sym_t *sym) |
1388{ 1389 int h; 1390 sym_t *nsym; 1391 1392 h = hash(sym->s_name); 1393 nsym = getblk(sizeof (sym_t)); 1394 if (sym->s_blklev > blklev) 1395 lerror("pushdown()"); 1396 nsym->s_name = sym->s_name; | 1430{ 1431 int h; 1432 sym_t *nsym; 1433 1434 h = hash(sym->s_name); 1435 nsym = getblk(sizeof (sym_t)); 1436 if (sym->s_blklev > blklev) 1437 lerror("pushdown()"); 1438 nsym->s_name = sym->s_name; |
1397 STRUCT_ASSIGN(nsym->s_dpos, curr_pos); | 1439 UNIQUE_CURR_POS(nsym->s_dpos); |
1398 nsym->s_kind = sym->s_kind; 1399 nsym->s_blklev = blklev; 1400 1401 if ((nsym->s_link = symtab[h]) != NULL) 1402 symtab[h]->s_rlink = &nsym->s_link; 1403 (symtab[h] = nsym)->s_rlink = &symtab[h]; 1404 1405 *dcs->d_ldlsym = nsym; 1406 dcs->d_ldlsym = &nsym->s_dlnxt; 1407 1408 return (nsym); 1409} 1410 1411/* 1412 * Free any dynamically allocated memory referenced by 1413 * the value stack or yylval. 1414 * The type of information in yylval is described by tok. 1415 */ 1416void | 1440 nsym->s_kind = sym->s_kind; 1441 nsym->s_blklev = blklev; 1442 1443 if ((nsym->s_link = symtab[h]) != NULL) 1444 symtab[h]->s_rlink = &nsym->s_link; 1445 (symtab[h] = nsym)->s_rlink = &symtab[h]; 1446 1447 *dcs->d_ldlsym = nsym; 1448 dcs->d_ldlsym = &nsym->s_dlnxt; 1449 1450 return (nsym); 1451} 1452 1453/* 1454 * Free any dynamically allocated memory referenced by 1455 * the value stack or yylval. 1456 * The type of information in yylval is described by tok. 1457 */ 1458void |
1417freeyyv(sp, tok) 1418 void *sp; 1419 int tok; | 1459freeyyv(void *sp, int tok) |
1420{ 1421 if (tok == T_NAME || tok == T_TYPENAME) { 1422 sbuf_t *sb = *(sbuf_t **)sp; 1423 freesb(sb); 1424 } else if (tok == T_CON) { 1425 val_t *val = *(val_t **)sp; 1426 free(val); 1427 } else if (tok == T_STRING) { 1428 strg_t *strg = *(strg_t **)sp; 1429 if (strg->st_tspec == CHAR) { 1430 free(strg->st_cp); 1431 } else if (strg->st_tspec == WCHAR) { 1432 free(strg->st_wcp); 1433 } else { 1434 lerror("fryylv() 1"); 1435 } 1436 free(strg); | 1460{ 1461 if (tok == T_NAME || tok == T_TYPENAME) { 1462 sbuf_t *sb = *(sbuf_t **)sp; 1463 freesb(sb); 1464 } else if (tok == T_CON) { 1465 val_t *val = *(val_t **)sp; 1466 free(val); 1467 } else if (tok == T_STRING) { 1468 strg_t *strg = *(strg_t **)sp; 1469 if (strg->st_tspec == CHAR) { 1470 free(strg->st_cp); 1471 } else if (strg->st_tspec == WCHAR) { 1472 free(strg->st_wcp); 1473 } else { 1474 lerror("fryylv() 1"); 1475 } 1476 free(strg); |
1437 } | 1477 } |
1438} | 1478} |