Selaa lähdekoodia

* Initial variantop and compare handlers. Patch from Laaca, bug #16853

git-svn-id: trunk@16486 -
marco 14 vuotta sitten
vanhempi
commit
c9c1179b00
1 muutettua tiedostoa jossa 38 lisäystä ja 3 poistoa
  1. 38 3
      rtl/inc/variants.pp

+ 38 - 3
rtl/inc/variants.pp

@@ -1218,10 +1218,40 @@ begin
 end;
 end;
 
 
 function DoVarCmpComplex(const Left, Right: TVarData; const OpCode: TVarOp): ShortInt;
 function DoVarCmpComplex(const Left, Right: TVarData; const OpCode: TVarOp): ShortInt;
+var Handler: TCustomVariantType;
+    CmpRes: boolean;
 begin
 begin
-  {!! custom variants? }
+  if FindCustomVariantType(Left.vType, Handler) then
+    CmpRes := Handler.CompareOp(Left, Right, OpCode)
+  else if FindCustomVariantType(Right.vType, Handler) then
+    CmpRes := Handler.CompareOp(Left, Right, OpCode)
+  else
   VarInvalidOp(Left.vType, Right.vType, OpCode);
   VarInvalidOp(Left.vType, Right.vType, OpCode);
-  Result:=0;
+
+  case OpCode of
+    opCmpEq:
+      if CmpRes then
+        Result:=0
+      else
+        Result:=1;
+    opCmpNe:
+      if CmpRes then
+        Result:=1
+      else
+        Result:=0;
+    opCmpLt,
+    opCmpLe:
+      if CmpRes then
+        Result:=-1
+      else
+        Result:=1;
+    opCmpGt,
+    opCmpGe:
+      if CmpRes then
+        Result:=1
+      else
+        Result:=-1;
+  end;
 end;
 end;
 
 
 
 
@@ -1603,8 +1633,13 @@ begin
 end;
 end;
 
 
 procedure DoVarOpComplex(var vl : TVarData; const vr : TVarData; const OpCode : TVarOp);
 procedure DoVarOpComplex(var vl : TVarData; const vr : TVarData; const OpCode : TVarOp);
+var Handler: TCustomVariantType;
 begin
 begin
-  {custom Variant support? }
+  if FindCustomVariantType(vl.vType, Handler) then
+    Handler.BinaryOp(vl, vr, OpCode)
+  else if FindCustomVariantType(vr.vType, Handler) then
+    Handler.BinaryOp(vl, vr, OpCode)
+  else
    VarInvalidOp(vl.vType, vr.vType, OpCode);
    VarInvalidOp(vl.vType, vr.vType, OpCode);
 end;
 end;