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


C# AstNode.AcceptVisitor方法代码示例

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


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

示例1: RunTransformationsUntil

        public static void RunTransformationsUntil(AstNode node, Predicate<IAstTransform> abortCondition, DecompilerContext context)
        {
            if (node == null)
                return;
            for (int i = 0; i < 4; i++) {
                context.CancellationToken.ThrowIfCancellationRequested();
                if (Options.ReduceAstJumps) {
                    node.AcceptVisitor(new Transforms.Ast.RemoveGotos(), null);
                    node.AcceptVisitor(new Transforms.Ast.RemoveDeadLabels(), null);
                }
                if (Options.ReduceAstLoops) {
                    node.AcceptVisitor(new Transforms.Ast.RestoreLoop(), null);
                }
                if (Options.ReduceAstOther) {
                    node.AcceptVisitor(new Transforms.Ast.RemoveEmptyElseBody(), null);
                }
            }

            foreach (var transform in CreatePipeline(context)) {
                context.CancellationToken.ThrowIfCancellationRequested();
                if (abortCondition != null && abortCondition(transform))
                    return;
                transform.Run(node);
            }
        }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:25,代码来源:TransformationPipeline.cs

示例2: AddLocals

        public virtual void AddLocals(IEnumerable<ParameterDeclaration> declarations, AstNode statement)
        {
            declarations.ToList().ForEach(item =>
            {
                var name = this.Emitter.GetEntityName(item);
                var vName = this.AddLocal(item.Name, item.Type);

                if (item.ParameterModifier == ParameterModifier.Out || item.ParameterModifier == ParameterModifier.Ref)
                {
                    this.Emitter.LocalsMap[item.Name] = name + ".v";
                }
                else
                {
                    this.Emitter.LocalsMap[item.Name] = name;
                }
            });

            var visitor = new ReferenceArgumentVisitor();
            statement.AcceptVisitor(visitor);

            foreach (var expr in visitor.DirectionExpression)
            {
                var rr = this.Emitter.Resolver.ResolveNode(expr, this.Emitter);

                if (rr is LocalResolveResult && expr is IdentifierExpression)
                {
                    var ie = (IdentifierExpression)expr;
                    this.Emitter.LocalsMap[ie.Identifier] = ie.Identifier + ".v";
                }
                else
                {
                    throw new EmitterException(expr, "Only local variables can be passed by reference");
                }
            }
        }
开发者ID:Cestbienmoi,项目名称:Bridge,代码行数:35,代码来源:AbstractEmitterBlock.Locals.cs

示例3: ToText

		public static string ToText(AstNode node)
		{
			var stringWriter = new StringWriter();
			var output = new CSharpOutputVisitor(stringWriter, FormattingOptionsFactory.CreateSharpDevelop());
			node.AcceptVisitor(output);

			return stringWriter.GetStringBuilder().ToString();
		}
开发者ID:nberardi,项目名称:ravendb,代码行数:8,代码来源:QueryParsingUtils.cs

示例4: WriteNode

 public static IDictionary<AstNode, ISegment> WriteNode(StringWriter writer, AstNode node, CSharpFormattingOptions policy, ICSharpCode.AvalonEdit.TextEditorOptions options)
 {
     var formatter = new SegmentTrackingOutputFormatter(writer);
     formatter.IndentationString = options.IndentationString;
     var visitor = new CSharpOutputVisitor(formatter, policy);
     node.AcceptVisitor(visitor);
     return formatter.Segments;
 }
开发者ID:sentientpc,项目名称:SharpSnippetCompiler-v5,代码行数:8,代码来源:SegmentTrackingOutputFormatter.cs

