本文整理汇总了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);
}
}
示例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");
}
}
}
示例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();
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
示例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();
}
}
示例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);
}
}
示例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);
}
}
示例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));
}
示例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);
}