Browse Source

* Finalize does not need result

Michaël Van Canneyt 3 years ago
parent
commit
10c60c45d5

+ 1 - 1
packages/fcl-passrc/src/pastree.pp

@@ -1176,7 +1176,7 @@ type
     otRightShift,
     otEnumerator, otIn,
     otInitialize,
-    orFinalize // Management operators
+    otFinalize // Management operators
     );
   TOperatorTypes = set of TOperatorType;
 

+ 1 - 1
packages/fcl-passrc/src/pparser.pp

@@ -5482,7 +5482,7 @@ begin
         ExpectToken(tkColon);
         ResultEl.ResultType := ParseType(ResultEl,CurSourcePos);
         end
-      else if not ((Parent is TPasOperator) and (TPasOperator(Parent).OperatorType=otInitialize)) then
+      else if not ((Parent is TPasOperator) and (TPasOperator(Parent).OperatorType in [otInitialize,otFinalize])) then
         // Initialize operator has no result
         begin
          if (CurToken=tkColon) then

+ 6 - 4
packages/fcl-passrc/tests/tcprocfunc.pas

@@ -1414,18 +1414,20 @@ begin
     begin
     if OperatorNames[t]='' then continue;
     // otInitialize has no result
-    if t=otInitialize then continue;
-    writeln('TTestProcedureFunction.TestOperatorTokens ',t);
     S:=GetEnumName(TypeInfo(TOperatorType),Ord(T));
     ResetParser;
-    if t in UnaryOperators then
+    if t in [otInitialize,otFinalize] then
+      AddDeclaration(Format('operator %s (var a: Integer)',[OperatorNames[t]]))
+    else if t in UnaryOperators then
       AddDeclaration(Format('operator %s (a: Integer) : te',[OperatorNames[t]]))
     else
       AddDeclaration(Format('operator %s (a: Integer; b: integer) : te',[OperatorNames[t]]));
     ParseOperator;
     AssertEquals(S+': Token based',t in [otIn],FOperator.TokenBased);
     AssertEquals(S+': Correct operator type',T,FOperator.OperatorType);
-    if t in UnaryOperators then
+    if t in [otInitialize,otFinalize] then
+      AssertEquals('Correct operator name',format('%s(Integer)',[OperatorNames[t]]),FOperator.Name)
+    else if t in UnaryOperators then
       AssertEquals('Correct operator name',format('%s(Integer):te',[OperatorNames[t]]),FOperator.Name)
     else
       AssertEquals('Correct operator name',format('%s(Integer,Integer):te',[OperatorNames[t]]),FOperator.Name);