Merge pull request #2228 from lukaspj/fix-enginexmlexport

Make EngineAPI Export work properly
This commit is contained in:
Areloch 2018-12-09 14:52:27 -06:00 committed by GitHub
commit e0591ddd2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 577 additions and 364 deletions

View file

@ -663,6 +663,29 @@ public:
T::initPersistFields(); T::initPersistFields();
T::consoleInit(); T::consoleInit();
EnginePropertyTable::Property* props = new EnginePropertyTable::Property[sg_tempFieldList.size()];
for (int i = 0; i < sg_tempFieldList.size(); ++i)
{
EnginePropertyTable::Property prop;
prop.mDocString = sg_tempFieldList[i].pFieldDocs;
prop.mName = sg_tempFieldList[i].pFieldname;
prop.mNumElements = sg_tempFieldList[i].elementCount;
prop.mFlags = 0;
if (sg_tempFieldList[i].type == StartGroupFieldType)
prop.mFlags |= EnginePropertyGroupBegin;
if (sg_tempFieldList[i].type == EndGroupFieldType)
prop.mFlags |= EnginePropertyGroupEnd;
prop.mType = sg_tempFieldList[i].type;
props[i] = prop;
}
_smPropertyTable = EnginePropertyTable(sg_tempFieldList.size(), props);
smPropertyTable = _smPropertyTable;
const_cast<EngineTypeInfo*>(mTypeInfo)->mPropertyTable = &_smPropertyTable;
// Let the base finish up. // Let the base finish up.
AbstractClassRep::init(); AbstractClassRep::init();
} }

View file

@ -25,6 +25,10 @@
#include <tuple> #include <tuple>
#ifndef _FIXEDTUPLE_H_
#include "fixedTuple.h"
#endif
#ifndef _ENGINEEXPORTS_H_ #ifndef _ENGINEEXPORTS_H_
#include "console/engineExports.h" #include "console/engineExports.h"
#endif #endif
@ -94,6 +98,7 @@ template<typename ...ArgTs>
struct _EngineFunctionDefaultArguments< void(ArgTs...) > : public EngineFunctionDefaultArguments struct _EngineFunctionDefaultArguments< void(ArgTs...) > : public EngineFunctionDefaultArguments
{ {
template<typename T> using DefVST = typename EngineTypeTraits<T>::DefaultArgumentValueStoreType; template<typename T> using DefVST = typename EngineTypeTraits<T>::DefaultArgumentValueStoreType;
fixed_tuple<DefVST<ArgTs> ...> mFixedArgs;
std::tuple<DefVST<ArgTs> ...> mArgs; std::tuple<DefVST<ArgTs> ...> mArgs;
private: private:
using SelfType = _EngineFunctionDefaultArguments< void(ArgTs...) >; using SelfType = _EngineFunctionDefaultArguments< void(ArgTs...) >;
@ -130,7 +135,9 @@ private:
public: public:
template<typename ...TailTs> _EngineFunctionDefaultArguments(TailTs ...tail) template<typename ...TailTs> _EngineFunctionDefaultArguments(TailTs ...tail)
: EngineFunctionDefaultArguments({sizeof...(TailTs)}), mArgs(SelfType::tailInit(tail...)) : EngineFunctionDefaultArguments({sizeof...(TailTs)}), mArgs(SelfType::tailInit(tail...))
{} {
fixed_tuple_mutator<void(DefVST<ArgTs>...), void(DefVST<ArgTs>...)>::copy(mArgs, mFixedArgs);
}
}; };
#pragma pack( pop ) #pragma pack( pop )

View file

@ -232,6 +232,9 @@ class EnginePropertyTable
/// Combination of EnginePropertyFlags. /// Combination of EnginePropertyFlags.
U32 mFlags; U32 mFlags;
/// Type-id of the property
U32 mType;
/// Return the name of the property. /// Return the name of the property.
const char* getName() const { return mName; } const char* getName() const { return mName; }
@ -255,6 +258,9 @@ class EnginePropertyTable
/// ///
bool hideInInspectors() const { return ( mFlags & EnginePropertyHideInInspectors ); } bool hideInInspectors() const { return ( mFlags & EnginePropertyHideInInspectors ); }
/// Return the type-id of the property.
U32 getType() const { return mType; }
}; };
protected: protected:

View file

