-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Support untyped enum declaration #902
Conversation
982fb8b
to
369d3f7
Compare
} else { | ||
// TODO: | ||
// report error | ||
unreachable!(); |
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.
Generally unreachable!
is used for "this statement is unreachable logically".
If reporting error is required in the future, todo!("report error");
is better.
@@ -626,6 +662,8 @@ impl<'a> VerylGrammarTrait for CreateSymbolTable<'a> { | |||
if let Some(namespace) = namespace { | |||
self.namespace.push(namespace); | |||
} | |||
|
|||
self.enum_member_value = Some(value.clone()); |
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.
clone
is not required because value
is not used after this statement.
crates/analyzer/src/symbol.rs
Outdated
@@ -458,12 +458,16 @@ impl fmt::Display for SymbolKind { | |||
format!("typedef alias ({})", x.r#type) | |||
} | |||
SymbolKind::Enum(x) => { | |||
format!("enum ({})", x.r#type) | |||
if x.r#type.is_some() { |
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.
Using if let Some
is more idiomatic.
if let Some(ref x) = x.r#type {
format!("enum ({})", x)
} else {
crates/emitter/src/emitter.rs
Outdated
|
||
fn default_enum_type(&mut self, arg: &EnumDeclaration) { | ||
let enum_symbol = symbol_table::resolve(arg.identifier.as_ref()) | ||
.unwrap() |
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.
This unwrap
may be troublesome.
If there is any error around symbol table, this resolve may be failed.
So Veryl compiler may panic before reporting these errors.
crates/emitter/src/emitter.rs
Outdated
if let SymbolKind::EnumMember(member) = member_symbol.kind { | ||
match member.value { | ||
EnumMemberValue::ExplicitValue(_expression, evaluated) => { | ||
if evaluated.is_some() && evaluated.unwrap() > max_value { |
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.
Could you use if let Some
?
369d3f7
to
e61e5ef
Compare
I fixed all review feedbacks. |
e61e5ef
to
10136e9
Compare
Looks good. |
resolve #539