Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Type names #697

Merged
merged 2 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion ttcn3/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func (k Kind) String() string {
// A Type represents a TTCN-3 type.
type Type interface {
String() string
string() string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to put this in Type interface.
Also I'd choose a different name. For example "describe"

}

// A PrimitiveType represents a non-composite type, such as integer, boolean,
Expand All @@ -146,6 +147,13 @@ type PrimitiveType struct {
}

func (t *PrimitiveType) String() string {
if t.Name != "" && t.Name != t.Kind.String() {
return t.Name + " [" + t.string() + "]"
}
return t.string()
}

func (t *PrimitiveType) string() string {
if t.ValueConstraints == nil {
return t.Kind.String()
}
Expand Down Expand Up @@ -179,9 +187,16 @@ type ListType struct {
}

func (t *ListType) String() string {
if t.Name != "" && t.Name != t.Kind.String() {
return t.Name + " [" + t.string() + "]"
}
return t.string()
}

func (t *ListType) string() string {
elem := "any"
if t.ElementType != nil && !isString(t.Kind) {
elem = t.ElementType.String()
elem = t.ElementType.string()
}
switch t.Kind {
case RecordOf, Any:
Expand Down Expand Up @@ -242,6 +257,10 @@ func (t *StructuredType) String() string {
return ""
}

func (t *StructuredType) string() string {
return t.String()
}

// A Field represents a fields in structures types.
type Field struct {
Type
Expand Down Expand Up @@ -270,6 +289,10 @@ func (t *BehaviourType) String() string {
return ""
}

func (t *BehaviourType) string() string {
return t.String()
}

// A PairType represents a pair. Pairs are not specified by TTCN-3 standard explicitly. It is for modeling map types as
// a set of key-value-pairs.
type PairType struct {
Expand All @@ -288,6 +311,10 @@ func (t *PairType) String() string {
return strings.Join(res, " to ")
}

func (t *PairType) string() string {
return t.String()
}

// A Value represents a single value constraint, such as '1' or '10..20'.
type Value struct {
syntax.Expr
Expand Down
10 changes: 5 additions & 5 deletions ttcn3/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func TestTypeStrings(t *testing.T) {
Kind: types.Array,
ElementType: &types.ListType{
Kind: types.SetOf,
ElementType: types.Float,
ElementType: types.Predefined["float"],
}},
},
},
Expand All @@ -247,13 +247,13 @@ func TestTypeStrings(t *testing.T) {

// Named types

{skip: true, Output: "foo [any]",
{Output: "foo [any]",
Type: &types.PrimitiveType{Name: "foo"}},

{skip: true, Output: "foo [record of any]",
{Output: "foo [record of any]",
Type: &types.ListType{Name: "foo"}},

{skip: true, Output: "foo [record of integer]",
{Output: "foo [record of integer]",
Type: &types.ListType{
Name: "foo",
ElementType: &types.PrimitiveType{
Expand All @@ -262,7 +262,7 @@ func TestTypeStrings(t *testing.T) {
},
}},

{skip: true, Output: "record of integer",
{Output: "record of integer",
Type: &types.ListType{
ElementType: &types.PrimitiveType{
Name: "foo",
Expand Down
Loading