]> gcc.gnu.org Git - gcc.git/blame - gcc/m2/mc-boot/GmcLexBuf.c
Remove unused parameter warning via introducing attribute unused.
[gcc.git] / gcc / m2 / mc-boot / GmcLexBuf.c
CommitLineData
7401123f
GM
1/* do not edit automatically generated by mc from mcLexBuf. */
2/* mcLexBuf.mod provides a buffer for the all the tokens created by m2.lex.
3
51bc4b81 4Copyright (C) 2015-2022 Free Software Foundation, Inc.
7401123f
GM
5Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6
7This file is part of GNU Modula-2.
8
9GNU Modula-2 is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 3, or (at your option)
12any later version.
13
14GNU Modula-2 is distributed in the hope that it will be useful, but
15WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along 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# if !defined (PROC_D)
26# define PROC_D
27 typedef void (*PROC_t) (void);
28 typedef struct { PROC_t proc; } PROC;
29# endif
30
31# if !defined (TRUE)
32# define TRUE (1==1)
33# endif
34
35# if !defined (FALSE)
36# define FALSE (1==0)
37# endif
38
39# include "GStorage.h"
40#if defined(__cplusplus)
41# undef NULL
42# define NULL 0
43#endif
44#define _mcLexBuf_H
45#define _mcLexBuf_C
46
47# include "Gmcflex.h"
48# include "Glibc.h"
49# include "GSYSTEM.h"
50# include "GStorage.h"
51# include "GDynamicStrings.h"
52# include "GFormatStrings.h"
53# include "GnameKey.h"
54# include "GmcReserved.h"
55# include "GmcComment.h"
56# include "GmcPrintf.h"
57# include "GmcDebug.h"
58# include "GM2RTS.h"
59
60mcComment_commentDesc mcLexBuf_currentcomment;
61mcComment_commentDesc mcLexBuf_lastcomment;
62int mcLexBuf_currentinteger;
63unsigned int mcLexBuf_currentcolumn;
64void * mcLexBuf_currentstring;
65mcReserved_toktype mcLexBuf_currenttoken;
66# define MaxBucketSize 100
67# define Debugging FALSE
68typedef struct tokenDesc_r tokenDesc;
69
70typedef struct listDesc_r listDesc;
71
72typedef struct _T1_r _T1;
73
74typedef _T1 *sourceList;
75
76typedef struct _T2_r _T2;
77
78typedef _T2 *tokenBucket;
79
80typedef struct _T3_a _T3;
81
82struct tokenDesc_r {
83 mcReserved_toktype token;
84 nameKey_Name str;
85 int int_;
86 mcComment_commentDesc com;
87 unsigned int line;
88 unsigned int col;
89 sourceList file;
90 };
91
92struct listDesc_r {
93 tokenBucket head;
94 tokenBucket tail;
95 unsigned int lastBucketOffset;
96 };
97
98struct _T1_r {
99 sourceList left;
100 sourceList right;
101 DynamicStrings_String name;
102 unsigned int line;
103 unsigned int col;
104 };
105
106struct _T3_a { tokenDesc array[MaxBucketSize+1]; };
107struct _T2_r {
108 _T3 buf;
109 unsigned int len;
110 tokenBucket next;
111 };
112
113static mcComment_commentDesc procedureComment;
114static mcComment_commentDesc bodyComment;
115static mcComment_commentDesc afterComment;
116static sourceList currentSource;
117static unsigned int useBufferedTokens;
118static unsigned int currentUsed;
119static listDesc listOfTokens;
120static unsigned int nextTokNo;
121
122/*
123 getProcedureComment - returns the procedure comment if it exists,
124 or NIL otherwise.
125*/
126
51bc4b81 127extern "C" mcComment_commentDesc mcLexBuf_getProcedureComment (void);
7401123f
GM
128
129/*
130 getBodyComment - returns the body comment if it exists,
131 or NIL otherwise. The body comment is
132 removed if found.
133*/
134
51bc4b81 135extern "C" mcComment_commentDesc mcLexBuf_getBodyComment (void);
7401123f
GM
136
137/*
138 getAfterComment - returns the after comment if it exists,
139 or NIL otherwise. The after comment is
140 removed if found.
141*/
142
51bc4b81 143extern "C" mcComment_commentDesc mcLexBuf_getAfterComment (void);
7401123f
GM
144
145/*
146 openSource - attempts to open the source file, s.
147 The success of the operation is returned.
148*/
149
51bc4b81 150extern "C" unsigned int mcLexBuf_openSource (DynamicStrings_String s);
7401123f
GM
151
152/*
153 closeSource - closes the current open file.
154*/
155
51bc4b81 156extern "C" void mcLexBuf_closeSource (void);
7401123f
GM
157
158/*
159 reInitialize - re-initialize the all the data structures.
160*/
161
51bc4b81 162extern "C" void mcLexBuf_reInitialize (void);
7401123f
GM
163
164/*
165 resetForNewPass - reset the buffer pointers to the beginning ready for
166 a new pass
167*/
168
51bc4b81 169extern "C" void mcLexBuf_resetForNewPass (void);
7401123f
GM
170
171/*
172 getToken - gets the next token into currenttoken.
173*/
174
51bc4b81 175extern "C" void mcLexBuf_getToken (void);
7401123f
GM
176
177/*
178 insertToken - inserts a symbol, token, infront of the current token
179 ready for the next pass.
180*/
181
51bc4b81 182extern "C" void mcLexBuf_insertToken (mcReserved_toktype token);
7401123f
GM
183
184/*
185 insertTokenAndRewind - inserts a symbol, token, infront of the current token
186 and then moves the token stream back onto the inserted token.
187*/
188
51bc4b81 189extern "C" void mcLexBuf_insertTokenAndRewind (mcReserved_toktype token);
7401123f
GM
190
191/*
192 getPreviousTokenLineNo - returns the line number of the previous token.
193*/
194
51bc4b81 195extern "C" unsigned int mcLexBuf_getPreviousTokenLineNo (void);
7401123f
GM
196
197/*
198 getLineNo - returns the current line number where the symbol occurs in
199 the source file.
200*/
201
51bc4b81 202extern "C" unsigned int mcLexBuf_getLineNo (void);
7401123f
GM
203
204/*
205 getTokenNo - returns the current token number.
206*/
207
51bc4b81 208extern "C" unsigned int mcLexBuf_getTokenNo (void);
7401123f
GM
209
210/*
211 tokenToLineNo - returns the line number of the current file for the
212 tokenNo. The depth refers to the include depth.
213 A depth of 0 is the current file, depth of 1 is the file
214 which included the current file. Zero is returned if the
215 depth exceeds the file nesting level.
216*/
217
51bc4b81 218extern "C" unsigned int mcLexBuf_tokenToLineNo (unsigned int tokenNo, unsigned int depth);
7401123f
GM
219
220/*
221 getColumnNo - returns the current column where the symbol occurs in
222 the source file.
223*/
224
51bc4b81 225extern "C" unsigned int mcLexBuf_getColumnNo (void);
7401123f
GM
226
227/*
228 tokenToColumnNo - returns the column number of the current file for the
229 tokenNo. The depth refers to the include depth.
230 A depth of 0 is the current file, depth of 1 is the file
231 which included the current file. Zero is returned if the
232 depth exceeds the file nesting level.
233*/
234
51bc4b81 235extern "C" unsigned int mcLexBuf_tokenToColumnNo (unsigned int tokenNo, unsigned int depth);
7401123f
GM
236
237/*
238 findFileNameFromToken - returns the complete FileName for the appropriate
239 source file yields the token number, tokenNo.
240 The, Depth, indicates the include level: 0..n
241 Level 0 is the current. NIL is returned if n+1
242 is requested.
243*/
244
51bc4b81 245extern "C" DynamicStrings_String mcLexBuf_findFileNameFromToken (unsigned int tokenNo, unsigned int depth);
7401123f
GM
246
247/*
248 getFileName - returns a String defining the current file.
249*/
250
51bc4b81 251extern "C" DynamicStrings_String mcLexBuf_getFileName (void);
7401123f
GM
252
253/*
254 addTok - adds a token to the buffer.
255*/
256
51bc4b81 257extern "C" void mcLexBuf_addTok (mcReserved_toktype t);
7401123f
GM
258
259/*
260 addTokCharStar - adds a token to the buffer and an additional string, s.
261 A copy of string, s, is made.
262*/
263
51bc4b81 264extern "C" void mcLexBuf_addTokCharStar (mcReserved_toktype t, void * s);
7401123f
GM
265
266/*
267 addTokInteger - adds a token and an integer to the buffer.
268*/
269
51bc4b81 270extern "C" void mcLexBuf_addTokInteger (mcReserved_toktype t, int i);
7401123f
GM
271
272/*
273 addTokComment - adds a token to the buffer and a comment descriptor, com.
274*/
275
51bc4b81 276extern "C" void mcLexBuf_addTokComment (mcReserved_toktype t, mcComment_commentDesc com);
7401123f
GM
277
278/*
279 setFile - sets the current filename to, filename.
280*/
281
51bc4b81 282extern "C" void mcLexBuf_setFile (void * filename);
7401123f
GM
283
284/*
285 pushFile - indicates that, filename, has just been included.
286*/
287
51bc4b81 288extern "C" void mcLexBuf_pushFile (void * filename);
7401123f
GM
289
290/*
291 popFile - indicates that we are returning to, filename, having finished
292 an include.
293*/
294
51bc4b81 295extern "C" void mcLexBuf_popFile (void * filename);
7401123f
GM
296
297/*
298 debugLex - display the last, n, tokens.
299*/
300
301static void debugLex (unsigned int n);
302
303/*
304 seekTo -
305*/
306
307static void seekTo (unsigned int t);
308
309/*
310 peeptokenBucket -
311*/
312
313static tokenBucket peeptokenBucket (unsigned int *t);
314
315/*
316 peepAfterComment - peeps ahead looking for an after statement comment. It stops at an END token
317 or if the line number changes.
318*/
319
320static void peepAfterComment (void);
321
322/*
323 init - initializes the token list and source list.
324*/
325
326static void init (void);
327
328/*
329 addTo - adds a new element to the end of sourceList, currentSource.
330*/
331
332static void addTo (sourceList l);
333
334/*
335 subFrom - subtracts, l, from the source list.
336*/
337
338static void subFrom (sourceList l);
339
340/*
341 newElement - returns a new sourceList
342*/
343
344static sourceList newElement (void * s);
345
346/*
347 newList - initializes an empty list with the classic dummy header element.
348*/
349
350static sourceList newList (void);
351
352/*
353 checkIfNeedToDuplicate - checks to see whether the currentSource has
354 been used, if it has then duplicate the list.
355*/
356
357static void checkIfNeedToDuplicate (void);
358
359/*
360 killList - kills the sourceList providing that it has not been used.
361*/
362
363static void killList (void);
364
365/*
366 displayToken -
367*/
368
369static void displayToken (mcReserved_toktype t);
370
371/*
372 updateFromBucket - updates the global variables: currenttoken,
373 currentstring, currentcolumn and currentinteger
374 from tokenBucket, b, and, offset.
375*/
376
377static void updateFromBucket (tokenBucket b, unsigned int offset);
378
379/*
380 doGetToken - fetch the next token into currenttoken.
381*/
382
383static void doGetToken (void);
384
385/*
386 syncOpenWithBuffer - synchronise the buffer with the start of a file.
387 Skips all the tokens to do with the previous file.
388*/
389
390static void syncOpenWithBuffer (void);
391
392/*
393 findtokenBucket - returns the tokenBucket corresponding to the tokenNo.
394*/
395
396static tokenBucket findtokenBucket (unsigned int *tokenNo);
397
398/*
399 getFileName - returns a String defining the current file.
400*/
401
402static void stop (void);
403
404/*
405 addTokToList - adds a token to a dynamic list.
406*/
407
408static void addTokToList (mcReserved_toktype t, nameKey_Name n, int i, mcComment_commentDesc comment, unsigned int l, unsigned int c, sourceList f);
409
410/*
411 isLastTokenEof - returns TRUE if the last token was an eoftok
412*/
413
414static unsigned int isLastTokenEof (void);
415
416
417/*
418 debugLex - display the last, n, tokens.
419*/
420
421static void debugLex (unsigned int n)
422{
423 unsigned int c;
424 unsigned int i;
425 unsigned int o;
426 unsigned int t;
427 tokenBucket b;
428
429 if (nextTokNo > n)
430 {
dce2ffd5 431 o = nextTokNo-n;
7401123f
GM
432 }
433 else
434 {
d08981bf 435 o = 0;
7401123f 436 }
d08981bf 437 i = 0;
7401123f 438 do {
dce2ffd5 439 t = o+i;
7401123f
GM
440 if (nextTokNo == t)
441 {
51bc4b81 442 mcPrintf_printf0 ((const char *) "nextTokNo ", 10);
7401123f 443 }
dce2ffd5 444 b = findtokenBucket (&t);
7401123f
GM
445 if (b == NULL)
446 {
dce2ffd5 447 t = o+i;
51bc4b81 448 mcPrintf_printf1 ((const char *) "end of buf (%d is further ahead than the buffer contents)\\n", 60, (const unsigned char *) &t, (sizeof (t)-1));
7401123f
GM
449 }
450 else
451 {
dce2ffd5 452 c = o+i;
51bc4b81 453 mcPrintf_printf2 ((const char *) "entry %d %d ", 13, (const unsigned char *) &c, (sizeof (c)-1), (const unsigned char *) &t, (sizeof (t)-1));
7401123f 454 displayToken (b->buf.array[t].token);
51bc4b81 455 mcPrintf_printf0 ((const char *) "\\n", 2);
7401123f
GM
456 i += 1;
457 }
458 } while (! (b == NULL));
459}
460
461
462/*
463 seekTo -
464*/
465
466static void seekTo (unsigned int t)
467{
468 tokenBucket b;
469
470 nextTokNo = t;
471 if (t > 0)
472 {
473 t -= 1;
dce2ffd5 474 b = findtokenBucket (&t);
7401123f
GM
475 if (b == NULL)
476 {
477 updateFromBucket (b, t);
478 }
479 }
480}
481
482
483/*
484 peeptokenBucket -
485*/
486
487static tokenBucket peeptokenBucket (unsigned int *t)
488{
489 mcReserved_toktype ct;
490 unsigned int old;
491 unsigned int n;
492 tokenBucket b;
493 tokenBucket c;
494
495 ct = mcLexBuf_currenttoken;
496 if (Debugging)
497 {
498 debugLex (5);
499 }
dce2ffd5 500 old = mcLexBuf_getTokenNo ();
7401123f
GM
501 do {
502 n = (*t);
dce2ffd5 503 b = findtokenBucket (&n);
7401123f
GM
504 if (b == NULL)
505 {
506 doGetToken ();
507 n = (*t);
dce2ffd5 508 b = findtokenBucket (&n);
7401123f
GM
509 if ((b == NULL) || (mcLexBuf_currenttoken == mcReserved_eoftok))
510 {
511 /* bailing out. */
dce2ffd5
GM
512 nextTokNo = old+1;
513 b = findtokenBucket (&old);
7401123f 514 updateFromBucket (b, old);
d08981bf 515 return NULL;
7401123f
GM
516 }
517 }
518 } while (! ((b != NULL) || (mcLexBuf_currenttoken == mcReserved_eoftok)));
519 (*t) = n;
dce2ffd5 520 nextTokNo = old+1;
7401123f
GM
521 if (Debugging)
522 {
51bc4b81 523 mcPrintf_printf2 ((const char *) "nextTokNo = %d, old = %d\\n", 26, (const unsigned char *) &nextTokNo, (sizeof (nextTokNo)-1), (const unsigned char *) &old, (sizeof (old)-1));
7401123f 524 }
dce2ffd5 525 b = findtokenBucket (&old);
7401123f
GM
526 if (Debugging)
527 {
51bc4b81 528 mcPrintf_printf1 ((const char *) " adjusted old = %d\\n", 21, (const unsigned char *) &old, (sizeof (old)-1));
7401123f
GM
529 }
530 if (b != NULL)
531 {
532 updateFromBucket (b, old);
533 }
534 if (Debugging)
535 {
536 debugLex (5);
537 }
538 mcDebug_assert (ct == mcLexBuf_currenttoken);
539 return b;
540 /* static analysis guarentees a RETURN statement will be used before here. */
541 __builtin_unreachable ();
542}
543
544
545/*
546 peepAfterComment - peeps ahead looking for an after statement comment. It stops at an END token
547 or if the line number changes.
548*/
549
550static void peepAfterComment (void)
551{
552 unsigned int oldTokNo;
553 unsigned int t;
554 unsigned int peep;
555 unsigned int cno;
556 unsigned int nextline;
557 unsigned int curline;
558 tokenBucket b;
559 unsigned int finished;
560
561 oldTokNo = nextTokNo;
dce2ffd5
GM
562 cno = mcLexBuf_getTokenNo ();
563 curline = mcLexBuf_tokenToLineNo (cno, 0);
7401123f 564 nextline = curline;
d08981bf 565 peep = 0;
7401123f
GM
566 finished = FALSE;
567 do {
dce2ffd5
GM
568 t = cno+peep;
569 b = peeptokenBucket (&t);
7401123f
GM
570 if ((b == NULL) || (mcLexBuf_currenttoken == mcReserved_eoftok))
571 {
572 finished = TRUE;
573 }
574 else
575 {
576 nextline = b->buf.array[t].line;
577 if (nextline == curline)
578 {
579 switch (b->buf.array[t].token)
580 {
581 case mcReserved_eoftok:
582 case mcReserved_endtok:
583 finished = TRUE;
584 break;
585
586 case mcReserved_commenttok:
587 if (mcComment_isAfterComment (b->buf.array[t].com))
588 {
589 afterComment = b->buf.array[t].com;
590 }
591 break;
592
593
594 default:
595 break;
596 }
597 }
598 else
599 {
600 finished = TRUE;
601 }
602 }
603 peep += 1;
604 } while (! (finished));
605 seekTo (oldTokNo);
606}
607
608
609/*
610 init - initializes the token list and source list.
611*/
612
613static void init (void)
614{
615 mcLexBuf_currenttoken = mcReserved_eoftok;
d08981bf
GM
616 nextTokNo = 0;
617 currentSource = NULL;
618 listOfTokens.head = NULL;
619 listOfTokens.tail = NULL;
7401123f 620 useBufferedTokens = FALSE;
51bc4b81
GM
621 procedureComment = static_cast<mcComment_commentDesc> (NULL);
622 bodyComment = static_cast<mcComment_commentDesc> (NULL);
623 afterComment = static_cast<mcComment_commentDesc> (NULL);
624 mcLexBuf_lastcomment = static_cast<mcComment_commentDesc> (NULL);
7401123f
GM
625}
626
627
628/*
629 addTo - adds a new element to the end of sourceList, currentSource.
630*/
631
632static void addTo (sourceList l)
633{
634 l->right = currentSource;
635 l->left = currentSource->left;
636 currentSource->left->right = l;
637 currentSource->left = l;
dce2ffd5
GM
638 l->left->line = mcflex_getLineNo ();
639 l->left->col = mcflex_getColumnNo ();
7401123f
GM
640}
641
642
643/*
644 subFrom - subtracts, l, from the source list.
645*/
646
647static void subFrom (sourceList l)
648{
649 l->left->right = l->right;
650 l->right->left = l->left;
651}
652
653
654/*
655 newElement - returns a new sourceList
656*/
657
658static sourceList newElement (void * s)
659{
660 sourceList l;
661
662 Storage_ALLOCATE ((void **) &l, sizeof (_T1));
663 if (l == NULL)
664 {
665 M2RTS_HALT (-1);
666 __builtin_unreachable ();
667 }
668 else
669 {
dce2ffd5 670 l->name = DynamicStrings_InitStringCharStar (s);
d08981bf
GM
671 l->left = NULL;
672 l->right = NULL;
7401123f
GM
673 }
674 return l;
675 /* static analysis guarentees a RETURN statement will be used before here. */
676 __builtin_unreachable ();
677}
678
679
680/*
681 newList - initializes an empty list with the classic dummy header element.
682*/
683
684static sourceList newList (void)
685{
686 sourceList l;
687
688 Storage_ALLOCATE ((void **) &l, sizeof (_T1));
689 l->left = l;
690 l->right = l;
51bc4b81 691 l->name = static_cast<DynamicStrings_String> (NULL);
7401123f
GM
692 return l;
693 /* static analysis guarentees a RETURN statement will be used before here. */
694 __builtin_unreachable ();
695}
696
697
698/*
699 checkIfNeedToDuplicate - checks to see whether the currentSource has
700 been used, if it has then duplicate the list.
701*/
702
703static void checkIfNeedToDuplicate (void)
704{
705 sourceList l;
706 sourceList h;
707
708 if (currentUsed)
709 {
710 l = currentSource->right;
711 h = currentSource;
dce2ffd5 712 currentSource = newList ();
7401123f
GM
713 while (l != h)
714 {
51bc4b81 715 addTo (newElement (reinterpret_cast<void *> (l->name)));
7401123f
GM
716 l = l->right;
717 }
718 }
719}
720
721
722/*
723 killList - kills the sourceList providing that it has not been used.
724*/
725
726static void killList (void)
727{
728 sourceList l;
729 sourceList k;
730
731 if (! currentUsed && (currentSource != NULL))
732 {
733 l = currentSource;
734 do {
735 k = l;
736 l = l->right;
737 Storage_DEALLOCATE ((void **) &k, sizeof (_T1));
738 } while (! (l == currentSource));
739 }
740}
741
742
743/*
744 displayToken -
745*/
746
747static void displayToken (mcReserved_toktype t)
748{
749 switch (t)
750 {
751 case mcReserved_eoftok:
51bc4b81 752 mcPrintf_printf0 ((const char *) "eoftok\\n", 8);
7401123f
GM
753 break;
754
755 case mcReserved_plustok:
51bc4b81 756 mcPrintf_printf0 ((const char *) "plustok\\n", 9);
7401123f
GM
757 break;
758
759 case mcReserved_minustok:
51bc4b81 760 mcPrintf_printf0 ((const char *) "minustok\\n", 10);
7401123f
GM
761 break;
762
763 case mcReserved_timestok:
51bc4b81 764 mcPrintf_printf0 ((const char *) "timestok\\n", 10);
7401123f
GM
765 break;
766
767 case mcReserved_dividetok:
51bc4b81 768 mcPrintf_printf0 ((const char *) "dividetok\\n", 11);
7401123f
GM
769 break;
770
771 case mcReserved_becomestok:
51bc4b81 772 mcPrintf_printf0 ((const char *) "becomestok\\n", 12);
7401123f
GM
773 break;
774
775 case mcReserved_ambersandtok:
51bc4b81 776 mcPrintf_printf0 ((const char *) "ambersandtok\\n", 14);
7401123f
GM
777 break;
778
779 case mcReserved_periodtok:
51bc4b81 780 mcPrintf_printf0 ((const char *) "periodtok\\n", 11);
7401123f
GM
781 break;
782
783 case mcReserved_commatok:
51bc4b81 784 mcPrintf_printf0 ((const char *) "commatok\\n", 10);
7401123f
GM
785 break;
786
787 case mcReserved_commenttok:
51bc4b81 788 mcPrintf_printf0 ((const char *) "commenttok\\n", 12);
7401123f
GM
789 break;
790
791 case mcReserved_semicolontok:
51bc4b81 792 mcPrintf_printf0 ((const char *) "semicolontok\\n", 14);
7401123f
GM
793 break;
794
795 case mcReserved_lparatok:
51bc4b81 796 mcPrintf_printf0 ((const char *) "lparatok\\n", 10);
7401123f
GM
797 break;
798
799 case mcReserved_rparatok:
51bc4b81 800 mcPrintf_printf0 ((const char *) "rparatok\\n", 10);
7401123f
GM
801 break;
802
803 case mcReserved_lsbratok:
51bc4b81 804 mcPrintf_printf0 ((const char *) "lsbratok\\n", 10);
7401123f
GM
805 break;
806
807 case mcReserved_rsbratok:
51bc4b81 808 mcPrintf_printf0 ((const char *) "rsbratok\\n", 10);
7401123f
GM
809 break;
810
811 case mcReserved_lcbratok:
51bc4b81 812 mcPrintf_printf0 ((const char *) "lcbratok\\n", 10);
7401123f
GM
813 break;
814
815 case mcReserved_rcbratok:
51bc4b81 816 mcPrintf_printf0 ((const char *) "rcbratok\\n", 10);
7401123f
GM
817 break;
818
819 case mcReserved_uparrowtok:
51bc4b81 820 mcPrintf_printf0 ((const char *) "uparrowtok\\n", 12);
7401123f
GM
821 break;
822
823 case mcReserved_singlequotetok:
51bc4b81 824 mcPrintf_printf0 ((const char *) "singlequotetok\\n", 16);
7401123f
GM
825 break;
826
827 case mcReserved_equaltok:
51bc4b81 828 mcPrintf_printf0 ((const char *) "equaltok\\n", 10);
7401123f
GM
829 break;
830
831 case mcReserved_hashtok:
51bc4b81 832 mcPrintf_printf0 ((const char *) "hashtok\\n", 9);
7401123f
GM
833 break;
834
835 case mcReserved_lesstok:
51bc4b81 836 mcPrintf_printf0 ((const char *) "lesstok\\n", 9);
7401123f
GM
837 break;
838
839 case mcReserved_greatertok:
51bc4b81 840 mcPrintf_printf0 ((const char *) "greatertok\\n", 12);
7401123f
GM
841 break;
842
843 case mcReserved_lessgreatertok:
51bc4b81 844 mcPrintf_printf0 ((const char *) "lessgreatertok\\n", 16);
7401123f
GM
845 break;
846
847 case mcReserved_lessequaltok:
51bc4b81 848 mcPrintf_printf0 ((const char *) "lessequaltok\\n", 14);
7401123f
GM
849 break;
850
851 case mcReserved_greaterequaltok:
51bc4b81 852 mcPrintf_printf0 ((const char *) "greaterequaltok\\n", 17);
7401123f
GM
853 break;
854
855 case mcReserved_periodperiodtok:
51bc4b81 856 mcPrintf_printf0 ((const char *) "periodperiodtok\\n", 17);
7401123f
GM
857 break;
858
859 case mcReserved_colontok:
51bc4b81 860 mcPrintf_printf0 ((const char *) "colontok\\n", 10);
7401123f
GM
861 break;
862
863 case mcReserved_doublequotestok:
51bc4b81 864 mcPrintf_printf0 ((const char *) "doublequotestok\\n", 17);
7401123f
GM
865 break;
866
867 case mcReserved_bartok:
51bc4b81 868 mcPrintf_printf0 ((const char *) "bartok\\n", 8);
7401123f
GM
869 break;
870
871 case mcReserved_andtok:
51bc4b81 872 mcPrintf_printf0 ((const char *) "andtok\\n", 8);
7401123f
GM
873 break;
874
875 case mcReserved_arraytok:
51bc4b81 876 mcPrintf_printf0 ((const char *) "arraytok\\n", 10);
7401123f
GM
877 break;
878
879 case mcReserved_begintok:
51bc4b81 880 mcPrintf_printf0 ((const char *) "begintok\\n", 10);
7401123f
GM
881 break;
882
883 case mcReserved_bytok:
51bc4b81 884 mcPrintf_printf0 ((const char *) "bytok\\n", 7);
7401123f
GM
885 break;
886
887 case mcReserved_casetok:
51bc4b81 888 mcPrintf_printf0 ((const char *) "casetok\\n", 9);
7401123f
GM
889 break;
890
891 case mcReserved_consttok:
51bc4b81 892 mcPrintf_printf0 ((const char *) "consttok\\n", 10);
7401123f
GM
893 break;
894
895 case mcReserved_definitiontok:
51bc4b81 896 mcPrintf_printf0 ((const char *) "definitiontok\\n", 15);
7401123f
GM
897 break;
898
899 case mcReserved_divtok:
51bc4b81 900 mcPrintf_printf0 ((const char *) "divtok\\n", 8);
7401123f
GM
901 break;
902
903 case mcReserved_dotok:
51bc4b81 904 mcPrintf_printf0 ((const char *) "dotok\\n", 7);
7401123f
GM
905 break;
906
907 case mcReserved_elsetok:
51bc4b81 908 mcPrintf_printf0 ((const char *) "elsetok\\n", 9);
7401123f
GM
909 break;
910
911 case mcReserved_elsiftok:
51bc4b81 912 mcPrintf_printf0 ((const char *) "elsiftok\\n", 10);
7401123f
GM
913 break;
914
915 case mcReserved_endtok:
51bc4b81 916 mcPrintf_printf0 ((const char *) "endtok\\n", 8);
7401123f
GM
917 break;
918
919 case mcReserved_exittok:
51bc4b81 920 mcPrintf_printf0 ((const char *) "exittok\\n", 9);
7401123f
GM
921 break;
922
923 case mcReserved_exporttok:
51bc4b81 924 mcPrintf_printf0 ((const char *) "exporttok\\n", 11);
7401123f
GM
925 break;
926
927 case mcReserved_fortok:
51bc4b81 928 mcPrintf_printf0 ((const char *) "fortok\\n", 8);
7401123f
GM
929 break;
930
931 case mcReserved_fromtok:
51bc4b81 932 mcPrintf_printf0 ((const char *) "fromtok\\n", 9);
7401123f
GM
933 break;
934
935 case mcReserved_iftok:
51bc4b81 936 mcPrintf_printf0 ((const char *) "iftok\\n", 7);
7401123f
GM
937 break;
938
939 case mcReserved_implementationtok:
51bc4b81 940 mcPrintf_printf0 ((const char *) "implementationtok\\n", 19);
7401123f
GM
941 break;
942
943 case mcReserved_importtok:
51bc4b81 944 mcPrintf_printf0 ((const char *) "importtok\\n", 11);
7401123f
GM
945 break;
946
947 case mcReserved_intok:
51bc4b81 948 mcPrintf_printf0 ((const char *) "intok\\n", 7);
7401123f
GM
949 break;
950
951 case mcReserved_looptok:
51bc4b81 952 mcPrintf_printf0 ((const char *) "looptok\\n", 9);
7401123f
GM
953 break;
954
955 case mcReserved_modtok:
51bc4b81 956 mcPrintf_printf0 ((const char *) "modtok\\n", 8);
7401123f
GM
957 break;
958
959 case mcReserved_moduletok:
51bc4b81 960 mcPrintf_printf0 ((const char *) "moduletok\\n", 11);
7401123f
GM
961 break;
962
963 case mcReserved_nottok:
51bc4b81 964 mcPrintf_printf0 ((const char *) "nottok\\n", 8);
7401123f
GM
965 break;
966
967 case mcReserved_oftok:
51bc4b81 968 mcPrintf_printf0 ((const char *) "oftok\\n", 7);
7401123f
GM
969 break;
970
971 case mcReserved_ortok:
51bc4b81 972 mcPrintf_printf0 ((const char *) "ortok\\n", 7);
7401123f
GM
973 break;
974
975 case mcReserved_pointertok:
51bc4b81 976 mcPrintf_printf0 ((const char *) "pointertok\\n", 12);
7401123f
GM
977 break;
978
979 case mcReserved_proceduretok:
51bc4b81 980 mcPrintf_printf0 ((const char *) "proceduretok\\n", 14);
7401123f
GM
981 break;
982
983 case mcReserved_qualifiedtok:
51bc4b81 984 mcPrintf_printf0 ((const char *) "qualifiedtok\\n", 14);
7401123f
GM
985 break;
986
987 case mcReserved_unqualifiedtok:
51bc4b81 988 mcPrintf_printf0 ((const char *) "unqualifiedtok\\n", 16);
7401123f
GM
989 break;
990
991 case mcReserved_recordtok:
51bc4b81 992 mcPrintf_printf0 ((const char *) "recordtok\\n", 11);
7401123f
GM
993 break;
994
995 case mcReserved_repeattok:
51bc4b81 996 mcPrintf_printf0 ((const char *) "repeattok\\n", 11);
7401123f
GM
997 break;
998
999 case mcReserved_returntok:
51bc4b81 1000 mcPrintf_printf0 ((const char *) "returntok\\n", 11);
7401123f
GM
1001 break;
1002
1003 case mcReserved_settok:
51bc4b81 1004 mcPrintf_printf0 ((const char *) "settok\\n", 8);
7401123f
GM
1005 break;
1006
1007 case mcReserved_thentok:
51bc4b81 1008 mcPrintf_printf0 ((const char *) "thentok\\n", 9);
7401123f
GM
1009 break;
1010
1011 case mcReserved_totok:
51bc4b81 1012 mcPrintf_printf0 ((const char *) "totok\\n", 7);
7401123f
GM
1013 break;
1014
1015 case mcReserved_typetok:
51bc4b81 1016 mcPrintf_printf0 ((const char *) "typetok\\n", 9);
7401123f
GM
1017 break;
1018
1019 case mcReserved_untiltok:
51bc4b81 1020 mcPrintf_printf0 ((const char *) "untiltok\\n", 10);
7401123f
GM
1021 break;
1022
1023 case mcReserved_vartok:
51bc4b81 1024 mcPrintf_printf0 ((const char *) "vartok\\n", 8);
7401123f
GM
1025 break;
1026
1027 case mcReserved_whiletok:
51bc4b81 1028 mcPrintf_printf0 ((const char *) "whiletok\\n", 10);
7401123f
GM
1029 break;
1030
1031 case mcReserved_withtok:
51bc4b81 1032 mcPrintf_printf0 ((const char *) "withtok\\n", 9);
7401123f
GM
1033 break;
1034
1035 case mcReserved_asmtok:
51bc4b81 1036 mcPrintf_printf0 ((const char *) "asmtok\\n", 8);
7401123f
GM
1037 break;
1038
1039 case mcReserved_volatiletok:
51bc4b81 1040 mcPrintf_printf0 ((const char *) "volatiletok\\n", 13);
7401123f
GM
1041 break;
1042
1043 case mcReserved_periodperiodperiodtok:
51bc4b81 1044 mcPrintf_printf0 ((const char *) "periodperiodperiodtok\\n", 23);
7401123f
GM
1045 break;
1046
1047 case mcReserved_datetok:
51bc4b81 1048 mcPrintf_printf0 ((const char *) "datetok\\n", 9);
7401123f
GM
1049 break;
1050
1051 case mcReserved_linetok:
51bc4b81 1052 mcPrintf_printf0 ((const char *) "linetok\\n", 9);
7401123f
GM
1053 break;
1054
1055 case mcReserved_filetok:
51bc4b81 1056 mcPrintf_printf0 ((const char *) "filetok\\n", 9);
7401123f
GM
1057 break;
1058
1059 case mcReserved_integertok:
51bc4b81 1060 mcPrintf_printf0 ((const char *) "integertok\\n", 12);
7401123f
GM
1061 break;
1062
1063 case mcReserved_identtok:
51bc4b81 1064 mcPrintf_printf0 ((const char *) "identtok\\n", 10);
7401123f
GM
1065 break;
1066
1067 case mcReserved_realtok:
51bc4b81 1068 mcPrintf_printf0 ((const char *) "realtok\\n", 9);
7401123f
GM
1069 break;
1070
1071 case mcReserved_stringtok:
51bc4b81 1072 mcPrintf_printf0 ((const char *) "stringtok\\n", 11);
7401123f
GM
1073 break;
1074
1075
1076 default:
51bc4b81 1077 mcPrintf_printf0 ((const char *) "unknown tok (--fixme--)\\n", 25);
7401123f
GM
1078 break;
1079 }
1080}
1081
1082
1083/*
1084 updateFromBucket - updates the global variables: currenttoken,
1085 currentstring, currentcolumn and currentinteger
1086 from tokenBucket, b, and, offset.
1087*/
1088
1089static void updateFromBucket (tokenBucket b, unsigned int offset)
1090{
1091 mcLexBuf_currenttoken = b->buf.array[offset].token;
dce2ffd5 1092 mcLexBuf_currentstring = nameKey_keyToCharStar (b->buf.array[offset].str);
7401123f
GM
1093 mcLexBuf_currentcolumn = b->buf.array[offset].col;
1094 mcLexBuf_currentinteger = b->buf.array[offset].int_;
1095 mcLexBuf_currentcomment = b->buf.array[offset].com;
1096 if (mcLexBuf_currentcomment != NULL)
1097 {
1098 mcLexBuf_lastcomment = mcLexBuf_currentcomment;
1099 }
1100 if (Debugging)
1101 {
51bc4b81 1102 mcPrintf_printf3 ((const char *) "line %d (# %d %d) ", 19, (const unsigned char *) &b->buf.array[offset].line, (sizeof (b->buf.array[offset].line)-1), (const unsigned char *) &offset, (sizeof (offset)-1), (const unsigned char *) &nextTokNo, (sizeof (nextTokNo)-1));
7401123f
GM
1103 }
1104}
1105
1106
1107/*
1108 doGetToken - fetch the next token into currenttoken.
1109*/
1110
1111static void doGetToken (void)
1112{
1113 void * a;
1114 unsigned int t;
1115 tokenBucket b;
1116
1117 if (useBufferedTokens)
1118 {
1119 t = nextTokNo;
dce2ffd5 1120 b = findtokenBucket (&t);
7401123f
GM
1121 updateFromBucket (b, t);
1122 }
1123 else
1124 {
1125 if (listOfTokens.tail == NULL)
1126 {
dce2ffd5 1127 a = mcflex_getToken ();
7401123f
GM
1128 if (listOfTokens.tail == NULL)
1129 {
1130 M2RTS_HALT (-1);
1131 __builtin_unreachable ();
1132 }
1133 }
1134 if (nextTokNo >= listOfTokens.lastBucketOffset)
1135 {
1136 /* nextTokNo is in the last bucket or needs to be read. */
1137 if ((nextTokNo-listOfTokens.lastBucketOffset) < listOfTokens.tail->len)
1138 {
1139 if (Debugging)
1140 {
51bc4b81 1141 mcPrintf_printf0 ((const char *) "fetching token from buffer (updateFromBucket)\\n", 47);
7401123f
GM
1142 }
1143 updateFromBucket (listOfTokens.tail, nextTokNo-listOfTokens.lastBucketOffset);
1144 }
1145 else
1146 {
1147 if (Debugging)
1148 {
51bc4b81 1149 mcPrintf_printf0 ((const char *) "calling flex to place token into buffer\\n", 41);
7401123f
GM
1150 }
1151 /* call the lexical phase to place a new token into the last bucket. */
dce2ffd5 1152 a = mcflex_getToken ();
7401123f 1153 mcLexBuf_getToken (); /* and call ourselves again to collect the token from bucket. */
dce2ffd5 1154 return ; /* and call ourselves again to collect the token from bucket. */
7401123f
GM
1155 }
1156 }
1157 else
1158 {
1159 if (Debugging)
1160 {
51bc4b81 1161 mcPrintf_printf0 ((const char *) "fetching token from buffer\\n", 28);
7401123f
GM
1162 }
1163 t = nextTokNo;
dce2ffd5 1164 b = findtokenBucket (&t);
7401123f
GM
1165 updateFromBucket (b, t);
1166 }
1167 }
1168 if (Debugging)
1169 {
1170 displayToken (mcLexBuf_currenttoken);
1171 }
1172 nextTokNo += 1;
1173}
1174
1175
1176/*
1177 syncOpenWithBuffer - synchronise the buffer with the start of a file.
1178 Skips all the tokens to do with the previous file.
1179*/
1180
1181static void syncOpenWithBuffer (void)
1182{
1183 if (listOfTokens.tail != NULL)
1184 {
dce2ffd5 1185 nextTokNo = listOfTokens.lastBucketOffset+listOfTokens.tail->len;
7401123f
GM
1186 }
1187}
1188
1189
1190/*
1191 findtokenBucket - returns the tokenBucket corresponding to the tokenNo.
1192*/
1193
1194static tokenBucket findtokenBucket (unsigned int *tokenNo)
1195{
1196 tokenBucket b;
1197
1198 b = listOfTokens.head;
1199 while (b != NULL)
1200 {
1201 if ((*tokenNo) < b->len)
1202 {
1203 return b;
1204 }
1205 else
1206 {
1207 (*tokenNo) -= b->len;
1208 }
1209 b = b->next;
1210 }
d08981bf 1211 return NULL;
7401123f
GM
1212 /* static analysis guarentees a RETURN statement will be used before here. */
1213 __builtin_unreachable ();
1214}
1215
1216
1217/*
1218 getFileName - returns a String defining the current file.
1219*/
1220
1221static void stop (void)
1222{
1223}
1224
1225
1226/*
1227 addTokToList - adds a token to a dynamic list.
1228*/
1229
1230static void addTokToList (mcReserved_toktype t, nameKey_Name n, int i, mcComment_commentDesc comment, unsigned int l, unsigned int c, sourceList f)
1231{
1232 tokenBucket b;
1233
1234 if (listOfTokens.head == NULL)
1235 {
1236 Storage_ALLOCATE ((void **) &listOfTokens.head, sizeof (_T2));
1237 if (listOfTokens.head == NULL)
1238 {} /* empty. */
1239 /* list error */
1240 listOfTokens.tail = listOfTokens.head;
d08981bf 1241 listOfTokens.tail->len = 0;
7401123f
GM
1242 }
1243 else if (listOfTokens.tail->len == MaxBucketSize)
1244 {
1245 /* avoid dangling else. */
1246 mcDebug_assert (listOfTokens.tail->next == NULL);
1247 Storage_ALLOCATE ((void **) &listOfTokens.tail->next, sizeof (_T2));
1248 if (listOfTokens.tail->next == NULL)
1249 {} /* empty. */
1250 else
1251 {
1252 /* list error */
1253 listOfTokens.tail = listOfTokens.tail->next;
d08981bf 1254 listOfTokens.tail->len = 0;
7401123f
GM
1255 }
1256 listOfTokens.lastBucketOffset += MaxBucketSize;
1257 }
d08981bf 1258 listOfTokens.tail->next = NULL;
7401123f
GM
1259 mcDebug_assert (listOfTokens.tail->len != MaxBucketSize);
1260 listOfTokens.tail->buf.array[listOfTokens.tail->len].token = t;
1261 listOfTokens.tail->buf.array[listOfTokens.tail->len].str = n;
1262 listOfTokens.tail->buf.array[listOfTokens.tail->len].int_ = i;
1263 listOfTokens.tail->buf.array[listOfTokens.tail->len].com = comment;
1264 listOfTokens.tail->buf.array[listOfTokens.tail->len].line = l;
1265 listOfTokens.tail->buf.array[listOfTokens.tail->len].col = c;
1266 listOfTokens.tail->buf.array[listOfTokens.tail->len].file = f;
1267 listOfTokens.tail->len += 1;
1268}
1269
1270
1271/*
1272 isLastTokenEof - returns TRUE if the last token was an eoftok
1273*/
1274
1275static unsigned int isLastTokenEof (void)
1276{
1277 unsigned int t;
1278 tokenBucket b;
1279
1280 if (listOfTokens.tail != NULL)
1281 {
1282 if (listOfTokens.tail->len == 0)
1283 {
1284 b = listOfTokens.head;
1285 if (b == listOfTokens.tail)
1286 {
1287 return FALSE;
1288 }
1289 while (b->next != listOfTokens.tail)
1290 {
1291 b = b->next;
1292 }
1293 }
1294 else
1295 {
1296 b = listOfTokens.tail;
1297 }
1298 mcDebug_assert (b->len > 0); /* len should always be >0 */
1299 return b->buf.array[b->len-1].token == mcReserved_eoftok; /* len should always be >0 */
1300 }
1301 return FALSE;
1302 /* static analysis guarentees a RETURN statement will be used before here. */
1303 __builtin_unreachable ();
1304}
1305
1306
1307/*
1308 getProcedureComment - returns the procedure comment if it exists,
1309 or NIL otherwise.
1310*/
1311
51bc4b81 1312extern "C" mcComment_commentDesc mcLexBuf_getProcedureComment (void)
7401123f
GM
1313{
1314 return procedureComment;
1315 /* static analysis guarentees a RETURN statement will be used before here. */
1316 __builtin_unreachable ();
1317}
1318
1319
1320/*
1321 getBodyComment - returns the body comment if it exists,
1322 or NIL otherwise. The body comment is
1323 removed if found.
1324*/
1325
51bc4b81 1326extern "C" mcComment_commentDesc mcLexBuf_getBodyComment (void)
7401123f
GM
1327{
1328 mcComment_commentDesc b;
1329
1330 b = bodyComment;
51bc4b81 1331 bodyComment = static_cast<mcComment_commentDesc> (NULL);
7401123f
GM
1332 return b;
1333 /* static analysis guarentees a RETURN statement will be used before here. */
1334 __builtin_unreachable ();
1335}
1336
1337
1338/*
1339 getAfterComment - returns the after comment if it exists,
1340 or NIL otherwise. The after comment is
1341 removed if found.
1342*/
1343
51bc4b81 1344extern "C" mcComment_commentDesc mcLexBuf_getAfterComment (void)
7401123f
GM
1345{
1346 mcComment_commentDesc a;
1347
1348 peepAfterComment ();
1349 a = afterComment;
51bc4b81 1350 afterComment = static_cast<mcComment_commentDesc> (NULL);
7401123f
GM
1351 return a;
1352 /* static analysis guarentees a RETURN statement will be used before here. */
1353 __builtin_unreachable ();
1354}
1355
1356
1357/*
1358 openSource - attempts to open the source file, s.
1359 The success of the operation is returned.
1360*/
1361
51bc4b81 1362extern "C" unsigned int mcLexBuf_openSource (DynamicStrings_String s)
7401123f
GM
1363{
1364 if (useBufferedTokens)
1365 {
1366 mcLexBuf_getToken ();
1367 return TRUE;
1368 }
1369 else
1370 {
1371 if (mcflex_openSource (DynamicStrings_string (s)))
1372 {
1373 mcLexBuf_setFile (DynamicStrings_string (s));
1374 syncOpenWithBuffer ();
1375 mcLexBuf_getToken ();
1376 return TRUE;
1377 }
1378 else
1379 {
1380 return FALSE;
1381 }
1382 }
1383 /* static analysis guarentees a RETURN statement will be used before here. */
1384 __builtin_unreachable ();
1385}
1386
1387
1388/*
1389 closeSource - closes the current open file.
1390*/
1391
51bc4b81 1392extern "C" void mcLexBuf_closeSource (void)
7401123f
GM
1393{
1394 if (useBufferedTokens)
1395 {
1396 while (mcLexBuf_currenttoken != mcReserved_eoftok)
1397 {
1398 mcLexBuf_getToken ();
1399 }
1400 }
1401 /* a subsequent call to mcflex.OpenSource will really close the file */
1402}
1403
1404
1405/*
1406 reInitialize - re-initialize the all the data structures.
1407*/
1408
51bc4b81 1409extern "C" void mcLexBuf_reInitialize (void)
7401123f
GM
1410{
1411 tokenBucket s;
1412 tokenBucket t;
1413
1414 if (listOfTokens.head != NULL)
1415 {
1416 t = listOfTokens.head;
1417 do {
1418 s = t;
1419 t = t->next;
1420 Storage_DEALLOCATE ((void **) &s, sizeof (_T2));
1421 } while (! (t == NULL));
1422 currentUsed = FALSE;
1423 killList ();
1424 }
1425 init ();
1426}
1427
1428
1429/*
1430 resetForNewPass - reset the buffer pointers to the beginning ready for
1431 a new pass
1432*/
1433
51bc4b81 1434extern "C" void mcLexBuf_resetForNewPass (void)
7401123f 1435{
d08981bf 1436 nextTokNo = 0;
7401123f
GM
1437 useBufferedTokens = TRUE;
1438}
1439
1440
1441/*
1442 getToken - gets the next token into currenttoken.
1443*/
1444
51bc4b81 1445extern "C" void mcLexBuf_getToken (void)
7401123f
GM
1446{
1447 do {
1448 doGetToken ();
1449 if (mcLexBuf_currenttoken == mcReserved_commenttok)
1450 {
1451 /* avoid gcc warning by using compound statement even if not strictly necessary. */
1452 if (mcComment_isProcedureComment (mcLexBuf_currentcomment))
1453 {
1454 procedureComment = mcLexBuf_currentcomment;
51bc4b81
GM
1455 bodyComment = static_cast<mcComment_commentDesc> (NULL);
1456 afterComment = static_cast<mcComment_commentDesc> (NULL);
7401123f
GM
1457 }
1458 else if (mcComment_isBodyComment (mcLexBuf_currentcomment))
1459 {
1460 /* avoid dangling else. */
1461 bodyComment = mcLexBuf_currentcomment;
51bc4b81 1462 afterComment = static_cast<mcComment_commentDesc> (NULL);
7401123f
GM
1463 }
1464 else if (mcComment_isAfterComment (mcLexBuf_currentcomment))
1465 {
1466 /* avoid dangling else. */
51bc4b81
GM
1467 procedureComment = static_cast<mcComment_commentDesc> (NULL);
1468 bodyComment = static_cast<mcComment_commentDesc> (NULL);
7401123f
GM
1469 afterComment = mcLexBuf_currentcomment;
1470 }
1471 }
1472 } while (! (mcLexBuf_currenttoken != mcReserved_commenttok));
1473}
1474
1475
1476/*
1477 insertToken - inserts a symbol, token, infront of the current token
1478 ready for the next pass.
1479*/
1480
51bc4b81 1481extern "C" void mcLexBuf_insertToken (mcReserved_toktype token)
7401123f
GM
1482{
1483 if (listOfTokens.tail != NULL)
1484 {
1485 if (listOfTokens.tail->len > 0)
1486 {
1487 listOfTokens.tail->buf.array[listOfTokens.tail->len-1].token = token;
1488 }
d08981bf 1489 addTokToList (mcLexBuf_currenttoken, nameKey_NulName, 0, static_cast<mcComment_commentDesc> (NULL), mcLexBuf_getLineNo (), mcLexBuf_getColumnNo (), currentSource);
7401123f
GM
1490 mcLexBuf_getToken ();
1491 }
1492}
1493
1494
1495/*
1496 insertTokenAndRewind - inserts a symbol, token, infront of the current token
1497 and then moves the token stream back onto the inserted token.
1498*/
1499
51bc4b81 1500extern "C" void mcLexBuf_insertTokenAndRewind (mcReserved_toktype token)
7401123f
GM
1501{
1502 if (listOfTokens.tail != NULL)
1503 {
1504 if (listOfTokens.tail->len > 0)
1505 {
1506 listOfTokens.tail->buf.array[listOfTokens.tail->len-1].token = token;
1507 }
d08981bf 1508 addTokToList (mcLexBuf_currenttoken, nameKey_NulName, 0, static_cast<mcComment_commentDesc> (NULL), mcLexBuf_getLineNo (), mcLexBuf_getColumnNo (), currentSource);
7401123f
GM
1509 mcLexBuf_currenttoken = token;
1510 }
1511}
1512
1513
1514/*
1515 getPreviousTokenLineNo - returns the line number of the previous token.
1516*/
1517
51bc4b81 1518extern "C" unsigned int mcLexBuf_getPreviousTokenLineNo (void)
7401123f 1519{
dce2ffd5 1520 return mcLexBuf_getLineNo ();
7401123f
GM
1521 /* static analysis guarentees a RETURN statement will be used before here. */
1522 __builtin_unreachable ();
1523}
1524
1525
1526/*
1527 getLineNo - returns the current line number where the symbol occurs in
1528 the source file.
1529*/
1530
51bc4b81 1531extern "C" unsigned int mcLexBuf_getLineNo (void)
7401123f
GM
1532{
1533 if (nextTokNo == 0)
1534 {
d08981bf 1535 return 0;
7401123f
GM
1536 }
1537 else
1538 {
dce2ffd5 1539 return mcLexBuf_tokenToLineNo (mcLexBuf_getTokenNo (), 0);
7401123f
GM
1540 }
1541 /* static analysis guarentees a RETURN statement will be used before here. */
1542 __builtin_unreachable ();
1543}
1544
1545
1546/*
1547 getTokenNo - returns the current token number.
1548*/
1549
51bc4b81 1550extern "C" unsigned int mcLexBuf_getTokenNo (void)
7401123f
GM
1551{
1552 if (nextTokNo == 0)
1553 {
d08981bf 1554 return 0;
7401123f
GM
1555 }
1556 else
1557 {
dce2ffd5 1558 return nextTokNo-1;
7401123f
GM
1559 }
1560 /* static analysis guarentees a RETURN statement will be used before here. */
1561 __builtin_unreachable ();
1562}
1563
1564
1565/*
1566 tokenToLineNo - returns the line number of the current file for the
1567 tokenNo. The depth refers to the include depth.
1568 A depth of 0 is the current file, depth of 1 is the file
1569 which included the current file. Zero is returned if the
1570 depth exceeds the file nesting level.
1571*/
1572
51bc4b81 1573extern "C" unsigned int mcLexBuf_tokenToLineNo (unsigned int tokenNo, unsigned int depth)
7401123f
GM
1574{
1575 tokenBucket b;
1576 sourceList l;
1577
dce2ffd5 1578 b = findtokenBucket (&tokenNo);
7401123f
GM
1579 if (b == NULL)
1580 {
d08981bf 1581 return 0;
7401123f
GM
1582 }
1583 else
1584 {
1585 if (depth == 0)
1586 {
1587 return b->buf.array[tokenNo].line;
1588 }
1589 else
1590 {
1591 l = b->buf.array[tokenNo].file->left;
1592 while (depth > 0)
1593 {
1594 l = l->left;
1595 if (l == b->buf.array[tokenNo].file->left)
1596 {
d08981bf 1597 return 0;
7401123f
GM
1598 }
1599 depth -= 1;
1600 }
1601 return l->line;
1602 }
1603 }
1604 /* static analysis guarentees a RETURN statement will be used before here. */
1605 __builtin_unreachable ();
1606}
1607
1608
1609/*
1610 getColumnNo - returns the current column where the symbol occurs in
1611 the source file.
1612*/
1613
51bc4b81 1614extern "C" unsigned int mcLexBuf_getColumnNo (void)
7401123f
GM
1615{
1616 if (nextTokNo == 0)
1617 {
d08981bf 1618 return 0;
7401123f
GM
1619 }
1620 else
1621 {
dce2ffd5 1622 return mcLexBuf_tokenToColumnNo (mcLexBuf_getTokenNo (), 0);
7401123f
GM
1623 }
1624 /* static analysis guarentees a RETURN statement will be used before here. */
1625 __builtin_unreachable ();
1626}
1627
1628
1629/*
1630 tokenToColumnNo - returns the column number of the current file for the
1631 tokenNo. The depth refers to the include depth.
1632 A depth of 0 is the current file, depth of 1 is the file
1633 which included the current file. Zero is returned if the
1634 depth exceeds the file nesting level.
1635*/
1636
51bc4b81 1637extern "C" unsigned int mcLexBuf_tokenToColumnNo (unsigned int tokenNo, unsigned int depth)
7401123f
GM
1638{
1639 tokenBucket b;
1640 sourceList l;
1641
dce2ffd5 1642 b = findtokenBucket (&tokenNo);
7401123f
GM
1643 if (b == NULL)
1644 {
d08981bf 1645 return 0;
7401123f
GM
1646 }
1647 else
1648 {
1649 if (depth == 0)
1650 {
1651 return b->buf.array[tokenNo].col;
1652 }
1653 else
1654 {
1655 l = b->buf.array[tokenNo].file->left;
1656 while (depth > 0)
1657 {
1658 l = l->left;
1659 if (l == b->buf.array[tokenNo].file->left)
1660 {
d08981bf 1661 return 0;
7401123f
GM
1662 }
1663 depth -= 1;
1664 }
1665 return l->col;
1666 }
1667 }
1668 /* static analysis guarentees a RETURN statement will be used before here. */
1669 __builtin_unreachable ();
1670}
1671
1672
1673/*
1674 findFileNameFromToken - returns the complete FileName for the appropriate
1675 source file yields the token number, tokenNo.
1676 The, Depth, indicates the include level: 0..n
1677 Level 0 is the current. NIL is returned if n+1
1678 is requested.
1679*/
1680
51bc4b81 1681extern "C" DynamicStrings_String mcLexBuf_findFileNameFromToken (unsigned int tokenNo, unsigned int depth)
7401123f
GM
1682{
1683 tokenBucket b;
1684 sourceList l;
1685
dce2ffd5 1686 b = findtokenBucket (&tokenNo);
7401123f
GM
1687 if (b == NULL)
1688 {
51bc4b81 1689 return static_cast<DynamicStrings_String> (NULL);
7401123f
GM
1690 }
1691 else
1692 {
1693 l = b->buf.array[tokenNo].file->left;
1694 while (depth > 0)
1695 {
1696 l = l->left;
1697 if (l == b->buf.array[tokenNo].file->left)
1698 {
51bc4b81 1699 return static_cast<DynamicStrings_String> (NULL);
7401123f
GM
1700 }
1701 depth -= 1;
1702 }
1703 return l->name;
1704 }
1705 /* static analysis guarentees a RETURN statement will be used before here. */
1706 __builtin_unreachable ();
1707}
1708
1709
1710/*
1711 getFileName - returns a String defining the current file.
1712*/
1713
51bc4b81 1714extern "C" DynamicStrings_String mcLexBuf_getFileName (void)
7401123f 1715{
dce2ffd5 1716 return mcLexBuf_findFileNameFromToken (mcLexBuf_getTokenNo (), 0);
7401123f
GM
1717 /* static analysis guarentees a RETURN statement will be used before here. */
1718 __builtin_unreachable ();
1719}
1720
1721
1722/*
1723 addTok - adds a token to the buffer.
1724*/
1725
51bc4b81 1726extern "C" void mcLexBuf_addTok (mcReserved_toktype t)
7401123f
GM
1727{
1728 if (! ((t == mcReserved_eoftok) && (isLastTokenEof ())))
1729 {
d08981bf 1730 addTokToList (t, nameKey_NulName, 0, static_cast<mcComment_commentDesc> (NULL), mcflex_getLineNo (), mcflex_getColumnNo (), currentSource);
7401123f
GM
1731 currentUsed = TRUE;
1732 }
1733}
1734
1735
1736/*
1737 addTokCharStar - adds a token to the buffer and an additional string, s.
1738 A copy of string, s, is made.
1739*/
1740
51bc4b81 1741extern "C" void mcLexBuf_addTokCharStar (mcReserved_toktype t, void * s)
7401123f
GM
1742{
1743 if ((libc_strlen (s)) > 80)
1744 {
1745 stop ();
1746 }
51bc4b81 1747 addTokToList (t, nameKey_makekey (s), 0, static_cast<mcComment_commentDesc> (NULL), mcflex_getLineNo (), mcflex_getColumnNo (), currentSource);
7401123f
GM
1748 currentUsed = TRUE;
1749}
1750
1751
1752/*
1753 addTokInteger - adds a token and an integer to the buffer.
1754*/
1755
51bc4b81 1756extern "C" void mcLexBuf_addTokInteger (mcReserved_toktype t, int i)
7401123f
GM
1757{
1758 DynamicStrings_String s;
1759 unsigned int c;
1760 unsigned int l;
1761
dce2ffd5
GM
1762 l = mcflex_getLineNo ();
1763 c = mcflex_getColumnNo ();
1764 s = FormatStrings_Sprintf1 (DynamicStrings_Mark (DynamicStrings_InitString ((const char *) "%d", 2)), (const unsigned char *) &i, (sizeof (i)-1));
51bc4b81 1765 addTokToList (t, nameKey_makekey (DynamicStrings_string (s)), i, static_cast<mcComment_commentDesc> (NULL), l, c, currentSource);
dce2ffd5 1766 s = DynamicStrings_KillString (s);
7401123f
GM
1767 currentUsed = TRUE;
1768}
1769
1770
1771/*
1772 addTokComment - adds a token to the buffer and a comment descriptor, com.
1773*/
1774
51bc4b81 1775extern "C" void mcLexBuf_addTokComment (mcReserved_toktype t, mcComment_commentDesc com)
7401123f 1776{
d08981bf 1777 addTokToList (t, nameKey_NulName, 0, com, mcflex_getLineNo (), mcflex_getColumnNo (), currentSource);
7401123f
GM
1778 currentUsed = TRUE;
1779}
1780
1781
1782/*
1783 setFile - sets the current filename to, filename.
1784*/
1785
51bc4b81 1786extern "C" void mcLexBuf_setFile (void * filename)
7401123f
GM
1787{
1788 killList ();
1789 currentUsed = FALSE;
dce2ffd5 1790 currentSource = newList ();
7401123f
GM
1791 addTo (newElement (filename));
1792}
1793
1794
1795/*
1796 pushFile - indicates that, filename, has just been included.
1797*/
1798
51bc4b81 1799extern "C" void mcLexBuf_pushFile (void * filename)
7401123f
GM
1800{
1801 sourceList l;
1802
1803 checkIfNeedToDuplicate ();
1804 addTo (newElement (filename));
1805 if (Debugging)
1806 {
1807 if (currentSource->right != currentSource)
1808 {
1809 l = currentSource;
1810 do {
51bc4b81 1811 mcPrintf_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));
7401123f
GM
1812 l = l->right;
1813 } while (! (l == currentSource));
1814 }
1815 }
1816}
1817
1818
1819/*
1820 popFile - indicates that we are returning to, filename, having finished
1821 an include.
1822*/
1823
51bc4b81 1824extern "C" void mcLexBuf_popFile (void * filename)
7401123f
GM
1825{
1826 sourceList l;
1827
1828 checkIfNeedToDuplicate ();
1829 if ((currentSource != NULL) && (currentSource->left != currentSource))
1830 {
1831 /* avoid dangling else. */
1832 l = currentSource->left; /* last element */
1833 subFrom (l); /* last element */
1834 Storage_DEALLOCATE ((void **) &l, sizeof (_T1));
1835 if ((currentSource->left != currentSource) && (! (DynamicStrings_Equal (currentSource->name, DynamicStrings_Mark (DynamicStrings_InitStringCharStar (filename))))))
1836 {} /* empty. */
1837 /* mismatch in source file names after preprocessing files */
1838 }
1839 /* source file list is empty, cannot pop an include.. */
1840}
1841
206c4f77 1842extern "C" void _M2_mcLexBuf_init (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
7401123f
GM
1843{
1844 init ();
1845}
1846
206c4f77 1847extern "C" void _M2_mcLexBuf_finish (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
7401123f
GM
1848{
1849}
This page took 0.258439 seconds and 5 git commands to generate.