From a29a6abc555daf005423a5c104905842e61941a8 Mon Sep 17 00:00:00 2001 From: svenbarth Date: Sun, 20 May 2018 11:50:19 +0000 Subject: [PATCH] + add support for Delphi's dynamic array constant syntax ("[...]") in Delphi modes git-svn-id: trunk@39042 - --- .gitattributes | 1 + compiler/ngtcon.pas | 9 +++-- tests/test/tarray16.pp | 81 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 tests/test/tarray16.pp diff --git a/.gitattributes b/.gitattributes index 8e299f4da1..213480e85c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12503,6 +12503,7 @@ tests/test/tarray12.pp svneol=native#text/pascal tests/test/tarray13.pp svneol=native#text/pascal tests/test/tarray14.pp svneol=native#text/pascal tests/test/tarray15.pp svneol=native#text/pascal +tests/test/tarray16.pp svneol=native#text/pascal tests/test/tarray2.pp svneol=native#text/plain tests/test/tarray3.pp svneol=native#text/plain tests/test/tarray4.pp svneol=native#text/plain diff --git a/compiler/ngtcon.pas b/compiler/ngtcon.pas index f32221d81e..a4084bfa7c 100644 --- a/compiler/ngtcon.pas +++ b/compiler/ngtcon.pas @@ -1160,6 +1160,9 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis procedure tasmlisttypedconstbuilder.parse_arraydef(def:tarraydef); + const + LKlammerToken: array[Boolean] of TToken = (_LKLAMMER, _LECKKLAMMER); + RKlammerToken: array[Boolean] of TToken = (_RKLAMMER, _RECKKLAMMER); var n : tnode; i : longint; @@ -1186,9 +1189,9 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis begin ftcb.emit_tai(Tai_const.Create_sym(nil),def); end - else if try_to_consume(_LKLAMMER) then + else if try_to_consume(LKlammerToken[m_delphi in current_settings.modeswitches]) then begin - if try_to_consume(_RKLAMMER) then + if try_to_consume(RKlammerToken[m_delphi in current_settings.modeswitches]) then begin ftcb.emit_tai(tai_const.create_sym(nil),def); end @@ -1210,7 +1213,7 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis begin read_typed_const_data(def.elementdef); inc(dyncount); - if try_to_consume(_RKLAMMER) then + if try_to_consume(RKlammerToken[m_delphi in current_settings.modeswitches]) then break else consume(_COMMA); diff --git a/tests/test/tarray16.pp b/tests/test/tarray16.pp new file mode 100644 index 0000000000..0142a1b763 --- /dev/null +++ b/tests/test/tarray16.pp @@ -0,0 +1,81 @@ +program tarray16; + +{$mode delphi} + +{$ifdef InLazIDE} +function CheckArray(aArr, aExpected: array of LongInt): Boolean; +{$else} +function CheckArray(aArr, aExpected: array of T): Boolean; +{$endif} +var + i: LongInt; +begin + if Length(aArr) <> Length(aExpected) then + Exit(False); + for i := Low(aArr) to High(aArr) do + if aArr[i] <> aExpected[i] then + Exit(False); + Result := True; +end; + +var + v1: array of LongInt = Nil; + v2: array of LongInt = []; + v3: array of LongInt = [1, 2, 3]; + v4: array of String = ['Alpha', 'Beta', 'Gamma', 'Delta']; + v5: array[0..2] of array of LongInt = (Nil, [], [1, 2, 3]); + // these do not work in Delphi + //v6: array of array[0..2] of LongInt = [(1, 2, 3), (4, 5, 6)]; + //v7: array[0..2] of array of array[0..2] of LongInt = ([(1, 2, 3), (4, 5, 6)], [], [(7, 8, 9)]); + +var + res: Boolean; +begin + if Length(v1) <> 0 then + Halt(1); + if Length(v2) <> 0 then + Halt(2); +{$ifndef InLazIDE} + res := CheckArray(v3, [1, 2, 3]); + if not res then + Halt(3); + res := CheckArray(v4, ['Alpha', 'Beta', 'Gamma', 'Delta']); + if not res then + Halt(4); + if Length(v5[0]) <> 0 then + Halt(5); + if Length(v5[1]) <> 0 then + Halt(6); + res := CheckArray(v5[2], [1, 2, 3]); + if not res then + Halt(7); + {if Length(v6) <> 2 then + Halt(8); + res := CheckArray(v6[0], [1, 2, 3]); + if not res then + Halt(9); + res := CheckArray(v6[1], [4, 5, 6]); + if not res then + Halt(10); + if Length(v7[0]) <> 2 then + Halt(11); + if Length(v7[1]) <> 0 then + Halt(12); + if Length(v7[2]) <> 1 then + Halt(13); + res := CheckArray(v7[0, 0], [1, 2, 3]); + if not res then + Halt(14); + res := CheckArray(v7[0, 1], [4, 5, 6]); + if not res then + Halt(15); + res := CheckArray(v7[2, 0], [7, 8, 9]); + if not res then + Halt(16);} + v3[1] := 42; + res := CheckArray(v3, [1, 42, 3]); + if not res then + Halt(17); +{$endif} + Writeln('ok'); +end.