public static Byte IntegerTypeByteCount(this PdlType integerType) { switch (integerType) { case PdlType.Byte: return(1); case PdlType.UInt16: return(2); case PdlType.UInt24: return(3); case PdlType.UInt32: return(4); case PdlType.UInt64: return(8); case PdlType.SByte: return(1); case PdlType.Int16: return(2); case PdlType.Int24: return(3); case PdlType.Int32: return(4); case PdlType.Int64: return(8); default: throw new InvalidOperationException(String.Format("Type '{0}' is not an integer type", integerType)); } }
public static Boolean IntegerTypeIsUnsigned(this PdlType type) { if (type <= PdlType.UInt64) { return(true); } if (type <= PdlType.Int64) { return(false); } throw new InvalidOperationException(String.Format("Cannot call this method on a non-integer type '{0}'", type)); }
static void ParseEnumOrFlagsDefinition(PdlFile pdlFile, LfdReader reader, NamedObjectDefinition currentObjectDefinition, LfdLine enumDefinitionLine, out LfdLine nextLine, Boolean isFlagsDefinition) { String enumOrFlagsString = isFlagsDefinition ? "Flags" : "Enum"; VerifyFieldCount(enumDefinitionLine, 2); String underlyingIntegerTypeString = enumDefinitionLine.fields[0]; PdlType underlyingIntegerType = PdlTypeExtensions.ParseIntegerType(underlyingIntegerTypeString); EnumOrFlagsDefinition definition; try { definition = new EnumOrFlagsDefinition(pdlFile, isFlagsDefinition, currentObjectDefinition, underlyingIntegerType, enumDefinitionLine.fields[1]); } catch (FormatException e) { throw new ParseException(enumDefinitionLine, e.Message); } Debug(" Entering {0} '{1}' (IntegerType={2})", enumOrFlagsString, enumDefinitionLine.id, definition.underlyingIntegerType); // // Read enum values // nextLine = reader.ReadLineIgnoreComments(); while (nextLine != null && nextLine.parent == enumDefinitionLine) { LfdLine enumValueLine = nextLine; VerifyFieldCount(enumValueLine, 1); Debug(" {0} {1} {2}", enumOrFlagsString, enumValueLine.id, enumValueLine.fields[0]); if (isFlagsDefinition) { definition.Add(new FlagsValueDefinition(enumValueLine.fields[0], Byte.Parse(enumValueLine.id))); } else { definition.Add(new EnumValueDefinition(enumValueLine.id, enumValueLine.fields[0])); } nextLine = reader.ReadLineIgnoreComments(); } Debug(" Exiting {0} '{1}'", enumOrFlagsString, definition.typeName); }
public EnumOrFlagsDefinition(PdlFile pdlFile, Boolean isFlagsDefinition, NamedObjectDefinition objectDefinedIn, PdlType underlyingIntegerType, String typeName) { this.isFlagsDefinition = isFlagsDefinition; this.isGlobalType = (objectDefinedIn == null); this.underlyingIntegerType = underlyingIntegerType; this.byteCount = underlyingIntegerType.IntegerTypeByteCount(); this.typeName = typeName; this.typeNameLowerInvariantCase = typeName.ToLowerInvariant(); this.globalReferenceNameLowerInvariant = (objectDefinedIn == null) ? typeNameLowerInvariantCase : (objectDefinedIn.globalReferenceNameLowerInvariant + "." + typeNameLowerInvariantCase); // // Add the definition to the static flags or enum definitions list // if (isFlagsDefinition) { enumValues = null; flagValues = new List <FlagsValueDefinition>(); } else { enumValues = new List <EnumValueDefinition>(); flagValues = null; } // // Add the defintion to the object and the pdl file // if (objectDefinedIn != null) { objectDefinedIn.AddEnumOrFlagDefinition(this); } pdlFile.AddEnumOrFlagsDefinition(this); }
public static Boolean IsIntegerType(this PdlType type) { return(type <= PdlType.Int64); }
public static Boolean IsValidUnderlyingEnumIntegerType(this PdlType type) { return(type <= PdlType.UInt64); }
public IntegerTypeReference(PdlType integerType, PdlArrayType arrayType) : base(integerType.ToString(), integerType, arrayType) { this.byteCount = integerType.IntegerTypeByteCount(); }
public TypeReference(String relativePdlTypeReferenceString, PdlType type, PdlArrayType arrayType) { this.relativePdlTypeReferenceString = relativePdlTypeReferenceString; this.type = type; this.arrayType = arrayType; }