Line 212... |
Line 212... |
*/
|
*/
|
TYP *nameref(ENODE **node)
|
TYP *nameref(ENODE **node)
|
{
|
{
|
SYM *sp;
|
SYM *sp;
|
TYP *tp;
|
TYP *tp;
|
|
char stnm[200];
|
sp = gsearch(lastid);
|
sp = gsearch(lastid);
|
if( sp == NULL ) {
|
if( sp == NULL ) {
|
while( isspace(lastch) )
|
while( isspace(lastch) )
|
getch();
|
getch();
|
if( lastch == '(') {
|
if( lastch == '(') {
|
Line 240... |
Line 241... |
error(ERR_UNDEFINED);
|
error(ERR_UNDEFINED);
|
return NULL; /* guard against untyped entries */
|
return NULL; /* guard against untyped entries */
|
}
|
}
|
switch( sp->storage_class ) {
|
switch( sp->storage_class ) {
|
case sc_static:
|
case sc_static:
|
|
if (sp->tp->type==bt_func || sp->tp->type==bt_ifunc) {
|
|
strcpy(stnm,GetNamespace());
|
|
strcat(stnm,"_");
|
|
strcat(stnm,sp->name);
|
|
*node = makesnode(en_nacon,litlate(stnm));
|
|
(*node)->constflag = TRUE;
|
|
//*node = makesnode(en_nacon,sp->name);
|
|
//(*node)->constflag = TRUE;
|
|
}
|
|
else {
|
*node = makeinode(en_labcon,sp->value.i);
|
*node = makeinode(en_labcon,sp->value.i);
|
(*node)->constflag = TRUE;
|
(*node)->constflag = TRUE;
|
|
}
|
break;
|
break;
|
case sc_global:
|
case sc_global:
|
case sc_external:
|
case sc_external:
|
*node = makesnode(en_nacon,sp->name);
|
*node = makesnode(en_nacon,sp->name);
|
(*node)->constflag = TRUE;
|
(*node)->constflag = TRUE;
|
Line 325... |
Line 337... |
* primary->id
|
* primary->id
|
* primary( parameter list )
|
* primary( parameter list )
|
*/
|
*/
|
TYP *ParsePrimaryExpression(ENODE **node)
|
TYP *ParsePrimaryExpression(ENODE **node)
|
{
|
{
|
ENODE *pnode, *qnode, *rnode, *snode;
|
ENODE *pnode, *qnode, *rnode, *snode, *rnode1, *pnode1, *qnode1, *qnode2;
|
|
__int64 i ;
|
|
int sza[10];
|
|
int brcount;
|
SYM *sp;
|
SYM *sp;
|
TYP *tptr;
|
TYP *tptr;
|
|
brcount = 0;
|
|
qnode1 = NULL;
|
|
qnode2 = NULL;
|
switch( lastst ) {
|
switch( lastst ) {
|
|
|
case id:
|
case id:
|
tptr = nameref(&pnode);
|
tptr = nameref(&pnode);
|
break;
|
break;
|
Line 341... |
Line 359... |
pnode->constflag = TRUE;
|
pnode->constflag = TRUE;
|
NextToken();
|
NextToken();
|
break;
|
break;
|
case sconst:
|
case sconst:
|
tptr = &stdstring;
|
tptr = &stdstring;
|
pnode = makenode(en_labcon,stringlit(laststr),NULL);
|
pnode = makenodei(en_labcon,NULL,stringlit(laststr));
|
pnode->constflag = TRUE;
|
pnode->constflag = TRUE;
|
NextToken();
|
NextToken();
|
break;
|
break;
|
|
|
case openpa:
|
case openpa:
|
Line 370... |
Line 388... |
return NULL;
|
return NULL;
|
}
|
}
|
for(;;) {
|
for(;;) {
|
switch( lastst ) {
|
switch( lastst ) {
|
case openbr: /* build a subscript reference */
|
case openbr: /* build a subscript reference */
|
|
brcount++;
|
if (tptr==NULL) {
|
if (tptr==NULL) {
|
error(ERR_UNDEFINED);
|
error(ERR_UNDEFINED);
|
goto fini;
|
goto fini;
|
}
|
}
|
if( tptr->type != bt_pointer )
|
if( tptr->type != bt_pointer )
|
error(ERR_NOPOINTER);
|
error(ERR_NOPOINTER);
|
else
|
else
|
tptr = tptr->btp;
|
tptr = tptr->btp;
|
NextToken();
|
NextToken();
|
|
if (tptr->val_flag && (tptr->size==1 || tptr->size==2 || tptr->size==4 || tptr->size==8)) {
|
|
expression(&rnode);
|
|
pnode = makenode(en_add,rnode,pnode);
|
|
pnode->constflag = rnode->constflag && pnode->p[1]->constflag;
|
|
pnode->scale = tptr->size;
|
|
}
|
|
else {
|
|
sza[brcount-1] = tptr->size;
|
qnode = makeinode(en_icon,tptr->size);
|
qnode = makeinode(en_icon,tptr->size);
|
|
// swap sizes for array indexing
|
|
if (brcount==3) {
|
|
qnode->i = sza[0];
|
|
qnode2->i = sza[1];
|
|
qnode1->i = sza[2];
|
|
}
|
|
else if (brcount==2) {
|
|
qnode->i = sza[0];
|
|
qnode1->i = sza[1];
|
|
}
|
|
if (qnode1==NULL)
|
|
qnode1 = qnode;
|
|
else
|
|
qnode2 = qnode;
|
qnode->constflag = TRUE;
|
qnode->constflag = TRUE;
|
expression(&rnode);
|
expression(&rnode);
|
|
needpunc(closebr);
|
/*
|
/*
|
* we could check the type of the expression here...
|
* we could check the type of the expression here...
|
*/
|
*/
|
qnode = makenode(en_mulu,qnode,rnode);
|
qnode = makenode(en_mulu,qnode,rnode);
|
qnode->constflag = rnode->constflag && qnode->p[0]->constflag;
|
qnode->constflag = rnode->constflag && qnode->p[0]->constflag;
|
pnode = makenode(en_add,qnode,pnode);
|
pnode = makenode(en_add,qnode,pnode);
|
pnode->constflag = qnode->constflag && pnode->p[1]->constflag;
|
pnode->constflag = qnode->constflag && pnode->p[1]->constflag;
|
|
pnode->scale = 1;
|
|
//if( tptr->val_flag == 0 )
|
|
// tptr = deref(&pnode,tptr);
|
|
}
|
////snode = makenode(en_mul,qnode,rnode);
|
////snode = makenode(en_mul,qnode,rnode);
|
////snode->constflag = rnode->constflag && snode->p[0]->constflag;
|
////snode->constflag = rnode->constflag && snode->p[0]->constflag;
|
////pnode = makenode(en_add,snode,pnode);
|
////pnode = makenode(en_add,snode,pnode);
|
////pnode->constflag = snode->constflag && pnode->p[1]->constflag;
|
////pnode->constflag = snode->constflag && pnode->p[1]->constflag;
|
if( tptr->val_flag == FALSE )
|
if( tptr->val_flag == FALSE )
|
tptr = deref(&pnode,tptr);
|
tptr = deref(&pnode,tptr);
|
needpunc(closebr);
|
// needpunc(closebr);
|
break;
|
break;
|
|
|
case pointsto:
|
case pointsto:
|
if (tptr==NULL) {
|
if (tptr==NULL) {
|
error(ERR_UNDEFINED);
|
error(ERR_UNDEFINED);
|
Line 653... |
Line 699... |
if( tp->type == bt_pointer )
|
if( tp->type == bt_pointer )
|
i = tp->btp->size;
|
i = tp->btp->size;
|
else
|
else
|
i = 1;
|
i = 1;
|
if( lastst == autoinc) {
|
if( lastst == autoinc) {
|
if( IsLValue(ep1) )
|
if( IsLValue(ep1) ) {
|
ep1 = makenodei(en_ainc,ep1,i);
|
if (tp->type == bt_pointer)
|
|
ep2 = makeinode(en_icon,tp->btp->size);
|
|
else
|
|
ep2 = makeinode(en_icon,1);
|
|
ep2->constflag = TRUE;
|
|
ep1 = makenode(en_asadd,ep1,ep2);
|
|
// ep1 = makenodei(en_ainc,ep1,i);
|
|
}
|
else
|
else
|
error(ERR_LVALUE);
|
error(ERR_LVALUE);
|
NextToken();
|
NextToken();
|
}
|
}
|
else if( lastst == autodec ) {
|
else if( lastst == autodec ) {
|
if( IsLValue(ep1) )
|
if( IsLValue(ep1) ) {
|
ep1 = makenodei(en_adec,ep1,i);
|
if (tp->type == bt_pointer)
|
|
ep2 = makeinode(en_icon,tp->btp->size);
|
|
else
|
|
ep2 = makeinode(en_icon,1);
|
|
ep2->constflag = TRUE;
|
|
ep1 = makenode(en_assub,ep1,ep2);
|
|
// ep1 = makenodei(en_adec,ep1,i);
|
|
}
|
else
|
else
|
error(ERR_LVALUE);
|
error(ERR_LVALUE);
|
NextToken();
|
NextToken();
|
}
|
}
|
}
|
}
|