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

Method AddPropertyToClass

sdk/angelscript/source/as_builder.cpp:4475–4520  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4473}
4474
4475asCObjectProperty *asCBuilder::AddPropertyToClass(sClassDeclaration *decl, const asCString &name, const asCDataType &dt, bool isPrivate, bool isProtected, bool isInherited, asCScriptCode *file, asCScriptNode *node)
4476{
4477 if( node )
4478 {
4479 asASSERT(!isInherited);
4480
4481 // Check if the property is allowed
4482 if( !dt.CanBeInstantiated() )
4483 {
4484 if( file && node )
4485 {
4486 asCString str;
4487 if( dt.IsAbstractClass() )
4488 str.Format(TXT_ABSTRACT_CLASS_s_CANNOT_BE_INSTANTIATED, dt.Format(decl->typeInfo->nameSpace).AddressOf());
4489 else if( dt.IsInterface() )
4490 str.Format(TXT_INTERFACE_s_CANNOT_BE_INSTANTIATED, dt.Format(decl->typeInfo->nameSpace).AddressOf());
4491 else
4492 // TODO: Improve error message to explain why
4493 str.Format(TXT_DATA_TYPE_CANT_BE_s, dt.Format(decl->typeInfo->nameSpace).AddressOf());
4494 WriteError(str, file, node);
4495 }
4496 return 0;
4497 }
4498
4499 // Register the initialization expression (if any) to be compiled later
4500 asCScriptNode *declNode = node;
4501 asCScriptNode *initNode = 0;
4502 if( node->next && node->next->nodeType != snIdentifier )
4503 {
4504 asASSERT( node->next->nodeType == snAssignment );
4505 initNode = node->next;
4506 }
4507
4508 sPropertyInitializer p(name, declNode, initNode, file);
4509 decl->propInits.PushLast(p);
4510 }
4511 else
4512 {
4513 // If the declaration node is not given, then
4514 // this property is inherited from a base class
4515 asASSERT(isInherited);
4516 }
4517
4518 // Add the property to the object type
4519 return CastToObjectType(decl->typeInfo)->AddPropertyToClass(name, dt, isPrivate, isProtected, isInherited);
4520}
4521
4522bool asCBuilder::DoesMethodExist(asCObjectType *objType, int methodId, asUINT *methodIndex)
4523{

Callers 1

ReadObjectPropertyMethod · 0.45

Calls 7

CastToObjectTypeFunction · 0.85
CanBeInstantiatedMethod · 0.80
IsAbstractClassMethod · 0.80
PushLastMethod · 0.80
FormatMethod · 0.45
AddressOfMethod · 0.45
IsInterfaceMethod · 0.45

Tested by

no test coverage detected