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

Side by Side Diff: src/parser.cc

Issue 150103004: Unify paren handling in (Pre)Parser::ParseExpressionOrLabelledStatement. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: comments 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 && 967 if (estmt != NULL && estmt->expression()->IsIdentifierNamed(
968 estmt->expression()->AsVariableProxy() != NULL && 968 isolate()->heap()->module_string()) &&
969 estmt->expression()->AsVariableProxy()->name()->Equals(
970 isolate()->heap()->module_string()) &&
971 !scanner().literal_contains_escapes()) { 969 !scanner().literal_contains_escapes()) {
972 return ParseModuleDeclaration(NULL, ok); 970 return ParseModuleDeclaration(NULL, ok);
973 } 971 }
974 } 972 }
975 return stmt; 973 return stmt;
976 } 974 }
977 } 975 }
978 } 976 }
979 977
980 978
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2119 2117
2120 2118
2121 Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels, 2119 Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels,
2122 bool* ok) { 2120 bool* ok) {
2123 // ExpressionStatement | LabelledStatement :: 2121 // ExpressionStatement | LabelledStatement ::
2124 // Expression ';' 2122 // Expression ';'
2125 // Identifier ':' Statement 2123 // Identifier ':' Statement
2126 int pos = peek_position(); 2124 int pos = peek_position();
2127 bool starts_with_idenfifier = peek_any_identifier(); 2125 bool starts_with_idenfifier = peek_any_identifier();
2128 Expression* expr = ParseExpression(true, CHECK_OK); 2126 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.
2129 if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL && 2130 if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL &&
2130 expr->AsVariableProxy() != NULL && 2131 expr->IsIdentifier()) {
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->AsVariableProxy() != NULL && 2168 expr->IsIdentifierNamed(isolate()->heap()->native_string()) &&
2169 expr->AsVariableProxy()->name()->Equals(
2170 isolate()->heap()->native_string()) &&
2171 !scanner().literal_contains_escapes()) { 2169 !scanner().literal_contains_escapes()) {
2172 return ParseNativeDeclaration(ok); 2170 return ParseNativeDeclaration(ok);
2173 } 2171 }
2174 2172
2175 // Parsed expression statement, or the context-sensitive 'module' keyword. 2173 // Parsed expression statement, or the context-sensitive 'module' keyword.
2176 // Only expect semicolon in the former case. 2174 // Only expect semicolon in the former case.
2177 if (!FLAG_harmony_modules || 2175 if (!FLAG_harmony_modules ||
2178 peek() != Token::IDENTIFIER || 2176 peek() != Token::IDENTIFIER ||
2179 scanner().HasAnyLineTerminatorBeforeNext() || 2177 scanner().HasAnyLineTerminatorBeforeNext() ||
2180 expr->AsVariableProxy() == NULL || 2178 !expr->IsIdentifierNamed(isolate()->heap()->module_string()) ||
2181 !expr->AsVariableProxy()->name()->Equals(
2182 isolate()->heap()->module_string()) ||
2183 scanner().literal_contains_escapes()) { 2179 scanner().literal_contains_escapes()) {
2184 ExpectSemicolon(CHECK_OK); 2180 ExpectSemicolon(CHECK_OK);
2185 } 2181 }
2186 return factory()->NewExpressionStatement(expr, pos); 2182 return factory()->NewExpressionStatement(expr, pos);
2187 } 2183 }
2188 2184
2189 2185
2190 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { 2186 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) {
2191 // IfStatement :: 2187 // IfStatement ::
2192 // 'if' '(' Expression ')' Statement ('else' Statement)? 2188 // 'if' '(' Expression ')' Statement ('else' Statement)?
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after
2939 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); 2935 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
2940 2936
2941 // TODO(1231235): We try to estimate the set of properties set by 2937 // TODO(1231235): We try to estimate the set of properties set by
2942 // constructors. We define a new property whenever there is an 2938 // constructors. We define a new property whenever there is an
2943 // assignment to a property of 'this'. We should probably only add 2939 // assignment to a property of 'this'. We should probably only add
2944 // properties if we haven't seen them before. Otherwise we'll 2940 // properties if we haven't seen them before. Otherwise we'll
2945 // probably overestimate the number of properties. 2941 // probably overestimate the number of properties.
2946 Property* property = expression ? expression->AsProperty() : NULL; 2942 Property* property = expression ? expression->AsProperty() : NULL;
2947 if (op == Token::ASSIGN && 2943 if (op == Token::ASSIGN &&
2948 property != NULL && 2944 property != NULL &&
2949 property->obj()->AsVariableProxy() != NULL && 2945 property->obj()->IsIdentifier()) {
2950 property->obj()->AsVariableProxy()->is_this()) {
2951 current_function_state_->AddProperty(); 2946 current_function_state_->AddProperty();
2952 } 2947 }
2953 2948
2954 // If we assign a function literal to a property we pretenure the 2949 // If we assign a function literal to a property we pretenure the
2955 // literal so it can be added as a constant function property. 2950 // literal so it can be added as a constant function property.
2956 if (property != NULL && right->AsFunctionLiteral() != NULL) { 2951 if (property != NULL && right->AsFunctionLiteral() != NULL) {
2957 right->AsFunctionLiteral()->set_pretenure(); 2952 right->AsFunctionLiteral()->set_pretenure();
2958 } 2953 }
2959 2954
2960 if (fni_ != NULL) { 2955 if (fni_ != NULL) {
(...skipping 2727 matching lines...) Expand 10 before | Expand all | Expand 10 after
5688 ASSERT(info()->isolate()->has_pending_exception()); 5683 ASSERT(info()->isolate()->has_pending_exception());
5689 } else { 5684 } else {
5690 result = ParseProgram(); 5685 result = ParseProgram();
5691 } 5686 }
5692 } 5687 }
5693 info()->SetFunction(result); 5688 info()->SetFunction(result);
5694 return (result != NULL); 5689 return (result != NULL);
5695 } 5690 }
5696 5691
5697 } } // namespace v8::internal 5692 } } // 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