@ -35,32 +35,32 @@
/// actually having to access them directly in the DLL as native entities. /// actually having to access them directly in the DLL as native entities.
static void exportScope( const EngineExportScope* scope, SimXMLDocument* xml, bool addNode = false ); static void exportScope(const EngineExportScope* scope, SimXMLDocument* xml, bool addNode = false);
static String getTypeName( const EngineTypeInfo* type ) static String getTypeName(const EngineTypeInfo* type)
{ {
if( !type ) if (!type)
{ {
static String sVoid( "void" ); static String sVoid("void");
return sVoid; return sVoid;
} }
return type->getFullyQualifiedExportName(); return type->getFullyQualifiedExportName();
} }
static const char* getDocString( const EngineExport* exportInfo ) static const char* getDocString(const EngineExport* exportInfo)
{ {
if( !exportInfo->getDocString() ) if (!exportInfo->getDocString())
return ""; return "";
return exportInfo->getDocString(); return exportInfo->getDocString();
} }
template< typename T > template< typename T >
inline T getArgValue( const EngineFunctionDefaultArguments* defaultArgs, U32 offset ) inline T getArgValue(const EngineFunctionDefaultArguments* defaultArgs, U32 offset)
{ {
return *reinterpret_cast< const T* >( defaultArgs->getArgs() + offset ); return *reinterpret_cast< const T* >(defaultArgs->getArgs() + offset);
} }
@ -71,12 +71,12 @@ static const char* sExportFilterList[] =
"Console", // Console namespace "Console", // Console namespace
}; };
static bool isExportFiltered( const EngineExport* exportInfo ) static bool isExportFiltered(const EngineExport* exportInfo)
{ {
String qualifiedName = exportInfo->getFullyQualifiedExportName(); String qualifiedName = exportInfo->getFullyQualifiedExportName();
for( U32 i = 0; i < ( sizeof( sExportFilterList ) / sizeof( sExportFilterList[ 0 ] ) ); ++ i ) for (U32 i = 0; i < (sizeof(sExportFilterList) / sizeof(sExportFilterList[0])); ++i)
if( qualifiedName.compare( sExportFilterList[ i ] ) == 0 ) if (qualifiedName.compare(sExportFilterList[i]) == 0)
return true; return true;
return false; return false;
@ -90,181 +90,181 @@ static bool isExportFiltered( const EngineExport* exportInfo )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/// Helper to parse argument names out of a prototype string. /// Helper to parse argument names out of a prototype string.
static Vector< String > parseFunctionArgumentNames( const EngineFunctionInfo* function ) static Vector< String > parseFunctionArgumentNames(const EngineFunctionInfo* function)
{ {
Vector< String > argNames; Vector< String > argNames;
const char* prototype = function->getPrototypeString(); const char* prototype = function->getPrototypeString();
if( !prototype ) if (!prototype)
return argNames; return argNames;
const U32 prototypeLength = dStrlen( prototype ); const U32 prototypeLength = dStrlen(prototype);
const char* prototypeEnd = &prototype[ prototypeLength ]; const char* prototypeEnd = &prototype[prototypeLength];
const char* ptr = prototypeEnd - 1; const char* ptr = prototypeEnd - 1;
// Search for right parenthesis. // Search for right parenthesis.
while( ptr >= prototype && *ptr != ')' ) while (ptr >= prototype && *ptr != ')')
ptr --; ptr--;
if( ptr < prototype ) if (ptr < prototype)
return argNames; return argNames;
ptr --; ptr--;
while( ptr >= prototype && *ptr != '(' ) while (ptr >= prototype && *ptr != '(')
{ {
// Skip back over spaces. // Skip back over spaces.
while( ptr >= prototype && dIsspace( *ptr ) ) while (ptr >= prototype && dIsspace(*ptr))
ptr --; ptr--;
if( ptr < prototype ) if (ptr < prototype)
return argNames; return argNames;
// Parse out name. // Parse out name.
const char* end = ptr + 1; const char* end = ptr + 1;
while( ptr > prototype && dIsalnum( *ptr ) ) while (ptr > prototype && dIsalnum(*ptr))
ptr --; ptr--;
const char* start = ptr + 1; const char* start = ptr + 1;
// Skip back over spaces. // Skip back over spaces.
while( ptr >= prototype && dIsspace( *ptr ) ) while (ptr >= prototype && dIsspace(*ptr))
ptr --; ptr--;
// If we're sure we don't have just a type name without an // If we're sure we don't have just a type name without an
// argument name, copy out the argument name name. // argument name, copy out the argument name name.
if( ptr >= prototype && *ptr != ',' && *ptr != '(' && end > start ) if (ptr >= prototype && *ptr != ',' && *ptr != '(' && end > start)
argNames.push_front( String( start, end - start ) ); argNames.push_front(String(start, end - start));
else else
argNames.push_front( "" ); argNames.push_front("");
// Skip back to comma or opening parenthesis. // Skip back to comma or opening parenthesis.
U32 parenNestingCount = 0; U32 parenNestingCount = 0;
while( ptr >= prototype ) while (ptr >= prototype)
{ {
if( *ptr == ')' ) if (*ptr == ')')
parenNestingCount ++; parenNestingCount++;
else if( *ptr == '(' ) else if (*ptr == '(')
parenNestingCount --; parenNestingCount--;
else if( *ptr == ',' && parenNestingCount == 0 ) else if (*ptr == ',' && parenNestingCount == 0)
{ {
ptr --; ptr--;
break; break;
} }
else if( *ptr == '(' && parenNestingCount == 0 ) else if (*ptr == '(' && parenNestingCount == 0)
break; break;
ptr --; ptr--;
} }
} }
// Add 'this' parameter if this is a method. // Add 'this' parameter if this is a method.
if( dStrncmp( prototype, "virtual ", sizeof( "virtual " ) - 1 ) == 0 ) if (dStrncmp(prototype, "virtual ", sizeof("virtual ") - 1) == 0)
argNames.push_front( "this" ); argNames.push_front("this");
return argNames; return argNames;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
static String getDefaultArgumentValue( const EngineFunctionInfo* function, const EngineTypeInfo* type, U32 offset ) static String getDefaultArgumentValue(const EngineFunctionInfo* function, const EngineTypeInfo* type, U32 offset)
{ {
String value; String value;
const EngineFunctionDefaultArguments* defaultArgs = function->getDefaultArguments(); const EngineFunctionDefaultArguments* defaultArgs = function->getDefaultArguments();
switch( type->getTypeKind() ) switch (type->getTypeKind())
{ {
case EngineTypeKindPrimitive: case EngineTypeKindPrimitive:
{ {
#define PRIMTYPE( tp ) \ #define PRIMTYPE( tp ) \
if( TYPE< tp >() == type ) \ if( TYPE< tp >() == type ) \
{ \ { \
tp val = getArgValue< tp >( defaultArgs, offset ); \ tp val = getArgValue< tp >( defaultArgs, offset ); \
value = String::ToString( val ); \ value = String::ToString( val ); \
} }
PRIMTYPE( bool ); PRIMTYPE(bool);
PRIMTYPE( S8 ); PRIMTYPE(S8);
PRIMTYPE( U8 ); PRIMTYPE(U8);
PRIMTYPE( S32 ); PRIMTYPE(S32);
PRIMTYPE( U32 ); PRIMTYPE(U32);
PRIMTYPE( F32 ); PRIMTYPE(F32);
PRIMTYPE( F64 ); PRIMTYPE(F64);
//TODO: for now we store string literals in ASCII; needs to be sorted out //TODO: for now we store string literals in ASCII; needs to be sorted out
if( TYPE< const char* >() == type ) if (TYPE< const char* >() == type)
{
const char* val = reinterpret_cast<const char*>(defaultArgs->getArgs() + offset);
value = val;
}
#undef PRIMTYPE
break;
}
case EngineTypeKindEnum:
{
S32 val = getArgValue< S32 >(defaultArgs, offset);
AssertFatal(type->getEnumTable(), "engineXMLExport - Enum type without table!");
const EngineEnumTable& table = *(type->getEnumTable());
const U32 numValues = table.getNumValues();
for (U32 i = 0; i < numValues; ++i)
if (table[i].getInt() == val)
{ {
const char* val = getArgValue< const char* >( defaultArgs, offset ); value = table[i].getName();
value = val; break;
} }
#undef PRIMTYPE break;
break; }
}
case EngineTypeKindEnum: case EngineTypeKindBitfield:
{ {
S32 val = getArgValue< S32 >( defaultArgs, offset ); S32 val = getArgValue< S32 >(defaultArgs, offset);
AssertFatal( type->getEnumTable(), "engineXMLExport - Enum type without table!" ); AssertFatal(type->getEnumTable(), "engineXMLExport - Bitfield type without table!");
const EngineEnumTable& table = *( type->getEnumTable() ); const EngineEnumTable& table = *(type->getEnumTable());
const U32 numValues = table.getNumValues(); const U32 numValues = table.getNumValues();
for( U32 i = 0; i < numValues; ++ i ) bool isFirst = true;
if( table[ i ].getInt() == val ) for (U32 i = 0; i < numValues; ++i)
{ if (table[i].getInt() & val)
value = table[ i ].getName(); {
break; if (!isFirst)
} value += '|';
break; value = table[i].getName();
} isFirst = false;
}
case EngineTypeKindBitfield: break;
{ }
S32 val = getArgValue< S32 >( defaultArgs, offset );
AssertFatal( type->getEnumTable(), "engineXMLExport - Bitfield type without table!" );
const EngineEnumTable& table = *( type->getEnumTable() ); case EngineTypeKindStruct:
const U32 numValues = table.getNumValues(); {
//TODO: struct type default argument values
break;
}
bool isFirst = true; case EngineTypeKindClass:
for( U32 i = 0; i < numValues; ++ i ) case EngineTypeKindFunction:
if( table[ i ].getInt() & val ) {
{ // For these two kinds, we support "null" as the only valid
if( !isFirst ) // default value.
value += '|';
value = table[ i ].getName(); const void* ptr = getArgValue< const void* >(defaultArgs, offset);
isFirst = false; if (!ptr)
} value = "null";
break;
}
break; default:
} break;
case EngineTypeKindStruct:
{
//TODO: struct type default argument values
break;
}
case EngineTypeKindClass:
case EngineTypeKindFunction:
{
// For these two kinds, we support "null" as the only valid
// default value.
const void* ptr = getArgValue< const void* >( defaultArgs, offset );
if( !ptr )
value = "null";
break;
}
default:
break;
} }
return value; return value;
@ -272,66 +272,66 @@ static String getDefaultArgumentValue( const EngineFunctionInfo* function, const
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
static void exportFunction( const EngineFunctionInfo* function, SimXMLDocument* xml ) static void exportFunction(const EngineFunctionInfo* function, SimXMLDocument* xml)
{ {
if( isExportFiltered( function ) ) if (isExportFiltered(function))
return; return;
xml->pushNewElement( "EngineFunction" ); xml->pushNewElement("EngineFunction");
xml->setAttribute( "name", function->getExportName() ); xml->setAttribute("name", function->getExportName());
xml->setAttribute( "returnType", getTypeName( function->getReturnType() ) ); xml->setAttribute("returnType", getTypeName(function->getReturnType()));
xml->setAttribute( "symbol", function->getBindingName() ); xml->setAttribute("symbol", function->getBindingName());
xml->setAttribute( "isCallback", function->isCallout() ? "1" : "0" ); xml->setAttribute("isCallback", function->isCallout() ? "1" : "0");
xml->setAttribute( "isVariadic", function->getFunctionType()->isVariadic() ? "1" : "0" ); xml->setAttribute("isVariadic", function->getFunctionType()->isVariadic() ? "1" : "0");
xml->setAttribute( "docs", getDocString( function ) ); xml->setAttribute("docs", getDocString(function));
xml->pushNewElement( "arguments" ); xml->pushNewElement("arguments");
const U32 numArguments = function->getNumArguments(); const U32 numArguments = function->getNumArguments();
const U32 numDefaultArguments = ( function->getDefaultArguments() ? function->getDefaultArguments()->mNumDefaultArgs : 0 ); const U32 numDefaultArguments = (function->getDefaultArguments() ? function->getDefaultArguments()->mNumDefaultArgs : 0);
const U32 firstDefaultArg = numArguments - numDefaultArguments; const U32 firstDefaultArg = numArguments - numDefaultArguments;
Vector< String > argumentNames = parseFunctionArgumentNames( function ); Vector< String > argumentNames = parseFunctionArgumentNames(function);
const U32 numArgumentNames = argumentNames.size(); const U32 numArgumentNames = argumentNames.size();
// Accumulated offset in function argument frame vector. // Accumulated offset in function argument frame vector.
U32 argFrameOffset = 0; U32 argFrameOffset = 0;
for( U32 i = 0; i < numArguments; ++ i ) for (U32 i = 0; i < numArguments; ++i)
{ {
xml->pushNewElement( "EngineFunctionArgument" ); xml->pushNewElement("EngineFunctionArgument");
const EngineTypeInfo* type = function->getArgumentType( i ); const EngineTypeInfo* type = function->getArgumentType(i);
AssertFatal( type != NULL, "exportFunction - Argument cannot have type void!" ); AssertFatal(type != NULL, "exportFunction - Argument cannot have type void!");
String argName; String argName;
if( i < numArgumentNames ) if (i < numArgumentNames)
argName = argumentNames[ i ]; argName = argumentNames[i];
xml->setAttribute( "name", argName ); xml->setAttribute("name", argName);
xml->setAttribute( "type", getTypeName( type ) ); xml->setAttribute("type", getTypeName(type));
if( i >= firstDefaultArg ) if (i >= firstDefaultArg)
{ {
String defaultValue = getDefaultArgumentValue( function, type, argFrameOffset ); String defaultValue = getDefaultArgumentValue(function, type, argFrameOffset);
xml->setAttribute( "defaultValue", defaultValue ); xml->setAttribute("defaultValue", defaultValue);
} }
xml->popElement();
if( type->getTypeKind() == EngineTypeKindStruct )
argFrameOffset += type->getInstanceSize();
else
argFrameOffset += type->getValueSize();
#ifdef _PACK_BUG_WORKAROUNDS
if( argFrameOffset % 4 > 0 )
argFrameOffset += 4 - ( argFrameOffset % 4 );
#endif
}
xml->popElement(); xml->popElement();
if (type->getTypeKind() == EngineTypeKindStruct)
argFrameOffset += type->getInstanceSize();
else
argFrameOffset += type->getValueSize();
#ifdef _PACK_BUG_WORKAROUNDS
if (argFrameOffset % 4 > 0)
argFrameOffset += 4 - (argFrameOffset % 4);
#endif
}
xml->popElement();
xml->popElement(); xml->popElement();
} }
@ -343,147 +343,171 @@ static void exportFunction( const EngineFunctionInfo* function, SimXMLDocument*
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
static void exportType( const EngineTypeInfo* type, SimXMLDocument* xml ) static void exportType(const EngineTypeInfo* type, SimXMLDocument* xml)
{ {
// Don't export anonymous types. // Don't export anonymous types.
if( !type->getTypeName()[ 0 ] ) if (!type->getTypeName()[0])
return; return;
if( isExportFiltered( type ) ) if (isExportFiltered(type))
return; return;
const char* nodeName = NULL; const char* nodeName = NULL;
switch( type->getTypeKind() ) switch (type->getTypeKind())
{ {
case EngineTypeKindPrimitive: case EngineTypeKindPrimitive:
nodeName = "EnginePrimitiveType"; nodeName = "EnginePrimitiveType";
break; break;
case EngineTypeKindEnum: case EngineTypeKindEnum:
nodeName = "EngineEnumType"; nodeName = "EngineEnumType";
break; break;
case EngineTypeKindBitfield: case EngineTypeKindBitfield:
nodeName = "EngineBitfieldType"; nodeName = "EngineBitfieldType";
break; break;
case EngineTypeKindStruct: case EngineTypeKindStruct:
nodeName = "EngineStructType"; nodeName = "EngineStructType";
break; break;
case EngineTypeKindClass: case EngineTypeKindClass:
nodeName = "EngineClassType"; nodeName = "EngineClassType";
break; break;
default: default:
return; return;
} }
xml->pushNewElement( nodeName ); xml->pushNewElement(nodeName);
xml->setAttribute( "name", type->getTypeName() ); xml->setAttribute("name", type->getTypeName());
xml->setAttribute( "size", String::ToString( type->getInstanceSize() ) ); xml->setAttribute("size", String::ToString(type->getInstanceSize()));
xml->setAttribute( "isAbstract", type->isAbstract() ? "1" : "0" ); xml->setAttribute("isAbstract", type->isAbstract() ? "1" : "0");
xml->setAttribute( "isInstantiable", type->isInstantiable() ? "1" : "0" ); xml->setAttribute("isInstantiable", type->isInstantiable() ? "1" : "0");
xml->setAttribute( "isDisposable", type->isDisposable() ? "1" : "0" ); xml->setAttribute("isDisposable", type->isDisposable() ? "1" : "0");
xml->setAttribute( "isSingleton", type->isSingleton() ? "1" : "0" ); xml->setAttribute("isSingleton", type->isSingleton() ? "1" : "0");
xml->setAttribute( "docs", getDocString( type ) ); xml->setAttribute("docs", getDocString(type));
if( type->getSuperType() ) if (type->getSuperType())
xml->setAttribute( "superType", getTypeName( type->getSuperType() ) ); xml->setAttribute("superType", getTypeName(type->getSuperType()));
if( type->getEnumTable() ) if (type->getEnumTable())
{
xml->pushNewElement("enums");
const EngineEnumTable& table = *(type->getEnumTable());
const U32 numValues = table.getNumValues();
for (U32 i = 0; i < numValues; ++i)
{ {
xml->pushNewElement( "enums" ); xml->pushNewElement("EngineEnum");
const EngineEnumTable& table = *( type->getEnumTable() ); xml->setAttribute("name", table[i].getName());
const U32 numValues = table.getNumValues(); xml->setAttribute("value", String::ToString(table[i].getInt()));
xml->setAttribute("docs", table[i].getDocString() ? table[i].getDocString() : "");
for( U32 i = 0; i < numValues; ++ i )
{
xml->pushNewElement( "EngineEnum" );
xml->setAttribute( "name", table[ i ].getName() );
xml->setAttribute( "value", String::ToString( table[ i ].getInt() ) );
xml->setAttribute( "docs", table[ i ].getDocString() ? table[ i ].getDocString() : "" );
xml->popElement();
}
xml->popElement(); xml->popElement();
} }
else if( type->getFieldTable() )
xml->popElement();
}
else if (type->getFieldTable())
{
xml->pushNewElement("fields");
const EngineFieldTable& table = *(type->getFieldTable());
const U32 numFields = table.getNumFields();
for (U32 i = 0; i < numFields; ++i)
{ {
xml->pushNewElement( "fields" ); const EngineFieldTable::Field& field = table[i];
const EngineFieldTable& table = *( type->getFieldTable() ); xml->pushNewElement("EngineField");
const U32 numFields = table.getNumFields();
for( U32 i = 0; i < numFields; ++ i ) xml->setAttribute("name", field.getName());
{ xml->setAttribute("type", getTypeName(field.getType()));
const EngineFieldTable::Field& field = table[ i ]; xml->setAttribute("offset", String::ToString(field.getOffset()));
xml->setAttribute("indexedSize", String::ToString(field.getNumElements()));
xml->pushNewElement( "EngineField" ); xml->setAttribute("docs", field.getDocString() ? field.getDocString() : "");
xml->setAttribute( "name", field.getName() );
xml->setAttribute( "type", getTypeName( field.getType() ) );
xml->setAttribute( "offset", String::ToString( field.getOffset() ) );
xml->setAttribute( "indexedSize", String::ToString( field.getNumElements() ) );
xml->setAttribute( "docs", field.getDocString() ? field.getDocString() : "" );
xml->popElement();
}
xml->popElement(); xml->popElement();
} }
else if( type->getPropertyTable() )
xml->popElement();
}
else if (type->getPropertyTable())
{
xml->pushNewElement("properties");
const EnginePropertyTable& table = *(type->getPropertyTable());
const U32 numProperties = table.getNumProperties();
U32 groupNestingDepth = 0;
for (U32 i = 0; i < numProperties; ++i)
{ {
xml->pushNewElement( "properties" ); const EnginePropertyTable::Property& property = table[i];
const EnginePropertyTable& table = *( type->getPropertyTable() ); if (property.isGroupBegin())
const U32 numProperties = table.getNumProperties(); {
U32 groupNestingDepth = 0; groupNestingDepth++;
xml->pushNewElement("EnginePropertyGroup");
for( U32 i = 0; i < numProperties; ++ i ) xml->setAttribute("name", property.getName());
xml->setAttribute("indexedSize", String::ToString(property.getNumElements()));
xml->setAttribute("docs", property.getDocString() ? property.getDocString() : "");
xml->pushNewElement("properties");
}
else if (property.isGroupEnd())
{
groupNestingDepth--;
xml->popElement();
xml->popElement();
}
else
{
if (property.getType() == AbstractClassRep::StartArrayFieldType
|| property.getType() == AbstractClassRep::EndArrayFieldType) {
continue;
}
xml->pushNewElement("EngineProperty");
xml->setAttribute("name", property.getName());
xml->setAttribute("indexedSize", String::ToString(property.getNumElements()));
xml->setAttribute("isConstant", property.isConstant() ? "1" : "0");
xml->setAttribute("isTransient", property.isTransient() ? "1" : "0");
xml->setAttribute("isVisible", property.hideInInspectors() ? "0" : "1");
xml->setAttribute("docs", property.getDocString() ? property.getDocString() : "");
const bool isDeprecated = (property.getType() == AbstractClassRep::DeprecatedFieldType);
if (isDeprecated)
{ {
const EnginePropertyTable::Property& property = table[ i ]; xml->setAttribute("type", "deprecated");
}
if( property.isGroupBegin() ) else
{
ConsoleBaseType *cbt = ConsoleBaseType::getType(property.getType());
if (cbt != NULL)
{ {
groupNestingDepth ++; xml->setAttribute("type", cbt->getTypeClassName());
xml->pushNewElement( "EnginePropertyGroup" );
xml->setAttribute( "name", property.getName() );
xml->setAttribute( "indexedSize", String::ToString( property.getNumElements() ) );
xml->setAttribute( "docs", property.getDocString() ? property.getDocString() : "" );
xml->pushNewElement( "properties" );
}
else if( property.isGroupEnd() )
{
groupNestingDepth --;
xml->popElement();
xml->popElement();
} }
else else
{ {
xml->pushNewElement( "EngineProperty" ); xml->setAttribute("type", "unknown");
xml->setAttribute( "name", property.getName() );
xml->setAttribute( "indexedSize", String::ToString( property.getNumElements() ) );
xml->setAttribute( "isConstant", property.isConstant() ? "1" : "0" );
xml->setAttribute( "isTransient", property.isTransient() ? "1" : "0" );
xml->setAttribute( "isVisible", property.hideInInspectors() ? "0" : "1" );
xml->setAttribute( "docs", property.getDocString() ? property.getDocString() : "" );
xml->popElement();
} }
} }
AssertFatal( !groupNestingDepth, "exportType - Property group nesting mismatch!" ); xml->popElement();
xml->popElement(); }
} }
exportScope( type, xml );
AssertFatal(!groupNestingDepth, "exportType - Property group nesting mismatch!");
xml->popElement();
}
exportScope(type, xml);
xml->popElement(); xml->popElement();
} }
@ -496,63 +520,63 @@ static void exportType( const EngineTypeInfo* type, SimXMLDocument* xml )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
static void exportScope( const EngineExportScope* scope, SimXMLDocument* xml, bool addNode ) static void exportScope(const EngineExportScope* scope, SimXMLDocument* xml, bool addNode)
{ {
if( addNode ) if (addNode)
{ {
if( isExportFiltered( scope ) ) if (isExportFiltered(scope))
return; return;
xml->pushNewElement( "EngineExportScope" ); xml->pushNewElement("EngineExportScope");
xml->setAttribute( "name", scope->getExportName() ); xml->setAttribute("name", scope->getExportName());
xml->setAttribute( "docs", getDocString( scope ) ); xml->setAttribute("docs", getDocString(scope));
} }
// Dump all contained exports. // Dump all contained exports.
xml->pushNewElement( "exports" ); xml->pushNewElement("exports");
for( const EngineExport* exportInfo = scope->getExports(); exportInfo != NULL; exportInfo = exportInfo->getNextExport() ) for (const EngineExport* exportInfo = scope->getExports(); exportInfo != NULL; exportInfo = exportInfo->getNextExport())
{
switch (exportInfo->getExportKind())
{ {
switch( exportInfo->getExportKind() ) case EngineExportKindScope:
{ exportScope(static_cast< const EngineExportScope* >(exportInfo), xml, true);
case EngineExportKindScope: break;
exportScope( static_cast< const EngineExportScope* >( exportInfo ), xml, true );
break;
case EngineExportKindFunction: case EngineExportKindFunction:
exportFunction( static_cast< const EngineFunctionInfo* >( exportInfo ), xml ); exportFunction(static_cast< const EngineFunctionInfo* >(exportInfo), xml);
break; break;
case EngineExportKindType: case EngineExportKindType:
exportType( static_cast< const EngineTypeInfo* >( exportInfo ), xml ); exportType(static_cast< const EngineTypeInfo* >(exportInfo), xml);
break; break;
default: default:
break; break;
}
} }
}
xml->popElement(); xml->popElement();
if( addNode ) if (addNode)
xml->popElement(); xml->popElement();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
DefineEngineFunction( exportEngineAPIToXML, SimXMLDocument*, (),, DefineEngineFunction(exportEngineAPIToXML, SimXMLDocument*, (), ,
"Create a XML document containing a dump of the entire exported engine API.\n\n" "Create a XML document containing a dump of the entire exported engine API.\n\n"
"@return A SimXMLDocument containing a dump of the engine's export information or NULL if the operation failed.\n\n" "@return A SimXMLDocument containing a dump of the engine's export information or NULL if the operation failed.\n\n"
"@ingroup Console" ) "@ingroup Console")
{ {
SimXMLDocument* xml = new SimXMLDocument; SimXMLDocument* xml = new SimXMLDocument;
xml->registerObject(); xml->registerObject();
Sim::getRootGroup()->addObject( xml ); Sim::getRootGroup()->addObject(xml);
xml->addHeader(); xml->addHeader();
exportScope( EngineExportScope::getGlobalScope(), xml, true ); exportScope(EngineExportScope::getGlobalScope(), xml, true);
return xml; return xml;
} }

View file

@ -0,0 +1,153 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _FIXEDTUPLE_H_
#define _FIXEDTUPLE_H_
/// @name Fixed-layout tuple definition
/// These structs and templates serve as a way to pass arguments from external
/// applications and into the T3D console system.
/// They work as std::tuple, but they ensure a standardized fixed memory
/// layout. Allowing for unmanaged calls with these tuples as the parameter
/// lists.
///
/// The implementation is from a SO solution:
/// https://codereview.stackexchange.com/a/52279
/// As out use-case is pretty simple, this code could probably be simplified by
/// stripping out a lot of extra functionality. But eh.
///
/// @{
template <typename ...Ts>
struct fixed_tuple;
template <typename T, typename ...Ts>
struct fixed_tuple<T, Ts...>
{
T first;
fixed_tuple<Ts...> rest;
fixed_tuple() = default;
template <class U, class...Us, class = typename ::std::enable_if<!::std::is_base_of<fixed_tuple, typename ::std::decay<U>::type>::value>::type>
fixed_tuple(U&& u, Us&&...tail) :
first(::std::forward<U>(u)),
rest(::std::forward<Us>(tail)...) {}
};
template <typename T>
struct fixed_tuple<T>
{
T first;
fixed_tuple() = default;
template <class U, class = typename ::std::enable_if<!::std::is_base_of<fixed_tuple, typename ::std::decay<U>::type>::value>::type>
fixed_tuple(U&& u) :
first(::std::forward<U>(u)) {}
};
template <>
struct fixed_tuple<> {};
template < ::std::size_t i, class T>
struct fixed_tuple_element;
template < ::std::size_t i, class T, class... Ts>
struct fixed_tuple_element<i, fixed_tuple<T, Ts...> >
: fixed_tuple_element<i - 1, fixed_tuple<Ts...> >
{};
template <class T, class... Ts>
struct fixed_tuple_element<0, fixed_tuple<T, Ts...> >
{
using type = T;
};
template < ::std::size_t i>
struct fixed_tuple_accessor
{
template <class... Ts>
static inline typename fixed_tuple_element<i, fixed_tuple<Ts...> >::type & get(fixed_tuple<Ts...> & t)
{
return fixed_tuple_accessor<i - 1>::get(t.rest);
}
template <class... Ts>
static inline const typename fixed_tuple_element<i, fixed_tuple<Ts...> >::type & get(const fixed_tuple<Ts...> & t)
{
return fixed_tuple_accessor<i - 1>::get(t.rest);
}
};
template <>
struct fixed_tuple_accessor<0>
{
template <class... Ts>
static inline typename fixed_tuple_element<0, fixed_tuple<Ts...> >::type & get(fixed_tuple<Ts...> & t)
{
return t.first;
}
template <class... Ts>
static inline const typename fixed_tuple_element<0, fixed_tuple<Ts...> >::type & get(const fixed_tuple<Ts...> & t)
{
return t.first;
}
};
template< typename T1, typename T2 >
struct fixed_tuple_mutator {};
template<typename... Tdest, typename... Tsrc>
struct fixed_tuple_mutator<void(Tdest...), void(Tsrc...)>
{
template<std::size_t I = 0>
static inline typename std::enable_if<I == sizeof...(Tsrc), void>::type
copy_r_t_l(fixed_tuple<Tsrc...>& src, fixed_tuple<Tdest...>& dest)
{ }
template<std::size_t I = 0>
static inline typename std::enable_if<I < sizeof...(Tsrc), void>::type
copy_r_t_l(fixed_tuple<Tsrc...>& src, fixed_tuple<Tdest...>& dest)
{
fixed_tuple_accessor<I + (sizeof...(Tdest)-sizeof...(Tsrc))>::get(dest) = fixed_tuple_accessor<I>::get(src);
copy_r_t_l<I + 1>(src, dest);
}
template<std::size_t I = 0>
static inline typename std::enable_if<I == sizeof...(Tsrc), void>::type
copy(std::tuple<Tsrc...>& src, fixed_tuple<Tdest...>& dest)
{ }
template<std::size_t I = 0>
static inline typename std::enable_if<I < sizeof...(Tsrc), void>::type
copy(std::tuple<Tsrc...>& src, fixed_tuple<Tdest...>& dest)
{
fixed_tuple_accessor<I>::get(dest) = std::get<I>(src);
copy<I + 1>(src, dest);
}
};
/// @}
#endif // !_FIXEDTUPLE_H_