| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_PARSER_H_ | 5 #ifndef VM_PARSER_H_ |
| 6 #define VM_PARSER_H_ | 6 #define VM_PARSER_H_ |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 | 9 |
| 10 #include "vm/ast.h" | 10 #include "vm/ast.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 const Script& script, | 132 const Script& script, |
| 133 intptr_t token_index, | 133 intptr_t token_index, |
| 134 const char* message_header, | 134 const char* message_header, |
| 135 const char* format, | 135 const char* format, |
| 136 va_list args); | 136 va_list args); |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 struct Block; | 139 struct Block; |
| 140 class TryBlocks; | 140 class TryBlocks; |
| 141 | 141 |
| 142 // The function being parsed. | 142 // The function for which we will generate code. |
| 143 const Function& current_function() const; | 143 const Function& current_function() const; |
| 144 | 144 |
| 145 // The innermost function being parsed. |
| 146 const Function& innermost_function() const; |
| 147 |
| 145 // Note that a local function may be parsed multiple times. It is first parsed | 148 // Note that a local function may be parsed multiple times. It is first parsed |
| 146 // when its outermost enclosing function is being parsed. It is then parsed | 149 // when its outermost enclosing function is being parsed. It is then parsed |
| 147 // again when an enclosing function calls this local function or calls | 150 // again when an enclosing function calls this local function or calls |
| 148 // another local function enclosing it. Code for the local function will only | 151 // another local function enclosing it. Code for the local function will only |
| 149 // be generated the last time the local function is parsed, i.e. when it is | 152 // be generated the last time the local function is parsed, i.e. when it is |
| 150 // invoked. For example, a local function nested in another local function, | 153 // invoked. For example, a local function nested in another local function, |
| 151 // itself nested in a static function, is parsed 3 times (unless it does not | 154 // itself nested in a static function, is parsed 3 times (unless it does not |
| 152 // end up being invoked). | 155 // end up being invoked). |
| 153 // Now, current_function() always points to the outermost function being | 156 // Now, current_function() always points to the outermost function being |
| 154 // parsed (i.e. the function that is being invoked), and is not updated while | 157 // compiled (i.e. the function that is being invoked), and is not updated |
| 155 // parsing a nested function of that outermost function. | 158 // while parsing a nested function of that outermost function. |
| 156 // Therefore, the statements being parsed may or may not belong to the body of | 159 // Therefore, the statements being parsed may or may not belong to the body |
| 157 // the current_function(); they may belong to nested functions. | 160 // of the current_function(); they may belong to nested functions. |
| 161 // innermost_function() is the function that is currently being parsed. |
| 162 // It is either the same as current_function(), or a lexically nested |
| 163 // function. |
| 158 // The function level of the current parsing scope reflects the function | 164 // The function level of the current parsing scope reflects the function |
| 159 // nesting. The function level is zero while parsing the body of the | 165 // nesting. The function level is zero while parsing the body of the |
| 160 // current_function(), but is greater than zero while parsing the body of | 166 // current_function(), but is greater than zero while parsing the body of |
| 161 // local functions nested in current_function(). | 167 // local functions nested in current_function(). |
| 162 | 168 |
| 163 // The class or interface being parsed. | 169 // The class or interface being parsed. |
| 164 const Class& current_class() const; | 170 const Class& current_class() const; |
| 165 void set_current_class(const Class& value); | 171 void set_current_class(const Class& value); |
| 166 | 172 |
| 167 // Parsing a library or a regular source script. | 173 // Parsing a library or a regular source script. |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 bool is_top_level_; | 518 bool is_top_level_; |
| 513 | 519 |
| 514 // The member currently being parsed during "top level" parsing. | 520 // The member currently being parsed during "top level" parsing. |
| 515 MemberDesc* current_member_; | 521 MemberDesc* current_member_; |
| 516 | 522 |
| 517 // Parser mode to allow/disallow function literals. This is used in | 523 // Parser mode to allow/disallow function literals. This is used in |
| 518 // constructor initializer expressions to handle ambiguous grammar. | 524 // constructor initializer expressions to handle ambiguous grammar. |
| 519 bool SetAllowFunctionLiterals(bool value); | 525 bool SetAllowFunctionLiterals(bool value); |
| 520 bool allow_function_literals_; | 526 bool allow_function_literals_; |
| 521 | 527 |
| 528 // The function currently being compiled. |
| 529 const Function& current_function_; |
| 530 |
| 522 // The function currently being parsed. | 531 // The function currently being parsed. |
| 523 const Function& current_function_; | 532 Function& innermost_function_; |
| 524 | 533 |
| 525 // The class or interface currently being parsed, or the owner class of the | 534 // The class or interface currently being parsed, or the owner class of the |
| 526 // function currently being parsed. It is used for primary identifier lookups. | 535 // function currently being parsed. It is used for primary identifier lookups. |
| 527 Class& current_class_; | 536 Class& current_class_; |
| 528 | 537 |
| 529 // The current library (and thus class dictionary) used to resolve names. | 538 // The current library (and thus class dictionary) used to resolve names. |
| 530 const Library& library_; | 539 const Library& library_; |
| 531 | 540 |
| 532 // List of try blocks seen so far, this is used to generate inlined finally | 541 // List of try blocks seen so far, this is used to generate inlined finally |
| 533 // code at all points in the try block where an exit from the block is | 542 // code at all points in the try block where an exit from the block is |
| 534 // done using 'return', 'break' or 'continue' statements. | 543 // done using 'return', 'break' or 'continue' statements. |
| 535 TryBlocks* try_blocks_list_; | 544 TryBlocks* try_blocks_list_; |
| 536 | 545 |
| 537 // Allocate temporary only once per function. | 546 // Allocate temporary only once per function. |
| 538 LocalVariable* expression_temp_; | 547 LocalVariable* expression_temp_; |
| 539 | 548 |
| 540 DISALLOW_COPY_AND_ASSIGN(Parser); | 549 DISALLOW_COPY_AND_ASSIGN(Parser); |
| 541 }; | 550 }; |
| 542 | 551 |
| 543 } // namespace dart | 552 } // namespace dart |
| 544 | 553 |
| 545 #endif // VM_PARSER_H_ | 554 #endif // VM_PARSER_H_ |
| OLD | NEW |