compiler: add unary plus node, search for unary plus operator if a type cannot be handled by compiler, increase ppu version because of node types change

git-svn-id: trunk@16640 -
This commit is contained in:
paul 2010-12-26 12:19:28 +00:00
parent c0c7e40b65
commit ee6fe6c4f5
8 changed files with 86 additions and 5 deletions

View File

@ -341,7 +341,9 @@ implementation
result:=false;
case treetyp of
subn,
addn,
unaryminusn,
unaryplusn,
inlinen:
begin
{ only Inc, Dec inline functions are supported for now, so skip check inlinenumber }
@ -506,6 +508,8 @@ implementation
optoken:=_OP_NOT;
unaryminusn:
optoken:=_MINUS;
unaryplusn:
optoken:=_PLUS;
inlinen:
case inlinenumber of
in_inc_x:

View File

@ -67,6 +67,13 @@ interface
end;
tunaryminusnodeclass = class of tunaryminusnode;
tunaryplusnode = class(tunarynode)
constructor create(expr : tnode);virtual;
function pass_1 : tnode;override;
function pass_typecheck:tnode;override;
end;
tunaryplusnodeclass = class of tunaryplusnode;
tnotnode = class(tunarynode)
constructor create(expr : tnode);virtual;
function pass_1 : tnode;override;
@ -82,6 +89,7 @@ interface
cmoddivnode : tmoddivnodeclass = tmoddivnode;
cshlshrnode : tshlshrnodeclass = tshlshrnode;
cunaryminusnode : tunaryminusnodeclass = tunaryminusnode;
cunaryplusnode : tunaryplusnodeclass = tunaryplusnode;
cnotnode : tnotnodeclass = tnotnode;
implementation
@ -730,6 +738,73 @@ implementation
end;
end;
{****************************************************************************
TUNARYPLUSNODE
****************************************************************************}
constructor tunaryplusnode.create(expr: tnode);
begin
inherited create(unaryplusn,expr);
end;
function tunaryplusnode.pass_1: tnode;
begin
{ can never happen because all the conversions happen
in pass_typecheck }
internalerror(201012250);
end;
function tunaryplusnode.pass_typecheck: tnode;
var
t:tnode;
begin
result:=nil;
typecheckpass(left);
set_varstate(left,vs_read,[vsf_must_be_valid]);
if codegenerror then
exit;
if is_constintnode(left) or
is_constrealnode(left) or
(left.resultdef.typ=floatdef) or
is_currency(left.resultdef)
{$ifdef SUPPORT_MMX}
or ((cs_mmx in current_settings.localswitches) and
is_mmx_able_array(left.resultdef))
{$endif SUPPORT_MMX}
then
begin
result:=left;
left:=nil;
end
{$ifndef cpu64bitaddr}
else if is_64bit(left.resultdef) then
begin
inserttypeconv(left,s64inttype);
result:=left;
left:=nil;
end
{$endif not cpu64bitaddr}
else if (left.resultdef.typ=orddef) then
begin
inserttypeconv(left,sinttype);
result:=left;
left:=nil;
end
else
begin
{ allow operator overloading }
t:=self;
if isunaryoverloaded(t) then
begin
result:=t;
exit;
end;
CGMessage(type_e_mismatch);
end;
end;
{****************************************************************************
TNOTNODE

View File

@ -67,6 +67,7 @@ interface
callparan, {Represents a parameter}
realconstn, {Represents a real value}
unaryminusn, {Represents a sign change (i.e. -2)}
unaryplusn, {Represents a check for +Value}
asmn, {Represents an assembler node }
vecn, {Represents array indexing}
pointerconstn, {Represents a pointer constant}
@ -151,6 +152,7 @@ interface
'callparan',
'realconstn',
'unaryminusn',
'unaryplusn',
'asmn',
'vecn',
'pointerconstn',

View File

@ -105,6 +105,7 @@ implementation
'noth-callpar',{callparan}
'realconst', {realconstn}
'unaryminus', {unaryminusn}
'unaryplus', {unaryplusn}
'asm', {asmn}
'vecn', {vecn}
'pointerconst',{pointerconstn}

View File

@ -831,7 +831,7 @@ implementation
case lastidtoken of
_IMPLICIT:optoken:=_ASSIGNMENT;
_NEGATIVE:optoken:=_MINUS;
// _POSITIVE:optoken:=_PLUS;
_POSITIVE:optoken:=_PLUS;
_LOGICALNOT:optoken:=_OP_NOT;
_IN:optoken:=_OP_IN;
_EQUAL:optoken:=_EQ;

View File

@ -2660,9 +2660,7 @@ implementation
begin
consume(_PLUS);
p1:=factor(false,false);
{ we must generate a new node to do 0+<p1> otherwise the + will
not be checked }
p1:=caddnode.create(addn,genintconstnode(0),p1);
p1:=cunaryplusnode.create(p1);
end;
_MINUS :

View File

@ -43,7 +43,7 @@ type
{$endif Test_Double_checksum}
const
CurrentPPUVersion = 123;
CurrentPPUVersion = 124;
{ buffer sizes }
maxentrysize = 1024;

View File

@ -506,6 +506,7 @@ implementation
nodeclass[callparan]:=ccallparanode;
nodeclass[realconstn]:=crealconstnode;
nodeclass[unaryminusn]:=cunaryminusnode;
nodeclass[unaryplusn]:=cunaryplusnode;
nodeclass[asmn]:=casmnode;
nodeclass[vecn]:=cvecnode;
nodeclass[pointerconstn]:=cpointerconstnode;