Revision: 17855
Author:   [email protected]
Date:     Tue Nov 19 08:17:07 2013 UTC
Log:      Experimental parser: cleanup switch generation

[email protected]

BUG=

Review URL: https://codereview.chromium.org/59983005
http://code.google.com/p/v8/source/detail?r=17855

Modified:
 /branches/experimental/parser/tools/lexer_generator/code_generator.jinja
 /branches/experimental/parser/tools/lexer_generator/code_generator.py

=======================================
--- /branches/experimental/parser/tools/lexer_generator/code_generator.jinja Mon Nov 18 20:02:55 2013 UTC +++ /branches/experimental/parser/tools/lexer_generator/code_generator.jinja Tue Nov 19 08:17:07 2013 UTC
@@ -82,31 +82,33 @@
   {%- if debug_print %}
     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 -%}

=======================================
--- /branches/experimental/parser/tools/lexer_generator/code_generator.py Mon Nov 18 20:02:55 2013 UTC +++ /branches/experimental/parser/tools/lexer_generator/code_generator.py Tue Nov 19 08:17:07 2013 UTC
@@ -164,14 +164,16 @@
     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.

Reply via email to