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


C# LNode.WithTarget方法代码示例

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


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

示例1: TranslateSpaceDefinition

		public static LNode @using1(LNode node, IMacroContext sink)
		{
			if (node.ArgCount == 1 && IsComplexId(node.Args[0])) {
				// Looks like an import statement
				sink.Write(Severity.Warning, node.Target, "The 'import' statement replaces the 'using' statement in LeMP.");
				return node.WithTarget(S.Import);
			}
			var result = TranslateSpaceDefinition(node, sink, S.Alias);
			if (result != null)
				return result.PlusAttr(F.Id(S.FilePrivate));
			return null;
		}
开发者ID:jonathanvdc,项目名称:Loyc,代码行数:12,代码来源:Prelude.Les.cs

示例2: ConvertToNormalDot

		static LNode ConvertToNormalDot(LNode prefix, LNode suffix)
		{
			// Essentially, we must increase the precedence of ?. to convert it to a normal dot.
			// This often requires multiple stages, as in:
			//     (a.b) ?. (c().d<x>)    ==> (a.b ?. c().d)<x>      ==> (a.b ?. c)().d<x>      ==> a.b.c().d<x>
			//     (a.b) ?. #of(c().d, x) ==> #of((a.b) ?. c().d, x) ==> #of((a.b ?. c)().d, x) ==> #of(a.b.c().d, x)
			// The cases to be handled are...
			//     x ?. y         <=>  x ?. y             ==>  x.y               (1)
			//     x ?. "foo"     <=>  x ?. "foo"         ==>  x."Foo"           (1)
			//     x ?. ++y       <=>  x ?. @`++`(y)      ==>  x.(++y)           (1)
			//     x ?. y<a, b>   <=>  x ?. #of(y, a, b)  ==>  #of(x.y, a, b)    (2)
			//     x ?. y[a, b]   <=>  x ?. @`[]`(y, a, b)==>  @`[]`(x.y, a, b)  (2)
			//     x ?. y.z       <=>  x ?. @.(y, z)      ==>  #.(x?.y, z)       (2)
			//     x ?. y::z      <=>  x ?. @`::`(y, z)   ==>  #::(x?.y, z)      (2)
			//     x ?. y:::z     <=>  x ?. @`:::`(y, z)  ==>  #:::(x?.y, z)     (2)
			//     x ?. y->z      <=>  x ?. @`->`(y, z)   ==>  #->(x?.y, z)      (2)
			//     x ?. y(->z)    <=>  x ?. #cast(y, z)   ==>  #cast(x?.y, z)    (2)
			//     x ?. y++       <=>  x ?. @`suf++`(y)   ==>  @`suf++`(x?.y)    (2)
			//     x ?. y ?. z    <=>  x ?. @`?.`(y, z)   ==>  @`?.`(x.y, z)       
			//     x ?. y(a, b)   <=>  x ?. y(a, b)       ==>  x.y(a, b)         (3: default case)
			// The following groups are handled essentially the same way:
			// 1. Ids, Literals and prefix operators (+ - ++ -- ! ~ new)
			// 2. #of, @`[]`, @`.`, @`::`, @`:::`, @`=:`, @`->`, #cast, @`suf++`, @`suf--`
			// 3. All other calls
			var c = suffix.ArgCount;
			var name = suffix.Name;
			if (suffix.IsCall) {
				if (c == 1 && PrefixOps.Contains(name)) // (1)
					return F.Dot(prefix, suffix);
				else if (c >= 1 && OtherOps.Contains(name)) { // (2)
					var inner = ConvertToNormalDot(prefix, suffix.Args[0]);
					return suffix.WithArgChanged(0, inner);
				} else { // (3)
					var inner = ConvertToNormalDot(prefix, suffix.Target);
					return suffix.WithTarget(inner);
				}
			} else // (1)
				return F.Dot(prefix, suffix);
		}
开发者ID:Shaykh,项目名称:Loyc,代码行数:39,代码来源:NullDotMacro.cs

示例3: if

		public static LNode @case(LNode node, IMessageSink sink)
		{
			if (node.ArgCount == 1)
				return node.WithTarget(S.Case);
			else if (node.ArgCount == 2 && node.Args[1].Calls(S.Braces))
				return F.Call(S.Splice, new RVList<LNode>(node.WithArgs(node.Args.First(1)), node.Args[1]));
			return null;
		}
开发者ID:BingjieGao,项目名称:Loyc,代码行数:8,代码来源:Prelude.cs

示例4:

		public static LNode @continue(LNode node, IMessageSink sink)
		{
			if (!node.IsId) return null;
			return node.WithTarget(S.Continue);
		}
