private int addEdges() {
		int nedges = 0;
		data.add(atn.states.size());
		for (ATNState s : atn.states) {
			if ( s==null ) { // might be optimized away
				data.add(ATNState.INVALID_TYPE);
				continue;
			}

			int stateType = s.getStateType();
			if (s instanceof DecisionState && ((DecisionState)s).nonGreedy) {
				nonGreedyStates.add(s.stateNumber);
			}

			if (s instanceof RuleStartState && ((RuleStartState)s).isLeftRecursiveRule) {
				precedenceStates.add(s.stateNumber);
			}

			data.add(stateType);

			data.add(s.ruleIndex);

			if ( s.getStateType() == ATNState.LOOP_END ) {
				data.add(((LoopEndState)s).loopBackState.stateNumber);
			}
			else if ( s instanceof BlockStartState ) {
				data.add(((BlockStartState)s).endState.stateNumber);
			}

			if (s.getStateType() != ATNState.RULE_STOP) {
				// the deserializer can trivially derive these edges, so there's no need to serialize them
				nedges += s.getNumberOfTransitions();
			}

			for (int i=0; i<s.getNumberOfTransitions(); i++) {
				Transition t = s.transition(i);
				int edgeType = Transition.serializationTypes.get(t.getClass());
				if ( edgeType == Transition.SET || edgeType == Transition.NOT_SET ) {
					SetTransition st = (SetTransition)t;
					sets.put(st.set, true);
				}
			}
		}
		return nedges;
	}
Serialize state descriptors, edge descriptors, and decision&rarr;state map
 into list of ints.  Likely out of date, but keeping as it could be helpful:

     SERIALIZED_VERSION
     UUID (2 longs)
		grammar-type, (ANTLRParser.LEXER, ...)
 	max token type,
 	num states,
 	state-0-type ruleIndex, state-1-type ruleIndex, ... state-i-type ruleIndex optional-arg ...
 	num rules,
 	rule-1-start-state rule-1-args, rule-2-start-state  rule-2-args, ...
 	(args are token type,actionIndex in lexer else 0,0)
     num modes,
     mode-0-start-state, mode-1-start-state, ... (parser has 0 modes)
     num unicode-bmp-sets
     bmp-set-0-interval-count intervals, bmp-set-1-interval-count intervals, ...
     num unicode-smp-sets
     smp-set-0-interval-count intervals, smp-set-1-interval-count intervals, ...
	num total edges,
     src, trg, edge-type, edge arg1, optional edge arg2 (present always), ...
     num decisions,
     decision-0-start-state, decision-1-start-state, ...

 Convenient to pack into unsigned shorts to make as Java string.
runtime/Java/src/org/antlr/v4/runtime/atn/ATNSerializer.java