Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Side by Side Diff: src/parser.h

Issue 8505012: A small collection of cleanup in the parser and AST. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/liveedit.cc ('k') | src/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 25 matching lines...) Expand all
36 #include "preparser.h" 36 #include "preparser.h"
37 37
38 namespace v8 { 38 namespace v8 {
39 namespace internal { 39 namespace internal {
40 40
41 class CompilationInfo; 41 class CompilationInfo;
42 class FuncNameInferrer; 42 class FuncNameInferrer;
43 class ParserLog; 43 class ParserLog;
44 class PositionStack; 44 class PositionStack;
45 class Target; 45 class Target;
46 class LexicalScope;
47 class SaveScope;
48 46
49 template <typename T> class ZoneListWrapper; 47 template <typename T> class ZoneListWrapper;
50 48
51 49
52 class ParserMessage : public Malloced { 50 class ParserMessage : public Malloced {
53 public: 51 public:
54 ParserMessage(Scanner::Location loc, const char* message, 52 ParserMessage(Scanner::Location loc, const char* message,
55 Vector<const char*> args) 53 Vector<const char*> args)
56 : loc_(loc), 54 : loc_(loc),
57 message_(message), 55 message_(message),
58 args_(args) { } 56 args_(args) { }
59 ~ParserMessage(); 57 ~ParserMessage();
60 Scanner::Location location() { return loc_; } 58 Scanner::Location location() { return loc_; }
61 const char* message() { return message_; } 59 const char* message() { return message_; }
62 Vector<const char*> args() { return args_; } 60 Vector<const char*> args() { return args_; }
63 private: 61 private:
64 Scanner::Location loc_; 62 Scanner::Location loc_;
65 const char* message_; 63 const char* message_;
66 Vector<const char*> args_; 64 Vector<const char*> args_;
67 }; 65 };
68 66
69 67
70 class FunctionEntry BASE_EMBEDDED { 68 class FunctionEntry BASE_EMBEDDED {
71 public: 69 public:
70 enum {
71 kStartPositionIndex,
72 kEndPositionIndex,
73 kLiteralCountIndex,
74 kPropertyCountIndex,
75 kStrictModeIndex,
76 kSize
77 };
78
72 explicit FunctionEntry(Vector<unsigned> backing) : backing_(backing) { } 79 explicit FunctionEntry(Vector<unsigned> backing) : backing_(backing) { }
73 FunctionEntry() : backing_(Vector<unsigned>::empty()) { } 80 FunctionEntry() : backing_(Vector<unsigned>::empty()) { }
74 81
75 int start_pos() { return backing_[kStartPosOffset]; } 82 int start_pos() { return backing_[kStartPositionIndex]; }
76 int end_pos() { return backing_[kEndPosOffset]; } 83 int end_pos() { return backing_[kEndPositionIndex]; }
77 int literal_count() { return backing_[kLiteralCountOffset]; } 84 int literal_count() { return backing_[kLiteralCountIndex]; }
78 int property_count() { return backing_[kPropertyCountOffset]; } 85 int property_count() { return backing_[kPropertyCountIndex]; }
79 StrictModeFlag strict_mode_flag() { 86 StrictModeFlag strict_mode_flag() {
80 ASSERT(backing_[kStrictModeOffset] == kStrictMode || 87 ASSERT(backing_[kStrictModeIndex] == kStrictMode ||
81 backing_[kStrictModeOffset] == kNonStrictMode); 88 backing_[kStrictModeIndex] == kNonStrictMode);
82 return static_cast<StrictModeFlag>(backing_[kStrictModeOffset]); 89 return static_cast<StrictModeFlag>(backing_[kStrictModeIndex]);
83 } 90 }
84 91
85 bool is_valid() { return backing_.length() > 0; } 92 bool is_valid() { return !backing_.is_empty(); }
86
87 static const int kSize = 5;
88 93
89 private: 94 private:
90 Vector<unsigned> backing_; 95 Vector<unsigned> backing_;
91 static const int kStartPosOffset = 0;
92 static const int kEndPosOffset = 1;
93 static const int kLiteralCountOffset = 2;
94 static const int kPropertyCountOffset = 3;
95 static const int kStrictModeOffset = 4;
96 }; 96 };
97 97
98 98
99 class ScriptDataImpl : public ScriptData { 99 class ScriptDataImpl : public ScriptData {
100 public: 100 public:
101 explicit ScriptDataImpl(Vector<unsigned> store) 101 explicit ScriptDataImpl(Vector<unsigned> store)
102 : store_(store), 102 : store_(store),
103 owns_store_(true) { } 103 owns_store_(true) { }
104 104
105 // Create an empty ScriptDataImpl that is guaranteed to not satisfy 105 // Create an empty ScriptDataImpl that is guaranteed to not satisfy
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 Vector<Handle<String> > args); 444 Vector<Handle<String> > args);
445 void SetHarmonyScoping(bool block_scoping); 445 void SetHarmonyScoping(bool block_scoping);
446 446
447 private: 447 private:
448 // Limit on number of function parameters is chosen arbitrarily. 448 // Limit on number of function parameters is chosen arbitrarily.
449 // Code::Flags uses only the low 17 bits of num-parameters to 449 // Code::Flags uses only the low 17 bits of num-parameters to
450 // construct a hashable id, so if more than 2^17 are allowed, this 450 // construct a hashable id, so if more than 2^17 are allowed, this
451 // should be checked. 451 // should be checked.
452 static const int kMaxNumFunctionParameters = 32766; 452 static const int kMaxNumFunctionParameters = 32766;
453 static const int kMaxNumFunctionLocals = 32767; 453 static const int kMaxNumFunctionLocals = 32767;
454 FunctionLiteral* ParseLazy(CompilationInfo* info, 454
455 UC16CharacterStream* source,
456 ZoneScope* zone_scope);
457 enum Mode { 455 enum Mode {
458 PARSE_LAZILY, 456 PARSE_LAZILY,
459 PARSE_EAGERLY 457 PARSE_EAGERLY
460 }; 458 };
461 459
462 enum VariableDeclarationContext { 460 enum VariableDeclarationContext {
463 kSourceElement, 461 kSourceElement,
464 kStatement, 462 kStatement,
465 kForStatement 463 kForStatement
466 }; 464 };
467 465
468 // If a list of variable declarations includes any initializers. 466 // If a list of variable declarations includes any initializers.
469 enum VariableDeclarationProperties { 467 enum VariableDeclarationProperties {
470 kHasInitializers, 468 kHasInitializers,
471 kHasNoInitializers 469 kHasNoInitializers
472 }; 470 };
473 471
472 class BlockState;
473 class FunctionState;
474
475 FunctionLiteral* ParseLazy(CompilationInfo* info,
476 UC16CharacterStream* source,
477 ZoneScope* zone_scope);
478
474 Isolate* isolate() { return isolate_; } 479 Isolate* isolate() { return isolate_; }
475 Zone* zone() { return isolate_->zone(); } 480 Zone* zone() { return isolate_->zone(); }
476 481
477 // Called by ParseProgram after setting up the scanner. 482 // Called by ParseProgram after setting up the scanner.
478 FunctionLiteral* DoParseProgram(Handle<String> source, 483 FunctionLiteral* DoParseProgram(Handle<String> source,
479 bool in_global_context, 484 bool in_global_context,
480 StrictModeFlag strict_mode, 485 StrictModeFlag strict_mode,
481 ZoneScope* zone_scope); 486 ZoneScope* zone_scope);
482 487
483 // Report syntax error 488 // Report syntax error
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 Vector< Handle<Object> > arguments); 728 Vector< Handle<Object> > arguments);
724 729
725 Isolate* isolate_; 730 Isolate* isolate_;
726 ZoneList<Handle<String> > symbol_cache_; 731 ZoneList<Handle<String> > symbol_cache_;
727 732
728 Handle<Script> script_; 733 Handle<Script> script_;
729 Scanner scanner_; 734 Scanner scanner_;
730 735
731 Scope* top_scope_; 736 Scope* top_scope_;
732 737
733 LexicalScope* lexical_scope_; 738 FunctionState* current_function_state_;
734 Mode mode_; 739 Mode mode_;
735 740
736 Target* target_stack_; // for break, continue statements 741 Target* target_stack_; // for break, continue statements
737 bool allow_natives_syntax_; 742 bool allow_natives_syntax_;
738 v8::Extension* extension_; 743 v8::Extension* extension_;
739 bool is_pre_parsing_; 744 bool is_pre_parsing_;
740 ScriptDataImpl* pre_data_; 745 ScriptDataImpl* pre_data_;
741 FuncNameInferrer* fni_; 746 FuncNameInferrer* fni_;
742 bool stack_overflow_; 747 bool stack_overflow_;
743 // If true, the next (and immediately following) function literal is 748 // If true, the next (and immediately following) function literal is
744 // preceded by a parenthesis. 749 // preceded by a parenthesis.
745 // Heuristically that means that the function will be called immediately, 750 // Heuristically that means that the function will be called immediately,
746 // so never lazily compile it. 751 // so never lazily compile it.
747 bool parenthesized_function_; 752 bool parenthesized_function_;
748 bool harmony_scoping_; 753 bool harmony_scoping_;
749 754
750 friend class LexicalScope; 755 friend class BlockState;
751 friend class SaveScope; 756 friend class FunctionState;
752 }; 757 };
753 758
754 759
755 // Support for handling complex values (array and object literals) that 760 // Support for handling complex values (array and object literals) that
756 // can be fully handled at compile time. 761 // can be fully handled at compile time.
757 class CompileTimeValue: public AllStatic { 762 class CompileTimeValue: public AllStatic {
758 public: 763 public:
759 enum Type { 764 enum Type {
760 OBJECT_LITERAL_FAST_ELEMENTS, 765 OBJECT_LITERAL_FAST_ELEMENTS,
761 OBJECT_LITERAL_SLOW_ELEMENTS, 766 OBJECT_LITERAL_SLOW_ELEMENTS,
(...skipping 16 matching lines...) Expand all
778 private: 783 private:
779 static const int kTypeSlot = 0; 784 static const int kTypeSlot = 0;
780 static const int kElementsSlot = 1; 785 static const int kElementsSlot = 1;
781 786
782 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 787 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
783 }; 788 };
784 789
785 } } // namespace v8::internal 790 } } // namespace v8::internal
786 791
787 #endif // V8_PARSER_H_ 792 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/liveedit.cc ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698