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_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 allow_harmony_restrictive_declarations_(false), | 114 allow_harmony_restrictive_declarations_(false), |
115 allow_legacy_const_(true), | 115 allow_legacy_const_(true), |
116 allow_harmony_do_expressions_(false), | 116 allow_harmony_do_expressions_(false), |
117 allow_harmony_function_name_(false), | 117 allow_harmony_function_name_(false), |
118 allow_harmony_function_sent_(false) {} | 118 allow_harmony_function_sent_(false) {} |
119 | 119 |
120 #define ALLOW_ACCESSORS(name) \ | 120 #define ALLOW_ACCESSORS(name) \ |
121 bool allow_##name() const { return allow_##name##_; } \ | 121 bool allow_##name() const { return allow_##name##_; } \ |
122 void set_allow_##name(bool allow) { allow_##name##_ = allow; } | 122 void set_allow_##name(bool allow) { allow_##name##_ = allow; } |
123 | 123 |
124 #define SCANNER_ACCESSORS(name) \ | |
125 bool allow_##name() const { return scanner_->allow_##name(); } \ | |
126 void set_allow_##name(bool allow) { \ | |
127 return scanner_->set_allow_##name(allow); \ | |
128 } | |
129 | |
124 ALLOW_ACCESSORS(lazy); | 130 ALLOW_ACCESSORS(lazy); |
125 ALLOW_ACCESSORS(natives); | 131 ALLOW_ACCESSORS(natives); |
126 ALLOW_ACCESSORS(harmony_sloppy); | 132 ALLOW_ACCESSORS(harmony_sloppy); |
127 ALLOW_ACCESSORS(harmony_sloppy_function); | 133 ALLOW_ACCESSORS(harmony_sloppy_function); |
128 ALLOW_ACCESSORS(harmony_sloppy_let); | 134 ALLOW_ACCESSORS(harmony_sloppy_let); |
129 ALLOW_ACCESSORS(harmony_restrictive_declarations); | 135 ALLOW_ACCESSORS(harmony_restrictive_declarations); |
130 ALLOW_ACCESSORS(legacy_const); | 136 ALLOW_ACCESSORS(legacy_const); |
131 ALLOW_ACCESSORS(harmony_do_expressions); | 137 ALLOW_ACCESSORS(harmony_do_expressions); |
132 ALLOW_ACCESSORS(harmony_function_name); | 138 ALLOW_ACCESSORS(harmony_function_name); |
133 ALLOW_ACCESSORS(harmony_function_sent); | 139 ALLOW_ACCESSORS(harmony_function_sent); |
140 SCANNER_ACCESSORS(harmony_exponentiation_operator); | |
134 #undef ALLOW_ACCESSORS | 141 #undef ALLOW_ACCESSORS |
nickie
2016/03/21 08:51:49
Shouldn't there be an #undef SCANNER_ACCESSORS her
caitp (gmail)
2016/03/21 10:44:17
Yes, there should! I'm surprised this doesn't trig
caitp (gmail)
2016/03/21 10:50:03
well, I guess I used a different name in scanner.h
| |
135 | 142 |
136 uintptr_t stack_limit() const { return stack_limit_; } | 143 uintptr_t stack_limit() const { return stack_limit_; } |
137 | 144 |
138 protected: | 145 protected: |
139 enum AllowRestrictedIdentifiers { | 146 enum AllowRestrictedIdentifiers { |
140 kAllowRestrictedIdentifiers, | 147 kAllowRestrictedIdentifiers, |
141 kDontAllowRestrictedIdentifiers | 148 kDontAllowRestrictedIdentifiers |
142 }; | 149 }; |
143 | 150 |
144 enum Mode { | 151 enum Mode { |
(...skipping 1858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2003 fni_->Infer(); | 2010 fni_->Infer(); |
2004 } else { | 2011 } else { |
2005 fni_->RemoveLastFunction(); | 2012 fni_->RemoveLastFunction(); |
2006 } | 2013 } |
2007 } | 2014 } |
2008 | 2015 |
2009 if (op == Token::ASSIGN && allow_harmony_function_name()) { | 2016 if (op == Token::ASSIGN && allow_harmony_function_name()) { |
2010 Traits::SetFunctionNameFromIdentifierRef(right, expression); | 2017 Traits::SetFunctionNameFromIdentifierRef(right, expression); |
2011 } | 2018 } |
2012 | 2019 |
2020 if (op == Token::ASSIGN_EXP) { | |
2021 DCHECK(!is_destructuring_assignment); | |
2022 return Traits::RewriteAssignExponentiation(expression, right, pos); | |
2023 } | |
2024 | |
2013 ExpressionT result = factory()->NewAssignment(op, expression, right, pos); | 2025 ExpressionT result = factory()->NewAssignment(op, expression, right, pos); |
2014 | 2026 |
2015 if (is_destructuring_assignment) { | 2027 if (is_destructuring_assignment) { |
2016 result = factory()->NewRewritableExpression(result); | 2028 result = factory()->NewRewritableExpression(result); |
2017 Traits::QueueDestructuringAssignmentForRewriting(result); | 2029 Traits::QueueDestructuringAssignmentForRewriting(result); |
2018 } | 2030 } |
2019 | 2031 |
2020 return result; | 2032 return result; |
2021 } | 2033 } |
2022 | 2034 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2112 DCHECK(prec >= 4); | 2124 DCHECK(prec >= 4); |
2113 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); | 2125 ExpressionT x = this->ParseUnaryExpression(classifier, CHECK_OK); |
2114 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { | 2126 for (int prec1 = Precedence(peek(), accept_IN); prec1 >= prec; prec1--) { |
2115 // prec1 >= 4 | 2127 // prec1 >= 4 |
2116 while (Precedence(peek(), accept_IN) == prec1) { | 2128 while (Precedence(peek(), accept_IN) == prec1) { |
2117 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2129 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2118 BindingPatternUnexpectedToken(classifier); | 2130 BindingPatternUnexpectedToken(classifier); |
2119 ArrowFormalParametersUnexpectedToken(classifier); | 2131 ArrowFormalParametersUnexpectedToken(classifier); |
2120 Token::Value op = Next(); | 2132 Token::Value op = Next(); |
2121 int pos = position(); | 2133 int pos = position(); |
2134 | |
2135 const bool is_right_associative = op == Token::EXP; | |
2136 const int next_prec = is_right_associative ? prec1 : prec1 + 1; | |
2122 ExpressionT y = | 2137 ExpressionT y = |
2123 ParseBinaryExpression(prec1 + 1, accept_IN, classifier, CHECK_OK); | 2138 ParseBinaryExpression(next_prec, accept_IN, classifier, CHECK_OK); |
2124 Traits::RewriteNonPattern(classifier, CHECK_OK); | 2139 Traits::RewriteNonPattern(classifier, CHECK_OK); |
2125 | 2140 |
2126 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, | 2141 if (this->ShortcutNumericLiteralBinaryExpression(&x, y, op, pos, |
2127 factory())) { | 2142 factory())) { |
2128 continue; | 2143 continue; |
2129 } | 2144 } |
2130 | 2145 |
2131 // For now we distinguish between comparisons and other binary | 2146 // For now we distinguish between comparisons and other binary |
2132 // operations. (We could combine the two and get rid of this | 2147 // operations. (We could combine the two and get rid of this |
2133 // code and AST node eventually.) | 2148 // code and AST node eventually.) |
2134 if (Token::IsCompareOp(op)) { | 2149 if (Token::IsCompareOp(op)) { |
2135 // We have a comparison. | 2150 // We have a comparison. |
2136 Token::Value cmp = op; | 2151 Token::Value cmp = op; |
2137 switch (op) { | 2152 switch (op) { |
2138 case Token::NE: cmp = Token::EQ; break; | 2153 case Token::NE: cmp = Token::EQ; break; |
2139 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break; | 2154 case Token::NE_STRICT: cmp = Token::EQ_STRICT; break; |
2140 default: break; | 2155 default: break; |
2141 } | 2156 } |
2142 if (FLAG_harmony_instanceof && cmp == Token::INSTANCEOF) { | 2157 if (FLAG_harmony_instanceof && cmp == Token::INSTANCEOF) { |
2143 x = Traits::RewriteInstanceof(x, y, pos); | 2158 x = Traits::RewriteInstanceof(x, y, pos); |
2144 } else { | 2159 } else { |
2145 x = factory()->NewCompareOperation(cmp, x, y, pos); | 2160 x = factory()->NewCompareOperation(cmp, x, y, pos); |
2146 if (cmp != op) { | 2161 if (cmp != op) { |
2147 // The comparison was negated - add a NOT. | 2162 // The comparison was negated - add a NOT. |
2148 x = factory()->NewUnaryOperation(Token::NOT, x, pos); | 2163 x = factory()->NewUnaryOperation(Token::NOT, x, pos); |
2149 } | 2164 } |
2150 } | 2165 } |
2166 | |
2167 } else if (op == Token::EXP) { | |
2168 x = Traits::RewriteExponentiation(x, y, pos); | |
2151 } else { | 2169 } else { |
2152 // We have a "normal" binary operation. | 2170 // We have a "normal" binary operation. |
2153 x = factory()->NewBinaryOperation(op, x, y, pos); | 2171 x = factory()->NewBinaryOperation(op, x, y, pos); |
2154 } | 2172 } |
2155 } | 2173 } |
2156 } | 2174 } |
2157 return x; | 2175 return x; |
2158 } | 2176 } |
2159 | 2177 |
2160 | 2178 |
(...skipping 25 matching lines...) Expand all Loading... | |
2186 | 2204 |
2187 if (op == Token::DELETE && is_strict(language_mode())) { | 2205 if (op == Token::DELETE && is_strict(language_mode())) { |
2188 if (this->IsIdentifier(expression)) { | 2206 if (this->IsIdentifier(expression)) { |
2189 // "delete identifier" is a syntax error in strict mode. | 2207 // "delete identifier" is a syntax error in strict mode. |
2190 ReportMessage(MessageTemplate::kStrictDelete); | 2208 ReportMessage(MessageTemplate::kStrictDelete); |
2191 *ok = false; | 2209 *ok = false; |
2192 return this->EmptyExpression(); | 2210 return this->EmptyExpression(); |
2193 } | 2211 } |
2194 } | 2212 } |
2195 | 2213 |
2214 if (peek() == Token::EXP) { | |
2215 ReportUnexpectedToken(Next()); | |
2216 *ok = false; | |
2217 return this->EmptyExpression(); | |
2218 } | |
2219 | |
2196 // Allow Traits do rewrite the expression. | 2220 // Allow Traits do rewrite the expression. |
2197 return this->BuildUnaryExpression(expression, op, pos, factory()); | 2221 return this->BuildUnaryExpression(expression, op, pos, factory()); |
2198 } else if (Token::IsCountOp(op)) { | 2222 } else if (Token::IsCountOp(op)) { |
2199 BindingPatternUnexpectedToken(classifier); | 2223 BindingPatternUnexpectedToken(classifier); |
2200 ArrowFormalParametersUnexpectedToken(classifier); | 2224 ArrowFormalParametersUnexpectedToken(classifier); |
2201 op = Next(); | 2225 op = Next(); |
2202 int beg_pos = peek_position(); | 2226 int beg_pos = peek_position(); |
2203 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); | 2227 ExpressionT expression = this->ParseUnaryExpression(classifier, CHECK_OK); |
2204 expression = this->CheckAndRewriteReferenceExpression( | 2228 expression = this->CheckAndRewriteReferenceExpression( |
2205 expression, beg_pos, scanner()->location().end_pos, | 2229 expression, beg_pos, scanner()->location().end_pos, |
(...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3083 has_seen_constructor_ = true; | 3107 has_seen_constructor_ = true; |
3084 return; | 3108 return; |
3085 } | 3109 } |
3086 } | 3110 } |
3087 | 3111 |
3088 | 3112 |
3089 } // namespace internal | 3113 } // namespace internal |
3090 } // namespace v8 | 3114 } // namespace v8 |
3091 | 3115 |
3092 #endif // V8_PARSING_PARSER_BASE_H | 3116 #endif // V8_PARSING_PARSER_BASE_H |
OLD | NEW |