| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_PARSING_PREPARSER_H | 5 #ifndef V8_PARSING_PREPARSER_H |
| 6 #define V8_PARSING_PREPARSER_H | 6 #define V8_PARSING_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
| 9 #include "src/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
| 10 #include "src/hashmap.h" | 10 #include "src/hashmap.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 137 |
| 138 static PreParserExpression StringLiteral() { | 138 static PreParserExpression StringLiteral() { |
| 139 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); | 139 return PreParserExpression(TypeField::encode(kStringLiteralExpression)); |
| 140 } | 140 } |
| 141 | 141 |
| 142 static PreParserExpression UseStrictStringLiteral() { | 142 static PreParserExpression UseStrictStringLiteral() { |
| 143 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | | 143 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | |
| 144 IsUseStrictField::encode(true)); | 144 IsUseStrictField::encode(true)); |
| 145 } | 145 } |
| 146 | 146 |
| 147 static PreParserExpression UseStrongStringLiteral() { | |
| 148 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | | |
| 149 IsUseStrongField::encode(true)); | |
| 150 } | |
| 151 | |
| 152 static PreParserExpression This() { | 147 static PreParserExpression This() { |
| 153 return PreParserExpression(TypeField::encode(kExpression) | | 148 return PreParserExpression(TypeField::encode(kExpression) | |
| 154 ExpressionTypeField::encode(kThisExpression)); | 149 ExpressionTypeField::encode(kThisExpression)); |
| 155 } | 150 } |
| 156 | 151 |
| 157 static PreParserExpression ThisProperty() { | 152 static PreParserExpression ThisProperty() { |
| 158 return PreParserExpression( | 153 return PreParserExpression( |
| 159 TypeField::encode(kExpression) | | 154 TypeField::encode(kExpression) | |
| 160 ExpressionTypeField::encode(kThisPropertyExpression)); | 155 ExpressionTypeField::encode(kThisPropertyExpression)); |
| 161 } | 156 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 202 |
| 208 bool IsStringLiteral() const { | 203 bool IsStringLiteral() const { |
| 209 return TypeField::decode(code_) == kStringLiteralExpression; | 204 return TypeField::decode(code_) == kStringLiteralExpression; |
| 210 } | 205 } |
| 211 | 206 |
| 212 bool IsUseStrictLiteral() const { | 207 bool IsUseStrictLiteral() const { |
| 213 return TypeField::decode(code_) == kStringLiteralExpression && | 208 return TypeField::decode(code_) == kStringLiteralExpression && |
| 214 IsUseStrictField::decode(code_); | 209 IsUseStrictField::decode(code_); |
| 215 } | 210 } |
| 216 | 211 |
| 217 bool IsUseStrongLiteral() const { | |
| 218 return TypeField::decode(code_) == kStringLiteralExpression && | |
| 219 IsUseStrongField::decode(code_); | |
| 220 } | |
| 221 | |
| 222 bool IsThis() const { | 212 bool IsThis() const { |
| 223 return TypeField::decode(code_) == kExpression && | 213 return TypeField::decode(code_) == kExpression && |
| 224 ExpressionTypeField::decode(code_) == kThisExpression; | 214 ExpressionTypeField::decode(code_) == kThisExpression; |
| 225 } | 215 } |
| 226 | 216 |
| 227 bool IsThisProperty() const { | 217 bool IsThisProperty() const { |
| 228 return TypeField::decode(code_) == kExpression && | 218 return TypeField::decode(code_) == kExpression && |
| 229 ExpressionTypeField::decode(code_) == kThisPropertyExpression; | 219 ExpressionTypeField::decode(code_) == kThisPropertyExpression; |
| 230 } | 220 } |
| 231 | 221 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 // Expression ASTNode --- This is by necessity, due to the fact that | 300 // Expression ASTNode --- This is by necessity, due to the fact that |
| 311 // Expression nodes may be represented as multiple Types, not exclusively | 301 // Expression nodes may be represented as multiple Types, not exclusively |
| 312 // through kExpression. | 302 // through kExpression. |
| 313 // TODO(caitp, adamk): clean up PreParserExpression bitfields. | 303 // TODO(caitp, adamk): clean up PreParserExpression bitfields. |
| 314 typedef BitField<bool, 31, 1> ParenthesizedField; | 304 typedef BitField<bool, 31, 1> ParenthesizedField; |
| 315 | 305 |
| 316 // The rest of the bits are interpreted depending on the value | 306 // The rest of the bits are interpreted depending on the value |
| 317 // of the Type field, so they can share the storage. | 307 // of the Type field, so they can share the storage. |
| 318 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; | 308 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; |
| 319 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; | 309 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; |
| 320 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; | |
| 321 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> | 310 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> |
| 322 IdentifierTypeField; | 311 IdentifierTypeField; |
| 323 typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField; | 312 typedef BitField<bool, TypeField::kNext, 1> HasCoverInitializedNameField; |
| 324 | 313 |
| 325 uint32_t code_; | 314 uint32_t code_; |
| 326 }; | 315 }; |
| 327 | 316 |
| 328 | 317 |
| 329 // The pre-parser doesn't need to build lists of expressions, identifiers, or | 318 // The pre-parser doesn't need to build lists of expressions, identifiers, or |
| 330 // the like. | 319 // the like. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 359 } | 348 } |
| 360 | 349 |
| 361 // Creates expression statement from expression. | 350 // Creates expression statement from expression. |
| 362 // Preserves being an unparenthesized string literal, possibly | 351 // Preserves being an unparenthesized string literal, possibly |
| 363 // "use strict". | 352 // "use strict". |
| 364 static PreParserStatement ExpressionStatement( | 353 static PreParserStatement ExpressionStatement( |
| 365 PreParserExpression expression) { | 354 PreParserExpression expression) { |
| 366 if (expression.IsUseStrictLiteral()) { | 355 if (expression.IsUseStrictLiteral()) { |
| 367 return PreParserStatement(kUseStrictExpressionStatement); | 356 return PreParserStatement(kUseStrictExpressionStatement); |
| 368 } | 357 } |
| 369 if (expression.IsUseStrongLiteral()) { | |
| 370 return PreParserStatement(kUseStrongExpressionStatement); | |
| 371 } | |
| 372 if (expression.IsStringLiteral()) { | 358 if (expression.IsStringLiteral()) { |
| 373 return PreParserStatement(kStringLiteralExpressionStatement); | 359 return PreParserStatement(kStringLiteralExpressionStatement); |
| 374 } | 360 } |
| 375 return Default(); | 361 return Default(); |
| 376 } | 362 } |
| 377 | 363 |
| 378 bool IsStringLiteral() { | 364 bool IsStringLiteral() { |
| 379 return code_ == kStringLiteralExpressionStatement | 365 return code_ == kStringLiteralExpressionStatement || IsUseStrictLiteral(); |
| 380 || IsUseStrictLiteral() || IsUseStrongLiteral(); | |
| 381 } | 366 } |
| 382 | 367 |
| 383 bool IsUseStrictLiteral() { | 368 bool IsUseStrictLiteral() { |
| 384 return code_ == kUseStrictExpressionStatement; | 369 return code_ == kUseStrictExpressionStatement; |
| 385 } | 370 } |
| 386 | 371 |
| 387 bool IsUseStrongLiteral() { return code_ == kUseStrongExpressionStatement; } | |
| 388 | |
| 389 bool IsFunctionDeclaration() { | 372 bool IsFunctionDeclaration() { |
| 390 return code_ == kFunctionDeclaration; | 373 return code_ == kFunctionDeclaration; |
| 391 } | 374 } |
| 392 | 375 |
| 393 bool IsJumpStatement() { | 376 bool IsJumpStatement() { |
| 394 return code_ == kJumpStatement; | 377 return code_ == kJumpStatement; |
| 395 } | 378 } |
| 396 | 379 |
| 397 private: | 380 private: |
| 398 enum Type { | 381 enum Type { |
| 399 kUnknownStatement, | 382 kUnknownStatement, |
| 400 kJumpStatement, | 383 kJumpStatement, |
| 401 kStringLiteralExpressionStatement, | 384 kStringLiteralExpressionStatement, |
| 402 kUseStrictExpressionStatement, | 385 kUseStrictExpressionStatement, |
| 403 kUseStrongExpressionStatement, | |
| 404 kFunctionDeclaration | 386 kFunctionDeclaration |
| 405 }; | 387 }; |
| 406 | 388 |
| 407 explicit PreParserStatement(Type code) : code_(code) {} | 389 explicit PreParserStatement(Type code) : code_(code) {} |
| 408 Type code_; | 390 Type code_; |
| 409 }; | 391 }; |
| 410 | 392 |
| 411 | 393 |
| 412 typedef PreParserList<PreParserStatement> PreParserStatementList; | 394 typedef PreParserList<PreParserStatement> PreParserStatementList; |
| 413 | 395 |
| (...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 const PreParserFormalParameters& parameters, FunctionKind kind, | 1149 const PreParserFormalParameters& parameters, FunctionKind kind, |
| 1168 FunctionLiteral::FunctionType function_type, bool* ok) { | 1150 FunctionLiteral::FunctionType function_type, bool* ok) { |
| 1169 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, | 1151 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, |
| 1170 kind, function_type, ok); | 1152 kind, function_type, ok); |
| 1171 } | 1153 } |
| 1172 | 1154 |
| 1173 } // namespace internal | 1155 } // namespace internal |
| 1174 } // namespace v8 | 1156 } // namespace v8 |
| 1175 | 1157 |
| 1176 #endif // V8_PARSING_PREPARSER_H | 1158 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |