-
Notifications
You must be signed in to change notification settings - Fork 33
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
Value literal inference #699
Conversation
ttcn3/types/types.go
Outdated
kind := kindConvert[n.Tok.Kind()] | ||
switch kind { | ||
case Integer, Float, Boolean: | ||
return Predefined[kind.String()] | ||
case Verdict: | ||
return Predefined["verdicttype"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without conversion table the code almost looks the same:
kind := kindConvert[n.Tok.Kind()] | |
switch kind { | |
case Integer, Float, Boolean: | |
return Predefined[kind.String()] | |
case Verdict: | |
return Predefined["verdicttype"] | |
switch n.Tok.Kind() { | |
case syntax.INT: | |
return Predefined["integer"] | |
case syntax.FLOAT: | |
return Predefined["float"] | |
case syntax.TRUE, syntax.FALSE: | |
return Predefined["boolean"] |
I would go with that.
ttcn3/types/types.go
Outdated
if strings.IndexFunc(n.Tok.String(), func(r rune) bool { | ||
return r <= 32 || r >= 126 | ||
}) > -1 { | ||
return Predefined["universal charstring"] | ||
} else { | ||
return Predefined["charstring"] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the flow hard to follow. What about:
if strings.IndexFunc(n.Tok.String(), func(r rune) bool { | |
return r <= 32 || r >= 126 | |
}) > -1 { | |
return Predefined["universal charstring"] | |
} else { | |
return Predefined["charstring"] | |
} | |
for _, r := range n.Tok.String() { | |
if r < 32 || 126 < r { | |
return Predefined["universal charstring"] | |
} | |
} | |
return Predefined["charstring"] |
ttcn3/types/types.go
Outdated
if strings.Contains(n.Tok.String(), "H") { | ||
return Predefined["hexstring"] | ||
} else if strings.Contains(n.Tok.String(), "O") { | ||
return Predefined["octetstring"] | ||
} | ||
return Predefined["bitstring"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking the whole string for H or B is too much, also I don't think bitstring
is the best default. I would use nil as default until we know better. How about something like:
if strings.Contains(n.Tok.String(), "H") { | |
return Predefined["hexstring"] | |
} else if strings.Contains(n.Tok.String(), "O") { | |
return Predefined["octetstring"] | |
} | |
return Predefined["bitstring"] | |
s := n.Tok.String() | |
if len(s) == 0 { | |
return nil | |
} | |
switch s[len(s)-1] { | |
case 'H', 'h': | |
return Predefined["hexstring"] | |
case 'O','o': | |
return Predefined["octetstring"] | |
case 'B','b': | |
return Predefined["bitstring"] | |
} | |
return nil |
No description provided.