1*7c478bd9Sstevel@tonic-gate %{ 2*7c478bd9Sstevel@tonic-gate /* 3*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 4*7c478bd9Sstevel@tonic-gate * 5*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 6*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 7*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 8*7c478bd9Sstevel@tonic-gate * with the License. 9*7c478bd9Sstevel@tonic-gate * 10*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 12*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 13*7c478bd9Sstevel@tonic-gate * and limitations under the License. 14*7c478bd9Sstevel@tonic-gate * 15*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 16*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 18*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 19*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 20*7c478bd9Sstevel@tonic-gate * 21*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 22*7c478bd9Sstevel@tonic-gate * 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */ 28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate /* 33*7c478bd9Sstevel@tonic-gate * cscope - interactive C symbol cross-reference 34*7c478bd9Sstevel@tonic-gate * 35*7c478bd9Sstevel@tonic-gate * 36*7c478bd9Sstevel@tonic-gate * C symbol scanner 37*7c478bd9Sstevel@tonic-gate */ 38*7c478bd9Sstevel@tonic-gate #ident "@(#)scanner.l 1.2 93/06/07 SMI" 39*7c478bd9Sstevel@tonic-gate #include "global.h" 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate /* the line counting has been moved from character reading for speed */ 42*7c478bd9Sstevel@tonic-gate /* comments are discarded */ 43*7c478bd9Sstevel@tonic-gate #undef input 44*7c478bd9Sstevel@tonic-gate #define input() \ 45*7c478bd9Sstevel@tonic-gate ((yytchar = (yytchar = yysptr > yysbuf ? \ 46*7c478bd9Sstevel@tonic-gate *--yysptr : getc(yyin)) == '/' ? comment() : yytchar) == \ 47*7c478bd9Sstevel@tonic-gate EOF ? 0 : toascii(yytchar)) 48*7c478bd9Sstevel@tonic-gate #define noncommentinput() \ 49*7c478bd9Sstevel@tonic-gate ((yytchar = yysptr > yysbuf ? *--yysptr : getc(yyin)) == \ 50*7c478bd9Sstevel@tonic-gate EOF ? 0 : yytchar) 51*7c478bd9Sstevel@tonic-gate #undef unput 52*7c478bd9Sstevel@tonic-gate #define unput(c) (*yysptr++ = (c)) 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate /* not a preprocessor line (allow Ingres(TM) "## char var;" lines) */ 55*7c478bd9Sstevel@tonic-gate #define notpp() (ppdefine == NO && (*yytext != '#' || yytext[1] == '#')) 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate #define IFLEVELINC 5 /* #if nesting level size increment */ 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate /* keyword text for fast testing of keywords in the scanner */ 60*7c478bd9Sstevel@tonic-gate extern char externtext[]; 61*7c478bd9Sstevel@tonic-gate extern char typedeftext[]; 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate int first; /* buffer index for first char of symbol */ 64*7c478bd9Sstevel@tonic-gate int last; /* buffer index for last char of symbol */ 65*7c478bd9Sstevel@tonic-gate int lineno; /* symbol line number */ 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate static BOOL arraydimension; /* inside array dimension declaration */ 68*7c478bd9Sstevel@tonic-gate static BOOL bplisting; /* breakpoint listing */ 69*7c478bd9Sstevel@tonic-gate static int braces; /* unmatched left brace count */ 70*7c478bd9Sstevel@tonic-gate static int cesudeftoken; /* class/enum/struct/union definition */ 71*7c478bd9Sstevel@tonic-gate static BOOL classdef; /* c++ class definition */ 72*7c478bd9Sstevel@tonic-gate static BOOL elseelif; /* #else or #elif found */ 73*7c478bd9Sstevel@tonic-gate static BOOL esudef; /* enum/struct/union definition */ 74*7c478bd9Sstevel@tonic-gate static int esubraces; /* outermost enum/struct/union */ 75*7c478bd9Sstevel@tonic-gate /* brace count */ 76*7c478bd9Sstevel@tonic-gate static BOOL externdec; /* extern declaration */ 77*7c478bd9Sstevel@tonic-gate static BOOL fcndef; /* function definition */ 78*7c478bd9Sstevel@tonic-gate static BOOL globalscope; /* file global scope */ 79*7c478bd9Sstevel@tonic-gate /* (outside functions) */ 80*7c478bd9Sstevel@tonic-gate static int iflevel; /* #if nesting level */ 81*7c478bd9Sstevel@tonic-gate static BOOL initializer; /* data initializer */ 82*7c478bd9Sstevel@tonic-gate static int initializerbraces; /* data initializer outer brace count */ 83*7c478bd9Sstevel@tonic-gate static BOOL lex; /* lex file */ 84*7c478bd9Sstevel@tonic-gate static BOOL localdef; /* function/block local definition */ 85*7c478bd9Sstevel@tonic-gate static int miflevel = IFLEVELINC; /* maximum #if nesting level */ 86*7c478bd9Sstevel@tonic-gate static int *maxifbraces; /* maximum brace count within #if */ 87*7c478bd9Sstevel@tonic-gate static int *preifbraces; /* brace count before #if */ 88*7c478bd9Sstevel@tonic-gate static int parens; /* unmatched left parenthesis count */ 89*7c478bd9Sstevel@tonic-gate static BOOL ppdefine; /* preprocessor define statement */ 90*7c478bd9Sstevel@tonic-gate static BOOL psuedoelif; /* psuedo-#elif */ 91*7c478bd9Sstevel@tonic-gate static BOOL oldtype; /* next identifier is an old type */ 92*7c478bd9Sstevel@tonic-gate static BOOL rules; /* lex/yacc rules */ 93*7c478bd9Sstevel@tonic-gate static BOOL sdl; /* SDL file */ 94*7c478bd9Sstevel@tonic-gate static BOOL structfield; /* structure field declaration */ 95*7c478bd9Sstevel@tonic-gate static BOOL template; /* function template */ 96*7c478bd9Sstevel@tonic-gate static int templateparens; /* function template outer parentheses count */ 97*7c478bd9Sstevel@tonic-gate static BOOL typedefdef; /* typedef name definition */ 98*7c478bd9Sstevel@tonic-gate static BOOL typedefname; /* typedef name use */ 99*7c478bd9Sstevel@tonic-gate static int token; /* token found */ 100*7c478bd9Sstevel@tonic-gate 101*7c478bd9Sstevel@tonic-gate static BOOL asy; /* assembly file */ 102*7c478bd9Sstevel@tonic-gate 103*7c478bd9Sstevel@tonic-gate void multicharconstant(char terminator); 104*7c478bd9Sstevel@tonic-gate int do_assembly(int token); 105*7c478bd9Sstevel@tonic-gate %} 106*7c478bd9Sstevel@tonic-gate identifier [a-zA-Z_][a-zA-Z_0-9]* 107*7c478bd9Sstevel@tonic-gate number \.?[0-9][.0-9a-fA-FlLuUxX]* 108*7c478bd9Sstevel@tonic-gate %start SDL 109*7c478bd9Sstevel@tonic-gate %a 6000 110*7c478bd9Sstevel@tonic-gate %o 11000 111*7c478bd9Sstevel@tonic-gate %p 3000 112*7c478bd9Sstevel@tonic-gate %% 113*7c478bd9Sstevel@tonic-gate %\{ { /* lex/yacc C declarations/definitions */ 114*7c478bd9Sstevel@tonic-gate globalscope = YES; 115*7c478bd9Sstevel@tonic-gate goto more; 116*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 117*7c478bd9Sstevel@tonic-gate } 118*7c478bd9Sstevel@tonic-gate %\} { 119*7c478bd9Sstevel@tonic-gate globalscope = NO; 120*7c478bd9Sstevel@tonic-gate goto more; 121*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 122*7c478bd9Sstevel@tonic-gate } 123*7c478bd9Sstevel@tonic-gate ^%% { /* lex/yacc rules delimiter */ 124*7c478bd9Sstevel@tonic-gate braces = 0; 125*7c478bd9Sstevel@tonic-gate if (rules == NO) { 126*7c478bd9Sstevel@tonic-gate rules = YES; 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate /* simulate a yylex() or yyparse() definition */ 129*7c478bd9Sstevel@tonic-gate (void) strcat(yytext, " /* "); 130*7c478bd9Sstevel@tonic-gate first = strlen(yytext); 131*7c478bd9Sstevel@tonic-gate if (lex == YES) { 132*7c478bd9Sstevel@tonic-gate (void) strcat(yytext, "yylex"); 133*7c478bd9Sstevel@tonic-gate } else { 134*7c478bd9Sstevel@tonic-gate /* 135*7c478bd9Sstevel@tonic-gate * yacc: yyparse implicitly calls yylex 136*7c478bd9Sstevel@tonic-gate */ 137*7c478bd9Sstevel@tonic-gate char *s = " yylex()"; 138*7c478bd9Sstevel@tonic-gate char *cp = s + strlen(s); 139*7c478bd9Sstevel@tonic-gate while (--cp >= s) { 140*7c478bd9Sstevel@tonic-gate unput(*cp); 141*7c478bd9Sstevel@tonic-gate } 142*7c478bd9Sstevel@tonic-gate (void) strcat(yytext, "yyparse"); 143*7c478bd9Sstevel@tonic-gate } 144*7c478bd9Sstevel@tonic-gate last = strlen(yytext); 145*7c478bd9Sstevel@tonic-gate (void) strcat(yytext, " */"); 146*7c478bd9Sstevel@tonic-gate yyleng = strlen(yytext); 147*7c478bd9Sstevel@tonic-gate yymore(); 148*7c478bd9Sstevel@tonic-gate return (FCNDEF); 149*7c478bd9Sstevel@tonic-gate } else { 150*7c478bd9Sstevel@tonic-gate rules = NO; 151*7c478bd9Sstevel@tonic-gate globalscope = YES; 152*7c478bd9Sstevel@tonic-gate last = first; 153*7c478bd9Sstevel@tonic-gate yymore(); 154*7c478bd9Sstevel@tonic-gate return (FCNEND); 155*7c478bd9Sstevel@tonic-gate } 156*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 157*7c478bd9Sstevel@tonic-gate } 158*7c478bd9Sstevel@tonic-gate <SDL>(PROCEDURE|STATE)[ \t]+({identifier}|\*) { /* SDL procedure or state */ 159*7c478bd9Sstevel@tonic-gate braces = 1; 160*7c478bd9Sstevel@tonic-gate fcndef = YES; /* treat as function definition */ 161*7c478bd9Sstevel@tonic-gate token = FCNDEF; 162*7c478bd9Sstevel@tonic-gate globalscope = NO; 163*7c478bd9Sstevel@tonic-gate goto findident; 164*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 165*7c478bd9Sstevel@tonic-gate } 166*7c478bd9Sstevel@tonic-gate <SDL>(CALL|NEXTSTATE)[ \t]+({identifier}|\*) { /* SDL call or nextstate */ 167*7c478bd9Sstevel@tonic-gate token = FCNCALL; 168*7c478bd9Sstevel@tonic-gate goto findident; /* treat as function call */ 169*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 170*7c478bd9Sstevel@tonic-gate } 171*7c478bd9Sstevel@tonic-gate <SDL>END(PROCEDURE|STATE)[ \t]+({identifier}|\*) { 172*7c478bd9Sstevel@tonic-gate /* end of an SDL procedure or state */ 173*7c478bd9Sstevel@tonic-gate goto endstate; /* treat as the end of a function */ 174*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 175*7c478bd9Sstevel@tonic-gate } 176*7c478bd9Sstevel@tonic-gate \{ { 177*7c478bd9Sstevel@tonic-gate /* count unmatched left braces for fcn def detection */ 178*7c478bd9Sstevel@tonic-gate ++braces; 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate /* 181*7c478bd9Sstevel@tonic-gate * mark an untagged enum/struct/union so its beginning 182*7c478bd9Sstevel@tonic-gate * can be found 183*7c478bd9Sstevel@tonic-gate */ 184*7c478bd9Sstevel@tonic-gate if (cesudeftoken) { 185*7c478bd9Sstevel@tonic-gate last = first; 186*7c478bd9Sstevel@tonic-gate savesymbol(cesudeftoken); 187*7c478bd9Sstevel@tonic-gate cesudeftoken = '\0'; 188*7c478bd9Sstevel@tonic-gate } 189*7c478bd9Sstevel@tonic-gate goto more; 190*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 191*7c478bd9Sstevel@tonic-gate } 192*7c478bd9Sstevel@tonic-gate \#[ \t]*endif/.*[\n\r][ \t\n\r]*#[ \t]*if { 193*7c478bd9Sstevel@tonic-gate /* 194*7c478bd9Sstevel@tonic-gate * attempt to correct erroneous brace count caused by: 195*7c478bd9Sstevel@tonic-gate * 196*7c478bd9Sstevel@tonic-gate * #if ... 197*7c478bd9Sstevel@tonic-gate * ... { 198*7c478bd9Sstevel@tonic-gate * #endif 199*7c478bd9Sstevel@tonic-gate * #if ... 200*7c478bd9Sstevel@tonic-gate * ... { 201*7c478bd9Sstevel@tonic-gate * #endif 202*7c478bd9Sstevel@tonic-gate */ 203*7c478bd9Sstevel@tonic-gate /* the current #if must not have an #else or #elif */ 204*7c478bd9Sstevel@tonic-gate if (elseelif == YES) { 205*7c478bd9Sstevel@tonic-gate goto endif; 206*7c478bd9Sstevel@tonic-gate } 207*7c478bd9Sstevel@tonic-gate psuedoelif = YES; 208*7c478bd9Sstevel@tonic-gate goto more; 209*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 210*7c478bd9Sstevel@tonic-gate } 211*7c478bd9Sstevel@tonic-gate \#[ \t]*ifn?(def)? { /* #if, #ifdef or #ifndef */ 212*7c478bd9Sstevel@tonic-gate elseelif = NO; 213*7c478bd9Sstevel@tonic-gate if (psuedoelif == YES) { 214*7c478bd9Sstevel@tonic-gate psuedoelif = NO; 215*7c478bd9Sstevel@tonic-gate goto elif; 216*7c478bd9Sstevel@tonic-gate } 217*7c478bd9Sstevel@tonic-gate /* 218*7c478bd9Sstevel@tonic-gate * make sure there is room for the current brace count 219*7c478bd9Sstevel@tonic-gate */ 220*7c478bd9Sstevel@tonic-gate if (iflevel == miflevel) { 221*7c478bd9Sstevel@tonic-gate miflevel += IFLEVELINC; 222*7c478bd9Sstevel@tonic-gate maxifbraces = myrealloc(maxifbraces, 223*7c478bd9Sstevel@tonic-gate miflevel * sizeof (int)); 224*7c478bd9Sstevel@tonic-gate preifbraces = myrealloc(preifbraces, 225*7c478bd9Sstevel@tonic-gate miflevel * sizeof (int)); 226*7c478bd9Sstevel@tonic-gate } 227*7c478bd9Sstevel@tonic-gate /* push the current brace count */ 228*7c478bd9Sstevel@tonic-gate preifbraces[iflevel] = braces; 229*7c478bd9Sstevel@tonic-gate maxifbraces[iflevel++] = 0; 230*7c478bd9Sstevel@tonic-gate goto more; 231*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 232*7c478bd9Sstevel@tonic-gate } 233*7c478bd9Sstevel@tonic-gate \#[ \t]*el(se|if) { /* #elif or #else */ 234*7c478bd9Sstevel@tonic-gate elseelif = YES; 235*7c478bd9Sstevel@tonic-gate elif: 236*7c478bd9Sstevel@tonic-gate if (iflevel > 0) { 237*7c478bd9Sstevel@tonic-gate 238*7c478bd9Sstevel@tonic-gate /* save the maximum brace count for this #if */ 239*7c478bd9Sstevel@tonic-gate if (braces > maxifbraces[iflevel]) { 240*7c478bd9Sstevel@tonic-gate maxifbraces[iflevel - 1] = braces; 241*7c478bd9Sstevel@tonic-gate } 242*7c478bd9Sstevel@tonic-gate /* restore the brace count to before the #if */ 243*7c478bd9Sstevel@tonic-gate braces = preifbraces[iflevel - 1]; 244*7c478bd9Sstevel@tonic-gate } 245*7c478bd9Sstevel@tonic-gate goto more; 246*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 247*7c478bd9Sstevel@tonic-gate } 248*7c478bd9Sstevel@tonic-gate \#[ \t]*endif { /* #endif */ 249*7c478bd9Sstevel@tonic-gate endif: 250*7c478bd9Sstevel@tonic-gate if (iflevel > 0) { 251*7c478bd9Sstevel@tonic-gate 252*7c478bd9Sstevel@tonic-gate /* get the maximum brace count for this #if */ 253*7c478bd9Sstevel@tonic-gate if (braces < maxifbraces[--iflevel]) { 254*7c478bd9Sstevel@tonic-gate braces = maxifbraces[iflevel]; 255*7c478bd9Sstevel@tonic-gate } 256*7c478bd9Sstevel@tonic-gate } 257*7c478bd9Sstevel@tonic-gate goto more; 258*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 259*7c478bd9Sstevel@tonic-gate } 260*7c478bd9Sstevel@tonic-gate \} { 261*7c478bd9Sstevel@tonic-gate /* could be the last enum member initializer */ 262*7c478bd9Sstevel@tonic-gate if (braces == initializerbraces) { 263*7c478bd9Sstevel@tonic-gate initializerbraces = -1; 264*7c478bd9Sstevel@tonic-gate initializer = NO; 265*7c478bd9Sstevel@tonic-gate } 266*7c478bd9Sstevel@tonic-gate if (--braces <= 0) { 267*7c478bd9Sstevel@tonic-gate endstate: 268*7c478bd9Sstevel@tonic-gate braces = 0; 269*7c478bd9Sstevel@tonic-gate classdef = NO; 270*7c478bd9Sstevel@tonic-gate } 271*7c478bd9Sstevel@tonic-gate /* 272*7c478bd9Sstevel@tonic-gate * if the end of an outermost enum/struct/union 273*7c478bd9Sstevel@tonic-gate * definition 274*7c478bd9Sstevel@tonic-gate */ 275*7c478bd9Sstevel@tonic-gate if (esudef == YES && braces == esubraces) { 276*7c478bd9Sstevel@tonic-gate esudef = NO; 277*7c478bd9Sstevel@tonic-gate esubraces = -1; 278*7c478bd9Sstevel@tonic-gate last = first; 279*7c478bd9Sstevel@tonic-gate yymore(); 280*7c478bd9Sstevel@tonic-gate return (ESUEND); 281*7c478bd9Sstevel@tonic-gate } 282*7c478bd9Sstevel@tonic-gate /* if the end of a function */ 283*7c478bd9Sstevel@tonic-gate if ((braces == 0 || braces == 1 && classdef == YES) && 284*7c478bd9Sstevel@tonic-gate fcndef == YES) { 285*7c478bd9Sstevel@tonic-gate fcndef = NO; 286*7c478bd9Sstevel@tonic-gate globalscope = YES; 287*7c478bd9Sstevel@tonic-gate last = first; 288*7c478bd9Sstevel@tonic-gate yymore(); 289*7c478bd9Sstevel@tonic-gate return (FCNEND); 290*7c478bd9Sstevel@tonic-gate } 291*7c478bd9Sstevel@tonic-gate goto more; 292*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 293*7c478bd9Sstevel@tonic-gate } 294*7c478bd9Sstevel@tonic-gate \( { 295*7c478bd9Sstevel@tonic-gate /* 296*7c478bd9Sstevel@tonic-gate * count unmatched left parentheses for function 297*7c478bd9Sstevel@tonic-gate * templates 298*7c478bd9Sstevel@tonic-gate */ 299*7c478bd9Sstevel@tonic-gate ++parens; 300*7c478bd9Sstevel@tonic-gate goto more; 301*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 302*7c478bd9Sstevel@tonic-gate } 303*7c478bd9Sstevel@tonic-gate \) { 304*7c478bd9Sstevel@tonic-gate if (--parens <= 0) { 305*7c478bd9Sstevel@tonic-gate parens = 0; 306*7c478bd9Sstevel@tonic-gate } 307*7c478bd9Sstevel@tonic-gate /* if the end of a function template */ 308*7c478bd9Sstevel@tonic-gate if (parens == templateparens) { 309*7c478bd9Sstevel@tonic-gate templateparens = -1; 310*7c478bd9Sstevel@tonic-gate template = NO; 311*7c478bd9Sstevel@tonic-gate } 312*7c478bd9Sstevel@tonic-gate goto more; 313*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 314*7c478bd9Sstevel@tonic-gate } 315*7c478bd9Sstevel@tonic-gate = { /* if a global definition initializer */ 316*7c478bd9Sstevel@tonic-gate if ((globalscope == YES || localdef == YES) && 317*7c478bd9Sstevel@tonic-gate notpp()) { 318*7c478bd9Sstevel@tonic-gate initializerbraces = braces; 319*7c478bd9Sstevel@tonic-gate initializer = YES; 320*7c478bd9Sstevel@tonic-gate } 321*7c478bd9Sstevel@tonic-gate goto more; 322*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 323*7c478bd9Sstevel@tonic-gate } 324*7c478bd9Sstevel@tonic-gate : { /* if a structure field */ 325*7c478bd9Sstevel@tonic-gate /* note: a pr header has a colon in the date */ 326*7c478bd9Sstevel@tonic-gate if (esudef == YES && notpp()) { 327*7c478bd9Sstevel@tonic-gate structfield = YES; 328*7c478bd9Sstevel@tonic-gate } 329*7c478bd9Sstevel@tonic-gate goto more; 330*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 331*7c478bd9Sstevel@tonic-gate } 332*7c478bd9Sstevel@tonic-gate \, { 333*7c478bd9Sstevel@tonic-gate if (braces == initializerbraces) { 334*7c478bd9Sstevel@tonic-gate initializerbraces = -1; 335*7c478bd9Sstevel@tonic-gate initializer = NO; 336*7c478bd9Sstevel@tonic-gate } 337*7c478bd9Sstevel@tonic-gate structfield = NO; 338*7c478bd9Sstevel@tonic-gate goto more; 339*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 340*7c478bd9Sstevel@tonic-gate } 341*7c478bd9Sstevel@tonic-gate "##" | /* start of Ingres(TM) code line */ 342*7c478bd9Sstevel@tonic-gate ; { 343*7c478bd9Sstevel@tonic-gate /* if not in an enum/struct/union declaration */ 344*7c478bd9Sstevel@tonic-gate if (esudef == NO) { 345*7c478bd9Sstevel@tonic-gate externdec = NO; 346*7c478bd9Sstevel@tonic-gate typedefdef = NO; 347*7c478bd9Sstevel@tonic-gate localdef = NO; 348*7c478bd9Sstevel@tonic-gate } 349*7c478bd9Sstevel@tonic-gate structfield = NO; 350*7c478bd9Sstevel@tonic-gate initializer = NO; 351*7c478bd9Sstevel@tonic-gate oldtype = NO; 352*7c478bd9Sstevel@tonic-gate goto more; 353*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 354*7c478bd9Sstevel@tonic-gate } 355*7c478bd9Sstevel@tonic-gate \#[ \t]*define[ \t]+{identifier} { 356*7c478bd9Sstevel@tonic-gate 357*7c478bd9Sstevel@tonic-gate /* preprocessor macro or constant definition */ 358*7c478bd9Sstevel@tonic-gate ppdefine = YES; 359*7c478bd9Sstevel@tonic-gate token = DEFINE; 360*7c478bd9Sstevel@tonic-gate if (compress == YES) { 361*7c478bd9Sstevel@tonic-gate /* compress the keyword */ 362*7c478bd9Sstevel@tonic-gate yytext[0] = '\7'; 363*7c478bd9Sstevel@tonic-gate } 364*7c478bd9Sstevel@tonic-gate findident: 365*7c478bd9Sstevel@tonic-gate first = yyleng - 1; 366*7c478bd9Sstevel@tonic-gate while (isalnum(yytext[first]) || yytext[first] == '_') { 367*7c478bd9Sstevel@tonic-gate --first; 368*7c478bd9Sstevel@tonic-gate } 369*7c478bd9Sstevel@tonic-gate ++first; 370*7c478bd9Sstevel@tonic-gate goto iflongline; 371*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 372*7c478bd9Sstevel@tonic-gate } 373*7c478bd9Sstevel@tonic-gate class[ \t]+{identifier}[ \t\n\ra-zA-Z0-9_():]*\{ { 374*7c478bd9Sstevel@tonic-gate /* class definition */ 375*7c478bd9Sstevel@tonic-gate classdef = YES; 376*7c478bd9Sstevel@tonic-gate cesudeftoken = 'c'; 377*7c478bd9Sstevel@tonic-gate REJECT; 378*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 379*7c478bd9Sstevel@tonic-gate } 380*7c478bd9Sstevel@tonic-gate (enum|struct|union)/([ \t\n\r]+{identifier})?[ \t\n\r]*\{ { 381*7c478bd9Sstevel@tonic-gate /* enum/struct/union definition */ 382*7c478bd9Sstevel@tonic-gate esudef = YES; 383*7c478bd9Sstevel@tonic-gate if (esubraces < 0) { 384*7c478bd9Sstevel@tonic-gate /* if outermost enum/struct/union */ 385*7c478bd9Sstevel@tonic-gate esubraces = braces; 386*7c478bd9Sstevel@tonic-gate } 387*7c478bd9Sstevel@tonic-gate cesudeftoken = *(yytext + first); 388*7c478bd9Sstevel@tonic-gate goto iflongline; 389*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 390*7c478bd9Sstevel@tonic-gate } 391*7c478bd9Sstevel@tonic-gate {identifier}/[ \t]*\(([ \t\n\ra-zA-Z0-9_*&[\]=,.]*|\([ \ta-zA-Z0-9_*[\],]*\))*\)[ \t\n\r()]*[:a-zA-Z_#{] { 392*7c478bd9Sstevel@tonic-gate 393*7c478bd9Sstevel@tonic-gate /* 394*7c478bd9Sstevel@tonic-gate * warning: "if (...)" must not overflow yytext, so 395*7c478bd9Sstevel@tonic-gate * the content of function argument definitions is 396*7c478bd9Sstevel@tonic-gate * restricted, in particular parentheses are 397*7c478bd9Sstevel@tonic-gate * not allowed 398*7c478bd9Sstevel@tonic-gate */ 399*7c478bd9Sstevel@tonic-gate 400*7c478bd9Sstevel@tonic-gate if (asy) { 401*7c478bd9Sstevel@tonic-gate /* 402*7c478bd9Sstevel@tonic-gate * In assembly files, if it looks like 403*7c478bd9Sstevel@tonic-gate * a definition, pass it down as one and we'll 404*7c478bd9Sstevel@tonic-gate * take care of it later. 405*7c478bd9Sstevel@tonic-gate */ 406*7c478bd9Sstevel@tonic-gate token = FCNDEF; 407*7c478bd9Sstevel@tonic-gate goto iflongline; 408*7c478bd9Sstevel@tonic-gate } 409*7c478bd9Sstevel@tonic-gate 410*7c478bd9Sstevel@tonic-gate /* if a function definition */ 411*7c478bd9Sstevel@tonic-gate /* 412*7c478bd9Sstevel@tonic-gate * note: "#define a (b) {" and "#if defined(a)\n#" 413*7c478bd9Sstevel@tonic-gate * are not 414*7c478bd9Sstevel@tonic-gate */ 415*7c478bd9Sstevel@tonic-gate if (braces == 0 && notpp() && rules == NO || 416*7c478bd9Sstevel@tonic-gate braces == 1 && classdef == YES) { 417*7c478bd9Sstevel@tonic-gate fcndef = YES; 418*7c478bd9Sstevel@tonic-gate token = FCNDEF; 419*7c478bd9Sstevel@tonic-gate globalscope = NO; 420*7c478bd9Sstevel@tonic-gate goto iflongline; 421*7c478bd9Sstevel@tonic-gate } 422*7c478bd9Sstevel@tonic-gate goto iffcncall; 423*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 424*7c478bd9Sstevel@tonic-gate } 425*7c478bd9Sstevel@tonic-gate {identifier}/[ \t]*\( { 426*7c478bd9Sstevel@tonic-gate if (asy) { 427*7c478bd9Sstevel@tonic-gate /* 428*7c478bd9Sstevel@tonic-gate * Macro calls can get here if they have 429*7c478bd9Sstevel@tonic-gate * arguments which contain %'s (i.e., 430*7c478bd9Sstevel@tonic-gate * registers). 431*7c478bd9Sstevel@tonic-gate */ 432*7c478bd9Sstevel@tonic-gate token = FCNDEF; 433*7c478bd9Sstevel@tonic-gate goto iflongline; 434*7c478bd9Sstevel@tonic-gate } 435*7c478bd9Sstevel@tonic-gate 436*7c478bd9Sstevel@tonic-gate /* if a function call */ 437*7c478bd9Sstevel@tonic-gate iffcncall: 438*7c478bd9Sstevel@tonic-gate if ((fcndef == YES || ppdefine == YES || 439*7c478bd9Sstevel@tonic-gate rules == YES) && externdec == NO && 440*7c478bd9Sstevel@tonic-gate (localdef == NO || initializer == YES)) { 441*7c478bd9Sstevel@tonic-gate token = FCNCALL; 442*7c478bd9Sstevel@tonic-gate goto iflongline; 443*7c478bd9Sstevel@tonic-gate } 444*7c478bd9Sstevel@tonic-gate if (template == NO && typedefdef == NO) { 445*7c478bd9Sstevel@tonic-gate templateparens = parens; 446*7c478bd9Sstevel@tonic-gate template = YES; 447*7c478bd9Sstevel@tonic-gate } 448*7c478bd9Sstevel@tonic-gate token = IDENT; 449*7c478bd9Sstevel@tonic-gate goto iflongline; 450*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 451*7c478bd9Sstevel@tonic-gate } 452*7c478bd9Sstevel@tonic-gate (\+\+|--)[ \t]*{identifier} { /* prefix increment or decrement */ 453*7c478bd9Sstevel@tonic-gate token = ASSIGNMENT; 454*7c478bd9Sstevel@tonic-gate goto findident; 455*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 456*7c478bd9Sstevel@tonic-gate } 457*7c478bd9Sstevel@tonic-gate {identifier}/[ \t]*(\+\+|--) { /* postfix increment or decrement */ 458*7c478bd9Sstevel@tonic-gate token = ASSIGNMENT; 459*7c478bd9Sstevel@tonic-gate goto iflongline; 460*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 461*7c478bd9Sstevel@tonic-gate } 462*7c478bd9Sstevel@tonic-gate \*[ \t]*{identifier}/[ \t]*[^a-zA-Z0-9_(+-][^+-] { 463*7c478bd9Sstevel@tonic-gate /* indirect assignment or dcl */ 464*7c478bd9Sstevel@tonic-gate while (!isalnum(yytext[first]) && 465*7c478bd9Sstevel@tonic-gate yytext[first] != '_') { 466*7c478bd9Sstevel@tonic-gate ++first; 467*7c478bd9Sstevel@tonic-gate } 468*7c478bd9Sstevel@tonic-gate goto ident; 469*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 470*7c478bd9Sstevel@tonic-gate } 471*7c478bd9Sstevel@tonic-gate {identifier}/[ \t\n\r]*(=[^=]|[-+*/%&^|]=|<<=|>>=) { /* assignment */ 472*7c478bd9Sstevel@tonic-gate if ((fcndef == YES || ppdefine == YES || 473*7c478bd9Sstevel@tonic-gate rules == YES) && localdef == NO) { 474*7c478bd9Sstevel@tonic-gate token = ASSIGNMENT; 475*7c478bd9Sstevel@tonic-gate goto iflongline; 476*7c478bd9Sstevel@tonic-gate } 477*7c478bd9Sstevel@tonic-gate goto ident; 478*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 479*7c478bd9Sstevel@tonic-gate } 480*7c478bd9Sstevel@tonic-gate {identifier}/[* \t\n\r]+[a-zA-Z0-9_] { /* possible typedef name use */ 481*7c478bd9Sstevel@tonic-gate if (notpp() && esudef == NO && fcndef == YES && 482*7c478bd9Sstevel@tonic-gate typedefdef == NO && parens == 0) { 483*7c478bd9Sstevel@tonic-gate char c, *s = yytext + first - 1; 484*7c478bd9Sstevel@tonic-gate 485*7c478bd9Sstevel@tonic-gate while (--s >= yytext && (c = *s) != ';' && 486*7c478bd9Sstevel@tonic-gate c != '{') { 487*7c478bd9Sstevel@tonic-gate if (!isspace(c) && !isalpha(c)) { 488*7c478bd9Sstevel@tonic-gate goto nottypedefname; 489*7c478bd9Sstevel@tonic-gate } 490*7c478bd9Sstevel@tonic-gate } 491*7c478bd9Sstevel@tonic-gate typedefname = YES; 492*7c478bd9Sstevel@tonic-gate } 493*7c478bd9Sstevel@tonic-gate nottypedefname: 494*7c478bd9Sstevel@tonic-gate /* skip the global/parameter/local tests */ 495*7c478bd9Sstevel@tonic-gate token = IDENT; 496*7c478bd9Sstevel@tonic-gate goto iflongline; 497*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 498*7c478bd9Sstevel@tonic-gate } 499*7c478bd9Sstevel@tonic-gate {identifier} { 500*7c478bd9Sstevel@tonic-gate struct keystruct *p; 501*7c478bd9Sstevel@tonic-gate char *s; 502*7c478bd9Sstevel@tonic-gate 503*7c478bd9Sstevel@tonic-gate ident: token = IDENT; 504*7c478bd9Sstevel@tonic-gate if (notpp() && externdec == NO && 505*7c478bd9Sstevel@tonic-gate arraydimension == NO && initializer == NO) { 506*7c478bd9Sstevel@tonic-gate 507*7c478bd9Sstevel@tonic-gate /* if an enum/struct/union member definition */ 508*7c478bd9Sstevel@tonic-gate if (esudef == YES) { 509*7c478bd9Sstevel@tonic-gate if (structfield == NO) { 510*7c478bd9Sstevel@tonic-gate token = MEMBERDEF; 511*7c478bd9Sstevel@tonic-gate } 512*7c478bd9Sstevel@tonic-gate } else if (typedefdef == YES && oldtype == NO) { 513*7c478bd9Sstevel@tonic-gate /* if a typedef name */ 514*7c478bd9Sstevel@tonic-gate token = TYPEDEF; 515*7c478bd9Sstevel@tonic-gate } else if (globalscope == YES && 516*7c478bd9Sstevel@tonic-gate template == NO && oldtype == NO) { 517*7c478bd9Sstevel@tonic-gate /* if a global definition */ 518*7c478bd9Sstevel@tonic-gate token = GLOBALDEF; 519*7c478bd9Sstevel@tonic-gate } else if (fcndef == YES && braces == 0) { 520*7c478bd9Sstevel@tonic-gate /* if a function parameter definition */ 521*7c478bd9Sstevel@tonic-gate token = PARAMETER; 522*7c478bd9Sstevel@tonic-gate } else if (localdef == YES) { 523*7c478bd9Sstevel@tonic-gate /* if a local definition */ 524*7c478bd9Sstevel@tonic-gate token = LOCALDEF; 525*7c478bd9Sstevel@tonic-gate } 526*7c478bd9Sstevel@tonic-gate } 527*7c478bd9Sstevel@tonic-gate iflongline: 528*7c478bd9Sstevel@tonic-gate /* if a long line */ 529*7c478bd9Sstevel@tonic-gate if (yyleng > STMTMAX) { 530*7c478bd9Sstevel@tonic-gate int c; 531*7c478bd9Sstevel@tonic-gate 532*7c478bd9Sstevel@tonic-gate /* skip to the end of the line */ 533*7c478bd9Sstevel@tonic-gate warning("line too long"); 534*7c478bd9Sstevel@tonic-gate while ((c = input()) != LEXEOF) { 535*7c478bd9Sstevel@tonic-gate if (c == '\n') { 536*7c478bd9Sstevel@tonic-gate unput(c); 537*7c478bd9Sstevel@tonic-gate break; 538*7c478bd9Sstevel@tonic-gate } 539*7c478bd9Sstevel@tonic-gate } 540*7c478bd9Sstevel@tonic-gate } 541*7c478bd9Sstevel@tonic-gate /* truncate a long symbol */ 542*7c478bd9Sstevel@tonic-gate if (yyleng - first > PATLEN) { 543*7c478bd9Sstevel@tonic-gate warning("symbol too long"); 544*7c478bd9Sstevel@tonic-gate yyleng = first + PATLEN; 545*7c478bd9Sstevel@tonic-gate yytext[yyleng] = '\0'; 546*7c478bd9Sstevel@tonic-gate } 547*7c478bd9Sstevel@tonic-gate 548*7c478bd9Sstevel@tonic-gate yymore(); 549*7c478bd9Sstevel@tonic-gate 550*7c478bd9Sstevel@tonic-gate if (asy) { 551*7c478bd9Sstevel@tonic-gate int t; 552*7c478bd9Sstevel@tonic-gate 553*7c478bd9Sstevel@tonic-gate last = yyleng; 554*7c478bd9Sstevel@tonic-gate t = do_assembly(token); 555*7c478bd9Sstevel@tonic-gate if (t >= 0) { 556*7c478bd9Sstevel@tonic-gate token = t; 557*7c478bd9Sstevel@tonic-gate return (token); 558*7c478bd9Sstevel@tonic-gate } 559*7c478bd9Sstevel@tonic-gate 560*7c478bd9Sstevel@tonic-gate goto end; 561*7c478bd9Sstevel@tonic-gate } 562*7c478bd9Sstevel@tonic-gate 563*7c478bd9Sstevel@tonic-gate /* if a keyword */ 564*7c478bd9Sstevel@tonic-gate if ((p = lookup(yytext + first)) != NULL) { 565*7c478bd9Sstevel@tonic-gate first = yyleng; 566*7c478bd9Sstevel@tonic-gate s = p->text; 567*7c478bd9Sstevel@tonic-gate 568*7c478bd9Sstevel@tonic-gate /* if an extern declaration */ 569*7c478bd9Sstevel@tonic-gate if (s == externtext) { 570*7c478bd9Sstevel@tonic-gate externdec = YES; 571*7c478bd9Sstevel@tonic-gate } else if (s == typedeftext) { 572*7c478bd9Sstevel@tonic-gate /* if a typedef name definition */ 573*7c478bd9Sstevel@tonic-gate typedefdef = YES; 574*7c478bd9Sstevel@tonic-gate oldtype = YES; 575*7c478bd9Sstevel@tonic-gate } else if (p->type == DECL && fcndef == YES && 576*7c478bd9Sstevel@tonic-gate typedefdef == NO && parens == 0) { 577*7c478bd9Sstevel@tonic-gate /* if a local definition */ 578*7c478bd9Sstevel@tonic-gate localdef = YES; 579*7c478bd9Sstevel@tonic-gate } else if (templateparens == parens && 580*7c478bd9Sstevel@tonic-gate template == YES) { 581*7c478bd9Sstevel@tonic-gate /* 582*7c478bd9Sstevel@tonic-gate * keyword doesn't start a function 583*7c478bd9Sstevel@tonic-gate * template 584*7c478bd9Sstevel@tonic-gate */ 585*7c478bd9Sstevel@tonic-gate templateparens = -1; 586*7c478bd9Sstevel@tonic-gate template = NO; 587*7c478bd9Sstevel@tonic-gate } else { 588*7c478bd9Sstevel@tonic-gate /* 589*7c478bd9Sstevel@tonic-gate * next identifier after typedef was 590*7c478bd9Sstevel@tonic-gate * a keyword 591*7c478bd9Sstevel@tonic-gate */ 592*7c478bd9Sstevel@tonic-gate oldtype = NO; 593*7c478bd9Sstevel@tonic-gate } 594*7c478bd9Sstevel@tonic-gate typedefname = NO; 595*7c478bd9Sstevel@tonic-gate } else { /* identifier */ 596*7c478bd9Sstevel@tonic-gate last = yyleng; 597*7c478bd9Sstevel@tonic-gate 598*7c478bd9Sstevel@tonic-gate /* 599*7c478bd9Sstevel@tonic-gate * if an enum/struct/union keyword preceded 600*7c478bd9Sstevel@tonic-gate * this ident. 601*7c478bd9Sstevel@tonic-gate */ 602*7c478bd9Sstevel@tonic-gate if (esudef == YES && cesudeftoken) { 603*7c478bd9Sstevel@tonic-gate token = cesudeftoken; 604*7c478bd9Sstevel@tonic-gate cesudeftoken = '\0'; 605*7c478bd9Sstevel@tonic-gate } else { 606*7c478bd9Sstevel@tonic-gate oldtype = NO; 607*7c478bd9Sstevel@tonic-gate } 608*7c478bd9Sstevel@tonic-gate /* if a local definition using a typedef name */ 609*7c478bd9Sstevel@tonic-gate if (typedefname == YES) { 610*7c478bd9Sstevel@tonic-gate localdef = YES; 611*7c478bd9Sstevel@tonic-gate } 612*7c478bd9Sstevel@tonic-gate typedefname = NO; 613*7c478bd9Sstevel@tonic-gate return (token); 614*7c478bd9Sstevel@tonic-gate } 615*7c478bd9Sstevel@tonic-gate 616*7c478bd9Sstevel@tonic-gate end: 617*7c478bd9Sstevel@tonic-gate ; 618*7c478bd9Sstevel@tonic-gate } 619*7c478bd9Sstevel@tonic-gate \[ { /* array dimension (don't worry about subscripts) */ 620*7c478bd9Sstevel@tonic-gate arraydimension = YES; 621*7c478bd9Sstevel@tonic-gate goto more; 622*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 623*7c478bd9Sstevel@tonic-gate } 624*7c478bd9Sstevel@tonic-gate \] { 625*7c478bd9Sstevel@tonic-gate arraydimension = NO; 626*7c478bd9Sstevel@tonic-gate goto more; 627*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 628*7c478bd9Sstevel@tonic-gate } 629*7c478bd9Sstevel@tonic-gate \\\n { /* preprocessor statement is continued on next line */ 630*7c478bd9Sstevel@tonic-gate goto eol; 631*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 632*7c478bd9Sstevel@tonic-gate } 633*7c478bd9Sstevel@tonic-gate \n { /* end of the line */ 634*7c478bd9Sstevel@tonic-gate if (ppdefine == YES) { /* end of a #define */ 635*7c478bd9Sstevel@tonic-gate ppdefine = NO; 636*7c478bd9Sstevel@tonic-gate (void) yyless(yyleng - 1); /* rescan \n */ 637*7c478bd9Sstevel@tonic-gate last = first; 638*7c478bd9Sstevel@tonic-gate yymore(); 639*7c478bd9Sstevel@tonic-gate return (DEFINEEND); 640*7c478bd9Sstevel@tonic-gate } 641*7c478bd9Sstevel@tonic-gate /* 642*7c478bd9Sstevel@tonic-gate * skip the first 8 columns of a breakpoint listing 643*7c478bd9Sstevel@tonic-gate * line and skip the file path in the page header 644*7c478bd9Sstevel@tonic-gate */ 645*7c478bd9Sstevel@tonic-gate if (bplisting == YES) { 646*7c478bd9Sstevel@tonic-gate int c, i; 647*7c478bd9Sstevel@tonic-gate 648*7c478bd9Sstevel@tonic-gate switch (input()) { 649*7c478bd9Sstevel@tonic-gate /* tab and EOF just fall through */ 650*7c478bd9Sstevel@tonic-gate case ' ': /* breakpoint number line */ 651*7c478bd9Sstevel@tonic-gate case '[': 652*7c478bd9Sstevel@tonic-gate for (i = 1; i < 8 && input() != LEXEOF; 653*7c478bd9Sstevel@tonic-gate ++i) { 654*7c478bd9Sstevel@tonic-gate /*EMPTY*/ 655*7c478bd9Sstevel@tonic-gate } 656*7c478bd9Sstevel@tonic-gate break; 657*7c478bd9Sstevel@tonic-gate case '.': /* header line */ 658*7c478bd9Sstevel@tonic-gate case '/': 659*7c478bd9Sstevel@tonic-gate /* skip to the end of the line */ 660*7c478bd9Sstevel@tonic-gate while ((c = input()) != LEXEOF) { 661*7c478bd9Sstevel@tonic-gate if (c == '\n') { 662*7c478bd9Sstevel@tonic-gate unput(c); 663*7c478bd9Sstevel@tonic-gate break; 664*7c478bd9Sstevel@tonic-gate } 665*7c478bd9Sstevel@tonic-gate } 666*7c478bd9Sstevel@tonic-gate break; 667*7c478bd9Sstevel@tonic-gate case '\n': /* empty line */ 668*7c478bd9Sstevel@tonic-gate unput('\n'); 669*7c478bd9Sstevel@tonic-gate break; 670*7c478bd9Sstevel@tonic-gate } 671*7c478bd9Sstevel@tonic-gate } 672*7c478bd9Sstevel@tonic-gate eol: 673*7c478bd9Sstevel@tonic-gate ++yylineno; 674*7c478bd9Sstevel@tonic-gate first = 0; 675*7c478bd9Sstevel@tonic-gate last = 0; 676*7c478bd9Sstevel@tonic-gate if (symbols > 0) { 677*7c478bd9Sstevel@tonic-gate return (NEWLINE); 678*7c478bd9Sstevel@tonic-gate } 679*7c478bd9Sstevel@tonic-gate lineno = yylineno; 680*7c478bd9Sstevel@tonic-gate } 681*7c478bd9Sstevel@tonic-gate \' { /* character constant */ 682*7c478bd9Sstevel@tonic-gate if (sdl == NO) { 683*7c478bd9Sstevel@tonic-gate multicharconstant('\''); 684*7c478bd9Sstevel@tonic-gate } 685*7c478bd9Sstevel@tonic-gate goto more; 686*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 687*7c478bd9Sstevel@tonic-gate } 688*7c478bd9Sstevel@tonic-gate \" { /* string constant */ 689*7c478bd9Sstevel@tonic-gate multicharconstant('"'); 690*7c478bd9Sstevel@tonic-gate goto more; 691*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 692*7c478bd9Sstevel@tonic-gate } 693*7c478bd9Sstevel@tonic-gate ^[ \t\f\b]+ { /* don't save leading white space */ 694*7c478bd9Sstevel@tonic-gate } 695*7c478bd9Sstevel@tonic-gate \#[# \t]*include[ \t]*["<][^"> \t\n\r]+ { /* #include or Ingres ##include */ 696*7c478bd9Sstevel@tonic-gate char *s; 697*7c478bd9Sstevel@tonic-gate 698*7c478bd9Sstevel@tonic-gate s = strpbrk(yytext, "\"<"); 699*7c478bd9Sstevel@tonic-gate incfile(s + 1, *s); 700*7c478bd9Sstevel@tonic-gate first = s - yytext; 701*7c478bd9Sstevel@tonic-gate last = yyleng; 702*7c478bd9Sstevel@tonic-gate if (compress == YES) { 703*7c478bd9Sstevel@tonic-gate /* compress the keyword */ 704*7c478bd9Sstevel@tonic-gate yytext[0] = '\1'; 705*7c478bd9Sstevel@tonic-gate } 706*7c478bd9Sstevel@tonic-gate /* 707*7c478bd9Sstevel@tonic-gate * avoid multicharconstant call triggered by trailing 708*7c478bd9Sstevel@tonic-gate * ", which puts a trailing comment in the database 709*7c478bd9Sstevel@tonic-gate */ 710*7c478bd9Sstevel@tonic-gate if (*s == '"') { 711*7c478bd9Sstevel@tonic-gate int c; 712*7c478bd9Sstevel@tonic-gate 713*7c478bd9Sstevel@tonic-gate while ((c = input()) != LEXEOF) { 714*7c478bd9Sstevel@tonic-gate if (c == '"') { 715*7c478bd9Sstevel@tonic-gate yytext[yyleng] = '"'; 716*7c478bd9Sstevel@tonic-gate yytext[++yyleng] = '\0'; 717*7c478bd9Sstevel@tonic-gate break; 718*7c478bd9Sstevel@tonic-gate } 719*7c478bd9Sstevel@tonic-gate /* the trailing '"' may be missing */ 720*7c478bd9Sstevel@tonic-gate if (c == '\n') { 721*7c478bd9Sstevel@tonic-gate unput('\n'); 722*7c478bd9Sstevel@tonic-gate break; 723*7c478bd9Sstevel@tonic-gate } 724*7c478bd9Sstevel@tonic-gate } 725*7c478bd9Sstevel@tonic-gate } 726*7c478bd9Sstevel@tonic-gate yymore(); 727*7c478bd9Sstevel@tonic-gate return (INCLUDE); 728*7c478bd9Sstevel@tonic-gate /* NOTREACHED */ 729*7c478bd9Sstevel@tonic-gate } 730*7c478bd9Sstevel@tonic-gate \#[ \t]*pragma[ \t]+weak[ \t]+{identifier} { 731*7c478bd9Sstevel@tonic-gate ppdefine = YES; 732*7c478bd9Sstevel@tonic-gate token = DEFINE; 733*7c478bd9Sstevel@tonic-gate goto findident; 734*7c478bd9Sstevel@tonic-gate 735*7c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 736*7c478bd9Sstevel@tonic-gate } 737*7c478bd9Sstevel@tonic-gate \#[ \t]*{identifier} | /* preprocessor keyword */ 738*7c478bd9Sstevel@tonic-gate {number} | /* number */ 739*7c478bd9Sstevel@tonic-gate . { /* punctuation and operators */ 740*7c478bd9Sstevel@tonic-gate more: first = yyleng; 741*7c478bd9Sstevel@tonic-gate yymore(); 742*7c478bd9Sstevel@tonic-gate } 743*7c478bd9Sstevel@tonic-gate %% 744*7c478bd9Sstevel@tonic-gate 745*7c478bd9Sstevel@tonic-gate void 746*7c478bd9Sstevel@tonic-gate initscanner(char *srcfile) 747*7c478bd9Sstevel@tonic-gate { 748*7c478bd9Sstevel@tonic-gate char *s; 749*7c478bd9Sstevel@tonic-gate 750*7c478bd9Sstevel@tonic-gate if (maxifbraces == NULL) { 751*7c478bd9Sstevel@tonic-gate maxifbraces = mymalloc(miflevel * sizeof (int)); 752*7c478bd9Sstevel@tonic-gate preifbraces = mymalloc(miflevel * sizeof (int)); 753*7c478bd9Sstevel@tonic-gate } 754*7c478bd9Sstevel@tonic-gate first = 0; /* buffer index for first char of symbol */ 755*7c478bd9Sstevel@tonic-gate last = 0; /* buffer index for last char of symbol */ 756*7c478bd9Sstevel@tonic-gate lineno = 1; /* symbol line number */ 757*7c478bd9Sstevel@tonic-gate yylineno = 1; /* input line number */ 758*7c478bd9Sstevel@tonic-gate arraydimension = NO; /* inside array dimension declaration */ 759*7c478bd9Sstevel@tonic-gate bplisting = NO; /* breakpoint listing */ 760*7c478bd9Sstevel@tonic-gate braces = 0; /* unmatched left brace count */ 761*7c478bd9Sstevel@tonic-gate cesudeftoken = '\0'; /* class/enum/struct/union definition */ 762*7c478bd9Sstevel@tonic-gate classdef = NO; /* c++ class definition */ 763*7c478bd9Sstevel@tonic-gate elseelif = NO; /* #else or #elif found */ 764*7c478bd9Sstevel@tonic-gate esudef = NO; /* enum/struct/union definition */ 765*7c478bd9Sstevel@tonic-gate esubraces = -1; /* outermost enum/struct/union brace count */ 766*7c478bd9Sstevel@tonic-gate externdec = NO; /* extern declaration */ 767*7c478bd9Sstevel@tonic-gate fcndef = NO; /* function definition */ 768*7c478bd9Sstevel@tonic-gate globalscope = YES; /* file global scope (outside functions) */ 769*7c478bd9Sstevel@tonic-gate iflevel = 0; /* #if nesting level */ 770*7c478bd9Sstevel@tonic-gate initializer = NO; /* data initializer */ 771*7c478bd9Sstevel@tonic-gate initializerbraces = -1; /* data initializer outer brace count */ 772*7c478bd9Sstevel@tonic-gate lex = NO; /* lex file */ 773*7c478bd9Sstevel@tonic-gate localdef = NO; /* function/block local definition */ 774*7c478bd9Sstevel@tonic-gate parens = 0; /* unmatched left parenthesis count */ 775*7c478bd9Sstevel@tonic-gate ppdefine = NO; /* preprocessor define statement */ 776*7c478bd9Sstevel@tonic-gate psuedoelif = NO; /* psuedo-#elif */ 777*7c478bd9Sstevel@tonic-gate oldtype = NO; /* next identifier is an old type */ 778*7c478bd9Sstevel@tonic-gate rules = NO; /* lex/yacc rules */ 779*7c478bd9Sstevel@tonic-gate sdl = NO; /* SDL file */ 780*7c478bd9Sstevel@tonic-gate structfield = NO; /* structure field declaration */ 781*7c478bd9Sstevel@tonic-gate template = NO; /* function template */ 782*7c478bd9Sstevel@tonic-gate templateparens = -1; /* function template outer parentheses count */ 783*7c478bd9Sstevel@tonic-gate typedefdef = NO; /* typedef name definition */ 784*7c478bd9Sstevel@tonic-gate typedefname = NO; /* typedef name use */ 785*7c478bd9Sstevel@tonic-gate asy = NO; /* assembly file */ 786*7c478bd9Sstevel@tonic-gate BEGIN 0; 787*7c478bd9Sstevel@tonic-gate 788*7c478bd9Sstevel@tonic-gate /* if this is not a C file */ 789*7c478bd9Sstevel@tonic-gate if ((s = strrchr(srcfile, '.')) != NULL) { 790*7c478bd9Sstevel@tonic-gate switch (*++s) { /* this switch saves time on C files */ 791*7c478bd9Sstevel@tonic-gate case 'b': 792*7c478bd9Sstevel@tonic-gate if (strcmp(s, "bp") == 0) { /* breakpoint listing */ 793*7c478bd9Sstevel@tonic-gate bplisting = YES; 794*7c478bd9Sstevel@tonic-gate } 795*7c478bd9Sstevel@tonic-gate break; 796*7c478bd9Sstevel@tonic-gate case 'l': 797*7c478bd9Sstevel@tonic-gate if (strcmp(s, "l") == 0) { /* lex */ 798*7c478bd9Sstevel@tonic-gate lex = YES; 799*7c478bd9Sstevel@tonic-gate globalscope = NO; 800*7c478bd9Sstevel@tonic-gate } 801*7c478bd9Sstevel@tonic-gate break; 802*7c478bd9Sstevel@tonic-gate case 'p': 803*7c478bd9Sstevel@tonic-gate case 's': 804*7c478bd9Sstevel@tonic-gate if (strcmp(s, "pr") == 0 || 805*7c478bd9Sstevel@tonic-gate strcmp(s, "sd") == 0) { /* SDL */ 806*7c478bd9Sstevel@tonic-gate sdl = YES; 807*7c478bd9Sstevel@tonic-gate BEGIN SDL; 808*7c478bd9Sstevel@tonic-gate } else if (strcmp(s, "s") == 0) { 809*7c478bd9Sstevel@tonic-gate asy = YES; 810*7c478bd9Sstevel@tonic-gate } 811*7c478bd9Sstevel@tonic-gate break; 812*7c478bd9Sstevel@tonic-gate case 'y': 813*7c478bd9Sstevel@tonic-gate if (strcmp(s, "y") == 0) { /* yacc */ 814*7c478bd9Sstevel@tonic-gate globalscope = NO; 815*7c478bd9Sstevel@tonic-gate } 816*7c478bd9Sstevel@tonic-gate break; 817*7c478bd9Sstevel@tonic-gate } 818*7c478bd9Sstevel@tonic-gate } 819*7c478bd9Sstevel@tonic-gate } 820*7c478bd9Sstevel@tonic-gate 821*7c478bd9Sstevel@tonic-gate int 822*7c478bd9Sstevel@tonic-gate comment(void) 823*7c478bd9Sstevel@tonic-gate { 824*7c478bd9Sstevel@tonic-gate int c, lastc; 825*7c478bd9Sstevel@tonic-gate 826*7c478bd9Sstevel@tonic-gate do { 827*7c478bd9Sstevel@tonic-gate if ((c = getc(yyin)) == '*') { /* C comment */ 828*7c478bd9Sstevel@tonic-gate lastc = '\0'; 829*7c478bd9Sstevel@tonic-gate while ((c = getc(yyin)) != EOF && 830*7c478bd9Sstevel@tonic-gate (c != '/' || lastc != '*')) { /* fewer '/'s */ 831*7c478bd9Sstevel@tonic-gate if (c == '\n') { 832*7c478bd9Sstevel@tonic-gate ++yylineno; 833*7c478bd9Sstevel@tonic-gate } 834*7c478bd9Sstevel@tonic-gate lastc = c; 835*7c478bd9Sstevel@tonic-gate } 836*7c478bd9Sstevel@tonic-gate /* return a blank for Reiser cpp token concatenation */ 837*7c478bd9Sstevel@tonic-gate if ((c = getc(yyin)) == '_' || isalnum(c)) { 838*7c478bd9Sstevel@tonic-gate (void) ungetc(c, yyin); 839*7c478bd9Sstevel@tonic-gate c = ' '; 840*7c478bd9Sstevel@tonic-gate break; 841*7c478bd9Sstevel@tonic-gate } 842*7c478bd9Sstevel@tonic-gate } else if (c == '/') { /* C++ comment */ 843*7c478bd9Sstevel@tonic-gate while ((c = getc(yyin)) != EOF && c != '\n') { 844*7c478bd9Sstevel@tonic-gate /*EMPTY*/ 845*7c478bd9Sstevel@tonic-gate } 846*7c478bd9Sstevel@tonic-gate break; 847*7c478bd9Sstevel@tonic-gate } else { /* not a comment */ 848*7c478bd9Sstevel@tonic-gate (void) ungetc(c, yyin); 849*7c478bd9Sstevel@tonic-gate c = '/'; 850*7c478bd9Sstevel@tonic-gate break; 851*7c478bd9Sstevel@tonic-gate } 852*7c478bd9Sstevel@tonic-gate 853*7c478bd9Sstevel@tonic-gate /* there may be an immediately following comment */ 854*7c478bd9Sstevel@tonic-gate } while (c == '/'); 855*7c478bd9Sstevel@tonic-gate return (c); 856*7c478bd9Sstevel@tonic-gate } 857*7c478bd9Sstevel@tonic-gate 858*7c478bd9Sstevel@tonic-gate void 859*7c478bd9Sstevel@tonic-gate multicharconstant(char terminator) 860*7c478bd9Sstevel@tonic-gate { 861*7c478bd9Sstevel@tonic-gate char c; 862*7c478bd9Sstevel@tonic-gate 863*7c478bd9Sstevel@tonic-gate /* scan until the terminator is found */ 864*7c478bd9Sstevel@tonic-gate while ((c = yytext[yyleng++] = noncommentinput()) != terminator) { 865*7c478bd9Sstevel@tonic-gate switch (c) { 866*7c478bd9Sstevel@tonic-gate case '\\': /* escape character */ 867*7c478bd9Sstevel@tonic-gate if ((yytext[yyleng++] = noncommentinput()) == '\n') { 868*7c478bd9Sstevel@tonic-gate ++yylineno; 869*7c478bd9Sstevel@tonic-gate } 870*7c478bd9Sstevel@tonic-gate break; 871*7c478bd9Sstevel@tonic-gate case '\t': /* tab character */ 872*7c478bd9Sstevel@tonic-gate 873*7c478bd9Sstevel@tonic-gate /* if not a lex program, continue */ 874*7c478bd9Sstevel@tonic-gate if (lex == NO) { 875*7c478bd9Sstevel@tonic-gate break; 876*7c478bd9Sstevel@tonic-gate } 877*7c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 878*7c478bd9Sstevel@tonic-gate 879*7c478bd9Sstevel@tonic-gate case '\n': /* illegal character */ 880*7c478bd9Sstevel@tonic-gate 881*7c478bd9Sstevel@tonic-gate /* 882*7c478bd9Sstevel@tonic-gate * assume the terminator is missing, so put 883*7c478bd9Sstevel@tonic-gate * this character back 884*7c478bd9Sstevel@tonic-gate */ 885*7c478bd9Sstevel@tonic-gate unput(c); 886*7c478bd9Sstevel@tonic-gate yytext[--yyleng] = '\0'; 887*7c478bd9Sstevel@tonic-gate /* FALLTHROUGH */ 888*7c478bd9Sstevel@tonic-gate 889*7c478bd9Sstevel@tonic-gate case LEXEOF: /* end of file */ 890*7c478bd9Sstevel@tonic-gate return; 891*7c478bd9Sstevel@tonic-gate 892*7c478bd9Sstevel@tonic-gate default: 893*7c478bd9Sstevel@tonic-gate /* change a control character to a blank */ 894*7c478bd9Sstevel@tonic-gate if (!isprint(c)) { 895*7c478bd9Sstevel@tonic-gate yytext[yyleng - 1] = ' '; 896*7c478bd9Sstevel@tonic-gate } 897*7c478bd9Sstevel@tonic-gate } 898*7c478bd9Sstevel@tonic-gate /* if this token will overflow the line buffer */ 899*7c478bd9Sstevel@tonic-gate /* note: '\\' may cause yyleng to be > STMTMAX */ 900*7c478bd9Sstevel@tonic-gate if (yyleng >= STMTMAX) { 901*7c478bd9Sstevel@tonic-gate 902*7c478bd9Sstevel@tonic-gate /* truncate the token */ 903*7c478bd9Sstevel@tonic-gate while ((c = noncommentinput()) != LEXEOF) { 904*7c478bd9Sstevel@tonic-gate if (c == terminator) { 905*7c478bd9Sstevel@tonic-gate unput(c); 906*7c478bd9Sstevel@tonic-gate break; 907*7c478bd9Sstevel@tonic-gate } else if (c == '\n') { 908*7c478bd9Sstevel@tonic-gate ++yylineno; 909*7c478bd9Sstevel@tonic-gate } 910*7c478bd9Sstevel@tonic-gate } 911*7c478bd9Sstevel@tonic-gate } 912*7c478bd9Sstevel@tonic-gate } 913*7c478bd9Sstevel@tonic-gate yytext[yyleng] = '\0'; 914*7c478bd9Sstevel@tonic-gate } 915*7c478bd9Sstevel@tonic-gate 916*7c478bd9Sstevel@tonic-gate /* 917*7c478bd9Sstevel@tonic-gate * Returns true if the beginning of str matches ident, and the next character 918*7c478bd9Sstevel@tonic-gate * is not alphanumeric and not an underscore. 919*7c478bd9Sstevel@tonic-gate */ 920*7c478bd9Sstevel@tonic-gate int 921*7c478bd9Sstevel@tonic-gate identcmp(const char *str, const char *ident) 922*7c478bd9Sstevel@tonic-gate { 923*7c478bd9Sstevel@tonic-gate int n = strlen(ident); 924*7c478bd9Sstevel@tonic-gate 925*7c478bd9Sstevel@tonic-gate return (strncmp(str, ident, n) == 0 && !isalnum(str[n]) && 926*7c478bd9Sstevel@tonic-gate str[n] != '_'); 927*7c478bd9Sstevel@tonic-gate } 928*7c478bd9Sstevel@tonic-gate 929*7c478bd9Sstevel@tonic-gate /* 930*7c478bd9Sstevel@tonic-gate * Here we want to 931*7c478bd9Sstevel@tonic-gate * - Make *ENTRY*() macro invocations into function definitions 932*7c478bd9Sstevel@tonic-gate * - Make SET_SIZE() macro calls into function ends 933*7c478bd9Sstevel@tonic-gate * - Make "call sym" instructions into function calls 934*7c478bd9Sstevel@tonic-gate * - Eliminate C function definitions (since they are for lint, and we want 935*7c478bd9Sstevel@tonic-gate * only one definition for each function) 936*7c478bd9Sstevel@tonic-gate */ 937*7c478bd9Sstevel@tonic-gate int 938*7c478bd9Sstevel@tonic-gate do_assembly(int token) 939*7c478bd9Sstevel@tonic-gate { 940*7c478bd9Sstevel@tonic-gate /* Handle C keywords? */ 941*7c478bd9Sstevel@tonic-gate 942*7c478bd9Sstevel@tonic-gate switch (token) { 943*7c478bd9Sstevel@tonic-gate 944*7c478bd9Sstevel@tonic-gate case FCNDEF: 945*7c478bd9Sstevel@tonic-gate /* 946*7c478bd9Sstevel@tonic-gate * We have a symbol that looks like a C function definition or 947*7c478bd9Sstevel@tonic-gate * call. (Note: That can include assembly instructions with 948*7c478bd9Sstevel@tonic-gate * the right parentheses.) We want to convert assembly macro 949*7c478bd9Sstevel@tonic-gate * invocations to function calls, and ignore everything else. 950*7c478bd9Sstevel@tonic-gate * Since we technically can't tell the difference, we'll use 951*7c478bd9Sstevel@tonic-gate * an all-caps heuristic. 952*7c478bd9Sstevel@tonic-gate * 953*7c478bd9Sstevel@tonic-gate * ... except for SET_SIZE macros, since they will precede 954*7c478bd9Sstevel@tonic-gate * FUNCEND tokens, which will break code in find.c which 955*7c478bd9Sstevel@tonic-gate * assumes that FUNCEND tokens occur at the beginning of 956*7c478bd9Sstevel@tonic-gate * lines. 957*7c478bd9Sstevel@tonic-gate */ 958*7c478bd9Sstevel@tonic-gate if (isupper(yytext[first]) && strcmp(yytext, "SET_SIZE") != 0) 959*7c478bd9Sstevel@tonic-gate return (FCNCALL); 960*7c478bd9Sstevel@tonic-gate 961*7c478bd9Sstevel@tonic-gate /* Don't return a token. */ 962*7c478bd9Sstevel@tonic-gate return (-1); 963*7c478bd9Sstevel@tonic-gate 964*7c478bd9Sstevel@tonic-gate case GLOBALDEF: 965*7c478bd9Sstevel@tonic-gate case IDENT: 966*7c478bd9Sstevel@tonic-gate /* Macro arguments come down as global variable definitions. */ 967*7c478bd9Sstevel@tonic-gate 968*7c478bd9Sstevel@tonic-gate if (identcmp(yytext, "ENTRY") || 969*7c478bd9Sstevel@tonic-gate identcmp(yytext, "ENTRY2") || 970*7c478bd9Sstevel@tonic-gate identcmp(yytext, "ENTRY_NP") || 971*7c478bd9Sstevel@tonic-gate identcmp(yytext, "ENTRY_NP2") || 972*7c478bd9Sstevel@tonic-gate identcmp(yytext, "RTENTRY") || 973*7c478bd9Sstevel@tonic-gate identcmp(yytext, "ALTENTRY")) { 974*7c478bd9Sstevel@tonic-gate /* 975*7c478bd9Sstevel@tonic-gate * Identifiers on lines beginning with *ENTRY* macros 976*7c478bd9Sstevel@tonic-gate * are actually function definitions. 977*7c478bd9Sstevel@tonic-gate */ 978*7c478bd9Sstevel@tonic-gate return (FCNDEF); 979*7c478bd9Sstevel@tonic-gate } 980*7c478bd9Sstevel@tonic-gate 981*7c478bd9Sstevel@tonic-gate if (identcmp(yytext, "SET_SIZE")) { 982*7c478bd9Sstevel@tonic-gate /* 983*7c478bd9Sstevel@tonic-gate * Identifiers on lines beginning with SET_SIZE are 984*7c478bd9Sstevel@tonic-gate * actually function ends. 985*7c478bd9Sstevel@tonic-gate */ 986*7c478bd9Sstevel@tonic-gate return (FCNEND); 987*7c478bd9Sstevel@tonic-gate } 988*7c478bd9Sstevel@tonic-gate 989*7c478bd9Sstevel@tonic-gate if (first != 0 && identcmp(yytext, "call")) { 990*7c478bd9Sstevel@tonic-gate /* 991*7c478bd9Sstevel@tonic-gate * Make this a function call. We exclude first == 0, 992*7c478bd9Sstevel@tonic-gate * because that happens when we're looking at "call" 993*7c478bd9Sstevel@tonic-gate * itself. (Then we'd get function calls to "call" 994*7c478bd9Sstevel@tonic-gate * everywhere.) 995*7c478bd9Sstevel@tonic-gate */ 996*7c478bd9Sstevel@tonic-gate return (FCNCALL); 997*7c478bd9Sstevel@tonic-gate } 998*7c478bd9Sstevel@tonic-gate 999*7c478bd9Sstevel@tonic-gate default: 1000*7c478bd9Sstevel@tonic-gate /* Default to normal behavior. */ 1001*7c478bd9Sstevel@tonic-gate return (token); 1002*7c478bd9Sstevel@tonic-gate } 1003*7c478bd9Sstevel@tonic-gate } 1004