* complain about turned off support of c style operators only in the parser,

so error recovery is better
This commit is contained in:
florian 2024-02-11 11:04:27 +01:00
parent 7bf502ad40
commit 2575cbc439
10 changed files with 674 additions and 599 deletions

View File

@ -1671,9 +1671,12 @@ parser_e_suspending_externals_not_supported_on_current_platform=03368_E_Declarin
parser_w_widechar_set_reduced=03369_W_Reducing Widechar set to single-byte AnsiChar set.
% The base type of a set can only have 255 elements. Sets of wide characters
% are reduced to sets of 1-byte characters.
parser_e_nostringaliasinsystem=03370_e_Using 'string' alias is not allowed in the system unit. Use short-,ansi- or unicodestring.
parser_e_nostringaliasinsystem=03370_E_Using 'string' alias is not allowed in the system unit. Use short-,ansi- or unicodestring.
% As a safeguard, the system unit may only use basic string types, not the
% string alias which is dependent on the mode in which a unit is compiled.
parser_e_coperators_off=03371_E_C styled assignment operators are turned off
% By default, c style assignment operators (+=, -=, *=, /=) are turn off. Either turn them on by the command line
% parameter -Sc or in the source code by {$COPERATORS ON}
%
% \end{description}
%

View File

@ -490,6 +490,7 @@ const
parser_e_suspending_externals_not_supported_on_current_platform=03368;
parser_w_widechar_set_reduced=03369;
parser_e_nostringaliasinsystem=03370;
parser_e_coperators_off=03371;
type_e_mismatch=04000;
type_e_incompatible_types=04001;
type_e_not_equal_types=04002;
@ -1177,9 +1178,9 @@ const
option_info=11024;
option_help_pages=11025;
MsgTxtSize = 92723;
MsgTxtSize = 92776;
MsgIdxMax : array[1..20] of longint=(
29,114,371,134,102,63,148,38,224,71,
29,114,372,134,102,63,148,38,224,71,
69,20,30,1,1,1,1,1,1,1
);

File diff suppressed because it is too large Load Diff

View File

@ -4952,24 +4952,32 @@ implementation
end;
_PLUSASN :
begin
if not(cs_support_c_operators in current_settings.moduleswitches) then
Message(parser_e_coperators_off);
consume(_PLUSASN);
p2:=sub_expr(opcompare,[ef_accept_equal],nil);
p1:=gen_c_style_operator(addn,p1,p2);
end;
_MINUSASN :
begin
if not(cs_support_c_operators in current_settings.moduleswitches) then
Message(parser_e_coperators_off);
consume(_MINUSASN);
p2:=sub_expr(opcompare,[ef_accept_equal],nil);
p1:=gen_c_style_operator(subn,p1,p2);
end;
_STARASN :
begin
if not(cs_support_c_operators in current_settings.moduleswitches) then
Message(parser_e_coperators_off);
consume(_STARASN );
p2:=sub_expr(opcompare,[ef_accept_equal],nil);
p1:=gen_c_style_operator(muln,p1,p2);
end;
_SLASHASN :
begin
if not(cs_support_c_operators in current_settings.moduleswitches) then
Message(parser_e_coperators_off);
consume(_SLASHASN );
p2:=sub_expr(opcompare,[ef_accept_equal],nil);
p1:=gen_c_style_operator(slashn,p1,p2);

View File

@ -5438,7 +5438,7 @@ type
'+' :
begin
readchar;
if (c='=') and (cs_support_c_operators in current_settings.moduleswitches) then
if c='=' then
begin
readchar;
token:=_PLUSASN;
@ -5451,7 +5451,7 @@ type
'-' :
begin
readchar;
if (c='=') and (cs_support_c_operators in current_settings.moduleswitches) then
if c='=' then
begin
readchar;
token:=_MINUSASN;
@ -5477,7 +5477,7 @@ type
'*' :
begin
readchar;
if (c='=') and (cs_support_c_operators in current_settings.moduleswitches) then
if c='=' then
begin
readchar;
token:=_STARASN;
@ -5499,12 +5499,9 @@ type
case c of
'=' :
begin
if (cs_support_c_operators in current_settings.moduleswitches) then
begin
readchar;
token:=_SLASHASN;
goto exit_label;
end;
readchar;
token:=_SLASHASN;
goto exit_label;
end;
'/' :
begin

20
tests/test/tcop1.pp Normal file
View File

@ -0,0 +1,20 @@
{ test c style assignment operators }
{$COPERATORS ON}
var
i : Single;
begin
i:=1234;
i += 1;
if i<>1235 then
halt(1);
i -= 1;
if i<>1234 then
halt(2);
i *= 2;
if i<>2468 then
halt(3);
i /= 2;
if i<>1234 then
halt(4);
end.

11
tests/test/tcop2.pp Normal file
View File

@ -0,0 +1,11 @@
{ %fail }
{ test c style assignment operators }
{$COPERATORS OFF}
var
i : Single;
begin
i:=1234;
i += 1;
end.

11
tests/test/tcop3.pp Normal file
View File

@ -0,0 +1,11 @@
{ %fail }
{ test c style assignment operators }
{$COPERATORS OFF}
var
i : Single;
begin
i:=1234;
i -= 1;
end.

11
tests/test/tcop4.pp Normal file
View File

@ -0,0 +1,11 @@
{ %fail }
{ test c style assignment operators }
{$COPERATORS OFF}
var
i : Single;
begin
i:=1234;
i *= 2;
end.

11
tests/test/tcop5.pp Normal file
View File

@ -0,0 +1,11 @@
{ %fail }
{ test c style assignment operators }
{$COPERATORS OFF}
var
i : Single;
begin
i:=1234;
i /= 2;
end.