开发者ID:BingjieGao,项目名称:Loyc,代码行数:5,代码来源:Prelude.cs

示例5: Tuple

		public static LNode Tuple(LNode node, IMacroContext context)
		{
			if (node.IsCall) {
				// Do not change a tuple on the LHS of =>, i.e. `(x, y) => expr`
				if (context.Parent == null || (context.Parent.Calls(S.Lambda, 2) && context.Parent.Args[0].Equals(node)))
					return null;
				var props = context.ScopedProperties;
				var tupleMakers = MaybeInitTupleMakers(props);
				LNode method = (node.ArgCount < tupleMakers.Count 
					? tupleMakers[node.ArgCount] : ((Pair<LNode, LNode>)props[DefaultTupleMaker])).B;
				if (method != null)
					return node.WithTarget(method);
			}
			return null;
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:15,代码来源:TupleMacros.cs

示例6: RemoveBraces

		static LNode RemoveBraces(LNode expr)
		{
			Debug.Assert(expr.Calls(S.Braces));
			if (expr.ArgCount == 1)
				return expr.Args[0];
			else
				return expr.WithTarget(S.Splice);
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:8,代码来源:StageTwoParser.cs

示例7:

		public static LNode @case(LNode node, IMessageSink sink)
		{
			if (node.ArgCount >= 2 && node.Args.Last.Calls(S.Braces))
				return F.Call(S.Splice, new VList<LNode>(node.WithArgs(node.Args.WithoutLast(1)), node.Args.Last));
			if (node.ArgCount >= 1)
				return node.WithTarget(S.Case);
			return null;
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:8,代码来源:Prelude.Les.cs

示例8: noMacro

		public static LNode noMacro(LNode node, IMacroContext sink)
		{
			if (!node.IsCall)
				return null;
			return node.WithTarget(S.Splice);
		}
开发者ID:jonathanvdc,项目名称:Loyc,代码行数:6,代码来源:BuiltinMacros.cs

示例9: BubbleUp_GeneralCall2

			// Bubbles up a call. The returned pair consists of 
			// 1. A sequence of statements to run before the call
			// 2. The call with all (outer) #runSequences removed
			Pair<VList<LNode>, LNode> BubbleUp_GeneralCall2(LNode expr)
			{
				var target = expr.Target;
				var args = expr.Args;
				var combinedSequence = LNode.List();
			
				// Bubbe up target
				target = BubbleUpBlocks(target);
				if (target.CallsMin(__numrunSequence, 1)) {
					combinedSequence = target.Args.WithoutLast(1);
					expr = expr.WithTarget(target.Args.Last);
				}
			
				// Bubble up each argument
				var isAssignment = EcsValidators.IsAssignmentOperator(expr.Name);
				if (isAssignment) {
					LNode lhs = BubbleUpBlocks(expr.Args[0]);
					LNode rhs = BubbleUpBlocks(expr.Args[1]);
					args = LNode.List(lhs, rhs);
				} else {	// most common case
					args = args.SmartSelect(arg => BubbleUpBlocks(arg));
				}
			
				int lastRunSeq = args.LastIndexWhere(a => a.CallsMin(__numrunSequence, 1));
				if (lastRunSeq >= 0) {
					// last index of #runSequence that is not marked pure
					int lastRunSeqImpure = args.First(lastRunSeq + 1).LastIndexWhere(a => 
					a.CallsMin(__numrunSequence, 1) && a.AttrNamed(_trivia_pure.Name) == null);
				
					if (lastRunSeq > 0 && 
					(args.Count == 2 && (target.IsIdNamed(S.And) || target.IsIdNamed(S.Or)) || args.Count == 3 && target.IsIdNamed(S.QuestionMark)))
					{
						Context.Sink.Error(target, 
						"#useSequenceExpressions is not designed to support sequences or variable declarations on the right-hand side of the `&&`, `||` or `?` operators. The generated code will be incorrect.");
					}
				
					var argsW = args.ToList();
					for (int i = 0; i <= lastRunSeq; i++) {
						LNode arg = argsW[i];
						if (!arg.IsLiteral) {
							if (arg.CallsMin(__numrunSequence, 1)) {
								combinedSequence.AddRange(arg.Args.WithoutLast(1));
								argsW[i] = arg = arg.Args.Last;
							}
							if (i < lastRunSeqImpure) {
								if (i == 0 && (expr.CallsMin(S.IndexBracks, 1) || expr.CallsMin(S.NullIndexBracks, 1))) {
									// Consider foo[#runSequence(f(), i)]. In case this appears in
									// an lvalue context and `foo` is a struct, we cannot store `foo` in 
									// a temporary, as this may silently change the code's behavior.
									// Better to take the risk of evaluating `foo` after `f()`.
								 } else {
									if (isAssignment || arg.Attrs.Any(a => a.IsIdNamed(S.Ref) || a.IsIdNamed(S.Out)))
										argsW[i] = MaybeCreateTemporaryForLValue(arg, ref combinedSequence);
									else {
										// Create a temporary variable to hold this argument
										LNode tmpVarName, tmpVarDecl = TempVarDecl(Context, arg, out tmpVarName);
										combinedSequence.Add(tmpVarDecl);
										argsW[i] = tmpVarName.PlusAttr(_trivia_isTmpVar);
									}
								}
							}
						}
					}
				
					expr = expr.WithArgs(LNode.List(argsW));
				}
			
				return Pair.Create(combinedSequence, expr);
			}
开发者ID:qwertie,项目名称:ecsharp,代码行数:72,代码来源:UseSequenceExpressions.out.cs

示例10: import

		public static LNode import(LNode node, IMessageSink sink)
		{
			if (!node.Args.TryGet(0, F._Missing).IsIdNamed(_macros))
				return node.WithTarget(S.Import);
			return null;
		}
开发者ID:BingjieGao,项目名称:Loyc,代码行数:6,代码来源:Prelude.cs

示例11: label

		public static LNode label(LNode node, IMessageSink sink)
		{
			if (node.ArgCount == 1)
				return node.WithTarget(S.Label);
			return null;
		}
开发者ID:BingjieGao,项目名称:Loyc,代码行数:6,代码来源:Prelude.cs

示例12: noMacro

		public static LNode noMacro(LNode node, IMessageSink sink)
		{
			if (!node.IsCall)
				return null;
			return node.WithTarget(S.Splice);
		}
开发者ID:BingjieGao,项目名称:Loyc,代码行数:6,代码来源:Prelude.cs

示例13: TranslateCall

		private static LNode TranslateCall(LNode node, Symbol symbol)
		{
			if (!node.IsCall) return null;
			return node.WithTarget(symbol);
		}
开发者ID:BingjieGao,项目名称:Loyc,代码行数:5,代码来源:Prelude.cs

示例14: DoneAttaching

		protected override LNode DoneAttaching(LNode node, LNode parent, int indexInParent)
		{
			// Constructors are funky in EC# because EC# generalizes constructors so
			// you can write, for example, `this() { F(); base(); G(); }`. 
			// Plain C# constructors like `this() : base() { G(); }`, `base(x)`
			// are actually stored like   `this() { base(); G(); }`, where the colon
			// is the beginning of the Range of the constructor body and the opening 
			// brace is the range of the Target of the method body. This makes it 
			// difficult to get the trivia attached the way we want. For example, this 
			// constructor:
			//
			//     Foo(int x) 
			//        : base(x)
			//     {
			//        Bar();
			//     }
			//
			// Gets trivia attached like this:
			//
			//     #cons(@``, Foo, #(int x), [#trivia_newline] ([#trivia_newline] @`'{}`)(
			//         [#trivia_appendStatement] base(x), Bar()));
			//
			// This code changes the trivia to something more reasonable:
			//
			//     #cons(@``, Foo, #(int x), [#trivia_newline] { base(x), Bar() });
			//
			LNode baseCall;
			if (node.CallsMin(S.Braces, 1) && parent != null && parent.Calls(S.Constructor) 
				&& (baseCall = node.Args[0]).Range.StartIndex < node.Target.Range.StartIndex)
			{
				if (RemoveLeadingNewline(ref node) != null)
					node = node.WithArgChanged(0, baseCall.WithoutAttrNamed(S.TriviaAppendStatement));
				LNode target = node.Target, newline_trivia;
				if ((newline_trivia = RemoveLeadingNewline(ref target)) != null) {
					node = node.WithTarget(target).PlusAttrBefore(newline_trivia);
				}
			}
			return node;
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:39,代码来源:EcsTriviaInjector.cs

示例15: runSequence

		public static LNode runSequence(LNode node, IMacroContext context)
		{
			if (context.Parent.Calls(S.Braces)) { 
				if (node.ArgCount == 1 && node.Args[0].Calls(S.Braces))
					return node.WithArgs(node.Args[0].Args);
				return node.WithTarget(S.Splice);
			}
			return Reject(context, node, "#useVarDeclExpressions is required to make #runSequence work");
		}
开发者ID:jonathanvdc,项目名称:Loyc,代码行数:9,代码来源:StandardMacros.cs


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