style: Part 11: Move Gecko borrowed FFI types to a separate header file.

Differential Revision: https://phabricator.services.mozilla.com/D8653
This commit is contained in:
Cameron McCormack 2018-10-14 00:06:13 +00:00 committed by Emilio Cobos Álvarez
parent 89e4d6c049
commit d960db340c
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 34 additions and 12 deletions

View file

@ -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))

View file

@ -8,7 +8,7 @@ use atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
use context::QuirksMode;
use dom::TElement;
use gecko_bindings::bindings::{self, RawServoStyleSet};
use gecko_bindings::structs::{RawGeckoPresContextOwned, ServoStyleSetSizes, StyleSheet as DomStyleSheet};
use gecko_bindings::structs::{RawGeckoPresContextBorrowed, ServoStyleSetSizes, StyleSheet as DomStyleSheet};
use gecko_bindings::structs::{StyleSheetInfo, nsIDocument};
use gecko_bindings::sugar::ownership::{HasArcFFI, HasBoxFFI, HasFFI, HasSimpleFFI};
use invalidation::media_queries::{MediaListKey, ToMediaListKey};
@ -143,7 +143,7 @@ pub struct PerDocumentStyleData(AtomicRefCell<PerDocumentStyleDataImpl>);
impl PerDocumentStyleData {
/// Create a dummy `PerDocumentStyleData`.
pub fn new(pres_context: RawGeckoPresContextOwned) -> Self {
pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self {
let device = Device::new(pres_context);
// FIXME(emilio, tlin): How is this supposed to work with XBL? This is

View file

@ -12,7 +12,7 @@ use euclid::TypedScale;
use gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor};
use gecko_bindings::bindings;
use gecko_bindings::structs;
use gecko_bindings::structs::{nsPresContext, RawGeckoPresContextOwned};
use gecko_bindings::structs::{nsPresContext, RawGeckoPresContextBorrowed};
use media_queries::MediaType;
use properties::ComputedValues;
use servo_arc::Arc;
@ -30,7 +30,7 @@ pub struct Device {
/// NB: The pres context lifetime is tied to the styleset, who owns the
/// stylist, and thus the `Device`, so having a raw pres context pointer
/// here is fine.
pres_context: RawGeckoPresContextOwned,
pres_context: RawGeckoPresContextBorrowed,
default_values: Arc<ComputedValues>,
/// The font size of the root element
/// This is set when computing the style of the root
@ -77,7 +77,7 @@ unsafe impl Send for Device {}
impl Device {
/// Trivially constructs a new `Device`.
pub fn new(pres_context: RawGeckoPresContextOwned) -> Self {
pub fn new(pres_context: RawGeckoPresContextBorrowed) -> Self {
assert!(!pres_context.is_null());
Device {
pres_context,