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

Side by Side Diff: src/hydrogen.cc

Issue 9460064: Further refactoring of declarations in the AST: (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 10 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
« src/ast.h ('K') | « src/hydrogen.h ('k') | src/parser.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 2448 matching lines...) Expand 10 before | Expand all | Expand 10 after
2459 // not replayed by the Lithium translation. 2459 // not replayed by the Lithium translation.
2460 HEnvironment* initial_env = environment()->CopyWithoutHistory(); 2460 HEnvironment* initial_env = environment()->CopyWithoutHistory();
2461 HBasicBlock* body_entry = CreateBasicBlock(initial_env); 2461 HBasicBlock* body_entry = CreateBasicBlock(initial_env);
2462 current_block()->Goto(body_entry); 2462 current_block()->Goto(body_entry);
2463 body_entry->SetJoinId(AstNode::kFunctionEntryId); 2463 body_entry->SetJoinId(AstNode::kFunctionEntryId);
2464 set_current_block(body_entry); 2464 set_current_block(body_entry);
2465 2465
2466 // Handle implicit declaration of the function name in named function 2466 // Handle implicit declaration of the function name in named function
2467 // expressions before other declarations. 2467 // expressions before other declarations.
2468 if (scope->is_function_scope() && scope->function() != NULL) { 2468 if (scope->is_function_scope() && scope->function() != NULL) {
2469 HandleVariableDeclaration(scope->function(), CONST, NULL, NULL); 2469 HandleDeclaration(scope->function(), CONST, NULL, NULL);
2470 } 2470 }
2471 VisitDeclarations(scope->declarations()); 2471 VisitDeclarations(scope->declarations());
2472 AddSimulate(AstNode::kDeclarationsId); 2472 AddSimulate(AstNode::kDeclarationsId);
2473 2473
2474 HValue* context = environment()->LookupContext(); 2474 HValue* context = environment()->LookupContext();
2475 AddInstruction( 2475 AddInstruction(
2476 new(zone()) HStackCheck(context, HStackCheck::kFunctionEntry)); 2476 new(zone()) HStackCheck(context, HStackCheck::kFunctionEntry));
2477 2477
2478 VisitStatements(info()->function()->body()); 2478 VisitStatements(info()->function()->body());
2479 if (HasStackOverflow()) return NULL; 2479 if (HasStackOverflow()) return NULL;
(...skipping 4246 matching lines...) Expand 10 before | Expand all | Expand 10 after
6726 void HGraphBuilder::VisitThisFunction(ThisFunction* expr) { 6726 void HGraphBuilder::VisitThisFunction(ThisFunction* expr) {
6727 ASSERT(!HasStackOverflow()); 6727 ASSERT(!HasStackOverflow());
6728 ASSERT(current_block() != NULL); 6728 ASSERT(current_block() != NULL);
6729 ASSERT(current_block()->HasPredecessor()); 6729 ASSERT(current_block()->HasPredecessor());
6730 HThisFunction* self = new(zone()) HThisFunction( 6730 HThisFunction* self = new(zone()) HThisFunction(
6731 function_state()->compilation_info()->closure()); 6731 function_state()->compilation_info()->closure());
6732 return ast_context()->ReturnInstruction(self, expr->id()); 6732 return ast_context()->ReturnInstruction(self, expr->id());
6733 } 6733 }
6734 6734
6735 6735
6736 void HGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) {
6737 UNREACHABLE();
6738 }
6739
6740 void HGraphBuilder::VisitDeclarations(ZoneList<Declaration*>* declarations) { 6736 void HGraphBuilder::VisitDeclarations(ZoneList<Declaration*>* declarations) {
6741 int length = declarations->length(); 6737 int length = declarations->length();
6742 int global_count = 0; 6738 int global_count = 0;
6743 for (int i = 0; i < declarations->length(); i++) { 6739 for (int i = 0; i < declarations->length(); i++) {
6744 VariableDeclaration* decl = declarations->at(i)->AsVariableDeclaration(); 6740 Declaration* decl = declarations->at(i);
6745 if (decl == NULL) continue; 6741 FunctionDeclaration* fun_decl = decl->AsFunctionDeclaration();
6746 HandleVariableDeclaration(decl->proxy(), 6742 HandleDeclaration(decl->proxy(),
6747 decl->mode(), 6743 decl->mode(),
6748 decl->fun(), 6744 fun_decl != NULL ? fun_decl->fun() : NULL,
6749 &global_count); 6745 &global_count);
6750 } 6746 }
6751 6747
6752 // Batch declare global functions and variables. 6748 // Batch declare global functions and variables.
6753 if (global_count > 0) { 6749 if (global_count > 0) {
6754 Handle<FixedArray> array = 6750 Handle<FixedArray> array =
6755 isolate()->factory()->NewFixedArray(2 * global_count, TENURED); 6751 isolate()->factory()->NewFixedArray(2 * global_count, TENURED);
6756 for (int j = 0, i = 0; i < length; i++) { 6752 for (int j = 0, i = 0; i < length; i++) {
6757 VariableDeclaration* decl = declarations->at(i)->AsVariableDeclaration(); 6753 Declaration* decl = declarations->at(i);
6758 if (decl == NULL) continue;
6759 Variable* var = decl->proxy()->var(); 6754 Variable* var = decl->proxy()->var();
6760 6755
6761 if (var->IsUnallocated()) { 6756 if (var->IsUnallocated()) {
6762 array->set(j++, *(var->name())); 6757 array->set(j++, *(var->name()));
6763 if (decl->fun() == NULL) { 6758 FunctionDeclaration* fun_decl = decl->AsFunctionDeclaration();
6759 if (fun_decl == NULL) {
6764 if (var->binding_needs_init()) { 6760 if (var->binding_needs_init()) {
6765 // In case this binding needs initialization use the hole. 6761 // In case this binding needs initialization use the hole.
6766 array->set_the_hole(j++); 6762 array->set_the_hole(j++);
6767 } else { 6763 } else {
6768 array->set_undefined(j++); 6764 array->set_undefined(j++);
6769 } 6765 }
6770 } else { 6766 } else {
6771 Handle<SharedFunctionInfo> function = 6767 Handle<SharedFunctionInfo> function =
6772 Compiler::BuildFunctionInfo(decl->fun(), info()->script()); 6768 Compiler::BuildFunctionInfo(fun_decl->fun(), info()->script());
6773 // Check for stack-overflow exception. 6769 // Check for stack-overflow exception.
6774 if (function.is_null()) { 6770 if (function.is_null()) {
6775 SetStackOverflow(); 6771 SetStackOverflow();
6776 return; 6772 return;
6777 } 6773 }
6778 array->set(j++, *function); 6774 array->set(j++, *function);
6779 } 6775 }
6780 } 6776 }
6781 } 6777 }
6782 int flags = DeclareGlobalsEvalFlag::encode(info()->is_eval()) | 6778 int flags = DeclareGlobalsEvalFlag::encode(info()->is_eval()) |
6783 DeclareGlobalsNativeFlag::encode(info()->is_native()) | 6779 DeclareGlobalsNativeFlag::encode(info()->is_native()) |
6784 DeclareGlobalsLanguageMode::encode(info()->language_mode()); 6780 DeclareGlobalsLanguageMode::encode(info()->language_mode());
6785 HInstruction* result = 6781 HInstruction* result =
6786 new(zone()) HDeclareGlobals(environment()->LookupContext(), 6782 new(zone()) HDeclareGlobals(environment()->LookupContext(),
6787 array, 6783 array,
6788 flags); 6784 flags);
6789 AddInstruction(result); 6785 AddInstruction(result);
6790 } 6786 }
6791 } 6787 }
6792 6788
6793 6789
6794 void HGraphBuilder::HandleVariableDeclaration(VariableProxy* proxy, 6790 void HGraphBuilder::HandleDeclaration(VariableProxy* proxy,
6795 VariableMode mode, 6791 VariableMode mode,
6796 FunctionLiteral* function, 6792 FunctionLiteral* function,
6797 int* global_count) { 6793 int* global_count) {
6798 Variable* var = proxy->var(); 6794 Variable* var = proxy->var();
6799 bool binding_needs_init = 6795 bool binding_needs_init =
6800 (mode == CONST || mode == CONST_HARMONY || mode == LET); 6796 (mode == CONST || mode == CONST_HARMONY || mode == LET);
6801 switch (var->location()) { 6797 switch (var->location()) {
6802 case Variable::UNALLOCATED: 6798 case Variable::UNALLOCATED:
6803 ++(*global_count); 6799 ++(*global_count);
6804 return; 6800 return;
6805 case Variable::PARAMETER: 6801 case Variable::PARAMETER:
6806 case Variable::LOCAL: 6802 case Variable::LOCAL:
6807 case Variable::CONTEXT: 6803 case Variable::CONTEXT:
(...skipping 15 matching lines...) Expand all
6823 environment()->Bind(var, value); 6819 environment()->Bind(var, value);
6824 } 6820 }
6825 } 6821 }
6826 break; 6822 break;
6827 case Variable::LOOKUP: 6823 case Variable::LOOKUP:
6828 return Bailout("unsupported lookup slot in declaration"); 6824 return Bailout("unsupported lookup slot in declaration");
6829 } 6825 }
6830 } 6826 }
6831 6827
6832 6828
6829 void HGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) {
6830 UNREACHABLE();
6831 }
6832
6833
6834 void HGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* decl) {
6835 UNREACHABLE();
6836 }
6837
6838
6833 void HGraphBuilder::VisitModuleDeclaration(ModuleDeclaration* decl) { 6839 void HGraphBuilder::VisitModuleDeclaration(ModuleDeclaration* decl) {
6834 // TODO(rossberg) 6840 // TODO(rossberg)
6835 } 6841 }
6836 6842
6837 6843
6838 void HGraphBuilder::VisitModuleLiteral(ModuleLiteral* module) { 6844 void HGraphBuilder::VisitModuleLiteral(ModuleLiteral* module) {
6839 // TODO(rossberg) 6845 // TODO(rossberg)
6840 } 6846 }
6841 6847
6842 6848
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
7900 } 7906 }
7901 } 7907 }
7902 7908
7903 #ifdef DEBUG 7909 #ifdef DEBUG
7904 if (graph_ != NULL) graph_->Verify(false); // No full verify. 7910 if (graph_ != NULL) graph_->Verify(false); // No full verify.
7905 if (allocator_ != NULL) allocator_->Verify(); 7911 if (allocator_ != NULL) allocator_->Verify();
7906 #endif 7912 #endif
7907 } 7913 }
7908 7914
7909 } } // namespace v8::internal 7915 } } // namespace v8::internal
OLDNEW
« src/ast.h ('K') | « src/hydrogen.h ('k') | src/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698