Beispiel #1
0
 static Compiler()
 {
     int num;
     DottedLocalsTupleType = MutableTuple.MakeTupleType(SpecialVariables.AutomaticVariableTypes);
     DottedScriptCmdletLocalsTupleType = MutableTuple.MakeTupleType(SpecialVariables.AutomaticVariableTypes.Concat<Type>(SpecialVariables.PreferenceVariableTypes).ToArray<Type>());
     DottedLocalsNameIndexMap = new Dictionary<string, int>(SpecialVariables.AutomaticVariableTypes.Length, StringComparer.OrdinalIgnoreCase);
     DottedScriptCmdletLocalsNameIndexMap = new Dictionary<string, int>(SpecialVariables.AutomaticVariableTypes.Length + SpecialVariables.PreferenceVariableTypes.Length, StringComparer.OrdinalIgnoreCase);
     _attributeGeneratorCache = new Dictionary<CallInfo, Delegate>();
     _functionContext = Expression.Parameter(typeof(FunctionContext), "funcContext");
     _executionContextParameter = Expression.Variable(typeof(System.Management.Automation.ExecutionContext), "context");
     _outputPipeParameter = Expression.Variable(typeof(Pipe), "pipe");
     _setDollarQuestionToTrue = Expression.Assign(Expression.Property(_executionContextParameter, CachedReflectionInfo.ExecutionContext_QuestionMarkVariableValue), ExpressionCache.TrueConstant);
     _callCheckForInterrupts = Expression.Call(CachedReflectionInfo.PipelineOps_CheckForInterrupts, _executionContextParameter);
     _getCurrentPipe = Expression.Field(_functionContext, CachedReflectionInfo.FunctionContext__outputPipe);
     ParameterExpression variable = Expression.Variable(typeof(Exception), "exception");
     _catchFlowControl = Expression.Catch(typeof(FlowControlException), Expression.Rethrow());
     CatchBlock block = Expression.Catch(variable, Expression.Block(new Expression[] { Expression.Call(CachedReflectionInfo.ExceptionHandlingOps_CheckActionPreference, _functionContext, variable) }));
     _stmtCatchHandlers = new CatchBlock[] { _catchFlowControl, block };
     _currentExceptionBeingHandled = Expression.Property(_executionContextParameter, CachedReflectionInfo.ExecutionContext_CurrentExceptionBeingHandled);
     for (num = 0; num < SpecialVariables.AutomaticVariables.Length; num++)
     {
         DottedLocalsNameIndexMap.Add(SpecialVariables.AutomaticVariables[num], num);
         DottedScriptCmdletLocalsNameIndexMap.Add(SpecialVariables.AutomaticVariables[num], num);
     }
     for (num = 0; num < SpecialVariables.PreferenceVariables.Length; num++)
     {
         DottedScriptCmdletLocalsNameIndexMap.Add(SpecialVariables.PreferenceVariables[num], num + 9);
     }
 }
            private new RemoteLinq.CatchBlock VisitCatch(SystemLinq.CatchBlock catchBlock)
            {
                var body     = Visit(catchBlock.Body).Unwrap();
                var filter   = Visit(catchBlock.Filter).UnwrapNullable();
                var variable = Visit(catchBlock.Variable).UnwrapNullable() as RemoteLinq.ParameterExpression;

                return(new RemoteLinq.CatchBlock(_typeInfoProvider.GetTypeInfo(catchBlock.Test), variable, body, filter));
            }
