MCPcopy Create free account
hub / github.com/anjo76/angelscript / FindMatchingFuncdef

Method FindMatchingFuncdef

sdk/angelscript/source/as_scriptengine.cpp:6099–6165  ·  view source on GitHub ↗

internal

Source from the content-addressed store, hash-verified

6097
6098// internal
6099asCFuncdefType *asCScriptEngine::FindMatchingFuncdef(asCScriptFunction *func, asCModule *module)
6100{
6101 asCFuncdefType *funcDef = func->funcdefType;
6102
6103 if (funcDef == 0)
6104 {
6105 // Check if there is any matching funcdefs already in the engine that can be reused
6106 for (asUINT n = 0; n < funcDefs.GetLength(); n++)
6107 {
6108 if (funcDefs[n]->funcdef->IsSignatureExceptNameEqual(func))
6109 {
6110 if (func->IsShared() && !funcDefs[n]->funcdef->IsShared())
6111 continue;
6112 funcDef = funcDefs[n];
6113 break;
6114 }
6115 }
6116 }
6117
6118 if (funcDef == 0)
6119 {
6120 // Create a matching funcdef
6121 asCScriptFunction *fd = asNEW(asCScriptFunction)(this, 0, asFUNC_FUNCDEF);
6122 fd->name = "$func_" + func->name; // Add a prefix to avoid name conflicts with explicitly declared funcdefs
6123 fd->nameSpace = func->nameSpace;
6124 fd->SetShared(func->IsShared());
6125
6126 fd->returnType = func->returnType;
6127 fd->parameterTypes = func->parameterTypes;
6128 fd->inOutFlags = func->inOutFlags;
6129
6130 funcDef = asNEW(asCFuncdefType)(this, fd);
6131 funcDefs.PushLast(funcDef); // doesn't increase the refCount
6132
6133 fd->id = GetNextScriptFunctionId();
6134 AddScriptFunction(fd);
6135
6136 if (module)
6137 {
6138 // Add the new funcdef to the module so it will
6139 // be available when saving the bytecode
6140 funcDef->module = module;
6141 module->AddFuncDef(funcDef); // the refCount was already accounted for in the constructor
6142 }
6143
6144 // Observe, if the funcdef is created without informing a module a reference will be stored in the
6145 // engine's funcDefs array, but it will not be owned by any module. This means that it will live on
6146 // until the engine is released.
6147 }
6148
6149 if (funcDef && module && funcDef->module && funcDef->module != module)
6150 {
6151 // Unless this is a registered funcDef the returned funcDef must
6152 // be stored as part of the module for saving/loading bytecode
6153 if (!module->m_funcDefs.Exists(funcDef))
6154 {
6155 module->AddFuncDef(funcDef);
6156 funcDef->AddRefInternal();

Callers 2

DetermineSingleFuncMethod · 0.80
GetTypeIdMethod · 0.80

Calls 8

SetSharedMethod · 0.80
PushLastMethod · 0.80
AddFuncDefMethod · 0.80
GetLengthMethod · 0.45
IsSharedMethod · 0.45
ExistsMethod · 0.45
AddRefInternalMethod · 0.45

Tested by

no test coverage detected