switch to TinyXML2 which is being fetches as submodule

This commit is contained in:
Markus Tavenrath 2016-02-17 14:03:05 +01:00
parent 027c6091b2
commit cd12306797
4 changed files with 122 additions and 114 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "tinyxml2"]
path = tinyxml2
url = https://github.com/leethomason/tinyxml2.git

View File

@ -28,42 +28,34 @@ cmake_minimum_required(VERSION 3.2)
project(VkCppGenerator) project(VkCppGenerator)
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/tinyxml/tinyxml.cpp")
message(FATAL_ERROR, "TinyXML is missing. Please download the latest version from http://www.grinninglizard.com/tinyxml/index.html and put the sources in a folder named 'tinyxml'")
endif()
set(HEADERS set(HEADERS
) )
set(SOURCES set(SOURCES
main.cpp VkCppGenerator.cpp
) )
set(TINYXML_SOURCES set(TINYXML2_SOURCES
tinyxml/tinyxml.cpp tinyxml2/tinyxml2.cpp
tinyxml/tinyxmlerror.cpp
tinyxml/tinyxmlparser.cpp
tinyxml/tinystr.cpp
) )
set(TINYXML_HEADERS set(TINYXML2_HEADERS
tinyxml/tinyxml.h tinyxml2/tinyxml2.h
tinyxml/tinystr.h
) )
source_group(headers FILES ${HEADERS}) source_group(headers FILES ${HEADERS})
source_group(sources FILES ${SOURCES}) source_group(sources FILES ${SOURCES})
source_group(TinyXML\\headers FILES ${TINYXML_HEADERS}) source_group(TinyXML2\\headers FILES ${TINYXML2_HEADERS})
source_group(TinyXML\\sources FILES ${TINYXML_SOURCES}) source_group(TinyXML2\\sources FILES ${TINYXML2_SOURCES})
add_executable(VkCppGenerator add_executable(VkCppGenerator
${HEADERS} ${HEADERS}
${SOURCES} ${SOURCES}
${TINYXML_SOURCES} ${TINYXML2_SOURCES}
${TINYXML_HEADERS} ${TINYXML2_HEADERS}
) )
set_property(TARGET VkCppGenerator PROPERTY CXX_STANDARD 11) set_property(TARGET VkCppGenerator PROPERTY CXX_STANDARD 11)
target_include_directories(VkCppGenerator PRIVATE "${CMAKE_SOURCE_DIR}/tinyxml") target_include_directories(VkCppGenerator PRIVATE "${CMAKE_SOURCE_DIR}/tinyxml2")

View File

@ -185,7 +185,7 @@ before this line:
# Build instructions for VkCppGenerator # Build instructions for VkCppGenerator
* Clone the repository * Clone the repository: git clone https://github.com/nvpro-pipeline/vkcpp.git
* Download tinyxml from http://www.grinninglizard.com/tinyxml/index.html and extract it in the source folder * Update submodules: git submodule update --init --recursive
* Use CMake to generate a solution or makefile for your favourite build environment * Use CMake to generate a solution or makefile for your favourite build environment
* Launch the build * Launch the build

View File

