5 /* Copyright (C) 1991-2014 Free Software Foundation, Inc.
6 Written by Steve Chamberlain of Cygnus Support.
8 This file is part of the GNU Binutils.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23 MA 02110-1301, USA. */
26 #include "safe-ctype.h"
36 #include "libiberty.h"
38 /* The type of top-level parser input.
39 yylex and yyparse (indirectly) both check this. */
40 input_type parser_input;
42 /* Line number in the current input file.
43 (FIXME Actually, it doesn't appear to get reset for each file?) */
44 unsigned int lineno = 1;
46 /* The string we are currently lexing, or NULL if we are reading a
48 const char *lex_string = NULL;
50 /* Support for flex reading from more than one input file (stream).
51 `include_stack' is flex's input state for each open file;
52 `file_name_stack' is the file names. `lineno_stack' is the current
55 If `include_stack_ptr' is 0, we haven't started reading anything yet.
56 Otherwise, stack elements 0 through `include_stack_ptr - 1' are valid. */
59 #define YY_INPUT(buf,result,max_size) result = yy_input (buf, max_size)
65 #define MAX_INCLUDE_DEPTH 10
66 static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
67 static const char *file_name_stack[MAX_INCLUDE_DEPTH];
68 static unsigned int lineno_stack[MAX_INCLUDE_DEPTH];
69 static unsigned int sysrooted_stack[MAX_INCLUDE_DEPTH];
70 static unsigned int include_stack_ptr = 0;
71 static int vers_node_nesting = 0;
73 static int yy_input (char *, int);
74 static void comment (void);
75 static void lex_warn_invalid (char *where, char *what);
78 EXPRESSION definitely in an expression
79 SCRIPT definitely in a script
80 BOTH either EXPRESSION or SCRIPT
81 DEFSYMEXP in an argument to -defsym
83 VERS_START starting a Sun style mapfile
84 VERS_SCRIPT a Sun style mapfile
85 VERS_NODE a node within a Sun style mapfile
87 #define RTOKEN(x) { yylval.token = x; return x; }
89 /* Some versions of flex want this. */
91 int yywrap (void) { return 1; }
98 CMDFILENAMECHAR [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~]
99 CMDFILENAMECHAR1 [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~]
100 FILENAMECHAR1 [_a-zA-Z\/\.\\\$\_\~]
101 SYMBOLCHARN [_a-zA-Z\/\.\\\$\_\~0-9]
102 FILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~]
103 WILDCHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~\?\*\^\!]
106 NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~]
108 V_TAG [.$_a-zA-Z][._a-zA-Z0-9]*
109 V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
121 if (parser_input != input_selected)
123 /* The first token of the input determines the initial parser state. */
124 input_type t = parser_input;
125 parser_input = input_selected;
128 case input_script: return INPUT_SCRIPT; break;
129 case input_mri_script: return INPUT_MRI_SCRIPT; break;
130 case input_version_script: return INPUT_VERSION_SCRIPT; break;
131 case input_dynamic_list: return INPUT_DYNAMIC_LIST; break;
132 case input_defsym: return INPUT_DEFSYM; break;
137 <BOTH,SCRIPT,EXPRESSION,VERS_START,VERS_NODE,VERS_SCRIPT>"/*" { comment (); }
140 <DEFSYMEXP>"-" { RTOKEN('-');}
141 <DEFSYMEXP>"+" { RTOKEN('+');}
142 <DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}* { yylval.name = xstrdup (yytext); return NAME; }
143 <DEFSYMEXP>"=" { RTOKEN('='); }
145 <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
146 yylval.integer = bfd_scan_vma (yytext + 1, 0, 16);
147 yylval.bigint.str = NULL;
151 <MRI,EXPRESSION>([0-9A-Fa-f])+(H|h|X|x|B|b|O|o|D|d) {
153 switch (yytext[yyleng - 1]) {
171 yylval.integer = bfd_scan_vma (yytext, 0,
173 yylval.bigint.str = NULL;
176 <SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>((("$"|0[xX])([0-9A-Fa-f])+)|(([0-9])+))(M|K|m|k)? {
185 yylval.integer = bfd_scan_vma (s, 0, ibase);
186 yylval.bigint.str = NULL;
187 if (yytext[yyleng - 1] == 'M'
188 || yytext[yyleng - 1] == 'm')
190 yylval.integer *= 1024 * 1024;
192 else if (yytext[yyleng - 1] == 'K'
193 || yytext[yyleng - 1]=='k')
195 yylval.integer *= 1024;
197 else if (yytext[0] == '0'
199 || yytext[1] == 'X'))
201 yylval.bigint.str = xstrdup (yytext + 2);
205 <BOTH,SCRIPT,EXPRESSION,MRI>"]" { RTOKEN(']');}
206 <BOTH,SCRIPT,EXPRESSION,MRI>"[" { RTOKEN('[');}
207 <BOTH,SCRIPT,EXPRESSION,MRI>"<<=" { RTOKEN(LSHIFTEQ);}
208 <BOTH,SCRIPT,EXPRESSION,MRI>">>=" { RTOKEN(RSHIFTEQ);}
209 <BOTH,SCRIPT,EXPRESSION,MRI>"||" { RTOKEN(OROR);}
210 <BOTH,SCRIPT,EXPRESSION,MRI>"==" { RTOKEN(EQ);}
211 <BOTH,SCRIPT,EXPRESSION,MRI>"!=" { RTOKEN(NE);}
212 <BOTH,SCRIPT,EXPRESSION,MRI>">=" { RTOKEN(GE);}
213 <BOTH,SCRIPT,EXPRESSION,MRI>"<=" { RTOKEN(LE);}
214 <BOTH,SCRIPT,EXPRESSION,MRI>"<<" { RTOKEN(LSHIFT);}
215 <BOTH,SCRIPT,EXPRESSION,MRI>">>" { RTOKEN(RSHIFT);}
216 <BOTH,SCRIPT,EXPRESSION,MRI>"+=" { RTOKEN(PLUSEQ);}
217 <BOTH,SCRIPT,EXPRESSION,MRI>"-=" { RTOKEN(MINUSEQ);}
218 <BOTH,SCRIPT,EXPRESSION,MRI>"*=" { RTOKEN(MULTEQ);}
219 <BOTH,SCRIPT,EXPRESSION,MRI>"/=" { RTOKEN(DIVEQ);}
220 <BOTH,SCRIPT,EXPRESSION,MRI>"&=" { RTOKEN(ANDEQ);}
221 <BOTH,SCRIPT,EXPRESSION,MRI>"|=" { RTOKEN(OREQ);}
222 <BOTH,SCRIPT,EXPRESSION,MRI>"&&" { RTOKEN(ANDAND);}
223 <BOTH,SCRIPT,EXPRESSION,MRI>">" { RTOKEN('>');}
224 <BOTH,SCRIPT,EXPRESSION,MRI>"," { RTOKEN(',');}
225 <BOTH,SCRIPT,EXPRESSION,MRI>"&" { RTOKEN('&');}
226 <BOTH,SCRIPT,EXPRESSION,MRI>"|" { RTOKEN('|');}
227 <BOTH,SCRIPT,EXPRESSION,MRI>"~" { RTOKEN('~');}
228 <BOTH,SCRIPT,EXPRESSION,MRI>"!" { RTOKEN('!');}
229 <BOTH,SCRIPT,EXPRESSION,MRI>"?" { RTOKEN('?');}
230 <BOTH,SCRIPT,EXPRESSION,MRI>"*" { RTOKEN('*');}
231 <BOTH,SCRIPT,EXPRESSION,MRI>"+" { RTOKEN('+');}
232 <BOTH,SCRIPT,EXPRESSION,MRI>"-" { RTOKEN('-');}
233 <BOTH,SCRIPT,EXPRESSION,MRI>"/" { RTOKEN('/');}
234 <BOTH,SCRIPT,EXPRESSION,MRI>"%" { RTOKEN('%');}
235 <BOTH,SCRIPT,EXPRESSION,MRI>"<" { RTOKEN('<');}
236 <BOTH,SCRIPT,EXPRESSION,MRI>"=" { RTOKEN('=');}
237 <BOTH,SCRIPT,EXPRESSION,MRI>"}" { RTOKEN('}') ; }
238 <BOTH,SCRIPT,EXPRESSION,MRI>"{" { RTOKEN('{'); }
239 <BOTH,SCRIPT,EXPRESSION,MRI>")" { RTOKEN(')');}
240 <BOTH,SCRIPT,EXPRESSION,MRI>"(" { RTOKEN('(');}
241 <BOTH,SCRIPT,EXPRESSION,MRI>":" { RTOKEN(':'); }
242 <BOTH,SCRIPT,EXPRESSION,MRI>";" { RTOKEN(';');}
243 <BOTH,SCRIPT>"MEMORY" { RTOKEN(MEMORY);}
244 <BOTH,SCRIPT>"REGION_ALIAS" { RTOKEN(REGION_ALIAS);}
245 <BOTH,SCRIPT>"LD_FEATURE" { RTOKEN(LD_FEATURE);}
246 <BOTH,SCRIPT,EXPRESSION>"ORIGIN" { RTOKEN(ORIGIN);}
247 <BOTH,SCRIPT>"VERSION" { RTOKEN(VERSIONK);}
248 <EXPRESSION,BOTH,SCRIPT>"BLOCK" { RTOKEN(BLOCK);}
249 <EXPRESSION,BOTH,SCRIPT>"BIND" { RTOKEN(BIND);}
250 <BOTH,SCRIPT,EXPRESSION>"LENGTH" { RTOKEN(LENGTH);}
251 <EXPRESSION,BOTH,SCRIPT>"ALIGN" { RTOKEN(ALIGN_K);}
252 <EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_ALIGN" { RTOKEN(DATA_SEGMENT_ALIGN);}
253 <EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_RELRO_END" { RTOKEN(DATA_SEGMENT_RELRO_END);}
254 <EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_END" { RTOKEN(DATA_SEGMENT_END);}
255 <EXPRESSION,BOTH,SCRIPT>"ADDR" { RTOKEN(ADDR);}
256 <EXPRESSION,BOTH,SCRIPT>"LOADADDR" { RTOKEN(LOADADDR);}
257 <EXPRESSION,BOTH,SCRIPT>"ALIGNOF" { RTOKEN(ALIGNOF); }
258 <EXPRESSION,BOTH>"MAX" { RTOKEN(MAX_K); }
259 <EXPRESSION,BOTH>"MIN" { RTOKEN(MIN_K); }
260 <EXPRESSION,BOTH>"LOG2CEIL" { RTOKEN(LOG2CEIL); }
261 <EXPRESSION,BOTH,SCRIPT>"ASSERT" { RTOKEN(ASSERT_K); }
262 <BOTH,SCRIPT>"ENTRY" { RTOKEN(ENTRY);}
263 <BOTH,SCRIPT,MRI>"EXTERN" { RTOKEN(EXTERN);}
264 <EXPRESSION,BOTH,SCRIPT>"NEXT" { RTOKEN(NEXT);}
265 <EXPRESSION,BOTH,SCRIPT>"sizeof_headers" { RTOKEN(SIZEOF_HEADERS);}
266 <EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS" { RTOKEN(SIZEOF_HEADERS);}
267 <EXPRESSION,BOTH,SCRIPT>"SEGMENT_START" { RTOKEN(SEGMENT_START);}
268 <BOTH,SCRIPT>"MAP" { RTOKEN(MAP);}
269 <EXPRESSION,BOTH,SCRIPT>"SIZEOF" { RTOKEN(SIZEOF);}
270 <BOTH,SCRIPT>"TARGET" { RTOKEN(TARGET_K);}
271 <BOTH,SCRIPT>"SEARCH_DIR" { RTOKEN(SEARCH_DIR);}
272 <BOTH,SCRIPT>"OUTPUT" { RTOKEN(OUTPUT);}
273 <BOTH,SCRIPT>"INPUT" { RTOKEN(INPUT);}
274 <EXPRESSION,BOTH,SCRIPT>"GROUP" { RTOKEN(GROUP);}
275 <EXPRESSION,BOTH,SCRIPT>"AS_NEEDED" { RTOKEN(AS_NEEDED);}
276 <EXPRESSION,BOTH,SCRIPT>"DEFINED" { RTOKEN(DEFINED);}
277 <BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);}
278 <BOTH,SCRIPT>"CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);}
279 <BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);}
280 <BOTH,SCRIPT>"INHIBIT_COMMON_ALLOCATION" { RTOKEN(INHIBIT_COMMON_ALLOCATION);}
281 <BOTH,SCRIPT>"SECTIONS" { RTOKEN(SECTIONS);}
282 <BOTH,SCRIPT>"INSERT" { RTOKEN(INSERT_K);}
283 <BOTH,SCRIPT>"AFTER" { RTOKEN(AFTER);}
284 <BOTH,SCRIPT>"BEFORE" { RTOKEN(BEFORE);}
285 <BOTH,SCRIPT>"FILL" { RTOKEN(FILL);}
286 <BOTH,SCRIPT>"STARTUP" { RTOKEN(STARTUP);}
287 <BOTH,SCRIPT>"OUTPUT_FORMAT" { RTOKEN(OUTPUT_FORMAT);}
288 <BOTH,SCRIPT>"OUTPUT_ARCH" { RTOKEN( OUTPUT_ARCH);}
289 <BOTH,SCRIPT>"HLL" { RTOKEN(HLL);}
290 <BOTH,SCRIPT>"SYSLIB" { RTOKEN(SYSLIB);}
291 <BOTH,SCRIPT>"FLOAT" { RTOKEN(FLOAT);}
292 <BOTH,SCRIPT>"QUAD" { RTOKEN( QUAD);}
293 <BOTH,SCRIPT>"SQUAD" { RTOKEN( SQUAD);}
294 <BOTH,SCRIPT>"LONG" { RTOKEN( LONG);}
295 <BOTH,SCRIPT>"SHORT" { RTOKEN( SHORT);}
296 <BOTH,SCRIPT>"BYTE" { RTOKEN( BYTE);}
297 <BOTH,SCRIPT>"NOFLOAT" { RTOKEN(NOFLOAT);}
298 <EXPRESSION,BOTH,SCRIPT>"NOCROSSREFS" { RTOKEN(NOCROSSREFS);}
299 <BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY); }
300 <BOTH,SCRIPT>"SORT_BY_NAME" { RTOKEN(SORT_BY_NAME); }
301 <BOTH,SCRIPT>"SORT_BY_ALIGNMENT" { RTOKEN(SORT_BY_ALIGNMENT); }
302 <BOTH,SCRIPT>"SORT" { RTOKEN(SORT_BY_NAME); }
303 <BOTH,SCRIPT>"SORT_BY_INIT_PRIORITY" { RTOKEN(SORT_BY_INIT_PRIORITY); }
304 <BOTH,SCRIPT>"SORT_NONE" { RTOKEN(SORT_NONE); }
305 <EXPRESSION,BOTH,SCRIPT>"NOLOAD" { RTOKEN(NOLOAD);}
306 <EXPRESSION,BOTH,SCRIPT>"DSECT" { RTOKEN(DSECT);}
307 <EXPRESSION,BOTH,SCRIPT>"COPY" { RTOKEN(COPY);}
308 <EXPRESSION,BOTH,SCRIPT>"INFO" { RTOKEN(INFO);}
309 <EXPRESSION,BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY);}
310 <EXPRESSION,BOTH,SCRIPT>"ONLY_IF_RO" { RTOKEN(ONLY_IF_RO); }
311 <EXPRESSION,BOTH,SCRIPT>"ONLY_IF_RW" { RTOKEN(ONLY_IF_RW); }
312 <EXPRESSION,BOTH,SCRIPT>"SPECIAL" { RTOKEN(SPECIAL); }
313 <BOTH,SCRIPT>"o" { RTOKEN(ORIGIN);}
314 <BOTH,SCRIPT>"org" { RTOKEN(ORIGIN);}
315 <BOTH,SCRIPT>"l" { RTOKEN( LENGTH);}
316 <BOTH,SCRIPT>"len" { RTOKEN( LENGTH);}
317 <EXPRESSION,BOTH,SCRIPT>"INPUT_SECTION_FLAGS" { RTOKEN(INPUT_SECTION_FLAGS); }
318 <EXPRESSION,BOTH,SCRIPT>"INCLUDE" { RTOKEN(INCLUDE);}
319 <BOTH,SCRIPT>"PHDRS" { RTOKEN (PHDRS); }
320 <EXPRESSION,BOTH,SCRIPT>"AT" { RTOKEN(AT);}
321 <EXPRESSION,BOTH,SCRIPT>"ALIGN_WITH_INPUT" { RTOKEN(ALIGN_WITH_INPUT);}
322 <EXPRESSION,BOTH,SCRIPT>"SUBALIGN" { RTOKEN(SUBALIGN);}
323 <EXPRESSION,BOTH,SCRIPT>"HIDDEN" { RTOKEN(HIDDEN); }
324 <EXPRESSION,BOTH,SCRIPT>"PROVIDE" { RTOKEN(PROVIDE); }
325 <EXPRESSION,BOTH,SCRIPT>"PROVIDE_HIDDEN" { RTOKEN(PROVIDE_HIDDEN); }
326 <EXPRESSION,BOTH,SCRIPT>"KEEP" { RTOKEN(KEEP); }
327 <EXPRESSION,BOTH,SCRIPT>"EXCLUDE_FILE" { RTOKEN(EXCLUDE_FILE); }
328 <EXPRESSION,BOTH,SCRIPT>"CONSTANT" { RTOKEN(CONSTANT);}
329 <MRI>"#".*\n? { ++ lineno; }
330 <MRI>"\n" { ++ lineno; RTOKEN(NEWLINE); }
331 <MRI>"*".* { /* Mri comment line */ }
332 <MRI>";".* { /* Mri comment line */ }
333 <MRI>"END" { RTOKEN(ENDWORD); }
334 <MRI>"ALIGNMOD" { RTOKEN(ALIGNMOD);}
335 <MRI>"ALIGN" { RTOKEN(ALIGN_K);}
336 <MRI>"CHIP" { RTOKEN(CHIP); }
337 <MRI>"BASE" { RTOKEN(BASE); }
338 <MRI>"ALIAS" { RTOKEN(ALIAS); }
339 <MRI>"TRUNCATE" { RTOKEN(TRUNCATE); }
340 <MRI>"LOAD" { RTOKEN(LOAD); }
341 <MRI>"PUBLIC" { RTOKEN(PUBLIC); }
342 <MRI>"ORDER" { RTOKEN(ORDER); }
343 <MRI>"NAME" { RTOKEN(NAMEWORD); }
344 <MRI>"FORMAT" { RTOKEN(FORMAT); }
345 <MRI>"CASE" { RTOKEN(CASE); }
346 <MRI>"START" { RTOKEN(START); }
347 <MRI>"LIST".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
348 <MRI>"SECT" { RTOKEN(SECT); }
349 <EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE" { RTOKEN(ABSOLUTE); }
350 <MRI>"end" { RTOKEN(ENDWORD); }
351 <MRI>"alignmod" { RTOKEN(ALIGNMOD);}
352 <MRI>"align" { RTOKEN(ALIGN_K);}
353 <MRI>"chip" { RTOKEN(CHIP); }
354 <MRI>"base" { RTOKEN(BASE); }
355 <MRI>"alias" { RTOKEN(ALIAS); }
356 <MRI>"truncate" { RTOKEN(TRUNCATE); }
357 <MRI>"load" { RTOKEN(LOAD); }
358 <MRI>"public" { RTOKEN(PUBLIC); }
359 <MRI>"order" { RTOKEN(ORDER); }
360 <MRI>"name" { RTOKEN(NAMEWORD); }
361 <MRI>"format" { RTOKEN(FORMAT); }
362 <MRI>"case" { RTOKEN(CASE); }
363 <MRI>"extern" { RTOKEN(EXTERN); }
364 <MRI>"start" { RTOKEN(START); }
365 <MRI>"list".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
366 <MRI>"sect" { RTOKEN(SECT); }
367 <EXPRESSION,BOTH,SCRIPT,MRI>"absolute" { RTOKEN(ABSOLUTE); }
369 <MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* {
370 /* Filename without commas, needed to parse mri stuff */
371 yylval.name = xstrdup (yytext);
376 <BOTH>{FILENAMECHAR1}{FILENAMECHAR}* {
377 yylval.name = xstrdup (yytext);
380 <BOTH>"-l"{FILENAMECHAR}+ {
381 yylval.name = xstrdup (yytext + 2);
384 <EXPRESSION>{FILENAMECHAR1}{NOCFILENAMECHAR}* {
385 yylval.name = xstrdup (yytext);
388 <EXPRESSION>"-l"{NOCFILENAMECHAR}+ {
389 yylval.name = xstrdup (yytext + 2);
392 <SCRIPT>{WILDCHAR}* {
393 /* Annoyingly, this pattern can match comments, and we have
394 longest match issues to consider. So if the first two
395 characters are a comment opening, put the input back and
397 if (yytext[0] == '/' && yytext[1] == '*')
404 yylval.name = xstrdup (yytext);
409 <EXPRESSION,BOTH,SCRIPT,VERS_NODE>"\""[^\"]*"\"" {
410 /* No matter the state, quotes
411 give what's inside */
412 yylval.name = xstrdup (yytext + 1);
413 yylval.name[yyleng - 2] = 0;
416 <BOTH,SCRIPT,EXPRESSION>"\n" { lineno++;}
417 <MRI,BOTH,SCRIPT,EXPRESSION>[ \t\r]+ { }
419 <VERS_NODE,VERS_SCRIPT>[:,;] { return *yytext; }
421 <VERS_NODE>global { RTOKEN(GLOBAL); }
423 <VERS_NODE>local { RTOKEN(LOCAL); }
425 <VERS_NODE>extern { RTOKEN(EXTERN); }
427 <VERS_NODE>{V_IDENTIFIER} { yylval.name = xstrdup (yytext);
428 return VERS_IDENTIFIER; }
430 <VERS_SCRIPT>{V_TAG} { yylval.name = xstrdup (yytext);
433 <VERS_START>"{" { BEGIN(VERS_SCRIPT); return *yytext; }
435 <VERS_SCRIPT>"{" { BEGIN(VERS_NODE);
436 vers_node_nesting = 0;
439 <VERS_SCRIPT>"}" { return *yytext; }
440 <VERS_NODE>"{" { vers_node_nesting++; return *yytext; }
441 <VERS_NODE>"}" { if (--vers_node_nesting < 0)
446 <VERS_START,VERS_NODE,VERS_SCRIPT>[\n] { lineno++; }
448 <VERS_START,VERS_NODE,VERS_SCRIPT>#.* { /* Eat up comments */ }
450 <VERS_START,VERS_NODE,VERS_SCRIPT>[ \t\r]+ { /* Eat up whitespace */ }
454 if (include_stack_ptr == 0)
457 yy_switch_to_buffer (include_stack[include_stack_ptr]);
459 lineno = lineno_stack[include_stack_ptr];
460 input_flags.sysrooted = sysrooted_stack[include_stack_ptr];
465 <SCRIPT,MRI,VERS_START,VERS_SCRIPT,VERS_NODE>. lex_warn_invalid (" in script", yytext);
466 <EXPRESSION,DEFSYMEXP,BOTH>. lex_warn_invalid (" in expression", yytext);
471 /* Switch flex to reading script file NAME, open on FILE,
472 saving the current input info on the include stack. */
475 lex_push_file (FILE *file, const char *name, unsigned int sysrooted)
477 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
479 einfo ("%F:includes nested too deeply\n");
481 file_name_stack[include_stack_ptr] = name;
482 lineno_stack[include_stack_ptr] = lineno;
483 sysrooted_stack[include_stack_ptr] = input_flags.sysrooted;
484 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
488 input_flags.sysrooted = sysrooted;
490 yy_switch_to_buffer (yy_create_buffer (yyin, YY_BUF_SIZE));
493 /* Return a newly created flex input buffer containing STRING,
494 which is SIZE bytes long. */
496 static YY_BUFFER_STATE
497 yy_create_string_buffer (const char *string, size_t size)
501 /* Calls to m-alloc get turned by sed into xm-alloc. */
502 b = malloc (sizeof (struct yy_buffer_state));
503 b->yy_input_file = 0;
504 b->yy_buf_size = size;
506 /* yy_ch_buf has to be 2 characters longer than the size given because
507 we need to put in 2 end-of-buffer characters. */
508 b->yy_ch_buf = malloc ((unsigned) (b->yy_buf_size + 3));
510 b->yy_ch_buf[0] = '\n';
511 strcpy (b->yy_ch_buf+1, string);
512 b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR;
513 b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR;
514 b->yy_n_chars = size+1;
515 b->yy_buf_pos = &b->yy_ch_buf[1];
517 b->yy_is_our_buffer = 1;
518 b->yy_is_interactive = 0;
520 b->yy_fill_buffer = 0;
522 /* flex 2.4.7 changed the interface. FIXME: We should not be using
523 a flex internal interface in the first place! */
525 b->yy_buffer_status = YY_BUFFER_NEW;
527 b->yy_eof_status = EOF_NOT_SEEN;
533 /* Switch flex to reading from STRING, saving the current input info
534 on the include stack. */
537 lex_redirect (const char *string, const char *fake_filename, unsigned int count)
542 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
544 einfo("%F: macros nested too deeply\n");
546 file_name_stack[include_stack_ptr] = fake_filename;
547 lineno_stack[include_stack_ptr] = lineno;
548 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
551 tmp = yy_create_string_buffer (string, strlen (string));
552 yy_switch_to_buffer (tmp);
555 /* Functions to switch to a different flex start condition,
556 saving the current start condition on `state_stack'. */
558 static int state_stack[MAX_INCLUDE_DEPTH * 2];
559 static int *state_stack_p = state_stack;
564 *(state_stack_p)++ = yy_start;
569 ldlex_mri_script (void)
571 *(state_stack_p)++ = yy_start;
576 ldlex_version_script (void)
578 *(state_stack_p)++ = yy_start;
583 ldlex_version_file (void)
585 *(state_stack_p)++ = yy_start;
592 *(state_stack_p)++ = yy_start;
597 ldlex_expression (void)
599 *(state_stack_p)++ = yy_start;
606 *(state_stack_p)++ = yy_start;
611 ldlex_popstate (void)
613 yy_start = *(--state_stack_p);
616 /* Return the current file name, or the previous file if no file is
620 ldlex_filename (void)
622 return file_name_stack[include_stack_ptr - (include_stack_ptr != 0)];
626 /* Place up to MAX_SIZE characters in BUF and return
627 either the number of characters read, or 0 to indicate EOF. */
630 yy_input (char *buf, int max_size)
633 if (YY_CURRENT_BUFFER->yy_input_file)
637 result = fread (buf, 1, max_size, yyin);
638 if (result < max_size && ferror (yyin))
639 einfo ("%F%P: read in flex scanner failed\n");
645 /* Eat the rest of a C-style comment. */
655 while (c != '*' && c != EOF)
668 break; /* found the end */
676 einfo( "%F%P: EOF in comment\n");
682 /* Warn the user about a garbage character WHAT in the input
686 lex_warn_invalid (char *where, char *what)
690 /* If we have found an input file whose format we do not recognize,
691 and we are therefore treating it as a linker script, and we find
692 an invalid character, then most likely this is a real object file
693 of some different format. Treat it as such. */
694 if (ldfile_assumed_script)
696 bfd_set_error (bfd_error_file_not_recognized);
697 einfo ("%F%s: file not recognized: %E\n", ldlex_filename ());
700 if (! ISPRINT (*what))
702 sprintf (buf, "\\%03o", *(unsigned char *) what);
706 einfo ("%P:%S: ignoring invalid character `%s'%s\n", NULL, what, where);