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

Method AddPropertyToClass

sdk/angelscript/source/as_objecttype.cpp:511–586  ·  view source on GitHub ↗

internal

Source from the content-addressed store, hash-verified

509
510// internal
511asCObjectProperty *asCObjectType::AddPropertyToClass(const asCString &propName, const asCDataType &dt, bool isPrivate, bool isProtected, bool isInherited)
512{
513 asASSERT( flags & asOBJ_SCRIPT_OBJECT );
514 asASSERT( dt.CanBeInstantiated() );
515 asASSERT( !IsInterface() );
516
517 // Store the properties in the object type descriptor
518 asCObjectProperty *prop = asNEW(asCObjectProperty);
519 if( prop == 0 )
520 {
521 // Out of memory
522 return 0;
523 }
524
525 prop->name = propName;
526 prop->type = dt;
527 prop->isPrivate = isPrivate;
528 prop->isProtected = isProtected;
529 prop->isInherited = isInherited;
530
531 int propSize;
532 if( dt.IsObject() )
533 {
534 // Non-POD value types can't be allocated inline,
535 // because there is a risk that the script might
536 // try to access the content without knowing that
537 // it hasn't been initialized yet.
538 if( dt.GetTypeInfo()->flags & asOBJ_POD )
539 propSize = dt.GetSizeInMemoryBytes();
540 else
541 {
542 propSize = dt.GetSizeOnStackDWords()*4;
543 if( !dt.IsObjectHandle() )
544 prop->type.MakeReference(true);
545 }
546 }
547 else if (dt.IsFuncdef())
548 {
549 // Funcdefs don't have a size, as they must always be stored as handles
550 asASSERT(dt.IsObjectHandle());
551 propSize = AS_PTR_SIZE * 4;
552 }
553 else
554 propSize = dt.GetSizeInMemoryBytes();
555
556 // Add extra bytes so that the property will be properly aligned
557#ifndef WIP_16BYTE_ALIGN
558 if( propSize == 2 && (size & 1) ) size += 1;
559 if( propSize > 2 && (size & 3) ) size += 4 - (size & 3);
560#else
561 asUINT alignment = dt.GetAlignment();
562 const asUINT propSizeAlignmentDifference = size & (alignment-1);
563 if( propSizeAlignmentDifference != 0 )
564 {
565 size += (alignment - propSizeAlignmentDifference);
566 }
567
568 asASSERT((size % alignment) == 0);

Callers

nothing calls this directly

Calls 13

CanBeInstantiatedMethod · 0.80
IsObjectMethod · 0.80
GetTypeInfoMethod · 0.80
GetSizeInMemoryBytesMethod · 0.80
GetSizeOnStackDWordsMethod · 0.80
IsObjectHandleMethod · 0.80
MakeReferenceMethod · 0.80
IsFuncdefMethod · 0.80
GetAlignmentMethod · 0.80
PushLastMethod · 0.80
AddRefMethod · 0.45

Tested by

no test coverage detected