@@ -631,180 +631,102 @@ module internal ExtensionTyping =
631631 override __.Equals y = assert false ; match y with :? ProvidedConstructorInfo as y -> x.Equals y.Handle | _ -> false
632632 override __.GetHashCode () = assert false ; x.GetHashCode()
633633
634- [<RequireQualifiedAccess; Class; AllowNullLiteral; Sealed>]
635- type ProvidedExpr ( x : Quotations.Expr , ctxt ) =
634+ type ProvidedExprType =
635+ | ProvidedNewArrayExpr of ProvidedType * ProvidedExpr []
636+ #if PROVIDED_ ADDRESS_ OF
637+ | ProvidedAddressOfExpr of ProvidedExpr
638+ #endif
639+ | ProvidedNewObjectExpr of ProvidedConstructorInfo * ProvidedExpr []
640+ | ProvidedWhileLoopExpr of ProvidedExpr * ProvidedExpr
641+ | ProvidedNewDelegateExpr of ProvidedType * ProvidedVar [] * ProvidedExpr
642+ | ProvidedForIntegerRangeLoopExpr of ProvidedVar * ProvidedExpr * ProvidedExpr * ProvidedExpr
643+ | ProvidedSequentialExpr of ProvidedExpr * ProvidedExpr
644+ | ProvidedTryWithExpr of ProvidedExpr * ProvidedVar * ProvidedExpr * ProvidedVar * ProvidedExpr
645+ | ProvidedTryFinallyExpr of ProvidedExpr * ProvidedExpr
646+ | ProvidedLambdaExpr of ProvidedVar * ProvidedExpr
647+ | ProvidedCallExpr of ProvidedExpr option * ProvidedMethodInfo * ProvidedExpr []
648+ | ProvidedConstantExpr of obj * ProvidedType
649+ | ProvidedDefaultExpr of ProvidedType
650+ | ProvidedNewTupleExpr of ProvidedExpr []
651+ | ProvidedTupleGetExpr of ProvidedExpr * int
652+ | ProvidedTypeAsExpr of ProvidedExpr * ProvidedType
653+ | ProvidedTypeTestExpr of ProvidedExpr * ProvidedType
654+ | ProvidedLetExpr of ProvidedVar * ProvidedExpr * ProvidedExpr
655+ | ProvidedVarSetExpr of ProvidedVar * ProvidedExpr
656+ | ProvidedIfThenElseExpr of ProvidedExpr * ProvidedExpr * ProvidedExpr
657+ | ProvidedVarExpr of ProvidedVar
658+
659+ and [<RequireQualifiedAccess; Class; AllowNullLiteral; Sealed>]
660+ ProvidedExpr ( x : Quotations.Expr , ctxt ) =
636661 member __.Type = x.Type |> ProvidedType.Create ctxt
637662 member __.Handle = x
638663 member __.Context = ctxt
639664 member __.UnderlyingExpressionString = x.ToString()
665+ member __.GetExprType () =
666+ match x with
667+ | Quotations.Patterns.NewObject( ctor, args) ->
668+ Some ( ProvidedNewObjectExpr ( ProvidedConstructorInfo.Create ctxt ctor, [| for a in args -> ProvidedExpr.Create ctxt a |]))
669+ | Quotations.Patterns.WhileLoop( guardExpr, bodyExpr) ->
670+ Some ( ProvidedWhileLoopExpr ( ProvidedExpr.Create ctxt guardExpr, ProvidedExpr.Create ctxt bodyExpr))
671+ | Quotations.Patterns.NewDelegate( ty, vs, expr) ->
672+ Some ( ProvidedNewDelegateExpr( ProvidedType.Create ctxt ty, ProvidedVar.CreateArray ctxt ( List.toArray vs), ProvidedExpr.Create ctxt expr))
673+ | Quotations.Patterns.Call( objOpt, meth, args) ->
674+ Some ( ProvidedCallExpr(( match objOpt with None -> None | Some obj -> Some ( ProvidedExpr.Create ctxt obj)),
675+ ProvidedMethodInfo.Create ctxt meth, [| for a in args -> ProvidedExpr.Create ctxt a |]))
676+ | Quotations.Patterns.DefaultValue ty ->
677+ Some ( ProvidedDefaultExpr ( ProvidedType.Create ctxt ty))
678+ | Quotations.Patterns.Value( obj, ty) ->
679+ Some ( ProvidedConstantExpr ( obj, ProvidedType.Create ctxt ty))
680+ | Quotations.Patterns.Coerce( arg, ty) ->
681+ Some ( ProvidedTypeAsExpr ( ProvidedExpr.Create ctxt arg, ProvidedType.Create ctxt ty))
682+ | Quotations.Patterns.NewTuple args ->
683+ Some ( ProvidedNewTupleExpr( ProvidedExpr.CreateArray ctxt ( Array.ofList args)))
684+ | Quotations.Patterns.TupleGet( arg, n) ->
685+ Some ( ProvidedTupleGetExpr ( ProvidedExpr.Create ctxt arg, n))
686+ | Quotations.Patterns.NewArray( ty, args) ->
687+ Some ( ProvidedNewArrayExpr( ProvidedType.Create ctxt ty, ProvidedExpr.CreateArray ctxt ( Array.ofList args)))
688+ | Quotations.Patterns.Sequential( e1, e2) ->
689+ Some ( ProvidedSequentialExpr( ProvidedExpr.Create ctxt e1, ProvidedExpr.Create ctxt e2))
690+ | Quotations.Patterns.Lambda( v, body) ->
691+ Some ( ProvidedLambdaExpr ( ProvidedVar.Create ctxt v, ProvidedExpr.Create ctxt body))
692+ | Quotations.Patterns.TryFinally( b1, b2) ->
693+ Some ( ProvidedTryFinallyExpr ( ProvidedExpr.Create ctxt b1, ProvidedExpr.Create ctxt b2))
694+ | Quotations.Patterns.TryWith( b, v1, e1, v2, e2) ->
695+ Some ( ProvidedTryWithExpr ( ProvidedExpr.Create ctxt b, ProvidedVar.Create ctxt v1, ProvidedExpr.Create ctxt e1, ProvidedVar.Create ctxt v2, ProvidedExpr.Create ctxt e2))
696+ #if PROVIDED_ ADDRESS_ OF
697+ | Quotations.Patterns.AddressOf e -> Some ( ProvidedAddressOfExpr ( ProvidedExpr.Create ctxt e))
698+ #endif
699+ | Quotations.Patterns.TypeTest( e, ty) ->
700+ Some ( ProvidedTypeTestExpr( ProvidedExpr.Create ctxt e, ProvidedType.Create ctxt ty))
701+ | Quotations.Patterns.Let( v, e, b) ->
702+ Some ( ProvidedLetExpr ( ProvidedVar.Create ctxt v, ProvidedExpr.Create ctxt e, ProvidedExpr.Create ctxt b))
703+ | Quotations.Patterns.ForIntegerRangeLoop ( v, e1, e2, e3) ->
704+ Some ( ProvidedForIntegerRangeLoopExpr ( ProvidedVar.Create ctxt v, ProvidedExpr.Create ctxt e1, ProvidedExpr.Create ctxt e2, ProvidedExpr.Create ctxt e3))
705+ | Quotations.Patterns.VarSet( v, e) ->
706+ Some ( ProvidedVarSetExpr ( ProvidedVar.Create ctxt v, ProvidedExpr.Create ctxt e))
707+ | Quotations.Patterns.IfThenElse( g, t, e) ->
708+ Some ( ProvidedIfThenElseExpr ( ProvidedExpr.Create ctxt g, ProvidedExpr.Create ctxt t, ProvidedExpr.Create ctxt e))
709+ | Quotations.Patterns.Var v ->
710+ Some ( ProvidedVarExpr ( ProvidedVar.Create ctxt v))
711+ | _ -> None
640712 static member Create ctxt t = match box t with null -> null | _ -> ProvidedExpr ( t, ctxt)
641713 static member CreateArray ctxt xs = match xs with null -> null | _ -> xs |> Array.map ( ProvidedExpr.Create ctxt)
642714 override __.Equals y = match y with :? ProvidedExpr as y -> x.Equals y.Handle | _ -> false
643715 override __.GetHashCode () = x.GetHashCode()
644716
645- [<RequireQualifiedAccess; Class; AllowNullLiteral; Sealed>]
646- type ProvidedVar ( x : Quotations.Var , ctxt ) =
717+ and [<RequireQualifiedAccess; Class; AllowNullLiteral; Sealed>]
718+ ProvidedVar ( x : Quotations.Var , ctxt ) =
647719 member __.Type = x.Type |> ProvidedType.Create ctxt
648720 member __.Name = x.Name
649721 member __.IsMutable = x.IsMutable
650722 member __.Handle = x
651723 member __.Context = ctxt
652724 static member Create ctxt t = match box t with null -> null | _ -> ProvidedVar ( t, ctxt)
653- static member Fresh ( nm , ty : ProvidedType ) = ProvidedVar.Create ty.Context ( new Quotations.Var( nm, ty.Handle))
725+ static member Fresh ( nm , ty : ProvidedType ) = ProvidedVar.Create ty.Context ( Quotations.Var( nm, ty.Handle))
654726 static member CreateArray ctxt xs = match xs with null -> null | _ -> xs |> Array.map ( ProvidedVar.Create ctxt)
655727 override __.Equals y = match y with :? ProvidedVar as y -> x.Equals y.Handle | _ -> false
656728 override __.GetHashCode () = x.GetHashCode()
657729
658-
659- /// Detect a provided new-object expression
660- let (| ProvidedNewObjectExpr | _ |) ( x : ProvidedExpr ) =
661- match x.Handle with
662- | Quotations.Patterns.NewObject( ctor, args) ->
663- Some ( ProvidedConstructorInfo.Create x.Context ctor, [| for a in args -> ProvidedExpr.Create x.Context a |])
664- | _ -> None
665-
666- /// Detect a provided while-loop expression
667- let (| ProvidedWhileLoopExpr | _ |) ( x : ProvidedExpr ) =
668- match x.Handle with
669- | Quotations.Patterns.WhileLoop( guardExpr, bodyExpr) ->
670- Some ( ProvidedExpr.Create x.Context guardExpr, ProvidedExpr.Create x.Context bodyExpr)
671- | _ -> None
672-
673- /// Detect a provided new-delegate expression
674- let (| ProvidedNewDelegateExpr | _ |) ( x : ProvidedExpr ) =
675- match x.Handle with
676- | Quotations.Patterns.NewDelegate( ty, vs, expr) ->
677- Some ( ProvidedType.Create x.Context ty, ProvidedVar.CreateArray x.Context ( List.toArray vs), ProvidedExpr.Create x.Context expr)
678- | _ -> None
679-
680- /// Detect a provided call expression
681- let (| ProvidedCallExpr | _ |) ( x : ProvidedExpr ) =
682- match x.Handle with
683- | Quotations.Patterns.Call( objOpt, meth, args) ->
684- Some (( match objOpt with None -> None | Some obj -> Some ( ProvidedExpr.Create x.Context obj)),
685- ProvidedMethodInfo.Create x.Context meth,
686- [| for a in args -> ProvidedExpr.Create x.Context a |])
687- | _ -> None
688-
689- /// Detect a provided default-value expression
690- let (| ProvidedDefaultExpr | _ |) ( x : ProvidedExpr ) =
691- match x.Handle with
692- | Quotations.Patterns.DefaultValue ty -> Some ( ProvidedType.Create x.Context ty)
693- | _ -> None
694-
695- /// Detect a provided constant expression
696- let (| ProvidedConstantExpr | _ |) ( x : ProvidedExpr ) =
697- match x.Handle with
698- | Quotations.Patterns.Value( obj, ty) -> Some ( obj, ProvidedType.Create x.Context ty)
699- | _ -> None
700-
701- /// Detect a provided type-as expression
702- let (| ProvidedTypeAsExpr | _ |) ( x : ProvidedExpr ) =
703- match x.Handle with
704- | Quotations.Patterns.Coerce( arg, ty) ->
705- Some ( ProvidedExpr.Create x.Context arg, ProvidedType.Create x.Context ty)
706- | _ -> None
707-
708- /// Detect a provided new-tuple expression
709- let (| ProvidedNewTupleExpr | _ |) ( x : ProvidedExpr ) =
710- match x.Handle with
711- | Quotations.Patterns.NewTuple args -> Some ( ProvidedExpr.CreateArray x.Context ( Array.ofList args))
712- | _ -> None
713-
714- /// Detect a provided tuple-get expression
715- let (| ProvidedTupleGetExpr | _ |) ( x : ProvidedExpr ) =
716- match x.Handle with
717- | Quotations.Patterns.TupleGet( arg, n) -> Some ( ProvidedExpr.Create x.Context arg, n)
718- | _ -> None
719-
720- /// Detect a provided new-array expression
721- let (| ProvidedNewArrayExpr | _ |) ( x : ProvidedExpr ) =
722- match x.Handle with
723- | Quotations.Patterns.NewArray( ty, args) ->
724- Some ( ProvidedType.Create x.Context ty, ProvidedExpr.CreateArray x.Context ( Array.ofList args))
725- | _ -> None
726-
727- /// Detect a provided sequential expression
728- let (| ProvidedSequentialExpr | _ |) ( x : ProvidedExpr ) =
729- match x.Handle with
730- | Quotations.Patterns.Sequential( e1, e2) ->
731- Some ( ProvidedExpr.Create x.Context e1, ProvidedExpr.Create x.Context e2)
732- | _ -> None
733-
734- /// Detect a provided lambda expression
735- let (| ProvidedLambdaExpr | _ |) ( x : ProvidedExpr ) =
736- match x.Handle with
737- | Quotations.Patterns.Lambda( v, body) ->
738- Some ( ProvidedVar.Create x.Context v, ProvidedExpr.Create x.Context body)
739- | _ -> None
740-
741- /// Detect a provided try/finally expression
742- let (| ProvidedTryFinallyExpr | _ |) ( x : ProvidedExpr ) =
743- match x.Handle with
744- | Quotations.Patterns.TryFinally( b1, b2) ->
745- Some ( ProvidedExpr.Create x.Context b1, ProvidedExpr.Create x.Context b2)
746- | _ -> None
747-
748- /// Detect a provided try/with expression
749- let (| ProvidedTryWithExpr | _ |) ( x : ProvidedExpr ) =
750- match x.Handle with
751- | Quotations.Patterns.TryWith( b, v1, e1, v2, e2) ->
752- Some ( ProvidedExpr.Create x.Context b, ProvidedVar.Create x.Context v1, ProvidedExpr.Create x.Context e1,
753- ProvidedVar.Create x.Context v2, ProvidedExpr.Create x.Context e2)
754- | _ -> None
755-
756- #if PROVIDED_ ADDRESS_ OF
757- let (| ProvidedAddressOfExpr | _ |) ( x : ProvidedExpr ) =
758- match x.Handle with
759- | Quotations.Patterns.AddressOf e -> Some ( ProvidedExpr.Create x.Context e)
760- | _ -> None
761- #endif
762-
763- /// Detect a provided type-test expression
764- let (| ProvidedTypeTestExpr | _ |) ( x : ProvidedExpr ) =
765- match x.Handle with
766- | Quotations.Patterns.TypeTest( e, ty) ->
767- Some ( ProvidedExpr.Create x.Context e, ProvidedType.Create x.Context ty)
768- | _ -> None
769-
770- /// Detect a provided 'let' expression
771- let (| ProvidedLetExpr | _ |) ( x : ProvidedExpr ) =
772- match x.Handle with
773- | Quotations.Patterns.Let( v, e, b) ->
774- Some ( ProvidedVar.Create x.Context v, ProvidedExpr.Create x.Context e, ProvidedExpr.Create x.Context b)
775- | _ -> None
776-
777-
778- /// Detect a provided expression which is a for-loop over integers
779- let (| ProvidedForIntegerRangeLoopExpr | _ |) ( x : ProvidedExpr ) =
780- match x.Handle with
781- | Quotations.Patterns.ForIntegerRangeLoop ( v, e1, e2, e3) ->
782- Some ( ProvidedVar.Create x.Context v,
783- ProvidedExpr.Create x.Context e1,
784- ProvidedExpr.Create x.Context e2,
785- ProvidedExpr.Create x.Context e3)
786- | _ -> None
787-
788- /// Detect a provided 'set variable' expression
789- let (| ProvidedVarSetExpr | _ |) ( x : ProvidedExpr ) =
790- match x.Handle with
791- | Quotations.Patterns.VarSet( v, e) ->
792- Some ( ProvidedVar.Create x.Context v, ProvidedExpr.Create x.Context e)
793- | _ -> None
794-
795- /// Detect a provided 'IfThenElse' expression
796- let (| ProvidedIfThenElseExpr | _ |) ( x : ProvidedExpr ) =
797- match x.Handle with
798- | Quotations.Patterns.IfThenElse( g, t, e) ->
799- Some ( ProvidedExpr.Create x.Context g, ProvidedExpr.Create x.Context t, ProvidedExpr.Create x.Context e)
800- | _ -> None
801-
802- /// Detect a provided 'Var' expression
803- let (| ProvidedVarExpr | _ |) ( x : ProvidedExpr ) =
804- match x.Handle with
805- | Quotations.Patterns.Var v -> Some ( ProvidedVar.Create x.Context v)
806- | _ -> None
807-
808730 /// Get the provided invoker expression for a particular use of a method.
809731 let GetInvokerExpression ( provider : ITypeProvider , methodBase : ProvidedMethodBase , paramExprs : ProvidedVar []) =
810732 provider.GetInvokerExpression( methodBase.Handle, [| for p in paramExprs -> Quotations.Expr.Var ( p.Handle) |]) |> ProvidedExpr.Create methodBase.Context
0 commit comments