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

Side by Side Diff: src/ast/ast-value-factory.h

Issue 2625873009: [ast] Remove heap accesses from AST numbering (Closed)
Patch Set: Address nits Created 3 years, 11 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
« no previous file with comments | « src/ast/ast-numbering.cc ('k') | src/compiler.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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 153
154 // AstValue is either a string, a number, a string array, a boolean, or a 154 // AstValue is either a string, a number, a string array, a boolean, or a
155 // special value (null, undefined, the hole). 155 // special value (null, undefined, the hole).
156 class AstValue : public ZoneObject { 156 class AstValue : public ZoneObject {
157 public: 157 public:
158 bool IsString() const { 158 bool IsString() const {
159 return type_ == STRING; 159 return type_ == STRING;
160 } 160 }
161 161
162 bool IsNumber() const { 162 bool IsNumber() const { return IsSmi() || IsHeapNumber(); }
163 return type_ == NUMBER || type_ == NUMBER_WITH_DOT || type_ == SMI ||
164 type_ == SMI_WITH_DOT;
165 }
166 163
167 bool ContainsDot() const { 164 bool ContainsDot() const {
168 return type_ == NUMBER_WITH_DOT || type_ == SMI_WITH_DOT; 165 return type_ == NUMBER_WITH_DOT || type_ == SMI_WITH_DOT;
169 } 166 }
170 167
171 const AstRawString* AsString() const { 168 const AstRawString* AsString() const {
172 CHECK_EQ(STRING, type_); 169 CHECK_EQ(STRING, type_);
173 return string_; 170 return string_;
174 } 171 }
175 172
176 double AsNumber() const { 173 double AsNumber() const {
177 if (type_ == NUMBER || type_ == NUMBER_WITH_DOT) 174 if (IsHeapNumber()) return number_;
178 return number_; 175 if (IsSmi()) return smi_;
179 if (type_ == SMI || type_ == SMI_WITH_DOT)
180 return smi_;
181 UNREACHABLE(); 176 UNREACHABLE();
182 return 0; 177 return 0;
183 } 178 }
184 179
185 Smi* AsSmi() const { 180 Smi* AsSmi() const {
186 CHECK(type_ == SMI || type_ == SMI_WITH_DOT); 181 CHECK(IsSmi());
187 return Smi::FromInt(smi_); 182 return Smi::FromInt(smi_);
188 } 183 }
189 184
185 bool ToUint32(uint32_t* value) const {
186 if (IsSmi()) {
187 int num = smi_;
188 if (num < 0) return false;
189 *value = static_cast<uint32_t>(num);
190 return true;
191 }
192 if (IsHeapNumber()) {
193 return DoubleToUint32IfEqualToSelf(number_, value);
194 }
195 return false;
196 }
197
190 bool EqualsString(const AstRawString* string) const { 198 bool EqualsString(const AstRawString* string) const {
191 return type_ == STRING && string_ == string; 199 return type_ == STRING && string_ == string;
192 } 200 }
193 201
194 bool IsPropertyName() const; 202 bool IsPropertyName() const;
195 203
196 bool BooleanValue() const; 204 bool BooleanValue() const;
197 205
198 bool IsSmi() const { return type_ == SMI || type_ == SMI_WITH_DOT; } 206 bool IsSmi() const { return type_ == SMI || type_ == SMI_WITH_DOT; }
207 bool IsHeapNumber() const {
208 return type_ == NUMBER || type_ == NUMBER_WITH_DOT;
209 }
199 bool IsFalse() const { return type_ == BOOLEAN && !bool_; } 210 bool IsFalse() const { return type_ == BOOLEAN && !bool_; }
200 bool IsTrue() const { return type_ == BOOLEAN && bool_; } 211 bool IsTrue() const { return type_ == BOOLEAN && bool_; }
201 bool IsUndefined() const { return type_ == UNDEFINED; } 212 bool IsUndefined() const { return type_ == UNDEFINED; }
202 bool IsTheHole() const { return type_ == THE_HOLE; } 213 bool IsTheHole() const { return type_ == THE_HOLE; }
203 bool IsNull() const { return type_ == NULL_TYPE; } 214 bool IsNull() const { return type_ == NULL_TYPE; }
204 215
205 void Internalize(Isolate* isolate); 216 void Internalize(Isolate* isolate);
206 217
207 // Can be called after Internalize has been called. 218 // Can be called after Internalize has been called.
208 V8_INLINE Handle<Object> value() const { 219 V8_INLINE Handle<Object> value() const {
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 OTHER_CONSTANTS(F) 457 OTHER_CONSTANTS(F)
447 #undef F 458 #undef F
448 }; 459 };
449 } // namespace internal 460 } // namespace internal
450 } // namespace v8 461 } // namespace v8
451 462
452 #undef STRING_CONSTANTS 463 #undef STRING_CONSTANTS
453 #undef OTHER_CONSTANTS 464 #undef OTHER_CONSTANTS
454 465
455 #endif // V8_AST_AST_VALUE_FACTORY_H_ 466 #endif // V8_AST_AST_VALUE_FACTORY_H_
OLDNEW
« no previous file with comments | « src/ast/ast-numbering.cc ('k') | src/compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698