Пример #1
0
 /// <summary>
 /// Creates a new ScriptScope whose storage contains the provided dictionary of objects
 ///
 /// Accesses to the ScriptScope will turn into get,set, and delete members against this dictionary
 /// </summary>
 public ScriptScope CreateScope(IDictionary <string, object> dictionary)
 {
     ContractUtils.RequiresNotNull(dictionary, "dictionary");
     return(new ScriptScope(this, _language.CreateScope(dictionary)));
 }
 public SwitchCaseProxy(SwitchCase node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
 public SwitchExpressionProxy(SwitchExpression node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
 public MethodCallExpressionProxy(MethodCallExpression node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
 public ParameterExpressionProxy(ParameterExpression node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
 public DefaultExpressionProxy(DefaultExpression node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
 public LambdaExpressionProxy(LambdaExpression node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
Пример #8
0
        /// <summary>
        /// Gets the formatting information for the given format.  This is a list of tuples.  The tuples
        /// include:
        ///
        /// text, field name, format spec, conversion
        /// </summary>
        public static IEnumerable <PythonTuple /*!*/> /*!*/ GetFormatInfo(string /*!*/ format)
        {
            ContractUtils.RequiresNotNull(format, nameof(format));

            return(StringFormatParser.Parse(format));
        }
Пример #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InvokeBinder" />.
 /// </summary>
 /// <param name="callInfo">The signature of the arguments at the call site.</param>
 protected InvokeBinder(CallInfo callInfo)
 {
     ContractUtils.RequiresNotNull(callInfo, "callInfo");
     _callInfo = callInfo;
 }
Пример #10
0
        /// <summary>
        /// Returns a new ObjectOperations object that inherits any semantics particular to the provided ScriptScope.
        ///
        /// See the Operations property for why you might want to call this.
        /// </summary>
        public ObjectOperations CreateOperations(ScriptScope scope)
        {
            ContractUtils.RequiresNotNull(scope, "scope");

            return(new ObjectOperations(_language.Operations, this));
        }
Пример #11
0
 internal SymbolDocumentInfo(string fileName)
 {
     ContractUtils.RequiresNotNull(fileName, "fileName");
     _fileName = fileName;
 }
Пример #12
0
        /// <summary>
        /// These methods return ScriptSource objects from stream contents with the current engine as the language binding.
        ///
        /// The default SourceCodeKind is File.
        ///
        /// The encoding defaults to Encoding.Default.
        /// </summary>
        public ScriptSource CreateScriptSource(StreamContentProvider content, string path)
        {
            ContractUtils.RequiresNotNull(content, "content");

            return(CreateScriptSource(content, path, StringUtils.DefaultEncoding, SourceCodeKind.File));
        }
Пример #13
0
        /// <summary>
        /// Return a ScriptSource object from string contents with the current engine as the language binding.
        ///
        /// The default SourceCodeKind is AutoDetect.
        /// </summary>
        public ScriptSource CreateScriptSourceFromString(string expression, string path)
        {
            ContractUtils.RequiresNotNull(expression, "expression");

            return(CreateScriptSource(new SourceStringContentProvider(expression), path, SourceCodeKind.AutoDetect));
        }
Пример #14
0
        /// <summary>
        /// Creates a new ScriptScope whose storage is an arbitrary object.
        ///
        /// Accesses to the ScriptScope will turn into get, set, and delete members against the object.
        /// </summary>
        public ScriptScope CreateScope(IDynamicMetaObjectProvider storage)
        {
            ContractUtils.RequiresNotNull(storage, "storage");

            return(new ScriptScope(this, _language.CreateScope(storage)));
        }
Пример #15
0
 /// <summary>
 /// Creates a <see cref="MemberMemberBinding"/> that represents the recursive initialization of members of a member that is accessed by using a property accessor method.
 /// </summary>
 /// <param name="propertyAccessor">The <see cref="MemberInfo"/> that represents a property accessor method.</param>
 /// <param name="bindings">An <see cref="IEnumerable{T}"/> that contains <see cref="MemberBinding"/> objects to use to populate the <see cref="MemberMemberBinding.Bindings"/> collection.</param>
 /// <returns>
 /// A <see cref="MemberMemberBinding"/> that has the <see cref="MemberBinding.BindingType"/> property equal to <see cref="MemberBinding"/>,
 /// the Member property set to the <see cref="PropertyInfo"/> that represents the property accessed in <paramref name="propertyAccessor"/>,
 /// and <see cref="MemberMemberBinding.Bindings"/> properties set to the specified values.
 /// </returns>
 public static MemberMemberBinding MemberBind(MethodInfo propertyAccessor, IEnumerable <MemberBinding> bindings)
 {
     ContractUtils.RequiresNotNull(propertyAccessor, nameof(propertyAccessor));
     return(MemberBind(GetProperty(propertyAccessor, nameof(propertyAccessor)), bindings));
 }
Пример #16
0
 /// <summary>
 /// Compiles the lambda into a method definition and custom debug information.
 /// </summary>
 /// <param name="method">A <see cref="MethodBuilder"/> which will be used to hold the lambda's IL.</param>
 /// <param name="debugInfoGenerator">Debugging information generator used by the compiler to mark sequence points and annotate local variables.</param>
 public void CompileToMethod(MethodBuilder method, DebugInfoGenerator debugInfoGenerator)
 {
     ContractUtils.RequiresNotNull(debugInfoGenerator, "debugInfoGenerator");
     CompileToMethodInternal(method, debugInfoGenerator);
 }
Пример #17
0
 /// <summary>
 /// Creates a <see cref="MemberExpression"/> accessing a property.
 /// </summary>
 /// <param name="expression">The containing object of the property.  This can be null for static properties.</param>
 /// <param name="propertyAccessor">An accessor method of the property to be accessed.</param>
 /// <returns>The created <see cref="MemberExpression"/>.</returns>
 public static MemberExpression Property(Expression expression, MethodInfo propertyAccessor)
 {
     ContractUtils.RequiresNotNull(propertyAccessor, "propertyAccessor");
     ValidateMethodInfo(propertyAccessor);
     return(Property(expression, GetProperty(propertyAccessor)));
 }
Пример #18
0
 /// <summary>
 /// Produces a delegate that represents the lambda expression.
 /// </summary>
 /// <param name="debugInfoGenerator">Debugging information generator used by the compiler to mark sequence points and annotate local variables.</param>
 /// <returns>A delegate containing the compiled version of the lambda.</returns>
 public new TDelegate Compile(DebugInfoGenerator debugInfoGenerator)
 {
     ContractUtils.RequiresNotNull(debugInfoGenerator, "debugInfoGenerator");
     return((TDelegate)(object)LambdaCompiler.Compile(this, debugInfoGenerator));
 }
 public InvocationExpressionProxy(InvocationExpression node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
Пример #20
0
 /// <summary>
 /// Creates a <see cref="CatchBlock"/> representing a catch statement with
 /// an <see cref="Exception"/> filter and a reference to the caught <see cref="Exception"/> object.
 /// </summary>
 /// <param name="variable">A <see cref="ParameterExpression"/> representing a reference to the <see cref="Exception"/> object caught by this handler.</param>
 /// <param name="body">The body of the catch statement.</param>
 /// <param name="filter">The body of the <see cref="Exception"/> filter.</param>
 /// <returns>The created <see cref="CatchBlock"/>.</returns>
 public static CatchBlock Catch(ParameterExpression variable, Expression body, Expression filter)
 {
     ContractUtils.RequiresNotNull(variable, nameof(variable));
     return(MakeCatchBlock(variable.Type, variable, body, filter));
 }
 public MemberInitExpressionProxy(MemberInitExpression node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
Пример #22
0
        /// <summary>
        /// Creates a <see cref="DebugInfoExpression"/> for clearing a sequence point.
        /// </summary>
        /// <param name="document">The <see cref="SymbolDocumentInfo"/> that represents the source file.</param>
        /// <returns>An instance of <see cref="DebugInfoExpression"/> for clearning a sequence point.</returns>
        public static DebugInfoExpression ClearDebugInfo(SymbolDocumentInfo document)
        {
            ContractUtils.RequiresNotNull(document, "document");

            return(new ClearDebugInfoExpression(document));
        }
 public NewArrayExpressionProxy(NewArrayExpression node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="DeleteIndexBinder" />.
 /// </summary>
 /// <param name="callInfo">The signature of the arguments at the call site.</param>
 protected DeleteIndexBinder(CallInfo callInfo)
 {
     ContractUtils.RequiresNotNull(callInfo, "callInfo");
     _callInfo = callInfo;
 }
 public RuntimeVariablesExpressionProxy(RuntimeVariablesExpression node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
Пример #26
0
 /// <summary>
 /// EventInfo.EventHandlerType getter is marked SecuritySafeCritical in CoreCLR
 /// This method is to get to the property without using Reflection
 /// </summary>
 /// <param name="eventInfo"></param>
 /// <returns></returns>
 public static Type GetEventHandlerType(EventInfo eventInfo)
 {
     ContractUtils.RequiresNotNull(eventInfo, nameof(eventInfo));
     return(eventInfo.EventHandlerType);
 }
 public BlockExpressionProxy(BlockExpression node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
Пример #28
0
        /// <summary>
        /// Performs the runtime binding of the dynamic operation on a set of arguments.
        /// </summary>
        /// <param name="args">An array of arguments to the dynamic operation.</param>
        /// <param name="parameters">The array of <see cref="ParameterExpression"/> instances that represent the parameters of the call site in the binding process.</param>
        /// <param name="returnLabel">A LabelTarget used to return the result of the dynamic binding.</param>
        /// <returns>
        /// An Expression that performs tests on the dynamic operation arguments, and
        /// performs the dynamic operation if the tests are valid. If the tests fail on
        /// subsequent occurrences of the dynamic operation, Bind will be called again
        /// to produce a new <see cref="Expression"/> for the new argument types.
        /// </returns>
        public sealed override Expression Bind(object[] args, ReadOnlyCollection <ParameterExpression> parameters, LabelTarget returnLabel)
        {
            ContractUtils.RequiresNotNull(args, nameof(args));
            ContractUtils.RequiresNotNull(parameters, nameof(parameters));
            ContractUtils.RequiresNotNull(returnLabel, nameof(returnLabel));
            if (args.Length == 0)
            {
                throw System.Linq.Expressions.Error.OutOfRange("args.Length", 1);
            }
            if (parameters.Count == 0)
            {
                throw System.Linq.Expressions.Error.OutOfRange("parameters.Count", 1);
            }
            if (args.Length != parameters.Count)
            {
                throw new ArgumentOutOfRangeException(nameof(args));
            }

            // Ensure that the binder's ReturnType matches CallSite's return
            // type. We do this so meta objects and language binders can
            // compose trees together without needing to insert converts.
            Type expectedResult;

            if (IsStandardBinder)
            {
                expectedResult = ReturnType;

                if (returnLabel.Type != typeof(void) &&
                    !TypeUtils.AreReferenceAssignable(returnLabel.Type, expectedResult))
                {
                    throw System.Linq.Expressions.Error.BinderNotCompatibleWithCallSite(expectedResult, this, returnLabel.Type);
                }
            }
            else
            {
                // Even for non-standard binders, we have to at least make sure
                // it works with the CallSite's type to build the return.
                expectedResult = returnLabel.Type;
            }

            DynamicMetaObject target = DynamicMetaObject.Create(args[0], parameters[0]);

            DynamicMetaObject[] metaArgs = CreateArgumentMetaObjects(args, parameters);

            DynamicMetaObject binding = Bind(target, metaArgs);

            if (binding == null)
            {
                throw System.Linq.Expressions.Error.BindingCannotBeNull();
            }

            Expression          body         = binding.Expression;
            BindingRestrictions restrictions = binding.Restrictions;

            // Ensure the result matches the expected result type.
            if (expectedResult != typeof(void) &&
                !TypeUtils.AreReferenceAssignable(expectedResult, body.Type))
            {
                //
                // Blame the last person that handled the result: assume it's
                // the dynamic object (if any), otherwise blame the language.
                //
                if (target.Value is IDynamicMetaObjectProvider)
                {
                    throw System.Linq.Expressions.Error.DynamicObjectResultNotAssignable(body.Type, target.Value.GetType(), this, expectedResult);
                }
                else
                {
                    throw System.Linq.Expressions.Error.DynamicBinderResultNotAssignable(body.Type, this, expectedResult);
                }
            }

            // if the target is IDO, standard binders ask it to bind the rule so we may have a target-specific binding.
            // it makes sense to restrict on the target's type in such cases.
            // ideally IDO metaobjects should do this, but they often miss that type of "this" is significant.
            if (IsStandardBinder && args[0] is IDynamicMetaObjectProvider)
            {
                if (restrictions == BindingRestrictions.Empty)
                {
                    throw System.Linq.Expressions.Error.DynamicBindingNeedsRestrictions(target.Value !.GetType(), this);
                }
            }

            // Add the return
            if (body.NodeType != ExpressionType.Goto)
            {
                body = Expression.Return(returnLabel, body);
            }

            // Finally, add restrictions
            if (restrictions != BindingRestrictions.Empty)
            {
                body = Expression.IfThen(restrictions.ToExpression(), body);
            }

            return(body);
        }
 public TypeBinaryExpressionProxy(TypeBinaryExpression node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
Пример #30
0
 /// <summary>
 /// Constructs a <see cref="ReadOnlyCollectionBuilder{T}"/> with a given initial capacity.
 /// The contents are empty but builder will have reserved room for the given
 /// number of elements before any reallocations are required.
 /// </summary>
 /// <param name="capacity">Initial capacity of the builder.</param>
 public ReadOnlyCollectionBuilder(int capacity)
 {
     ContractUtils.Requires(capacity >= 0, nameof(capacity));
     _items = new T[capacity];
 }