コード例 #1
0
 public SerializerTypeReference(PdlArrayType lengthType, PdlArrayType arrayType)
     : base("Serializer", PdlType.Serializer, arrayType)
 {
     if (lengthType == null)
     {
         throw new InvalidOperationException("A Serializer must have an array type");
     }
     this.lengthType = lengthType;
 }
コード例 #2
0
        public void CalculateFixedSerializationLength()
        {
            if (calculatedFixedSerializationLength)
            {
                throw new InvalidOperationException(
                          "Cannot calculate FixedSerializationLength after it has already been calculated");
            }

            UInt32 length = 0;

            for (int i = 0; i < fields.Count; i++)
            {
                ObjectDefinitionField field = fields[i];
                TypeReference         fieldTypeReference = field.typeReference;
                UInt32 fieldFixedSerializationLength     = fieldTypeReference.FixedElementSerializationLength;
                if (fieldFixedSerializationLength == UInt32.MaxValue)
                {
                    this.fixedSerializationLength      = UInt32.MaxValue;
                    calculatedFixedSerializationLength = true;
                    return;
                }

                PdlArrayType arrayType = fieldTypeReference.arrayType;
                if (arrayType == null)
                {
                    length += fieldFixedSerializationLength;
                }
                else
                {
                    if (arrayType.type != PdlArraySizeTypeEnum.Fixed)
                    {
                        this.fixedSerializationLength      = UInt32.MaxValue;
                        calculatedFixedSerializationLength = true;
                        return;
                    }
                    length += arrayType.GetFixedArraySize() * fieldFixedSerializationLength;
                }
            }

            this.fixedSerializationLength      = length;
            calculatedFixedSerializationLength = true;
        }
コード例 #3
0
 public ObjectTypeReference(String relativeObjectReferenceTypeString, NamedObjectDefinition definition, PdlArrayType arrayType)
     : base(relativeObjectReferenceTypeString, PdlType.Object, arrayType)
 {
     this.relativeObjectReferenceTypeString = relativeObjectReferenceTypeString;
     this.definition = definition;
 }
コード例 #4
0
 public EnumOrFlagsTypeReference(String relativeEnumReferenceTypeString, EnumOrFlagsDefinition definition, PdlArrayType arrayType)
     : base(relativeEnumReferenceTypeString, definition.isFlagsDefinition ? PdlType.Flags : PdlType.Enum, arrayType)
 {
     this.relativeEnumReferenceTypeString = relativeEnumReferenceTypeString;
     this.definition = definition;
 }
コード例 #5
0
 public AsciiTypeReference(String typeString, PdlArrayType arrayType)
     : base(typeString, PdlType.Ascii, arrayType)
 {
 }
コード例 #6
0
 public IntegerTypeReference(PdlType integerType, PdlArrayType arrayType)
     : base(integerType.ToString(), integerType, arrayType)
 {
     this.byteCount = integerType.IntegerTypeByteCount();
 }
コード例 #7
0
 public TypeReference(String relativePdlTypeReferenceString, PdlType type, PdlArrayType arrayType)
 {
     this.relativePdlTypeReferenceString = relativePdlTypeReferenceString;
     this.type      = type;
     this.arrayType = arrayType;
 }
