1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
// Copyright 2020 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /// Central registry of all information known about types. /// At present this is very minimal; in future we should roll /// known_types.rs into this and possibly other things as well. #[derive(Default, Hash)] pub struct TypeConfig { pod_requests: Vec<String>, allowlist: Vec<String>, // not TypeName as it may be funcs not types. blocklist: Vec<String>, // not TypeName as it may be funcs not types. } impl TypeConfig { pub fn new() -> Self { Self::default() } pub(crate) fn note_pod_request(&mut self, tn: String) { self.pod_requests.push(tn); } pub(crate) fn add_to_allowlist(&mut self, item: String) { self.allowlist.push(item); } pub(crate) fn add_to_blocklist(&mut self, item: String) { self.blocklist.push(item); } pub fn get_pod_requests(&self) -> &[String] { &self.pod_requests } pub fn allowlist(&self) -> impl Iterator<Item = &String> { self.allowlist.iter() } pub fn allowlist_is_empty(&self) -> bool { self.allowlist.is_empty() } /// Whether this type is on the allowlist specified by the user. /// /// A note on the allowlist handling in general. It's used in two places: /// 1) As directives to bindgen /// 2) After bindgen has generated code, to filter the APIs which /// we pass to cxx. /// This second pass may seem redundant. But sometimes bindgen generates /// unnecessary stuff. pub fn is_on_allowlist(&self, cpp_name: &str) -> bool { self.allowlist.contains(&cpp_name.to_string()) } pub fn is_on_blocklist(&self, cpp_name: &str) -> bool { self.blocklist.contains(&cpp_name.to_string()) } pub fn get_blocklist(&self) -> impl Iterator<Item = &String> { self.blocklist.iter() } }