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