OLD | NEW |
---|---|
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 8693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
8704 CHECK_EQ(data->backing_store_[index++], scope->start_position()); | 8704 CHECK_EQ(data->backing_store_[index++], scope->start_position()); |
8705 CHECK_EQ(data->backing_store_[index++], scope->end_position()); | 8705 CHECK_EQ(data->backing_store_[index++], scope->end_position()); |
8706 | 8706 |
8707 int inner_scope_count = 0; | 8707 int inner_scope_count = 0; |
8708 for (Scope* inner = scope->inner_scope(); inner != nullptr; | 8708 for (Scope* inner = scope->inner_scope(); inner != nullptr; |
8709 inner = inner->sibling()) { | 8709 inner = inner->sibling()) { |
8710 ++inner_scope_count; | 8710 ++inner_scope_count; |
8711 } | 8711 } |
8712 CHECK_EQ(data->backing_store_[index++], inner_scope_count); | 8712 CHECK_EQ(data->backing_store_[index++], inner_scope_count); |
8713 | 8713 |
8714 // Variable count is 0. TODO(marja): implement. | 8714 int variable_count = 0; |
8715 CHECK_EQ(data->backing_store_[index++], 0); | 8715 for (Variable* local : scope->locals_) { |
8716 if (local->mode() == VAR || local->mode() == LET || | |
8717 local->mode() == CONST) { | |
8718 ++variable_count; | |
8719 } | |
8720 } | |
8721 | |
8722 CHECK_EQ(data->backing_store_[index++], variable_count); | |
vogelheim
2017/01/26 09:34:35
Why does this work? The way I read Scope::CollectV
marja
2017/01/26 09:40:59
Offline discussion: the scope contains only the va
| |
8723 | |
8724 for (Variable* local : scope->locals_) { | |
8725 if (local->mode() == VAR || local->mode() == LET || | |
8726 local->mode() == CONST) { | |
8727 CHECK_EQ(data->backing_store_[index++], local->location()); | |
8728 CHECK_EQ(data->backing_store_[index++], local->maybe_assigned()); | |
8729 } | |
8730 } | |
8716 | 8731 |
8717 for (Scope* inner = scope->inner_scope(); inner != nullptr; | 8732 for (Scope* inner = scope->inner_scope(); inner != nullptr; |
8718 inner = inner->sibling()) { | 8733 inner = inner->sibling()) { |
8719 CompareScopeToData(inner, data, index); | 8734 CompareScopeToData(inner, data, index); |
8720 } | 8735 } |
8721 } | 8736 } |
8722 }; | 8737 }; |
8723 } // namespace internal | 8738 } // namespace internal |
8724 } // namespace v8 | 8739 } // namespace v8 |
8725 | 8740 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9015 const char* lazy_inner = " function inner(%s) { %s }"; | 9030 const char* lazy_inner = " function inner(%s) { %s }"; |
9016 const char* eager_inner = "(function inner(%s) { %s })()"; | 9031 const char* eager_inner = "(function inner(%s) { %s })()"; |
9017 | 9032 |
9018 struct { | 9033 struct { |
9019 const char* params; | 9034 const char* params; |
9020 const char* source; | 9035 const char* source; |
9021 } inners[] = { | 9036 } inners[] = { |
9022 {"", "var1"}, | 9037 {"", "var1"}, |
9023 {"", "if (true) {}"}, | 9038 {"", "if (true) {}"}, |
9024 {"", "function f1() {}"}, | 9039 {"", "function f1() {}"}, |
9025 {"", "if (true) { function f1() {} }"}, | |
9026 }; | 9040 }; |
9027 | 9041 |
9028 for (unsigned i = 0; i < arraysize(inners); ++i) { | 9042 for (unsigned i = 0; i < arraysize(inners); ++i) { |
9029 // First compile with the lazy inner function and extract the scope data. | 9043 // First compile with the lazy inner function and extract the scope data. |
9030 const char* inner_function = lazy_inner; | 9044 const char* inner_function = lazy_inner; |
9031 int inner_function_len = Utf8LengthHelper(inner_function) - 4; | 9045 int inner_function_len = Utf8LengthHelper(inner_function) - 4; |
9032 | 9046 |
9033 int params_len = Utf8LengthHelper(inners[i].params); | 9047 int params_len = Utf8LengthHelper(inners[i].params); |
9034 int source_len = Utf8LengthHelper(inners[i].source); | 9048 int source_len = Utf8LengthHelper(inners[i].source); |
9035 int len = | 9049 int len = |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9069 i::SNPrintF(eager_program + prefix_len + inner_function_len + params_len + | 9083 i::SNPrintF(eager_program + prefix_len + inner_function_len + params_len + |
9070 source_len, | 9084 source_len, |
9071 "%s", suffix); | 9085 "%s", suffix); |
9072 | 9086 |
9073 source = factory->InternalizeUtf8String(eager_program.start()); | 9087 source = factory->InternalizeUtf8String(eager_program.start()); |
9074 source->PrintOn(stdout); | 9088 source->PrintOn(stdout); |
9075 printf("\n"); | 9089 printf("\n"); |
9076 | 9090 |
9077 script = factory->NewScript(source); | 9091 script = factory->NewScript(source); |
9078 i::ParseInfo eager_info(&zone, script); | 9092 i::ParseInfo eager_info(&zone, script); |
9093 eager_info.set_allow_lazy_parsing(false); | |
9079 | 9094 |
9080 CHECK(i::parsing::ParseProgram(&eager_info)); | 9095 CHECK(i::parsing::ParseProgram(&eager_info)); |
9081 CHECK(i::Compiler::Analyze(&eager_info)); | 9096 CHECK(i::Compiler::Analyze(&eager_info)); |
9082 | 9097 |
9083 i::Scope* scope = | 9098 i::Scope* scope = |
9084 eager_info.literal()->scope()->inner_scope()->inner_scope(); | 9099 eager_info.literal()->scope()->inner_scope()->inner_scope(); |
9085 DCHECK_NOT_NULL(scope); | 9100 DCHECK_NOT_NULL(scope); |
9086 DCHECK_NULL(scope->sibling()); | 9101 DCHECK_NULL(scope->sibling()); |
9087 DCHECK(scope->is_function_scope()); | 9102 DCHECK(scope->is_function_scope()); |
9088 | 9103 |
9089 size_t index = 0; | 9104 size_t index = 0; |
9090 i::ScopeTestHelper::CompareScopeToData( | 9105 i::ScopeTestHelper::CompareScopeToData( |
9091 scope, lazy_info.preparsed_scope_data(), index); | 9106 scope, lazy_info.preparsed_scope_data(), index); |
9092 } | 9107 } |
9093 } | 9108 } |
OLD | NEW |