/// <summary> /// Parses a type definition /// </summary> /// <returns>The type definition</returns> private TypeDefinition _parseDefinition(bool eagerOptional = true) { TokenType type; TypeDefinition definition; type = _peekType(); switch (type) { case TokenType.Null: _read(); definition = PrimitiveDefinition.Null; break; case TokenType.Boolean: _read(); definition = PrimitiveDefinition.Boolean; break; case TokenType.Unsigned: _read(); definition = PrimitiveDefinition.Unsigned32; _skipRangeSpecifier(); break; case TokenType.Unsigned8: _read(); definition = PrimitiveDefinition.Unsigned8; _skipRangeSpecifier(); break; case TokenType.Unsigned16: _read(); definition = PrimitiveDefinition.Unsigned16; _skipRangeSpecifier(); break; case TokenType.Signed: _read(); definition = PrimitiveDefinition.Signed32; break; case TokenType.Float32: _read(); definition = PrimitiveDefinition.Float32; break; case TokenType.Float64: _read(); definition = PrimitiveDefinition.Float64; break; case TokenType.OctetString: _read(); definition = PrimitiveDefinition.OctetString; _skipLengthSpecifier(); break; case TokenType.CharString: _read(); definition = PrimitiveDefinition.CharString; _skipLengthSpecifier(); break; // bitstring handled below // enumerated handled below case TokenType.Date: _read(); definition = PrimitiveDefinition.Date; break; case TokenType.Time: _read(); definition = PrimitiveDefinition.Time; break; case TokenType.ObjectId: _read(); definition = PrimitiveDefinition.ObjectId; break; case TokenType.Generic: _read(); definition = PrimitiveDefinition.Generic; break; case TokenType.Enumerated: definition = _parseEnumeration(); break; case TokenType.BitString: definition = _parseBitString(); break; case TokenType.Sequence: definition = _parseSequence(); break; case TokenType.Choice: definition = _parseChoice(); break; case TokenType.Identifier: definition = new NameDefinition(_get(TokenType.Identifier)); break; default: throw new InvalidDataException(type.ToString()); } if (eagerOptional && _peekType() == TokenType.Optional) { definition = new OptionDefinition(definition); _read(); } return(definition); }
/// <summary> /// Parses a type definition /// </summary> /// <returns>The type definition</returns> private TypeDefinition _parseDefinition(bool eagerOptional = true) { TokenType type; TypeDefinition definition; type = _peekType(); switch (type) { case TokenType.Null: _read(); definition = PrimitiveDefinition.Null; break; case TokenType.Boolean: _read(); definition = PrimitiveDefinition.Boolean; break; case TokenType.Unsigned: _read(); definition = PrimitiveDefinition.Unsigned32; _skipRangeSpecifier(); break; case TokenType.Unsigned8: _read(); definition = PrimitiveDefinition.Unsigned8; _skipRangeSpecifier(); break; case TokenType.Unsigned16: _read(); definition = PrimitiveDefinition.Unsigned16; _skipRangeSpecifier(); break; case TokenType.Signed: _read(); definition = PrimitiveDefinition.Signed32; break; case TokenType.Float32: _read(); definition = PrimitiveDefinition.Float32; break; case TokenType.Float64: _read(); definition = PrimitiveDefinition.Float64; break; case TokenType.OctetString: _read(); definition = PrimitiveDefinition.OctetString; _skipLengthSpecifier(); break; case TokenType.CharString: _read(); definition = PrimitiveDefinition.CharString; _skipLengthSpecifier(); break; // bitstring handled below // enumerated handled below case TokenType.Date: _read(); definition = PrimitiveDefinition.Date; break; case TokenType.Time: _read(); definition = PrimitiveDefinition.Time; break; case TokenType.ObjectId: _read(); definition = PrimitiveDefinition.ObjectId; break; case TokenType.Generic: _read(); definition = PrimitiveDefinition.Generic; break; case TokenType.Enumerated: definition = _parseEnumeration(); break; case TokenType.BitString: definition = _parseBitString(); break; case TokenType.Sequence: definition = _parseSequence(); break; case TokenType.Choice: definition = _parseChoice(); break; case TokenType.Identifier: definition = new NameDefinition(_get(TokenType.Identifier)); break; default: throw new InvalidDataException(type.ToString()); } if(eagerOptional && _peekType() == TokenType.Optional) { definition = new OptionDefinition(definition); _read(); } return definition; }
/// <summary> /// Generates an name alias type /// </summary> /// <param name="emitter">The emitter to write to</param> /// <param name="typeName">The name of the type</param> /// <param name="def">The name definition</param> /// <param name="root">True if this is the root type, false otherwise</param> private void _generateNameType(CSharpEmitter emitter, string typeName, string fieldName, NameDefinition def, bool root) { if(root) { typeName = _getDefinitionName(typeName, fieldName, def); var elementTypeName = _getDefinitionName(null, null, def); using (var wrapper = _generateWrapperType(emitter, typeName, elementTypeName)) { } } }