| 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/flow_graph_builder.h" | 5 #include "vm/flow_graph_builder.h" | 
| 6 | 6 | 
| 7 #include "vm/ast_printer.h" | 7 #include "vm/ast_printer.h" | 
| 8 #include "vm/bit_vector.h" | 8 #include "vm/bit_vector.h" | 
| 9 #include "vm/code_descriptors.h" | 9 #include "vm/code_descriptors.h" | 
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" | 
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 583 } | 583 } | 
| 584 | 584 | 
| 585 | 585 | 
| 586 void EffectGraphVisitor::BuildTypecheckArguments( | 586 void EffectGraphVisitor::BuildTypecheckArguments( | 
| 587     intptr_t token_pos, | 587     intptr_t token_pos, | 
| 588     Value** instantiator_result, | 588     Value** instantiator_result, | 
| 589     Value** instantiator_type_arguments_result) { | 589     Value** instantiator_type_arguments_result) { | 
| 590   Value* instantiator = NULL; | 590   Value* instantiator = NULL; | 
| 591   Value* instantiator_type_arguments = NULL; | 591   Value* instantiator_type_arguments = NULL; | 
| 592   const Class& instantiator_class = Class::Handle( | 592   const Class& instantiator_class = Class::Handle( | 
| 593       owner()->parsed_function().function().owner()); | 593       owner()->parsed_function().function().Owner()); | 
| 594   // Since called only when type tested against is not instantiated. | 594   // Since called only when type tested against is not instantiated. | 
| 595   ASSERT(instantiator_class.NumTypeParameters() > 0); | 595   ASSERT(instantiator_class.NumTypeParameters() > 0); | 
| 596   instantiator = BuildInstantiator(); | 596   instantiator = BuildInstantiator(); | 
| 597   if (instantiator == NULL) { | 597   if (instantiator == NULL) { | 
| 598     // No instantiator when inside factory. | 598     // No instantiator when inside factory. | 
| 599     instantiator = BuildNullValue(); | 599     instantiator = BuildNullValue(); | 
| 600     instantiator_type_arguments = | 600     instantiator_type_arguments = | 
| 601         BuildInstantiatorTypeArguments(token_pos, NULL); | 601         BuildInstantiatorTypeArguments(token_pos, NULL); | 
| 602   } else { | 602   } else { | 
| 603     // Preserve instantiator. | 603     // Preserve instantiator. | 
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1448   Value* context = Bind(new CurrentContextComp()); | 1448   Value* context = Bind(new CurrentContextComp()); | 
| 1449   Value* clone = Bind(new CloneContextComp(node->token_pos(), | 1449   Value* clone = Bind(new CloneContextComp(node->token_pos(), | 
| 1450                                            owner()->try_index(), | 1450                                            owner()->try_index(), | 
| 1451                                            context)); | 1451                                            context)); | 
| 1452   ReturnComputation(new StoreContextComp(clone)); | 1452   ReturnComputation(new StoreContextComp(clone)); | 
| 1453 } | 1453 } | 
| 1454 | 1454 | 
| 1455 | 1455 | 
| 1456 Value* EffectGraphVisitor::BuildObjectAllocation( | 1456 Value* EffectGraphVisitor::BuildObjectAllocation( | 
| 1457     ConstructorCallNode* node) { | 1457     ConstructorCallNode* node) { | 
| 1458   const Class& cls = Class::ZoneHandle(node->constructor().owner()); | 1458   const Class& cls = Class::ZoneHandle(node->constructor().Owner()); | 
| 1459   const bool requires_type_arguments = cls.HasTypeArguments(); | 1459   const bool requires_type_arguments = cls.HasTypeArguments(); | 
| 1460 | 1460 | 
| 1461   // In checked mode, if the type arguments are uninstantiated, they may need to | 1461   // In checked mode, if the type arguments are uninstantiated, they may need to | 
| 1462   // be checked against declared bounds at run time. | 1462   // be checked against declared bounds at run time. | 
| 1463   Computation* allocate_comp = NULL; | 1463   Computation* allocate_comp = NULL; | 
| 1464   if (FLAG_enable_type_checks && | 1464   if (FLAG_enable_type_checks && | 
| 1465       requires_type_arguments && | 1465       requires_type_arguments && | 
| 1466       !node->type_arguments().IsNull() && | 1466       !node->type_arguments().IsNull() && | 
| 1467       !node->type_arguments().IsInstantiated() && | 1467       !node->type_arguments().IsInstantiated() && | 
| 1468       !node->type_arguments().IsWithinBoundsOf(cls, | 1468       !node->type_arguments().IsWithinBoundsOf(cls, | 
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1544   //   StaticCall(constructor, t_n+1, t_n+2, ...) | 1544   //   StaticCall(constructor, t_n+1, t_n+2, ...) | 
| 1545   // No need to preserve allocated value (simpler than in ValueGraphVisitor). | 1545   // No need to preserve allocated value (simpler than in ValueGraphVisitor). | 
| 1546   Value* allocated_value = BuildObjectAllocation(node); | 1546   Value* allocated_value = BuildObjectAllocation(node); | 
| 1547   PushArgumentInstr* push_allocated_value = PushArgument(allocated_value); | 1547   PushArgumentInstr* push_allocated_value = PushArgument(allocated_value); | 
| 1548   BuildConstructorCall(node, push_allocated_value); | 1548   BuildConstructorCall(node, push_allocated_value); | 
| 1549 } | 1549 } | 
| 1550 | 1550 | 
| 1551 | 1551 | 
| 1552 Value* EffectGraphVisitor::BuildInstantiator() { | 1552 Value* EffectGraphVisitor::BuildInstantiator() { | 
| 1553   const Class& instantiator_class = Class::Handle( | 1553   const Class& instantiator_class = Class::Handle( | 
| 1554       owner()->parsed_function().function().owner()); | 1554       owner()->parsed_function().function().Owner()); | 
| 1555   if (instantiator_class.NumTypeParameters() == 0) { | 1555   if (instantiator_class.NumTypeParameters() == 0) { | 
| 1556     return NULL; | 1556     return NULL; | 
| 1557   } | 1557   } | 
| 1558   Function& outer_function = | 1558   Function& outer_function = | 
| 1559       Function::Handle(owner()->parsed_function().function().raw()); | 1559       Function::Handle(owner()->parsed_function().function().raw()); | 
| 1560   while (outer_function.IsLocalFunction()) { | 1560   while (outer_function.IsLocalFunction()) { | 
| 1561     outer_function = outer_function.parent_function(); | 1561     outer_function = outer_function.parent_function(); | 
| 1562   } | 1562   } | 
| 1563   if (outer_function.IsFactory()) { | 1563   if (outer_function.IsFactory()) { | 
| 1564     return NULL; | 1564     return NULL; | 
| 1565   } | 1565   } | 
| 1566 | 1566 | 
| 1567   ASSERT(owner()->parsed_function().instantiator() != NULL); | 1567   ASSERT(owner()->parsed_function().instantiator() != NULL); | 
| 1568   ValueGraphVisitor for_instantiator(owner(), temp_index()); | 1568   ValueGraphVisitor for_instantiator(owner(), temp_index()); | 
| 1569   owner()->parsed_function().instantiator()->Visit(&for_instantiator); | 1569   owner()->parsed_function().instantiator()->Visit(&for_instantiator); | 
| 1570   Append(for_instantiator); | 1570   Append(for_instantiator); | 
| 1571   return for_instantiator.value(); | 1571   return for_instantiator.value(); | 
| 1572 } | 1572 } | 
| 1573 | 1573 | 
| 1574 | 1574 | 
| 1575 // 'expression_temp_var' may not be used inside this method if 'instantiator' | 1575 // 'expression_temp_var' may not be used inside this method if 'instantiator' | 
| 1576 // is not NULL. | 1576 // is not NULL. | 
| 1577 Value* EffectGraphVisitor::BuildInstantiatorTypeArguments( | 1577 Value* EffectGraphVisitor::BuildInstantiatorTypeArguments( | 
| 1578     intptr_t token_pos, Value* instantiator) { | 1578     intptr_t token_pos, Value* instantiator) { | 
| 1579   const Class& instantiator_class = Class::Handle( | 1579   const Class& instantiator_class = Class::Handle( | 
| 1580       owner()->parsed_function().function().owner()); | 1580       owner()->parsed_function().function().Owner()); | 
| 1581   if (instantiator_class.NumTypeParameters() == 0) { | 1581   if (instantiator_class.NumTypeParameters() == 0) { | 
| 1582     // The type arguments are compile time constants. | 1582     // The type arguments are compile time constants. | 
| 1583     AbstractTypeArguments& type_arguments = AbstractTypeArguments::ZoneHandle(); | 1583     AbstractTypeArguments& type_arguments = AbstractTypeArguments::ZoneHandle(); | 
| 1584     // Type is temporary. Only its type arguments are preserved. | 1584     // Type is temporary. Only its type arguments are preserved. | 
| 1585     Type& type = Type::Handle( | 1585     Type& type = Type::Handle( | 
| 1586         Type::New(instantiator_class, type_arguments, token_pos, Heap::kNew)); | 1586         Type::New(instantiator_class, type_arguments, token_pos, Heap::kNew)); | 
| 1587     type ^= ClassFinalizer::FinalizeType( | 1587     type ^= ClassFinalizer::FinalizeType( | 
| 1588         instantiator_class, type, ClassFinalizer::kFinalize); | 1588         instantiator_class, type, ClassFinalizer::kFinalize); | 
| 1589     ASSERT(!type.IsMalformed()); | 1589     ASSERT(!type.IsMalformed()); | 
| 1590     type_arguments = type.arguments(); | 1590     type_arguments = type.arguments(); | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1637                                                type_arguments, | 1637                                                type_arguments, | 
| 1638                                                instantiator_value)); | 1638                                                instantiator_value)); | 
| 1639 } | 1639 } | 
| 1640 | 1640 | 
| 1641 | 1641 | 
| 1642 void EffectGraphVisitor::BuildConstructorTypeArguments( | 1642 void EffectGraphVisitor::BuildConstructorTypeArguments( | 
| 1643     ConstructorCallNode* node, | 1643     ConstructorCallNode* node, | 
| 1644     Value** type_arguments, | 1644     Value** type_arguments, | 
| 1645     Value** instantiator, | 1645     Value** instantiator, | 
| 1646     ZoneGrowableArray<PushArgumentInstr*>* call_arguments) { | 1646     ZoneGrowableArray<PushArgumentInstr*>* call_arguments) { | 
| 1647   const Class& cls = Class::ZoneHandle(node->constructor().owner()); | 1647   const Class& cls = Class::ZoneHandle(node->constructor().Owner()); | 
| 1648   ASSERT(cls.HasTypeArguments() && !node->constructor().IsFactory()); | 1648   ASSERT(cls.HasTypeArguments() && !node->constructor().IsFactory()); | 
| 1649   if (node->type_arguments().IsNull() || | 1649   if (node->type_arguments().IsNull() || | 
| 1650       node->type_arguments().IsInstantiated()) { | 1650       node->type_arguments().IsInstantiated()) { | 
| 1651     Value* type_arguments_val = Bind(new ConstantVal(node->type_arguments())); | 1651     Value* type_arguments_val = Bind(new ConstantVal(node->type_arguments())); | 
| 1652     if (call_arguments != NULL) { | 1652     if (call_arguments != NULL) { | 
| 1653       ASSERT(type_arguments == NULL); | 1653       ASSERT(type_arguments == NULL); | 
| 1654       call_arguments->Add(PushArgument(type_arguments_val)); | 1654       call_arguments->Add(PushArgument(type_arguments_val)); | 
| 1655     } else { | 1655     } else { | 
| 1656       ASSERT(type_arguments != NULL); | 1656       ASSERT(type_arguments != NULL); | 
| 1657       *type_arguments = type_arguments_val; | 1657       *type_arguments = type_arguments_val; | 
| (...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2823   intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; | 2823   intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, reason) + 1; | 
| 2824   char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 2824   char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 
| 2825   OS::SNPrint(chars, len, kFormat, function_name, reason); | 2825   OS::SNPrint(chars, len, kFormat, function_name, reason); | 
| 2826   const Error& error = Error::Handle( | 2826   const Error& error = Error::Handle( | 
| 2827       LanguageError::New(String::Handle(String::New(chars)))); | 2827       LanguageError::New(String::Handle(String::New(chars)))); | 
| 2828   Isolate::Current()->long_jump_base()->Jump(1, error); | 2828   Isolate::Current()->long_jump_base()->Jump(1, error); | 
| 2829 } | 2829 } | 
| 2830 | 2830 | 
| 2831 | 2831 | 
| 2832 }  // namespace dart | 2832 }  // namespace dart | 
| OLD | NEW | 
|---|