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


C# IMessageSink.Error方法代码示例

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


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

示例1: unroll

		public static LNode unroll(LNode var, VList<LNode> cases, LNode body, IMessageSink sink)
		{
			// Maps identifiers => replacements. The integer counts how many times replacement occurred.
			var replacements = InternalList<Triplet<Symbol, LNode, int>>.Empty;
			if (var.IsId && !var.HasPAttrs()) {
				replacements.Add(Pair.Create(var.Name, (LNode)LNode.Missing, 0));
			} else {
				var vars = var.Args;
				if ((var.Calls(S.Tuple) || var.Calls(S.Braces)) && vars.All(a => a.IsId && !a.HasPAttrs())) {
					replacements = new Triplet<Symbol, LNode, int>[vars.Count].AsInternalList();
					for (int i = 0; i < vars.Count; i++) {
						replacements.InternalArray[i].A = vars[i].Name;
						
						// Check for duplicate names
						for (int j = 0; j < i; j++)
							if (replacements[i].A == replacements[j].A && replacements[i].A.Name != "_")
								sink.Error(vars[i], "Duplicate name in the left-hand tuple"); // non-fatal
					}
				} else
					return Reject(sink, var, "The left-hand side of 'in' should be a simple identifier or a tuple of simple identifiers.");
			}

			UnrollCtx ctx = new UnrollCtx { Replacements = replacements };
			WList<LNode> output = new WList<LNode>();
			int iteration = 0;
			foreach (LNode replacement in cases)
			{
				iteration++;
				bool tuple = replacement.Calls(S.Tuple) || replacement.Calls(S.Braces);
				int count = tuple ? replacement.ArgCount : 1;
				if (replacements.Count != count)
				{
					sink.Error(replacement, "iteration {0}: Expected {1} replacement items, got {2}", iteration, replacements.Count, count);
					if (count < replacements.Count)
						continue; // too few
				}
				for (int i = 0; i < replacements.Count; i++)
					replacements.InternalArray[i].B = tuple ? replacement.Args[i] : replacement;

				if (body.Calls(S.Braces)) {
					foreach (LNode stmt in body.Args)
						output.Add(ctx.Replace(stmt).Value);
				} else
					output.Add(ctx.Replace(body).Value);
			}

			foreach (var r in replacements)
				if (r.C == 0 && !r.A.Name.StartsWith("_"))
					sink.Write(Severity.Warning, var, "Replacement variable '{0}' was never used", r.A);
			
			return body.With(S.Splice, output.ToVList());
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:52,代码来源:UnrollMacro.cs

示例2: BackingField

		public static LNode BackingField(LNode prop, IMessageSink sink)
		{
			LNode propType, propName, propArgs, body;
			if (prop.ArgCount != 4 || !(body = prop.Args[3]).Calls(S.Braces))
				return null;

			// Look for an attribute of the form [field], [field name] or [field Type name]
			LNode fieldAttr = null, fieldName;
			bool autoType = false;
			int i;
			for (i = 0; i < prop.Attrs.Count; i++) {
				LNode attr = prop.Attrs[i];
				if (attr.IsIdNamed(_field)) {
					fieldAttr = attr;
					break;
				} else if (attr.Calls(S.Var, 2)) {
					LNode fieldVarAttr = null;
					attr = attr.WithoutAttrNamed(__field, out fieldVarAttr);
					if (fieldVarAttr != null && fieldVarAttr.IsId || (autoType = attr.Args[0].IsIdNamed(_field))) {
						fieldAttr = attr;
						break;
					}
				}
			}
			if (fieldAttr == null)
				return null;

			// Extract the type and name of the backing field, if specified
			LNode field = fieldAttr;
			propType = prop.Args[0];
			propName = prop.Args[1];
			propArgs = prop.Args[2];
			if (field.IsId) {
				fieldName = F.Id(ChooseFieldName(Loyc.Ecs.EcsNodePrinter.KeyNameComponentOf(propName)));
				field = F.Call(S.Var, propType, fieldName).WithAttrs(fieldAttr.Attrs);
			} else {
				fieldName = field.Args[1];
				if (fieldName.Calls(S.Assign, 2))
					fieldName = fieldName.Args[0];
			}
			if (autoType)
				field = field.WithArgChanged(0, propType);

			// Construct the new backing field, fill in the property getter and/or setter
			if (body.ArgCount == 0)
				body = body.WithArgs(LNode.Id(S.get));
			LNode newBody = body.WithArgs(body.Args.SmartSelect(stmt =>
			{
				var fieldAccessExpr = fieldName;
				if (propArgs.ArgCount > 0) {
					// Special case: the property has arguments, 
					// e.g. [field List<T> L] T this[int x] { get; set; } 
					//  ==> List<T> L; T this[int x] { get { return L[x]; } set { L[x] = value; } }
					var argList = GetArgNamesFromFormalArgList(propArgs, formalArg =>
						sink.Error(formalArg, "'field' macro expected a variable declaration here"));
					fieldAccessExpr = F.Call(S.IndexBracks, argList.Insert(0, fieldName));
				}
				var attrs = stmt.Attrs;
				if (stmt.IsIdNamed(S.get)) {
					stmt = F.Call(stmt.WithoutAttrs(), F.Braces(F.Call(S.Return, fieldAccessExpr))).WithAttrs(attrs);
					stmt.BaseStyle = NodeStyle.Special;
				}
				if (stmt.IsIdNamed(S.set)) {
					stmt = F.Call(stmt.WithoutAttrs(), F.Braces(F.Call(S.Assign, fieldAccessExpr, F.Id(S.value)))).WithAttrs(attrs);
					stmt.BaseStyle = NodeStyle.Special;
				}
				return stmt;
			}));
			if (newBody == body)
				sink.Warning(fieldAttr, "The body of the property does not contain a 'get;' or 'set;' statement without a body, so no code was generated to get or set the backing field.");

			prop = prop.WithAttrs(prop.Attrs.RemoveAt(i)).WithArgChanged(3, newBody);
			prop.Style &= ~NodeStyle.OneLiner; // avoid collapsing output to one line
			return F.Call(S.Splice, new VList<LNode>(field, prop));
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:75,代码来源:BackingFieldMacro.cs

示例3: if

		public static LNode @try(LNode node, IMessageSink sink)
		{
			if (!node.IsCall)
				return null;

			// try(code, catch, Exception::e, handler, catch, ..., finally, handler)
			// ...becomes...
			// #try(#{ stmt1; stmt2; ... }, #catch(#var(Exception, e), handler), #finally(handler))
			LNode finallyCode = null;
			WList<LNode> clauses = new WList<LNode>();
			var parts = node.Args;
			
			for (int i = parts.Count-2; i >= 1; i -= 2)
			{
				var p = parts[i];
				if (p.IsIdNamed(_finally)) {
					if (clauses.Count != 0 || finallyCode != null)
						sink.Error(p, "The «finally» clause must come last, there can only be one of them.");
					finallyCode = parts[i+1];
				} else if (p.Name == _catch) {
					if (p.ArgCount > 0) {
						if (p.ArgCount > 1)
							sink.Error(p, "Expected catch() to take one argument.");
						// This is a normal catch clause
						clauses.Insert(0, F.Call(S.Catch, p.Args[0], F.Missing, parts[i + 1]));
					} else {
						// This is a catch-all clause (the type argument is missing)
						if (clauses.Count != 0)
							sink.Error(p, "The catch-all clause must be the last «catch» clause.");
						clauses.Add(F.Call(S.Catch, F.Missing, F.Missing, parts[i + 1]));
					}
				} else if (i > 1 && parts[i-1].IsIdNamed(_catch)) {
					// This is a normal catch clause
					clauses.Insert(0, F.Call(S.Catch, AutoRemoveParens(p), F.Missing, parts[i+1]));
					i--;
				} else {
					return Reject(sink, p, "Expected «catch» or «finally» clause here. Clause is missing or malformed.");
				}
				if (i == 2)
					return Reject(sink, parts[1], "Expected «catch» or «finally» clause here. Clause is missing or malformed.");
			}
			if (clauses.Count == 0 && finallyCode == null) {
				Debug.Assert(node.ArgCount <= 1);
				return Reject(sink, node, "Missing «catch, Type, Code» or «finally, Code» clause");
			}
			if (finallyCode != null)
				clauses.Add(F.Call(S.Finally, finallyCode));
			clauses.Insert(0, node.Args[0]);
			return node.With(S.Try, clauses.ToVList());
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:50,代码来源:Prelude.Les.cs

示例4: OpenSourceFiles

		/// <summary>Opens a set of source files by file name, and creates a text file for each.</summary>
		/// <param name="sink"></param>
		/// <param name="fileNames"></param>
		/// <returns></returns>
		public static List<InputOutput> OpenSourceFiles(IMessageSink sink, IEnumerable<string> fileNames)
		{
			var openFiles = new List<InputOutput>();
			foreach (var filename in fileNames) {
				try {
					var stream = File.OpenRead(filename);
					var text = File.ReadAllText(filename, Encoding.UTF8);
					var io = new InputOutput(new StreamCharSource(stream), filename);
					openFiles.Add(io);
				} catch (Exception ex) {
					sink.Error(filename, ex.GetType().Name + ": " + ex.Message);
				}
			}
			return openFiles;
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:19,代码来源:Compiler.cs

示例5: TryCatch

		static bool TryCatch(object context, IMessageSink sink, Action action)
		{
			try {
				action();
				return true;
			} catch (Exception ex) {
				sink.Error(context, "{0} ({1})", ex.Message, ex.GetType().Name);
				return false;
			}
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:10,代码来源:Compiler.cs

示例6: ApplyLanguageOption

		static void ApplyLanguageOption(IMessageSink sink, string option, string value, ref IParsingService lang)
		{
			if (string.IsNullOrEmpty(value))
				sink.Error(option, "Missing value");
			else {
				if (!value.StartsWith("."))
					value = "." + value;
				if ((lang = ParsingService.GetServiceForFileName(value)) == null)
					sink.Error(option, "No language was found for extension «{0}»", value);
			}
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:11,代码来源:Compiler.cs

示例7: ParseBoolOption

		private bool? ParseBoolOption(BMultiMap<string, string> options, string key, IMessageSink sink)
		{
			string value;
			if (!options.TryGetValue(key, out value))
				return null;
			if (value == null)
				return true;
			if (value.Equals("true", StringComparison.InvariantCultureIgnoreCase) || value == "1")
				return true;
			if (value.Equals("false", StringComparison.InvariantCultureIgnoreCase) || value == "0")
				return false;
			if (sink != null)
				sink.Error("--" + key, "Expected boolean `true` or `false`");
			return null;
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:15,代码来源:Compiler.cs

示例8: ParseNumericOption

		private double? ParseNumericOption(BMultiMap<string, string> options, string key, IMessageSink sink, double? min = null, double? max = null)
		{
			string value;
			if (!options.TryGetValue(key, out value))
				return null;
			double num;
			if (double.TryParse(value ?? "", out num)) {
				if ((min == null || num >= min.Value) && 
					(max == null || num <= max.Value))
					return num;
			}
			if (sink != null) {
				if (min != null && max != null)
					sink.Error("--" + key, "Expected numeric value between {0} and {1}", min.Value, max.Value);
				else
					sink.Error("--" + key, "Expected numeric value");
			}
			return null;
		}
开发者ID:qwertie,项目名称:ecsharp,代码行数:19,代码来源:Compiler.cs


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