aboutsummaryrefslogtreecommitdiffstats
path: root/components/style/build_gecko.rs
diff options
context:
space:
mode:
authorCameron McCormack <cam@mcc.id.au>2018-10-14 00:06:13 +0000
committerEmilio Cobos Álvarez <emilio@crisal.io>2018-10-19 00:36:59 +0200
commitd960db340c3a84a47538e41c6dc6eb604d02b616 (patch)
treef66236d86edc589959361179c324c907fb7f917b /components/style/build_gecko.rs
parent89e4d6c0492da4129e00df7078740a435afe08b5 (diff)
downloadservo-d960db340c3a84a47538e41c6dc6eb604d02b616.tar.gz
servo-d960db340c3a84a47538e41c6dc6eb604d02b616.zip
style: Part 11: Move Gecko borrowed FFI types to a separate header file.
Differential Revision: https://phabricator.services.mozilla.com/D8653
Diffstat (limited to 'components/style/build_gecko.rs')
-rw-r--r--components/style/build_gecko.rs36
1 files changed, 29 insertions, 7 deletions
diff --git a/components/style/build_gecko.rs b/components/style/build_gecko.rs
index a30a2a8aeb8..c8e886c4b29 100644
--- a/components/style/build_gecko.rs
+++ b/components/style/build_gecko.rs
@@ -300,7 +300,7 @@ mod bindings {
.expect("Unable to write output");
}
- fn get_types(filename: &str, macro_name: &str) -> Vec<String> {
+ fn get_types(filename: &str, macro_pat: &str) -> Vec<(String, String)> {
// Read the file
let path = DISTDIR_PATH.join("include/mozilla/").join(filename);
let mut list_file = File::open(path)
@@ -315,31 +315,46 @@ mod bindings {
let content = block_comment_re.replace_all(&content, "");
let content = line_comment_re.replace_all(&content, "");
// Extract the list
- let re_string = format!(r#"^{}\(\w+,\s*(\w+)\)$"#, macro_name);
+ let re_string = format!(r#"^({})\(.+,\s*(\w+)\)$"#, macro_pat);
let re = Regex::new(&re_string).unwrap();
content
.lines()
.map(|line| line.trim())
.filter(|line| !line.is_empty())
.map(|line| {
- re.captures(&line)
+ let captures = re.captures(&line)
.expect(&format!(
"Unrecognized line in {}: '{}'",
filename,
line
- )).get(1)
- .unwrap()
- .as_str()
- .to_string()
+ ));
+ let macro_name = captures.get(1).unwrap().as_str().to_string();
+ let type_name = captures.get(2).unwrap().as_str().to_string();
+ (macro_name, type_name)
}).collect()
}
+ fn get_borrowed_types() -> Vec<(bool, String)> {
+ get_types("BorrowedTypeList.h", "GECKO_BORROWED_TYPE(?:_MUT)?")
+ .into_iter()
+ .map(|(macro_name, type_name)| {
+ (macro_name.ends_with("MUT"), type_name)
+ })
+ .collect()
+ }
+
fn get_arc_types() -> Vec<String> {
get_types("ServoArcTypeList.h", "SERVO_ARC_TYPE")
+ .into_iter()
+ .map(|(_, type_name)| type_name)
+ .collect()
}
fn get_boxed_types() -> Vec<String> {
get_types("ServoBoxedTypeList.h", "SERVO_BOXED_TYPE")
+ .into_iter()
+ .map(|(_, type_name)| type_name)
+ .collect()
}
struct BuilderWithConfig<'a> {
@@ -544,6 +559,13 @@ mod bindings {
// which _do_ need to be opaque, we'll need a separate mode.
.handle_str_items("servo-borrow-types", |b, ty| b.mutable_borrowed_type(ty))
.get_builder();
+ for (is_mut, ty) in get_borrowed_types().iter() {
+ if *is_mut {
+ builder = builder.mutable_borrowed_type(ty);
+ } else {
+ builder = builder.borrowed_type(ty);
+ }
+ }
for ty in get_arc_types().iter() {
builder = builder
.blacklist_type(format!("{}Strong", ty))