chromium/third_party/blink/renderer/build/scripts/templates/macros.tmpl

{#
    FIXME: Do we need to put license blocks in generated files?
#}
{% macro license(year=2014) %}
// Copyright {{year}} The Chromium Authors
// 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 %}


{#
    `is_lchar` indicates if the strings are LChars. If false, the string is
    UChar.
#}
{% macro trie_leaf(index, object, return_macro, lowercase_data, is_lchar) %}
{% set name, value = (object.items()|list)[0] %}
{% set string_prefix = "" if is_lchar else "u" %}
{% set factor = "" if is_lchar else "2 * " %}
{% if name|length > 1 and not lowercase_data %}
if (memcmp(data + {{index}}, {{string_prefix}}"{{name}}", {{factor}}{{name|length}}) == 0) {
  return {{ return_macro(value) }};
}
break;
{% elif 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, is_lchar) %}
{% if trie|length == 1 and (trie.values()|list)[0] is string %}
{{ trie_leaf(index, trie, return_macro, lowercase_data, is_lchar) -}}
{% 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, is_lchar) | indent(2) -}}
    {% endfor %}
}
break;
{% endif %}
{% endmacro %}


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


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

{%- macro platform_buildflag(platform) -%}
BUILDFLAG(IS_{{platform | upper}})
{%- endmacro -%}