* ensure that the correct amount of parameters is used for an operator overload (this is essentially important for unary operators that were declared with two arguments)

git-svn-id: trunk@41868 -
This commit is contained in:
svenbarth 2019-04-14 20:47:43 +00:00
parent 349bb2ff38
commit c147debda1
5 changed files with 75 additions and 27 deletions

3
.gitattributes vendored
View File

@ -11161,6 +11161,9 @@ tests/tbf/tb0265.pp svneol=native#text/pascal
tests/tbf/tb0266a.pp svneol=native#text/pascal
tests/tbf/tb0266b.pp svneol=native#text/pascal
tests/tbf/tb0267.pp svneol=native#text/plain
tests/tbf/tb0268.pp svneol=native#text/pascal
tests/tbf/tb0269.pp svneol=native#text/pascal
tests/tbf/tb0270.pp svneol=native#text/pascal
tests/tbf/tb0588.pp svneol=native#text/pascal
tests/tbf/ub0115.pp svneol=native#text/plain
tests/tbf/ub0149.pp svneol=native#text/plain

View File

@ -37,6 +37,8 @@ interface
nod : tnodetype;
inr : tinlinenumber;
op_overloading_supported : boolean;
minargs : longint;
maxargs : longint;
end;
Ttok2opRec=record
@ -111,33 +113,33 @@ interface
const
tok2nodes=27;
tok2node:array[1..tok2nodes] of ttok2noderec=(
(tok:_PLUS ;nod:addn;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_MINUS ;nod:subn;inr:in_none;op_overloading_supported:true), { binary and unary overloading supported }
(tok:_STAR ;nod:muln;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_SLASH ;nod:slashn;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_EQ ;nod:equaln;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_GT ;nod:gtn;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_LT ;nod:ltn;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_GTE ;nod:gten;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_LTE ;nod:lten;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_SYMDIF ;nod:symdifn;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_STARSTAR ;nod:starstarn;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_OP_AS ;nod:asn;inr:in_none;op_overloading_supported:false), { binary overloading NOT supported }
(tok:_OP_IN ;nod:inn;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_OP_IS ;nod:isn;inr:in_none;op_overloading_supported:false), { binary overloading NOT supported }
(tok:_OP_OR ;nod:orn;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_OP_AND ;nod:andn;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_OP_DIV ;nod:divn;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_OP_NOT ;nod:notn;inr:in_none;op_overloading_supported:true), { unary overloading supported }
(tok:_OP_MOD ;nod:modn;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_OP_SHL ;nod:shln;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_OP_SHR ;nod:shrn;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_OP_XOR ;nod:xorn;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_ASSIGNMENT ;nod:assignn;inr:in_none;op_overloading_supported:true), { unary overloading supported }
(tok:_OP_EXPLICIT;nod:assignn;inr:in_none;op_overloading_supported:true), { unary overloading supported }
(tok:_NE ;nod:unequaln;inr:in_none;op_overloading_supported:true), { binary overloading supported }
(tok:_OP_INC ;nod:inlinen;inr:in_inc_x;op_overloading_supported:true), { unary overloading supported }
(tok:_OP_DEC ;nod:inlinen;inr:in_dec_x;op_overloading_supported:true) { unary overloading supported }
(tok:_PLUS ;nod:addn;inr:in_none;op_overloading_supported:true;minargs:1;maxargs:2), { binary overloading supported }
(tok:_MINUS ;nod:subn;inr:in_none;op_overloading_supported:true;minargs:1;maxargs:2), { binary and unary overloading supported }
(tok:_STAR ;nod:muln;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_SLASH ;nod:slashn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_EQ ;nod:equaln;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_GT ;nod:gtn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_LT ;nod:ltn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_GTE ;nod:gten;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_LTE ;nod:lten;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_SYMDIF ;nod:symdifn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_STARSTAR ;nod:starstarn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_OP_AS ;nod:asn;inr:in_none;op_overloading_supported:false;minargs:0;maxargs:0), { binary overloading NOT supported }
(tok:_OP_IN ;nod:inn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_OP_IS ;nod:isn;inr:in_none;op_overloading_supported:false;minargs:0;maxargs:0), { binary overloading NOT supported }
(tok:_OP_OR ;nod:orn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_OP_AND ;nod:andn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_OP_DIV ;nod:divn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_OP_NOT ;nod:notn;inr:in_none;op_overloading_supported:true;minargs:1;maxargs:1), { unary overloading supported }
(tok:_OP_MOD ;nod:modn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_OP_SHL ;nod:shln;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_OP_SHR ;nod:shrn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_OP_XOR ;nod:xorn;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_ASSIGNMENT ;nod:assignn;inr:in_none;op_overloading_supported:true;minargs:1;maxargs:1), { unary overloading supported }
(tok:_OP_EXPLICIT;nod:assignn;inr:in_none;op_overloading_supported:true;minargs:1;maxargs:1), { unary overloading supported }
(tok:_NE ;nod:unequaln;inr:in_none;op_overloading_supported:true;minargs:2;maxargs:2), { binary overloading supported }
(tok:_OP_INC ;nod:inlinen;inr:in_inc_x;op_overloading_supported:true;minargs:1;maxargs:1), { unary overloading supported }
(tok:_OP_DEC ;nod:inlinen;inr:in_dec_x;op_overloading_supported:true;minargs:1;maxargs:1) { unary overloading supported }
);
tok2ops=4;
@ -697,6 +699,8 @@ implementation
begin
result:=
tok2node[i].op_overloading_supported and
(tok2node[i].minargs<=1) and
(tok2node[i].maxargs>=1) and
isunaryoperatoroverloadable(tok2node[i].nod,tok2node[i].inr,ld);
break;
end;
@ -713,6 +717,8 @@ implementation
rd:=tparavarsym(pf.parast.SymList[1]).vardef;
result:=
tok2node[i].op_overloading_supported and
(tok2node[i].minargs<=2) and
(tok2node[i].maxargs>=2) and
isbinaryoperatoroverloadable(tok2node[i].nod,ld,nothingn,rd,nothingn);
break;
end;

13
tests/tbf/tb0268.pp Normal file
View File

@ -0,0 +1,13 @@
{ %FAIL }
program tb0268;
{$mode objfpc}
operator Not (aArg1: TObject; aArg2: TObject): TObject;
begin
end;
begin
end.

13
tests/tbf/tb0269.pp Normal file
View File

@ -0,0 +1,13 @@
{ %FAIL }
program tb0269;
{$mode objfpc}
operator + (aArg1: TObject; aArg2: TObject; aArg3: TObject): TObject;
begin
end;
begin
end.

13
tests/tbf/tb0270.pp Normal file
View File

@ -0,0 +1,13 @@
{ %FAIL }
program tb0270;
{$mode objfpc}
operator / (aArg1: TObject): TObject;
begin
end;
begin
end.