Use portable types in the C/C++ code generator
[ragel-jkt.git] / ragel / cdcodegen.cpp
blob3d7cafcd87b3e47b6552ebfe96b09f5b52491db9
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 */
7 /* This file is part of Ragel.
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.
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.
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
24 #include "cdcodegen.h"
25 #include "ragel.h"
26 #include "redfsm.h"
27 #include "gendata.h"
28 #include <sstream>
29 #include <string>
30 #include <assert.h>
33 using std::ostream;
34 using std::ostringstream;
35 using std::string;
36 using std::cerr;
37 using std::endl;
38 using std::istream;
39 using std::ifstream;
40 using std::ostream;
41 using std::ios;
42 using std::cin;
43 using std::cout;
44 using std::cerr;
45 using std::endl;
48 extern int numSplitPartitions;
49 extern bool noLineDirectives;
51 void cdLineDirective( ostream &out, const char *fileName, int line )
53 if ( noLineDirectives )
54 out << "/* ";
56 /* Write the preprocessor line info for to the input file. */
57 out << "#line " << line << " \"";
58 for ( const char *pc = fileName; *pc != 0; pc++ ) {
59 if ( *pc == '\\' )
60 out << "\\\\";
61 else
62 out << *pc;
64 out << '"';
66 if ( noLineDirectives )
67 out << " */";
69 out << '\n';
72 void FsmCodeGen::genLineDirective( ostream &out )
74 std::streambuf *sbuf = out.rdbuf();
75 output_filter *filter = static_cast<output_filter*>(sbuf);
76 cdLineDirective( out, filter->fileName, filter->line + 1 );
80 /* Init code gen with in parameters. */
81 FsmCodeGen::FsmCodeGen( ostream &out )
83 CodeGenData(out)
87 unsigned int FsmCodeGen::arrayTypeSize( unsigned long maxVal )
89 long long maxValLL = (long long) maxVal;
90 HostType *arrayType = keyOps->typeSubsumes( maxValLL );
91 assert( arrayType != 0 );
92 return arrayType->size;
95 string FsmCodeGen::ARRAY_TYPE( unsigned long maxVal )
97 long long maxValLL = (long long) maxVal;
98 HostType *arrayType = keyOps->typeSubsumes( maxValLL );
99 assert( arrayType != 0 );
101 string ret = arrayType->data1;
102 if ( arrayType->data2 != 0 ) {
103 ret += " ";
104 ret += arrayType->data2;
106 return ret;
110 /* Write out the fsm name. */
111 string FsmCodeGen::FSM_NAME()
113 return fsmName;
116 /* Emit the offset of the start state as a decimal integer. */
117 string FsmCodeGen::START_STATE_ID()
119 ostringstream ret;
120 ret << redFsm->startState->id;
121 return ret.str();
124 /* Write out the array of actions. */
125 std::ostream &FsmCodeGen::ACTIONS_ARRAY()
127 out << "\t0, ";
128 int totalActions = 1;
129 for ( GenActionTableMap::Iter act = redFsm->actionMap; act.lte(); act++ ) {
130 /* Write out the length, which will never be the last character. */
131 out << act->key.length() << ", ";
132 /* Put in a line break every 8 */
133 if ( totalActions++ % 8 == 7 )
134 out << "\n\t";
136 for ( GenActionTable::Iter item = act->key; item.lte(); item++ ) {
137 out << item->value->actionId;
138 if ( ! (act.last() && item.last()) )
139 out << ", ";
141 /* Put in a line break every 8 */
142 if ( totalActions++ % 8 == 7 )
143 out << "\n\t";
146 out << "\n";
147 return out;
151 string FsmCodeGen::ACCESS()
153 ostringstream ret;
154 if ( accessExpr != 0 )
155 INLINE_LIST( ret, accessExpr, 0, false, false );
156 return ret.str();
160 string FsmCodeGen::P()
162 ostringstream ret;
163 if ( pExpr == 0 )
164 ret << "p";
165 else {
166 ret << "(";
167 INLINE_LIST( ret, pExpr, 0, false, false );
168 ret << ")";
170 return ret.str();
173 string FsmCodeGen::PE()
175 ostringstream ret;
176 if ( peExpr == 0 )
177 ret << "pe";
178 else {
179 ret << "(";
180 INLINE_LIST( ret, peExpr, 0, false, false );
181 ret << ")";
183 return ret.str();
186 string FsmCodeGen::vEOF()
188 ostringstream ret;
189 if ( eofExpr == 0 )
190 ret << "eof";
191 else {
192 ret << "(";
193 INLINE_LIST( ret, eofExpr, 0, false, false );
194 ret << ")";
196 return ret.str();
199 string FsmCodeGen::vCS()
201 ostringstream ret;
202 if ( csExpr == 0 )
203 ret << ACCESS() << "cs";
204 else {
205 /* Emit the user supplied method of retrieving the key. */
206 ret << "(";
207 INLINE_LIST( ret, csExpr, 0, false, false );
208 ret << ")";
210 return ret.str();
213 string FsmCodeGen::TOP()
215 ostringstream ret;
216 if ( topExpr == 0 )
217 ret << ACCESS() + "top";
218 else {
219 ret << "(";
220 INLINE_LIST( ret, topExpr, 0, false, false );
221 ret << ")";
223 return ret.str();
226 string FsmCodeGen::STACK()
228 ostringstream ret;
229 if ( stackExpr == 0 )
230 ret << ACCESS() + "stack";
231 else {
232 ret << "(";
233 INLINE_LIST( ret, stackExpr, 0, false, false );
234 ret << ")";
236 return ret.str();
239 string FsmCodeGen::ACT()
241 ostringstream ret;
242 if ( actExpr == 0 )
243 ret << ACCESS() + "act";
244 else {
245 ret << "(";
246 INLINE_LIST( ret, actExpr, 0, false, false );
247 ret << ")";
249 return ret.str();
252 string FsmCodeGen::TOKSTART()
254 ostringstream ret;
255 if ( tokstartExpr == 0 )
256 ret << ACCESS() + "ts";
257 else {
258 ret << "(";
259 INLINE_LIST( ret, tokstartExpr, 0, false, false );
260 ret << ")";
262 return ret.str();
265 string FsmCodeGen::TOKEND()
267 ostringstream ret;
268 if ( tokendExpr == 0 )
269 ret << ACCESS() + "te";
270 else {
271 ret << "(";
272 INLINE_LIST( ret, tokendExpr, 0, false, false );
273 ret << ")";
275 return ret.str();
278 string FsmCodeGen::GET_WIDE_KEY()
280 if ( redFsm->anyConditions() )
281 return "_widec";
282 else
283 return GET_KEY();
286 string FsmCodeGen::GET_WIDE_KEY( RedStateAp *state )
288 if ( state->stateCondList.length() > 0 )
289 return "_widec";
290 else
291 return GET_KEY();
294 string FsmCodeGen::GET_KEY()
296 ostringstream ret;
297 if ( getKeyExpr != 0 ) {
298 /* Emit the user supplied method of retrieving the key. */
299 ret << "(";
300 INLINE_LIST( ret, getKeyExpr, 0, false, false );
301 ret << ")";
303 else {
304 /* Expression for retrieving the key, use simple dereference. */
305 ret << "(*" << P() << ")";
307 return ret.str();
310 /* Write out level number of tabs. Makes the nested binary search nice
311 * looking. */
312 string FsmCodeGen::TABS( int level )
314 string result;
315 while ( level-- > 0 )
316 result += "\t";
317 return result;
320 /* Write out a key from the fsm code gen. Depends on wether or not the key is
321 * signed. */
322 string FsmCodeGen::KEY( Key key )
324 ostringstream ret;
325 if ( keyOps->isSigned || !hostLang->explicitUnsigned )
326 ret << key.getVal();
327 else
328 ret << (unsigned long) key.getVal() << 'u';
329 return ret.str();
332 bool FsmCodeGen::isAlphTypeSigned()
334 return keyOps->isSigned;
337 bool FsmCodeGen::isWideAlphTypeSigned()
339 string ret;
340 if ( redFsm->maxKey <= keyOps->maxKey )
341 return isAlphTypeSigned();
342 else {
343 long long maxKeyVal = redFsm->maxKey.getLongLong();
344 HostType *wideType = keyOps->typeSubsumes( keyOps->isSigned, maxKeyVal );
345 return wideType->isSigned;
349 string FsmCodeGen::WIDE_KEY( RedStateAp *state, Key key )
351 if ( state->stateCondList.length() > 0 ) {
352 ostringstream ret;
353 if ( isWideAlphTypeSigned() )
354 ret << key.getVal();
355 else
356 ret << (unsigned long) key.getVal() << 'u';
357 return ret.str();
359 else {
360 return KEY( key );
366 void FsmCodeGen::EXEC( ostream &ret, GenInlineItem *item, int targState, int inFinish )
368 /* The parser gives fexec two children. The double brackets are for D
369 * code. If the inline list is a single word it will get interpreted as a
370 * C-style cast by the D compiler. */
371 ret << "{" << P() << " = ((";
372 INLINE_LIST( ret, item->children, targState, inFinish, false );
373 ret << "))-1;}";
376 void FsmCodeGen::LM_SWITCH( ostream &ret, GenInlineItem *item,
377 int targState, int inFinish, bool csForced )
379 ret <<
380 " switch( " << ACT() << " ) {\n";
382 bool haveDefault = false;
383 for ( GenInlineList::Iter lma = *item->children; lma.lte(); lma++ ) {
384 /* Write the case label, the action and the case break. */
385 if ( lma->lmId < 0 ) {
386 ret << " default:\n";
387 haveDefault = true;
389 else
390 ret << " case " << lma->lmId << ":\n";
392 /* Write the block and close it off. */
393 ret << " {";
394 INLINE_LIST( ret, lma->children, targState, inFinish, csForced );
395 ret << "}\n";
397 ret << " break;\n";
400 if ( (hostLang->lang == HostLang::D || hostLang->lang == HostLang::D2) && !haveDefault )
401 ret << " default: break;";
403 ret <<
404 " }\n"
405 "\t";
408 void FsmCodeGen::SET_ACT( ostream &ret, GenInlineItem *item )
410 ret << ACT() << " = " << item->lmId << ";";
413 void FsmCodeGen::SET_TOKEND( ostream &ret, GenInlineItem *item )
415 /* The tokend action sets tokend. */
416 ret << TOKEND() << " = " << P();
417 if ( item->offset != 0 )
418 out << "+" << item->offset;
419 out << ";";
422 void FsmCodeGen::GET_TOKEND( ostream &ret, GenInlineItem *item )
424 ret << TOKEND();
427 void FsmCodeGen::INIT_TOKSTART( ostream &ret, GenInlineItem *item )
429 ret << TOKSTART() << " = " << NULL_ITEM() << ";";
432 void FsmCodeGen::INIT_ACT( ostream &ret, GenInlineItem *item )
434 ret << ACT() << " = 0;";
437 void FsmCodeGen::SET_TOKSTART( ostream &ret, GenInlineItem *item )
439 ret << TOKSTART() << " = " << P() << ";";
442 void FsmCodeGen::SUB_ACTION( ostream &ret, GenInlineItem *item,
443 int targState, bool inFinish, bool csForced )
445 if ( item->children->length() > 0 ) {
446 /* Write the block and close it off. */
447 ret << "{";
448 INLINE_LIST( ret, item->children, targState, inFinish, csForced );
449 ret << "}";
454 /* Write out an inline tree structure. Walks the list and possibly calls out
455 * to virtual functions than handle language specific items in the tree. */
456 void FsmCodeGen::INLINE_LIST( ostream &ret, GenInlineList *inlineList,
457 int targState, bool inFinish, bool csForced )
459 for ( GenInlineList::Iter item = *inlineList; item.lte(); item++ ) {
460 switch ( item->type ) {
461 case GenInlineItem::Text:
462 ret << item->data;
463 break;
464 case GenInlineItem::Goto:
465 GOTO( ret, item->targState->id, inFinish );
466 break;
467 case GenInlineItem::Call:
468 CALL( ret, item->targState->id, targState, inFinish );
469 break;
470 case GenInlineItem::Next:
471 NEXT( ret, item->targState->id, inFinish );
472 break;
473 case GenInlineItem::Ret:
474 RET( ret, inFinish );
475 break;
476 case GenInlineItem::PChar:
477 ret << P();
478 break;
479 case GenInlineItem::Char:
480 ret << GET_KEY();
481 break;
482 case GenInlineItem::Hold:
483 ret << P() << "--;";
484 break;
485 case GenInlineItem::Exec:
486 EXEC( ret, item, targState, inFinish );
487 break;
488 case GenInlineItem::Curs:
489 CURS( ret, inFinish );
490 break;
491 case GenInlineItem::Targs:
492 TARGS( ret, inFinish, targState );
493 break;
494 case GenInlineItem::Entry:
495 ret << item->targState->id;
496 break;
497 case GenInlineItem::GotoExpr:
498 GOTO_EXPR( ret, item, inFinish );
499 break;
500 case GenInlineItem::CallExpr:
501 CALL_EXPR( ret, item, targState, inFinish );
502 break;
503 case GenInlineItem::NextExpr:
504 NEXT_EXPR( ret, item, inFinish );
505 break;
506 case GenInlineItem::LmSwitch:
507 LM_SWITCH( ret, item, targState, inFinish, csForced );
508 break;
509 case GenInlineItem::LmSetActId:
510 SET_ACT( ret, item );
511 break;
512 case GenInlineItem::LmSetTokEnd:
513 SET_TOKEND( ret, item );
514 break;
515 case GenInlineItem::LmGetTokEnd:
516 GET_TOKEND( ret, item );
517 break;
518 case GenInlineItem::LmInitTokStart:
519 INIT_TOKSTART( ret, item );
520 break;
521 case GenInlineItem::LmInitAct:
522 INIT_ACT( ret, item );
523 break;
524 case GenInlineItem::LmSetTokStart:
525 SET_TOKSTART( ret, item );
526 break;
527 case GenInlineItem::SubAction:
528 SUB_ACTION( ret, item, targState, inFinish, csForced );
529 break;
530 case GenInlineItem::Break:
531 BREAK( ret, targState, csForced );
532 break;
536 /* Write out paths in line directives. Escapes any special characters. */
537 string FsmCodeGen::LDIR_PATH( char *path )
539 ostringstream ret;
540 for ( char *pc = path; *pc != 0; pc++ ) {
541 if ( *pc == '\\' )
542 ret << "\\\\";
543 else
544 ret << *pc;
546 return ret.str();
549 void FsmCodeGen::ACTION( ostream &ret, GenAction *action, int targState,
550 bool inFinish, bool csForced )
552 /* Write the preprocessor line info for going into the source file. */
553 cdLineDirective( ret, action->loc.fileName, action->loc.line );
555 /* Write the block and close it off. */
556 ret << "\t{";
557 INLINE_LIST( ret, action->inlineList, targState, inFinish, csForced );
558 ret << "}\n";
561 void FsmCodeGen::CONDITION( ostream &ret, GenAction *condition )
563 ret << "\n";
564 cdLineDirective( ret, condition->loc.fileName, condition->loc.line );
565 INLINE_LIST( ret, condition->inlineList, 0, false, false );
568 string FsmCodeGen::ERROR_STATE()
570 ostringstream ret;
571 if ( redFsm->errState != 0 )
572 ret << redFsm->errState->id;
573 else
574 ret << "-1";
575 return ret.str();
578 string FsmCodeGen::FIRST_FINAL_STATE()
580 ostringstream ret;
581 if ( redFsm->firstFinState != 0 )
582 ret << redFsm->firstFinState->id;
583 else
584 ret << redFsm->nextStateId;
585 return ret.str();
588 void FsmCodeGen::writeInit()
590 out << " {\n";
592 if ( !noCS )
593 out << "\t" << vCS() << " = " << START() << ";\n";
595 /* If there are any calls, then the stack top needs initialization. */
596 if ( redFsm->anyActionCalls() || redFsm->anyActionRets() )
597 out << "\t" << TOP() << " = 0;\n";
599 if ( hasLongestMatch ) {
600 out <<
601 " " << TOKSTART() << " = " << NULL_ITEM() << ";\n"
602 " " << TOKEND() << " = " << NULL_ITEM() << ";\n"
603 " " << ACT() << " = 0;\n";
605 out << " }\n";
608 string FsmCodeGen::DATA_PREFIX()
610 if ( !noPrefix )
611 return FSM_NAME() + "_";
612 return "";
615 /* Emit the alphabet data type. */
616 string FsmCodeGen::ALPH_TYPE()
618 string ret = keyOps->alphType->data1;
619 if ( keyOps->alphType->data2 != 0 ) {
620 ret += " ";
621 ret += + keyOps->alphType->data2;
623 return ret;
626 /* Emit the alphabet data type. */
627 string FsmCodeGen::WIDE_ALPH_TYPE()
629 string ret;
630 if ( redFsm->maxKey <= keyOps->maxKey )
631 ret = ALPH_TYPE();
632 else {
633 long long maxKeyVal = redFsm->maxKey.getLongLong();
634 HostType *wideType = keyOps->typeSubsumes( keyOps->isSigned, maxKeyVal );
635 assert( wideType != 0 );
637 ret = wideType->data1;
638 if ( wideType->data2 != 0 ) {
639 ret += " ";
640 ret += wideType->data2;
643 return ret;
646 void FsmCodeGen::STATE_IDS()
648 if ( redFsm->startState != 0 )
649 STATIC_VAR( "int", START() ) << " = " << START_STATE_ID() << ";\n";
651 if ( !noFinal )
652 STATIC_VAR( "int" , FIRST_FINAL() ) << " = " << FIRST_FINAL_STATE() << ";\n";
654 if ( !noError )
655 STATIC_VAR( "int", ERROR() ) << " = " << ERROR_STATE() << ";\n";
657 out << "\n";
659 if ( entryPointNames.length() > 0 ) {
660 for ( EntryNameVect::Iter en = entryPointNames; en.lte(); en++ ) {
661 STATIC_VAR( "int", DATA_PREFIX() + "en_" + *en ) <<
662 " = " << entryPointIds[en.pos()] << ";\n";
664 out << "\n";
668 void FsmCodeGen::writeStart()
670 out << START_STATE_ID();
673 void FsmCodeGen::writeFirstFinal()
675 out << FIRST_FINAL_STATE();
678 void FsmCodeGen::writeError()
680 out << ERROR_STATE();
684 * Language specific, but style independent code generators functions.
687 string CCodeGen::PTR_CONST()
689 return "const ";
692 string CCodeGen::PTR_CONST_END()
694 return "";
697 std::ostream &CCodeGen::OPEN_ARRAY( string type, string name )
699 out << "static const " << type << " " << name << "[] = {\n";
700 return out;
703 std::ostream &CCodeGen::CLOSE_ARRAY()
705 return out << "};\n";
708 std::ostream &CCodeGen::STATIC_VAR( string type, string name )
710 out << "static const " << type << " " << name;
711 return out;
714 string CCodeGen::UINT( )
716 return "unsigned int";
719 string CCodeGen::ARR_OFF( string ptr, string offset )
721 return ptr + " + " + offset;
724 string CCodeGen::CAST( string type )
726 return "(" + type + ")";
729 string CCodeGen::NULL_ITEM()
731 return "0";
734 string CCodeGen::POINTER()
736 return " *";
739 std::ostream &CCodeGen::SWITCH_DEFAULT()
741 return out;
744 string CCodeGen::CTRL_FLOW()
746 return "";
749 void CCodeGen::writeExports()
751 if ( exportList.length() > 0 ) {
752 for ( ExportList::Iter ex = exportList; ex.lte(); ex++ ) {
753 out << "#define " << DATA_PREFIX() << "ex_" << ex->name << " " <<
754 KEY(ex->key) << "\n";
756 out << "\n";
761 * D Specific
764 string DCodeGen::NULL_ITEM()
766 return "null";
769 string DCodeGen::POINTER()
771 // multiple items seperated by commas can also be pointer types.
772 return "* ";
775 string DCodeGen::PTR_CONST()
777 return "";
780 string DCodeGen::PTR_CONST_END()
782 return "";
785 std::ostream &DCodeGen::OPEN_ARRAY( string type, string name )
787 out << "static const " << type << "[] " << name << " = [\n";
788 return out;
791 std::ostream &DCodeGen::CLOSE_ARRAY()
793 return out << "];\n";
796 std::ostream &DCodeGen::STATIC_VAR( string type, string name )
798 out << "static const " << type << " " << name;
799 return out;
802 string DCodeGen::ARR_OFF( string ptr, string offset )
804 return "&" + ptr + "[" + offset + "]";
807 string DCodeGen::CAST( string type )
809 return "cast(" + type + ")";
812 string DCodeGen::UINT( )
814 return "uint";
817 std::ostream &DCodeGen::SWITCH_DEFAULT()
819 out << " default: break;\n";
820 return out;
823 string DCodeGen::CTRL_FLOW()
825 return "if (true) ";
828 void DCodeGen::writeExports()
830 if ( exportList.length() > 0 ) {
831 for ( ExportList::Iter ex = exportList; ex.lte(); ex++ ) {
832 out << "static const " << ALPH_TYPE() << " " << DATA_PREFIX() <<
833 "ex_" << ex->name << " = " << KEY(ex->key) << ";\n";
835 out << "\n";
840 * End D-specific code.
844 * D2 Specific
847 string D2CodeGen::NULL_ITEM()
849 return "null";
852 string D2CodeGen::POINTER()
854 // multiple items seperated by commas can also be pointer types.
855 return "* ";
858 string D2CodeGen::PTR_CONST()
860 return "const(";
863 string D2CodeGen::PTR_CONST_END()
865 return ")";
868 std::ostream &D2CodeGen::OPEN_ARRAY( string type, string name )
870 out << "enum " << type << "[] " << name << " = [\n";
871 return out;
874 std::ostream &D2CodeGen::CLOSE_ARRAY()
876 return out << "];\n";
879 std::ostream &D2CodeGen::STATIC_VAR( string type, string name )
881 out << "enum " << type << " " << name;
882 return out;
885 string D2CodeGen::ARR_OFF( string ptr, string offset )
887 return "&" + ptr + "[" + offset + "]";
890 string D2CodeGen::CAST( string type )
892 return "cast(" + type + ")";
895 string D2CodeGen::UINT( )
897 return "uint";
900 std::ostream &D2CodeGen::SWITCH_DEFAULT()
902 out << " default: break;\n";
903 return out;
906 string D2CodeGen::CTRL_FLOW()
908 return "if (true) ";
911 void D2CodeGen::writeExports()
913 if ( exportList.length() > 0 ) {
914 for ( ExportList::Iter ex = exportList; ex.lte(); ex++ ) {
915 out << "enum " << ALPH_TYPE() << " " << DATA_PREFIX() <<
916 "ex_" << ex->name << " = " << KEY(ex->key) << ";\n";
918 out << "\n";
922 void D2CodeGen::SUB_ACTION( ostream &ret, GenInlineItem *item,
923 int targState, bool inFinish, bool csForced )
925 if ( item->children->length() > 0 ) {
926 /* Write the block and close it off. */
927 ret << "{{";
928 INLINE_LIST( ret, item->children, targState, inFinish, csForced );
929 ret << "}}";
933 void D2CodeGen::ACTION( ostream &ret, GenAction *action, int targState,
934 bool inFinish, bool csForced )
936 /* Write the preprocessor line info for going into the source file. */
937 cdLineDirective( ret, action->loc.fileName, action->loc.line );
939 /* Write the block and close it off. */
940 ret << "\t{{";
941 INLINE_LIST( ret, action->inlineList, targState, inFinish, csForced );
942 ret << "}}\n";
946 * End D2-specific code.
949 void FsmCodeGen::finishRagelDef()
951 if ( codeStyle == GenGoto || codeStyle == GenFGoto ||
952 codeStyle == GenIpGoto || codeStyle == GenSplit )
954 /* For directly executable machines there is no required state
955 * ordering. Choose a depth-first ordering to increase the
956 * potential for fall-throughs. */
957 redFsm->depthFirstOrdering();
959 else {
960 /* The frontend will do this for us, but it may be a good idea to
961 * force it if the intermediate file is edited. */
962 redFsm->sortByStateId();
965 /* Choose default transitions and the single transition. */
966 redFsm->chooseDefaultSpan();
968 /* Maybe do flat expand, otherwise choose single. */
969 if ( codeStyle == GenFlat || codeStyle == GenFFlat )
970 redFsm->makeFlat();
971 else
972 redFsm->chooseSingle();
974 /* If any errors have occured in the input file then don't write anything. */
975 if ( gblErrorCount > 0 )
976 return;
978 if ( codeStyle == GenSplit )
979 redFsm->partitionFsm( numSplitPartitions );
981 if ( codeStyle == GenIpGoto || codeStyle == GenSplit )
982 redFsm->setInTrans();
984 /* Anlayze Machine will find the final action reference counts, among
985 * other things. We will use these in reporting the usage
986 * of fsm directives in action code. */
987 analyzeMachine();
989 /* Determine if we should use indicies. */
990 calcIndexSize();
993 ostream &FsmCodeGen::source_warning( const InputLoc &loc )
995 cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": warning: ";
996 return cerr;
999 ostream &FsmCodeGen::source_error( const InputLoc &loc )
1001 gblErrorCount += 1;
1002 assert( sourceFileName != 0 );
1003 cerr << sourceFileName << ":" << loc.line << ":" << loc.col << ": ";
1004 return cerr;