Skip to content

Commit

Permalink
Support for subroutine init
Browse files Browse the repository at this point in the history
Better detection of wait transitions
Support for RestoreStep op
  • Loading branch information
cyraxred committed Sep 29, 2020
1 parent 68a4632 commit 743bc94
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
6 changes: 4 additions & 2 deletions files.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func (p *File) parseAst(fileAst *ast.File) {

const TypeStateUpdate = "StateUpdate"
const GetInitStateForFunc = "GetInitStateFor"
const GetSubroutineInitState = "GetSubroutineInitState"

func (p *File) parseFuncDecl(fd *ast.FuncDecl) *MethodDecl {
if fd.Type.Results == nil {
Expand All @@ -72,8 +73,9 @@ func (p *File) parseFuncDecl(fd *ast.FuncDecl) *MethodDecl {
case fd.Name == nil:
return nil
default:
if fd.Name.Name == GetInitStateForFunc {
md = p.findFuncWith(fd.Type.Results.List, GetInitStateForFunc, "InitFunc")
switch fd.Name.Name {
case GetInitStateForFunc, GetSubroutineInitState:
md = p.findFuncWith(fd.Type.Results.List, fd.Name.Name, "InitFunc")
}
if md == nil {
return nil
Expand Down
1 change: 1 addition & 0 deletions methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type MethodTransition struct {
HiddenPropagate string

InheritMigration bool
WaitTransition bool

TransitionTo *MethodDecl
HiddenPropTo *MethodDecl
Expand Down
13 changes: 12 additions & 1 deletion trace_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,23 @@ func (p *ExecTrace) addContextOpTransition(su *StateUpdate, mt *MethodTransition
mt.Operation = `Repeat(` + p.shortenArgs(su.args, maxArgLen) + `)`
return true

case "RestoreStep":
mt.WaitTransition = true
mt.Operation = su.name

default:
if strings.HasPrefix(su.name, "Then") {
switch op := su.parent.name; {
case op == "Sleep":
mt.WaitTransition = true
case strings.HasPrefix(op, "Wait"):
mt.WaitTransition = true
}

mt.Operation, mt.DelayedStart = p.buildOperation(su.parent)
}

if strings.HasSuffix(su.name, "Ext") || strings.HasSuffix(su.name, "Step") {
if strings.HasSuffix(su.name, "Ext") {
break
}
if len(su.args) == 0 { // repeat and similar ops
Expand Down
4 changes: 1 addition & 3 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,9 @@ func (p *Writer) WriteDecl(d *SMDecl) {
for _, tr := range step.Transitions {
connIdx++

waitOperation := false
waitOperation := tr.WaitTransition

if tr.TransitionTo == nil || !tr.TransitionTo.IsSubroutine {
waitOperation = tr.Operation != ""

m := ""
switch {
case tr.Transition == "<stop>":
Expand Down

0 comments on commit 743bc94

Please sign in to comment.