当前位置: 首页>>代码示例>>C#>>正文


C# Context.Clone方法代码示例

本文整理汇总了C#中Context.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Context.Clone方法的具体用法?C# Context.Clone怎么用?C# Context.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Context的用法示例。


在下文中一共展示了Context.Clone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

 /// <summary>
 /// Performs stage specific processing on the compiler context.
 /// </summary>
 public virtual void Run()
 {
     for (int index = 0; index < basicBlocks.Count; index++)
         for (Context ctx = new Context(instructionSet, basicBlocks[index]); !ctx.EndOfInstruction; ctx.GotoNext())
             if (!ctx.IsEmpty)
                 ctx.Clone().Visit(this);
 }
开发者ID:jeffreye,项目名称:MOSA-Project,代码行数:10,代码来源:BaseCodeTransformationStage.cs

示例2: Run

 protected override void Run()
 {
     for (int index = 0; index < BasicBlocks.Count; index++)
         for (Context ctx = new Context(InstructionSet, BasicBlocks[index]); !ctx.IsBlockEndInstruction; ctx.GotoNext())
             if (!ctx.IsEmpty)
                 ctx.Clone().Visit(this);
 }
开发者ID:tea,项目名称:MOSA-Project,代码行数:7,代码来源:BaseCodeTransformationStage.cs

示例3: Interpret

        public static IFilter Interpret(Context context, string statement)
        {
            if (string.IsNullOrWhiteSpace(statement)) return null;

            string[] words = statement.Split(' ');
            string mask = words.Skip(1).First();
            string command = words.First();
            bool recurse = words.Contains("-recursive");
            

            if (words.Contains("-fromoutput"))
            {
                string target = context.TargetDir;
                context = context.Clone();
                context.FullPath = target;
            }
            if (command == "make")
            {
                string target = words.Skip(2).FirstOrDefault();
                return Make.Filter(context, mask, recurse);
            }
            else if (command == "copy")
            {
                string target = words.Skip(2).FirstOrDefault();
                return Work.Filter<Copy>(context, mask, null, recurse);
            }
            
            else if (command == "structure")
            {
                return Work.Filter<StructureWork>(context, mask, null, recurse);
            }
            else if (command == "template")
            {
                return Work.Filter<Templater>(context, mask, null, recurse);
            }
            else
            {
                Pipeline pipeline = new Pipeline();
                foreach (string c in command.Split('+'))
                {
                    if (c == "razor") pipeline.Add(new RazorRenderer());
                    if (c == "markdown") pipeline.Add(new MarkdownRenderer());
                    if (c == "profiletable") pipeline.Add(new ProfileTableRenderer());
                    //if (c == "structure") pipeline.Add(new StructureRenderer());


                }

                string target = words.Skip(2).First();
                
                return Work.Filter(context, mask, target, recurse, c => new Render(c, pipeline));
            }
           
        }
开发者ID:Xperterra,项目名称:Fhir.Publication,代码行数:54,代码来源:Make.cs

示例4: Run

        protected override void Run()
        {
            for (int index = 0; index < BasicBlocks.Count; index++)
                for (Context ctx = new Context(InstructionSet, BasicBlocks[index]); !ctx.IsBlockEndInstruction; ctx.GotoNext())
                    if (!ctx.IsEmpty)
                        ProcessInstruction(ctx.Clone());

            for (int index = 0; index < BasicBlocks.Count; index++)
                for (Context ctx = new Context(InstructionSet, BasicBlocks[index]); !ctx.IsBlockEndInstruction; ctx.GotoNext())
                    if (!ctx.IsEmpty)
                        ReplaceOperands(ctx.Clone());

            repl.Clear();
        }
开发者ID:tea,项目名称:MOSA-Project,代码行数:14,代码来源:ConvertCompoundMoveStage.cs

示例5: GetBlock

        private BasicBlock GetBlock(Context context, bool backwards)
        {
            var block = context.BasicBlock;

            if (block == null)
            {
                Context clone = context.Clone();

                if (backwards)
                    clone.GotoFirst();
                else
                    clone.GotoLast();

                block = BasicBlocks.GetByLabel(clone.Label);
            }

            return block;
        }
开发者ID:Boddlnagg,项目名称:MOSA-Project,代码行数:18,代码来源:SparseConditionalConstantPropagation.cs

