OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "lib/invocation_mirror.h" | 5 #include "lib/invocation_mirror.h" |
6 #include "vm/bootstrap_natives.h" | 6 #include "vm/bootstrap_natives.h" |
7 #include "vm/class_finalizer.h" | 7 #include "vm/class_finalizer.h" |
8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
10 #include "vm/object_store.h" | 10 #include "vm/object_store.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 const Instance& owner_mirror) { | 118 const Instance& owner_mirror) { |
119 HANDLESCOPE(Isolate::Current()); | 119 HANDLESCOPE(Isolate::Current()); |
120 const intptr_t implicit_param_count = func.NumImplicitParameters(); | 120 const intptr_t implicit_param_count = func.NumImplicitParameters(); |
121 const intptr_t non_implicit_param_count = func.NumParameters() - | 121 const intptr_t non_implicit_param_count = func.NumParameters() - |
122 implicit_param_count; | 122 implicit_param_count; |
123 const intptr_t index_of_first_optional_param = | 123 const intptr_t index_of_first_optional_param = |
124 non_implicit_param_count - func.NumOptionalParameters(); | 124 non_implicit_param_count - func.NumOptionalParameters(); |
125 const intptr_t index_of_first_named_param = | 125 const intptr_t index_of_first_named_param = |
126 non_implicit_param_count - func.NumOptionalNamedParameters(); | 126 non_implicit_param_count - func.NumOptionalNamedParameters(); |
127 const Array& results = Array::Handle(Array::New(non_implicit_param_count)); | 127 const Array& results = Array::Handle(Array::New(non_implicit_param_count)); |
128 const Array& args = Array::Handle(Array::New(8)); | 128 const Array& args = Array::Handle(Array::New(9)); |
129 | 129 |
130 // Return for synthetic functions and getters. | 130 // Return for synthetic functions and getters. |
131 if (func.IsGetterFunction() || | 131 if (func.IsGetterFunction() || |
132 func.IsImplicitConstructor() || | 132 func.IsImplicitConstructor() || |
133 func.IsImplicitGetterFunction() || | 133 func.IsImplicitGetterFunction() || |
134 func.IsImplicitSetterFunction()) { | 134 func.IsImplicitSetterFunction()) { |
135 return results.raw(); | 135 return results.raw(); |
136 } | 136 } |
137 | 137 |
138 Smi& pos = Smi::Handle(); | 138 Smi& pos = Smi::Handle(); |
139 String& name = String::Handle(); | 139 String& name = String::Handle(); |
140 Instance& param = Instance::Handle(); | 140 Instance& param = Instance::Handle(); |
141 Bool& is_final = Bool::Handle(); | 141 Bool& is_final = Bool::Handle(); |
142 Object& default_value = Object::Handle(); | 142 Object& default_value = Object::Handle(); |
143 Object& metadata = Object::Handle(); | |
143 | 144 |
144 // Reparse the function for the following information: | 145 // Reparse the function for the following information: |
145 // * The default value of a parameter. | 146 // * The default value of a parameter. |
146 // * Whether a parameters has been deflared as final. | 147 // * Whether a parameters has been deflared as final. |
147 const Object& result = Object::Handle(Parser::ParseFunctionParameters(func)); | 148 const Object& result = Object::Handle(Parser::ParseFunctionParameters(func)); |
148 if (result.IsError()) { | 149 if (result.IsError()) { |
149 ThrowInvokeError(Error::Cast(result)); | 150 ThrowInvokeError(Error::Cast(result)); |
150 UNREACHABLE(); | 151 UNREACHABLE(); |
151 } | 152 } |
152 | 153 |
153 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); | 154 args.SetAt(0, MirrorReference::Handle(MirrorReference::New(func))); |
154 args.SetAt(2, owner_mirror); | 155 args.SetAt(2, owner_mirror); |
155 | 156 |
156 const Array& param_descriptor = Array::Cast(result); | 157 const Array& param_descriptor = Array::Cast(result); |
157 ASSERT(param_descriptor.Length() == (2 * non_implicit_param_count)); | 158 ASSERT(param_descriptor.Length() == (3 * non_implicit_param_count)); |
siva
2013/08/28 23:26:48
You should probably make 3 a named constant,
const
| |
158 for (intptr_t i = 0; i < non_implicit_param_count; i++) { | 159 for (intptr_t i = 0; i < non_implicit_param_count; i++) { |
159 pos ^= Smi::New(i); | 160 pos ^= Smi::New(i); |
160 name ^= func.ParameterNameAt(implicit_param_count + i); | 161 name ^= func.ParameterNameAt(implicit_param_count + i); |
161 is_final ^= param_descriptor.At(i * 2); | 162 is_final ^= param_descriptor.At(i * 3); |
162 default_value = param_descriptor.At(i * 2 + 1); | 163 default_value = param_descriptor.At(i * 3 + 1); |
164 metadata = param_descriptor.At(i * 3 + 2); | |
165 | |
163 ASSERT(default_value.IsNull() || default_value.IsInstance()); | 166 ASSERT(default_value.IsNull() || default_value.IsInstance()); |
164 | 167 |
165 // Arguments 0 (referent) and 2 (owner) are the same for all parameters. See | 168 // Arguments 0 (referent) and 2 (owner) are the same for all parameters. See |
166 // above. | 169 // above. |
167 args.SetAt(1, name); | 170 args.SetAt(1, name); |
168 args.SetAt(3, pos); | 171 args.SetAt(3, pos); |
169 args.SetAt(4, (i >= index_of_first_optional_param) ? | 172 args.SetAt(4, (i >= index_of_first_optional_param) ? |
170 Bool::True() : Bool::False()); | 173 Bool::True() : Bool::False()); |
171 args.SetAt(5, (i >= index_of_first_named_param) ? | 174 args.SetAt(5, (i >= index_of_first_named_param) ? |
172 Bool::True() : Bool::False()); | 175 Bool::True() : Bool::False()); |
173 args.SetAt(6, is_final); | 176 args.SetAt(6, is_final); |
174 args.SetAt(7, default_value); | 177 args.SetAt(7, default_value); |
178 args.SetAt(8, metadata); | |
175 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args); | 179 param ^= CreateMirror(Symbols::_LocalParameterMirrorImpl(), args); |
176 results.SetAt(i, param); | 180 results.SetAt(i, param); |
177 } | 181 } |
178 results.MakeImmutable(); | 182 results.MakeImmutable(); |
179 return results.raw(); | 183 return results.raw(); |
180 } | 184 } |
181 | 185 |
182 | 186 |
183 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param, | 187 static RawInstance* CreateTypeVariableMirror(const TypeParameter& param, |
184 const Instance& owner_mirror) { | 188 const Instance& owner_mirror) { |
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1350 } | 1354 } |
1351 | 1355 |
1352 | 1356 |
1353 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { | 1357 DEFINE_NATIVE_ENTRY(VariableMirror_type, 1) { |
1354 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); | 1358 GET_NON_NULL_NATIVE_ARGUMENT(MirrorReference, ref, arguments->NativeArgAt(0)); |
1355 const Field& field = Field::Handle(ref.GetFieldReferent()); | 1359 const Field& field = Field::Handle(ref.GetFieldReferent()); |
1356 return field.type(); | 1360 return field.type(); |
1357 } | 1361 } |
1358 | 1362 |
1359 } // namespace dart | 1363 } // namespace dart |
OLD | NEW |