internal
| 3654 | |
| 3655 | // internal |
| 3656 | asCObjectType *asCScriptEngine::GetTemplateInstanceType(asCObjectType *templateType, asCArray<asCDataType> &subTypes, asCModule *requestingModule) |
| 3657 | { |
| 3658 | asUINT n; |
| 3659 | |
| 3660 | // Is there any template instance type or template specialization already with this subtype? |
| 3661 | for( n = 0; n < templateInstanceTypes.GetLength(); n++ ) |
| 3662 | { |
| 3663 | asCObjectType *type = templateInstanceTypes[n]; |
| 3664 | if( type && |
| 3665 | type->name == templateType->name && |
| 3666 | type->nameSpace == templateType->nameSpace && |
| 3667 | type->templateSubTypes == subTypes ) |
| 3668 | { |
| 3669 | // If the template instance is generated, then the module should hold a reference |
| 3670 | // to it so the config group can determine see that the template type is in use. |
| 3671 | // Template specializations will be treated as normal types |
| 3672 | if( requestingModule && generatedTemplateTypes.Exists(type) ) |
| 3673 | { |
| 3674 | if( type->module == 0 ) |
| 3675 | { |
| 3676 | // Set the ownership of this template type |
| 3677 | // It may be without ownership if it was previously created from application with for example GetTypeInfoByDecl |
| 3678 | type->module = requestingModule; |
| 3679 | } |
| 3680 | if( !requestingModule->m_templateInstances.Exists(type) ) |
| 3681 | { |
| 3682 | requestingModule->m_templateInstances.PushLast(type); |
| 3683 | type->AddRefInternal(); |
| 3684 | } |
| 3685 | } |
| 3686 | |
| 3687 | return templateInstanceTypes[n]; |
| 3688 | } |
| 3689 | } |
| 3690 | |
| 3691 | // No previous template instance exists |
| 3692 | |
| 3693 | // Make sure this template supports the subtype |
| 3694 | for( n = 0; n < subTypes.GetLength(); n++ ) |
| 3695 | { |
| 3696 | if( !templateType->acceptValueSubType && (subTypes[n].IsPrimitive() || (subTypes[n].GetTypeInfo()->flags & asOBJ_VALUE)) ) |
| 3697 | return 0; |
| 3698 | |
| 3699 | if( !templateType->acceptRefSubType && (subTypes[n].IsObject() && (subTypes[n].GetTypeInfo()->flags & asOBJ_REF)) ) |
| 3700 | return 0; |
| 3701 | } |
| 3702 | |
| 3703 | // Create a new template instance type based on the templateType |
| 3704 | asCObjectType *ot = asNEW(asCObjectType)(this); |
| 3705 | if( ot == 0 ) |
| 3706 | { |
| 3707 | // Out of memory |
| 3708 | return 0; |
| 3709 | } |
| 3710 | |
| 3711 | ot->templateSubTypes = subTypes; |
| 3712 | ot->flags = templateType->flags; |
| 3713 | ot->size = templateType->size; |
no test coverage detected