示例6: FoldIntegerCompareBranch

        /// <summary>
        /// Folds the integer compare branch.
        /// </summary>
        /// <param name="context">The context.</param>
        private void FoldIntegerCompareBranch(Context context)
        {
            if (context.IsEmpty)
                return;

            if (context.OperandCount != 2)
                return;

            if (!(context.Instruction is IR.IntegerCompareBranch))
                return;

            Operand result = context.Result;
            Operand op1 = context.Operand1;
            Operand op2 = context.Operand2;

            if (!op1.IsConstant || !op2.IsConstant)
                return;

            if (!(context.Next.Instruction is IR.Jmp))
                return;

            if (context.BranchTargets[0] == context.Next.BranchTargets[0])
            {
                if (IsLogging) Trace("REMOVED:\t" + context.ToString());
                AddOperandUsageToWorkList(context);
                context.SetInstruction(IRInstruction.Nop);
                instructionsRemoved++;
                return;
            }

            bool compareResult = true;

            switch (context.ConditionCode)
            {
                case ConditionCode.Equal: compareResult = (op1.ValueAsLongInteger == op2.ValueAsLongInteger); break;
                case ConditionCode.NotEqual: compareResult = (op1.ValueAsLongInteger != op2.ValueAsLongInteger); break;
                case ConditionCode.GreaterOrEqual: compareResult = (op1.ValueAsLongInteger >= op2.ValueAsLongInteger); break;
                case ConditionCode.GreaterThan: compareResult = (op1.ValueAsLongInteger > op2.ValueAsLongInteger); break;
                case ConditionCode.LessOrEqual: compareResult = (op1.ValueAsLongInteger <= op2.ValueAsLongInteger); break;
                case ConditionCode.LessThan: compareResult = (op1.ValueAsLongInteger < op2.ValueAsLongInteger); break;
                // TODO: Add more
                default: return;
            }

            Debug.Assert(context.Next.Instruction is IR.Jmp);

            BasicBlock target;

            if (compareResult)
            {
                target = basicBlocks.GetByLabel(context.Next.BranchTargets[0]);

                if (IsLogging) Trace("BEFORE:\t" + context.ToString());

                // change to JMP
                context.SetInstruction(IRInstruction.Jmp, basicBlocks.GetByLabel(context.BranchTargets[0]));
                if (IsLogging) Trace("AFTER:\t" + context.ToString());

                // goto next instruction and prepare to remove it
                context.GotoNext();
            }
            else
            {
                target = basicBlocks.GetByLabel(context.BranchTargets[0]);
            }

            if (IsLogging) Trace("REMOVED:\t" + context.ToString());
            AddOperandUsageToWorkList(context);
            context.SetInstruction(IRInstruction.Nop);
            instructionsRemoved++;

            // Goto the beginning of the block, to get to the first index of the block
            Context first = context.Clone();
            first.GotoFirst();

            // Find block based on first index
            BasicBlock currentBlock = null;
            foreach (var block in basicBlocks)
            {
                if (block.Index == first.Index)
                {
                    currentBlock = block;
                    break;
                }
            }

            currentBlock.NextBlocks.Remove(target);
            target.PreviousBlocks.Remove(currentBlock);

            // TODO: if target block no longer has any predecessors (or the only predecessor is itself), remove all instructions from it.
        }
开发者ID:pdelprat,项目名称:MOSA-Project,代码行数:95,代码来源:SSAOptimizations.cs

示例7: OurHistoryMementoData

 public OurHistoryMementoData(Context context)
 {
     this.context = (Context)context.Clone();
 }
开发者ID:metadeta96,项目名称:openpdn,代码行数:4,代码来源:MoveSelectionTool.cs

