Branch data Line data Source code
1 : : /* do not edit automatically generated by mc from M2LexBuf. */
2 : : /* M2LexBuf.mod provides a buffer for m2.lex.
3 : :
4 : : Copyright (C) 2001-2025 Free Software Foundation, Inc.
5 : : Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 : :
7 : : This file is part of GNU Modula-2.
8 : :
9 : : GNU Modula-2 is free software; you can redistribute it and/or modify
10 : : it under the terms of the GNU General Public License as published by
11 : : the Free Software Foundation; either version 3, or (at your option)
12 : : any later version.
13 : :
14 : : GNU Modula-2 is distributed in the hope that it will be useful, but
15 : : WITHOUT ANY WARRANTY; without even the implied warranty of
16 : : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 : : General Public License for more details.
18 : :
19 : : You should have received a copy of the GNU General Public License
20 : : along with GNU Modula-2; see the file COPYING3. If not see
21 : : <http://www.gnu.org/licenses/>. */
22 : :
23 : : #include "config.h"
24 : : #include "system.h"
25 : : #include "gcc-consolidation.h"
26 : :
27 : : #include <stdbool.h>
28 : : # if !defined (PROC_D)
29 : : # define PROC_D
30 : : typedef void (*PROC_t) (void);
31 : : typedef struct { PROC_t proc; } PROC;
32 : : # endif
33 : :
34 : : # if !defined (TRUE)
35 : : # define TRUE (1==1)
36 : : # endif
37 : :
38 : : # if !defined (FALSE)
39 : : # define FALSE (1==0)
40 : : # endif
41 : :
42 : : # include "GStorage.h"
43 : : #if defined(__cplusplus)
44 : : # undef NULL
45 : : # define NULL 0
46 : : #endif
47 : : #define _M2LexBuf_C
48 : :
49 : : #include "GM2LexBuf.h"
50 : : # include "Gm2flex.h"
51 : : # include "GFIO.h"
52 : : # include "Glibc.h"
53 : : # include "GSYSTEM.h"
54 : : # include "GStorage.h"
55 : : # include "GDynamicStrings.h"
56 : : # include "GFormatStrings.h"
57 : : # include "GNameKey.h"
58 : : # include "GM2Reserved.h"
59 : : # include "GM2Printf.h"
60 : : # include "GM2Debug.h"
61 : : # include "GNumberIO.h"
62 : : # include "Ggcctypes.h"
63 : : # include "Gm2linemap.h"
64 : : # include "GM2Emit.h"
65 : : # include "GM2Error.h"
66 : : # include "GM2MetaError.h"
67 : : # include "GM2Options.h"
68 : : # include "GM2LangDump.h"
69 : : # include "GIndexing.h"
70 : : # include "GM2RTS.h"
71 : :
72 : : # define M2LexBuf_UnknownTokenNo 0
73 : : # define M2LexBuf_BuiltinTokenNo 1
74 : : # define Tracing false
75 : : # define Debugging false
76 : : # define DebugRecover false
77 : : # define BadTokenNo 32579
78 : : # define InitialSourceToken 2
79 : : typedef struct M2LexBuf__T1_r M2LexBuf__T1;
80 : :
81 : : typedef M2LexBuf__T1 *M2LexBuf_SourceList;
82 : :
83 : : typedef struct M2LexBuf__T2_r M2LexBuf__T2;
84 : :
85 : : typedef M2LexBuf__T2 *M2LexBuf_TokenDesc;
86 : :
87 : : struct M2LexBuf__T1_r {
88 : : M2LexBuf_SourceList left;
89 : : M2LexBuf_SourceList right;
90 : : DynamicStrings_String name;
91 : : unsigned int line;
92 : : unsigned int col;
93 : : };
94 : :
95 : : struct M2LexBuf__T2_r {
96 : : M2Reserved_toktype token;
97 : : NameKey_Name str;
98 : : int int_;
99 : : unsigned int line;
100 : : unsigned int col;
101 : : M2LexBuf_SourceList file;
102 : : location_t loc;
103 : : Indexing_Index insert;
104 : : };
105 : :
106 : : static M2LexBuf_SourceList CurrentSource;
107 : : static bool UseBufferedTokens;
108 : : static bool CurrentUsed;
109 : : static Indexing_Index ListOfTokens;
110 : : static unsigned int CurrentTokNo;
111 : : static unsigned int InsertionIndex;
112 : : static bool SeenEof;
113 : : static unsigned int indent;
114 : :
115 : : /*
116 : : OpenSource - Attempts to open the source file, s.
117 : : The success of the operation is returned.
118 : : */
119 : :
120 : : extern "C" bool M2LexBuf_OpenSource (DynamicStrings_String s);
121 : :
122 : : /*
123 : : CloseSource - closes the current open file.
124 : : */
125 : :
126 : : extern "C" void M2LexBuf_CloseSource (void);
127 : :
128 : : /*
129 : : ReInitialize - re-initialize the all the data structures.
130 : : */
131 : :
132 : : extern "C" void M2LexBuf_ReInitialize (void);
133 : :
134 : : /*
135 : : ResetForNewPass - reset the buffer pointers to the beginning ready for
136 : : a new pass
137 : : */
138 : :
139 : : extern "C" void M2LexBuf_ResetForNewPass (void);
140 : :
141 : : /*
142 : : GetToken - gets the next token into currenttoken.
143 : : */
144 : :
145 : : extern "C" void M2LexBuf_GetToken (void);
146 : :
147 : : /*
148 : : InsertToken - inserts a symbol token infront of the current token
149 : : ready for the next pass.
150 : : */
151 : :
152 : : extern "C" void M2LexBuf_InsertToken (M2Reserved_toktype token);
153 : :
154 : : /*
155 : : InsertTokenAndRewind - inserts a symbol token infront of the current token
156 : : and then moves the token stream back onto the inserted
157 : : token.
158 : : */
159 : :
160 : : extern "C" void M2LexBuf_InsertTokenAndRewind (M2Reserved_toktype token);
161 : :
162 : : /*
163 : : GetPreviousTokenLineNo - returns the line number of the previous token.
164 : : */
165 : :
166 : : extern "C" unsigned int M2LexBuf_GetPreviousTokenLineNo (void);
167 : :
168 : : /*
169 : : GetLineNo - returns the current line number where the symbol occurs in
170 : : the source file.
171 : : */
172 : :
173 : : extern "C" unsigned int M2LexBuf_GetLineNo (void);
174 : :
175 : : /*
176 : : GetTokenNo - returns the current token number.
177 : : */
178 : :
179 : : extern "C" unsigned int M2LexBuf_GetTokenNo (void);
180 : :
181 : : /*
182 : : GetTokenName - returns the token name given the tokenno.
183 : : */
184 : :
185 : : extern "C" NameKey_Name M2LexBuf_GetTokenName (unsigned int tokenno);
186 : :
187 : : /*
188 : : TokenToLineNo - returns the line number of the current file for the
189 : : tokenno. The depth refers to the include depth.
190 : : A depth of 0 is the current file, depth of 1 is the file
191 : : which included the current file. Zero is returned if the
192 : : depth exceeds the file nesting level.
193 : : */
194 : :
195 : : extern "C" unsigned int M2LexBuf_TokenToLineNo (unsigned int tokenno, unsigned int depth);
196 : :
197 : : /*
198 : : GetColumnNo - returns the current column where the symbol occurs in
199 : : the source file.
200 : : */
201 : :
202 : : extern "C" unsigned int M2LexBuf_GetColumnNo (void);
203 : :
204 : : /*
205 : : TokenToColumnNo - returns the column number of the current file for the
206 : : tokenno. The depth refers to the include depth.
207 : : A depth of 0 is the current file, depth of 1 is the file
208 : : which included the current file. Zero is returned if the
209 : : depth exceeds the file nesting level.
210 : : */
211 : :
212 : : extern "C" unsigned int M2LexBuf_TokenToColumnNo (unsigned int tokenno, unsigned int depth);
213 : :
214 : : /*
215 : : TokenToLocation - returns the location_t corresponding to tokenno.
216 : : */
217 : :
218 : : extern "C" location_t M2LexBuf_TokenToLocation (unsigned int tokenno);
219 : :
220 : : /*
221 : : FindFileNameFromToken - returns the complete FileName for the appropriate
222 : : source file yields the token number, TokenNo.
223 : : The, Depth, indicates the include level: 0..n
224 : : Level 0 is the current. NIL is returned if n+1
225 : : is requested.
226 : : */
227 : :
228 : : extern "C" DynamicStrings_String M2LexBuf_FindFileNameFromToken (unsigned int tokenno, unsigned int depth);
229 : :
230 : : /*
231 : : GetFileName - returns a String defining the current file.
232 : : */
233 : :
234 : : extern "C" DynamicStrings_String M2LexBuf_GetFileName (void);
235 : :
236 : : /*
237 : : MakeVirtualTok - providing caret, left, right are associated with a source file
238 : : and exist on the same src line then
239 : : create and return a new tokenno which is created from
240 : : tokenno left and right. Otherwise return caret.
241 : : If caret is UnknownTokenNo then it is replaced with left or right
242 : : in sequence to avoid an UnknownTokenNo.
243 : : */
244 : :
245 : : extern "C" unsigned int M2LexBuf_MakeVirtualTok (unsigned int caret, unsigned int left, unsigned int right);
246 : :
247 : : /*
248 : : MakeVirtual2Tok - creates and return a new tokenno which is created from
249 : : two tokens left and right. It tries to avoid UnknownTokenNo
250 : : and will fall back to left or right if necessary.
251 : : */
252 : :
253 : : extern "C" unsigned int M2LexBuf_MakeVirtual2Tok (unsigned int left, unsigned int right);
254 : :
255 : : /*
256 : : AddTok - adds a token to the buffer.
257 : : */
258 : :
259 : : extern "C" void M2LexBuf_AddTok (M2Reserved_toktype t);
260 : :
261 : : /*
262 : : AddTokCharStar - adds a token to the buffer and an additional string, s.
263 : : A copy of string, s, is made.
264 : : */
265 : :
266 : : extern "C" void M2LexBuf_AddTokCharStar (M2Reserved_toktype t, void * s);
267 : :
268 : : /*
269 : : AddTokInteger - adds a token and an integer to the buffer.
270 : : */
271 : :
272 : : extern "C" void M2LexBuf_AddTokInteger (M2Reserved_toktype t, int i);
273 : :
274 : : /*
275 : : SetFile - sets the current filename to, filename.
276 : : */
277 : :
278 : : extern "C" void M2LexBuf_SetFile (void * filename);
279 : :
280 : : /*
281 : : PushFile - indicates that, filename, has just been included.
282 : : */
283 : :
284 : : extern "C" void M2LexBuf_PushFile (void * filename);
285 : :
286 : : /*
287 : : PopFile - indicates that we are returning to, filename, having finished
288 : : an include.
289 : : */
290 : :
291 : : extern "C" void M2LexBuf_PopFile (void * filename);
292 : :
293 : : /*
294 : : PrintTokenNo - displays token and the location of the token.
295 : : */
296 : :
297 : : extern "C" void M2LexBuf_PrintTokenNo (unsigned int tokenno);
298 : :
299 : : /*
300 : : DisplayToken - display the token name using printf0 no newline is emitted.
301 : : */
302 : :
303 : : extern "C" void M2LexBuf_DisplayToken (M2Reserved_toktype tok);
304 : :
305 : : /*
306 : : DumpTokens - displays all tokens.
307 : : */
308 : :
309 : : extern "C" void M2LexBuf_DumpTokens (void);
310 : : static void stop (void);
311 : :
312 : : /*
313 : : InitTokenDesc - returns a TokenDesc filled in with the parameters and
314 : : the insert field set to NIL.
315 : : */
316 : :
317 : : static M2LexBuf_TokenDesc InitTokenDesc (M2Reserved_toktype token, NameKey_Name str, int int_, unsigned int line, unsigned int col, M2LexBuf_SourceList file, location_t loc);
318 : :
319 : : /*
320 : : DeleteTokenDesc - delete tokdesc and any sub indices.
321 : : */
322 : :
323 : : static void DeleteTokenDesc (M2LexBuf_TokenDesc tokdesc);
324 : :
325 : : /*
326 : : Append - appends tokdesc to the end of the list defined by index.
327 : : */
328 : :
329 : : static void Append (Indexing_Index index, M2LexBuf_TokenDesc tokdesc);
330 : :
331 : : /*
332 : : InitTokenList - creates an empty token list, which starts the first source token
333 : : at position 2. This allows position 0 to be used for the unknown
334 : : location and position 1 for the builtin token.
335 : : */
336 : :
337 : : static void InitTokenList (void);
338 : :
339 : : /*
340 : : Init - initializes the token list and source list.
341 : : */
342 : :
343 : : static void Init (void);
344 : :
345 : : /*
346 : : AddTo - adds a new element to the end of SourceList, CurrentSource.
347 : : */
348 : :
349 : : static void AddTo (M2LexBuf_SourceList l);
350 : :
351 : : /*
352 : : SubFrom - subtracts, l, from the source list.
353 : : */
354 : :
355 : : static void SubFrom (M2LexBuf_SourceList l);
356 : :
357 : : /*
358 : : NewElement - returns a new SourceList
359 : : */
360 : :
361 : : static M2LexBuf_SourceList NewElement (void * s);
362 : :
363 : : /*
364 : : NewList - initializes an empty list with the classic dummy header element.
365 : : */
366 : :
367 : : static M2LexBuf_SourceList NewList (void);
368 : :
369 : : /*
370 : : CheckIfNeedToDuplicate - checks to see whether the CurrentSource has
371 : : been used, if it has then duplicate the list.
372 : : */
373 : :
374 : : static void CheckIfNeedToDuplicate (void);
375 : :
376 : : /*
377 : : KillList - kills the SourceList providing that it has not been used.
378 : : */
379 : :
380 : : static void KillList (void);
381 : :
382 : : /*
383 : : DumpToken -
384 : : */
385 : :
386 : : static void DumpToken (M2LexBuf_TokenDesc tokdesc);
387 : :
388 : : /*
389 : : CopyOutCurrent - copies the token in buffer[index][insertion] into
390 : : then current token global variables.
391 : : */
392 : :
393 : : static void CopyOutCurrent (Indexing_Index buffer, unsigned int index, unsigned int insertion);
394 : :
395 : : /*
396 : : UpdateToken - update the global current token variables from buffer[index]
397 : : using inserted tokens if directed by InsertionIndex.
398 : : */
399 : :
400 : : static void UpdateToken (Indexing_Index buffer, unsigned int index);
401 : :
402 : : /*
403 : : GetTokenFiltered - providing that we have not already seen an eof for this source
404 : : file call m2flex.GetToken and GetToken if requested.
405 : : */
406 : :
407 : : static void GetTokenFiltered (bool callGetToken);
408 : :
409 : : /*
410 : : AppendInsertToken -
411 : : */
412 : :
413 : : static void AppendInsertToken (Indexing_Index index, M2LexBuf_TokenDesc tokdesc);
414 : :
415 : : /*
416 : : DupTok - duplicate tokdesc and replaces the token field with token.
417 : : */
418 : :
419 : : static M2LexBuf_TokenDesc DupTok (M2LexBuf_TokenDesc tokdesc, M2Reserved_toktype token);
420 : :
421 : : /*
422 : : AddTokToList - adds a token to a dynamic list.
423 : : */
424 : :
425 : : static void AddTokToList (M2Reserved_toktype token, NameKey_Name str, int int_, unsigned int line, unsigned int col, M2LexBuf_SourceList file, location_t location);
426 : :
427 : : /*
428 : : IsLastTokenEof - returns TRUE if the last token was an eoftok
429 : : */
430 : :
431 : : static bool IsLastTokenEof (void);
432 : :
433 : : /*
434 : : isSrcToken - returns TRUE if tokenno is associated with
435 : : program source code.
436 : : */
437 : :
438 : : static bool isSrcToken (unsigned int tokenno);
439 : :
440 : : /*
441 : : tprintf0 -
442 : : */
443 : :
444 : : static void tprintf0 (const char *format_, unsigned int _format_high);
445 : :
446 : : /*
447 : : tprintf1 -
448 : : */
449 : :
450 : : static void tprintf1 (const char *format_, unsigned int _format_high, DynamicStrings_String str);
451 : :
452 : 0 : static void stop (void)
453 : : {
454 : 0 : }
455 : :
456 : :
457 : : /*
458 : : InitTokenDesc - returns a TokenDesc filled in with the parameters and
459 : : the insert field set to NIL.
460 : : */
461 : :
462 : 112873306 : static M2LexBuf_TokenDesc InitTokenDesc (M2Reserved_toktype token, NameKey_Name str, int int_, unsigned int line, unsigned int col, M2LexBuf_SourceList file, location_t loc)
463 : : {
464 : 112873306 : M2LexBuf_TokenDesc tokdesc;
465 : :
466 : 0 : Storage_ALLOCATE ((void **) &tokdesc, sizeof (M2LexBuf__T2));
467 : 112873306 : tokdesc->token = token;
468 : 112873306 : tokdesc->str = str;
469 : 112873306 : tokdesc->int_ = int_;
470 : 112873306 : tokdesc->line = line;
471 : 112873306 : tokdesc->col = col;
472 : 112873306 : tokdesc->file = file;
473 : 112873306 : tokdesc->loc = loc;
474 : 112873306 : tokdesc->insert = static_cast<Indexing_Index> (NULL);
475 : 112873306 : return tokdesc;
476 : : /* static analysis guarentees a RETURN statement will be used before here. */
477 : : __builtin_unreachable ();
478 : : }
479 : :
480 : :
481 : : /*
482 : : DeleteTokenDesc - delete tokdesc and any sub indices.
483 : : */
484 : :
485 : 79908 : static void DeleteTokenDesc (M2LexBuf_TokenDesc tokdesc)
486 : : {
487 : 79908 : if (tokdesc->insert != NULL)
488 : : {
489 : 0 : Indexing_ForeachIndiceInIndexDo (tokdesc->insert, (Indexing_IndexProcedure) {(Indexing_IndexProcedure_t) DeleteTokenDesc});
490 : : }
491 : 79908 : Storage_DEALLOCATE ((void **) &tokdesc, sizeof (M2LexBuf__T2));
492 : 79908 : }
493 : :
494 : :
495 : : /*
496 : : Append - appends tokdesc to the end of the list defined by index.
497 : : */
498 : :
499 : 112873306 : static void Append (Indexing_Index index, M2LexBuf_TokenDesc tokdesc)
500 : : {
501 : 112873306 : if (Indexing_IsEmpty (index))
502 : : {
503 : 30513 : Indexing_PutIndice (index, Indexing_LowIndice (index), reinterpret_cast <void *> (tokdesc));
504 : : }
505 : : else
506 : : {
507 : 112842793 : Indexing_PutIndice (index, (Indexing_HighIndice (index))+1, reinterpret_cast <void *> (tokdesc));
508 : : }
509 : 112873306 : }
510 : :
511 : :
512 : : /*
513 : : InitTokenList - creates an empty token list, which starts the first source token
514 : : at position 2. This allows position 0 to be used for the unknown
515 : : location and position 1 for the builtin token.
516 : : */
517 : :
518 : 30513 : static void InitTokenList (void)
519 : : {
520 : : /* 65K elements in the array and when it becomes full it will grow to 1M, 16M etc elements. */
521 : 30513 : ListOfTokens = Indexing_InitIndexTuned (0, (1024*1024) / 16, 16);
522 : 30513 : Append (ListOfTokens, InitTokenDesc (M2Reserved_eoftok, NameKey_NulName, 0, 0, 0, NULL, M2Emit_UnknownLocation ()));
523 : 30513 : Append (ListOfTokens, InitTokenDesc (M2Reserved_eoftok, NameKey_NulName, 0, 0, 0, NULL, M2Emit_BuiltinsLocation ()));
524 : 30513 : }
525 : :
526 : :
527 : : /*
528 : : Init - initializes the token list and source list.
529 : : */
530 : :
531 : 30513 : static void Init (void)
532 : : {
533 : 30513 : SeenEof = false;
534 : 30513 : InsertionIndex = 0;
535 : 30513 : M2LexBuf_currenttoken = M2Reserved_eoftok;
536 : 30513 : CurrentTokNo = InitialSourceToken;
537 : 30513 : CurrentSource = NULL;
538 : 30513 : UseBufferedTokens = false;
539 : 30513 : InitTokenList ();
540 : 30513 : }
541 : :
542 : :
543 : : /*
544 : : AddTo - adds a new element to the end of SourceList, CurrentSource.
545 : : */
546 : :
547 : 230281 : static void AddTo (M2LexBuf_SourceList l)
548 : : {
549 : 230281 : l->right = CurrentSource;
550 : 230281 : l->left = CurrentSource->left;
551 : 230281 : CurrentSource->left->right = l;
552 : 230281 : CurrentSource->left = l;
553 : 230281 : l->left->line = m2flex_GetLineNo ();
554 : 230281 : l->left->col = m2flex_GetColumnNo ();
555 : 230281 : }
556 : :
557 : :
558 : : /*
559 : : SubFrom - subtracts, l, from the source list.
560 : : */
561 : :
562 : 0 : static void SubFrom (M2LexBuf_SourceList l)
563 : : {
564 : 0 : l->left->right = l->right;
565 : 0 : l->right->left = l->left;
566 : 0 : }
567 : :
568 : :
569 : : /*
570 : : NewElement - returns a new SourceList
571 : : */
572 : :
573 : 230281 : static M2LexBuf_SourceList NewElement (void * s)
574 : : {
575 : 230281 : M2LexBuf_SourceList l;
576 : :
577 : 230281 : Storage_ALLOCATE ((void **) &l, sizeof (M2LexBuf__T1));
578 : 230281 : if (l == NULL)
579 : : {
580 : 0 : M2RTS_HALT (-1);
581 : : __builtin_unreachable ();
582 : : }
583 : : else
584 : : {
585 : 230281 : l->name = DynamicStrings_InitStringCharStar (s);
586 : 230281 : l->left = NULL;
587 : 230281 : l->right = NULL;
588 : : }
589 : 230281 : return l;
590 : : /* static analysis guarentees a RETURN statement will be used before here. */
591 : : __builtin_unreachable ();
592 : : }
593 : :
594 : :
595 : : /*
596 : : NewList - initializes an empty list with the classic dummy header element.
597 : : */
598 : :
599 : 230281 : static M2LexBuf_SourceList NewList (void)
600 : : {
601 : 230281 : M2LexBuf_SourceList l;
602 : :
603 : 230281 : Storage_ALLOCATE ((void **) &l, sizeof (M2LexBuf__T1));
604 : 230281 : l->left = l;
605 : 230281 : l->right = l;
606 : 230281 : l->name = static_cast<DynamicStrings_String> (NULL);
607 : 230281 : return l;
608 : : /* static analysis guarentees a RETURN statement will be used before here. */
609 : : __builtin_unreachable ();
610 : : }
611 : :
612 : :
613 : : /*
614 : : CheckIfNeedToDuplicate - checks to see whether the CurrentSource has
615 : : been used, if it has then duplicate the list.
616 : : */
617 : :
618 : 0 : static void CheckIfNeedToDuplicate (void)
619 : : {
620 : 0 : M2LexBuf_SourceList l;
621 : 0 : M2LexBuf_SourceList h;
622 : :
623 : 0 : if (CurrentUsed)
624 : : {
625 : 0 : l = CurrentSource->right;
626 : 0 : h = CurrentSource;
627 : 0 : CurrentSource = NewList ();
628 : 0 : while (l != h)
629 : : {
630 : 0 : AddTo (NewElement (reinterpret_cast <void *> (l->name)));
631 : 0 : l = l->right;
632 : : }
633 : : }
634 : 0 : }
635 : :
636 : :
637 : : /*
638 : : KillList - kills the SourceList providing that it has not been used.
639 : : */
640 : :
641 : 245534 : static void KillList (void)
642 : : {
643 : 245534 : M2LexBuf_SourceList l;
644 : 245534 : M2LexBuf_SourceList k;
645 : :
646 : 245534 : if (! CurrentUsed && (CurrentSource != NULL))
647 : : {
648 : : l = CurrentSource;
649 : 84258 : do {
650 : 84258 : k = l;
651 : 84258 : l = l->right;
652 : 84258 : Storage_DEALLOCATE ((void **) &k, sizeof (M2LexBuf__T1));
653 : 84258 : } while (! (l == CurrentSource));
654 : : }
655 : 245534 : }
656 : :
657 : :
658 : : /*
659 : : DumpToken -
660 : : */
661 : :
662 : 0 : static void DumpToken (M2LexBuf_TokenDesc tokdesc)
663 : : {
664 : 0 : unsigned int n;
665 : :
666 : 0 : n = indent;
667 : 0 : while (n > 0)
668 : : {
669 : 0 : M2Printf_printf0 ((const char *) " ", 1);
670 : 0 : n -= 1;
671 : : }
672 : 0 : M2LexBuf_DisplayToken (tokdesc->token);
673 : 0 : if (tokdesc->str != NameKey_NulName)
674 : : {
675 : 0 : M2Printf_printf1 ((const char *) " %a", 3, (const unsigned char *) &tokdesc->str, (sizeof (tokdesc->str)-1));
676 : : }
677 : 0 : if (tokdesc->insert != NULL)
678 : : {
679 : 0 : M2Printf_printf0 ((const char *) "inserted error recovery tokens\\n", 32);
680 : 0 : indent += 2;
681 : 0 : Indexing_ForeachIndiceInIndexDo (tokdesc->insert, (Indexing_IndexProcedure) {(Indexing_IndexProcedure_t) DumpToken});
682 : 0 : indent -= 2;
683 : : }
684 : 0 : }
685 : :
686 : :
687 : : /*
688 : : CopyOutCurrent - copies the token in buffer[index][insertion] into
689 : : then current token global variables.
690 : : */
691 : :
692 : 552654393 : static void CopyOutCurrent (Indexing_Index buffer, unsigned int index, unsigned int insertion)
693 : : {
694 : 552654393 : M2LexBuf_TokenDesc tokdesc;
695 : :
696 : 552654393 : tokdesc = static_cast<M2LexBuf_TokenDesc> (Indexing_GetIndice (buffer, index));
697 : 552654393 : if (insertion != 0)
698 : : {
699 : 48 : tokdesc = static_cast<M2LexBuf_TokenDesc> (Indexing_GetIndice (tokdesc->insert, insertion));
700 : : }
701 : 552654393 : M2LexBuf_currenttoken = tokdesc->token;
702 : 552654393 : M2LexBuf_currentstring = NameKey_KeyToCharStar (tokdesc->str);
703 : 552654393 : M2LexBuf_currentcolumn = tokdesc->col;
704 : 552654393 : M2LexBuf_currentinteger = tokdesc->int_;
705 : 552654393 : }
706 : :
707 : :
708 : : /*
709 : : UpdateToken - update the global current token variables from buffer[index]
710 : : using inserted tokens if directed by InsertionIndex.
711 : : */
712 : :
713 : 552654393 : static void UpdateToken (Indexing_Index buffer, unsigned int index)
714 : : {
715 : 552654393 : M2LexBuf_TokenDesc tokdesc;
716 : :
717 : 552654393 : tokdesc = static_cast<M2LexBuf_TokenDesc> (Indexing_GetIndice (buffer, index));
718 : 552654393 : if (InsertionIndex > 0)
719 : : {
720 : : /* avoid dangling else. */
721 : : /* We have an inserted token to use. */
722 : 48 : M2Debug_Assert (tokdesc->insert != NULL);
723 : 48 : CopyOutCurrent (buffer, index, InsertionIndex);
724 : : /* Move InsertionIndex to the next position. */
725 : 48 : InsertionIndex += 1;
726 : 48 : if (InsertionIndex > (Indexing_HighIndice (tokdesc->insert)))
727 : : {
728 : : /* We are done consuming the inserted tokens, so move
729 : : onto the next original source token. */
730 : 48 : InsertionIndex = 0;
731 : 48 : CurrentTokNo += 1;
732 : : }
733 : : }
734 : 552654345 : else if ((tokdesc->insert != NULL) && (InsertionIndex == 0))
735 : : {
736 : : /* avoid dangling else. */
737 : : /* This source token has extra tokens appended after it by the error recovery.
738 : : Set the index ready for the next UpdateToken which will read the extra
739 : : tokens. */
740 : 24 : InsertionIndex = 1;
741 : : /* However this call must read the original token. */
742 : 24 : CopyOutCurrent (buffer, index, 0);
743 : : }
744 : : else
745 : : {
746 : : /* avoid dangling else. */
747 : 552654321 : CopyOutCurrent (buffer, index, 0);
748 : : /* Move onto the next original source token. */
749 : 552654321 : CurrentTokNo += 1;
750 : : }
751 : 552654393 : }
752 : :
753 : :
754 : : /*
755 : : GetTokenFiltered - providing that we have not already seen an eof for this source
756 : : file call m2flex.GetToken and GetToken if requested.
757 : : */
758 : :
759 : 110916842 : static void GetTokenFiltered (bool callGetToken)
760 : : {
761 : 110916842 : if (SeenEof)
762 : : {
763 : 0 : M2LexBuf_currenttoken = M2Reserved_eoftok;
764 : : }
765 : : else
766 : : {
767 : : /* Call the lexical phase to place a new token into the last bucket. */
768 : 110916842 : m2flex_GetToken ();
769 : 110916842 : if (callGetToken)
770 : : {
771 : 0 : M2LexBuf_GetToken ();
772 : : }
773 : : }
774 : 110916842 : }
775 : :
776 : :
777 : : /*
778 : : AppendInsertToken -
779 : : */
780 : :
781 : 174 : static void AppendInsertToken (Indexing_Index index, M2LexBuf_TokenDesc tokdesc)
782 : : {
783 : 174 : if (Indexing_IsEmpty (index))
784 : : {
785 : 108 : Indexing_PutIndice (index, Indexing_LowIndice (index), reinterpret_cast <void *> (tokdesc));
786 : : }
787 : : else
788 : : {
789 : 66 : Indexing_PutIndice (index, (Indexing_HighIndice (index))+1, reinterpret_cast <void *> (tokdesc));
790 : : }
791 : 174 : }
792 : :
793 : :
794 : : /*
795 : : DupTok - duplicate tokdesc and replaces the token field with token.
796 : : */
797 : :
798 : 174 : static M2LexBuf_TokenDesc DupTok (M2LexBuf_TokenDesc tokdesc, M2Reserved_toktype token)
799 : : {
800 : 174 : M2LexBuf_TokenDesc dup;
801 : :
802 : 174 : Storage_ALLOCATE ((void **) &dup, sizeof (M2LexBuf__T2));
803 : 174 : M2Debug_Assert (dup != NULL);
804 : 174 : (*dup) = (*tokdesc);
805 : 174 : dup->token = token;
806 : 174 : return dup;
807 : : /* static analysis guarentees a RETURN statement will be used before here. */
808 : : __builtin_unreachable ();
809 : : }
810 : :
811 : :
812 : : /*
813 : : AddTokToList - adds a token to a dynamic list.
814 : : */
815 : :
816 : 112812280 : static void AddTokToList (M2Reserved_toktype token, NameKey_Name str, int int_, unsigned int line, unsigned int col, M2LexBuf_SourceList file, location_t location)
817 : : {
818 : 112812280 : Append (ListOfTokens, InitTokenDesc (token, str, int_, line, col, file, location));
819 : 112812280 : }
820 : :
821 : :
822 : : /*
823 : : IsLastTokenEof - returns TRUE if the last token was an eoftok
824 : : */
825 : :
826 : 202735 : static bool IsLastTokenEof (void)
827 : : {
828 : 202735 : M2LexBuf_TokenDesc tokdesc;
829 : :
830 : 202735 : if (Indexing_IsEmpty (ListOfTokens))
831 : : {
832 : : return false;
833 : : }
834 : : else
835 : : {
836 : 202735 : tokdesc = static_cast<M2LexBuf_TokenDesc> (Indexing_GetIndice (ListOfTokens, Indexing_HighIndice (ListOfTokens)));
837 : 202735 : return tokdesc->token == M2Reserved_eoftok;
838 : : }
839 : : /* static analysis guarentees a RETURN statement will be used before here. */
840 : : __builtin_unreachable ();
841 : : }
842 : :
843 : :
844 : : /*
845 : : isSrcToken - returns TRUE if tokenno is associated with
846 : : program source code.
847 : : */
848 : :
849 : 0 : static bool isSrcToken (unsigned int tokenno)
850 : : {
851 : 0 : return (tokenno != M2LexBuf_UnknownTokenNo) && (tokenno != M2LexBuf_BuiltinTokenNo);
852 : : /* static analysis guarentees a RETURN statement will be used before here. */
853 : : __builtin_unreachable ();
854 : : }
855 : :
856 : :
857 : : /*
858 : : tprintf0 -
859 : : */
860 : :
861 : 947801 : static void tprintf0 (const char *format_, unsigned int _format_high)
862 : : {
863 : 947801 : char format[_format_high+1];
864 : :
865 : : /* make a local copy of each unbounded array. */
866 : 947801 : memcpy (format, format_, _format_high+1);
867 : :
868 : 947801 : if (Tracing)
869 : : {
870 : : M2Printf_printf0 ((const char *) format, _format_high);
871 : : }
872 : 947801 : }
873 : :
874 : :
875 : : /*
876 : : tprintf1 -
877 : : */
878 : :
879 : 948073 : static void tprintf1 (const char *format_, unsigned int _format_high, DynamicStrings_String str)
880 : : {
881 : 948073 : char format[_format_high+1];
882 : :
883 : : /* make a local copy of each unbounded array. */
884 : 948073 : memcpy (format, format_, _format_high+1);
885 : :
886 : 948073 : if (Tracing)
887 : : {
888 : : M2Printf_printf1 ((const char *) format, _format_high, (const unsigned char *) &str, (sizeof (str)-1));
889 : : }
890 : 948073 : }
891 : :
892 : :
893 : : /*
894 : : OpenSource - Attempts to open the source file, s.
895 : : The success of the operation is returned.
896 : : */
897 : :
898 : 948073 : extern "C" bool M2LexBuf_OpenSource (DynamicStrings_String s)
899 : : {
900 : 948073 : tprintf1 ((const char *) "OpenSource (%s)\\n", 17, s);
901 : 948073 : SeenEof = false;
902 : 948073 : if (UseBufferedTokens)
903 : : {
904 : 745337 : M2LexBuf_GetToken ();
905 : 745337 : return true;
906 : : }
907 : : else
908 : : {
909 : 202736 : if (m2flex_OpenSource (DynamicStrings_string (s)))
910 : : {
911 : 202735 : M2LexBuf_SetFile (DynamicStrings_string (s));
912 : 202735 : M2LexBuf_GetToken ();
913 : 202735 : if (IsLastTokenEof ())
914 : : {
915 : 6 : M2MetaError_MetaErrorT0 (M2LexBuf_GetTokenNo (), (const char *) "source file is empty", 20);
916 : : }
917 : 202735 : return true;
918 : : }
919 : : else
920 : : {
921 : : return false;
922 : : }
923 : : }
924 : : /* static analysis guarentees a RETURN statement will be used before here. */
925 : : __builtin_unreachable ();
926 : : }
927 : :
928 : :
929 : : /*
930 : : CloseSource - closes the current open file.
931 : : */
932 : :
933 : 947801 : extern "C" void M2LexBuf_CloseSource (void)
934 : : {
935 : 947801 : tprintf0 ((const char *) "CloseSource\\n", 13);
936 : 947801 : if (UseBufferedTokens)
937 : : {
938 : 745084 : while (M2LexBuf_currenttoken != M2Reserved_eoftok)
939 : : {
940 : 0 : M2LexBuf_GetToken ();
941 : : }
942 : : }
943 : : /* a subsequent call to m2flex.OpenSource will really close the file */
944 : 947801 : }
945 : :
946 : :
947 : : /*
948 : : ReInitialize - re-initialize the all the data structures.
949 : : */
950 : :
951 : 15253 : extern "C" void M2LexBuf_ReInitialize (void)
952 : : {
953 : 15253 : Indexing_ForeachIndiceInIndexDo (ListOfTokens, (Indexing_IndexProcedure) {(Indexing_IndexProcedure_t) DeleteTokenDesc});
954 : 15253 : CurrentUsed = false;
955 : 15253 : KillList ();
956 : 15253 : Init ();
957 : 15253 : }
958 : :
959 : :
960 : : /*
961 : : ResetForNewPass - reset the buffer pointers to the beginning ready for
962 : : a new pass
963 : : */
964 : :
965 : 60156 : extern "C" void M2LexBuf_ResetForNewPass (void)
966 : : {
967 : 60156 : InsertionIndex = 0;
968 : 60156 : CurrentTokNo = InitialSourceToken;
969 : 60156 : UseBufferedTokens = true;
970 : 60156 : }
971 : :
972 : :
973 : : /*
974 : : GetToken - gets the next token into currenttoken.
975 : : */
976 : :
977 : 552654393 : extern "C" void M2LexBuf_GetToken (void)
978 : : {
979 : 552654393 : typedef struct GetToken__T3_a GetToken__T3;
980 : :
981 : 552654393 : struct GetToken__T3_a { char array[20+1]; };
982 : 552654393 : GetToken__T3 buf;
983 : :
984 : 552654393 : if (UseBufferedTokens)
985 : : {
986 : : /* avoid dangling else. */
987 : 441737503 : UpdateToken (ListOfTokens, CurrentTokNo);
988 : 441737503 : if (M2Options_GetDebugTraceToken ())
989 : : {
990 : 0 : NumberIO_CardToStr (CurrentTokNo, 0, (char *) &buf.array[0], 20);
991 : 0 : FIO_WriteString (M2LangDump_GetDumpFile (), (const char *) "token: ", 7);
992 : 0 : FIO_WriteString (M2LangDump_GetDumpFile (), (const char *) &buf.array[0], 20);
993 : 0 : FIO_WriteLine (M2LangDump_GetDumpFile ());
994 : : }
995 : : }
996 : : else
997 : : {
998 : 110916890 : if (! (Indexing_InBounds (ListOfTokens, CurrentTokNo)))
999 : : {
1000 : 110916842 : GetTokenFiltered (false);
1001 : : }
1002 : 110916890 : UpdateToken (ListOfTokens, CurrentTokNo);
1003 : 110916890 : if (M2Options_GetDebugTraceToken ())
1004 : : {
1005 : 0 : NumberIO_CardToStr (CurrentTokNo, 0, (char *) &buf.array[0], 20);
1006 : 0 : m2flex_M2Error (&buf);
1007 : : }
1008 : : }
1009 : 552654393 : }
1010 : :
1011 : :
1012 : : /*
1013 : : InsertToken - inserts a symbol token infront of the current token
1014 : : ready for the next pass.
1015 : : */
1016 : :
1017 : 150 : extern "C" void M2LexBuf_InsertToken (M2Reserved_toktype token)
1018 : : {
1019 : 150 : unsigned int prev;
1020 : 150 : M2LexBuf_TokenDesc tokdesc;
1021 : :
1022 : 150 : M2Debug_Assert (ListOfTokens != NULL);
1023 : 150 : M2Debug_Assert (! (Indexing_IsEmpty (ListOfTokens)));
1024 : 150 : prev = (M2LexBuf_GetTokenNo ())-1;
1025 : 150 : tokdesc = static_cast<M2LexBuf_TokenDesc> (Indexing_GetIndice (ListOfTokens, prev));
1026 : 150 : if (tokdesc->insert == NULL)
1027 : : {
1028 : 108 : tokdesc->insert = Indexing_InitIndex (1);
1029 : : }
1030 : 150 : AppendInsertToken (tokdesc->insert, DupTok (tokdesc, token));
1031 : 150 : }
1032 : :
1033 : :
1034 : : /*
1035 : : InsertTokenAndRewind - inserts a symbol token infront of the current token
1036 : : and then moves the token stream back onto the inserted
1037 : : token.
1038 : : */
1039 : :
1040 : 24 : extern "C" void M2LexBuf_InsertTokenAndRewind (M2Reserved_toktype token)
1041 : : {
1042 : 24 : unsigned int position;
1043 : 24 : M2LexBuf_TokenDesc tokdesc;
1044 : :
1045 : 24 : if ((M2LexBuf_GetTokenNo ()) > 0)
1046 : : {
1047 : 24 : M2LexBuf_InsertToken (token);
1048 : 24 : position = CurrentTokNo-2;
1049 : 24 : tokdesc = static_cast<M2LexBuf_TokenDesc> (Indexing_GetIndice (ListOfTokens, position));
1050 : 24 : if (tokdesc->insert == NULL)
1051 : : {
1052 : 0 : tokdesc->insert = Indexing_InitIndex (1);
1053 : : }
1054 : 24 : AppendInsertToken (tokdesc->insert, DupTok (tokdesc, token));
1055 : 24 : InsertionIndex = Indexing_HighIndice (tokdesc->insert);
1056 : 24 : CurrentTokNo -= 2;
1057 : 24 : M2LexBuf_GetToken ();
1058 : : }
1059 : 24 : }
1060 : :
1061 : :
1062 : : /*
1063 : : GetPreviousTokenLineNo - returns the line number of the previous token.
1064 : : */
1065 : :
1066 : 71150 : extern "C" unsigned int M2LexBuf_GetPreviousTokenLineNo (void)
1067 : : {
1068 : 71150 : return M2LexBuf_GetLineNo ();
1069 : : /* static analysis guarentees a RETURN statement will be used before here. */
1070 : : __builtin_unreachable ();
1071 : : }
1072 : :
1073 : :
1074 : : /*
1075 : : GetLineNo - returns the current line number where the symbol occurs in
1076 : : the source file.
1077 : : */
1078 : :
1079 : 7085243 : extern "C" unsigned int M2LexBuf_GetLineNo (void)
1080 : : {
1081 : 7085243 : if (CurrentTokNo == 0)
1082 : : {
1083 : : return 0;
1084 : : }
1085 : : else
1086 : : {
1087 : 7085243 : return M2LexBuf_TokenToLineNo (M2LexBuf_GetTokenNo (), 0);
1088 : : }
1089 : : /* static analysis guarentees a RETURN statement will be used before here. */
1090 : : __builtin_unreachable ();
1091 : : }
1092 : :
1093 : :
1094 : : /*
1095 : : GetTokenNo - returns the current token number.
1096 : : */
1097 : :
1098 : 107400360 : extern "C" unsigned int M2LexBuf_GetTokenNo (void)
1099 : : {
1100 : 107400360 : if (CurrentTokNo == 0)
1101 : : {
1102 : : return 0;
1103 : : }
1104 : : else
1105 : : {
1106 : 107400360 : return CurrentTokNo-1;
1107 : : }
1108 : : /* static analysis guarentees a RETURN statement will be used before here. */
1109 : : __builtin_unreachable ();
1110 : : }
1111 : :
1112 : :
1113 : : /*
1114 : : GetTokenName - returns the token name given the tokenno.
1115 : : */
1116 : :
1117 : 0 : extern "C" NameKey_Name M2LexBuf_GetTokenName (unsigned int tokenno)
1118 : : {
1119 : 0 : M2LexBuf_TokenDesc tokdesc;
1120 : 0 : NameKey_Name name;
1121 : :
1122 : 0 : if (Indexing_InBounds (ListOfTokens, tokenno))
1123 : : {
1124 : 0 : tokdesc = static_cast<M2LexBuf_TokenDesc> (Indexing_GetIndice (ListOfTokens, tokenno));
1125 : 0 : name = M2Reserved_tokToTok (tokdesc->token);
1126 : 0 : if (name == NameKey_NulName)
1127 : : {
1128 : 0 : return tokdesc->str;
1129 : : }
1130 : : else
1131 : : {
1132 : : return name;
1133 : : }
1134 : : }
1135 : : return NameKey_NulName;
1136 : : /* static analysis guarentees a RETURN statement will be used before here. */
1137 : : __builtin_unreachable ();
1138 : : }
1139 : :
1140 : :
1141 : : /*
1142 : : TokenToLineNo - returns the line number of the current file for the
1143 : : tokenno. The depth refers to the include depth.
1144 : : A depth of 0 is the current file, depth of 1 is the file
1145 : : which included the current file. Zero is returned if the
1146 : : depth exceeds the file nesting level.
1147 : : */
1148 : :
1149 : 7097426 : extern "C" unsigned int M2LexBuf_TokenToLineNo (unsigned int tokenno, unsigned int depth)
1150 : : {
1151 : 7097426 : M2LexBuf_TokenDesc tokdesc;
1152 : 7097426 : M2LexBuf_SourceList level;
1153 : :
1154 : 7097426 : if ((tokenno != M2LexBuf_UnknownTokenNo) && (tokenno != M2LexBuf_BuiltinTokenNo))
1155 : : {
1156 : 7097426 : if (Indexing_InBounds (ListOfTokens, tokenno))
1157 : : {
1158 : 7097426 : tokdesc = static_cast<M2LexBuf_TokenDesc> (Indexing_GetIndice (ListOfTokens, tokenno));
1159 : 7097426 : if (depth == 0)
1160 : : {
1161 : 7097426 : return tokdesc->line;
1162 : : }
1163 : : else
1164 : : {
1165 : 0 : level = tokdesc->file->left;
1166 : 0 : while (depth > 0)
1167 : : {
1168 : 0 : level = level->left;
1169 : 0 : if (level == tokdesc->file->left)
1170 : : {
1171 : : return 0;
1172 : : }
1173 : 0 : depth -= 1;
1174 : : }
1175 : 0 : return level->line;
1176 : : }
1177 : : }
1178 : : }
1179 : : return 0;
1180 : : /* static analysis guarentees a RETURN statement will be used before here. */
1181 : : __builtin_unreachable ();
1182 : : }
1183 : :
1184 : :
1185 : : /*
1186 : : GetColumnNo - returns the current column where the symbol occurs in
1187 : : the source file.
1188 : : */
1189 : :
1190 : 0 : extern "C" unsigned int M2LexBuf_GetColumnNo (void)
1191 : : {
1192 : 0 : if (CurrentTokNo == 0)
1193 : : {
1194 : : return 0;
1195 : : }
1196 : : else
1197 : : {
1198 : 0 : return M2LexBuf_TokenToColumnNo (M2LexBuf_GetTokenNo (), 0);
1199 : : }
1200 : : /* static analysis guarentees a RETURN statement will be used before here. */
1201 : : __builtin_unreachable ();
1202 : : }
1203 : :
1204 : :
1205 : : /*
1206 : : TokenToColumnNo - returns the column number of the current file for the
1207 : : tokenno. The depth refers to the include depth.
1208 : : A depth of 0 is the current file, depth of 1 is the file
1209 : : which included the current file. Zero is returned if the
1210 : : depth exceeds the file nesting level.
1211 : : */
1212 : :
1213 : 12183 : extern "C" unsigned int M2LexBuf_TokenToColumnNo (unsigned int tokenno, unsigned int depth)
1214 : : {
1215 : 12183 : M2LexBuf_TokenDesc tokdesc;
1216 : 12183 : M2LexBuf_SourceList level;
1217 : :
1218 : 12183 : if ((tokenno != M2LexBuf_UnknownTokenNo) && (tokenno != M2LexBuf_BuiltinTokenNo))
1219 : : {
1220 : 12183 : if (Indexing_InBounds (ListOfTokens, tokenno))
1221 : : {
1222 : 12183 : tokdesc = static_cast<M2LexBuf_TokenDesc> (Indexing_GetIndice (ListOfTokens, tokenno));
1223 : 12183 : if (depth == 0)
1224 : : {
1225 : 12183 : return tokdesc->col;
1226 : : }
1227 : : else
1228 : : {
1229 : 0 : level = tokdesc->file->left;
1230 : 0 : while (depth > 0)
1231 : : {
1232 : 0 : level = level->left;
1233 : 0 : if (level == tokdesc->file->left)
1234 : : {
1235 : : return 0;
1236 : : }
1237 : 0 : depth -= 1;
1238 : : }
1239 : 0 : return level->col;
1240 : : }
1241 : : }
1242 : : }
1243 : : return 0;
1244 : : /* static analysis guarentees a RETURN statement will be used before here. */
1245 : : __builtin_unreachable ();
1246 : : }
1247 : :
1248 : :
1249 : : /*
1250 : : TokenToLocation - returns the location_t corresponding to tokenno.
1251 : : */
1252 : :
1253 : 35522538 : extern "C" location_t M2LexBuf_TokenToLocation (unsigned int tokenno)
1254 : : {
1255 : 35522538 : M2LexBuf_TokenDesc tokdesc;
1256 : :
1257 : 35522538 : if (tokenno == M2LexBuf_UnknownTokenNo)
1258 : : {
1259 : 10138586 : return M2Emit_UnknownLocation ();
1260 : : }
1261 : 25383952 : else if (tokenno == M2LexBuf_BuiltinTokenNo)
1262 : : {
1263 : : /* avoid dangling else. */
1264 : 277990 : return M2Emit_BuiltinsLocation ();
1265 : : }
1266 : 25105962 : else if (Indexing_InBounds (ListOfTokens, tokenno))
1267 : : {
1268 : : /* avoid dangling else. */
1269 : 25105962 : tokdesc = static_cast<M2LexBuf_TokenDesc> (Indexing_GetIndice (ListOfTokens, tokenno));
1270 : 25105962 : return tokdesc->loc;
1271 : : }
1272 : 0 : return M2Emit_UnknownLocation ();
1273 : : /* static analysis guarentees a RETURN statement will be used before here. */
1274 : : __builtin_unreachable ();
1275 : : }
1276 : :
1277 : :
1278 : : /*
1279 : : FindFileNameFromToken - returns the complete FileName for the appropriate
1280 : : source file yields the token number, TokenNo.
1281 : : The, Depth, indicates the include level: 0..n
1282 : : Level 0 is the current. NIL is returned if n+1
1283 : : is requested.
1284 : : */
1285 : :
1286 : 596910 : extern "C" DynamicStrings_String M2LexBuf_FindFileNameFromToken (unsigned int tokenno, unsigned int depth)
1287 : : {
1288 : 596910 : M2LexBuf_TokenDesc tokdesc;
1289 : 596910 : M2LexBuf_SourceList level;
1290 : :
1291 : 596910 : if ((tokenno != M2LexBuf_UnknownTokenNo) && (tokenno != M2LexBuf_BuiltinTokenNo))
1292 : : {
1293 : 596762 : if (Indexing_InBounds (ListOfTokens, tokenno))
1294 : : {
1295 : 596762 : tokdesc = static_cast<M2LexBuf_TokenDesc> (Indexing_GetIndice (ListOfTokens, tokenno));
1296 : 596762 : level = tokdesc->file->left;
1297 : 600451 : while (depth > 0)
1298 : : {
1299 : 3689 : level = level->left;
1300 : 3689 : if (level == tokdesc->file->left)
1301 : : {
1302 : : return static_cast<DynamicStrings_String> (NULL);
1303 : : }
1304 : 3689 : depth -= 1;
1305 : : }
1306 : 596762 : return level->name;
1307 : : }
1308 : : }
1309 : : return static_cast<DynamicStrings_String> (NULL);
1310 : : /* static analysis guarentees a RETURN statement will be used before here. */
1311 : : __builtin_unreachable ();
1312 : : }
1313 : :
1314 : :
1315 : : /*
1316 : : GetFileName - returns a String defining the current file.
1317 : : */
1318 : :
1319 : 580890 : extern "C" DynamicStrings_String M2LexBuf_GetFileName (void)
1320 : : {
1321 : 580890 : return M2LexBuf_FindFileNameFromToken (M2LexBuf_GetTokenNo (), 0);
1322 : : /* static analysis guarentees a RETURN statement will be used before here. */
1323 : : __builtin_unreachable ();
1324 : : }
1325 : :
1326 : :
1327 : : /*
1328 : : MakeVirtualTok - providing caret, left, right are associated with a source file
1329 : : and exist on the same src line then
1330 : : create and return a new tokenno which is created from
1331 : : tokenno left and right. Otherwise return caret.
1332 : : If caret is UnknownTokenNo then it is replaced with left or right
1333 : : in sequence to avoid an UnknownTokenNo.
1334 : : */
1335 : :
1336 : 2164347 : extern "C" unsigned int M2LexBuf_MakeVirtualTok (unsigned int caret, unsigned int left, unsigned int right)
1337 : : {
1338 : 2164347 : M2LexBuf_TokenDesc descLeft;
1339 : 2164347 : M2LexBuf_TokenDesc descRight;
1340 : 2164347 : location_t lc;
1341 : 2164347 : location_t ll;
1342 : 2164347 : location_t lr;
1343 : :
1344 : 2164347 : if (caret == M2LexBuf_UnknownTokenNo)
1345 : : {
1346 : 56960 : caret = left;
1347 : : }
1348 : 56960 : if (caret == M2LexBuf_UnknownTokenNo)
1349 : : {
1350 : 38466 : caret = right;
1351 : : }
1352 : 2164347 : if (((isSrcToken (caret)) && (isSrcToken (left))) && (isSrcToken (right)))
1353 : : {
1354 : 1899642 : lc = M2LexBuf_TokenToLocation (caret);
1355 : 1899642 : ll = M2LexBuf_TokenToLocation (left);
1356 : 1899642 : lr = M2LexBuf_TokenToLocation (right);
1357 : 1899642 : if ((Indexing_InBounds (ListOfTokens, left)) && (Indexing_InBounds (ListOfTokens, right)))
1358 : : {
1359 : 1899642 : descLeft = static_cast<M2LexBuf_TokenDesc> (Indexing_GetIndice (ListOfTokens, left));
1360 : 1899642 : descRight = static_cast<M2LexBuf_TokenDesc> (Indexing_GetIndice (ListOfTokens, right));
1361 : 1899642 : if ((descLeft->line == descRight->line) && (descLeft->file == descRight->file))
1362 : : {
1363 : : /* On the same line, create a new token and location. */
1364 : 1895438 : AddTokToList (M2Reserved_virtualrangetok, NameKey_NulName, 0, descLeft->line, descLeft->col, descLeft->file, m2linemap_GetLocationBinary (lc, ll, lr));
1365 : 1895438 : caret = Indexing_HighIndice (ListOfTokens);
1366 : : }
1367 : : }
1368 : : }
1369 : 2164347 : if (caret == BadTokenNo)
1370 : : {
1371 : 2164347 : stop ();
1372 : : }
1373 : 2164347 : return caret;
1374 : : /* static analysis guarentees a RETURN statement will be used before here. */
1375 : : __builtin_unreachable ();
1376 : : }
1377 : :
1378 : :
1379 : : /*
1380 : : MakeVirtual2Tok - creates and return a new tokenno which is created from
1381 : : two tokens left and right. It tries to avoid UnknownTokenNo
1382 : : and will fall back to left or right if necessary.
1383 : : */
1384 : :
1385 : 286324 : extern "C" unsigned int M2LexBuf_MakeVirtual2Tok (unsigned int left, unsigned int right)
1386 : : {
1387 : 286324 : if (left == M2LexBuf_UnknownTokenNo)
1388 : : {
1389 : : left = right;
1390 : : }
1391 : 286184 : else if (right == M2LexBuf_UnknownTokenNo)
1392 : : {
1393 : : /* avoid dangling else. */
1394 : 18333 : right = left;
1395 : : }
1396 : 286324 : return M2LexBuf_MakeVirtualTok (left, left, right);
1397 : : /* static analysis guarentees a RETURN statement will be used before here. */
1398 : : __builtin_unreachable ();
1399 : : }
1400 : :
1401 : :
1402 : : /*
1403 : : AddTok - adds a token to the buffer.
1404 : : */
1405 : :
1406 : 67304710 : extern "C" void M2LexBuf_AddTok (M2Reserved_toktype t)
1407 : : {
1408 : 67304710 : DynamicStrings_String s;
1409 : :
1410 : 67304710 : if (Tracing)
1411 : : {
1412 : : M2Printf_printf0 ((const char *) " m2.flex -> AddTok ", 19);
1413 : : M2LexBuf_DisplayToken (t);
1414 : : M2Printf_printf0 ((const char *) "\\n", 2);
1415 : : }
1416 : 67304710 : if ((t == M2Reserved_eoftok) && SeenEof)
1417 : : {
1418 : : /* avoid dangling else. */
1419 : : if (Debugging)
1420 : : {
1421 : : M2Printf_printf0 ((const char *) "extra eoftok ignored as buffer already contains eoftok\\n", 56);
1422 : : }
1423 : : }
1424 : : else
1425 : : {
1426 : 67117228 : if (Debugging)
1427 : : {
1428 : : M2Printf_printf0 ((const char *) "adding token: ", 14);
1429 : : M2LexBuf_DisplayToken (t);
1430 : : M2Printf_printf0 ((const char *) "\\n", 2);
1431 : : }
1432 : 67117228 : AddTokToList (t, NameKey_NulName, 0, m2flex_GetLineNo (), m2flex_GetColumnNo (), CurrentSource, m2flex_GetLocation ());
1433 : 67117228 : CurrentUsed = true;
1434 : 67117228 : if (Debugging)
1435 : : {
1436 : : /* display each token as a warning. */
1437 : : s = DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (M2LexBuf_GetTokenName (M2LexBuf_GetTokenNo ())));
1438 : : M2Error_WarnStringAt (s, M2LexBuf_GetTokenNo ());
1439 : : }
1440 : 67117228 : if (t == M2Reserved_eoftok)
1441 : : {
1442 : 187470 : SeenEof = true;
1443 : : }
1444 : : }
1445 : 67304710 : }
1446 : :
1447 : :
1448 : : /*
1449 : : AddTokCharStar - adds a token to the buffer and an additional string, s.
1450 : : A copy of string, s, is made.
1451 : : */
1452 : :
1453 : 43664074 : extern "C" void M2LexBuf_AddTokCharStar (M2Reserved_toktype t, void * s)
1454 : : {
1455 : 43664074 : DynamicStrings_String str;
1456 : :
1457 : 43664074 : M2Debug_Assert (t != M2Reserved_eoftok);
1458 : 43664074 : if (Tracing)
1459 : : {
1460 : : M2Printf_printf0 ((const char *) " m2.flex -> AddTokCharStar ", 27);
1461 : : M2LexBuf_DisplayToken (t);
1462 : : str = DynamicStrings_InitStringCharStar (s);
1463 : : M2Printf_printf1 ((const char *) " %s\\n", 5, (const unsigned char *) &str, (sizeof (str)-1));
1464 : : str = DynamicStrings_KillString (str);
1465 : : }
1466 : 43664074 : if (Debugging)
1467 : : {
1468 : : M2Printf_printf0 ((const char *) "AddTokCharStar: ", 16);
1469 : : M2LexBuf_DisplayToken (t);
1470 : : M2Printf_printf0 ((const char *) "\\n", 2);
1471 : : }
1472 : 43664074 : AddTokToList (t, NameKey_makekey (s), 0, m2flex_GetLineNo (), m2flex_GetColumnNo (), CurrentSource, m2flex_GetLocation ());
1473 : 43664074 : CurrentUsed = true;
1474 : 43664074 : }
1475 : :
1476 : :
1477 : : /*
1478 : : AddTokInteger - adds a token and an integer to the buffer.
1479 : : */
1480 : :
1481 : 135540 : extern "C" void M2LexBuf_AddTokInteger (M2Reserved_toktype t, int i)
1482 : : {
1483 : 135540 : DynamicStrings_String s;
1484 : 135540 : unsigned int c;
1485 : 135540 : unsigned int l;
1486 : :
1487 : 135540 : M2Debug_Assert (t != M2Reserved_eoftok);
1488 : 135540 : if (Tracing)
1489 : : {
1490 : : M2Printf_printf0 ((const char *) " m2.flex -> AddTokInteger ", 26);
1491 : : M2LexBuf_DisplayToken (t);
1492 : : M2Printf_printf1 ((const char *) " %d\\n", 5, (const unsigned char *) &i, (sizeof (i)-1));
1493 : : }
1494 : 135540 : l = m2flex_GetLineNo ();
1495 : 135540 : c = m2flex_GetColumnNo ();
1496 : 135540 : s = FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "%d", 2)), (const unsigned char *) &i, (sizeof (i)-1));
1497 : 135540 : AddTokToList (t, NameKey_makekey (DynamicStrings_string (s)), i, l, c, CurrentSource, m2flex_GetLocation ());
1498 : 135540 : s = DynamicStrings_KillString (s);
1499 : 135540 : CurrentUsed = true;
1500 : 135540 : }
1501 : :
1502 : :
1503 : : /*
1504 : : SetFile - sets the current filename to, filename.
1505 : : */
1506 : :
1507 : 230281 : extern "C" void M2LexBuf_SetFile (void * filename)
1508 : : {
1509 : 230281 : KillList ();
1510 : 230281 : CurrentUsed = false;
1511 : 230281 : CurrentSource = NewList ();
1512 : 230281 : AddTo (NewElement (filename));
1513 : 230281 : }
1514 : :
1515 : :
1516 : : /*
1517 : : PushFile - indicates that, filename, has just been included.
1518 : : */
1519 : :
1520 : 0 : extern "C" void M2LexBuf_PushFile (void * filename)
1521 : : {
1522 : 0 : M2LexBuf_SourceList l;
1523 : :
1524 : 0 : CheckIfNeedToDuplicate ();
1525 : 0 : AddTo (NewElement (filename));
1526 : 0 : if (Debugging)
1527 : : {
1528 : : if (CurrentSource->right != CurrentSource)
1529 : : {
1530 : : l = CurrentSource;
1531 : : do {
1532 : : M2Printf_printf3 ((const char *) "name = %s, line = %d, col = %d\\n", 32, (const unsigned char *) &l->name, (sizeof (l->name)-1), (const unsigned char *) &l->line, (sizeof (l->line)-1), (const unsigned char *) &l->col, (sizeof (l->col)-1));
1533 : : l = l->right;
1534 : : } while (! (l == CurrentSource));
1535 : : }
1536 : : }
1537 : 0 : }
1538 : :
1539 : :
1540 : : /*
1541 : : PopFile - indicates that we are returning to, filename, having finished
1542 : : an include.
1543 : : */
1544 : :
1545 : 0 : extern "C" void M2LexBuf_PopFile (void * filename)
1546 : : {
1547 : 0 : M2LexBuf_SourceList l;
1548 : :
1549 : 0 : CheckIfNeedToDuplicate ();
1550 : 0 : if ((CurrentSource != NULL) && (CurrentSource->left != CurrentSource))
1551 : : {
1552 : : /* avoid dangling else. */
1553 : 0 : l = CurrentSource->left; /* last element */
1554 : 0 : SubFrom (l); /* last element */
1555 : 0 : Storage_DEALLOCATE ((void **) &l, sizeof (M2LexBuf__T1));
1556 : 0 : if ((CurrentSource->left != CurrentSource) && (! (DynamicStrings_Equal (CurrentSource->name, DynamicStrings_Mark (DynamicStrings_InitStringCharStar (filename))))))
1557 : : {} /* empty. */
1558 : : /* mismatch in source file names after preprocessing files */
1559 : : }
1560 : : /* source file list is empty, cannot pop an include.. */
1561 : 0 : }
1562 : :
1563 : :
1564 : : /*
1565 : : PrintTokenNo - displays token and the location of the token.
1566 : : */
1567 : :
1568 : 0 : extern "C" void M2LexBuf_PrintTokenNo (unsigned int tokenno)
1569 : : {
1570 : 0 : DynamicStrings_String s;
1571 : :
1572 : 0 : M2Printf_printf1 ((const char *) "tokenno = %d, ", 14, (const unsigned char *) &tokenno, (sizeof (tokenno)-1));
1573 : 0 : s = DynamicStrings_InitStringCharStar (NameKey_KeyToCharStar (M2LexBuf_GetTokenName (tokenno)));
1574 : 0 : M2Printf_printf1 ((const char *) "%s\\n", 4, (const unsigned char *) &s, (sizeof (s)-1));
1575 : 0 : s = DynamicStrings_KillString (s);
1576 : 0 : }
1577 : :
1578 : :
1579 : : /*
1580 : : DisplayToken - display the token name using printf0 no newline is emitted.
1581 : : */
1582 : :
1583 : 0 : extern "C" void M2LexBuf_DisplayToken (M2Reserved_toktype tok)
1584 : : {
1585 : 0 : switch (tok)
1586 : : {
1587 : 0 : case M2Reserved_eoftok:
1588 : 0 : M2Printf_printf0 ((const char *) "eoftok", 6);
1589 : 0 : break;
1590 : :
1591 : 0 : case M2Reserved_plustok:
1592 : 0 : M2Printf_printf0 ((const char *) "plustok", 7);
1593 : 0 : break;
1594 : :
1595 : 0 : case M2Reserved_minustok:
1596 : 0 : M2Printf_printf0 ((const char *) "minustok", 8);
1597 : 0 : break;
1598 : :
1599 : 0 : case M2Reserved_timestok:
1600 : 0 : M2Printf_printf0 ((const char *) "timestok", 8);
1601 : 0 : break;
1602 : :
1603 : 0 : case M2Reserved_dividetok:
1604 : 0 : M2Printf_printf0 ((const char *) "dividetok", 9);
1605 : 0 : break;
1606 : :
1607 : 0 : case M2Reserved_becomestok:
1608 : 0 : M2Printf_printf0 ((const char *) "becomestok", 10);
1609 : 0 : break;
1610 : :
1611 : 0 : case M2Reserved_ambersandtok:
1612 : 0 : M2Printf_printf0 ((const char *) "ambersandtok", 12);
1613 : 0 : break;
1614 : :
1615 : 0 : case M2Reserved_periodtok:
1616 : 0 : M2Printf_printf0 ((const char *) "periodtok", 9);
1617 : 0 : break;
1618 : :
1619 : 0 : case M2Reserved_commatok:
1620 : 0 : M2Printf_printf0 ((const char *) "commatok", 8);
1621 : 0 : break;
1622 : :
1623 : 0 : case M2Reserved_semicolontok:
1624 : 0 : M2Printf_printf0 ((const char *) "semicolontok", 12);
1625 : 0 : break;
1626 : :
1627 : 0 : case M2Reserved_lparatok:
1628 : 0 : M2Printf_printf0 ((const char *) "lparatok", 8);
1629 : 0 : break;
1630 : :
1631 : 0 : case M2Reserved_rparatok:
1632 : 0 : M2Printf_printf0 ((const char *) "rparatok", 8);
1633 : 0 : break;
1634 : :
1635 : 0 : case M2Reserved_lsbratok:
1636 : 0 : M2Printf_printf0 ((const char *) "lsbratok", 8);
1637 : 0 : break;
1638 : :
1639 : 0 : case M2Reserved_rsbratok:
1640 : 0 : M2Printf_printf0 ((const char *) "rsbratok", 8);
1641 : 0 : break;
1642 : :
1643 : 0 : case M2Reserved_lcbratok:
1644 : 0 : M2Printf_printf0 ((const char *) "lcbratok", 8);
1645 : 0 : break;
1646 : :
1647 : 0 : case M2Reserved_rcbratok:
1648 : 0 : M2Printf_printf0 ((const char *) "rcbratok", 8);
1649 : 0 : break;
1650 : :
1651 : 0 : case M2Reserved_uparrowtok:
1652 : 0 : M2Printf_printf0 ((const char *) "uparrowtok", 10);
1653 : 0 : break;
1654 : :
1655 : 0 : case M2Reserved_singlequotetok:
1656 : 0 : M2Printf_printf0 ((const char *) "singlequotetok", 14);
1657 : 0 : break;
1658 : :
1659 : 0 : case M2Reserved_equaltok:
1660 : 0 : M2Printf_printf0 ((const char *) "equaltok", 8);
1661 : 0 : break;
1662 : :
1663 : 0 : case M2Reserved_hashtok:
1664 : 0 : M2Printf_printf0 ((const char *) "hashtok", 7);
1665 : 0 : break;
1666 : :
1667 : 0 : case M2Reserved_lesstok:
1668 : 0 : M2Printf_printf0 ((const char *) "lesstok", 7);
1669 : 0 : break;
1670 : :
1671 : 0 : case M2Reserved_greatertok:
1672 : 0 : M2Printf_printf0 ((const char *) "greatertok", 10);
1673 : 0 : break;
1674 : :
1675 : 0 : case M2Reserved_lessgreatertok:
1676 : 0 : M2Printf_printf0 ((const char *) "lessgreatertok", 14);
1677 : 0 : break;
1678 : :
1679 : 0 : case M2Reserved_lessequaltok:
1680 : 0 : M2Printf_printf0 ((const char *) "lessequaltok", 12);
1681 : 0 : break;
1682 : :
1683 : 0 : case M2Reserved_greaterequaltok:
1684 : 0 : M2Printf_printf0 ((const char *) "greaterequaltok", 15);
1685 : 0 : break;
1686 : :
1687 : 0 : case M2Reserved_periodperiodtok:
1688 : 0 : M2Printf_printf0 ((const char *) "periodperiodtok", 15);
1689 : 0 : break;
1690 : :
1691 : 0 : case M2Reserved_colontok:
1692 : 0 : M2Printf_printf0 ((const char *) "colontok", 8);
1693 : 0 : break;
1694 : :
1695 : 0 : case M2Reserved_doublequotestok:
1696 : 0 : M2Printf_printf0 ((const char *) "doublequotestok", 15);
1697 : 0 : break;
1698 : :
1699 : 0 : case M2Reserved_bartok:
1700 : 0 : M2Printf_printf0 ((const char *) "bartok", 6);
1701 : 0 : break;
1702 : :
1703 : 0 : case M2Reserved_andtok:
1704 : 0 : M2Printf_printf0 ((const char *) "andtok", 6);
1705 : 0 : break;
1706 : :
1707 : 0 : case M2Reserved_arraytok:
1708 : 0 : M2Printf_printf0 ((const char *) "arraytok", 8);
1709 : 0 : break;
1710 : :
1711 : 0 : case M2Reserved_begintok:
1712 : 0 : M2Printf_printf0 ((const char *) "begintok", 8);
1713 : 0 : break;
1714 : :
1715 : 0 : case M2Reserved_bytok:
1716 : 0 : M2Printf_printf0 ((const char *) "bytok", 5);
1717 : 0 : break;
1718 : :
1719 : 0 : case M2Reserved_casetok:
1720 : 0 : M2Printf_printf0 ((const char *) "casetok", 7);
1721 : 0 : break;
1722 : :
1723 : 0 : case M2Reserved_consttok:
1724 : 0 : M2Printf_printf0 ((const char *) "consttok", 8);
1725 : 0 : break;
1726 : :
1727 : 0 : case M2Reserved_definitiontok:
1728 : 0 : M2Printf_printf0 ((const char *) "definitiontok", 13);
1729 : 0 : break;
1730 : :
1731 : 0 : case M2Reserved_divtok:
1732 : 0 : M2Printf_printf0 ((const char *) "divtok", 6);
1733 : 0 : break;
1734 : :
1735 : 0 : case M2Reserved_dotok:
1736 : 0 : M2Printf_printf0 ((const char *) "dotok", 5);
1737 : 0 : break;
1738 : :
1739 : 0 : case M2Reserved_elsetok:
1740 : 0 : M2Printf_printf0 ((const char *) "elsetok", 7);
1741 : 0 : break;
1742 : :
1743 : 0 : case M2Reserved_elsiftok:
1744 : 0 : M2Printf_printf0 ((const char *) "elsiftok", 8);
1745 : 0 : break;
1746 : :
1747 : 0 : case M2Reserved_endtok:
1748 : 0 : M2Printf_printf0 ((const char *) "endtok", 6);
1749 : 0 : break;
1750 : :
1751 : 0 : case M2Reserved_exittok:
1752 : 0 : M2Printf_printf0 ((const char *) "exittok", 7);
1753 : 0 : break;
1754 : :
1755 : 0 : case M2Reserved_exporttok:
1756 : 0 : M2Printf_printf0 ((const char *) "exporttok", 9);
1757 : 0 : break;
1758 : :
1759 : 0 : case M2Reserved_fortok:
1760 : 0 : M2Printf_printf0 ((const char *) "fortok", 6);
1761 : 0 : break;
1762 : :
1763 : 0 : case M2Reserved_fromtok:
1764 : 0 : M2Printf_printf0 ((const char *) "fromtok", 7);
1765 : 0 : break;
1766 : :
1767 : 0 : case M2Reserved_iftok:
1768 : 0 : M2Printf_printf0 ((const char *) "iftok", 5);
1769 : 0 : break;
1770 : :
1771 : 0 : case M2Reserved_implementationtok:
1772 : 0 : M2Printf_printf0 ((const char *) "implementationtok", 17);
1773 : 0 : break;
1774 : :
1775 : 0 : case M2Reserved_importtok:
1776 : 0 : M2Printf_printf0 ((const char *) "importtok", 9);
1777 : 0 : break;
1778 : :
1779 : 0 : case M2Reserved_intok:
1780 : 0 : M2Printf_printf0 ((const char *) "intok", 5);
1781 : 0 : break;
1782 : :
1783 : 0 : case M2Reserved_looptok:
1784 : 0 : M2Printf_printf0 ((const char *) "looptok", 7);
1785 : 0 : break;
1786 : :
1787 : 0 : case M2Reserved_modtok:
1788 : 0 : M2Printf_printf0 ((const char *) "modtok", 6);
1789 : 0 : break;
1790 : :
1791 : 0 : case M2Reserved_moduletok:
1792 : 0 : M2Printf_printf0 ((const char *) "moduletok", 9);
1793 : 0 : break;
1794 : :
1795 : 0 : case M2Reserved_nottok:
1796 : 0 : M2Printf_printf0 ((const char *) "nottok", 6);
1797 : 0 : break;
1798 : :
1799 : 0 : case M2Reserved_oftok:
1800 : 0 : M2Printf_printf0 ((const char *) "oftok", 5);
1801 : 0 : break;
1802 : :
1803 : 0 : case M2Reserved_ortok:
1804 : 0 : M2Printf_printf0 ((const char *) "ortok", 5);
1805 : 0 : break;
1806 : :
1807 : 0 : case M2Reserved_pointertok:
1808 : 0 : M2Printf_printf0 ((const char *) "pointertok", 10);
1809 : 0 : break;
1810 : :
1811 : 0 : case M2Reserved_proceduretok:
1812 : 0 : M2Printf_printf0 ((const char *) "proceduretok", 12);
1813 : 0 : break;
1814 : :
1815 : 0 : case M2Reserved_qualifiedtok:
1816 : 0 : M2Printf_printf0 ((const char *) "qualifiedtok", 12);
1817 : 0 : break;
1818 : :
1819 : 0 : case M2Reserved_unqualifiedtok:
1820 : 0 : M2Printf_printf0 ((const char *) "unqualifiedtok", 14);
1821 : 0 : break;
1822 : :
1823 : 0 : case M2Reserved_recordtok:
1824 : 0 : M2Printf_printf0 ((const char *) "recordtok", 9);
1825 : 0 : break;
1826 : :
1827 : 0 : case M2Reserved_repeattok:
1828 : 0 : M2Printf_printf0 ((const char *) "repeattok", 9);
1829 : 0 : break;
1830 : :
1831 : 0 : case M2Reserved_returntok:
1832 : 0 : M2Printf_printf0 ((const char *) "returntok", 9);
1833 : 0 : break;
1834 : :
1835 : 0 : case M2Reserved_settok:
1836 : 0 : M2Printf_printf0 ((const char *) "settok", 6);
1837 : 0 : break;
1838 : :
1839 : 0 : case M2Reserved_thentok:
1840 : 0 : M2Printf_printf0 ((const char *) "thentok", 7);
1841 : 0 : break;
1842 : :
1843 : 0 : case M2Reserved_totok:
1844 : 0 : M2Printf_printf0 ((const char *) "totok", 5);
1845 : 0 : break;
1846 : :
1847 : 0 : case M2Reserved_typetok:
1848 : 0 : M2Printf_printf0 ((const char *) "typetok", 7);
1849 : 0 : break;
1850 : :
1851 : 0 : case M2Reserved_untiltok:
1852 : 0 : M2Printf_printf0 ((const char *) "untiltok", 8);
1853 : 0 : break;
1854 : :
1855 : 0 : case M2Reserved_vartok:
1856 : 0 : M2Printf_printf0 ((const char *) "vartok", 6);
1857 : 0 : break;
1858 : :
1859 : 0 : case M2Reserved_whiletok:
1860 : 0 : M2Printf_printf0 ((const char *) "whiletok", 8);
1861 : 0 : break;
1862 : :
1863 : 0 : case M2Reserved_withtok:
1864 : 0 : M2Printf_printf0 ((const char *) "withtok", 7);
1865 : 0 : break;
1866 : :
1867 : 0 : case M2Reserved_asmtok:
1868 : 0 : M2Printf_printf0 ((const char *) "asmtok", 6);
1869 : 0 : break;
1870 : :
1871 : 0 : case M2Reserved_volatiletok:
1872 : 0 : M2Printf_printf0 ((const char *) "volatiletok", 11);
1873 : 0 : break;
1874 : :
1875 : 0 : case M2Reserved_periodperiodperiodtok:
1876 : 0 : M2Printf_printf0 ((const char *) "periodperiodperiodtok", 21);
1877 : 0 : break;
1878 : :
1879 : 0 : case M2Reserved_datetok:
1880 : 0 : M2Printf_printf0 ((const char *) "datetok", 7);
1881 : 0 : break;
1882 : :
1883 : 0 : case M2Reserved_linetok:
1884 : 0 : M2Printf_printf0 ((const char *) "linetok", 7);
1885 : 0 : break;
1886 : :
1887 : 0 : case M2Reserved_filetok:
1888 : 0 : M2Printf_printf0 ((const char *) "filetok", 7);
1889 : 0 : break;
1890 : :
1891 : 0 : case M2Reserved_integertok:
1892 : 0 : M2Printf_printf0 ((const char *) "integertok", 10);
1893 : 0 : break;
1894 : :
1895 : 0 : case M2Reserved_identtok:
1896 : 0 : M2Printf_printf0 ((const char *) "identtok", 8);
1897 : 0 : break;
1898 : :
1899 : 0 : case M2Reserved_realtok:
1900 : 0 : M2Printf_printf0 ((const char *) "realtok", 7);
1901 : 0 : break;
1902 : :
1903 : 0 : case M2Reserved_stringtok:
1904 : 0 : M2Printf_printf0 ((const char *) "stringtok", 9);
1905 : 0 : break;
1906 : :
1907 : :
1908 : : default:
1909 : : break;
1910 : : }
1911 : 0 : }
1912 : :
1913 : :
1914 : : /*
1915 : : DumpTokens - displays all tokens.
1916 : : */
1917 : :
1918 : 0 : extern "C" void M2LexBuf_DumpTokens (void)
1919 : : {
1920 : 0 : unsigned int high;
1921 : 0 : unsigned int ind;
1922 : :
1923 : 0 : if (Indexing_IsEmpty (ListOfTokens))
1924 : : {
1925 : 0 : M2Printf_printf0 ((const char *) "The token buffer is empty\\n", 27);
1926 : : }
1927 : : else
1928 : : {
1929 : 0 : ind = Indexing_LowIndice (ListOfTokens);
1930 : 0 : high = Indexing_HighIndice (ListOfTokens);
1931 : 0 : while (ind <= high)
1932 : : {
1933 : 0 : M2Printf_printf1 ((const char *) "%5d ", 4, (const unsigned char *) &ind, (sizeof (ind)-1));
1934 : 0 : DumpToken (reinterpret_cast <M2LexBuf_TokenDesc> (Indexing_GetIndice (ListOfTokens, ind)));
1935 : 0 : ind += 1;
1936 : : }
1937 : : }
1938 : 0 : }
1939 : :
1940 : 15260 : extern "C" void _M2_M2LexBuf_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
1941 : : {
1942 : 15260 : Init ();
1943 : 15260 : }
1944 : :
1945 : 0 : extern "C" void _M2_M2LexBuf_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
1946 : : {
1947 : 0 : }
|