Bug 1482782 - Part 3: Define atom type in nsGkAtomList.h. r=njn
authorCameron McCormack <cam@mcc.id.au>
Wed, 15 Aug 2018 15:46:00 +1000
changeset 486775 57507aba8ffd33917ad48c52b29a0fe2dad3f7a1
parent 486774 7ef73ff1649501f237c2df7d588ad8f9f544bed8
child 486776 6605ef249363dcf770e4d07d9753b2252690d1f2
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1482782
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1482782 - Part 3: Define atom type in nsGkAtomList.h. r=njn Summary: Depends On D3281 Reviewers: njn! Tags: #secure-revision Bug #: 1482782 Differential Revision: https://phabricator.services.mozilla.com/D3282
servo/components/style/gecko/regen_atoms.py
xpcom/ds/Atom.py
xpcom/ds/StaticAtoms.py
xpcom/ds/nsGkAtoms.cpp
xpcom/ds/nsGkAtoms.h
xpcom/ds/nsStaticAtom.h
--- a/servo/components/style/gecko/regen_atoms.py
+++ b/servo/components/style/gecko/regen_atoms.py
@@ -34,35 +34,35 @@ def msvc64_symbolify(source, ident):
 
 def msvc32_symbolify(source, ident):
     # Prepend "\x01" to avoid LLVM prefixing the mangled name with "_".
     # See https://github.com/rust-lang/rust/issues/36097
     return "\\x01?{}@{}@@2PAV{}@@A".format(ident, source.CLASS, source.TYPE)
 
 
 class GkAtomSource:
