Initialize Tizen 2.3
[external/ragel.git] / ragel / cscodegen.cpp
1 /*
2  *  Copyright 2001-2006 Adrian Thurston <thurston@complang.org>
3  *            2004 Erich Ocean <eric.ocean@ampede.com>
4  *            2005 Alan West <alan@alanz.com>
5  */
6
7 /*  This file is part of Ragel.
8  *
9  *  Ragel 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 2 of the License, or
12  *  (at your option) any later version.
13  * 
14  *  Ragel is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  * 
19  *  You should have received a copy of the GNU General Public License
20  *  along with Ragel; if not, write to the Free Software
21  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
22  */
23
24 #include "ragel.h"
25 #include "cscodegen.h"
26 #include "redfsm.h"
27 #include "gendata.h"
28 #include <sstream>
29 #include <iomanip>
30 #include <string>
31 #include <assert.h>
32
33 using std::ostream;
34 using std::ostringstream;
35 using std::string;
36 using std::cerr;
37 using std::endl;
38
39 using std::istream;
40 using std::ifstream;
41 using std::ostream;
42 using std::ios;
43 using std::cin;
44 using std::cout;
45 using std::cerr;
46 using std::endl;
47
48 void csharpLineDirective( ostream &out, const char *fileName, int line )
49 {
50         if ( noLineDirectives )
51                 out << "/* ";
52
53         /* Write the preprocessor line info for to the input file. */
54         out << "#line " << line  << " \"";
55         for ( const char *pc = fileName; *pc != 0; pc++ ) {
56                 if ( *pc == '\\' )
57                         out << "\\\\";
58                 else
59                         out << *pc;
60         }
61         out << '"';
62
63         if ( noLineDirectives )
64                 out << " */";
65
66         out << '\n';
67 }
68
69 void CSharpFsmCodeGen::genLineDirective( ostream &out )
70 {
71         std::streambuf *sbuf = out.rdbuf();
72         output_filter *filter = static_cast<output_filter*>(sbuf);
73         csharpLineDirective( out, filter->fileName, filter->line + 1 );
74 }
75
76
77 /* Init code gen with in parameters. */
78 CSharpFsmCodeGen::CSharpFsmCodeGen( ostream &out )
79 :
80         CodeGenData(out)
81 {
82 }
83
84 unsigned int CSharpFsmCodeGen::arrayTypeSize( unsigned long maxVal )
85 {
86         long long maxValLL = (long long) maxVal;
87         HostType *arrayType = keyOps->typeSubsumes( maxValLL );
88         assert( arrayType != 0 );
89         return arrayType->size;
90 }
91
92 string CSharpFsmCodeGen::ARRAY_TYPE( unsigned long maxVal )
93 {
94         return ARRAY_TYPE( maxVal, false );
95 }
96
97 string CSharpFsmCodeGen::ARRAY_TYPE( unsigned long maxVal, bool forceSigned )
98 {
99         long long maxValLL = (long long) maxVal;
100         HostType *arrayType;
101         if (forceSigned)
102                 arrayType = keyOps->typeSubsumes(true, maxValLL);
103         else
104                 arrayType = keyOps->typeSubsumes( maxValLL );
105         assert( arrayType != 0 );
106
107         string ret = arrayType->data1;
108         if ( arrayType->data2 != 0 ) {
109                 ret += " ";
110                 ret += arrayType->data2;
111         }
112         return ret;
113 }
114
115 /* Write out the fsm name. */
116 string CSharpFsmCodeGen::FSM_NAME()
117 {
118         return fsmName;
119 }
120
121 /* Emit the offset of the start state as a decimal integer. */
122 string CSharpFsmCodeGen::START_STATE_ID()
123 {
124         ostringstream ret;
125         ret << redFsm->startState->id;
126         return ret.str();
127 };
128
129 /* Write out the array of actions. */
130 std::ostream &CSharpFsmCodeGen::ACTIONS_ARRAY()
131 {
132         out << "\t0, ";
133         int totalActions = 1;
134         for ( GenActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
135                 /* Write out the length, which will never be the last character. */
136                 out << act->key.length() << ", ";
137                 /* Put in a line break every 8 */
138                 if ( totalActions++ % 8 == 7 )
139                         out << "\n\t";
140
141                 for ( GenActionTable::Iter item = act->key; item.lte(); item++ ) {
142                         out << item->value->actionId;
143                         if ( ! (act.last() && item.last()) )
144                                 out << ", ";
145
146                         /* Put in a line break every 8 */
147                         if ( totalActions++ % 8 == 7 )
148                                 out << "\n\t";
149                 }
150         }
151         out << "\n";
152         return out;
153 }
154
155
156 string CSharpFsmCodeGen::ACCESS()
157 {
158         ostringstream ret;
159         if ( accessExpr != 0 )
160                 INLINE_LIST( ret, accessExpr, 0, false );
161         return ret.str();
162 }
163
164
165 string CSharpFsmCodeGen::P()
166
167         ostringstream ret;
168         if ( pExpr == 0 )
169                 ret << "p";
170         else {
171                 ret << "(";
172                 INLINE_LIST( ret, pExpr, 0, false );
173                 ret << ")";
174         }
175         return ret.str();
176 }
177
178 string CSharpFsmCodeGen::PE()
179 {
180         ostringstream ret;
181         if ( peExpr == 0 )
182                 ret << "pe";
183         else {
184                 ret << "(";
185                 INLINE_LIST( ret, peExpr, 0, false );
186                 ret << ")";
187         }
188         return ret.str();
189 }
190
191 string CSharpFsmCodeGen::vEOF()
192 {
193         ostringstream ret;
194         if ( eofExpr == 0 )
195                 ret << "eof";
196         else {
197                 ret << "(";
198                 INLINE_LIST( ret, eofExpr, 0, false );
199                 ret << ")";
200         }
201         return ret.str();
202 }
203
204 string CSharpFsmCodeGen::vCS()
205 {
206         ostringstream ret;
207         if ( csExpr == 0 )
208                 ret << ACCESS() << "cs";
209         else {
210                 /* Emit the user supplied method of retrieving the key. */
211                 ret << "(";
212                 INLINE_LIST( ret, csExpr, 0, false );
213                 ret << ")";
214         }
215         return ret.str();
216 }
217
218 string CSharpFsmCodeGen::TOP()
219 {
220         ostringstream ret;
221         if ( topExpr == 0 )
222                 ret << ACCESS() + "top";
223         else {
224                 ret << "(";
225                 INLINE_LIST( ret, topExpr, 0, false );
226                 ret << ")";
227         }
228         return ret.str();
229 }
230
231 string CSharpFsmCodeGen::STACK()
232 {
233         ostringstream ret;
234         if ( stackExpr == 0 )
235                 ret << ACCESS() + "stack";
236         else {
237                 ret << "(";
238                 INLINE_LIST( ret, stackExpr, 0, false );
239                 ret << ")";
240         }
241         return ret.str();
242 }
243
244 string CSharpFsmCodeGen::ACT()
245 {
246         ostringstream ret;
247         if ( actExpr == 0 )
248                 ret << ACCESS() + "act";
249         else {
250                 ret << "(";
251                 INLINE_LIST( ret, actExpr, 0, false );
252                 ret << ")";
253         }
254         return ret.str();
255 }
256
257 string CSharpFsmCodeGen::TOKSTART()
258 {
259         ostringstream ret;
260         if ( tokstartExpr == 0 )
261                 ret << ACCESS() + "ts";
262         else {
263                 ret << "(";
264                 INLINE_LIST( ret, tokstartExpr, 0, false );
265                 ret << ")";
266         }
267         return ret.str();
268 }
269
270 string CSharpFsmCodeGen::TOKEND()
271 {
272         ostringstream ret;
273         if ( tokendExpr == 0 )
274                 ret << ACCESS() + "te";
275         else {
276                 ret << "(";
277                 INLINE_LIST( ret, tokendExpr, 0, false );
278                 ret << ")";
279         }
280         return ret.str();
281 }
282
283 string CSharpFsmCodeGen::GET_WIDE_KEY()
284 {
285         if ( redFsm->anyConditions() ) 
286                 return "_widec";
287         else
288                 return GET_KEY();
289 }
290
291 string CSharpFsmCodeGen::GET_WIDE_KEY( RedStateAp *state )
292 {
293         if ( state->stateCondList.length() > 0 )
294                 return "_widec";
295         else
296                 return GET_KEY();
297 }
298
299 string CSharpFsmCodeGen::GET_KEY()
300 {
301         ostringstream ret;
302         if ( getKeyExpr != 0 ) { 
303                 /* Emit the user supplied method of retrieving the key. */
304                 ret << "(";
305                 INLINE_LIST( ret, getKeyExpr, 0, false );
306                 ret << ")";
307         }
308         else {
309                 /* Expression for retrieving the key, use simple dereference. */
310                 ret << "(*" << P() << ")";
311         }
312         return ret.str();
313 }
314
315 /* Write out level number of tabs. Makes the nested binary search nice
316  * looking. */
317 string CSharpFsmCodeGen::TABS( int level )
318 {
319         string result;
320         while ( level-- > 0 )
321                 result += "\t";
322         return result;
323 }
324
325 /* Write out a key from the fsm code gen. Depends on wether or not the key is
326  * signed. */
327 string CSharpFsmCodeGen::KEY( Key key )
328 {
329         ostringstream ret;
330         if ( keyOps->isSigned || !hostLang->explicitUnsigned )
331                 ret << key.getVal();
332         else
333                 ret << (unsigned long) key.getVal() << 'u';
334         return ret.str();
335 }
336
337 string CSharpFsmCodeGen::ALPHA_KEY( Key key )
338 {
339         ostringstream ret;
340         if (key.getVal() > 0xFFFF) {
341                 ret << key.getVal();
342         } else {
343                 ret << "'\\u" << std::hex << std::setw(4) << std::setfill('0') << 
344                         key.getVal() << "'";
345         }
346         //ret << "(char) " << key.getVal();
347         return ret.str();
348 }
349
350 void CSharpFsmCodeGen::EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish )
351 {
352         /* The parser gives fexec two children. The double brackets are for D
353          * code. If the inline list is a single word it will get interpreted as a
354          * C-style cast by the D compiler. */
355         ret << "{" << P() << " = ((";
356         INLINE_LIST( ret, item->children, targState, inFinish );
357         ret << "))-1;}";
358 }
359
360 void CSharpFsmCodeGen::LM_SWITCH( ostream &ret, GenInlineItem *item, 
361                 int targState, int inFinish )
362 {
363         ret << 
364                 "       switch( " << ACT() << " ) {\n";
365
366         for ( GenInlineList::Iter lma = *item->children; lma.lte(); lma++ ) {
367                 /* Write the case label, the action and the case break. */
368                 if ( lma->lmId < 0 )
369                         ret << "        default:\n";
370                 else
371                         ret << "        case " << lma->lmId << ":\n";
372
373                 /* Write the block and close it off. */
374                 ret << "        {";
375                 INLINE_LIST( ret, lma->children, targState, inFinish );
376                 ret << "}\n";
377
378                 ret << "        break;\n";
379         }
380
381         ret << 
382                 "       }\n"
383                 "\t";
384 }
385
386 void CSharpFsmCodeGen::SET_ACT( ostream &ret, GenInlineItem *item )
387 {
388         ret << ACT() << " = " << item->lmId << ";";
389 }
390
391 void CSharpFsmCodeGen::SET_TOKEND( ostream &ret, GenInlineItem *item )
392 {
393         /* The tokend action sets tokend. */
394         ret << TOKEND() << " = " << P();
395         if ( item->offset != 0 ) 
396                 out << "+" << item->offset;
397         out << ";";
398 }
399
400 void CSharpFsmCodeGen::GET_TOKEND( ostream &ret, GenInlineItem *item )
401 {
402         ret << TOKEND();
403 }
404
405 void CSharpFsmCodeGen::INIT_TOKSTART( ostream &ret, GenInlineItem *item )
406 {
407         ret << TOKSTART() << " = " << NULL_ITEM() << ";";
408 }
409
410 void CSharpFsmCodeGen::INIT_ACT( ostream &ret, GenInlineItem *item )
411 {
412         ret << ACT() << " = 0;";
413 }
414
415 void CSharpFsmCodeGen::SET_TOKSTART( ostream &ret, GenInlineItem *item )
416 {
417         ret << TOKSTART() << " = " << P() << ";";
418 }
419
420 void CSharpFsmCodeGen::SUB_ACTION( ostream &ret, GenInlineItem *item, 
421                 int targState, bool inFinish )
422 {
423         if ( item->children->length() > 0 ) {
424                 /* Write the block and close it off. */
425                 ret << "{";
426                 INLINE_LIST( ret, item->children, targState, inFinish );
427                 ret << "}";
428         }
429 }
430
431
432 /* Write out an inline tree structure. Walks the list and possibly calls out
433  * to virtual functions than handle language specific items in the tree. */
434 void CSharpFsmCodeGen::INLINE_LIST( ostream &ret, GenInlineList *inlineList, 
435                 int targState, bool inFinish )
436 {
437         for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) {
438                 switch ( item->type ) {
439                 case GenInlineItem::Text:
440                         ret << item->data;
441                         break;
442                 case GenInlineItem::Goto:
443                         GOTO( ret, item->targState->id, inFinish );
444                         break;
445                 case GenInlineItem::Call:
446                         CALL( ret, item->targState->id, targState, inFinish );
447                         break;
448                 case GenInlineItem::Next:
449                         NEXT( ret, item->targState->id, inFinish );
450                         break;
451                 case GenInlineItem::Ret:
452                         RET( ret, inFinish );
453                         break;
454                 case GenInlineItem::PChar:
455                         ret << P();
456                         break;
457                 case GenInlineItem::Char:
458                         ret << GET_KEY();
459                         break;
460                 case GenInlineItem::Hold:
461                         ret << P() << "--;";
462                         break;
463                 case GenInlineItem::Exec:
464                         EXEC( ret, item, targState, inFinish );
465                         break;
466                 case GenInlineItem::Curs:
467                         CURS( ret, inFinish );
468                         break;
469                 case GenInlineItem::Targs:
470                         TARGS( ret, inFinish, targState );
471                         break;
472                 case GenInlineItem::Entry:
473                         ret << item->targState->id;
474                         break;
475                 case GenInlineItem::GotoExpr:
476                         GOTO_EXPR( ret, item, inFinish );
477                         break;
478                 case GenInlineItem::CallExpr:
479                         CALL_EXPR( ret, item, targState, inFinish );
480                         break;
481                 case GenInlineItem::NextExpr:
482                         NEXT_EXPR( ret, item, inFinish );
483                         break;
484                 case GenInlineItem::LmSwitch:
485                         LM_SWITCH( ret, item, targState, inFinish );
486                         break;
487                 case GenInlineItem::LmSetActId:
488                         SET_ACT( ret, item );
489                         break;
490                 case GenInlineItem::LmSetTokEnd:
491                         SET_TOKEND( ret, item );
492                         break;
493                 case GenInlineItem::LmGetTokEnd:
494                         GET_TOKEND( ret, item );
495                         break;
496                 case GenInlineItem::LmInitTokStart:
497                         INIT_TOKSTART( ret, item );
498                         break;
499                 case GenInlineItem::LmInitAct:
500                         INIT_ACT( ret, item );
501                         break;
502                 case GenInlineItem::LmSetTokStart:
503                         SET_TOKSTART( ret, item );
504                         break;
505                 case GenInlineItem::SubAction:
506                         SUB_ACTION( ret, item, targState, inFinish );
507                         break;
508                 case GenInlineItem::Break:
509                         BREAK( ret, targState );
510                         break;
511                 }
512         }
513 }
514 /* Write out paths in line directives. Escapes any special characters. */
515 string CSharpFsmCodeGen::LDIR_PATH( char *path )
516 {
517         ostringstream ret;
518         for ( char *pc = path; *pc != 0; pc++ ) {
519                 if ( *pc == '\\' )
520                         ret << "\\\\";
521                 else
522                         ret << *pc;
523         }
524         return ret.str();
525 }
526
527 void CSharpFsmCodeGen::ACTION( ostream &ret, GenAction *action, int targState, bool inFinish )
528 {
529         /* Write the preprocessor line info for going into the source file. */
530         csharpLineDirective( ret, action->loc.fileName, action->loc.line );
531
532         /* Write the block and close it off. */
533         ret << "\t{";
534         INLINE_LIST( ret, action->inlineList, targState, inFinish );
535         ret << "}\n";
536 }
537
538 void CSharpFsmCodeGen::CONDITION( ostream &ret, GenAction *condition )
539 {
540         ret << "\n";
541         csharpLineDirective( ret, condition->loc.fileName, condition->loc.line );
542         INLINE_LIST( ret, condition->inlineList, 0, false );
543 }
544
545 string CSharpFsmCodeGen::ERROR_STATE()
546 {
547         ostringstream ret;
548         if ( redFsm->errState != 0 )
549                 ret << redFsm->errState->id;
550         else
551                 ret << "-1";
552         return ret.str();
553 }
554
555 string CSharpFsmCodeGen::FIRST_FINAL_STATE()
556 {
557         ostringstream ret;
558         if ( redFsm->firstFinState != 0 )
559                 ret << redFsm->firstFinState->id;
560         else
561                 ret << redFsm->nextStateId;
562         return ret.str();
563 }
564
565 void CSharpFsmCodeGen::writeInit()
566 {
567         out << "        {\n";
568
569         if ( !noCS )
570                 out << "\t" << vCS() << " = " << START() << ";\n";
571         
572         /* If there are any calls, then the stack top needs initialization. */
573         if ( redFsm->anyActionCalls() || redFsm->anyActionRets() )
574                 out << "\t" << TOP() << " = 0;\n";
575
576         if ( hasLongestMatch ) {
577                 out << 
578                         "       " << TOKSTART() << " = " << NULL_ITEM() << ";\n"
579                         "       " << TOKEND() << " = " << NULL_ITEM() << ";\n"
580                         "       " << ACT() << " = 0;\n";
581         }
582         out << "        }\n";
583 }
584
585 string CSharpFsmCodeGen::DATA_PREFIX()
586 {
587         if ( !noPrefix )
588                 return FSM_NAME() + "_";
589         return "";
590 }
591
592 /* Emit the alphabet data type. */
593 string CSharpFsmCodeGen::ALPH_TYPE()
594 {
595         string ret = keyOps->alphType->data1;
596         if ( keyOps->alphType->data2 != 0 ) {
597                 ret += " ";
598                 ret += + keyOps->alphType->data2;
599         }
600         return ret;
601 }
602
603 /* Emit the alphabet data type. */
604 string CSharpFsmCodeGen::WIDE_ALPH_TYPE()
605 {
606         string ret;
607         if ( redFsm->maxKey <= keyOps->maxKey )
608                 ret = ALPH_TYPE();
609         else {
610                 long long maxKeyVal = redFsm->maxKey.getLongLong();
611                 HostType *wideType = keyOps->typeSubsumes( keyOps->isSigned, maxKeyVal );
612                 assert( wideType != 0 );
613
614                 ret = wideType->data1;
615                 if ( wideType->data2 != 0 ) {
616                         ret += " ";
617                         ret += wideType->data2;
618                 }
619         }
620         return ret;
621 }
622
623 void CSharpFsmCodeGen::STATE_IDS()
624 {
625         if ( redFsm->startState != 0 )
626                 STATIC_VAR( "int", START() ) << " = " << START_STATE_ID() << ";\n";
627
628         if ( !noFinal )
629                 STATIC_VAR( "int" , FIRST_FINAL() ) << " = " << FIRST_FINAL_STATE() << ";\n";
630
631         if ( !noError )
632                 STATIC_VAR( "int", ERROR() ) << " = " << ERROR_STATE() << ";\n";
633
634         out << "\n";
635
636         if ( entryPointNames.length() > 0 ) {
637                 for ( EntryNameVect::Iter en = entryPointNames; en.lte(); en++ ) {
638                         STATIC_VAR( "int", DATA_PREFIX() + "en_" + *en ) << 
639                                         " = " << entryPointIds[en.pos()] << ";\n";
640                 }
641                 out << "\n";
642         }
643 }
644
645
646 void CSharpFsmCodeGen::writeStart()
647 {
648         out << START_STATE_ID();
649 }
650
651 void CSharpFsmCodeGen::writeFirstFinal()
652 {
653         out << FIRST_FINAL_STATE();
654 }
655
656 void CSharpFsmCodeGen::writeError()
657 {
658         out << ERROR_STATE();
659 }
660
661 /*
662  * C# Specific
663  */
664 string CSharpCodeGen::GET_KEY()
665 {
666         ostringstream ret;
667         if ( getKeyExpr != 0 ) { 
668                 /* Emit the user supplied method of retrieving the key. */
669                 ret << "(";
670                 INLINE_LIST( ret, getKeyExpr, 0, false );
671                 ret << ")";
672         }
673         else {
674                 /* Expression for retrieving the key, use simple dereference. */
675                 ret << "data[" << P() << "]";
676         }
677         return ret.str();
678 }
679 string CSharpCodeGen::NULL_ITEM()
680 {
681         return "-1";
682 }
683
684 string CSharpCodeGen::POINTER()
685 {
686         // XXX C# has no pointers
687         // multiple items seperated by commas can also be pointer types.
688         return " ";
689 }
690
691 string CSharpCodeGen::PTR_CONST()
692 {
693         return "";
694 }
695
696 std::ostream &CSharpCodeGen::OPEN_ARRAY( string type, string name )
697 {
698         out << "static readonly " << type << "[] " << name << " =  ";
699         /*
700         if (type == "char")
701                 out << "Encoding.ASCII.Get";
702         else */
703                 out << "new " << type << " [] {\n";
704         return out;
705 }
706
707 std::ostream &CSharpCodeGen::CLOSE_ARRAY()
708 {
709         return out << "};\n";
710 }
711
712 std::ostream &CSharpCodeGen::STATIC_VAR( string type, string name )
713 {
714         out << "const " << type << " " << name;
715         return out;
716 }
717
718 string CSharpCodeGen::ARR_OFF( string ptr, string offset )
719 {
720         // XXX C# can't do pointer arithmetic
721         return "&" + ptr + "[" + offset + "]";
722 }
723
724 string CSharpCodeGen::CAST( string type )
725 {
726         return "(" + type + ")";
727 }
728
729 string CSharpCodeGen::UINT( )
730 {
731         return "uint";
732 }
733
734 std::ostream &CSharpCodeGen::SWITCH_DEFAULT()
735 {
736         out << "                default: break;\n";
737         return out;
738 }
739
740 string CSharpCodeGen::CTRL_FLOW()
741 {
742         return "if (true) ";
743 }
744
745 void CSharpCodeGen::writeExports()
746 {
747         if ( exportList.length() > 0 ) {
748                 for ( ExportList::Iter ex = exportList; ex.lte(); ex++ ) {
749                         out << "const " << ALPH_TYPE() << " " << DATA_PREFIX() << 
750                                         "ex_" << ex->name << " = " << KEY(ex->key) << ";\n";
751                 }
752                 out << "\n";
753         }
754 }
755
756 /*
757  * End C#-specific code.
758  */
759
760 void CSharpFsmCodeGen::finishRagelDef()
761 {
762         if ( codeStyle == GenGoto || codeStyle == GenFGoto || 
763                         codeStyle == GenIpGoto || codeStyle == GenSplit )
764         {
765                 /* For directly executable machines there is no required state
766                  * ordering. Choose a depth-first ordering to increase the
767                  * potential for fall-throughs. */
768                 redFsm->depthFirstOrdering();
769         }
770         else {
771                 /* The frontend will do this for us, but it may be a good idea to
772                  * force it if the intermediate file is edited. */
773                 redFsm->sortByStateId();
774         }
775
776         /* Choose default transitions and the single transition. */
777         redFsm->chooseDefaultSpan();
778                 
779         /* Maybe do flat expand, otherwise choose single. */
780         if ( codeStyle == GenFlat || codeStyle == GenFFlat )
781                 redFsm->makeFlat();
782         else
783                 redFsm->chooseSingle();
784
785         /* If any errors have occured in the input file then don't write anything. */
786         if ( gblErrorCount > 0 )
787                 return;
788         
789         if ( codeStyle == GenSplit )
790                 redFsm->partitionFsm( numSplitPartitions );
791
792         if ( codeStyle == GenIpGoto || codeStyle == GenSplit )
793                 redFsm->setInTrans();
794
795         /* Anlayze Machine will find the final action reference counts, among
796          * other things. We will use these in reporting the usage
797          * of fsm directives in action code. */
798         analyzeMachine();
799
800         /* Determine if we should use indicies. */
801         calcIndexSize();
802 }
803
804 ostream &CSharpFsmCodeGen::source_warning( const InputLoc &loc )
805 {
806         cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": warning: ";
807         return cerr;
808 }
809
810 ostream &CSharpFsmCodeGen::source_error( const InputLoc &loc )
811 {
812         gblErrorCount += 1;
813         assert( sourceFileName != 0 );
814         cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": ";
815         return cerr;
816 }
817