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

Side by Side Diff: tools/lexer_generator/code_generator.jinja

Issue 75513002: Experimental parser: inline rules (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/lexer_generator/code_generator.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "lexer/even-more-experimental-scanner.h" 1 #include "lexer/even-more-experimental-scanner.h"
2 2
3 3
4 {# TODO implement CLASS checks #} 4 {# TODO implement CLASS checks #}
5 {%- macro do_key(key) -%} 5 {%- macro do_key(key) -%}
6 {%- for r in key.range_iter() -%} 6 {%- for r in key.range_iter() -%}
7 {%- if not loop.first %} || {% endif -%} 7 {%- if not loop.first %} || {% endif -%}
8 {%- if r[0] == 'LATIN_1' -%} 8 {%- if r[0] == 'LATIN_1' -%}
9 {%- if r[1][0] == r[1][1] -%} 9 {%- if r[1][0] == r[1][1] -%}
10 yych == {{r[1][0]}} 10 yych == {{r[1][0]}}
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 {% elif type == 'push_token' %} 46 {% elif type == 'push_token' %}
47 PUSH_TOKEN(Token::{{value}}) 47 PUSH_TOKEN(Token::{{value}})
48 {% elif type == 'push_token_and_go_forward' %} 48 {% elif type == 'push_token_and_go_forward' %}
49 PUSH_TOKEN_AND_GO_FORWARD(Token::{{value}}) 49 PUSH_TOKEN_AND_GO_FORWARD(Token::{{value}})
50 {% else %} 50 {% else %}
51 uncompilable code for {{type}} 51 uncompilable code for {{type}}
52 {% endif -%} 52 {% endif -%}
53 {%- endmacro -%} 53 {%- endmacro -%}
54 54
55 55
56 {%- macro do_dfa_state(state) -%} 56 {%- macro do_dfa_state(node_number, inline) -%}
57 57
58 {%- if start_node_number == state.node_number %} 58 {%- set state = dfa_states[node_number] -%}
59 code_start: 59
60 {% else %} 60 {%- if not inline -%}
61 code_{{state.node_number}}: 61 {%- if state['inline'] -%}
62 {% endif %} 62 bad generated code for {{node_number}}
63 {%- endif -%}
64 {%- if start_node_number == node_number -%}
65 code_start:
66 {%- else -%}
67 code_{{node_number}}:
68 {%- endif -%}
69 {%- else -%}
70 // inlined state {{node_number}}
71 {%- endif %}
63 72
64 {% if debug_print %} 73 {% if debug_print %}
65 fprintf(stderr, "state {{state.node_number}}\n"); 74 fprintf(stderr, "state {{state.node_number}}\n");
66 {% endif -%} 75 {% endif -%}
67 76
68 {%- set entry_action = state.entry_action -%} 77 {%- set entry_action = state.entry_action -%}
69 {%- if entry_action %} 78 {%- if entry_action %}
70 {{ dispatch_action(entry_action[0], entry_action[1]) }} 79 {{ dispatch_action(entry_action[0], entry_action[1]) }}
71 {%- endif %} 80 {%- endif %}
72 81
73 {%- if debug_print %} 82 {%- if debug_print %}
74 fprintf(stderr, "char at hand is %c (%d)\n", yych, yych); 83 fprintf(stderr, "char at hand is %c (%d)\n", yych, yych);
75 {% endif %} 84 {% endif -%}
76 85
77 // matchers 86 {%- for key, transition_state_id in state.transitions %}
78 {%- for match_key, match_state in state.transitions %} 87 {%- set inline_transition = dfa_states[transition_state_id]['inline'] -%}
79 if ({{do_key(match_key)}}) { 88 if ({{do_key(key)}}) {
80 FORWARD(); 89 FORWARD();
81 goto code_{{match_state}}; 90 {%- if inline_transition %}
91 {{ do_dfa_state(transition_state_id, True) }}
92 {% else %}
93 goto code_{{transition_state_id}};
94 {% endif %}
82 } 95 }
83 {% endfor -%} 96 {% endfor -%}
84 97
85 {%- set match_action = state.match_action -%} 98 {%- set match_action = state.match_action -%}
86 99
87 {%- if match_action %} 100 {%- if match_action %}
88 {{ dispatch_action(match_action[0], match_action[1]) }} 101 {{ dispatch_action(match_action[0], match_action[1]) }}
89 goto code_start; 102 goto code_start;
90 {% else %} 103 {% else %}
91 goto default_action; 104 goto default_action;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 148
136 namespace v8 { 149 namespace v8 {
137 namespace internal { 150 namespace internal {
138 Token::Value EvenMoreExperimentalScanner::Next(int* beg_pos_to_return, 151 Token::Value EvenMoreExperimentalScanner::Next(int* beg_pos_to_return,
139 int* end_pos_to_return) { 152 int* end_pos_to_return) {
140 // Setup environment. 153 // Setup environment.
141 YYCTYPE yych = *cursor_; 154 YYCTYPE yych = *cursor_;
142 155
143 {# first node is start node #} 156 {# first node is start node #}
144 {% for dfa_state in dfa_states -%} 157 {% for dfa_state in dfa_states -%}
145 {{ do_dfa_state(dfa_state) }} 158 {%- set inline = dfa_state['inline'] -%}
159 {%- if not inline %}
160 {{ do_dfa_state(dfa_state['node_number'], False) }}
161 {%- endif -%}
146 {%- endfor %} 162 {%- endfor %}
147 163
148 // Should never fall off the edge. 164 // Should never fall off the edge.
149 goto fell_through; 165 goto fell_through;
150 // Execute the default action. 166 // Execute the default action.
151 default_action: 167 default_action:
152 {%- if debug_print %} 168 {%- if debug_print %}
153 fprintf(stderr, "default action\n"); 169 fprintf(stderr, "default action\n");
154 {% endif -%} 170 {% endif -%}
155 {{dispatch_action(default_action[0], default_action[1])}} 171 {{dispatch_action(default_action[0], default_action[1])}}
156 FORWARD(); 172 FORWARD();
157 goto code_start; 173 goto code_start;
158 174
159 fell_through: 175 fell_through:
160 CHECK(false); 176 CHECK(false);
161 } 177 }
162 } } 178 } }
163 179
OLDNEW
« no previous file with comments | « no previous file | tools/lexer_generator/code_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698