Beispiel #3
0
 internal static CatchBlock Serialize(E.CatchBlock handler)
 {
     return(new CatchBlock()
     {
         Test = handler.Variable == null
             ? TypeRef.Serialize(handler.Test)
             : null,
         Variable = handler.Variable.Null(v => Node.Parameter(v)),
         Filter = handler.Filter.Null(e => Node.Serialize(e)),
         Body = Node.Serialize(handler.Body),
     });
 }
        private static System.Linq.Expressions.CatchBlock[] ToCatchBlocks(IReadOnlyList <CatchBlock> hs)
        {
            if (hs == null)
            {
                return(Tools.Empty <System.Linq.Expressions.CatchBlock>());
            }
            var catchBlocks = new System.Linq.Expressions.CatchBlock[hs.Count];

            for (var i = 0; i < hs.Count; ++i)
            {
                catchBlocks[i] = hs[i].ToCatchBlock();
            }
            return(catchBlocks);
        }
        /// <summary>
        /// Checks if the specified catch <paramref name="block"/> contains an unconditional rethrow statement.
        /// </summary>
        /// <param name="block">The catch block to check.</param>
        /// <returns><c>true</c> if the catch block has an unconditional rethrow; otherwise, <c>false</c>.</returns>
        private static bool IsRethrow(CatchBlock block)
        {
            if (block.Filter == null)
            {
                if (block.Body.NodeType == ExpressionType.Throw)
                {
                    var @throw = (UnaryExpression)block.Body;
                    if (@throw.Operand == null)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #6
0
 protected override CatchBlock VisitCatchBlock(CatchBlock node)
 {
     Out(Flow.NewLine, "} catch (" + node.Test.Name);
     if (node.Variable != null)
     {
         Out(Flow.Space, node.Variable.Name ?? "");
     }
     if (node.Filter != null)
     {
         Out(") if (", Flow.Break);
         Visit(node.Filter);
     }
     Out(") {", Flow.NewLine);
     Indent();
     Visit(node.Body);
     Dedent();
     return(node);
 }
Beispiel #7
0
 protected override CatchBlock VisitCatchBlock(CatchBlock node)
 {
     this.Out(Flow.NewLine, "} .Catch (" + node.Test.ToString());
     if (node.Variable != null)
     {
         this.Out(Flow.Space, "");
         this.VisitParameter(node.Variable);
     }
     if (node.Filter != null)
     {
         this.Out(") .If (", Flow.Break);
         this.Visit(node.Filter);
     }
     this.Out(") {", Flow.NewLine);
     this.Indent();
     this.Visit(node.Body);
     this.Dedent();
     return(node);
 }
        protected override MSAst.CatchBlock VisitCatchBlock(MSAst.CatchBlock node)
        {
            MSAst.ParameterExpression v = VisitAndConvert(node.Variable, "VisitCatchBlock");

            MSAst.Expression f;
            MSAst.Expression b;

            _insideConditionalBlock = true;
            try {
                f = Visit(node.Filter);
                b = Visit(node.Body);
            } finally {
                _insideConditionalBlock = false;
            }

            if (v == node.Variable && b == node.Body && f == node.Filter)
            {
                return(node);
            }
            return(Ast.MakeCatchBlock(node.Test, v, b, f));
        }
Beispiel #9
0
            protected override CatchBlock VisitCatchBlock(CatchBlock node)
            {
                if (node.Variable != null)
                {
                    _environment.Push(new[] { node.Variable });
                }

                //
                // Just visit children to perform inlining of constants or defaults. Note that the parent
                // try expression requires that non-trivial bindings are satisfied by the protected region
                // so we don't have to worry about that over here.
                //

                var filter = Visit(node.Filter);
                var body   = Visit(node.Body);

                if (node.Variable != null)
                {
                    _environment.Pop();
                }

                return(node.Update(node.Variable, filter, body));
            }
        protected override CatchBlock VisitCatchBlock(CatchBlock node)
        {
            var args = new List <object>();

            if (node.Variable != null)
            {
                args.Add(new XElement(nameof(node.Variable), Visit(node.Variable)));
            }
            else
            {
                args.Add(new XAttribute(nameof(node.Test), node.Test));
            }

            args.Add(new XElement(nameof(node.Body), Visit(node.Body)));

            if (node.Filter != null)
            {
                args.Add(new XElement(nameof(node.Filter), Visit(node.Filter)));
            }

            _nodes.Push(new XElement(nameof(CatchBlock), args));

            return(node);
        }
Beispiel #11
0
 public CatchBlockProxy(CatchBlock node)
 {
     ArgumentNullException.ThrowIfNull(node);
     _node = node;
 }
Beispiel #12
0
        protected virtual new CatchBlock VisitCatchBlock(CatchBlock node)
        {
            Contract.Requires(node != null);

            return(default(CatchBlock));
        }
 public CatchBlockProxy(CatchBlock node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
Beispiel #14
0
 public CatchBlockProxy(CatchBlock node)
 {
     _node = node;
 }
Beispiel #15
0
 private static CatchBlock[] GenerateLoopBreakContinueCatchBlocks(string label, LabelTarget breakLabel, LabelTarget continueLabel)
 {
     ParameterExpression variable = Expression.Parameter(typeof(BreakException));
     ParameterExpression expression2 = Expression.Parameter(typeof(ContinueException));
     CatchBlock[] blockArray = new CatchBlock[2];
     Expression[] arguments = new Expression[] { Expression.Constant(label ?? "", typeof(string)) };
     blockArray[0] = Expression.Catch(variable, Expression.IfThenElse(Expression.Call(variable, CachedReflectionInfo.LoopFlowException_MatchLabel, arguments), Expression.Break(breakLabel), Expression.Rethrow()));
     Expression[] expressionArray2 = new Expression[] { Expression.Constant(label ?? "", typeof(string)) };
     blockArray[1] = Expression.Catch(expression2, Expression.IfThenElse(Expression.Call(expression2, CachedReflectionInfo.LoopFlowException_MatchLabel, expressionArray2), Expression.Continue(continueLabel), Expression.Rethrow()));
     return blockArray;
 }
 protected override CatchBlock VisitCatchBlock(CatchBlock node)
 {
     return node; // NB: In nested catch blocks, the meaning of a rethrow changes.
 }
Beispiel #17
0
        public override DLR.Expression Generate(AplusScope scope)
        {
            // TODO: Add usage of Protected Execute Flag

            // Save the previous return target
            DLR.LabelTarget oldTarget = scope.ReturnTarget;
            scope.ReturnTarget = DLR.Expression.Label(typeof(AType), "EXIT");

            DLR.Expression protectedCode = DLR.Expression.Label(
                scope.ReturnTarget,
                this.codeblock.Generate(scope)
                );

            // Restore the return target;
            scope.ReturnTarget = oldTarget;

            // Code block contining the strandard execution's result
            // wrapped in a strand
            DLR.Expression block =
                DLR.Expression.Call(
                    typeof(Runtime.Helpers).GetMethod("BuildStrand"),
                    DLR.Expression.NewArrayInit(
                        typeof(AType),
                        // We need to pass in reverse order
                        protectedCode,
                        DLR.Expression.Constant(AInteger.Create(0), typeof(AType))
                        )
                    );

            // Parameter for Catch block
            DLR.ParameterExpression errorVariable = DLR.Expression.Parameter(typeof(Error), "error");

            // Catch block, returns the ([errorcode]; [errortext]) strand
            DLR.CatchBlock catchBlock = DLR.Expression.Catch(
                errorVariable,
                DLR.Expression.Call(
                    typeof(Runtime.Helpers).GetMethod("BuildStrand"),
                    DLR.Expression.NewArrayInit(
                        typeof(AType),
                        // We need to pass in reverse order
                        // Error Text
                        DLR.Expression.Call(
                            typeof(Runtime.Helpers).GetMethod("BuildString"),
                            DLR.Expression.Property(errorVariable, "ErrorText")
                            ),
                        // Error Code
                        DLR.Expression.Call(
                            typeof(AInteger).GetMethod("Create", new Type[] { typeof(int) }),
                            DLR.Expression.Convert(
                                DLR.Expression.Property(errorVariable, "ErrorType"),
                                typeof(int)
                                )
                            )
                        )
                    )
                );

            DLR.Expression result = DLR.Expression.TryCatch(
                block,
                catchBlock
                );

            return(result);
        }
 protected virtual new CatchBlock VisitCatchBlock(CatchBlock node)
 {
     return(default(CatchBlock));
 }
        /// <summary>
        /// Checks if the specified catch <paramref name="block"/> in unreachable due to a constant filter
        /// expression that always returns <c>false</c>.
        /// </summary>
        /// <param name="block">The catch block to check.</param>
        /// <returns><c>true</c> if the catch block is unreachable; otherwise, <c>false</c>.</returns>
        private bool HasUnreachableFilter(CatchBlock block)
        {
            var filter = block.Filter;

            return(filter != null && HasConstantValue(filter) && !(bool)GetConstantValue(filter));
        }
 /// <summary>
 /// Gets the debug view for the specified catch block.
 /// </summary>
 /// <param name="catchBlock">The catch block to get a debug view for.</param>
 /// <returns>Debug view for the specified catch block.</returns>
 public XNode GetDebugView(CatchBlock catchBlock)
 {
     return(Visit(catchBlock));
 }
Beispiel #21
0
 protected virtual CatchBlock VisitCatchBlock(CatchBlock node)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Makes a catch block slim object representing a CatchBlock with the given children.
        /// </summary>
        /// <param name="node">Original catch block.</param>
        /// <param name="variable">Variable expression slim.</param>
        /// <param name="body">Body expression slim.</param>
        /// <param name="filter">Filter expression slim.</param>
        /// <returns>Slim representation of the original catch block.</returns>
        protected override CatchBlockSlim MakeCatchBlock(CatchBlock node, ParameterExpressionSlim variable, ExpressionSlim body, ExpressionSlim filter)
        {
            var test = MakeType(node.Test);

            return(_factory.MakeCatchBlock(test, variable, body, filter));
        }
Beispiel #23
0
 private CatchBlock VisitCatchBlockExtracted(CatchBlock node)
 {
     return(node.Update(node.Variable == null ? null : VisitAndConvert(node.Variable, nameof(VisitCatchBlock)), Visit(node.Filter), Visit(node.Body)));
 }
 private DynamicMetaObject BinaryComparision(DynamicMetaObject target, DynamicMetaObject arg, Func<Expression, Expression> toResult)
 {
     bool flag = false;
     Expression expression;
     Expression boxedTrue;
     Expression expression1;
     Expression stringComparisonInvariantCultureIgnoreCase;
     if (!target.LimitType.Equals(typeof(string)))
     {
         Type limitType = target.LimitType;
         LanguagePrimitives.ConversionData conversionDatum = LanguagePrimitives.FigureConversion(arg.Value, limitType, out flag);
         DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1];
         dynamicMetaObjectArray[0] = arg;
         BindingRestrictions bindingRestriction = target.CombineRestrictions(dynamicMetaObjectArray);
         bindingRestriction = bindingRestriction.Merge(BinderUtils.GetOptionalVersionAndLanguageCheckForType(this, limitType, this._version));
         if (conversionDatum.Rank != ConversionRank.Identity)
         {
             ParameterExpression parameterExpression = Expression.Parameter(typeof(InvalidCastException));
             CatchBlock[] catchBlockArray = new CatchBlock[1];
             Expression[] expressionArray = new Expression[3];
             expressionArray[0] = Expression.Dynamic(PSToStringBinder.Get(), typeof(string), target.Expression, ExpressionCache.GetExecutionContextFromTLS);
             expressionArray[1] = Expression.Dynamic(PSToStringBinder.Get(), typeof(string), arg.Expression, ExpressionCache.GetExecutionContextFromTLS);
             expressionArray[2] = Expression.Property(parameterExpression, CachedReflectionInfo.Exception_Message);
             catchBlockArray[0] = Expression.Catch(parameterExpression, Compiler.ThrowRuntimeErrorWithInnerException("ComparisonFailure", Expression.Constant(ExtendedTypeSystem.ComparisonFailure), parameterExpression, limitType, expressionArray));
             expression = Expression.TryCatch(PSConvertBinder.InvokeConverter(conversionDatum, arg.Expression, limitType, flag, ExpressionCache.InvariantCulture), catchBlockArray);
         }
         else
         {
             expression = arg.Expression;
         }
         if (target.LimitType.Equals(arg.LimitType))
         {
             Type[] interfaces = target.Value.GetType().GetInterfaces();
             int num = 0;
             while (num < (int)interfaces.Length)
             {
                 Type type = interfaces[num];
                 if (!type.IsGenericType || !(type.GetGenericTypeDefinition() == typeof(IComparable<>)))
                 {
                     num++;
                 }
                 else
                 {
                     Expression[] expressionArray1 = new Expression[1];
                     expressionArray1[0] = expression.Cast(arg.LimitType);
                     DynamicMetaObject dynamicMetaObject = new DynamicMetaObject(toResult(Expression.Call(Expression.Convert(target.Expression, type), type.GetMethod("CompareTo"), expressionArray1)).Cast(typeof(object)), bindingRestriction);
                     return dynamicMetaObject;
                 }
             }
         }
         if (target.Value as IComparable == null)
         {
             Expression[] expression2 = new Expression[1];
             expression2[0] = target.Expression;
             Expression expression3 = Compiler.ThrowRuntimeError("NotIcomparable", ExtendedTypeSystem.NotIcomparable, this.ReturnType, expression2);
             Expression[] expressionArray2 = new Expression[1];
             expressionArray2[0] = arg.Expression.Cast(typeof(object));
             MethodCallExpression methodCallExpression = Expression.Call(target.Expression.Cast(typeof(object)), CachedReflectionInfo.Object_Equals, expressionArray2);
             if (base.Operation == ExpressionType.GreaterThanOrEqual || base.Operation == ExpressionType.LessThanOrEqual)
             {
                 boxedTrue = ExpressionCache.BoxedTrue;
             }
             else
             {
                 boxedTrue = ExpressionCache.BoxedFalse;
             }
             return new DynamicMetaObject(Expression.Condition(methodCallExpression, boxedTrue, expression3), bindingRestriction);
         }
         else
         {
             Expression[] expressionArray3 = new Expression[1];
             expressionArray3[0] = expression.Cast(typeof(object));
             return new DynamicMetaObject(toResult(Expression.Call(target.Expression.Cast(typeof(IComparable)), CachedReflectionInfo.IComparable_CompareTo, expressionArray3)).Cast(typeof(object)), bindingRestriction);
         }
     }
     else
     {
         Expression expression4 = target.Expression.Cast(typeof(string));
         if (!arg.LimitType.Equals(typeof(string)))
         {
             expression1 = Expression.Dynamic(PSToStringBinder.Get(), typeof(string), arg.Expression, ExpressionCache.GetExecutionContextFromTLS);
         }
         else
         {
             expression1 = arg.Expression.Cast(typeof(string));
         }
         Expression expression5 = expression1;
         MethodInfo stringCompare = CachedReflectionInfo.String_Compare;
         Expression expression6 = expression4;
         Expression expression7 = expression5;
         if (this._ignoreCase)
         {
             stringComparisonInvariantCultureIgnoreCase = ExpressionCache.StringComparisonInvariantCultureIgnoreCase;
         }
         else
         {
             stringComparisonInvariantCultureIgnoreCase = ExpressionCache.StringComparisonInvariantCulture;
         }
         MethodCallExpression methodCallExpression1 = Expression.Call(stringCompare, expression6, expression7, stringComparisonInvariantCultureIgnoreCase);
         DynamicMetaObject[] dynamicMetaObjectArray1 = new DynamicMetaObject[1];
         dynamicMetaObjectArray1[0] = arg;
         return new DynamicMetaObject(toResult(methodCallExpression1).Cast(typeof(object)), target.CombineRestrictions(dynamicMetaObjectArray1));
     }
 }
 public CatchBlockProxy(CatchBlock node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
Beispiel #26
0
 private static CatchBlock VisitCatchBlock(CatchBlock node)
 {
     throw new NotImplementedException();
 }
    public virtual bool IsEvaluatableCatchBlock (CatchBlock node)
    {
      ArgumentUtility.CheckNotNull ("node", node);

      return true;
    }
		public virtual void Write (CatchBlock block)
		{
			VisitCatchBlock (block);
		}
 public CatchBlockProxy(CatchBlock node) {
     _node = node;
 }
 private DynamicMetaObject BinaryNumericStringOp(DynamicMetaObject target, DynamicMetaObject arg)
 {
     Expression number;
     Expression boxedFalse;
     List<ParameterExpression> parameterExpressions = new List<ParameterExpression>();
     List<Expression> expressions = new List<Expression>();
     Expression expression = target.Expression;
     if (target.LimitType.Equals(typeof(string)))
     {
         expression = PSBinaryOperationBinder.ConvertStringToNumber(target.Expression, arg.LimitType);
     }
     if (arg.LimitType.Equals(typeof(string)))
     {
         number = PSBinaryOperationBinder.ConvertStringToNumber(arg.Expression, target.LimitType);
     }
     else
     {
         number = arg.Expression;
     }
     Expression expression1 = number;
     expressions.Add(Expression.Dynamic(PSBinaryOperationBinder.Get(base.Operation, true, false), typeof(object), expression, expression1));
     Expression expression2 = Expression.Block(parameterExpressions, expressions);
     if (base.Operation == ExpressionType.Equal || base.Operation == ExpressionType.NotEqual)
     {
         Expression expression3 = expression2;
         CatchBlock[] catchBlockArray = new CatchBlock[1];
         CatchBlock[] catchBlockArray1 = catchBlockArray;
         int num = 0;
         Type type = typeof(InvalidCastException);
         if (base.Operation == ExpressionType.Equal)
         {
             boxedFalse = ExpressionCache.BoxedFalse;
         }
         else
         {
             boxedFalse = ExpressionCache.BoxedTrue;
         }
         catchBlockArray1[num] = Expression.Catch(type, boxedFalse);
         expression2 = Expression.TryCatch(expression3, catchBlockArray);
     }
     DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1];
     dynamicMetaObjectArray[0] = arg;
     return new DynamicMetaObject(expression2, target.CombineRestrictions(dynamicMetaObjectArray));
 }
Beispiel #31
0
 /// <summary>
 /// Visits the children of the <see cref="CatchBlock"/>.
 /// </summary>
 /// <param name="node">The expression to visit.</param>
 /// <returns>The modified expression, if it or any subexpression was modified;
 /// otherwise, returns the original expression.</returns>
 protected virtual CatchBlock VisitCatchBlock(CatchBlock node)
 {
     return(node.Update(VisitAndConvert(node.Variable, nameof(VisitCatchBlock)), Visit(node.Filter), Visit(node.Body)));
 }
Beispiel #32
0
        static Compiler()
        {
            _functionContext = Expression.Parameter(typeof(FunctionContext), "funcContext");
            _executionContextParameter = Expression.Variable(typeof(ExecutionContext), "context");

            s_setDollarQuestionToTrue = Expression.Assign(
                Expression.Property(_executionContextParameter, CachedReflectionInfo.ExecutionContext_QuestionMarkVariableValue),
                ExpressionCache.TrueConstant);

            s_callCheckForInterrupts = Expression.Call(CachedReflectionInfo.PipelineOps_CheckForInterrupts,
                                                      _executionContextParameter);

            s_getCurrentPipe = Expression.Field(_functionContext, CachedReflectionInfo.FunctionContext__outputPipe);
            _returnPipe = Expression.Variable(s_getCurrentPipe.Type, "returnPipe");

            var exception = Expression.Variable(typeof(Exception), "exception");

            s_catchFlowControl = Expression.Catch(typeof(FlowControlException), Expression.Rethrow());
            var catchAll = Expression.Catch(
                exception,
                Expression.Block(
                    Expression.Call(
                        CachedReflectionInfo.ExceptionHandlingOps_CheckActionPreference,
                            Compiler._functionContext, exception)));
            _stmtCatchHandlers = new CatchBlock[] { s_catchFlowControl, catchAll };

            s_currentExceptionBeingHandled = Expression.Property(
                _executionContextParameter, CachedReflectionInfo.ExecutionContext_CurrentExceptionBeingHandled);

            int i;
            for (i = 0; i < SpecialVariables.AutomaticVariables.Length; ++i)
            {
                DottedLocalsNameIndexMap.Add(SpecialVariables.AutomaticVariables[i], i);
                DottedScriptCmdletLocalsNameIndexMap.Add(SpecialVariables.AutomaticVariables[i], i);
            }
            for (i = 0; i < SpecialVariables.PreferenceVariables.Length; ++i)
            {
                DottedScriptCmdletLocalsNameIndexMap.Add(SpecialVariables.PreferenceVariables[i],
                                                         i + (int)AutomaticVariable.NumberOfAutomaticVariables);
            }

            s_builtinAttributeGenerator.Add(typeof(CmdletBindingAttribute), NewCmdletBindingAttribute);
            s_builtinAttributeGenerator.Add(typeof(ParameterAttribute), NewParameterAttribute);
            s_builtinAttributeGenerator.Add(typeof(OutputTypeAttribute), NewOutputTypeAttribute);
            s_builtinAttributeGenerator.Add(typeof(AliasAttribute), NewAliasAttribute);
            s_builtinAttributeGenerator.Add(typeof(ValidateSetAttribute), NewValidateSetAttribute);
            s_builtinAttributeGenerator.Add(typeof(DebuggerHiddenAttribute), NewDebuggerHiddenAttribute);
            s_builtinAttributeGenerator.Add(typeof(ValidateNotNullAttribute), NewValidateNotNullAttribute);
            s_builtinAttributeGenerator.Add(typeof(ValidateNotNullOrEmptyAttribute), NewValidateNotNullOrEmptyAttribute);
        }
 protected override CatchBlock VisitCatchBlock(CatchBlock node)
 {
     throw new NotSupportedException();
 }
        //protected internal virtual Expression VisitBinary(BinaryExpression node)
        //{
        //    return (Expression)null;
        //}

        //protected internal virtual Expression VisitBlock(BlockExpression node)
        //{
        //    return (Expression)null;
        //}

        protected virtual CatchBlock VisitCatchBlock(CatchBlock node)
        {
            return((CatchBlock)null);
        }
 private DynamicMetaObject BinaryEqualityComparison(DynamicMetaObject target, DynamicMetaObject arg)
 {
     bool flag = false;
     Func<Expression, Expression> func;
     MethodInfo charOpsCompareIeq;
     Expression expression;
     if (base.Operation == ExpressionType.NotEqual)
     {
         func = new Func<Expression, Expression>(Expression.Not);
     }
     else
     {
         func = (Expression e) => e;
     }
     Func<Expression, Expression> func1 = func;
     if (!target.LimitType.Equals(typeof(string)))
     {
         if (target.LimitType.Equals(typeof(char)) && this._ignoreCase)
         {
             Expression expression1 = null;
             BindingRestrictions bindingRestriction = null;
             if (!arg.LimitType.Equals(typeof(char)))
             {
                 string value = arg.Value as string;
                 if (value != null && value.Length == 1)
                 {
                     Expression[] expressionArray = new Expression[1];
                     expressionArray[0] = ExpressionCache.Constant(0);
                     expression1 = Expression.Call(arg.Expression.Cast(typeof(string)), CachedReflectionInfo.String_get_Chars, expressionArray);
                     bindingRestriction = arg.PSGetTypeRestriction().Merge(BindingRestrictions.GetExpressionRestriction(Expression.Equal(Expression.Property(arg.Expression.Cast(typeof(string)), CachedReflectionInfo.String_Length), ExpressionCache.Constant(1))));
                 }
             }
             else
             {
                 expression1 = arg.Expression;
                 bindingRestriction = arg.PSGetTypeRestriction();
             }
             if (expression1 != null)
             {
                 if (base.Operation == ExpressionType.Equal)
                 {
                     charOpsCompareIeq = CachedReflectionInfo.CharOps_CompareIeq;
                 }
                 else
                 {
                     charOpsCompareIeq = CachedReflectionInfo.CharOps_CompareIne;
                 }
                 return new DynamicMetaObject(Expression.Call(charOpsCompareIeq, target.Expression.Cast(typeof(char)), expression1.Cast(typeof(char))), target.PSGetTypeRestriction().Merge(bindingRestriction));
             }
         }
         Expression[] expressionArray1 = new Expression[1];
         expressionArray1[0] = arg.Expression.Cast(typeof(object));
         Expression expression2 = Expression.Call(target.Expression.Cast(typeof(object)), CachedReflectionInfo.Object_Equals, expressionArray1);
         Type limitType = target.LimitType;
         LanguagePrimitives.ConversionData conversionDatum = LanguagePrimitives.FigureConversion(arg.Value, limitType, out flag);
         if (conversionDatum.Rank != ConversionRank.Identity)
         {
             DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1];
             dynamicMetaObjectArray[0] = arg;
             BindingRestrictions bindingRestriction1 = target.CombineRestrictions(dynamicMetaObjectArray);
             bindingRestriction1 = bindingRestriction1.Merge(BinderUtils.GetOptionalVersionAndLanguageCheckForType(this, limitType, this._version));
             ParameterExpression parameterExpression = Expression.Parameter(typeof(bool));
             Expression[] expressionArray2 = new Expression[1];
             expressionArray2[0] = PSConvertBinder.InvokeConverter(conversionDatum, arg.Expression, limitType, flag, ExpressionCache.InvariantCulture).Cast(typeof(object));
             Expression expression3 = Expression.Call(target.Expression.Cast(typeof(object)), CachedReflectionInfo.Object_Equals, expressionArray2);
             ParameterExpression[] parameterExpressionArray = new ParameterExpression[1];
             parameterExpressionArray[0] = parameterExpression;
             Expression[] expressionArray3 = new Expression[3];
             expressionArray3[0] = Expression.Assign(parameterExpression, expression2);
             CatchBlock[] catchBlockArray = new CatchBlock[1];
             catchBlockArray[0] = Expression.Catch(typeof(InvalidCastException), Expression.Assign(parameterExpression, ExpressionCache.Constant(false)));
             expressionArray3[1] = Expression.IfThen(Expression.Not(parameterExpression), Expression.TryCatch(Expression.Assign(parameterExpression, expression3), catchBlockArray));
             expressionArray3[2] = func1(parameterExpression);
             BlockExpression blockExpression = Expression.Block(parameterExpressionArray, expressionArray3);
             return new DynamicMetaObject(blockExpression.Cast(typeof(object)), bindingRestriction1);
         }
         else
         {
             DynamicMetaObject[] dynamicMetaObjectArray1 = new DynamicMetaObject[1];
             dynamicMetaObjectArray1[0] = arg;
             return new DynamicMetaObject(func1(expression2).Cast(typeof(object)), target.CombineRestrictions(dynamicMetaObjectArray1));
         }
     }
     else
     {
         Expression expression4 = target.Expression.Cast(typeof(string));
         if (!arg.LimitType.Equals(typeof(string)))
         {
             expression = Expression.Dynamic(PSToStringBinder.Get(), typeof(string), arg.Expression, ExpressionCache.GetExecutionContextFromTLS);
         }
         else
         {
             expression = arg.Expression.Cast(typeof(string));
         }
         Expression expression5 = expression;
         DynamicMetaObject[] dynamicMetaObjectArray2 = new DynamicMetaObject[1];
         dynamicMetaObjectArray2[0] = arg;
         return new DynamicMetaObject(func1(Compiler.CallStringEquals(expression4, expression5, this._ignoreCase)).Cast(typeof(object)), target.CombineRestrictions(dynamicMetaObjectArray2));
     }
 }
 protected virtual CatchBlock VisitCatchBlock(CatchBlock node)
 {
     return(node.Update(this.VisitAndConvert <ParameterExpression>(node.Variable, "VisitCatchBlock"), this.Visit(node.Filter), this.Visit(node.Body)));
 }
 private DynamicMetaObject BinaryNumericOp(string methodName, DynamicMetaObject target, DynamicMetaObject arg)
 {
     TypeCode typeCode;
     Expression boxedFalse;
     Type type = null;
     Type type1 = null;
     TypeCode typeCode1 = LanguagePrimitives.GetTypeCode(target.LimitType);
     TypeCode typeCode2 = LanguagePrimitives.GetTypeCode(arg.LimitType);
     if (typeCode1 >= typeCode2)
     {
         typeCode = typeCode1;
     }
     else
     {
         typeCode = typeCode2;
     }
     TypeCode typeCode3 = typeCode;
     if (typeCode3 > TypeCode.Int32)
     {
         if (typeCode3 > TypeCode.UInt32)
         {
             if (typeCode3 > TypeCode.Int64)
             {
                 if (typeCode3 > TypeCode.UInt64)
                 {
                     if (typeCode3 != TypeCode.Decimal)
                     {
                         type = typeof(DoubleOps);
                         type1 = typeof(double);
                     }
                     else
                     {
                         if (methodName.StartsWith("Compare", StringComparison.Ordinal))
                         {
                             if (!LanguagePrimitives.IsFloating(typeCode1))
                             {
                                 if (LanguagePrimitives.IsFloating(typeCode2))
                                 {
                                     DynamicMetaObject[] dynamicMetaObjectArray = new DynamicMetaObject[1];
                                     dynamicMetaObjectArray[0] = arg;
                                     return new DynamicMetaObject(Expression.Call(typeof(DecimalOps).GetMethod(string.Concat(methodName, "2"), BindingFlags.Static | BindingFlags.NonPublic), target.Expression.Cast(target.LimitType).Cast(typeof(decimal)), arg.Expression.Cast(arg.LimitType).Cast(typeof(double))), target.CombineRestrictions(dynamicMetaObjectArray));
                                 }
                             }
                             else
                             {
                                 DynamicMetaObject[] dynamicMetaObjectArray1 = new DynamicMetaObject[1];
                                 dynamicMetaObjectArray1[0] = arg;
                                 return new DynamicMetaObject(Expression.Call(typeof(DecimalOps).GetMethod(string.Concat(methodName, "1"), BindingFlags.Static | BindingFlags.NonPublic), target.Expression.Cast(target.LimitType).Cast(typeof(double)), arg.Expression.Cast(arg.LimitType).Cast(typeof(decimal))), target.CombineRestrictions(dynamicMetaObjectArray1));
                             }
                         }
                         type = typeof(DecimalOps);
                         type1 = typeof(decimal);
                     }
                 }
                 else
                 {
                     if (!LanguagePrimitives.IsSignedInteger(typeCode1))
                     {
                         if (LanguagePrimitives.IsSignedInteger(typeCode2))
                         {
                             arg = PSBinaryOperationBinder.FigureSignedUnsignedInt(arg, typeCode2, out type, out type1);
                         }
                     }
                     else
                     {
                         target = PSBinaryOperationBinder.FigureSignedUnsignedInt(target, typeCode1, out type, out type1);
                     }
                     if (type == null)
                     {
                         type = typeof(ULongOps);
                         type1 = typeof(ulong);
                     }
                 }
             }
             else
             {
                 type = typeof(LongOps);
                 type1 = typeof(long);
             }
         }
         else
         {
             if (!LanguagePrimitives.IsSignedInteger(typeCode1))
             {
                 if (LanguagePrimitives.IsSignedInteger(typeCode2))
                 {
                     arg = PSBinaryOperationBinder.FigureSignedUnsignedInt(arg, typeCode2, out type, out type1);
                 }
             }
             else
             {
                 target = PSBinaryOperationBinder.FigureSignedUnsignedInt(target, typeCode1, out type, out type1);
             }
             if (type == null)
             {
                 type = typeof(UIntOps);
                 type1 = typeof(int);
             }
         }
     }
     else
     {
         type = typeof(IntOps);
         type1 = typeof(int);
     }
     Expression expression = Expression.Call(type.GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic), target.Expression.Cast(target.LimitType).Cast(type1), arg.Expression.Cast(arg.LimitType).Cast(type1));
     if (base.Operation == ExpressionType.Equal || base.Operation == ExpressionType.NotEqual)
     {
         Expression expression1 = expression;
         CatchBlock[] catchBlockArray = new CatchBlock[1];
         CatchBlock[] catchBlockArray1 = catchBlockArray;
         int num = 0;
         Type type2 = typeof(InvalidCastException);
         if (base.Operation == ExpressionType.Equal)
         {
             boxedFalse = ExpressionCache.BoxedFalse;
         }
         else
         {
             boxedFalse = ExpressionCache.BoxedTrue;
         }
         catchBlockArray1[num] = Expression.Catch(type2, boxedFalse);
         expression = Expression.TryCatch(expression1, catchBlockArray);
     }
     DynamicMetaObject[] dynamicMetaObjectArray2 = new DynamicMetaObject[1];
     dynamicMetaObjectArray2[0] = arg;
     return new DynamicMetaObject(expression, target.CombineRestrictions(dynamicMetaObjectArray2));
 }
Beispiel #38
0
 private Variable VisitCatchBlock(CatchBlock node)
 {
     throw new NotSupportedException();
     //this.Out("catch (" + node.Test.Name);
     //if (node.Variable != null)
     //{
     //    this.Out(node.Variable.Name ?? "");
     //}
     //this.Out(") { ... }");
 }