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


C# AstNode类代码示例

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


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

示例1: FindPhrase

        private static Phrase FindPhrase(AstNode node)
        {
            var text = node.GetText();

            if (node.Role == Roles.Comment)
                return Phrase.Comment;

            if (node.Role == Roles.Type)
            {
                var type = (node as PrimitiveType);
                if (type != null)
                    return (type.Keyword != null) ? Phrase.Keyword : Phrase.Type;

                // some keywords can be type like "var" which our parser does not recognise
                return text.IsKeyword() ? Phrase.Keyword : Phrase.Type;
            }

            if (node is PrimitiveExpression)
            {
                if (text.IsString())
                    return Phrase.String;
            }

            if (node is CSharpTokenNode)
            {
                if (text.IsKeyword())
                    return Phrase.Keyword;
            }

            return Phrase.Unknwon;
        }
开发者ID:shayanelhami,项目名称:syntaxtame,代码行数:31,代码来源:Code.cs

示例2: IsEquivalentTo

 public override bool IsEquivalentTo(AstNode otherNode)
 {
     var otherRegExp = otherNode as RegExpLiteral;
     return otherRegExp != null
         && string.CompareOrdinal(Pattern, otherRegExp.Pattern) == 0
         && string.CompareOrdinal(PatternSwitches, otherRegExp.PatternSwitches) == 0;
 }
开发者ID:nuxleus,项目名称:ajaxmin,代码行数:7,代码来源:regexpliteral.cs

