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

Commit 68768066 authored by Martin Geisler's avatar Martin Geisler Committed by Henri Chataing
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: I80d0845d03f91988dbad9b3612cf1203e5460c6d
parent e3c6b277
Loading
Loading
Loading
Loading
+23 −1
Original line number Original line Diff line number Diff line
//! Rust compiler backend.
//! Rust compiler backend.


use crate::{ast, lint};
use crate::{ast, lint};
use heck::ToUpperCamelCase;
use quote::{format_ident, quote};
use quote::{format_ident, quote};
use std::collections::BTreeSet;
use std::collections::BTreeSet;
use std::path::Path;
use std::path::Path;
@@ -16,6 +15,29 @@ mod types;
use parser::FieldParser;
use parser::FieldParser;
use serializer::FieldSerializer;
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.
/// Generate a block of code.
///
///
/// Like `quote!`, but the code block will be followed by an empty
/// Like `quote!`, but the code block will be followed by an empty
+1 −2
Original line number Original line Diff line number Diff line
use crate::analyzer::ast as analyzer_ast;
use crate::analyzer::ast as analyzer_ast;
use crate::backends::rust::{
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 crate::{ast, lint};
use heck::ToUpperCamelCase;
use quote::{format_ident, quote};
use quote::{format_ident, quote};
use std::collections::{BTreeSet, HashMap};
use std::collections::{BTreeSet, HashMap};


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


/// A single bit-field value.
/// A single bit-field value.