mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Move list of Servo Boxed types to a separate header file.
Differential Revision: https://phabricator.services.mozilla.com/D8652
This commit is contained in:
parent
52d054ab5f
commit
89e4d6c049
2 changed files with 28 additions and 20 deletions
|
@ -300,21 +300,23 @@ mod bindings {
|
||||||
.expect("Unable to write output");
|
.expect("Unable to write output");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_arc_types() -> Vec<String> {
|
fn get_types(filename: &str, macro_name: &str) -> Vec<String> {
|
||||||
// Read the file
|
// Read the file
|
||||||
let mut list_file = File::open(DISTDIR_PATH.join("include/mozilla/ServoArcTypeList.h"))
|
let path = DISTDIR_PATH.join("include/mozilla/").join(filename);
|
||||||
.expect("Unable to open ServoArcTypeList.h");
|
let mut list_file = File::open(path)
|
||||||
|
.expect(&format!("Unable to open {}", filename));
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
list_file
|
list_file
|
||||||
.read_to_string(&mut content)
|
.read_to_string(&mut content)
|
||||||
.expect("Fail to read ServoArcTypeList.h");
|
.expect(&format!("Failed to read {}", filename));
|
||||||
// Remove comments
|
// Remove comments
|
||||||
let block_comment_re = Regex::new(r#"(?s)/\*.*?\*/"#).unwrap();
|
let block_comment_re = Regex::new(r#"(?s)/\*.*?\*/"#).unwrap();
|
||||||
let line_comment_re = Regex::new(r#"//.*"#).unwrap();
|
let line_comment_re = Regex::new(r#"//.*"#).unwrap();
|
||||||
let content = block_comment_re.replace_all(&content, "");
|
let content = block_comment_re.replace_all(&content, "");
|
||||||
let content = line_comment_re.replace_all(&content, "");
|
let content = line_comment_re.replace_all(&content, "");
|
||||||
// Extract the list
|
// Extract the list
|
||||||
let re = Regex::new(r#"^SERVO_ARC_TYPE\(\w+,\s*(\w+)\)$"#).unwrap();
|
let re_string = format!(r#"^{}\(\w+,\s*(\w+)\)$"#, macro_name);
|
||||||
|
let re = Regex::new(&re_string).unwrap();
|
||||||
content
|
content
|
||||||
.lines()
|
.lines()
|
||||||
.map(|line| line.trim())
|
.map(|line| line.trim())
|
||||||
|
@ -322,7 +324,8 @@ mod bindings {
|
||||||
.map(|line| {
|
.map(|line| {
|
||||||
re.captures(&line)
|
re.captures(&line)
|
||||||
.expect(&format!(
|
.expect(&format!(
|
||||||
"Unrecognized line in ServoArcTypeList.h: '{}'",
|
"Unrecognized line in {}: '{}'",
|
||||||
|
filename,
|
||||||
line
|
line
|
||||||
)).get(1)
|
)).get(1)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -331,6 +334,14 @@ mod bindings {
|
||||||
}).collect()
|
}).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_arc_types() -> Vec<String> {
|
||||||
|
get_types("ServoArcTypeList.h", "SERVO_ARC_TYPE")
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_boxed_types() -> Vec<String> {
|
||||||
|
get_types("ServoBoxedTypeList.h", "SERVO_BOXED_TYPE")
|
||||||
|
}
|
||||||
|
|
||||||
struct BuilderWithConfig<'a> {
|
struct BuilderWithConfig<'a> {
|
||||||
builder: Builder,
|
builder: Builder,
|
||||||
config: &'a Table,
|
config: &'a Table,
|
||||||
|
@ -526,19 +537,6 @@ mod bindings {
|
||||||
"&'a mut ::gecko_bindings::structs::nsTArray<{}>;"),
|
"&'a mut ::gecko_bindings::structs::nsTArray<{}>;"),
|
||||||
cpp_type, rust_type))
|
cpp_type, rust_type))
|
||||||
})
|
})
|
||||||
.handle_table_items("servo-owned-types", |mut builder, item| {
|
|
||||||
let name = item["name"].as_str().unwrap();
|
|
||||||
builder = builder.blacklist_type(format!("{}Owned", name))
|
|
||||||
.raw_line(format!("pub type {0}Owned = ::gecko_bindings::sugar::ownership::Owned<{0}>;", name))
|
|
||||||
.blacklist_type(format!("{}OwnedOrNull", name))
|
|
||||||
.raw_line(format!(concat!("pub type {0}OwnedOrNull = ",
|
|
||||||
"::gecko_bindings::sugar::ownership::OwnedOrNull<{0}>;"), name))
|
|
||||||
.mutable_borrowed_type(name);
|
|
||||||
if item["opaque"].as_bool().unwrap() {
|
|
||||||
builder = builder.zero_size_type(name, &structs_types);
|
|
||||||
}
|
|
||||||
builder
|
|
||||||
})
|
|
||||||
.handle_str_items("servo-immutable-borrow-types", |b, ty| b.borrowed_type(ty))
|
.handle_str_items("servo-immutable-borrow-types", |b, ty| b.borrowed_type(ty))
|
||||||
// Right now the only immutable borrow types are ones which we import
|
// Right now the only immutable borrow types are ones which we import
|
||||||
// from the |structs| module. As such, we don't need to create an opaque
|
// from the |structs| module. As such, we don't need to create an opaque
|
||||||
|
@ -555,6 +553,16 @@ mod bindings {
|
||||||
)).borrowed_type(ty)
|
)).borrowed_type(ty)
|
||||||
.zero_size_type(ty, &structs_types);
|
.zero_size_type(ty, &structs_types);
|
||||||
}
|
}
|
||||||
|
for ty in get_boxed_types().iter() {
|
||||||
|
builder = builder
|
||||||
|
.blacklist_type(format!("{}Owned", ty))
|
||||||
|
.raw_line(format!("pub type {0}Owned = ::gecko_bindings::sugar::ownership::Owned<{0}>;", ty))
|
||||||
|
.blacklist_type(format!("{}OwnedOrNull", ty))
|
||||||
|
.raw_line(format!(concat!("pub type {0}OwnedOrNull = ",
|
||||||
|
"::gecko_bindings::sugar::ownership::OwnedOrNull<{0}>;"), ty))
|
||||||
|
.mutable_borrowed_type(ty)
|
||||||
|
.zero_size_type(ty, &structs_types);
|
||||||
|
}
|
||||||
write_binding_file(builder, BINDINGS_FILE, &fixups);
|
write_binding_file(builder, BINDINGS_FILE, &fixups);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
%>
|
%>
|
||||||
|
|
||||||
#[cfg(feature = "gecko")] use gecko_bindings::bindings::RawServoAnimationValueMap;
|
#[cfg(feature = "gecko")] use gecko_bindings::structs::RawServoAnimationValueMap;
|
||||||
#[cfg(feature = "gecko")] use gecko_bindings::structs::RawGeckoGfxMatrix4x4;
|
#[cfg(feature = "gecko")] use gecko_bindings::structs::RawGeckoGfxMatrix4x4;
|
||||||
#[cfg(feature = "gecko")] use gecko_bindings::structs::nsCSSPropertyID;
|
#[cfg(feature = "gecko")] use gecko_bindings::structs::nsCSSPropertyID;
|
||||||
#[cfg(feature = "gecko")] use gecko_bindings::sugar::ownership::{HasFFI, HasSimpleFFI};
|
#[cfg(feature = "gecko")] use gecko_bindings::sugar::ownership::{HasFFI, HasSimpleFFI};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue