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

Side by Side Diff: src/parser-symbol-table.h

Issue 231073002: WIP: Parser: delay string internalization. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 6 years, 7 months 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
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
27
28 #ifndef V8_PARSER_SYMBOL_TABLE_H_
29 #define V8_PARSER_SYMBOL_TABLE_H_
30
31 #include "api.h"
32 #include "hashmap.h"
33 #include "utils.h"
34
35 namespace v8 {
36 namespace internal {
37
38 struct ParserSymbol {
39 public:
40 ParserSymbol(bool i, Vector<const byte> lb, int h)
41 : is_one_byte(i),
42 literal_bytes(lb),
43 hash(h) {}
44
45 ParserSymbol()
46 : is_one_byte(true),
47 hash(0) {}
48
49 V8_INLINE Handle<String> string() {
50 ASSERT(!string_.is_null());
51 return string_;
52 }
53
54 bool is_one_byte;
55 // Weak. Points to memory owned by ParserSymbolTable.
56 Vector<const byte> literal_bytes;
57 int hash;
58
59 private:
60 friend class ParserSymbolTable;
61 // This is null until the string is internalized.
62 Handle<String> string_;
63 };
64
65
66 class ParserSymbolTable {
67 public:
68 typedef ParserSymbol Symbol;
69
70 ParserSymbolTable();
71 Symbol* GetOneByteSymbol(Vector<const uint8_t> literal);
72 Symbol* GetTwoByteSymbol(Vector<const uint16_t> literal);
73 Symbol* GetSymbol(Handle<String> literal);
74
75 static bool SymbolMatches(Symbol* symbol, const char* data, int length);
76
77 void Internalize(Isolate* isolate);
78 void AlwaysInternalize(Isolate* isolate) {
79 isolate_ = isolate;
80 Internalize(isolate);
81 }
82
83 static bool IsArrayIndexSlow(Symbol* symbol, uint32_t* ix = NULL);
84
85 // Some constant strings which are always needed.
86 ParserSymbol* anonymous_function_string() const {
87 return anonymous_function_string_;
88 }
89 ParserSymbol* arguments_string() const {
90 return arguments_string_;
91 }
92 ParserSymbol* dot_for_string() const {
93 return dot_for_string_;
94 }
95 ParserSymbol* dot_iterator_string() const {
96 return dot_iterator_string_;
97 }
98 ParserSymbol* dot_module_string() const {
99 return dot_module_string_;
100 }
101 ParserSymbol* dot_result_string() const {
102 return dot_result_string_;
103 }
104 ParserSymbol* empty_string() const { return empty_string_; }
105 ParserSymbol* eval_string() const { return eval_string_; }
106 ParserSymbol* initialize_const_global_string() const {
107 return initialize_const_global_string_;
108 }
109 ParserSymbol* initialize_var_global_string() const {
110 return initialize_var_global_string_;
111 }
112 ParserSymbol* make_reference_error_string() const {
113 return make_reference_error_string_;
114 }
115 ParserSymbol* make_syntax_error_string() const {
116 return make_syntax_error_string_;
117 }
118 ParserSymbol* make_type_error_string() const {
119 return make_type_error_string_;
120 }
121 ParserSymbol* module_string() const {
122 return module_string_;
123 }
124 ParserSymbol* native_string() const {
125 return native_string_;
126 }
127 ParserSymbol* prototype_string() const {
128 return prototype_string_;
129 }
130 ParserSymbol* this_string() const { return this_string_; }
131 ParserSymbol* use_strict_string() const {
132 return use_strict_string_;
133 }
134
135 private:
136 Symbol* GetSymbol(int hash, bool is_one_byte,
137 Vector<const byte> literal_bytes);
138
139 static void Internalize(Symbol* symbol, Isolate* isolate);
140
141 // All symbols are copied here, one after another.
142 Collector<byte> literal_chars_;
143 // List of all Symbols we have seen; keys of string_table_ are pointers into
144 // Symbols in symbol_keys_.
145 Collector<Symbol> symbol_keys_;
146 HashMap string_table_;
147 Isolate* isolate_;
148
149 // FIXME: these are easily created with a macro.
150 // FIXME: .generator
151 ParserSymbol* anonymous_function_string_;
152 ParserSymbol* arguments_string_;
153 ParserSymbol* dot_for_string_;
154 ParserSymbol* dot_iterator_string_;
155 ParserSymbol* dot_result_string_;
156 ParserSymbol* dot_module_string_;
157 ParserSymbol* empty_string_;
158 ParserSymbol* eval_string_;
159 ParserSymbol* initialize_const_global_string_;
160 ParserSymbol* initialize_var_global_string_;
161 ParserSymbol* make_reference_error_string_;
162 ParserSymbol* make_syntax_error_string_;
163 ParserSymbol* make_type_error_string_;
164 ParserSymbol* module_string_;
165 ParserSymbol* native_string_;
166 ParserSymbol* prototype_string_;
167 ParserSymbol* this_string_;
168 ParserSymbol* use_strict_string_;
169 };
170
171 } } // namespace v8::internal
172
173 #endif // V8_PARSER_SYMBOL_TABLE_H_
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | src/parser-symbol-table.cc » ('j') | src/parser-symbol-table.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698