2012-09-19 15:15:01 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// 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.
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
#include "console/engineExports.h"
|
|
|
|
|
#include "console/engineAPI.h"
|
|
|
|
|
#include "console/engineTypes.h"
|
|
|
|
|
#include "console/engineFunctions.h"
|
|
|
|
|
#include "console/SimXMLDocument.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// @file
|
|
|
|
|
/// A generator that will dump all export structures contained in an engine
|
|
|
|
|
/// DLL to an XML file which may then be used by wrapper generators to create a
|
|
|
|
|
/// language-specific binding for the engine API. Using XML as an intermediary
|
|
|
|
|
/// format allows the generators to use all of the export structures without
|
|
|
|
|
/// actually having to access them directly in the DLL as native entities.
|
|
|
|
|
|
|
|
|
|
|
2018-04-21 07:08:26 +00:00
|
|
|
static void exportScope(const EngineExportScope* scope, SimXMLDocument* xml, bool addNode = false);
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
|
2018-04-21 07:08:26 +00:00
|
|
|
static String getTypeName(const EngineTypeInfo* type)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
if (!type)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
static String sVoid("void");
|
2012-09-19 15:15:01 +00:00
|
|
|
return sVoid;
|
|
|
|
|
}
|
2018-04-21 07:08:26 +00:00
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
return type->getFullyQualifiedExportName();
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-21 07:08:26 +00:00
|
|
|
static const char* getDocString(const EngineExport* exportInfo)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
if (!exportInfo->getDocString())
|
2012-09-19 15:15:01 +00:00
|
|
|
return "";
|
2018-04-21 07:08:26 +00:00
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
return exportInfo->getDocString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template< typename T >
|
2018-04-21 07:08:26 +00:00
|
|
|
inline T getArgValue(const EngineFunctionDefaultArguments* defaultArgs, U32 offset)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
return *reinterpret_cast< const T* >(defaultArgs->getArgs() + offset);
|
2012-09-19 15:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// List of exports that we want filtered out. This will only be needed as long
|
|
|
|
|
// as the console system is still around.
|
|
|
|
|
static const char* sExportFilterList[] =
|
|
|
|
|
{
|
|
|
|
|
"Console", // Console namespace
|
|
|
|
|
};
|
|
|
|
|
|
2018-04-21 07:08:26 +00:00
|
|
|
static bool isExportFiltered(const EngineExport* exportInfo)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
|
|
|
|
String qualifiedName = exportInfo->getFullyQualifiedExportName();
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
for (U32 i = 0; i < (sizeof(sExportFilterList) / sizeof(sExportFilterList[0])); ++i)
|
|
|
|
|
if (qualifiedName.compare(sExportFilterList[i]) == 0)
|
2012-09-19 15:15:01 +00:00
|
|
|
return true;
|
2018-04-21 07:08:26 +00:00
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Functions.
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// MARK: ---- Functions ----
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
/// Helper to parse argument names out of a prototype string.
|
2018-04-21 07:08:26 +00:00
|
|
|
static Vector< String > parseFunctionArgumentNames(const EngineFunctionInfo* function)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
|
|
|
|
Vector< String > argNames;
|
2018-04-21 07:08:26 +00:00
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
const char* prototype = function->getPrototypeString();
|
2018-04-21 07:08:26 +00:00
|
|
|
if (!prototype)
|
2012-09-19 15:15:01 +00:00
|
|
|
return argNames;
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
const U32 prototypeLength = dStrlen(prototype);
|
|
|
|
|
const char* prototypeEnd = &prototype[prototypeLength];
|
2012-09-19 15:15:01 +00:00
|
|
|
const char* ptr = prototypeEnd - 1;
|
2018-04-21 07:08:26 +00:00
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
// Search for right parenthesis.
|
2018-04-21 07:08:26 +00:00
|
|
|
while (ptr >= prototype && *ptr != ')')
|
|
|
|
|
ptr--;
|
|
|
|
|
|
|
|
|
|
if (ptr < prototype)
|
2012-09-19 15:15:01 +00:00
|
|
|
return argNames;
|
2018-04-21 07:08:26 +00:00
|
|
|
ptr--;
|
|
|
|
|
|
|
|
|
|
while (ptr >= prototype && *ptr != '(')
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
|
|
|
|
// Skip back over spaces.
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
while (ptr >= prototype && dIsspace(*ptr))
|
|
|
|
|
ptr--;
|
|
|
|
|
if (ptr < prototype)
|
2012-09-19 15:15:01 +00:00
|
|
|
return argNames;
|
2018-04-21 07:08:26 +00:00
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
// Parse out name.
|
2018-04-21 07:08:26 +00:00
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
const char* end = ptr + 1;
|
2018-04-21 07:08:26 +00:00
|
|
|
while (ptr > prototype && dIsalnum(*ptr))
|
|
|
|
|
ptr--;
|
2012-09-19 15:15:01 +00:00
|
|
|
const char* start = ptr + 1;
|
2018-04-21 07:08:26 +00:00
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
// Skip back over spaces.
|
|
|
|
|
|
2018-04-21 07:08:26 +00:00
|
|
|
while (ptr >= prototype && dIsspace(*ptr))
|
|
|
|
|
ptr--;
|
|
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
// If we're sure we don't have just a type name without an
|
|
|
|
|
// argument name, copy out the argument name name.
|
|
|
|
|
|
2018-04-21 07:08:26 +00:00
|
|
|
if (ptr >= prototype && *ptr != ',' && *ptr != '(' && end > start)
|
|
|
|
|
argNames.push_front(String(start, end - start));
|
2012-09-19 15:15:01 +00:00
|
|
|
else
|
2018-04-21 07:08:26 +00:00
|
|
|
argNames.push_front("");
|
|
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
// Skip back to comma or opening parenthesis.
|
2018-04-21 07:08:26 +00:00
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
U32 parenNestingCount = 0;
|
2018-04-21 07:08:26 +00:00
|
|
|
while (ptr >= prototype)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
if (*ptr == ')')
|
|
|
|
|
parenNestingCount++;
|
|
|
|
|
else if (*ptr == '(')
|
|
|
|
|
parenNestingCount--;
|
|
|
|
|
else if (*ptr == ',' && parenNestingCount == 0)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
ptr--;
|
2012-09-19 15:15:01 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2018-04-21 07:08:26 +00:00
|
|
|
else if (*ptr == '(' && parenNestingCount == 0)
|
2012-09-19 15:15:01 +00:00
|
|
|
break;
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
ptr--;
|
2012-09-19 15:15:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
2018-04-21 07:08:26 +00:00
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
// Add 'this' parameter if this is a method.
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
if (dStrncmp(prototype, "virtual ", sizeof("virtual ") - 1) == 0)
|
|
|
|
|
argNames.push_front("this");
|
2012-09-19 15:15:01 +00:00
|
|
|
|
|
|
|
|
return argNames;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2018-04-21 07:08:26 +00:00
|
|
|
static String getDefaultArgumentValue(const EngineFunctionInfo* function, const EngineTypeInfo* type, U32 offset)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
|
|
|
|
String value;
|
|
|
|
|
const EngineFunctionDefaultArguments* defaultArgs = function->getDefaultArguments();
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
switch (type->getTypeKind())
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
case EngineTypeKindPrimitive:
|
|
|
|
|
{
|
|
|
|
|
#define PRIMTYPE( tp ) \
|
2012-09-19 15:15:01 +00:00
|
|
|
if( TYPE< tp >() == type ) \
|
|
|
|
|
{ \
|
|
|
|
|
tp val = getArgValue< tp >( defaultArgs, offset ); \
|
|
|
|
|
value = String::ToString( val ); \
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-21 07:08:26 +00:00
|
|
|
PRIMTYPE(bool);
|
|
|
|
|
PRIMTYPE(S8);
|
|
|
|
|
PRIMTYPE(U8);
|
|
|
|
|
PRIMTYPE(S32);
|
|
|
|
|
PRIMTYPE(U32);
|
|
|
|
|
PRIMTYPE(F32);
|
|
|
|
|
PRIMTYPE(F64);
|
2012-09-19 15:15:01 +00:00
|
|
|
|
2018-04-21 07:08:26 +00:00
|
|
|
//TODO: for now we store string literals in ASCII; needs to be sorted out
|
|
|
|
|
if (TYPE< const char* >() == type)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
const char* val = reinterpret_cast<const char*>(defaultArgs->getArgs() + offset);
|
|
|
|
|
value = val;
|
2012-09-19 15:15:01 +00:00
|
|
|
}
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
#undef PRIMTYPE
|
|
|
|
|
break;
|
2012-09-19 15:15:01 +00:00
|
|
|
}
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
value = table[i].getName();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case EngineTypeKindBitfield:
|
|
|
|
|
{
|
|
|
|
|
S32 val = getArgValue< S32 >(defaultArgs, offset);
|
|
|
|
|
AssertFatal(type->getEnumTable(), "engineXMLExport - Bitfield type without table!");
|
|
|
|
|
|
|
|
|
|
const EngineEnumTable& table = *(type->getEnumTable());
|
|
|
|
|
const U32 numValues = table.getNumValues();
|
|
|
|
|
|
|
|
|
|
bool isFirst = true;
|
|
|
|
|
for (U32 i = 0; i < numValues; ++i)
|
|
|
|
|
if (table[i].getInt() & val)
|
|
|
|
|
{
|
|
|
|
|
if (!isFirst)
|
|
|
|
|
value += '|';
|
|
|
|
|
|
|
|
|
|
value = table[i].getName();
|
|
|
|
|
isFirst = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2018-04-21 07:08:26 +00:00
|
|
|
static void exportFunction(const EngineFunctionInfo* function, SimXMLDocument* xml)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
if (isExportFiltered(function))
|
2012-09-19 15:15:01 +00:00
|
|
|
return;
|
|
|
|
|
|
2018-04-21 07:08:26 +00:00
|
|
|
xml->pushNewElement("EngineFunction");
|
|
|
|
|
|
|
|
|
|
xml->setAttribute("name", function->getExportName());
|
|
|
|
|
xml->setAttribute("returnType", getTypeName(function->getReturnType()));
|
|
|
|
|
xml->setAttribute("symbol", function->getBindingName());
|
|
|
|
|
xml->setAttribute("isCallback", function->isCallout() ? "1" : "0");
|
|
|
|
|
xml->setAttribute("isVariadic", function->getFunctionType()->isVariadic() ? "1" : "0");
|
|
|
|
|
xml->setAttribute("docs", getDocString(function));
|
|
|
|
|
|
|
|
|
|
xml->pushNewElement("arguments");
|
|
|
|
|
|
|
|
|
|
const U32 numArguments = function->getNumArguments();
|
|
|
|
|
const U32 numDefaultArguments = (function->getDefaultArguments() ? function->getDefaultArguments()->mNumDefaultArgs : 0);
|
|
|
|
|
const U32 firstDefaultArg = numArguments - numDefaultArguments;
|
|
|
|
|
|
|
|
|
|
Vector< String > argumentNames = parseFunctionArgumentNames(function);
|
|
|
|
|
const U32 numArgumentNames = argumentNames.size();
|
|
|
|
|
|
|
|
|
|
// Accumulated offset in function argument frame vector.
|
|
|
|
|
U32 argFrameOffset = 0;
|
|
|
|
|
|
|
|
|
|
for (U32 i = 0; i < numArguments; ++i)
|
|
|
|
|
{
|
|
|
|
|
xml->pushNewElement("EngineFunctionArgument");
|
|
|
|
|
const EngineTypeInfo* type = function->getArgumentType(i);
|
|
|
|
|
AssertFatal(type != NULL, "exportFunction - Argument cannot have type void!");
|
|
|
|
|
|
|
|
|
|
String argName;
|
|
|
|
|
if (i < numArgumentNames)
|
|
|
|
|
argName = argumentNames[i];
|
|
|
|
|
|
|
|
|
|
xml->setAttribute("name", argName);
|
|
|
|
|
xml->setAttribute("type", getTypeName(type));
|
|
|
|
|
|
|
|
|
|
if (i >= firstDefaultArg)
|
|
|
|
|
{
|
|
|
|
|
String defaultValue = getDefaultArgumentValue(function, type, argFrameOffset);
|
|
|
|
|
xml->setAttribute("defaultValue", defaultValue);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
xml->popElement();
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
xml->popElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Types.
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// MARK: ---- Types ----
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2018-04-21 07:08:26 +00:00
|
|
|
static void exportType(const EngineTypeInfo* type, SimXMLDocument* xml)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
|
|
|
|
// Don't export anonymous types.
|
2018-04-21 07:08:26 +00:00
|
|
|
if (!type->getTypeName()[0])
|
2012-09-19 15:15:01 +00:00
|
|
|
return;
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
if (isExportFiltered(type))
|
2012-09-19 15:15:01 +00:00
|
|
|
return;
|
2018-04-21 07:08:26 +00:00
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
const char* nodeName = NULL;
|
2018-04-21 07:08:26 +00:00
|
|
|
switch (type->getTypeKind())
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
case EngineTypeKindPrimitive:
|
|
|
|
|
nodeName = "EnginePrimitiveType";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EngineTypeKindEnum:
|
|
|
|
|
nodeName = "EngineEnumType";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EngineTypeKindBitfield:
|
|
|
|
|
nodeName = "EngineBitfieldType";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EngineTypeKindStruct:
|
|
|
|
|
nodeName = "EngineStructType";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EngineTypeKindClass:
|
|
|
|
|
nodeName = "EngineClassType";
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return;
|
2012-09-19 15:15:01 +00:00
|
|
|
}
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
xml->pushNewElement(nodeName);
|
|
|
|
|
|
|
|
|
|
xml->setAttribute("name", type->getTypeName());
|
|
|
|
|
xml->setAttribute("size", String::ToString(type->getInstanceSize()));
|
|
|
|
|
xml->setAttribute("isAbstract", type->isAbstract() ? "1" : "0");
|
|
|
|
|
xml->setAttribute("isInstantiable", type->isInstantiable() ? "1" : "0");
|
|
|
|
|
xml->setAttribute("isDisposable", type->isDisposable() ? "1" : "0");
|
|
|
|
|
xml->setAttribute("isSingleton", type->isSingleton() ? "1" : "0");
|
|
|
|
|
xml->setAttribute("docs", getDocString(type));
|
|
|
|
|
|
|
|
|
|
if (type->getSuperType())
|
|
|
|
|
xml->setAttribute("superType", getTypeName(type->getSuperType()));
|
|
|
|
|
|
|
|
|
|
if (type->getEnumTable())
|
|
|
|
|
{
|
|
|
|
|
xml->pushNewElement("enums");
|
|
|
|
|
|
|
|
|
|
const EngineEnumTable& table = *(type->getEnumTable());
|
|
|
|
|
const U32 numValues = table.getNumValues();
|
|
|
|
|
|
|
|
|
|
for (U32 i = 0; i < numValues; ++i)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
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() : "");
|
|
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
xml->popElement();
|
|
|
|
|
}
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
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)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
const EngineFieldTable::Field& field = table[i];
|
|
|
|
|
|
|
|
|
|
xml->pushNewElement("EngineField");
|
|
|
|
|
|
|
|
|
|
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() : "");
|
|
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
xml->popElement();
|
|
|
|
|
}
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
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)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
const EnginePropertyTable::Property& property = table[i];
|
|
|
|
|
|
|
|
|
|
if (property.isGroupBegin())
|
|
|
|
|
{
|
|
|
|
|
groupNestingDepth++;
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
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)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
xml->setAttribute("type", "deprecated");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ConsoleBaseType *cbt = ConsoleBaseType::getType(property.getType());
|
|
|
|
|
if (cbt != NULL)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
xml->setAttribute("type", cbt->getTypeClassName());
|
2012-09-19 15:15:01 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
xml->setAttribute("type", "unknown");
|
2012-09-19 15:15:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
xml->popElement();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AssertFatal(!groupNestingDepth, "exportType - Property group nesting mismatch!");
|
|
|
|
|
xml->popElement();
|
|
|
|
|
}
|
|
|
|
|
exportScope(type, xml);
|
|
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
xml->popElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// Scopes.
|
|
|
|
|
//=============================================================================
|
|
|
|
|
// MARK: ---- Scopes ----
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2018-04-21 07:08:26 +00:00
|
|
|
static void exportScope(const EngineExportScope* scope, SimXMLDocument* xml, bool addNode)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
if (addNode)
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
if (isExportFiltered(scope))
|
2012-09-19 15:15:01 +00:00
|
|
|
return;
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
xml->pushNewElement("EngineExportScope");
|
|
|
|
|
|
|
|
|
|
xml->setAttribute("name", scope->getExportName());
|
|
|
|
|
xml->setAttribute("docs", getDocString(scope));
|
2012-09-19 15:15:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Dump all contained exports.
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
xml->pushNewElement("exports");
|
|
|
|
|
|
|
|
|
|
for (const EngineExport* exportInfo = scope->getExports(); exportInfo != NULL; exportInfo = exportInfo->getNextExport())
|
|
|
|
|
{
|
|
|
|
|
switch (exportInfo->getExportKind())
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
2018-04-21 07:08:26 +00:00
|
|
|
case EngineExportKindScope:
|
|
|
|
|
exportScope(static_cast< const EngineExportScope* >(exportInfo), xml, true);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EngineExportKindFunction:
|
|
|
|
|
exportFunction(static_cast< const EngineFunctionInfo* >(exportInfo), xml);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case EngineExportKindType:
|
|
|
|
|
exportType(static_cast< const EngineTypeInfo* >(exportInfo), xml);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2012-09-19 15:15:01 +00:00
|
|
|
}
|
2018-04-21 07:08:26 +00:00
|
|
|
}
|
|
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
xml->popElement();
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
if (addNode)
|
2012-09-19 15:15:01 +00:00
|
|
|
xml->popElement();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
2018-04-21 07:08:26 +00:00
|
|
|
DefineEngineFunction(exportEngineAPIToXML, SimXMLDocument*, (), ,
|
2012-09-19 15:15:01 +00:00
|
|
|
"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"
|
2018-04-21 07:08:26 +00:00
|
|
|
"@ingroup Console")
|
2012-09-19 15:15:01 +00:00
|
|
|
{
|
|
|
|
|
SimXMLDocument* xml = new SimXMLDocument;
|
|
|
|
|
xml->registerObject();
|
2018-04-21 07:08:26 +00:00
|
|
|
Sim::getRootGroup()->addObject(xml);
|
2012-09-19 15:15:01 +00:00
|
|
|
xml->addHeader();
|
2018-04-21 07:08:26 +00:00
|
|
|
|
|
|
|
|
exportScope(EngineExportScope::getGlobalScope(), xml, true);
|
|
|
|
|
|
2012-09-19 15:15:01 +00:00
|
|
|
return xml;
|
2018-04-21 07:08:26 +00:00
|
|
|
}
|