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

Side by Side Diff: src/parser.cc

Issue 23597037: Unify handling of position info in AST, part 2 (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Simplify SetExpressionPosition Created 7 years, 3 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/full-codegen.cc ('k') | no next file » | 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 2574 matching lines...) Expand 10 before | Expand all | Expand 10 after
2585 2585
2586 DoWhileStatement* loop = 2586 DoWhileStatement* loop =
2587 factory()->NewDoWhileStatement(labels, peek_position()); 2587 factory()->NewDoWhileStatement(labels, peek_position());
2588 Target target(&this->target_stack_, loop); 2588 Target target(&this->target_stack_, loop);
2589 2589
2590 Expect(Token::DO, CHECK_OK); 2590 Expect(Token::DO, CHECK_OK);
2591 Statement* body = ParseStatement(NULL, CHECK_OK); 2591 Statement* body = ParseStatement(NULL, CHECK_OK);
2592 Expect(Token::WHILE, CHECK_OK); 2592 Expect(Token::WHILE, CHECK_OK);
2593 Expect(Token::LPAREN, CHECK_OK); 2593 Expect(Token::LPAREN, CHECK_OK);
2594 2594
2595 if (loop != NULL) loop->set_condition_position(position());
2596
2597 Expression* cond = ParseExpression(true, CHECK_OK); 2595 Expression* cond = ParseExpression(true, CHECK_OK);
2598 Expect(Token::RPAREN, CHECK_OK); 2596 Expect(Token::RPAREN, CHECK_OK);
2599 2597
2600 // Allow do-statements to be terminated with and without 2598 // Allow do-statements to be terminated with and without
2601 // semi-colons. This allows code such as 'do;while(0)return' to 2599 // semi-colons. This allows code such as 'do;while(0)return' to
2602 // parse, which would not be the case if we had used the 2600 // parse, which would not be the case if we had used the
2603 // ExpectSemicolon() functionality here. 2601 // ExpectSemicolon() functionality here.
2604 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON); 2602 if (peek() == Token::SEMICOLON) Consume(Token::SEMICOLON);
2605 2603
2606 if (loop != NULL) loop->Initialize(cond, body); 2604 if (loop != NULL) loop->Initialize(cond, body);
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
3038 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression 3036 // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression
3039 3037
3040 int pos = peek_position(); 3038 int pos = peek_position();
3041 // We start using the binary expression parser for prec >= 4 only! 3039 // We start using the binary expression parser for prec >= 4 only!
3042 Expression* expression = ParseBinaryExpression(4, accept_IN, CHECK_OK); 3040 Expression* expression = ParseBinaryExpression(4, accept_IN, CHECK_OK);
3043 if (peek() != Token::CONDITIONAL) return expression; 3041 if (peek() != Token::CONDITIONAL) return expression;
3044 Consume(Token::CONDITIONAL); 3042 Consume(Token::CONDITIONAL);
3045 // In parsing the first assignment expression in conditional 3043 // In parsing the first assignment expression in conditional
3046 // expressions we always accept the 'in' keyword; see ECMA-262, 3044 // expressions we always accept the 'in' keyword; see ECMA-262,
3047 // section 11.12, page 58. 3045 // section 11.12, page 58.
3048 int left_position = peek_position();
3049 Expression* left = ParseAssignmentExpression(true, CHECK_OK); 3046 Expression* left = ParseAssignmentExpression(true, CHECK_OK);
3050 Expect(Token::COLON, CHECK_OK); 3047 Expect(Token::COLON, CHECK_OK);
3051 int right_position = peek_position();
3052 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK); 3048 Expression* right = ParseAssignmentExpression(accept_IN, CHECK_OK);
3053 return factory()->NewConditional( 3049 return factory()->NewConditional(expression, left, right, pos);
3054 expression, left, right, left_position, right_position, pos);
3055 } 3050 }
3056 3051
3057 3052
3058 static int Precedence(Token::Value tok, bool accept_IN) { 3053 static int Precedence(Token::Value tok, bool accept_IN) {
3059 if (tok == Token::IN && !accept_IN) 3054 if (tok == Token::IN && !accept_IN)
3060 return 0; // 0 precedence will terminate binary expression parsing 3055 return 0; // 0 precedence will terminate binary expression parsing
3061 3056
3062 return Token::Precedence(tok); 3057 return Token::Precedence(tok);
3063 } 3058 }
3064 3059
(...skipping 2934 matching lines...) Expand 10 before | Expand all | Expand 10 after
5999 ASSERT(info()->isolate()->has_pending_exception()); 5994 ASSERT(info()->isolate()->has_pending_exception());
6000 } else { 5995 } else {
6001 result = ParseProgram(); 5996 result = ParseProgram();
6002 } 5997 }
6003 } 5998 }
6004 info()->SetFunction(result); 5999 info()->SetFunction(result);
6005 return (result != NULL); 6000 return (result != NULL);
6006 } 6001 }
6007 6002
6008 } } // namespace v8::internal 6003 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/full-codegen.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698