From 4b5b2401de77cf82276e9953eaddc814f41e5b3a Mon Sep 17 00:00:00 2001 From: Uwe Truetsch Date: Fri, 27 Sep 2024 14:00:42 +0300 Subject: [PATCH 1/4] add support for altstep interleave --- ttcn3/syntax/nodes.go | 55 +++++++++++++++++++------------------ ttcn3/syntax/nodes_gen.go | 36 ++++++++++++++++++++++-- ttcn3/syntax/parser.go | 15 ++++++++++ ttcn3/syntax/parser_test.go | 4 +++ 4 files changed, 81 insertions(+), 29 deletions(-) diff --git a/ttcn3/syntax/nodes.go b/ttcn3/syntax/nodes.go index aba8b4ba..9365e056 100644 --- a/ttcn3/syntax/nodes.go +++ b/ttcn3/syntax/nodes.go @@ -566,11 +566,12 @@ type ( // A BehaviourSpec represents a behaviour type specification. BehaviourSpec struct { - Kind Token // TESTCASE, FUNCTION, ALTSTEP - Params *FormalPars // Parameter list or nil - RunsOn *RunsOnSpec // runs on spec or nil - System *SystemSpec // system spec or nil - Return *ReturnSpec // return value spec or nil + Kind Token // TESTCASE, FUNCTION, ALTSTEP + Interleave Token // INTERLEAVE or nil + Params *FormalPars // Parameter list or nil + RunsOn *RunsOnSpec // runs on spec or nil + System *SystemSpec // system spec or nil + Return *ReturnSpec // return value spec or nil } ) @@ -626,18 +627,19 @@ type ( // A FuncDecl represents a behaviour definition. FuncDecl struct { - External Token // Position of "external" or nil - Kind Token // TESTCASE, ALTSTEP, FUNCTION - Name *Ident - Modif Token // Position of "@deterministic" or nil - TypePars *FormalPars - Params *FormalPars // Formal parameter list or nil - RunsOn *RunsOnSpec // Optional runs-on-spec - Mtc *MtcSpec // Optional mtc-spec - System *SystemSpec // Optional system-spec - Return *ReturnSpec // Optional return-spec - Body *BlockStmt // Body or nil - With *WithSpec + External Token // Position of "external" or nil + Kind Token // TESTCASE, ALTSTEP, FUNCTION + Interleave Token // INTERLEAVE or nil + Name *Ident + Modif Token // Position of "@deterministic" or nil + TypePars *FormalPars + Params *FormalPars // Formal parameter list or nil + RunsOn *RunsOnSpec // Optional runs-on-spec + Mtc *MtcSpec // Optional mtc-spec + System *SystemSpec // Optional system-spec + Return *ReturnSpec // Optional return-spec + Body *BlockStmt // Body or nil + With *WithSpec } // A ConstructorDecl represents a class constructor definition. @@ -718,15 +720,16 @@ type ( // A BehaviourTypeDecl represents a named behaviour type. BehaviourTypeDecl struct { - TypeTok Token // Position of "type" - Kind Token // TESTCASE, ALTSTEP, FUNCTION - Name *Ident - TypePars *FormalPars - Params *FormalPars // Formal parameter list - RunsOn *RunsOnSpec // Optional runs-on spec - System *SystemSpec // Optional system spec - Return *ReturnSpec // Optional return spec - With *WithSpec + TypeTok Token // Position of "type" + Kind Token // TESTCASE, ALTSTEP, FUNCTION + Interleave Token // INTERLEAVE or nil + Name *Ident + TypePars *FormalPars + Params *FormalPars // Formal parameter list + RunsOn *RunsOnSpec // Optional runs-on spec + System *SystemSpec // Optional system spec + Return *ReturnSpec // Optional return spec + With *WithSpec } PortTypeDecl struct { diff --git a/ttcn3/syntax/nodes_gen.go b/ttcn3/syntax/nodes_gen.go index cd56c75d..2f0fc791 100644 --- a/ttcn3/syntax/nodes_gen.go +++ b/ttcn3/syntax/nodes_gen.go @@ -85,6 +85,9 @@ func (n *BehaviourSpec) FirstTok() Token { case n.Kind != nil: return n.Kind + case n.Interleave != nil: + return n.Interleave + case n.Params != nil: return n.Params.FirstTok() @@ -117,6 +120,9 @@ func (n *BehaviourSpec) LastTok() Token { case n.Params != nil: return n.Params.LastTok() + case n.Interleave != nil: + return n.Interleave + case n.Kind != nil: return n.Kind @@ -126,12 +132,16 @@ func (n *BehaviourSpec) LastTok() Token { } func (n *BehaviourSpec) Children() []Node { - ret := make([]Node, 0, 5) + ret := make([]Node, 0, 6) if n.Kind != nil { ret = append(ret, n.Kind) } + if n.Interleave != nil { + ret = append(ret, n.Interleave) + } + if n.Params != nil { ret = append(ret, n.Params) } @@ -206,6 +216,9 @@ func (n *BehaviourTypeDecl) FirstTok() Token { case n.Kind != nil: return n.Kind + case n.Interleave != nil: + return n.Interleave + case n.Name != nil: return n.Name.FirstTok() @@ -256,6 +269,9 @@ func (n *BehaviourTypeDecl) LastTok() Token { case n.Name != nil: return n.Name.LastTok() + case n.Interleave != nil: + return n.Interleave + case n.Kind != nil: return n.Kind @@ -268,7 +284,7 @@ func (n *BehaviourTypeDecl) LastTok() Token { } func (n *BehaviourTypeDecl) Children() []Node { - ret := make([]Node, 0, 9) + ret := make([]Node, 0, 10) if n.TypeTok != nil { ret = append(ret, n.TypeTok) @@ -278,6 +294,10 @@ func (n *BehaviourTypeDecl) Children() []Node { ret = append(ret, n.Kind) } + if n.Interleave != nil { + ret = append(ret, n.Interleave) + } + if n.Name != nil { ret = append(ret, n.Name) } @@ -3436,6 +3456,9 @@ func (n *FuncDecl) FirstTok() Token { case n.Kind != nil: return n.Kind + case n.Interleave != nil: + return n.Interleave + case n.Name != nil: return n.Name.FirstTok() @@ -3504,6 +3527,9 @@ func (n *FuncDecl) LastTok() Token { case n.Name != nil: return n.Name.LastTok() + case n.Interleave != nil: + return n.Interleave + case n.Kind != nil: return n.Kind @@ -3516,7 +3542,7 @@ func (n *FuncDecl) LastTok() Token { } func (n *FuncDecl) Children() []Node { - ret := make([]Node, 0, 12) + ret := make([]Node, 0, 13) if n.External != nil { ret = append(ret, n.External) @@ -3526,6 +3552,10 @@ func (n *FuncDecl) Children() []Node { ret = append(ret, n.Kind) } + if n.Interleave != nil { + ret = append(ret, n.Interleave) + } + if n.Name != nil { ret = append(ret, n.Name) } diff --git a/ttcn3/syntax/parser.go b/ttcn3/syntax/parser.go index 3605eb3e..e00c35f0 100644 --- a/ttcn3/syntax/parser.go +++ b/ttcn3/syntax/parser.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/nokia/ntt/internal/fs" + "github.com/nokia/ntt/internal/log" ) // A Mode value is a set of flags (or 0). @@ -1819,6 +1820,11 @@ func (p *parser) parseBehaviourTypeDecl() *BehaviourTypeDecl { x := new(BehaviourTypeDecl) x.TypeTok = p.consume() x.Kind = p.consume() + log.Debugf("@@BehaviourTypeDecl: %s", p.tok) + if p.tok == INTERLEAVE { + x.Interleave = p.consume() + } + x.Name = p.parseName() if p.tok == LT { x.TypePars = p.parseTypeFormalPars() @@ -1987,6 +1993,11 @@ func (p *parser) parseBehaviourSpec() *BehaviourSpec { x := new(BehaviourSpec) x.Kind = p.consume() + + if p.tok == INTERLEAVE { + x.Interleave = p.consume() + } + x.Params = p.parseFormalPars() if p.tok == RUNS { @@ -2163,6 +2174,10 @@ func (p *parser) parseFuncDecl() *FuncDecl { x := new(FuncDecl) x.Kind = p.consume() + log.Debugf("@@parseFuncDecl: %s", p.tok) + if p.tok == INTERLEAVE { + x.Interleave = p.consume() + } if p.tok == MODIF { x.Modif = p.consume() } diff --git a/ttcn3/syntax/parser_test.go b/ttcn3/syntax/parser_test.go index 47d1969d..29e1f5d6 100644 --- a/ttcn3/syntax/parser_test.go +++ b/ttcn3/syntax/parser_test.go @@ -103,6 +103,7 @@ func TestFuncDecls(t *testing.T) { {pass, `function f() mtc C {}`}, {pass, `function f() runs on C mtc C system C {}`}, {pass, `altstep as() { var roi[-] a[4][4]; [] receive; [else] {}}`}, + {pass, `altstep interleave interleaveStep() { [] p1.receive; [] p2.check{}}`}, {pass, `signature f();`}, {pass, `signature f() exception (integer);`}, {pass, `signature f() return int;`}, @@ -233,6 +234,8 @@ func TestTypes(t *testing.T) { {pass, `type set s {int a optional }`}, {pass, `type set s {set length(1) of set length(2) of int() f1[-][-] length(3) optional}`}, {pass, `type set s {function () runs on self return template int callback}`}, + {pass, `type set s {altstep (integer p_i) runs on self as_callback}`}, + {pass, `type set s {altstep interleave(integer p_i) runs on C is_callback}`}, {pass, `type union s {@default set of int f1 optional}`}, {pass, `type union s {enumerated { e(1) } foo}`}, {pass, `type enumerated a {e, e(1), e(1)}`}, @@ -258,6 +261,7 @@ func TestTypes(t *testing.T) { // Behaviour Types {pass, `type function fn() runs on self return template int`}, {pass, `type altstep as() runs on self return int`}, + {pass, `type altstep interleave iStep() runs on C`}, {pass, `type testcase tc() runs on C system TSI`}, // Class Types From a18185f169e3837ff6e7725114ca94707e386eb6 Mon Sep 17 00:00:00 2001 From: Uwe Truetsch Date: Fri, 27 Sep 2024 15:25:09 +0300 Subject: [PATCH 2/4] removing some debug logs --- ttcn3/syntax/parser.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ttcn3/syntax/parser.go b/ttcn3/syntax/parser.go index e00c35f0..321116df 100644 --- a/ttcn3/syntax/parser.go +++ b/ttcn3/syntax/parser.go @@ -11,7 +11,6 @@ import ( "strings" "github.com/nokia/ntt/internal/fs" - "github.com/nokia/ntt/internal/log" ) // A Mode value is a set of flags (or 0). @@ -1820,7 +1819,7 @@ func (p *parser) parseBehaviourTypeDecl() *BehaviourTypeDecl { x := new(BehaviourTypeDecl) x.TypeTok = p.consume() x.Kind = p.consume() - log.Debugf("@@BehaviourTypeDecl: %s", p.tok) + if p.tok == INTERLEAVE { x.Interleave = p.consume() } @@ -2174,7 +2173,7 @@ func (p *parser) parseFuncDecl() *FuncDecl { x := new(FuncDecl) x.Kind = p.consume() - log.Debugf("@@parseFuncDecl: %s", p.tok) + if p.tok == INTERLEAVE { x.Interleave = p.consume() } From 9272576490eb3027d59bbd89786e27535f0cec70 Mon Sep 17 00:00:00 2001 From: Uwe Truetsch Date: Fri, 27 Sep 2024 17:14:15 +0300 Subject: [PATCH 3/4] add new altstep interleave opcodes --- k3/t3xf/opcode/opcode_gen.go | 86 +++++++++++++++++++++++++++++++++++- k3/t3xf/opcode/opcodes.yml | 52 ++++++++++++++++++++++ 2 files changed, 137 insertions(+), 1 deletion(-) diff --git a/k3/t3xf/opcode/opcode_gen.go b/k3/t3xf/opcode/opcode_gen.go index 7cad0bd4..5de0054b 100644 --- a/k3/t3xf/opcode/opcode_gen.go +++ b/k3/t3xf/opcode/opcode_gen.go @@ -1,5 +1,5 @@ // Code generated from opcode.tmpl.go and by 'go generate'; DO NOT EDIT. -// This file was generated by robots at 2024-08-01 08:50:29.679332793 +0200 CEST m=+0.341422798 +// This file was generated by robots at 2024-09-27 16:09:13.179602483 +0300 EEST m=+0.584646302 // Package opcode defines the opcodes used in T3XF. package opcode @@ -1093,6 +1093,42 @@ const ( // INTERLEAVE Opcode = 0x0393 + // Define an interleavestep object from a block pblk containing its + // parameters, bblk containing its behaviour and a name, and then + // attach it to the module object owning the current block. + // + // [pblk bblk name] INTERLEAVESTEP [] + // + INTERLEAVESTEP Opcode = 0x2033 + + // Define a bound interleavestep object from a component type comp, a + // block pblk containing its parameters, bblk containing its + // behaviour and a name, then attach it to the module object + // owning the current block. + // + // [comp pblk bblk name] INTERLEAVESTEPB [] + // + INTERLEAVESTEPB Opcode = 0x2043 + + // Define a bound interleavestep object from a component type comp, a + // block pblk containing its parameters, bblk containing its + // behaviour and a name, attach the attributes from block ablk, + // and then attach it to the module object owning the current + // block. + // + // [comp ablk pblk bblk name] INTERLEAVESTEPBW [] + // + INTERLEAVESTEPBW Opcode = 0x2053 + + // Define an interleavestep object from a block pblk containing its + // parameters, bblk containing its behaviour and a name, attach + // the attributes from block ablk, and then attach it to the + // module object owning the current block. + // + // [ablk pblk bblk name] INTERLEAVESTEPW [] + // + INTERLEAVESTEPW Opcode = 0x2063 + // Stack operations might be dynamic. // // [] ISBOUND [] @@ -3860,6 +3896,46 @@ var Descriptions = map[Opcode]*Descriptor{ }, }, + INTERLEAVESTEP: { + Opcode: 0x2033, + Description: "Define an interleavestep object from a block pblk containing its\nparameters, bblk containing its behaviour and a name, and then\nattach it to the module object owning the current block.\n\n", + Context: []string{"beha_def"}, + Operations: Operation{ + Pre: []string{"pblk", "bblk", "name"}, + Post: []string{}, + }, + }, + + INTERLEAVESTEPB: { + Opcode: 0x2043, + Description: "Define a bound interleavestep object from a component type comp, a\nblock pblk containing its parameters, bblk containing its\nbehaviour and a name, then attach it to the module object\nowning the current block.\n\n", + Context: []string{"beha_def"}, + Operations: Operation{ + Pre: []string{"comp", "pblk", "bblk", "name"}, + Post: []string{}, + }, + }, + + INTERLEAVESTEPBW: { + Opcode: 0x2053, + Description: "Define a bound interleavestep object from a component type comp, a\nblock pblk containing its parameters, bblk containing its\nbehaviour and a name, attach the attributes from block ablk,\nand then attach it to the module object owning the current\nblock.\n\n", + Context: []string{"beha_def"}, + Operations: Operation{ + Pre: []string{"comp", "ablk", "pblk", "bblk", "name"}, + Post: []string{}, + }, + }, + + INTERLEAVESTEPW: { + Opcode: 0x2063, + Description: "Define an interleavestep object from a block pblk containing its\nparameters, bblk containing its behaviour and a name, attach\nthe attributes from block ablk, and then attach it to the\nmodule object owning the current block.\n\n", + Context: []string{"beha_def"}, + Operations: Operation{ + Pre: []string{"ablk", "pblk", "bblk", "name"}, + Post: []string{}, + }, + }, + ISBOUND: { Opcode: 0x1ad3, Description: "Stack operations might be dynamic.\n\n", @@ -5880,6 +5956,10 @@ var opcodeStrings = map[Opcode]string{ INT2STR: "int2str", INTEGER: "integer", INTERLEAVE: "interleave", + INTERLEAVESTEP: "interleavestep", + INTERLEAVESTEPB: "interleavestepb", + INTERLEAVESTEPBW: "interleavestepbw", + INTERLEAVESTEPW: "interleavestepw", ISBOUND: "isbound", ISCHOSEN: "ischosen", ISPRESENT: "ispresent", @@ -6218,6 +6298,10 @@ var opcodeNames = map[string]Opcode{ "int2str": INT2STR, "integer": INTEGER, "interleave": INTERLEAVE, + "interleavestep": INTERLEAVESTEP, + "interleavestepb": INTERLEAVESTEPB, + "interleavestepbw": INTERLEAVESTEPBW, + "interleavestepw": INTERLEAVESTEPW, "isbound": ISBOUND, "ischosen": ISCHOSEN, "ispresent": ISPRESENT, diff --git a/k3/t3xf/opcode/opcodes.yml b/k3/t3xf/opcode/opcodes.yml index 7c041bb6..d5f82d44 100644 --- a/k3/t3xf/opcode/opcodes.yml +++ b/k3/t3xf/opcode/opcodes.yml @@ -1633,6 +1633,58 @@ interleave: Actions attached to successful alternatives may extend the set of alternatives to complete. +interleavestep: + opcode: 515 + context: + - beha_def + operations: + pre: [pblk, bblk, name] + post: [] + description: |+ + Define an interleavestep object from a block pblk containing its + parameters, bblk containing its behaviour and a name, and then + attach it to the module object owning the current block. + +interleavestepb: + opcode: 516 + context: + - beha_def + operations: + pre: [comp, pblk, bblk, name] + post: [] + description: |+ + Define a bound interleavestep object from a component type comp, a + block pblk containing its parameters, bblk containing its + behaviour and a name, then attach it to the module object + owning the current block. + +interleavestepbw: + opcode: 517 + context: + - beha_def + operations: + pre: [comp, ablk, pblk, bblk, name] + post: [] + description: |+ + Define a bound interleavestep object from a component type comp, a + block pblk containing its parameters, bblk containing its + behaviour and a name, attach the attributes from block ablk, + and then attach it to the module object owning the current + block. + +interleavestepw: + opcode: 518 + context: + - beha_def + operations: + pre: [ablk, pblk, bblk, name] + post: [] + description: |+ + Define an interleavestep object from a block pblk containing its + parameters, bblk containing its behaviour and a name, attach + the attributes from block ablk, and then attach it to the + module object owning the current block. + isbound: opcode: 429 context: From 59040ba7a5d1d905a5ed6819575feee2e01158e8 Mon Sep 17 00:00:00 2001 From: Uwe Truetsch Date: Fri, 27 Sep 2024 18:09:51 +0300 Subject: [PATCH 4/4] re-aranged opcodes --- k3/t3xf/opcode/opcode_gen.go | 18 +++++++++--------- k3/t3xf/opcode/opcodes.yml | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/k3/t3xf/opcode/opcode_gen.go b/k3/t3xf/opcode/opcode_gen.go index 5de0054b..b970d15c 100644 --- a/k3/t3xf/opcode/opcode_gen.go +++ b/k3/t3xf/opcode/opcode_gen.go @@ -1,5 +1,5 @@ // Code generated from opcode.tmpl.go and by 'go generate'; DO NOT EDIT. -// This file was generated by robots at 2024-09-27 16:09:13.179602483 +0300 EEST m=+0.584646302 +// This file was generated by robots at 2024-09-27 17:55:42.208292873 +0300 EEST m=+0.588710008 // Package opcode defines the opcodes used in T3XF. package opcode @@ -489,7 +489,7 @@ const ( // // [enc decTemplate] DECMATCH [res] // - DECMATCH Opcode = 0x1ff3 + DECMATCH Opcode = 0x2033 // Decode encoded bitstring enc placing the result in dec and // returning integer res holding the outcome of the operation: 0 @@ -1099,7 +1099,7 @@ const ( // // [pblk bblk name] INTERLEAVESTEP [] // - INTERLEAVESTEP Opcode = 0x2033 + INTERLEAVESTEP Opcode = 0x2043 // Define a bound interleavestep object from a component type comp, a // block pblk containing its parameters, bblk containing its @@ -1108,7 +1108,7 @@ const ( // // [comp pblk bblk name] INTERLEAVESTEPB [] // - INTERLEAVESTEPB Opcode = 0x2043 + INTERLEAVESTEPB Opcode = 0x2053 // Define a bound interleavestep object from a component type comp, a // block pblk containing its parameters, bblk containing its @@ -1118,7 +1118,7 @@ const ( // // [comp ablk pblk bblk name] INTERLEAVESTEPBW [] // - INTERLEAVESTEPBW Opcode = 0x2053 + INTERLEAVESTEPBW Opcode = 0x2073 // Define an interleavestep object from a block pblk containing its // parameters, bblk containing its behaviour and a name, attach @@ -3117,7 +3117,7 @@ var Descriptions = map[Opcode]*Descriptor{ }, DECMATCH: { - Opcode: 0x1ff3, + Opcode: 0x2033, Description: "The encoded value enc is decoded and the decoded content\nwill be matched against the provided decTemplate returning\na boolean value res on the stack\n\n", Context: []string{"value"}, Operations: Operation{ @@ -3897,7 +3897,7 @@ var Descriptions = map[Opcode]*Descriptor{ }, INTERLEAVESTEP: { - Opcode: 0x2033, + Opcode: 0x2043, Description: "Define an interleavestep object from a block pblk containing its\nparameters, bblk containing its behaviour and a name, and then\nattach it to the module object owning the current block.\n\n", Context: []string{"beha_def"}, Operations: Operation{ @@ -3907,7 +3907,7 @@ var Descriptions = map[Opcode]*Descriptor{ }, INTERLEAVESTEPB: { - Opcode: 0x2043, + Opcode: 0x2053, Description: "Define a bound interleavestep object from a component type comp, a\nblock pblk containing its parameters, bblk containing its\nbehaviour and a name, then attach it to the module object\nowning the current block.\n\n", Context: []string{"beha_def"}, Operations: Operation{ @@ -3917,7 +3917,7 @@ var Descriptions = map[Opcode]*Descriptor{ }, INTERLEAVESTEPBW: { - Opcode: 0x2053, + Opcode: 0x2073, Description: "Define a bound interleavestep object from a component type comp, a\nblock pblk containing its parameters, bblk containing its\nbehaviour and a name, attach the attributes from block ablk,\nand then attach it to the module object owning the current\nblock.\n\n", Context: []string{"beha_def"}, Operations: Operation{ diff --git a/k3/t3xf/opcode/opcodes.yml b/k3/t3xf/opcode/opcodes.yml index d5f82d44..b0b16f3f 100644 --- a/k3/t3xf/opcode/opcodes.yml +++ b/k3/t3xf/opcode/opcodes.yml @@ -707,7 +707,7 @@ deactivatea: Deactivate all altsteps activated on the current component. decmatch: - opcode: 511 + opcode: 515 context: - value operations: @@ -1634,7 +1634,7 @@ interleave: of alternatives to complete. interleavestep: - opcode: 515 + opcode: 516 context: - beha_def operations: @@ -1646,7 +1646,7 @@ interleavestep: attach it to the module object owning the current block. interleavestepb: - opcode: 516 + opcode: 517 context: - beha_def operations: @@ -1659,7 +1659,7 @@ interleavestepb: owning the current block. interleavestepbw: - opcode: 517 + opcode: 519 context: - beha_def operations: