Example #1
0
static int DaoCstruct_Compare( DaoCstruct *left, DaoCstruct *right, DMap *cycmap )
{
	if( left == right ) return 0;

	if( DaoType_ChildOf( left->ctype, right->ctype ) ){
		if( left->ctype->core->Compare ){
			return left->ctype->core->Compare( (DaoValue*) left, (DaoValue*) right, cycmap );
		}else if( right->ctype->core->Compare ){
			return - right->ctype->core->Compare( (DaoValue*) right, (DaoValue*) left, cycmap );
		}
	}else if( DaoType_ChildOf( right->ctype, left->ctype ) ){
		if( right->ctype->core->Compare ){
			return - right->ctype->core->Compare( (DaoValue*) right, (DaoValue*) left, cycmap );
		}else if( left->ctype->core->Compare ){
			return left->ctype->core->Compare( (DaoValue*) left, (DaoValue*) right, cycmap );
		}
	}


	if( left->ctype != right->ctype ){
		return number_compare( (size_t)left->ctype, (size_t)right->ctype );
	}else if( left->type == DAO_CDATA ){
		DaoCdata *l = (DaoCdata*) left;
		DaoCdata *r = (DaoCdata*) right;
		return number_compare( (size_t)l->data, (size_t)r->data );
	}
	return number_compare( (size_t)left, (size_t)right );
}
Example #2
0
DaoValue* DaoObject_CastToBase( DaoObject *self, DaoType *host )
{
	DaoValue *sup = self->parent;
	if( host == NULL ) return NULL;
	host = DaoType_GetBaseType( host );
	if( self->defClass->objType == host ) return (DaoValue*) self;
	if( self->parent == NULL ) return NULL;
	if( sup->type == DAO_OBJECT ){
		if( (sup = DaoObject_CastToBase( & sup->xObject, host ) ) ) return sup;
	}else if( sup->type == DAO_CSTRUCT && host->tid == DAO_CSTRUCT ){
		if( DaoType_ChildOf( sup->xCdata.ctype, host ) ) return sup;
	}else if( sup->type == DAO_CDATA && host->tid == DAO_CDATA ){
		if( DaoType_ChildOf( sup->xCdata.ctype, host ) ) return sup;
	}
	return NULL;
}
Example #3
0
DaoCdata* DaoValue_CastCdata( DaoValue *self, DaoType *type )
{
	if( self == NULL || type == NULL ) return (DaoCdata*) self;
	if( self->type != DAO_CDATA ) return NULL;
	if( DaoType_ChildOf( self->xCdata.ctype, type ) ) return (DaoCdata*) self;
	return NULL;
}
Example #4
0
DaoCstruct* DaoValue_CastCstruct( DaoValue *self, DaoType *type )
{
	if( self == NULL || type == NULL ) return (DaoCstruct*) self;
	if( self->type != DAO_CSTRUCT && self->type != DAO_CDATA ) return NULL;
	if( DaoType_ChildOf( self->xCstruct.ctype, type ) ) return (DaoCstruct*) self;
	return NULL;
}
Example #5
0
static DaoType* DaoObject_CheckConversion( DaoType *self, DaoType *type, DaoRoutine *ctx )
{
	DString *buffer;
	DaoRoutine *rout;
	DaoType *hostype = ctx->routHost;
	DaoClass *host = hostype != NULL && hostype->tid == DAO_OBJECT ? (DaoClass*) hostype->aux : NULL;

	if( DaoType_ChildOf( self, type ) ) return type;
	if( DaoType_ChildOf( type, self ) ) return type;

	buffer = DString_NewChars( "(" );
	DString_Append( buffer, type->name );
	DString_AppendChars( buffer, ")" );
	rout = DaoClass_FindMethod( (DaoClass*) self->aux, buffer->chars, host );
	DString_Delete( buffer );
	if( rout != NULL ){
		DaoType *ttype = DaoNamespace_GetType( ctx->nameSpace, (DaoValue*) type );
		rout = DaoRoutine_MatchByType( rout, self, & ttype, 1, DVM_CALL );
	}
	if( rout != NULL ) return type;
	return NULL;
}
Example #6
0
static int DaoObject_Compare( DaoObject *left, DaoObject *right, DMap *cycmap )
{
	DaoValue *base1 = left->parent;
	DaoValue *base2 = right->parent;

	if( left == right ) return 0;

	while( base1 != NULL && base1->type == DAO_OBJECT ) base1 = base1->xObject.parent;
	while( base2 != NULL && base2->type == DAO_OBJECT ) base2 = base2->xObject.parent;

	if( DaoType_ChildOf( left->defClass->objType, right->defClass->objType ) ){
		if( base1 != NULL ){
			return DaoCstruct_Compare( (DaoCstruct*) base1, (DaoCstruct*) base2, cycmap );
		}
	}else if( DaoType_ChildOf( right->defClass->objType, left->defClass->objType ) ){
		if( base1 != NULL ){
			return DaoCstruct_Compare( (DaoCstruct*) base1, (DaoCstruct*) base2, cycmap );
		}
	}

	return number_compare( (size_t)left, (size_t)right );
}
Example #7
0
DaoCstruct* DaoValue_CastCstructTC( DaoValue *self, DaoTypeCore *core )
{
	DaoType *type = NULL;
	if( self == NULL || core == NULL ) return (DaoCstruct*) self;
	if( self->type == DAO_OBJECT ){
		type = DaoVmSpace_GetType( self->xObject.defClass->nameSpace->vmSpace, core );
		self = (DaoValue*) DaoObject_CastCstruct( (DaoObject*) self, type );
		if( self == NULL ) return NULL;
	}
	if( self->type != DAO_CSTRUCT && self->type != DAO_CDATA ) return NULL;
	type = DaoVmSpace_GetType( self->xCstruct.ctype->aux->xCtype.nameSpace->vmSpace, core );
	if( DaoType_ChildOf( self->xCstruct.ctype, type ) ) return (DaoCstruct*) self;
	return NULL;
}
Example #8
0
void DaoObject_SetParentCdata( DaoObject *self, DaoCdata *parent )
{
	DaoObject *child = NULL;
	DaoObject *obj = (DaoObject*) self->parent;
	DaoValue *sup = self->defClass->parent;
	if( parent == NULL ) return;
	if( sup == NULL ) return;
	if( obj && obj->type == DAO_OBJECT ){
		DaoObject_SetParentCdata( obj, parent );
	}else if( sup->type == DAO_CTYPE ){
		DaoCdata *cdata = (DaoCdata*)sup;
		if( DaoType_ChildOf( cdata->ctype, parent->ctype ) ){
			GC_Assign( & self->parent, parent );
		}
	}
}
Example #9
0
void DaoObject_SetParentCstruct( DaoObject *self, DaoCstruct *parent )
{
	DaoObject *child = NULL;
	DaoObject *obj = (DaoObject*) self->parent;
	DaoValue *sup = self->defClass->parent;
	if( parent == NULL ) return;
	if( sup == NULL ) return;
	if( obj && obj->type == DAO_OBJECT ){
		DaoObject_SetParentCstruct( obj, parent );
	}else if( sup->type == DAO_CTYPE ){
		DaoCtype *ctype = (DaoCtype*)sup;
		if( DaoType_ChildOf( ctype->classType, parent->ctype ) ){
			DaoValue_MoveCstruct( (DaoValue*) parent, & self->parent, 1 );
		}
	}
}
Example #10
0
int DaoObject_ChildOf( DaoValue *self, DaoValue *obj )
{
	int i;
	if( obj == self ) return 1;
	if( self->type == DAO_CDATA || self->type == DAO_CSTRUCT ){
		if( obj->type == DAO_CDATA || obj->type == DAO_CSTRUCT ){
			DaoCstruct *cdata1 = (DaoCstruct*) self;
			DaoCstruct *cdata2 = (DaoCstruct*) obj;
			if( DaoType_ChildOf( cdata1->ctype, cdata2->ctype ) ) return 1;
		}
		return 0;
	}
	if( self->type != DAO_OBJECT || self->xObject.parent == NULL ) return 0;
	if( obj == self->xObject.parent ) return 1;
	if( DaoObject_ChildOf( self->xObject.parent, obj ) ) return 1;
	return 0;
}
Example #11
0
int DaoObject_ChildOf( DaoObject *self, DaoValue *obj )
{
	if( obj == (DaoValue*) self ) return 1;
#if 0
	// No way to determine inheritance relationship between wrapped C++ objects;
	if( self->type >= DAO_CSTRUCT && self->type <= DAO_CDATA ){
		if( obj->type >= DAO_CSTRUCT && obj->type <= DAO_CDATA ){
			DaoCstruct *cdata1 = (DaoCstruct*) self;
			DaoCstruct *cdata2 = (DaoCstruct*) obj;
			if( DaoType_ChildOf( cdata1->ctype, cdata2->ctype ) ) return 1;
		}
		return 0;
	}
#endif
	if( self->parent == NULL ) return 0;
	if( self->parent == obj ) return 1;
	if( self->parent->type != DAO_OBJECT ) return 0;
	return DaoObject_ChildOf( (DaoObject*) self->parent, obj );
}
Example #12
0
FILE* DaoStream_GetFile( DaoStream *self )
{
	if( DaoType_ChildOf( self->ctype, dao_type_file_stream ) ){
		DaoFileStream *stream = (DaoFileStream*) self;
		return stream->file;
	}else if( self->Write == DaoStdStream_WriteStdout || self->Write == DaoStdStream_WriteStderr ){
		DaoStdStream *stream = (DaoStdStream*) self;
		if( stream->redirect ){
			return DaoStream_GetFile( stream->redirect );
		}else if( self->Write == DaoStdStream_WriteStdout ){
			return stdout;
		}else if( self->Write == DaoStdStream_WriteStderr ){
			return stderr;
		}
	}else if( self->Write == DaoStream_WriteStdout ){
		return stdout;
	}else if( self->Write == DaoStream_WriteStderr ){
		return stderr;
	}
	return NULL;
}