* Forbid use of string alias in system unit

This commit is contained in:
Michael VAN CANNEYT 2023-01-04 14:41:51 +01:00 committed by Michael Van Canneyt
parent fb9c718371
commit f364bb6b11
7 changed files with 696 additions and 687 deletions

View File

@ -1654,6 +1654,9 @@ 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.
% 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.
%
% \end{description}
%

View File

@ -483,6 +483,7 @@ const
parser_e_promising_exports_not_supported_on_current_platform=03367;
parser_e_suspending_externals_not_supported_on_current_platform=03368;
parser_w_widechar_set_reduced=03369;
parser_e_nostringaliasinsystem=03370;
type_e_mismatch=04000;
type_e_incompatible_types=04001;
type_e_not_equal_types=04002;
@ -1168,9 +1169,9 @@ const
option_info=11024;
option_help_pages=11025;
MsgTxtSize = 91613;
MsgTxtSize = 91712;
MsgIdxMax : array[1..20] of longint=(
28,109,370,134,102,63,148,38,223,71,
28,109,371,134,102,63,148,38,223,71,
68,20,30,1,1,1,1,1,1,1
);

File diff suppressed because it is too large Load Diff

View File

@ -372,7 +372,7 @@ implementation
exit(true);
end;
{ system.char? (char=widechar comes from the implicit
uuchar unit -> override) }
uachar/uuchar unit -> override) }
if (pattern='CHAR') and
(tmodule(tunitsym(srsym).module).globalsymtable=systemunit) then
begin
@ -399,6 +399,8 @@ implementation
end;
_STRING:
begin
if cs_compilesystem in current_settings.moduleswitches then
Message(parser_e_nostringaliasinsystem);
{ system.string? }
if tmodule(tunitsym(srsym).module).globalsymtable=systemunit then
begin

View File

@ -141,6 +141,9 @@ implementation
end
else
begin
// string[x] is allowed in system unit since it is a shortstring.
if cs_compilesystem in current_settings.moduleswitches then
Message(parser_e_nostringaliasinsystem);
if cs_refcountedstrings in current_settings.localswitches then
begin
if m_default_unicodestring in current_settings.modeswitches then
@ -4036,6 +4039,8 @@ implementation
_STRING :
begin
if cs_compilesystem in current_settings.moduleswitches then
Message(parser_e_nostringaliasinsystem);
string_dec(hdef,true);
{ STRING can be also a type cast }
if try_to_consume(_LKLAMMER) then
@ -5017,11 +5022,11 @@ implementation
end
else if (tstringconstnode(p).cst_type in [cst_unicodestring,cst_widestring]) then
begin
pw:=pcompilerwideString(tstringconstnode(p).value_str);
pc:=getmem(getlengthwidestring(pw));
unicode2ascii(pw,pc,current_settings.sourcecodepage);
get_stringconst:=strpas(pc);
freemem(pc);
pw:=pcompilerwideString(tstringconstnode(p).value_str);
pc:=getmem(getlengthwidestring(pw));
unicode2ascii(pw,pc,current_settings.sourcecodepage);
get_stringconst:=strpas(pc);
freemem(pc);
end
else
get_stringconst:=strpas(snode.value_str);

View File

@ -495,7 +495,6 @@ implementation
case token of
_STRING:
string_dec(def,stoAllowTypeDef in options);
_FILE:
begin
consume(_FILE);
@ -1324,8 +1323,8 @@ implementation
begin
if (m_default_unicodestring in current_settings.modeswitches) then
begin
Message(parser_w_widechar_set_reduced);
def:=csetdef.create(cansichartype,torddef(cansichartype).low.svalue,torddef(cansichartype).high.svalue,true);
Message(parser_w_widechar_set_reduced);
def:=csetdef.create(cansichartype,torddef(cansichartype).low.svalue,torddef(cansichartype).high.svalue,true);
end
else
Message(sym_e_ill_type_decl_set);

View File

@ -1635,7 +1635,7 @@ type
case current_scanner.preproc_token of
_ID:
{ system.char? (char=widechar comes from the implicit
uuchar unit -> override) }
uachar/uuchar unit -> override) }
if (current_scanner.preproc_pattern='CHAR') and
(tmodule(tunitsym(srsym).module).globalsymtable=systemunit) then
begin