Line directives need to use the fileName stored in the InputLoc stuctures from
[external/ragel.git] / ragel / xmlcodegen.cpp
index 30b757e..9a9c388 100644 (file)
 
 #include "ragel.h"
 #include "xmlcodegen.h"
-#include "xmlparse.h"
 #include "parsedata.h"
 #include "fsmgraph.h"
 #include "gendata.h"
 #include "inputdata.h"
 #include <string.h>
+#include "rlparse.h"
+#include "version.h"
 
 using namespace std;
 
@@ -463,13 +464,14 @@ void BackendGen::makeText( GenInlineList *outList, InlineItem *item )
        outList->append( inlineItem );
 }
 
-void BackendGen::makeTargetItem( GenInlineList *outList, long entryId, GenInlineItem::Type type )
+void BackendGen::makeTargetItem( GenInlineList *outList, NameInst *nameTarg, 
+               GenInlineItem::Type type )
 {
        long targetState;
        if ( pd->generatingSectionSubset )
                targetState = -1;
        else {
-               EntryMapEl *targ = fsm->entryPoints.find( entryId );
+               EntryMapEl *targ = fsm->entryPoints.find( nameTarg->id );
                targetState = targ->value->alg.stateNum;
        }
 
@@ -626,19 +628,19 @@ void BackendGen::makeGenInlineList( GenInlineList *outList, InlineList *inList )
                        makeText( outList, item );
                        break;
                case InlineItem::Goto:
-                       makeTargetItem( outList, item->nameTarg->id, GenInlineItem::Goto );
+                       makeTargetItem( outList, item->nameTarg, GenInlineItem::Goto );
                        break;
                case InlineItem::GotoExpr:
                        makeSubList( outList, item->children, GenInlineItem::GotoExpr );
                        break;
                case InlineItem::Call:
-                       makeTargetItem( outList, item->nameTarg->id, GenInlineItem::Call );
+                       makeTargetItem( outList, item->nameTarg, GenInlineItem::Call );
                        break;
                case InlineItem::CallExpr:
                        makeSubList( outList, item->children, GenInlineItem::CallExpr );
                        break;
                case InlineItem::Next:
-                       makeTargetItem( outList, item->nameTarg->id, GenInlineItem::Next );
+                       makeTargetItem( outList, item->nameTarg, GenInlineItem::Next );
                        break;
                case InlineItem::NextExpr:
                        makeSubList( outList, item->children, GenInlineItem::NextExpr );
@@ -662,7 +664,7 @@ void BackendGen::makeGenInlineList( GenInlineList *outList, InlineList *inList )
                        outList->append( new GenInlineItem( InputLoc(), GenInlineItem::Targs ) );
                        break;
                case InlineItem::Entry:
-                       makeTargetItem( outList, item->nameTarg->id, GenInlineItem::Entry );
+                       makeTargetItem( outList, item->nameTarg, GenInlineItem::Entry );
                        break;
 
                case InlineItem::Hold:
@@ -1025,8 +1027,7 @@ void BackendGen::makeAction( Action *action )
        GenInlineList *genList = new GenInlineList;
        makeGenInlineList( genList, action->inlineList );
 
-       cgd->newAction( curAction++, action->name, 
-                       action->loc.line, action->loc.col, genList );
+       cgd->newAction( curAction++, action->name, action->loc, genList );
 }
 
 
@@ -1396,4 +1397,30 @@ void BackendGen::makeBackend()
        close_ragel_def();
 }
 
+void InputData::writeLanguage( std::ostream &out )
+{
+       out << " lang=\"";
+       switch ( hostLang->lang ) {
+               case HostLang::C:    out << "C"; break;
+               case HostLang::D:    out << "D"; break;
+               case HostLang::Java: out << "Java"; break;
+               case HostLang::Ruby: out << "Ruby"; break;
+               case HostLang::CSharp: out << "C#"; break;
+       }
+       out << "\"";
+}
+
+void InputData::writeXML( std::ostream &out )
+{
+       out << "<ragel version=\"" VERSION "\" filename=\"" << inputFileName << "\"";
+       writeLanguage( out );
+       out << ">\n";
 
+       for ( ParserDict::Iter parser = parserDict; parser.lte(); parser++ ) {
+               ParseData *pd = parser->value->pd;
+               if ( pd->instanceList.length() > 0 )
+                       pd->generateXML( *outStream );
+       }
+
+       out << "</ragel>\n";
+}