-    PATTERN = re.compile('^(GK_ATOM)\(([^,]*),[^"]*"([^"]*)"\)',
+    PATTERN = re.compile('^(GK_ATOM)\(([^,]*),[^"]*"([^"]*)",\s*([^)]*)\)',
                          re.MULTILINE)
     FILE = "include/nsGkAtomList.h"
     CLASS = "nsGkAtoms"
     TYPE = "nsStaticAtom"
 
 
 class CSSPseudoElementsAtomSource:
-    PATTERN = re.compile('^(CSS_PSEUDO_ELEMENT)\(([^,]*),[^"]*"([^"]*)",',
+    PATTERN = re.compile('^(CSS_PSEUDO_ELEMENT)\(([^,]*),[^"]*"([^"]*)",()',
                          re.MULTILINE)
     FILE = "include/nsCSSPseudoElementList.h"
     CLASS = "nsCSSPseudoElements"
     # NB: nsICSSPseudoElement is effectively the same as a nsStaticAtom, but we need
     # this for MSVC name mangling.
     TYPE = "nsICSSPseudoElement"
 
 
 class CSSAnonBoxesAtomSource:
-    PATTERN = re.compile('^(CSS_ANON_BOX|CSS_NON_INHERITING_ANON_BOX|CSS_WRAPPER_ANON_BOX)\(([^,]*),[^"]*"([^"]*)"\)',  # NOQA: E501
+    PATTERN = re.compile('^(CSS_ANON_BOX|CSS_NON_INHERITING_ANON_BOX|CSS_WRAPPER_ANON_BOX)\(([^,]*),[^"]*"([^"]*)"()\)',  # NOQA: E501
                          re.MULTILINE)
     FILE = "include/nsCSSAnonBoxList.h"
     CLASS = "nsCSSAnonBoxes"
     TYPE = "nsICSSAnonBoxPseudo"
 
 
 SOURCES = [
     GkAtomSource,
@@ -74,39 +74,40 @@ SOURCES = [
 def map_atom(ident):
     if ident in {"box", "loop", "match", "mod", "ref",
                  "self", "type", "use", "where", "in"}:
         return ident + "_"
     return ident
 
 
 class Atom:
-    def __init__(self, source, macro_name, ident, value):
+    def __init__(self, source, macro_name, ident, value, ty):
         self.ident = "{}_{}".format(source.CLASS, ident)
         self.original_ident = ident
         self.value = value
         self.source = source
         self.macro = macro_name
+        self.ty = ty
         if self.is_anon_box():
             assert self.is_inheriting_anon_box() or self.is_non_inheriting_anon_box()
 
     def cpp_class(self):
         return self.source.CLASS
 
     def gnu_symbol(self):
         return gnu_symbolify(self.source, self.original_ident)
 
     def msvc32_symbol(self):
         return msvc32_symbolify(self.source, self.original_ident)
 
     def msvc64_symbol(self):
         return msvc64_symbolify(self.source, self.original_ident)
 
     def type(self):
-        return self.source.TYPE
+        return self.ty
 
     def capitalized(self):
         return self.original_ident[0].upper() + self.original_ident[1:]
 
     def is_anon_box(self):
         return self.type() == "nsICSSAnonBoxPseudo"
 
     def is_non_inheriting_anon_box(self):
@@ -123,17 +124,18 @@ class Atom:
 def collect_atoms(objdir):
     atoms = []
     for source in SOURCES:
         path = os.path.abspath(os.path.join(objdir, source.FILE))
         print("cargo:rerun-if-changed={}".format(path))
         with open(path) as f:
             content = f.read()
             for result in source.PATTERN.finditer(content):
-                atoms.append(Atom(source, result.group(1), result.group(2), result.group(3)))
+                ty = result.group(4) or source.TYPE
+                atoms.append(Atom(source, result.group(1), result.group(2), result.group(3), ty))
     return atoms
 
 
 class FileAvoidWrite(BytesIO):
     """File-like object that buffers output and only writes if content changed."""
     def __init__(self, filename):
         BytesIO.__init__(self)
         self.name = filename
@@ -214,19 +216,19 @@ def write_atom_macro(atoms, file_name):
         return '\n'.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)
         f.write(IMPORTS)
 
-        for source in SOURCES:
-            if source.TYPE != "nsStaticAtom":
-                f.write("pub enum {} {{}}\n\n".format(source.TYPE))
+        for ty in sorted(set([atom.type() for atom in atoms])):
+            if ty != "nsStaticAtom":
+                f.write("pub enum {} {{}}\n\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))
 
--- a/xpcom/ds/Atom.py
+++ b/xpcom/ds/Atom.py
@@ -1,9 +1,10 @@
 # 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/.
 
 
 class Atom():
-    def __init__(self, ident, string):
+    def __init__(self, ident, string, ty="nsStaticAtom"):
         self.ident = ident
         self.string = string
+        self.ty = ty
--- a/xpcom/ds/StaticAtoms.py
+++ b/xpcom/ds/StaticAtoms.py
@@ -2258,14 +2258,15 @@ def verify():
 
 
 def generate_nsgkatomlist_h(output, *ignore):
     verify()
     output.write("/* THIS FILE IS AUTOGENERATED BY StaticAtoms.py.  DO NOT EDIT */\n\n"
                  "#ifdef small\n"
                  "#undef small\n"
                  "#endif\n\n"
-                 "// GK_ATOM(identifier, string)\n" +
-                 "".join(["GK_ATOM(%s, \"%s\")\n" % (a.ident, a.string) for a in STATIC_ATOMS]))
+                 "// GK_ATOM(identifier, string, gecko_type)\n" +
+                 "".join(["GK_ATOM(%s, \"%s\", %s)\n" % (a.ident, a.string, a.ty)
+                          for a in STATIC_ATOMS]))
 
 
 if __name__ == '__main__':
     generate_nsgkatomlist_h(sys.stdout)
--- a/xpcom/ds/nsGkAtoms.cpp
+++ b/xpcom/ds/nsGkAtoms.cpp
@@ -6,36 +6,36 @@
 
 #include "nsGkAtoms.h"
 
 namespace mozilla {
 namespace detail {
 
 MOZ_PUSH_DISABLE_INTEGRAL_CONSTANT_OVERFLOW_WARNING
 extern constexpr GkAtoms gGkAtoms = {
-  #define GK_ATOM(name_, value_) NS_STATIC_ATOM_INIT_STRING(value_)
+  #define GK_ATOM(name_, value_, type_) NS_STATIC_ATOM_INIT_STRING(value_)
   #include "nsGkAtomList.h"
   #undef GK_ATOM
   {
-    #define GK_ATOM(name_, value_) \
+    #define GK_ATOM(name_, value_, type_) \
       NS_STATIC_ATOM_INIT_ATOM(nsStaticAtom, GkAtoms, name_, value_)
     #include "nsGkAtomList.h"
     #undef GK_ATOM
   }
 };
 MOZ_POP_DISABLE_INTEGRAL_CONSTANT_OVERFLOW_WARNING
 
 } // namespace detail
 } // namespace mozilla
 
 const nsStaticAtom* const nsGkAtoms::sAtoms = mozilla::detail::gGkAtoms.mAtoms;
 
-#define GK_ATOM(name_, value_) \
+#define GK_ATOM(name_, value_, type_) \
   NS_STATIC_ATOM_DEFN_PTR( \
-    nsStaticAtom, mozilla::detail::GkAtoms, mozilla::detail::gGkAtoms, \
+    type_, mozilla::detail::GkAtoms, mozilla::detail::gGkAtoms, \
     nsGkAtoms, name_)
 #include "nsGkAtomList.h"
 #undef GK_ATOM
 
 void nsGkAtoms::RegisterStaticAtoms()
 {
   NS_RegisterStaticAtoms(sAtoms, sAtomsLen);
 }
--- a/xpcom/ds/nsGkAtoms.h
+++ b/xpcom/ds/nsGkAtoms.h
@@ -10,22 +10,22 @@
 #include "nsAtom.h"
 #include "nsStaticAtom.h"
 
 namespace mozilla {
 namespace detail {
 
 struct GkAtoms
 {
-  #define GK_ATOM(name_, value_) NS_STATIC_ATOM_DECL_STRING(name_, value_)
+  #define GK_ATOM(name_, value_, type_) NS_STATIC_ATOM_DECL_STRING(name_, value_)
   #include "nsGkAtomList.h"
   #undef GK_ATOM
 
   enum class Atoms {
-    #define GK_ATOM(name_, value_) NS_STATIC_ATOM_ENUM(name_)
+    #define GK_ATOM(name_, value_, type_) NS_STATIC_ATOM_ENUM(name_)
     #include "nsGkAtomList.h"
     #undef GK_ATOM
     AtomsCount
   };
 
   const nsStaticAtom mAtoms[static_cast<size_t>(Atoms::AtomsCount)];
 };
 
@@ -37,14 +37,14 @@ class nsGkAtoms
 private:
   static const nsStaticAtom* const sAtoms;
   static constexpr size_t sAtomsLen =
     static_cast<size_t>(mozilla::detail::GkAtoms::Atoms::AtomsCount);
 
 public:
   static void RegisterStaticAtoms();
 
-  #define GK_ATOM(name_, value_) NS_STATIC_ATOM_DECL_PTR(nsStaticAtom, name_)
+  #define GK_ATOM(name_, value_, type_) NS_STATIC_ATOM_DECL_PTR(type_, name_)
   #include "nsGkAtomList.h"
   #undef GK_ATOM
 };
 
 #endif /* nsGkAtoms_h___ */
--- a/xpcom/ds/nsStaticAtom.h
+++ b/xpcom/ds/nsStaticAtom.h
@@ -221,18 +221,18 @@
         sizeof(value_) - 1, \
         offsetof(detailClass_, \
                  mAtoms[static_cast<size_t>(detailClass_::Atoms::name_)]) - \
         offsetof(detailClass_, name_##_string)),
 
 // Definition of the pointer to the static atom. `type_` must be `nsStaticAtom`
 // or a subclass thereof.
 #define NS_STATIC_ATOM_DEFN_PTR(type_, detailClass_, detailObj_, class_, name_) \
-  type_* class_::name_ = const_cast<type_*>( \
-    &detailObj_.mAtoms[static_cast<size_t>(detailClass_::Atoms::name_)]);
+  type_* class_::name_ = const_cast<type_*>(static_cast<const type_*>( \
+    &detailObj_.mAtoms[static_cast<size_t>(detailClass_::Atoms::name_)]));
 
 // Register an array of static atoms with the atom table.
 void
 NS_RegisterStaticAtoms(const nsStaticAtom* aAtoms, size_t aAtomsLen);
 
 // This class holds basic operations on arrays of static atoms.
 class nsStaticAtomUtils {
 public: