summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/blink/renderer/build/scripts/templates/macros.tmpl
blob: 0244433af2e8bed2e1fc1131eb06bb68aba863bc (plain)
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
{#
    FIXME: Do we need to put license blocks in generated files?
#}
{% macro license() %}
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
{%- endmacro %}


{% macro source_files_for_generated_file(template_file, input_files) %}
{% if not template_file %}
{{ "template_file must be defined in template scripts."/0 }}
{% endif %}
{% if not input_files %}
{{ "input_files must be defined in template scripts."/0 }}
{% endif %}
// Generated from template:
//   {{template_file}}
// and input files:
{% for input in input_files|sort %}
//   {{input}}
{% endfor %}
{%- endmacro %}


{% macro trie_leaf(index, object, return_macro, lowercase_data) %}
{% set name, value = object.items()[0] %}
{% if name|length %}
if (
    {%- for c in name -%}
        {%- if lowercase_data -%}
    {{ " && " if not loop.first }}ToASCIILower(data[{{index + loop.index0}}]) == '{{c}}'
        {%- else -%}
    {{ " && " if not loop.first }}data[{{index + loop.index0}}] == '{{c}}'
        {%- endif -%}
        {%- endfor -%}
    )
    return {{ return_macro(value) }};
break;
{% else %}
return {{ return_macro(value) }};
{% endif %}
{% endmacro %}


{% macro trie_switch(trie, index, return_macro, lowercase_data) %}
{% if trie|length == 1 and trie.values()[0] is string %}
{{ trie_leaf(index, trie, return_macro, lowercase_data) -}}
{% else %}
    {% if lowercase_data %}
switch (ToASCIILower(data[{{index}}])) {
    {% else %}
switch (data[{{index}}]) {
    {% endif %}
    {% for char, value in trie.items()|sort %}
case '{{char}}':
    {{ trie_switch(value, index + 1, return_macro, lowercase_data) | indent(4) }}
    {% endfor %}
}
break;
{% endif %}
{% endmacro %}


{% macro trie_length_switch(length_tries, return_macro, lowercase_data) %}
switch (length) {
{% for length, trie in length_tries %}
case {{ length }}:
    {{ trie_switch(trie, 0, return_macro, lowercase_data) | indent(4) }}
{% endfor %}
}
{% endmacro %}


{% macro print_if(predicate, str) -%}
{% if predicate %}{{str}}{% endif %}
{%- endmacro %}