1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include "nsGkAtoms.h"
8 
9 namespace mozilla {
10 namespace detail {
11 
12 // Because this is `constexpr` it ends up in read-only memory where it can be
13 // shared between processes.
14 extern constexpr GkAtoms gGkAtoms = {
15 // The initialization of each atom's string.
16 //
17 // Expansion of the example GK_ATOM entries in nsGkAtoms.h:
18 //
19 //   u"a",
20 //   u"bb",
21 //   u"Ccc",
22 //
23 #define GK_ATOM(name_, value_, hash_, is_ascii_lower_, type_, atom_type_) \
24   u"" value_,
25 #include "nsGkAtomList.h"
26 #undef GK_ATOM
27     {
28 // The initialization of the atoms themselves.
29 //
30 // Note that |value_| is an 8-bit string, and so |sizeof(value_)| is equal
31 // to the number of chars (including the terminating '\0'). The |u""| prefix
32 // converts |value_| to a 16-bit string.
33 //
34 // Expansion of the example GK_ATOM entries in nsGkAtoms.h:
35 //
36 //   nsStaticAtom(
37 //     1,
38 //     0x01234567,
39 //     offsetof(GkAtoms, mAtoms[static_cast<size_t>(GkAtoms::Atoms::a)]) -
40 //       offsetof(GkAtoms, a_string),
41 //     true),
42 //
43 //   nsStaticAtom(
44 //     2,
45 //     0x12345678,
46 //     offsetof(GkAtoms, mAtoms[static_cast<size_t>(GkAtoms::Atoms::bb)]) -
47 //       offsetof(GkAtoms, bb_string),
48 //     false),
49 //
50 //   nsStaticAtom(
51 //     3,
52 //     0x23456789,
53 //     offsetof(GkAtoms, mAtoms[static_cast<size_t>(GkAtoms::Atoms::Ccc)]) -
54 //       offsetof(GkAtoms, Ccc_string),
55 //     false),
56 //
57 #define GK_ATOM(name_, value_, hash_, is_ascii_lower_, type_, atom_type_)     \
58   nsStaticAtom(                                                               \
59       sizeof(value_) - 1, hash_,                                              \
60       offsetof(GkAtoms, mAtoms[static_cast<size_t>(GkAtoms::Atoms::name_)]) - \
61           offsetof(GkAtoms, name_##_string),                                  \
62       is_ascii_lower_),
63 #include "nsGkAtomList.h"
64 #undef GK_ATOM
65     }};
66 
67 }  // namespace detail
68 }  // namespace mozilla
69 
70 const nsStaticAtom* const nsGkAtoms::sAtoms = mozilla::detail::gGkAtoms.mAtoms;
71