diff --git a/components/style/gecko/regen_atoms.py b/components/style/gecko/regen_atoms.py index 13f0a8c0005..fe6150d5479 100755 --- a/components/style/gecko/regen_atoms.py +++ b/components/style/gecko/regen_atoms.py @@ -15,14 +15,6 @@ sys.path.insert(0, os.path.join(os.path.dirname(GECKO_DIR), "properties")) import build -PRELUDE = """ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -/* Autogenerated file created by components/style/gecko/regen_atoms.py, DO NOT EDIT DIRECTLY */ -"""[1:] # NOQA: E501 - # Matches lines like `GK_ATOM(foo, "foo", 0x12345678, nsStaticAtom, PseudoElementAtom)`. PATTERN = re.compile('^GK_ATOM\(([^,]*),[^"]*"([^"]*)",\s*(0x[0-9a-f]+),\s*([^,]*),\s*([^)]*)\)', @@ -144,55 +136,72 @@ class FileAvoidWrite(BytesIO): self.close() -IMPORTS = ("\nuse gecko_bindings::structs::nsStaticAtom;" - "\nuse string_cache::Atom;\n\n") +PRELUDE = ''' +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -ATOM_TEMPLATE = (" #[link_name = \"{link_name}\"]\n" - " pub static {name}: *mut {type};") +// Autogenerated file created by components/style/gecko/regen_atoms.py. +// DO NOT EDIT DIRECTLY +'''[1:] -UNSAFE_STATIC = ("#[inline(always)]\n" - "pub unsafe fn atom_from_static(ptr: *mut nsStaticAtom) -> Atom {\n" - " Atom::from_static(ptr)\n" - "}\n\n") +IMPORTS = ''' +use gecko_bindings::structs::nsStaticAtom; +use string_cache::Atom; -CFG_IF = ''' +''' + +UNSAFE_STATIC = ''' +#[inline(always)] +pub unsafe fn atom_from_static(ptr: *mut nsStaticAtom) -> Atom { + Atom::from_static(ptr) +} +''' + +ATOM_TEMPLATE = ''' + #[link_name = \"{link_name}\"] + pub static {name}: *mut {type}; +'''[1:] + +CFG_IF_TEMPLATE = ''' cfg_if! {{ if #[cfg(not(target_env = "msvc"))] {{ extern {{ -{gnu} +{gnu}\ }} }} else if #[cfg(target_pointer_width = "64")] {{ extern {{ -{msvc64} +{msvc64}\ }} }} else {{ extern {{ -{msvc32} +{msvc32}\ }} }} }} ''' -RULE_TEMPLATE = ('("{atom}") =>\n ' - '{{{{ ' - '#[allow(unsafe_code)] #[allow(unused_unsafe)]' - 'unsafe {{ $crate::string_cache::atom_macro::atom_from_static' - '($crate::string_cache::atom_macro::{name} as *mut _) }}' - ' }}}};') +RULE_TEMPLATE = ''' +("{atom}") => + {{{{ + #[allow(unsafe_code)] #[allow(unused_unsafe)] + unsafe {{ $crate::string_cache::atom_macro::atom_from_static ($crate::string_cache::atom_macro::{name} as *mut _) }} + }}}}; +'''[1:] -MACRO = ''' +MACRO_TEMPLATE = ''' #[macro_export] macro_rules! atom {{ -{} +{body}\ }} ''' def write_atom_macro(atoms, file_name): def get_symbols(func): - return '\n'.join([ATOM_TEMPLATE.format(name=atom.ident, - link_name=func(atom), - type=atom.type()) for atom in atoms]) + return ''.join([ATOM_TEMPLATE.format(name=atom.ident, + link_name=func(atom), + type=atom.type()) for atom in atoms]) with FileAvoidWrite(file_name) as f: f.write(PRELUDE) @@ -200,17 +209,17 @@ def write_atom_macro(atoms, file_name): for ty in sorted(set([atom.type() for atom in atoms])): if ty != "nsStaticAtom": - f.write("pub enum {} {{}}\n\n".format(ty)) + f.write("pub enum {} {{}}\n".format(ty)) f.write(UNSAFE_STATIC) gnu_symbols = get_symbols(Atom.gnu_symbol) msvc32_symbols = get_symbols(Atom.msvc32_symbol) msvc64_symbols = get_symbols(Atom.msvc64_symbol) - f.write(CFG_IF.format(gnu=gnu_symbols, msvc32=msvc32_symbols, msvc64=msvc64_symbols)) + f.write(CFG_IF_TEMPLATE.format(gnu=gnu_symbols, msvc32=msvc32_symbols, msvc64=msvc64_symbols)) macro_rules = [RULE_TEMPLATE.format(atom=atom.value, name=atom.ident) for atom in atoms] - f.write(MACRO.format('\n'.join(macro_rules))) + f.write(MACRO_TEMPLATE.format(body=''.join(macro_rules))) def write_pseudo_elements(atoms, target_filename):