本文整理汇总了C++中KReturn函数的典型用法代码示例。如果您正苦于以下问题:C++ KReturn函数的具体用法?C++ KReturn怎么用?C++ KReturn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了KReturn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Object_as
// @SmartReturn Object Object.as(Object target)
static KMETHOD Object_as(KonohaContext *kctx, KonohaStack *sfp)
{
KonohaClass *selfClass = O_ct(sfp[0].asObject), *targetClass = KGetReturnType(sfp);
kObject *returnValue;
if(selfClass == targetClass || selfClass->isSubType(kctx, selfClass, targetClass)) {
returnValue = sfp[0].asObject;
}
else {
returnValue = KLIB Knull(kctx, targetClass);
}
sfp[K_RTNIDX].unboxValue = O_unbox(returnValue);
KReturn(returnValue);
}
示例2: TypeCheck_to
static KMETHOD TypeCheck_to(KonohaContext *kctx, KonohaStack *sfp)
{
VAR_TypeCheck(stmt, expr, gma, reqty);
kExpr *targetExpr = SUGAR kStmt_TypeCheckExprAt(kctx, stmt, expr, 2, gma, TY_var, 0);
kExpr *selfExpr = SUGAR kStmt_TypeCheckExprAt(kctx, stmt, expr, 1, gma, targetExpr->ty, TypeCheckPolicy_NOCHECK);
if(selfExpr != K_NULLEXPR && targetExpr != K_NULLEXPR) {
KonohaClass *selfClass = CT_(selfExpr->ty), *targetClass = CT_(targetExpr->ty);
if(selfExpr->ty == targetExpr->ty || selfClass->isSubType(kctx, selfClass, targetClass)) {
kStmtExpr_Message(kctx, stmt, selfExpr, InfoTag, "no need: %s to %s", TY_t(selfExpr->ty), TY_t(targetExpr->ty));
KReturn(selfExpr);
}
kNameSpace *ns = Stmt_ns(stmt);
kMethod *mtd = KLIB kNameSpace_GetCoercionMethodNULL(kctx, ns, selfExpr->ty, targetExpr->ty);
if(mtd == NULL) {
mtd = KLIB kNameSpace_GetMethodByParamSizeNULL(kctx, ns, selfExpr->ty, MN_("to"), 0);
DBG_ASSERT(mtd != NULL); // because Object.to is found.
if(mtd->typeId != selfExpr->ty) {
KReturn(kStmtExpr_Message(kctx, stmt, selfExpr, ErrTag, "undefined coercion: %s to %s", TY_t(selfExpr->ty), TY_t(targetExpr->ty)));
}
}
KReturn(SUGAR kStmtkExpr_TypeCheckCallParam(kctx, stmt, expr, mtd, gma, targetClass->typeId));
}
}
示例3: KSymbol_toString
//## @Public @Const @Immutable @Coercion String Symbol.toString();
static KMETHOD KSymbol_toString(KonohaContext *kctx, KonohaStack *sfp)
{
ksymbol_t symbol = (ksymbol_t)sfp[0].intValue;
kString *s = KSymbol_GetString(kctx, KSymbol_Unmask(symbol));
if(KSymbol_Attr(symbol) != 0) {
KBuffer wb;
const char *prefix = KSymbol_prefixText(symbol);
KLIB KBuffer_Init(&(kctx->stack->cwb), &wb);
KLIB KBuffer_Write(kctx, &wb, prefix, strlen(prefix));
KLIB KBuffer_Write(kctx, &wb, kString_text(s), kString_size(s));
s = KLIB KBuffer_Stringfy(kctx, &wb, OnStack, StringPolicy_FreeKBuffer);
}
KReturn(s);
}
示例4: String_new_fromBytes_withDefaultDecode
//## String String.new(Bytes ba);
static KMETHOD String_new_fromBytes_withDefaultDecode(KonohaContext *kctx, KonohaStack *sfp)
{
kBytes *ba = sfp[1].asBytes;
kString *s = TS_EMPTY;
if(ba->bytesize != 0) {
KMakeTrace(trace, sfp);
KBuffer wb;
KLIB KBuffer_Init(&(kctx->stack->cwb), &wb);
KBuffer_convertCharset(kctx, &wb, "UTF-8", I18NAPI systemCharset, ba->buf, ba->bytesize, trace);
KLIB KBuffer_text(kctx, &wb, EnsureZero); /* String must be Null terminated */
s = KLIB KBuffer_Stringfy(kctx, &wb, OnStack, StringPolicy_FreeKBuffer);
}
KReturn(s);
}
示例5: Expression_Defined
static KMETHOD Expression_Defined(KonohaContext *kctx, KonohaStack *sfp)
{
VAR_Expression(expr, tokenList, beginIdx, currentIdx, endIdx);
kNameSpace *ns = kNode_ns(expr);
if(beginIdx == currentIdx && beginIdx + 1 < endIdx) {
kTokenVar *definedToken = tokenList->TokenVarItems[beginIdx]; // defined
kTokenVar *pToken = tokenList->TokenVarItems[beginIdx+1];
if(IS_Array(pToken->GroupTokenList)) {
SUGAR kNode_Op(kctx, expr, definedToken, 0);
FilterDefinedParam(kctx, ns, RangeGroup(pToken->GroupTokenList));
KReturn(SUGAR AppendParsedNode(kctx, expr, RangeGroup(pToken->GroupTokenList), NULL, ParseExpressionOption, "("));
}
}
}
示例6: System_stat
//## Stat System.stat(String path)
static KMETHOD System_stat(KonohaContext *kctx, KonohaStack *sfp)
{
KMakeTrace(trace, sfp);
char buffer[K_PATHMAX];
kString *path = sfp[1].asString;
const char *systemPath = PLATAPI I18NModule.formatSystemPath(kctx, buffer, sizeof(buffer), kString_text(path), kString_size(path), trace);
struct stat buf = {}; /* zero */
int ret = stat(systemPath, &buf);
if(ret == -1) {
int fault = KLIB DiagnosisFaultType(kctx, kString_GuessUserFault(path)|SystemError, trace);
KTraceErrorPoint(trace, fault, "stat", LogText("path", kString_text(path)), LogErrno);
}
KReturn(KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), (uintptr_t)&buf));
}
示例7: MecabNode_enext
// MecabNode MecabNode.enext()
static KMETHOD MecabNode_enext(KonohaContext *kctx, KonohaStack *sfp)
{
struct _kMecabNode *node = (struct _kMecabNode *)sfp[0].asObject;
mecab_node_t* enext = node->node->enext;
struct _kMecabNode* ret;
if(node != NULL) {
ret = (struct _kMecabNode *)KLIB new_kObject(kctx, OnStack, KGetReturnType(sfp), 0);
ret->node = enext;
KReturn(ret);
}
else {
KReturnDefaultValue();
}
}
示例8: TypeCheck_to
static KMETHOD TypeCheck_to(KonohaContext *kctx, KonohaStack *sfp)
{
VAR_TypeCheck2(stmt, expr, ns, reqc);
kNode *targetNode = SUGAR TypeCheckNodeAt(kctx, expr, 2, ns, KClass_INFER, 0);
kNode *selfNode = SUGAR TypeCheckNodeAt(kctx, expr, 1, ns, KClass_(targetNode->attrTypeId), TypeCheckPolicy_NoCheck);
if(selfNode != K_NULLNODE && targetNode != K_NULLNODE) {
KClass *selfClass = KClass_(selfNode->attrTypeId), *targetClass = KClass_(targetNode->attrTypeId);
if(selfNode->attrTypeId == targetNode->attrTypeId || selfClass->isSubType(kctx, selfClass, targetClass)) {
SUGAR MessageNode(kctx, selfNode, NULL, ns, InfoTag, "no need: %s to %s", KType_text(selfNode->attrTypeId), KType_text(targetNode->attrTypeId));
KReturn(selfNode);
}
kNameSpace *ns = kNode_ns(stmt);
kMethod *mtd = KLIB kNameSpace_GetCoercionMethodNULL(kctx, ns, selfClass, targetClass);
if(mtd == NULL) {
mtd = KLIB kNameSpace_GetMethodByParamSizeNULL(kctx, ns, selfClass, KMethodName_("to"), 0, KMethodMatch_CamelStyle);
DBG_ASSERT(mtd != NULL); // because Object.to is found.
if(mtd->typeId != selfClass->typeId) {
KReturn(SUGAR MessageNode(kctx, selfNode, NULL, ns, ErrTag, "undefined coercion: %s to %s", KClass_text(selfClass), KClass_text(targetClass)));
}
}
KReturn(SUGAR TypeCheckMethodParam(kctx, mtd, expr, ns, targetClass));
}
}
示例9: _set_value
static CMPIStatus _set_value(KValue* kv, KTag tag, const CMPIData* cd)
{
/* Strip unused flags */
tag = KTypeOf(tag) | (tag & KTAG_ARRAY);
if (_cmpitype_to_ktag(cd->type) != tag)
{
KReturn(ERR_FAILED);
}
kv->exists = 1;
if (cd->state & CMPI_nullValue)
{
kv->null = 1;
kv->u.uint64 = 0;
KReturn(OK);
}
else
{
kv->u.uint64 = cd->value.uint64;
if (tag == KTYPE_STRING)
{
KString* ks = (KString*)kv;
ks->chars = KChars(ks->value);
}
if (tag & KTAG_ARRAY)
{
KArray* ks = (KArray*)kv;
ks->count = CMGetArrayCount(ks->value, NULL);
}
/* ATTN: validate references and instances */
KReturn(OK);
}
}
示例10: Array_shift
static KMETHOD Array_shift(KonohaContext *kctx, KonohaStack *sfp)
{
kArray *a = sfp[0].asArray;
struct _kAbstractArray *a2 = (struct _kAbstractArray *)a;
if(kArray_isUnboxData(a)) {
uintptr_t v = a->unboxItems[0];
kArray_removeAt(kctx, a, 0);
KReturnUnboxValue(v);
}
else {
kObject *value = a2->a.ObjectItems[0];
kArray_removeAt(kctx, a, 0);
KReturn(value);
}
}
示例11: KStackReturnTypeCheck
static void KStackReturnTypeCheck(KonohaContext *kctx, KonohaStack *sfp, kMethod *mtd, KClass *reqType, KClass *thisClass)
{
if(!kMethod_Is(SmartReturn, mtd)) {
KClass *returnType = kMethod_GetReturnType(mtd);
returnType = returnType->realtype(kctx, returnType, thisClass);
if(reqType == returnType || returnType->isSubType(kctx, returnType, reqType)) {
if(KClass_Is(UnboxType, returnType) && !KClass_Is(UnboxType, reqType)) {
KReturn(KLIB new_kObject(kctx, OnStack, returnType, sfp[K_RTNIDX].unboxValue));
}
}
else {
ThrowTypeError(kctx, sfp, -1);
}
}
}
示例12: ResultSet_get
//## @SmartReturn Object ResultSet.get(String n);
static KMETHOD ResultSet_get(KonohaContext *kctx, KonohaStack *sfp)
{
KClass *retClass = KGetReturnType(sfp);
if(retClass->typeId == KType_Int) {
ResultSet_getInt(kctx, sfp);
} else if(retClass->typeId == KType_String) {
ResultSet_getString(kctx, sfp);
} else if(KDefinedKonohaCommonModule() && retClass->typeId == KType_float) {
ResultSet_getFloat(kctx, sfp);
} else {
kObject *returnValue = KLIB Knull(kctx, retClass);
KStackSetUnboxValue(sfp[K_RTNIDX].unboxValue, kObject_Unbox(returnValue));
KReturn(returnValue);
}
}
示例13: Stmt_getTokenList
//## Token[] Stmt.getTokenList(symbol keyword, Token[] def);
static KMETHOD Stmt_getTokenList(KonohaContext *kctx, KonohaStack *sfp)
{
kStmt *stmt = sfp[0].asStmt;
ksymbol_t keyword = (ksymbol_t)sfp[1].intValue;
kArray *def = sfp[2].asArray;
kTokenArray *tokenList = (kTokenArray *)kStmt_GetObject(kctx, stmt, keyword, def);
kTokenArray *ret;
if(!IS_Array(tokenList)) {
ret = new_(TokenArray, 0, OnStack);
KLIB kArray_Add(kctx, ret, tokenList);
}
else {
ret = tokenList;
}
KReturn(ret);
}
示例14: String_new_fromBytes_withSpecifiedDecode
//## String String.new(Bytes ba, String charset);
static KMETHOD String_new_fromBytes_withSpecifiedDecode(KonohaContext *kctx, KonohaStack *sfp)
{
kBytes *ba = sfp[1].asBytes;
kString *charset = sfp[2].asString;
kString *s = TS_EMPTY;
if(ba->bytesize != 0) {
// At this point, we assuem 'ba' is null terminated.
DBG_ASSERT(ba->buf[ba->bytesize] == '\0');
KMakeTrace(trace, sfp);
KBuffer wb;
KLIB KBuffer_Init(&(kctx->stack->cwb), &wb);
KBuffer_convertCharset(kctx, &wb, kString_text(charset), "UTF-8", ba->buf, ba->bytesize, trace);
s = KLIB KBuffer_Stringfy(kctx, &wb, OnStack, StringPolicy_FreeKBuffer);
}
KReturn(s);
}
示例15: Array_newArray
static KMETHOD Array_newArray(KonohaContext *kctx, KonohaStack *sfp)
{
kArrayVar *a = (kArrayVar *)sfp[0].asObject;
size_t asize = (size_t)sfp[1].intValue;
a->bytemax = asize * sizeof(uintptr_t);
kArray_SetSize(a, asize);
a->ObjectItems = (kObject**)KCalloc_UNTRACE(a->bytemax, 1);
if(!kArray_isUnboxData(a)) {
size_t i;
kObject *null = KLIB Knull(kctx, CT_(O_p0(a)));
for(i = 0; i < asize; i++) {
KFieldSet(a, a->ObjectItems[i], null);
}
}
KReturn(a);
}