Browse Source

* Merging revisions 40927,40930,40935,40936,40939,40940,40942,40944 from trunk:
------------------------------------------------------------------------
r40927 | michael | 2019-01-20 12:12:49 +0100 (Sun, 20 Jan 2019) | 1 line

* Widestring -> unicodestring
------------------------------------------------------------------------
r40930 | michael | 2019-01-20 13:32:01 +0100 (Sun, 20 Jan 2019) | 1 line

* Fix syntax error
------------------------------------------------------------------------
r40935 | michael | 2019-01-20 14:04:15 +0100 (Sun, 20 Jan 2019) | 1 line

* Remove debug statement
------------------------------------------------------------------------
r40936 | michael | 2019-01-20 14:04:28 +0100 (Sun, 20 Jan 2019) | 1 line

* Add in operator
------------------------------------------------------------------------
r40939 | michael | 2019-01-20 17:45:31 +0100 (Sun, 20 Jan 2019) | 1 line

* Parse type constraints in generics
------------------------------------------------------------------------
r40940 | michael | 2019-01-20 17:52:09 +0100 (Sun, 20 Jan 2019) | 1 line

* Fix compilation
------------------------------------------------------------------------
r40942 | michael | 2019-01-20 18:10:16 +0100 (Sun, 20 Jan 2019) | 1 line

* Generic templates can be separated by semicolon (used in fgl unit)
------------------------------------------------------------------------
r40944 | michael | 2019-01-20 18:55:15 +0100 (Sun, 20 Jan 2019) | 1 line

* Defaults are not to add default identifiers (fpdoc)
------------------------------------------------------------------------

git-svn-id: branches/fixes_3_2@40947 -

michael 6 years ago
parent
commit
081900de7c

+ 7 - 4
packages/fcl-passrc/src/pastree.pp

@@ -717,7 +717,10 @@ type
     Procedure SetGenericTemplates(AList : TFPList);
   end;
 
-  TPasGenericTemplateType = Class(TPasType);
+  TPasGenericTemplateType = Class(TPasType)
+  Public
+    TypeConstraint : String;
+  end;
 
   TPasObjKind = (
     okObject, okClass, okInterface, okGeneric,
@@ -1063,7 +1066,7 @@ type
                    otGreaterThan, otAssign,otNotEqual,otLessEqualThan,otGreaterEqualThan,otPower,
                    otSymmetricalDifference, otInc, otDec, otMod, otNegative, otPositive, otBitWiseOr, otDiv,
                    otLeftShift, otLogicalOr, otBitwiseAnd, otbitwiseXor,otLogicalAnd,otLogicalNot,otLogicalXor,
-                   otRightShift,otEnumerator);
+                   otRightShift,otEnumerator, otIn);
   TOperatorTypes = set of TOperatorType;
 
   TPasOperator = class(TPasFunction)
@@ -1597,13 +1600,13 @@ const
            '>',':=','<>','<=','>=','**',
            '><','Inc','Dec','mod','-','+','Or','div',
            'shl','or','and','xor','and','not','xor',
-           'shr','enumerator');
+           'shr','enumerator','in');
   OperatorNames : Array[TOperatorType] of string
        =  ('','implicit','explicit','multiply','add','subtract','divide','lessthan','equal',
            'greaterthan','assign','notequal','lessthanorequal','greaterthanorequal','power',
            'symmetricaldifference','inc','dec','modulus','negative','positive','bitwiseor','intdivide',
            'leftshift','logicalor','bitwiseand','bitwisexor','logicaland','logicalnot','logicalxor',
-           'rightshift','enumerator');
+           'rightshift','enumerator','in');
 
   AssignKindNames : Array[TAssignKind] of string = (':=','+=','-=','*=','/=' );
 

+ 17 - 4
packages/fcl-passrc/src/pparser.pp

@@ -619,7 +619,7 @@ var
     l := CurPos - Start;
     if l <= 0 then
       exit;
-    s:=copy(FPCCommandLine,Start,l);
+    s:=Trim(copy(FPCCommandLine,Start,l));
     if (s[1] = '-') and (length(s)>1) then
     begin
       case s[2] of
@@ -721,6 +721,12 @@ begin
         Scanner.AddDefine('CPU32');
       end;
     Parser := TPasParser.Create(Scanner, FileResolver, AEngine);
+    if (poSkipDefaultDefs in Options) then
+      begin
+      Writeln('>>> Clearing <<<');
+      Parser.ImplicitUses.Clear;
+      end;
+    Writeln('Implicit >>>',Parser.ImplicitUses.Text,'<<<');
     Filename := '';
     Parser.LogEvents:=AEngine.ParserLogEvents;
     Parser.OnLog:=AEngine.Onlog;
@@ -3875,16 +3881,23 @@ procedure TPasParser.ReadGenericArguments(List: TFPList; Parent: TPasElement);
 
 Var
   N : String;
+  T : TPasGenericTemplateType;
 
 begin
   ExpectToken(tkLessThan);
   repeat
     N:=ExpectIdentifier;
-    List.Add(CreateElement(TPasGenericTemplateType,N,Parent));
+    T:=TPasGenericTemplateType(CreateElement(TPasGenericTemplateType,N,Parent));
+    List.Add(T);
     NextToken;
