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

fix: error parsing single subtype constraint #69

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion rasn-compiler-tests/tests/structured_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ e2e_pdu!(
"#
);


e2e_pdu!(
multiple_named_bits_default,
r#"
Expand Down
4 changes: 2 additions & 2 deletions rasn-compiler/src/intermediate/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ pub enum SubtypeElement {
PermittedAlphabet(Box<ElementOrSetOperation>),
SizeConstraint(Box<ElementOrSetOperation>),
TypeConstraint(ASN1Type),
SingleTypeConstraint(InnerTypeConstraint),
SingleTypeConstraint(Vec<Constraint>),
MultipleTypeConstraints(InnerTypeConstraint),
PatternConstraint(PatternConstraint),
UserDefinedConstraint(UserDefinedConstraint),
Expand Down Expand Up @@ -766,7 +766,7 @@ impl
Vec<(&str, Option<Vec<Constraint>>, Option<ComponentPresence>)>,
),
) -> Self {
SubtypeElement::SingleTypeConstraint(InnerTypeConstraint {
SubtypeElement::MultipleTypeConstraints(InnerTypeConstraint {
is_partial: value.0.is_some(),
constraints: value
.1
Expand Down
241 changes: 155 additions & 86 deletions rasn-compiler/src/lexer/constraint.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion rasn-compiler/src/lexer/real.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ mod tests {
.1,
ASN1Type::Real(Real {
constraints: vec![Constraint::SubtypeConstraint(ElementSet {
set: ElementOrSetOperation::Element(SubtypeElement::SingleTypeConstraint(
set: ElementOrSetOperation::Element(SubtypeElement::MultipleTypeConstraints(
InnerTypeConstraint {
is_partial: false,
constraints: vec![
Expand Down
2 changes: 1 addition & 1 deletion rasn-compiler/src/lexer/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ is_recursive: false,
name: "clusterBoundingBoxShape".into(),
tag: None,
ty: ASN1Type::ElsewhereDeclaredType(DeclarationElsewhere { parent: None,
identifier: "Shape".into(), constraints: vec![Constraint::SubtypeConstraint(ElementSet { set: ElementOrSetOperation::Element(SubtypeElement::SingleTypeConstraint(InnerTypeConstraint { is_partial: true, constraints: vec![ConstrainedComponent { identifier: "elliptical".into(), constraints: vec![], presence: ComponentPresence::Absent },ConstrainedComponent { identifier: "radial".into(), constraints: vec![], presence: ComponentPresence::Absent },ConstrainedComponent { identifier: "radialShapes".into(), constraints: vec![], presence: ComponentPresence::Absent }] })), extensible: false })
identifier: "Shape".into(), constraints: vec![Constraint::SubtypeConstraint(ElementSet { set: ElementOrSetOperation::Element(SubtypeElement::MultipleTypeConstraints(InnerTypeConstraint { is_partial: true, constraints: vec![ConstrainedComponent { identifier: "elliptical".into(), constraints: vec![], presence: ComponentPresence::Absent },ConstrainedComponent { identifier: "radial".into(), constraints: vec![], presence: ComponentPresence::Absent },ConstrainedComponent { identifier: "radialShapes".into(), constraints: vec![], presence: ComponentPresence::Absent }] })), extensible: false })
]}),
default_value: None,
is_optional: true,
Expand Down
48 changes: 32 additions & 16 deletions rasn-compiler/src/lexer/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,24 +175,40 @@ fn parses_toplevel_crossrefering_declaration() {
identifier: "EventHistory".into(),
constraints: vec![Constraint::SubtypeConstraint(ElementSet {
set: ElementOrSetOperation::SetOperation(SetOperation {
base: SubtypeElement::MultipleTypeConstraints(InnerTypeConstraint {
is_partial: true,
constraints: vec![ConstrainedComponent {
identifier: "eventDeltaTime".into(),
constraints: vec![],
presence: ComponentPresence::Present
}]
}),
base: SubtypeElement::SingleTypeConstraint(vec![
Constraint::SubtypeConstraint(ElementSet {
extensible: false,
set: ElementOrSetOperation::Element(
SubtypeElement::MultipleTypeConstraints(InnerTypeConstraint {
is_partial: true,
constraints: vec![ConstrainedComponent {
identifier: "eventDeltaTime".into(),
constraints: vec![],
presence: ComponentPresence::Present
}]
})
)
})
]),
operator: SetOperator::Union,
operant: Box::new(ElementOrSetOperation::Element(
SubtypeElement::MultipleTypeConstraints(InnerTypeConstraint {
is_partial: true,
constraints: vec![ConstrainedComponent {
identifier: "eventDeltaTime".into(),
constraints: vec![],
presence: ComponentPresence::Absent
}]
})
SubtypeElement::SingleTypeConstraint(vec![
Constraint::SubtypeConstraint(ElementSet {
extensible: false,
set: ElementOrSetOperation::Element(
SubtypeElement::MultipleTypeConstraints(
InnerTypeConstraint {
is_partial: true,
constraints: vec![ConstrainedComponent {
identifier: "eventDeltaTime".into(),
constraints: vec![],
presence: ComponentPresence::Absent
}]
}
)
)
})
])
))
}),
extensible: false
Expand Down
14 changes: 10 additions & 4 deletions rasn-compiler/src/validator/linking/constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ impl SubtypeElement {
SubtypeElement::TypeConstraint(t) => {
t.link_constraint_reference(identifier, tlds)?;
}
SubtypeElement::SingleTypeConstraint(s)
| SubtypeElement::MultipleTypeConstraints(s) => {
SubtypeElement::SingleTypeConstraint(constraints) => {
for c in constraints {
c.link_cross_reference(identifier, tlds)?;
}
}
SubtypeElement::MultipleTypeConstraints(s) => {
for b in s.constraints.iter_mut().flat_map(|cc| &mut cc.constraints) {
b.link_cross_reference(identifier, tlds)?;
}
Expand Down Expand Up @@ -98,8 +102,10 @@ impl SubtypeElement {
}
SubtypeElement::SizeConstraint(s) => s.has_cross_reference(),
SubtypeElement::TypeConstraint(t) => t.references_class_by_name(),
SubtypeElement::MultipleTypeConstraints(s)
| SubtypeElement::SingleTypeConstraint(s) => s
SubtypeElement::SingleTypeConstraint(c) => {
c.iter().any(|constraint| constraint.has_cross_reference())
}
SubtypeElement::MultipleTypeConstraints(s) => s
.constraints
.iter()
.any(|cc| cc.constraints.iter().any(|c| c.has_cross_reference())),
Expand Down
32 changes: 22 additions & 10 deletions rasn-compiler/src/validator/linking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,11 +1045,17 @@ impl ASN1Value {
ASN1Value::SequenceOrSet(o),
) => {
*self = ASN1Value::BitStringNamedBits(
o.iter().filter_map(|(_, v)| match &**v {
ASN1Value::ElsewhereDeclaredValue { identifier, .. } => Some(identifier.clone()),
ASN1Value::EnumeratedValue { enumerable, .. } => Some(enumerable.clone()),
_ => None
}).collect()
o.iter()
.filter_map(|(_, v)| match &**v {
ASN1Value::ElsewhereDeclaredValue { identifier, .. } => {
Some(identifier.clone())
}
ASN1Value::EnumeratedValue { enumerable, .. } => {
Some(enumerable.clone())
}
_ => None,
})
.collect(),
);
self.link_with_type(tlds, ty, type_name)
}
Expand All @@ -1062,11 +1068,17 @@ impl ASN1Value {
) if matches![**value, ASN1Value::SequenceOrSet(_)] => {
if let ASN1Value::SequenceOrSet(o) = &**value {
*value = Box::new(ASN1Value::BitStringNamedBits(
o.iter().filter_map(|(_, v)| match &**v {
ASN1Value::ElsewhereDeclaredValue { identifier, .. } => Some(identifier.clone()),
ASN1Value::EnumeratedValue { enumerable, .. } => Some(enumerable.clone()),
_ => None
}).collect()
o.iter()
.filter_map(|(_, v)| match &**v {
ASN1Value::ElsewhereDeclaredValue { identifier, .. } => {
Some(identifier.clone())
}
ASN1Value::EnumeratedValue { enumerable, .. } => {
Some(enumerable.clone())
}
_ => None,
})
.collect(),
));
self.link_with_type(tlds, ty, type_name)?;
}
Expand Down
Loading