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

Side by Side Diff: src/parser.cc

Issue 156673002: Revert "Unify paren handling in Parser and PreParser." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 10 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
« no previous file with comments | « src/ast.cc ('k') | src/preparser.h » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 946 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 case Token::EXPORT: 957 case Token::EXPORT:
958 return ParseExportDeclaration(ok); 958 return ParseExportDeclaration(ok);
959 default: { 959 default: {
960 Statement* stmt = ParseStatement(labels, CHECK_OK); 960 Statement* stmt = ParseStatement(labels, CHECK_OK);
961 // Handle 'module' as a context-sensitive keyword. 961 // Handle 'module' as a context-sensitive keyword.
962 if (FLAG_harmony_modules && 962 if (FLAG_harmony_modules &&
963 peek() == Token::IDENTIFIER && 963 peek() == Token::IDENTIFIER &&
964 !scanner().HasAnyLineTerminatorBeforeNext() && 964 !scanner().HasAnyLineTerminatorBeforeNext() &&
965 stmt != NULL) { 965 stmt != NULL) {
966 ExpressionStatement* estmt = stmt->AsExpressionStatement(); 966 ExpressionStatement* estmt = stmt->AsExpressionStatement();
967 if (estmt != NULL && estmt->expression()->IsIdentifierNamed( 967 if (estmt != NULL &&
968 isolate()->heap()->module_string()) && 968 estmt->expression()->AsVariableProxy() != NULL &&
969 estmt->expression()->AsVariableProxy()->name()->Equals(
970 isolate()->heap()->module_string()) &&
969 !scanner().literal_contains_escapes()) { 971 !scanner().literal_contains_escapes()) {
970 return ParseModuleDeclaration(NULL, ok); 972 return ParseModuleDeclaration(NULL, ok);
971 } 973 }
972 } 974 }
973 return stmt; 975 return stmt;
974 } 976 }
975 } 977 }
976 } 978 }
977 979
978 980
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2117 2119
2118 2120
2119 Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels, 2121 Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels,
2120 bool* ok) { 2122 bool* ok) {
2121 // ExpressionStatement | LabelledStatement :: 2123 // ExpressionStatement | LabelledStatement ::
2122 // Expression ';' 2124 // Expression ';'
2123 // Identifier ':' Statement 2125 // Identifier ':' Statement
2124 int pos = peek_position(); 2126 int pos = peek_position();
2125 bool starts_with_idenfifier = peek_any_identifier(); 2127 bool starts_with_idenfifier = peek_any_identifier();
2126 Expression* expr = ParseExpression(true, CHECK_OK); 2128 Expression* expr = ParseExpression(true, CHECK_OK);
2127 // Even if the expression starts with an identifier, it is not necessarily an
2128 // identifier. For example, "foo + bar" starts with an identifier but is not
2129 // an identifier.
2130 if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL && 2129 if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL &&
2131 expr->IsIdentifier()) { 2130 expr->AsVariableProxy() != NULL &&
2131 !expr->AsVariableProxy()->is_this()) {
2132 // Expression is a single identifier, and not, e.g., a parenthesized 2132 // Expression is a single identifier, and not, e.g., a parenthesized
2133 // identifier. 2133 // identifier.
2134 VariableProxy* var = expr->AsVariableProxy(); 2134 VariableProxy* var = expr->AsVariableProxy();
2135 Handle<String> label = var->name(); 2135 Handle<String> label = var->name();
2136 // TODO(1240780): We don't check for redeclaration of labels 2136 // TODO(1240780): We don't check for redeclaration of labels
2137 // during preparsing since keeping track of the set of active 2137 // during preparsing since keeping track of the set of active
2138 // labels requires nontrivial changes to the way scopes are 2138 // labels requires nontrivial changes to the way scopes are
2139 // structured. However, these are probably changes we want to 2139 // structured. However, these are probably changes we want to
2140 // make later anyway so we should go back and fix this then. 2140 // make later anyway so we should go back and fix this then.
2141 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) { 2141 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) {
(...skipping 16 matching lines...) Expand all
2158 return ParseStatement(labels, ok); 2158 return ParseStatement(labels, ok);
2159 } 2159 }
2160 2160
2161 // If we have an extension, we allow a native function declaration. 2161 // If we have an extension, we allow a native function declaration.
2162 // A native function declaration starts with "native function" with 2162 // A native function declaration starts with "native function" with
2163 // no line-terminator between the two words. 2163 // no line-terminator between the two words.
2164 if (extension_ != NULL && 2164 if (extension_ != NULL &&
2165 peek() == Token::FUNCTION && 2165 peek() == Token::FUNCTION &&
2166 !scanner().HasAnyLineTerminatorBeforeNext() && 2166 !scanner().HasAnyLineTerminatorBeforeNext() &&
2167 expr != NULL && 2167 expr != NULL &&
2168 expr->IsIdentifierNamed(isolate()->heap()->native_string()) && 2168 expr->AsVariableProxy() != NULL &&
2169 expr->AsVariableProxy()->name()->Equals(
2170 isolate()->heap()->native_string()) &&
2169 !scanner().literal_contains_escapes()) { 2171 !scanner().literal_contains_escapes()) {
2170 return ParseNativeDeclaration(ok); 2172 return ParseNativeDeclaration(ok);
2171 } 2173 }
2172 2174
2173 // Parsed expression statement, or the context-sensitive 'module' keyword. 2175 // Parsed expression statement, or the context-sensitive 'module' keyword.
2174 // Only expect semicolon in the former case. 2176 // Only expect semicolon in the former case.
2175 if (!FLAG_harmony_modules || 2177 if (!FLAG_harmony_modules ||
2176 peek() != Token::IDENTIFIER || 2178 peek() != Token::IDENTIFIER ||
2177 scanner().HasAnyLineTerminatorBeforeNext() || 2179 scanner().HasAnyLineTerminatorBeforeNext() ||
2178 !expr->IsIdentifierNamed(isolate()->heap()->module_string()) || 2180 expr->AsVariableProxy() == NULL ||
2181 !expr->AsVariableProxy()->name()->Equals(
2182 isolate()->heap()->module_string()) ||
2179 scanner().literal_contains_escapes()) { 2183 scanner().literal_contains_escapes()) {
2180 ExpectSemicolon(CHECK_OK); 2184 ExpectSemicolon(CHECK_OK);
2181 } 2185 }
2182 return factory()->NewExpressionStatement(expr, pos); 2186 return factory()->NewExpressionStatement(expr, pos);
2183 } 2187 }
2184 2188
2185 2189
2186 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { 2190 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) {
2187 // IfStatement :: 2191 // IfStatement ::
2188 // 'if' '(' Expression ')' Statement ('else' Statement)? 2192 // 'if' '(' Expression ')' Statement ('else' Statement)?
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
2935 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); 2939 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
2936 2940
2937 // TODO(1231235): We try to estimate the set of properties set by 2941 // TODO(1231235): We try to estimate the set of properties set by
2938 // constructors. We define a new property whenever there is an 2942 // constructors. We define a new property whenever there is an
2939 // assignment to a property of 'this'. We should probably only add 2943 // assignment to a property of 'this'. We should probably only add
2940 // properties if we haven't seen them before. Otherwise we'll 2944 // properties if we haven't seen them before. Otherwise we'll
2941 // probably overestimate the number of properties. 2945 // probably overestimate the number of properties.
2942 Property* property = expression ? expression->AsProperty() : NULL; 2946 Property* property = expression ? expression->AsProperty() : NULL;
2943 if (op == Token::ASSIGN && 2947 if (op == Token::ASSIGN &&
2944 property != NULL && 2948 property != NULL &&
2945 property->obj()->IsIdentifier()) { 2949 property->obj()->AsVariableProxy() != NULL &&
2950 property->obj()->AsVariableProxy()->is_this()) {
2946 current_function_state_->AddProperty(); 2951 current_function_state_->AddProperty();
2947 } 2952 }
2948 2953
2949 // If we assign a function literal to a property we pretenure the 2954 // If we assign a function literal to a property we pretenure the
2950 // literal so it can be added as a constant function property. 2955 // literal so it can be added as a constant function property.
2951 if (property != NULL && right->AsFunctionLiteral() != NULL) { 2956 if (property != NULL && right->AsFunctionLiteral() != NULL) {
2952 right->AsFunctionLiteral()->set_pretenure(); 2957 right->AsFunctionLiteral()->set_pretenure();
2953 } 2958 }
2954 2959
2955 if (fni_ != NULL) { 2960 if (fni_ != NULL) {
(...skipping 2727 matching lines...) Expand 10 before | Expand all | Expand 10 after
5683 ASSERT(info()->isolate()->has_pending_exception()); 5688 ASSERT(info()->isolate()->has_pending_exception());
5684 } else { 5689 } else {
5685 result = ParseProgram(); 5690 result = ParseProgram();
5686 } 5691 }
5687 } 5692 }
5688 info()->SetFunction(result); 5693 info()->SetFunction(result);
5689 return (result != NULL); 5694 return (result != NULL);
5690 } 5695 }
5691 5696
5692 } } // namespace v8::internal 5697 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ast.cc ('k') | src/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698