@ -24,8 +24,10 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assert.h> #include <cassert>
#include <algorithm>
#include <fstream> #include <fstream>
#include <functional>
#include <iostream> #include <iostream>
#include <list> #include <list>
#include <map> #include <map>
@ -34,7 +36,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <tinyxml.h> #include <tinyxml2.h>
#define VK_PROTOTYPES #define VK_PROTOTYPES
@ -175,6 +177,14 @@ const std::string flagsHeader(
"\n" "\n"
); );
// trim from end
std::string trimEnd(std::string const& input)
{
std::string result = input;
result.erase(std::find_if(result.rbegin(), result.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), result.end());
return result;
}
struct MemberData struct MemberData
{ {
std::string type; std::string type;
@ -246,25 +256,25 @@ size_t findComplexIndex(CommandData const& commandData, std::vector<std::pair<si
size_t findReturnIndex(CommandData const& commandData, std::vector<std::pair<size_t, size_t>> const& lenParameters); size_t findReturnIndex(CommandData const& commandData, std::vector<std::pair<size_t, size_t>> const& lenParameters);
std::vector<std::pair<size_t, size_t>> getLenParameters(CommandData const& commandData); std::vector<std::pair<size_t, size_t>> getLenParameters(CommandData const& commandData);
bool noDependencies(std::set<std::string> const& dependencies, std::map<std::string, std::string> & listedTypes); bool noDependencies(std::set<std::string> const& dependencies, std::map<std::string, std::string> & listedTypes);
void readCommandParam( TiXmlElement * element, DependencyData & typeData, std::vector<MemberData> & arguments ); void readCommandParam( tinyxml2::XMLElement * element, DependencyData & typeData, std::vector<MemberData> & arguments );
CommandData & readCommandProto( TiXmlElement * element, std::list<DependencyData> & dependencies, std::map<std::string,CommandData> & commands ); CommandData & readCommandProto( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies, std::map<std::string,CommandData> & commands );
void readCommands( TiXmlElement * element, std::list<DependencyData> & dependencies, std::map<std::string,CommandData> & commands ); void readCommands( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies, std::map<std::string,CommandData> & commands );
void readCommandsCommand( TiXmlElement * element, std::list<DependencyData> & dependencies, std::map<std::string,CommandData> & commands ); void readCommandsCommand( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies, std::map<std::string,CommandData> & commands );
void readEnums( TiXmlElement * element, std::list<DependencyData> & dependencies, std::map<std::string,EnumData> & enums, std::set<std::string> & vkTypes ); void readEnums( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies, std::map<std::string,EnumData> & enums, std::set<std::string> & vkTypes );
void readEnumsEnum( TiXmlElement * element, std::string const& prefix, std::string const& postfix, EnumData & enumData ); void readEnumsEnum( tinyxml2::XMLElement * element, std::string const& prefix, std::string const& postfix, EnumData & enumData );
void readExtensionRequire( TiXmlElement * element, std::vector<std::string> & elements ); void readExtensionRequire( tinyxml2::XMLElement * element, std::vector<std::string> & elements );
void readExtensions( TiXmlElement * element, std::vector<ExtensionData> & extensions ); void readExtensions( tinyxml2::XMLElement * element, std::vector<ExtensionData> & extensions );
void readExtensionsExtension( TiXmlElement * element, std::vector<ExtensionData> & extensions ); void readExtensionsExtension( tinyxml2::XMLElement * element, std::vector<ExtensionData> & extensions );
void readTypeBasetype( TiXmlElement * element, std::list<DependencyData> & dependencies ); void readTypeBasetype( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies );
void readTypeBitmask( TiXmlElement * element, std::list<DependencyData> & dependencies, std::set<std::string> & flags, std::set<std::string> & vkTypes ); void readTypeBitmask( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies, std::set<std::string> & flags, std::set<std::string> & vkTypes );
void readTypeDefine( TiXmlElement * element, std::string & version ); void readTypeDefine( tinyxml2::XMLElement * element, std::string & version );
void readTypeFuncpointer( TiXmlElement * element, std::list<DependencyData> & dependencies ); void readTypeFuncpointer( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies );
void readTypeHandle( TiXmlElement * element, std::list<DependencyData> & dependencies ); void readTypeHandle( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies );
void readTypeStruct( TiXmlElement * element, std::list<DependencyData> & dependencies, std::map<std::string,StructData> & structs, std::set<std::string> & vkTypes ); void readTypeStruct( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies, std::map<std::string,StructData> & structs, std::set<std::string> & vkTypes );
void readTypeStructMember( TiXmlElement * element, std::vector<MemberData> & members, std::set<std::string> & dependencies ); void readTypeStructMember( tinyxml2::XMLElement * element, std::vector<MemberData> & members, std::set<std::string> & dependencies );
void readTypeUnion( TiXmlElement * element, std::list<DependencyData> & dependencies, std::map<std::string,StructData> & structs, std::set<std::string> & vkTypes ); void readTypeUnion( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies, std::map<std::string,StructData> & structs, std::set<std::string> & vkTypes );
void readTypeUnionMember( TiXmlElement * element, std::vector<MemberData> & members, std::set<std::string> & dependencies ); void readTypeUnionMember( tinyxml2::XMLElement * element, std::vector<MemberData> & members, std::set<std::string> & dependencies );
void readTypes( TiXmlElement * element, std::string & version, std::list<DependencyData> & dependencies, std::set<std::string> & flags, std::map<std::string,StructData> & structs, std::set<std::string> & vkTypes ); void readTypes( tinyxml2::XMLElement * element, std::string & version, std::list<DependencyData> & dependencies, std::set<std::string> & flags, std::map<std::string,StructData> & structs, std::set<std::string> & vkTypes );
void sortDependencies( std::list<DependencyData> & dependencies, std::vector<ExtensionData> const& extensions, std::vector<std::vector<DependencyData>> & sortedDependencies ); void sortDependencies( std::list<DependencyData> & dependencies, std::vector<ExtensionData> const& extensions, std::vector<std::vector<DependencyData>> & sortedDependencies );
std::string reduceName(std::string const& name); std::string reduceName(std::string const& name);
std::string strip( std::string const& value, std::string const& prefix ); std::string strip( std::string const& value, std::string const& prefix );
@ -395,7 +405,7 @@ bool noDependencies(std::set<std::string> const& dependencies, std::set<std::str
return( ok ); return( ok );
} }
void readCommandParam( TiXmlElement * element, DependencyData & typeData, std::vector<MemberData> & arguments ) void readCommandParam( tinyxml2::XMLElement * element, DependencyData & typeData, std::vector<MemberData> & arguments )
{ {
arguments.push_back( MemberData() ); arguments.push_back( MemberData() );
MemberData & arg = arguments.back(); MemberData & arg = arguments.back();
@ -405,17 +415,18 @@ void readCommandParam( TiXmlElement * element, DependencyData & typeData, std::v
arg.len = element->Attribute("len"); arg.len = element->Attribute("len");
} }
TiXmlNode * child = element->FirstChild(); tinyxml2::XMLNode * child = element->FirstChild();
assert( child ); assert( child );
if ( child->Type() == TiXmlNode::TINYXML_TEXT ) if ( child->ToText() )
{ {
assert( ( strcmp( child->Value(), "const" ) == 0 ) || ( strcmp( child->Value(), "struct" ) == 0 ) ); std::string value = trimEnd(child->Value());
arg.type = std::string( child->Value() ) + " "; assert( (value == "const") || (value == "struct") );
arg.type = value + " ";
child = child->NextSibling(); child = child->NextSibling();
assert( child ); assert( child );
} }
assert( child->Type() == TiXmlNode::TINYXML_ELEMENT ); assert( child->ToElement() );
assert( ( strcmp( child->Value(), "type" ) == 0 ) && child->ToElement() && child->ToElement()->GetText() ); assert( ( strcmp( child->Value(), "type" ) == 0 ) && child->ToElement() && child->ToElement()->GetText() );
std::string type = strip( child->ToElement()->GetText(), "Vk" ); std::string type = strip( child->ToElement()->GetText(), "Vk" );
typeData.dependencies.insert( type ); typeData.dependencies.insert( type );
@ -424,15 +435,15 @@ void readCommandParam( TiXmlElement * element, DependencyData & typeData, std::v
child = child->NextSibling(); child = child->NextSibling();
assert( child ); assert( child );
if ( child->Type() == TiXmlNode::TINYXML_TEXT ) if ( child->ToText() )
{ {
std::string value = child->Value(); std::string value = trimEnd(child->Value());
assert( ( value == "*" ) || ( value == "**" ) || ( value == "* const*" ) ); assert( ( value == "*" ) || ( value == "**" ) || ( value == "* const*" ) );
arg.type += value; arg.type += value;
child = child->NextSibling(); child = child->NextSibling();
} }
assert( ( child->Type() == TiXmlNode::TINYXML_ELEMENT ) && ( strcmp( child->Value(), "name" ) == 0 ) && child->ToElement() ); assert( child->ToElement() && ( strcmp( child->Value(), "name" ) == 0 ) );
arg.name = child->ToElement()->GetText(); arg.name = child->ToElement()->GetText();
if ( arg.name.back() == ']' ) if ( arg.name.back() == ']' )
@ -447,18 +458,18 @@ void readCommandParam( TiXmlElement * element, DependencyData & typeData, std::v
child = child->NextSibling(); child = child->NextSibling();
if ( child ) if ( child )
{ {
if ( child->Type() == TiXmlNode::TINYXML_TEXT ) if ( child->ToText() )
{ {
std::string value = child->Value(); std::string value = child->Value();
if ( value == "[" ) if ( value == "[" )
{ {
child = child->NextSibling(); child = child->NextSibling();
assert( child ); assert( child );
assert( ( child->Type() == TiXmlNode::TINYXML_ELEMENT ) && ( strcmp( child->Value(), "enum" ) == 0 ) ); assert( child->ToElement() && ( strcmp( child->Value(), "enum" ) == 0 ) );
arg.arraySize = child->ToElement()->GetText(); arg.arraySize = child->ToElement()->GetText();
child = child->NextSibling(); child = child->NextSibling();
assert( child ); assert( child );
assert( child->Type() == TiXmlNode::TINYXML_TEXT ); assert( child->ToText() );
assert( strcmp( child->Value(), "]" ) == 0 ); assert( strcmp( child->Value(), "]" ) == 0 );
assert( !child->NextSibling() ); assert( !child->NextSibling() );
} }
@ -472,11 +483,11 @@ void readCommandParam( TiXmlElement * element, DependencyData & typeData, std::v
} }
} }
CommandData & readCommandProto( TiXmlElement * element, std::list<DependencyData> & dependencies, std::map<std::string,CommandData> & commands ) CommandData & readCommandProto( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies, std::map<std::string,CommandData> & commands )
{ {
TiXmlElement * typeElement = element->FirstChildElement(); tinyxml2::XMLElement * typeElement = element->FirstChildElement();
assert( typeElement && ( strcmp( typeElement->Value(), "type" ) == 0 ) ); assert( typeElement && ( strcmp( typeElement->Value(), "type" ) == 0 ) );
TiXmlElement * nameElement = typeElement->NextSiblingElement(); tinyxml2::XMLElement * nameElement = typeElement->NextSiblingElement();
assert( nameElement && ( strcmp( nameElement->Value(), "name" ) == 0 ) ); assert( nameElement && ( strcmp( nameElement->Value(), "name" ) == 0 ) );
assert( !nameElement->NextSiblingElement() ); assert( !nameElement->NextSiblingElement() );
@ -494,9 +505,9 @@ CommandData & readCommandProto( TiXmlElement * element, std::list<DependencyData
return it->second; return it->second;
} }
void readCommands( TiXmlElement * element, std::list<DependencyData> & dependencies, std::map<std::string,CommandData> & commands ) void readCommands( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies, std::map<std::string,CommandData> & commands )
{ {
TiXmlElement * child = element->FirstChildElement(); tinyxml2::XMLElement * child = element->FirstChildElement();
assert( child ); assert( child );
do do
{ {
@ -505,9 +516,9 @@ void readCommands( TiXmlElement * element, std::list<DependencyData> & dependenc
} while ( child = child->NextSiblingElement() ); } while ( child = child->NextSiblingElement() );
} }
void readCommandsCommand( TiXmlElement * element, std::list<DependencyData> & dependencies, std::map<std::string,CommandData> & commands ) void readCommandsCommand( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies, std::map<std::string,CommandData> & commands )
{ {
TiXmlElement * child = element->FirstChildElement(); tinyxml2::XMLElement * child = element->FirstChildElement();
assert( child && ( strcmp( child->Value(), "proto" ) == 0 ) ); assert( child && ( strcmp( child->Value(), "proto" ) == 0 ) );
CommandData & commandData = readCommandProto( child, dependencies, commands ); CommandData & commandData = readCommandProto( child, dependencies, commands );
@ -526,7 +537,7 @@ void readCommandsCommand( TiXmlElement * element, std::list<DependencyData> & de
} }
} }
void readEnums( TiXmlElement * element, std::list<DependencyData> & dependencies, std::map<std::string,EnumData> & enums, std::set<std::string> & vkTypes ) void readEnums( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies, std::map<std::string,EnumData> & enums, std::set<std::string> & vkTypes )
{ {
assert( element->Attribute( "name" ) ); assert( element->Attribute( "name" ) );
std::string name = strip( element->Attribute( "name" ), "Vk" ); std::string name = strip( element->Attribute( "name" ), "Vk" );
@ -559,9 +570,9 @@ void readEnums( TiXmlElement * element, std::list<DependencyData> & dependencies
} }
} }
void readEnumsEnum( TiXmlElement * element, std::string const& prefix, std::string const& postfix, EnumData & enumData ) void readEnumsEnum( tinyxml2::XMLElement * element, std::string const& prefix, std::string const& postfix, EnumData & enumData )
{ {
TiXmlElement * child = element->FirstChildElement(); tinyxml2::XMLElement * child = element->FirstChildElement();
do do
{ {
if ( child->Attribute( "name" ) ) if ( child->Attribute( "name" ) )
@ -581,9 +592,9 @@ void readEnumsEnum( TiXmlElement * element, std::string const& prefix, std::stri
} while ( child = child->NextSiblingElement() ); } while ( child = child->NextSiblingElement() );
} }
void readExtensionRequire( TiXmlElement * element, std::vector<std::string> & elements ) void readExtensionRequire( tinyxml2::XMLElement * element, std::vector<std::string> & elements )
{ {
TiXmlElement * child = element->FirstChildElement(); tinyxml2::XMLElement * child = element->FirstChildElement();
do do
{ {
std::string value = child->Value(); std::string value = child->Value();
@ -605,9 +616,9 @@ void readExtensionRequire( TiXmlElement * element, std::vector<std::string> & el
} while ( child = child->NextSiblingElement() ); } while ( child = child->NextSiblingElement() );
} }
void readExtensions( TiXmlElement * element, std::vector<ExtensionData> & extensions ) void readExtensions( tinyxml2::XMLElement * element, std::vector<ExtensionData> & extensions )
{ {
TiXmlElement * child = element->FirstChildElement(); tinyxml2::XMLElement * child = element->FirstChildElement();
assert( child ); assert( child );
do do
{ {
@ -616,7 +627,7 @@ void readExtensions( TiXmlElement * element, std::vector<ExtensionData> & extens
} while ( child = child->NextSiblingElement() ); } while ( child = child->NextSiblingElement() );
} }
void readExtensionsExtension( TiXmlElement * element, std::vector<ExtensionData> & extensions ) void readExtensionsExtension( tinyxml2::XMLElement * element, std::vector<ExtensionData> & extensions )
{ {
extensions.push_back( ExtensionData() ); extensions.push_back( ExtensionData() );
ExtensionData & ext = extensions.back(); ExtensionData & ext = extensions.back();
@ -628,19 +639,19 @@ void readExtensionsExtension( TiXmlElement * element, std::vector<ExtensionData>
ext.protect = element->Attribute( "protect" ); ext.protect = element->Attribute( "protect" );
} }
TiXmlElement * child = element->FirstChildElement(); tinyxml2::XMLElement * child = element->FirstChildElement();
assert( child && ( strcmp( child->Value(), "require" ) == 0 ) && !child->NextSiblingElement() ); assert( child && ( strcmp( child->Value(), "require" ) == 0 ) && !child->NextSiblingElement() );
readExtensionRequire( child, ext.elements ); readExtensionRequire( child, ext.elements );
} }
void readTypeBasetype( TiXmlElement * element, std::list<DependencyData> & dependencies ) void readTypeBasetype( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies )
{ {
TiXmlElement * typeElement = element->FirstChildElement(); tinyxml2::XMLElement * typeElement = element->FirstChildElement();
assert( typeElement && ( strcmp( typeElement->Value(), "type" ) == 0 ) && typeElement->GetText() ); assert( typeElement && ( strcmp( typeElement->Value(), "type" ) == 0 ) && typeElement->GetText() );
std::string type = typeElement->GetText(); std::string type = typeElement->GetText();
assert( ( type == "uint32_t" ) || ( type == "uint64_t" ) ); assert( ( type == "uint32_t" ) || ( type == "uint64_t" ) );
TiXmlElement * nameElement = typeElement->NextSiblingElement(); tinyxml2::XMLElement * nameElement = typeElement->NextSiblingElement();
assert( nameElement && ( strcmp( nameElement->Value(), "name" ) == 0 ) && nameElement->GetText() ); assert( nameElement && ( strcmp( nameElement->Value(), "name" ) == 0 ) && nameElement->GetText() );
std::string name = strip( nameElement->GetText(), "Vk" ); std::string name = strip( nameElement->GetText(), "Vk" );
@ -656,13 +667,13 @@ void readTypeBasetype( TiXmlElement * element, std::list<DependencyData> & depen
} }
} }
void readTypeBitmask( TiXmlElement * element, std::list<DependencyData> & dependencies, std::set<std::string> & flags, std::set<std::string> & vkTypes ) void readTypeBitmask( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies, std::set<std::string> & flags, std::set<std::string> & vkTypes )
{ {
TiXmlElement * typeElement = element->FirstChildElement(); tinyxml2::XMLElement * typeElement = element->FirstChildElement();
assert( typeElement && ( strcmp( typeElement->Value(), "type" ) == 0 ) && typeElement->GetText() && ( strcmp( typeElement->GetText(), "VkFlags" ) == 0 ) ); assert( typeElement && ( strcmp( typeElement->Value(), "type" ) == 0 ) && typeElement->GetText() && ( strcmp( typeElement->GetText(), "VkFlags" ) == 0 ) );
std::string type = typeElement->GetText(); std::string type = typeElement->GetText();
TiXmlElement * nameElement = typeElement->NextSiblingElement(); tinyxml2::XMLElement * nameElement = typeElement->NextSiblingElement();
assert( nameElement && ( strcmp( nameElement->Value(), "name" ) == 0 ) && nameElement->GetText() ); assert( nameElement && ( strcmp( nameElement->Value(), "name" ) == 0 ) && nameElement->GetText() );
std::string name = strip( nameElement->GetText(), "Vk" ); std::string name = strip( nameElement->GetText(), "Vk" );
@ -685,54 +696,55 @@ void readTypeBitmask( TiXmlElement * element, std::list<DependencyData> & depend
} }
} }
void readTypeDefine( TiXmlElement * element, std::string & version ) void readTypeDefine( tinyxml2::XMLElement * element, std::string & version )
{ {
TiXmlElement * child = element->FirstChildElement(); tinyxml2::XMLElement * child = element->FirstChildElement();
if ( child && ( strcmp( child->GetText(), "VK_API_VERSION" ) == 0 ) ) if ( child && ( strcmp( child->GetText(), "VK_API_VERSION" ) == 0 ) )
{ {
version = element->LastChild()->ToText()->Value(); version = element->LastChild()->ToText()->Value();
} }
} }
void readTypeFuncpointer( TiXmlElement * element, std::list<DependencyData> & dependencies ) void readTypeFuncpointer( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies )
{ {
TiXmlElement * child = element->FirstChildElement(); tinyxml2::XMLElement * child = element->FirstChildElement();
assert( child && ( strcmp( child->Value(), "name" ) == 0 ) && child->GetText() ); assert( child && ( strcmp( child->Value(), "name" ) == 0 ) && child->GetText() );
dependencies.push_back( DependencyData( DependencyData::Category::FUNC_POINTER, child->GetText() ) ); dependencies.push_back( DependencyData( DependencyData::Category::FUNC_POINTER, child->GetText() ) );
} }
void readTypeHandle( TiXmlElement * element, std::list<DependencyData> & dependencies ) void readTypeHandle( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies )
{ {
TiXmlElement * typeElement = element->FirstChildElement(); tinyxml2::XMLElement * typeElement = element->FirstChildElement();
assert( typeElement && ( strcmp( typeElement->Value(), "type" ) == 0 ) && typeElement->GetText() ); assert( typeElement && ( strcmp( typeElement->Value(), "type" ) == 0 ) && typeElement->GetText() );
#if !defined(NDEBUG) #if !defined(NDEBUG)
std::string type = typeElement->GetText(); std::string type = typeElement->GetText();
assert( type.find( "VK_DEFINE" ) == 0 ); assert( type.find( "VK_DEFINE" ) == 0 );
#endif #endif
TiXmlElement * nameElement = typeElement->NextSiblingElement(); tinyxml2::XMLElement * nameElement = typeElement->NextSiblingElement();
assert( nameElement && ( strcmp( nameElement->Value(), "name" ) == 0 ) && nameElement->GetText() ); assert( nameElement && ( strcmp( nameElement->Value(), "name" ) == 0 ) && nameElement->GetText() );
std::string name = strip( nameElement->GetText(), "Vk" ); std::string name = strip( nameElement->GetText(), "Vk" );
dependencies.push_back( DependencyData( DependencyData::Category::HANDLE, name ) ); dependencies.push_back( DependencyData( DependencyData::Category::HANDLE, name ) );
} }
void readTypeStructMember( TiXmlElement * element, std::vector<MemberData> & members, std::set<std::string> & dependencies ) void readTypeStructMember( tinyxml2::XMLElement * element, std::vector<MemberData> & members, std::set<std::string> & dependencies )
{ {
members.push_back( MemberData() ); members.push_back( MemberData() );
MemberData & member = members.back(); MemberData & member = members.back();
TiXmlNode * child = element->FirstChild(); tinyxml2::XMLNode * child = element->FirstChild();
assert( child ); assert( child );
if ( child->Type() == TiXmlNode::TINYXML_TEXT ) if ( child->ToText())
{ {
assert( ( strcmp( child->Value(), "const" ) == 0 ) || ( strcmp( child->Value(), "struct" ) == 0 ) ); std::string value = trimEnd(child->Value());
member.type = std::string( child->Value() ) + " "; assert( (value == "const") || (value == "struct") );
member.type = value + " ";
child = child->NextSibling(); child = child->NextSibling();
assert( child ); assert( child );
} }
assert( child->Type() == TiXmlNode::TINYXML_ELEMENT ); assert( child->ToElement() );
assert( ( strcmp( child->Value(), "type" ) == 0 ) && child->ToElement() && child->ToElement()->GetText() ); assert( ( strcmp( child->Value(), "type" ) == 0 ) && child->ToElement() && child->ToElement()->GetText() );
std::string type = strip( child->ToElement()->GetText(), "Vk" ); std::string type = strip( child->ToElement()->GetText(), "Vk" );
dependencies.insert( type ); dependencies.insert( type );
@ -741,15 +753,15 @@ void readTypeStructMember( TiXmlElement * element, std::vector<MemberData> & mem
child = child->NextSibling(); child = child->NextSibling();
assert( child ); assert( child );
if ( child->Type() == TiXmlNode::TINYXML_TEXT ) if ( child->ToText())
{ {
std::string value = child->Value(); std::string value = trimEnd(child->Value());
assert( ( value == "*" ) || ( value == "**" ) || ( value == "* const*" ) ); assert( ( value == "*" ) || ( value == "**" ) || ( value == "* const*" ) );
member.type += value; member.type += value;
child = child->NextSibling(); child = child->NextSibling();
} }
assert( ( child->Type() == TiXmlNode::TINYXML_ELEMENT ) && ( strcmp( child->Value(), "name" ) == 0 ) && child->ToElement() ); assert( ( child->ToElement() && strcmp( child->Value(), "name" ) == 0 ));
member.name = child->ToElement()->GetText(); member.name = child->ToElement()->GetText();
if ( member.name.back() == ']' ) if ( member.name.back() == ']' )
@ -765,18 +777,18 @@ void readTypeStructMember( TiXmlElement * element, std::vector<MemberData> & mem
if ( child ) if ( child )
{ {
assert( member.arraySize.empty() ); assert( member.arraySize.empty() );
if ( child->Type() == TiXmlNode::TINYXML_TEXT ) if ( child->ToText() )
{ {
std::string value = child->Value(); std::string value = child->Value();
if ( value == "[" ) if ( value == "[" )
{ {
child = child->NextSibling(); child = child->NextSibling();
assert( child ); assert( child );
assert( ( child->Type() == TiXmlNode::TINYXML_ELEMENT ) && ( strcmp( child->Value(), "enum" ) == 0 ) ); assert( child->ToElement() && ( strcmp( child->Value(), "enum" ) == 0 ) );
member.arraySize = child->ToElement()->GetText(); member.arraySize = child->ToElement()->GetText();
child = child->NextSibling(); child = child->NextSibling();
assert( child ); assert( child );
assert( child->Type() == TiXmlNode::TINYXML_TEXT ); assert( child->ToText() );
assert( strcmp( child->Value(), "]" ) == 0 ); assert( strcmp( child->Value(), "]" ) == 0 );
assert( !child->NextSibling() ); assert( !child->NextSibling() );
} }
@ -790,7 +802,7 @@ void readTypeStructMember( TiXmlElement * element, std::vector<MemberData> & mem
} }
} }
void readTypeStruct( TiXmlElement * element, std::list<DependencyData> & dependencies, std::map<std::string,StructData> & structs, std::set<std::string> & vkTypes ) void readTypeStruct( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies, std::map<std::string,StructData> & structs, std::set<std::string> & vkTypes )
{ {
assert( !element->Attribute( "returnedonly" ) || ( strcmp( element->Attribute( "returnedonly" ), "true" ) == 0 ) ); assert( !element->Attribute( "returnedonly" ) || ( strcmp( element->Attribute( "returnedonly" ), "true" ) == 0 ) );
@ -808,7 +820,7 @@ void readTypeStruct( TiXmlElement * element, std::list<DependencyData> & depende
std::map<std::string,StructData>::iterator it = structs.insert( std::make_pair( name, StructData() ) ).first; std::map<std::string,StructData>::iterator it = structs.insert( std::make_pair( name, StructData() ) ).first;
it->second.returnedOnly = !!element->Attribute( "returnedonly" ); it->second.returnedOnly = !!element->Attribute( "returnedonly" );
TiXmlElement * child = element->FirstChildElement(); tinyxml2::XMLElement * child = element->FirstChildElement();
do do
{ {
assert( child->Value() ); assert( child->Value() );
@ -827,14 +839,14 @@ void readTypeStruct( TiXmlElement * element, std::list<DependencyData> & depende
vkTypes.insert( name ); vkTypes.insert( name );
} }
void readTypeUnionMember( TiXmlElement * element, std::vector<MemberData> & members, std::set<std::string> & dependencies ) void readTypeUnionMember( tinyxml2::XMLElement * element, std::vector<MemberData> & members, std::set<std::string> & dependencies )
{ {
members.push_back( MemberData() ); members.push_back( MemberData() );
MemberData & member = members.back(); MemberData & member = members.back();
TiXmlNode * child = element->FirstChild(); tinyxml2::XMLNode * child = element->FirstChild();
assert( child ); assert( child );
if ( child->Type() == TiXmlNode::TINYXML_TEXT ) if ( child->ToText() )
{ {
assert( ( strcmp( child->Value(), "const" ) == 0 ) || ( strcmp( child->Value(), "struct" ) == 0 ) ); assert( ( strcmp( child->Value(), "const" ) == 0 ) || ( strcmp( child->Value(), "struct" ) == 0 ) );
member.type = std::string( child->Value() ) + " "; member.type = std::string( child->Value() ) + " ";
@ -842,7 +854,7 @@ void readTypeUnionMember( TiXmlElement * element, std::vector<MemberData> & memb
assert( child ); assert( child );
} }
assert( child->Type() == TiXmlNode::TINYXML_ELEMENT ); assert( child->ToElement() );
assert( ( strcmp( child->Value(), "type" ) == 0 ) && child->ToElement() && child->ToElement()->GetText() ); assert( ( strcmp( child->Value(), "type" ) == 0 ) && child->ToElement() && child->ToElement()->GetText() );
std::string type = strip( child->ToElement()->GetText(), "Vk" ); std::string type = strip( child->ToElement()->GetText(), "Vk" );
dependencies.insert( type ); dependencies.insert( type );
@ -851,7 +863,7 @@ void readTypeUnionMember( TiXmlElement * element, std::vector<MemberData> & memb
child = child->NextSibling(); child = child->NextSibling();
assert( child ); assert( child );
if ( child->Type() == TiXmlNode::TINYXML_TEXT ) if ( child->ToText() )
{ {
std::string value = child->Value(); std::string value = child->Value();
assert( ( value == "*" ) || ( value == "**" ) || ( value == "* const*" ) ); assert( ( value == "*" ) || ( value == "**" ) || ( value == "* const*" ) );
@ -859,7 +871,7 @@ void readTypeUnionMember( TiXmlElement * element, std::vector<MemberData> & memb
child = child->NextSibling(); child = child->NextSibling();
} }
assert( ( child->Type() == TiXmlNode::TINYXML_ELEMENT ) && ( strcmp( child->Value(), "name" ) == 0 ) && child->ToElement() ); assert( child->ToElement() && ( strcmp( child->Value(), "name" ) == 0 ) );
member.name = child->ToElement()->GetText(); member.name = child->ToElement()->GetText();
if ( member.name.back() == ']' ) if ( member.name.back() == ']' )
@ -874,18 +886,18 @@ void readTypeUnionMember( TiXmlElement * element, std::vector<MemberData> & memb
child = child->NextSibling(); child = child->NextSibling();
if ( child ) if ( child )
{ {
if ( child->Type() == TiXmlNode::TINYXML_TEXT ) if ( child->ToText() )
{ {
std::string value = child->Value(); std::string value = child->Value();
if ( value == "[" ) if ( value == "[" )
{ {
child = child->NextSibling(); child = child->NextSibling();
assert( child ); assert( child );
assert( ( child->Type() == TiXmlNode::TINYXML_ELEMENT ) && ( strcmp( child->Value(), "enum" ) == 0 ) ); assert( child->ToElement() && ( strcmp( child->Value(), "enum" ) == 0 ) );
member.arraySize = child->ToElement()->GetText(); member.arraySize = child->ToElement()->GetText();
child = child->NextSibling(); child = child->NextSibling();
assert( child ); assert( child );
assert( child->Type() == TiXmlNode::TINYXML_TEXT ); assert( child->ToText() );
assert( strcmp( child->Value(), "]" ) == 0 ); assert( strcmp( child->Value(), "]" ) == 0 );
assert( !child->NextSibling() ); assert( !child->NextSibling() );
} }
@ -899,7 +911,7 @@ void readTypeUnionMember( TiXmlElement * element, std::vector<MemberData> & memb
} }
} }
void readTypeUnion( TiXmlElement * element, std::list<DependencyData> & dependencies, std::map<std::string,StructData> & structs, std::set<std::string> & vkTypes ) void readTypeUnion( tinyxml2::XMLElement * element, std::list<DependencyData> & dependencies, std::map<std::string,StructData> & structs, std::set<std::string> & vkTypes )
{ {
assert( element->Attribute( "name" ) ); assert( element->Attribute( "name" ) );
std::string name = strip( element->Attribute( "name" ), "Vk" ); std::string name = strip( element->Attribute( "name" ), "Vk" );
@ -909,7 +921,7 @@ void readTypeUnion( TiXmlElement * element, std::list<DependencyData> & dependen
assert( structs.find( name ) == structs.end() ); assert( structs.find( name ) == structs.end() );
std::map<std::string,StructData>::iterator it = structs.insert( std::make_pair( name, StructData() ) ).first; std::map<std::string,StructData>::iterator it = structs.insert( std::make_pair( name, StructData() ) ).first;
TiXmlElement * child = element->FirstChildElement(); tinyxml2::XMLElement * child = element->FirstChildElement();
do do
{ {
assert( strcmp( child->Value(), "member" ) == 0 ); assert( strcmp( child->Value(), "member" ) == 0 );
@ -920,9 +932,9 @@ void readTypeUnion( TiXmlElement * element, std::list<DependencyData> & dependen
vkTypes.insert( name ); vkTypes.insert( name );
} }
void readTypes( TiXmlElement * element, std::string & version, std::list<DependencyData> & dependencies, std::set<std::string> & flags, std::map<std::string,StructData> & structs, std::set<std::string> & vkTypes ) void readTypes( tinyxml2::XMLElement * element, std::string & version, std::list<DependencyData> & dependencies, std::set<std::string> & flags, std::map<std::string,StructData> & structs, std::set<std::string> & vkTypes )
{ {
TiXmlElement * child = element->FirstChildElement(); tinyxml2::XMLElement * child = element->FirstChildElement();
do do
{ {
assert( strcmp( child->Value(), "type" ) == 0 ); assert( strcmp( child->Value(), "type" ) == 0 );
@ -1794,15 +1806,16 @@ void writeVersionCheck( std::ofstream & ofs, std::string const& version )
int main( int argc, char **argv ) int main( int argc, char **argv )
{ {
TiXmlDocument doc; tinyxml2::XMLDocument doc;
if ( !doc.LoadFile( argv[1] ) ) tinyxml2::XMLError error = doc.LoadFile( argv[1] );
if (error != tinyxml2::XML_SUCCESS)
{ {
std::cout << "VkGenerate: failed to load file " << argv[1] << std::endl; std::cout << "VkGenerate: failed to load file " << argv[1] << " . Error code: " << error << std::endl;
return -1; return -1;
} }
TiXmlElement * registryElement = doc.FirstChildElement(); tinyxml2::XMLElement * registryElement = doc.FirstChildElement();
assert( strcmp( registryElement->Value(), "registry" ) == 0 ); assert( strcmp( registryElement->Value(), "registry" ) == 0 );
assert( !registryElement->NextSiblingElement() ); assert( !registryElement->NextSiblingElement() );
@ -1815,7 +1828,7 @@ int main( int argc, char **argv )
std::map<std::string,CommandData> commands; std::map<std::string,CommandData> commands;
std::set<std::string> vkTypes; std::set<std::string> vkTypes;
TiXmlElement * child = registryElement->FirstChildElement(); tinyxml2::XMLElement * child = registryElement->FirstChildElement();
do do
{ {
assert( child->Value() ); assert( child->Value() );