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