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/func-name-inferrer.h" | 8 #include "src/func-name-inferrer.h" |
9 #include "src/hashmap.h" | 9 #include "src/hashmap.h" |
10 #include "src/scopes.h" | 10 #include "src/scopes.h" |
(...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 return ReportMessageAt(source_location, "unexpected_token_identifier"); | 1227 return ReportMessageAt(source_location, "unexpected_token_identifier"); |
1228 case Token::FUTURE_RESERVED_WORD: | 1228 case Token::FUTURE_RESERVED_WORD: |
1229 return ReportMessageAt(source_location, "unexpected_reserved"); | 1229 return ReportMessageAt(source_location, "unexpected_reserved"); |
1230 case Token::YIELD: | 1230 case Token::YIELD: |
1231 case Token::FUTURE_STRICT_RESERVED_WORD: | 1231 case Token::FUTURE_STRICT_RESERVED_WORD: |
1232 return ReportMessageAt(source_location, strict_mode() == SLOPPY | 1232 return ReportMessageAt(source_location, strict_mode() == SLOPPY |
1233 ? "unexpected_token_identifier" : "unexpected_strict_reserved"); | 1233 ? "unexpected_token_identifier" : "unexpected_strict_reserved"); |
1234 default: | 1234 default: |
1235 const char* name = Token::String(token); | 1235 const char* name = Token::String(token); |
1236 ASSERT(name != NULL); | 1236 ASSERT(name != NULL); |
1237 Traits::ReportMessageAt( | 1237 Traits::ReportMessageAt(source_location, "unexpected_token", name); |
1238 source_location, "unexpected_token", name); | |
1239 } | 1238 } |
1240 } | 1239 } |
1241 | 1240 |
1242 | 1241 |
1243 template<class Traits> | 1242 template<class Traits> |
1244 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier( | 1243 typename ParserBase<Traits>::IdentifierT ParserBase<Traits>::ParseIdentifier( |
1245 AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments, | 1244 AllowEvalOrArgumentsAsIdentifier allow_eval_or_arguments, |
1246 bool* ok) { | 1245 bool* ok) { |
1247 Token::Value next = Next(); | 1246 Token::Value next = Next(); |
1248 if (next == Token::IDENTIFIER) { | 1247 if (next == Token::IDENTIFIER) { |
1249 IdentifierT name = this->GetSymbol(scanner()); | 1248 IdentifierT name = this->GetSymbol(scanner()); |
1250 if (allow_eval_or_arguments == kDontAllowEvalOrArguments && | 1249 if (allow_eval_or_arguments == kDontAllowEvalOrArguments && |
1251 strict_mode() == STRICT && this->IsEvalOrArguments(name)) { | 1250 strict_mode() == STRICT && this->IsEvalOrArguments(name)) { |
1252 ReportMessageAt(scanner()->location(), "strict_eval_arguments"); | 1251 ReportMessage("strict_eval_arguments"); |
1253 *ok = false; | 1252 *ok = false; |
1254 } | 1253 } |
1255 return name; | 1254 return name; |
1256 } else if (strict_mode() == SLOPPY && | 1255 } else if (strict_mode() == SLOPPY && |
1257 (next == Token::FUTURE_STRICT_RESERVED_WORD || | 1256 (next == Token::FUTURE_STRICT_RESERVED_WORD || |
1258 (next == Token::YIELD && !is_generator()))) { | 1257 (next == Token::YIELD && !is_generator()))) { |
1259 return this->GetSymbol(scanner()); | 1258 return this->GetSymbol(scanner()); |
1260 } else { | 1259 } else { |
1261 this->ReportUnexpectedToken(next); | 1260 this->ReportUnexpectedToken(next); |
1262 *ok = false; | 1261 *ok = false; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1319 ReportMessage("unterminated_regexp"); | 1318 ReportMessage("unterminated_regexp"); |
1320 *ok = false; | 1319 *ok = false; |
1321 return Traits::EmptyExpression(); | 1320 return Traits::EmptyExpression(); |
1322 } | 1321 } |
1323 | 1322 |
1324 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 1323 int literal_index = function_state_->NextMaterializedLiteralIndex(); |
1325 | 1324 |
1326 IdentifierT js_pattern = this->NextLiteralString(scanner(), TENURED); | 1325 IdentifierT js_pattern = this->NextLiteralString(scanner(), TENURED); |
1327 if (!scanner()->ScanRegExpFlags()) { | 1326 if (!scanner()->ScanRegExpFlags()) { |
1328 Next(); | 1327 Next(); |
1329 ReportMessageAt(scanner()->location(), "invalid_regexp_flags"); | 1328 ReportMessage("invalid_regexp_flags"); |
1330 *ok = false; | 1329 *ok = false; |
1331 return Traits::EmptyExpression(); | 1330 return Traits::EmptyExpression(); |
1332 } | 1331 } |
1333 IdentifierT js_flags = this->NextLiteralString(scanner(), TENURED); | 1332 IdentifierT js_flags = this->NextLiteralString(scanner(), TENURED); |
1334 Next(); | 1333 Next(); |
1335 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos); | 1334 return factory()->NewRegExpLiteral(js_pattern, js_flags, literal_index, pos); |
1336 } | 1335 } |
1337 | 1336 |
1338 | 1337 |
1339 #define CHECK_OK ok); \ | 1338 #define CHECK_OK ok); \ |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1662 | 1661 |
1663 typename Traits::Type::ExpressionList result = | 1662 typename Traits::Type::ExpressionList result = |
1664 this->NewExpressionList(4, zone_); | 1663 this->NewExpressionList(4, zone_); |
1665 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); | 1664 Expect(Token::LPAREN, CHECK_OK_CUSTOM(NullExpressionList)); |
1666 bool done = (peek() == Token::RPAREN); | 1665 bool done = (peek() == Token::RPAREN); |
1667 while (!done) { | 1666 while (!done) { |
1668 ExpressionT argument = this->ParseAssignmentExpression( | 1667 ExpressionT argument = this->ParseAssignmentExpression( |
1669 true, CHECK_OK_CUSTOM(NullExpressionList)); | 1668 true, CHECK_OK_CUSTOM(NullExpressionList)); |
1670 result->Add(argument, zone_); | 1669 result->Add(argument, zone_); |
1671 if (result->length() > Code::kMaxArguments) { | 1670 if (result->length() > Code::kMaxArguments) { |
1672 ReportMessageAt(scanner()->location(), "too_many_arguments"); | 1671 ReportMessage("too_many_arguments"); |
1673 *ok = false; | 1672 *ok = false; |
1674 return this->NullExpressionList(); | 1673 return this->NullExpressionList(); |
1675 } | 1674 } |
1676 done = (peek() == Token::RPAREN); | 1675 done = (peek() == Token::RPAREN); |
1677 if (!done) { | 1676 if (!done) { |
1678 // Need {} because of the CHECK_OK_CUSTOM macro. | 1677 // Need {} because of the CHECK_OK_CUSTOM macro. |
1679 Expect(Token::COMMA, CHECK_OK_CUSTOM(NullExpressionList)); | 1678 Expect(Token::COMMA, CHECK_OK_CUSTOM(NullExpressionList)); |
1680 } | 1679 } |
1681 } | 1680 } |
1682 Expect(Token::RPAREN, CHECK_OK_CUSTOM(NullExpressionList)); | 1681 Expect(Token::RPAREN, CHECK_OK_CUSTOM(NullExpressionList)); |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2145 if (property == Token::NUMBER) { | 2144 if (property == Token::NUMBER) { |
2146 old = scanner()->FindNumber(&finder_, type); | 2145 old = scanner()->FindNumber(&finder_, type); |
2147 } else { | 2146 } else { |
2148 old = scanner()->FindSymbol(&finder_, type); | 2147 old = scanner()->FindSymbol(&finder_, type); |
2149 } | 2148 } |
2150 PropertyKind old_type = static_cast<PropertyKind>(old); | 2149 PropertyKind old_type = static_cast<PropertyKind>(old); |
2151 if (HasConflict(old_type, type)) { | 2150 if (HasConflict(old_type, type)) { |
2152 if (IsDataDataConflict(old_type, type)) { | 2151 if (IsDataDataConflict(old_type, type)) { |
2153 // Both are data properties. | 2152 // Both are data properties. |
2154 if (strict_mode_ == SLOPPY) return; | 2153 if (strict_mode_ == SLOPPY) return; |
2155 parser()->ReportMessageAt(scanner()->location(), | 2154 parser()->ReportMessage("strict_duplicate_property"); |
2156 "strict_duplicate_property"); | |
2157 } else if (IsDataAccessorConflict(old_type, type)) { | 2155 } else if (IsDataAccessorConflict(old_type, type)) { |
2158 // Both a data and an accessor property with the same name. | 2156 // Both a data and an accessor property with the same name. |
2159 parser()->ReportMessageAt(scanner()->location(), | 2157 parser()->ReportMessage("accessor_data_property"); |
2160 "accessor_data_property"); | |
2161 } else { | 2158 } else { |
2162 ASSERT(IsAccessorAccessorConflict(old_type, type)); | 2159 ASSERT(IsAccessorAccessorConflict(old_type, type)); |
2163 // Both accessors of the same type. | 2160 // Both accessors of the same type. |
2164 parser()->ReportMessageAt(scanner()->location(), | 2161 parser()->ReportMessage("accessor_get_set"); |
2165 "accessor_get_set"); | |
2166 } | 2162 } |
2167 *ok = false; | 2163 *ok = false; |
2168 } | 2164 } |
2169 } | 2165 } |
2170 | 2166 |
2171 | 2167 |
2172 } } // v8::internal | 2168 } } // v8::internal |
2173 | 2169 |
2174 #endif // V8_PREPARSER_H | 2170 #endif // V8_PREPARSER_H |
OLD | NEW |