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

Unified Diff: src/ast/ast.h

Issue 1309813007: [es6] implement destructuring assignment (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Oh god it seems to work again thank goodness Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/ast/ast-expression-visitor.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ast/ast.h
diff --git a/src/ast/ast.h b/src/ast/ast.h
index 1c053ddf076ac166903b3e4d7ec2fa8dbef43ab2..4e3c5c598a32a80058e2bf3ed27f2a3e4db4670e 100644
--- a/src/ast/ast.h
+++ b/src/ast/ast.h
@@ -91,7 +91,8 @@ namespace internal {
V(SuperCallReference) \
V(CaseClause) \
V(EmptyParentheses) \
- V(DoExpression)
+ V(DoExpression) \
+ V(RewritableExpression)
#define AST_NODE_LIST(V) \
DECLARATION_NODE_LIST(V) \
@@ -402,6 +403,53 @@ class Expression : public AstNode {
};
+class RewritableExpression : public Expression {
+ public:
+ DECLARE_NODE_TYPE(RewritableExpression)
+
+ enum RewriteHint {
+ // Reasons for a rewrite to occur.
+ kDestructuringAssignment = 1,
+ };
+
+ Expression* expression() { return expr_; }
+ int hints() const { return RewriteHintsField::decode(bit_field_); }
adamk 2015/12/02 01:13:13 This returns an int, but will only ever be kDestru
+
+ bool IsRewritableAs(RewriteHint hint) const {
adamk 2015/12/02 01:13:13 There is only a single argument that could be pass
+ return (RewriteHintsField::decode(bit_field_) & hint) != 0 &&
+ !IsRewrittenAs(hint);
+ }
+
+ bool IsRewrittenAs(RewriteHint reason) const {
adamk 2015/12/02 01:13:13 Ditto
+ return (RewriteReasonField::decode(bit_field_) & reason) != 0;
+ }
+
+ void RewriteAs(Expression* new_expression, RewriteHint reason) {
adamk 2015/12/02 01:13:13 And again, the second argument here is can only ev
+ DCHECK(!IsRewrittenAs(reason));
+ DCHECK((RewriteHintsField::decode(bit_field_) & reason) != 0);
+ expr_ = new_expression;
+ bit_field_ = RewriteReasonField::update(bit_field_, reason);
+ }
+
+ static int num_ids() { return parent_num_ids(); }
+
+ protected:
+ RewritableExpression(Zone* zone, Expression* expression, int hints)
+ : Expression(zone, expression->position()),
+ bit_field_(RewriteHintsField::encode(hints)),
+ expr_(expression) {}
+
+ private:
+ int local_id(int n) const { return base_id() + parent_num_ids() + n; }
+
+ uint8_t bit_field_;
+ Expression* expr_;
+ class RewriteHintsField : public BitField<uint16_t, 0, 4> {};
adamk 2015/12/02 01:13:13 This bit field wouldn't be necessary, you could ha
+ class RewriteReasonField
+ : public BitField<uint16_t, RewriteHintsField::kNext, 4> {};
+};
+
+
class BreakableStatement : public Statement {
public:
enum BreakableType {
@@ -2333,6 +2381,7 @@ class Assignment final : public Expression {
Token::Value op() const { return TokenField::decode(bit_field_); }
Expression* target() const { return target_; }
Expression* value() const { return value_; }
+
BinaryOperation* binary_operation() const { return binary_operation_; }
// This check relies on the definition order of token in token.h.
@@ -2380,9 +2429,12 @@ class Assignment final : public Expression {
int local_id(int n) const { return base_id() + parent_num_ids() + n; }
class IsUninitializedField : public BitField16<bool, 0, 1> {};
- class KeyTypeField : public BitField16<IcCheckType, 1, 1> {};
- class StoreModeField : public BitField16<KeyedAccessStoreMode, 2, 3> {};
- class TokenField : public BitField16<Token::Value, 5, 8> {};
+ class KeyTypeField
+ : public BitField16<IcCheckType, IsUninitializedField::kNext, 1> {};
+ class StoreModeField
+ : public BitField16<KeyedAccessStoreMode, KeyTypeField::kNext, 3> {};
+ class TokenField : public BitField16<Token::Value, StoreModeField::kNext, 8> {
+ };
// Starts with 16-bit field, which should get packed together with
// Expression's trailing 16-bit field.
@@ -3195,7 +3247,6 @@ class AstVisitor BASE_EMBEDDED {
#undef DEF_VISIT
};
-
#define DEFINE_AST_VISITOR_SUBCLASS_MEMBERS() \
public: \
void Visit(AstNode* node) final { \
@@ -3548,6 +3599,14 @@ class AstNodeFactory final BASE_EMBEDDED {
local_zone_, condition, then_expression, else_expression, position);
}
+ RewritableExpression* NewRewritableExpression(Expression* expression,
+ int hints) {
+ DCHECK_NOT_NULL(expression);
+ DCHECK(hints);
+ return new (local_zone_)
+ RewritableExpression(local_zone_, expression, hints);
+ }
+
Assignment* NewAssignment(Token::Value op,
Expression* target,
Expression* value,
« no previous file with comments | « no previous file | src/ast/ast-expression-visitor.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698