~yolanda.robla/ubuntu/trusty/nodejs/add_distribution

« back to all changes in this revision

Viewing changes to deps/v8/src/preparser.h

  • Committer: Package Import Robot
  • Author(s): Jérémy Lal
  • Date: 2013-08-14 00:16:46 UTC
  • mfrom: (7.1.40 sid)
  • Revision ID: package-import@ubuntu.com-20130814001646-bzlysfh8sd6mukbo
Tags: 0.10.15~dfsg1-4
* Update 2005 patch, adding a handful of tests that can fail on
  slow platforms.
* Add 1004 patch to fix test failures when writing NaN to buffer
  on mipsel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2011 the V8 project authors. All rights reserved.
 
1
// Copyright 2012 the V8 project authors. All rights reserved.
2
2
// Redistribution and use in source and binary forms, with or without
3
3
// modification, are permitted provided that the following conditions are
4
4
// met:
28
28
#ifndef V8_PREPARSER_H
29
29
#define V8_PREPARSER_H
30
30
 
 
31
#include "hashmap.h"
31
32
#include "token.h"
32
33
#include "scanner.h"
33
34
 
64
65
        map_(&Match) { }
65
66
 
66
67
  int AddAsciiSymbol(i::Vector<const char> key, int value);
67
 
  int AddUC16Symbol(i::Vector<const uint16_t> key, int value);
 
68
  int AddUtf16Symbol(i::Vector<const uint16_t> key, int value);
68
69
  // Add a a number literal by converting it (if necessary)
69
70
  // to the string that ToString(ToNumber(literal)) would generate.
70
71
  // and then adding that string with AddAsciiSymbol.
110
111
    kPreParseSuccess
111
112
  };
112
113
 
 
114
 
 
115
  PreParser(i::Scanner* scanner,
 
116
            i::ParserRecorder* log,
 
117
            uintptr_t stack_limit,
 
118
            bool allow_lazy,
 
119
            bool allow_natives_syntax,
 
120
            bool allow_modules)
 
121
      : scanner_(scanner),
 
122
        log_(log),
 
123
        scope_(NULL),
 
124
        stack_limit_(stack_limit),
 
125
        strict_mode_violation_location_(i::Scanner::Location::invalid()),
 
126
        strict_mode_violation_type_(NULL),
 
127
        stack_overflow_(false),
 
128
        allow_lazy_(allow_lazy),
 
129
        allow_modules_(allow_modules),
 
130
        allow_natives_syntax_(allow_natives_syntax),
 
131
        parenthesized_function_(false),
 
132
        harmony_scoping_(scanner->HarmonyScoping()) { }
 
133
 
113
134
  ~PreParser() {}
114
135
 
115
136
  // Pre-parse the program from the character stream; returns true on
116
137
  // success (even if parsing failed, the pre-parse data successfully
117
138
  // captured the syntax error), and false if a stack-overflow happened
118
139
  // during parsing.
119
 
  static PreParseResult PreParseProgram(i::JavaScriptScanner* scanner,
 
140
  static PreParseResult PreParseProgram(i::Scanner* scanner,
120
141
                                        i::ParserRecorder* log,
121
 
                                        bool allow_lazy,
 
142
                                        int flags,
122
143
                                        uintptr_t stack_limit) {
123
 
    return PreParser(scanner, log, stack_limit, allow_lazy).PreParse();
 
144
    bool allow_lazy = (flags & i::kAllowLazy) != 0;
 
145
    bool allow_natives_syntax = (flags & i::kAllowNativesSyntax) != 0;
 
146
    bool allow_modules = (flags & i::kAllowModules) != 0;
 
147
    return PreParser(scanner, log, stack_limit, allow_lazy,
 
148
                     allow_natives_syntax, allow_modules).PreParse();
124
149
  }
125
150
 
 
151
  // Parses a single function literal, from the opening parentheses before
 
152
  // parameters to the closing brace after the body.
 
153
  // Returns a FunctionEntry describing the body of the function in enough
 
154
  // detail that it can be lazily compiled.
 
155
  // The scanner is expected to have matched the "function" keyword and
 
156
  // parameters, and have consumed the initial '{'.
 
157
  // At return, unless an error occurred, the scanner is positioned before the
 
158
  // the final '}'.
 
159
  PreParseResult PreParseLazyFunction(i::LanguageMode mode,
 
160
                                      i::ParserRecorder* log);
 
161
 
126
162
 private:
127
163
  // Used to detect duplicates in object literals. Each of the values
128
164
  // kGetterProperty, kSetterProperty and kValueProperty represents
179
215
    kForStatement
180
216
  };
181
217
 
 
218
  // If a list of variable declarations includes any initializers.
 
219
  enum VariableDeclarationProperties {
 
220
    kHasInitializers,
 
221
    kHasNoInitializers
 
222
  };
 
223
 
182
224
  class Expression;
183
225
 
