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

Value literal inference #699

Merged
merged 6 commits into from
Aug 1, 2023
Merged

Conversation

nnnnblaser
Copy link
Contributor

No description provided.

Comment on lines 427 to 432
kind := kindConvert[n.Tok.Kind()]
switch kind {
case Integer, Float, Boolean:
return Predefined[kind.String()]
case Verdict:
return Predefined["verdicttype"]
Copy link
Member

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:

Suggested change
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.

Comment on lines 416 to 422
if strings.IndexFunc(n.Tok.String(), func(r rune) bool {
return r <= 32 || r >= 126
}) > -1 {
return Predefined["universal charstring"]
} else {
return Predefined["charstring"]
}
Copy link
Member

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:

Suggested change
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"]

Comment on lines 424 to 429
if strings.Contains(n.Tok.String(), "H") {
return Predefined["hexstring"]
} else if strings.Contains(n.Tok.String(), "O") {
return Predefined["octetstring"]
}
return Predefined["bitstring"]
Copy link
Member

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:

Suggested change
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

@5nord 5nord merged commit 223d9f4 into nokia:master Aug 1, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants