void printAttr(corto_object o) { printf("attributes of %s: ", corto_fullpath(NULL, o)); if (corto_checkAttr(o, CORTO_ATTR_SCOPED)) printf("S"); if (corto_checkAttr(o, CORTO_ATTR_WRITABLE)) printf("W"); if (corto_checkAttr(o, CORTO_ATTR_OBSERVABLE)) printf("O"); if (corto_checkAttr(o, CORTO_ATTR_PERSISTENT)) printf("P"); if (corto_attrof(o) == 0) { printf("none"); } printf("\n"); }
corto_void _test_compositeUnionApi_tc_defineDefault( test_compositeUnionApi _this) { /* $begin(test/compositeUnionApi/tc_defineDefault) */ corto_int16 result; test_compositeUnionType *o = test_compositeUnionTypeDeclareChild(root_o, "o"); test_assert(o != NULL); test_assert(corto_typeof(o) == corto_type(test_compositeUnionType_o)); test_assert(!corto_checkState(o, CORTO_DEFINED)); test_assert(corto_checkAttr(o, CORTO_ATTR_SCOPED)); test_assert(corto_parentof(o) == root_o); test_assert(!strcmp(corto_idof(o), "o")); test_assert(o->d == 2); test_assertstr(o->is.str, "foo"); result = test_compositeUnionTypeDefine_other(o, 4, 10); test_assert(result == 0); test_assert(corto_checkState(o, CORTO_DEFINED)); test_assert(o->d == 4); test_assert(o->is.other == 10); test_assert(!corto_delete(o)); /* $end */ }
corto_void _test_compositeApi_tc_define( test_compositeApi _this) { /* $begin(test/compositeApi/tc_define) */ corto_int16 result; test_compositeType *o = test_compositeTypeDeclareChild(root_o, "o"); test_assert(o != NULL); test_assert(corto_typeof(o) == corto_type(test_compositeType_o)); test_assert(!corto_checkState(o, CORTO_DEFINED)); test_assert(corto_checkAttr(o, CORTO_ATTR_SCOPED)); test_assert(corto_parentof(o) == root_o); test_assert(!strcmp(corto_idof(o), "o")); test_assert(o->x == 1); test_assert(o->y == 2); result = test_compositeTypeDefine(o, 10, 20); test_assert(result == 0); test_assert(corto_checkState(o, CORTO_DEFINED)); test_assert(o->x == 10); test_assert(o->y == 20); test_assert(!corto_delete(o)); /* $end */ }
corto_bool corto_authorized(corto_object object, corto_secure_actionKind access) { if (corto_checkAttr(object, CORTO_ATTR_NAMED)) { corto_id objectId; corto_fullpath(objectId, object); return corto_authorizedId(objectId, access); } else { return TRUE; } }
void corto_mount_notify(corto_subscriberEvent *e) { corto_mount this = (corto_mount)e->subscriber; corto_eventMask event = e->event; corto_result *r = &e->data; if (!r->object || (!this->attr || corto_checkAttr(r->object, this->attr))) { if (this->policy.mask & CORTO_MOUNT_NOTIFY) { corto_mount_onNotify(this, e); } switch(event) { case CORTO_DEFINE: this->sent.updates ++; if (this->policy.mask & CORTO_MOUNT_MOUNT) { corto_query q = { .select = e->data.id, .from = e->data.parent }; if (r->object) { corto_mount_subscribeOrMount(this, &q, false, true); } } break; case CORTO_UPDATE: this->sent.updates ++; break; case CORTO_DELETE: this->sent.deletes ++; if (this->policy.mask & CORTO_MOUNT_MOUNT) { corto_query q = { .select = e->data.id, .from = e->data.parent }; if (r->object) { corto_mount_unsubscribeOrUnmount(this, &q, false, true); } } break; default: break; } } }
corto_void _test_OptionalStringApi_tc_declareChild( test_OptionalStringApi _this) { /* $begin(test/OptionalStringApi/tc_declareChild) */ test_OptionalString *o = test_OptionalStringDeclareChild(root_o, "a"); test_assert(o != NULL); test_assert(!corto_checkState(o, CORTO_DEFINED)); test_assert(corto_checkAttr(o, CORTO_ATTR_SCOPED)); test_assertstr(corto_idof(o), "a"); test_assert(corto_parentof(o) == root_o); test_assert(o->a == NULL); test_assert(o->b == NULL); /* $end */ }
corto_void _test_OptionalStringApi_tc_createChildNotSet( test_OptionalStringApi _this) { /* $begin(test/OptionalStringApi/tc_createChildNotSet) */ test_OptionalString *o = test_OptionalStringCreateChild( root_o, "a", NotSet, "Bar"); test_assert(o != NULL); test_assert(corto_checkAttr(o, CORTO_ATTR_SCOPED)); test_assertstr(corto_idof(o), "a"); test_assert(corto_parentof(o) == root_o); test_assert(o->a == NULL); test_assertstr(o->b, "Bar"); /* $end */ }
corto_void _test_voidReferenceApi_tc_createChildAuto( test_voidReferenceApi _this) { /* $begin(test/voidReferenceApi/tc_createChildAuto) */ test_voidReferenceTypeCreateChild_auto(root_o, o); test_assert(o != NULL); test_assert(corto_typeof(o) == test_voidReferenceType_o); test_assert(corto_checkState(o, CORTO_DEFINED)); test_assert(corto_checkAttr(o, CORTO_ATTR_SCOPED)); test_assert(corto_parentof(o) == root_o); test_assert(!strcmp(corto_idof(o), "o")); test_assert(!corto_delete(o)); /* $end */ }
corto_void _test_compositeUnionApi_tc_declareChildAuto( test_compositeUnionApi _this) { /* $begin(test/compositeUnionApi/tc_declareChildAuto) */ test_compositeUnionTypeDeclareChild_auto(root_o, o); test_assert(o != NULL); test_assert(corto_typeof(o) == corto_type(test_compositeUnionType_o)); test_assert(!corto_checkState(o, CORTO_DEFINED)); test_assert(corto_checkAttr(o, CORTO_ATTR_SCOPED)); test_assert(corto_parentof(o) == root_o); test_assert(!strcmp(corto_idof(o), "o")); test_assert(o->d == 2); test_assertstr(o->is.str, "foo"); test_assert(!corto_delete(o)); /* $end */ }
corto_void _test_compositeApi_tc_createChildAuto( test_compositeApi _this) { /* $begin(test/compositeApi/tc_createChildAuto) */ test_compositeTypeCreateChild_auto(root_o, o, 10, 20); test_assert(o != NULL); test_assert(corto_typeof(o) == corto_type(test_compositeType_o)); test_assert(corto_checkState(o, CORTO_DEFINED)); test_assert(corto_checkAttr(o, CORTO_ATTR_SCOPED)); test_assert(corto_parentof(o) == root_o); test_assert(!strcmp(corto_idof(o), "o")); test_assert(o->x == 10); test_assert(o->y == 20); test_assert(!corto_delete(o)); /* $end */ }
corto_void _test_compositeUnionApi_tc_createChildAutoDefault( test_compositeUnionApi _this) { /* $begin(test/compositeUnionApi/tc_createChildAutoDefault) */ test_compositeUnionTypeCreateChild_other_auto( root_o, o, 4, 10); test_assert(o != NULL); test_assert(corto_typeof(o) == corto_type(test_compositeUnionType_o)); test_assert(corto_checkState(o, CORTO_DEFINED)); test_assert(corto_checkAttr(o, CORTO_ATTR_SCOPED)); test_assert(corto_parentof(o) == root_o); test_assert(!strcmp(corto_idof(o), "o")); test_assert(o->d == 4); test_assert(o->is.other == 10); test_assert(!corto_delete(o)); /* $end */ }
corto_void _test_compositeUnionApi_tc_createChild( test_compositeUnionApi _this) { /* $begin(test/compositeUnionApi/tc_createChild) */ test_compositeUnionType *o = test_compositeUnionTypeCreateChild_flt( root_o, "o", 1, 10.5); test_assert(o != NULL); test_assert(corto_typeof(o) == corto_type(test_compositeUnionType_o)); test_assert(corto_checkState(o, CORTO_DEFINED)); test_assert(corto_checkAttr(o, CORTO_ATTR_SCOPED)); test_assert(corto_parentof(o) == root_o); test_assert(!strcmp(corto_idof(o), "o")); test_assert(o->d == 1); test_assert(o->is.flt == 10.5); test_assert(!corto_delete(o)); /* $end */ }
corto_int16 corto_valueExpr_getTypeForBinary( corto_type leftType, corto_bool t1ByRef, corto_type rightType, corto_bool t2ByRef, corto_operatorKind _operator, corto_type *operandType, corto_type *resultType) { corto_type castType = NULL; corto_bool equal = FALSE; corto_assert(operandType != NULL, "NULL provided for out-parameter operandType"); corto_assert(resultType != NULL, "NULL provided for out-parameter resultType"); /* If operator is condition result type is a boolean */ if (corto_valueExpr_isOperatorConditional(_operator)) { *resultType = corto_type(corto_bool_o); } /* Get leftType and rightType */ if (!(leftType = corto_valueExpr_getType(leftType, NULL, FALSE))) { goto error; } if (!(rightType = corto_valueExpr_getType(rightType, leftType, t1ByRef))) { goto error; } if (!leftType) { leftType = rightType; } /* If objects are not scoped, verify whether they're equal */ if (!corto_checkAttr(leftType, CORTO_ATTR_NAMED) && !corto_checkAttr(rightType, CORTO_ATTR_NAMED)) { if (corto_compare(leftType, rightType) == CORTO_EQ) { equal = TRUE; } } else { equal = leftType == rightType; } if (_operator == CORTO_DIV) { castType = corto_type(corto_float64_o); } else if (!equal) { /* Can only cast between primitive types */ if ((leftType->kind == CORTO_PRIMITIVE ) && (rightType->kind == CORTO_PRIMITIVE)) { corto_primitive ltype = corto_primitive(leftType), rtype = corto_primitive(rightType); corto_int8 lscore, rscore; corto_int8 lCastScore, rCastScore; lscore = corto_valueExpr_getTypeScore(ltype); rscore = corto_valueExpr_getTypeScore(rtype); lCastScore = corto_valueExpr_getCastScore(ltype); rCastScore = corto_valueExpr_getCastScore(rtype); /* If expression is an assignment, always take type of lvalue. * Otherwise determine based on expressibility score which type to * cast to. */ if (corto_valueExpr_isOperatorAssignment(_operator)) { if (lCastScore == rCastScore) { if (ltype->width != rtype->width) { castType = leftType; } } else { castType = leftType; } } else { if (lCastScore == rCastScore) { if (ltype->width == rtype->width) { /* If width and kind are equal, no conversion is required. */ if (lscore > rscore) { *operandType = leftType; } else if (lscore < rscore) { *operandType = rightType; } } else { /* If lvalue has a larger width than rvalue, cast rvalue to leftType (and vice versa) */ if (ltype->width > rtype->width) { castType = leftType; } else { castType = rightType; } } /* If kinds do not match figure a cast is potentially needed. Figure out which type to cast to */ } else { if (lscore > rscore) { castType = leftType; } else { castType = rightType; } } } } else if (leftType->reference && rightType->reference) { castType = NULL; /* Check if types are compatible */ } else if ((rightType->reference || (t2ByRef)) && !leftType->reference) { if (corto_type_castable(leftType, corto_object_o)) { castType = leftType; } } else { corto_seterr("cannot cast from '%s' to '%s'", corto_fullpath(NULL, leftType), corto_fullpath(NULL, rightType)); goto error; } } else if ((rightType->reference || (t2ByRef)) && !leftType->reference) { if (corto_type_castable(leftType, corto_object_o)) { castType = leftType; } } if (!castType) { castType = leftType; } if (castType) { *operandType = castType; } if (!*resultType) { *resultType = *operandType; } return 0; error: return -1; }