Skip to content

Commit

Permalink
Merge pull request #31 from v0-e/chore-update-compiler
Browse files Browse the repository at this point in the history
chore: Update codegen-rust's compiler
  • Loading branch information
jpbusch authored Aug 1, 2024
2 parents 62e54d0 + 783b79b commit cd8eb40
Show file tree
Hide file tree
Showing 12 changed files with 2,091 additions and 2,044 deletions.
5 changes: 2 additions & 3 deletions utils/codegen/codegen-rust/rgen/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion utils/codegen/codegen-rust/rgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ name = "asn1-to-ros-conversion-headers"
path = "src/conversion/bin.rs"

[dependencies]
rasn-compiler = "0.1.4"
rasn-compiler = { git = "https://github.com/librasn/compiler.git", rev = "ef06d5f827768726efe6a32da9e1ea1329fc4f7a" }
regex = "1.10.4"
clap = { version = "4.5.4", features = ["derive"] }
22 changes: 21 additions & 1 deletion utils/codegen/codegen-rust/rgen/src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rasn_compiler::prelude::ir::IntegerType;
use rasn_compiler::prelude::ir::{IntegerType, ASN1Value};

pub trait IntegerTypeExt {
fn to_str(self) -> &'static str;
Expand All @@ -19,6 +19,26 @@ impl IntegerTypeExt for IntegerType {
}
}
}

pub trait ASN1ValueExt {
fn is_const_type(&self) -> bool;
}

impl ASN1ValueExt for ASN1Value {
fn is_const_type(&self) -> bool {
match self {
ASN1Value::Null | ASN1Value::Boolean(_) | ASN1Value::EnumeratedValue { .. } => true,
ASN1Value::Choice { inner_value, .. } => inner_value.is_const_type(),
ASN1Value::LinkedIntValue { integer_type, .. } => {
integer_type != &IntegerType::Unbounded
}
ASN1Value::LinkedNestedValue { value, .. } => value.is_const_type(),
ASN1Value::LinkedElsewhereDefinedValue { can_be_const, .. } => *can_be_const,
_ => false,
}
}
}

pub fn to_ros_snake_case(input: &str) -> String {
let input = input.replace('-', "_");
let mut lowercase = String::with_capacity(input.len());
Expand Down
9 changes: 6 additions & 3 deletions utils/codegen/codegen-rust/rgen/src/conversion/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clap::Parser;
use regex::Regex;

use rasn_compiler::prelude::*;
use ros_backend::conversion::Conversion;
use ros_backend::conversion::{Conversion, ConversionOptions};

#[derive(Parser, Debug)]
struct Cli {
Expand All @@ -19,10 +19,13 @@ struct Cli {
fn main() {
let args = Cli::parse();

let backend = Conversion::default().set_main_pdu_name(&args.pdu.clone());
let config = ConversionOptions {
main_pdu: args.pdu,
};
let backend = Conversion::from_config(config);

// Compile conversion headers
let compiler_res = Compiler::new()
let compiler_res = Compiler::<Conversion, _>::new()
.with_backend(backend)
.add_asn_sources_by_path(args.paths.iter())
.compile_to_string();
Expand Down
Loading

0 comments on commit cd8eb40

Please sign in to comment.