internal
| 1099 | |
| 1100 | // internal |
| 1101 | void asCScriptFunction::AddReferences() |
| 1102 | { |
| 1103 | // This array will be used to make sure we only add the reference to the same resource once |
| 1104 | // This is especially important for global variables, as it expects the initialization function |
| 1105 | // to hold only one reference to the variable. However, if the variable is initialized through |
| 1106 | // the default constructor followed by the assignment operator we will have two references to |
| 1107 | // the variable in the function. |
| 1108 | asCArray<void*> ptrs; |
| 1109 | |
| 1110 | // Only count references if there is any bytecode |
| 1111 | if( scriptData && scriptData->byteCode.GetLength() ) |
| 1112 | { |
| 1113 | if( returnType.GetTypeInfo() ) |
| 1114 | { |
| 1115 | returnType.GetTypeInfo()->AddRefInternal(); |
| 1116 | |
| 1117 | asCConfigGroup *group = engine->FindConfigGroupForTypeInfo(returnType.GetTypeInfo()); |
| 1118 | if( group != 0 ) group->AddRef(); |
| 1119 | } |
| 1120 | |
| 1121 | for( asUINT p = 0; p < parameterTypes.GetLength(); p++ ) |
| 1122 | if( parameterTypes[p].GetTypeInfo() ) |
| 1123 | { |
| 1124 | parameterTypes[p].GetTypeInfo()->AddRefInternal(); |
| 1125 | |
| 1126 | asCConfigGroup *group = engine->FindConfigGroupForTypeInfo(parameterTypes[p].GetTypeInfo()); |
| 1127 | if( group != 0 ) group->AddRef(); |
| 1128 | } |
| 1129 | |
| 1130 | for (asUINT v = 0; v < scriptData->variables.GetLength(); v++) |
| 1131 | { |
| 1132 | asCTypeInfo* ti = reinterpret_cast<asCTypeInfo*>(scriptData->variables[v]->type.GetTypeInfo()); |
| 1133 | if (ti) // The null handle is also stored, but it doesn't have an object type |
| 1134 | { |
| 1135 | ti->AddRefInternal(); |
| 1136 | |
| 1137 | asCConfigGroup* group = engine->FindConfigGroupForTypeInfo(ti); |
| 1138 | if (group != 0) group->AddRef(); |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | // Go through the byte code and add references to all resources used by the function |
| 1143 | asCArray<asDWORD> &bc = scriptData->byteCode; |
| 1144 | for( asUINT n = 0; n < bc.GetLength(); n += asBCTypeSize[asBCInfo[*(asBYTE*)&bc[n]].type] ) |
| 1145 | { |
| 1146 | switch( *(asBYTE*)&bc[n] ) |
| 1147 | { |
| 1148 | // Object types |
| 1149 | case asBC_OBJTYPE: |
| 1150 | case asBC_FREE: |
| 1151 | case asBC_REFCPY: |
| 1152 | case asBC_RefCpyV: |
| 1153 | { |
| 1154 | asCObjectType *objType = (asCObjectType*)asBC_PTRARG(&bc[n]); |
| 1155 | asASSERT( objType ); |
| 1156 | if( objType ) |
| 1157 | objType->AddRefInternal(); |
| 1158 | } |
no test coverage detected