More work on the direct connection between frontend and backend. Now appears to
[external/ragel.git] / ragel / xmlcodegen.h
index 6c80ac7..22d6dec 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2005-2007 Adrian Thurston <thurston@cs.queensu.ca>
+ *  Copyright 2005-2007 Adrian Thurston <thurston@complang.org>
  */
 
 /*  This file is part of Ragel.
 #include "avltree.h"
 #include "fsmgraph.h"
 #include "parsedata.h"
+#include "redfsm.h"
 
 /* Forwards. */
 struct TransAp;
 struct FsmAp;
 struct ParseData;
+struct GenInlineList;
 
 struct RedActionTable
 :
@@ -76,30 +78,44 @@ struct NextRedTrans
        }
 };
 
-class XMLCodeGen
+struct GenBase
+{
+       GenBase( char *fsmName, ParseData *pd, FsmAp *fsm, XmlParser &xmlParser );
+
+       void appendTrans( TransListVect &outList, Key lowKey, Key highKey, TransAp *trans );
+       void reduceActionTables();
+
+       char *fsmName;
+       ParseData *pd;
+       FsmAp *fsm;
+       XmlParser &xmlParser;
+
+       ActionTableMap actionTableMap;
+       int nextActionTableId;
+};
+
+class XMLCodeGen : protected GenBase
 {
 public:
-       XMLCodeGen( char *fsmName, ParseData *pd, FsmAp *fsm, std::ostream &out );
+       XMLCodeGen( char *fsmName, ParseData *pd, FsmAp *fsm, 
+                       std::ostream &out, XmlParser &xmlParser );
+
        void writeXML( );
 
 private:
-       void appendTrans( TransListVect &outList, Key lowKey, Key highKey, TransAp *trans );
        void writeStateActions( StateAp *state );
        void writeStateList();
        void writeStateConditions( StateAp *state );
 
        void writeKey( Key key );
        void writeText( InlineItem *item );
-       void writeCtrlFlow( InlineItem *item, InlineItem *context );
-       void writePtrMod( InlineItem *item, InlineItem *context );
-       void writeGoto( InlineItem *item, InlineItem *context );
-       void writeGotoExpr( InlineItem *item, InlineItem *context );
-       void writeCall( InlineItem *item, InlineItem *context );
-       void writeCallExpr( InlineItem *item, InlineItem *context );
-       void writeNext( InlineItem *item, InlineItem *context );
-       void writeNextExpr( InlineItem *item, InlineItem *context );
+       void writeGoto( InlineItem *item );
+       void writeGotoExpr( InlineItem *item );
+       void writeCall( InlineItem *item );
+       void writeCallExpr( InlineItem *item );
+       void writeNext( InlineItem *item );
+       void writeNextExpr( InlineItem *item );
        void writeEntry( InlineItem *item );
-       void writeLmSetActId( InlineItem *item );
        void writeLmOnLast( InlineItem *item );
        void writeLmOnNext( InlineItem *item );
        void writeLmOnLagBehind( InlineItem *item );
@@ -107,30 +123,58 @@ private:
        void writeExports();
        bool writeNameInst( NameInst *nameInst );
        void writeEntryPoints();
-       void writeGetKeyExpr();
-       void writeAccessExpr();
-       void writeCurStateExpr();
        void writeConditions();
-       void writeInlineList( InlineList *inlineList, InlineItem *context );
-       void writeAlphType();
+       void writeInlineList( InlineList *inlineList );
        void writeActionList();
        void writeActionTableList();
        void reduceTrans( TransAp *trans );
-       void reduceActionTables();
        void writeTransList( StateAp *state );
+       void writeEofTrans( StateAp *state );
        void writeTrans( Key lowKey, Key highKey, TransAp *defTrans );
        void writeAction( Action *action );
        void writeLmSwitch( InlineItem *item );
        void writeMachine();
        void writeActionExec( InlineItem *item );
-       void writeActionExecTE( InlineItem *item );
 
-       char *fsmName;
-       ParseData *pd;
-       FsmAp *fsm;
        std::ostream &out;
-       ActionTableMap actionTableMap;
-       int nextActionTableId;
+};
+
+class BackendGen : protected GenBase
+{
+public:
+       BackendGen( char *fsmName, ParseData *pd, FsmAp *fsm, XmlParser &xmlParser );
+       void makeBackend( );
+
+private:
+       void makeGenInlineList( GenInlineList *outList, InlineList *inList );
+       void makeKey( GenInlineList *outList, Key key );
+       void makeText( GenInlineList *outList, InlineItem *item );
+       void makeLmOnLast( GenInlineList *outList, InlineItem *item );
+       void makeLmOnNext( GenInlineList *outList, InlineItem *item );
+       void makeLmOnLagBehind( GenInlineList *outList, InlineItem *item );
+       void makeActionExec( GenInlineList *outList, InlineItem *item );
+       void makeLmSwitch( GenInlineList *outList, InlineItem *item );
+       void makeSetTokend( GenInlineList *outList, long offset );
+       void makeSetAct( GenInlineList *outList, long lmId );
+       void makeSubList( GenInlineList *outList, InlineList *inlineList, 
+                       GenInlineItem::Type type );
+       void makeTargetItem( GenInlineList *outList, long targetId, GenInlineItem::Type type );
+       void makeExecGetTokend( GenInlineList *outList );
+       void makeExports();
+       void makeMachine();
+       void makeActionList();
+       void makeAction( Action *action );
+       void makeActionTableList();
+       void makeConditions();
+       void makeEntryPoints();
+       bool makeNameInst( std::string &out, NameInst *nameInst );
+       void makeStateList();
+
+       void makeStateActions( StateAp *state );
+       void makeEofTrans( StateAp *state );
+       void makeStateConditions( StateAp *state );
+       void makeTransList( StateAp *state );
+       void makeTrans( Key lowKey, Key highKey, TransAp *trans );
 };