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

Side by Side Diff: src/parser.cc

Issue 348038: Add support for initialization block assignments in the toplevel code... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Add support for initialization block assignments in the toplevel code... Created 11 years, 1 month 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/ia32/fast-codegen-ia32.cc ('k') | src/x64/fast-codegen-x64.cc » ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 1321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 static Assignment* AsAssignment(Statement* stat) { 1332 static Assignment* AsAssignment(Statement* stat) {
1333 if (stat == NULL) return NULL; 1333 if (stat == NULL) return NULL;
1334 ExpressionStatement* exp_stat = stat->AsExpressionStatement(); 1334 ExpressionStatement* exp_stat = stat->AsExpressionStatement();
1335 if (exp_stat == NULL) return NULL; 1335 if (exp_stat == NULL) return NULL;
1336 return exp_stat->expression()->AsAssignment(); 1336 return exp_stat->expression()->AsAssignment();
1337 } 1337 }
1338 }; 1338 };
1339 1339
1340 1340
1341 // An InitializationBlockFinder finds and marks sequences of statements of the 1341 // An InitializationBlockFinder finds and marks sequences of statements of the
1342 // form x.y.z.a = ...; x.y.z.b = ...; etc. 1342 // form expr.a = ...; expr.b = ...; etc.
1343 class InitializationBlockFinder : public ParserFinder { 1343 class InitializationBlockFinder : public ParserFinder {
1344 public: 1344 public:
1345 InitializationBlockFinder() 1345 InitializationBlockFinder()
1346 : first_in_block_(NULL), last_in_block_(NULL), block_size_(0) {} 1346 : first_in_block_(NULL), last_in_block_(NULL), block_size_(0) {}
1347 1347
1348 ~InitializationBlockFinder() { 1348 ~InitializationBlockFinder() {
1349 if (InBlock()) EndBlock(); 1349 if (InBlock()) EndBlock();
1350 } 1350 }
1351 1351
1352 void Update(Statement* stat) { 1352 void Update(Statement* stat) {
1353 Assignment* assignment = AsAssignment(stat); 1353 Assignment* assignment = AsAssignment(stat);
1354 if (InBlock()) { 1354 if (InBlock()) {
1355 if (BlockContinues(assignment)) { 1355 if (BlockContinues(assignment)) {
1356 UpdateBlock(assignment); 1356 UpdateBlock(assignment);
1357 } else { 1357 } else {
1358 EndBlock(); 1358 EndBlock();
1359 } 1359 }
1360 } 1360 }
1361 if (!InBlock() && (assignment != NULL) && 1361 if (!InBlock() && (assignment != NULL) &&
1362 (assignment->op() == Token::ASSIGN)) { 1362 (assignment->op() == Token::ASSIGN)) {
1363 StartBlock(assignment); 1363 StartBlock(assignment);
1364 } 1364 }
1365 } 1365 }
1366 1366
1367 private: 1367 private:
1368 // Returns true if the expressions appear to denote the same object. 1368 // Returns true if the expressions appear to denote the same object.
1369 // In the context of initialization blocks, we only consider expressions 1369 // In the context of initialization blocks, we only consider expressions
1370 // of the form 'x.y.z'. 1370 // of the form 'expr.x' or expr["x"].
1371 static bool SameObject(Expression* e1, Expression* e2) { 1371 static bool SameObject(Expression* e1, Expression* e2) {
1372 VariableProxy* v1 = e1->AsVariableProxy(); 1372 VariableProxy* v1 = e1->AsVariableProxy();
1373 VariableProxy* v2 = e2->AsVariableProxy(); 1373 VariableProxy* v2 = e2->AsVariableProxy();
1374 if (v1 != NULL && v2 != NULL) { 1374 if (v1 != NULL && v2 != NULL) {
1375 return v1->name()->Equals(*v2->name()); 1375 return v1->name()->Equals(*v2->name());
1376 } 1376 }
1377 Property* p1 = e1->AsProperty(); 1377 Property* p1 = e1->AsProperty();
1378 Property* p2 = e2->AsProperty(); 1378 Property* p2 = e2->AsProperty();
1379 if ((p1 == NULL) || (p2 == NULL)) return false; 1379 if ((p1 == NULL) || (p2 == NULL)) return false;
1380 Literal* key1 = p1->key()->AsLiteral(); 1380 Literal* key1 = p1->key()->AsLiteral();
(...skipping 3430 matching lines...) Expand 10 before | Expand all | Expand 10 after
4811 start_position, 4811 start_position,
4812 is_expression); 4812 is_expression);
4813 return result; 4813 return result;
4814 } 4814 }
4815 4815
4816 4816
4817 #undef NEW 4817 #undef NEW
4818 4818
4819 4819
4820 } } // namespace v8::internal 4820 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/ia32/fast-codegen-ia32.cc ('k') | src/x64/fast-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698