/* Compiles all added states and transitions into a new Automaton and returns it. */
495331
func (b *AutomatonBuilder) finish() *Automaton {
	// fmt.Printf("LA.Builder.finish: count=%v\n", len(b.transitions)/4)
	// fmt.Println("finish pending")
	util.NewInPlaceMergeSorter(srcMinMaxDestSorter(b.transitions)).Sort(0, len(b.transitions)/4)
	for upto := 0; upto < len(b.transitions); upto += 4 {
		b.a.addTransitionRange(
			b.transitions[upto],
			b.transitions[upto+1],
			b.transitions[upto+2],
			b.transitions[upto+3],
		)
	}

	b.a.finishState()
	return b.a
}
986547
func (d *DFA) transition(fromState int, b uint8) int {
	return int(d.transitions[fromState][b])
}
936444
func (s *Execution_State) Evolve(newState Execution_State) error {
	nextStates := validExecutionStateEvolution[*s]
	if nextStates == nil {
		return fmt.Errorf("invalid state transition: no transitions defined for %s", *s)
	}

	if newState == *s {
		return nil
	}

	for _, val := range nextStates {
		if newState == val {
			*s = newState
			return nil
		}
	}

	return fmt.Errorf("invalid state transition %v -> %v", *s, newState)
}
385361
func (table *TableElem) Compile(d Dialect, params *Parameters) string {
	return fmt.Sprintf(`"%s"`, table.String())
}
16624
func reverse(a *Automaton) (*Automaton, map[int]bool) {
	if isEmpty(a) {
		return newEmptyAutomaton(), nil
	}

	numStates := a.numStates()

	// build a new automaton with all edges reversed
	b := newAutomatonBuilder()

	// initial node; we'll add epsilon transitions in the end:
	b.createState()
	for s := 0; s < numStates; s++ {
		b.createState()
	}

	// old initial state becomes new accept state:
	b.setAccept(1, true)

	t := newTransition()
	for s := 0; s < numStates; s++ {
		numTransitions := a.numTransitions(s)
		a.initTransition(s, t)
		for i := 0; i < numTransitions; i++ {
			a.nextTransition(t)
			b.addTransitionRange(t.dest+1, s+1, t.min, t.max)
		}
	}

	ans := b.finish()
	initialStates := make(map[int]bool)

	acceptStates := a.isAccept
	for s := acceptStates.NextSetBit(0); s != -1; s = acceptStates.NextSetBit(s + 1) {
		ans.addEpsilon(0, int(s+1))
		initialStates[int(s+1)] = true
	}

	ans.finishState()
	return ans, initialStates
}
1241847
func (r *Rego) Compile(ctx context.Context) (*CompileResult, error) {

	pq, err := r.Partial(ctx)
	if err != nil {
		return nil, err
	}

	if len(pq.Support) > 0 {
		return nil, fmt.Errorf("modules not supported")
	}

	policy, err := planner.New().WithQueries(pq.Queries).Plan()
	if err != nil {
		return nil, err
	}

	if r.dump != nil {
		fmt.Fprintln(r.dump, "PLAN:")
		fmt.Fprintln(r.dump, "-----")
		ir.Pretty(r.dump, policy)
		fmt.Fprintln(r.dump)
	}

	m, err := wasm.New().WithPolicy(policy).Compile()
	if err != nil {
		return nil, err
	}

	var out bytes.Buffer

	if err := encoding.WriteModule(&out, m); err != nil {
		return nil, err
	}

	result := &CompileResult{
		Bytes: out.Bytes(),
	}

	return result, nil
}
1373971
func (b *Driver) GenerateAllStates() (err error) {
	b.stepsfa0b++
	buf := []byte{0x04, byte(b.stepsfa0b), 0x00, 0x04, 0x01, 0x00, 0x32, 0x30, 0x31, 0x34, 0x2D, 0x31, 0x30, 0x2D, 0x32, 0x38, 0x00}
	err = b.adaptor().WriteCharacteristic(commandCharacteristic, buf)

	return
}
141327
func stateStepsFor21() []Step {
	return []Step{
		&upgradeStep{
			description: "add attempt to migration docs",
			targets:     []Target{DatabaseMaster},
			run: func(context Context) error {
				return context.State().AddMigrationAttempt()
			},
		},
		&upgradeStep{
			description: "add sequences to track used local charm revisions",
			targets:     []Target{DatabaseMaster},
			run: func(context Context) error {
				return context.State().AddLocalCharmSequences()
			},
		},
		&upgradeStep{
			description: "update lxd cloud/credentials",
			targets:     []Target{DatabaseMaster},
			run: func(context Context) error {
				return updateLXDCloudCredentials(context.State())
			},
		},
	}
}
1372184
func (a *Automaton) startPoints() []int {
	pointset := make(map[int]bool)
	pointset[MIN_CODE_POINT] = true
	// fmt.Println("getStartPoints")
	for s := 0; s < len(a.states); s += 2 {
		trans := a.states[s]
		limit := trans + 3*a.states[s+1]
		// fmt.Printf("  state=%v trans=%v limit=%v\n", s/2, trans, limit)
		for trans < limit {
			min, max := a.transitions[trans+1], a.transitions[trans+2]
			// fmt.Printf("    min=%v\n", min)
			pointset[min] = true
			if max < unicode.MaxRune {
				pointset[max+1] = true
			}
			trans += 3
		}
	}
	var points []int
	for m, _ := range pointset {
		points = append(points, m)
	}
	sort.Ints(points)
	return points
}
1253546
func (f *FSM) Transition() error {
	f.eventMu.Lock()
	defer f.eventMu.Unlock()
	return f.doTransition()
}
400412
func (c *Compiler) Compile(ctx context.Context, stmtNode ast.StmtNode) (*ExecStmt, error) {
	return c.compile(ctx, stmtNode, false)
}
1026280
func makeString(s string) *Automaton {
	a := newEmptyAutomaton()
	lastState := a.createState()
	for _, r := range s {
		state := a.createState()
		a.addTransitionRange(lastState, state, int(r), int(r))
		lastState = state
	}

	a.setAccept(lastState, true)
	a.finishState()

	assert(a.deterministic)
	assert(!hasDeadStates(a))

	return a
}
232533
func NewStateMachine(p *Plugin) *StateMachine {
	sm := StateMachine{
		state:  0,
		plugin: p,
	}
	sm.states = map[string]int{}
	sm.resetFn = func(*Msg) {}
	return &sm
}
738778
func (parser *TransitionParser) Add(stateName string, token string, nextStateName string, flags ParserFlag, callback ParsedFunc) {
	nextStateID := parser.GetStateID(nextStateName)
	parser.AddTransition(stateName, NewTransition(nextStateID, flags, callback), token)
}
574425
func newDumpState(value interface{}, options *Options, writer io.Writer) *dumpState {
	result := &dumpState{
		config:   options,
		pointers: MapReusedPointers(reflect.ValueOf(value)),
		w:        writer,
	}

	if options.HomePackage != "" {
		result.homePackageRegexp = regexp.MustCompile(fmt.Sprintf("\\b%s\\.", options.HomePackage))
	}

	return result
}
560088
func newDumpState(value interface{}, options *Options) *dumpState {
	result := &dumpState{
		config: options,
	}

	result.allPointers, result.reusedPointers, result.primitivePointers = GetPointers(reflect.ValueOf(value))

	if options.HomePackage != "" {
		result.homePackageRegexp = regexp.MustCompile(fmt.Sprintf("\\b%s\\.", options.HomePackage))
	}

	return result
}
556911
func (a *Automaton) numTransitions(state int) int {
	if count := a.states[2*state+1]; count != -1 {
		return count
	}
	return 0
}