Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / build / scripts / templates / MakeQualifiedNames.cpp.tmpl
1 {% from "macros.tmpl" import license %}
2 {{ license() }}
3
4 #include "config.h"
5
6 #include "{{namespace}}Names.h"
7
8 #include "wtf/StaticConstructors.h"
9 #include "wtf/StdLibExtras.h"
10
11 namespace blink {
12 namespace {{namespace}}Names {
13
14 using namespace blink;
15
16 DEFINE_GLOBAL(AtomicString, {{namespace_prefix}}NamespaceURI)
17
18 {% if tags %}
19 // Tags
20
21 void* {{suffix}}TagStorage[{{namespace}}TagsCount * ((sizeof({{namespace}}QualifiedName) + sizeof(void *) - 1) / sizeof(void *))];
22 {% for tag in tags|sort(attribute='name', case_sensitive=True) %}
23 const {{namespace}}QualifiedName& {{tag|symbol}}Tag = reinterpret_cast<{{namespace}}QualifiedName*>(&{{suffix}}TagStorage)[{{loop.index0}}];
24 {% endfor %}
25
26
27 {% if namespace == 'SVG' %}
28 PassOwnPtr<const {{namespace}}QualifiedName*[]> get{{namespace}}Tags()
29 {
30     OwnPtr<const {{namespace}}QualifiedName*[]> tags = adoptArrayPtr(new const {{namespace}}QualifiedName*[{{namespace}}TagsCount]);
31     for (size_t i = 0; i < {{namespace}}TagsCount; i++)
32         tags[i] = reinterpret_cast<{{namespace}}QualifiedName*>(&{{suffix}}TagStorage) + i;
33     return tags.release();
34 }
35 {% endif %}
36
37 {% endif %}
38 // Attributes
39
40 void* {{suffix}}AttrStorage[{{namespace}}AttrsCount * ((sizeof(QualifiedName) + sizeof(void *) - 1) / sizeof(void *))];
41
42 {% for attr in attrs|sort(attribute='name', case_sensitive=True) %}
43 const QualifiedName& {{attr|symbol}}Attr = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage)[{{loop.index0}}];
44 {% endfor %}
45
46 {% if namespace != 'HTML' %}
47 PassOwnPtr<const QualifiedName*[]> get{{namespace}}Attrs()
48 {
49     OwnPtr<const QualifiedName*[]> attrs = adoptArrayPtr(new const QualifiedName*[{{namespace}}AttrsCount]);
50     for (size_t i = 0; i < {{namespace}}AttrsCount; i++)
51         attrs[i] = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage) + i;
52     return attrs.release();
53 }
54 {% endif %}
55
56
57 void init()
58 {
59     struct NameEntry {
60         const char* name;
61         unsigned hash;
62         unsigned char length;
63         unsigned char isTag;
64         unsigned char isAttr;
65     };
66
67     // Use placement new to initialize the globals.
68     AtomicString {{namespace_prefix}}NS("{{namespace_uri}}", AtomicString::ConstructFromLiteral);
69
70     // Namespace
71     new ((void*)&{{namespace_prefix}}NamespaceURI) AtomicString({{namespace_prefix}}NS);
72     {% set tagnames = tags|map(attribute='name')|list() %}
73     {% set attrnames = attrs|map(attribute='name')|list() %}
74     static const NameEntry kNames[] = {
75     {% for name, tag_list in (tags + attrs)|groupby('name')|sort(attribute=0, case_sensitive=True) %}
76         { "{{name}}", {{name|hash}}, {{name|length}}, {{ (name in tagnames)|int }}, {{ (name in attrnames)|int }} },
77     {% endfor %}
78     };
79
80     {% if tags %}
81     size_t tag_i = 0;
82     {% endif %}
83     size_t attr_i = 0;
84     for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNames); i++) {
85         StringImpl* stringImpl = StringImpl::createStatic(kNames[i].name, kNames[i].length, kNames[i].hash);
86         {% if tags %}
87         if (kNames[i].isTag) {
88             void* address = reinterpret_cast<{{namespace}}QualifiedName*>(&{{suffix}}TagStorage) + tag_i;
89             QualifiedName::createStatic(address, stringImpl, {{namespace_prefix}}NS);
90             tag_i++;
91         }
92
93         if (!kNames[i].isAttr)
94             continue;
95         {% endif %}
96         void* address = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage) + attr_i;
97         {% if use_namespace_for_attrs %}
98         QualifiedName::createStatic(address, stringImpl, {{namespace_prefix}}NS);
99         {% else %}
100         QualifiedName::createStatic(address, stringImpl);
101         {% endif %}
102         attr_i++;
103     }
104     {% if tags %}
105     ASSERT(tag_i == {{namespace}}TagsCount);
106     {% endif %}
107     ASSERT(attr_i == {{namespace}}AttrsCount);
108 }
109
110 } // {{namespace}}
111 } // namespace blink