7.Parse - v8 ソースコードリーディング

ParserApi::PartialPreParse から PreParse の結果のデータ構造を見ていく。
DoPreParse の結果は ParserRecorder に記録されるようだ。Parse の結果に影響を与える各種フラグを見た後に Parser の本体へ。

FunctionLiteral* Parser::DoParseProgram(Handle<String> source,
                                        bool in_global_context,
                                        StrictModeFlag strict_mode,
                                        ZoneScope* zone_scope) {
void* Parser::ParseSourceElements(ZoneList<Statement*>* processor,
                                  int end_token,
                                  bool* ok) {

かを見て Scope を作る。
scanner が Token::FUNCTION を見つけたら ParseFunctionDeclaration で、それ以外は ParseStatement.
更に ParseStatement で Tokenn::VAR が

Block* Parser::ParseVariableStatement(bool* ok) {
  // VariableStatement ::
  //   VariableDeclarations ';'
  Handle<String> ignore;
  Block* result = ParseVariableDeclarations(true, &ignore, CHECK_OK);
  ExpectSemicolon(CHECK_OK);
  return result;
}

そういえば Parser は手書きなのだね。
variable が見つかると Variable インスタンス(ASTの要素の一つ)が zone() で new されてあれこれ格納されるようだ。

// The AST refers to variables via VariableProxies - placeholders for the actual
// variables. Variables themselves are never directly referred to from the AST,
// they are maintained by scopes, and referred to from VariableProxies and Slots
// after binding and variable allocation.

class Variable: public ZoneObject {
 public:
  enum Mode {
    // User declared variables:
    VAR,       // declared via 'var', and 'function' declarations

... 略

 private:
  Scope* scope_;
  Handle<String> name_;
  Mode mode_;
  Kind kind_;

  Variable* local_if_not_shadowed_;

  // Code generation.
  Slot* rewrite_;

  // Valid as a LHS? (const and this are not valid LHS, for example)
  bool is_valid_LHS_;

  // Usage info.
  bool is_accessed_from_inner_scope_;  // set by variable resolver
  bool is_used_;
};

まとめる時間がないので適当だなあ。まあいいか。
続く。