comparison mc-parse.c @ 487:b4d9809d6ee2

type attribute (half done)
author kono
date Fri, 16 Dec 2005 20:27:34 +0900
parents 33735a212eff
children 62f3c801b6ac
comparison
equal deleted inserted replaced
486:66d4b78f6219 487:b4d9809d6ee2
950 } 950 }
951 if(mode==LDECL) return 0; // not a type 951 if(mode==LDECL) return 0; // not a type
952 t= INT; // empty typespec 952 t= INT; // empty typespec
953 } 953 }
954 qualifiers(); 954 qualifiers();
955 if (ctmode) {
956 t = set_type_attr(t,ctmode);
957 }
955 return t; 958 return t;
956 } 959 }
957 960
958 /* 961 /*
959 indirect * 962 indirect *
1182 */ 1185 */
1183 1186
1184 extern int 1187 extern int
1185 size(int t) 1188 size(int t)
1186 { 1189 {
1190 t = type_value(t);
1187 if (t<0) { 1191 if (t<0) {
1188 switch(t) { 1192 switch(t) {
1189 case CHAR: return 1; 1193 case CHAR: return 1;
1190 case UCHAR: return 1; 1194 case UCHAR: return 1;
1191 case VOID: return 1; /* not 0 */ 1195 case VOID: return 1; /* not 0 */
1365 */ 1369 */
1366 1370
1367 static int 1371 static int
1368 decl_data(int t, NMTBL *n,int offset,int skip) 1372 decl_data(int t, NMTBL *n,int offset,int skip)
1369 { 1373 {
1370 int t1,e,i,mode_save; 1374 int t0,t1,e,i,mode_save;
1371 1375
1372 conv->decl_data_(); 1376 conv->decl_data_();
1377 t0 = type_value(t);
1373 mode_save = mode; 1378 mode_save = mode;
1374 mode=STAT; 1379 mode=STAT;
1375 if (offset==0) { 1380 if (offset==0) {
1376 if (n->sc==GVAR && n->dsp==-1) { 1381 if (n->sc==GVAR && n->dsp==-1) {
1377 /* duplicate initialization */ 1382 /* duplicate initialization */
1393 if(car(e)!=CONST && t==CHAR) 1398 if(car(e)!=CONST && t==CHAR)
1394 error(TYERR); 1399 error(TYERR);
1395 offset = assign_data(e,t,n,offset); 1400 offset = assign_data(e,t,n,offset);
1396 type=t; 1401 type=t;
1397 return offset; 1402 return offset;
1398 } else if (t==FLOAT||t==DOUBLE||t==LONGLONG||t==ULONGLONG) { 1403 } else if (t0==FLOAT||t0==DOUBLE||t0==LONGLONG||t0==ULONGLONG) {
1399 e=expr1(); 1404 e=expr1();
1400 mode = mode_save; 1405 mode = mode_save;
1401 offset = assign_data(e,t,n,offset); 1406 offset = assign_data(e,t,n,offset);
1402 type=t; 1407 type=t;
1403 return offset; 1408 return offset;
1404 } else if ((t1 = car(t)) && t1==ARRAY) { 1409 } else if ((t1 = car(t0)) && t1==ARRAY) {
1405 if (sym==LC) { 1410 if (sym==LC) {
1406 conv->decl_data_begin_(); 1411 conv->decl_data_begin_();
1407 mode = mode_save; 1412 mode = mode_save;
1408 t1 = cadr(t); 1413 t1 = cadr(t);
1409 for(i=0;;i++) { 1414 for(i=0;;i++) {
1426 getsym(0); 1431 getsym(0);
1427 return offset; 1432 return offset;
1428 } 1433 }
1429 } 1434 }
1430 /* NOT REACHED */ 1435 /* NOT REACHED */
1431 } else if (cadr(t)==CHAR) { 1436 } else if (cadr(t0)==CHAR) {
1432 e=expr1(); 1437 e=expr1();
1433 mode = mode_save; 1438 mode = mode_save;
1434 if(car(e)!=STRING) 1439 if(car(e)!=STRING)
1435 error(TYERR); 1440 error(TYERR);
1436 offset=assign_data(e,list3(ARRAY,CHAR,size(type)),n,offset); 1441 offset=assign_data(e,list3(ARRAY,CHAR,size(type)),n,offset);
1437 if (caddr(t)==0) { /* size not defined */ 1442 if (caddr(t0)==0) { /* size not defined */
1438 caddr(t)=size(type); /* define array size */ 1443 caddr(t0)=size(type); /* define array size */
1439 } else if (caddr(t)!=size(type)) { /* size match? */ 1444 } else if (caddr(t0)!=size(type)) { /* size match? */
1440 error(TYERR); 1445 error(TYERR);
1441 } 1446 }
1442 return offset; /* not reached */ 1447 return offset; /* not reached */
1443 } 1448 }
1444 } else if (t1==BIT_FIELD) { 1449 } else if (t1==BIT_FIELD) {
4649 fprintf(stderr,"nptr->dsp %d ",n->dsp); 4654 fprintf(stderr,"nptr->dsp %d ",n->dsp);
4650 fprintf(stderr,"nptr->ty %d ",n->ty); 4655 fprintf(stderr,"nptr->ty %d ",n->ty);
4651 fprintf(stderr,"nptr->nm %s\n",n->nm); 4656 fprintf(stderr,"nptr->nm %s\n",n->nm);
4652 } 4657 }
4653 4658
4659 extern int
4660 set_type_attr(int type,int attr)
4661 {
4662 if (type>0 && car(type)==ATTRIBUTE) {
4663 caddr(type) = attr;
4664 } else {
4665 type = list3(ATTRIBUTE,type,attr);
4666 }
4667 return type;
4668 }
4669
4670 extern int
4671 get_type_attr(int type)
4672 {
4673 if (type>0 && car(type)==ATTRIBUTE) {
4674 return caddr(type);
4675 } else {
4676 return 0;
4677 }
4678 }
4679
4680 extern int
4681 type_value(int type)
4682 {
4683 if (type>0 && car(type)==ATTRIBUTE) {
4684 return cadr(type);
4685 } else {
4686 return type;
4687 }
4688 }
4689
4690 extern int
4691 set_type_with_attr(int type,int type_with_attr)
4692 {
4693 if (type_with_attr>0 && car(type_with_attr)==ATTRIBUTE) {
4694 return list3(ATTRIBUTE,type_value(type),get_type_attr(type_with_attr));
4695 } else {
4696 return type;
4697 }
4698 }
4699
4654 /* for gdb... */ 4700 /* for gdb... */
4655 4701
4656 extern int c0(int d) { fprintf(stderr,"heap[%d]=",d);return car(d); } 4702 extern int c0(int d) { fprintf(stderr,"heap[%d]=",d);return car(d); }
4657 extern int c1(int d) { fprintf(stderr,"heap[%d]=",d);return cadr(d); } 4703 extern int c1(int d) { fprintf(stderr,"heap[%d]=",d);return cadr(d); }
4658 extern int c2(int d) { fprintf(stderr,"heap[%d]=",d);return caddr(d); } 4704 extern int c2(int d) { fprintf(stderr,"heap[%d]=",d);return caddr(d); }