"Fossies" - the Fresh Open Source Software Archive

Member "ragel-6.10/ragel/gendata.h" (24 Mar 2017, 5459 Bytes) of package /linux/misc/ragel-6.10.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "gendata.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 6.9_vs_6.10.

    1 /*
    2  *  Copyright 2005-2007 Adrian Thurston <thurston@complang.org>
    3  */
    4 
    5 /*  This file is part of Ragel.
    6  *
    7  *  Ragel is free software; you can redistribute it and/or modify
    8  *  it under the terms of the GNU General Public License as published by
    9  *  the Free Software Foundation; either version 2 of the License, or
   10  *  (at your option) any later version.
   11  * 
   12  *  Ragel is distributed in the hope that it will be useful,
   13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15  *  GNU General Public License for more details.
   16  * 
   17  *  You should have received a copy of the GNU General Public License
   18  *  along with Ragel; if not, write to the Free Software
   19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
   20  */
   21 
   22 #ifndef _GENDATA_H
   23 #define _GENDATA_H
   24 
   25 #include <iostream>
   26 #include "config.h"
   27 #include "redfsm.h"
   28 #include "common.h"
   29 
   30 using std::ostream;
   31 
   32 extern bool generateDot;
   33 
   34 struct NameInst;
   35 typedef DList<GenAction> GenActionList;
   36 
   37 typedef unsigned long ulong;
   38 
   39 extern int gblErrorCount;
   40 
   41 struct CodeGenData;
   42 
   43 typedef AvlMap<char *, CodeGenData*, CmpStr> CodeGenMap;
   44 typedef AvlMapEl<char *, CodeGenData*> CodeGenMapEl;
   45 
   46 void cdLineDirective( ostream &out, const char *fileName, int line );
   47 void javaLineDirective( ostream &out, const char *fileName, int line );
   48 void goLineDirective( ostream &out, const char *fileName, int line );
   49 void rubyLineDirective( ostream &out, const char *fileName, int line );
   50 void csharpLineDirective( ostream &out, const char *fileName, int line );
   51 void ocamlLineDirective( ostream &out, const char *fileName, int line );
   52 void genLineDirective( ostream &out );
   53 void lineDirective( ostream &out, const char *fileName, int line );
   54 
   55 string itoa( int i );
   56 
   57 /*********************************/
   58 
   59 struct CodeGenData
   60 {
   61     /*
   62      * The interface to the code generator.
   63      */
   64     virtual void finishRagelDef() {}
   65 
   66     /* These are invoked by the corresponding write statements. */
   67     virtual void writeData() {};
   68     virtual void writeInit() {};
   69     virtual void writeExec() {};
   70     virtual void writeExports() {};
   71     virtual void writeStart() {};
   72     virtual void writeFirstFinal() {};
   73     virtual void writeError() {};
   74 
   75     /* This can also be overwridden to modify the processing of write
   76      * statements. */
   77     virtual bool writeStatement( InputLoc &loc, int nargs, char **args );
   78 
   79     /********************/
   80 
   81     CodeGenData( ostream &out );
   82     virtual ~CodeGenData() {}
   83 
   84     /* 
   85      * Collecting the machine.
   86      */
   87 
   88     const char *sourceFileName;
   89     const char *fsmName;
   90     ostream &out;
   91     RedFsmAp *redFsm;
   92     GenAction *allActions;
   93     RedAction *allActionTables;
   94     Condition *allConditions;
   95     GenCondSpace *allCondSpaces;
   96     RedStateAp *allStates;
   97     NameInst **nameIndex;
   98     int startState;
   99     int errState;
  100     GenActionList actionList;
  101     ConditionList conditionList;
  102     CondSpaceList condSpaceList;
  103     GenInlineList *getKeyExpr;
  104     GenInlineList *accessExpr;
  105     GenInlineList *prePushExpr;
  106     GenInlineList *postPopExpr;
  107 
  108     /* Overriding variables. */
  109     GenInlineList *pExpr;
  110     GenInlineList *peExpr;
  111     GenInlineList *eofExpr;
  112     GenInlineList *csExpr;
  113     GenInlineList *topExpr;
  114     GenInlineList *stackExpr;
  115     GenInlineList *actExpr;
  116     GenInlineList *tokstartExpr;
  117     GenInlineList *tokendExpr;
  118     GenInlineList *dataExpr;
  119 
  120     KeyOps thisKeyOps;
  121     bool wantComplete;
  122     EntryIdVect entryPointIds;
  123     EntryNameVect entryPointNames;
  124     bool hasLongestMatch;
  125     ExportList exportList;
  126 
  127     /* Write options. */
  128     bool noEnd;
  129     bool noPrefix;
  130     bool noFinal;
  131     bool noError;
  132     bool noEntry;
  133     bool noCS;
  134 
  135     void createMachine();
  136     void initActionList( unsigned long length );
  137     void newAction( int anum, const char *name, const InputLoc &loc, GenInlineList *inlineList );
  138     void initActionTableList( unsigned long length );
  139     void initStateList( unsigned long length );
  140     void setStartState( unsigned long startState );
  141     void setErrorState( unsigned long errState );
  142     void addEntryPoint( char *name, unsigned long entryState );
  143     void setId( int snum, int id );
  144     void setFinal( int snum );
  145     void initTransList( int snum, unsigned long length );
  146     void newTrans( int snum, int tnum, Key lowKey, Key highKey, 
  147             long targ, long act );
  148     void finishTransList( int snum );
  149     void setStateActions( int snum, long toStateAction, 
  150             long fromStateAction, long eofAction );
  151     void setEofTrans( int snum, long targ, long eofAction );
  152     void setForcedErrorState()
  153         { redFsm->forcedErrorState = true; }
  154 
  155     
  156     void initCondSpaceList( ulong length );
  157     void condSpaceItem( int cnum, long condActionId );
  158     void newCondSpace( int cnum, int condSpaceId, Key baseKey );
  159 
  160     void initStateCondList( int snum, ulong length );
  161     void addStateCond( int snum, Key lowKey, Key highKey, long condNum );
  162 
  163     GenCondSpace *findCondSpace( Key lowKey, Key highKey );
  164     Condition *findCondition( Key key );
  165 
  166     bool setAlphType( const char *data );
  167 
  168     void resolveTargetStates( GenInlineList *inlineList );
  169     Key findMaxKey();
  170 
  171     /* Gather various info on the machine. */
  172     void analyzeActionList( RedAction *redAct, GenInlineList *inlineList );
  173     void analyzeAction( GenAction *act, GenInlineList *inlineList );
  174     void findFinalActionRefs();
  175     void analyzeMachine();
  176 
  177     void closeMachine();
  178     void setValueLimits();
  179     void assignActionIds();
  180 
  181     ostream &source_warning( const InputLoc &loc );
  182     ostream &source_error( const InputLoc &loc );
  183     void write_option_error( InputLoc &loc, char *arg );
  184 };
  185 
  186 CodeGenData *makeCodeGen( const char *sourceFileName, 
  187         const char *fsmName, ostream &out );
  188 
  189 #endif