From ee6fe6c4f5b2482660eba3bd2922312b81dd0938 Mon Sep 17 00:00:00 2001 From: paul Date: Sun, 26 Dec 2010 12:19:28 +0000 Subject: [PATCH] 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 - --- compiler/htypechk.pas | 4 +++ compiler/nmat.pas | 75 +++++++++++++++++++++++++++++++++++++++++++ compiler/node.pas | 2 ++ compiler/pass_2.pas | 1 + compiler/pdecsub.pas | 2 +- compiler/pexpr.pas | 4 +-- compiler/ppu.pas | 2 +- compiler/psystem.pas | 1 + 8 files changed, 86 insertions(+), 5 deletions(-) diff --git a/compiler/htypechk.pas b/compiler/htypechk.pas index 94415c41c8..89b3957b29 100644 --- a/compiler/htypechk.pas +++ b/compiler/htypechk.pas @@ -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: diff --git a/compiler/nmat.pas b/compiler/nmat.pas index d3b01bf91f..d32049a223 100644 --- a/compiler/nmat.pas +++ b/compiler/nmat.pas @@ -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 diff --git a/compiler/node.pas b/compiler/node.pas index 75e5da7dfc..7ca37dcc54 100644 --- a/compiler/node.pas +++ b/compiler/node.pas @@ -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', diff --git a/compiler/pass_2.pas b/compiler/pass_2.pas index 055361b194..a20cb7d744 100644 --- a/compiler/pass_2.pas +++ b/compiler/pass_2.pas @@ -105,6 +105,7 @@ implementation 'noth-callpar',{callparan} 'realconst', {realconstn} 'unaryminus', {unaryminusn} + 'unaryplus', {unaryplusn} 'asm', {asmn} 'vecn', {vecn} 'pointerconst',{pointerconstn} diff --git a/compiler/pdecsub.pas b/compiler/pdecsub.pas index 659bc1f4eb..19a988040d 100644 --- a/compiler/pdecsub.pas +++ b/compiler/pdecsub.pas @@ -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; diff --git a/compiler/pexpr.pas b/compiler/pexpr.pas index 9b9818f457..b4e2e29d2e 100644 --- a/compiler/pexpr.pas +++ b/compiler/pexpr.pas @@ -2660,9 +2660,7 @@ implementation begin consume(_PLUS); p1:=factor(false,false); - { we must generate a new node to do 0+ otherwise the + will - not be checked } - p1:=caddnode.create(addn,genintconstnode(0),p1); + p1:=cunaryplusnode.create(p1); end; _MINUS : diff --git a/compiler/ppu.pas b/compiler/ppu.pas index 7343376145..fb32980614 100644 --- a/compiler/ppu.pas +++ b/compiler/ppu.pas @@ -43,7 +43,7 @@ type {$endif Test_Double_checksum} const - CurrentPPUVersion = 123; + CurrentPPUVersion = 124; { buffer sizes } maxentrysize = 1024; diff --git a/compiler/psystem.pas b/compiler/psystem.pas index 89907ba2da..f765d99695 100644 --- a/compiler/psystem.pas +++ b/compiler/psystem.pas @@ -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;