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

Commit 76ecc0bb authored by Martin Geisler's avatar Martin Geisler Committed by David Duarte
Browse files

pdl: Update code for Heck 0.3.3

This is for integration with UWB.

Tag: #feature
Bug: 228306436
Test: atest pdl_tests pdl_rust_generator_tests_{le,be}
Change-Id: Ieecf603e4ab71b593d5df40852ccba1c10ab39fa
Merged-In: Ia531f3d90859407a8b10ce55493d244defe4de1e
parent cb605d12
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ rust_defaults {
        "libsyn",
        "libtempfile",
    ],
    cfgs: ["tm_mainline_prod"],
    proc_macros: [
        "libpest_derive",
    ],
+23 −1
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@
#![allow(clippy::format_push_string)]

use crate::{ast, lint};
use heck::ToUpperCamelCase;
use quote::{format_ident, quote};
use std::collections::BTreeSet;
use std::path::Path;
@@ -26,6 +25,29 @@ use declarations::FieldDeclarations;
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
+1 −2
Original line number Diff line number Diff line
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::parser::ast as parser_ast;
use crate::{ast, lint};
use heck::ToUpperCamelCase;
use quote::{format_ident, quote};
use std::collections::{BTreeSet, HashMap};

+1 −2
Original line number Diff line number Diff line
use crate::backends::rust::{mask_bits, types};
use crate::backends::rust::{mask_bits, types, ToUpperCamelCase};
use crate::parser::ast as parser_ast;
use crate::{ast, lint};
use heck::ToUpperCamelCase;
use quote::{format_ident, quote};

/// A single bit-field value.