static LEXEME *getTypeList(LEXEME *lex, SYMBOL *funcsp, INITLIST **lptr) { *lptr = NULL; do { TYPE *tp = NULL; lex = getsym(); /* past ( or , */ lex = get_type_id(lex, &tp, funcsp, sc_cast, FALSE, TRUE); if (!tp) break; if (tp->type != bt_templateparam) { *lptr = Alloc(sizeof(INITLIST)); (*lptr)->tp = tp; (*lptr)->exp = intNode(en_c_i, 0); lptr = &(*lptr)->next; } else if (tp->templateParam->p->packed) { TEMPLATEPARAMLIST *tpl = tp->templateParam->p->byPack.pack; needkw(&lex, ellipse); while (tpl) { if (tpl->p->byClass.val) { *lptr = Alloc(sizeof(INITLIST)); (*lptr)->tp = tpl->p->byClass.val; (*lptr)->exp = intNode(en_c_i, 0); lptr = &(*lptr)->next; } tpl = tpl->next; } } else { if (tp->templateParam->p->byClass.val) { *lptr = Alloc(sizeof(INITLIST)); (*lptr)->tp = tp->templateParam->p->byClass.val; (*lptr)->exp = intNode(en_c_i, 0); lptr = &(*lptr)->next; } } } while (MATCHKW(lex, comma)); needkw(&lex, closepa); return lex; }
IMODE *make_direct(int i) /* * make a direct reference to an immediate value. */ { return make_ioffset(intNode(en_c_i, i)); }
static BOOLEAN is_polymorphic(LEXEME **lex, SYMBOL *funcsp, SYMBOL *sym, TYPE **tp, EXPRESSION **exp) { INITLIST *lst; BOOLEAN rv = FALSE; FUNCTIONCALL funcparams; memset(&funcparams, 0, sizeof(funcparams)); funcparams.sp = sym; *lex = getTypeList(*lex, funcsp, &funcparams.arguments); lst = funcparams.arguments; while (lst) { lst->tp = PerformDeferredInitialization(lst->tp, NULL); lst = lst->next; } if (funcparams.arguments && !funcparams.arguments-> next) { // yes references are literal types... if (isstructured(funcparams.arguments->tp)) rv = !! hasVTab(basetype(funcparams.arguments->tp)->sp); } *exp = intNode(en_c_i, rv); *tp = &stdint; return TRUE; }
static EXPRESSION *newReturn(TYPE *tp) { EXPRESSION *exp ; if (!isstructured(tp) && !isvoid(tp)) { exp = varNode(en_auto, anonymousVar(sc_auto, tp)); deref(tp, &exp); } else exp = intNode(en_c_i, 0); return exp; }
static BOOLEAN is_union(LEXEME **lex, SYMBOL *funcsp, SYMBOL *sym, TYPE **tp, EXPRESSION **exp) { INITLIST *lst; BOOLEAN rv = FALSE; FUNCTIONCALL funcparams; memset(&funcparams, 0, sizeof(funcparams)); funcparams.sp = sym; *lex = getTypeList(*lex, funcsp, &funcparams.arguments); if (funcparams.arguments && !funcparams.arguments-> next) { rv = basetype(funcparams.arguments->tp)->type == bt_union; } *exp = intNode(en_c_i, rv); *tp = &stdint; return TRUE; }
static BOOLEAN is_literal(LEXEME **lex, SYMBOL *funcsp, SYMBOL *sym, TYPE **tp, EXPRESSION **exp) { INITLIST *lst; BOOLEAN rv = FALSE; FUNCTIONCALL funcparams; memset(&funcparams, 0, sizeof(funcparams)); funcparams.sp = sym; *lex = getTypeList(*lex, funcsp, &funcparams.arguments); if (funcparams.arguments && !funcparams.arguments-> next) { // yes references are literal types... rv = !isstructured(funcparams.arguments->tp); } *exp = intNode(en_c_i, rv); *tp = &stdint; return TRUE; }
static BOOLEAN is_trivially_constructible(LEXEME **lex, SYMBOL *funcsp, SYMBOL *sym, TYPE **tp, EXPRESSION **exp) { INITLIST *lst; BOOLEAN rv = FALSE; FUNCTIONCALL funcparams; memset(&funcparams, 0, sizeof(funcparams)); funcparams.sp = sym; *lex = getTypeList(*lex, funcsp, &funcparams.arguments); lst = funcparams.arguments; while (lst) { lst->tp = PerformDeferredInitialization(lst->tp, NULL); lst = lst->next; } if (funcparams.arguments && !funcparams.arguments-> next) { rv = trivialCopyConstructible(funcparams.arguments->tp) && trivialDefaultConstructor(funcparams.arguments->tp); } *exp = intNode(en_c_i, rv); *tp = &stdint; return TRUE; }
static BOOLEAN is_standard_layout(LEXEME **lex, SYMBOL *funcsp, SYMBOL *sym, TYPE **tp, EXPRESSION **exp) { INITLIST *lst; BOOLEAN rv = FALSE; FUNCTIONCALL funcparams; memset(&funcparams, 0, sizeof(funcparams)); funcparams.sp = sym; *lex = getTypeList(*lex, funcsp, &funcparams.arguments); lst = funcparams.arguments; while (lst) { lst->tp = PerformDeferredInitialization(lst->tp, NULL); lst = lst->next; } if (funcparams.arguments && !funcparams.arguments-> next) { rv = !!isStandardLayout(funcparams.arguments->tp, NULL); } *exp = intNode(en_c_i, rv); *tp = &stdint; return TRUE; }
static BOOLEAN is_empty(LEXEME **lex, SYMBOL *funcsp, SYMBOL *sym, TYPE **tp, EXPRESSION **exp) { INITLIST *lst; BOOLEAN rv = FALSE; FUNCTIONCALL funcparams; memset(&funcparams, 0, sizeof(funcparams)); funcparams.sp = sym; *lex = getTypeList(*lex, funcsp, &funcparams.arguments); lst = funcparams.arguments; while (lst) { lst->tp = PerformDeferredInitialization(lst->tp, NULL); lst = lst->next; } if (funcparams.arguments && !funcparams.arguments-> next) { if (isstructured(funcparams.arguments->tp)) rv = !basetype(funcparams.arguments->tp)->syms->table[0] || !basetype(funcparams.arguments->tp)->syms->table[0]->next; } *exp = intNode(en_c_i, rv); *tp = &stdint; return TRUE; }
static EXPRESSION *createLambda(BOOLEAN noinline) { EXPRESSION *rv = NULL, **cur = &rv; HASHREC *hr; EXPRESSION *clsThs, *parentThs; SYMBOL *cls = makeID(lambdas->enclosingFunc ? sc_auto : sc_localstatic, lambdas->cls->tp, NULL, AnonymousName()); SetLinkerNames(cls, lk_cdecl); cls->allocate = TRUE; if (lambdas->enclosingFunc) { insert(cls, localNameSpace->syms); clsThs = varNode(en_auto, cls); // this ptr } else { insert(cls, globalNameSpace->syms); // well if we could put this as an auto in the init func that would be good but there is no way to do that here... clsThs = varNode(en_label, cls); // this ptr cls->label = nextLabel++; insertInitSym(cls); } { INITIALIZER *init = NULL; EXPRESSION *exp = clsThs; callDestructor(cls, NULL, &exp, NULL, TRUE, FALSE, FALSE); initInsert(&init, cls->tp, exp, 0, TRUE); if (cls->storage_class != sc_auto) { insertDynamicDestructor(cls, init); } else { cls->dest = init; } } parentThs = varNode(en_auto, (SYMBOL *)basetype(lambdas->func->tp)->syms->table[0]->p); // this ptr hr = lambdas->cls->tp->syms->table[0]; while (hr) { SYMBOL *sp = (SYMBOL *)hr->p; EXPRESSION *en = NULL, *en1 = NULL; if (!strcmp(sp->name, "$self")) { en1 = clsThs; en = varNode(en_label, sp); deref(&stdpointer, &en); en = exprNode(en_assign, en, en1); } else if (!strcmp(sp->name, "$parent")) { en1 = parentThs; // get parent from function call deref(&stdpointer, &en1); en = exprNode(en_add, clsThs, intNode(en_c_i, sp->offset)) ; deref(&stdpointer, &en); en = exprNode(en_assign, en, en1); } else if (!strcmp(sp->name, "$this")) { if (!lambdas->next || !lambdas->captureThis) { en1 = parentThs; // get parent from function call } else { SYMBOL *parent = search("$parent", lambdas->cls->tp->syms); en1 = varNode(en_auto, cls); deref(&stdpointer, &en1); en1 = exprNode(en_add, en1, intNode(en_c_i, parent->offset)); } deref(&stdpointer, &en1); en = exprNode(en_add, clsThs, intNode(en_c_i, sp->offset)) ; deref(&stdpointer, &en); en = exprNode(en_assign, en, en1); } else if (sp->lambdaMode) { LAMBDASP *lsp = (LAMBDASP *)search(sp->name, lambdas->captured); if (lsp) { en1 = exprNode(en_add, clsThs, intNode(en_c_i, sp->offset)); if (sp->lambdaMode == cmRef) { SYMBOL *capture = lsp->parent; deref(&stdpointer, &en1); if (capture->lambdaMode) { en = parentThs; deref(&stdpointer, &en); en = exprNode(en_add, en, intNode(en_c_i, capture->offset)); } else // must be an sc_auto { en = varNode(en_auto, capture); } if (isref(capture->tp)) { deref(&stdpointer, &en); } en = exprNode(en_assign, en1, en); } else // cmValue { SYMBOL *capture = lsp->parent; TYPE *ctp = capture->tp; if (capture->lambdaMode) { en = parentThs; deref(&stdpointer, &en); en = exprNode(en_add, en, intNode(en_c_i, capture->offset)); } else // must be an sc_auto { en = varNode(en_auto, capture); } if (isref(ctp)) { ctp = basetype(ctp)->btp; deref(&stdpointer, &en); } if (isstructured(ctp)) { FUNCTIONCALL *params = (FUNCTIONCALL *)Alloc(sizeof(FUNCTIONCALL)); params->arguments = (INITLIST *)Alloc(sizeof(INITLIST)); params->arguments->tp = ctp; params->arguments->exp = en; if (!callConstructor(&ctp, &en1, params, FALSE, NULL, TRUE, FALSE, TRUE, FALSE, FALSE)) errorsym(ERR_NO_APPROPRIATE_CONSTRUCTOR, lsp->sym); en = en1; } else { deref(ctp, &en1); deref(ctp, &en); en = exprNode(en_assign, en1, en); } } } else { diag("createLambda: no capture var"); } } if (en) { *cur = exprNode(en_void, en, NULL); cur = &(*cur)->right; } hr = hr->next; } *cur = clsThs; // this expression will be used in copy constructors, or discarded if unneeded return rv; }
EXPRESSION *convertInitToExpression(TYPE *tp, SYMBOL *sp, SYMBOL *funcsp, INITIALIZER *init, EXPRESSION *thisptr, BOOLEAN isdest) { EXPRESSION *rv = NULL, **pos = &rv; EXPRESSION *exp = NULL, **expp; EXPRESSION *expsym; BOOLEAN noClear = FALSE; if (sp) sp->destructed = FALSE; if (isstructured(tp) || isarray(tp)) { INITIALIZER **i2 = &init; while (*i2) i2 = &(*i2)->next; initInsert(i2, NULL, NULL, tp->size, FALSE); } if (!sp) { if (thisptr) expsym = thisptr; else if (funcsp) { SYMBOL *sp = (SYMBOL *)basetype(funcsp->tp)->syms->table[0] ? (SYMBOL *)basetype(funcsp->tp)->syms->table[0]->p : NULL; if (sp && sp->thisPtr) expsym = varNode(en_auto, sp ); // this ptr else expsym = anonymousVar(sc_auto, tp); } else { expsym = intNode(en_c_i, 0); diag("convertInitToExpression: no this ptr"); } } else switch (sp->storage_class) { case sc_auto: case sc_register: case sc_parameter: expsym = varNode(en_auto, sp); break; case sc_localstatic: if (sp->linkage3 == lk_threadlocal) { expsym = exprNode(en_add, thisptr, intNode(en_c_i, sp->offset)); } else { expsym = varNode(en_label, sp); } break; case sc_static: case sc_global: if (sp->linkage3 == lk_threadlocal) { expsym = exprNode(en_add, thisptr, intNode(en_c_i, sp->offset)); } else { expsym = varNode(en_global, sp); } break; case sc_member: case sc_mutable: if (thisptr) expsym = thisptr; else if (funcsp) expsym = varNode(en_auto, (SYMBOL *)basetype(funcsp->tp)->syms->table[0]->p); // this ptr else { expsym = intNode(en_c_i, 0); diag("convertInitToExpression: no this ptr"); } expsym = exprNode(en_add, expsym, intNode(en_c_i, sp->offset)); break; case sc_external: /* expsym = varNode(en_global, sp); break; */ default: diag("convertInitToExpression: unknown sym type"); expsym = intNode(en_c_i, 0); break; } while (init) { exp = NULL; if (init->basetp) { if (init->noassign) { exp = init->exp; if (exp->type == en_thisref) exp = exp->left; if (thisptr && exp->type == en_func) { EXPRESSION *exp1 = init->offset ? exprNode(en_add, expsym, intNode(en_c_i, init->offset)) : expsym; if (isarray(tp)) { exp->v.func->arguments->exp = exp1; } else { exp->v.func->thisptr = exp1; } } exp = init->exp; } else if (!init->exp) { // usually empty braces, coudl be an error though exp = exprNode(en_blockclear, expsym, NULL); exp->size = init->offset; } else if (isstructured(init->basetp) || isarray(init->basetp)) { INITIALIZER *temp = init; if (isstructured(temp->basetp)) { EXPRESSION *exp2 = init->exp; while(exp2->type == en_not_lvalue) exp2 = exp2->left; if (exp2->type == en_func && exp2->v.func->returnSP) { exp2->v.func->returnSP->allocate = FALSE; exp2->v.func->returnEXP = expsym; exp = exp2; noClear = TRUE; } else if (exp2->type == en_thisref && exp2->left->v.func->returnSP) { exp2->left->v.func->returnSP->allocate = FALSE; exp2->left->v.func->returnEXP = expsym; exp = exp2; noClear = TRUE; } else if (cparams.prm_cplusplus) { TYPE *ctype = init->basetp; FUNCTIONCALL *funcparams = Alloc(sizeof(FUNCTIONCALL)); funcparams->arguments = Alloc(sizeof(INITLIST)); funcparams->arguments->tp = ctype; funcparams->arguments->exp = exp2; callConstructor(&ctype, &expsym, funcparams, FALSE, NULL, TRUE, FALSE, FALSE, FALSE, FALSE); exp = expsym; } else { exp = exprNode(en_blockassign, expsym, exp2); exp->size = init->basetp->size; } } else { TYPE *btp = init->basetp; while(isarray(btp)) btp = basetype(btp)->btp; btp = basetype(btp); while (temp) { if (temp->exp) if (!isarithmeticconst(temp->exp) && !isconstaddress(temp->exp)) break; temp = temp->next; } if (temp) { /* some members are non-constant expressions */ if (!cparams.prm_c99 && !cparams.prm_cplusplus) error(ERR_C99_NON_CONSTANT_INITIALIZATION); if (!sp) { expsym = anonymousVar(sc_auto, init->basetp); sp = expsym->v.sp; } if (!isstructured(btp) || btp->sp->trivialCons) { exp = exprNode(en_blockclear, expsym, NULL); exp->size = init->basetp->size; exp = exprNode(en_void, exp, NULL); expp = &exp->right; } else { expp = &exp; } { EXPRESSION *right = init->exp; if (!isstructured(btp)) { EXPRESSION *asn = exprNode(en_add, expsym, intNode(en_c_i, init->offset)); deref(init->basetp, &asn); cast(init->basetp, &right); right = exprNode(en_assign, asn, right); } if (*expp) *expp = exprNode(en_void, *expp, right); else *expp = right; expp = &(*expp)->right; } } else { /* constant expression */ SYMBOL *spc ; IncGlobalFlag(); exp = anonymousVar(sc_localstatic, init->basetp); spc = exp->v.sp; spc->init = init ; insertInitSym(spc); insert(spc, localNameSpace->syms); DecGlobalFlag(); spc->label =nextLabel++; if (expsym) { if (cparams.prm_cplusplus && isstructured(init->basetp) && !init->basetp->sp->trivialCons) { TYPE *ctype = init->basetp; FUNCTIONCALL *funcparams = Alloc(sizeof(FUNCTIONCALL)); funcparams->arguments = Alloc(sizeof(INITLIST)); funcparams->arguments->tp = ctype; funcparams->arguments->exp = exp; callConstructor(&ctype, &expsym, funcparams, FALSE, NULL, TRUE, FALSE, FALSE, FALSE, FALSE); exp = expsym; } else { exp = exprNode(en_blockassign, expsym, exp); exp->size = init->basetp->size; } } } } } else if (basetype(init->basetp)->type == bt_memberptr) { EXPRESSION *exp2 = init->exp;; while(exp2->type == en_not_lvalue) exp2 = exp2->left; if (exp2->type == en_func && exp2->v.func->returnSP) { exp2->v.func->returnSP->allocate = FALSE; exp2->v.func->returnEXP = expsym; exp = exp2; } else { if (exp2->type == en_memberptr) { int lab = dumpMemberPtr(exp2->v.sp, init->basetp, TRUE); exp2 = intNode(en_labcon, lab); } exp = exprNode(en_blockassign, expsym, exp2); exp->size = init->basetp->size; } } else { EXPRESSION *exps = expsym; if (init->offset) exps = exprNode(en_add, exps, intNode(en_c_i, init->offset)); deref(init->basetp, &exps); exp = init->exp; if (exp->type == en_void) { cast(init->basetp, &exp->right); if (expsym) exp->right = exprNode(en_assign, exps, exp->right); } else { cast(init->basetp, &exp); if (exps) exp = exprNode(en_assign, exps, exp); } } if (sp && sp->init && isatomic(init->basetp) && needsAtomicLockFromType(init->basetp)) { EXPRESSION *p1 = exprNode(en_add, expsym->left, intNode(en_c_i, init->basetp->size - ATOMIC_FLAG_SPACE)); deref(&stdint, &p1); p1 = exprNode(en_assign, p1, intNode(en_c_i, 0)); exp = exprNode(en_void, exp, p1); } } if (exp) { if (*pos) { *pos = exprNode(en_void, *pos, exp); pos = &(*pos)->right; } else { *pos = exp; } } init = init->next; } if (sp && sp->storage_class == sc_localstatic) { if (isdest) { rv = exprNode(en_voidnz, exprNode(en_void, sp->localInitGuard, rv), intNode(en_c_i, 0)); } else { EXPRESSION *guard = anonymousVar(sc_static, &stdint); insertInitSym(guard->v.sp); deref(&stdpointer, &guard); optimize_for_constants(&rv); rv = exprNode(en_voidnz, exprNode(en_void, exprNode(en_not, guard, NULL), exprNode(en_void, rv, exprNode(en_autoinc, guard, intNode(en_c_i, 1)))), intNode(en_c_i, 0)); sp->localInitGuard = guard; } } // plop in a clear block if necessary if (sp && !noClear && !isdest && (isarray(tp) || isstructured(tp) && (!cparams.prm_cplusplus || basetype(tp)->sp->trivialCons))) { EXPRESSION *fexp = expsym; EXPRESSION *exp; if (fexp->type == en_thisref) fexp = fexp->left->v.func->thisptr; exp = exprNode(en_blockclear, fexp, NULL); exp->size = sp->tp->size; rv = exprNode(en_void, exp, rv); } if (isstructured(tp) && !cparams.prm_cplusplus) { if (*pos) { *pos = exprNode(en_void, *pos, expsym); pos = &(*pos)->right; } else { *pos = expsym; } } return rv; }
EXPRESSION *stringlit(STRING *s) { return intNode(en_c_i, 0); }
void genfunc(SYMBOL *funcsp) /* * generate a function body and dump the icode */ { IMODE *allocaAP = NULL; SYMBOL *oldCurrentFunc; EXPRESSION *funcexp = varNode(en_global, funcsp); SYMBOL *tmpl = funcsp; if (total_errors) return; while (tmpl) if (tmpl->templateLevel) break; else tmpl = tmpl->parentClass; // //printf("%s\n", funcsp->name); temporarySymbols = NULL; contlab = breaklab = - 1; structret_imode = 0 ; tempCount = 0; blockCount = 0; blockMax = 0; exitBlock = 0; consIndex = 0; oldCurrentFunc = theCurrentFunc; theCurrentFunc = funcsp; iexpr_func_init(); if (funcsp->xc && funcsp->xc->xctab) { EXPRESSION *exp; xcexp = varNode(en_auto, funcsp->xc->xctab); xcexp = exprNode(en_add, xcexp, intNode(en_c_i, (LLONG_TYPE)&(((struct _xctab *)0)->funcIndex))); deref(&stdpointer, &xcexp); exp = intNode(en_c_i, 0); xcexp = exprNode(en_assign, xcexp, exp); } else { xcexp = NULL; } /* firstlabel = nextLabel;*/ cseg(); gen_line(funcsp->linedata); gen_func(funcexp, 1); /* in C99 inlines can clash if declared 'extern' in multiple modules */ /* in C++ we introduce virtual functions that get coalesced at link time */ if (cparams.prm_cplusplus && (funcsp->linkage == lk_inline || tmpl)) gen_virtual(funcsp, FALSE); else { if (funcsp->storage_class == sc_global || (funcsp->storage_class == sc_member || funcsp->storage_class == sc_virtual) && funcsp->inlineFunc.stmt) globaldef(funcsp); else localdef(funcsp); gen_strlab(funcsp); /* name of function */ } addblock( - 1); if (funcsp->linkage == lk_interrupt || funcsp->linkage == lk_fault) { gen_icode(i_pushcontext, 0,0,0); /* if (funcsp->loadds) */ /* gen_icode(i_loadcontext, 0,0,0); */ } gen_icode(i_prologue,0,0,0); gen_label(startlab); if (cparams.prm_xcept && funcsp->xc && funcsp->xc->xcInitializeFunc) { gen_expr(funcsp, funcsp->xc->xcInitializeFunc, F_NOVALUE, ISZ_UINT); gen_label(funcsp->xc->xcInitLab); } /* if (funcsp->loadds && funcsp->farproc) */ /* gen_icode(i_loadcontext, 0,0,0); */ AllocateLocalContext(NULL, funcsp); if (funcsp->allocaUsed) { EXPRESSION *allocaExp = anonymousVar(sc_auto, &stdpointer); allocaAP = gen_expr(funcsp, allocaExp, 0, ISZ_ADDR); gen_icode(i_savestack, 0, allocaAP, 0); } /* Generate the icode */ /* LCSE is done while code is generated */ genstmt(funcsp->inlineFunc.stmt->lower, funcsp); if (funcsp->inlineFunc.stmt->blockTail) { gen_icode(i_functailstart, 0, 0, 0); genstmt(funcsp->inlineFunc.stmt->blockTail, funcsp); gen_icode(i_functailend, 0, 0, 0); } genreturn(0, funcsp, 1, 0, allocaAP); gen_func(funcexp, 0); tFree(); InsertParameterThunks(funcsp, blockArray[1]); optimize(funcsp); FreeLocalContext(NULL, funcsp); AllocateStackSpace(funcsp); FillInPrologue(intermed_head, funcsp); /* Code gen from icode */ rewrite_icode(); /* Translate to machine code & dump */ if (chosenAssembler->gen->post_function_gen) chosenAssembler->gen->post_function_gen(funcsp, intermed_head); if (cparams.prm_cplusplus && (funcsp->linkage == lk_inline || tmpl)) gen_endvirtual(funcsp); XTDumpTab(funcsp); intermed_head = NULL; dag_rundown(); oFree(); theCurrentFunc = oldCurrentFunc; if (blockCount > maxBlocks) maxBlocks = blockCount; if (tempCount > maxTemps) maxTemps = tempCount; }
static BOOLEAN is_convertible_to(LEXEME **lex, SYMBOL *funcsp, SYMBOL *sym, TYPE **tp, EXPRESSION **exp) { BOOLEAN rv = TRUE; FUNCTIONCALL funcparams; memset(&funcparams, 0, sizeof(funcparams)); funcparams.sp = sym; *lex = getTypeList(*lex, funcsp, &funcparams.arguments); if (funcparams.arguments && funcparams.arguments->next && !funcparams.arguments->next->next) { TYPE *from = funcparams.arguments->tp; TYPE *to = funcparams.arguments->next->tp; if (isref(from) && isref(to)) { if (basetype(to)->type == bt_lref) { if (basetype(from)->type == bt_rref) rv = FALSE; } } else if (isref(from)) rv = FALSE; if (isfunction(from)) from = basetype(from)->btp; if (rv) { while (isref(from)) from = basetype(from)->btp; while (isref(to)) to = basetype(to)->btp; rv = comparetypes(to, from, FALSE); if (!rv && isstructured(from) && isstructured(to)) { if (classRefCount(basetype(to)->sp, basetype(from)->sp) == 1) rv = TRUE; } if (!rv && isstructured(from)) { SYMBOL *sp = search("$bcall", basetype(from)->syms); if (sp) { HASHREC *hr = sp->tp->syms->table[0]; while (hr) { if (comparetypes(basetype(((SYMBOL *)hr->p)->tp)->btp, to, FALSE)) { rv= TRUE; break; } hr = hr->next; } } } } } else { rv = FALSE; } *exp = intNode(en_c_i, rv); *tp = &stdint; return TRUE; }
static BOOLEAN is_constructible(LEXEME **lex, SYMBOL *funcsp, SYMBOL *sym, TYPE **tp, EXPRESSION **exp) { INITLIST *lst; BOOLEAN rv = FALSE; FUNCTIONCALL funcparams; memset(&funcparams, 0, sizeof(funcparams)); funcparams.sp = sym; *lex = getTypeList(*lex, funcsp, &funcparams.arguments); lst = funcparams.arguments; while (lst) { lst->tp = PerformDeferredInitialization(lst->tp, NULL); lst = lst->next; } if (funcparams.arguments) { TYPE *tp2 = funcparams.arguments->tp; if (isarray(tp2)) { while (isarray(tp2) && tp2->size != 0) tp2 = tp2->btp; if (isarray(tp2)) { tp2 = FALSE; } } if (tp2) { if (isarithmetic(tp2) || ispointer(tp2) || basetype(tp2)->type == bt_enum) { if (!funcparams.arguments->next) { rv = TRUE; } else if (!funcparams.arguments->next->next) { rv = comparetypes(tp2, funcparams.arguments->next->tp, TRUE); } } else if (isref(tp2)) { if (funcparams.arguments->next && !funcparams.arguments->next->next) { rv = comparetypes(tp2, funcparams.arguments->next->tp, TRUE); } } else if (isstructured(tp2)) { TYPE *ctp = tp2; EXPRESSION *cexp = NULL; SYMBOL *cons = search(overloadNameTab[CI_CONSTRUCTOR], basetype(tp2)->syms); funcparams.thisptr = intNode(en_c_i, 0); funcparams.thistp = Alloc(sizeof(TYPE)); funcparams.thistp->type = bt_pointer; funcparams.thistp->btp = basetype(tp2); funcparams.thistp->size = getSize(bt_pointer); funcparams.ascall = TRUE; funcparams.arguments = funcparams.arguments->next; rv = GetOverloadedFunction(tp, &funcparams.fcall, cons, &funcparams, NULL, FALSE, FALSE, FALSE, _F_SIZEOF) != NULL; } } } *exp = intNode(en_c_i, rv); *tp = &stdint; return TRUE; }