| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 {%- macro jump(id) -%} | 28 {%- macro jump(id) -%} |
| 29 {%- set node = jump_table[id] -%} | 29 {%- set node = jump_table[id] -%} |
| 30 goto {{ node[1] ~ '_' ~ node[0] }}; | 30 goto {{ node[1] ~ '_' ~ node[0] }}; |
| 31 {%- endmacro -%} | 31 {%- endmacro -%} |
| 32 | 32 |
| 33 {%- macro do_key(key) -%} | 33 {%- macro do_key(key) -%} |
| 34 {%- for r in key -%} | 34 {%- for r in key -%} |
| 35 {%- if not loop.first %} || {% endif -%} | 35 {%- if not loop.first %} || {% endif -%} |
| 36 {%- if r[0] == 'PRIMARY_RANGE' -%} | 36 {%- if r[0] == 'PRIMARY_RANGE' -%} |
| 37 {%- if r[1][0] == r[1][1] -%} | 37 {%- if r[1][0] == r[1][1] and r[1][0] != 0 -%} |
| 38 primary_char == {{r[1][0]}} | 38 primary_char == {{r[1][0]}} |
| 39 {%- elif r[1][0] == r[1][1] -%} |
| 40 (primary_char == 0 && cursor_ < buffer_end_) |
| 39 {%- elif r[1][0] == 0 -%} | 41 {%- elif r[1][0] == 0 -%} |
| 40 primary_char <= {{r[1][1]}} | 42 primary_char <= {{r[1][1]}} |
| 41 {%- elif r[1][1] == upper_bound and not encoding == 'utf16'-%} | 43 {%- elif r[1][1] == upper_bound and not encoding == 'utf16'-%} |
| 42 primary_char >= {{r[1][0]}} | 44 primary_char >= {{r[1][0]}} |
| 43 {%- else -%} | 45 {%- else -%} |
| 44 ({{r[1][0]}} <= primary_char && primary_char <= {{r[1][1]}}) | 46 ({{r[1][0]}} <= primary_char && primary_char <= {{r[1][1]}}) |
| 45 {%- endif -%} | 47 {%- endif -%} |
| 46 {# These classes require long_char and to be outside the primary range #} | 48 {# These classes require long_char and to be outside the primary range #} |
| 47 {%- elif r[0] == 'LONG_CHAR_CLASS' and encoding in ['utf16', 'utf8'] -%} | 49 {%- elif r[0] == 'LONG_CHAR_CLASS' and encoding in ['utf16', 'utf8'] -%} |
| 48 {%- if r[1] == 'byte_order_mark' -%} | 50 {%- if r[1] == 'byte_order_mark' -%} |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 {{ dispatch_entry_action(entry_action[0], entry_action[1]) }} | 224 {{ dispatch_entry_action(entry_action[0], entry_action[1]) }} |
| 223 {%- endif %} | 225 {%- endif %} |
| 224 | 226 |
| 225 {{ write_label('after_entry_code', node_number) }} | 227 {{ write_label('after_entry_code', node_number) }} |
| 226 | 228 |
| 227 {%- if debug_print %} | 229 {%- if debug_print %} |
| 228 fprintf(stderr, "char at hand is %c (%d)\n", primary_char, primary_char); | 230 fprintf(stderr, "char at hand is %c (%d)\n", primary_char, primary_char); |
| 229 {% endif -%} | 231 {% endif -%} |
| 230 | 232 |
| 231 {%- macro do_transition(jump_id) -%} | 233 {%- macro do_transition(jump_id) -%} |
| 234 {%- set transition_state_id = jump_table[jump_id][0] -%} |
| 235 {%- set inline_transition = jump_table[jump_id][1] == 'inline' %} |
| 232 FORWARD(); | 236 FORWARD(); |
| 233 if (cursor_ < buffer_end_) { | 237 {%- if inline_transition %} |
| 234 {%- set transition_state_id = jump_table[jump_id][0] -%} | 238 {{ do_dfa_state(transition_state_id) }} |
| 235 {%- set inline_transition = jump_table[jump_id][1] == 'inline' %} | 239 {% else %} |
| 236 {%- if inline_transition %} | 240 {{ jump(jump_id) }} |
| 237 {{ do_dfa_state(transition_state_id) }} | 241 {% endif %} |
| 238 {% else %} | |
| 239 {{ jump(jump_id) }} | |
| 240 {% endif %} | |
| 241 } | |
| 242 {% if 'eos' in state['unique_transitions'] -%} | |
| 243 {{ jump(state['unique_transitions']['eos']) }} // eos handler | |
| 244 {%- else -%} | |
| 245 BACKWARD(1); | |
| 246 {{ jump(state['jump_before_match']) }} // no eos handler | |
| 247 {%- endif %} | |
| 248 {%- endmacro -%} | 242 {%- endmacro -%} |
| 249 | 243 |
| 250 {%- if state['switch_transitions'] -%} | 244 {%- if state['switch_transitions'] -%} |
| 251 switch(primary_char) { | 245 switch(primary_char) { |
| 252 {%- for ranges, jump_id in state['switch_transitions'] %} | 246 {%- for ranges, jump_id in state['switch_transitions'] %} |
| 253 {%- for r in ranges -%} | 247 {%- for r in ranges -%} |
| 254 {%- for key in range(r[0], r[1] + 1) -%} | 248 {%- for key in range(r[0], r[1] + 1) -%} |
| 255 case {{key}}: | 249 case {{key}}: |
| 256 {% endfor %} | 250 {% endfor %} |
| 257 {%- endfor -%} | 251 {%- endfor -%} |
| 258 {{ do_transition(jump_id) }} | 252 {{ do_transition(jump_id) }} |
| 259 {% endfor -%} | 253 {% endfor -%} |
| 260 } | 254 } |
| 261 {%- endif -%} | 255 {%- endif -%} |
| 262 | 256 |
| 263 {%- for key, jump_id in state['if_transitions'] %} | 257 {%- for key, jump_id in state['if_transitions'] %} |
| 264 if ({{do_key(key)}}) { // normal if transition | 258 if ({{do_key(key)}}) { // normal if transition |
| 265 {{ do_transition(jump_id) }} | 259 {{ do_transition(jump_id) }} |
| 266 } | 260 } |
| 267 {% endfor -%} | 261 {% endfor -%} |
| 268 | 262 |
| 269 {%- if state['deferred_transitions'] -%} | 263 {%- if 'eos' in state['unique_transitions'] %} |
| 264 if (primary_char == 0 && cursor_ >= buffer_end_) { // eos handler |
| 265 {{ jump(state['unique_transitions']['eos']) }} |
| 266 } |
| 267 {%- endif -%} |
| 268 |
| 269 {%- if state['deferred_transitions'] %} |
| 270 if ({{long_char_check()}}) { | 270 if ({{long_char_check()}}) { |
| 271 next_.is_onebyte = false; | 271 next_.is_onebyte = false; |
| 272 {{long_char_create()}} | 272 {{long_char_create()}} |
| 273 {%- for key, jump_id in state['deferred_transitions'] %} | 273 {%- for key, jump_id in state['deferred_transitions'] %} |
| 274 if ({{do_key(key)}}) { // long_char transition | 274 if ({{do_key(key)}}) { // long_char transition |
| 275 {{ do_transition(jump_id) }} | 275 {{ do_transition(jump_id) }} |
| 276 } | 276 } |
| 277 {% endfor -%} | 277 {% endfor -%} |
| 278 } | 278 } |
| 279 {%- endif-%} | 279 {%- endif -%} |
| 280 | |
| 281 {{ write_label('before_match', node_number) }} | |
| 282 | 280 |
| 283 {%- set match_action = state.match_action -%} | 281 {%- set match_action = state.match_action -%} |
| 284 {%- if match_action %} | 282 {%- if match_action %} |
| 285 {{ dispatch_match_action(match_action[0], match_action[1]) }} | 283 {{ dispatch_match_action(match_action[0], match_action[1]) }} |
| 286 CRASH(); | 284 CRASH(); |
| 287 {% else %} | 285 {% else %} |
| 288 goto default_action; | 286 goto default_action; |
| 289 {%- endif %} | 287 {%- endif %} |
| 290 | 288 |
| 291 {%- endmacro %} | 289 {%- endmacro %} |
| (...skipping 13 matching lines...) Expand all Loading... |
| 305 | 303 |
| 306 #define FORWARD() { \ | 304 #define FORWARD() { \ |
| 307 cursor_++; \ | 305 cursor_++; \ |
| 308 } | 306 } |
| 309 | 307 |
| 310 #define BACKWARD(n) { \ | 308 #define BACKWARD(n) { \ |
| 311 cursor_ -= n; \ | 309 cursor_ -= n; \ |
| 312 } | 310 } |
| 313 | 311 |
| 314 #define READ_CURSOR() { \ | 312 #define READ_CURSOR() { \ |
| 315 ASSERT(cursor_ < buffer_end_); \ | 313 if (cursor_ >= buffer_end_) primary_char = 0; \ |
| 316 primary_char = *(cursor_); \ | 314 else primary_char = *(cursor_); \ |
| 317 } | 315 } |
| 318 | 316 |
| 319 #ifdef DEBUG | 317 #ifdef DEBUG |
| 320 #define CRASH() { ((void(*)())0)(); } | 318 #define CRASH() { ((void(*)())0)(); } |
| 321 #else | 319 #else |
| 322 #define CRASH() { } | 320 #define CRASH() { } |
| 323 #endif | 321 #endif |
| 324 | 322 |
| 325 namespace v8 { | 323 namespace v8 { |
| 326 namespace internal { | 324 namespace internal { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 353 // force use of stored_token | 351 // force use of stored_token |
| 354 stored_token = Token::ILLEGAL; | 352 stored_token = Token::ILLEGAL; |
| 355 // force use of marker | 353 // force use of marker |
| 356 marker = NULL; | 354 marker = NULL; |
| 357 // force use of state_entry_0 | 355 // force use of state_entry_0 |
| 358 goto state_entry_0; | 356 goto state_entry_0; |
| 359 } | 357 } |
| 360 } | 358 } |
| 361 } } | 359 } } |
| 362 | 360 |
| OLD | NEW |