Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d13df434 authored by Henri Chataing's avatar Henri Chataing Committed by Automerger Merge Worker
Browse files

Merge changes Ib242d348,Ie56d7658,I80d0845d am: 73787c94

parents 42e79b85 73787c94
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ rust_defaults {
    name: "pdl_defaults",
    // LINT.IfChange
    rustlibs: [
        "libclap",
        "libclap_3.2.23",
        "libcodespan_reporting",
        "libheck",
        "libpest",
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ pest_derive = "2.4.0"
proc-macro2 = "1.0.46"
quote = "1.0.21"
serde_json = "1.0.86"
clap = { version = "3.2.22", features = ["derive"] }
clap = "3.2.23"
syn = "1.0.102"

[dependencies.serde]
+9 −2
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@ pub mod ast {
    use serde::Serialize;

    /// Field and declaration size information.
    #[derive(Default, Debug, Clone, Copy)]
    #[derive(Debug, Clone, Copy)]
    #[allow(unused)]
    pub enum Size {
        /// Constant size in bits.
@@ -22,10 +22,17 @@ pub mod ast {
        Dynamic,
        /// The size cannot be determined statically or at runtime.
        /// The packet assumes the largest possible size.
        #[default]
        Unknown,
    }

    // TODO: use derive(Default) when UWB is using Rust 1.62.0.
    #[allow(clippy::derivable_impls)]
    impl Default for Size {
        fn default() -> Size {
            Size::Unknown
        }
    }

    #[derive(Debug, Serialize, Default, Clone, PartialEq)]
    pub struct Annotation;

+24 −2
Original line number Diff line number Diff line
//! Rust compiler backend.

use crate::{ast, lint};
use heck::ToUpperCamelCase;
use quote::{format_ident, quote};
use std::collections::BTreeSet;
use std::path::Path;
@@ -16,6 +15,29 @@ mod types;
use parser::FieldParser;
use serializer::FieldSerializer;

#[cfg(not(tm_mainline_prod))]
pub use heck::ToUpperCamelCase;

#[cfg(tm_mainline_prod)]
pub trait ToUpperCamelCase {
    fn to_upper_camel_case(&self) -> String;
}

#[cfg(tm_mainline_prod)]
impl ToUpperCamelCase for str {
    fn to_upper_camel_case(&self) -> String {
        use heck::CamelCase;
        let camel_case = self.to_camel_case();
        if camel_case.is_empty() {
            camel_case
        } else {
            // PDL identifiers are a-zA-z0-9, so we're dealing with
            // simple ASCII text.
            format!("{}{}", &camel_case[..1].to_ascii_uppercase(), &camel_case[1..])
        }
    }
}

/// Generate a block of code.
///
/// Like `quote!`, but the code block will be followed by an empty
@@ -404,7 +426,7 @@ fn generate_packet_decl(
        let named_fields = {
            let mut names =
                parent_packet_scope.iter_fields().filter_map(ast::Field::id).collect::<Vec<_>>();
            names.sort();
            names.sort_unstable();
            names
        };

+5 −5
Original line number Diff line number Diff line
use crate::analyzer::ast as analyzer_ast;
use crate::backends::rust::{
    constraint_to_value, find_constrained_parent_fields, mask_bits, types,
    constraint_to_value, find_constrained_parent_fields, mask_bits, types, ToUpperCamelCase,
};
use crate::{ast, lint};
use heck::ToUpperCamelCase;
use quote::{format_ident, quote};
use std::collections::{BTreeSet, HashMap};

@@ -319,15 +318,16 @@ impl<'a> FieldParser<'a> {
                    }
                });
            }
            (ElementWidth::Unknown, ArrayShape::Static(_)) => {
            (ElementWidth::Unknown, ArrayShape::Static(count)) => {
                // The element width is not known, but the array
                // element count is known statically. Parse elements
                // item by item as an array.
                let count = syn::Index::from(*count);
                self.code.push(quote! {
                    // TODO(mgeisler): use
                    // https://doc.rust-lang.org/std/array/fn.try_from_fn.html
                    // when stabilized.
                    let #id = std::array::from_fn(|_| #parse_element.unwrap());
                    let #id = [0; #count].map(|_| #parse_element.unwrap());
                });
            }
            (ElementWidth::Unknown, ArrayShape::CountField(count_field)) => {
@@ -366,7 +366,7 @@ impl<'a> FieldParser<'a> {
                    // TODO(mgeisler): use
                    // https://doc.rust-lang.org/std/array/fn.try_from_fn.html
                    // when stabilized.
                    let #id = std::array::from_fn(|_| #parse_element.unwrap());
                    let #id = [0; #count].map(|_| #parse_element.unwrap());
                });
            }
            (ElementWidth::Static(_), ArrayShape::CountField(count_field)) => {
Loading