コード例 #8
0
ファイル: PdlParser.cs プロジェクト: As-You-Like/DotNetStuff
        public static void ParseObjectFieldLine(PdlFile pdlFile, LfdReader reader, NamedObjectDefinition containingNamedObject,
                                                IFieldContainer containingObject, LfdLine fieldLine, out LfdLine nextLine)
        {
            //
            // Check if it is only a definition (enum or flag)
            //
            if (fieldLine.id.Equals("enum", StringComparison.OrdinalIgnoreCase))
            {
                ParseEnumOrFlagsDefinition(pdlFile, reader, containingNamedObject, fieldLine, out nextLine, false);
                return;
            }
            if (fieldLine.id.Equals("flags", StringComparison.OrdinalIgnoreCase))
            {
                ParseEnumOrFlagsDefinition(pdlFile, reader, containingNamedObject, fieldLine, out nextLine, true);
                return;
            }

            String typeString = fieldLine.id;

            //
            // The rest of the fields can have arrayParse the Array Size Type
            //
            PdlArrayType arrayType;

            int indexOfOpenBracket = typeString.IndexOf('[');

            if (indexOfOpenBracket < 0)
            {
                arrayType = null;
            }
            else
            {
                String arraySizeTypeString = typeString.Substring(indexOfOpenBracket + 1);

                typeString = typeString.Remove(indexOfOpenBracket);

                int indexOfCloseBracket = arraySizeTypeString.IndexOf(']');
                if (indexOfCloseBracket < 0)
                {
                    throw new ParseException(fieldLine, "Found an opening bracket '[' without a closing bracket");
                }
                if (indexOfCloseBracket != arraySizeTypeString.Length - 1)
                {
                    throw new ParseException(fieldLine, "The array size type '{0}' had a closing bracket, but the closing bracket was not the last character", arraySizeTypeString);
                }

                arraySizeTypeString = arraySizeTypeString.Remove(indexOfCloseBracket);
                arrayType           = PdlArrayType.Parse(fieldLine, arraySizeTypeString);
            }

            //
            // Parse object inline definition
            //
            if (typeString.Equals("object", StringComparison.OrdinalIgnoreCase))
            {
                VerifyFieldCount(fieldLine, 1);

                String objectDefinitionAndFieldName = fieldLine.fields[0];

                NamedObjectDefinition fieldObjectDefinition = ParseObjectDefinition(pdlFile, reader, fieldLine,
                                                                                    containingNamedObject, objectDefinitionAndFieldName, out nextLine);

                containingObject.AddField(new ObjectDefinitionField(
                                              new ObjectTypeReference(objectDefinitionAndFieldName, fieldObjectDefinition, arrayType),
                                              objectDefinitionAndFieldName));
                return;
            }

            //
            // Check if it is a serializer
            //
            if (fieldLine.id.Equals("serializer", StringComparison.OrdinalIgnoreCase))
            {
                VerifyFieldCount(fieldLine, 2);
                String       serializerLengthTypeString = fieldLine.fields[0];
                String       serializerFieldName        = fieldLine.fields[1];
                PdlArrayType serializerLengthType       = PdlArrayType.Parse(fieldLine, serializerLengthTypeString);

                containingObject.AddField(new ObjectDefinitionField(new SerializerTypeReference(serializerLengthType, arrayType), serializerFieldName));

                nextLine = reader.ReadLineIgnoreComments();
                return;
            }

            //
            // Check if it is an 'if' type
            //
            if (typeString.Equals("if", StringComparison.OrdinalIgnoreCase))
            {
                VerifyFieldCount(fieldLine, 1);

                IfTypeReference ifType = ParseIf(pdlFile, reader, fieldLine,
                                                 containingNamedObject, out nextLine);

                containingObject.AddField(new ObjectDefinitionField(ifType, null));
                return;
            }

            //
            // Check if it is a switch type
            //
            if (typeString.Equals("switch", StringComparison.OrdinalIgnoreCase))
            {
                VerifyFieldCount(fieldLine, 1);

                SwitchTypeReference switchType = ParseSwitch(pdlFile, reader, fieldLine,
                                                             containingNamedObject, out nextLine);

                containingObject.AddField(new ObjectDefinitionField(switchType, null));
                return;
            }

            //
            // The field is only one line, so read the next line now for the caller
            //
            nextLine = reader.ReadLineIgnoreComments();



            EnumOrFlagsDefinition enumDefinition = pdlFile.TryGetEnumOrFlagsDefinition(containingNamedObject, typeString);

            if (enumDefinition != null)
            {
                VerifyFieldCount(fieldLine, 1);
                containingObject.AddField(new ObjectDefinitionField(new EnumOrFlagsTypeReference(typeString, enumDefinition, arrayType),
                                                                    fieldLine.fields[0]));
                return;
            }

            // Check if it is an object type
            NamedObjectDefinition objectDefinition = pdlFile.TryGetObjectDefinition(containingNamedObject, typeString);

            if (objectDefinition != null)
            {
                if (fieldLine.fields == null || fieldLine.fields.Length <= 0)
                {
                    //
                    // Add each field from the object definition to the current object definition
                    //
                    List <ObjectDefinitionField> objectDefinitionFields = objectDefinition.Fields;
                    for (int i = 0; i < objectDefinitionFields.Count; i++)
                    {
                        ObjectDefinitionField fieldDefinition = objectDefinitionFields[i];
                        containingObject.AddField(fieldDefinition);
                    }
                }
                else if (fieldLine.fields.Length == 1)
                {
                    containingObject.AddField(new ObjectDefinitionField(
                                                  new ObjectTypeReference(typeString, objectDefinition, arrayType), fieldLine.fields[0]));
                }
                else
                {
                    throw new ParseException(fieldLine, "Expected line to have 0 or 1 fields but had {0}", fieldLine.fields.Length);
                }
                return;
            }

            //
            // Check if it a string type
            //
            if (typeString.Equals("ascii", StringComparison.OrdinalIgnoreCase))
            {
                VerifyFieldCount(fieldLine, 1);
                containingObject.AddField(new ObjectDefinitionField(
                                              new AsciiTypeReference(typeString, arrayType), fieldLine.fields[0]));
                return;
            }


            //
            // It must be an integer type
            //
            VerifyFieldCount(fieldLine, 1);

            PdlType type;

            try { type = (PdlType)Enum.Parse(typeof(PdlType), typeString, true); }
            catch (ArgumentException) { throw new FormatException(String.Format("Unknown Pdl Type '{0}'", typeString)); }
            if (!type.IsIntegerType())
            {
                throw new InvalidOperationException(String.Format("Unhandled PDL type '{0}'", type));
            }

            containingObject.AddField(new ObjectDefinitionField(new IntegerTypeReference(type, arrayType), fieldLine.fields[0]));
        }