codegen.h (ragel-7.0.0.11) | : | codegen.h (ragel-7.0.0.12) | ||
---|---|---|---|---|
skipping to change at line 60 | skipping to change at line 60 | |||
struct RedAction; | struct RedAction; | |||
struct LongestMatch; | struct LongestMatch; | |||
struct LongestMatchPart; | struct LongestMatchPart; | |||
string itoa( int i ); | string itoa( int i ); | |||
struct Variable | struct Variable | |||
{ | { | |||
Variable( const char *name ) : name(name), isReferenced(false) {} | Variable( const char *name ) : name(name), isReferenced(false) {} | |||
operator const char *() { isReferenced = true; return name; } | operator const std::string() { isReferenced = true; return name; } | |||
void reference() { isReferenced = true; } | void reference() { isReferenced = true; } | |||
const char *name; | const char *name; | |||
bool isReferenced; | bool isReferenced; | |||
}; | }; | |||
struct GotoLabel | ||||
{ | ||||
GotoLabel( const char *name ) : name(name), isReferenced(false) {} | ||||
operator std::string() { isReferenced = true; return name; } | ||||
void reference() { isReferenced = true; } | ||||
const char *name; | ||||
bool isReferenced; | ||||
}; | ||||
std::ostream &operator<<( std::ostream &out, GotoLabel &l ); | ||||
std::ostream &operator<<( std::ostream &out, Variable &v ); | ||||
struct TableArray; | struct TableArray; | |||
typedef Vector<TableArray*> ArrayVector; | typedef Vector<TableArray*> ArrayVector; | |||
struct CodeGen; | struct CodeGen; | |||
struct TableArray | struct TableArray | |||
{ | { | |||
enum State { | enum State { | |||
InitialState = 1, | InitialState = 1, | |||
AnalyzePass, | AnalyzePass, | |||
GeneratePass | GeneratePass | |||
skipping to change at line 92 | skipping to change at line 106 | |||
void startAnalyze(); | void startAnalyze(); | |||
void startGenerate(); | void startGenerate(); | |||
void setType( std::string type, int width, bool isChar ) | void setType( std::string type, int width, bool isChar ) | |||
{ | { | |||
this->type = type; | this->type = type; | |||
this->width = width; | this->width = width; | |||
this->isChar = isChar; | this->isChar = isChar; | |||
} | } | |||
std::string ref() const; | std::string ref(); | |||
void value( long long v ); | void value( long long v ); | |||
void valueAnalyze( long long v ); | void valueAnalyze( long long v ); | |||
void valueGenerate( long long v ); | void valueGenerate( long long v ); | |||
void stringGenerate( long long value ); | void stringGenerate( long long value ); | |||
void finish(); | void finish(); | |||
void finishAnalyze(); | void finishAnalyze(); | |||
void finishGenerate(); | void finishGenerate(); | |||
skipping to change at line 123 | skipping to change at line 137 | |||
bool isSigned; | bool isSigned; | |||
bool isChar; | bool isChar; | |||
bool stringTables; | bool stringTables; | |||
int iall; | int iall; | |||
long long values; | long long values; | |||
long long min; | long long min; | |||
long long max; | long long max; | |||
CodeGen &codeGen; | CodeGen &codeGen; | |||
std::ostream &out; | std::ostream &out; | |||
int ln; | int ln; | |||
bool isReferenced; | ||||
bool started; | ||||
}; | }; | |||
struct IlOpts | struct IlOpts | |||
{ | { | |||
IlOpts( int targState, bool inFinish, bool csForced ) | IlOpts( int targState, bool inFinish, bool csForced ) | |||
: targState(targState), inFinish(inFinish), csForced(csForced) {} | : targState(targState), inFinish(inFinish), csForced(csForced) {} | |||
int targState; | int targState; | |||
bool inFinish; | bool inFinish; | |||
bool csForced; | bool csForced; | |||
skipping to change at line 157 | skipping to change at line 173 | |||
virtual void writeFirstFinal(); | virtual void writeFirstFinal(); | |||
virtual void writeError(); | virtual void writeError(); | |||
virtual void statsSummary(); | virtual void statsSummary(); | |||
protected: | protected: | |||
friend class TableArray; | friend class TableArray; | |||
typedef Vector<TableArray*> ArrayVector; | typedef Vector<TableArray*> ArrayVector; | |||
ArrayVector arrayVector; | ArrayVector arrayVector; | |||
Variable cpc; | Variable cpc; | |||
Variable pop_test; | ||||
Variable new_recs; | ||||
Variable alt; | ||||
string FSM_NAME(); | string FSM_NAME(); | |||
string START_STATE_ID(); | string START_STATE_ID(); | |||
void taActions(); | void taActions(); | |||
string TABS( int level ); | ||||
string KEY( Key key ); | string KEY( Key key ); | |||
string LDIR_PATH( char *path ); | string LDIR_PATH( char *path ); | |||
void ACTION( ostream &ret, GenAction *action, IlOpts opts ); | void ACTION( ostream &ret, GenAction *action, IlOpts opts ); | |||
void NFA_CONDITION( ostream &ret, GenAction *condition, bool last ); | void NFA_CONDITION( ostream &ret, GenAction *condition, bool last ); | |||
void NFA_POP_TEST_EXEC(); | ||||
void CONDITION( ostream &ret, GenAction *condition ); | void CONDITION( ostream &ret, GenAction *condition ); | |||
string ALPH_TYPE(); | string ALPH_TYPE(); | |||
bool isAlphTypeSigned(); | bool isAlphTypeSigned(); | |||
long long tableData; | long long tableData; | |||
RagelBackend backend; | RagelBackend backend; | |||
bool stringTables; | bool stringTables; | |||
BackendFeature backendFeature; | BackendFeature backendFeature; | |||
TableArray nfaTargs; | TableArray nfaTargs; | |||
skipping to change at line 208 | skipping to change at line 227 | |||
string FIRST_FINAL() { return DATA_PREFIX() + "first_final"; } | string FIRST_FINAL() { return DATA_PREFIX() + "first_final"; } | |||
/* Declare a variable only if referenced. */ | /* Declare a variable only if referenced. */ | |||
void DECLARE( std::string type, Variable &var, std::string init = "" ); | void DECLARE( std::string type, Variable &var, std::string init = "" ); | |||
string CAST( string type ); | string CAST( string type ); | |||
string ARR_TYPE( const TableArray &ta ) | string ARR_TYPE( const TableArray &ta ) | |||
{ return ta.type; } | { return ta.type; } | |||
string ARR_REF( const TableArray &ta ) | string ARR_REF( TableArray &ta ) | |||
{ return ta.ref(); } | { return ta.ref(); } | |||
void INLINE_EXPR( ostream &ret, GenInlineList *inlineList ); | void INLINE_EXPR( ostream &ret, GenInlineList *inlineList ); | |||
void INLINE_BLOCK( ostream &ret, GenInlineExpr *inlineExpr ); | void INLINE_BLOCK( ostream &ret, GenInlineExpr *inlineExpr ); | |||
void INLINE_PLAIN( ostream &ret, GenInlineExpr *inlineExpr ); | void INLINE_PLAIN( ostream &ret, GenInlineExpr *inlineExpr ); | |||
void EOF_CHECK( ostream &ret ); | ||||
void INLINE_LIST( ostream &ret, GenInlineList *inlineList, | void INLINE_LIST( ostream &ret, GenInlineList *inlineList, | |||
int targState, bool inFinish, bool csForced ); | int targState, bool inFinish, bool csForced ); | |||
virtual void GOTO( ostream &ret, int gotoDest, bool inFinish ) = 0; | virtual void GOTO( ostream &ret, int gotoDest, bool inFinish ) = 0; | |||
virtual void CALL( ostream &ret, int callDest, int targState, bool inFini sh ) = 0; | virtual void CALL( ostream &ret, int callDest, int targState, bool inFini sh ) = 0; | |||
virtual void NCALL( ostream &ret, int callDest, int targState, bool inFin ish ) = 0; | virtual void NCALL( ostream &ret, int callDest, int targState, bool inFin ish ) = 0; | |||
virtual void NEXT( ostream &ret, int nextDest, bool inFinish ) = 0; | virtual void NEXT( ostream &ret, int nextDest, bool inFinish ) = 0; | |||
virtual void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinis h ) = 0; | virtual void GOTO_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinis h ) = 0; | |||
virtual void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinis h ) = 0; | virtual void NEXT_EXPR( ostream &ret, GenInlineItem *ilItem, bool inFinis h ) = 0; | |||
virtual void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, | virtual void CALL_EXPR( ostream &ret, GenInlineItem *ilItem, | |||
int targState, bool inFinish ) = 0; | int targState, bool inFinish ) = 0; | |||
skipping to change at line 259 | skipping to change at line 276 | |||
void GEN_STMT( ostream &ret, GenInlineItem *item, int targState, bool inF inish, bool csForced ); | void GEN_STMT( ostream &ret, GenInlineItem *item, int targState, bool inF inish, bool csForced ); | |||
void GEN_EXPR( ostream &ret, GenInlineItem *item, int targState, bool inF inish, bool csForced ); | void GEN_EXPR( ostream &ret, GenInlineItem *item, int targState, bool inF inish, bool csForced ); | |||
void STATE_IDS(); | void STATE_IDS(); | |||
string ERROR_STATE(); | string ERROR_STATE(); | |||
string FIRST_FINAL_STATE(); | string FIRST_FINAL_STATE(); | |||
string STR( int v ); | string STR( int v ); | |||
bool outLabelUsed; | ||||
bool testEofUsed; | ||||
bool againLabelUsed; | ||||
bool matchCondLabelUsed; | ||||
void VALUE( string type, string name, string value ); | void VALUE( string type, string name, string value ); | |||
string ACCESS_OPER() | string ACCESS_OPER() | |||
{ return backend == Direct ? "" : " -> "; } | { return backend == Direct ? "" : " -> "; } | |||
string OPEN_HOST_EXPR() | string OPEN_HOST_EXPR() | |||
{ return backend == Direct ? "(" : "host( \"-\", 1 ) ={"; } | { return backend == Direct ? "(" : "host( \"-\", 1 ) ={"; } | |||
string OPEN_HOST_EXPR( string fileName, int line ) | string OPEN_HOST_EXPR( string fileName, int line ) | |||
{ | { | |||
return backend == Direct ? "(" : "host( \"" + fileName + "\", " + STR(line) + " ) ={"; | return backend == Direct ? "(" : "host( \"" + fileName + "\", " + STR(line) + " ) ={"; | |||
} | } | |||
string CLOSE_HOST_EXPR() | string CLOSE_HOST_EXPR() | |||
{ return backend == Direct ? ")" : "}="; } | { return backend == Direct ? ")" : "}="; } | |||
string OPEN_HOST_BLOCK( string fileName, int line ) | string OPEN_HOST_BLOCK( string fileName, int line ) | |||
{ | { | |||
if ( backend == Direct ) { | if ( backend == Direct ) { | |||
if ( lineDirectives ) | std::stringstream ss; | |||
return "{\n#line " + STR(line) + " \"" + fileName | ss << "{\n" ; | |||
+ "\"\n"; | (*genLineDirective)( ss, lineDirectives, line, fileName.c | |||
else | _str() ); | |||
return "{\n"; | return ss.str(); | |||
} | } | |||
else { | else { | |||
return "host( \"" + fileName + "\", " + STR(line) + " ) $ {"; | return "host( \"" + fileName + "\", " + STR(line) + " ) $ {"; | |||
} | } | |||
} | } | |||
string OPEN_HOST_BLOCK( GenInlineExpr *inlineExpr ) | string OPEN_HOST_BLOCK( GenInlineExpr *inlineExpr ) | |||
{ | { | |||
return OPEN_HOST_BLOCK( inlineExpr->loc.fileName, inlineExpr->loc .line ); | return OPEN_HOST_BLOCK( inlineExpr->loc.fileName, inlineExpr->loc .line ); | |||
} | } | |||
string CLOSE_HOST_BLOCK() | string CLOSE_HOST_BLOCK() | |||
{ return backend == Direct ? "}" : "}$"; } | { return backend == Direct ? "}\n" : "}$"; } | |||
string OPEN_HOST_PLAIN() | string OPEN_HOST_PLAIN() | |||
{ return backend == Direct ? "" : "host( \"-\", 1 ) @{"; } | { return backend == Direct ? "" : "host( \"-\", 1 ) @{"; } | |||
string CLOSE_HOST_PLAIN() | string CLOSE_HOST_PLAIN() | |||
{ return backend == Direct ? "" : "}@"; } | { return backend == Direct ? "" : "}@"; } | |||
string OPEN_GEN_EXPR() | string OPEN_GEN_EXPR() | |||
{ return backend == Direct ? "(" : "={"; } | { return backend == Direct ? "(" : "={"; } | |||
skipping to change at line 325 | skipping to change at line 337 | |||
string CLOSE_GEN_BLOCK() | string CLOSE_GEN_BLOCK() | |||
{ return backend == Direct ? "}" : "}$"; } | { return backend == Direct ? "}" : "}$"; } | |||
string OPEN_GEN_PLAIN() | string OPEN_GEN_PLAIN() | |||
{ return backend == Direct ? "" : "@{"; } | { return backend == Direct ? "" : "@{"; } | |||
string CLOSE_GEN_PLAIN() | string CLOSE_GEN_PLAIN() | |||
{ return backend == Direct ? "" : "}@"; } | { return backend == Direct ? "" : "}@"; } | |||
string INT() | ||||
{ return "int"; } | ||||
string UINT() | string UINT() | |||
{ return backend == Direct ? "unsigned int" : "uint"; } | { return backend == Direct ? "unsigned int" : "uint"; } | |||
string INDEX( string type, string name ) | string INDEX( string type, string name ) | |||
{ | { | |||
if ( backend == Direct ) | if ( backend == Direct ) | |||
return "const " + type + " *" + name; | return "const " + type + " *" + name; | |||
else | else | |||
return "index " + type + " " + name; | return "index " + type + " " + name; | |||
} | } | |||
string INDEX( string type ) | string INDEX( string type ) | |||
{ | { | |||
if ( backend == Direct ) | if ( backend == Direct ) | |||
return "const " + type + " *"; | return "const " + type + " *"; | |||
else | else | |||
return "index " + type + " "; | return "index " + type + " "; | |||
} | } | |||
string ENTRY() | string LABEL( string name ) | |||
{ | { | |||
if ( backend == Direct ) | return name + ": "; | |||
return ""; | ||||
else | ||||
return "entry"; | ||||
} | } | |||
string LABEL( string name ) | string EMIT_LABEL( GotoLabel label ) | |||
{ | { | |||
if ( backend == Direct ) | if ( label.isReferenced ) | |||
return name + ": "; | return std::string(label.name) + ": {}\n"; | |||
else | else | |||
return "label " + name; | return ""; | |||
} | } | |||
string OFFSET( string arr, string off ) | string OFFSET( string arr, string off ) | |||
{ | { | |||
if ( backend == Direct ) | if ( backend == Direct ) | |||
return "( " + arr + " + (" + off + "))"; | return "( " + arr + " + (" + off + "))"; | |||
else | else | |||
return "offset( " + arr + ", " + off + " )"; | return "offset( " + arr + ", " + off + " )"; | |||
} | } | |||
skipping to change at line 432 | skipping to change at line 444 | |||
} | } | |||
string EXPORT( string type, string name, string value ) | string EXPORT( string type, string name, string value ) | |||
{ | { | |||
if ( backend == Direct ) | if ( backend == Direct ) | |||
return "#define " + name + " " + value; | return "#define " + name + " " + value; | |||
else | else | |||
return "export " + type + " " + name + " " + value + ";"; | return "export " + type + " " + name + " " + value + ";"; | |||
} | } | |||
void NFA_POST_POP(); | ||||
virtual void NFA_PUSH( std::string ); | virtual void NFA_PUSH( std::string ); | |||
virtual void NFA_POP() = 0; | virtual void NFA_POP() = 0; | |||
virtual void LOCATE_TRANS() {} | virtual void LOCATE_TRANS() {} | |||
virtual void LOCATE_COND() {} | ||||
virtual void EOF_TRANS() {} | virtual void EOF_TRANS() {} | |||
virtual void COND_EXEC( std::string expr ) {} | virtual void COND_EXEC( std::string expr ) {} | |||
virtual void COND_BIN_SEARCH( Variable &var, TableArray &keys, std::strin g ok, std::string error ) {} | virtual void COND_BIN_SEARCH( Variable &var, TableArray &keys, std::strin g ok, std::string error ) {} | |||
public: | public: | |||
virtual void writeExports(); | virtual void writeExports(); | |||
}; | }; | |||
#endif | #endif | |||
End of changes. 20 change blocks. | ||||
26 lines changed or deleted | 40 lines changed or added |