示例8: SplitIntoBlocks

        /// <summary>
        /// Finds all targets.
        /// </summary>
        /// <param name="index">The index.</param>
        private void SplitIntoBlocks(int index)
        {
            Dictionary<int, int> targets = new Dictionary<int, int>();

            targets.Add(index, -1);

            // Find out all targets labels
            for (Context ctx = new Context(InstructionSet, index); ctx.Index >= 0; ctx.GotoNext())
            {
                switch (ctx.Instruction.FlowControl)
                {
                    case FlowControl.Next: continue;
                    case FlowControl.Call: continue;
                    case FlowControl.Break: goto case FlowControl.UnconditionalBranch;
                    case FlowControl.Return: continue;
                    case FlowControl.Throw: continue;
                    case FlowControl.UnconditionalBranch:

                        // Unconditional branch
                        Debug.Assert(ctx.BranchTargets.Length == 1);
                        if (!targets.ContainsKey(ctx.BranchTargets[0]))
                            targets.Add(ctx.BranchTargets[0], -1);
                        continue;
                    case FlowControl.Switch: goto case FlowControl.ConditionalBranch;
                    case FlowControl.ConditionalBranch:

                        // Conditional branch with multiple targets
                        foreach (int target in ctx.BranchTargets)
                            if (!targets.ContainsKey(target))
                                targets.Add(target, -1);
                        int next = ctx.Next.Label;
                        if (!targets.ContainsKey(next))
                            targets.Add(next, -1);
                        continue;
                    case FlowControl.EndFinally: continue;
                    case FlowControl.Leave:
                        Debug.Assert(ctx.BranchTargets.Length == 1);
                        if (!targets.ContainsKey(ctx.BranchTargets[0]))
                            targets.Add(ctx.BranchTargets[0], -1);
                        continue;
                    default:
                        Debug.Assert(false);
                        break;
                }
            }

            // Add Exception Class targets
            foreach (var clause in MethodCompiler.Method.ExceptionBlocks)
            {
                if (!targets.ContainsKey(clause.HandlerOffset))
                    targets.Add(clause.HandlerOffset, -1);

                if (!targets.ContainsKey(clause.TryOffset))
                    targets.Add(clause.TryOffset, -1);

                if (clause.FilterOffset != null && !targets.ContainsKey(clause.FilterOffset.Value))
                    targets.Add(clause.FilterOffset.Value, -1);
            }

            BasicBlock currentBlock = null;
            Context previous = null;

            for (Context ctx = new Context(InstructionSet, index); ctx.Index >= 0; ctx.GotoNext())
            {
                if (targets.ContainsKey(ctx.Label))
                {
                    if (currentBlock != null)
                    {
                        previous = ctx.Previous;

                        var flow = previous.Instruction.FlowControl;

                        if (flow == FlowControl.Next || flow == FlowControl.Call || flow == FlowControl.ConditionalBranch || flow == FlowControl.Switch)
                        {
                            // This jump joins fall-through blocks, by giving them a proper end.
                            previous.AppendInstruction(IRInstruction.Jmp);
                            previous.SetBranch(ctx.Label);
                        }

                        // Close current block
                        previous.AppendInstruction(IRInstruction.BlockEnd);
                        currentBlock.EndIndex = previous.Index;
                    }

                    Context prev = ctx.InsertBefore();
                    prev.SetInstruction(IRInstruction.BlockStart);
                    currentBlock = BasicBlocks.CreateBlock(ctx.Label, prev.Index);

                    targets.Remove(ctx.Label);
                }

                previous = ctx.Clone();
            }

            // Close current block
            previous.AppendInstruction(IRInstruction.BlockEnd);
//.........这里部分代码省略.........
开发者ID:tea,项目名称:MOSA-Project,代码行数:101,代码来源:BasicBlockBuilderStage.cs

示例9: ScanForOperatorNew

 private IEnumerable<Context> ScanForOperatorNew()
 {
     foreach (var block in BasicBlocks)
     {
         for (var context = new Context(block); !context.IsBlockEndInstruction; context.GotoNext())
         {
             if (!context.IsEmpty && (context.Instruction is NewobjInstruction || context.Instruction is NewarrInstruction))
             {
                 yield return context.Clone();
             }
         }
     }
 }
开发者ID:yonglehou,项目名称:MOSA-Project,代码行数:13,代码来源:StaticAllocationResolutionStage.cs

示例10: OurContextHistoryMementoData

 public OurContextHistoryMementoData(Context context)
 {
     this.context = (MoveToolContext)context.Clone();
 }
开发者ID:herbqiao,项目名称:paint.net,代码行数:4,代码来源:MoveTool.cs

示例11: ScanForOperatorNew

        private IEnumerable<Context> ScanForOperatorNew()
        {
            foreach (BasicBlock block in this.basicBlocks)
            {
                Context context = new Context(instructionSet, block);
                while (!context.EndOfInstruction)
                {
                    if (context.Instruction is NewobjInstruction || context.Instruction is NewarrInstruction)
                    {
                        Debug.WriteLine(@"StaticAllocationResolutionStage: Found a newobj or newarr instruction.");
                        yield return context.Clone();
                    }

                    context.GotoNext();
                }
            }
        }
开发者ID:jeffreye,项目名称:MOSA-Project,代码行数:17,代码来源:StaticAllocationResolutionStage.cs

示例12: CreateBasicBlocksFromTargets

        /// <summary>
        /// Creates the basic blocks from targets.
        /// </summary>
        /// <param name="targets">The targets.</param>
        private void CreateBasicBlocksFromTargets(SortedSet<int> targets)
        {
            BasicBlock currentBlock = null;
            Context previous = null;

            for (var ctx = new Context(InstructionSet, 0); ctx.Index >= 0; previous = ctx.Clone(), ctx.GotoNext())
            {
                if (!targets.Contains(ctx.Label))
                    continue;

                if (currentBlock != null)
                {
                    previous = ctx.Previous;

                    var flow = previous.Instruction.FlowControl;

                    if (flow == FlowControl.Next || flow == FlowControl.Call || flow == FlowControl.ConditionalBranch || flow == FlowControl.Switch)
                    {
                        // This jump joins fall-through blocks by giving them a proper end.
                        previous.AppendInstruction(IRInstruction.Jmp);
                        previous.SetBranch(ctx.Label);
                    }

                    // Close current block
                    previous.AppendInstruction(IRInstruction.BlockEnd);
                    currentBlock.EndIndex = previous.Index;
                }

                Context prev = ctx.InsertBefore();
                prev.SetInstruction(IRInstruction.BlockStart);
                currentBlock = BasicBlocks.CreateBlock(ctx.Label, prev.Index);
            }

            // Close current block
            previous.AppendInstruction(IRInstruction.BlockEnd);
            currentBlock.EndIndex = previous.Index;
        }
开发者ID:Boddlnagg,项目名称:MOSA-Project,代码行数:41,代码来源:BasicBlockBuilderStage.cs

示例13: ScanForOperatorNew

 private IEnumerable<Context> ScanForOperatorNew()
 {
     foreach (BasicBlock block in BasicBlocks)
     {
         for (Context context = new Context(InstructionSet, block); !context.IsBlockEndInstruction; context.GotoNext())
         {
             if (!context.IsEmpty && (context.Instruction is NewobjInstruction || context.Instruction is NewarrInstruction))
             {
                 //Debug.WriteLine(@"StaticAllocationResolutionStage: Found a newobj or newarr instruction.");
                 yield return context.Clone();
             }
         }
     }
 }
开发者ID:tea,项目名称:MOSA-Project,代码行数:14,代码来源:StaticAllocationResolutionStage.cs

示例14: ProcessContext

        private Context ProcessContext(Context activeContext, JArray localContexts, IList<string> remoteContexts)
        {
            Context result = activeContext.Clone();
            foreach (JToken context in localContexts)
            {
                JValue localContext = context as JValue;
                if ((context == null) || ((localContext != null) && (localContext.Value == null)))
                {
                    result = new Context() { BaseIri = (activeContext.DocumentUri != null ? activeContext.DocumentUri.ToString() : null) };
                    continue;
                }

                if ((localContext != null) && (localContext.Type == JTokenType.String))
                {
                    string contextIri = MakeAbsoluteUri(activeContext.BaseIri, (string)localContext.Value);
                    if (remoteContexts.Contains(contextIri))
                    {
                        throw new InvalidOperationException("Recursive context inclusion.");
                    }

                    JObject remoteContext = LoadRemoteContext(new Uri(contextIri), remoteContexts) as JObject;
                    if ((remoteContext == null) || (!remoteContext.IsPropertySet(Context)))
                    {
                        throw new InvalidOperationException("Invalid remote context.");
                    }

                    result = ProcessContext(result, remoteContext, remoteContexts);
                    continue;
                }

                if (!(context is JObject))
                {
                    throw new InvalidOperationException("Invalid local context.");
                }

                JObject contextObject = (JObject)context;
                result.SetupBase(contextObject, remoteContexts);
                result.SetupVocab(contextObject);
                result.SetupLanguage(contextObject);
                IDictionary<string, bool> defined = new Dictionary<string, bool>();
                foreach (JProperty property in contextObject.Properties())
                {
                    if ((property.Name != Base) && (property.Name != Vocab) && (property.Name != Language))
                    {
                        CreateTermDefinition(property.Name, result, contextObject, defined);
                    }
                }
            }

            return result;
        }
开发者ID:rafalrosochacki,项目名称:RomanticWeb,代码行数:51,代码来源:JsonLdProcessor.expand.cs

示例15: SplitContext

        /// <summary>
        /// Splits the block.
        /// </summary>
        /// <param name="ctx">The context.</param>
        /// <param name="addJump">if set to <c>true</c> [add jump].</param>
        /// <returns></returns>
        protected Context SplitContext(Context ctx, bool addJump)
        {
            Context current = ctx.Clone();

            BasicBlock nextBlock = basicBlocks.CreateBlock();

            foreach (BasicBlock block in current.BasicBlock.NextBlocks)
                nextBlock.NextBlocks.Add(block);

            current.BasicBlock.NextBlocks.Clear();

            if (addJump)
            {
                current.BasicBlock.NextBlocks.Add(nextBlock);
                nextBlock.PreviousBlocks.Add(ctx.BasicBlock);
            }

            if (current.IsLastInstruction)
            {
                current.AppendInstruction(null);
                nextBlock.Index = current.Index;
                current.SliceBefore();
            }
            else
            {
                nextBlock.Index = current.Next.Index;
                current.SliceAfter();
            }

            if (addJump)
                current.AppendInstruction(IR.IRInstruction.Jmp, nextBlock);

            return CreateContext(nextBlock);
        }
开发者ID:jeffreye,项目名称:MOSA-Project,代码行数:40,代码来源:BaseCodeTransformationStage.cs


注:本文中的Context.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。