Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / build / scripts / templates / ElementLookupTrie.cpp.tmpl
blob6363a035e243999c8f54083667a5b17e7c1b3b58
1 {% from 'macros.tmpl' import license %}
2 {{license()}}
3 {% macro trie_switch(trie, index) %}
4 {# FIXME: No need to switch if there's only a single item in the subtrie:
5    can just have an if statement as we're currently doing for leaves. #}
6 switch (data[{{index}}]) {
7 {% for char, subtrie, tag, conditions in trie %}
8 case '{{char}}':
9     {% if subtrie %}{# Recurse on subtrie #}
10     {{trie_switch(subtrie, index + 1) | indent}}
11     {% elif conditions %}{# Check suffix #}
12     if ({{conditions | join(' && ')}})
13         return {{tag}}Tag.localName().impl();
14     return 0;
15     {% else %}{# Terminal node (no suffix) #}
16     return {{tag}}Tag.localName().impl();
17     {% endif %}
18 {% endfor %}
20 return 0;
21 {% endmacro %}
23 #include "config.h"
24 #include "{{namespace}}ElementLookupTrie.h"
26 #include "{{namespace}}Names.h"
28 namespace blink {
30 using namespace {{namespace}}Names;
32 StringImpl* lookup{{namespace}}Tag(const UChar* data, unsigned length)
34     ASSERT(data);
35     ASSERT(length);
36     switch (length) {
37     {% for length, trie in length_tries %}
38     case {{length}}:
39         {{trie_switch(trie, 0) | indent(8)}}
40     {% endfor %}
41     }
42     return 0;
45 } // namespace blink