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"); } } } }
static llvm::ArrayRef<OverloadPtr> callableOverloads(ObjectPtr x) { initCallable(x); switch (x->objKind) { case TYPE : { Type *y = (Type *)x.ptr(); return y->overloads; } case RECORD_DECL : { RecordDecl *y = (RecordDecl *)x.ptr(); return y->overloads; } case VARIANT_DECL : { VariantDecl *y = (VariantDecl *)x.ptr(); return y->overloads; } case PROCEDURE : { Procedure *y = (Procedure *)x.ptr(); return y->overloads; } case PRIM_OP : { assert(isOverloadablePrimOp(x)); PrimOp *y = (PrimOp *)x.ptr(); return primOpOverloads(y); } case GLOBAL_ALIAS : { GlobalAlias *a = (GlobalAlias *)x.ptr(); assert(a->hasParams()); return a->overloads; } default : { assert(false); const vector<OverloadPtr> *ptr = NULL; return *ptr; } } }