File: MakeQualifiedNames.cpp.tmpl

package info (click to toggle)
chromium-browser 41.0.2272.118-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,189,132 kB
  • sloc: cpp: 9,691,462; ansic: 3,341,451; python: 712,689; asm: 518,779; xml: 208,926; java: 169,820; sh: 119,353; perl: 68,907; makefile: 28,311; yacc: 13,305; objc: 11,385; tcl: 3,186; cs: 2,225; sql: 2,217; lex: 2,215; lisp: 1,349; pascal: 1,256; awk: 407; ruby: 155; sed: 53; php: 14; exp: 11
file content (109 lines) | stat: -rw-r--r-- 3,750 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
{% from "macros.tmpl" import license %}
{{ license() }}

#include "config.h"

#include "{{namespace}}Names.h"

#include "wtf/StaticConstructors.h"
#include "wtf/StdLibExtras.h"

namespace blink {
namespace {{namespace}}Names {

using namespace blink;

DEFINE_GLOBAL(AtomicString, {{namespace_prefix}}NamespaceURI)

{% if tags %}
// Tags

void* {{suffix}}TagStorage[{{namespace}}TagsCount * ((sizeof({{namespace}}QualifiedName) + sizeof(void *) - 1) / sizeof(void *))];
{% for tag in tags|sort(attribute='name', case_sensitive=True) %}
const {{namespace}}QualifiedName& {{tag|symbol}}Tag = reinterpret_cast<{{namespace}}QualifiedName*>(&{{suffix}}TagStorage)[{{loop.index0}}];
{% endfor %}


PassOwnPtr<const {{namespace}}QualifiedName*[]> get{{namespace}}Tags()
{
    OwnPtr<const {{namespace}}QualifiedName*[]> tags = adoptArrayPtr(new const {{namespace}}QualifiedName*[{{namespace}}TagsCount]);
    for (size_t i = 0; i < {{namespace}}TagsCount; i++)
        tags[i] = reinterpret_cast<{{namespace}}QualifiedName*>(&{{suffix}}TagStorage) + i;
    return tags.release();
}

{% endif %}
// Attributes

void* {{suffix}}AttrStorage[{{namespace}}AttrsCount * ((sizeof(QualifiedName) + sizeof(void *) - 1) / sizeof(void *))];

{% for attr in attrs|sort(attribute='name', case_sensitive=True) %}
const QualifiedName& {{attr|symbol}}Attr = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage)[{{loop.index0}}];
{% endfor %}

{% if namespace != 'HTML' %}
PassOwnPtr<const QualifiedName*[]> get{{namespace}}Attrs()
{
    OwnPtr<const QualifiedName*[]> attrs = adoptArrayPtr(new const QualifiedName*[{{namespace}}AttrsCount]);
    for (size_t i = 0; i < {{namespace}}AttrsCount; i++)
        attrs[i] = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage) + i;
    return attrs.release();
}
{% endif %}


void init()
{
    struct NameEntry {
        const char* name;
        unsigned hash;
        unsigned char length;
        unsigned char isTag;
        unsigned char isAttr;
    };

    // Use placement new to initialize the globals.
    AtomicString {{namespace_prefix}}NS("{{namespace_uri}}", AtomicString::ConstructFromLiteral);

    // Namespace
    new ((void*)&{{namespace_prefix}}NamespaceURI) AtomicString({{namespace_prefix}}NS);
    {% set tagnames = tags|map(attribute='name')|list() %}
    {% set attrnames = attrs|map(attribute='name')|list() %}
    static const NameEntry kNames[] = {
    {% for name, tag_list in (tags + attrs)|groupby('name')|sort(attribute=0, case_sensitive=True) %}
        { "{{name}}", {{name|hash}}, {{name|length}}, {{ (name in tagnames)|int }}, {{ (name in attrnames)|int }} },
    {% endfor %}
    };

    {% if tags %}
    size_t tag_i = 0;
    {% endif %}
    size_t attr_i = 0;
    for (size_t i = 0; i < WTF_ARRAY_LENGTH(kNames); i++) {
        StringImpl* stringImpl = StringImpl::createStatic(kNames[i].name, kNames[i].length, kNames[i].hash);
        {% if tags %}
        if (kNames[i].isTag) {
            void* address = reinterpret_cast<{{namespace}}QualifiedName*>(&{{suffix}}TagStorage) + tag_i;
            QualifiedName::createStatic(address, stringImpl, {{namespace_prefix}}NS);
            tag_i++;
        }

        if (!kNames[i].isAttr)
            continue;
        {% endif %}
        void* address = reinterpret_cast<QualifiedName*>(&{{suffix}}AttrStorage) + attr_i;
        {% if use_namespace_for_attrs %}
        QualifiedName::createStatic(address, stringImpl, {{namespace_prefix}}NS);
        {% else %}
        QualifiedName::createStatic(address, stringImpl);
        {% endif %}
        attr_i++;
    }
    {% if tags %}
    ASSERT(tag_i == {{namespace}}TagsCount);
    {% endif %}
    ASSERT(attr_i == {{namespace}}AttrsCount);
}

} // {{namespace}}
} // namespace blink