Explorar o código

* Copy & AddRef operators

Michaël Van Canneyt %!s(int64=3) %!d(string=hai) anos
pai
achega
c44f82d11a

+ 6 - 3
packages/fcl-passrc/src/pastree.pp

@@ -1175,8 +1175,11 @@ type
     otLogicalAnd, otLogicalNot, otLogicalXor,
     otRightShift,
     otEnumerator, otIn,
+    // Management operators
     otInitialize,
-    otFinalize // Management operators
+    otFinalize,
+    otAddRef,
+    otCopy
     );
   TOperatorTypes = set of TOperatorType;
 
@@ -1765,13 +1768,13 @@ const
            '>',':=','<>','<=','>=','**',
            '><','Inc','Dec','mod','-','+','Or','div',
            'shl','or','and','xor','and','not','xor',
-           'shr','enumerator','in','','');
+           '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','in','initialize','finalize');
+           'rightshift','enumerator','in','initialize','finalize','addref','copy');
 
   AssignKindNames : Array[TAssignKind] of string = (':=','+=','-=','*=','/=' );
 

+ 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 in [otInitialize,otFinalize])) then
+      else if not ((Parent is TPasOperator) and (TPasOperator(Parent).OperatorType in [otInitialize,otFinalize,otAddRef,otCopy])) then
         // Initialize operator has no result
         begin
          if (CurToken=tkColon) then

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

@@ -1416,7 +1416,9 @@ begin
     // otInitialize has no result
     S:=GetEnumName(TypeInfo(TOperatorType),Ord(T));
     ResetParser;
-    if t in [otInitialize,otFinalize] then
+    if t in [otCopy] then
+      AddDeclaration(Format('operator %s (constref Src: Integer; var Dest : Integer)',[OperatorNames[t]]))
+    else if t in [otInitialize,otFinalize,otAddRef] 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]]))
@@ -1425,7 +1427,9 @@ begin
     ParseOperator;
     AssertEquals(S+': Token based',t in [otIn],FOperator.TokenBased);
     AssertEquals(S+': Correct operator type',T,FOperator.OperatorType);
-    if t in [otInitialize,otFinalize] then
+    if t in [otCopy] then
+      AssertEquals('Correct operator name',format('%s(Integer,Integer)',[OperatorNames[t]]),FOperator.Name)
+    else if t in [otInitialize,otFinalize,otAddRef] 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)

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

@@ -494,7 +494,9 @@ const
     'Enumerator',
     'In',
     'Initialize',
-    'Finalize'
+    'Finalize',
+    'AddRef',
+    'Copy'
     );
 
   PCUProcedureModifierNames: array[TProcedureModifier] of string = (