32
32
if (lval->c_vtype) {
37
/* clear lval array - djm second arg was lval.. now cast, clears lval */
37
/* clear lval array - djm second arg was lval.. now cast, clears lval */
43
43
clevel=lval->castlevel;
44
44
memset(lval,0,sizeof(LVALUE));
50
50
lval->castlevel = clevel;
52
if ( symname(sname) ) {
53
if ( strcmp(sname, "sizeof") == 0 ) {
57
else if ( (ptr=findloc(sname)) && ptr->ident !=GOTOLABEL ) {
52
if ( symname(sname) ) {
53
if ( strcmp(sname, "sizeof") == 0 ) {
57
else if ( (ptr=findloc(sname)) && ptr->ident !=GOTOLABEL ) {
59
lval->offset=getloc(ptr, 0);
61
lval->val_type = lval->indirect = ptr->type;
62
lval->flags = ptr->flags;
63
lval->ident = ptr->ident;
59
lval->offset=getloc(ptr, 0);
61
lval->val_type = lval->indirect = ptr->type;
62
lval->flags = ptr->flags;
63
lval->ident = ptr->ident;
64
64
lval->storage = ptr->storage;
67
if ( ptr->type == STRUCT )
68
lval->tagsym = tagtab + ptr->tag_idx ;
69
if ( ptr->ident == POINTER ) {
70
lval->ptr_type = ptr->type;
67
if ( ptr->type == STRUCT )
68
lval->tagsym = tagtab + ptr->tag_idx ;
69
if ( ptr->ident == POINTER ) {
70
lval->ptr_type = ptr->type;
71
71
/* djm long pointers */
72
lval->indirect=lval->val_type = (ptr->flags&FARPTR ? CPTR : CINT);
75
if ( ptr->ident == ARRAY ||
76
(ptr->ident == VARIABLE && ptr->type == STRUCT) ) {
78
lval->ptr_type = ptr->type ;
79
lval->val_type = (ptr->flags&FARPTR ? CPTR : CINT );
72
lval->indirect=lval->val_type = (ptr->flags&FARPTR ? CPTR : CINT);
75
if ( ptr->ident == ARRAY ||
76
(ptr->ident == VARIABLE && ptr->type == STRUCT) ) {
78
lval->ptr_type = ptr->type ;
79
lval->val_type = (ptr->flags&FARPTR ? CPTR : CINT );
84
84
/* djm search for local statics */
86
if (!ptr) ptr=findglb(sname);
88
if ( ptr->ident != FUNCTION && ptr->ident !=FUNCTIONP ) {
89
if (ptr->ident==ENUM )
90
error(E_UNSYMB,sname);
91
if (ptr->type==ENUM) {
92
lval->symbol = NULL_SYM ;
95
lval->const_val=ptr->size;
97
lval->ident = VARIABLE;
102
lval->val_type = ptr->type ;
103
lval->flags = ptr->flags ;
104
lval->ident = ptr->ident;
86
if (!ptr) ptr=findglb(sname);
88
if ( ptr->ident != FUNCTION && ptr->ident !=FUNCTIONP ) {
89
if (ptr->ident==ENUM )
90
error(E_UNSYMB,sname);
91
if (ptr->type==ENUM) {
92
lval->symbol = NULL_SYM ;
95
lval->const_val=ptr->size;
97
lval->ident = VARIABLE;
102
lval->val_type = ptr->type ;
103
lval->flags = ptr->flags ;
104
lval->ident = ptr->ident;
106
106
lval->storage = ptr->storage;
108
if ( ptr->type == STRUCT )
109
lval->tagsym = tagtab + ptr->tag_idx ;
110
if ( ptr->ident != ARRAY &&
111
(ptr->ident != VARIABLE || ptr->type != STRUCT) ) {
112
if ( ptr->ident == POINTER ) {
113
lval->ptr_type = ptr->type;
114
lval->val_type = (ptr->flags&FARPTR ? CPTR : CINT);
115
ltype=lval->val_type;
108
if ( ptr->type == STRUCT )
109
lval->tagsym = tagtab + ptr->tag_idx ;
110
if ( ptr->ident != ARRAY &&
111
(ptr->ident != VARIABLE || ptr->type != STRUCT) ) {
112
if ( ptr->ident == POINTER ) {
113
lval->ptr_type = ptr->type;
114
lval->val_type = (ptr->flags&FARPTR ? CPTR : CINT);
115
ltype=lval->val_type;
119
119
/* Handle arrays... */
121
121
/* djm sommat here about pointer types? */
122
lval->indirect = lval->ptr_type = ptr->type ;
123
lval->val_type = (ptr->flags&FARPTR ? CPTR : CINT);
126
lval->ident=FUNCTION;
122
lval->indirect = lval->ptr_type = ptr->type ;
123
lval->val_type = (ptr->flags&FARPTR ? CPTR : CINT);
126
lval->ident=FUNCTION;
130
130
/* Check to see if we have a right bracket, if we don't assume
131
131
* it's a function then we can break an awful lot of code, do it
132
132
* this way and it's safer... we're not GNU after all!
135
warning(W_FUNC_NO_PROTO);
137
error(E_UNSYMB,sname);
135
warning(W_FUNC_NO_PROTO);
137
error(E_UNSYMB,sname);
139
/* assume it's a function we haven't seen yet */
140
/* NB value set to 0 */
141
ptr = addglb(sname,FUNCTION,CINT,0,STATIK,0,0);
143
ptr->prototyped=0; /* No parameters known */
144
ptr->args[0]=CalcArgValue(CINT, FUNCTION, 0);
148
lval->val_type = CINT ; /* Null function, always int */
149
lval->flags = 0 ; /* Assume signed, no far */
150
lval->ident=FUNCTION;
153
if ( constant(lval) ) {
154
lval->symbol = NULL_SYM ;
156
lval->ident = VARIABLE;
139
/* assume it's a function we haven't seen yet */
140
/* NB value set to 0 */
141
ptr = addglb(sname,FUNCTION,CINT,0,STATIK,0,0);
143
ptr->prototyped=0; /* No parameters known */
144
ptr->args[0]=CalcArgValue(CINT, FUNCTION, 0);
148
lval->val_type = CINT ; /* Null function, always int */
149
lval->flags = 0 ; /* Assume signed, no far */
150
lval->ident=FUNCTION;
153
if ( constant(lval) ) {
154
lval->symbol = NULL_SYM ;
156
lval->ident = VARIABLE;
240
240
void force(int t1, int t2,char sign1,char sign2,int lconst)
242
242
if ( t2 == CARRY ) {
249
DoDoubConv(t2,sign2);
249
DoDoubConv(t2,sign2);
259
259
/* t2 =source, t1=dest */
260
260
/* int to long, if signed, do sign, if not ld de,0 */
261
261
/* Check to see if constant or not... */
263
if (t2!=LONG && (!lconst)) {
264
if (sign2==NO && sign1==NO && t2 != CARRY) convSint2long();
265
else convUint2long();
263
if (t2!=LONG && (!lconst)) {
264
if (sign2==NO && sign1==NO && t2 != CARRY) convSint2long();
265
else convUint2long();
269
269
/* Converting long to int, not needed, if it don't fit tough!! */
271
271
/* Converting between pointer types..far and near */
272
if (t1==CPTR && t2==CINT) convUint2long();
273
else if (t2==CPTR && t1==CINT) warning(W_FARNR);
272
if (t1==CPTR && t2==CINT) convUint2long();
273
else if (t2==CPTR && t1==CINT) warning(W_FARNR);
275
275
/* Char conversion */
276
276
if ( t1 == CCHAR && sign2 == NO && !lconst) {
746
747
if (lval->level != lval->castlevel ) return 0;
749
if ( lval->c_id == VARIABLE ) {
750
if ( lval->c_id == VARIABLE ) {
751
752
* Straight forward variable conversion now..
753
if (df) force(lval->c_vtype,lval->val_type,lval->c_flags&UNSIGNED,lval->flags&UNSIGNED,0);
754
lval->val_type=lval->c_vtype;
756
lval->ident=VARIABLE;
757
lval->flags= ( (lval->flags&FARACC) | (lval->c_flags&UNSIGNED) );
754
if (df) force(lval->c_vtype,lval->val_type,lval->c_flags&UNSIGNED,lval->flags&UNSIGNED,0);
755
lval->val_type=lval->c_vtype;
757
lval->ident=VARIABLE;
758
lval->flags= ( (lval->flags&FARACC) | (lval->c_flags&UNSIGNED) );
758
759
lval->c_id=0; lval->c_vtype=0; lval->c_flags=0;
762
if ( lval->c_id == POINTER || lval->c_id==PTR_TO_FN ) {
763
switch(lval->c_vtype) {
764
if ( lval->c_id == POINTER || lval->c_id==PTR_TO_FN ) {
765
switch(lval->c_vtype) {
766
768
* Casting a structure - has to be a pointer...
768
lval->tagsym=lval->c_tag; /* Copy tag symbol over */
769
lval->ptr_type=STRUCT;
770
temp_type=( ( lval->c_flags&FARPTR ) ? CPTR : CINT );
771
if (df) force(temp_type,lval->val_type,0,0,0);
772
lval->val_type=temp_type;
773
lval->flags=( (lval->flags&FARACC) | lval->c_flags );
770
lval->tagsym=lval->c_tag; /* Copy tag symbol over */
771
lval->ptr_type=STRUCT;
772
temp_type=( ( lval->c_flags&FARPTR ) ? CPTR : CINT );
773
if (df) force(temp_type,lval->val_type,0,0,0);
774
lval->val_type=temp_type;
775
lval->flags=( (lval->flags&FARACC) | lval->c_flags );
774
776
if (df) {lval->c_id=0; lval->c_vtype=0; lval->c_flags=0;}
777
779
/* All other simple pointers.. */
779
debug(DBG_CAST2,"Converting %d to %d",lval->ptr_type,lval->c_vtype);
780
lval->ptr_type=lval->c_vtype;
781
lval->symbol=dummy_sym[(int)lval->c_vtype];
782
temp_type=( ( lval->c_flags&FARPTR ) ? CPTR : CINT );
783
if (df) force(temp_type,lval->val_type,0,0,0);
784
lval->val_type=temp_type;
785
lval->flags=( (lval->flags&FARACC) | lval->c_flags );
781
debug(DBG_CAST2,"Converting %d to %d",lval->ptr_type,lval->c_vtype);
782
lval->ptr_type=lval->c_vtype;
783
lval->symbol=dummy_sym[(int)lval->c_vtype];
784
temp_type=( ( lval->c_flags&FARPTR ) ? CPTR : CINT );
785
if (df) force(temp_type,lval->val_type,0,0,0);
786
lval->val_type=temp_type;
787
lval->flags=( (lval->flags&FARACC) | lval->c_flags );
787
789
if (df) {lval->c_id=0; lval->c_vtype=0; lval->c_flags=0; }
791
793
/* Now we deal with pointers to pointers and pointers to functions
792
794
* returning pointers - to do this, we will define dummy symbols in
793
795
* the local symbol table so that they do what we want them to do!
795
sprintf(nam,"0dptr%d",(int)locptr);
796
temp_type = ( (lval->c_flags&FARPTR) ? CPTR : CINT );
797
sprintf(nam,"0dptr%d",(int)locptr);
798
temp_type = ( (lval->c_flags&FARPTR) ? CPTR : CINT );
799
801
itag=lval->c_tag-tagtab;
800
802
ptr=lval->symbol;
801
lval->symbol = addloc(nam,POINTER,temp_type,dummy_idx(lval->c_vtype,lval->c_tag),itag);
803
lval->symbol = addloc(nam,POINTER,temp_type,dummy_idx(lval->c_vtype,lval->c_tag),itag);
802
804
lval->symbol->offset.p=ptr;
804
806
force(temp_type,lval->val_type,0,0,0);
805
lval->val_type=temp_type;
806
lval->flags=( (lval->flags&FARACC) | lval->c_flags );
807
lval->val_type=temp_type;
808
lval->flags=( (lval->flags&FARACC) | lval->c_flags );
808
810
lval->c_id=0; lval->c_vtype=0; lval->c_flags=0;