From 3d6d5145bfd4a8e7961776d47ed7e2d802a49900 Mon Sep 17 00:00:00 2001 From: florian Date: Sun, 12 Feb 2017 17:29:45 +0000 Subject: [PATCH] * fix handling of const string symbols in preprocessor expressions + accept string constants in preprocessor expressions, resolves #31246 git-svn-id: trunk@35432 - --- .gitattributes | 1 + compiler/scanner.pas | 20 ++++++++++++++++---- tests/webtbs/tw31246.pp | 13 +++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 tests/webtbs/tw31246.pp diff --git a/.gitattributes b/.gitattributes index f95c56f94e..089ce1b3d0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/compiler/scanner.pas b/compiler/scanner.pas index e00802de02..40a46b0028 100644 --- a/compiler/scanner.pas +++ b/compiler/scanner.pas @@ -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; diff --git a/tests/webtbs/tw31246.pp b/tests/webtbs/tw31246.pp new file mode 100644 index 0000000000..533600d4ea --- /dev/null +++ b/tests/webtbs/tw31246.pp @@ -0,0 +1,13 @@ +program Project1; +const + + text = ''; + + text2 = {$IF text <> ''} + asdf + {$ELSE} + ''; + {$IFEND} + +begin +end.