184
226
  class Identifier {
408
450
          materialized_literal_count_(0),
409
451
          expected_properties_(0),
410
452
          with_nesting_count_(0),
411
 
          strict_((prev_ != NULL) && prev_->is_strict()) {
 
453
          language_mode_(
 
454
              (prev_ != NULL) ? prev_->language_mode() : i::CLASSIC_MODE) {
412
455
      *variable = this;
413
456
    }
414
457
    ~Scope() { *variable_ = prev_; }
418
461
    int expected_properties() { return expected_properties_; }
419
462
    int materialized_literal_count() { return materialized_literal_count_; }
420
463
    bool IsInsideWith() { return with_nesting_count_ != 0; }
421
 
    bool is_strict() { return strict_; }
422
 
    void set_strict() { strict_ = true; }
423
 
    void EnterWith() { with_nesting_count_++; }
424
 
    void LeaveWith() { with_nesting_count_--; }
 
464
    bool is_classic_mode() {
 
465
      return language_mode_ == i::CLASSIC_MODE;
 
466
    }
 
467
    i::LanguageMode language_mode() {
 
468
      return language_mode_;
 
469
    }
 
470
    void set_language_mode(i::LanguageMode language_mode) {
 
471
      language_mode_ = language_mode;
 
472
    }
 
473
 
 
474
    class InsideWith {
 
475
     public:
 
476
      explicit InsideWith(Scope* scope) : scope_(scope) {
 
477
        scope->with_nesting_count_++;
 
478
      }
 
479
 
 
480
      ~InsideWith() { scope_->with_nesting_count_--; }
 
481
 
 
482
     private:
 
483
      Scope* scope_;
 
484
      DISALLOW_COPY_AND_ASSIGN(InsideWith);
 
485
    };
425
486
 
426
487
   private:
427
488
    Scope** const variable_;
430
491
    int materialized_literal_count_;
431
492
    int expected_properties_;
432
493
    int with_nesting_count_;
433
 
    bool strict_;
 
494
    i::LanguageMode language_mode_;
434
495
  };
435
496
 
436
 
  // Private constructor only used in PreParseProgram.
437
 
  PreParser(i::JavaScriptScanner* scanner,
438
 
            i::ParserRecorder* log,
439
 
            uintptr_t stack_limit,
440
 
            bool allow_lazy)
441
 
      : scanner_(scanner),
442
 
        log_(log),
443
 
        scope_(NULL),
444
 
        stack_limit_(stack_limit),
445
 
        strict_mode_violation_location_(i::Scanner::Location::invalid()),
446
 
        strict_mode_violation_type_(NULL),
447
 
        stack_overflow_(false),
448
 
        allow_lazy_(true),
449
 
        parenthesized_function_(false),
450
 
        harmony_block_scoping_(scanner->HarmonyBlockScoping()) { }
451
 
 
452
497
  // Preparse the program. Only called in PreParseProgram after creating
453
498
  // the instance.
454
499
  PreParseResult PreParse() {
459
504
    if (stack_overflow_) return kPreParseStackOverflow;
460
505
    if (!ok) {
461
506
      ReportUnexpectedToken(scanner_->current_token());
462
 
    } else if (scope_->is_strict()) {
 
507
    } else if (!scope_->is_classic_mode()) {
463
508
      CheckOctalLiteral(start_position, scanner_->location().end_pos, &ok);
464
509
    }
465
510
    return kPreParseSuccess;
493
538
  Statement ParseVariableStatement(VariableDeclarationContext var_context,
494
539
                                   bool* ok);
495
540
  Statement ParseVariableDeclarations(VariableDeclarationContext var_context,
 
541
                                      VariableDeclarationProperties* decl_props,
496
542
                                      int* num_decl,
497
543
                                      bool* ok);
498
544
  Statement ParseExpressionOrLabelledStatement(bool* ok);
527
573
 
528
574
  Arguments ParseArguments(bool* ok);
529
575
  Expression ParseFunctionLiteral(bool* ok);
 
576
  void ParseLazyFunctionLiteralBody(bool* ok);
530
577
 
531
578
  Identifier ParseIdentifier(bool* ok);
532
579
  Identifier ParseIdentifierName(bool* ok);
562
609
 
563
610
  bool peek_any_identifier();
564
611
 
565
 
  void set_strict_mode() {
566
 
    scope_->set_strict();
567
 
  }
568
 
 
569
 
  bool strict_mode() { return scope_->is_strict(); }
 
612
  void set_language_mode(i::LanguageMode language_mode) {
 
613
    scope_->set_language_mode(language_mode);
 
614
  }
 
615
 
 
616
  bool is_classic_mode() {
 
617
    return scope_->language_mode() == i::CLASSIC_MODE;
 
618
  }
 
619
 
 
620
  bool is_extended_mode() {
 
621
    return scope_->language_mode() == i::EXTENDED_MODE;
 
622
  }
 
623
 
 
624
  i::LanguageMode language_mode() { return scope_->language_mode(); }
570
625
 
571
626
  void Consume(i::Token::Value token) { Next(); }
572
627
 
590
645
 
591
646
  void SetStrictModeViolation(i::Scanner::Location,
592
647
                              const char* type,
593
 
                              bool *ok);
 
648
                              bool* ok);
594
649
 
595
650
  void CheckDelayedStrictModeViolation(int beg_pos, int end_pos, bool* ok);
596
651
 
599
654
                                     Identifier identifier,
600
655
                                     bool* ok);
601
656
 
602
 
  i::JavaScriptScanner* scanner_;
 
657
  i::Scanner* scanner_;
603
658
  i::ParserRecorder* log_;
604
659
  Scope* scope_;
605
660
  uintptr_t stack_limit_;
607
662
  const char* strict_mode_violation_type_;
608
663
  bool stack_overflow_;
609
664
  bool allow_lazy_;
 
665
  bool allow_modules_;
 
666
  bool allow_natives_syntax_;
610
667
  bool parenthesized_function_;
611
 
  bool harmony_block_scoping_;
 
668
  bool harmony_scoping_;
612
669
};
613
670
} }  // v8::preparser
614
671