Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(893)

Side by Side Diff: third_party/WebKit/Source/build/scripts/templates/macros.tmpl

Issue 1938343002: Generate a series of nested switch statements to parse CSSPrimitiveValue units. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 {# 1 {#
2 FIXME: Do we need to put license blocks in generated files? 2 FIXME: Do we need to put license blocks in generated files?
3 #} 3 #}
4 {% macro license() %} 4 {% macro license() %}
5 // Copyright (c) 2014 The Chromium Authors. All rights reserved. 5 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
6 // Use of this source code is governed by a BSD-style license that can be 6 // Use of this source code is governed by a BSD-style license that can be
7 // found in the LICENSE file. 7 // found in the LICENSE file.
8 {%- endmacro %} 8 {%- endmacro %}
9
10 {% macro trie_leaf(index, entry, return_macro, default_return_value) %}
Timothy Loh 2016/05/03 07:40:25 We'll need a flag should_lower since unlike the ta
11 {% if entry.conditions %}
12 if ({{entry.conditions | join(' && ')}})
13 {{return_macro(entry.value)}}
14 {% else %}
15 if (data[{{index}}] == '{{entry.char}}')
16 {{return_macro(entry.value)}}
17 {% endif %}
18 return {{default_return_value}};
Timothy Loh 2016/05/03 07:40:25 It might be possible to make this a "break" so we
meade_UTC10 2016/05/04 07:24:54 Done.
19 {% endmacro %}
20
21 {% macro trie_switch(trie, index, return_macro, default_return_value) %}
22 switch (data[{{index}}]) {
23 {% for entry in trie %}
24 case '{{entry.char}}':
25 {% if entry.subtrie %}
26 {{trie_switch(entry.subtrie, index + 1, return_macro, default_return_value) | indent}}
27 {% elif entry.conditions %}{# Check suffix #}
28 {{trie_leaf(index, entry, return_macro, default_return_value)}}
29 {% else %}{# Terminal node (no suffix) #}
30 {{return_macro(entry.value)}}
31 {% endif %}
32 {% endfor %}
33 }
34 return {{default_return_value}};
35 {% endmacro %}
36
37 {% macro trie_length_switch(empty_case_return_value, length_tries, return_macro, default_return_value) %}
38 switch (length) {
39 {% if empty_case_return_value %}
40 case 0:
41 {{return_macro(empty_case_return_value)}}
42 {% endif %}
43 {% for length, trie in length_tries %}
44 case {{length}}:
45 {% if trie|length > 1 or trie[0].subtrie %}
46 {{trie_switch(trie, 0, return_macro, default_return_value) | indent(8)}}
47 {% else %}
48 {{trie_leaf(0, trie[0], return_macro, default_return_value) | indent(8)} }
49 {% endif %}
50 {% endfor %}
51 }
52 return {{default_return_value}};
53 {% endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698