| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 | 68 |
| 69 {#- entry actions must not change the value of the cursor | 69 {#- entry actions must not change the value of the cursor |
| 70 unless they jump -#} | 70 unless they jump -#} |
| 71 {% macro dispatch_entry_action(type, value) -%} | 71 {% macro dispatch_entry_action(type, value) -%} |
| 72 {% if type == 'store_token' %} | 72 {% if type == 'store_token' %} |
| 73 stored_token = Token::{{value}}; | 73 stored_token = Token::{{value}}; |
| 74 {% elif type == 'set_marker' %} | 74 {% elif type == 'set_marker' %} |
| 75 marker_ = cursor_ - {{value}}; | 75 marker_ = cursor_ - {{value}}; |
| 76 {% elif type == 'set_has_escapes' %} | 76 {% elif type == 'set_has_escapes' %} |
| 77 next_.has_escapes = true; | 77 next_.has_escapes = true; |
| 78 {% elif type == 'octal_inside_string' %} | 78 {% elif type == 'octal_inside_string' %} |
| 79 last_octal_end_ = cursor_; | 79 last_octal_end_ = cursor_; |
| 80 next_.has_escapes = true; | 80 next_.has_escapes = true; |
| 81 {% elif type == 'line_terminator_in_multiline_comment' %} | 81 {% elif type == 'line_terminator_in_multiline_comment' %} |
| 82 has_multiline_comment_before_next_ = true; | 82 has_multiline_comment_before_next_ = true; |
| 83 {% elif type == 'check_escaped_identifier_start' %} | 83 {% elif type == 'check_escaped_identifier_start' %} |
| 84 if (!ValidIdentifierStart()) goto default_action; | 84 if (!ValidIdentifierStart()) goto default_action; |
| 85 next_.has_escapes = true; | 85 next_.has_escapes = true; |
| 86 {% elif type == 'check_escaped_identifier_part' %} | 86 {% elif type == 'check_escaped_identifier_part' %} |
| 87 if (!ValidIdentifierPart()) goto default_action; | 87 if (!ValidIdentifierPart()) goto default_action; |
| 88 next_.has_escapes = true; | 88 next_.has_escapes = true; |
| 89 {% elif type == 'if_line_terminator_backtrack' %} | 89 {% elif type == 'if_line_terminator_backtrack' %} |
| 90 if (!has_line_terminator_before_next_) { | 90 if (!has_line_terminator_before_next_) { |
| 91 {{dispatch_match_action('backtrack', value)}} | 91 {{dispatch_match_action('backtrack', value)}} |
| 92 } | 92 } |
| 93 {% else %} | 93 {% else %} |
| 94 uncompilable code for {{type}} {{value}} | 94 uncompilable code for {{type}} {{value}} |
| 95 {% endif -%} | 95 {% endif -%} |
| 96 {%- endmacro -%} | 96 {%- endmacro -%} |
| 97 | 97 |
| 98 | 98 |
| 99 {#- match actions must all explicitly jump or return -#} | 99 {#- match actions must all explicitly jump or return -#} |
| 100 {% macro dispatch_match_action(type, value) -%} | 100 {% macro dispatch_match_action(type, value) -%} |
| 101 {% if type == 'terminate' %} | 101 {% if type == 'terminate' %} |
| 102 DO_EOS(); | 102 {{dispatch_match_action('backtrack', ('1', 'EOS'))}} |
| 103 return; | |
| 104 {% elif type == 'terminate_illegal' %} | 103 {% elif type == 'terminate_illegal' %} |
| 105 start_ = marker_; | 104 start_ = marker_; |
| 106 BACKWARD(1); | 105 {{dispatch_match_action('backtrack', ('1', 'ILLEGAL'))}} |
| 107 DO_TOKEN(Token::ILLEGAL); | |
| 108 return; | |
| 109 {% elif type == 'skip' %} | 106 {% elif type == 'skip' %} |
| 110 SKIP(); | 107 RESET_START(); |
| 111 goto state_entry_0; | 108 goto state_entry_0; |
| 112 {% elif type == 'skip_and_terminate' %} | 109 {% elif type == 'skip_and_terminate' %} |
| 113 SKIP(); | 110 RESET_START(); |
| 114 --start_; | 111 --start_; |
| 115 {{dispatch_match_action('terminate', None)}} | 112 {{dispatch_match_action('terminate', None)}} |
| 116 {% elif type == 'line_terminator' %} | 113 {% elif type == 'line_terminator' %} |
| 117 DO_LINE_TERMINATOR(); | 114 RESET_START(); |
| 115 has_line_terminator_before_next_ = true; |
| 118 goto state_entry_0; | 116 goto state_entry_0; |
| 119 {% elif type == 'token' %} | 117 {% elif type == 'token' %} |
| 120 DO_TOKEN(Token::{{value}}) | 118 DO_TOKEN(Token::{{value}}) |
| 121 return; | 119 return; |
| 122 {% elif type == 'goto_start' %} | 120 {% elif type == 'goto_start' %} |
| 123 goto state_entry_{{value[0]}}; | 121 goto state_entry_{{value[0]}}; |
| 124 {% elif type == 'store_token_and_goto' %} | 122 {% elif type == 'store_token_and_goto' %} |
| 125 stored_token = Token::{{value[0]}}; | 123 stored_token = Token::{{value[0]}}; |
| 126 goto after_entry_code_{{value[1]}}; | 124 goto after_entry_code_{{value[1]}}; |
| 127 {% elif type == 'do_stored_token' %} | 125 {% elif type == 'do_stored_token' %} |
| 128 DO_TOKEN(stored_token) | 126 DO_TOKEN(stored_token) |
| 129 return; | 127 return; |
| 130 {% elif type == 'do_token_and_go_forward' %} | 128 {% elif type == 'do_token_and_go_forward' %} |
| 131 DO_TOKEN_AND_GO_FORWARD(Token::{{value}}) | 129 DO_TOKEN(Token::{{value}}); |
| 130 FORWARD(); |
| 131 RESET_START(); |
| 132 return; | 132 return; |
| 133 {% elif type == 'harmony_token' %} | 133 {% elif type == 'harmony_token' %} |
| 134 if (harmony_{{value[0]}}_) { | 134 if (harmony_{{value[0]}}_) { |
| 135 DO_TOKEN(Token::{{value[1]}}); | 135 DO_TOKEN(Token::{{value[1]}}); |
| 136 } else { | 136 } else { |
| 137 DO_TOKEN(Token::{{value[2]}}); | 137 DO_TOKEN(Token::{{value[2]}}); |
| 138 } | 138 } |
| 139 return; | 139 return; |
| 140 {% elif type == 'store_harmony_token_and_goto' %} | 140 {% elif type == 'store_harmony_token_and_goto' %} |
| 141 if (harmony_{{value[0]}}_) { | 141 if (harmony_{{value[0]}}_) { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 {{ dispatch_match_action(match_action[0], match_action[1]) }} | 275 {{ dispatch_match_action(match_action[0], match_action[1]) }} |
| 276 CRASH(); | 276 CRASH(); |
| 277 {% else %} | 277 {% else %} |
| 278 goto default_action; | 278 goto default_action; |
| 279 {%- endif %} | 279 {%- endif %} |
| 280 | 280 |
| 281 {%- endmacro %} | 281 {%- endmacro %} |
| 282 | 282 |
| 283 #include "lexer/experimental-scanner.h" | 283 #include "lexer/experimental-scanner.h" |
| 284 | 284 |
| 285 #define PREPARE_TOKEN() { \ | 285 #define RESET_START() { \ |
| 286 next_.beg_pos = start_ - buffer_; \ | |
| 287 next_.end_pos = cursor_ - buffer_; \ | |
| 288 start_ = cursor_; \ | 286 start_ = cursor_; \ |
| 289 } | 287 } |
| 290 | 288 |
| 291 #define DO_TOKEN(T) { \ | 289 #define DO_TOKEN(T) { \ |
| 292 PREPARE_TOKEN(); \ | 290 next_.beg_pos = start_ - buffer_; \ |
| 291 next_.end_pos = cursor_ - buffer_; \ |
| 293 next_.token = T; \ | 292 next_.token = T; \ |
| 294 } | 293 RESET_START(); \ |
| 295 | |
| 296 #define DO_TOKEN_AND_GO_FORWARD(T) { \ | |
| 297 PREPARE_TOKEN(); \ | |
| 298 FORWARD(); \ | |
| 299 next_.token = T; \ | |
| 300 start_ = cursor_; \ | |
| 301 } | |
| 302 | |
| 303 #define DO_EOS() { \ | |
| 304 cursor_ -= 1; \ | |
| 305 DO_TOKEN(Token::EOS); \ | |
| 306 } | |
| 307 | |
| 308 #define DO_LINE_TERMINATOR(s) { \ | |
| 309 start_ = cursor_; \ | |
| 310 has_line_terminator_before_next_ = true; \ | |
| 311 } | 294 } |
| 312 | 295 |
| 313 #define FORWARD() { \ | 296 #define FORWARD() { \ |
| 314 if (++cursor_ >= buffer_end_) primary_char = 0; \ | 297 cursor_++; \ |
| 315 else primary_char = *(cursor_); \ | 298 READ_CURSOR(); \ |
| 316 } | 299 } |
| 317 | 300 |
| 318 #define BACKWARD(n) { \ | 301 #define BACKWARD(n) { \ |
| 319 cursor_ -= n; \ | 302 cursor_ -= n; \ |
| 303 READ_CURSOR(); \ |
| 304 } |
| 305 |
| 306 #define READ_CURSOR() { \ |
| 320 if (cursor_ >= buffer_end_) primary_char = 0; \ | 307 if (cursor_ >= buffer_end_) primary_char = 0; \ |
| 321 else primary_char = *(cursor_); \ | 308 else primary_char = *(cursor_); \ |
| 322 } | 309 } |
| 323 | 310 |
| 324 #define SKIP() { \ | |
| 325 start_ = cursor_; \ | |
| 326 } | |
| 327 | |
| 328 #ifdef DEBUG | 311 #ifdef DEBUG |
| 329 #define CRASH() { ((void(*)())0)(); } | 312 #define CRASH() { ((void(*)())0)(); } |
| 330 #else | 313 #else |
| 331 #define CRASH() { } | 314 #define CRASH() { } |
| 332 #endif | 315 #endif |
| 333 | 316 |
| 334 namespace v8 { | 317 namespace v8 { |
| 335 namespace internal { | 318 namespace internal { |
| 336 template<> | 319 template<> |
| 337 void ExperimentalScanner<{{char_type}}>::Scan() { | 320 void ExperimentalScanner<{{char_type}}>::Scan() { |
| 321 |
| 322 // Setup environment. |
| 338 next_.has_escapes = false; | 323 next_.has_escapes = false; |
| 339 // Setup environment. | |
| 340 Token::Value stored_token; | 324 Token::Value stored_token; |
| 341 {{char_type}} primary_char; | 325 {{char_type}} primary_char; |
| 342 if (cursor_ >= buffer_end_) primary_char = 0; | 326 READ_CURSOR(); |
| 343 else primary_char = *(cursor_); | |
| 344 | 327 |
| 345 {# first node is start node #} | 328 {# first node is start node #} |
| 346 {% for dfa_state in dfa_states -%} | 329 {% for dfa_state in dfa_states -%} |
| 347 {%- if not dfa_state['inline'] %} | 330 {%- if not dfa_state['inline'] %} |
| 348 {{ do_dfa_state([dfa_state['node_number']]) }} | 331 {{ do_dfa_state([dfa_state['node_number']]) }} |
| 349 {%- endif -%} | 332 {%- endif -%} |
| 350 {%- endfor %} | 333 {%- endfor %} |
| 351 | 334 |
| 352 // Execute the default action. | 335 // Execute the default action. |
| 353 default_action: | 336 default_action: |
| 354 {%- if debug_print %} | 337 {%- if debug_print %} |
| 355 fprintf(stderr, "default action\n"); | 338 fprintf(stderr, "default action\n"); |
| 356 {% endif -%} | 339 {% endif -%} |
| 357 {{dispatch_match_action(default_action[0], default_action[1])}} | 340 {{dispatch_match_action(default_action[0], default_action[1])}} |
| 358 CRASH(); | 341 CRASH(); |
| 359 | 342 |
| 360 if (false) { | 343 if (false) { |
| 361 // force use of stored_token | 344 // force use of stored_token |
| 362 stored_token = Token::ILLEGAL; | 345 stored_token = Token::ILLEGAL; |
| 363 // force use of state_entry_0 | 346 // force use of state_entry_0 |
| 364 goto state_entry_0; | 347 goto state_entry_0; |
| 365 } | 348 } |
| 366 } | 349 } |
| 367 } } | 350 } } |
| 368 | 351 |
| OLD | NEW |