示例3: GetEndOfPrev

		TextLocation GetEndOfPrev(AstNode node)
		{
			do {
				node = node.GetPrevNode();
			} while (node.NodeType == NodeType.Whitespace);
			return node.EndLocation;
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:7,代码来源:FoldingVisitor.cs

示例4: StartNode

		public override void StartNode(AstNode node)
		{
			currentList.Add(node);
			nodes.Push(currentList);
			currentList = new List<AstNode>();
			base.StartNode(node);
		}
开发者ID:JackWangCUMT,项目名称:NRefactory,代码行数:7,代码来源:InsertMissingTokensDecorator.cs

示例5: SetIndexValue

        /// <summary>
        /// Sets a value on a member of a basic type.
        /// </summary>
        /// <param name="ctx">The context of the runtime</param>
        /// <param name="varExp">The expression representing the index of the instance to set</param>
        /// <param name="valExp">The expression representing the value to set</param>
        /// <param name="node">The assignment ast node</param>
        public static void SetIndexValue(Context ctx, IAstVisitor visitor, AstNode node, Expr varExp, Expr valExp)
        {
            // 1. Get the value that is being assigned.
            var val = valExp.Evaluate(visitor) as LObject;

            // 2. Check the limit if string.
            ctx.Limits.CheckStringLength(node, val);

            // 3. Evaluate expression to get index info.
            var indexExp = varExp.Evaluate(visitor) as IndexAccess;
            if (indexExp == null)
                throw ComLib.Lang.Helpers.ExceptionHelper.BuildRunTimeException(node, "Value to assign is null");

            // 4. Get the target of the index access and the name / number to set.
            var target = indexExp.Instance;
            var memberNameOrIndex = indexExp.MemberName;

            // Get methods associated with type.
            var methods = ctx.Methods.Get(target.Type);

            // Case 1: users[0] = 'kishore'
            if (target.Type == LTypes.Array)
            {
                var index = Convert.ToInt32(((LNumber)memberNameOrIndex).Value);
                methods.SetByNumericIndex(target, index, val);
            }
            // Case 2: users['total'] = 20
            else if (target.Type == LTypes.Map)
            {
                var name = ((LString)memberNameOrIndex).Value;
                methods.SetByStringMember(target, name, val);
            }
        }
开发者ID:shuxingliu,项目名称:SambaPOS-3,代码行数:40,代码来源:AssignHelper.cs

示例6: EmitMethodParameters

        protected override void EmitMethodParameters(IEnumerable<ParameterDeclaration> declarations, AstNode context, bool skipClose)
        {
            this.WriteOpenParentheses();
            bool needComma = false;

            foreach (var p in declarations)
            {
                var name = this.Emitter.GetEntityName(p);

                if (needComma)
                {
                    this.WriteComma();
                }

                needComma = true;
                this.Write(name);
                this.WriteColon();
                name = BridgeTypes.ToTypeScriptName(p.Type, this.Emitter);
                this.Write(name);
            }

            if (!skipClose)
            {
                this.WriteCloseParentheses();
            }
        }
开发者ID:GavinHwa,项目名称:Bridge,代码行数:26,代码来源:IndexerBlock.cs

示例7: Run

		void Run(AstNode node, DefiniteAssignmentAnalysis daa)
		{
			BlockStatement block = node as BlockStatement;
			if (block != null) {
				var variables = block.Statements.TakeWhile(stmt => stmt is VariableDeclarationStatement)
					.Cast<VariableDeclarationStatement>().ToList();
				if (variables.Count > 0) {
					// remove old variable declarations:
					foreach (VariableDeclarationStatement varDecl in variables) {
						Debug.Assert(varDecl.Variables.Single().Initializer.IsNull);
						varDecl.Remove();
					}
					if (daa == null) {
						// If possible, reuse the DefiniteAssignmentAnalysis that was created for the parent block
						daa = new DefiniteAssignmentAnalysis(block, cancellationToken);
					}
					foreach (VariableDeclarationStatement varDecl in variables) {
						string variableName = varDecl.Variables.Single().Name;
						bool allowPassIntoLoops = varDecl.Variables.Single().Annotation<DelegateConstruction.CapturedVariableAnnotation>() == null;
						DeclareVariableInBlock(daa, block, varDecl.Type, variableName, allowPassIntoLoops);
					}
				}
			}
			for (AstNode child = node.FirstChild; child != null; child = child.NextSibling) {
				Run(child, daa);
			}
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:27,代码来源:DeclareVariables.cs

示例8: EndNode

        public override void EndNode(AstNode node)
        {
            if (nodeStack.Pop() != node)
                throw new InvalidOperationException();

            var startLocation = startLocations.Pop();

            // code mappings
            var ranges = node.Annotation<List<ILRange>>();
            if (symbolsStack.Count > 0 && ranges != null && ranges.Count > 0) {
                // Ignore the newline which was printed at the end of the statement
                TextLocation endLocation = (node is Statement) ? (lastEndOfLine ?? output.Location) : output.Location;
                symbolsStack.Peek().SequencePoints.Add(
                    new SequencePoint() {
                        ILRanges = ILRange.OrderAndJoin(ranges).ToArray(),
                        StartLocation = startLocation,
                        EndLocation = endLocation
                    });
            }

            if (node.Annotation<MethodDebugSymbols>() != null) {
                symbolsStack.Peek().EndLocation = output.Location;
                output.AddDebugSymbols(symbolsStack.Pop());
            }
        }
开发者ID:ichengzi,项目名称:SharpDevelop,代码行数:25,代码来源:TextTokenWriter.cs

示例9: RequiresParens

		public static bool RequiresParens(AstNode replaceNode, AstNode replaceWithNode)
		{
			if (!(replaceWithNode is BinaryOperatorExpression) &&
			    !(replaceWithNode is AssignmentExpression) &&
			    !(replaceWithNode is AsExpression) &&
			    !(replaceWithNode is IsExpression) &&
			    !(replaceWithNode is CastExpression) &&
			    !(replaceWithNode is LambdaExpression) &&
				!(replaceWithNode is ConditionalExpression)) {
				return false;
			}

			var cond = replaceNode.Parent as ConditionalExpression;
			if (cond != null && cond.Condition == replaceNode)
				return true;

			var indexer = replaceNode.Parent as IndexerExpression;
			if (indexer != null && indexer.Target == replaceNode)
				return true;

			return replaceNode.Parent is BinaryOperatorExpression || 
				replaceNode.Parent is UnaryOperatorExpression || 
				replaceNode.Parent is AssignmentExpression || 
				replaceNode.Parent is MemberReferenceExpression ||
				replaceNode.Parent is AsExpression || 
				replaceNode.Parent is IsExpression || 
				replaceNode.Parent is CastExpression ||
				replaceNode.Parent is LambdaExpression ||
				replaceNode.Parent is PointerReferenceExpression;
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:30,代码来源:InlineLocalVariableAction.cs

示例10: Run

		public void Run(AstNode compilationUnit)
		{
			foreach (InvocationExpression invocation in compilationUnit.Descendants.OfType<InvocationExpression>()) {
				MemberReferenceExpression mre = invocation.Target as MemberReferenceExpression;
				MethodReference methodReference = invocation.Annotation<MethodReference>();
				if (mre != null && mre.Target is TypeReferenceExpression && methodReference != null && invocation.Arguments.Any()) {
					MethodDefinition d = methodReference.Resolve();
					if (d != null) {
						foreach (var ca in d.CustomAttributes) {
							if (ca.AttributeType.Name == "ExtensionAttribute" && ca.AttributeType.Namespace == "System.Runtime.CompilerServices") {
								var firstArgument = invocation.Arguments.First();
								if (firstArgument is NullReferenceExpression)
									firstArgument = firstArgument.ReplaceWith(expr => expr.CastTo(AstBuilder.ConvertType(d.Parameters.First().ParameterType)));
								else
									mre.Target = firstArgument.Detach();
								if (invocation.Arguments.Any()) {
									// HACK: removing type arguments should be done indepently from whether a method is an extension method,
									// just by testing whether the arguments can be inferred
									mre.TypeArguments.Clear();
								}
								break;
							}
						}
					}
				}
			}
		}
开发者ID:Costo,项目名称:Xamarin.Forms,代码行数:27,代码来源:IntroduceExtensionMethods.cs

示例11: StartNode

			public override void StartNode(AstNode node)
			{
				if (parameterIndex == highlightedParameterIndex && node is ParameterDeclaration) {
					parameterStartOffset = b.Length;
				}
				base.StartNode(node);
			}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:7,代码来源:CSharpInsightItem.cs

示例12: ToolTipData

			public ToolTipData (ICSharpCode.NRefactory.CSharp.SyntaxTree unit, ICSharpCode.NRefactory.Semantics.ResolveResult result, ICSharpCode.NRefactory.CSharp.AstNode node, CSharpAstResolver file)
			{
				this.Unit = unit;
				this.Result = result;
				this.Node = node;
				this.Resolver = file;
			}
开发者ID:kthguru,项目名称:monodevelop,代码行数:7,代码来源:LanguageItemTooltipProvider.cs

示例13: GetParentFinallyBlock

        public AstNode GetParentFinallyBlock(AstNode node, bool stopOnLoops)
        {
            var insideTryFinally = false;
            var target = node.GetParent(n =>
            {
                if (n is LambdaExpression || n is AnonymousMethodExpression || n is MethodDeclaration)
                {
                    return true;
                }

                if (stopOnLoops && (n is WhileStatement || n is ForeachStatement || n is ForStatement || n is DoWhileStatement))
                {
                    return true;
                }

                if (n is TryCatchStatement && !((TryCatchStatement)n).FinallyBlock.IsNull)
                {
                    insideTryFinally = true;
                    return true;
                }

                return false;
            });

            return insideTryFinally ? ((TryCatchStatement)target).FinallyBlock : null;
        }
开发者ID:GavinHwa,项目名称:Bridge,代码行数:26,代码来源:AbstractEmitterBlock.cs

示例14: GetNodeTitle

		string GetNodeTitle(AstNode node)
		{
			StringBuilder b = new StringBuilder();
			b.Append(node.Role.ToString());
			b.Append(": ");
			b.Append(node.GetType().Name);
			bool hasProperties = false;
			foreach (PropertyInfo p in node.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) {
				if (p.Name == "NodeType" || p.Name == "IsNull")
					continue;
				if (p.PropertyType == typeof(string) || p.PropertyType.IsEnum || p.PropertyType == typeof(bool)) {
					if (!hasProperties) {
						hasProperties = true;
						b.Append(" (");
					} else {
						b.Append(", ");
					}
					b.Append(p.Name);
					b.Append(" = ");
					try {
						object val = p.GetValue(node, null);
						b.Append(val != null ? val.ToString() : "**null**");
					} catch (TargetInvocationException ex) {
						b.Append("**" + ex.InnerException.GetType().Name + "**");
					}
				}
			}
			if (hasProperties)
				b.Append(")");
			return b.ToString();
		}
开发者ID:ThomasZitzler,项目名称:ILSpy,代码行数:31,代码来源:MainForm.cs

示例15: GetActionsForAddNamespaceUsing

        IEnumerable<CodeAction> GetActionsForAddNamespaceUsing(RefactoringContext context, AstNode node)
        {
            var nrr = context.Resolve(node) as NamespaceResolveResult;
            if (nrr == null)
                return EmptyList<CodeAction>.Instance;

            var trr = context.Resolve(node.Parent) as TypeResolveResult;
            if (trr == null)
                return EmptyList<CodeAction>.Instance;
            ITypeDefinition typeDef = trr.Type.GetDefinition();
            if (typeDef == null)
                return EmptyList<CodeAction>.Instance;

            IList<IType> typeArguments;
            ParameterizedType parameterizedType = trr.Type as ParameterizedType;
            if (parameterizedType != null)
                typeArguments = parameterizedType.TypeArguments;
            else
                typeArguments = EmptyList<IType>.Instance;

            var resolver = context.GetResolverStateBefore(node.Parent);
            if (resolver.ResolveSimpleName(typeDef.Name, typeArguments) is UnknownIdentifierResolveResult) {
                // It's possible to remove the explicit namespace usage and introduce a using instead
                return new[] { NewUsingAction(context, node, typeDef.Namespace) };
            }
            return EmptyList<CodeAction>.Instance;
        }
开发者ID:segaman,项目名称:NRefactory,代码行数:27,代码来源:AddUsingAction.cs


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