shrunk serialized ATN a bit
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9526]
This commit is contained in:
parent
b09077209c
commit
2ddb8100e9
|
@ -62,9 +62,8 @@ public abstract class ATNSimulator {
|
||||||
int nstates = toInt(data[p++]);
|
int nstates = toInt(data[p++]);
|
||||||
for (int i=1; i<=nstates; i++) {
|
for (int i=1; i<=nstates; i++) {
|
||||||
int stype = toInt(data[p++]);
|
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 ) {
|
if ( stype==ATNState.INVALID_TYPE ) {
|
||||||
p++;
|
|
||||||
atn.addState(null);
|
atn.addState(null);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -88,9 +87,6 @@ public abstract class ATNSimulator {
|
||||||
int actionIndex = toInt(data[p++]);
|
int actionIndex = toInt(data[p++]);
|
||||||
atn.ruleToActionIndex[i] = actionIndex;
|
atn.ruleToActionIndex[i] = actionIndex;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
p += 2;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
int nmodes = toInt(data[p++]);
|
int nmodes = toInt(data[p++]);
|
||||||
for (int i=0; i<nmodes; i++) {
|
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_BACK : s = new StarLoopbackState(); break;
|
||||||
case ATNState.STAR_LOOP_ENTRY : s = new StarLoopEntryState(); break;
|
case ATNState.STAR_LOOP_ENTRY : s = new StarLoopEntryState(); break;
|
||||||
case ATNState.PLUS_LOOP_BACK : s = new PlusLoopbackState(); 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;
|
s.stateNumber = stateNumber;
|
||||||
return s;
|
return s;
|
||||||
|
|
|
@ -84,7 +84,6 @@ public class ATNSerializer {
|
||||||
for (ATNState s : atn.states) {
|
for (ATNState s : atn.states) {
|
||||||
if ( s==null ) { // might be optimized away
|
if ( s==null ) { // might be optimized away
|
||||||
data.add(ATNState.INVALID_TYPE);
|
data.add(ATNState.INVALID_TYPE);
|
||||||
data.add(-1);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
data.add(s.getStateType());
|
data.add(s.getStateType());
|
||||||
|
@ -110,10 +109,6 @@ public class ATNSerializer {
|
||||||
Rule rule = g.getRule(ruleName);
|
Rule rule = g.getRule(ruleName);
|
||||||
data.add(rule.actionIndex);
|
data.add(rule.actionIndex);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
data.add(0);
|
|
||||||
data.add(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
int nmodes = atn.modeToStartState.size();
|
int nmodes = atn.modeToStartState.size();
|
||||||
data.add(nmodes);
|
data.add(nmodes);
|
||||||
|
@ -203,8 +198,8 @@ public class ATNSerializer {
|
||||||
int nstates = ATNSimulator.toInt(data[p++]);
|
int nstates = ATNSimulator.toInt(data[p++]);
|
||||||
for (int i=1; i<=nstates; i++) {
|
for (int i=1; i<=nstates; i++) {
|
||||||
int stype = ATNSimulator.toInt(data[p++]);
|
int stype = ATNSimulator.toInt(data[p++]);
|
||||||
|
if ( stype==ATNState.INVALID_TYPE ) continue; // ignore bad type of states
|
||||||
int ruleIndex = ATNSimulator.toInt(data[p++]);
|
int ruleIndex = ATNSimulator.toInt(data[p++]);
|
||||||
if ( stype==0 ) continue; // ignore bad type of states
|
|
||||||
buf.append((i - 1) + ":" +
|
buf.append((i - 1) + ":" +
|
||||||
ATNState.serializationNames.get(stype) + " "+
|
ATNState.serializationNames.get(stype) + " "+
|
||||||
ruleIndex + "\n");
|
ruleIndex + "\n");
|
||||||
|
@ -212,9 +207,14 @@ public class ATNSerializer {
|
||||||
int nrules = ATNSimulator.toInt(data[p++]);
|
int nrules = ATNSimulator.toInt(data[p++]);
|
||||||
for (int i=0; i<nrules; i++) {
|
for (int i=0; i<nrules; i++) {
|
||||||
int s = ATNSimulator.toInt(data[p++]);
|
int s = ATNSimulator.toInt(data[p++]);
|
||||||
int arg1 = ATNSimulator.toInt(data[p++]);
|
if ( g.isLexer() ) {
|
||||||
int arg2 = ATNSimulator.toInt(data[p++]);
|
int arg1 = ATNSimulator.toInt(data[p++]);
|
||||||
buf.append("rule "+i+":"+s+" "+arg1+","+arg2+'\n');
|
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++]);
|
int nmodes = ATNSimulator.toInt(data[p++]);
|
||||||
for (int i=0; i<nmodes; i++) {
|
for (int i=0; i<nmodes; i++) {
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class TestATNSerialization extends BaseTest {
|
||||||
"4:BASIC 0\n" +
|
"4:BASIC 0\n" +
|
||||||
"5:BASIC 0\n" +
|
"5:BASIC 0\n" +
|
||||||
"6:BASIC 0\n" +
|
"6:BASIC 0\n" +
|
||||||
"rule 0:0 0,0\n" +
|
"rule 0:0\n" +
|
||||||
"0->2 EPSILON 0,0,0\n" +
|
"0->2 EPSILON 0,0,0\n" +
|
||||||
"1->6 ATOM -1,0,0\n" +
|
"1->6 ATOM -1,0,0\n" +
|
||||||
"2->4 ATOM 3,0,0\n" +
|
"2->4 ATOM 3,0,0\n" +
|
||||||
|
@ -72,7 +72,7 @@ public class TestATNSerialization extends BaseTest {
|
||||||
"4:BASIC 0\n" +
|
"4:BASIC 0\n" +
|
||||||
"5:BASIC 0\n" +
|
"5:BASIC 0\n" +
|
||||||
"6:BASIC 0\n" +
|
"6:BASIC 0\n" +
|
||||||
"rule 0:0 0,0\n" +
|
"rule 0:0\n" +
|
||||||
"0->2 EPSILON 0,0,0\n" +
|
"0->2 EPSILON 0,0,0\n" +
|
||||||
"1->6 ATOM -1,0,0\n" +
|
"1->6 ATOM -1,0,0\n" +
|
||||||
"2->4 ATOM 3,0,0\n" +
|
"2->4 ATOM 3,0,0\n" +
|
||||||
|
@ -94,7 +94,7 @@ public class TestATNSerialization extends BaseTest {
|
||||||
"2:BASIC 0\n" +
|
"2:BASIC 0\n" +
|
||||||
"3:BASIC 0\n" +
|
"3:BASIC 0\n" +
|
||||||
"4:BASIC 0\n" +
|
"4:BASIC 0\n" +
|
||||||
"rule 0:0 0,0\n" +
|
"rule 0:0\n" +
|
||||||
"0:EOF..EOF, A..A\n" +
|
"0:EOF..EOF, A..A\n" +
|
||||||
"0->2 EPSILON 0,0,0\n" +
|
"0->2 EPSILON 0,0,0\n" +
|
||||||
"1->4 ATOM -1,0,0\n" +
|
"1->4 ATOM -1,0,0\n" +
|
||||||
|
@ -117,7 +117,7 @@ public class TestATNSerialization extends BaseTest {
|
||||||
"2:BASIC 0\n" +
|
"2:BASIC 0\n" +
|
||||||
"3:BASIC 0\n" +
|
"3:BASIC 0\n" +
|
||||||
"4:BASIC 0\n" +
|
"4:BASIC 0\n" +
|
||||||
"rule 0:0 0,0\n" +
|
"rule 0:0\n" +
|
||||||
"0:A..A\n" +
|
"0:A..A\n" +
|
||||||
"0->2 EPSILON 0,0,0\n" +
|
"0->2 EPSILON 0,0,0\n" +
|
||||||
"1->4 ATOM -1,0,0\n" +
|
"1->4 ATOM -1,0,0\n" +
|
||||||
|
@ -142,7 +142,7 @@ public class TestATNSerialization extends BaseTest {
|
||||||
"2:BASIC 0\n" +
|
"2:BASIC 0\n" +
|
||||||
"3:BASIC 0\n" +
|
"3:BASIC 0\n" +
|
||||||
"4:BASIC 0\n" +
|
"4:BASIC 0\n" +
|
||||||
"rule 0:0 0,0\n" +
|
"rule 0:0\n" +
|
||||||
"0->2 EPSILON 0,0,0\n" +
|
"0->2 EPSILON 0,0,0\n" +
|
||||||
"1->4 ATOM -1,0,0\n" +
|
"1->4 ATOM -1,0,0\n" +
|
||||||
"2->3 WILDCARD 0,0,0\n" +
|
"2->3 WILDCARD 0,0,0\n" +
|
||||||
|
@ -166,7 +166,7 @@ public class TestATNSerialization extends BaseTest {
|
||||||
"8:BLOCK_START 0\n" +
|
"8:BLOCK_START 0\n" +
|
||||||
"9:BLOCK_END 0\n" +
|
"9:BLOCK_END 0\n" +
|
||||||
"10:BASIC 0\n" +
|
"10:BASIC 0\n" +
|
||||||
"rule 0:0 0,0\n" +
|
"rule 0:0\n" +
|
||||||
"0->8 EPSILON 0,0,0\n" +
|
"0->8 EPSILON 0,0,0\n" +
|
||||||
"1->10 ATOM -1,0,0\n" +
|
"1->10 ATOM -1,0,0\n" +
|
||||||
"2->9 ATOM 3,0,0\n" +
|
"2->9 ATOM 3,0,0\n" +
|
||||||
|
@ -198,7 +198,7 @@ public class TestATNSerialization extends BaseTest {
|
||||||
"14:BLOCK_START 0\n" +
|
"14:BLOCK_START 0\n" +
|
||||||
"15:BLOCK_END 0\n" +
|
"15:BLOCK_END 0\n" +
|
||||||
"16:BASIC 0\n" +
|
"16:BASIC 0\n" +
|
||||||
"rule 0:0 0,0\n" +
|
"rule 0:0\n" +
|
||||||
"0->14 EPSILON 0,0,0\n" +
|
"0->14 EPSILON 0,0,0\n" +
|
||||||
"1->16 ATOM -1,0,0\n" +
|
"1->16 ATOM -1,0,0\n" +
|
||||||
"2->15 ATOM 3,0,0\n" +
|
"2->15 ATOM 3,0,0\n" +
|
||||||
|
@ -233,7 +233,7 @@ public class TestATNSerialization extends BaseTest {
|
||||||
"8:BASIC 0\n" +
|
"8:BASIC 0\n" +
|
||||||
"9:BASIC 0\n" +
|
"9:BASIC 0\n" +
|
||||||
"10:BASIC 0\n" +
|
"10:BASIC 0\n" +
|
||||||
"rule 0:0 0,0\n" +
|
"rule 0:0\n" +
|
||||||
"0->4 EPSILON 0,0,0\n" +
|
"0->4 EPSILON 0,0,0\n" +
|
||||||
"1->10 ATOM -1,0,0\n" +
|
"1->10 ATOM -1,0,0\n" +
|
||||||
"2->5 ATOM 3,0,0\n" +
|
"2->5 ATOM 3,0,0\n" +
|
||||||
|
@ -266,8 +266,8 @@ public class TestATNSerialization extends BaseTest {
|
||||||
"6:BASIC 1\n" +
|
"6:BASIC 1\n" +
|
||||||
"7:BASIC 1\n" +
|
"7:BASIC 1\n" +
|
||||||
"8:BASIC 1\n" +
|
"8:BASIC 1\n" +
|
||||||
"rule 0:0 0,0\n" +
|
"rule 0:0\n" +
|
||||||
"rule 1:2 0,0\n" +
|
"rule 1:2\n" +
|
||||||
"0->4 EPSILON 0,0,0\n" +
|
"0->4 EPSILON 0,0,0\n" +
|
||||||
"1->8 ATOM -1,0,0\n" +
|
"1->8 ATOM -1,0,0\n" +
|
||||||
"2->6 EPSILON 0,0,0\n" +
|
"2->6 EPSILON 0,0,0\n" +
|
||||||
|
|
Loading…
Reference in New Issue