Mercurial > hg > CbC > old > device
comparison mc-parse.c @ 203:28baf6cd9ad1
*** empty log message ***
author | kono |
---|---|
date | Tue, 13 Apr 2004 10:28:21 +0900 |
parents | 601301152d9c |
children | 4c614334f3d0 |
comparison
equal
deleted
inserted
replaced
202:601301152d9c | 203:28baf6cd9ad1 |
---|---|
1 /* Micro-C Parser Part */ | 1 /* Micro-C Parser Part */ /* $Id$ */ |
2 /* $Id$ */ | |
3 | 2 |
4 #define EXTERN /**/ | 3 #define EXTERN /**/ |
5 #include "mc.h" | 4 #include "mc.h" |
6 #include "mc-codegen.h" | 5 #include "mc-codegen.h" |
7 | 6 |
630 | 629 |
631 static NMTBL * | 630 static NMTBL * |
632 decl1(void) | 631 decl1(void) |
633 { | 632 { |
634 NMTBL *n; | 633 NMTBL *n; |
635 int i,t; | 634 int i,array_type,arg; |
636 | 635 |
637 if(sym==LPAR) { | 636 if(sym==LPAR) { |
638 getsym(0); | 637 getsym(0); |
639 n=decl0(); | 638 n=decl0(); |
640 checksym(RPAR); | 639 checksym(RPAR); |
655 type=list3(ARRAY,type,0); | 654 type=list3(ARRAY,type,0); |
656 } else { | 655 } else { |
657 error(DCERR); | 656 error(DCERR); |
658 } | 657 } |
659 } else { | 658 } else { |
660 t=type; | 659 array_type=type; |
661 i=cexpr(expr(1)); | 660 i=cexpr(expr(1)); |
662 checksym(RBRA); | 661 checksym(RBRA); |
663 type=list3(ARRAY,t,i); | 662 type=list3(ARRAY,array_type,i); |
664 } | 663 } |
665 } else if(sym==LPAR) { /* function or code segment */ | 664 } else if(sym==LPAR) { /* function or code segment */ |
666 if(mode==GDECL) { | 665 if(mode==GDECL) { |
667 mode=ADECL;getsym(0);mode=GDECL; /* ??? */ | 666 mode=ADECL;getsym(0);mode=GDECL; /* ??? */ |
668 } else | 667 } else |
671 if(stmode==EXTRN) n->sc=EXTRN; | 670 if(stmode==EXTRN) n->sc=EXTRN; |
672 else if(stmode==STATIC) n->sc=STATIC; | 671 else if(stmode==STATIC) n->sc=STATIC; |
673 if (type==CODE) { | 672 if (type==CODE) { |
674 n->ty=CODE; | 673 n->ty=CODE; |
675 if(sym==RPAR) { | 674 if(sym==RPAR) { |
676 getsym(0);t=0; | 675 getsym(0);arg=0; |
677 } else { | 676 } else { |
678 t=adecl(n); | 677 arg=adecl(n); |
679 } | 678 } |
680 type=glist3(CODE,CODE,t); | 679 type=glist3(CODE,CODE,arg); |
681 } else { | 680 } else { |
682 if(sym==RPAR) { | 681 if(sym==RPAR) { |
683 getsym(0);t=0; | 682 getsym(0);arg=0; |
684 } else { | 683 } else { |
685 t=adecl(n); | 684 arg=adecl(n); |
686 } | 685 } |
687 type=glist3(FUNCTION,type,t); | 686 type=glist3(FUNCTION,type,arg); |
688 } | 687 } |
689 /* Do not set n->ty here. It could be K&R style arguments or | 688 /* Do not set n->ty here. It could be K&R style arguments or |
690 struct field names */ | 689 struct field names */ |
691 /* in GDECL n->dsp contains real parameter, if not, | 690 /* in GDECL n->dsp contains real parameter, if not, |
692 it contains arg type list. Real parameter list is compatible | 691 it contains arg type list. Real parameter list is compatible |
693 with arg type list. See def/ADECL */ | 692 with arg type list. See def/ADECL */ |
694 if (mode!=GDECL) | 693 if (mode!=GDECL) |
695 n->dsp=t; | 694 n->dsp=arg; |
696 } else | 695 } else |
697 return n; | 696 return n; |
698 } | 697 } |
699 /* NOT REACHED */ | 698 /* NOT REACHED */ |
700 } | 699 } |
1507 if ((sz=size(cadr(fntype)))==-1) error(TYERR); | 1506 if ((sz=size(cadr(fntype)))==-1) error(TYERR); |
1508 else { | 1507 else { |
1509 args = 0; | 1508 args = 0; |
1510 def(&str_ret); | 1509 def(&str_ret); |
1511 struct_return = list3(list2(LVAR,str_ret.dsp),sz,type); | 1510 struct_return = list3(list2(LVAR,str_ret.dsp),sz,type); |
1511 caddr(fnptr->ty) = glist2(POINTER,caddr(fnptr->ty)); | |
1512 } | 1512 } |
1513 type = type_save; | 1513 type = type_save; |
1514 mode = mode_save; | 1514 mode = mode_save; |
1515 } else { | 1515 } else { |
1516 struct_return = 0; | 1516 struct_return = 0; |
2698 static int | 2698 static int |
2699 fname(NMTBL *nptr) | 2699 fname(NMTBL *nptr) |
2700 { | 2700 { |
2701 int e1; | 2701 int e1; |
2702 e1=list2(FNAME,(int)nptr); | 2702 e1=list2(FNAME,(int)nptr); |
2703 // type=list3(FUNCTION,type,arg); | |
2703 type=list3(car(nptr->ty),cadr(nptr->ty),caddr(nptr->ty)); | 2704 type=list3(car(nptr->ty),cadr(nptr->ty),caddr(nptr->ty)); |
2704 getsym(0); | 2705 getsym(0); |
2705 extrn_use(nptr); | 2706 extrn_use(nptr); |
2706 return expr16(e1); | 2707 return expr16(e1); |
2707 } | 2708 } |
3259 static int | 3260 static int |
3260 binop(int op, int e1, int e2, int t1, int t2) | 3261 binop(int op, int e1, int e2, int t1, int t2) |
3261 { | 3262 { |
3262 int e=0; | 3263 int e=0; |
3263 | 3264 |
3265 if(t1>0&&car(t1)==POINTER) { e2= int_value(e2,t2); t2=INT; } | |
3266 else if(t2>0&&car(t2)==POINTER) { e1= int_value(e1,t1); t1=INT; } | |
3264 #if FLOAT_CODE | 3267 #if FLOAT_CODE |
3265 if(t1==DOUBLE||t2==DOUBLE) | 3268 if(t1==DOUBLE||t2==DOUBLE) |
3266 return dbinop(op,e1,e2,t1,t2); | 3269 return dbinop(op,e1,e2,t1,t2); |
3267 if(t1==FLOAT||t2==FLOAT) | 3270 if(t1==FLOAT||t2==FLOAT) |
3268 return fbinop(op,e1,e2,t1,t2); | 3271 return fbinop(op,e1,e2,t1,t2); |
3456 conv->funcall_(type); | 3459 conv->funcall_(type); |
3457 | 3460 |
3458 /* function argments */ | 3461 /* function argments */ |
3459 | 3462 |
3460 argtypes = caddr(type); | 3463 argtypes = caddr(type); |
3461 if (!integral(t=cadr(type))&& | 3464 if ((t=cadr(type))>=0 && (car(t)==STRUCT||car(t)==UNION)) { |
3462 !(t==FLOAT||t==DOUBLE) && | |
3463 !(t==LONGLONG||t==ULONGLONG) && | |
3464 (car(t)==STRUCT||car(t)==UNION)) { | |
3465 /* skip return struct pointer */ | 3465 /* skip return struct pointer */ |
3466 if (argtypes==0) error(-1); | 3466 if (argtypes==0) error(-1); |
3467 argtypes = cadr(argtypes); | 3467 argtypes = cadr(argtypes); |
3468 } | 3468 } |
3469 arglist=0; | 3469 arglist=0; |