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 "vm/parser.h" | 5 #include "vm/parser.h" |
6 | 6 |
7 #include "lib/invocation_mirror.h" | 7 #include "lib/invocation_mirror.h" |
8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
9 #include "vm/ast_transformer.h" | 9 #include "vm/ast_transformer.h" |
10 #include "vm/bootstrap.h" | 10 #include "vm/bootstrap.h" |
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 // TODO(koda): Should there be a StackZone here? | 1145 // TODO(koda): Should there be a StackZone here? |
1146 Zone* zone = thread->zone(); | 1146 Zone* zone = thread->zone(); |
1147 | 1147 |
1148 const Class& script_cls = Class::Handle(zone, field.origin()); | 1148 const Class& script_cls = Class::Handle(zone, field.origin()); |
1149 const Script& script = Script::Handle(zone, script_cls.script()); | 1149 const Script& script = Script::Handle(zone, script_cls.script()); |
1150 | 1150 |
1151 const String& field_name = String::Handle(zone, field.name()); | 1151 const String& field_name = String::Handle(zone, field.name()); |
1152 String& init_name = String::Handle(zone, | 1152 String& init_name = String::Handle(zone, |
1153 Symbols::FromConcat(Symbols::InitPrefix(), field_name)); | 1153 Symbols::FromConcat(Symbols::InitPrefix(), field_name)); |
1154 | 1154 |
| 1155 Object& initializer_owner = Object::Handle(field.owner()); |
| 1156 if (field.owner() != field.origin()) { |
| 1157 initializer_owner = |
| 1158 PatchClass::New(Class::Handle(field.owner()), script_cls); |
| 1159 } |
| 1160 |
1155 const Function& initializer = Function::ZoneHandle(zone, | 1161 const Function& initializer = Function::ZoneHandle(zone, |
1156 Function::New(init_name, | 1162 Function::New(init_name, |
1157 RawFunction::kRegularFunction, | 1163 RawFunction::kImplicitStaticFinalGetter, |
1158 true, // static | 1164 true, // static |
1159 false, // !const | 1165 false, // !const |
1160 false, // !abstract | 1166 false, // !abstract |
1161 false, // !external | 1167 false, // !external |
1162 false, // !native | 1168 false, // !native |
1163 Class::Handle(field.owner()), | 1169 initializer_owner, |
1164 field.token_pos())); | 1170 field.token_pos())); |
1165 initializer.set_result_type(AbstractType::Handle(zone, field.type())); | 1171 initializer.set_result_type(AbstractType::Handle(zone, field.type())); |
1166 // Static initializer functions are hidden from the user. | 1172 // Static initializer functions are hidden from the user. |
1167 // Since they are only executed once, we avoid optimizing | 1173 // Since they are only executed once, we avoid optimizing |
1168 // and inlining them. After the field is initialized, the | 1174 // and inlining them. After the field is initialized, the |
1169 // compiler can eliminate the call to the static initializer. | 1175 // compiler can eliminate the call to the static initializer. |
1170 initializer.set_is_reflectable(false); | 1176 initializer.set_is_reflectable(false); |
1171 initializer.set_is_debuggable(false); | 1177 initializer.set_is_debuggable(false); |
1172 initializer.SetIsOptimizable(false); | 1178 initializer.SetIsOptimizable(false); |
1173 initializer.set_is_inlinable(false); | 1179 initializer.set_is_inlinable(false); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1242 | 1248 |
1243 // Build local scope for function and populate with the formal parameters. | 1249 // Build local scope for function and populate with the formal parameters. |
1244 OpenFunctionBlock(func); | 1250 OpenFunctionBlock(func); |
1245 AddFormalParamsToScope(¶ms, current_block_->scope); | 1251 AddFormalParamsToScope(¶ms, current_block_->scope); |
1246 | 1252 |
1247 intptr_t ident_pos = TokenPos(); | 1253 intptr_t ident_pos = TokenPos(); |
1248 const String& field_name = *ExpectIdentifier("field name expected"); | 1254 const String& field_name = *ExpectIdentifier("field name expected"); |
1249 const Class& field_class = Class::Handle(Z, func.Owner()); | 1255 const Class& field_class = Class::Handle(Z, func.Owner()); |
1250 const Field& field = | 1256 const Field& field = |
1251 Field::ZoneHandle(Z, field_class.LookupStaticField(field_name)); | 1257 Field::ZoneHandle(Z, field_class.LookupStaticField(field_name)); |
| 1258 ASSERT(!field.IsNull()); |
1252 | 1259 |
1253 // Static final fields must have an initializer. | 1260 // Static final fields must have an initializer. |
1254 ExpectToken(Token::kASSIGN); | 1261 ExpectToken(Token::kASSIGN); |
1255 | 1262 |
1256 const intptr_t expr_pos = TokenPos(); | 1263 const intptr_t expr_pos = TokenPos(); |
1257 if (field.is_const()) { | 1264 if (field.is_const()) { |
1258 // We don't want to use ParseConstExpr() here because we don't want | 1265 // We don't want to use ParseConstExpr() here because we don't want |
1259 // the constant folding code to create, compile and execute a code | 1266 // the constant folding code to create, compile and execute a code |
1260 // fragment to evaluate the expression. Instead, we just make sure | 1267 // fragment to evaluate the expression. Instead, we just make sure |
1261 // the static const field initializer is a constant expression and | 1268 // the static const field initializer is a constant expression and |
(...skipping 13001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14263 void Parser::SkipQualIdent() { | 14270 void Parser::SkipQualIdent() { |
14264 ASSERT(IsIdentifier()); | 14271 ASSERT(IsIdentifier()); |
14265 ConsumeToken(); | 14272 ConsumeToken(); |
14266 if (CurrentToken() == Token::kPERIOD) { | 14273 if (CurrentToken() == Token::kPERIOD) { |
14267 ConsumeToken(); // Consume the kPERIOD token. | 14274 ConsumeToken(); // Consume the kPERIOD token. |
14268 ExpectIdentifier("identifier expected after '.'"); | 14275 ExpectIdentifier("identifier expected after '.'"); |
14269 } | 14276 } |
14270 } | 14277 } |
14271 | 14278 |
14272 } // namespace dart | 14279 } // namespace dart |
OLD | NEW |