From: thurston Date: Fri, 2 Feb 2007 17:12:27 +0000 (+0000) Subject: Removed Java code generation from rlcodegen. Added the cd javagen && make to X-Git-Tag: 2.0_alpha~429 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2407432ffcf699bf915875db0bec31b1b2754f4c;p=external%2Fragel.git Removed Java code generation from rlcodegen. Added the cd javagen && make to the top level makefile (not covered by SUBDIRS variable). git-svn-id: http://svn.complang.org/ragel/trunk@57 052ea7fc-9027-0410-9066-f65837a77df0 --- diff --git a/Makefile.in b/Makefile.in index f390ce7..b51f6e0 100644 --- a/Makefile.in +++ b/Makefile.in @@ -30,7 +30,8 @@ include version.mk # Rules. all: - @cd common && $(MAKE) && cd ../ragel && $(MAKE) && cd ../rlcodegen && $(MAKE) + @cd common && $(MAKE) && cd ../ragel && $(MAKE) && \ + cd ../rlcodegen && $(MAKE) && cd ../javagen && $(MAKE) new-version: sed 's/^\(Version:[[:space:]]*\)[0-9.]*$$/\1$(VERSION)/' ragel.spec > spec-new diff --git a/rlcodegen/Makefile.in b/rlcodegen/Makefile.in index 6060456..c263da9 100644 --- a/rlcodegen/Makefile.in +++ b/rlcodegen/Makefile.in @@ -27,7 +27,7 @@ LDFLAGS += CC_SRCS = main.cpp gvdotgen.cpp fsmcodegen.cpp \ tabcodegen.cpp ftabcodegen.cpp flatcodegen.cpp \ fflatcodegen.cpp gotocodegen.cpp fgotocodegen.cpp \ - ipgotocodegen.cpp splitcodegen.cpp javacodegen.cpp + ipgotocodegen.cpp splitcodegen.cpp GEN_SRC = xmltags.cpp xmlscan.cpp xmlparse.cpp xmlparse.h diff --git a/rlcodegen/fsmcodegen.cpp b/rlcodegen/fsmcodegen.cpp index 6e0405e..2ca7e87 100644 --- a/rlcodegen/fsmcodegen.cpp +++ b/rlcodegen/fsmcodegen.cpp @@ -608,91 +608,6 @@ string DCodeGen::CTRL_FLOW() return "if (true) "; } - -/* - * Java Specific - */ - -string JavaCodeGen::PTR_CONST() -{ - /* Not used in Java code. */ - assert( false ); - return "final"; -} - -std::ostream &JavaCodeGen::OPEN_ARRAY( string type, string name ) -{ - out << "static final " << type << "[] " << name << " = {\n"; - return out; -} - -std::ostream &JavaCodeGen::CLOSE_ARRAY() -{ - return out << "};\n"; -} - -std::ostream &JavaCodeGen::STATIC_VAR( string type, string name ) -{ - out << "static final " << type << " " << name; - return out; -} - -string JavaCodeGen::UINT( ) -{ - /* Not used. */ - assert( false ); - return "long"; -} - -string JavaCodeGen::ARR_OFF( string ptr, string offset ) -{ - return ptr + " + " + offset; -} - -string JavaCodeGen::CAST( string type ) -{ - return "(" + type + ")"; -} - -string JavaCodeGen::NULL_ITEM() -{ - /* In java we use integers instead of pointers. */ - return "-1"; -} - -string JavaCodeGen::POINTER() -{ - /* Not used. */ - assert( false ); - return " *"; -} - -std::ostream &JavaCodeGen::SWITCH_DEFAULT() -{ - return out; -} - -string JavaCodeGen::GET_KEY() -{ - ostringstream ret; - if ( getKeyExpr != 0 ) { - /* Emit the user supplied method of retrieving the key. */ - ret << "("; - INLINE_LIST( ret, getKeyExpr, 0, false ); - ret << ")"; - } - else { - /* Expression for retrieving the key, use simple dereference. */ - ret << "data[" << P() << "]"; - } - return ret.str(); -} - -string JavaCodeGen::CTRL_FLOW() -{ - return "if (true) "; -} - /* Generate the code for an fsm. Assumes parseData is set up properly. Called * by parser code. */ void FsmCodeGen::prepareMachine() diff --git a/rlcodegen/fsmcodegen.h b/rlcodegen/fsmcodegen.h index 1071190..fec052b 100644 --- a/rlcodegen/fsmcodegen.h +++ b/rlcodegen/fsmcodegen.h @@ -225,23 +225,4 @@ public: virtual string CTRL_FLOW(); }; -class JavaCodeGen : virtual public FsmCodeGen -{ -public: - JavaCodeGen( ostream &out ) : FsmCodeGen(out) {} - - virtual string NULL_ITEM(); - virtual string POINTER(); - virtual ostream &SWITCH_DEFAULT(); - virtual ostream &OPEN_ARRAY( string type, string name ); - virtual ostream &CLOSE_ARRAY(); - virtual ostream &STATIC_VAR( string type, string name ); - virtual string ARR_OFF( string ptr, string offset ); - virtual string CAST( string type ); - virtual string UINT(); - virtual string PTR_CONST(); - virtual string GET_KEY(); - virtual string CTRL_FLOW(); -}; - #endif /* _FSMCODEGEN_H */ diff --git a/rlcodegen/javacodegen.cpp b/rlcodegen/javacodegen.cpp deleted file mode 100644 index f305d12..0000000 --- a/rlcodegen/javacodegen.cpp +++ /dev/null @@ -1,309 +0,0 @@ -/* - * Copyright 2006 Adrian Thurston - */ - -/* This file is part of Ragel. - * - * Ragel is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Ragel is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Ragel; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "javacodegen.h" -#include "rlcodegen.h" -#include "tabcodegen.h" -#include "redfsm.h" -#include "gendata.h" - -void JavaTabCodeGen::GOTO( ostream &ret, int gotoDest, bool inFinish ) -{ - ret << "{" << CS() << " = " << gotoDest << "; " << - CTRL_FLOW() << "break _again;}"; -} - -void JavaTabCodeGen::GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ) -{ - ret << "{" << CS() << " = ("; - INLINE_LIST( ret, ilItem->children, 0, inFinish ); - ret << "); " << CTRL_FLOW() << "break _again;}"; -} - -void JavaTabCodeGen::CALL( ostream &ret, int callDest, int targState, bool inFinish ) -{ - ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = " << - callDest << "; " << CTRL_FLOW() << "break _again;}"; -} - -void JavaTabCodeGen::CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ) -{ - ret << "{" << STACK() << "[" << TOP() << "++] = " << CS() << "; " << CS() << " = ("; - INLINE_LIST( ret, ilItem->children, targState, inFinish ); - ret << "); " << CTRL_FLOW() << "break _again;}"; -} - -void JavaTabCodeGen::RET( ostream &ret, bool inFinish ) -{ - ret << "{" << CS() << " = " << STACK() << "[--" << TOP() - << "]; " << CTRL_FLOW() << "break _again;}"; -} - -void JavaTabCodeGen::BREAK( ostream &ret, int targState ) -{ - ret << CTRL_FLOW() << "break _resume;"; -} - -void JavaTabCodeGen::COND_TRANSLATE() -{ - out << - " _widec = " << GET_KEY() << ";\n" - " _keys = " << CO() << "[" << CS() << "]*2\n;" - " _klen = " << CL() << "[" << CS() << "];\n" - " if ( _klen > 0 ) {\n" - " int _lower = _keys\n;" - " int _mid;\n" - " int _upper = _keys + (_klen<<1) - 2;\n" - " while (true) {\n" - " if ( _upper < _lower )\n" - " break;\n" - "\n" - " _mid = _lower + (((_upper-_lower) >> 1) & ~1);\n" - " if ( " << GET_WIDE_KEY() << " < " << CK() << "[_mid] )\n" - " _upper = _mid - 2;\n" - " else if ( " << GET_WIDE_KEY() << " > " << CK() << "[_mid] )\n" - " _lower = _mid + 2;\n" - " else {\n" - " switch ( " << C() << "[" << CO() << "[" << CS() << "]" - " + ((_mid - _keys)>>1)] ) {\n" - ; - - for ( CondSpaceList::Iter csi = condSpaceList; csi.lte(); csi++ ) { - CondSpace *condSpace = csi; - out << " case " << condSpace->condSpaceId << ": {\n"; - out << TABS(2) << "_widec = " << KEY(condSpace->baseKey) << - " + (" << GET_KEY() << " - " << KEY(keyOps->minKey) << ");\n"; - - for ( CondSet::Iter csi = condSpace->condSet; csi.lte(); csi++ ) { - out << TABS(2) << "if ( "; - CONDITION( out, *csi ); - Size condValOffset = ((1 << csi.pos()) * keyOps->alphSize()); - out << " ) _widec += " << condValOffset << ";\n"; - } - - out << - " break;\n" - " }\n"; - } - - out << - " }\n" - " break;\n" - " }\n" - " }\n" - " }\n" - "\n"; -} - - -void JavaTabCodeGen::LOCATE_TRANS() -{ - out << - " _match: do {\n" - " _keys = " << KO() << "[" << CS() << "]" << ";\n" - " _trans = " << IO() << "[" << CS() << "];\n" - " _klen = " << SL() << "[" << CS() << "];\n" - " if ( _klen > 0 ) {\n" - " int _lower = _keys;\n" - " int _mid;\n" - " int _upper = _keys + _klen - 1;\n" - " while (true) {\n" - " if ( _upper < _lower )\n" - " break;\n" - "\n" - " _mid = _lower + ((_upper-_lower) >> 1);\n" - " if ( " << GET_WIDE_KEY() << " < " << K() << "[_mid] )\n" - " _upper = _mid - 1;\n" - " else if ( " << GET_WIDE_KEY() << " > " << K() << "[_mid] )\n" - " _lower = _mid + 1;\n" - " else {\n" - " _trans += (_mid - _keys);\n" - " break _match;\n" - " }\n" - " }\n" - " _keys += _klen;\n" - " _trans += _klen;\n" - " }\n" - "\n" - " _klen = " << RL() << "[" << CS() << "];\n" - " if ( _klen > 0 ) {\n" - " int _lower = _keys;\n" - " int _mid;\n" - " int _upper = _keys + (_klen<<1) - 2;\n" - " while (true) {\n" - " if ( _upper < _lower )\n" - " break;\n" - "\n" - " _mid = _lower + (((_upper-_lower) >> 1) & ~1);\n" - " if ( " << GET_WIDE_KEY() << " < " << K() << "[_mid] )\n" - " _upper = _mid - 2;\n" - " else if ( " << GET_WIDE_KEY() << " > " << K() << "[_mid+1] )\n" - " _lower = _mid + 2;\n" - " else {\n" - " _trans += ((_mid - _keys)>>1);\n" - " break _match;\n" - " }\n" - " }\n" - " _trans += _klen;\n" - " }\n" - " } while (false);\n" - "\n"; -} - -void JavaTabCodeGen::writeOutExec() -{ - out << - " {\n" - " int _klen"; - - if ( redFsm->anyRegCurStateRef() ) - out << ", _ps"; - - out << - ";\n" - " int _trans;\n"; - - if ( redFsm->anyConditions() ) - out << " int _widec;\n"; - - if ( redFsm->anyToStateActions() || redFsm->anyRegActions() || - redFsm->anyFromStateActions() ) - { - out << - " int _acts;\n" - " int _nacts;\n"; - } - - out << - " int _keys;\n" - "\n"; - - if ( hasEnd ) - out << " if ( " << P() << " != " << PE() << " ) {\n"; - - out << " _resume: while ( true ) {\n"; - - out << " _again: do {\n"; - - if ( redFsm->errState != 0 ) { - out << - " if ( " << CS() << " == " << redFsm->errState->id << " )\n" - " break _resume;\n"; - } - - if ( redFsm->anyFromStateActions() ) { - out << - " _acts = " << FSA() << "[" << CS() << "]" << ";\n" - " _nacts = " << CAST("int") << " " << A() << "[_acts++];\n" - " while ( _nacts-- > 0 ) {\n" - " switch ( " << A() << "[_acts++] ) {\n"; - FROM_STATE_ACTION_SWITCH(); - SWITCH_DEFAULT() << - " }\n" - " }\n" - "\n"; - } - - if ( redFsm->anyConditions() ) - COND_TRANSLATE(); - - LOCATE_TRANS(); - - if ( redFsm->anyRegCurStateRef() ) - out << " _ps = " << CS() << ";\n"; - - if ( useIndicies ) - out << " _trans = " << I() << "[_trans];\n"; - - out << - " " << CS() << " = " << TT() << "[_trans];\n" - "\n"; - - if ( redFsm->anyRegActions() ) { - out << - " if ( " << TA() << "[_trans] == 0 )\n" - " break _again;\n" - "\n" - " _acts = " << TA() << "[_trans]" << ";\n" - " _nacts = " << CAST("int") << " " << A() << "[_acts++];\n" - " while ( _nacts-- > 0 )\n {\n" - " switch ( " << A() << "[_acts++] )\n" - " {\n"; - ACTION_SWITCH(); - SWITCH_DEFAULT() << - " }\n" - " }\n" - "\n"; - } - - /* Again loop, functions as again label. */ - out << " } while (false);\n"; - - if ( redFsm->anyToStateActions() ) { - out << - " _acts = " << TSA() << "[" << CS() << "]" << ";\n" - " _nacts = " << CAST("int") << " " << A() << "[_acts++];\n" - " while ( _nacts-- > 0 ) {\n" - " switch ( " << A() << "[_acts++] ) {\n"; - TO_STATE_ACTION_SWITCH(); - SWITCH_DEFAULT() << - " }\n" - " }\n" - "\n"; - } - - if ( hasEnd ) { - out << - " if ( ++" << P() << " == " << PE() << " )\n" - " break _resume;\n"; - } - else { - out << - " " << P() << " += 1;\n"; - } - - /* Close the resume loop. */ - out << " }\n"; - - /* The if guarding on empty string. */ - if ( hasEnd ) - out << " }\n"; - - /* The execute block. */ - out << " }\n"; -} - -void JavaTabCodeGen::writeOutEOF() -{ - if ( redFsm->anyEofActions() ) { - out << - " int _acts = " << EA() << "[" << CS() << "]" << ";\n" - " int _nacts = " << CAST("int") << " " << A() << "[_acts++];\n" - " while ( _nacts-- > 0 ) {\n" - " switch ( " << A() << "[_acts++] ) {\n"; - EOF_ACTION_SWITCH(); - SWITCH_DEFAULT() << - " }\n" - " }\n" - "\n"; - } -} - diff --git a/rlcodegen/javacodegen.h b/rlcodegen/javacodegen.h deleted file mode 100644 index 3481a6c..0000000 --- a/rlcodegen/javacodegen.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2006 Adrian Thurston - */ - -/* This file is part of Ragel. - * - * Ragel is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Ragel is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Ragel; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef _JAVACODEGEN_H -#define _JAVACODEGEN_H - -#include "tabcodegen.h" - -/* - * JavaTabCodeGen - */ -struct JavaTabCodeGen - : public TabCodeGen, public JavaCodeGen -{ - JavaTabCodeGen( ostream &out ) : - FsmCodeGen(out), TabCodeGen(out), JavaCodeGen(out) {} - - void BREAK( ostream &ret, int targState ); - void GOTO( ostream &ret, int gotoDest, bool inFinish ); - void GOTO_EXPR( ostream &ret, InlineItem *ilItem, bool inFinish ); - void CALL( ostream &ret, int callDest, int targState, bool inFinish ); - void CALL_EXPR( ostream &ret, InlineItem *ilItem, int targState, bool inFinish ); - void RET( ostream &ret, bool inFinish ); - - void COND_TRANSLATE(); - void LOCATE_TRANS(); - virtual void writeOutExec(); - virtual void writeOutEOF(); -}; - - -#endif diff --git a/rlcodegen/main.cpp b/rlcodegen/main.cpp index 9521948..7977728 100644 --- a/rlcodegen/main.cpp +++ b/rlcodegen/main.cpp @@ -42,7 +42,6 @@ #include "fgotocodegen.h" #include "ipgotocodegen.h" #include "splitcodegen.h" -#include "javacodegen.h" #include "gvdotgen.h" @@ -210,15 +209,9 @@ ostream *openOutput( char *inputFile, char *language ) hostLangType = DCode; hostLang = &hostLangD; } - else if ( strcmp( language, "Java" ) == 0 ) { - hostLangType = JavaCode; - hostLang = &hostLangJava; - } - - /* Eventually more types will be supported. */ - if ( hostLangType == JavaCode && codeStyle != GenTables ) { - error() << "java: only the table code style -T0 is " - "currently supported" << endl; + else { + error() << PROGNAME " generates code for C and D only, you " + "need a diferent code generator for " << language << endl; } /* If the output format is code and no output file name is given, then @@ -232,7 +225,7 @@ ostream *openOutput( char *inputFile, char *language ) switch ( hostLangType ) { case CCode: defExtension = ".c"; break; case DCode: defExtension = ".d"; break; - case JavaCode: defExtension = ".java"; break; + default: break; } outputFileName = fileNameFromStem( inputFile, defExtension ); } @@ -331,16 +324,7 @@ CodeGenData *makeCodeGen( char *sourceFileName, char *fsmName, } break; - case JavaCode: - switch ( codeStyle ) { - case GenTables: - codeGen = new JavaTabCodeGen(out); - break; - default: - assert(false); - break; - } - break; + default: break; } }