當前位置: 首頁>>代碼示例>>C#>>正文


C# AstExpression.GetSelfAndChildrenRecursive方法代碼示例

本文整理匯總了C#中AstExpression.GetSelfAndChildrenRecursive方法的典型用法代碼示例。如果您正苦於以下問題:C# AstExpression.GetSelfAndChildrenRecursive方法的具體用法?C# AstExpression.GetSelfAndChildrenRecursive怎麽用?C# AstExpression.GetSelfAndChildrenRecursive使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在AstExpression的用法示例。


在下文中一共展示了AstExpression.GetSelfAndChildrenRecursive方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: UnboxByRefIfGeneric

        private static void UnboxByRefIfGeneric(XTypeReference type, AstExpression node, XTypeSystem typeSystem)
        {
            if (!type.IsGenericParameter)
                return;
            
            var resultType = node.InferredType ?? node.ExpectedType;
            if (resultType == null)
                return;

            if (!TreatAsStruct(type, resultType))
                return;

            // find the first unbox, which should be our target.
            var unbox = node.GetSelfAndChildrenRecursive<AstExpression>( n => n.Code == AstCode.Unbox).FirstOrDefault();

            if (unbox == null)
                return;

            // TODO: Of course we need to unbox generic instances as well,
            //       but at the moment the GenericInstanceConverter does
            //       not look at 'node.StoreByRefExpression' and thus
            //       does not add the required argument, resulting
            //       in unverifyable code. This should be fixed, and
            //       then these lines can be removed.
            if (resultType.IsGenericInstance)
                return;

            ConvertUnboxStruct(unbox, resultType, typeSystem);
        }
開發者ID:Xtremrules,項目名稱:dot42,代碼行數:29,代碼來源:GenericsConverter.cs

示例2: IsSafeForInlineOver

        /// <summary>
        /// Determines whether it is safe to move 'expressionBeingMoved' past 'expr'
        /// </summary>
        bool IsSafeForInlineOver(AstExpression expr, AstExpression expressionBeingMoved)
        {
            switch (expr.Code) {
                case AstCode.Ldloc:
                    AstVariable loadedVar = (AstVariable)expr.Operand;
                    if (numLdloca.GetOrDefault(loadedVar) != 0) {
                        // abort, inlining is not possible
                        return false;
                    }
                    foreach (AstExpression potentialStore in expressionBeingMoved.GetSelfAndChildrenRecursive<AstExpression>()) {
                        if (potentialStore.Code == AstCode.Stloc && potentialStore.Operand == loadedVar)
                            return false;
                    }
                    // the expression is loading a non-forbidden variable
                    return true;
                case AstCode.Ldloca:
                case AstCode.Ldflda:
                case AstCode.Ldsflda:
                case AstCode.Ldelema:
                case AstCode.AddressOf:
                case AstCode.ValueOf:
                case AstCode.NullableOf:
                    // address-loading instructions are safe if their arguments are safe
                    foreach (AstExpression arg in expr.Arguments) {
                        if (!IsSafeForInlineOver(arg, expressionBeingMoved))
                            return false;
                    }
                    return true;
                default:
                    // instructions with no side-effects are safe (except for Ldloc and Ldloca which are handled separately)
                    return expr.HasNoSideEffects();
            }
        }
開發者ID:Xtremrules,項目名稱:dot42,代碼行數:36,代碼來源:AstInlining.cs


注:本文中的AstExpression.GetSelfAndChildrenRecursive方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。