* ldlex.l: Use #include "" instead of <> for local header files.
[deliverable/binutils-gdb.git] / ld / ldlex.l
1 %{
2
3 /* Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 2000, 2001, 2002 Free Software Foundation, Inc.
5
6 This file is part of GLD, the Gnu Linker.
7
8 GLD is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GLD is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GLD; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA. */
22
23 /*
24 This was written by steve chamberlain
25 sac@cygnus.com
26 */
27
28
29 #include "ansidecl.h"
30 #include <stdio.h>
31
32 #ifdef MPW
33 /* Prevent enum redefinition problems. */
34 #define TRUE_FALSE_ALREADY_DEFINED
35 #endif /* MPW */
36
37 #include "bfd.h"
38 #include "sysdep.h"
39 #include "safe-ctype.h"
40 #include "ld.h"
41 #include "ldmisc.h"
42 #include "ldexp.h"
43 #include "ldlang.h"
44 #include "ldgram.h"
45 #include "ldfile.h"
46 #include "ldlex.h"
47 #include "ldmain.h"
48 #include "libiberty.h"
49
50 /* The type of top-level parser input.
51 yylex and yyparse (indirectly) both check this. */
52 input_type parser_input;
53
54 /* Line number in the current input file.
55 (FIXME Actually, it doesn't appear to get reset for each file?) */
56 unsigned int lineno = 1;
57
58 /* The string we are currently lexing, or NULL if we are reading a
59 file. */
60 const char *lex_string = NULL;
61
62 /* Support for flex reading from more than one input file (stream).
63 `include_stack' is flex's input state for each open file;
64 `file_name_stack' is the file names. `lineno_stack' is the current
65 line numbers.
66
67 If `include_stack_ptr' is 0, we haven't started reading anything yet.
68 Otherwise, stack elements 0 through `include_stack_ptr - 1' are valid. */
69
70 #undef YY_INPUT
71 #define YY_INPUT(buf,result,max_size) yy_input(buf, &result, max_size)
72
73 #define MAX_INCLUDE_DEPTH 10
74 static YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
75 static const char *file_name_stack[MAX_INCLUDE_DEPTH];
76 static unsigned int lineno_stack[MAX_INCLUDE_DEPTH];
77 static unsigned int include_stack_ptr = 0;
78 static int vers_node_nesting = 0;
79
80 static YY_BUFFER_STATE yy_create_string_buffer PARAMS ((const char *string,
81 size_t size));
82 static void yy_input PARAMS ((char *, int *result, int max_size));
83
84 static void comment PARAMS ((void));
85 static void lex_warn_invalid PARAMS ((char *where, char *what));
86
87 /* STATES
88 EXPRESSION definitely in an expression
89 SCRIPT definitely in a script
90 BOTH either EXPRESSION or SCRIPT
91 DEFSYMEXP in an argument to -defsym
92 MRI in an MRI script
93 VERS_START starting a Sun style mapfile
94 VERS_SCRIPT a Sun style mapfile
95 VERS_NODE a node within a Sun style mapfile
96 */
97 #define RTOKEN(x) { yylval.token = x; return x; }
98
99 /* Some versions of flex want this. */
100 #ifndef yywrap
101 int yywrap () { return 1; }
102 #endif
103 %}
104
105 %a 4000
106 %o 5000
107
108 CMDFILENAMECHAR [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\-\~]
109 CMDFILENAMECHAR1 [_a-zA-Z0-9\/\.\\_\+\$\:\[\]\\\,\=\&\!\<\>\~]
110 FILENAMECHAR1 [_a-zA-Z\/\.\\\$\_\~]
111 SYMBOLCHARN [_a-zA-Z\/\.\\\$\_\~0-9]
112 FILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~]
113 WILDCHAR [_a-zA-Z0-9\/\.\-\_\+\=\$\:\[\]\\\,\~\?\*]
114 WHITE [ \t\n\r]+
115
116 NOCFILENAMECHAR [_a-zA-Z0-9\/\.\-\_\+\$\:\[\]\\\~]
117
118 V_TAG [.$_a-zA-Z][._a-zA-Z0-9]*
119 V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^]([*?.$_a-zA-Z0-9\[\]\-\!\^]|::)*
120
121 %s SCRIPT
122 %s EXPRESSION
123 %s BOTH
124 %s DEFSYMEXP
125 %s MRI
126 %s VERS_START
127 %s VERS_SCRIPT
128 %s VERS_NODE
129 %%
130
131 if (parser_input != input_selected)
132 {
133 /* The first token of the input determines the initial parser state. */
134 input_type t = parser_input;
135 parser_input = input_selected;
136 switch (t)
137 {
138 case input_script: return INPUT_SCRIPT; break;
139 case input_mri_script: return INPUT_MRI_SCRIPT; break;
140 case input_version_script: return INPUT_VERSION_SCRIPT; break;
141 case input_defsym: return INPUT_DEFSYM; break;
142 default: abort ();
143 }
144 }
145
146 <BOTH,SCRIPT,EXPRESSION>"/*" { comment(); }
147
148
149 <DEFSYMEXP>"-" { RTOKEN('-');}
150 <DEFSYMEXP>"+" { RTOKEN('+');}
151 <DEFSYMEXP>{FILENAMECHAR1}{SYMBOLCHARN}* { yylval.name = xstrdup(yytext); return NAME; }
152 <DEFSYMEXP>"=" { RTOKEN('='); }
153
154 <MRI,EXPRESSION>"$"([0-9A-Fa-f])+ {
155 yylval.integer = bfd_scan_vma (yytext+1, 0,16);
156 yylval.bigint.str = (char *) 0;
157 return INT;
158 }
159
160 <MRI,EXPRESSION>([0-9A-Fa-f])+(H|h|X|x|B|b|O|o|D|d) {
161 int ibase ;
162 switch (yytext[yyleng-1]) {
163 case 'X':
164 case 'x':
165 case 'H':
166 case 'h':
167 ibase = 16;
168 break;
169 case 'O':
170 case 'o':
171 ibase = 8;
172 break;
173 case 'B':
174 case 'b':
175 ibase = 2;
176 break;
177 default:
178 ibase = 10;
179 }
180 yylval.integer = bfd_scan_vma (yytext, 0,
181 ibase);
182 yylval.bigint.str = (char *) 0;
183 return INT;
184 }
185 <SCRIPT,DEFSYMEXP,MRI,BOTH,EXPRESSION>((("$"|0[xX])([0-9A-Fa-f])+)|(([0-9])+))(M|K|m|k)? {
186 char *s = yytext;
187 int ibase = 0;
188
189 if (*s == '$')
190 {
191 ++s;
192 ibase = 16;
193 }
194 yylval.integer = bfd_scan_vma (s, 0, ibase);
195 yylval.bigint.str = (char *) 0;
196 if (yytext[yyleng-1] == 'M'
197 || yytext[yyleng-1] == 'm')
198 {
199 yylval.integer *= 1024 * 1024;
200 }
201 else if (yytext[yyleng-1] == 'K'
202 || yytext[yyleng-1]=='k')
203 {
204 yylval.integer *= 1024;
205 }
206 else if (yytext[0] == '0'
207 && (yytext[1] == 'x'
208 || yytext[1] == 'X'))
209 {
210 yylval.bigint.str = xstrdup (yytext + 2);
211 }
212 return INT;
213 }
214 <BOTH,SCRIPT,EXPRESSION,MRI>"]" { RTOKEN(']');}
215 <BOTH,SCRIPT,EXPRESSION,MRI>"[" { RTOKEN('[');}
216 <BOTH,SCRIPT,EXPRESSION,MRI>"<<=" { RTOKEN(LSHIFTEQ);}
217 <BOTH,SCRIPT,EXPRESSION,MRI>">>=" { RTOKEN(RSHIFTEQ);}
218 <BOTH,SCRIPT,EXPRESSION,MRI>"||" { RTOKEN(OROR);}
219 <BOTH,SCRIPT,EXPRESSION,MRI>"==" { RTOKEN(EQ);}
220 <BOTH,SCRIPT,EXPRESSION,MRI>"!=" { RTOKEN(NE);}
221 <BOTH,SCRIPT,EXPRESSION,MRI>">=" { RTOKEN(GE);}
222 <BOTH,SCRIPT,EXPRESSION,MRI>"<=" { RTOKEN(LE);}
223 <BOTH,SCRIPT,EXPRESSION,MRI>"<<" { RTOKEN(LSHIFT);}
224 <BOTH,SCRIPT,EXPRESSION,MRI>">>" { RTOKEN(RSHIFT);}
225 <BOTH,SCRIPT,EXPRESSION,MRI>"+=" { RTOKEN(PLUSEQ);}
226 <BOTH,SCRIPT,EXPRESSION,MRI>"-=" { RTOKEN(MINUSEQ);}
227 <BOTH,SCRIPT,EXPRESSION,MRI>"*=" { RTOKEN(MULTEQ);}
228 <BOTH,SCRIPT,EXPRESSION,MRI>"/=" { RTOKEN(DIVEQ);}
229 <BOTH,SCRIPT,EXPRESSION,MRI>"&=" { RTOKEN(ANDEQ);}
230 <BOTH,SCRIPT,EXPRESSION,MRI>"|=" { RTOKEN(OREQ);}
231 <BOTH,SCRIPT,EXPRESSION,MRI>"&&" { RTOKEN(ANDAND);}
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,EXPRESSION,MRI>"%" { RTOKEN('%');}
244 <BOTH,SCRIPT,EXPRESSION,MRI>"<" { RTOKEN('<');}
245 <BOTH,SCRIPT,EXPRESSION,MRI>"=" { RTOKEN('=');}
246 <BOTH,SCRIPT,EXPRESSION,MRI>"}" { RTOKEN('}') ; }
247 <BOTH,SCRIPT,EXPRESSION,MRI>"{" { RTOKEN('{'); }
248 <BOTH,SCRIPT,EXPRESSION,MRI>")" { RTOKEN(')');}
249 <BOTH,SCRIPT,EXPRESSION,MRI>"(" { RTOKEN('(');}
250 <BOTH,SCRIPT,EXPRESSION,MRI>":" { RTOKEN(':'); }
251 <BOTH,SCRIPT,EXPRESSION,MRI>";" { RTOKEN(';');}
252 <BOTH,SCRIPT>"MEMORY" { RTOKEN(MEMORY);}
253 <BOTH,SCRIPT>"ORIGIN" { RTOKEN(ORIGIN);}
254 <BOTH,SCRIPT>"VERSION" { RTOKEN(VERSIONK);}
255 <EXPRESSION,BOTH,SCRIPT>"BLOCK" { RTOKEN(BLOCK);}
256 <EXPRESSION,BOTH,SCRIPT>"BIND" { RTOKEN(BIND);}
257 <BOTH,SCRIPT>"LENGTH" { RTOKEN(LENGTH);}
258 <EXPRESSION,BOTH,SCRIPT>"ALIGN" { RTOKEN(ALIGN_K);}
259 <EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_ALIGN" { RTOKEN(DATA_SEGMENT_ALIGN);}
260 <EXPRESSION,BOTH,SCRIPT>"DATA_SEGMENT_END" { RTOKEN(DATA_SEGMENT_END);}
261 <EXPRESSION,BOTH,SCRIPT>"ADDR" { RTOKEN(ADDR);}
262 <EXPRESSION,BOTH,SCRIPT>"LOADADDR" { RTOKEN(LOADADDR);}
263 <EXPRESSION,BOTH>"MAX" { RTOKEN(MAX_K); }
264 <EXPRESSION,BOTH>"MIN" { RTOKEN(MIN_K); }
265 <EXPRESSION,BOTH>"ASSERT" { RTOKEN(ASSERT_K); }
266 <BOTH,SCRIPT>"ENTRY" { RTOKEN(ENTRY);}
267 <BOTH,SCRIPT,MRI>"EXTERN" { RTOKEN(EXTERN);}
268 <EXPRESSION,BOTH,SCRIPT>"NEXT" { RTOKEN(NEXT);}
269 <EXPRESSION,BOTH,SCRIPT>"sizeof_headers" { RTOKEN(SIZEOF_HEADERS);}
270 <EXPRESSION,BOTH,SCRIPT>"SIZEOF_HEADERS" { RTOKEN(SIZEOF_HEADERS);}
271 <BOTH,SCRIPT>"MAP" { RTOKEN(MAP);}
272 <EXPRESSION,BOTH,SCRIPT>"SIZEOF" { RTOKEN(SIZEOF);}
273 <BOTH,SCRIPT>"TARGET" { RTOKEN(TARGET_K);}
274 <BOTH,SCRIPT>"SEARCH_DIR" { RTOKEN(SEARCH_DIR);}
275 <BOTH,SCRIPT>"OUTPUT" { RTOKEN(OUTPUT);}
276 <BOTH,SCRIPT>"INPUT" { RTOKEN(INPUT);}
277 <EXPRESSION,BOTH,SCRIPT>"GROUP" { RTOKEN(GROUP);}
278 <EXPRESSION,BOTH,SCRIPT>"DEFINED" { RTOKEN(DEFINED);}
279 <BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);}
280 <BOTH,SCRIPT>"CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);}
281 <BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);}
282 <BOTH,SCRIPT>"INHIBIT_COMMON_ALLOCATION" { RTOKEN(INHIBIT_COMMON_ALLOCATION);}
283 <BOTH,SCRIPT>"SECTIONS" { RTOKEN(SECTIONS);}
284 <BOTH,SCRIPT>"FILL" { RTOKEN(FILL);}
285 <BOTH,SCRIPT>"STARTUP" { RTOKEN(STARTUP);}
286 <BOTH,SCRIPT>"OUTPUT_FORMAT" { RTOKEN(OUTPUT_FORMAT);}
287 <BOTH,SCRIPT>"OUTPUT_ARCH" { RTOKEN( OUTPUT_ARCH);}
288 <BOTH,SCRIPT>"HLL" { RTOKEN(HLL);}
289 <BOTH,SCRIPT>"SYSLIB" { RTOKEN(SYSLIB);}
290 <BOTH,SCRIPT>"FLOAT" { RTOKEN(FLOAT);}
291 <BOTH,SCRIPT>"QUAD" { RTOKEN( QUAD);}
292 <BOTH,SCRIPT>"SQUAD" { RTOKEN( SQUAD);}
293 <BOTH,SCRIPT>"LONG" { RTOKEN( LONG);}
294 <BOTH,SCRIPT>"SHORT" { RTOKEN( SHORT);}
295 <BOTH,SCRIPT>"BYTE" { RTOKEN( BYTE);}
296 <BOTH,SCRIPT>"NOFLOAT" { RTOKEN(NOFLOAT);}
297 <EXPRESSION,BOTH,SCRIPT>"NOCROSSREFS" { RTOKEN(NOCROSSREFS);}
298 <BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY); }
299 <BOTH,SCRIPT>"SORT" { RTOKEN(SORT); }
300 <EXPRESSION,BOTH,SCRIPT>"NOLOAD" { RTOKEN(NOLOAD);}
301 <EXPRESSION,BOTH,SCRIPT>"DSECT" { RTOKEN(DSECT);}
302 <EXPRESSION,BOTH,SCRIPT>"COPY" { RTOKEN(COPY);}
303 <EXPRESSION,BOTH,SCRIPT>"INFO" { RTOKEN(INFO);}
304 <EXPRESSION,BOTH,SCRIPT>"OVERLAY" { RTOKEN(OVERLAY);}
305 <BOTH,SCRIPT>"o" { RTOKEN(ORIGIN);}
306 <BOTH,SCRIPT>"org" { RTOKEN(ORIGIN);}
307 <BOTH,SCRIPT>"l" { RTOKEN( LENGTH);}
308 <BOTH,SCRIPT>"len" { RTOKEN( LENGTH);}
309 <BOTH,SCRIPT>"INCLUDE" { RTOKEN(INCLUDE);}
310 <BOTH,SCRIPT>"PHDRS" { RTOKEN (PHDRS); }
311 <EXPRESSION,BOTH,SCRIPT>"AT" { RTOKEN(AT);}
312 <EXPRESSION,BOTH,SCRIPT>"PROVIDE" { RTOKEN(PROVIDE); }
313 <EXPRESSION,BOTH,SCRIPT>"KEEP" { RTOKEN(KEEP); }
314 <EXPRESSION,BOTH,SCRIPT>"EXCLUDE_FILE" { RTOKEN(EXCLUDE_FILE); }
315 <MRI>"#".*\n? { ++ lineno; }
316 <MRI>"\n" { ++ lineno; RTOKEN(NEWLINE); }
317 <MRI>"*".* { /* Mri comment line */ }
318 <MRI>";".* { /* Mri comment line */ }
319 <MRI>"END" { RTOKEN(ENDWORD); }
320 <MRI>"ALIGNMOD" { RTOKEN(ALIGNMOD);}
321 <MRI>"ALIGN" { RTOKEN(ALIGN_K);}
322 <MRI>"CHIP" { RTOKEN(CHIP); }
323 <MRI>"BASE" { RTOKEN(BASE); }
324 <MRI>"ALIAS" { RTOKEN(ALIAS); }
325 <MRI>"TRUNCATE" { RTOKEN(TRUNCATE); }
326 <MRI>"LOAD" { RTOKEN(LOAD); }
327 <MRI>"PUBLIC" { RTOKEN(PUBLIC); }
328 <MRI>"ORDER" { RTOKEN(ORDER); }
329 <MRI>"NAME" { RTOKEN(NAMEWORD); }
330 <MRI>"FORMAT" { RTOKEN(FORMAT); }
331 <MRI>"CASE" { RTOKEN(CASE); }
332 <MRI>"START" { RTOKEN(START); }
333 <MRI>"LIST".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
334 <MRI>"SECT" { RTOKEN(SECT); }
335 <EXPRESSION,BOTH,SCRIPT,MRI>"ABSOLUTE" { RTOKEN(ABSOLUTE); }
336 <MRI>"end" { RTOKEN(ENDWORD); }
337 <MRI>"alignmod" { RTOKEN(ALIGNMOD);}
338 <MRI>"align" { RTOKEN(ALIGN_K);}
339 <MRI>"chip" { RTOKEN(CHIP); }
340 <MRI>"base" { RTOKEN(BASE); }
341 <MRI>"alias" { RTOKEN(ALIAS); }
342 <MRI>"truncate" { RTOKEN(TRUNCATE); }
343 <MRI>"load" { RTOKEN(LOAD); }
344 <MRI>"public" { RTOKEN(PUBLIC); }
345 <MRI>"order" { RTOKEN(ORDER); }
346 <MRI>"name" { RTOKEN(NAMEWORD); }
347 <MRI>"format" { RTOKEN(FORMAT); }
348 <MRI>"case" { RTOKEN(CASE); }
349 <MRI>"extern" { RTOKEN(EXTERN); }
350 <MRI>"start" { RTOKEN(START); }
351 <MRI>"list".* { RTOKEN(LIST); /* LIST and ignore to end of line */ }
352 <MRI>"sect" { RTOKEN(SECT); }
353 <EXPRESSION,BOTH,SCRIPT,MRI>"absolute" { RTOKEN(ABSOLUTE); }
354
355 <MRI>{FILENAMECHAR1}{NOCFILENAMECHAR}* {
356 /* Filename without commas, needed to parse mri stuff */
357 yylval.name = xstrdup(yytext);
358 return NAME;
359 }
360
361
362 <BOTH,EXPRESSION>{FILENAMECHAR1}{FILENAMECHAR}* {
363 yylval.name = xstrdup(yytext);
364 return NAME;
365 }
366 <BOTH,EXPRESSION>"-l"{FILENAMECHAR}+ {
367 yylval.name = xstrdup (yytext + 2);
368 return LNAME;
369 }
370 <SCRIPT>{WILDCHAR}* {
371 /* Annoyingly, this pattern can match comments, and we have
372 longest match issues to consider. So if the first two
373 characters are a comment opening, put the input back and
374 try again. */
375 if (yytext[0] == '/' && yytext[1] == '*')
376 {
377 yyless(2);
378 comment ();
379 }
380 else
381 {
382 yylval.name = xstrdup(yytext);
383 return NAME;
384 }
385 }
386
387 <EXPRESSION,BOTH,SCRIPT,VERS_NODE>"\""[^\"]*"\"" {
388 /* No matter the state, quotes
389 give what's inside */
390 yylval.name = xstrdup(yytext+1);
391 yylval.name[yyleng-2] = 0;
392 return NAME;
393 }
394 <BOTH,SCRIPT,EXPRESSION>"\n" { lineno++;}
395 <MRI,BOTH,SCRIPT,EXPRESSION>[ \t\r]+ { }
396
397 <VERS_NODE,VERS_SCRIPT>[:,;] { return *yytext; }
398
399 <VERS_NODE>global { RTOKEN(GLOBAL); }
400
401 <VERS_NODE>local { RTOKEN(LOCAL); }
402
403 <VERS_NODE>extern { RTOKEN(EXTERN); }
404
405 <VERS_NODE>{V_IDENTIFIER} { yylval.name = xstrdup (yytext);
406 return VERS_IDENTIFIER; }
407
408 <VERS_SCRIPT>{V_TAG} { yylval.name = xstrdup (yytext);
409 return VERS_TAG; }
410
411 <VERS_START>"{" { BEGIN(VERS_SCRIPT); return *yytext; }
412
413 <VERS_SCRIPT>"{" { BEGIN(VERS_NODE);
414 vers_node_nesting = 0;
415 return *yytext;
416 }
417 <VERS_SCRIPT>"}" { return *yytext; }
418 <VERS_NODE>"{" { vers_node_nesting++; return *yytext; }
419 <VERS_NODE>"}" { if (--vers_node_nesting < 0)
420 BEGIN(VERS_SCRIPT);
421 return *yytext;
422 }
423
424 <VERS_START,VERS_NODE,VERS_SCRIPT>[\n] { lineno++; }
425
426 <VERS_START,VERS_NODE,VERS_SCRIPT>#.* { /* Eat up comments */ }
427
428 <VERS_START,VERS_NODE,VERS_SCRIPT>[ \t\r]+ { /* Eat up whitespace */ }
429
430 <<EOF>> {
431 include_stack_ptr--;
432
433 if (include_stack_ptr == 0)
434 {
435 yyterminate();
436 }
437 else
438 {
439 yy_switch_to_buffer(include_stack[include_stack_ptr]);
440 }
441
442 ldfile_input_filename = file_name_stack[include_stack_ptr - 1];
443 lineno = lineno_stack[include_stack_ptr];
444
445 return END;
446 }
447
448 <SCRIPT,MRI,VERS_START,VERS_SCRIPT,VERS_NODE>. lex_warn_invalid(" in script", yytext);
449 <EXPRESSION,DEFSYMEXP,BOTH>. lex_warn_invalid(" in expression", yytext);
450
451 %%
452 \f
453
454 /* Switch flex to reading script file NAME, open on FILE,
455 saving the current input info on the include stack. */
456
457 void
458 lex_push_file (file, name)
459 FILE *file;
460 const char *name;
461 {
462 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
463 {
464 einfo("%F:includes nested too deeply\n");
465 }
466 file_name_stack[include_stack_ptr] = name;
467 lineno_stack[include_stack_ptr] = lineno;
468 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
469
470 include_stack_ptr++;
471 lineno = 1;
472 yyin = file;
473 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
474 }
475
476 /* Return a newly created flex input buffer containing STRING,
477 which is SIZE bytes long. */
478
479 static YY_BUFFER_STATE
480 yy_create_string_buffer (string, size)
481 CONST char *string;
482 size_t size;
483 {
484 YY_BUFFER_STATE b;
485
486 /* Calls to m-alloc get turned by sed into xm-alloc. */
487 b = (YY_BUFFER_STATE) malloc (sizeof (struct yy_buffer_state));
488 b->yy_input_file = 0;
489 b->yy_buf_size = size;
490
491 /* yy_ch_buf has to be 2 characters longer than the size given because
492 we need to put in 2 end-of-buffer characters. */
493 b->yy_ch_buf = (char *) malloc ((unsigned) (b->yy_buf_size + 3));
494
495 b->yy_ch_buf[0] = '\n';
496 strcpy (b->yy_ch_buf+1, string);
497 b->yy_ch_buf[size+1] = YY_END_OF_BUFFER_CHAR;
498 b->yy_ch_buf[size+2] = YY_END_OF_BUFFER_CHAR;
499 b->yy_n_chars = size+1;
500 b->yy_buf_pos = &b->yy_ch_buf[1];
501
502 b->yy_is_our_buffer = 1;
503 b->yy_is_interactive = 0;
504 b->yy_at_bol = 1;
505 b->yy_fill_buffer = 0;
506
507 /* flex 2.4.7 changed the interface. FIXME: We should not be using
508 a flex internal interface in the first place! */
509 #ifdef YY_BUFFER_NEW
510 b->yy_buffer_status = YY_BUFFER_NEW;
511 #else
512 b->yy_eof_status = EOF_NOT_SEEN;
513 #endif
514
515 return b;
516 }
517
518 /* Switch flex to reading from STRING, saving the current input info
519 on the include stack. */
520
521 void
522 lex_redirect (string)
523 CONST char *string;
524 {
525 YY_BUFFER_STATE tmp;
526
527 yy_init = 0;
528 if (include_stack_ptr >= MAX_INCLUDE_DEPTH)
529 {
530 einfo("%F: macros nested too deeply\n");
531 }
532 file_name_stack[include_stack_ptr] = "redirect";
533 lineno_stack[include_stack_ptr] = lineno;
534 include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
535 include_stack_ptr++;
536 lineno = 1;
537 tmp = yy_create_string_buffer (string, strlen (string));
538 yy_switch_to_buffer (tmp);
539 }
540 \f
541 /* Functions to switch to a different flex start condition,
542 saving the current start condition on `state_stack'. */
543
544 static int state_stack[MAX_INCLUDE_DEPTH * 2];
545 static int *state_stack_p = state_stack;
546
547 void
548 ldlex_script ()
549 {
550 *(state_stack_p)++ = yy_start;
551 BEGIN (SCRIPT);
552 }
553
554 void
555 ldlex_mri_script ()
556 {
557 *(state_stack_p)++ = yy_start;
558 BEGIN (MRI);
559 }
560
561 void
562 ldlex_version_script ()
563 {
564 *(state_stack_p)++ = yy_start;
565 BEGIN (VERS_START);
566 }
567
568 void
569 ldlex_version_file ()
570 {
571 *(state_stack_p)++ = yy_start;
572 BEGIN (VERS_SCRIPT);
573 }
574
575 void
576 ldlex_defsym ()
577 {
578 *(state_stack_p)++ = yy_start;
579 BEGIN (DEFSYMEXP);
580 }
581
582 void
583 ldlex_expression ()
584 {
585 *(state_stack_p)++ = yy_start;
586 BEGIN (EXPRESSION);
587 }
588
589 void
590 ldlex_both ()
591 {
592 *(state_stack_p)++ = yy_start;
593 BEGIN (BOTH);
594 }
595
596 void
597 ldlex_popstate ()
598 {
599 yy_start = *(--state_stack_p);
600 }
601 \f
602
603 /* Place up to MAX_SIZE characters in BUF and return in *RESULT
604 either the number of characters read, or 0 to indicate EOF. */
605
606 static void
607 yy_input (buf, result, max_size)
608 char *buf;
609 int *result;
610 int max_size;
611 {
612 *result = 0;
613 if (yy_current_buffer->yy_input_file)
614 {
615 if (yyin)
616 {
617 *result = fread ((char *) buf, 1, max_size, yyin);
618 if (*result < max_size && ferror (yyin))
619 einfo ("%F%P: read in flex scanner failed\n");
620 }
621 }
622 }
623
624 /* Eat the rest of a C-style comment. */
625
626 static void
627 comment ()
628 {
629 int c;
630
631 while (1)
632 {
633 c = input();
634 while (c != '*' && c != EOF)
635 {
636 if (c == '\n')
637 lineno++;
638 c = input();
639 }
640
641 if (c == '*')
642 {
643 c = input();
644 while (c == '*')
645 c = input();
646 if (c == '/')
647 break; /* found the end */
648 }
649
650 if (c == '\n')
651 lineno++;
652
653 if (c == EOF)
654 {
655 einfo( "%F%P: EOF in comment\n");
656 break;
657 }
658 }
659 }
660
661 /* Warn the user about a garbage character WHAT in the input
662 in context WHERE. */
663
664 static void
665 lex_warn_invalid (where, what)
666 char *where, *what;
667 {
668 char buf[5];
669
670 /* If we have found an input file whose format we do not recognize,
671 and we are therefore treating it as a linker script, and we find
672 an invalid character, then most likely this is a real object file
673 of some different format. Treat it as such. */
674 if (ldfile_assumed_script)
675 {
676 bfd_set_error (bfd_error_file_not_recognized);
677 einfo ("%F%s: file not recognized: %E\n", ldfile_input_filename);
678 }
679
680 if (! ISPRINT (*what))
681 {
682 sprintf (buf, "\\%03o", (unsigned int) *what);
683 what = buf;
684 }
685
686 einfo ("%P:%S: ignoring invalid character `%s'%s\n", what, where);
687 }
This page took 0.043937 seconds and 5 git commands to generate.