📄 expr.c
字号:
{
/* External non-function. These also get put in the symbol table so that
* we don't keep spitting errors out but also put an error out
*/
sp = makesym(sc_external);
sp->name = litlate(buf);
sp->tp = tp = maketype(bt_matchall, stdintsize);
*(sp->tp) = stdmatch;
sp->tp->sp = sp;
if (!cosym)
insert(sp, &lsyms);
*node = makenode(en_nacon, &undef, 0);
if (prm_cplusplus && override)
genclass2error(ERR_UNDEFINED, cobuf, buf);
else
gensymerror(ERR_UNDEFINED, buf);
tp = deref(node, tp);
/* now skip sub-pointers if it was an unknown struct ref */
if (tin)
{
while (lastst == pointsto || lastst == dot)
{
getsym();
getsym();
}
}
}
}
else
{
/* If we get here the symbol was already in the table
*/
foundsp:
if (prm_cplusplus && lastst == lt)
if (sp->tp->type == bt_struct || sp->tp->type == bt_class)
if (sp->istemplate)
{
sp = lookupTemplateType(sp,0);
if (lastst == classsel)
{
override = TRUE;
dclasssel = TRUE;
cosym = sp;
sp = 0;
goto docls;
}
}
if (prm_cplusplus && andtyp && andtyp->type == bt_memberptr &&
(andtyp->btp->type == bt_func || andtyp->btp->type == bt_ifunc))
{
tp1 = andtyp->btp;
*node = pnode = makenode(en_placeholder, (void*)sp, 0);
}
if (prm_cplusplus && andtyp && andtyp->type == bt_pointer &&
(andtyp->btp->type == bt_func || andtyp->btp->type == bt_ifunc))
{
tp1 = andtyp->btp;
*node = pnode = makeintnode(en_icon, 0);
}
if (prm_cplusplus && andtyp && andtyp->type == bt_farpointer &&
(andtyp->btp->type == bt_func || andtyp->btp->type == bt_ifunc))
{
tp1 = andtyp->btp;
*node = pnode = makeintnode(en_icon, 0);
}
if (sp->storage_class == sc_namespace)
{
gensymerror(ERR_ILLEGALNAMESPACEUSE, sp->name);
*node = makeintnode(en_icon, 0);
return &stdint;
}
sp->tp->uflags |= UF_USED;
if ((tp = sp->tp) == 0)
{
/* This lack of type info should never happen */
tp = &stdmatch;
*node = makenode(en_nacon, &undef, 0);
gensymerror(ERR_UNDEFINED, buf);
tp = deref(node, tp);
return tp; /* guard against untyped entries */
}
switch (sp->storage_class)
{
case sc_defunc:
if (!reclass && *node || declclass && sp->parentclass &&
declclass->mainsym == sp->parentclass->mainsym)
*node = makenode(en_thiscall, *node, 0);
else
*node = makenode(en_placeholder, sp, 0);
break;
case sc_static:
case sc_global:
case sc_external:
case sc_externalfunc:
case sc_abs:
if ((sp->tp->cflags &DF_CONST) && scalarnonfloat(sp->tp) && sp
->storage_class == sc_static)
{
if (sp->init)
*node = makeintnode(en_icon, sp->init->val.i);
else
*node = makeintnode(en_icon, 0);
return sp->tp;
}
else
{
sp->mainsym->extflag = TRUE;
if (sp->value.classdata.gdeclare)
sp->value.classdata.gdeclare->mainsym->extflag =
TRUE;
if (sp->absflag)
*node = makenode(en_absacon, sp, 0);
else
if (sp->tp->type == bt_func || sp->tp->type == bt_ifunc)
{
*node = makenode(en_napccon, sp, 0);
}
else
if (sp->staticlabel)
*node = makenode(en_nalabcon, sp, 0);
else
*node = makenode(en_nacon, sp, 0);
}
break;
case sc_const:
/* constants and enums */
*node = makeintnode(en_icon, sp->value.i);
if (prm_cplusplus)
return sp->tp;
else
return &stdint;
/* structure/class elements */
case sc_member:
if (sp->value.classdata.cppflags &PF_STATIC)
{
*node = makenode(en_nacon, sp, 0);
sp->mainsym->extflag = TRUE;
sp->value.classdata.gdeclare->mainsym->extflag = TRUE;
}
else
{
qnode = makeintnode(en_icon, sp->value.i + offset);
*node = makenode(en_addstruc, qnode, *node);
}
break;
default:
/* auto and any errors */
if ((sp->tp->cflags &DF_CONST) && sp->init && scalarnonfloat(sp
->tp) && sp->storage_class == sc_static)
{
*node = makeintnode(en_icon, sp->init->val.i);
return sp->tp;
}
else
{
SYM *sp1;
if (prm_cplusplus && isstructured(sp->tp) && lastst ==
openpa)
{
ENODE *ep2;
ENODE *epm = dummyvar(sp->tp->size, sp->tp, 0);
ENODE *epq;
TYP tp3, *tp2;
getsym();
tp3.lst.head = - 1;
tp3.lst.tail = - 1;
tp3.type = bt_func;
tp2 = gatherparms(&ep2, FALSE);
epq = do_destructor(epm->v.sp, &tp3, sp->tp, 0, 1, 0,
TRUE);
if (epq)
expr_rundown[expr_updowncount - 1] = makenode
(en_void, epq, expr_rundown[expr_updowncount -
1]);
epq = do_constructor(epm->v.sp, tp2, sp->tp, ep2, 1, 0,
FALSE, FALSE);
if (epq)
if (expr_runup[expr_updowncount - 1])
expr_runup[expr_updowncount - 1] = makenode
(en_void, expr_runup[expr_updowncount - 1],
epq);
else
expr_runup[expr_updowncount - 1] = epq;
*node = epm;
tp = sp->tp;
// needpunc(closepa, skm_declclosepa) ;
parm_ns_level--;
}
else if (sp->storage_class != sc_auto && sp->storage_class
!= sc_autoreg)
{
gensymerror(ERR_ILLCLASS2, sp->name);
tp = &stdint;
*node = makenode(en_nacon, &undef, 0);
}
else
{
/* auto variables */
if (sp->storage_class == sc_auto)
*node = makenode(en_autocon, sp, 0);
else if (sp->storage_class == sc_autoreg)
*node = makenode(en_autoreg, sp, 0);
}
}
break;
}
/* dereference if it isn't an array or structure address */
if (tp)
{
(*node)->cflags = tp->cflags;
/* deref if not an array or if is function parm */
if (sp->importable && tp->type != bt_func && tp->type != bt_ifunc)
{
*node = makenode(en_add, (void*) * node, makeintnode(en_icon, 2)
);
*node = makenode(en_a_ref, (void*) * node, 0);
*node = makenode(en_a_ref, (void*) * node, 0);
}
if (tp && (tp->val_flag == 0 || (tp->val_flag &VARARRAY) || (sp
->funcparm && (tp->type == bt_pointer || tp->type ==
bt_farpointer))) && (*node)->nodetype != en_icon)
/* and dereference it if it is an imported variable */
if (tp->type != bt_defunc)
tp = deref(node, tp);
/* and dereference again if it is a refernece variable */
if (tp->type == bt_ref)
{
//if (tp->btp->type == bt_pointer)
deref(node, tp->btp);
tp = tp->btp;
(*node)->cflags = tp->cflags;
}
}
if (sp->parentclass && !(sp->value.classdata.cppflags &PF_STATIC) &&
/*member && dclasssel && */((goodcode &GF_AND) || sp->tp->type ==
bt_defunc && lastst != openpa))
{
// if a func, ep1 will get overwritten later
if (sp->tp->type == bt_defunc)
{
TYP *tp1 = maketype(bt_memberptr, 0);
*node = makenode(en_placeholder, (void*)sp, 0);
tp1->btp = tp;
tp1->sp = sp->parentclass;
tp = tp1;
}
else if (asntyp)
{
TYP *tp1 = maketype(bt_memberptr, 0);
tp1->btp = tp;
tp1->sp = sp->parentclass;
tp = tp1;
cseg();
put_label(nextlabel);
genlong(sp->value.i + 1);
genlong(0);
nl();
*node = makeintnode(en_labcon, nextlabel++);
}
}
}
if (dclasssel && (!(goodcode &GF_AND) || tp->type != bt_memberptr) && sp
->storage_class != sc_defunc && sp->tp->type != bt_ifunc && sp->tp
->type != bt_func && (sp->value.classdata.cppflags &PF_MEMBER) && !(sp
->value.classdata.cppflags &PF_STATIC))
gensymerror(ERR_STATICNOACCESS, sp->name);
if (override)
(*node)->cflags |= DF_HASOVERRIDE;
if (tp->type == bt_fcomplex || tp->type == bt_rcomplex || tp->type == bt_lrcomplex)
{
if (*node)
if (stdpragmas &STD_PRAGMA_CXLIMITED)
(*node)->cflags |= DF_CXLIMITED;
}
lastsym = sp;
return tp;
}
//-------------------------------------------------------------------------
int cppcast(TYP *newtype, TYP *oldtype, ENODE **node, int alwayserr)
{
ENODE *pnode = *node, *qnode;
int rv = FALSE;
SYM *sp;
SYM *s1;
CLASSLIST *l;
if (oldtype->type == bt_void)
{
generror(ERR_NOVOID, 0, 0);
}
else if (newtype)
{
if (newtype->type == bt_pointer && oldtype->type == bt_pointer &&
isstructured(newtype->btp) && isstructured(oldtype->btp))
{
sp = newtype->btp->sp;
s1 = oldtype->btp->sp;
l = s1->value.classdata.baseclass;
while (l)
{
if (sp->mainsym == l->data->mainsym)
{
if (l->offset)
pnode = makenode(en_addcast, pnode, makeintnode(en_icon,
l->offset));
break;
}
l = l->link;
}
if (!l)
{
l = sp->value.classdata.baseclass;
while (l)
{
if (s1->mainsym == l->data->mainsym)
{
if (l->offset)
pnode = makenode(en_addcast, pnode, makeintnode
(en_icon, - l->offset));
break;
}
l = l->link;
}
}
if (l)
rv = TRUE;
else if (alwayserr)
genmismatcherror(oldtype, newtype);
}
else
if (isstructured(oldtype))
if (isstructured(newtype))
{
SYM *sp = newtype->sp;
SYM *s1 = oldtype->sp;
CLASSLIST *l = s1->value.classdata.baseclass;
while (l)
{
if (!strcmp(sp->name, l->data->name))
{
pnode = makenode(en_addstruc, pnode, makeintnode(en_icon, l
->offset));
break;
}
l = l->link;
}
}
else
{
SYM *sp = oldtype->sp;
sp = search("$casts$", &sp->tp->lst);
if (!sp)
genmismatcherror(oldtype, newtype);
else
{
sp = castmatch(oldtype->sp, newtype, &sp->tp->lst);
if (!sp)
genmismatcherror(oldtype, newtype);
else
{
ENODE *xnode;
CLASSLIST *l = oldtype->sp->value.classdata.baseclass;
if (!isaccessible(sp))
genclasserror(ERR_NOTACCESSIBLE, fullcppmangle(0, sp
->name, 0));
while (l)
{
if (!strcmp(sp->parentclass->name, l->data->name))
break;
l = l->link;
}
if (l && l->offset)
xnode = makenode(en_addstruc, pnode, makeintnode
(en_icon, l->offset));
else
xnode = pnode;
sp->mainsym->extflag = TRUE;
pnode = makenode(en_void, 0, 0);
qnode = makenode(en_napccon, sp, 0);
qnode = makenode(en_void, qnode, qnode);
pnode = makenode(en_void, qnode, pnode);
qnode = makeintnode(en_icon, retvalsize(sp->tp->btp));
if (isstructured(sp->tp->btp))
{
pnode = makenode(en_fcallb, qnode, pnode);
(pnode)->size = sp->tp->btp->size;
}
else
pnode = makenode(en_fcall, qnode, pnode);
pnode = makenode(en_thiscall, xnode, pnode);
pnode = doinline(pnode);
rv = TRUE;
}
}
}
else if (isstructured(newtype) || newtype->type == bt_pointer &&
isstructured(newtype->btp))
{
if (newtype->type == bt_pointer && scalarnonfloat(oldtype))
{
ENODE *epx = *node;
while (castvalue(epx))
epx = epx->v.p[0];
if (!isintconst(epx->nodetype) || epx->v.i != 0)
genmismatcherror(oldtype, newtype);
}
else
genmismatcherror(oldtype, newtype);
}
else if (newtype->type != oldtype->type && (newtype->type ==
bt_memberptr || oldtype->type == bt_memberptr))
{
rv = FALSE;
}
else if (newtype->type != bt_void && oldtype->type != bt_void)
rv = TRUE;
}
*node = pnode;
return rv;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -