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

Method IncludeMethodsFromMixins

sdk/angelscript/source/as_builder.cpp:4223–4295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4221}
4222
4223void asCBuilder::IncludeMethodsFromMixins(sClassDeclaration *decl)
4224{
4225 asCScriptNode *node = decl->node->firstChild;
4226
4227 // Skip the class attributes
4228 while( node->nodeType == snIdentifier &&
4229 !decl->script->TokenEquals(node->tokenPos, node->tokenLength, decl->name.AddressOf()) )
4230 node = node->next;
4231
4232 // Skip the name of the class
4233 node = node->next;
4234
4235 // Find the included mixin classes
4236 while( node && node->nodeType == snIdentifier )
4237 {
4238 asSNameSpace *ns;
4239 asCString name;
4240 if( GetNamespaceAndNameFromNode(node, decl->script, decl->typeInfo->nameSpace, ns, name) < 0 )
4241 {
4242 node = node->next;
4243 continue;
4244 }
4245
4246 sMixinClass *mixin = 0;
4247 while( ns )
4248 {
4249 // Need to make sure the name is not an object type
4250 asCObjectType *objType = GetObjectType(name.AddressOf(), ns);
4251 if( objType == 0 )
4252 mixin = GetMixinClass(name.AddressOf(), ns);
4253
4254 if( objType || mixin )
4255 break;
4256
4257 ns = engine->GetParentNameSpace(ns);
4258 }
4259
4260 if( mixin )
4261 {
4262 // Find methods from mixin declaration
4263 asCScriptNode *n = mixin->node->firstChild;
4264
4265 // Skip to the member declarations
4266 // Possible keywords 'final' and 'shared' are removed in RegisterMixinClass so we don't need to worry about those here
4267 while( n && n->nodeType == snIdentifier )
4268 n = n->next;
4269
4270 // Add methods from the mixin that are not already existing in the class
4271 while( n )
4272 {
4273 if( n->nodeType == snFunction )
4274 {
4275 // Instead of disconnecting the node, we need to clone it, otherwise other
4276 // classes that include the same mixin will not see the methods
4277 asCScriptNode *copy = n->CreateCopy(engine);
4278
4279 // Register the method, but only if it doesn't already exist in the class
4280 RegisterScriptFunctionFromNode(copy, mixin->script, CastToObjectType(decl->typeInfo), false, false, mixin->ns, false, true);

Callers

nothing calls this directly

Calls 5

CastToObjectTypeFunction · 0.85
TokenEqualsMethod · 0.80
GetParentNameSpaceMethod · 0.80
CreateCopyMethod · 0.80
AddressOfMethod · 0.45

Tested by

no test coverage detected