diff --git a/contrib/openddlparser/code/OpenDDLParser.cpp b/contrib/openddlparser/code/OpenDDLParser.cpp index 104471965..c1b36620c 100644 --- a/contrib/openddlparser/code/OpenDDLParser.cpp +++ b/contrib/openddlparser/code/OpenDDLParser.cpp @@ -46,6 +46,7 @@ namespace Grammar { static const char *BoolTrue = "true"; static const char *BoolFalse = "false"; static const char *RefToken = "ref"; + static const char *CommaSeparator = ","; static const char* PrimitiveTypeToken[ Value::ddl_types_max ] = { "bool", @@ -752,13 +753,16 @@ char *OpenDDLParser::parseHexaLiteral( char *in, char *end, Value **data ) { int value( 0 ); while( pos > 0 ) { + int v = hex2Decimal( *start ); pos--; - value += hex2Decimal( *start ) * static_cast( pow( 16.0, pos ) ); + value = ( value << 4 ) | v; start++; } - *data = ValueAllocator::allocPrimData( Value::ddl_int32 ); - (*data)->setInt32( value ); + *data = ValueAllocator::allocPrimData( Value::ddl_unsigned_int64 ); + if( ddl_nullptr != *data ) { + ( *data )->setUnsignedInt64( value ); + } return in; } @@ -856,7 +860,7 @@ char *OpenDDLParser::parseDataList( char *in, char *end, Value **data, size_t &n return in; } -DataArrayList *createDataArrayList( Value *currentValue, size_t numValues ) { +static DataArrayList *createDataArrayList( Value *currentValue, size_t numValues ) { DataArrayList *dataList = new DataArrayList; dataList->m_dataList = currentValue; dataList->m_numItems = numValues; @@ -892,7 +896,7 @@ char *OpenDDLParser::parseDataArrayList( char *in, char *end, DataArrayList **da } } } - } while( ',' == *in && in != end ); + } while( Grammar::CommaSeparator[ 0 ] == *in && in != end ); in = lookForNextToken( in, end ); in++; } diff --git a/contrib/openddlparser/code/Value.cpp b/contrib/openddlparser/code/Value.cpp index 5e88d6572..c815d52a2 100644 --- a/contrib/openddlparser/code/Value.cpp +++ b/contrib/openddlparser/code/Value.cpp @@ -88,6 +88,47 @@ int64 Value::getInt64() { return ( int64 ) ( *m_data ); } +void Value::setUnsignedInt8( uint8 value ) { + assert( ddl_unsigned_int8 == m_type ); + ::memcpy( m_data, &value, m_size ); +} + +uint8 Value::getUnsignedInt8() const { + assert( ddl_unsigned_int8 == m_type ); + return ( uint8 ) ( *m_data ); +} + +void Value::setUnsignedInt16( uint16 value ) { + assert( ddl_unsigned_int16 == m_type ); + ::memcpy( m_data, &value, m_size ); + +} +uint16 Value::getUnsignedInt16() const { + assert( ddl_unsigned_int16 == m_type ); + return ( uint8 ) ( *m_data ); + +} + +void Value::setUnsignedInt32( uint32 value ) { + assert( ddl_unsigned_int32 == m_type ); + ::memcpy( m_data, &value, m_size ); +} + +uint32 Value::getUnsignedInt32() const { + assert( ddl_unsigned_int32 == m_type ); + return ( uint8 ) ( *m_data ); +} + +void Value::setUnsignedInt64( uint64 value ) { + assert( ddl_unsigned_int64 == m_type ); + ::memcpy( m_data, &value, m_size ); +} + +uint64 Value::getUnsignedInt64() const { + assert( ddl_unsigned_int64 == m_type ); + return ( uint64 ) ( *m_data ); +} + void Value::setFloat( float value ) { assert( ddl_float == m_type ); ::memcpy( m_data, &value, m_size ); diff --git a/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h b/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h index 40e54ea4b..a42fbcf59 100644 --- a/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h +++ b/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h @@ -67,12 +67,52 @@ typedef char int8; typedef short int16; typedef int int32; typedef long int64; +typedef unsigned char uint8; +typedef unsigned short uint16; +typedef unsigned int uint32; +typedef unsigned long uint64; enum NameType { GlobalName, LocalName }; +struct Token { +public: + Token( const char *token ) + : m_token( token ) + , m_size( 0 ){ + if( ddl_nullptr != token ) { + m_size = strlen( m_token ); + } + } + + ~Token() { + // empty + } + + size_t length() const { + return m_size; + } + + bool operator == ( const Token &rhs ) const { + if( m_size != rhs.m_size ) { + return false; + } + + const int res( strncmp( m_token, rhs.m_token, m_size ) ); + return ( res == 0 ); + } + +private: + Token(); + Token( const Token & ); + Token &operator = ( const Token & ); + +private: + const char *m_token; + size_t m_size; +}; struct Name { NameType m_type; Identifier *m_id; diff --git a/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h b/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h index a8d21b710..a4c0f2180 100644 --- a/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h +++ b/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h @@ -227,17 +227,18 @@ static T *getNextSeparator( T *in, T *end ) { return in; } -static const int ErrorHex2Decimal = 9999; +static const int ErrorHex2Decimal = 9999999; inline int hex2Decimal( char in ) { if( isNumeric( in ) ) { - return (int) in-48; + return ( in - 48 ); } + char hexCodeLower( 'a' ), hexCodeUpper( 'A' ); for( int i = 0; i<16; i++ ) { if( in == hexCodeLower + i || in == hexCodeUpper + i ) { - return i+10; + return ( i+10 ); } } diff --git a/contrib/openddlparser/include/openddlparser/Value.h b/contrib/openddlparser/include/openddlparser/Value.h index 48eb6e771..a11b823a3 100644 --- a/contrib/openddlparser/include/openddlparser/Value.h +++ b/contrib/openddlparser/include/openddlparser/Value.h @@ -66,11 +66,19 @@ public: void setInt8( int8 value ); int8 getInt8(); void setInt16( int16 value ); - int16 getInt16(); + int16 getInt16(); void setInt32( int32 value ); - int32 getInt32(); + int32 getInt32(); void setInt64( int64 value ); - int64 getInt64(); + int64 getInt64(); + void setUnsignedInt8( uint8 value ); + uint8 getUnsignedInt8() const; + void setUnsignedInt16( uint16 value ); + uint16 getUnsignedInt16() const; + void setUnsignedInt32( uint32 value ); + uint32 getUnsignedInt32() const; + void setUnsignedInt64( uint64 value ); + uint64 getUnsignedInt64() const; void setFloat( float value ); float getFloat() const; void setDouble( double value );