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

Side by Side Diff: src/parser.cc

Issue 7206020: Make "native" not a keyword. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 6 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/heap.h ('k') | src/preparser.h » ('j') | src/preparser-api.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 1251 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 // of SourceElements. 1262 // of SourceElements.
1263 if (top_scope_->is_strict_mode()) { 1263 if (top_scope_->is_strict_mode()) {
1264 ReportMessageAt(scanner().peek_location(), "strict_function", 1264 ReportMessageAt(scanner().peek_location(), "strict_function",
1265 Vector<const char*>::empty()); 1265 Vector<const char*>::empty());
1266 *ok = false; 1266 *ok = false;
1267 return NULL; 1267 return NULL;
1268 } 1268 }
1269 return ParseFunctionDeclaration(ok); 1269 return ParseFunctionDeclaration(ok);
1270 } 1270 }
1271 1271
1272 case Token::NATIVE:
1273 return ParseNativeDeclaration(ok);
1274
1275 case Token::DEBUGGER: 1272 case Token::DEBUGGER:
1276 stmt = ParseDebuggerStatement(ok); 1273 stmt = ParseDebuggerStatement(ok);
1277 break; 1274 break;
1278 1275
1279 default: 1276 default:
1280 stmt = ParseExpressionOrLabelledStatement(labels, ok); 1277 stmt = ParseExpressionOrLabelledStatement(labels, ok);
1281 } 1278 }
1282 1279
1283 // Store the source position of the statement 1280 // Store the source position of the statement
1284 if (stmt != NULL) stmt->set_statement_pos(statement_pos); 1281 if (stmt != NULL) stmt->set_statement_pos(statement_pos);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 1382
1386 return proxy; 1383 return proxy;
1387 } 1384 }
1388 1385
1389 1386
1390 // Language extension which is only enabled for source files loaded 1387 // Language extension which is only enabled for source files loaded
1391 // through the API's extension mechanism. A native function 1388 // through the API's extension mechanism. A native function
1392 // declaration is resolved by looking up the function through a 1389 // declaration is resolved by looking up the function through a
1393 // callback provided by the extension. 1390 // callback provided by the extension.
1394 Statement* Parser::ParseNativeDeclaration(bool* ok) { 1391 Statement* Parser::ParseNativeDeclaration(bool* ok) {
1395 if (extension_ == NULL) {
1396 ReportUnexpectedToken(Token::NATIVE);
1397 *ok = false;
1398 return NULL;
1399 }
1400
1401 Expect(Token::NATIVE, CHECK_OK);
1402 Expect(Token::FUNCTION, CHECK_OK); 1392 Expect(Token::FUNCTION, CHECK_OK);
1403 Handle<String> name = ParseIdentifier(CHECK_OK); 1393 Handle<String> name = ParseIdentifier(CHECK_OK);
1404 Expect(Token::LPAREN, CHECK_OK); 1394 Expect(Token::LPAREN, CHECK_OK);
1405 bool done = (peek() == Token::RPAREN); 1395 bool done = (peek() == Token::RPAREN);
1406 while (!done) { 1396 while (!done) {
1407 ParseIdentifier(CHECK_OK); 1397 ParseIdentifier(CHECK_OK);
1408 done = (peek() == Token::RPAREN); 1398 done = (peek() == Token::RPAREN);
1409 if (!done) { 1399 if (!done) {
1410 Expect(Token::COMMA, CHECK_OK); 1400 Expect(Token::COMMA, CHECK_OK);
1411 } 1401 }
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1744 } 1734 }
1745 1735
1746 1736
1747 Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels, 1737 Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels,
1748 bool* ok) { 1738 bool* ok) {
1749 // ExpressionStatement | LabelledStatement :: 1739 // ExpressionStatement | LabelledStatement ::
1750 // Expression ';' 1740 // Expression ';'
1751 // Identifier ':' Statement 1741 // Identifier ':' Statement
1752 bool starts_with_idenfifier = peek_any_identifier(); 1742 bool starts_with_idenfifier = peek_any_identifier();
1753 Expression* expr = ParseExpression(true, CHECK_OK); 1743 Expression* expr = ParseExpression(true, CHECK_OK);
1754 if (peek() == Token::COLON && starts_with_idenfifier && expr && 1744 if (peek() == Token::COLON && starts_with_idenfifier && expr != NULL &&
1755 expr->AsVariableProxy() != NULL && 1745 expr->AsVariableProxy() != NULL &&
1756 !expr->AsVariableProxy()->is_this()) { 1746 !expr->AsVariableProxy()->is_this()) {
1757 // Expression is a single identifier, and not, e.g., a parenthesized 1747 // Expression is a single identifier, and not, e.g., a parenthesized
1758 // identifier. 1748 // identifier.
1759 VariableProxy* var = expr->AsVariableProxy(); 1749 VariableProxy* var = expr->AsVariableProxy();
1760 Handle<String> label = var->name(); 1750 Handle<String> label = var->name();
1761 // TODO(1240780): We don't check for redeclaration of labels 1751 // TODO(1240780): We don't check for redeclaration of labels
1762 // during preparsing since keeping track of the set of active 1752 // during preparsing since keeping track of the set of active
1763 // labels requires nontrivial changes to the way scopes are 1753 // labels requires nontrivial changes to the way scopes are
1764 // structured. However, these are probably changes we want to 1754 // structured. However, these are probably changes we want to
1765 // make later anyway so we should go back and fix this then. 1755 // make later anyway so we should go back and fix this then.
1766 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) { 1756 if (ContainsLabel(labels, label) || TargetStackContainsLabel(label)) {
1767 SmartPointer<char> c_string = label->ToCString(DISALLOW_NULLS); 1757 SmartPointer<char> c_string = label->ToCString(DISALLOW_NULLS);
1768 const char* elms[2] = { "Label", *c_string }; 1758 const char* elms[2] = { "Label", *c_string };
1769 Vector<const char*> args(elms, 2); 1759 Vector<const char*> args(elms, 2);
1770 ReportMessage("redeclaration", args); 1760 ReportMessage("redeclaration", args);
1771 *ok = false; 1761 *ok = false;
1772 return NULL; 1762 return NULL;
1773 } 1763 }
1774 if (labels == NULL) labels = new(zone()) ZoneStringList(4); 1764 if (labels == NULL) labels = new(zone()) ZoneStringList(4);
1775 labels->Add(label); 1765 labels->Add(label);
1776 // Remove the "ghost" variable that turned out to be a label 1766 // Remove the "ghost" variable that turned out to be a label
1777 // from the top scope. This way, we don't try to resolve it 1767 // from the top scope. This way, we don't try to resolve it
1778 // during the scope processing. 1768 // during the scope processing.
1779 top_scope_->RemoveUnresolved(var); 1769 top_scope_->RemoveUnresolved(var);
1780 Expect(Token::COLON, CHECK_OK); 1770 Expect(Token::COLON, CHECK_OK);
1781 return ParseStatement(labels, ok); 1771 return ParseStatement(labels, ok);
1782 } 1772 }
1783 1773
1774 // If we have an extension, we allow a native function declaration.
1775 // A native function declaration starts with "native function" with
1776 // no line-terminator between the two words.
1777 if (extension_ != NULL &&
1778 peek() == Token::FUNCTION &&
1779 !scanner().has_line_terminator_before_next() &&
1780 expr != NULL &&
1781 expr->AsVariableProxy() != NULL &&
1782 expr->AsVariableProxy()->name()->Equals(
1783 isolate()->heap()->native_symbol())) {
1784 return ParseNativeDeclaration(ok);
1785 }
1786
1784 // Parsed expression statement. 1787 // Parsed expression statement.
1785 ExpectSemicolon(CHECK_OK); 1788 ExpectSemicolon(CHECK_OK);
1786 return new(zone()) ExpressionStatement(expr); 1789 return new(zone()) ExpressionStatement(expr);
1787 } 1790 }
1788 1791
1789 1792
1790 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { 1793 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) {
1791 // IfStatement :: 1794 // IfStatement ::
1792 // 'if' '(' Expression ')' Statement ('else' Statement)? 1795 // 'if' '(' Expression ')' Statement ('else' Statement)?
1793 1796
(...skipping 3173 matching lines...) Expand 10 before | Expand all | Expand 10 after
4967 4970
4968 4971
4969 bool ParserApi::Parse(CompilationInfo* info) { 4972 bool ParserApi::Parse(CompilationInfo* info) {
4970 ASSERT(info->function() == NULL); 4973 ASSERT(info->function() == NULL);
4971 FunctionLiteral* result = NULL; 4974 FunctionLiteral* result = NULL;
4972 Handle<Script> script = info->script(); 4975 Handle<Script> script = info->script();
4973 if (info->is_lazy()) { 4976 if (info->is_lazy()) {
4974 Parser parser(script, true, NULL, NULL); 4977 Parser parser(script, true, NULL, NULL);
4975 result = parser.ParseLazy(info); 4978 result = parser.ParseLazy(info);
4976 } else { 4979 } else {
4980 // Whether we allow %identifier(..) syntax.
4977 bool allow_natives_syntax = 4981 bool allow_natives_syntax =
4978 info->allows_natives_syntax() || FLAG_allow_natives_syntax; 4982 info->allows_natives_syntax() || FLAG_allow_natives_syntax;
4979 ScriptDataImpl* pre_data = info->pre_parse_data(); 4983 ScriptDataImpl* pre_data = info->pre_parse_data();
4980 Parser parser(script, allow_natives_syntax, info->extension(), pre_data); 4984 Parser parser(script, allow_natives_syntax, info->extension(), pre_data);
4981 if (pre_data != NULL && pre_data->has_error()) { 4985 if (pre_data != NULL && pre_data->has_error()) {
4982 Scanner::Location loc = pre_data->MessageLocation(); 4986 Scanner::Location loc = pre_data->MessageLocation();
4983 const char* message = pre_data->BuildMessage(); 4987 const char* message = pre_data->BuildMessage();
4984 Vector<const char*> args = pre_data->BuildArgs(); 4988 Vector<const char*> args = pre_data->BuildArgs();
4985 parser.ReportMessageAt(loc, message, args); 4989 parser.ReportMessageAt(loc, message, args);
4986 DeleteArray(message); 4990 DeleteArray(message);
4987 for (int i = 0; i < args.length(); i++) { 4991 for (int i = 0; i < args.length(); i++) {
4988 DeleteArray(args[i]); 4992 DeleteArray(args[i]);
4989 } 4993 }
4990 DeleteArray(args.start()); 4994 DeleteArray(args.start());
4991 ASSERT(info->isolate()->has_pending_exception()); 4995 ASSERT(info->isolate()->has_pending_exception());
4992 } else { 4996 } else {
4993 Handle<String> source = Handle<String>(String::cast(script->source())); 4997 Handle<String> source = Handle<String>(String::cast(script->source()));
4994 result = parser.ParseProgram(source, 4998 result = parser.ParseProgram(source,
4995 info->is_global(), 4999 info->is_global(),
4996 info->StrictMode()); 5000 info->StrictMode());
4997 } 5001 }
4998 } 5002 }
4999 5003
5000 info->SetFunction(result); 5004 info->SetFunction(result);
5001 return (result != NULL); 5005 return (result != NULL);
5002 } 5006 }
5003 5007
5004 } } // namespace v8::internal 5008 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/heap.h ('k') | src/preparser.h » ('j') | src/preparser-api.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698