示例5: AssertOutput

		void AssertOutput(string expected, AstNode node, CSharpFormattingOptions policy = null)
		{
			if (policy == null)
				policy = FormattingOptionsFactory.CreateMono();
			StringWriter w = new StringWriter();
			w.NewLine = "\n";
			node.AcceptVisitor(new CSharpOutputVisitor(new TextWriterOutputFormatter(w) { IndentationString = "$" }, policy));
			Assert.AreEqual(expected.Replace("\r", ""), w.ToString());
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:9,代码来源:CSharpOutputVisitorTests.cs

示例6: VisitNestedFunction

			private void VisitNestedFunction(AstNode node, AstNode body) {
				var parentFunction = currentFunction;

				currentFunction = new NestedFunctionData(parentFunction) { DefinitionNode = node, BodyNode = body, ResolveResult = (LambdaResolveResult)_resolver.Resolve(node) };
				body.AcceptVisitor(this);

				parentFunction.NestedFunctions.Add(currentFunction);
				currentFunction = parentFunction;
			}
开发者ID:ShuntaoChen,项目名称:SaltarelleCompiler,代码行数:9,代码来源:NestedFunctionGatherer.cs

示例7: HasContinue

 public static bool HasContinue(AbstractEmitterBlock block, AstNode node) {
     var visitor = new ContinueSearchVisitor();
     node.AcceptVisitor(visitor);
     bool has = visitor.Found;
     if(has) {
         EmitBeginContinue(block);
     }
     return has;
 }
开发者ID:yindongfei,项目名称:bridge.lua,代码行数:9,代码来源:ContinueBlock.cs

示例8: AssertOutput

		void AssertOutput(AstNode node)
		{
			RemoveTokens(node);
			StringWriter w = new StringWriter();
			w.NewLine = "\n";
			node.AcceptVisitor(new CSharpOutputVisitor(TokenWriter.CreateWriterThatSetsLocationsInAST(w), FormattingOptionsFactory.CreateSharpDevelop()));
			var doc = new ReadOnlyDocument(w.ToString());
			ConsistencyChecker.CheckMissingTokens(node, "test.cs", doc);
			ConsistencyChecker.CheckPositionConsistency(node, "test.cs", doc);
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:10,代码来源:InsertMissingTokensDecoratorTests.cs

示例9: OutputNode

		public string OutputNode (ProjectDom dom, AstNode node, string indent)
		{
			StringWriter w = new StringWriter();
			var policyParent = dom != null && dom.Project != null ? dom.Project.Policies : null;
			IEnumerable<string> types = DesktopService.GetMimeTypeInheritanceChain (CSharpFormatter.MimeType);
			CSharpFormattingPolicy codePolicy = policyParent != null ? policyParent.Get<CSharpFormattingPolicy> (types) : MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<CSharpFormattingPolicy> (types);
			var formatter = new TextWriterOutputFormatter(w);
			int col = GetColumn (indent, 0, 4);
			formatter.Indentation = System.Math.Max (0, col / 4);
			OutputVisitor visitor = new OutputVisitor (formatter, codePolicy.CreateOptions ());
			node.AcceptVisitor (visitor, null);
			return w.ToString();
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:13,代码来源:CSharpNRefactoryASTProvider.cs

示例10: GatherVariables

		public Tuple<IDictionary<IVariable, VariableData>, ISet<string>> GatherVariables(AstNode node, IMethod method, ISet<string> usedNames) {
			_result = new Dictionary<IVariable, VariableData>();
			_usedNames = new HashSet<string>(usedNames);
			_currentMethod = node;
			_variablesDeclaredInsideLoop = new HashSet<IVariable>();

			if (method != null) {
				foreach (var p in method.Parameters) {
					AddVariable(p, p.IsRef || p.IsOut);
				}
			}

			node.AcceptVisitor(this);
			return Tuple.Create((IDictionary<IVariable, VariableData>)_result, (ISet<string>)_usedNames);
		}
开发者ID:ShuntaoChen,项目名称:SaltarelleCompiler,代码行数:15,代码来源:VariableGatherer.cs

示例11: EmitBlockOrIndentedLine

        public virtual void EmitBlockOrIndentedLine(AstNode node)
        {
            bool block = node is BlockStatement;

            if (!block)
            {
                this.WriteNewLine();
                this.Indent();
            }
            else
            {
                this.WriteSpace();
            }

            node.AcceptVisitor(this.Emitter);

            if (!block)
            {
                this.Outdent();
            }
        }
开发者ID:GavinHwa,项目名称:Bridge,代码行数:21,代码来源:AbstractEmitterBlock.cs

示例12: RunTransformationsUntil

        public static void RunTransformationsUntil(AstNode node, Predicate<IAstVisitor<object, object>> abortCondition)
        {
            if (node == null)
                return;
            for (int i = 0; i < 4; i++) {
                if (Options.ReduceAstJumps) {
                    node.AcceptVisitor(new Transforms.Ast.RemoveGotos(), null);
                    node.AcceptVisitor(new Transforms.Ast.RemoveDeadLabels(), null);
                }
                if (Options.ReduceAstLoops) {
                    node.AcceptVisitor(new Transforms.Ast.RestoreLoop(), null);
                }
                if (Options.ReduceAstOther) {
                    node.AcceptVisitor(new Transforms.Ast.RemoveEmptyElseBody(), null);
                    node.AcceptVisitor(new Transforms.Ast.PushNegation(), null);
                }
            }

            foreach (var visitor in CreatePipeline()) {
                if (abortCondition != null && abortCondition(visitor))
                    return;
                node.AcceptVisitor(visitor, null);
            }
        }
开发者ID:FriedWishes,项目名称:ILSpy,代码行数:24,代码来源:TransformationPipeline.cs

示例13: FixEmbeddedStatment

        void FixEmbeddedStatment(BraceStyle braceStyle, CSharpTokenNode token, bool allowInLine, AstNode node, bool statementAlreadyIndented = false)
        {
            if (node == null)
                return;
            bool isBlock = node is BlockStatement;
            FormattingChanges.TextReplaceAction beginBraceAction = null;
            FormattingChanges.TextReplaceAction endBraceAction = null;
            BlockStatement closeBlockToBeFixed = null;
            if (isBlock) {
                BlockStatement block = node as BlockStatement;
                if (allowInLine && block.StartLocation.Line == block.EndLocation.Line && block.Statements.Count() <= 1) {
                    if (block.Statements.Count() == 1)
                        nextStatementIndent = " ";
                } else {
                    if (!statementAlreadyIndented)
                        FixOpenBrace(braceStyle, block.LBraceToken);
                    closeBlockToBeFixed = block;
                }

                if (braceStyle == BraceStyle.NextLineShifted2)
                    curIndent.Push(IndentType.Block);
            } else {
                if (allowInLine && token.StartLocation.Line == node.EndLocation.Line) {
                    nextStatementIndent = " ";
                }
            }
            bool pushed = false;
            if (policy.IndentBlocks && !(policy.AlignEmbeddedIfStatements && node is IfElseStatement && node.Parent is IfElseStatement || policy.AlignEmbeddedUsingStatements && node is UsingStatement && node.Parent is UsingStatement)) {
                curIndent.Push(IndentType.Block);
                pushed = true;
            }
            if (isBlock) {
                VisitBlockWithoutFixingBraces((BlockStatement)node, false);
            } else {
                if (!statementAlreadyIndented)
                    FixStatementIndentation(node.StartLocation);
                node.AcceptVisitor(this);
            }
            if (pushed)
                curIndent.Pop();
            if (beginBraceAction != null && endBraceAction != null) {
                beginBraceAction.DependsOn = endBraceAction;
                endBraceAction.DependsOn = beginBraceAction;
            }

            if (isBlock && braceStyle == BraceStyle.NextLineShifted2)
                curIndent.Pop();
            if (closeBlockToBeFixed != null) {
                FixClosingBrace(braceStyle, closeBlockToBeFixed.RBraceToken);
            }
        }
开发者ID:segaman,项目名称:NRefactory,代码行数:51,代码来源:FormattingVisitor_Statements.cs

示例14: ContainsLocalReferences

		static bool ContainsLocalReferences (RefactoringContext context, AstNode expr, AstNode body)
		{
			var visitor = new ExtractMethod.VariableLookupVisitor (context);
			body.AcceptVisitor (visitor);
			return visitor.UsedVariables.Any (variable => !expr.Contains (variable.Region.Begin));
		}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:6,代码来源:ExtractAnonymousMethodAction.cs

示例15: EmitLambda

        protected virtual void EmitLambda(IEnumerable<ParameterDeclaration> parameters, AstNode body, AstNode context)
        {
            AsyncBlock asyncBlock = null;
            this.PushLocals();

            if (this.IsAsync)
            {
                if (context is LambdaExpression)
                {
                    asyncBlock = new AsyncBlock(this.Emitter, (LambdaExpression)context);
                }
                else
                {
                    asyncBlock = new AsyncBlock(this.Emitter, (AnonymousMethodExpression)context);
                }

                asyncBlock.InitAsyncBlock();
            }

            var prevMap = this.BuildLocalsMap();
            var prevNamesMap = this.BuildLocalsNamesMap();
            this.AddLocals(parameters, body);

            bool block = body is BlockStatement;
            this.Write("");

            var savedPos = this.Emitter.Output.Length;
            var savedThisCount = this.Emitter.ThisRefCounter;

            this.WriteFunction();
            this.EmitMethodParameters(parameters, context);
            this.WriteSpace();

            if (!block && !this.IsAsync)
            {
                this.BeginBlock();
            }

            bool isSimpleLambda = body.Parent is LambdaExpression && !block && !this.IsAsync;

            if (isSimpleLambda)
            {
                this.ConvertParamsToReferences(parameters);
                this.WriteReturn(true);
            }

            if (this.IsAsync)
            {
                asyncBlock.Emit(true);
            }
            else
            {
                body.AcceptVisitor(this.Emitter);
            }

            if (isSimpleLambda)
            {
                this.WriteSemiColon();
            }

            if (!block && !this.IsAsync)
            {
                this.WriteNewLine();
                this.EndBlock();
            }

            if (this.Emitter.ThisRefCounter > savedThisCount)
            {
                this.Emitter.Output.Insert(savedPos, Bridge.Translator.Emitter.ROOT + "." + Bridge.Translator.Emitter.DELEGATE_BIND + "(this, ");
                this.WriteCloseParentheses();
            }

            this.PopLocals();
            this.ClearLocalsMap(prevMap);
            this.ClearLocalsNamesMap(prevNamesMap);
        }
开发者ID:txdv,项目名称:Builder,代码行数:76,代码来源:LambdaBlock.cs


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