| 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 {%- macro jump(id) -%} |
| 29 {%- set node = jump_table[id] -%} |
| 30 goto {{ node[1] ~ '_' ~ node[0] }}; |
| 31 {%- endmacro -%} |
| 32 |
| 28 {%- macro do_key(key) -%} | 33 {%- macro do_key(key) -%} |
| 29 {%- for r in key -%} | 34 {%- for r in key -%} |
| 30 {%- if not loop.first %} || {% endif -%} | 35 {%- if not loop.first %} || {% endif -%} |
| 31 {%- if r[0] == 'PRIMARY_RANGE' -%} | 36 {%- if r[0] == 'PRIMARY_RANGE' -%} |
| 32 {%- if r[1][0] == r[1][1] -%} | 37 {%- if r[1][0] == r[1][1] -%} |
| 33 primary_char == {{r[1][0]}} | 38 primary_char == {{r[1][0]}} |
| 34 {%- elif r[1][0] == 0 -%} | 39 {%- elif r[1][0] == 0 -%} |
| 35 primary_char <= {{r[1][1]}} | 40 primary_char <= {{r[1][1]}} |
| 36 {%- elif r[1][1] == upper_bound and not encoding == 'utf16'-%} | 41 {%- elif r[1][1] == upper_bound and not encoding == 'utf16'-%} |
| 37 primary_char >= {{r[1][0]}} | 42 primary_char >= {{r[1][0]}} |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 RESET_START(); | 122 RESET_START(); |
| 118 {%- if encoding == 'utf16'-%} | 123 {%- if encoding == 'utf16'-%} |
| 119 next_.is_onebyte = true; | 124 next_.is_onebyte = true; |
| 120 {%- endif -%} | 125 {%- endif -%} |
| 121 has_line_terminator_before_next_ = true; | 126 has_line_terminator_before_next_ = true; |
| 122 goto state_entry_0; | 127 goto state_entry_0; |
| 123 {% elif type == 'token' %} | 128 {% elif type == 'token' %} |
| 124 DO_TOKEN(Token::{{value}}) | 129 DO_TOKEN(Token::{{value}}) |
| 125 return; | 130 return; |
| 126 {% elif type == 'goto_start' %} | 131 {% elif type == 'goto_start' %} |
| 127 goto state_entry_{{value[0]}}; | 132 {{ jump(value[0]) }} |
| 128 {% elif type == 'store_token_and_goto' %} | 133 {% elif type == 'store_token_and_goto' %} |
| 129 stored_token = Token::{{value[0]}}; | 134 stored_token = Token::{{value[0]}}; |
| 130 goto after_entry_code_{{value[1]}}; | 135 {{ jump(value[1]) }} |
| 131 {% elif type == 'do_stored_token' %} | 136 {% elif type == 'do_stored_token' %} |
| 132 DO_TOKEN(stored_token) | 137 DO_TOKEN(stored_token) |
| 133 return; | 138 return; |
| 134 {% elif type == 'do_token_and_go_forward' %} | 139 {% elif type == 'do_token_and_go_forward' %} |
| 135 DO_TOKEN(Token::{{value}}); | 140 DO_TOKEN(Token::{{value}}); |
| 136 FORWARD(); | 141 FORWARD(); |
| 137 RESET_START(); | 142 RESET_START(); |
| 138 return; | 143 return; |
| 139 {% elif type == 'harmony_token' %} | 144 {% elif type == 'harmony_token' %} |
| 140 if (harmony_{{value[0]}}_) { | 145 if (harmony_{{value[0]}}_) { |
| 141 DO_TOKEN(Token::{{value[1]}}); | 146 DO_TOKEN(Token::{{value[1]}}); |
| 142 } else { | 147 } else { |
| 143 DO_TOKEN(Token::{{value[2]}}); | 148 DO_TOKEN(Token::{{value[2]}}); |
| 144 } | 149 } |
| 145 return; | 150 return; |
| 146 {% elif type == 'store_harmony_token_and_goto' %} | 151 {% elif type == 'store_harmony_token_and_goto' %} |
| 147 if (harmony_{{value[0]}}_) { | 152 if (harmony_{{value[0]}}_) { |
| 148 stored_token = Token::{{value[1]}}; | 153 stored_token = Token::{{value[1]}}; |
| 149 } else { | 154 } else { |
| 150 stored_token = Token::{{value[2]}}; | 155 stored_token = Token::{{value[2]}}; |
| 151 } | 156 } |
| 152 goto after_entry_code_{{value[3]}}; | 157 {{ jump(value[3]) }} |
| 153 {% elif type == 'octal_number' %} | 158 {% elif type == 'octal_number' %} |
| 154 last_octal_end_ = cursor_; | 159 last_octal_end_ = cursor_; |
| 155 DO_TOKEN(Token::NUMBER); | 160 DO_TOKEN(Token::NUMBER); |
| 156 return; | 161 return; |
| 157 {% elif type == 'backtrack' %} | 162 {% elif type == 'backtrack' %} |
| 158 BACKWARD({{value[0]}}); | 163 BACKWARD({{value[0]}}); |
| 159 DO_TOKEN(Token::{{value[1]}}); | 164 DO_TOKEN(Token::{{value[1]}}); |
| 160 return; | 165 return; |
| 161 {% else %} | 166 {% else %} |
| 162 uncompilable code for {{type}} {{value}} | 167 uncompilable code for {{type}} {{value}} |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 {%- if entry_action %} | 231 {%- if entry_action %} |
| 227 {{ dispatch_entry_action(entry_action[0], entry_action[1]) }} | 232 {{ dispatch_entry_action(entry_action[0], entry_action[1]) }} |
| 228 {%- endif %} | 233 {%- endif %} |
| 229 | 234 |
| 230 {{ write_label('after_entry_code', node_number_chain) }} | 235 {{ write_label('after_entry_code', node_number_chain) }} |
| 231 | 236 |
| 232 {%- if debug_print %} | 237 {%- if debug_print %} |
| 233 fprintf(stderr, "char at hand is %c (%d)\n", primary_char, primary_char); | 238 fprintf(stderr, "char at hand is %c (%d)\n", primary_char, primary_char); |
| 234 {% endif -%} | 239 {% endif -%} |
| 235 | 240 |
| 236 {%- macro do_transition(transition_state_id) -%} | 241 {%- macro do_transition(jump_id) -%} |
| 242 {%- set transition_state_id = jump_table[jump_id][0] -%} |
| 237 {%- set inline_transition = dfa_states[transition_state_id]['inline'] %} | 243 {%- set inline_transition = dfa_states[transition_state_id]['inline'] %} |
| 238 FORWARD(); | 244 FORWARD(); |
| 239 {%- if inline_transition %} | 245 {%- if inline_transition %} |
| 240 {{ do_dfa_state([transition_state_id] + node_number_chain) }} | 246 {{ do_dfa_state([transition_state_id] + node_number_chain) }} |
| 241 {% else %} | 247 {% else %} |
| 242 goto state_entry_{{transition_state_id}}; | 248 {{ jump(jump_id) }} |
| 243 {% endif %} | 249 {% endif %} |
| 244 {%- endmacro -%} | 250 {%- endmacro -%} |
| 245 | 251 |
| 246 {%- if state['switch_transitions'] -%} | 252 {%- if state['switch_transitions'] -%} |
| 247 switch(primary_char) { | 253 switch(primary_char) { |
| 248 {%- for ranges, transition_state_id in state['switch_transitions'] %} | 254 {%- for ranges, jump_id in state['switch_transitions'] %} |
| 249 {%- for r in ranges -%} | 255 {%- for r in ranges -%} |
| 250 {%- for key in range(r[0], r[1] + 1) -%} | 256 {%- for key in range(r[0], r[1] + 1) -%} |
| 251 case {{key}}: | 257 case {{key}}: |
| 252 {% endfor %} | 258 {% endfor %} |
| 253 {%- endfor -%} | 259 {%- endfor -%} |
| 254 {{ do_transition(transition_state_id) }} | 260 {{ do_transition(jump_id) }} |
| 255 {% endfor -%} | 261 {% endfor -%} |
| 256 } | 262 } |
| 257 {%- endif -%} | 263 {%- endif -%} |
| 258 | 264 |
| 259 {%- for key, transition_state_id in state['if_transitions'] %} | 265 {%- for key, jump_id in state['if_transitions'] %} |
| 260 if ({{do_key(key)}}) { // normal if transition | 266 if ({{do_key(key)}}) { // normal if transition |
| 261 {{ do_transition(transition_state_id) }} | 267 {{ do_transition(jump_id) }} |
| 262 } | 268 } |
| 263 {% endfor -%} | 269 {% endfor -%} |
| 264 | 270 |
| 265 {%- for key, transition_state_id in state['deferred_transitions'] %} | 271 {%- for key, jump_id in state['deferred_transitions'] %} |
| 266 if ({{do_key(key)}}) { // deferred transition | 272 if ({{do_key(key)}}) { // deferred transition |
| 267 {{ do_transition(transition_state_id) }} | 273 {{ do_transition(jump_id) }} |
| 268 } | 274 } |
| 269 {% endfor -%} | 275 {% endfor -%} |
| 270 | 276 |
| 271 {%- if state['long_char_transitions'] -%} | 277 {%- if state['long_char_transitions'] -%} |
| 272 if ({{long_char_check()}}) { | 278 if ({{long_char_check()}}) { |
| 273 next_.is_onebyte = false; | 279 next_.is_onebyte = false; |
| 274 {{long_char_create()}} | 280 {{long_char_create()}} |
| 275 {%- for key, transition_state_id in state['long_char_transitions'] %} | 281 {%- for key, jump_id in state['long_char_transitions'] %} |
| 276 if ({{do_key(key)}}) { // long_char transition | 282 if ({{do_key(key)}}) { // long_char transition |
| 277 {{ do_transition(transition_state_id) }} | 283 {{ do_transition(jump_id) }} |
| 278 } | 284 } |
| 279 {% endfor -%} | 285 {% endfor -%} |
| 280 } | 286 } |
| 281 {%- endif-%} | 287 {%- endif-%} |
| 282 | 288 |
| 283 {%- set match_action = state.match_action -%} | 289 {%- set match_action = state.match_action -%} |
| 284 | 290 |
| 285 {%- if match_action %} | 291 {%- if match_action %} |
| 286 {{ dispatch_match_action(match_action[0], match_action[1]) }} | 292 {{ dispatch_match_action(match_action[0], match_action[1]) }} |
| 287 CRASH(); | 293 CRASH(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 // force use of stored_token | 360 // force use of stored_token |
| 355 stored_token = Token::ILLEGAL; | 361 stored_token = Token::ILLEGAL; |
| 356 // force use of marker | 362 // force use of marker |
| 357 marker = NULL; | 363 marker = NULL; |
| 358 // force use of state_entry_0 | 364 // force use of state_entry_0 |
| 359 goto state_entry_0; | 365 goto state_entry_0; |
| 360 } | 366 } |
| 361 } | 367 } |
| 362 } } | 368 } } |
| 363 | 369 |
| OLD | NEW |