* fix handling of const string symbols in preprocessor expressions

+ accept string constants in preprocessor expressions, resolves #31246

git-svn-id: trunk@35432 -
This commit is contained in:
florian 2017-02-12 17:29:45 +00:00
parent 0276bb374d
commit 3d6d5145bf
3 changed files with 30 additions and 4 deletions

1
.gitattributes vendored
View File

@ -15364,6 +15364,7 @@ tests/webtbs/tw31120.pp svneol=native#text/pascal
tests/webtbs/tw3113.pp svneol=native#text/plain
tests/webtbs/tw31201.pp svneol=native#text/pascal
tests/webtbs/tw3124.pp svneol=native#text/plain
tests/webtbs/tw31246.pp svneol=native#text/pascal
tests/webtbs/tw31305.pp svneol=native#text/pascal
tests/webtbs/tw3131.pp svneol=native#text/plain
tests/webtbs/tw31332.pp svneol=native#text/pascal

View File

@ -948,7 +948,7 @@ type
begin
value.len:=c.value.len;
getmem(value.valueptr,value.len+1);
move(c.value.valueptr^,value.valueptr,value.len+1);
move(c.value.valueptr^,value.valueptr^,value.len+1);
end;
constwstring:
begin
@ -1028,7 +1028,7 @@ type
getmem(sp,len+1);
move(s[1],sp^,len+1);
value.valueptr:=sp;
value.len:=length(s);
value.len:=len;
def:=strdef;
end;
@ -1091,7 +1091,7 @@ type
(is_ordinal(v.def) or is_fpu(v.def)) and
(is_ordinal(def) or is_fpu(def))
) or
(is_string(v.def) and is_string(def));
(is_stringlike(v.def) and is_stringlike(def));
if not result then
Message2(type_e_incompatible_types,def.typename,v.def.typename);
end;
@ -1359,7 +1359,7 @@ type
case consttyp of
conststring,
constresourcestring :
freemem(pchar(value.valueptr),value.len+1);
freemem(value.valueptr,value.len+1);
constwstring :
donewidestring(pcompilerwidestring(value.valueptr));
constreal :
@ -2042,6 +2042,11 @@ type
end;
preproc_consume(_INTCONST);
end
else if current_scanner.preproc_token = _CSTRING then
begin
result:=texprvalue.create_str(current_scanner.preproc_pattern);
preproc_consume(_CSTRING);
end
else if current_scanner.preproc_token = _REALNUMBER then
begin
result:=texprvalue.try_parse_real(current_scanner.preproc_pattern);
@ -5331,6 +5336,7 @@ exit_label:
var
low,high,mid: longint;
optoken: ttoken;
s : string;
begin
skipspace;
case c of
@ -5367,6 +5373,12 @@ exit_label:
current_scanner.preproc_pattern:=pattern;
readpreproc:=optoken;
end;
'''' :
begin
s:=readquotedstring;
current_scanner.preproc_pattern:=cstringpattern;
readpreproc:=_CSTRING;
end;
'0'..'9' :
begin
readnumber;

13
tests/webtbs/tw31246.pp Normal file
View File

@ -0,0 +1,13 @@
program Project1;
const
text = '';
text2 = {$IF text <> ''}
asdf
{$ELSE}
'';
{$IFEND}
begin
end.