static kbool_t SetParamType(KonohaContext *kctx, kNode *stmt, int n, kparamtype_t *p) { kToken *typeToken = SUGAR kNode_GetToken(kctx, stmt, KSymbol_TypePattern, NULL); kNode *expr = SUGAR kNode_GetNode(kctx, stmt, KSymbol_ExprPattern, NULL); DBG_ASSERT(typeToken != NULL); DBG_ASSERT(expr != NULL); if(kNode_isSymbolTerm(expr)) { kToken *tkN = expr->TermToken; p[n].name = tkN->symbol; p[n].attrTypeId = Token_typeLiteral(typeToken); return true; } return false; }
static KMETHOD TypeCheck_UntypedAssign(KonohaContext *kctx, KonohaStack *sfp) { VAR_TypeCheck2(stmt, expr, ns, reqc); kNodeVar *leftHandNode = (kNodeVar *)kNode_At(expr, 1); if(kNode_isSymbolTerm(leftHandNode)) { kNode *texpr = KLIB TypeVariableNULL(kctx, leftHandNode, ns, KClass_INFER); if(texpr == NULL) { kNode *rightHandNode = KLIB TypeCheckNodeAt(kctx, expr, 2, ns, KClass_INFER, 0); if(rightHandNode != K_NULLNODE) { DeclVariable(kctx, stmt, ns, rightHandNode->typeAttr, leftHandNode); } } else { KFieldSet(expr->NodeList, expr->NodeList->NodeItems[1], texpr); } } }
static void DeclVariable(KonohaContext *kctx, kNode *stmt, kNameSpace *ns, ktypeattr_t ty, kNode *termNode) { DBG_ASSERT(kNode_isSymbolTerm(termNode)); kToken *termToken = termNode->TermToken; if(kNameSpace_IsTopLevel(ns)) { if(ns->globalObjectNULL == NULL) { kNodeToken_Message(kctx, stmt, termToken, ErrTag, "unavailable global variable"); return; } kNodeToken_Message(kctx, stmt, termToken, InfoTag, "global variable %s%s has type %s", KSymbol_Fmt2(termToken->symbol), KType_text(ty)); KLIB KClass_AddField(kctx, kObject_class(ns->globalObjectNULL), ty, termToken->symbol); } else { kNodeToken_Message(kctx, stmt, termToken, InfoTag, "%s%s has type %s", KSymbol_Fmt2(termToken->symbol), KType_text(ty)); KLIB AddLocalVariable(kctx, ns, ty, termToken->symbol); } }