| 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_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
| 6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 if (token == Token::IN && !accept_IN) | 529 if (token == Token::IN && !accept_IN) |
| 530 return 0; // 0 precedence will terminate binary expression parsing | 530 return 0; // 0 precedence will terminate binary expression parsing |
| 531 return Token::Precedence(token); | 531 return Token::Precedence(token); |
| 532 } | 532 } |
| 533 | 533 |
| 534 typename Traits::Type::Factory* factory() { | 534 typename Traits::Type::Factory* factory() { |
| 535 return function_state_->factory(); | 535 return function_state_->factory(); |
| 536 } | 536 } |
| 537 | 537 |
| 538 LanguageMode language_mode() { return scope_->language_mode(); } | 538 LanguageMode language_mode() { return scope_->language_mode(); } |
| 539 AsmMode asm_mode() { return scope_->asm_mode(); } |
| 539 bool is_generator() const { return function_state_->is_generator(); } | 540 bool is_generator() const { return function_state_->is_generator(); } |
| 540 | 541 |
| 541 // Report syntax errors. | 542 // Report syntax errors. |
| 542 void ReportMessage(MessageTemplate::Template message, const char* arg = NULL, | 543 void ReportMessage(MessageTemplate::Template message, const char* arg = NULL, |
| 543 ParseErrorType error_type = kSyntaxError) { | 544 ParseErrorType error_type = kSyntaxError) { |
| 544 Scanner::Location source_location = scanner()->location(); | 545 Scanner::Location source_location = scanner()->location(); |
| 545 Traits::ReportMessageAt(source_location, message, arg, error_type); | 546 Traits::ReportMessageAt(source_location, message, arg, error_type); |
| 546 } | 547 } |
| 547 | 548 |
| 548 void ReportMessageAt(Scanner::Location location, | 549 void ReportMessageAt(Scanner::Location location, |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 static PreParserExpression UseStrictStringLiteral() { | 1137 static PreParserExpression UseStrictStringLiteral() { |
| 1137 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | | 1138 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | |
| 1138 IsUseStrictField::encode(true)); | 1139 IsUseStrictField::encode(true)); |
| 1139 } | 1140 } |
| 1140 | 1141 |
| 1141 static PreParserExpression UseStrongStringLiteral() { | 1142 static PreParserExpression UseStrongStringLiteral() { |
| 1142 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | | 1143 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | |
| 1143 IsUseStrongField::encode(true)); | 1144 IsUseStrongField::encode(true)); |
| 1144 } | 1145 } |
| 1145 | 1146 |
| 1147 static PreParserExpression UseAsmStringLiteral() { |
| 1148 return PreParserExpression(TypeField::encode(kStringLiteralExpression) | |
| 1149 IsUseAsmField::encode(true)); |
| 1150 } |
| 1151 |
| 1146 static PreParserExpression This() { | 1152 static PreParserExpression This() { |
| 1147 return PreParserExpression(TypeField::encode(kExpression) | | 1153 return PreParserExpression(TypeField::encode(kExpression) | |
| 1148 ExpressionTypeField::encode(kThisExpression)); | 1154 ExpressionTypeField::encode(kThisExpression)); |
| 1149 } | 1155 } |
| 1150 | 1156 |
| 1151 static PreParserExpression ThisProperty() { | 1157 static PreParserExpression ThisProperty() { |
| 1152 return PreParserExpression( | 1158 return PreParserExpression( |
| 1153 TypeField::encode(kExpression) | | 1159 TypeField::encode(kExpression) | |
| 1154 ExpressionTypeField::encode(kThisPropertyExpression)); | 1160 ExpressionTypeField::encode(kThisPropertyExpression)); |
| 1155 } | 1161 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1187 bool IsUseStrictLiteral() const { | 1193 bool IsUseStrictLiteral() const { |
| 1188 return TypeField::decode(code_) == kStringLiteralExpression && | 1194 return TypeField::decode(code_) == kStringLiteralExpression && |
| 1189 IsUseStrictField::decode(code_); | 1195 IsUseStrictField::decode(code_); |
| 1190 } | 1196 } |
| 1191 | 1197 |
| 1192 bool IsUseStrongLiteral() const { | 1198 bool IsUseStrongLiteral() const { |
| 1193 return TypeField::decode(code_) == kStringLiteralExpression && | 1199 return TypeField::decode(code_) == kStringLiteralExpression && |
| 1194 IsUseStrongField::decode(code_); | 1200 IsUseStrongField::decode(code_); |
| 1195 } | 1201 } |
| 1196 | 1202 |
| 1203 bool IsUseAsmLiteral() const { |
| 1204 return TypeField::decode(code_) == kStringLiteralExpression && |
| 1205 IsUseAsmField::decode(code_); |
| 1206 } |
| 1207 |
| 1197 bool IsThis() const { | 1208 bool IsThis() const { |
| 1198 return TypeField::decode(code_) == kExpression && | 1209 return TypeField::decode(code_) == kExpression && |
| 1199 ExpressionTypeField::decode(code_) == kThisExpression; | 1210 ExpressionTypeField::decode(code_) == kThisExpression; |
| 1200 } | 1211 } |
| 1201 | 1212 |
| 1202 bool IsThisProperty() const { | 1213 bool IsThisProperty() const { |
| 1203 return TypeField::decode(code_) == kExpression && | 1214 return TypeField::decode(code_) == kExpression && |
| 1204 ExpressionTypeField::decode(code_) == kThisPropertyExpression; | 1215 ExpressionTypeField::decode(code_) == kThisPropertyExpression; |
| 1205 } | 1216 } |
| 1206 | 1217 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1270 : code_(expression_code) {} | 1281 : code_(expression_code) {} |
| 1271 | 1282 |
| 1272 // The first three bits are for the Type. | 1283 // The first three bits are for the Type. |
| 1273 typedef BitField<Type, 0, 3> TypeField; | 1284 typedef BitField<Type, 0, 3> TypeField; |
| 1274 | 1285 |
| 1275 // The rest of the bits are interpreted depending on the value | 1286 // The rest of the bits are interpreted depending on the value |
| 1276 // of the Type field, so they can share the storage. | 1287 // of the Type field, so they can share the storage. |
| 1277 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; | 1288 typedef BitField<ExpressionType, TypeField::kNext, 3> ExpressionTypeField; |
| 1278 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; | 1289 typedef BitField<bool, TypeField::kNext, 1> IsUseStrictField; |
| 1279 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; | 1290 typedef BitField<bool, IsUseStrictField::kNext, 1> IsUseStrongField; |
| 1291 typedef BitField<bool, IsUseStrongField::kNext, 1> IsUseAsmField; |
| 1280 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> | 1292 typedef BitField<PreParserIdentifier::Type, TypeField::kNext, 10> |
| 1281 IdentifierTypeField; | 1293 IdentifierTypeField; |
| 1282 | 1294 |
| 1283 uint32_t code_; | 1295 uint32_t code_; |
| 1284 }; | 1296 }; |
| 1285 | 1297 |
| 1286 | 1298 |
| 1287 // The pre-parser doesn't need to build lists of expressions, identifiers, or | 1299 // The pre-parser doesn't need to build lists of expressions, identifiers, or |
| 1288 // the like. | 1300 // the like. |
| 1289 template <typename T> | 1301 template <typename T> |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1320 // Preserves being an unparenthesized string literal, possibly | 1332 // Preserves being an unparenthesized string literal, possibly |
| 1321 // "use strict". | 1333 // "use strict". |
| 1322 static PreParserStatement ExpressionStatement( | 1334 static PreParserStatement ExpressionStatement( |
| 1323 PreParserExpression expression) { | 1335 PreParserExpression expression) { |
| 1324 if (expression.IsUseStrictLiteral()) { | 1336 if (expression.IsUseStrictLiteral()) { |
| 1325 return PreParserStatement(kUseStrictExpressionStatement); | 1337 return PreParserStatement(kUseStrictExpressionStatement); |
| 1326 } | 1338 } |
| 1327 if (expression.IsUseStrongLiteral()) { | 1339 if (expression.IsUseStrongLiteral()) { |
| 1328 return PreParserStatement(kUseStrongExpressionStatement); | 1340 return PreParserStatement(kUseStrongExpressionStatement); |
| 1329 } | 1341 } |
| 1342 if (expression.IsUseAsmLiteral()) { |
| 1343 return PreParserStatement(kUseAsmExpressionStatement); |
| 1344 } |
| 1330 if (expression.IsStringLiteral()) { | 1345 if (expression.IsStringLiteral()) { |
| 1331 return PreParserStatement(kStringLiteralExpressionStatement); | 1346 return PreParserStatement(kStringLiteralExpressionStatement); |
| 1332 } | 1347 } |
| 1333 return Default(); | 1348 return Default(); |
| 1334 } | 1349 } |
| 1335 | 1350 |
| 1336 bool IsStringLiteral() { | 1351 bool IsStringLiteral() { |
| 1337 return code_ == kStringLiteralExpressionStatement; | 1352 return code_ == kStringLiteralExpressionStatement; |
| 1338 } | 1353 } |
| 1339 | 1354 |
| 1340 bool IsUseStrictLiteral() { | 1355 bool IsUseStrictLiteral() { |
| 1341 return code_ == kUseStrictExpressionStatement; | 1356 return code_ == kUseStrictExpressionStatement; |
| 1342 } | 1357 } |
| 1343 | 1358 |
| 1344 bool IsUseStrongLiteral() { return code_ == kUseStrongExpressionStatement; } | 1359 bool IsUseStrongLiteral() { return code_ == kUseStrongExpressionStatement; } |
| 1345 | 1360 |
| 1361 bool IsUseAsmLiteral() { return code_ == kUseAsmExpressionStatement; } |
| 1362 |
| 1346 bool IsFunctionDeclaration() { | 1363 bool IsFunctionDeclaration() { |
| 1347 return code_ == kFunctionDeclaration; | 1364 return code_ == kFunctionDeclaration; |
| 1348 } | 1365 } |
| 1349 | 1366 |
| 1350 bool IsJumpStatement() { | 1367 bool IsJumpStatement() { |
| 1351 return code_ == kJumpStatement; | 1368 return code_ == kJumpStatement; |
| 1352 } | 1369 } |
| 1353 | 1370 |
| 1354 private: | 1371 private: |
| 1355 enum Type { | 1372 enum Type { |
| 1356 kUnknownStatement, | 1373 kUnknownStatement, |
| 1357 kJumpStatement, | 1374 kJumpStatement, |
| 1358 kStringLiteralExpressionStatement, | 1375 kStringLiteralExpressionStatement, |
| 1359 kUseStrictExpressionStatement, | 1376 kUseStrictExpressionStatement, |
| 1360 kUseStrongExpressionStatement, | 1377 kUseStrongExpressionStatement, |
| 1378 kUseAsmExpressionStatement, |
| 1361 kFunctionDeclaration | 1379 kFunctionDeclaration |
| 1362 }; | 1380 }; |
| 1363 | 1381 |
| 1364 explicit PreParserStatement(Type code) : code_(code) {} | 1382 explicit PreParserStatement(Type code) : code_(code) {} |
| 1365 Type code_; | 1383 Type code_; |
| 1366 }; | 1384 }; |
| 1367 | 1385 |
| 1368 | 1386 |
| 1369 typedef PreParserList<PreParserStatement> PreParserStatementList; | 1387 typedef PreParserList<PreParserStatement> PreParserStatementList; |
| 1370 | 1388 |
| (...skipping 2678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4049 *ok = false; | 4067 *ok = false; |
| 4050 return; | 4068 return; |
| 4051 } | 4069 } |
| 4052 has_seen_constructor_ = true; | 4070 has_seen_constructor_ = true; |
| 4053 return; | 4071 return; |
| 4054 } | 4072 } |
| 4055 } | 4073 } |
| 4056 } } // v8::internal | 4074 } } // v8::internal |
| 4057 | 4075 |
| 4058 #endif // V8_PREPARSER_H | 4076 #endif // V8_PREPARSER_H |
| OLD | NEW |