More work on the direct access to the backend. The xml code gen should be
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Wed, 8 Oct 2008 17:47:19 +0000 (17:47 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Wed, 8 Oct 2008 17:47:19 +0000 (17:47 +0000)
preserved, not converted. Going to have to bring back some changed code.

git-svn-id: http://svn.complang.org/ragel/trunk@487 052ea7fc-9027-0410-9066-f65837a77df0

common/common.cpp
common/common.h
ragel/xmlcodegen.cpp
ragel/xmlcodegen.h
redfsm/gendata.cpp
redfsm/gendata.h
redfsm/xmlparse.kl

index 7030b44..d5e945d 100644 (file)
@@ -110,7 +110,7 @@ HostLang hostLangCSharp = { HostLang::CSharp, hostTypesCSharp, 9, hostTypesCShar
 
 HostLang *hostLang = &hostLangC;
 
-HostType *findAlphType( char *s1 )
+HostType *findAlphType( const char *s1 )
 {
        for ( int i = 0; i < hostLang->numHostTypes; i++ ) {
                if ( strcmp( s1, hostLang->hostTypes[i].data1 ) == 0 && 
@@ -123,7 +123,7 @@ HostType *findAlphType( char *s1 )
        return 0;
 }
 
-HostType *findAlphType( char *s1, char *s2 )
+HostType *findAlphType( const char *s1, const char *s2 )
 {
        for ( int i = 0; i < hostLang->numHostTypes; i++ ) {
                if ( strcmp( s1, hostLang->hostTypes[i].data1 ) == 0 && 
@@ -137,7 +137,7 @@ HostType *findAlphType( char *s1, char *s2 )
        return 0;
 }
 
-HostType *findAlphTypeInternal( char *s1 )
+HostType *findAlphTypeInternal( const char *s1 )
 {
        for ( int i = 0; i < hostLang->numHostTypes; i++ ) {
                if ( strcmp( s1, hostLang->hostTypes[i].internalName ) == 0 )
index 5370d02..4185a82 100644 (file)
@@ -133,9 +133,9 @@ extern HostLang hostLangJava;
 extern HostLang hostLangRuby;
 extern HostLang hostLangCSharp;
 
-HostType *findAlphType( char *s1 );
-HostType *findAlphType( char *s1, char *s2 );
-HostType *findAlphTypeInternal( char *s1 );
+HostType *findAlphType( const char *s1 );
+HostType *findAlphType( const char *s1, const char *s2 );
+HostType *findAlphTypeInternal( const char *s1 );
 
 /* An abstraction of the key operators that manages key operations such as
  * comparison and increment according the signedness of the key. */
index 1f6a3d0..e197e07 100644 (file)
@@ -25,6 +25,7 @@
 #include "xmlparse.h"
 #include "parsedata.h"
 #include "fsmgraph.h"
+#include "gendata.h"
 #include <string.h>
 
 using namespace std;
@@ -441,6 +442,156 @@ void XMLCodeGen::writeInlineList( InlineList *inlineList )
        }
 }
 
+void XMLCodeGen::makeKey( GenInlineList *outList, Key key )
+{
+}
+
+void XMLCodeGen::makeText( GenInlineList *outList, InlineItem *item )
+{
+}
+
+void XMLCodeGen::makeGoto( GenInlineList *outList, InlineItem *item )
+{
+}
+
+void XMLCodeGen::makeGotoExpr( GenInlineList *outList, InlineItem *item )
+{
+}
+
+void XMLCodeGen::makeCall( GenInlineList *outList, InlineItem *item )
+{
+}
+
+void XMLCodeGen::makeCallExpr( GenInlineList *outList, InlineItem *item )
+{
+}
+
+void XMLCodeGen::makeNext( GenInlineList *outList, InlineItem *item )
+{
+}
+
+void XMLCodeGen::makeNextExpr( GenInlineList *outList, InlineItem *item )
+{
+}
+
+void XMLCodeGen::makeEntry( GenInlineList *outList, InlineItem *item )
+{
+}
+
+void XMLCodeGen::makeLmSetActId( GenInlineList *outList, InlineItem *item )
+{
+}
+
+void XMLCodeGen::makeLmOnLast( GenInlineList *outList, InlineItem *item )
+{
+}
+
+void XMLCodeGen::makeLmOnNext( GenInlineList *outList, InlineItem *item )
+{
+}
+
+void XMLCodeGen::makeLmOnLagBehind( GenInlineList *outList, InlineItem *item )
+{
+}
+
+void XMLCodeGen::makeActionExec( GenInlineList *outList, InlineItem *item )
+{
+}
+
+void XMLCodeGen::makeLmSwitch( GenInlineList *outList, InlineItem *item )
+{
+}
+
+void XMLCodeGen::makeGenInlineList( GenInlineList *outList, InlineList *inList )
+{
+       for ( InlineList::Iter item = *inList; item.lte(); item++ ) {
+               switch ( item->type ) {
+               case InlineItem::Text:
+                       makeText( outList, item );
+                       break;
+               case InlineItem::Goto:
+                       makeGoto( outList, item );
+                       break;
+               case InlineItem::GotoExpr:
+                       makeGotoExpr( outList, item );
+                       break;
+               case InlineItem::Call:
+                       makeCall( outList, item );
+                       break;
+               case InlineItem::CallExpr:
+                       makeCallExpr( outList, item );
+                       break;
+               case InlineItem::Next:
+                       makeNext( outList, item );
+                       break;
+               case InlineItem::NextExpr:
+                       makeNextExpr( outList, item );
+                       break;
+               case InlineItem::Break:
+                       out << "<break></break>";
+                       break;
+               case InlineItem::Ret: 
+                       out << "<ret></ret>";
+                       break;
+               case InlineItem::PChar:
+                       out << "<pchar></pchar>";
+                       break;
+               case InlineItem::Char: 
+                       out << "<char></char>";
+                       break;
+               case InlineItem::Curs: 
+                       out << "<curs></curs>";
+                       break;
+               case InlineItem::Targs: 
+                       out << "<targs></targs>";
+                       break;
+               case InlineItem::Entry:
+                       makeEntry( outList, item );
+                       break;
+
+               case InlineItem::Hold:
+                       out << "<hold></hold>";
+                       break;
+               case InlineItem::Exec:
+                       makeActionExec( outList, item );
+                       break;
+
+               case InlineItem::LmSetActId:
+                       out << "<set_act>" << 
+                                       item->longestMatchPart->longestMatchId << 
+                                       "</set_act>";
+                       break;
+               case InlineItem::LmSetTokEnd:
+                       out << "<set_tokend>1</set_tokend>";
+                       break;
+
+               case InlineItem::LmOnLast:
+                       makeLmOnLast( outList, item );
+                       break;
+               case InlineItem::LmOnNext:
+                       makeLmOnNext( outList, item );
+                       break;
+               case InlineItem::LmOnLagBehind:
+                       makeLmOnLagBehind( outList, item );
+                       break;
+               case InlineItem::LmSwitch: 
+                       makeLmSwitch( outList, item );
+                       break;
+
+               case InlineItem::LmInitAct:
+                       out << "<init_act></init_act>";
+                       break;
+               case InlineItem::LmInitTokStart:
+                       out << "<init_tokstart></init_tokstart>";
+                       break;
+               case InlineItem::LmSetTokStart:
+                       out << "<set_tokstart></set_tokstart>";
+                       break;
+               }
+       }
+}
+
+
 void XMLCodeGen::writeAction( Action *action )
 {
        out << "      <action id=\"" << action->actionId << "\"";
@@ -644,10 +795,9 @@ void XMLCodeGen::writeXML()
 {
        /* Open the definition. */
        xmlParser.open_ragel_def( fsmName );
-       out << "<ragel_def>\n";
 
        /* Alphabet type. */
-       out << "  <alphtype>" << keyOps->alphType->internalName << "</alphtype>\n";
+       xmlParser.cgd->setAlphType( keyOps->alphType->internalName );
        
        /* Getkey expression. */
        if ( pd->getKeyExpr != 0 ) {
@@ -749,3 +899,112 @@ void XMLCodeGen::writeXML()
                "</ragel_def>\n";
 }
 
+void XMLCodeGen::makeBackend()
+{
+       /* Open the definition. */
+       xmlParser.open_ragel_def( fsmName );
+
+       /* Alphabet type. */
+       xmlParser.cgd->setAlphType( keyOps->alphType->internalName );
+       
+       /* Getkey expression. */
+       if ( pd->getKeyExpr != 0 ) {
+               out << "  <getkey>";
+               writeInlineList( pd->getKeyExpr );
+               out << "</getkey>\n";
+       }
+
+       /* Access expression. */
+       if ( pd->accessExpr != 0 ) {
+               out << "  <access>";
+               writeInlineList( pd->accessExpr );
+               out << "</access>\n";
+       }
+
+       /* PrePush expression. */
+       if ( pd->prePushExpr != 0 ) {
+               out << "  <prepush>";
+               writeInlineList( pd->prePushExpr );
+               out << "</prepush>\n";
+       }
+
+       /* PostPop expression. */
+       if ( pd->postPopExpr != 0 ) {
+               out << "  <postpop>";
+               writeInlineList( pd->postPopExpr );
+               out << "</postpop>\n";
+       }
+
+       /*
+        * Variable expressions.
+        */
+
+       if ( pd->pExpr != 0 ) {
+               out << "  <p_expr>";
+               writeInlineList( pd->pExpr );
+               out << "</p_expr>\n";
+       }
+       
+       if ( pd->peExpr != 0 ) {
+               out << "  <pe_expr>";
+               writeInlineList( pd->peExpr );
+               out << "</pe_expr>\n";
+       }
+
+       if ( pd->eofExpr != 0 ) {
+               out << "  <eof_expr>";
+               writeInlineList( pd->eofExpr );
+               out << "</eof_expr>\n";
+       }
+       
+       if ( pd->csExpr != 0 ) {
+               out << "  <cs_expr>";
+               writeInlineList( pd->csExpr );
+               out << "</cs_expr>\n";
+       }
+       
+       if ( pd->topExpr != 0 ) {
+               out << "  <top_expr>";
+               writeInlineList( pd->topExpr );
+               out << "</top_expr>\n";
+       }
+       
+       if ( pd->stackExpr != 0 ) {
+               out << "  <stack_expr>";
+               writeInlineList( pd->stackExpr );
+               out << "</stack_expr>\n";
+       }
+       
+       if ( pd->actExpr != 0 ) {
+               out << "  <act_expr>";
+               writeInlineList( pd->actExpr );
+               out << "</act_expr>\n";
+       }
+       
+       if ( pd->tokstartExpr != 0 ) {
+               out << "  <tokstart_expr>";
+               writeInlineList( pd->tokstartExpr );
+               out << "</tokstart_expr>\n";
+       }
+       
+       if ( pd->tokendExpr != 0 ) {
+               out << "  <tokend_expr>";
+               writeInlineList( pd->tokendExpr );
+               out << "</tokend_expr>\n";
+       }
+       
+       if ( pd->dataExpr != 0 ) {
+               out << "  <data_expr>";
+               writeInlineList( pd->dataExpr );
+               out << "</data_expr>\n";
+       }
+       
+       writeExports();
+       
+       writeMachine();
+
+       out <<
+               "</ragel_def>\n";
+}
+
+
index 0809e80..74a2bbd 100644 (file)
@@ -31,6 +31,7 @@
 struct TransAp;
 struct FsmAp;
 struct ParseData;
+struct GenInlineList;
 
 struct RedActionTable
 :
@@ -82,6 +83,7 @@ public:
        XMLCodeGen( char *fsmName, ParseData *pd, FsmAp *fsm, 
                        std::ostream &out, XmlParser &xmlParser );
        void writeXML( );
+       void makeBackend( );
 
 private:
        void appendTrans( TransListVect &outList, Key lowKey, Key highKey, TransAp *trans );
@@ -120,6 +122,23 @@ private:
        void writeMachine();
        void writeActionExec( InlineItem *item );
 
+       void makeGenInlineList( GenInlineList *outList, InlineList *inList );
+       void makeKey( GenInlineList *outList, Key key );
+       void makeText( GenInlineList *outList, InlineItem *item );
+       void makeGoto( GenInlineList *outList, InlineItem *item );
+       void makeGotoExpr( GenInlineList *outList, InlineItem *item );
+       void makeCall( GenInlineList *outList, InlineItem *item );
+       void makeCallExpr( GenInlineList *outList, InlineItem *item );
+       void makeNext( GenInlineList *outList, InlineItem *item );
+       void makeNextExpr( GenInlineList *outList, InlineItem *item );
+       void makeEntry( GenInlineList *outList, InlineItem *item );
+       void makeLmSetActId( 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 );
+
        char *fsmName;
        ParseData *pd;
        FsmAp *fsm;
index bff07a3..f1f8bec 100644 (file)
@@ -288,7 +288,7 @@ void CodeGenData::closeMachine()
 }
 
 
-bool CodeGenData::setAlphType( char *data )
+bool CodeGenData::setAlphType( const char *data )
 {
        HostType *alphType = findAlphTypeInternal( data );
        if ( alphType == 0 )
index 13a12ac..81dde1c 100644 (file)
@@ -178,7 +178,7 @@ struct CodeGenData
        GenCondSpace *findCondSpace( Key lowKey, Key highKey );
        Condition *findCondition( Key key );
 
-       bool setAlphType( char *data );
+       bool setAlphType( const char *data );
 
        void resolveTargetStates( GenInlineList *inlineList );
        Key findMaxKey();
index 8f0b7af..bf81fc0 100644 (file)
@@ -216,8 +216,6 @@ tag_export: TAG_ex '/' TAG_ex
 
 tag_alph_type: TAG_alphtype '/' TAG_alphtype
        final {
-               if ( ! cgd->setAlphType( $3->tag->content ) )
-                       error($1->loc) << "tag <alphtype> specifies unknown alphabet type" << endp;
        };
 
 tag_getkey_expr: TAG_getkey inline_list '/' TAG_getkey