示例#1
0
文件: loader.cpp 项目: Blei/clay
static void initOverload(OverloadPtr x) {
    EnvPtr env = overloadPatternEnv(x);
    PatternPtr pattern = evaluateOnePattern(x->target, env);
    ObjectPtr obj = derefDeep(pattern);
    if (obj == NULL) {
        x->nameIsPattern = true;
        addPatternOverload(x);
    }
    else {
        switch (obj->objKind) {
        case PROCEDURE : {
            Procedure *proc = (Procedure *)obj.ptr();
            addProcedureOverload(proc, env, x);
            break;
        }
        case RECORD_DECL : {
            RecordDecl *r = (RecordDecl *)obj.ptr();
            r->overloads.insert(r->overloads.begin(), x);
            break;
        }
        case VARIANT_DECL : {
            VariantDecl *v = (VariantDecl *)obj.ptr();
            v->overloads.insert(v->overloads.begin(), x);
            break;
        }
        case TYPE : {
            Type *t = (Type *)obj.ptr();
            t->overloads.insert(t->overloads.begin(), x);
            break;
        }
        case PRIM_OP : {
            if (isOverloadablePrimOp(obj))
                addPrimOpOverload((PrimOp *)obj.ptr(), x);
            else
                error(x->target, "invalid overload target");
            break;
        }
        case GLOBAL_ALIAS : {
            GlobalAlias *a = (GlobalAlias*)obj.ptr();
            if (!a->hasParams())
                error(x->target, "invalid overload target");
            a->overloads.insert(a->overloads.begin(), x);
            break;
        }
        case INTRINSIC : {
            error(x->target, "invalid overload target");
        }
        default : {
            error(x->target, "invalid overload target");
        }
        }
    }
}
示例#2
0
void addProcedureOverload(ProcedurePtr proc, OverloadPtr x) {
    proc->overloads.insert(proc->overloads.begin(), x);
    getProcedureMonoTypes(proc->mono, overloadPatternEnv(x),
        x->code->formalArgs,
        x->code->formalVarArg);
}