Update skeleton

This commit is contained in:
Jeehoon Kang
2020-04-20 16:19:44 +09:00
parent 72ec63ea82
commit 5b45cf1fd8
5 changed files with 34 additions and 5 deletions

View File

@@ -88,11 +88,20 @@ impl IsEquiv for Initializer {
fn is_equiv(&self, other: &Self) -> bool {
match (self, other) {
(Self::Expression(expr), Self::Expression(other_expr)) => expr.is_equiv(other_expr),
(Self::List(items), Self::List(other_items)) => items.is_equiv(other_items),
_ => false,
}
}
}
impl IsEquiv for InitializerListItem {
fn is_equiv(&self, other: &Self) -> bool {
self.designation.is_empty()
&& other.designation.is_empty()
&& self.initializer.is_equiv(&other.initializer)
}
}
impl IsEquiv for Declarator {
fn is_equiv(&self, other: &Self) -> bool {
self.kind.is_equiv(&other.kind) && self.derived.is_equiv(&other.derived)

View File

@@ -208,11 +208,18 @@ impl AssertSupported for Initializer {
fn assert_supported(&self) {
match self {
Self::Expression(expr) => expr.assert_supported(),
Self::List(_) => panic!("Initializer::List"),
Self::List(items) => items.assert_supported(),
}
}
}
impl AssertSupported for InitializerListItem {
fn assert_supported(&self) {
assert!(self.designation.is_empty());
self.initializer.assert_supported();
}
}
impl AssertSupported for Declarator {
fn assert_supported(&self) {
self.kind.assert_supported();

View File

@@ -611,10 +611,9 @@ impl TryFrom<&ast::Initializer> for Constant {
type Error = ();
fn try_from(initializer: &ast::Initializer) -> Result<Self, Self::Error> {
if let ast::Initializer::Expression(expr) = &initializer {
Self::try_from(&expr.node)
} else {
Err(())
match initializer {
ast::Initializer::Expression(expr) => Self::try_from(&expr.node),
ast::Initializer::List(_) => todo!(),
}
}
}