]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/cpp/DataBoardTest/DataBoard/LangDumpDecl.c
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / DataBoard / LangDumpDecl.c
1 /** \file
2  *  This C source file was generated by $ANTLR version 3.2 Sep 23, 2009 12:02:23
3  *
4  *     -  From the grammar source file : LangDumpDecl.g
5  *     -                            On : 2010-02-24 13:30:09
6  *     -           for the tree parser : LangDumpDeclTreeParser *
7  * Editing it, at least manually, is not wise. 
8  *
9  * C language generator and runtime by Jim Idle, jimi|hereisanat|idle|dotgoeshere|ws.
10  *
11  *
12 */
13 // [The "BSD licence"]
14 // Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC
15 // http://www.temporal-wave.com
16 // http://www.linkedin.com/in/jimidle
17 //
18 // All rights reserved.
19 //
20 // Redistribution and use in source and binary forms, with or without
21 // modification, are permitted provided that the following conditions
22 // are met:
23 // 1. Redistributions of source code must retain the above copyright
24 //    notice, this list of conditions and the following disclaimer.
25 // 2. Redistributions in binary form must reproduce the above copyright
26 //    notice, this list of conditions and the following disclaimer in the
27 //    documentation and/or other materials provided with the distribution.
28 // 3. The name of the author may not be used to endorse or promote products
29 //    derived from this software without specific prior written permission.
30 //
31 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
32 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
33 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
34 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
35 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
40 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41
42 /* -----------------------------------------
43  * Include the ANTLR3 generated header file.
44  */
45 #include    "LangDumpDecl.h"
46 /* ----------------------------------------- */
47
48
49
50
51
52 /* MACROS that hide the C interface implementations from the
53  * generated code, which makes it a little more understandable to the human eye.
54  * I am very much against using C pre-processor macros for function calls and bits
55  * of code as you cannot see what is happening when single stepping in debuggers
56  * and so on. The exception (in my book at least) is for generated code, where you are
57  * not maintaining it, but may wish to read and understand it. If you single step it, you know that input()
58  * hides some indirect calls, but is always referring to the input stream. This is
59  * probably more readable than ctx->input->istream->input(snarfle0->blarg) and allows me to rejig
60  * the runtime interfaces without changing the generated code too often, without
61  * confusing the reader of the generated output, who may not wish to know the gory
62  * details of the interface inheritance.
63  */
64  
65 #define         CTX     ctx
66
67 /* Aids in accessing scopes for grammar programmers
68  */
69 #undef  SCOPE_TYPE
70 #undef  SCOPE_STACK
71 #undef  SCOPE_TOP
72 #define SCOPE_TYPE(scope)   pLangDumpDecl_##scope##_SCOPE
73 #define SCOPE_STACK(scope)  pLangDumpDecl_##scope##Stack
74 #define SCOPE_TOP(scope)    ctx->pLangDumpDecl_##scope##Top
75 #define SCOPE_SIZE(scope)               ctx->pLangDumpDecl_##scope##Stack_limit
76 #define SCOPE_INSTANCE(scope, i)        (ctx->SCOPE_STACK(scope)->get(ctx->SCOPE_STACK(scope),i))
77
78 /* Macros for accessing things in the parser
79  */
80  
81 #undef      PARSER
82 #undef      RECOGNIZER              
83 #undef      HAVEPARSEDRULE
84 #undef      INPUT
85 #undef      STRSTREAM
86 #undef      HASEXCEPTION
87 #undef      EXCEPTION
88 #undef      MATCHT
89 #undef      MATCHANYT
90 #undef      FOLLOWSTACK
91 #undef      FOLLOWPUSH
92 #undef      FOLLOWPOP
93 #undef      PRECOVER
94 #undef      PREPORTERROR
95 #undef      LA
96 #undef      LT
97 #undef      CONSTRUCTEX
98 #undef      CONSUME
99 #undef      MARK
100 #undef      REWIND
101 #undef      REWINDLAST
102 #undef      PERRORRECOVERY
103 #undef      HASFAILED
104 #undef      FAILEDFLAG
105 #undef      RECOVERFROMMISMATCHEDSET
106 #undef      RECOVERFROMMISMATCHEDELEMENT
107 #undef      BACKTRACKING
108 #undef      ADAPTOR
109 #undef      RULEMEMO            
110 #undef          SEEK    
111 #undef          INDEX
112 #undef          DBG
113
114 #define     PARSER                                                      ctx->pTreeParser  
115 #define     RECOGNIZER                                          PARSER->rec
116 #define         PSRSTATE                                                RECOGNIZER->state
117 #define     HAVEPARSEDRULE(r)                           RECOGNIZER->alreadyParsedRule(RECOGNIZER, r)
118 #define     INPUT                                                       PARSER->ctnstream
119 #define         ISTREAM                                                 INPUT->tnstream->istream
120 #define     STRSTREAM                                           INPUT->tnstream
121 #define     HASEXCEPTION()                                      (PSRSTATE->error == ANTLR3_TRUE)
122 #define     EXCEPTION                                           PSRSTATE->exception
123 #define     MATCHT(t, fs)                                       RECOGNIZER->match(RECOGNIZER, t, fs)
124 #define     MATCHANYT()                                         RECOGNIZER->matchAny(RECOGNIZER)
125 #define     FOLLOWSTACK                                     PSRSTATE->following
126 #define     FOLLOWPUSH(x)                                       FOLLOWSTACK->push(FOLLOWSTACK, ((void *)(&(x))), NULL)
127 #define     FOLLOWPOP()                                         FOLLOWSTACK->pop(FOLLOWSTACK)
128 #define     PRECOVER()                                          RECOGNIZER->recover(RECOGNIZER)
129 #define     PREPORTERROR()                                      RECOGNIZER->reportError(RECOGNIZER)
130 #define     LA(n)                                                       ISTREAM->_LA(ISTREAM, n)
131 #define     LT(n)                                                       INPUT->tnstream->_LT(INPUT->tnstream, n)
132 #define     CONSTRUCTEX()                                       RECOGNIZER->exConstruct(RECOGNIZER)
133 #define     CONSUME()                                           ISTREAM->consume(ISTREAM)
134 #define     MARK()                                                      ISTREAM->mark(ISTREAM)
135 #define     REWIND(m)                                           ISTREAM->rewind(ISTREAM, m)
136 #define     REWINDLAST()                                        ISTREAM->rewindLast(ISTREAM)
137 #define     PERRORRECOVERY                                      PSRSTATE->errorRecovery
138 #define     FAILEDFLAG                                          PSRSTATE->failed
139 #define     HASFAILED()                                         (FAILEDFLAG == ANTLR3_TRUE)
140 #define     BACKTRACKING                                        PSRSTATE->backtracking
141 #define     RECOVERFROMMISMATCHEDSET(s)         RECOGNIZER->recoverFromMismatchedSet(RECOGNIZER, s)
142 #define     RECOVERFROMMISMATCHEDELEMENT(e)     RECOGNIZER->recoverFromMismatchedElement(RECOGNIZER, s)
143 #define     ADAPTOR                         INPUT->adaptor
144 #define         RULEMEMO                                                PSRSTATE->ruleMemo
145 #define         SEEK(n)                                                 ISTREAM->seek(ISTREAM, n)
146 #define         INDEX()                                                 ISTREAM->index(ISTREAM)
147 #define         DBG                                                             RECOGNIZER->debugger
148
149
150 #define         TOKTEXT(tok, txt)                               tok, (pANTLR3_UINT8)txt
151
152 /* The 4 tokens defined below may well clash with your own #defines or token types. If so
153  * then for the present you must use different names for your defines as these are hard coded
154  * in the code generator. It would be better not to use such names internally, and maybe
155  * we can change this in a forthcoming release. I deliberately do not #undef these
156  * here as this will at least give you a redefined error somewhere if they clash.
157  */
158 #define     UP      ANTLR3_TOKEN_UP
159 #define     DOWN    ANTLR3_TOKEN_DOWN
160 #define     EOR     ANTLR3_TOKEN_EOR
161 #define     INVALID ANTLR3_TOKEN_INVALID
162
163
164 /* =============================================================================
165  * Functions to create and destroy scopes. First come the rule scopes, followed
166  * by the global declared scopes.
167  */
168
169
170
171 /* ============================================================================= */
172
173 /* =============================================================================
174  * Start of recognizer
175  */
176
177
178
179 /** \brief Table of all token names in symbolic order, mainly used for
180  *         error reporting.
181  */
182 pANTLR3_UINT8   LangDumpDeclTokenNames[7+4]
183      = {
184         (pANTLR3_UINT8) "<invalid>",       /* String to print to indicate an invalid token */
185         (pANTLR3_UINT8) "<EOR>",
186         (pANTLR3_UINT8) "<DOWN>", 
187         (pANTLR3_UINT8) "<UP>", 
188         (pANTLR3_UINT8) "DECL",
189         (pANTLR3_UINT8) "ID",
190         (pANTLR3_UINT8) "INTTYPE",
191         (pANTLR3_UINT8) "FLOATTYPE",
192         (pANTLR3_UINT8) "INT",
193         (pANTLR3_UINT8) "WS",
194         (pANTLR3_UINT8) "';'"
195        };
196
197         
198
199 // Forward declare the locally static matching functions we have generated.
200 //
201 static void     decl    (pLangDumpDecl ctx);
202 static void     decls    (pLangDumpDecl ctx);
203 static void     type    (pLangDumpDecl ctx);
204 static LangDumpDecl_declarator_return   declarator    (pLangDumpDecl ctx);
205 static void     LangDumpDeclFree(pLangDumpDecl ctx);
206 /* For use in tree output where we are accumulating rule labels via label += ruleRef
207  * we need a function that knows how to free a return scope when the list is destroyed. 
208  * We cannot just use ANTLR3_FREE because in debug tracking mode, this is a macro.
209  */
210 static  void ANTLR3_CDECL freeScope(void * scope)
211 {
212     ANTLR3_FREE(scope);
213 }
214
215 /** \brief Name of the grammar file that generated this code
216  */
217 static const char fileName[] = "LangDumpDecl.g";
218
219 /** \brief Return the name of the grammar file that generated this code.
220  */
221 static const char * getGrammarFileName()
222 {
223         return fileName;
224 }
225 /** \brief Create a new LangDumpDecl parser and return a context for it.
226  *
227  * \param[in] instream Pointer to an input stream interface.
228  *
229  * \return Pointer to new parser context upon success.
230  */
231 ANTLR3_API pLangDumpDecl
232 LangDumpDeclNew   (pANTLR3_COMMON_TREE_NODE_STREAM instream)
233 {
234         // See if we can create a new parser with the standard constructor
235         //
236         return LangDumpDeclNewSSD(instream, NULL);
237 }
238
239 /** \brief Create a new LangDumpDecl parser and return a context for it.
240  *
241  * \param[in] instream Pointer to an input stream interface.
242  *
243  * \return Pointer to new parser context upon success.
244  */
245 ANTLR3_API pLangDumpDecl
246 LangDumpDeclNewSSD   (pANTLR3_COMMON_TREE_NODE_STREAM instream, pANTLR3_RECOGNIZER_SHARED_STATE state)
247 {
248     pLangDumpDecl ctx;      /* Context structure we will build and return   */
249     
250     ctx = (pLangDumpDecl) ANTLR3_CALLOC(1, sizeof(LangDumpDecl));
251     
252     if  (ctx == NULL)
253     {
254                 // Failed to allocate memory for parser context
255                 //
256         return  NULL;
257     }
258     
259     /* -------------------------------------------------------------------
260      * Memory for basic structure is allocated, now to fill in
261      * the base ANTLR3 structures. We initialize the function pointers
262      * for the standard ANTLR3 parser function set, but upon return
263      * from here, the programmer may set the pointers to provide custom
264      * implementations of each function. 
265      *
266      * We don't use the macros defined in LangDumpDecl.h here, in order that you can get a sense
267      * of what goes where.
268      */
269
270     /* Create a base Tree parser/recognizer, using the supplied tree node stream
271      */
272     ctx->pTreeParser            = antlr3TreeParserNewStream(ANTLR3_SIZE_HINT, instream, state);
273     /* Install the implementation of our LangDumpDecl interface
274      */
275     ctx->decl   = decl;
276     ctx->decls  = decls;
277     ctx->type   = type;
278     ctx->declarator     = declarator;
279     ctx->free                   = LangDumpDeclFree;
280     ctx->getGrammarFileName     = getGrammarFileName;
281     
282     /* Install the scope pushing methods.
283      */
284
285         
286     
287
288         
289     /* Install the token table
290      */
291     PSRSTATE->tokenNames   = LangDumpDeclTokenNames;
292     
293     
294     /* Return the newly built parser to the caller
295      */
296     return  ctx;
297 }
298
299 /** Free the parser resources
300  */
301  static void
302  LangDumpDeclFree(pLangDumpDecl ctx)
303  {
304     /* Free any scope memory
305      */
306     
307         
308         // Free this parser
309         //
310     ctx->pTreeParser->free(ctx->pTreeParser);
311     ANTLR3_FREE(ctx);
312
313     /* Everything is released, so we can return
314      */
315     return;
316  }
317  
318 /** Return token names used by this tree parser
319  *
320  * The returned pointer is used as an index into the token names table (using the token 
321  * number as the index).
322  * 
323  * \return Pointer to first char * in the table.
324  */
325 static pANTLR3_UINT8    *getTokenNames() 
326 {
327         return LangDumpDeclTokenNames; 
328 }
329
330     
331 /* Declare the bitsets
332  */
333
334 /** Bitset defining follow set for error recovery in rule state: FOLLOW_decls_in_decl58  */
335 static  ANTLR3_BITWORD FOLLOW_decls_in_decl58_bits[]    = { ANTLR3_UINT64_LIT(0x0000000000000012) };
336 static  ANTLR3_BITSET_LIST FOLLOW_decls_in_decl58       = { FOLLOW_decls_in_decl58_bits, 1      };
337 /** Bitset defining follow set for error recovery in rule state: FOLLOW_DECL_in_decls71  */
338 static  ANTLR3_BITWORD FOLLOW_DECL_in_decls71_bits[]    = { ANTLR3_UINT64_LIT(0x0000000000000004) };
339 static  ANTLR3_BITSET_LIST FOLLOW_DECL_in_decls71       = { FOLLOW_DECL_in_decls71_bits, 1      };
340 /** Bitset defining follow set for error recovery in rule state: FOLLOW_type_in_decls73  */
341 static  ANTLR3_BITWORD FOLLOW_type_in_decls73_bits[]    = { ANTLR3_UINT64_LIT(0x0000000000000020) };
342 static  ANTLR3_BITSET_LIST FOLLOW_type_in_decls73       = { FOLLOW_type_in_decls73_bits, 1      };
343 /** Bitset defining follow set for error recovery in rule state: FOLLOW_declarator_in_decls77  */
344 static  ANTLR3_BITWORD FOLLOW_declarator_in_decls77_bits[]      = { ANTLR3_UINT64_LIT(0x0000000000000008) };
345 static  ANTLR3_BITSET_LIST FOLLOW_declarator_in_decls77 = { FOLLOW_declarator_in_decls77_bits, 1        };
346 /** Bitset defining follow set for error recovery in rule state: FOLLOW_INTTYPE_in_type110  */
347 static  ANTLR3_BITWORD FOLLOW_INTTYPE_in_type110_bits[] = { ANTLR3_UINT64_LIT(0x0000000000000002) };
348 static  ANTLR3_BITSET_LIST FOLLOW_INTTYPE_in_type110    = { FOLLOW_INTTYPE_in_type110_bits, 1   };
349 /** Bitset defining follow set for error recovery in rule state: FOLLOW_ID_in_declarator126  */
350 static  ANTLR3_BITWORD FOLLOW_ID_in_declarator126_bits[]        = { ANTLR3_UINT64_LIT(0x0000000000000002) };
351 static  ANTLR3_BITSET_LIST FOLLOW_ID_in_declarator126   = { FOLLOW_ID_in_declarator126_bits, 1  };
352      
353
354  
355  
356 /* ==============================================
357  * Parsing rules
358  */
359 /** 
360  * $ANTLR start decl
361  * LangDumpDecl.g:10:1: decl : ( decls )+ ;
362  */
363 static void
364 decl(pLangDumpDecl ctx)
365 {   
366     /* Initialize rule variables
367      */
368
369
370     {
371         // LangDumpDecl.g:10:6: ( ( decls )+ )
372         // LangDumpDecl.g:10:8: ( decls )+
373         {
374             // LangDumpDecl.g:10:8: ( decls )+
375             {
376                 int cnt1=0;
377
378                 for (;;)
379                 {
380                     int alt1=2;
381                 switch ( LA(1) ) 
382                 {
383                 case DECL:
384                         {
385                                 alt1=1;
386                         }
387                     break;
388
389                 }
390
391                 switch (alt1) 
392                 {
393                     case 1:
394                         // LangDumpDecl.g:10:8: decls
395                         {
396                             FOLLOWPUSH(FOLLOW_decls_in_decl58);
397                             decls(ctx);
398
399                             FOLLOWPOP();
400                             if  (HASEXCEPTION())
401                             {
402                                 goto ruledeclEx;
403                             }
404
405
406                         }
407                         break;
408
409                     default:
410                     
411                         if ( cnt1 >= 1 )
412                         {
413                             goto loop1;
414                         }
415                         /* mismatchedSetEx()
416                          */
417                         CONSTRUCTEX();
418                         EXCEPTION->type = ANTLR3_EARLY_EXIT_EXCEPTION;
419                         EXCEPTION->name = (void *)ANTLR3_EARLY_EXIT_NAME;
420
421
422                         goto ruledeclEx;
423                 }
424                 cnt1++;
425                 }
426                 loop1: ;        /* Jump to here if this rule does not match */
427             }
428
429         }
430
431     }
432     
433
434     // This is where rules clean up and exit
435     //
436     goto ruledeclEx; /* Prevent compiler warnings */
437     ruledeclEx: ;
438
439             if (HASEXCEPTION())
440             {
441                 PREPORTERROR();
442                 PRECOVER();
443             }
444
445
446     return ;
447 }
448 /* $ANTLR end decl */
449
450 /** 
451  * $ANTLR start decls
452  * LangDumpDecl.g:13:1: decls : ^( DECL type d= declarator ) ;
453  */
454 static void
455 decls(pLangDumpDecl ctx)
456 {   
457     LangDumpDecl_declarator_return d;
458     #undef      RETURN_TYPE_d
459     #define     RETURN_TYPE_d LangDumpDecl_declarator_return
460
461     /* Initialize rule variables
462      */
463
464
465     {
466         // LangDumpDecl.g:13:7: ( ^( DECL type d= declarator ) )
467         // LangDumpDecl.g:13:9: ^( DECL type d= declarator )
468         {
469              MATCHT(DECL, &FOLLOW_DECL_in_decls71); 
470             if  (HASEXCEPTION())
471             {
472                 goto ruledeclsEx;
473             }
474
475
476             MATCHT(ANTLR3_TOKEN_DOWN, NULL); 
477             if  (HASEXCEPTION())
478             {
479                 goto ruledeclsEx;
480             }
481
482             FOLLOWPUSH(FOLLOW_type_in_decls73);
483             type(ctx);
484
485             FOLLOWPOP();
486             if  (HASEXCEPTION())
487             {
488                 goto ruledeclsEx;
489             }
490
491             FOLLOWPUSH(FOLLOW_declarator_in_decls77);
492             d=declarator(ctx);
493
494             FOLLOWPOP();
495             if  (HASEXCEPTION())
496             {
497                 goto ruledeclsEx;
498             }
499
500
501             MATCHT(ANTLR3_TOKEN_UP, NULL); 
502             if  (HASEXCEPTION())
503             {
504                 goto ruledeclsEx;
505             }
506
507             {
508
509                                         printf("int %s\n", (STRSTREAM->toStringSS(STRSTREAM, d.start, d.start))->chars);
510                        
511             }
512
513         }
514
515     }
516     
517
518     // This is where rules clean up and exit
519     //
520     goto ruledeclsEx; /* Prevent compiler warnings */
521     ruledeclsEx: ;
522
523             if (HASEXCEPTION())
524             {
525                 PREPORTERROR();
526                 PRECOVER();
527             }
528
529
530     return ;
531 }
532 /* $ANTLR end decls */
533
534 /** 
535  * $ANTLR start type
536  * LangDumpDecl.g:21:1: type : INTTYPE ;
537  */
538 static void
539 type(pLangDumpDecl ctx)
540 {   
541     /* Initialize rule variables
542      */
543
544
545     {
546         // LangDumpDecl.g:21:6: ( INTTYPE )
547         // LangDumpDecl.g:21:8: INTTYPE
548         {
549              MATCHT(INTTYPE, &FOLLOW_INTTYPE_in_type110); 
550             if  (HASEXCEPTION())
551             {
552                 goto ruletypeEx;
553             }
554
555
556         }
557
558     }
559     
560
561     // This is where rules clean up and exit
562     //
563     goto ruletypeEx; /* Prevent compiler warnings */
564     ruletypeEx: ;
565
566             if (HASEXCEPTION())
567             {
568                 PREPORTERROR();
569                 PRECOVER();
570             }
571
572
573     return ;
574 }
575 /* $ANTLR end type */
576
577 /** 
578  * $ANTLR start declarator
579  * LangDumpDecl.g:23:1: declarator : i= ID ;
580  */
581 static LangDumpDecl_declarator_return
582 declarator(pLangDumpDecl ctx)
583 {   
584     LangDumpDecl_declarator_return retval;
585
586     pANTLR3_BASE_TREE    i;
587
588     /* Initialize rule variables
589      */
590
591
592     i       = NULL;
593     retval.start = LT(1); retval.stop = retval.start;
594
595     {
596         // LangDumpDecl.g:24:6: (i= ID )
597         // LangDumpDecl.g:24:8: i= ID
598         {
599             i = (pANTLR3_BASE_TREE) MATCHT(ID, &FOLLOW_ID_in_declarator126); 
600             if  (HASEXCEPTION())
601             {
602                 goto ruledeclaratorEx;
603             }
604
605
606         }
607
608     }
609     
610
611     // This is where rules clean up and exit
612     //
613     goto ruledeclaratorEx; /* Prevent compiler warnings */
614     ruledeclaratorEx: ;
615
616             if (HASEXCEPTION())
617             {
618                 PREPORTERROR();
619                 PRECOVER();
620             }
621
622
623     return retval;
624 }
625 /* $ANTLR end declarator */
626 /* End of parsing rules
627  * ==============================================
628  */
629
630 /* ==============================================
631  * Syntactic predicates
632  */
633 /* End of syntactic predicates
634  * ==============================================
635  */
636
637  
638  
639
640
641
642 /* End of code
643  * =============================================================================
644  */