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

Side by Side Diff: src/parser.cc

Issue 9615009: Basic interface inference for modules. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Eps. Created 8 years, 9 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/parser.h ('k') | src/scopes.h » ('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 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 739 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 return LookupSymbol(symbol_id); 750 return LookupSymbol(symbol_id);
751 } 751 }
752 752
753 753
754 void Parser::ReportMessage(const char* type, Vector<const char*> args) { 754 void Parser::ReportMessage(const char* type, Vector<const char*> args) {
755 Scanner::Location source_location = scanner().location(); 755 Scanner::Location source_location = scanner().location();
756 ReportMessageAt(source_location, type, args); 756 ReportMessageAt(source_location, type, args);
757 } 757 }
758 758
759 759
760 void Parser::ReportMessage(const char* type, Vector<Handle<String> > args) {
761 Scanner::Location source_location = scanner().location();
762 ReportMessageAt(source_location, type, args);
763 }
764
765
760 void Parser::ReportMessageAt(Scanner::Location source_location, 766 void Parser::ReportMessageAt(Scanner::Location source_location,
761 const char* type, 767 const char* type,
762 Vector<const char*> args) { 768 Vector<const char*> args) {
763 MessageLocation location(script_, 769 MessageLocation location(script_,
764 source_location.beg_pos, 770 source_location.beg_pos,
765 source_location.end_pos); 771 source_location.end_pos);
766 Factory* factory = isolate()->factory(); 772 Factory* factory = isolate()->factory();
767 Handle<FixedArray> elements = factory->NewFixedArray(args.length()); 773 Handle<FixedArray> elements = factory->NewFixedArray(args.length());
768 for (int i = 0; i < args.length(); i++) { 774 for (int i = 0; i < args.length(); i++) {
769 Handle<String> arg_string = factory->NewStringFromUtf8(CStrVector(args[i])); 775 Handle<String> arg_string = factory->NewStringFromUtf8(CStrVector(args[i]));
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 if (top_scope_->is_function_scope()) { 1162 if (top_scope_->is_function_scope()) {
1157 bool only_simple_this_property_assignments = 1163 bool only_simple_this_property_assignments =
1158 this_property_assignment_finder.only_simple_this_property_assignments() 1164 this_property_assignment_finder.only_simple_this_property_assignments()
1159 && top_scope_->declarations()->length() == 0; 1165 && top_scope_->declarations()->length() == 0;
1160 if (only_simple_this_property_assignments) { 1166 if (only_simple_this_property_assignments) {
1161 current_function_state_->SetThisPropertyAssignmentInfo( 1167 current_function_state_->SetThisPropertyAssignmentInfo(
1162 only_simple_this_property_assignments, 1168 only_simple_this_property_assignments,
1163 this_property_assignment_finder.GetThisPropertyAssignments()); 1169 this_property_assignment_finder.GetThisPropertyAssignments());
1164 } 1170 }
1165 } 1171 }
1172
1166 return 0; 1173 return 0;
1167 } 1174 }
1168 1175
1169 1176
1170 Statement* Parser::ParseModuleElement(ZoneStringList* labels, 1177 Statement* Parser::ParseModuleElement(ZoneStringList* labels,
1171 bool* ok) { 1178 bool* ok) {
1172 // (Ecma 262 5th Edition, clause 14): 1179 // (Ecma 262 5th Edition, clause 14):
1173 // SourceElement: 1180 // SourceElement:
1174 // Statement 1181 // Statement
1175 // FunctionDeclaration 1182 // FunctionDeclaration
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 } 1221 }
1215 1222
1216 1223
1217 Block* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) { 1224 Block* Parser::ParseModuleDeclaration(ZoneStringList* names, bool* ok) {
1218 // ModuleDeclaration: 1225 // ModuleDeclaration:
1219 // 'module' Identifier Module 1226 // 'module' Identifier Module
1220 1227
1221 // Create new block with one expected declaration. 1228 // Create new block with one expected declaration.
1222 Block* block = factory()->NewBlock(NULL, 1, true); 1229 Block* block = factory()->NewBlock(NULL, 1, true);
1223 Handle<String> name = ParseIdentifier(CHECK_OK); 1230 Handle<String> name = ParseIdentifier(CHECK_OK);
1231
1232 #ifdef DEBUG
1233 if (FLAG_print_interface_details)
1234 PrintF("# Module %s...\n", name->ToAsciiArray());
1235 #endif
1236
1224 Module* module = ParseModule(CHECK_OK); 1237 Module* module = ParseModule(CHECK_OK);
1225 VariableProxy* proxy = NewUnresolved(name, LET); 1238 VariableProxy* proxy = NewUnresolved(name, LET, module->interface());
1226 Declaration* declaration = 1239 Declaration* declaration =
1227 factory()->NewModuleDeclaration(proxy, module, top_scope_); 1240 factory()->NewModuleDeclaration(proxy, module, top_scope_);
1228 Declare(declaration, true, CHECK_OK); 1241 Declare(declaration, true, CHECK_OK);
1229 1242
1243 #ifdef DEBUG
1244 if (FLAG_print_interface_details)
1245 PrintF("# Module %s.\n", name->ToAsciiArray());
1246
1247 if (FLAG_print_interfaces) {
1248 PrintF("module %s : ", name->ToAsciiArray());
1249 module->interface()->Print();
1250 }
1251 #endif
1252
1230 // TODO(rossberg): Add initialization statement to block. 1253 // TODO(rossberg): Add initialization statement to block.
1231 1254
1232 if (names) names->Add(name); 1255 if (names) names->Add(name);
1233 return block; 1256 return block;
1234 } 1257 }
1235 1258
1236 1259
1237 Module* Parser::ParseModule(bool* ok) { 1260 Module* Parser::ParseModule(bool* ok) {
1238 // Module: 1261 // Module:
1239 // '{' ModuleElement '}' 1262 // '{' ModuleElement '}'
(...skipping 20 matching lines...) Expand all
1260 } 1283 }
1261 } 1284 }
1262 1285
1263 1286
1264 Module* Parser::ParseModuleLiteral(bool* ok) { 1287 Module* Parser::ParseModuleLiteral(bool* ok) {
1265 // Module: 1288 // Module:
1266 // '{' ModuleElement '}' 1289 // '{' ModuleElement '}'
1267 1290
1268 // Construct block expecting 16 statements. 1291 // Construct block expecting 16 statements.
1269 Block* body = factory()->NewBlock(NULL, 16, false); 1292 Block* body = factory()->NewBlock(NULL, 16, false);
1293 #ifdef DEBUG
1294 if (FLAG_print_interface_details) PrintF("# Literal ");
1295 #endif
1270 Scope* scope = NewScope(top_scope_, MODULE_SCOPE); 1296 Scope* scope = NewScope(top_scope_, MODULE_SCOPE);
1271 1297
1272 Expect(Token::LBRACE, CHECK_OK); 1298 Expect(Token::LBRACE, CHECK_OK);
1273 scope->set_start_position(scanner().location().beg_pos); 1299 scope->set_start_position(scanner().location().beg_pos);
1274 scope->SetLanguageMode(EXTENDED_MODE); 1300 scope->SetLanguageMode(EXTENDED_MODE);
1275 1301
1276 { 1302 {
1277 BlockState block_state(this, scope); 1303 BlockState block_state(this, scope);
1278 TargetCollector collector; 1304 TargetCollector collector;
1279 Target target(&this->target_stack_, &collector); 1305 Target target(&this->target_stack_, &collector);
1280 Target target_body(&this->target_stack_, body); 1306 Target target_body(&this->target_stack_, body);
1281 InitializationBlockFinder block_finder(top_scope_, target_stack_); 1307 InitializationBlockFinder block_finder(top_scope_, target_stack_);
1282 1308
1283 while (peek() != Token::RBRACE) { 1309 while (peek() != Token::RBRACE) {
1284 Statement* stat = ParseModuleElement(NULL, CHECK_OK); 1310 Statement* stat = ParseModuleElement(NULL, CHECK_OK);
1285 if (stat && !stat->IsEmpty()) { 1311 if (stat && !stat->IsEmpty()) {
1286 body->AddStatement(stat); 1312 body->AddStatement(stat);
1287 block_finder.Update(stat); 1313 block_finder.Update(stat);
1288 } 1314 }
1289 } 1315 }
1290 } 1316 }
1291 1317
1292 Expect(Token::RBRACE, CHECK_OK); 1318 Expect(Token::RBRACE, CHECK_OK);
1293 scope->set_end_position(scanner().location().end_pos); 1319 scope->set_end_position(scanner().location().end_pos);
1294 body->set_block_scope(scope); 1320 body->set_block_scope(scope);
1295 return factory()->NewModuleLiteral(body); 1321
1322 scope->interface()->Freeze(ok);
1323 ASSERT(ok);
1324 return factory()->NewModuleLiteral(body, scope->interface());
1296 } 1325 }
1297 1326
1298 1327
1299 Module* Parser::ParseModulePath(bool* ok) { 1328 Module* Parser::ParseModulePath(bool* ok) {
1300 // ModulePath: 1329 // ModulePath:
1301 // Identifier 1330 // Identifier
1302 // ModulePath '.' Identifier 1331 // ModulePath '.' Identifier
1303 1332
1304 Module* result = ParseModuleVariable(CHECK_OK); 1333 Module* result = ParseModuleVariable(CHECK_OK);
1305
1306 while (Check(Token::PERIOD)) { 1334 while (Check(Token::PERIOD)) {
1307 Handle<String> name = ParseIdentifierName(CHECK_OK); 1335 Handle<String> name = ParseIdentifierName(CHECK_OK);
1308 result = factory()->NewModulePath(result, name); 1336 #ifdef DEBUG
1337 if (FLAG_print_interface_details)
1338 PrintF("# Path .%s ", name->ToAsciiArray());
1339 #endif
1340 Module* member = factory()->NewModulePath(result, name);
1341 result->interface()->Add(name, member->interface(), ok);
1342 if (!*ok) {
1343 #ifdef DEBUG
1344 if (FLAG_print_interfaces) {
1345 PrintF("PATH TYPE ERROR at '%s'\n", name->ToAsciiArray());
1346 PrintF("result: ");
1347 result->interface()->Print();
1348 PrintF("member: ");
1349 member->interface()->Print();
1350 }
1351 #endif
1352 ReportMessage("invalid_module_path", Vector<Handle<String> >(&name, 1));
1353 return NULL;
1354 }
1355 result = member;
1309 } 1356 }
1310 1357
1311 return result; 1358 return result;
1312 } 1359 }
1313 1360
1314 1361
1315 Module* Parser::ParseModuleVariable(bool* ok) { 1362 Module* Parser::ParseModuleVariable(bool* ok) {
1316 // ModulePath: 1363 // ModulePath:
1317 // Identifier 1364 // Identifier
1318 1365
1319 Handle<String> name = ParseIdentifier(CHECK_OK); 1366 Handle<String> name = ParseIdentifier(CHECK_OK);
1367 #ifdef DEBUG
1368 if (FLAG_print_interface_details)
1369 PrintF("# Module variable %s ", name->ToAsciiArray());
1370 #endif
1320 VariableProxy* proxy = top_scope_->NewUnresolved( 1371 VariableProxy* proxy = top_scope_->NewUnresolved(
1321 factory(), name, scanner().location().beg_pos); 1372 factory(), name, scanner().location().beg_pos, Interface::NewModule());
1373
1322 return factory()->NewModuleVariable(proxy); 1374 return factory()->NewModuleVariable(proxy);
1323 } 1375 }
1324 1376
1325 1377
1326 Module* Parser::ParseModuleUrl(bool* ok) { 1378 Module* Parser::ParseModuleUrl(bool* ok) {
1327 // Module: 1379 // Module:
1328 // String 1380 // String
1329 1381
1330 Expect(Token::STRING, CHECK_OK); 1382 Expect(Token::STRING, CHECK_OK);
1331 Handle<String> symbol = GetSymbol(CHECK_OK); 1383 Handle<String> symbol = GetSymbol(CHECK_OK);
1332 1384
1385 // TODO(ES6): Request JS resource from environment...
1386
1387 #ifdef DEBUG
1388 if (FLAG_print_interface_details) PrintF("# Url ");
1389 #endif
1333 return factory()->NewModuleUrl(symbol); 1390 return factory()->NewModuleUrl(symbol);
1334 } 1391 }
1335 1392
1336 1393
1337 Module* Parser::ParseModuleSpecifier(bool* ok) { 1394 Module* Parser::ParseModuleSpecifier(bool* ok) {
1338 // ModuleSpecifier: 1395 // ModuleSpecifier:
1339 // String 1396 // String
1340 // ModulePath 1397 // ModulePath
1341 1398
1342 if (peek() == Token::STRING) { 1399 if (peek() == Token::STRING) {
1343 return ParseModuleUrl(ok); 1400 return ParseModuleUrl(ok);
1344 } else { 1401 } else {
1345 return ParseModulePath(ok); 1402 return ParseModulePath(ok);
1346 } 1403 }
1347 } 1404 }
1348 1405
1349 1406
1350 Block* Parser::ParseImportDeclaration(bool* ok) { 1407 Block* Parser::ParseImportDeclaration(bool* ok) {
1351 // ImportDeclaration: 1408 // ImportDeclaration:
1352 // 'import' IdentifierName (',' IdentifierName)* 'from' ModuleSpecifier ';' 1409 // 'import' IdentifierName (',' IdentifierName)* 'from' ModuleSpecifier ';'
1353 // 1410 //
1354 // TODO(ES6): implement destructuring ImportSpecifiers 1411 // TODO(ES6): implement destructuring ImportSpecifiers
1355 1412
1356 Expect(Token::IMPORT, CHECK_OK); 1413 Expect(Token::IMPORT, CHECK_OK);
1357 ZoneStringList names(1); 1414 ZoneStringList names(1);
1358 1415
1359 Handle<String> name = ParseIdentifierName(CHECK_OK); 1416 Handle<String> name = ParseIdentifierName(CHECK_OK);
1417 names.Add(name);
1360 while (peek() == Token::COMMA) { 1418 while (peek() == Token::COMMA) {
1361 Consume(Token::COMMA); 1419 Consume(Token::COMMA);
1362 name = ParseIdentifierName(CHECK_OK); 1420 name = ParseIdentifierName(CHECK_OK);
1363 names.Add(name); 1421 names.Add(name);
1364 } 1422 }
1365 1423
1366 ExpectContextualKeyword("from", CHECK_OK); 1424 ExpectContextualKeyword("from", CHECK_OK);
1367 Module* module = ParseModuleSpecifier(CHECK_OK); 1425 Module* module = ParseModuleSpecifier(CHECK_OK);
1368 ExpectSemicolon(CHECK_OK); 1426 ExpectSemicolon(CHECK_OK);
1369 1427
1370 // Generate a separate declaration for each identifier. 1428 // Generate a separate declaration for each identifier.
1371 // TODO(ES6): once we implement destructuring, make that one declaration. 1429 // TODO(ES6): once we implement destructuring, make that one declaration.
1372 Block* block = factory()->NewBlock(NULL, 1, true); 1430 Block* block = factory()->NewBlock(NULL, 1, true);
1373 for (int i = 0; i < names.length(); ++i) { 1431 for (int i = 0; i < names.length(); ++i) {
1374 VariableProxy* proxy = NewUnresolved(names[i], LET); 1432 #ifdef DEBUG
1433 if (FLAG_print_interface_details)
1434 PrintF("# Import %s ", names[i]->ToAsciiArray());
1435 #endif
1436 Interface* interface = Interface::NewUnknown();
1437 module->interface()->Add(names[i], interface, ok);
1438 if (!*ok) {
1439 #ifdef DEBUG
1440 if (FLAG_print_interfaces) {
1441 PrintF("IMPORT TYPE ERROR at '%s'\n", names[i]->ToAsciiArray());
1442 PrintF("module: ");
1443 module->interface()->Print();
1444 }
1445 #endif
1446 ReportMessage("invalid_module_path", Vector<Handle<String> >(&name, 1));
1447 return NULL;
1448 }
1449 VariableProxy* proxy = NewUnresolved(names[i], LET, interface);
1375 Declaration* declaration = 1450 Declaration* declaration =
1376 factory()->NewImportDeclaration(proxy, module, top_scope_); 1451 factory()->NewImportDeclaration(proxy, module, top_scope_);
1377 Declare(declaration, true, CHECK_OK); 1452 Declare(declaration, true, CHECK_OK);
1378 // TODO(rossberg): Add initialization statement to block. 1453 // TODO(rossberg): Add initialization statement to block.
1379 } 1454 }
1380 1455
1381
1382 return block; 1456 return block;
1383 } 1457 }
1384 1458
1385 1459
1386 Statement* Parser::ParseExportDeclaration(bool* ok) { 1460 Statement* Parser::ParseExportDeclaration(bool* ok) {
1387 // ExportDeclaration: 1461 // ExportDeclaration:
1388 // 'export' Identifier (',' Identifier)* ';' 1462 // 'export' Identifier (',' Identifier)* ';'
1389 // 'export' VariableDeclaration 1463 // 'export' VariableDeclaration
1390 // 'export' FunctionDeclaration 1464 // 'export' FunctionDeclaration
1391 // 'export' ModuleDeclaration 1465 // 'export' ModuleDeclaration
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1424 case Token::CONST: 1498 case Token::CONST:
1425 result = ParseVariableStatement(kModuleElement, &names, CHECK_OK); 1499 result = ParseVariableStatement(kModuleElement, &names, CHECK_OK);
1426 break; 1500 break;
1427 1501
1428 default: 1502 default:
1429 *ok = false; 1503 *ok = false;
1430 ReportUnexpectedToken(scanner().current_token()); 1504 ReportUnexpectedToken(scanner().current_token());
1431 return NULL; 1505 return NULL;
1432 } 1506 }
1433 1507
1434 // Extract declared names into export declarations. 1508 // Extract declared names into export declarations and interface.
1509 Interface* interface = top_scope_->interface();
1435 for (int i = 0; i < names.length(); ++i) { 1510 for (int i = 0; i < names.length(); ++i) {
1436 VariableProxy* proxy = NewUnresolved(names[i], LET); 1511 #ifdef DEBUG
1437 Declaration* declaration = 1512 if (FLAG_print_interface_details)
1438 factory()->NewExportDeclaration(proxy, top_scope_); 1513 PrintF("# Export %s ", names[i]->ToAsciiArray());
1439 top_scope_->AddDeclaration(declaration); 1514 #endif
1515 Interface* inner = Interface::NewUnknown();
1516 interface->Add(names[i], inner, CHECK_OK);
1517 VariableProxy* proxy = NewUnresolved(names[i], LET, inner);
1518 USE(proxy);
1519 // TODO(rossberg): Rethink whether we actually need to store export
1520 // declarations (for compilation?).
1521 // ExportDeclaration* declaration =
1522 // factory()->NewExportDeclaration(proxy, top_scope_);
1523 // top_scope_->AddDeclaration(declaration);
1440 } 1524 }
1441 1525
1442 ASSERT(result != NULL); 1526 ASSERT(result != NULL);
1443 return result; 1527 return result;
1444 } 1528 }
1445 1529
1446 1530
1447 Statement* Parser::ParseBlockElement(ZoneStringList* labels, 1531 Statement* Parser::ParseBlockElement(ZoneStringList* labels,
1448 bool* ok) { 1532 bool* ok) {
1449 // (Ecma 262 5th Edition, clause 14): 1533 // (Ecma 262 5th Edition, clause 14):
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1590 default: 1674 default:
1591 stmt = ParseExpressionOrLabelledStatement(labels, ok); 1675 stmt = ParseExpressionOrLabelledStatement(labels, ok);
1592 } 1676 }
1593 1677
1594 // Store the source position of the statement 1678 // Store the source position of the statement
1595 if (stmt != NULL) stmt->set_statement_pos(statement_pos); 1679 if (stmt != NULL) stmt->set_statement_pos(statement_pos);
1596 return stmt; 1680 return stmt;
1597 } 1681 }
1598 1682
1599 1683
1600 VariableProxy* Parser::NewUnresolved(Handle<String> name, VariableMode mode) { 1684 VariableProxy* Parser::NewUnresolved(
1685 Handle<String> name, VariableMode mode, Interface* interface) {
1601 // If we are inside a function, a declaration of a var/const variable is a 1686 // If we are inside a function, a declaration of a var/const variable is a
1602 // truly local variable, and the scope of the variable is always the function 1687 // truly local variable, and the scope of the variable is always the function
1603 // scope. 1688 // scope.
1604 // Let/const variables in harmony mode are always added to the immediately 1689 // Let/const variables in harmony mode are always added to the immediately
1605 // enclosing scope. 1690 // enclosing scope.
1606 return DeclarationScope(mode)->NewUnresolved( 1691 return DeclarationScope(mode)->NewUnresolved(
1607 factory(), name, scanner().location().beg_pos); 1692 factory(), name, scanner().location().beg_pos, interface);
1608 } 1693 }
1609 1694
1610 1695
1611 void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) { 1696 void Parser::Declare(Declaration* declaration, bool resolve, bool* ok) {
1612 Handle<String> name = declaration->proxy()->name(); 1697 VariableProxy* proxy = declaration->proxy();
1698 Handle<String> name = proxy->name();
1613 VariableMode mode = declaration->mode(); 1699 VariableMode mode = declaration->mode();
1614 Scope* declaration_scope = DeclarationScope(mode); 1700 Scope* declaration_scope = DeclarationScope(mode);
1615 Variable* var = NULL; 1701 Variable* var = NULL;
1616 1702
1617 // If a function scope exists, then we can statically declare this 1703 // If a function scope exists, then we can statically declare this
1618 // variable and also set its mode. In any case, a Declaration node 1704 // variable and also set its mode. In any case, a Declaration node
1619 // will be added to the scope so that the declaration can be added 1705 // will be added to the scope so that the declaration can be added
1620 // to the corresponding activation frame at runtime if necessary. 1706 // to the corresponding activation frame at runtime if necessary.
1621 // For instance declarations inside an eval scope need to be added 1707 // For instance declarations inside an eval scope need to be added
1622 // to the calling function context. 1708 // to the calling function context.
1623 // Similarly, strict mode eval scope does not leak variable declarations to 1709 // Similarly, strict mode eval scope does not leak variable declarations to
1624 // the caller's scope so we declare all locals, too. 1710 // the caller's scope so we declare all locals, too.
1625 // Also for block scoped let/const bindings the variable can be 1711 // Also for block scoped let/const bindings the variable can be
1626 // statically declared. 1712 // statically declared.
1627 if (declaration_scope->is_function_scope() || 1713 if (declaration_scope->is_function_scope() ||
1628 declaration_scope->is_strict_or_extended_eval_scope() || 1714 declaration_scope->is_strict_or_extended_eval_scope() ||
1629 declaration_scope->is_block_scope() || 1715 declaration_scope->is_block_scope() ||
1630 declaration_scope->is_module_scope()) { 1716 declaration_scope->is_module_scope() ||
1717 declaration->AsModuleDeclaration() != NULL) {
1631 // Declare the variable in the function scope. 1718 // Declare the variable in the function scope.
1632 var = declaration_scope->LocalLookup(name); 1719 var = declaration_scope->LocalLookup(name);
1633 if (var == NULL) { 1720 if (var == NULL) {
1634 // Declare the name. 1721 // Declare the name.
1635 var = declaration_scope->DeclareLocal( 1722 var = declaration_scope->DeclareLocal(
1636 name, mode, declaration->initialization()); 1723 name, mode, declaration->initialization(), proxy->interface());
1637 } else { 1724 } else {
1638 // The name was declared in this scope before; check for conflicting 1725 // The name was declared in this scope before; check for conflicting
1639 // re-declarations. We have a conflict if either of the declarations is 1726 // re-declarations. We have a conflict if either of the declarations is
1640 // not a var. There is similar code in runtime.cc in the Declare 1727 // not a var. There is similar code in runtime.cc in the Declare
1641 // functions. The function CheckNonConflictingScope checks for conflicting 1728 // functions. The function CheckNonConflictingScope checks for conflicting
1642 // var and let bindings from different scopes whereas this is a check for 1729 // var and let bindings from different scopes whereas this is a check for
1643 // conflicting declarations within the same scope. This check also covers 1730 // conflicting declarations within the same scope. This check also covers
1644 // 1731 //
1645 // function () { let x; { var x; } } 1732 // function () { let x; { var x; } }
1646 // 1733 //
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1736 // var f = function () {}; 1823 // var f = function () {};
1737 // } 1824 // }
1738 // 1825 //
1739 // Note that if 'f' is accessed from inside the 'with' statement, it 1826 // Note that if 'f' is accessed from inside the 'with' statement, it
1740 // will be allocated in the context (because we must be able to look 1827 // will be allocated in the context (because we must be able to look
1741 // it up dynamically) but it will also be accessed statically, i.e., 1828 // it up dynamically) but it will also be accessed statically, i.e.,
1742 // with a context slot index and a context chain length for this 1829 // with a context slot index and a context chain length for this
1743 // initialization code. Thus, inside the 'with' statement, we need 1830 // initialization code. Thus, inside the 'with' statement, we need
1744 // both access to the static and the dynamic context chain; the 1831 // both access to the static and the dynamic context chain; the
1745 // runtime needs to provide both. 1832 // runtime needs to provide both.
1746 if (resolve && var != NULL) declaration->proxy()->BindTo(var); 1833 if (resolve && var != NULL) {
1834 proxy->BindTo(var);
1835
1836 if (FLAG_harmony_modules) {
1837 bool ok;
1838 #ifdef DEBUG
1839 if (FLAG_print_interface_details)
1840 PrintF("# Declare %s\n", var->name()->ToAsciiArray());
1841 #endif
1842 proxy->interface()->Unify(var->interface(), &ok);
1843 if (!ok) {
1844 #ifdef DEBUG
1845 if (FLAG_print_interfaces) {
1846 PrintF("DECLARE TYPE ERROR\n");
1847 PrintF("proxy: ");
1848 proxy->interface()->Print();
1849 PrintF("var: ");
1850 var->interface()->Print();
1851 }
1852 #endif
1853 ReportMessage("module_type_error", Vector<Handle<String> >(&name, 1));
1854 }
1855 }
1856 }
1747 } 1857 }
1748 1858
1749 1859
1750 // Language extension which is only enabled for source files loaded 1860 // Language extension which is only enabled for source files loaded
1751 // through the API's extension mechanism. A native function 1861 // through the API's extension mechanism. A native function
1752 // declaration is resolved by looking up the function through a 1862 // declaration is resolved by looking up the function through a
1753 // callback provided by the extension. 1863 // callback provided by the extension.
1754 Statement* Parser::ParseNativeDeclaration(bool* ok) { 1864 Statement* Parser::ParseNativeDeclaration(bool* ok) {
1755 Expect(Token::FUNCTION, CHECK_OK); 1865 Expect(Token::FUNCTION, CHECK_OK);
1756 Handle<String> name = ParseIdentifier(CHECK_OK); 1866 Handle<String> name = ParseIdentifier(CHECK_OK);
(...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after
3491 3601
3492 case Token::FALSE_LITERAL: 3602 case Token::FALSE_LITERAL:
3493 Consume(Token::FALSE_LITERAL); 3603 Consume(Token::FALSE_LITERAL);
3494 result = factory()->NewLiteral(isolate()->factory()->false_value()); 3604 result = factory()->NewLiteral(isolate()->factory()->false_value());
3495 break; 3605 break;
3496 3606
3497 case Token::IDENTIFIER: 3607 case Token::IDENTIFIER:
3498 case Token::FUTURE_STRICT_RESERVED_WORD: { 3608 case Token::FUTURE_STRICT_RESERVED_WORD: {
3499 Handle<String> name = ParseIdentifier(CHECK_OK); 3609 Handle<String> name = ParseIdentifier(CHECK_OK);
3500 if (fni_ != NULL) fni_->PushVariableName(name); 3610 if (fni_ != NULL) fni_->PushVariableName(name);
3611 // The name may refer to a module instance object, so its type is unknown.
3612 #ifdef DEBUG
3613 if (FLAG_print_interface_details)
3614 PrintF("# Variable %s ", name->ToAsciiArray());
3615 #endif
3616 Interface* interface = Interface::NewUnknown();
3501 result = top_scope_->NewUnresolved( 3617 result = top_scope_->NewUnresolved(
3502 factory(), name, scanner().location().beg_pos); 3618 factory(), name, scanner().location().beg_pos, interface);
3503 break; 3619 break;
3504 } 3620 }
3505 3621
3506 case Token::NUMBER: { 3622 case Token::NUMBER: {
3507 Consume(Token::NUMBER); 3623 Consume(Token::NUMBER);
3508 ASSERT(scanner().is_literal_ascii()); 3624 ASSERT(scanner().is_literal_ascii());
3509 double value = StringToDouble(isolate()->unicode_cache(), 3625 double value = StringToDouble(isolate()->unicode_cache(),
3510 scanner().literal_ascii_string(), 3626 scanner().literal_ascii_string(),
3511 ALLOW_HEX | ALLOW_OCTALS); 3627 ALLOW_HEX | ALLOW_OCTALS);
3512 result = factory()->NewNumberLiteral(value); 3628 result = factory()->NewNumberLiteral(value);
(...skipping 2412 matching lines...) Expand 10 before | Expand all | Expand 10 after
5925 ASSERT(info->isolate()->has_pending_exception()); 6041 ASSERT(info->isolate()->has_pending_exception());
5926 } else { 6042 } else {
5927 result = parser.ParseProgram(info); 6043 result = parser.ParseProgram(info);
5928 } 6044 }
5929 } 6045 }
5930 info->SetFunction(result); 6046 info->SetFunction(result);
5931 return (result != NULL); 6047 return (result != NULL);
5932 } 6048 }
5933 6049
5934 } } // namespace v8::internal 6050 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/parser.h ('k') | src/scopes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698