internal void OnContainerElementUnregistered(CIElement aElement) { if (ElementEvents != null) { ElementEvents(this, aElement, TCIElementEventType.ECIEventChildRemoved); } }
/// <summary> /// Ensure that we only allow single instances of some objects to be added /// as direct children. /// </summary> public override void AddChild(CIElement aChild) { bool exception = false; // if (aChild is CIEventList && Events != null) { exception = true; } else if (aChild is CISymbolDictionary && Symbols != null) { exception = true; } else if (aChild is CIMessageDictionary && Messages != null) { exception = true; } else if (aChild is CISourceElement && Source != null) { exception = true; } else if (aChild is CISummarisableEntityList && Summaries != null) { exception = true; } else if (aChild is CIHeader && Header != null) { exception = true; } else if (aChild is CIReportInfo && ReportInfo != null) { exception = true; } else { // These aren't mandatory, but there should only be one... int count = -1; if (aChild is CIInfoHW) { count = base.ChildrenByType <CIInfoHW>().Count; } else if (aChild is CIInfoSW) { count = base.ChildrenByType <CIInfoSW>().Count; } if (count > 1) { throw new ArgumentException("An instance of the specified object has already been added to the container"); } } if (exception) { throw new ArgumentException("Can only add a single instance of " + aChild.GetType() + " to the container"); } base.AddChild(aChild); }
protected void CreateError(CIContainer aContainer, CIElement aAssociatedElement, string aTitle, string aDescription) { CIMessageError message = new CIMessageError(aContainer, aTitle); message.Description = aDescription; // aAssociatedElement.AddChild(message); }
protected void CreateMessage(CIContainer aContainer, CIElement aAssociatedElement, string aTitle, string aDescription) { CIMessage message = CIMessage.NewMessage(aContainer); message.Title = aTitle; message.Description = aDescription; // aAssociatedElement.AddChild(message); }
protected override void OnElementAddedToSelf(CIElement aElement) { System.Diagnostics.Debug.Assert(aElement is CICodeSeg); CICodeSeg codeSeg = (CICodeSeg)aElement; iCollection.Add(codeSeg); // base.OnElementAddedToSelf(aElement); }
public override void AddChild(CIElement aChild) { if (aChild.GetType() != typeof(CIMemoryInfo)) { throw new ArgumentException("Child must be a CIMemoryInfo"); } base.AddChild(aChild); }
public static void WriteId(CIElement aElement, XmlWriter aWriter) { aWriter.WriteStartElement(SegConstants.CmnId); if (aElement.IsIdExplicit) { aWriter.WriteAttributeString(SegConstants.CmnType, SegConstants.CmnId_Explicit); } aWriter.WriteValue(aElement.Id.ToString()); aWriter.WriteEndElement(); }
internal CISymbol RefreshRegistration(CIElement aElement, uint aSymbolAddress, CISymbol aOldSymbolOrNull) { CISymbol ret = aOldSymbolOrNull; bool needToRegister = false; if (aOldSymbolOrNull != null) { // We only need to do this if the symbol address changed. if (aSymbolAddress != aOldSymbolOrNull.Address) { // We must unregister the symbol from the parent element because potentially we might // replace the symbol with an entirely new one. aElement.RemoveChild(aOldSymbolOrNull); // However, we only do this if there are no other client of the same symbol. int newRefCount = aOldSymbolOrNull.ReferenceCountDecrement(); if (newRefCount <= 0) { // Remove old references to dead symbol DoDeregister(aOldSymbolOrNull); } // Since the address of the symbol has changed, we will need to // re-register a new symbol needToRegister = true; } else { // The symbol address hasn't changed } } else if (aSymbolAddress == 0 && aOldSymbolOrNull == null) { // Err, nothing to do here. } else { // We weren't supplied with an original symbol object which means we will // definitely need to register a symbol (if we don't find a pre-existing match). needToRegister = true; } // Do we need to register a new symbol? if (needToRegister) { // Create new entry (or look up existing reference). This will also // ensure any new symbol is registered with this dictionary. ret = Register(aSymbolAddress); // Associate with parent element aElement.AddChild(ret); } return(ret); }
/// <summary> /// Internal constructor called by CIRegisterListForThread which sets a thread up as a parent /// of the register list. /// </summary> internal CIRegisterList(CIContainer aContainer, CIElement aParent, TArmRegisterBank aBank) : base(aContainer, aParent) { iCollection = new ArmRegisterCollection(aBank); iCollection.Tag = this; iCollection.BackingStore = this; // Restrict children base.AddSupportedChildType(typeof(CIRegister)); base.AddSupportedChildType(typeof(CrashItemLib.Crash.Messages.CIMessage)); }
public void TryAutoPopulateColumns(CIElement aElement) { Type customAttributeType = typeof(CIDBAttributeColumn); Type thisObjectType = aElement.GetType(); object[] attribs = thisObjectType.GetCustomAttributes(customAttributeType, true); if (attribs != null && attribs.Length > 0) { ExtractAttributeColumns(attribs, aElement); } }
internal void RunFinalizers(CIElementFinalizationParameters aParams) { Queue <CIElement> mustBeCalledLast = new Queue <CIElement>(); base.DoFinalize(aParams, mustBeCalledLast, false); // Now call the elements that are to be finalized last while (mustBeCalledLast.Count > 0) { CIElement child = mustBeCalledLast.Dequeue(); child.DoFinalize(aParams, mustBeCalledLast, true); } }
public void TryAutoPopulateCells(CIElement aElement) { if (AutoPopulate) { SortedDictionary <int, CIDBRow> rows = new SortedDictionary <int, CIDBRow>(); Type customAttributeType = typeof(CIDBAttributeCell); Type thisObjectType = aElement.GetType(); // Get properties featuring the CIDBAttribute PropertyInfo[] propertyInfo = thisObjectType.GetProperties(); foreach (PropertyInfo p in propertyInfo) { object[] attribs = p.GetCustomAttributes(customAttributeType, true); if (attribs != null && attribs.Length > 0) { object propertyValue = p.GetValue(aElement, null); ExtractAttributeCells(p.ToString(), aElement, attribs, propertyValue, rows); } } // Same, but get methods featuring the CIDBAttribute MethodInfo[] methodInfo = thisObjectType.GetMethods(); foreach (MethodInfo m in methodInfo) { object[] attribs = m.GetCustomAttributes(customAttributeType, true); if (attribs != null && attribs.Length > 0) { // We only support this attribute on methods that don't contain // any arguments int paramCount = m.GetParameters().Length; if (paramCount != 0) { throw new NotSupportedException("Method: " + m.ToString() + " has CIDBAttribute but non-empty parameter list -> Not supported"); } // Get property value object propertyValue = m.Invoke(aElement, null); ExtractAttributeCells(m.ToString(), aElement, attribs, propertyValue, rows); } } // Since the list is already sorted for us, just add the items in order foreach (KeyValuePair <int, CIDBRow> kvp in rows) { this.Add(kvp.Value); } } }
private void DiscardImplicitCodeSegments() { // Go through each child and see if it's a code seg. If it is, and if // it is implicit, throw it away int childCount = base.Count; for (int i = childCount - 1; i >= 0; i--) { CIElement element = base[i]; if (element is CICodeSeg) { CICodeSeg cs = (CICodeSeg)element; // if (!cs.IsExplicit) { base.Trace(string.Format("[CIProcess] DiscardImplicitCodeSegments() - dicarded: {0}", cs)); base.RemoveChild(cs); } } } }
private void AddMandatoryElements() { Type attribType = typeof(CIElementAttributeMandatory); Type[] types = Assembly.GetExecutingAssembly().GetTypes(); // foreach (Type t in types) { // Get all the constructors for the type if (!t.IsAbstract && typeof(CIElement).IsAssignableFrom(t)) { ConstructorInfo[] ctors = t.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); foreach (ConstructorInfo ctor in ctors) { // If the specified ctor is decorated with the "mandatory" attribute // then it must be a mandatory class, so new an instance up... object[] attribs = ctor.GetCustomAttributes(attribType, false); if (attribs.Length > 0) { // Check that it has the expected signature. // We expect mandatory constructors to take only a single parameter // which is the container itself, i.e. this object ParameterInfo[] parameters = ctor.GetParameters(); if (parameters.Length == 1 && parameters[0].ParameterType == this.GetType()) { CIElement element = ctor.Invoke(new object[] { this }) as CIElement; if (element != null) { element.Parent = this; AddChild(element); } } } } } } // AddChild(new CISymbolDictionary(this)); }
private void ExtractAttributeColumns(object[] aColumnAttributes, CIElement aElement) { bool foundColumnAttributes = false; SortedDictionary <int, CIDBColumn> columns = new SortedDictionary <int, CIDBColumn>(); foreach (object obj in aColumnAttributes) { if (obj is CIDBAttributeColumn) { CIDBAttributeColumn attribute = (CIDBAttributeColumn)obj; // Make a column CIDBColumn col = new CIDBColumn(attribute.Caption); col.Width = attribute.Width; col.WidthSet = attribute.WidthSet; col.TakesUpSlack = attribute.TakesUpSlack; if (columns.ContainsKey(attribute.Order)) { throw new Exception(string.Format("Column: [{0}] in element: [{1}] specifies order: {2} which is already in use", attribute.Caption, aElement, attribute.Order)); } columns.Add(attribute.Order, col); foundColumnAttributes = true; } } // Since the list is already sorted for us, just add the items in order foreach (KeyValuePair <int, CIDBColumn> kvp in columns) { this.Add(kvp.Value); } // We'll override the auto populate feature if we find a valid // column attribute iAutoPopulate = foundColumnAttributes; }
public override void AddChild(CIElement aChild) { // We support 4 types of children at the moment. // Registers, stacks and exit info, messages. if (aChild.GetType() == typeof(CIExitInfo)) { if (base.ChildrenByType <CIExitInfo>().Count != 0) { throw new ArgumentException("Exit Info already associated with the thread"); } } else if (aChild.GetType() == typeof(CIThreadRegisterListCollection)) { if (base.ChildrenByType <CIThreadRegisterListCollection>().Count != 0) { throw new ArgumentException("Registers already associated with the thread"); } } else if (aChild.GetType() == typeof(CIStack)) { CIStack stack = (CIStack)aChild; // We must ensure we don't already have a stack of the specified mode // associated with the thread. bool exists = iStacks.ContainsKey(stack.Type); if (exists) { throw new ArgumentException(ArmRegisterBankUtils.BankAsStringLong(stack.Type) + " mode stack already registered with thread"); } else { iStacks.Add(stack.Type, stack); } } // base.AddChild(aChild); }
public CIDBModel(CIElement aElement, bool aAutoPopulate) { iElement = aElement; iAutoPopulate = aAutoPopulate; }
private void ExtractAttributeCells(string aEntityName, CIElement aElement, object[] aCIDBAttributeEntries, object aValue, SortedDictionary <int, CIDBRow> aRows) { foreach (object obj in aCIDBAttributeEntries) { if (obj is CIDBAttributeCell) { CIDBAttributeCell attribute = (CIDBAttributeCell)obj; // If the property is an 'auto expand' entry, then don't look at this // property, but instead look at the object itself if (attribute.Options == CIDBAttributeCell.TOptions.EAutoExpand) { // The object must be an element CIElement element = aValue as CIElement; if (element == null) { throw new ArgumentException("CIDBAttributeCell(TOptions.EAutoExpand) may only be applied to CIElement objects"); } TryAutoPopulateCells(element); } else { // Whether or not to create a row bool makeRow = true; // Convert attribute value to string. If the object is an enum, we'll check if it has // a System.ComponentModel.Description attached to it, and use that in preference to a raw // value. string defaultValueString = (attribute.DefaultValue != null) ? attribute.DefaultValue.ToString() : null; string propertyValueString = aValue.ToString(); if (aValue.GetType().BaseType == typeof(Enum)) { // Check if it supports System.ComponentModel.Description FieldInfo fi = aValue.GetType().GetField(propertyValueString); if (fi != null) { DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); if (attributes != null && attributes.Length > 0) { propertyValueString = attributes[0].Description; } } } else if (attribute.Format.Length > 0 && aValue is IFormattable) { string formatSpec = attribute.Format; IFormattable formattable = (IFormattable)aValue; propertyValueString = formattable.ToString(formatSpec, null); // Also get the default value if available bool defaultIsFormattable = attribute.DefaultValue is IFormattable; if (attribute.DefaultValue != null && defaultIsFormattable) { formattable = (IFormattable)attribute.DefaultValue; defaultValueString = formattable.ToString(formatSpec, null); } } // If the value of the property is the same as the default, then don't // show it. if (defaultValueString != null) { makeRow = (defaultValueString.CompareTo(propertyValueString) != 0); } // Make a row if (makeRow) { CIDBRow row = new CIDBRow(); row.Add(new CIDBCell(attribute.Caption)); row.Add(new CIDBCell(propertyValueString, attribute.ForeColor, attribute.BackColor, attribute.Format)); // Add the row if it doesn't exist. If it does, then that implies // duplicate ordering, which we treat as a programming error. if (aRows.ContainsKey(attribute.Order)) { throw new Exception(string.Format("Entity: [{0}] in element: [{1}] specifies order: {2} which is already in use", aEntityName, aElement, attribute.Order)); } aRows.Add(attribute.Order, row); } } } } }
public CIExitInfo(CIElement aParent) : base(aParent.Container, aParent) { }
internal CIRegisterListCollection(CIContainer aContainer, CIElement aParent) : base(aContainer, aParent) { }
protected void CreateError(CIContainer aContainer, CIElement aAssociatedElement, string aTitle) { CreateError(aContainer, aAssociatedElement, aTitle, string.Empty); }
/// <summary> /// Called by CIElement when an object is *directly* added /// as a child of the container. /// </summary> protected override void OnElementAddedToSelf(CIElement aElement) { // The master switch that ensures all elements and their children // are flagged as in the container. aElement.IsInContainer = true; }
public static void XmlSerializeMessages(CXmlDocumentSerializationParameters aParameters, CIElement aElement) { CIElementList <CIMessage> messages = aElement.ChildrenByType <CIMessage>(); foreach (CIMessage msg in messages) { CXmlNode.WriteLink(msg.Id, SegConstants.Messages, aParameters.Writer); } }