-    if not (CurToken in [tkComma, tkGreaterThan]) then
+    if Curtoken = tkColon then
+      begin
+      T.TypeConstraint:=ExpectIdentifier;
+      NextToken;
+      end;
+    if not (CurToken in [tkComma,tkSemicolon,tkGreaterThan]) then
       ParseExc(nParserExpectToken2Error,SParserExpectToken2Error,
-        [TokenInfos[tkComma], TokenInfos[tkGreaterThan]]);
+        [TokenInfos[tkComma], TokenInfos[tkColon], TokenInfos[tkGreaterThan]]);
   until CurToken = tkGreaterThan;
 end;
 

+ 45 - 0
packages/fcl-passrc/tests/tcgenerics.pp

@@ -12,13 +12,16 @@ Type
   { TTestGenerics }
 
   TTestGenerics = Class(TBaseTestTypeParser)
+  private
   Published
     Procedure TestObjectGenerics;
     Procedure TestRecordGenerics;
     Procedure TestArrayGenerics;
     Procedure TestSpecializationDelphi;
+    procedure TestDeclarationConstraint;
     Procedure TestDeclarationDelphi;
     Procedure TestDeclarationDelphiSpecialize;
+    procedure TestDeclarationFPC;
     Procedure TestMethodImplementation;
     Procedure TestInlineSpecializationInArgument;
     Procedure TestSpecializeNested;
@@ -84,6 +87,48 @@ begin
   AssertSame('Parent 1 is class',T,TPasElement(T.GenericTemplateTypes[1]).Parent);
 end;
 
+procedure TTestGenerics.TestDeclarationFPC;
+Var
+  T : TPasClassType;
+begin
+  Scanner.CurrentModeSwitches:=[msDelphi]+Scanner.CurrentModeSwitches ;
+  Source.Add('Type');
+  Source.Add('  TSomeClass<T;T2> = Class(TObject)');
+  Source.Add('  b : T;');
+  Source.Add('  b2 : T2;');
+  Source.Add('end;');
+  ParseDeclarations;
+  AssertNotNull('have generic definition',Declarations.Classes);
+  AssertEquals('have generic definition',1,Declarations.Classes.Count);
+  AssertEquals('Pascal class',TPasClassType,TObject(Declarations.Classes[0]).ClassType);
+  T:=TPasClassType(Declarations.Classes[0]);
+  AssertNotNull('have generic templates',T.GenericTemplateTypes);
+  AssertEquals('2 template types',2,T.GenericTemplateTypes.Count);
+  AssertSame('Parent 0 is class',T,TPasElement(T.GenericTemplateTypes[0]).Parent);
+  AssertSame('Parent 1 is class',T,TPasElement(T.GenericTemplateTypes[1]).Parent);
+end;
+
+
+procedure TTestGenerics.TestDeclarationConstraint;
+Var
+  T : TPasClassType;
+begin
+  Scanner.CurrentModeSwitches:=[msDelphi]+Scanner.CurrentModeSwitches ;
+  Source.Add('Type');
+  Source.Add('  TSomeClass<T: T2> = Class(TObject)');
+  Source.Add('  b : T;');
+  Source.Add('end;');
+  ParseDeclarations;
+  AssertNotNull('have generic definition',Declarations.Classes);
+  AssertEquals('have generic definition',1,Declarations.Classes.Count);
+  AssertEquals('Pascal class',TPasClassType,TObject(Declarations.Classes[0]).ClassType);
+  T:=TPasClassType(Declarations.Classes[0]);
+  AssertNotNull('have generic templates',T.GenericTemplateTypes);
+  AssertEquals('1 template types',1,T.GenericTemplateTypes.Count);
+  AssertSame('Parent 0 is class',T,TPasElement(T.GenericTemplateTypes[0]).Parent);
+  AssertEquals('Type constraint is recorded','T2',TPasGenericTemplateType(T.GenericTemplateTypes[0]).TypeConstraint);
+end;
+
 procedure TTestGenerics.TestDeclarationDelphiSpecialize;
 Var
   T : TPasClassType;

+ 1 - 1
packages/fcl-xml/src/xmlutils.pp

@@ -25,7 +25,7 @@ uses
 type
   TXMLVersion = (xmlVersionUnknown, xmlVersion10, xmlVersion11);
   TSetOfChar = set of Char;
-  XMLString = WideString;
+  XMLString = UnicodeString;
   PXMLString = ^XMLString;
   PXMLChar = PWideChar;
 

+ 2 - 1
packages/pastojs/src/pas2jsfiler.pp

@@ -429,7 +429,8 @@ const
     'LogicalNot',
     'LogicalXor',
     'RightShift',
-    'Enumerator'
+    'Enumerator',
+    'In'
     );
 
   PCUProcedureModifierNames: array[TProcedureModifier] of string = (

+ 1 - 1
packages/rtl-extra/src/unix/ipc.pp

@@ -179,7 +179,7 @@ type
         cgid  : kernel_gid_t;
         mode  : kernel_mode_t;
 {$if sizeof(kernel_mode_t) < 4}
-        __pad1    : array[1..4-sizeof(mode_t)];
+        __pad1    : array[1..4-sizeof(mode_t)] of byte;
 {$endif}
 {$ifdef cpupowerpc}
         seq       : cuint;