summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2014-12-03 17:27:04 -0500
committerAdrian Thurston <thurston@complang.org>2014-12-03 17:29:54 -0500
commitd6e45efb6ddeebc4a6856827525b7a59f78717f0 (patch)
tree3961672dd96f9c124c9534b38ca50fb7d08d84cf
parented1567b6459f07e30d53ab57d5a189f8688f7614 (diff)
downloadragel-d6e45efb6ddeebc4a6856827525b7a59f78717f0.tar.gz
build the equiv map and emit arrays from range-based equiv data
Codegen based off of range-base equiv computation is now functional. Test suite passes. Using the original makeFlat. Next step is to modify makeFlat to use reduced input chars. refs #22
-rw-r--r--ragel/cdcodegen.cpp3
-rw-r--r--ragel/redfsm.cpp31
2 files changed, 29 insertions, 5 deletions
diff --git a/ragel/cdcodegen.cpp b/ragel/cdcodegen.cpp
index 9bee6fca..0ffe5690 100644
--- a/ragel/cdcodegen.cpp
+++ b/ragel/cdcodegen.cpp
@@ -1026,8 +1026,7 @@ void FsmCodeGen::finishRagelDef()
/* Maybe do flat expand, otherwise choose single. */
if ( codeStyle == GenFlat || codeStyle == GenFFlat ) {
- redFsm->makeFlat();
- redFsm->characterClass( fsmName );
+ redFsm->characterClassRange( fsmName );
}
else {
redFsm->chooseSingle();
diff --git a/ragel/redfsm.cpp b/ragel/redfsm.cpp
index 4bb6e72d..3c234e49 100644
--- a/ragel/redfsm.cpp
+++ b/ragel/redfsm.cpp
@@ -490,14 +490,39 @@ void RedFsmAp::characterClassRange( const char *fsmName )
equiv.transfer( newList );
}
- std::cerr << fsmName << std::endl;
+ /* Produce Flat indicies. */
+ makeFlat();
+
+ /* Build the map and emit arrays from the range-based equiv classes. Will
+ * likely crash if there are no transitions in the FSM. */
+ long long maxSpan = keyOps->span( lowKey, highKey );
+ long long *dest = new long long[maxSpan];
+ memset( dest, 0, sizeof(long long) * maxSpan );
+
+ long long *emit = new long long[maxSpan];
+ memset( emit, 0, sizeof(long long) * maxSpan );
+
+ long long targ = 0;
+ long long d = 0;
for ( EquivClass *c = equiv.head; c != 0; c = c->next ) {
- std::cerr << " class: " << c->lowKey.getVal() <<
- " " << c->highKey.getVal() << std::endl;
+ long long span = keyOps->span( c->lowKey, c->highKey );
+
+ dest[d] = targ;
+ emit[d] = 1;
+ d += 1;
+ for ( long long s = 1; s < span; s++ ) {
+ dest[d] = targ;
+ emit[d] = 0;
+ d += 1;
+ }
+ targ += 1;
}
this->lowKey = lowKey;
this->highKey = highKey;
+ this->classMap = dest;
+ this->classEmit = emit;
+
equiv.empty();
}