Skip to content

Commit

Permalink
refactor(header): unpack GlobalModuleReference in header
Browse files Browse the repository at this point in the history
  • Loading branch information
6d7a committed Mar 22, 2024
1 parent 1a5d9f9 commit 04df8f4
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 100 deletions.
2 changes: 1 addition & 1 deletion rasn-compiler-tests/tests/structured_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ e2e_pdu!(
fn personnel_record_children_default () -> SequenceOf<VisibleString> {
alloc::vec![]
} "#
);
);
2 changes: 1 addition & 1 deletion rasn-compiler/src/generator/rasn/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Backend for Rust {
if let Some((module_ref, _)) = tlds.first().and_then(|tld| tld.get_index().cloned()) {
let name = to_rust_snake_case(&module_ref.name);
let imports = module_ref.imports.iter().map(|import| {
let module = to_rust_snake_case(&import.origin_name);
let module = to_rust_snake_case(&import.global_module_reference.module_reference);
let mut usages = Some(vec![]);
'imports: for usage in &import.types {
if usage.contains("{}") || usage.chars().all(|c| c.is_uppercase() || c == '-') {
Expand Down
10 changes: 8 additions & 2 deletions rasn-compiler/src/generator/rasn/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,14 @@ pub fn type_to_tokens(ty: &ASN1Type) -> Result<TokenStream, GeneratorError> {
"Set values are currently unsupported!"
)),
ASN1Type::ElsewhereDeclaredType(e) => Ok(to_rust_title_case(&e.identifier)),
ASN1Type::InformationObjectFieldReference(_) => todo!(),
ASN1Type::Time(_) => todo!(),
ASN1Type::InformationObjectFieldReference(_) => Err(error!(
NotYetInplemented,
"Information Object field reference values are currently unsupported!"
)),
ASN1Type::Time(_) => Err(error!(
NotYetInplemented,
"Time values are currently unsupported!"
)),
ASN1Type::GeneralizedTime(_) => Ok(quote!(GeneralizedTime)),
ASN1Type::UTCTime(_) => Ok(quote!(UtcTime)),
ASN1Type::EmbeddedPdv | ASN1Type::External => Ok(quote!(Any)),
Expand Down
61 changes: 44 additions & 17 deletions rasn-compiler/src/intermediate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,33 +272,60 @@ pub enum With {
Descendants,
}

/// Represents a global module reference as specified in
/// Rec. ITU-T X.680 (02/2021)
#[derive(Debug, Clone, PartialEq)]
pub struct ExternalValueReference {
pub module_reference: String,
pub value_reference: String,
}

/// Represents a global module reference as specified in
/// Rec. ITU-T X.680 (02/2021)
#[derive(Debug, Clone, PartialEq)]
pub struct GlobalModuleReference {
pub module_reference: String,
pub assigned_identifier: AssignedIdentifier,
}

impl From<(&str, AssignedIdentifier)> for GlobalModuleReference {
fn from(value: (&str, AssignedIdentifier)) -> Self {
Self {
module_reference: value.0.to_owned(),
assigned_identifier: value.1,
}
}
}

/// Represents an assigned identifier as specified in
/// Rec. ITU-T X.680 (02/2021)
#[derive(Debug, Clone, PartialEq)]
pub enum AssignedIdentifier {
ObjectIdentifierValue(ObjectIdentifierValue),
ExternalValueReference(ExternalValueReference),
ValueReference(String),
ParameterizedValue {
value_reference: String,
actual_parameter_list: String,
},
Empty,
}

/// Represents a module import as specified in
/// Rec. ITU-T X.680 (02/2021) § 13.16
#[derive(Debug, Clone, PartialEq)]
pub struct Import {
pub types: Vec<String>,
pub origin_name: String,
pub origin_identifier: Option<ObjectIdentifierValue>,
pub global_module_reference: GlobalModuleReference,
pub with: Option<With>,
}

impl
From<(
Vec<&str>,
(&str, Option<ObjectIdentifierValue>, Option<&str>),
)> for Import
{
fn from(
value: (
Vec<&str>,
(&str, Option<ObjectIdentifierValue>, Option<&str>),
),
) -> Self {
impl From<(Vec<&str>, (GlobalModuleReference, Option<&str>))> for Import {
fn from(value: (Vec<&str>, (GlobalModuleReference, Option<&str>))) -> Self {
Self {
types: value.0.into_iter().map(String::from).collect(),
origin_name: value.1 .0.into(),
origin_identifier: value.1 .1,
with: value.1 .2.map(|with| {
global_module_reference: value.1 .0,
with: value.1 .1.map(|with| {
if with == WITH_SUCCESSORS {
With::Successors
} else {
Expand Down
Loading

0 comments on commit 04df8f4

Please sign in to comment.