Reviewers: marja,
Message:
Committed patchset #1 manually as r17855.
Description:
Experimental parser: cleanup switch generation
[email protected]
BUG=
Committed: https://code.google.com/p/v8/source/detail?r=17855
Please review this at https://codereview.chromium.org/59983005/
SVN Base: https://v8.googlecode.com/svn/branches/experimental/parser
Affected files (+22, -18 lines):
M tools/lexer_generator/code_generator.jinja
M tools/lexer_generator/code_generator.py
Index: tools/lexer_generator/code_generator.jinja
diff --git a/tools/lexer_generator/code_generator.jinja
b/tools/lexer_generator/code_generator.jinja
index
fb5d8ea2986f961ef10a6a0aa3d7c2c87091db14..acc2262b0c513ac435f2ed3af685142a96b79a71
100644
--- a/tools/lexer_generator/code_generator.jinja
+++ b/tools/lexer_generator/code_generator.jinja
@@ -83,30 +83,32 @@
fprintf(stderr, "char at hand is %c (%d)\n", yych, yych);
{% endif -%}
+ {%- macro do_transition(transition_state_id) -%}
+ {%- set inline_transition =
dfa_states[transition_state_id]['inline'] %}
+ FORWARD();
+ {%- if inline_transition %}
+ {{ do_dfa_state(transition_state_id, True) }}
+ {% else %}
+ goto code_{{transition_state_id}};
+ {% endif %}
+ {%- endmacro -%}
+
{%- if state['switch_transitions'] -%}
switch(yych) {
- {%- for key, transition_state_id in state['switch_transitions'] %}
- case {{key}}:
- {%- set inline_transition =
dfa_states[transition_state_id]['inline'] %}
- FORWARD();
- {%- if inline_transition %}
- {{ do_dfa_state(transition_state_id, True) }}
- {% else %}
- goto code_{{transition_state_id}};
- {% endif %}
+ {%- for ranges, transition_state_id in state['switch_transitions'] %}
+ {%- for r in ranges -%}
+ {%- for key in range(r[0], r[1] + 1) -%}
+ case {{key}}:
+ {% endfor %}
+ {%- endfor -%}
+ {{ do_transition(transition_state_id) }}
{% endfor -%}
}
{%- endif -%}
{%- for key, transition_state_id in state.transitions %}
if ({{do_key(key)}}) {
- {%- set inline_transition =
dfa_states[transition_state_id]['inline'] %}
- FORWARD();
- {%- if inline_transition %}
- {{ do_dfa_state(transition_state_id, True) }}
- {% else %}
- goto code_{{transition_state_id}};
- {% endif %}
+ {{ do_transition(transition_state_id) }}
}
{% endfor -%}
Index: tools/lexer_generator/code_generator.py
diff --git a/tools/lexer_generator/code_generator.py
b/tools/lexer_generator/code_generator.py
index
42a990e60e9d09df02b667fbcc40d2b66c47806d..39129989cac49c26dbdba1f708799b1df0ed40ed
100644
--- a/tools/lexer_generator/code_generator.py
+++ b/tools/lexer_generator/code_generator.py
@@ -164,14 +164,16 @@ class CodeGenerator:
if_transitions = []
for (ranges, node_id) in state['transitions']:
i = []
+ s = []
for r in ranges:
if r[0] == 'CLASS':
i.append(r)
else:
- for x in range(r[1][0], r[1][1] + 1):
- switch_transitions.append((x, node_id))
+ s.append(r[1])
if i:
if_transitions.append((i, node_id))
+ if s:
+ switch_transitions.append((s, node_id))
state['transitions'] = if_transitions
state['switch_transitions'] = switch_transitions
return split_count + 1
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.