////////////////////////////////////////////////////////////////////////////// // Project: Ob51 // License: Apache License, Version 2.0; for details see LICENSE file // Copyright: see NOTICE file // // Last file commit: $Revision: 215 $ Made by: $Author: avek $ ////////////////////////////////////////////////////////////////////////////// using System; using System.Collections.Generic; using IEnumerable = System.Collections.IEnumerable; using IEnumerator = System.Collections.IEnumerator; using System.Text; namespace Ob51.Compiler { /// /// Storage for error and warning messages generated during the compilation. /// public class IssueList : IEnumerable { #region Internal data storage /// /// Internal storage for the list of instances. /// private List list = new List(20); /// /// Internal counter of the errors. /// private uint errorCount = 0u; /// /// Internal counter of the warnings. /// private uint warningCount = 0u; /// /// Internal counter of the notes. /// private uint noteCount = 0u; #endregion /// /// Adds , the information about the error or warning, /// to this list. /// /// to add public void Add(Issue issue) { list.Add(issue); switch (issue.Severity) { case Issue.Severities.Warning: ++warningCount; break; case Issue.Severities.Note: ++noteCount; break; case Issue.Severities.FatalError: case Issue.Severities.Error: default: ++errorCount; break; } } /// /// Registers in the given log. If no log is given, /// throws . /// /// Error, warning or note to record /// to record in or null public static void Record(Issue issue, IssueList list) { if (issue == null) throw new ArgumentNullException("issue"); if (list == null) throw new Issue.UnableToRecordIssueException(issue); list.Add(issue); } /// /// Creates an based on parameters given and /// registers it in the given log. If no log provided, throws /// . /// /// Severity code of the issue /// Numeric status code of the issue /// Issue description /// that /// produced the issue /// to record in public static void Record(Issue.Severities severity, uint code, string message, InternalTree.ProgramNode src, IssueList list) { Record(new Issue(severity, code, message, src), list); } /// /// Removes all the instances from this list. /// public void Clear() { list.Clear(); errorCount = warningCount = noteCount = 0u; } /// /// Indicates whether this is empty. /// public bool IsEmpty { get { return list.Count == 0; } } /// /// Indicates whether any s or /// s are present in this list. /// public bool ContainsErrors { get { return errorCount != 0; } } /// /// Indicates whether any s are /// present in this list. /// public bool ContainsWarnings { get { return warningCount != 0; } } /// /// Indicates whether any s are /// present in this list. /// public bool ContainsNotes { get { return noteCount != 0; } } /// /// The number of s in this list. /// public int Count { get { return list.Count; } } /// /// Default read only indexer for . /// /// Index of the to get /// at index public Issue this[int position] { get { return list[position]; } } /// /// implementation method that /// returns generic /// /// Generic enumerator public IEnumerator GetEnumerator() { return list.GetEnumerator(); } /// /// implementation method that returns /// non-generic . /// /// Non-generic enumerator IEnumerator IEnumerable.GetEnumerator() { return this.GetEnumerator(); } } }