| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 {%- endif -%} | 61 {%- endif -%} |
| 62 {%- endfor -%} | 62 {%- endfor -%} |
| 63 {%- endmacro -%} | 63 {%- endmacro -%} |
| 64 | 64 |
| 65 | 65 |
| 66 {#- entry actions must not change the value of the cursor | 66 {#- entry actions must not change the value of the cursor |
| 67 unless they jump -#} | 67 unless they jump -#} |
| 68 {% macro dispatch_entry_action(type, args) -%} | 68 {% macro dispatch_entry_action(type, args) -%} |
| 69 {% if type == 'store_token' %} | 69 {% if type == 'store_token' %} |
| 70 stored_token = Token::{{args[0]}}; | 70 stored_token = Token::{{args[0]}}; |
| 71 {% elif type == 'no_op' %} |
| 72 {# TODO(dcarney): remove #} |
| 71 {% elif type == 'set_marker' %} | 73 {% elif type == 'set_marker' %} |
| 72 marker = cursor_ - {{args[0]}}; | 74 marker = cursor_ - {{args[0]}}; |
| 73 {% elif type == 'set_has_escapes' %} | 75 {% elif type == 'set_has_escapes' %} |
| 74 next_.has_escapes = true; | 76 next_.has_escapes = true; |
| 75 {% elif type == 'octal_inside_string' %} | 77 {% elif type == 'octal_inside_string' %} |
| 76 last_octal_end_ = cursor_; | 78 last_octal_end_ = cursor_; |
| 77 next_.has_escapes = true; | 79 next_.has_escapes = true; |
| 78 {% elif type == 'line_terminator_in_multiline_comment' %} | 80 {% elif type == 'line_terminator_in_multiline_comment' %} |
| 79 has_multiline_comment_before_next_ = true; | 81 has_multiline_comment_before_next_ = true; |
| 82 {% elif type == 'store_token' %} |
| 83 stored_token = Token::{{args[0]}}; |
| 84 {% elif type == 'store_harmony_token' %} |
| 85 if (harmony_{{args[0]}}_) { |
| 86 stored_token = Token::{{args[1]}}; |
| 87 } else { |
| 88 stored_token = Token::{{args[2]}}; |
| 89 } |
| 80 {% elif type == 'check_escaped_identifier_start' %} | 90 {% elif type == 'check_escaped_identifier_start' %} |
| 81 if (!ValidIdentifierStart()) goto default_action; | 91 if (!ValidIdentifierStart()) goto default_action; |
| 82 next_.has_escapes = true; | 92 next_.has_escapes = true; |
| 83 {% elif type == 'check_escaped_identifier_part' %} | 93 {% elif type == 'check_escaped_identifier_part' %} |
| 84 if (!ValidIdentifierPart()) goto default_action; | 94 if (!ValidIdentifierPart()) goto default_action; |
| 85 next_.has_escapes = true; | 95 next_.has_escapes = true; |
| 86 {% elif type == 'if_line_terminator_backtrack' %} | 96 {% elif type == 'if_line_terminator_backtrack' %} |
| 87 if (!has_line_terminator_before_next_) { | 97 if (!has_line_terminator_before_next_) { |
| 88 {{dispatch_match_action('backtrack', args)}} | 98 {{dispatch_match_action('backtrack', args)}} |
| 89 } | 99 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 113 {% elif type == 'line_terminator' %} | 123 {% elif type == 'line_terminator' %} |
| 114 RESET_START(); | 124 RESET_START(); |
| 115 {%- if encoding == 'utf16'-%} | 125 {%- if encoding == 'utf16'-%} |
| 116 next_.is_onebyte = true; | 126 next_.is_onebyte = true; |
| 117 {%- endif -%} | 127 {%- endif -%} |
| 118 has_line_terminator_before_next_ = true; | 128 has_line_terminator_before_next_ = true; |
| 119 goto state_entry_0; | 129 goto state_entry_0; |
| 120 {% elif type == 'token' %} | 130 {% elif type == 'token' %} |
| 121 DO_TOKEN(Token::{{args[0]}}) | 131 DO_TOKEN(Token::{{args[0]}}) |
| 122 return; | 132 return; |
| 123 {% elif type == 'goto_start' %} | |
| 124 {{ jump(args[0]|int) }} | |
| 125 {% elif type == 'store_token_and_goto' %} | |
| 126 stored_token = Token::{{args[0]}}; | |
| 127 {{ jump(args[1]|int) }} | |
| 128 {% elif type == 'do_stored_token' %} | 133 {% elif type == 'do_stored_token' %} |
| 129 DO_TOKEN(stored_token) | 134 DO_TOKEN(stored_token) |
| 130 return; | 135 return; |
| 131 {% elif type == 'do_token_and_go_forward' %} | 136 {% elif type == 'do_token_and_go_forward' %} |
| 132 DO_TOKEN(Token::{{args[0]}}); | 137 DO_TOKEN(Token::{{args[0]}}); |
| 133 FORWARD(); | 138 FORWARD(); |
| 134 RESET_START(); | 139 RESET_START(); |
| 135 return; | 140 return; |
| 136 {% elif type == 'harmony_token' %} | 141 {% elif type == 'harmony_token' %} |
| 137 if (harmony_{{args[0]}}_) { | 142 if (harmony_{{args[0]}}_) { |
| 138 DO_TOKEN(Token::{{args[1]}}); | 143 DO_TOKEN(Token::{{args[1]}}); |
| 139 } else { | 144 } else { |
| 140 DO_TOKEN(Token::{{args[2]}}); | 145 DO_TOKEN(Token::{{args[2]}}); |
| 141 } | 146 } |
| 142 return; | 147 return; |
| 143 {% elif type == 'store_harmony_token_and_goto' %} | |
| 144 if (harmony_{{args[0]}}_) { | |
| 145 stored_token = Token::{{args[1]}}; | |
| 146 } else { | |
| 147 stored_token = Token::{{args[2]}}; | |
| 148 } | |
| 149 {{ jump(args[3]|int) }} | |
| 150 {% elif type == 'octal_number' %} | 148 {% elif type == 'octal_number' %} |
| 151 last_octal_end_ = cursor_; | 149 last_octal_end_ = cursor_; |
| 152 DO_TOKEN(Token::NUMBER); | 150 DO_TOKEN(Token::NUMBER); |
| 153 return; | 151 return; |
| 154 {% elif type == 'backtrack' %} | 152 {% elif type == 'backtrack' %} |
| 155 BACKWARD({{args[0]}}); | 153 BACKWARD({{args[0]}}); |
| 156 DO_TOKEN(Token::{{args[1]}}); | 154 DO_TOKEN(Token::{{args[1]}}); |
| 157 return; | 155 return; |
| 158 {% else %} | 156 {% else %} |
| 159 uncompilable code for {{type}} {{args}} | 157 uncompilable code for {{type}} {{args}} |
| (...skipping 25 matching lines...) Expand all Loading... |
| 185 {%- else -%} | 183 {%- else -%} |
| 186 uncompilable code for {{encoding}} | 184 uncompilable code for {{encoding}} |
| 187 {%- endif -%} | 185 {%- endif -%} |
| 188 {%- endmacro -%} | 186 {%- endmacro -%} |
| 189 | 187 |
| 190 | 188 |
| 191 {%- macro write_label(label_name, node_number) %} | 189 {%- macro write_label(label_name, node_number) %} |
| 192 {%- set state = dfa_states[node_number] -%} | 190 {%- set state = dfa_states[node_number] -%} |
| 193 {%- set used = state['entry_points'][label_name] -%} | 191 {%- set used = state['entry_points'][label_name] -%} |
| 194 {%- set long_label = label_name ~ '_' ~ node_number -%} | 192 {%- set long_label = label_name ~ '_' ~ node_number -%} |
| 193 {%- set inlined = 'inlined' if state['inline'] else 'not inlined' -%} |
| 195 {% if used -%} | 194 {% if used -%} |
| 196 {{long_label}}: | 195 {{long_label}}: // {{inlined}} |
| 197 {%- else -%} | 196 {%- else -%} |
| 198 // {{long_label}}: | 197 // {{long_label}}: {{inlined}} |
| 199 {%- endif %} | 198 {%- endif %} |
| 200 {% endmacro -%} | 199 {% endmacro -%} |
| 201 | 200 |
| 202 | 201 |
| 203 {%- macro do_dfa_state(node_number) -%} | 202 {%- macro do_dfa_state(node_number) -%} |
| 204 | 203 |
| 205 {%- set state = dfa_states[node_number] -%} | 204 {%- set state = dfa_states[node_number] -%} |
| 206 | 205 |
| 207 {{ write_label('state_entry', node_number) }} | 206 {{ write_label('state_entry', node_number) }} |
| 208 | 207 |
| 209 {% if not state['can_elide_read'] -%} | 208 {% if not state['elide_read'] -%} |
| 210 READ_CURSOR(); | 209 READ_CURSOR(); |
| 211 {%- endif -%} | 210 {%- endif -%} |
| 212 | 211 |
| 213 {% if debug_print %} | 212 {% if debug_print %} |
| 214 fprintf(stderr, | 213 fprintf(stderr, |
| 215 "state {{state.node_number}}, start %d, cursor %d\n", | 214 "state {{state.node_number}}, start %d, cursor %d\n", |
| 216 start_ - buffer_, | 215 start_ - buffer_, |
| 217 cursor_ - buffer_); | 216 cursor_ - buffer_); |
| 218 {% endif -%} | 217 {% endif -%} |
| 219 | 218 |
| 220 {%- set entry_action = state.entry_action -%} | 219 {%- set action = state['action'].term() -%} |
| 221 {%- if entry_action %} | 220 {%- if action %} |
| 222 {{ dispatch_entry_action(entry_action.name(), entry_action.args()) }} | 221 {%- if not state['total_transitions'] -%} |
| 222 {{ dispatch_match_action(action.name(), action.args()) }} |
| 223 {%- else -%} |
| 224 {{ dispatch_entry_action(action.name(), action.args()) }} |
| 225 {%- endif -%} |
| 223 {%- endif %} | 226 {%- endif %} |
| 224 | 227 |
| 225 {{ write_label('after_entry_code', node_number) }} | 228 {{ write_label('after_entry_code', node_number) }} |
| 226 | 229 |
| 227 {%- if debug_print %} | 230 {%- if debug_print %} |
| 228 fprintf(stderr, "char at hand is %c (%d)\n", primary_char, primary_char); | 231 fprintf(stderr, "char at hand is %c (%d)\n", primary_char, primary_char); |
| 229 {% endif -%} | 232 {% endif -%} |
| 230 | 233 |
| 231 {%- macro do_transition(jump_id) -%} | 234 {%- macro do_transition(jump_id, do_forward = True) -%} |
| 232 {%- set transition_state_id = jump_table[jump_id][0] -%} | 235 {%- set transition_state_id = jump_table[jump_id][0] -%} |
| 233 {%- set inline_transition = jump_table[jump_id][1] == 'inline' %} | 236 {%- set inline_transition = jump_table[jump_id][1] == 'inline' %} |
| 234 FORWARD(); | 237 {%- if do_forward %} |
| 238 FORWARD(); |
| 239 {% endif %} |
| 235 {%- if inline_transition %} | 240 {%- if inline_transition %} |
| 236 {{ do_dfa_state(transition_state_id) }} | 241 {{ do_dfa_state(transition_state_id) }} |
| 237 {% else %} | 242 {% else %} |
| 238 {{ jump(jump_id) }} | 243 {{ jump(jump_id) }} |
| 239 {% endif %} | 244 {% endif %} |
| 240 {%- endmacro -%} | 245 {%- endmacro -%} |
| 241 | 246 |
| 242 {%- if state['switch_transitions'] -%} | 247 {%- if state['switch_transitions'] -%} |
| 243 switch(primary_char) { | 248 switch(primary_char) { |
| 244 {%- for ranges, jump_id in state['switch_transitions'] %} | 249 {%- for ranges, jump_id in state['switch_transitions'] %} |
| (...skipping 25 matching lines...) Expand all Loading... |
| 270 next_.is_onebyte = false; | 275 next_.is_onebyte = false; |
| 271 {{long_char_create()}} | 276 {{long_char_create()}} |
| 272 {%- for key, jump_id in state['deferred_transitions'] %} | 277 {%- for key, jump_id in state['deferred_transitions'] %} |
| 273 if ({{do_key(key)}}) { // long_char transition | 278 if ({{do_key(key)}}) { // long_char transition |
| 274 {{ do_transition(jump_id) }} | 279 {{ do_transition(jump_id) }} |
| 275 } | 280 } |
| 276 {% endfor -%} | 281 {% endfor -%} |
| 277 } | 282 } |
| 278 {%- endif -%} | 283 {%- endif -%} |
| 279 | 284 |
| 280 {%- set match_action = state.match_action -%} | 285 {%- if state['omega_transition'] %} |
| 281 {%- if match_action %} | 286 {{ do_transition(state['omega_transition'], False) }} |
| 282 {{ dispatch_match_action(match_action.name(), match_action.args()) }} | 287 {%- endif -%} |
| 283 CRASH(); | 288 |
| 284 {% else %} | 289 goto default_action; {# this is wrong, should be CRASH(); #} |
| 285 goto default_action; | |
| 286 {%- endif %} | |
| 287 | 290 |
| 288 {%- endmacro %} | 291 {%- endmacro %} |
| 289 | 292 |
| 290 #include "lexer/experimental-scanner.h" | 293 #include "lexer/experimental-scanner.h" |
| 291 | 294 |
| 292 #define RESET_START() { \ | 295 #define RESET_START() { \ |
| 293 start_ = cursor_; \ | 296 start_ = cursor_; \ |
| 294 } | 297 } |
| 295 | 298 |
| 296 #define DO_TOKEN(T) { \ | 299 #define DO_TOKEN(T) { \ |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 {%- if not dfa_state['inline'] %} | 339 {%- if not dfa_state['inline'] %} |
| 337 {{ do_dfa_state(dfa_state['node_number']) }} | 340 {{ do_dfa_state(dfa_state['node_number']) }} |
| 338 {%- endif -%} | 341 {%- endif -%} |
| 339 {%- endfor %} | 342 {%- endfor %} |
| 340 | 343 |
| 341 // Execute the default action. | 344 // Execute the default action. |
| 342 default_action: | 345 default_action: |
| 343 {%- if debug_print %} | 346 {%- if debug_print %} |
| 344 fprintf(stderr, "default action\n"); | 347 fprintf(stderr, "default action\n"); |
| 345 {% endif -%} | 348 {% endif -%} |
| 346 {{dispatch_match_action(default_action.name(), default_action.args())}} | 349 {%- set action = default_action.term() -%} |
| 350 {{dispatch_match_action(action.name(), action.args())}} |
| 347 CRASH(); | 351 CRASH(); |
| 348 | 352 |
| 349 if (false) { | 353 if (false) { |
| 350 // force use of stored_token | 354 // force use of stored_token |
| 351 stored_token = Token::ILLEGAL; | 355 stored_token = Token::ILLEGAL; |
| 352 // force use of marker | 356 // force use of marker |
| 353 marker = NULL; | 357 marker = NULL; |
| 354 // force use of state_entry_0 | 358 // force use of state_entry_0 |
| 355 goto state_entry_0; | 359 goto state_entry_0; |
| 356 } | 360 } |
| 357 } | 361 } |
| 358 } } | 362 } } |
| 359 | 363 |
| OLD | NEW |