* new int - int conversion -dNEWCNV

* some function renamings
This commit is contained in:
peter 1998-11-26 13:10:39 +00:00
parent 13d2cb30b0
commit a62eb86cde
5 changed files with 683 additions and 445 deletions

File diff suppressed because it is too large Load Diff

View File

@ -739,7 +739,7 @@ implementation
exprasmlist^.concat(new(pai386,op_reg(asmop,opsize,
p^.location.register)));
emitoverflowcheck(p);
emitrangecheck(p);
emitrangecheck(p,p^.resulttype);
end;
in_dec_x,
in_inc_x :
@ -843,7 +843,7 @@ implementation
ungetregister32(hregister);
end;
emitoverflowcheck(p^.left^.left);
emitrangecheck(p^.left^.left);
emitrangecheck(p^.left^.left,p^.left^.left^.resulttype);
end;
in_assigned_x :
begin
@ -970,7 +970,11 @@ implementation
end.
{
$Log$
Revision 1.18 1998-11-24 17:04:27 peter
Revision 1.19 1998-11-26 13:10:40 peter
* new int - int conversion -dNEWCNV
* some function renamings
Revision 1.18 1998/11/24 17:04:27 peter
* fixed length(char) when char is a variable
Revision 1.17 1998/11/05 12:02:33 peter

View File

@ -64,11 +64,26 @@ implementation
function isconvertable(def_from,def_to : pdef;
var doconv : tconverttype;fromtreetype : ttreetyp;
explicit : boolean) : boolean;
const
{$ifdef NEWCNV}
{ Tbasetype: uauto,uvoid,uchar,
u8bit,u16bit,u32bit,
s8bit,s16bit,s32,
bool8bit,bool16bit,boot32bit }
type
tbasedef=(bvoid,bchar,bint,bbool);
const
basedeftbl:array[tbasetype] of tbasedef =
(bvoid,bvoid,bchar,
bint,bint,bint,
bint,bint,bint,
bbool,bbool,bbool);
basedefconverts : array[tbasedef,tbasedef] of tconverttype =
((tc_not_possible,tc_not_possible,tc_not_possible,tc_not_possible),
(tc_not_possible,tc_equal,tc_not_possible,tc_not_possible),
(tc_not_possible,tc_not_possible,tc_int_2_int,tc_int_2_bool),
(tc_not_possible,tc_not_possible,tc_bool_2_int,tc_int_2_bool));
{$else}
const
basedefconverts : array[tbasetype,tbasetype] of tconverttype =
{uauto}
((tc_not_possible,tc_not_possible,tc_not_possible,
@ -130,6 +145,7 @@ implementation
tc_bool_2_int,tc_bool_2_int,tc_bool_2_int,
tc_bool_2_int,tc_bool_2_int,tc_bool_2_int,
tc_int_2_bool,tc_int_2_bool,tc_only_rangechecks32bit));
{$endif}
var
b : boolean;
@ -148,30 +164,49 @@ implementation
case def_to^.deftype of
orddef :
begin
if (def_from^.deftype=orddef) then
begin
doconv:=basedefconverts[porddef(def_from)^.typ,porddef(def_to)^.typ];
b:=true;
if (doconv=tc_not_possible) or
((doconv=tc_int_2_bool) and
(not explicit) and
(not is_boolean(def_from))) then
b:=false;
end;
case def_from^.deftype of
orddef :
begin
{$ifdef NEWCNV}
doconv:=basedefconverts[basedeftbl[porddef(def_from)^.typ],basedeftbl[porddef(def_to)^.typ]];
b:=true;
if (doconv=tc_not_possible) or
((doconv=tc_int_2_bool) and
(not explicit) and
(not is_boolean(def_from))) then
b:=false;
{$else}
doconv:=basedefconverts[porddef(def_from)^.typ,porddef(def_to)^.typ];
b:=true;
if (doconv=tc_not_possible) or
((doconv=tc_int_2_bool) and
(not explicit) and
(not is_boolean(def_from))) then
b:=false;
{$endif}
end;
{$ifdef NEWCNV}
enumdef :
begin
doconv:=tc_int_2_int;
b:=true;
end;
{$endif}
end;
end;
stringdef :
begin
case def_from^.deftype of
stringdef : begin
doconv:=tc_string_to_string;
doconv:=tc_string_2_string;
b:=true;
end;
orddef : begin
{ char to string}
if is_char(def_from) then
begin
doconv:=tc_char_to_string;
doconv:=tc_char_2_string;
b:=true;
end;
end;
@ -261,7 +296,7 @@ implementation
if (parraydef(def_to)^.lowrange=0) and
is_equal(ppointerdef(def_from)^.definition,parraydef(def_to)^.definition) then
begin
doconv:=tc_pointer_to_array;
doconv:=tc_pointer_2_array;
b:=true;
end;
end;
@ -269,7 +304,7 @@ implementation
{ array of char to string }
if is_equal(parraydef(def_to)^.definition,cchardef) then
begin
doconv:=tc_string_chararray;
doconv:=tc_string_2_chararray;
b:=true;
end;
end;
@ -285,16 +320,16 @@ implementation
if (fromtreetype=stringconstn) and
is_pchar(def_to) then
begin
doconv:=tc_cstring_charpointer;
doconv:=tc_cstring_2_pchar;
b:=true;
end;
end;
orddef : begin
{ char constant to zero terminated string constant }
if (fromtreetype=ordconstn) and is_equal(def_from,cchardef) and
is_pchar(def_to) then
is_pchar(def_to) then
begin
doconv:=tc_cchar_charpointer;
doconv:=tc_cchar_2_pchar;
b:=true;
end;
end;
@ -303,7 +338,7 @@ implementation
if (parraydef(def_from)^.lowrange=0) and
is_equal(parraydef(def_from)^.definition,ppointerdef(def_to)^.definition) then
begin
doconv:=tc_array_to_pointer;
doconv:=tc_array_2_pointer;
b:=true;
end;
end;
@ -370,7 +405,7 @@ implementation
if (def_from^.deftype=procdef) then
begin
def_from^.deftype:=procvardef;
doconv:=tc_proc2procvar;
doconv:=tc_proc_2_procvar;
b:=is_equal(def_from,def_to);
def_from^.deftype:=procdef;
end
@ -675,7 +710,11 @@ implementation
end.
{
$Log$
Revision 1.8 1998-11-17 00:36:42 peter
Revision 1.9 1998-11-26 13:10:42 peter
* new int - int conversion -dNEWCNV
* some function renamings
Revision 1.8 1998/11/17 00:36:42 peter
* more ansistring fixes
Revision 1.7 1998/10/14 13:33:24 peter

View File

@ -234,30 +234,43 @@ implementation
type
tfirstconvproc = procedure(var p : ptree);
{$ifdef NEWCNV}
procedure first_int_to_int(var p : ptree);
begin
if (p^.registers32=0) and
(p^.left^.location.loc<>LOC_REGISTER) and
(p^.resulttype^.size>p^.left^.resulttype^.size) then
begin
p^.registers32:=1;
p^.location.loc:=LOC_REGISTER;
end;
end;
{$else}
procedure first_bigger_smaller(var p : ptree);
begin
if (p^.left^.location.loc<>LOC_REGISTER) and (p^.registers32=0) then
p^.registers32:=1;
p^.location.loc:=LOC_REGISTER;
end;
{$endif}
procedure first_cstring_charpointer(var p : ptree);
procedure first_cstring_to_pchar(var p : ptree);
begin
p^.registers32:=1;
p^.location.loc:=LOC_REGISTER;
end;
procedure first_string_chararray(var p : ptree);
procedure first_string_to_chararray(var p : ptree);
begin
p^.registers32:=1;
p^.location.loc:=LOC_REGISTER;
end;
procedure first_string_string(var p : ptree);
procedure first_string_to_string(var p : ptree);
begin
if pstringdef(p^.resulttype)^.string_typ<>
pstringdef(p^.left^.resulttype)^.string_typ then
@ -309,7 +322,7 @@ implementation
end;
procedure first_int_real(var p : ptree);
procedure first_int_to_real(var p : ptree);
var
t : ptree;
begin
@ -338,7 +351,7 @@ implementation
end;
procedure first_int_fix(var p : ptree);
procedure first_int_to_fix(var p : ptree);
begin
if p^.left^.treetype=ordconstn then
begin
@ -358,7 +371,7 @@ implementation
end;
procedure first_real_fix(var p : ptree);
procedure first_real_to_fix(var p : ptree);
begin
if p^.left^.treetype=realconstn then
begin
@ -381,7 +394,7 @@ implementation
end;
procedure first_fix_real(var p : ptree);
procedure first_fix_to_real(var p : ptree);
begin
if p^.left^.treetype=fixconstn then
begin
@ -401,7 +414,7 @@ implementation
end;
procedure first_real_real(var p : ptree);
procedure first_real_to_real(var p : ptree);
begin
if p^.registersfpu<1 then
p^.registersfpu:=1;
@ -417,7 +430,7 @@ implementation
end;
procedure first_chararray_string(var p : ptree);
procedure first_chararray_to_string(var p : ptree);
begin
{ the only important information is the location of the }
{ result }
@ -426,7 +439,7 @@ implementation
end;
procedure first_cchar_charpointer(var p : ptree);
procedure first_cchar_to_pchar(var p : ptree);
begin
p^.left:=gentypeconvnode(p^.left,cshortstringdef);
{ convert constant char to constant string }
@ -436,13 +449,15 @@ implementation
end;
{$ifndef NEWCNV}
procedure first_locmem(var p : ptree);
begin
p^.location.loc:=LOC_MEM;
end;
{$endif}
procedure first_bool_int(var p : ptree);
procedure first_bool_to_int(var p : ptree);
begin
p^.location.loc:=LOC_REGISTER;
{ Florian I think this is overestimated
@ -456,7 +471,7 @@ implementation
end;
procedure first_int_bool(var p : ptree);
procedure first_int_to_bool(var p : ptree);
begin
p^.location.loc:=LOC_REGISTER;
{ Florian I think this is overestimated
@ -500,6 +515,7 @@ implementation
p^.location.loc:=LOC_MEM;
end;
procedure first_ansistring_to_pchar(var p : ptree);
begin
p^.location.loc:=LOC_REGISTER;
@ -529,13 +545,39 @@ implementation
aprocdef : pprocdef;
proctype : tdeftype;
const
firstconvert : array[tconverttype] of
tfirstconvproc = (first_nothing,first_nothing,
firstconvert : array[tconverttype] of tfirstconvproc = (
{$ifdef NEWCNV}
first_nothing, {equal}
first_nothing, {not_possible}
first_string_to_string,
first_char_to_string,
first_pchar_to_string,
first_cchar_to_pchar,
first_cstring_to_pchar,
first_ansistring_to_pchar,
first_string_to_chararray,
first_chararray_to_string,
first_array_to_pointer,
first_pointer_to_array,
first_int_to_int,
first_bool_to_int,
first_int_to_bool,
first_real_to_real,
first_int_to_real,
first_int_to_fix,
first_real_to_fix,
first_fix_to_real,
first_proc_to_procvar,
first_arrayconstructor_to_set,
first_load_smallset
);
{$else}
first_nothing,first_nothing,
first_bigger_smaller,first_nothing,first_bigger_smaller,
first_bigger_smaller,first_bigger_smaller,
first_bigger_smaller,first_bigger_smaller,
first_bigger_smaller,first_string_string,
first_cstring_charpointer,first_string_chararray,
first_bigger_smaller,first_string_to_string,
first_cstring_to_pchar,first_string_to_chararray,
first_array_to_pointer,first_pointer_to_array,
first_char_to_string,first_bigger_smaller,
first_bigger_smaller,first_bigger_smaller,
@ -547,16 +589,16 @@ implementation
first_bigger_smaller,first_bigger_smaller,
first_bigger_smaller,first_bigger_smaller,
first_bigger_smaller,first_bigger_smaller,
first_bool_int,first_int_bool,
first_int_real,first_real_fix,
first_fix_real,first_int_fix,first_real_real,
first_bool_to_int,first_int_to_bool,
first_int_to_real,first_real_to_fix,
first_fix_to_real,first_int_to_fix,first_real_to_real,
first_locmem,first_proc_to_procvar,
first_cchar_charpointer,
first_cchar_to_pchar,
first_load_smallset,
first_ansistring_to_pchar,
first_pchar_to_string,
first_arrayconstructor_to_set);
{$endif}
begin
aprocdef:=nil;
{ if explicite type cast, then run firstpass }
@ -689,7 +731,7 @@ implementation
aprocdef:=pprocsym(p^.left^.symtableentry)^.definition;
end;
p^.convtyp:=tc_proc2procvar;
p^.convtyp:=tc_proc_2_procvar;
{ Now check if the procedure we are going to assign to
the procvar, is compatible with the procvar's type.
Did the original procvar support do such a check?
@ -913,7 +955,11 @@ implementation
end.
{
$Log$
Revision 1.8 1998-11-05 12:03:03 peter
Revision 1.9 1998-11-26 13:10:43 peter
* new int - int conversion -dNEWCNV
* some function renamings
Revision 1.8 1998/11/05 12:03:03 peter
* released useansistring
* removed -Sv, its now available in fpc modes

View File

@ -45,96 +45,125 @@ unit tree;
pconstset = ^tconstset;
tconstset = array[0..31] of byte;
ttreetyp = (addn, {Represents the + operator.}
muln, {Represents the * operator.}
subn, {Represents the - operator.}
divn, {Represents the div operator.}
symdifn, {Represents the >< operator.}
modn, {Represents the mod operator.}
assignn, {Represents an assignment.}
loadn, {Represents the use of a variabele.}
rangen, {Represents a range (i.e. 0..9).}
ltn, {Represents the < operator.}
lten, {Represents the <= operator.}
gtn, {Represents the > operator.}
gten, {Represents the >= operator.}
equaln, {Represents the = operator.}
unequaln, {Represents the <> operator.}
inn, {Represents the in operator.}
orn, {Represents the or operator.}
xorn, {Represents the xor operator.}
shrn, {Represents the shr operator.}
shln, {Represents the shl operator.}
slashn, {Represents the / operator.}
andn, {Represents the and operator.}
subscriptn, {??? Field in a record/object?}
derefn, {Dereferences a pointer.}
addrn, {Represents the @ operator.}
doubleaddrn, {Represents the @@ operator.}
ordconstn, {Represents an ordinal value.}
typeconvn, {Represents type-conversion/typecast.}
calln, {Represents a call node.}
callparan, {Represents a parameter.}
realconstn, {Represents a real value.}
fixconstn, {Represents a fixed value.}
umminusn, {Represents a sign change (i.e. -2).}
asmn, {Represents an assembler node }
vecn, {Represents array indexing.}
stringconstn, {Represents a string constant.}
funcretn, {Represents the function result var.}
selfn, {Represents the self parameter.}
notn, {Represents the not operator.}
inlinen, {Internal procedures (i.e. writeln).}
niln, {Represents the nil pointer.}
errorn, {This part of the tree could not be
parsed because of a compiler error.}
typen, {A type name. Used for i.e. typeof(obj).}
hnewn, {The new operation, constructor call.}
hdisposen, {The dispose operation with destructor call.}
newn, {The new operation, constructor call.}
simpledisposen, {The dispose operation.}
setelementn, {A set element(s) (i.e. [a,b] and also [a..b]).}
setconstn, {A set constant (i.e. [1,2]).}
blockn, {A block of statements.}
statementn, {One statement in a block of nodes.}
loopn, { used in genloopnode, must be converted }
ifn, {An if statement.}
breakn, {A break statement.}
continuen, {A continue statement.}
repeatn, {A repeat until block.}
whilen, {A while do statement.}
forn, {A for loop.}
exitn, {An exit statement.}
withn, {A with statement.}
casen, {A case statement.}
labeln, {A label.}
goton, {A goto statement.}
simplenewn, {The new operation.}
tryexceptn, {A try except block.}
raisen, {A raise statement.}
switchesn, {??? Currently unused...}
tryfinallyn, {A try finally statement.}
onn, { for an on statement in exception code }
isn, {Represents the is operator.}
asn, {Represents the as typecast.}
caretn, {Represents the ^ operator.}
failn, {Represents the fail statement.}
starstarn, {Represents the ** operator exponentiation }
procinlinen, {Procedures that can be inlined }
arrayconstructn, {Construction node for [...] parsing}
arrayconstructrangen, {Range element to allow sets in array construction tree}
{ added for optimizations where we cannot suppress }
nothingn,
loadvmtn); {???.}
ttreetyp = (
addn, {Represents the + operator.}
muln, {Represents the * operator.}
subn, {Represents the - operator.}
divn, {Represents the div operator.}
symdifn, {Represents the >< operator.}
modn, {Represents the mod operator.}
assignn, {Represents an assignment.}
loadn, {Represents the use of a variabele.}
rangen, {Represents a range (i.e. 0..9).}
ltn, {Represents the < operator.}
lten, {Represents the <= operator.}
gtn, {Represents the > operator.}
gten, {Represents the >= operator.}
equaln, {Represents the = operator.}
unequaln, {Represents the <> operator.}
inn, {Represents the in operator.}
orn, {Represents the or operator.}
xorn, {Represents the xor operator.}
shrn, {Represents the shr operator.}
shln, {Represents the shl operator.}
slashn, {Represents the / operator.}
andn, {Represents the and operator.}
subscriptn, {??? Field in a record/object?}
derefn, {Dereferences a pointer.}
addrn, {Represents the @ operator.}
doubleaddrn, {Represents the @@ operator.}
ordconstn, {Represents an ordinal value.}
typeconvn, {Represents type-conversion/typecast.}
calln, {Represents a call node.}
callparan, {Represents a parameter.}
realconstn, {Represents a real value.}
fixconstn, {Represents a fixed value.}
umminusn, {Represents a sign change (i.e. -2).}
asmn, {Represents an assembler node }
vecn, {Represents array indexing.}
stringconstn, {Represents a string constant.}
funcretn, {Represents the function result var.}
selfn, {Represents the self parameter.}
notn, {Represents the not operator.}
inlinen, {Internal procedures (i.e. writeln).}
niln, {Represents the nil pointer.}
errorn, {This part of the tree could not be
parsed because of a compiler error.}
typen, {A type name. Used for i.e. typeof(obj).}
hnewn, {The new operation, constructor call.}
hdisposen, {The dispose operation with destructor call.}
newn, {The new operation, constructor call.}
simpledisposen, {The dispose operation.}
setelementn, {A set element(s) (i.e. [a,b] and also [a..b]).}
setconstn, {A set constant (i.e. [1,2]).}
blockn, {A block of statements.}
statementn, {One statement in a block of nodes.}
loopn, { used in genloopnode, must be converted }
ifn, {An if statement.}
breakn, {A break statement.}
continuen, {A continue statement.}
repeatn, {A repeat until block.}
whilen, {A while do statement.}
forn, {A for loop.}
exitn, {An exit statement.}
withn, {A with statement.}
casen, {A case statement.}
labeln, {A label.}
goton, {A goto statement.}
simplenewn, {The new operation.}
tryexceptn, {A try except block.}
raisen, {A raise statement.}
switchesn, {??? Currently unused...}
tryfinallyn, {A try finally statement.}
onn, { for an on statement in exception code }
isn, {Represents the is operator.}
asn, {Represents the as typecast.}
caretn, {Represents the ^ operator.}
failn, {Represents the fail statement.}
starstarn, {Represents the ** operator exponentiation }
procinlinen, {Procedures that can be inlined }
arrayconstructn, {Construction node for [...] parsing}
arrayconstructrangen, {Range element to allow sets in array construction tree}
{ added for optimizations where we cannot suppress }
nothingn,
loadvmtn
);
{$ifdef NEWCNV}
tconverttype = (
tc_equal,
tc_not_possible,
tc_string_2_string,
tc_char_2_string,
tc_pchar_2_string,
tc_cchar_2_pchar,
tc_cstring_2_pchar,
tc_ansistring_2_pchar,
tc_string_2_chararray,
tc_chararray_2_string,
tc_array_2_pointer,
tc_pointer_2_array,
tc_int_2_int,
tc_bool_2_int,
tc_int_2_bool,
tc_real_2_real,
tc_int_2_real,
tc_int_2_fix,
tc_real_2_fix,
tc_fix_2_real,
tc_proc_2_procvar,
tc_arrayconstructor_2_set,
tc_load_smallset
);
{$else}
tconverttype = (tc_equal,tc_not_possible,tc_u8bit_2_s32bit,
tc_only_rangechecks32bit,tc_s8bit_2_s32bit,
tc_u16bit_2_s32bit,tc_s16bit_2_s32bit,
tc_s32bit_2_s16bit,tc_s32bit_2_u8bit,
tc_s32bit_2_u16bit,tc_string_to_string,
tc_cstring_charpointer,tc_string_chararray,
tc_array_to_pointer,tc_pointer_to_array,
tc_char_to_string,tc_u8bit_2_s16bit,
tc_s32bit_2_u16bit,tc_string_2_string,
tc_cstring_2_pchar,tc_string_2_chararray,
tc_array_2_pointer,tc_pointer_2_array,
tc_char_2_string,tc_u8bit_2_s16bit,
tc_u8bit_2_u16bit,tc_s8bit_2_s16bit,
tc_s16bit_2_s8bit,tc_s16bit_2_u8bit,
tc_u16bit_2_s8bit,tc_u16bit_2_u8bit,
@ -148,9 +177,10 @@ unit tree;
tc_int_2_real,tc_real_2_fix,
tc_fix_2_real,tc_int_2_fix,tc_real_2_real,
tc_chararray_2_string,
tc_proc2procvar,tc_cchar_charpointer,tc_load_smallset,
tc_proc_2_procvar,tc_cchar_2_pchar,tc_load_smallset,
tc_ansistring_2_pchar,tc_pchar_2_string,
tc_arrayconstructor_2_set);
{$endif}
{ allows to determine which elementes are to be replaced }
tdisposetyp = (dt_nothing,dt_leftright,dt_left,
@ -1622,7 +1652,11 @@ unit tree;
end.
{
$Log$
Revision 1.53 1998-11-24 12:52:42 peter
Revision 1.54 1998-11-26 13:10:44 peter
* new int - int conversion -dNEWCNV
* some function renamings
Revision 1.53 1998/11/24 12:52:42 peter
* sets are not written twice anymore
* optimize for emptyset+single element which uses a new routine from
set.inc FPC_SET_CREATE_ELEMENT