shrunk serialized ATN a bit

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9526]
This commit is contained in:
parrt 2011-12-04 18:39:20 -08:00
parent b09077209c
commit 2ddb8100e9
3 changed files with 23 additions and 24 deletions

View File

@ -62,9 +62,8 @@ public abstract class ATNSimulator {
int nstates = toInt(data[p++]);
for (int i=1; i<=nstates; i++) {
int stype = toInt(data[p++]);
// ignore bad type of states, skip it's bad ruleIndex too
// ignore bad type of states
if ( stype==ATNState.INVALID_TYPE ) {
p++;
atn.addState(null);
continue;
}
@ -88,9 +87,6 @@ public abstract class ATNSimulator {
int actionIndex = toInt(data[p++]);
atn.ruleToActionIndex[i] = actionIndex;
}
else {
p += 2;
}
}
int nmodes = toInt(data[p++]);
for (int i=0; i<nmodes; i++) {
@ -182,6 +178,9 @@ public abstract class ATNSimulator {
case ATNState.STAR_LOOP_BACK : s = new StarLoopbackState(); break;
case ATNState.STAR_LOOP_ENTRY : s = new StarLoopEntryState(); break;
case ATNState.PLUS_LOOP_BACK : s = new PlusLoopbackState(); break;
default :
System.err.println("invalid state type in ATN deserialization: "+type+" for state "+stateNumber);
break;
}
s.stateNumber = stateNumber;
return s;

View File

@ -84,7 +84,6 @@ public class ATNSerializer {
for (ATNState s : atn.states) {
if ( s==null ) { // might be optimized away
data.add(ATNState.INVALID_TYPE);
data.add(-1);
continue;
}
data.add(s.getStateType());
@ -110,10 +109,6 @@ public class ATNSerializer {
Rule rule = g.getRule(ruleName);
data.add(rule.actionIndex);
}
else {
data.add(0);
data.add(0);
}
}
int nmodes = atn.modeToStartState.size();
data.add(nmodes);
@ -203,8 +198,8 @@ public class ATNSerializer {
int nstates = ATNSimulator.toInt(data[p++]);
for (int i=1; i<=nstates; i++) {
int stype = ATNSimulator.toInt(data[p++]);
if ( stype==ATNState.INVALID_TYPE ) continue; // ignore bad type of states
int ruleIndex = ATNSimulator.toInt(data[p++]);
if ( stype==0 ) continue; // ignore bad type of states
buf.append((i - 1) + ":" +
ATNState.serializationNames.get(stype) + " "+
ruleIndex + "\n");
@ -212,9 +207,14 @@ public class ATNSerializer {
int nrules = ATNSimulator.toInt(data[p++]);
for (int i=0; i<nrules; i++) {
int s = ATNSimulator.toInt(data[p++]);
int arg1 = ATNSimulator.toInt(data[p++]);
int arg2 = ATNSimulator.toInt(data[p++]);
buf.append("rule "+i+":"+s+" "+arg1+","+arg2+'\n');
if ( g.isLexer() ) {
int arg1 = ATNSimulator.toInt(data[p++]);
int arg2 = ATNSimulator.toInt(data[p++]);
buf.append("rule "+i+":"+s+" "+arg1+","+arg2+'\n');
}
else {
buf.append("rule "+i+":"+s+'\n');
}
}
int nmodes = ATNSimulator.toInt(data[p++]);
for (int i=0; i<nmodes; i++) {

View File

@ -49,7 +49,7 @@ public class TestATNSerialization extends BaseTest {
"4:BASIC 0\n" +
"5:BASIC 0\n" +
"6:BASIC 0\n" +
"rule 0:0 0,0\n" +
"rule 0:0\n" +
"0->2 EPSILON 0,0,0\n" +
"1->6 ATOM -1,0,0\n" +
"2->4 ATOM 3,0,0\n" +
@ -72,7 +72,7 @@ public class TestATNSerialization extends BaseTest {
"4:BASIC 0\n" +
"5:BASIC 0\n" +
"6:BASIC 0\n" +
"rule 0:0 0,0\n" +
"rule 0:0\n" +
"0->2 EPSILON 0,0,0\n" +
"1->6 ATOM -1,0,0\n" +
"2->4 ATOM 3,0,0\n" +
@ -94,7 +94,7 @@ public class TestATNSerialization extends BaseTest {
"2:BASIC 0\n" +
"3:BASIC 0\n" +
"4:BASIC 0\n" +
"rule 0:0 0,0\n" +
"rule 0:0\n" +
"0:EOF..EOF, A..A\n" +
"0->2 EPSILON 0,0,0\n" +
"1->4 ATOM -1,0,0\n" +
@ -117,7 +117,7 @@ public class TestATNSerialization extends BaseTest {
"2:BASIC 0\n" +
"3:BASIC 0\n" +
"4:BASIC 0\n" +
"rule 0:0 0,0\n" +
"rule 0:0\n" +
"0:A..A\n" +
"0->2 EPSILON 0,0,0\n" +
"1->4 ATOM -1,0,0\n" +
@ -142,7 +142,7 @@ public class TestATNSerialization extends BaseTest {
"2:BASIC 0\n" +
"3:BASIC 0\n" +
"4:BASIC 0\n" +
"rule 0:0 0,0\n" +
"rule 0:0\n" +
"0->2 EPSILON 0,0,0\n" +
"1->4 ATOM -1,0,0\n" +
"2->3 WILDCARD 0,0,0\n" +
@ -166,7 +166,7 @@ public class TestATNSerialization extends BaseTest {
"8:BLOCK_START 0\n" +
"9:BLOCK_END 0\n" +
"10:BASIC 0\n" +
"rule 0:0 0,0\n" +
"rule 0:0\n" +
"0->8 EPSILON 0,0,0\n" +
"1->10 ATOM -1,0,0\n" +
"2->9 ATOM 3,0,0\n" +
@ -198,7 +198,7 @@ public class TestATNSerialization extends BaseTest {
"14:BLOCK_START 0\n" +
"15:BLOCK_END 0\n" +
"16:BASIC 0\n" +
"rule 0:0 0,0\n" +
"rule 0:0\n" +
"0->14 EPSILON 0,0,0\n" +
"1->16 ATOM -1,0,0\n" +
"2->15 ATOM 3,0,0\n" +
@ -233,7 +233,7 @@ public class TestATNSerialization extends BaseTest {
"8:BASIC 0\n" +
"9:BASIC 0\n" +
"10:BASIC 0\n" +
"rule 0:0 0,0\n" +
"rule 0:0\n" +
"0->4 EPSILON 0,0,0\n" +
"1->10 ATOM -1,0,0\n" +
"2->5 ATOM 3,0,0\n" +
@ -266,8 +266,8 @@ public class TestATNSerialization extends BaseTest {
"6:BASIC 1\n" +
"7:BASIC 1\n" +
"8:BASIC 1\n" +
"rule 0:0 0,0\n" +
"rule 1:2 0,0\n" +
"rule 0:0\n" +
"rule 1:2\n" +
"0->4 EPSILON 0,0,0\n" +
"1->8 ATOM -1,0,0\n" +
"2->6 EPSILON 0,0,0\n" +