/// <summary> /// Creates a pointer HeapType that points to the given type. /// </summary> /// <param name="pointerTypeName">The name of this pointer type.</param> /// <param name="pointedTypeID">The ID of the pointed type.</param> public HeapType(string pointerTypeName, short pointedTypeID) { if (pointerTypeName == null) { throw new ArgumentNullException("pointerTypeName"); } if (pointedTypeID < 0) { throw new ArgumentOutOfRangeException("", "ID of the pointed type must be non-negative!"); } pointerTypeName = pointerTypeName.Trim(); if (!IDENTIFIER_SYNTAX.IsMatch(pointerTypeName)) { throw new HeapException(string.Format("Invalid type name '{0}'!", pointerTypeName)); } /// Members filled at initialization. this.name = pointerTypeName; this.pointedTypeID = pointedTypeID; this.allocationSize = 4; this.builtInType = BuiltInTypeEnum.NonBuiltIn; this.fieldTypeIDs = null; this.fieldOffsets = null; this.fieldIndices = null; this.tmpFieldTypeNames = null; /// Members that will be filled during validation. this.id = -1; }
/// <summary> /// Constructs a built-in HeapType. /// </summary> /// <param name="builtInType">The built-in type to be constructed.</param> public HeapType(BuiltInTypeEnum builtInType) { /// Members filled at initialization. switch (builtInType) { case BuiltInTypeEnum.Byte: this.allocationSize = 1; break; case BuiltInTypeEnum.Short: this.allocationSize = 2; break; case BuiltInTypeEnum.Integer: case BuiltInTypeEnum.Number: this.allocationSize = 4; break; case BuiltInTypeEnum.Long: this.allocationSize = 8; break; case BuiltInTypeEnum.IntVector: case BuiltInTypeEnum.NumVector: this.allocationSize = 9; break; case BuiltInTypeEnum.IntRectangle: case BuiltInTypeEnum.NumRectangle: this.allocationSize = 17; break; default: throw new ArgumentException("Unexpected value of 'builtInType'!", "builtInType"); } string name; if (!EnumMap <BuiltInTypeEnum, string> .TryMap(builtInType, out name) || name == null) { throw new ArgumentException("No name defined for the built-in type!", "builtInType"); } if (!IDENTIFIER_SYNTAX.IsMatch(name) || name.EndsWith("*")) { throw new HeapException(string.Format("Invalid built-in type name '{0}'!", name)); } this.name = name; this.builtInType = builtInType; this.pointedTypeID = -1; this.fieldTypeIDs = null; this.fieldOffsets = null; this.tmpFieldTypeNames = null; this.fieldIndices = null; /// Members that will be filled during validation. this.id = -1; }
/// <summary> /// Constructs a composite HeapType. /// </summary> /// <param name="name">The name of this composite type.</param> /// <param name="fields">The fields of this composite type.</param> public HeapType(string name, List <KeyValuePair <string, string> > fields) { if (name == null) { throw new ArgumentNullException("name"); } name = name.Trim(); if (!IDENTIFIER_SYNTAX.IsMatch(name) || name.EndsWith("*")) { throw new HeapException(string.Format("Invalid type name '{0}'!", name)); } if (fields == null) { throw new ArgumentNullException("fields"); } //if (fields.Count == 0) { throw new HeapException(string.Format("User defined type '{0}' doesn't define any fields!", name)); } /// Members filled at initialization. this.name = name; this.builtInType = BuiltInTypeEnum.NonBuiltIn; this.pointedTypeID = -1; this.fieldTypeIDs = new List <short>(); this.fieldOffsets = new List <int>(); this.tmpFieldTypeNames = new List <string>(); this.fieldIndices = new Dictionary <string, short>(); foreach (KeyValuePair <string, string> field in fields) { string fieldName = field.Key.Trim(); if (!IDENTIFIER_SYNTAX.IsMatch(fieldName) || fieldName.EndsWith("*")) { throw new HeapException(string.Format("Invalid field name '{0}' defined in type '{1}'!", fieldName, name)); } if (field.Value == null) { throw new ArgumentNullException(string.Format("fields[{0}]", fieldName)); } string fieldType = field.Value.Trim(); if (!IDENTIFIER_SYNTAX.IsMatch(fieldType)) { throw new HeapException(string.Format("Invalid field type '{0}' defined for field '{1}' in type '{2}'!", fieldType, fieldName, name)); } this.fieldIndices.Add(fieldName, (short)this.fieldTypeIDs.Count); this.fieldTypeIDs.Add(-1); /// Will be filled during validation this.fieldOffsets.Add(-1); /// Will be filled during validation this.tmpFieldTypeNames.Add(fieldType); } /// Members that will be filled during validation. this.id = -1; this.allocationSize = -1; }