static DaoType* DaoInterface_CheckForEach( DaoType *self, DaoRoutine *ctx ) { DaoRoutine *rout = DaoType_FindFunctionChars( self, "for" ); if( rout != NULL ){ DaoType *type, *itype; if( rout->routType->args->size != 2 ) return NULL; type = rout->routType->args->items.pType[1]; if( type->tid == DAO_PAR_NAMED ) type = (DaoType*) type->aux; if( type->tid != DAO_TUPLE || type->args->size != 2 ) return NULL; itype = type->args->items.pType[0]; if( itype->tid != DAO_BOOLEAN ) return NULL; return DaoNamespace_MakeIteratorType( ctx->nameSpace, type->args->items.pType[1] ); } return NULL; }
DaoType* DaoObject_CheckForEach( DaoType *self, DaoRoutine *ctx ) { DaoType *hostype = ctx->routHost; DaoClass *host = hostype != NULL && hostype->tid == DAO_OBJECT ? (DaoClass*) hostype->aux : NULL; DaoRoutine *rout = DaoClass_FindMethod( (DaoClass*) self->aux, "for", host ); if( rout != NULL ){ DaoType *type, *itype; if( rout->routType->args->size != 2 ) return NULL; type = rout->routType->args->items.pType[1]; if( type->tid == DAO_PAR_NAMED ) type = (DaoType*) type->aux; if( type->tid != DAO_TUPLE || type->args->size != 2 ) return NULL; itype = type->args->items.pType[0]; if( itype->tid != DAO_BOOLEAN ) return NULL; return DaoNamespace_MakeIteratorType( ctx->nameSpace, type->args->items.pType[1] ); } return NULL; }
DaoType* DaoCinValue_CheckForEach( DaoType *self, DaoRoutine *ctx ) { DaoTypeCore *core; DaoCinType *cintype = (DaoCinType*) self->aux; DaoRoutine *rout = DaoType_FindFunctionChars( cintype->vatype, "for" ); if( rout != NULL ){ DaoType *type, *itype; if( rout->routType->args->size != 2 ) goto TryTarget; type = rout->routType->args->items.pType[1]; if( type->tid == DAO_PAR_NAMED ) type = (DaoType*) type->aux; if( type->tid != DAO_TUPLE || type->args->size != 2 ) goto TryTarget; itype = type->args->items.pType[0]; if( itype->tid != DAO_BOOLEAN ) goto TryTarget; return DaoNamespace_MakeIteratorType( ctx->nameSpace, type->args->items.pType[1] ); } TryTarget: core = cintype->target->core; if( core != NULL && core->CheckForEach ){ return core->CheckForEach( cintype->target, ctx ); } return NULL; }