From 62fef214ed5fad571f05605a48d2cc0959db00f3 Mon Sep 17 00:00:00 2001 From: ZXShady <153229951+ZXShady@users.noreply.github.com> Date: Sat, 21 Mar 2026 00:44:48 +0200 Subject: [PATCH 1/2] Create .clang-format --- .clang-format | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..05ad7439 --- /dev/null +++ b/.clang-format @@ -0,0 +1,70 @@ +--- +Language: Cpp +Standard: c++03 +BasedOnStyle: LLVM +ReflowComments: false +SortIncludes: false + +IndentWidth: 4 +TabWidth: 4 +UseTab: ForIndentation + + +ColumnLimit: 0 # this when 0 prevents clangformat from fixing manual line breaks +MaxEmptyLinesToKeep: 50 + +BreakBeforeBraces: Custom +BraceWrapping: + AfterControlStatement: true + AfterFunction: true + AfterClass: true + AfterStruct: true + AfterUnion: true + AfterNamespace: false + BeforeElse: true + AfterExternBlock: false + AfterCaseLabel: true +SpacesInParentheses: false # for 'if( x )' +SpaceBeforeParens: Custom +SpaceBeforeParensOptions: + AfterControlStatements: false + AfterFunctionDefinitionName: false + AfterPlacementOperator: true + +SpacesInConditionalStatement: true +BreakTemplateDeclarations: No +AlignConsecutiveDeclarations: true +AlignConsecutiveAssignments: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: true + PadOperators: true + +PointerAlignment: Right # int *ptr +DerivePointerAlignment: false + +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceAroundPointerQualifiers: Both + +AllowShortBlocksOnASingleLine: Always +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: AllIfsAndElse + +IndentCaseLabels: true +IndentPPDirectives: BeforeHash +PPIndentWidth: 4 +NamespaceIndentation: None +IndentAccessModifiers: false +AccessModifierOffset: -4 +StatementMacros: + - BEGIN_AS_NAMESPACE + - END_AS_NAMESPACE + +WhitespaceSensitiveMacros: + - asASSERT + +QualifierAlignment: Custom +QualifierOrder: ['static', 'inline', 'constexpr', 'const', 'volatile', 'type'] From 87be760f0fdcad02fabc23650f2c79fe292903ac Mon Sep 17 00:00:00 2001 From: ZXShady <153229951+ZXShady@users.noreply.github.com> Date: Sat, 21 Mar 2026 00:55:00 +0200 Subject: [PATCH 2/2] Format codebase --- sdk/angelscript/source/as_array.h | 106 +- sdk/angelscript/source/as_atomic.cpp | 37 +- sdk/angelscript/source/as_atomic.h | 2 +- sdk/angelscript/source/as_builder.cpp | 1823 ++--- sdk/angelscript/source/as_builder.h | 135 +- sdk/angelscript/source/as_bytecode.cpp | 1611 ++--- sdk/angelscript/source/as_bytecode.h | 63 +- sdk/angelscript/source/as_callfunc.cpp | 414 +- sdk/angelscript/source/as_callfunc.h | 52 +- sdk/angelscript/source/as_callfunc_arm.cpp | 488 +- sdk/angelscript/source/as_callfunc_arm64.cpp | 209 +- sdk/angelscript/source/as_callfunc_e2k.cpp | 417 +- sdk/angelscript/source/as_callfunc_mips.cpp | 690 +- sdk/angelscript/source/as_callfunc_ppc.cpp | 716 +- sdk/angelscript/source/as_callfunc_ppc_64.cpp | 784 +-- .../source/as_callfunc_riscv64.cpp | 193 +- sdk/angelscript/source/as_callfunc_sh4.cpp | 342 +- .../source/as_callfunc_x64_gcc.cpp | 388 +- .../source/as_callfunc_x64_mingw.cpp | 315 +- .../source/as_callfunc_x64_msvc.cpp | 102 +- sdk/angelscript/source/as_callfunc_x86.cpp | 1672 +++-- sdk/angelscript/source/as_callfunc_xenon.cpp | 298 +- sdk/angelscript/source/as_compiler.cpp | 4107 +++++------ sdk/angelscript/source/as_compiler.h | 325 +- sdk/angelscript/source/as_config.h | 198 +- sdk/angelscript/source/as_configgroup.cpp | 40 +- sdk/angelscript/source/as_configgroup.h | 16 +- sdk/angelscript/source/as_context.cpp | 6104 ++++++++--------- sdk/angelscript/source/as_context.h | 52 +- sdk/angelscript/source/as_criticalsection.h | 84 +- sdk/angelscript/source/as_datatype.cpp | 231 +- sdk/angelscript/source/as_datatype.h | 144 +- sdk/angelscript/source/as_debug.h | 62 +- sdk/angelscript/source/as_gc.cpp | 839 ++- sdk/angelscript/source/as_gc.h | 73 +- sdk/angelscript/source/as_generic.cpp | 212 +- sdk/angelscript/source/as_generic.h | 70 +- sdk/angelscript/source/as_globalproperty.cpp | 44 +- sdk/angelscript/source/as_map.h | 256 +- sdk/angelscript/source/as_memory.cpp | 48 +- sdk/angelscript/source/as_memory.h | 56 +- sdk/angelscript/source/as_module.cpp | 324 +- sdk/angelscript/source/as_module.h | 68 +- sdk/angelscript/source/as_namespace.h | 9 +- sdk/angelscript/source/as_objecttype.cpp | 93 +- sdk/angelscript/source/as_objecttype.h | 52 +- sdk/angelscript/source/as_outputbuffer.cpp | 17 +- sdk/angelscript/source/as_outputbuffer.h | 29 +- sdk/angelscript/source/as_parser.cpp | 737 +- sdk/angelscript/source/as_parser.h | 20 +- sdk/angelscript/source/as_property.h | 39 +- sdk/angelscript/source/as_restore.cpp | 1937 +++--- sdk/angelscript/source/as_restore.h | 58 +- sdk/angelscript/source/as_scriptcode.cpp | 26 +- sdk/angelscript/source/as_scriptengine.cpp | 2317 +++---- sdk/angelscript/source/as_scriptengine.h | 236 +- sdk/angelscript/source/as_scriptfunction.cpp | 722 +- sdk/angelscript/source/as_scriptfunction.h | 324 +- sdk/angelscript/source/as_scriptnode.cpp | 33 +- sdk/angelscript/source/as_scriptnode.h | 19 +- sdk/angelscript/source/as_scriptobject.cpp | 361 +- sdk/angelscript/source/as_scriptobject.h | 42 +- sdk/angelscript/source/as_string.cpp | 104 +- sdk/angelscript/source/as_string.h | 54 +- sdk/angelscript/source/as_string_util.cpp | 130 +- sdk/angelscript/source/as_string_util.h | 8 +- sdk/angelscript/source/as_symboltable.h | 174 +- sdk/angelscript/source/as_texts.h | 683 +- sdk/angelscript/source/as_thread.cpp | 185 +- sdk/angelscript/source/as_thread.h | 10 +- sdk/angelscript/source/as_tokendef.h | 207 +- sdk/angelscript/source/as_tokenizer.cpp | 192 +- sdk/angelscript/source/as_tokenizer.h | 17 +- sdk/angelscript/source/as_typeinfo.cpp | 132 +- sdk/angelscript/source/as_typeinfo.h | 223 +- sdk/angelscript/source/as_variablescope.cpp | 12 +- sdk/angelscript/source/as_variablescope.h | 8 +- 77 files changed, 16968 insertions(+), 16452 deletions(-) diff --git a/sdk/angelscript/source/as_array.h b/sdk/angelscript/source/as_array.h index 0d28a7ba..6641bd9f 100644 --- a/sdk/angelscript/source/as_array.h +++ b/sdk/angelscript/source/as_array.h @@ -32,12 +32,12 @@ #define AS_ARRAY_H #if !defined(AS_NO_MEMORY_H) -#include + #include #endif #include // some compilers declare memcpy() here #ifdef _MSC_VER -#pragma warning(disable:4345) // warning about a change in how the code is handled in this version + #pragma warning(disable : 4345) // warning about a change in how the code is handled in this version #endif BEGIN_AS_NAMESPACE @@ -50,29 +50,29 @@ template class asCArray explicit asCArray(asUINT reserve); ~asCArray(); - void Allocate(asUINT numElements, bool keepData); - void AllocateNoConstruct(asUINT numElements, bool keepData); + void Allocate(asUINT numElements, bool keepData); + void AllocateNoConstruct(asUINT numElements, bool keepData); inline asUINT GetCapacity() const; - void PushLast(const T &element); - inline T PopLast(); + void PushLast(const T &element); + inline T PopLast(); - bool SetLength(asUINT numElements); - bool SetLengthNoConstruct(asUINT numElements); + bool SetLength(asUINT numElements); + bool SetLengthNoConstruct(asUINT numElements); inline void SetLengthNoAllocate(asUINT numElements); inline asUINT GetLength() const; - void Copy(const T*, asUINT count); - asCArray &operator =(const asCArray &); + void Copy(const T *, asUINT count); + asCArray &operator=(const asCArray &); void SwapWith(asCArray &other); - inline const T &operator [](asUINT index) const; - inline T &operator [](asUINT index); + inline const T &operator[](asUINT index) const; + inline T &operator[](asUINT index); inline T *AddressOf(); inline const T *AddressOf() const; bool Concatenate(const asCArray &); - void Concatenate(T*, unsigned int count); + void Concatenate(T *, unsigned int count); bool Exists(const T &element) const; int IndexOf(const T &element) const; @@ -84,14 +84,14 @@ template class asCArray bool operator!=(const asCArray &) const; public: - // These are public to allow external code (e.g. JIT compiler) to do asOFFSET to + // These are public to allow external code (e.g. JIT compiler) to do asOFFSET to // access the members directly without having to modify the code to add friend - T *array; - asUINT length; // 32bits is enough for all uses of this array - asUINT maxLength; + T *array; + asUINT length; // 32bits is enough for all uses of this array + asUINT maxLength; protected: - char buf[2*4*AS_PTR_SIZE]; // Avoid dynamically allocated memory for tiny arrays + char buf[2 * 4 * AS_PTR_SIZE]; // Avoid dynamically allocated memory for tiny arrays }; // Implementation @@ -140,7 +140,7 @@ template asCArray::~asCArray(void) { // Allocating a zero length array will free all memory - Allocate(0,0); + Allocate(0, 0); } template @@ -150,7 +150,7 @@ inline asUINT asCArray::GetLength() const } template -inline const T &asCArray::operator [](asUINT index) const +inline const T &asCArray::operator[](asUINT index) const { asASSERT(index < length); @@ -158,7 +158,7 @@ inline const T &asCArray::operator [](asUINT index) const } template -inline T &asCArray::operator [](asUINT index) +inline T &asCArray::operator[](asUINT index) { asASSERT(index < length); @@ -173,7 +173,7 @@ void asCArray::PushLast(const T &element) if( maxLength == 0 ) Allocate(1, false); else - Allocate(2*maxLength, true); + Allocate(2 * maxLength, true); if( length == maxLength ) { @@ -205,13 +205,13 @@ void asCArray::Allocate(asUINT numElements, bool keepData) T *tmp = 0; if( numElements ) { - if( sizeof(T)*numElements <= sizeof(buf) ) + if( sizeof(T) * numElements <= sizeof(buf) ) // Use the internal buffer - tmp = reinterpret_cast(buf); + tmp = reinterpret_cast(buf); else { // Allocate the array and construct each of the elements - tmp = asNEWARRAY(T,numElements); + tmp = asNEWARRAY(T, numElements); if( tmp == 0 ) { // Out of memory. Return without doing anything @@ -234,7 +234,7 @@ void asCArray::Allocate(asUINT numElements, bool keepData) } if( array ) - { + { asUINT oldLength = length; if( array == tmp ) @@ -268,12 +268,12 @@ void asCArray::Allocate(asUINT numElements, bool keepData) for( asUINT n = 0; n < oldLength; n++ ) array[n].~T(); - if( array != reinterpret_cast(buf) ) + if( array != reinterpret_cast(buf) ) asDELETEARRAY(array); } } - array = tmp; + array = tmp; maxLength = numElements; } @@ -290,13 +290,13 @@ void asCArray::AllocateNoConstruct(asUINT numElements, bool keepData) if( numElements ) { asASSERT(asQWORD(numElements) * sizeof(T) <= 2147483647); - if( sizeof(T)*numElements <= sizeof(buf) ) + if( sizeof(T) * numElements <= sizeof(buf) ) // Use the internal buffer - tmp = reinterpret_cast(buf); + tmp = reinterpret_cast(buf); else { // Allocate the array and construct each of the elements - tmp = asNEWARRAY(T,numElements); + tmp = asNEWARRAY(T, numElements); if( tmp == 0 ) { // Out of memory. Return without doing anything @@ -324,17 +324,17 @@ void asCArray::AllocateNoConstruct(asUINT numElements, bool keepData) if( length > numElements ) length = numElements; - memcpy(tmp, array, sizeof(T)*length); + memcpy(tmp, array, sizeof(T) * length); } else length = 0; - if( array != reinterpret_cast(buf) ) + if( array != reinterpret_cast(buf) ) asDELETEARRAY(array); } } - array = tmp; + array = tmp; maxLength = numElements; } @@ -405,7 +405,7 @@ void asCArray::Copy(const T *data, asUINT count) } template -asCArray &asCArray::operator =(const asCArray ©) +asCArray &asCArray::operator=(const asCArray ©) { Copy(copy.array, copy.length); @@ -415,31 +415,31 @@ asCArray &asCArray::operator =(const asCArray ©) template void asCArray::SwapWith(asCArray &other) { - T *tmpArray = array; - asUINT tmpLength = length; - asUINT tmpMaxLength = maxLength; - char tmpBuf[sizeof(buf)]; + T *tmpArray = array; + asUINT tmpLength = length; + asUINT tmpMaxLength = maxLength; + char tmpBuf[sizeof(buf)]; memcpy(tmpBuf, buf, sizeof(buf)); - array = other.array; - length = other.length; + array = other.array; + length = other.length; maxLength = other.maxLength; memcpy(buf, other.buf, sizeof(buf)); - other.array = tmpArray; - other.length = tmpLength; + other.array = tmpArray; + other.length = tmpLength; other.maxLength = tmpMaxLength; memcpy(other.buf, tmpBuf, sizeof(buf)); // If the data is in the internal buffer, then the array pointer must refer to it - if( array == reinterpret_cast(other.buf) ) - array = reinterpret_cast(buf); - if( other.array == reinterpret_cast(buf) ) - other.array = reinterpret_cast(other.buf); + if( array == reinterpret_cast(other.buf) ) + array = reinterpret_cast(buf); + if( other.array == reinterpret_cast(buf) ) + other.array = reinterpret_cast(other.buf); } template -bool asCArray::operator ==(const asCArray &other) const +bool asCArray::operator==(const asCArray &other) const { if( length != other.length ) return false; @@ -451,7 +451,7 @@ bool asCArray::operator ==(const asCArray &other) const } template -bool asCArray::operator !=(const asCArray &other) const +bool asCArray::operator!=(const asCArray &other) const { return !(*this == other); } @@ -472,7 +472,7 @@ bool asCArray::Concatenate(const asCArray &other) } for( asUINT n = 0; n < other.length; n++ ) - array[length+n] = other.array[n]; + array[length + n] = other.array[n]; length += other.length; @@ -481,7 +481,7 @@ bool asCArray::Concatenate(const asCArray &other) } template -void asCArray::Concatenate(T* other, unsigned int count) +void asCArray::Concatenate(T *other, unsigned int count) { for( unsigned int c = 0; c < count; c++ ) PushLast(other[c]); @@ -507,8 +507,8 @@ void asCArray::RemoveIndex(asUINT index) { if( index < length ) { - for( asUINT n = index; n < length-1; n++ ) - array[n] = array[n+1]; + for( asUINT n = index; n < length - 1; n++ ) + array[n] = array[n + 1]; PopLast(); } diff --git a/sdk/angelscript/source/as_atomic.cpp b/sdk/angelscript/source/as_atomic.cpp index 73aa4a2a..d192f321 100644 --- a/sdk/angelscript/source/as_atomic.cpp +++ b/sdk/angelscript/source/as_atomic.cpp @@ -27,7 +27,7 @@ Andreas Jonsson andreas@angelcode.com */ - + // // as_atomic.cpp // @@ -67,7 +67,7 @@ asDWORD asCAtomic::atomicInc() // memory that has been overwritten or is being accessed after it was deleted. asASSERT(value < 1000000); - return asAtomicInc((int&)value); + return asAtomicInc((int &)value); } asDWORD asCAtomic::atomicDec() @@ -76,7 +76,7 @@ asDWORD asCAtomic::atomicDec() // memory that has been overwritten or is being accessed after it was deleted. asASSERT(value < 1000000); - return asAtomicDec((int&)value); + return asAtomicDec((int &)value); } // @@ -97,49 +97,49 @@ int asAtomicDec(int &value) #elif defined(AS_XENON) /// XBox360 END_AS_NAMESPACE -#include + #include BEGIN_AS_NAMESPACE int asAtomicInc(int &value) { - return InterlockedIncrement((LONG*)&value); + return InterlockedIncrement((LONG *)&value); } int asAtomicDec(int &value) { - return InterlockedDecrement((LONG*)&value); + return InterlockedDecrement((LONG *)&value); } #elif defined(AS_WIN) END_AS_NAMESPACE -#define WIN32_MEAN_AND_LEAN -#include + #define WIN32_MEAN_AND_LEAN + #include BEGIN_AS_NAMESPACE int asAtomicInc(int &value) { - return InterlockedIncrement((LONG*)&value); + return InterlockedIncrement((LONG *)&value); } int asAtomicDec(int &value) { asASSERT(value > 0); - return InterlockedDecrement((LONG*)&value); + return InterlockedDecrement((LONG *)&value); } #elif defined(AS_LINUX) || defined(AS_BSD) || defined(AS_ILLUMOS) || defined(AS_ANDROID) // -// atomic_inc_and_test() and atomic_dec_and_test() from asm/atomic.h is not meant -// to be used outside the Linux kernel. Instead we should use the GNUC provided +// atomic_inc_and_test() and atomic_dec_and_test() from asm/atomic.h is not meant +// to be used outside the Linux kernel. Instead we should use the GNUC provided // __sync_add_and_fetch() and __sync_sub_and_fetch() functions. // // Reference: http://golubenco.org/blog/atomic-operations/ // -// These are only available in GCC 4.1 and above, so for older versions we +// These are only available in GCC 4.1 and above, so for older versions we // use the critical sections, though it is a lot slower. -// +// int asAtomicInc(int &value) { @@ -170,25 +170,24 @@ int asAtomicDec(int &value) */ END_AS_NAMESPACE -#include + #include BEGIN_AS_NAMESPACE int asAtomicInc(int &value) { - return std::atomic_fetch_add((std::atomic*)&value, 1) + 1; + return std::atomic_fetch_add((std::atomic *)&value, 1) + 1; } int asAtomicDec(int &value) { - return std::atomic_fetch_sub((std::atomic*)&value, 1) - 1; + return std::atomic_fetch_sub((std::atomic *)&value, 1) - 1; } #else // If we get here, then the configuration in as_config.h -// is wrong for the compiler/platform combination. +// is wrong for the compiler/platform combination. int ERROR_PleaseFixTheConfig[-1]; #endif END_AS_NAMESPACE - diff --git a/sdk/angelscript/source/as_atomic.h b/sdk/angelscript/source/as_atomic.h index c6fea885..c3bd8acf 100644 --- a/sdk/angelscript/source/as_atomic.h +++ b/sdk/angelscript/source/as_atomic.h @@ -33,7 +33,7 @@ // as_atomic.h // // The asCAtomic class provides methods for performing threadsafe -// operations on a single dword, e.g. reference counting and +// operations on a single dword, e.g. reference counting and // bitfields. // diff --git a/sdk/angelscript/source/as_builder.cpp b/sdk/angelscript/source/as_builder.cpp index b9a43030..b17a229e 100644 --- a/sdk/angelscript/source/as_builder.cpp +++ b/sdk/angelscript/source/as_builder.cpp @@ -52,12 +52,12 @@ BEGIN_AS_NAMESPACE #ifndef AS_NO_COMPILER // asCSymbolTable template specializations for sGlobalVariableDescription entries -template<> +template <> void asCSymbolTable::GetKey(const sGlobalVariableDescription *entry, asSNameSpaceNamePair &key) const { - asSNameSpace *ns = entry->ns; - asCString name = entry->name; - key = asSNameSpaceNamePair(ns, name); + asSNameSpace *ns = entry->ns; + asCString name = entry->name; + key = asSNameSpaceNamePair(ns, name); } // Comparator for exact variable search @@ -65,17 +65,22 @@ class asCCompGlobVarType : public asIFilter { public: const asCDataType &m_type; - asCCompGlobVarType(const asCDataType &type) : m_type(type) {} + asCCompGlobVarType(const asCDataType &type) : m_type(type) + { + } bool operator()(const void *p) const { - const sGlobalVariableDescription* desc = reinterpret_cast(p); + const sGlobalVariableDescription *desc = reinterpret_cast(p); return desc->datatype == m_type; } private: // The assignment operator is required for MSVC9, otherwise it will complain that it is not possible to auto generate the operator - asCCompGlobVarType &operator=(const asCCompGlobVarType &) {return *this;} + asCCompGlobVarType &operator=(const asCCompGlobVarType &) + { + return *this; + } }; #endif @@ -84,7 +89,7 @@ asCBuilder::asCBuilder(asCScriptEngine *_engine, asCModule *_module) { this->engine = _engine; this->module = _module; - silent = false; + silent = false; } asCBuilder::~asCBuilder() @@ -100,7 +105,7 @@ asCBuilder::~asCBuilder() if( functions[n]->node ) functions[n]->node->Destroy(engine); - asDELETE(functions[n],sFunctionDescription); + asDELETE(functions[n], sFunctionDescription); } functions[n] = 0; @@ -115,7 +120,7 @@ asCBuilder::~asCBuilder() (*it)->declaredAtNode->Destroy(engine); if( (*it)->initializationNode ) (*it)->initializationNode->Destroy(engine); - asDELETE((*it),sGlobalVariableDescription); + asDELETE((*it), sGlobalVariableDescription); it++; } globVariables.Clear(); @@ -124,7 +129,7 @@ asCBuilder::~asCBuilder() for( n = 0; n < scripts.GetLength(); n++ ) { if( scripts[n] ) - asDELETE(scripts[n],asCScriptCode); + asDELETE(scripts[n], asCScriptCode); scripts[n] = 0; } @@ -137,7 +142,7 @@ asCBuilder::~asCBuilder() if( classDeclarations[n]->node ) classDeclarations[n]->node->Destroy(engine); - asDELETE(classDeclarations[n],sClassDeclaration); + asDELETE(classDeclarations[n], sClassDeclaration); classDeclarations[n] = 0; } } @@ -149,7 +154,7 @@ asCBuilder::~asCBuilder() if( interfaceDeclarations[n]->node ) interfaceDeclarations[n]->node->Destroy(engine); - asDELETE(interfaceDeclarations[n],sClassDeclaration); + asDELETE(interfaceDeclarations[n], sClassDeclaration); interfaceDeclarations[n] = 0; } } @@ -161,7 +166,7 @@ asCBuilder::~asCBuilder() if( namedTypeDeclarations[n]->node ) namedTypeDeclarations[n]->node->Destroy(engine); - asDELETE(namedTypeDeclarations[n],sClassDeclaration); + asDELETE(namedTypeDeclarations[n], sClassDeclaration); namedTypeDeclarations[n] = 0; } } @@ -173,7 +178,7 @@ asCBuilder::~asCBuilder() if( funcDefs[n]->node ) funcDefs[n]->node->Destroy(engine); - asDELETE(funcDefs[n],sFuncDef); + asDELETE(funcDefs[n], sFuncDef); funcDefs[n] = 0; } } @@ -185,7 +190,7 @@ asCBuilder::~asCBuilder() if( mixinClasses[n]->node ) mixinClasses[n]->node->Destroy(engine); - asDELETE(mixinClasses[n],sMixinClass); + asDELETE(mixinClasses[n], sMixinClass); mixinClasses[n] = 0; } } @@ -195,8 +200,8 @@ asCBuilder::~asCBuilder() void asCBuilder::Reset() { - numErrors = 0; - numWarnings = 0; + numErrors = 0; + numWarnings = 0; engine->preMessage.isSet = false; #ifndef AS_NO_COMPILER @@ -221,7 +226,7 @@ int asCBuilder::AddCode(const char *name, const char *code, int codeLength, int } script->lineOffset = lineOffset; - script->idx = sectionIdx; + script->idx = sectionIdx; scripts.PushLast(script); return 0; @@ -229,16 +234,16 @@ int asCBuilder::AddCode(const char *name, const char *code, int codeLength, int asCScriptCode *asCBuilder::FindOrAddCode(const char *name, const char *code, size_t length) { - for (asUINT n = 0; n < scripts.GetLength(); n++) + for( asUINT n = 0; n < scripts.GetLength(); n++ ) if( scripts[n]->name == name && scripts[n]->codeLength == length && memcmp(scripts[n]->code, code, length) == 0 ) return scripts[n]; asCScriptCode *script = asNEW(asCScriptCode); - if (script == 0) + if( script == 0 ) return 0; int r = script->SetCode(name, code, length, true); - if (r < 0) + if( r < 0 ) { asDELETE(script, asCScriptCode); return 0; @@ -265,9 +270,9 @@ void asCBuilder::EvaluateTemplateInstances(asUINT startIdx, bool keepSilent) // TODO: This is not exactly correct, since another thread may have created template instances in parallel for( asUINT n = startIdx; n < engine->templateInstanceTypes.GetLength(); n++ ) { - bool dontGarbageCollect = false; - asCObjectType *tmpl = engine->templateInstanceTypes[n]; - asCScriptFunction *callback = engine->scriptFunctions[tmpl->beh.templateCallback]; + bool dontGarbageCollect = false; + asCObjectType *tmpl = engine->templateInstanceTypes[n]; + asCScriptFunction *callback = engine->scriptFunctions[tmpl->beh.templateCallback]; if( callback && !engine->CallGlobalFunctionRetBool(tmpl, &dontGarbageCollect, callback->sysFuncIntf, callback) ) { asCString sub = tmpl->templateSubTypes[0].Format(engine->nameSpaces[0]); @@ -278,7 +283,7 @@ void asCBuilder::EvaluateTemplateInstances(asUINT startIdx, bool keepSilent) } asCString str; str.Format(TXT_INSTANCING_INVLD_TMPL_TYPE_s_s, tmpl->name.AddressOf(), sub.AddressOf()); - WriteError(tmpl->scriptSectionIdx >= 0 ? engine->scriptSectionNames[tmpl->scriptSectionIdx]->AddressOf() : "", str, tmpl->declaredAt&0xFFFFF, (tmpl->declaredAt>>20)&0xFFF); + WriteError(tmpl->scriptSectionIdx >= 0 ? engine->scriptSectionNames[tmpl->scriptSectionIdx]->AddressOf() : "", str, tmpl->declaredAt & 0xFFFFF, (tmpl->declaredAt >> 20) & 0xFFF); } else { @@ -308,10 +313,10 @@ int asCBuilder::Build() // thread requesting a template instance in parallel to the compilation wouldn't // evaluate the template instance. engine->deferValidationOfTemplateTypes = true; - asUINT numTempl = (asUINT)engine->templateInstanceTypes.GetLength(); + asUINT numTempl = (asUINT)engine->templateInstanceTypes.GetLength(); ParseScripts(); - if (numErrors > 0) + if( numErrors > 0 ) return asERROR; // Compile the types first @@ -322,7 +327,7 @@ int asCBuilder::Build() // all classes have been fully built and it is known which ones will need garbage collection. EvaluateTemplateInstances(numTempl, false); engine->deferValidationOfTemplateTypes = false; - if (numErrors > 0) + if( numErrors > 0 ) return asERROR; // Then the global variables. Here the variables declared with auto @@ -364,7 +369,7 @@ int asCBuilder::CompileGlobalVar(const char *sectionName, const char *code, int script->SetCode(sectionName, code, true); script->lineOffset = lineOffset; - script->idx = engine->GetScriptSectionNameIndex(sectionName ? sectionName : ""); + script->idx = engine->GetScriptSectionNameIndex(sectionName ? sectionName : ""); scripts.PushLast(script); // Parse the string @@ -376,9 +381,9 @@ int asCBuilder::CompileGlobalVar(const char *sectionName, const char *code, int // Make sure there is nothing else than the global variable in the script code if( node == 0 || - node->firstChild == 0 || - node->firstChild != node->lastChild || - node->firstChild->nodeType != snDeclaration ) + node->firstChild == 0 || + node->firstChild != node->lastChild || + node->firstChild->nodeType != snDeclaration ) { WriteError(TXT_ONLY_ONE_VARIABLE_ALLOWED, script, 0); return asERROR; @@ -393,9 +398,9 @@ int asCBuilder::CompileGlobalVar(const char *sectionName, const char *code, int // It is possible that the global variable initialization included anonymous functions that must be compiled too for( asUINT n = 0; n < functions.GetLength(); n++ ) { - asCCompiler compiler(engine); + asCCompiler compiler(engine); asCScriptFunction *func = engine->scriptFunctions[functions[n]->funcId]; - int r = compiler.CompileFunction(this, functions[n]->script, func->parameterNames, functions[n]->node, func, 0); + int r = compiler.CompileFunction(this, functions[n]->script, func->parameterNames, functions[n]->node, func, 0); if( r < 0 ) break; } @@ -423,7 +428,7 @@ int asCBuilder::CompileGlobalVar(const char *sectionName, const char *code, int { // Remove the variable from the module, if it was registered if( globVariables.GetSize() > 0 ) - module->RemoveGlobalVar(module->GetGlobalVarCount()-1); + module->RemoveGlobalVar(module->GetGlobalVarCount() - 1); return asERROR; } @@ -470,17 +475,17 @@ int asCBuilder::CheckForConflictsDueToDefaultArgs(asCScriptCode *script, asCScri if( func->IsReadOnly() != func2->IsReadOnly() ) continue; - bool match = true; - asUINT p = 0; + bool match = true; + asUINT p = 0; for( ; p < func->parameterTypes.GetLength() && p < func2->parameterTypes.GetLength(); p++ ) { // Only verify until the first argument with default args if( (func->defaultArgs.GetLength() > p && func->defaultArgs[p]) || - (func2->defaultArgs.GetLength() > p && func2->defaultArgs[p]) ) + (func2->defaultArgs.GetLength() > p && func2->defaultArgs[p]) ) break; if( func->parameterTypes[p] != func2->parameterTypes[p] || - func->inOutFlags[p] != func2->inOutFlags[p] ) + func->inOutFlags[p] != func2->inOutFlags[p] ) { match = false; break; @@ -490,7 +495,7 @@ int asCBuilder::CheckForConflictsDueToDefaultArgs(asCScriptCode *script, asCScri if( match ) { if( !((p >= func->parameterTypes.GetLength() && p < func2->defaultArgs.GetLength() && func2->defaultArgs[p]) || - (p >= func2->parameterTypes.GetLength() && p < func->defaultArgs.GetLength() && func->defaultArgs[p])) ) + (p >= func2->parameterTypes.GetLength() && p < func->defaultArgs.GetLength() && func->defaultArgs[p])) ) { // The argument lists match for the full length of the shorter, but the next // argument on the longer does not have a default arg so there is no conflict @@ -523,7 +528,7 @@ int asCBuilder::CompileFunction(const char *sectionName, const char *code, int l script->SetCode(sectionName, code, true); script->lineOffset = lineOffset; - script->idx = engine->GetScriptSectionNameIndex(sectionName ? sectionName : ""); + script->idx = engine->GetScriptSectionNameIndex(sectionName ? sectionName : ""); scripts.PushLast(script); // Parse the string @@ -535,9 +540,9 @@ int asCBuilder::CompileFunction(const char *sectionName, const char *code, int l // Make sure there is nothing else than the function in the script code if( node == 0 || - node->firstChild == 0 || - node->firstChild != node->lastChild || - node->firstChild->nodeType != snFunction ) + node->firstChild == 0 || + node->firstChild != node->lastChild || + node->firstChild->nodeType != snFunction ) { WriteError(TXT_ONLY_ONE_FUNCTION_ALLOWED, script, 0); return asERROR; @@ -547,7 +552,7 @@ int asCBuilder::CompileFunction(const char *sectionName, const char *code, int l node = node->firstChild; // Create the function - asSFunctionTraits funcTraits; + asSFunctionTraits funcTraits; asCScriptFunction *func = asNEW(asCScriptFunction)(engine, compileFlags & asCOMP_ADD_TO_MODULE ? module : 0, asFUNC_SCRIPT); if( func == 0 ) return asOUT_OF_MEMORY; @@ -557,8 +562,8 @@ int asCBuilder::CompileFunction(const char *sectionName, const char *code, int l func->scriptData->scriptSectionIdx = engine->GetScriptSectionNameIndex(sectionName ? sectionName : ""); int row, col; scripts[0]->ConvertPosToRowCol(node->tokenPos, &row, &col); - func->scriptData->declaredAt = (row & 0xFFFFF)|((col & 0xFFF)<<20); - func->nameSpace = module->m_defaultNamespace; + func->scriptData->declaredAt = (row & 0xFFFFF) | ((col & 0xFFF) << 20); + func->nameSpace = module->m_defaultNamespace; // Make sure the default args are declared correctly int r = ValidateDefaultArgs(script, node, func); @@ -595,19 +600,19 @@ int asCBuilder::CompileFunction(const char *sectionName, const char *code, int l } functions.PushLast(funcDesc); - funcDesc->script = scripts[0]; - funcDesc->node = node; - funcDesc->name = func->name; - funcDesc->funcId = func->id; - funcDesc->paramNames = func->parameterNames; - funcDesc->isExistingShared = false; + funcDesc->script = scripts[0]; + funcDesc->node = node; + funcDesc->name = func->name; + funcDesc->funcId = func->id; + funcDesc->paramNames = func->parameterNames; + funcDesc->isExistingShared = false; // This must be done in a loop, as it is possible that additional functions get declared as lambda's in the code for( asUINT n = 0; n < functions.GetLength(); n++ ) { - asCCompiler compiler(engine); + asCCompiler compiler(engine); asCScriptFunction *f = engine->scriptFunctions[functions[n]->funcId]; - r = compiler.CompileFunction(this, functions[n]->script, f->parameterNames, functions[n]->node, f, 0); + r = compiler.CompileFunction(this, functions[n]->script, f->parameterNames, functions[n]->node, f, 0); if( r < 0 ) break; } @@ -649,7 +654,7 @@ void asCBuilder::ParseScripts() { TimeIt("asCBuilder::ParseScripts"); - asCArray parsers((int)scripts.GetLength()); + asCArray parsers((int)scripts.GetLength()); // Parse all the files as if they were one asUINT n = 0; @@ -665,17 +670,17 @@ void asCBuilder::ParseScripts() } } - if (numErrors == 0) + if( numErrors == 0 ) { // Register namespace visibility - for (n = 0; n < scripts.GetLength(); n++) + for( n = 0; n < scripts.GetLength(); n++ ) { - asCScriptNode* node = parsers[n]->GetScriptNode(); + asCScriptNode *node = parsers[n]->GetScriptNode(); RegisterNamespaceVisibility(node, scripts[n], engine->nameSpaces[0]); } - + // Find all type declarations - for (n = 0; n < scripts.GetLength(); n++) + for( n = 0; n < scripts.GetLength(); n++ ) { asCScriptNode *node = parsers[n]->GetScriptNode(); RegisterTypesFromScript(node, scripts[n], engine->nameSpaces[0]); @@ -690,7 +695,7 @@ void asCBuilder::ParseScripts() CompleteFuncDef(funcDefs[n]); // Find other global nodes - for (n = 0; n < scripts.GetLength(); n++) + for( n = 0; n < scripts.GetLength(); n++ ) { // Find other global nodes asCScriptNode *node = parsers[n]->GetScriptNode(); @@ -701,7 +706,7 @@ void asCBuilder::ParseScripts() for( n = 0; n < interfaceDeclarations.GetLength(); n++ ) { sClassDeclaration *decl = interfaceDeclarations[n]; - asCScriptNode *node = decl->node->firstChild->next; + asCScriptNode *node = decl->node->firstChild->next; // Skip list of inherited interfaces while( node && node->nodeType == snIdentifier ) @@ -753,22 +758,22 @@ void asCBuilder::ParseScripts() node = next; } - if (!decl->isExistingShared) + if( !decl->isExistingShared ) { // Add the default copy operator if needed (only if no other opAssign with single parameter is defined) - bool copyOperatorExists = false; - asCObjectType* ot = CastToObjectType(decl->typeInfo); - for (asUINT i = 0; i < ot->methods.GetLength(); i++) + bool copyOperatorExists = false; + asCObjectType *ot = CastToObjectType(decl->typeInfo); + for( asUINT i = 0; i < ot->methods.GetLength(); i++ ) { - asCScriptFunction* f = engine->scriptFunctions[ot->methods[i]]; - if (f->name == "opAssign" && f->parameterTypes.GetLength() == 1) + asCScriptFunction *f = engine->scriptFunctions[ot->methods[i]]; + if( f->name == "opAssign" && f->parameterTypes.GetLength() == 1 ) { copyOperatorExists = true; break; } } - if (engine->ep.alwaysImplDefaultCopy == 2 || decl->isDefaultCopyDeleted || - (copyOperatorExists && ot->beh.copy == engine->scriptTypeBehaviours.beh.copy && engine->ep.alwaysImplDefaultCopy == 0)) + if( engine->ep.alwaysImplDefaultCopy == 2 || decl->isDefaultCopyDeleted || + (copyOperatorExists && ot->beh.copy == engine->scriptTypeBehaviours.beh.copy && engine->ep.alwaysImplDefaultCopy == 0) ) { // Script class has a declared constructor, so remove the default opAssign // unless the engine is configured to always provide a default opAssign @@ -777,35 +782,35 @@ void asCBuilder::ParseScripts() } // Add the default constructors if needed (only if no other constructor is explicitly defined) - if ( !decl->isDefaultConstructorDeleted && - ((engine->ep.alwaysImplDefaultConstruct == 0 && ot->beh.construct == engine->scriptTypeBehaviours.beh.construct && ot->beh.constructors.GetLength() == 1) || - engine->ep.alwaysImplDefaultConstruct == 1) ) + if( !decl->isDefaultConstructorDeleted && + ((engine->ep.alwaysImplDefaultConstruct == 0 && ot->beh.construct == engine->scriptTypeBehaviours.beh.construct && ot->beh.constructors.GetLength() == 1) || + engine->ep.alwaysImplDefaultConstruct == 1) ) { AddDefaultConstructor(ot, decl->script); } // Add the default copy constructor if needed (only if no other constructor with single parameter is explicitly defined) bool copyConstructExists = false; - for (asUINT i = 0; i < ot->beh.constructors.GetLength(); i++) + for( asUINT i = 0; i < ot->beh.constructors.GetLength(); i++ ) { - if (engine->scriptFunctions[ot->beh.constructors[i]]->parameterTypes.GetLength() == 1) + if( engine->scriptFunctions[ot->beh.constructors[i]]->parameterTypes.GetLength() == 1 ) { copyConstructExists = true; break; } } - if ( !decl->isDefaultCopyConstructorDeleted && - ((engine->ep.alwaysImplDefaultCopyConstruct == 0 && !copyConstructExists) || engine->ep.alwaysImplDefaultCopyConstruct == 1) ) + if( !decl->isDefaultCopyConstructorDeleted && + ((engine->ep.alwaysImplDefaultCopyConstruct == 0 && !copyConstructExists) || engine->ep.alwaysImplDefaultCopyConstruct == 1) ) AddDefaultCopyConstructor(ot, decl->script); - // If the default constructor has not been generated now, then release the dummy - if (ot->beh.construct == engine->scriptTypeBehaviours.beh.construct) + // If the default constructor has not been generated now, then release the dummy + if( ot->beh.construct == engine->scriptTypeBehaviours.beh.construct ) { engine->scriptFunctions[ot->beh.construct]->ReleaseInternal(); ot->beh.construct = 0; ot->beh.constructors.RemoveIndex(0); - if (ot->beh.factory) + if( ot->beh.factory ) { engine->scriptFunctions[ot->beh.factory]->ReleaseInternal(); ot->beh.factory = 0; @@ -818,7 +823,7 @@ void asCBuilder::ParseScripts() for( n = 0; n < parsers.GetLength(); n++ ) { - asDELETE(parsers[n],asCParser); + asDELETE(parsers[n], asCParser); } } @@ -880,26 +885,26 @@ void asCBuilder::RegisterTypesFromScript(asCScriptNode *node, asCScriptCode *scr } } -void asCBuilder::RegisterNamespaceVisibility(asCScriptNode* node, asCScriptCode* script, asSNameSpace* ns) +void asCBuilder::RegisterNamespaceVisibility(asCScriptNode *node, asCScriptCode *script, asSNameSpace *ns) { asASSERT(node->nodeType == snScript); node = node->firstChild; // First, register all namespaces - while ( node ) + while( node ) { - asCScriptNode* next = node->next; - if ( node->nodeType == snNamespace ) + asCScriptNode *next = node->next; + if( node->nodeType == snNamespace ) { asCString nsName; nsName.Assign(&script->code[node->firstChild->tokenPos], node->firstChild->tokenLength); - if ( ns->name != "" ) + if( ns->name != "" ) nsName = ns->name + "::" + nsName; - asSNameSpace* nsChild = engine->AddNameSpace(nsName.AddressOf()); + asSNameSpace *nsChild = engine->AddNameSpace(nsName.AddressOf()); RegisterNamespaceVisibility(node->lastChild, script, nsChild); } - else if ( node->nodeType == snUsing ) + else if( node->nodeType == snUsing ) { node->DisconnectParent(); RegisterUsingNamespace(node, script, ns); @@ -909,19 +914,19 @@ void asCBuilder::RegisterNamespaceVisibility(asCScriptNode* node, asCScriptCode* } #endif -void asCBuilder::AddVisibleNamespaces(asSNameSpace *ns, const asCArray& visited, asCArray& pending) +void asCBuilder::AddVisibleNamespaces(asSNameSpace *ns, const asCArray &visited, asCArray &pending) { - asSMapNode< asSNameSpace*, asCArray >* cursor = 0; + asSMapNode > *cursor = 0; - if (namespaceVisibility.MoveTo(&cursor, ns)) + if( namespaceVisibility.MoveTo(&cursor, ns) ) { - asCArray& visibilityBuffer = namespaceVisibility.GetValue(cursor); - asUINT count = visibilityBuffer.GetLength(); + asCArray &visibilityBuffer = namespaceVisibility.GetValue(cursor); + asUINT count = visibilityBuffer.GetLength(); - for (asUINT i = 0; i < count; ++i) + for( asUINT i = 0; i < count; ++i ) { - asSNameSpace* visibleNameSpace = visibilityBuffer[i]; - if (!visited.Exists(visibleNameSpace) && !pending.Exists(visibleNameSpace)) + asSNameSpace *visibleNameSpace = visibilityBuffer[i]; + if( !visited.Exists(visibleNameSpace) && !pending.Exists(visibleNameSpace) ) { pending.PushLast(visibleNameSpace); } @@ -929,14 +934,14 @@ void asCBuilder::AddVisibleNamespaces(asSNameSpace *ns, const asCArray& visited, asCArray& pending, asSNameSpace *parentNs, bool* checkAmbiguous) +asSNameSpace *asCBuilder::FindNextVisibleNamespace(const asCArray &visited, asCArray &pending, asSNameSpace *parentNs, bool *checkAmbiguous) { // First iterate through all pending namespaces that have been included with 'using namespace' - asSNameSpace* nextNs = 0; - while ( pending.GetLength() != 0 ) + asSNameSpace *nextNs = 0; + while( pending.GetLength() != 0 ) { asSNameSpace *candidate = pending.PopLast(); - if (!visited.Exists(candidate)) + if( !visited.Exists(candidate) ) { nextNs = candidate; break; @@ -944,10 +949,10 @@ asSNameSpace *asCBuilder::FindNextVisibleNamespace(const asCArray } // Even if the parent namespace has already been visited, it still needs to be traversed - if (nextNs == 0) + if( nextNs == 0 ) nextNs = parentNs; - if (checkAmbiguous && !(*checkAmbiguous)) + if( checkAmbiguous && !(*checkAmbiguous) ) *checkAmbiguous = nextNs == engine->nameSpaces[0]; return nextNs; @@ -1011,10 +1016,10 @@ void asCBuilder::CompileFunctions() if( current->isExistingShared ) continue; // Don't compile if there is no statement block - if (current->node && !(current->node->nodeType == snStatementBlock || current->node->lastChild->nodeType == snStatementBlock)) + if( current->node && !(current->node->nodeType == snStatementBlock || current->node->lastChild->nodeType == snStatementBlock) ) continue; - asCCompiler compiler(engine); + asCCompiler compiler(engine); asCScriptFunction *func = engine->scriptFunctions[current->funcId]; // Find the class declaration for constructors @@ -1051,10 +1056,10 @@ void asCBuilder::CompileFunctions() { asCScriptNode *node = classDecl ? classDecl->node : 0; - if (func->parameterTypes.GetLength() == 0) + if( func->parameterTypes.GetLength() == 0 ) { int r = 0, c = 0; - if (node) + if( node ) current->script->ConvertPosToRowCol(node->tokenPos, &r, &c); asCString str = func->GetDeclarationStr(); @@ -1070,7 +1075,7 @@ void asCBuilder::CompileFunctions() asASSERT(func->parameterTypes.GetLength() == 1 && func->parameterTypes[0].GetTypeInfo() == current->objType); int r = 0, c = 0; - if (node) + if( node ) current->script->ConvertPosToRowCol(node->tokenPos, &r, &c); asCString str = func->GetDeclarationStr(); @@ -1101,7 +1106,7 @@ int asCBuilder::ParseDataType(const char *datatype, asCDataType *result, asSName source.SetCode("", datatype, true); asCParser parser(this); - int r = parser.ParseDataType(&source, isReturnType); + int r = parser.ParseDataType(&source, isReturnType); if( r < 0 ) return asINVALID_TYPE; @@ -1126,7 +1131,7 @@ int asCBuilder::ParseTemplateDecl(const char *decl, asCString *name, asCArrayregisteredGlobalProps.GetFirst(ns, name); if( globProp ) { if( isAppProp ) *isAppProp = true; - if( outProp ) *outProp = globProp; + if( outProp ) *outProp = globProp; return true; } #ifndef AS_NO_COMPILER // Check properties being compiled now - sGlobalVariableDescription* desc = globVariables.GetFirst(ns, prop); + sGlobalVariableDescription *desc = globVariables.GetFirst(ns, prop); if( desc && !desc->isEnumValue ) { if( outProp ) *outProp = desc->property; @@ -1279,10 +1284,10 @@ bool asCBuilder::DoesGlobalPropertyExist(const char *prop, asSNameSpace *ns, asC asCGlobalProperty *asCBuilder::GetGlobalProperty(const char *prop, asSNameSpace *ns, bool *isCompiled, bool *isPureConstant, asQWORD *constantValue, bool *isAppProp) { - if( isCompiled ) *isCompiled = true; + if( isCompiled ) *isCompiled = true; if( isPureConstant ) *isPureConstant = false; - if( isAppProp ) *isAppProp = false; - if( constantValue ) *constantValue = 0; + if( isAppProp ) *isAppProp = false; + if( constantValue ) *constantValue = 0; asCGlobalProperty *globProp = 0; sGlobalVariableDescription *globDesc = 0; @@ -1292,13 +1297,13 @@ asCGlobalProperty *asCBuilder::GetGlobalProperty(const char *prop, asSNameSpace if( globDesc ) { // The property was declared in this build call, check if it has been compiled successfully already - if( isCompiled ) *isCompiled = globDesc->isCompiled; + if( isCompiled ) *isCompiled = globDesc->isCompiled; if( isPureConstant ) *isPureConstant = globDesc->isPureConstant; - if( constantValue ) *constantValue = globDesc->constantValue; + if( constantValue ) *constantValue = globDesc->constantValue; } else #endif - if( isAppProp ) + if( isAppProp ) { // Don't return the property if the module doesn't have access to it if( !(module->m_accessMask & globProp->accessMask) ) @@ -1314,9 +1319,9 @@ int asCBuilder::ParseFunctionDeclaration(asCObjectType *objType, const char *dec { asASSERT( objType || ns ); - if (listPattern) + if( listPattern ) *listPattern = 0; - if (outParentClass) + if( outParentClass ) *outParentClass = 0; // TODO: Can't we use GetParsedFunctionDetails to do most of what is done in this function? @@ -1327,43 +1332,43 @@ int asCBuilder::ParseFunctionDeclaration(asCObjectType *objType, const char *dec source.SetCode(TXT_SYSTEM_FUNCTION, decl, true); asCParser parser(this); - int r = parser.ParseFunctionDefinition(&source, listPattern != 0); + int r = parser.ParseFunctionDefinition(&source, listPattern != 0); if( r < 0 ) return asINVALID_DECLARATION; asCScriptNode *node = parser.GetScriptNode(); // Determine scope - asCScriptNode *n = node->firstChild->next->next; + asCScriptNode *n = node->firstChild->next->next; asCObjectType *parentClass = 0; - func->nameSpace = GetNameSpaceFromNode(n, &source, ns, &n, &parentClass); + func->nameSpace = GetNameSpaceFromNode(n, &source, ns, &n, &parentClass); if( func->nameSpace == 0 && parentClass == 0 ) return asINVALID_DECLARATION; - if (parentClass && func->funcType != asFUNC_FUNCDEF) + if( parentClass && func->funcType != asFUNC_FUNCDEF ) return asINVALID_DECLARATION; - if (outParentClass) + if( outParentClass ) *outParentClass = parentClass; // Find name func->name.Assign(&source.code[n->tokenPos], n->tokenLength); // Handle templates - asCScriptNode* tmp = n; - bool isTemplate = false; - while(tmp->next->nodeType != snParameterList) + asCScriptNode *tmp = n; + bool isTemplate = false; + while( tmp->next->nodeType != snParameterList ) { - asCString name(decl + tmp->next->tokenPos, tmp->next->tokenLength); - asCTypeInfo* templSubType = engine->GetTemplateSubTypeByName(name); - if (templSubType == 0) + asCString name(decl + tmp->next->tokenPos, tmp->next->tokenLength); + asCTypeInfo *templSubType = engine->GetTemplateSubTypeByName(name); + if( templSubType == 0 ) return asOUT_OF_MEMORY; - func->templateSubTypes.PushLast(asCDataType::CreateType(templSubType,false)); + func->templateSubTypes.PushLast(asCDataType::CreateType(templSubType, false)); templSubType->AddRefInternal(); isTemplate = true; - tmp = tmp->next; + tmp = tmp->next; } - + // Initialize a script function object for registration bool autoHandle; @@ -1372,28 +1377,28 @@ int asCBuilder::ParseFunctionDeclaration(asCObjectType *objType, const char *dec if( numErrors > 0 ) return asINVALID_DECLARATION; func->returnType = ModifyDataTypeFromNode(func->returnType, node->firstChild->next, &source, 0, &autoHandle); - + if( autoHandle && (!func->returnType.IsObjectHandle() || func->returnType.IsReference()) ) return asINVALID_DECLARATION; if( returnAutoHandle ) *returnAutoHandle = autoHandle; // Reference types cannot be returned by value from system functions if( isSystemFunction && - (func->returnType.GetTypeInfo() && - (func->returnType.GetTypeInfo()->flags & asOBJ_REF)) && - !(func->returnType.IsReference() || - func->returnType.IsObjectHandle()) ) + (func->returnType.GetTypeInfo() && + (func->returnType.GetTypeInfo()->flags & asOBJ_REF)) && + !(func->returnType.IsReference() || + func->returnType.IsObjectHandle()) ) return asINVALID_DECLARATION; // Count number of parameters - int paramCount = 0; - asCScriptNode *paramList = tmp->next; - n = paramList->firstChild; + int paramCount = 0; + asCScriptNode *paramList = tmp->next; + n = paramList->firstChild; while( n ) { - if (n && n->nodeType == snVariadic) + if( n && n->nodeType == snVariadic ) break; // Should be the last argument - + paramCount++; n = n->next->next; if( n && n->nodeType == snIdentifier ) @@ -1410,23 +1415,23 @@ int asCBuilder::ParseFunctionDeclaration(asCObjectType *objType, const char *dec func->defaultArgs.Allocate(paramCount, false); if( paramAutoHandles ) paramAutoHandles->Allocate(paramCount, false); - n = paramList->firstChild; + n = paramList->firstChild; asUINT index = 0; while( n ) { asETypeModifiers inOutFlags; - asCDataType type; + asCDataType type; type = CreateDataTypeFromNode(n, &source, objType ? objType->nameSpace : ns, false, parentClass ? parentClass : objType, true, 0, isTemplate ? &func->templateSubTypes : 0); - if (numErrors > 0) + if( numErrors > 0 ) return asINVALID_DECLARATION; type = ModifyDataTypeFromNode(type, n->next, &source, &inOutFlags, &autoHandle); // Reference types cannot be passed by value to system functions if( isSystemFunction && - (type.GetTypeInfo() && - (type.GetTypeInfo()->flags & asOBJ_REF)) && - !(type.IsReference() || - type.IsObjectHandle()) ) + (type.GetTypeInfo() && + (type.GetTypeInfo()->flags & asOBJ_REF)) && + !(type.IsReference() || + type.IsObjectHandle()) ) return asINVALID_DECLARATION; // Store the parameter type @@ -1444,12 +1449,12 @@ int asCBuilder::ParseFunctionDeclaration(asCObjectType *objType, const char *dec // Make sure that var type parameters are references if( type.GetTokenType() == ttQuestion && - !type.IsReference() ) + !type.IsReference() ) return asINVALID_DECLARATION; // Move to next parameter n = n->next->next; - if (n && n->nodeType == snVariadic) + if( n && n->nodeType == snVariadic ) { func->SetVariadic(true); break; @@ -1457,7 +1462,7 @@ int asCBuilder::ParseFunctionDeclaration(asCObjectType *objType, const char *dec if( n && n->nodeType == snIdentifier ) { func->parameterNames[index] = asCString(&source.code[n->tokenPos], n->tokenLength); - n = n->next; + n = n->next; } ++index; @@ -1491,11 +1496,11 @@ int asCBuilder::ParseFunctionDeclaration(asCObjectType *objType, const char *dec func->SetReadOnly(false); // Check for additional function traits - while (n && n->nodeType == snIdentifier) + while( n && n->nodeType == snIdentifier ) { - if (source.TokenEquals(n->tokenPos, n->tokenLength, EXPLICIT_TOKEN)) + if( source.TokenEquals(n->tokenPos, n->tokenLength, EXPLICIT_TOKEN) ) func->SetExplicit(true); - else if( source.TokenEquals(n->tokenPos, n->tokenLength, PROPERTY_TOKEN)) + else if( source.TokenEquals(n->tokenPos, n->tokenLength, PROPERTY_TOKEN) ) func->SetProperty(true); else return asINVALID_DECLARATION; @@ -1569,7 +1574,7 @@ int asCBuilder::CheckNameConflictMember(asCTypeInfo *t, const char *name, asCScr // It's not necessary to check against object types asCObjectType *ot = CastToObjectType(t); - if (!ot) + if( !ot ) return 0; // Check against properties @@ -1618,12 +1623,12 @@ int asCBuilder::CheckNameConflictMember(asCTypeInfo *t, const char *name, asCScr } // Check against child types - asCArray &funcdefs = ot->childFuncDefs; - for (asUINT n = 0; n < funcdefs.GetLength(); n++) + asCArray &funcdefs = ot->childFuncDefs; + for( asUINT n = 0; n < funcdefs.GetLength(); n++ ) { - if (funcdefs[n]->name == name) + if( funcdefs[n]->name == name ) { - if (code) + if( code ) { asCString str; str.Format(TXT_NAME_CONFLICT_s_IS_FUNCDEF, name); @@ -1657,17 +1662,17 @@ int asCBuilder::CheckNameConflictMember(asCTypeInfo *t, const char *name, asCScr // If there is a namespace at the same level with the same name as the class, then need to check for conflicts with symbols in that namespace too // TODO: When classes can have static members, the code should change so that class name cannot be the same as a namespace asCString scope; - if (ot->nameSpace->name != "") + if( ot->nameSpace->name != "" ) scope = ot->nameSpace->name + "::" + ot->name; else scope = ot->name; asSNameSpace *ns = engine->FindNameSpace(scope.AddressOf()); - if (ns) + if( ns ) { // Check as if not a function as it doesn't matter the function signature return CheckNameConflict(name, node, code, ns, true, isVirtualProperty, false); } - + return 0; } @@ -1680,7 +1685,7 @@ int asCBuilder::CheckNameConflict(const char *name, asCScriptNode *node, asCScri if( code ) { asCString str; - if (ns->name != "") + if( ns->name != "" ) str = ns->name + "::" + name; else str = name; @@ -1698,7 +1703,7 @@ int asCBuilder::CheckNameConflict(const char *name, asCScriptNode *node, asCScri if( code ) { asCString str; - if (ns->name != "") + if( ns->name != "" ) str = ns->name + "::" + name; else str = name; @@ -1708,22 +1713,22 @@ int asCBuilder::CheckNameConflict(const char *name, asCScriptNode *node, asCScri return -1; } - + // Check against registered global virtual properties // Don't do this when the check is for a virtual property, as it is allowed to have multiple overloads for virtual properties if( !isProperty || !isVirtualProperty ) { - for (asUINT n = 0; n < engine->registeredGlobalFuncs.GetSize(); n++) + for( asUINT n = 0; n < engine->registeredGlobalFuncs.GetSize(); n++ ) { asCScriptFunction *func = engine->registeredGlobalFuncs.Get(n); - if (func->IsProperty() && - func->nameSpace == ns && - func->name.SubString(4) == name) + if( func->IsProperty() && + func->nameSpace == ns && + func->name.SubString(4) == name ) { - if (code) + if( code ) { asCString str; - if (ns->name != "") + if( ns->name != "" ) str = ns->name + "::" + name; else str = name; @@ -1737,17 +1742,17 @@ int asCBuilder::CheckNameConflict(const char *name, asCScriptNode *node, asCScri } // Property names must be checked against function names - if (isProperty) + if( isProperty ) { - for (asUINT n = 0; n < engine->registeredGlobalFuncs.GetSize(); n++) + for( asUINT n = 0; n < engine->registeredGlobalFuncs.GetSize(); n++ ) { - if (engine->registeredGlobalFuncs.Get(n)->name == name && - engine->registeredGlobalFuncs.Get(n)->nameSpace == ns) + if( engine->registeredGlobalFuncs.Get(n)->name == name && + engine->registeredGlobalFuncs.Get(n)->nameSpace == ns ) { - if (code) + if( code ) { asCString str; - if (ns->name != "") + if( ns->name != "" ) str = ns->name + "::" + name; else str = name; @@ -1763,18 +1768,18 @@ int asCBuilder::CheckNameConflict(const char *name, asCScriptNode *node, asCScri #ifndef AS_NO_COMPILER // Check against interface types asUINT n; - for (n = 0; n < interfaceDeclarations.GetLength(); n++) + for( n = 0; n < interfaceDeclarations.GetLength(); n++ ) { - if (interfaceDeclarations[n]->name == name && - interfaceDeclarations[n]->typeInfo->nameSpace == ns) + if( interfaceDeclarations[n]->name == name && + interfaceDeclarations[n]->typeInfo->nameSpace == ns ) { // Don't report an error if the application wants to ignore duplicate declarations of shared interfaces - if (!(isSharedIntf && engine->ep.ignoreDuplicateSharedIntf)) + if( !(isSharedIntf && engine->ep.ignoreDuplicateSharedIntf) ) { - if (code) + if( code ) { asCString str; - if (ns->name != "") + if( ns->name != "" ) str = ns->name + "::" + name; else str = name; @@ -1791,12 +1796,12 @@ int asCBuilder::CheckNameConflict(const char *name, asCScriptNode *node, asCScri for( n = 0; n < classDeclarations.GetLength(); n++ ) { if( classDeclarations[n]->name == name && - classDeclarations[n]->typeInfo->nameSpace == ns ) + classDeclarations[n]->typeInfo->nameSpace == ns ) { if( code ) { asCString str; - if (ns->name != "") + if( ns->name != "" ) str = ns->name + "::" + name; else str = name; @@ -1812,12 +1817,12 @@ int asCBuilder::CheckNameConflict(const char *name, asCScriptNode *node, asCScri for( n = 0; n < namedTypeDeclarations.GetLength(); n++ ) { if( namedTypeDeclarations[n]->name == name && - namedTypeDeclarations[n]->typeInfo->nameSpace == ns ) + namedTypeDeclarations[n]->typeInfo->nameSpace == ns ) { if( code ) { asCString str; - if (ns->name != "") + if( ns->name != "" ) str = ns->name + "::" + name; else str = name; @@ -1833,12 +1838,12 @@ int asCBuilder::CheckNameConflict(const char *name, asCScriptNode *node, asCScri for( n = 0; n < funcDefs.GetLength(); n++ ) { if( funcDefs[n]->name == name && - module->m_funcDefs[funcDefs[n]->idx]->nameSpace == ns ) + module->m_funcDefs[funcDefs[n]->idx]->nameSpace == ns ) { if( code ) { asCString str; - if (ns->name != "") + if( ns->name != "" ) str = ns->name + "::" + name; else str = name; @@ -1856,7 +1861,7 @@ int asCBuilder::CheckNameConflict(const char *name, asCScriptNode *node, asCScri if( code ) { asCString str; - if (ns->name != "") + if( ns->name != "" ) str = ns->name + "::" + name; else str = name; @@ -1871,19 +1876,19 @@ int asCBuilder::CheckNameConflict(const char *name, asCScriptNode *node, asCScri // Don't do this when the check is for a virtual property, as it is allowed to have multiple overloads for virtual properties if( !isProperty && !isVirtualProperty ) { - for (n = 0; n < functions.GetLength(); n++) + for( n = 0; n < functions.GetLength(); n++ ) { asCScriptFunction *func = engine->scriptFunctions[functions[n] ? functions[n]->funcId : 0]; - if (func && - func->IsProperty() && - func->objectType == 0 && - func->nameSpace == ns && - func->name.SubString(4) == name) + if( func && + func->IsProperty() && + func->objectType == 0 && + func->nameSpace == ns && + func->name.SubString(4) == name ) { - if (code) + if( code ) { asCString str; - if (ns->name != "") + if( ns->name != "" ) str = ns->name + "::" + name; else str = name; @@ -1895,21 +1900,21 @@ int asCBuilder::CheckNameConflict(const char *name, asCScriptNode *node, asCScri } } } - + // Property names must be checked against function names - if (isProperty) + if( isProperty ) { - for (n = 0; n < functions.GetLength(); n++) + for( n = 0; n < functions.GetLength(); n++ ) { - if (functions[n] && - functions[n]->objType == 0 && - functions[n]->name == name && - engine->scriptFunctions[functions[n]->funcId]->nameSpace == ns ) + if( functions[n] && + functions[n]->objType == 0 && + functions[n]->name == name && + engine->scriptFunctions[functions[n]->funcId]->nameSpace == ns ) { - if (code) + if( code ) { asCString str; - if (ns->name != "") + if( ns->name != "" ) str = ns->name + "::" + name; else str = name; @@ -1936,27 +1941,27 @@ int asCBuilder::CheckNameConflict(const char *name, asCScriptNode *node, asCScri int asCBuilder::ValidateVirtualProperty(asCScriptFunction *func) { asASSERT( func->IsProperty() ); - + // A virtual property must have the prefix "get_" or "set_" asCString prefix = func->name.SubString(0, 4); if( prefix != "get_" && prefix != "set_" ) return -2; - + // A getter must return a non-void type and have at most 1 argument (indexed property) if( prefix == "get_" && (func->returnType == asCDataType::CreatePrimitive(ttVoid, false) || func->parameterTypes.GetLength() > 1) ) return -3; - + // A setter must return a void and have 1 or 2 arguments (indexed property) if( prefix == "set_" && (func->returnType != asCDataType::CreatePrimitive(ttVoid, false) || func->parameterTypes.GetLength() < 1 || func->parameterTypes.GetLength() > 2) ) return -3; - + // Check matching getter/setter asCDataType getType, setType; - bool found = false; + bool found = false; if( prefix == "get_" ) { getType = func->returnType; - + // Find if there is a set accessor in the same scope, and then validate the type of it // TODO: optimize search asCString setName = "set_" + func->name.SubString(4); @@ -1965,20 +1970,20 @@ int asCBuilder::ValidateVirtualProperty(asCScriptFunction *func) asCScriptFunction *setFunc = engine->scriptFunctions[n]; if( setFunc == 0 || setFunc->name != setName || !setFunc->IsProperty() ) continue; - + // Is it the same scope? if( func->module != setFunc->module || func->nameSpace != setFunc->nameSpace || func->objectType != setFunc->objectType ) continue; - + setType = setFunc->parameterTypes[setFunc->parameterTypes.GetLength() - 1]; - found = true; + found = true; break; } } else { setType = func->parameterTypes[func->parameterTypes.GetLength() - 1]; - + // Find if there is a get accessor in the same scope and then validate the type of it // TODO: optimize search asCString getName = "get_" + func->name.SubString(4); @@ -1987,29 +1992,29 @@ int asCBuilder::ValidateVirtualProperty(asCScriptFunction *func) asCScriptFunction *getFunc = engine->scriptFunctions[n]; if( getFunc == 0 || getFunc->name != getName || !getFunc->IsProperty() ) continue; - + // Is it the same scope? if( func->module != getFunc->module || func->nameSpace != getFunc->nameSpace || func->objectType != getFunc->objectType ) continue; - + getType = getFunc->returnType; - found = true; + found = true; break; } } - + if( found ) { // Check that the type matches // It is permitted for a getter to return a handle and the setter to take a reference if( !getType.IsEqualExceptRefAndConst(setType) && - !((getType.IsObjectHandle() && !setType.IsObjectHandle()) && - (getType.GetTypeInfo() == setType.GetTypeInfo())) ) + !((getType.IsObjectHandle() && !setType.IsObjectHandle()) && + (getType.GetTypeInfo() == setType.GetTypeInfo())) ) { return -4; } } - + // Check name conflict with other entities in the same scope // It is allowed to have a real property of the same name, in which case the virtual property hides the real one. int r; @@ -2019,7 +2024,7 @@ int asCBuilder::ValidateVirtualProperty(asCScriptFunction *func) r = CheckNameConflict(func->name.SubString(4).AddressOf(), 0, 0, func->nameSpace, true, true, false); if( r < 0 ) return -5; - + // Everything is OK return 0; } @@ -2029,7 +2034,7 @@ sMixinClass *asCBuilder::GetMixinClass(const char *name, asSNameSpace *ns) { for( asUINT n = 0; n < mixinClasses.GetLength(); n++ ) if( mixinClasses[n]->name == name && - mixinClasses[n]->ns == ns ) + mixinClasses[n]->ns == ns ) return mixinClasses[n]; return 0; @@ -2042,7 +2047,7 @@ int asCBuilder::RegisterFuncDef(asCScriptNode *node, asCScriptCode *file, asSNam // Skip leading 'shared' and 'external' keywords asCScriptNode *n = node->firstChild; - while (n->nodeType == snIdentifier) + while( n->nodeType == snIdentifier ) n = n->next; // Find the name @@ -2053,10 +2058,10 @@ int asCBuilder::RegisterFuncDef(asCScriptNode *node, asCScriptCode *file, asSNam name.Assign(&file->code[n->tokenPos], n->tokenLength); // Check for name conflict with other types - if (ns) + if( ns ) { int r = CheckNameConflict(name.AddressOf(), node, file, ns, true, false, false); - if (asSUCCESS != r) + if( asSUCCESS != r ) { node->Destroy(engine); return r; @@ -2065,7 +2070,7 @@ int asCBuilder::RegisterFuncDef(asCScriptNode *node, asCScriptCode *file, asSNam else { int r = CheckNameConflictMember(parent, name.AddressOf(), node, file, false, false); - if (asSUCCESS != r) + if( asSUCCESS != r ) { node->Destroy(engine); return r; @@ -2098,8 +2103,8 @@ int asCBuilder::RegisterFuncDef(asCScriptNode *node, asCScriptCode *file, asSNam void asCBuilder::CompleteFuncDef(sFuncDef *funcDef) { - asCArray defaultArgs; - asSFunctionTraits funcTraits; + asCArray defaultArgs; + asSFunctionTraits funcTraits; asCFuncdefType *fdt = module->m_funcDefs[funcDef->idx]; asASSERT( fdt ); @@ -2116,9 +2121,9 @@ void asCBuilder::CompleteFuncDef(sFuncDef *funcDef) // All funcdefs are shared, unless one of the parameter types or return type is not shared bool declaredShared = funcTraits.GetTrait(asTRAIT_SHARED); funcTraits.SetTrait(asTRAIT_SHARED, true); - if (func->returnType.GetTypeInfo() && !func->returnType.GetTypeInfo()->IsShared()) + if( func->returnType.GetTypeInfo() && !func->returnType.GetTypeInfo()->IsShared() ) { - if (declaredShared) + if( declaredShared ) { asCString s; s.Format(TXT_SHARED_CANNOT_USE_NON_SHARED_TYPE_s, func->returnType.GetTypeInfo()->name.AddressOf()); @@ -2127,9 +2132,9 @@ void asCBuilder::CompleteFuncDef(sFuncDef *funcDef) funcTraits.SetTrait(asTRAIT_SHARED, false); } for( asUINT n = 0; funcTraits.GetTrait(asTRAIT_SHARED) && n < func->parameterTypes.GetLength(); n++ ) - if (func->parameterTypes[n].GetTypeInfo() && !func->parameterTypes[n].GetTypeInfo()->IsShared()) + if( func->parameterTypes[n].GetTypeInfo() && !func->parameterTypes[n].GetTypeInfo()->IsShared() ) { - if (declaredShared) + if( declaredShared ) { asCString s; s.Format(TXT_SHARED_CANNOT_USE_NON_SHARED_TYPE_s, func->parameterTypes[n].GetTypeInfo()->name.AddressOf()); @@ -2153,9 +2158,9 @@ void asCBuilder::CompleteFuncDef(sFuncDef *funcDef) continue; if( fdt2->name == fdt->name && - fdt2->nameSpace == fdt->nameSpace && - fdt2->parentClass == fdt->parentClass && - fdt2->funcdef->IsSignatureExceptNameEqual(func) ) + fdt2->nameSpace == fdt->nameSpace && + fdt2->parentClass == fdt->parentClass && + fdt2->funcdef->IsSignatureExceptNameEqual(func) ) { // Replace our funcdef for the existing one module->ReplaceFuncDef(fdt, fdt2); @@ -2171,7 +2176,7 @@ void asCBuilder::CompleteFuncDef(sFuncDef *funcDef) } // If the funcdef was declared as external then the existing shared declaration must have been found - if (funcTraits.GetTrait(asTRAIT_EXTERNAL) && !found) + if( funcTraits.GetTrait(asTRAIT_EXTERNAL) && !found ) { asCString str; str.Format(TXT_EXTERNAL_SHARED_s_NOT_FOUND, funcDef->name.AddressOf()); @@ -2179,7 +2184,7 @@ void asCBuilder::CompleteFuncDef(sFuncDef *funcDef) } // Remember if the type was declared as external so the saved bytecode can be flagged accordingly - if (funcTraits.GetTrait(asTRAIT_EXTERNAL) && found) + if( funcTraits.GetTrait(asTRAIT_EXTERNAL) && found ) module->m_externalTypes.PushLast(engine->scriptFunctions[module->m_funcDefs[funcDef->idx]->GetFuncdefSignature()->GetId()]->funcdefType); } @@ -2240,16 +2245,16 @@ int asCBuilder::RegisterGlobalVar(asCScriptNode *node, asCScriptCode *file, asSN gvar->declaredAtNode = n; - n = n->next; + n = n->next; gvar->declaredAtNode->DisconnectParent(); gvar->initializationNode = 0; if( n && - ( n->nodeType == snAssignment || - n->nodeType == snArgList || - n->nodeType == snInitList ) ) + (n->nodeType == snAssignment || + n->nodeType == snArgList || + n->nodeType == snInitList) ) { gvar->initializationNode = n; - n = n->next; + n = n->next; gvar->initializationNode->DisconnectParent(); } } @@ -2261,27 +2266,27 @@ int asCBuilder::RegisterGlobalVar(asCScriptNode *node, asCScriptCode *file, asSN int asCBuilder::RegisterUsingNamespace(asCScriptNode *node, asCScriptCode *file, asSNameSpace *ns) { - asCScriptNode* n = node->firstChild; - asCString name(&file->code[n->tokenPos], n->tokenLength); + asCScriptNode *n = node->firstChild; + asCString name(&file->code[n->tokenPos], n->tokenLength); - while (n->next) + while( n->next ) { - n = n->next; + n = n->next; name += "::" + asCString(&file->code[n->tokenPos], n->tokenLength); } - asSNameSpace* visibleNamespace = engine->AddNameSpace(name.AddressOf()); - asSMapNode< asSNameSpace*, asCArray >* cursor = 0; + asSNameSpace *visibleNamespace = engine->AddNameSpace(name.AddressOf()); + asSMapNode > *cursor = 0; - if (namespaceVisibility.MoveTo(&cursor, ns)) + if( namespaceVisibility.MoveTo(&cursor, ns) ) { - asCArray& visibleNamespaces = namespaceVisibility.GetValue(cursor); - if (!visibleNamespaces.Exists(visibleNamespace)) + asCArray &visibleNamespaces = namespaceVisibility.GetValue(cursor); + if( !visibleNamespaces.Exists(visibleNamespace) ) namespaceVisibility.GetValue(cursor).PushLast(visibleNamespace); } else { - asCArray tmp; + asCArray tmp; tmp.PushLast(visibleNamespace); namespaceVisibility.Insert(ns, tmp); } @@ -2299,10 +2304,10 @@ int asCBuilder::RegisterMixinClass(asCScriptNode *node, asCScriptCode *file, asS // Skip potential decorator tokens while( n->tokenType == ttIdentifier && - (file->TokenEquals(n->tokenPos, n->tokenLength, FINAL_TOKEN) || - file->TokenEquals(n->tokenPos, n->tokenLength, SHARED_TOKEN) || - file->TokenEquals(n->tokenPos, n->tokenLength, ABSTRACT_TOKEN) || - file->TokenEquals(n->tokenPos, n->tokenLength, EXTERNAL_TOKEN)) ) + (file->TokenEquals(n->tokenPos, n->tokenLength, FINAL_TOKEN) || + file->TokenEquals(n->tokenPos, n->tokenLength, SHARED_TOKEN) || + file->TokenEquals(n->tokenPos, n->tokenLength, ABSTRACT_TOKEN) || + file->TokenEquals(n->tokenPos, n->tokenLength, EXTERNAL_TOKEN)) ) { // Report error, because mixin class cannot be final or shared asCString msg; @@ -2310,7 +2315,7 @@ int asCBuilder::RegisterMixinClass(asCScriptNode *node, asCScriptCode *file, asS WriteError(msg, file, n); asCScriptNode *tmp = n; - n = n->next; + n = n->next; // Remove the invalid node, so compilation can continue as if it wasn't there tmp->DisconnectParent(); @@ -2344,9 +2349,9 @@ int asCBuilder::RegisterMixinClass(asCScriptNode *node, asCScriptCode *file, asS // Check that the mixin class doesn't contain any child types // TODO: Add support for child types in mixin classes n = cl->firstChild; - while (n) + while( n ) { - if (n->nodeType == snFuncDef) + if( n->nodeType == snFuncDef ) { WriteError(TXT_MIXIN_CANNOT_HAVE_CHILD_TYPES, file, n); break; @@ -2359,11 +2364,11 @@ int asCBuilder::RegisterMixinClass(asCScriptNode *node, asCScriptCode *file, asS int asCBuilder::RegisterClass(asCScriptNode *node, asCScriptCode *file, asSNameSpace *ns) { - asCScriptNode *n = node->firstChild; - bool isFinal = false; - bool isShared = false; - bool isAbstract = false; - bool isExternal = false; + asCScriptNode *n = node->firstChild; + bool isFinal = false; + bool isShared = false; + bool isAbstract = false; + bool isExternal = false; // Check the class modifiers while( n->tokenType == ttIdentifier ) @@ -2393,9 +2398,9 @@ int asCBuilder::RegisterClass(asCScriptNode *node, asCScriptCode *file, asSNameS } isShared = true; } - else if (file->TokenEquals(n->tokenPos, n->tokenLength, EXTERNAL_TOKEN)) + else if( file->TokenEquals(n->tokenPos, n->tokenLength, EXTERNAL_TOKEN) ) { - if (isExternal) + if( isExternal ) { asCString msg; msg.Format(TXT_ATTR_s_INFORMED_MULTIPLE_TIMES, asCString(&file->code[n->tokenPos], n->tokenLength).AddressOf()); @@ -2442,18 +2447,18 @@ int asCBuilder::RegisterClass(asCScriptNode *node, asCScriptCode *file, asSNameS } classDeclarations.PushLast(decl); - decl->name = name; - decl->script = file; - decl->node = node; + decl->name = name; + decl->script = file; + decl->node = node; // External shared interfaces must not try to redefine the interface - if (isExternal && (n->next == 0 || n->next->tokenType != ttEndStatement)) + if( isExternal && (n->next == 0 || n->next->tokenType != ttEndStatement) ) { asCString str; str.Format(TXT_EXTERNAL_SHARED_s_CANNOT_REDEF, name.AddressOf()); WriteError(str, file, n); } - else if (!isExternal && n->next && n->next->tokenType == ttEndStatement) + else if( !isExternal && n->next && n->next->tokenType == ttEndStatement ) { asCString str; str.Format(TXT_MISSING_DEFINITION_OF_s, name.AddressOf()); @@ -2470,10 +2475,10 @@ int asCBuilder::RegisterClass(asCScriptNode *node, asCScriptCode *file, asSNameS { st = CastToObjectType(engine->sharedScriptTypes[i]); if( st && - st->IsShared() && - st->name == name && - st->nameSpace == ns && - !st->IsInterface() ) + st->IsShared() && + st->name == name && + st->nameSpace == ns && + !st->IsInterface() ) { // We'll use the existing type decl->isExistingShared = true; @@ -2486,7 +2491,7 @@ int asCBuilder::RegisterClass(asCScriptNode *node, asCScriptCode *file, asSNameS } // If the class was declared as external then it must have been compiled in a different module first - if (isExternal && decl->typeInfo == 0) + if( isExternal && decl->typeInfo == 0 ) { asCString str; str.Format(TXT_EXTERNAL_SHARED_s_NOT_FOUND, name.AddressOf()); @@ -2494,14 +2499,14 @@ int asCBuilder::RegisterClass(asCScriptNode *node, asCScriptCode *file, asSNameS } // Remember if the class was declared as external so the saved bytecode can be flagged accordingly - if (isExternal) + if( isExternal ) module->m_externalTypes.PushLast(st); - if (!decl->isExistingShared) + if( !decl->isExistingShared ) { // Create a new object type for this class st = asNEW(asCObjectType)(engine); - if (st == 0) + if( st == 0 ) return asOUT_OF_MEMORY; // By default all script classes are marked as garbage collected. @@ -2512,27 +2517,27 @@ int asCBuilder::RegisterClass(asCScriptNode *node, asCScriptCode *file, asSNameS // completes, and until it is known, the callback must assume the class // is garbage collected. st->flags = asOBJ_REF | asOBJ_SCRIPT_OBJECT | asOBJ_GC; - if (engine->ep.disableScriptClassGC) + if( engine->ep.disableScriptClassGC ) st->flags &= ~asOBJ_GC; - if (isShared) + if( isShared ) st->flags |= asOBJ_SHARED; - if (isFinal) + if( isFinal ) st->flags |= asOBJ_NOINHERIT; - if (isAbstract) + if( isAbstract ) st->flags |= asOBJ_ABSTRACT; - if (node->tokenType == ttHandle) + if( node->tokenType == ttHandle ) st->flags |= asOBJ_IMPLICIT_HANDLE; - st->size = sizeof(asCScriptObject); - st->name = name; + st->size = sizeof(asCScriptObject); + st->name = name; st->nameSpace = ns; - st->module = module; + st->module = module; module->AddClassType(st); - if (isShared) + if( isShared ) { engine->sharedScriptTypes.PushLast(st); st->AddRefInternal(); @@ -2557,18 +2562,18 @@ int asCBuilder::RegisterClass(asCScriptNode *node, asCScriptCode *file, asSNameS engine->scriptFunctions[st->beh.getWeakRefFlag]->AddRefInternal(); // Skip to the content of the class - while (n && n->nodeType == snIdentifier) + while( n && n->nodeType == snIdentifier ) n = n->next; } // Register possible child types - while (n) + while( n ) { node = n->next; - if (n->nodeType == snFuncDef) + if( n->nodeType == snFuncDef ) { n->DisconnectParent(); - if (!decl->isExistingShared) + if( !decl->isExistingShared ) RegisterFuncDef(n, file, 0, st); else { @@ -2587,13 +2592,13 @@ int asCBuilder::RegisterInterface(asCScriptNode *node, asCScriptCode *file, asSN { asCScriptNode *n = node->firstChild; - bool isShared = false; + bool isShared = false; bool isExternal = false; while( n->nodeType == snIdentifier ) { - if (file->TokenEquals(n->tokenPos, n->tokenLength, SHARED_TOKEN)) + if( file->TokenEquals(n->tokenPos, n->tokenLength, SHARED_TOKEN) ) isShared = true; - else if (file->TokenEquals(n->tokenPos, n->tokenLength, EXTERNAL_TOKEN)) + else if( file->TokenEquals(n->tokenPos, n->tokenLength, EXTERNAL_TOKEN) ) isExternal = true; else break; @@ -2615,18 +2620,18 @@ int asCBuilder::RegisterInterface(asCScriptNode *node, asCScriptCode *file, asSN } interfaceDeclarations.PushLast(decl); - decl->name = name; - decl->script = file; - decl->node = node; + decl->name = name; + decl->script = file; + decl->node = node; // External shared interfaces must not try to redefine the interface - if (isExternal && (n->next == 0 || n->next->tokenType != ttEndStatement) ) + if( isExternal && (n->next == 0 || n->next->tokenType != ttEndStatement) ) { asCString str; str.Format(TXT_EXTERNAL_SHARED_s_CANNOT_REDEF, name.AddressOf()); WriteError(str, file, n); } - else if (!isExternal && n->next && n->next->tokenType == ttEndStatement) + else if( !isExternal && n->next && n->next->tokenType == ttEndStatement ) { asCString str; str.Format(TXT_MISSING_DEFINITION_OF_s, name.AddressOf()); @@ -2642,19 +2647,19 @@ int asCBuilder::RegisterInterface(asCScriptNode *node, asCScriptCode *file, asSN { asCObjectType *st = CastToObjectType(engine->sharedScriptTypes[i]); if( st && - st->IsShared() && - st->name == name && - st->nameSpace == ns && - st->IsInterface() ) + st->IsShared() && + st->name == name && + st->nameSpace == ns && + st->IsInterface() ) { // We'll use the existing type decl->isExistingShared = true; - decl->typeInfo = st; + decl->typeInfo = st; module->AddClassType(st); st->AddRefInternal(); // Remember if the interface was declared as external so the saved bytecode can be flagged accordingly - if (isExternal) + if( isExternal ) module->m_externalTypes.PushLast(st); return 0; @@ -2663,7 +2668,7 @@ int asCBuilder::RegisterInterface(asCScriptNode *node, asCScriptCode *file, asSN } // If the interface was declared as external then it must have been compiled in a different module first - if (isExternal) + if( isExternal ) { asCString str; str.Format(TXT_EXTERNAL_SHARED_s_NOT_FOUND, name.AddressOf()); @@ -2680,10 +2685,10 @@ int asCBuilder::RegisterInterface(asCScriptNode *node, asCScriptCode *file, asSN if( isShared ) st->flags |= asOBJ_SHARED; - st->size = 0; // Cannot be instantiated - st->name = name; + st->size = 0; // Cannot be instantiated + st->name = name; st->nameSpace = ns; - st->module = module; + st->module = module; module->AddClassType(st); if( isShared ) { @@ -2694,7 +2699,7 @@ int asCBuilder::RegisterInterface(asCScriptNode *node, asCScriptCode *file, asSN // Use the default script class behaviours st->beh.construct = 0; - st->beh.addref = engine->scriptTypeBehaviours.beh.addref; + st->beh.addref = engine->scriptTypeBehaviours.beh.addref; engine->scriptFunctions[st->beh.addref]->AddRefInternal(); st->beh.release = engine->scriptTypeBehaviours.beh.release; engine->scriptFunctions[st->beh.release]->AddRefInternal(); @@ -2720,7 +2725,7 @@ void asCBuilder::CompileGlobalVariables() asCOutputBuffer outBuffer; engine->SetMessageCallback(asFUNCTION(asCOutputBuffer::CDeclCallback), &outBuffer, asCALL_CDECL_OBJLAST); - asCOutputBuffer finalOutput; + asCOutputBuffer finalOutput; asCScriptFunction *initFunc = 0; asCSymbolTable initOrder; @@ -2738,7 +2743,7 @@ void asCBuilder::CompileGlobalVariables() { compileSucceeded = false; - int accumErrors = 0; + int accumErrors = 0; int accumWarnings = 0; // Restore state of compilation @@ -2752,7 +2757,7 @@ void asCBuilder::CompileGlobalVariables() asCByteCode init(engine); numWarnings = 0; - numErrors = 0; + numErrors = 0; outBuffer.Clear(); // Skip this for now if we're not compiling complex types yet @@ -2763,8 +2768,8 @@ void asCBuilder::CompileGlobalVariables() { int r, c; gvar->script->ConvertPosToRowCol(gvar->declaredAtNode->tokenPos, &r, &c); - asCString str = gvar->datatype.Format(gvar->ns); - str += " " + gvar->name; + asCString str = gvar->datatype.Format(gvar->ns); + str += " " + gvar->name; str.Format(TXT_COMPILING_s, str.AddressOf()); WriteInfo(gvar->script->name, str, r, c, true); } @@ -2774,7 +2779,7 @@ void asCBuilder::CompileGlobalVariables() int r; if( gvar->initializationNode ) { - asCCompiler comp(engine); + asCCompiler comp(engine); asCScriptFunction func(engine, module, asFUNC_SCRIPT); // Set the namespace that should be used during the compilation @@ -2782,10 +2787,10 @@ void asCBuilder::CompileGlobalVariables() // Temporarily switch the type of the variable to the enums' underlying type so it can be compiled properly asCEnumType *enumType = CastToEnumType(gvar->datatype.GetTypeInfo()); - asCDataType saveType; - saveType = gvar->datatype; + asCDataType saveType; + saveType = gvar->datatype; gvar->datatype = enumType->enumType; - r = comp.CompileGlobalVariable(this, gvar->script, gvar->initializationNode, gvar, &func); + r = comp.CompileGlobalVariable(this, gvar->script, gvar->initializationNode, gvar, &func); gvar->datatype = saveType; // Make the function a dummy so it doesn't try to release objects while destroying the function @@ -2796,13 +2801,13 @@ void asCBuilder::CompileGlobalVariables() r = 0; // When there is no assignment the value is the last + 1 - asINT64 enumVal = 0; + asINT64 enumVal = 0; asCSymbolTable::iterator prev_it = it; prev_it--; if( prev_it ) { sGlobalVariableDescription *gvar2 = *prev_it; - if(gvar2->datatype == gvar->datatype ) + if( gvar2->datatype == gvar->datatype ) { enumVal = asINT64(gvar2->constantValue) + 1; @@ -2811,8 +2816,8 @@ void asCBuilder::CompileGlobalVariables() int row, col; gvar->script->ConvertPosToRowCol(gvar->declaredAtNode->tokenPos, &row, &col); - asCString str = gvar->datatype.Format(gvar->ns); - str += " " + gvar->name; + asCString str = gvar->datatype.Format(gvar->ns); + str += " " + gvar->name; str.Format(TXT_COMPILING_s, str.AddressOf()); WriteInfo(gvar->script->name, str, row, col, true); @@ -2847,7 +2852,7 @@ void asCBuilder::CompileGlobalVariables() initFunc->nameSpace = gvar->ns; asCCompiler comp(engine); - int r = comp.CompileGlobalVariable(this, gvar->script, gvar->initializationNode, gvar, initFunc); + int r = comp.CompileGlobalVariable(this, gvar->script, gvar->initializationNode, gvar, initFunc); if( r >= 0 ) { // Compilation succeeded @@ -2885,13 +2890,13 @@ void asCBuilder::CompileGlobalVariables() engine->AddScriptFunction(initFunc); // Finalize the init function for this variable - initFunc->returnType = asCDataType::CreatePrimitive(ttVoid, false); + initFunc->returnType = asCDataType::CreatePrimitive(ttVoid, false); initFunc->scriptData->scriptSectionIdx = engine->GetScriptSectionNameIndex(gvar->script->name.AddressOf()); if( gvar->declaredAtNode ) { int row, col; gvar->script->ConvertPosToRowCol(gvar->declaredAtNode->tokenPos, &row, &col); - initFunc->scriptData->declaredAt = (row & 0xFFFFF)|((col & 0xFFF)<<20); + initFunc->scriptData->declaredAt = (row & 0xFFFFF) | ((col & 0xFFF) << 20); } gvar->property->SetInitFunc(initFunc); @@ -2921,7 +2926,7 @@ void asCBuilder::CompileGlobalVariables() return; } - e->name = gvar->name; + e->name = gvar->name; e->value = asINT64(gvar->constantValue); enumType->enumValues.PushLast(e); @@ -2931,7 +2936,7 @@ void asCBuilder::CompileGlobalVariables() { // Add output to final output finalOutput.Append(outBuffer); - accumErrors += numErrors; + accumErrors += numErrors; accumWarnings += numWarnings; } @@ -2984,26 +2989,26 @@ void asCBuilder::CleanupEnumValues() { // Delete the enum expressions asCSymbolTableIterator it = globVariables.List(); - while (it) + while( it ) { sGlobalVariableDescription *gvar = *it; - if (gvar->isEnumValue) + if( gvar->isEnumValue ) { // Remove from symboltable. This has to be done prior to freeing the memeory globVariables.Erase(it.GetIndex()); // Destroy the gvar property - if (gvar->declaredAtNode) + if( gvar->declaredAtNode ) { gvar->declaredAtNode->Destroy(engine); gvar->declaredAtNode = 0; } - if (gvar->initializationNode) + if( gvar->initializationNode ) { gvar->initializationNode->Destroy(engine); gvar->initializationNode = 0; } - if (gvar->property) + if( gvar->property ) { asDELETE(gvar->property, asCGlobalProperty); gvar->property = 0; @@ -3028,7 +3033,7 @@ int asCBuilder::GetNamespaceAndNameFromNode(asCScriptNode *n, asCScriptCode *scr // Get the name asCString name(&script->code[n->lastChild->tokenPos], n->lastChild->tokenLength); - outNs = ns; + outNs = ns; outName = name; return 0; @@ -3046,9 +3051,9 @@ void asCBuilder::AddInterfaceFromMixinToClass(sClassDeclaration *decl, asCScript while( node && node->nodeType == snIdentifier ) { - bool ok = true; + bool ok = true; asSNameSpace *ns; - asCString name; + asCString name; if( GetNamespaceAndNameFromNode(node, mixin->script, mixin->ns, ns, name) < 0 ) ok = false; else @@ -3074,7 +3079,7 @@ void asCBuilder::AddInterfaceFromMixinToClass(sClassDeclaration *decl, asCScript { // Remove this node so the error isn't reported again asCScriptNode *delNode = node; - node = node->prev; + node = node->prev; delNode->DisconnectParent(); delNode->Destroy(engine); } @@ -3134,15 +3139,15 @@ void asCBuilder::CompileInterfaces() for( n = 0; n < interfaceDeclarations.GetLength(); n++ ) { sClassDeclaration *intfDecl = interfaceDeclarations[n]; - asCObjectType *intfType = CastToObjectType(intfDecl->typeInfo); + asCObjectType *intfType = CastToObjectType(intfDecl->typeInfo); if( intfType->interfaces.GetLength() == 0 ) continue; // If any of the derived interfaces are found after this interface, then move this to the end of the list - for( asUINT m = n+1; m < interfaceDeclarations.GetLength(); m++ ) + for( asUINT m = n + 1; m < interfaceDeclarations.GetLength(); m++ ) { if( intfType != interfaceDeclarations[m]->typeInfo && - intfType->Implements(interfaceDeclarations[m]->typeInfo) ) + intfType->Implements(interfaceDeclarations[m]->typeInfo) ) { interfaceDeclarations.RemoveIndex(n); interfaceDeclarations.PushLast(intfDecl); @@ -3165,7 +3170,7 @@ void asCBuilder::CompileInterfaces() intfDecl->validState = 1; continue; } - + asCObjectType *intfType = CastToObjectType(intfDecl->typeInfo); // TODO: Is this really at the correct place? Hasn't the vfTableIdx already been set here? @@ -3174,7 +3179,7 @@ void asCBuilder::CompileInterfaces() for( asUINT d = 0; d < intfType->methods.GetLength(); d++ ) { asCScriptFunction *func = GetFunctionDescription(intfType->methods[d]); - func->vfTableIdx = d; + func->vfTableIdx = d; asASSERT(func->objectType == intfType); } @@ -3193,9 +3198,9 @@ void asCBuilder::CompileInterfaces() for( asUINT l = 0; l < base->methods.GetLength(); l++ ) { // If the derived interface implements the same method, then don't add the base interface' method - asCScriptFunction *baseFunc = GetFunctionDescription(base->methods[l]); + asCScriptFunction *baseFunc = GetFunctionDescription(base->methods[l]); asCScriptFunction *derivedFunc = 0; - bool found = false; + bool found = false; for( asUINT d = 0; d < intfType->methods.GetLength(); d++ ) { derivedFunc = GetFunctionDescription(intfType->methods[d]); @@ -3220,10 +3225,10 @@ void asCBuilder::CompileInterfaces() void asCBuilder::DetermineTypeRelations() { // Determine inheritance between interfaces - for (asUINT n = 0; n < interfaceDeclarations.GetLength(); n++) + for( asUINT n = 0; n < interfaceDeclarations.GetLength(); n++ ) { sClassDeclaration *intfDecl = interfaceDeclarations[n]; - asCObjectType *intfType = CastToObjectType(intfDecl->typeInfo); + asCObjectType *intfType = CastToObjectType(intfDecl->typeInfo); asCScriptNode *node = intfDecl->node; asASSERT(node && node->nodeType == snInterface); @@ -3231,35 +3236,35 @@ void asCBuilder::DetermineTypeRelations() // Skip the 'shared' & 'external' keywords while( node->nodeType == snIdentifier && - (intfDecl->script->TokenEquals(node->tokenPos, node->tokenLength, SHARED_TOKEN) || - intfDecl->script->TokenEquals(node->tokenPos, node->tokenLength, EXTERNAL_TOKEN)) ) + (intfDecl->script->TokenEquals(node->tokenPos, node->tokenLength, SHARED_TOKEN) || + intfDecl->script->TokenEquals(node->tokenPos, node->tokenLength, EXTERNAL_TOKEN)) ) node = node->next; // Skip the name node = node->next; // Verify the inherited interfaces - while (node && node->nodeType == snIdentifier) + while( node && node->nodeType == snIdentifier ) { asSNameSpace *ns; - asCString name; - bool isExplicitNs = false; - if (GetNamespaceAndNameFromNode(node, intfDecl->script, intfType->nameSpace, ns, name, &isExplicitNs) < 0) + asCString name; + bool isExplicitNs = false; + if( GetNamespaceAndNameFromNode(node, intfDecl->script, intfType->nameSpace, ns, name, &isExplicitNs) < 0 ) { node = node->next; continue; } - asCObjectType* objType = 0; - bool ok = FindObjectTypeOrMixinInNsHierarchy(name, ns, isExplicitNs, node, intfDecl->script, &objType, 0); + asCObjectType *objType = 0; + bool ok = FindObjectTypeOrMixinInNsHierarchy(name, ns, isExplicitNs, node, intfDecl->script, &objType, 0); // Check that the object type is an interface - if (ok) + if( ok ) { - if (objType && objType->IsInterface()) + if( objType && objType->IsInterface() ) { // Check that the implemented interface is shared if the base interface is shared - if (intfType->IsShared() && !objType->IsShared()) + if( intfType->IsShared() && !objType->IsShared() ) { asCString str; str.Format(TXT_SHARED_CANNOT_IMPLEMENT_NON_SHARED_s, objType->GetName()); @@ -3274,13 +3279,13 @@ void asCBuilder::DetermineTypeRelations() } } - if (ok) + if( ok ) { // Make sure none of the implemented interfaces implement from this one asCObjectType *base = objType; - while (base != 0) + while( base != 0 ) { - if (base == intfType) + if( base == intfType ) { WriteError(TXT_CANNOT_IMPLEMENT_SELF, intfDecl->script, node); ok = false; @@ -3288,38 +3293,38 @@ void asCBuilder::DetermineTypeRelations() } // At this point there is at most one implemented interface - if (base->interfaces.GetLength()) + if( base->interfaces.GetLength() ) base = base->interfaces[0]; else break; } } - if (ok) + if( ok ) AddInterfaceToClass(intfDecl, node, objType); // Remove the nodes so they aren't parsed again asCScriptNode *delNode = node; - node = node->next; + node = node->next; delNode->DisconnectParent(); delNode->Destroy(engine); } } // Determine class inheritances and interfaces - for (asUINT n = 0; n < classDeclarations.GetLength(); n++) + for( asUINT n = 0; n < classDeclarations.GetLength(); n++ ) { sClassDeclaration *decl = classDeclarations[n]; - asCScriptCode *file = decl->script; + asCScriptCode *file = decl->script; // Find the base class that this class inherits from - bool multipleInheritance = false; - asCScriptNode *node = decl->node->firstChild; + bool multipleInheritance = false; + asCScriptNode *node = decl->node->firstChild; - while (file->TokenEquals(node->tokenPos, node->tokenLength, FINAL_TOKEN) || - file->TokenEquals(node->tokenPos, node->tokenLength, SHARED_TOKEN) || - file->TokenEquals(node->tokenPos, node->tokenLength, ABSTRACT_TOKEN) || - file->TokenEquals(node->tokenPos, node->tokenLength, EXTERNAL_TOKEN)) + while( file->TokenEquals(node->tokenPos, node->tokenLength, FINAL_TOKEN) || + file->TokenEquals(node->tokenPos, node->tokenLength, SHARED_TOKEN) || + file->TokenEquals(node->tokenPos, node->tokenLength, ABSTRACT_TOKEN) || + file->TokenEquals(node->tokenPos, node->tokenLength, EXTERNAL_TOKEN) ) { node = node->next; } @@ -3328,12 +3333,12 @@ void asCBuilder::DetermineTypeRelations() asASSERT(node->tokenType == ttIdentifier); node = node->next; - while (node && node->nodeType == snIdentifier) + while( node && node->nodeType == snIdentifier ) { asSNameSpace *ns; - asCString name; - bool isExplicitNs = false; - if (GetNamespaceAndNameFromNode(node, file, decl->typeInfo->nameSpace, ns, name, &isExplicitNs) < 0) + asCString name; + bool isExplicitNs = false; + if( GetNamespaceAndNameFromNode(node, file, decl->typeInfo->nameSpace, ns, name, &isExplicitNs) < 0 ) { node = node->next; continue; @@ -3341,28 +3346,28 @@ void asCBuilder::DetermineTypeRelations() // Find the object type for the interface asCObjectType *objType = 0; - sMixinClass *mixin = 0; - asSNameSpace *origNs = ns; + sMixinClass *mixin = 0; + asSNameSpace *origNs = ns; bool ok = FindObjectTypeOrMixinInNsHierarchy(name, ns, isExplicitNs, node, file, &objType, &mixin); - if (ok) + if( ok ) { - if (objType == 0 && mixin == 0) + if( objType == 0 && mixin == 0 ) { asCString str; - if (origNs->name == "") + if( origNs->name == "" ) str.Format(TXT_IDENTIFIER_s_NOT_DATA_TYPE_IN_GLOBAL_NS, name.AddressOf()); else str.Format(TXT_IDENTIFIER_s_NOT_DATA_TYPE_IN_NS_s, name.AddressOf(), origNs->name.AddressOf()); WriteError(str, file, node); } - else if (mixin) + else if( mixin ) { AddInterfaceFromMixinToClass(decl, node, mixin); } - else if (!(objType->flags & asOBJ_SCRIPT_OBJECT) || - (objType->flags & asOBJ_NOINHERIT)) + else if( !(objType->flags & asOBJ_SCRIPT_OBJECT) || + (objType->flags & asOBJ_NOINHERIT) ) { // Either the class is not a script class or interface // or the class has been declared as 'final' @@ -3370,12 +3375,12 @@ void asCBuilder::DetermineTypeRelations() str.Format(TXT_CANNOT_INHERIT_FROM_s_FINAL, objType->name.AddressOf()); WriteError(str, file, node); } - else if (objType->size != 0) + else if( objType->size != 0 ) { // The class inherits from another script class - if (!decl->isExistingShared && CastToObjectType(decl->typeInfo)->derivedFrom != 0) + if( !decl->isExistingShared && CastToObjectType(decl->typeInfo)->derivedFrom != 0 ) { - if (!multipleInheritance) + if( !multipleInheritance ) { WriteError(TXT_CANNOT_INHERIT_FROM_MULTIPLE_CLASSES, file, node); multipleInheritance = true; @@ -3384,11 +3389,11 @@ void asCBuilder::DetermineTypeRelations() else { // Make sure none of the base classes inherit from this one - asCObjectType* base = objType; - bool error = false; - while (base != 0) + asCObjectType *base = objType; + bool error = false; + while( base != 0 ) { - if (base == decl->typeInfo) + if( base == decl->typeInfo ) { WriteError(TXT_CANNOT_INHERIT_FROM_SELF, file, node); error = true; @@ -3398,10 +3403,10 @@ void asCBuilder::DetermineTypeRelations() base = base->derivedFrom; } - if (!error) + if( !error ) { // A shared type may only inherit from other shared types - if ((decl->typeInfo->IsShared()) && !(objType->IsShared())) + if( (decl->typeInfo->IsShared()) && !(objType->IsShared()) ) { asCString msg; msg.Format(TXT_SHARED_CANNOT_INHERIT_FROM_NON_SHARED_s, objType->name.AddressOf()); @@ -3410,12 +3415,12 @@ void asCBuilder::DetermineTypeRelations() } } - if (!error) + if( !error ) { - if (decl->isExistingShared) + if( decl->isExistingShared ) { // Verify that the base class is the same as the original shared type - if (CastToObjectType(decl->typeInfo)->derivedFrom != objType) + if( CastToObjectType(decl->typeInfo)->derivedFrom != objType ) { asCString str; str.Format(TXT_SHARED_s_DOESNT_MATCH_ORIGINAL_s, decl->typeInfo->GetName(), decl->typeInfo->GetModule() ? decl->typeInfo->GetModule()->GetName() : ""); @@ -3446,21 +3451,21 @@ void asCBuilder::DetermineTypeRelations() // numTempl is the number of template instances that existed in the engine before the build begun void asCBuilder::CompileClasses(asUINT numTempl) { - asUINT n; - asCArray toValidate((int)classDeclarations.GetLength()); + asUINT n; + asCArray toValidate((int)classDeclarations.GetLength()); // Order class declarations so that base classes are compiled before derived classes. // This will allow the derived classes to copy properties and methods in the next step. for( n = 0; n < classDeclarations.GetLength(); n++ ) { - sClassDeclaration *decl = classDeclarations[n]; - asCObjectType *derived = CastToObjectType(decl->typeInfo); - asCObjectType *base = derived->derivedFrom; + sClassDeclaration *decl = classDeclarations[n]; + asCObjectType *derived = CastToObjectType(decl->typeInfo); + asCObjectType *base = derived->derivedFrom; if( base == 0 ) continue; // If the base class is found after the derived class, then move the derived class to the end of the list - for( asUINT m = n+1; m < classDeclarations.GetLength(); m++ ) + for( asUINT m = n + 1; m < classDeclarations.GetLength(); m++ ) { sClassDeclaration *declBase = classDeclarations[m]; if( base == declBase->typeInfo ) @@ -3479,7 +3484,7 @@ void asCBuilder::CompileClasses(asUINT numTempl) for( n = 0; n < classDeclarations.GetLength(); n++ ) { sClassDeclaration *decl = classDeclarations[n]; - asCObjectType *ot = CastToObjectType(decl->typeInfo); + asCObjectType *ot = CastToObjectType(decl->typeInfo); if( decl->isExistingShared ) { // Set the declaration as validated already, so that other @@ -3517,25 +3522,26 @@ void asCBuilder::CompileClasses(asUINT numTempl) asCObjectProperty *prop = AddPropertyToClass(decl, baseType->properties[p]->name, baseType->properties[p]->type, baseType->properties[p]->isPrivate, baseType->properties[p]->isProtected, true); // The properties must maintain the same offset - asASSERT(prop && prop->byteOffset == baseType->properties[p]->byteOffset); UNUSED_VAR(prop); + asASSERT(prop && prop->byteOffset == baseType->properties[p]->byteOffset); + UNUSED_VAR(prop); } // Copy methods from base class to derived class for( asUINT m = 0; m < baseType->methods.GetLength(); m++ ) { // If the derived class implements the same method, then don't add the base class' method - asCScriptFunction *baseFunc = GetFunctionDescription(baseType->methods[m]); + asCScriptFunction *baseFunc = GetFunctionDescription(baseType->methods[m]); asCScriptFunction *derivedFunc = 0; - bool found = false; + bool found = false; for( asUINT d = 0; d < ot->methods.GetLength(); d++ ) { derivedFunc = GetFunctionDescription(ot->methods[d]); if( baseFunc->name == "opConv" || baseFunc->name == "opImplConv" || - baseFunc->name == "opCast" || baseFunc->name == "opImplCast" ) + baseFunc->name == "opCast" || baseFunc->name == "opImplCast" ) { // For the opConv and opCast methods, the return type can differ if they are different methods if( derivedFunc->name == baseFunc->name && - derivedFunc->IsSignatureExceptNameEqual(baseFunc) ) + derivedFunc->IsSignatureExceptNameEqual(baseFunc) ) { if( baseFunc->IsFinal() ) { @@ -3554,7 +3560,7 @@ void asCBuilder::CompileClasses(asUINT numTempl) else { if( derivedFunc->name == baseFunc->name && - derivedFunc->IsSignatureExceptNameAndReturnTypeEqual(baseFunc) ) + derivedFunc->IsSignatureExceptNameAndReturnTypeEqual(baseFunc) ) { if( baseFunc->returnType != derivedFunc->returnType ) { @@ -3678,17 +3684,17 @@ void asCBuilder::CompileClasses(asUINT numTempl) if( nd && nd->tokenType == ttPrivate ) { isPrivate = true; - nd = nd->next; + nd = nd->next; } else if( nd && nd->tokenType == ttProtected ) { isProtected = true; - nd = nd->next; + nd = nd->next; } // Determine the type of the property asCScriptCode *file = decl->script; - asCDataType dt = CreateDataTypeFromNode(nd, file, ot->nameSpace, false, ot); + asCDataType dt = CreateDataTypeFromNode(nd, file, ot->nameSpace, false, ot); if( ot->IsShared() && dt.GetTypeInfo() && !dt.GetTypeInfo()->IsShared() ) { asCString msg; @@ -3718,9 +3724,9 @@ void asCBuilder::CompileClasses(asUINT numTempl) { asCObjectProperty *prop = ot->properties[p]; if( prop->isPrivate == isPrivate && - prop->isProtected == isProtected && - prop->name == name && - prop->type.IsEqualExceptRef(dt) ) + prop->isProtected == isProtected && + prop->name == name && + prop->type.IsEqualExceptRef(dt) ) { found = true; break; @@ -3770,7 +3776,7 @@ void asCBuilder::CompileClasses(asUINT numTempl) asCObjectType *ot = CastToObjectType(decl->typeInfo); asCArray overrideValidations(ot->GetMethodCount()); for( asUINT k = 0; k < ot->methods.GetLength(); k++ ) - overrideValidations.PushLast( !static_cast(ot->GetMethodByIndex(k, false))->IsOverride() ); + overrideValidations.PushLast(!static_cast(ot->GetMethodByIndex(k, false))->IsOverride()); for( asUINT m = 0; m < ot->interfaces.GetLength(); m++ ) { @@ -3787,7 +3793,7 @@ void asCBuilder::CompileClasses(asUINT numTempl) { asCString str; str.Format(TXT_MISSING_IMPLEMENTATION_OF_s, - engine->GetFunctionDeclaration(objType->methods[i]).AddressOf()); + engine->GetFunctionDeclaration(objType->methods[i]).AddressOf()); WriteError(str, decl->script, decl->node); } else @@ -3814,17 +3820,17 @@ void asCBuilder::CompileClasses(asUINT numTempl) { asUINT numClasses = (asUINT)toValidate.GetLength(); - asCArray toValidateNext((int)toValidate.GetLength()); + asCArray toValidateNext((int)toValidate.GetLength()); while( toValidate.GetLength() > 0 ) { - sClassDeclaration *decl = toValidate[toValidate.GetLength()-1]; - asCObjectType *ot = CastToObjectType(decl->typeInfo); - int validState = 1; + sClassDeclaration *decl = toValidate[toValidate.GetLength() - 1]; + asCObjectType *ot = CastToObjectType(decl->typeInfo); + int validState = 1; for( n = 0; n < ot->properties.GetLength(); n++ ) { // A valid structure is one that uses only primitives or other valid objects asCObjectProperty *prop = ot->properties[n]; - asCDataType dt = prop->type; + asCDataType dt = prop->type; // TODO: Add this check again, once solving the issues commented below /* @@ -3901,64 +3907,64 @@ void asCBuilder::CompileClasses(asUINT numTempl) if( numErrors > 0 ) return; // Iterate through classes and verify if any automatically generated copy constructor can really be compiled, - // i.e. all members and the base class can be copied. If not, then remove the auto generated copy constructor + // i.e. all members and the base class can be copied. If not, then remove the auto generated copy constructor // so it will not be compiled. This is done here when it is known the order of class inheritance, and all classes // have received their members from mixins, etc. - for (n = 0; n < classDeclarations.GetLength(); n++) + for( n = 0; n < classDeclarations.GetLength(); n++ ) { - sClassDeclaration* decl = classDeclarations[n]; - if (decl->isExistingShared) + sClassDeclaration *decl = classDeclarations[n]; + if( decl->isExistingShared ) continue; - asCObjectType* ot = CastToObjectType(decl->typeInfo); - if (ot == 0 || ot->beh.copyconstruct == 0) + asCObjectType *ot = CastToObjectType(decl->typeInfo); + if( ot == 0 || ot->beh.copyconstruct == 0 ) continue; // Find the sFunctionDescriptor to determine if the copy constructor is auto generated or not asUINT funcDesc = asUINT(-1); - for (asUINT d = 0; d < functions.GetLength(); d++) - if (functions[d] && functions[d]->funcId == ot->beh.copyconstruct) + for( asUINT d = 0; d < functions.GetLength(); d++ ) + if( functions[d] && functions[d]->funcId == ot->beh.copyconstruct ) { funcDesc = d; break; } - if (funcDesc != asUINT(-1) && functions[funcDesc]->node == 0) + if( funcDesc != asUINT(-1) && functions[funcDesc]->node == 0 ) { // The copy constructor is auto generated. Check if all members and base class can be copied - bool canBeCopied = true; - asCScriptFunction *func = engine->scriptFunctions[ot->beh.copyconstruct]; - asCObjectType* objType = func->objectType; - if (objType->derivedFrom) + bool canBeCopied = true; + asCScriptFunction *func = engine->scriptFunctions[ot->beh.copyconstruct]; + asCObjectType *objType = func->objectType; + if( objType->derivedFrom ) { - if (objType->derivedFrom->beh.copyconstruct == 0 && - (objType->derivedFrom->beh.construct == 0 || objType->derivedFrom->beh.copy == 0)) + if( objType->derivedFrom->beh.copyconstruct == 0 && + (objType->derivedFrom->beh.construct == 0 || objType->derivedFrom->beh.copy == 0) ) canBeCopied = false; else { // The base class can be copied. Check if it can be done from a const object // TODO: Should allow it anyway, but the copy constructor should be generated as taking a non-const reference - asCScriptFunction* baseFunc = engine->scriptFunctions[objType->derivedFrom->beh.copyconstruct]; - if (baseFunc && !baseFunc->parameterTypes[0].IsObjectConst()) + asCScriptFunction *baseFunc = engine->scriptFunctions[objType->derivedFrom->beh.copyconstruct]; + if( baseFunc && !baseFunc->parameterTypes[0].IsObjectConst() ) canBeCopied = false; - else if (!baseFunc) + else if( !baseFunc ) { baseFunc = engine->scriptFunctions[objType->derivedFrom->beh.copy]; - if (baseFunc && !baseFunc->parameterTypes[0].IsObjectConst()) + if( baseFunc && !baseFunc->parameterTypes[0].IsObjectConst() ) canBeCopied = false; } } } - for (asUINT m = 0; canBeCopied && m < objType->properties.GetLength(); m++) + for( asUINT m = 0; canBeCopied && m < objType->properties.GetLength(); m++ ) { - asCObjectProperty* prop = objType->properties[m]; + asCObjectProperty *prop = objType->properties[m]; // Check if the property is inherited - asCScriptNode* declNode = 0; - for (asUINT p = 0; p < decl->propInits.GetLength(); p++) + asCScriptNode *declNode = 0; + for( asUINT p = 0; p < decl->propInits.GetLength(); p++ ) { - if (decl->propInits[p].name == prop->name) + if( decl->propInits[p].name == prop->name ) { declNode = decl->propInits[p].declNode; break; @@ -3966,31 +3972,31 @@ void asCBuilder::CompileClasses(asUINT numTempl) } // If declNode is null then the property was inherited - if (declNode == 0) + if( declNode == 0 ) continue; // Check if the property can be copied - asCObjectType* propObjType = CastToObjectType(prop->type.GetTypeInfo()); - if (propObjType && !prop->type.IsObjectHandle() && propObjType->beh.copyconstruct == 0 && - (propObjType->beh.construct == 0 || propObjType->beh.copy == 0)) + asCObjectType *propObjType = CastToObjectType(prop->type.GetTypeInfo()); + if( propObjType && !prop->type.IsObjectHandle() && propObjType->beh.copyconstruct == 0 && + (propObjType->beh.construct == 0 || propObjType->beh.copy == 0) ) canBeCopied = false; - else if(propObjType && !prop->type.IsObjectHandle()) + else if( propObjType && !prop->type.IsObjectHandle() ) { // The property can be copied. Check if it can be done from a const object // TODO: Should allow it anyway, but the copy constructor should be generated as taking a non-const reference - asCScriptFunction* baseFunc = engine->scriptFunctions[propObjType->beh.copyconstruct]; - if (baseFunc && !baseFunc->parameterTypes[0].IsObjectConst()) + asCScriptFunction *baseFunc = engine->scriptFunctions[propObjType->beh.copyconstruct]; + if( baseFunc && !baseFunc->parameterTypes[0].IsObjectConst() ) canBeCopied = false; - else if (!baseFunc) + else if( !baseFunc ) { baseFunc = engine->scriptFunctions[propObjType->beh.copy]; - if (baseFunc && !baseFunc->parameterTypes[0].IsObjectConst()) + if( baseFunc && !baseFunc->parameterTypes[0].IsObjectConst() ) canBeCopied = false; } } } - if (!canBeCopied) + if( !canBeCopied ) { // Remove the function descriptor and the script function that was prepared for compilation asDELETE(functions[funcDesc], sFunctionDescription); @@ -4004,8 +4010,8 @@ void asCBuilder::CompileClasses(asUINT numTempl) func->ReleaseInternal(); // Do the same for the copyfactory - for (asUINT d = 0; d < functions.GetLength(); d++) - if (functions[d] && functions[d]->funcId == ot->beh.copyfactory) + for( asUINT d = 0; d < functions.GetLength(); d++ ) + if( functions[d] && functions[d]->funcId == ot->beh.copyfactory ) { asDELETE(functions[d], sFunctionDescription); functions.RemoveIndex(d); @@ -4037,19 +4043,19 @@ void asCBuilder::CompileClasses(asUINT numTempl) if( !engine->ep.disableScriptClassGC ) { - asCArray typesToValidate; + asCArray typesToValidate; for( n = 0; n < classDeclarations.GetLength(); n++ ) { // Existing shared classes won't need evaluating, nor interfaces sClassDeclaration *decl = classDeclarations[n]; if( decl->isExistingShared ) continue; - + asCObjectType *ot = CastToObjectType(decl->typeInfo); if( ot->IsInterface() ) continue; - + typesToValidate.PushLast(ot); } - + asUINT numReevaluations = 0; while( typesToValidate.GetLength() ) { @@ -4059,10 +4065,10 @@ void asCBuilder::CompileClasses(asUINT numTempl) // we consider the remaining types in the array as garbage collected break; } - + asCObjectType *type = typesToValidate[0]; typesToValidate.RemoveIndex(0); - + // If the type inherits from another type that is yet to be validated, then reinsert it at the end if( type->derivedFrom && typesToValidate.Exists(type->derivedFrom) ) { @@ -4070,29 +4076,29 @@ void asCBuilder::CompileClasses(asUINT numTempl) numReevaluations++; continue; } - + // If the type inherits from a known garbage collected type, then this type must also be garbage collected if( type->derivedFrom && (type->derivedFrom->flags & asOBJ_GC) ) { type->flags |= asOBJ_GC; continue; } - + // Evaluate template instances (silently) before verifying each of the classes, since it is possible that // a class will be marked as non-garbage collected, which in turn will mark the template instance that uses // it as non-garbage collected, which in turn means the class that contains the array also do not have to be // garbage collected EvaluateTemplateInstances(numTempl, true); - + // Is there some path in which this structure is involved in circular references? // If the type contains a member of a type that is yet to be validated, then reinsert it at the end bool mustReevaluate = false; - bool gc = false; + bool gc = false; for( asUINT p = 0; p < type->properties.GetLength(); p++ ) { asCDataType dt = type->properties[p]->type; - - if (dt.IsFuncdef()) + + if( dt.IsFuncdef() ) { // If a class holds a function pointer as member then the class must be garbage collected as the // function pointer can form circular references with the class through use of a delegate. Example: @@ -4108,10 +4114,10 @@ void asCBuilder::CompileClasses(asUINT numTempl) gc = true; break; } - + if( !dt.IsObject() ) continue; - + if( typesToValidate.Exists(CastToObjectType(dt.GetTypeInfo())) ) mustReevaluate = true; else @@ -4122,24 +4128,24 @@ void asCBuilder::CompileClasses(asUINT numTempl) bool skip = false; for( asUINT s = 0; s < dt.GetTypeInfo()->GetSubTypeCount(); s++ ) { - asCObjectType *t = reinterpret_cast(dt.GetTypeInfo()->GetSubType(s)); + asCObjectType *t = reinterpret_cast(dt.GetTypeInfo()->GetSubType(s)); if( typesToValidate.Exists(t) ) { mustReevaluate = true; - skip = true; + skip = true; break; } } if( skip ) continue; } - + if( dt.IsObjectHandle() ) { // If it is known that the handle can't be involved in a circular reference // then this object doesn't need to be marked as garbage collected. asCObjectType *prop = CastToObjectType(dt.GetTypeInfo()); - + if( prop->flags & asOBJ_SCRIPT_OBJECT ) { // For script objects, treat non-final classes as if they can contain references @@ -4151,7 +4157,7 @@ void asCBuilder::CompileClasses(asUINT numTempl) for( asUINT sp = 0; sp < prop->properties.GetLength(); sp++ ) { asCDataType sdt = prop->properties[sp]->type; - + if( sdt.IsObject() ) { if( sdt.IsObjectHandle() ) @@ -4172,7 +4178,7 @@ void asCBuilder::CompileClasses(asUINT numTempl) } } } - + if( gc ) break; } @@ -4202,7 +4208,7 @@ void asCBuilder::CompileClasses(asUINT numTempl) } } } - + // If the class wasn't found to require garbage collection, but it // contains another type that has yet to be evaluated then it must be // re-evaluated. @@ -4212,13 +4218,13 @@ void asCBuilder::CompileClasses(asUINT numTempl) numReevaluations++; continue; } - + // Update the flag in the object type if( gc ) type->flags |= asOBJ_GC; else type->flags &= ~asOBJ_GC; - + // Reset the counter numReevaluations = 0; } @@ -4231,7 +4237,7 @@ void asCBuilder::IncludeMethodsFromMixins(sClassDeclaration *decl) // Skip the class attributes while( node->nodeType == snIdentifier && - !decl->script->TokenEquals(node->tokenPos, node->tokenLength, decl->name.AddressOf()) ) + !decl->script->TokenEquals(node->tokenPos, node->tokenLength, decl->name.AddressOf()) ) node = node->next; // Skip the name of the class @@ -4241,7 +4247,7 @@ void asCBuilder::IncludeMethodsFromMixins(sClassDeclaration *decl) while( node && node->nodeType == snIdentifier ) { asSNameSpace *ns; - asCString name; + asCString name; if( GetNamespaceAndNameFromNode(node, decl->script, decl->typeInfo->nameSpace, ns, name) < 0 ) { node = node->next; @@ -4305,7 +4311,7 @@ void asCBuilder::IncludePropertiesFromMixins(sClassDeclaration *decl) // Skip the class attributes while( node->nodeType == snIdentifier && - !decl->script->TokenEquals(node->tokenPos, node->tokenLength, decl->name.AddressOf()) ) + !decl->script->TokenEquals(node->tokenPos, node->tokenLength, decl->name.AddressOf()) ) node = node->next; // Skip the name of the class @@ -4315,7 +4321,7 @@ void asCBuilder::IncludePropertiesFromMixins(sClassDeclaration *decl) while( node && node->nodeType == snIdentifier ) { asSNameSpace *ns; - asCString name; + asCString name; if( GetNamespaceAndNameFromNode(node, decl->script, decl->typeInfo->nameSpace, ns, name) < 0 ) { node = node->next; @@ -4351,21 +4357,21 @@ void asCBuilder::IncludePropertiesFromMixins(sClassDeclaration *decl) { if( n->nodeType == snDeclaration ) { - asCScriptNode *n2 = n->firstChild; - bool isPrivate = false, isProtected = false; + asCScriptNode *n2 = n->firstChild; + bool isPrivate = false, isProtected = false; if( n2 && n2->tokenType == ttPrivate ) { isPrivate = true; - n2 = n2->next; + n2 = n2->next; } else if( n2 && n2->tokenType == ttProtected ) { isProtected = true; - n2 = n2->next; + n2 = n2->next; } asCScriptCode *file = mixin->script; - asCDataType dt = CreateDataTypeFromNode(n2, file, mixin->ns); + asCDataType dt = CreateDataTypeFromNode(n2, file, mixin->ns); if( decl->typeInfo->IsShared() && dt.GetTypeInfo() && !dt.GetTypeInfo()->IsShared() ) { @@ -4384,8 +4390,8 @@ void asCBuilder::IncludePropertiesFromMixins(sClassDeclaration *decl) name.Assign(&file->code[n2->tokenPos], n2->tokenLength); // Add the property only if it doesn't already exist in the class - bool exists = false; - asCObjectType *ot = CastToObjectType(decl->typeInfo); + bool exists = false; + asCObjectType *ot = CastToObjectType(decl->typeInfo); for( asUINT p = 0; p < ot->properties.GetLength(); p++ ) if( ot->properties[p]->name == name ) { @@ -4412,9 +4418,9 @@ void asCBuilder::IncludePropertiesFromMixins(sClassDeclaration *decl) { asCObjectProperty *prop = ot->properties[p]; if( prop->isPrivate == isPrivate && - prop->isProtected == isProtected && - prop->name == name && - prop->type == dt ) + prop->isProtected == isProtected && + prop->name == name && + prop->type == dt ) { found = true; break; @@ -4452,17 +4458,17 @@ int asCBuilder::CreateVirtualFunction(asCScriptFunction *func, int idx) if( vf == 0 ) return asOUT_OF_MEMORY; - vf->name = func->name; - vf->nameSpace = func->nameSpace; - vf->returnType = func->returnType; - vf->parameterTypes = func->parameterTypes; - vf->inOutFlags = func->inOutFlags; - vf->id = engine->GetNextScriptFunctionId(); - vf->objectType = func->objectType; + vf->name = func->name; + vf->nameSpace = func->nameSpace; + vf->returnType = func->returnType; + vf->parameterTypes = func->parameterTypes; + vf->inOutFlags = func->inOutFlags; + vf->id = engine->GetNextScriptFunctionId(); + vf->objectType = func->objectType; vf->objectType->AddRefInternal(); - vf->signatureId = func->signatureId; - vf->vfTableIdx = idx; - vf->traits = func->traits; + vf->signatureId = func->signatureId; + vf->vfTableIdx = idx; + vf->traits = func->traits; // Clear the shared trait since the virtual function should not have that vf->SetShared(false); @@ -4532,11 +4538,11 @@ bool asCBuilder::DoesMethodExist(asCObjectType *objType, int methodId, asUINT *m { asCScriptFunction *m = GetFunctionDescription(objType->methods[n]); - if( m->name != method->name ) continue; - if( m->returnType != method->returnType ) continue; - if( m->IsReadOnly() != method->IsReadOnly() ) continue; + if( m->name != method->name ) continue; + if( m->returnType != method->returnType ) continue; + if( m->IsReadOnly() != method->IsReadOnly() ) continue; if( m->parameterTypes != method->parameterTypes ) continue; - if( m->inOutFlags != method->inOutFlags ) continue; + if( m->inOutFlags != method->inOutFlags ) continue; if( methodIndex ) *methodIndex = n; @@ -4547,19 +4553,19 @@ bool asCBuilder::DoesMethodExist(asCObjectType *objType, int methodId, asUINT *m return false; } -void asCBuilder::AddDefaultCopyConstructor(asCObjectType* objType, asCScriptCode* file) +void asCBuilder::AddDefaultCopyConstructor(asCObjectType *objType, asCScriptCode *file) { // Check if a copy constructor does not already exist, in which case this should be skipped - if (objType->beh.copyconstruct != 0) + if( objType->beh.copyconstruct != 0 ) return; int funcId = engine->GetNextScriptFunctionId(); - asCDataType returnType = asCDataType::CreatePrimitive(ttVoid, false); - asCArray parameterTypes; + asCDataType returnType = asCDataType::CreatePrimitive(ttVoid, false); + asCArray parameterTypes; asCArray inOutFlags; - asCArray defaultArgs; - asCArray parameterNames; + asCArray defaultArgs; + asCArray parameterNames; parameterTypes.PushLast(asCDataType::CreateType(objType, true)); parameterTypes[0].MakeReference(true); @@ -4579,8 +4585,8 @@ void asCBuilder::AddDefaultCopyConstructor(asCObjectType* objType, asCScriptCode // The bytecode for the default constructor will be generated // only after the potential inheritance has been established - sFunctionDescription* func = asNEW(sFunctionDescription); - if (func == 0) + sFunctionDescription *func = asNEW(sFunctionDescription); + if( func == 0 ) { // Out of memory return; @@ -4588,18 +4594,18 @@ void asCBuilder::AddDefaultCopyConstructor(asCObjectType* objType, asCScriptCode functions.PushLast(func); - func->script = file; - func->node = 0; - func->name = objType->name; - func->objType = objType; - func->funcId = funcId; + func->script = file; + func->node = 0; + func->name = objType->name; + func->objType = objType; + func->funcId = funcId; func->isExistingShared = false; // Add a factory as well funcId = engine->GetNextScriptFunctionId(); objType->beh.factories.PushLast(funcId); objType->beh.copyfactory = funcId; - returnType = asCDataType::CreateObjectHandle(objType, false); + returnType = asCDataType::CreateObjectHandle(objType, false); // TODO: should be the same as the constructor module->AddScriptFunction(file->idx, 0, funcId, objType->name, returnType, parameterTypes, parameterNames, inOutFlags, defaultArgs, false); functions.PushLast(0); @@ -4608,23 +4614,23 @@ void asCBuilder::AddDefaultCopyConstructor(asCObjectType* objType, asCScriptCode engine->scriptFunctions[funcId]->AddRefInternal(); // If the object is shared, then the factory must also be marked as shared - if (objType->flags & asOBJ_SHARED) + if( objType->flags & asOBJ_SHARED ) engine->scriptFunctions[funcId]->SetShared(true); } void asCBuilder::AddDefaultConstructor(asCObjectType *objType, asCScriptCode *file) { // Check if a default constructor does not already exist, in which case this should be skipped - if (objType->beh.construct != engine->scriptTypeBehaviours.beh.construct) + if( objType->beh.construct != engine->scriptTypeBehaviours.beh.construct ) return; int funcId = engine->GetNextScriptFunctionId(); - asCDataType returnType = asCDataType::CreatePrimitive(ttVoid, false); - asCArray parameterTypes; + asCDataType returnType = asCDataType::CreatePrimitive(ttVoid, false); + asCArray parameterTypes; asCArray inOutFlags; - asCArray defaultArgs; - asCArray parameterNames; + asCArray defaultArgs; + asCArray parameterNames; // Add the script function // TODO: declaredAt should be set to where the class has been declared @@ -4633,7 +4639,7 @@ void asCBuilder::AddDefaultConstructor(asCObjectType *objType, asCScriptCode *fi // Set it as default constructor if( objType->beh.construct ) engine->scriptFunctions[objType->beh.construct]->ReleaseInternal(); - objType->beh.construct = funcId; + objType->beh.construct = funcId; objType->beh.constructors[0] = funcId; engine->scriptFunctions[funcId]->AddRefInternal(); @@ -4648,20 +4654,20 @@ void asCBuilder::AddDefaultConstructor(asCObjectType *objType, asCScriptCode *fi functions.PushLast(func); - func->script = file; - func->node = 0; - func->name = objType->name; - func->objType = objType; - func->funcId = funcId; - func->isExistingShared = false; + func->script = file; + func->node = 0; + func->name = objType->name; + func->objType = objType; + func->funcId = funcId; + func->isExistingShared = false; // Add a default factory as well funcId = engine->GetNextScriptFunctionId(); if( objType->beh.factory ) engine->scriptFunctions[objType->beh.factory]->ReleaseInternal(); - objType->beh.factory = funcId; + objType->beh.factory = funcId; objType->beh.factories[0] = funcId; - returnType = asCDataType::CreateObjectHandle(objType, false); + returnType = asCDataType::CreateObjectHandle(objType, false); // TODO: should be the same as the constructor module->AddScriptFunction(file->idx, 0, funcId, objType->name, returnType, parameterTypes, parameterNames, inOutFlags, defaultArgs, false); functions.PushLast(0); @@ -4677,15 +4683,15 @@ void asCBuilder::AddDefaultConstructor(asCObjectType *objType, asCScriptCode *fi int asCBuilder::RegisterEnum(asCScriptNode *node, asCScriptCode *file, asSNameSpace *ns) { // Is it a shared enum? - bool isShared = false; - bool isExternal = false; - asCEnumType *existingSharedType = 0; - asCScriptNode *tmp = node->firstChild; + bool isShared = false; + bool isExternal = false; + asCEnumType *existingSharedType = 0; + asCScriptNode *tmp = node->firstChild; while( tmp->nodeType == snIdentifier ) { - if (file->TokenEquals(tmp->tokenPos, tmp->tokenLength, SHARED_TOKEN)) + if( file->TokenEquals(tmp->tokenPos, tmp->tokenLength, SHARED_TOKEN) ) isShared = true; - else if (file->TokenEquals(tmp->tokenPos, tmp->tokenLength, EXTERNAL_TOKEN)) + else if( file->TokenEquals(tmp->tokenPos, tmp->tokenLength, EXTERNAL_TOKEN) ) isExternal = true; else break; @@ -4699,9 +4705,9 @@ int asCBuilder::RegisterEnum(asCScriptNode *node, asCScriptCode *file, asSNameSp name.Assign(&file->code[tmp->firstChild->tokenPos], tmp->firstChild->tokenLength); // Grab the type of the enumeration - asCDataType type = asCDataType::CreatePrimitive(ttInt, true); - asCScriptNode * dataNode = tmp->firstChild->next; - if (dataNode) + asCDataType type = asCDataType::CreatePrimitive(ttInt, true); + asCScriptNode *dataNode = tmp->firstChild->next; + if( dataNode ) { asASSERT(snDataType == dataNode->nodeType); asASSERT((dataNode->tokenType >= ttInt && dataNode->tokenType <= ttInt64) || @@ -4716,11 +4722,11 @@ int asCBuilder::RegisterEnum(asCScriptNode *node, asCScriptCode *file, asSNameSp { asCTypeInfo *o = engine->sharedScriptTypes[n]; if( o && - o->IsShared() && - (o->flags & asOBJ_ENUM) && - o->name == name && - o->nameSpace == ns && - CastToEnumType(o)->enumType == type) + o->IsShared() && + (o->flags & asOBJ_ENUM) && + o->name == name && + o->nameSpace == ns && + CastToEnumType(o)->enumType == type ) { existingSharedType = CastToEnumType(o); break; @@ -4729,7 +4735,7 @@ int asCBuilder::RegisterEnum(asCScriptNode *node, asCScriptCode *file, asSNameSp } // If the enum was declared as external then it must have been compiled in a different module first - if (isExternal && existingSharedType == 0) + if( isExternal && existingSharedType == 0 ) { asCString str; str.Format(TXT_EXTERNAL_SHARED_s_NOT_FOUND, name.AddressOf()); @@ -4737,7 +4743,7 @@ int asCBuilder::RegisterEnum(asCScriptNode *node, asCScriptCode *file, asSNameSp } // Remember if the type was declared as external so the saved bytecode can be flagged accordingly - if (isExternal && existingSharedType) + if( isExternal && existingSharedType ) module->m_externalTypes.PushLast(existingSharedType); // Check the name and add the enum @@ -4757,7 +4763,7 @@ int asCBuilder::RegisterEnum(asCScriptNode *node, asCScriptCode *file, asSNameSp if( st == 0 ) return asOUT_OF_MEMORY; - st->flags = asOBJ_ENUM; + st->flags = asOBJ_ENUM; if( isShared ) st->flags |= asOBJ_SHARED; st->size = type.GetSizeInMemoryBytes(); @@ -4779,22 +4785,22 @@ int asCBuilder::RegisterEnum(asCScriptNode *node, asCScriptCode *file, asSNameSp if( decl == 0 ) return asOUT_OF_MEMORY; - decl->name = name; - decl->script = file; - decl->typeInfo = st; + decl->name = name; + decl->script = file; + decl->typeInfo = st; namedTypeDeclarations.PushLast(decl); type = CreateDataTypeFromNode(tmp, file, ns); asASSERT(!type.IsReference()); // External shared enums must not redeclare the enum values - if (isExternal && (tmp->next == 0 || tmp->next->tokenType != ttEndStatement) ) + if( isExternal && (tmp->next == 0 || tmp->next->tokenType != ttEndStatement) ) { asCString str; str.Format(TXT_EXTERNAL_SHARED_s_CANNOT_REDEF, name.AddressOf()); WriteError(str, file, tmp); } - else if (!isExternal && tmp->next && tmp->next->tokenType == ttEndStatement) + else if( !isExternal && tmp->next && tmp->next->tokenType == ttEndStatement ) { asCString str; str.Format(TXT_MISSING_DEFINITION_OF_s, name.AddressOf()); @@ -4859,9 +4865,9 @@ int asCBuilder::RegisterEnum(asCScriptNode *node, asCScriptCode *file, asSNameSp if( gvar == 0 ) return asOUT_OF_MEMORY; - gvar->script = file; - gvar->declaredAtNode = tmp; - tmp = tmp->next; + gvar->script = file; + gvar->declaredAtNode = tmp; + tmp = tmp->next; gvar->declaredAtNode->DisconnectParent(); gvar->initializationNode = asnNode; gvar->name = name; @@ -4869,11 +4875,11 @@ int asCBuilder::RegisterEnum(asCScriptNode *node, asCScriptCode *file, asSNameSp gvar->ns = ns; // No need to allocate space on the global memory stack since the values are stored in the asCObjectType // Set the index to a negative to allow compiler to diferentiate from ordinary global var when compiling the initialization - gvar->index = -1; - gvar->isCompiled = false; - gvar->isPureConstant = true; - gvar->isEnumValue = true; - gvar->constantValue = 0xdeadbeef; + gvar->index = -1; + gvar->isCompiled = false; + gvar->isPureConstant = true; + gvar->isEnumValue = true; + gvar->constantValue = 0xdeadbeef; // Allocate dummy property so we can compile the value. // This will be removed later on so we don't add it to the engine. @@ -4925,12 +4931,12 @@ int asCBuilder::RegisterTypedef(asCScriptNode *node, asCScriptCode *file, asSNam if( asSUCCESS == r ) { - st->flags = asOBJ_TYPEDEF; - st->size = dataType.GetSizeInMemoryBytes(); - st->name = name; - st->nameSpace = ns; - st->aliasForType = dataType; - st->module = module; + st->flags = asOBJ_TYPEDEF; + st->size = dataType.GetSizeInMemoryBytes(); + st->name = name; + st->nameSpace = ns; + st->aliasForType = dataType; + st->module = module; module->AddTypeDef(st); @@ -4940,9 +4946,9 @@ int asCBuilder::RegisterTypedef(asCScriptNode *node, asCScriptCode *file, asSNam r = asOUT_OF_MEMORY; else { - decl->name = name; - decl->script = file; - decl->typeInfo = st; + decl->name = name; + decl->script = file; + decl->typeInfo = st; namedTypeDeclarations.PushLast(decl); } } @@ -4959,11 +4965,11 @@ void asCBuilder::GetParsedFunctionDetails(asCScriptNode *node, asCScriptCode *fi // Is the function shared? funcTraits.SetTrait(asTRAIT_SHARED, false); funcTraits.SetTrait(asTRAIT_EXTERNAL, false); - while (node->tokenType == ttIdentifier) + while( node->tokenType == ttIdentifier ) { - if (file->TokenEquals(node->tokenPos, node->tokenLength, SHARED_TOKEN)) + if( file->TokenEquals(node->tokenPos, node->tokenLength, SHARED_TOKEN) ) funcTraits.SetTrait(asTRAIT_SHARED, true); - else if (file->TokenEquals(node->tokenPos, node->tokenLength, EXTERNAL_TOKEN)) + else if( file->TokenEquals(node->tokenPos, node->tokenLength, EXTERNAL_TOKEN) ) funcTraits.SetTrait(asTRAIT_EXTERNAL, true); else break; @@ -5012,11 +5018,11 @@ void asCBuilder::GetParsedFunctionDetails(asCScriptNode *node, asCScriptCode *fi returnType = ModifyDataTypeFromNode(returnType, node->next, file, 0, 0); if( engine->ep.disallowValueAssignForRefType && - returnType.GetTypeInfo() && - (returnType.GetTypeInfo()->flags & asOBJ_REF) && - !(returnType.GetTypeInfo()->flags & asOBJ_SCOPED) && - !returnType.IsReference() && - !returnType.IsObjectHandle() ) + returnType.GetTypeInfo() && + (returnType.GetTypeInfo()->flags & asOBJ_REF) && + !(returnType.GetTypeInfo()->flags & asOBJ_SCOPED) && + !returnType.IsReference() && + !returnType.IsObjectHandle() ) { WriteError(TXT_REF_TYPE_CANT_BE_RETURNED_BY_VAL, file, node); } @@ -5043,30 +5049,30 @@ void asCBuilder::GetParsedFunctionDetails(asCScriptNode *node, asCScriptCode *fi while( decorator && decorator->tokenType == ttIdentifier ) { - if (objType && file->TokenEquals(decorator->tokenPos, decorator->tokenLength, FINAL_TOKEN)) + if( objType && file->TokenEquals(decorator->tokenPos, decorator->tokenLength, FINAL_TOKEN) ) funcTraits.SetTrait(asTRAIT_FINAL, true); - else if (objType && file->TokenEquals(decorator->tokenPos, decorator->tokenLength, OVERRIDE_TOKEN)) + else if( objType && file->TokenEquals(decorator->tokenPos, decorator->tokenLength, OVERRIDE_TOKEN) ) funcTraits.SetTrait(asTRAIT_OVERRIDE, true); - else if (objType && file->TokenEquals(decorator->tokenPos, decorator->tokenLength, EXPLICIT_TOKEN)) + else if( objType && file->TokenEquals(decorator->tokenPos, decorator->tokenLength, EXPLICIT_TOKEN) ) funcTraits.SetTrait(asTRAIT_EXPLICIT, true); - else if (file->TokenEquals(decorator->tokenPos, decorator->tokenLength, PROPERTY_TOKEN)) + else if( file->TokenEquals(decorator->tokenPos, decorator->tokenLength, PROPERTY_TOKEN) ) funcTraits.SetTrait(asTRAIT_PROPERTY, true); - else if (file->TokenEquals(decorator->tokenPos, decorator->tokenLength, DELETE_TOKEN)) + else if( file->TokenEquals(decorator->tokenPos, decorator->tokenLength, DELETE_TOKEN) ) funcTraits.SetTrait(asTRAIT_DELETED, true); else { asCString msg(&file->code[decorator->tokenPos], decorator->tokenLength); msg.Format(TXT_UNEXPECTED_TOKEN_s, msg.AddressOf()); WriteError(msg.AddressOf(), file, decorator); - } - + } + decorator = decorator->next; } } // Count the number of parameters - int count = 0; - asCScriptNode *c = n->next->firstChild; + int count = 0; + asCScriptNode *c = n->next->firstChild; while( c ) { count++; @@ -5086,15 +5092,15 @@ void asCBuilder::GetParsedFunctionDetails(asCScriptNode *node, asCScriptCode *fi while( n ) { asETypeModifiers inOutFlag; - asCDataType type = CreateDataTypeFromNode(n, file, implicitNamespace, false, objType); - type = ModifyDataTypeFromNode(type, n->next, file, &inOutFlag, 0); + asCDataType type = CreateDataTypeFromNode(n, file, implicitNamespace, false, objType); + type = ModifyDataTypeFromNode(type, n->next, file, &inOutFlag, 0); if( engine->ep.disallowValueAssignForRefType && - type.GetTypeInfo() && - (type.GetTypeInfo()->flags & asOBJ_REF) && - !(type.GetTypeInfo()->flags & asOBJ_SCOPED) && - !type.IsReference() && - !type.IsObjectHandle() ) + type.GetTypeInfo() && + (type.GetTypeInfo()->flags & asOBJ_REF) && + !(type.GetTypeInfo()->flags & asOBJ_SCOPED) && + !type.IsReference() && + !type.IsObjectHandle() ) { WriteError(TXT_REF_TYPE_CANT_BE_PASSED_BY_VAL, file, node); } @@ -5143,13 +5149,13 @@ asCString asCBuilder::GetCleanExpressionString(asCScriptNode *node, asCScriptCod asCString cleanStr; for( asUINT n = 0; n < str.GetLength(); ) { - asUINT len = 0; + asUINT len = 0; asETokenClass tok = engine->ParseToken(str.AddressOf() + n, str.GetLength() - n, &len); // Replace comments and whitespace with a single space - if (tok == asTC_COMMENT || tok == asTC_WHITESPACE) + if( tok == asTC_COMMENT || tok == asTC_WHITESPACE ) { - if (cleanStr.GetLength() && cleanStr[cleanStr.GetLength() - 1] != ' ') + if( cleanStr.GetLength() && cleanStr[cleanStr.GetLength() - 1] != ' ' ) cleanStr += " "; } else @@ -5162,7 +5168,7 @@ asCString asCBuilder::GetCleanExpressionString(asCScriptNode *node, asCScriptCod } #ifndef AS_NO_COMPILER -int asCBuilder::RegisterScriptFunctionFromNode(asCScriptNode *node, asCScriptCode *file, asCObjectType *objType, bool isInterface, bool isGlobalFunction, asSNameSpace *ns, bool isExistingShared, bool isMixin, sClassDeclaration* decl) +int asCBuilder::RegisterScriptFunctionFromNode(asCScriptNode *node, asCScriptCode *file, asCObjectType *objType, bool isInterface, bool isGlobalFunction, asSNameSpace *ns, bool isExistingShared, bool isMixin, sClassDeclaration *decl) { asCString name; asCDataType returnType; @@ -5191,14 +5197,14 @@ int asCBuilder::RegisterScriptFunctionFromNode(asCScriptNode *node, asCScriptCod asCScriptFunction *asCBuilder::RegisterLambda(asCScriptNode *node, asCScriptCode *file, asCScriptFunction *funcDef, const asCString &name, asSNameSpace *ns, bool isShared) { // Get the parameter names from the node - asCArray parameterNames; - asCArray defaultArgs; - asCScriptNode *args = node->firstChild; + asCArray parameterNames; + asCArray defaultArgs; + asCScriptNode *args = node->firstChild; while( args && args->nodeType != snStatementBlock ) { - if (args->nodeType == snUndefined) + if( args->nodeType == snUndefined ) { - if (args->lastChild && args->lastChild->nodeType == snIdentifier) + if( args->lastChild && args->lastChild->nodeType == snIdentifier ) { asCString argName; argName.Assign(&file->code[args->lastChild->tokenPos], args->lastChild->tokenLength); @@ -5215,7 +5221,7 @@ asCScriptFunction *asCBuilder::RegisterLambda(asCScriptNode *node, asCScriptCode args->DisconnectParent(); // Get the return and parameter types from the funcDef - asCString funcName = name; + asCString funcName = name; asSFunctionTraits traits; traits.SetTrait(asTRAIT_SHARED, isShared); int r = RegisterScriptFunction(args, file, 0, 0, true, ns, false, false, funcName, funcDef->returnType, parameterNames, funcDef->parameterTypes, funcDef->inOutFlags, defaultArgs, traits, 0); @@ -5223,10 +5229,10 @@ asCScriptFunction *asCBuilder::RegisterLambda(asCScriptNode *node, asCScriptCode return 0; // Return the function that was just created (but that will be compiled later) - return engine->scriptFunctions[functions[functions.GetLength()-1]->funcId]; + return engine->scriptFunctions[functions[functions.GetLength() - 1]->funcId]; } -int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, asCObjectType *objType, bool isInterface, bool isGlobalFunction, asSNameSpace *ns, bool isExistingShared, bool isMixin, asCString &name, asCDataType &returnType, asCArray ¶meterNames, asCArray ¶meterTypes, asCArray &inOutFlags, asCArray &defaultArgs, asSFunctionTraits funcTraits, sClassDeclaration* classDecl) +int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, asCObjectType *objType, bool isInterface, bool isGlobalFunction, asSNameSpace *ns, bool isExistingShared, bool isMixin, asCString &name, asCDataType &returnType, asCArray ¶meterNames, asCArray ¶meterTypes, asCArray &inOutFlags, asCArray &defaultArgs, asSFunctionTraits funcTraits, sClassDeclaration *classDecl) { // Determine default namespace if not specified if( ns == 0 ) @@ -5243,7 +5249,7 @@ int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, // Should validate that the function really exists in the class/interface bool found = false; - if(funcTraits.GetTrait(asTRAIT_CONSTRUCTOR) || funcTraits.GetTrait(asTRAIT_DESTRUCTOR) ) + if( funcTraits.GetTrait(asTRAIT_CONSTRUCTOR) || funcTraits.GetTrait(asTRAIT_DESTRUCTOR) ) { // TODO: shared: Should check the existance of these too found = true; @@ -5254,7 +5260,7 @@ int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, { asCScriptFunction *func = engine->scriptFunctions[objType->methods[n]]; if( func->name == name && - func->IsSignatureExceptNameEqual(returnType, parameterTypes, inOutFlags, objType, funcTraits.GetTrait(asTRAIT_CONST), funcTraits.GetTrait(asTRAIT_VARIADIC)) ) + func->IsSignatureExceptNameEqual(returnType, parameterTypes, inOutFlags, objType, funcTraits.GetTrait(asTRAIT_CONST), funcTraits.GetTrait(asTRAIT_VARIADIC)) ) { // Add the shared function in this module too module->AddScriptFunction(func); @@ -5314,14 +5320,14 @@ int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, if( name != objType->name ) { asCString str; - if(funcTraits.GetTrait(asTRAIT_DESTRUCTOR) ) + if( funcTraits.GetTrait(asTRAIT_DESTRUCTOR) ) str.Format(TXT_DESTRUCTOR_s_s_NAME_ERROR, objType->name.AddressOf(), name.AddressOf()); else str.Format(TXT_METHOD_s_s_HAS_NO_RETURN_TYPE, objType->name.AddressOf(), name.AddressOf()); WriteError(str, file, node); } - if(funcTraits.GetTrait(asTRAIT_DESTRUCTOR)) + if( funcTraits.GetTrait(asTRAIT_DESTRUCTOR) ) name = "~" + name; } @@ -5329,15 +5335,15 @@ int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, if( funcTraits.GetTrait(asTRAIT_PROPERTY) ) { asCScriptFunction func(engine, module, asFUNC_SCRIPT); - func.name = name; - func.nameSpace = ns; - func.objectType = objType; + func.name = name; + func.nameSpace = ns; + func.objectType = objType; if( objType ) objType->AddRefInternal(); func.traits = funcTraits; func.returnType = returnType; func.parameterTypes = parameterTypes; - + int r = ValidateVirtualProperty(&func); if( r < 0 ) { @@ -5350,46 +5356,46 @@ int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, str.Format(TXT_NAME_CONFLICT_s_ALREADY_USED, name.SubString(4).AddressOf()); WriteError(str, file, node); } - + // Set the type as dummy so the clean-up works correctly func.funcType = asFUNC_DUMMY; } - + // If the method is deleted, then don't register it - if (funcTraits.GetTrait(asTRAIT_DELETED)) + if( funcTraits.GetTrait(asTRAIT_DELETED) ) { // Delete can only be used for default constructor, default copy constructor, and default copy operator - if (classDecl && funcTraits.GetTrait(asTRAIT_CONSTRUCTOR) && parameterTypes.GetLength() == 0) + if( classDecl && funcTraits.GetTrait(asTRAIT_CONSTRUCTOR) && parameterTypes.GetLength() == 0 ) { classDecl->isDefaultConstructorDeleted = true; - if (objType->beh.construct && objType->beh.construct != engine->scriptTypeBehaviours.beh.construct) + if( objType->beh.construct && objType->beh.construct != engine->scriptTypeBehaviours.beh.construct ) WriteError(TXT_CANNOT_DEFINE_FUNC_THAT_IS_DELETED, file, node); } - else if (classDecl && funcTraits.GetTrait(asTRAIT_CONSTRUCTOR) && parameterTypes.GetLength() == 1 && parameterTypes[0].GetTypeInfo() == objType) + else if( classDecl && funcTraits.GetTrait(asTRAIT_CONSTRUCTOR) && parameterTypes.GetLength() == 1 && parameterTypes[0].GetTypeInfo() == objType ) { classDecl->isDefaultCopyConstructorDeleted = true; - if (objType->beh.copyconstruct) + if( objType->beh.copyconstruct ) WriteError(TXT_CANNOT_DEFINE_FUNC_THAT_IS_DELETED, file, node); } - else if (classDecl && name == "opAssign" && parameterTypes.GetLength() == 1 && parameterTypes[0].GetTypeInfo() == objType) + else if( classDecl && name == "opAssign" && parameterTypes.GetLength() == 1 && parameterTypes[0].GetTypeInfo() == objType ) { classDecl->isDefaultCopyDeleted = true; - if (objType->beh.copy && objType->beh.copy != engine->scriptTypeBehaviours.beh.copy) + if( objType->beh.copy && objType->beh.copy != engine->scriptTypeBehaviours.beh.copy ) WriteError(TXT_CANNOT_DEFINE_FUNC_THAT_IS_DELETED, file, node); } else WriteError(TXT_CANNOT_DELETE_NON_AUTO_FUNC, file, node); // Deleted functions must not have implementation - if (node && node->lastChild && node->lastChild->nodeType == snStatementBlock) + if( node && node->lastChild && node->lastChild->nodeType == snStatementBlock ) WriteError(TXT_DELETED_FUNC_CANT_HAVE_IMPL, file, node); // Free the default args - for (asUINT n = 0; n < defaultArgs.GetLength(); n++) - if (defaultArgs[n]) + for( asUINT n = 0; n < defaultArgs.GetLength(); n++ ) + if( defaultArgs[n] ) asDELETE(defaultArgs[n], asCString); node->Destroy(engine); @@ -5398,7 +5404,7 @@ int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, } isExistingShared = false; - int funcId = engine->GetNextScriptFunctionId(); + int funcId = engine->GetNextScriptFunctionId(); if( !isInterface ) { sFunctionDescription *func = asNEW(sFunctionDescription); @@ -5414,26 +5420,26 @@ int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, functions.PushLast(func); - func->script = file; - func->node = node; - func->name = name; - func->objType = objType; - func->funcId = funcId; - func->isExistingShared = false; - func->paramNames = parameterNames; + func->script = file; + func->node = node; + func->name = name; + func->objType = objType; + func->funcId = funcId; + func->isExistingShared = false; + func->paramNames = parameterNames; - if(funcTraits.GetTrait(asTRAIT_SHARED)) + if( funcTraits.GetTrait(asTRAIT_SHARED) ) { // Look for a pre-existing shared function with the same signature for( asUINT n = 0; n < engine->scriptFunctions.GetLength(); n++ ) { asCScriptFunction *f = engine->scriptFunctions[n]; if( f && - f->IsShared() && - f->name == name && - f->nameSpace == ns && - f->objectType == objType && - f->IsSignatureExceptNameEqual(returnType, parameterTypes, inOutFlags, 0, false, funcTraits.GetTrait(asTRAIT_VARIADIC)) ) + f->IsShared() && + f->name == name && + f->nameSpace == ns && + f->objectType == objType && + f->IsSignatureExceptNameEqual(returnType, parameterTypes, inOutFlags, 0, false, funcTraits.GetTrait(asTRAIT_VARIADIC)) ) { funcId = func->funcId = f->id; isExistingShared = func->isExistingShared = true; @@ -5443,10 +5449,10 @@ int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, } // Remember if the function was declared as external so the saved bytecode can be flagged accordingly - if (funcTraits.GetTrait(asTRAIT_EXTERNAL) && func->isExistingShared) + if( funcTraits.GetTrait(asTRAIT_EXTERNAL) && func->isExistingShared ) module->m_externalFunctions.PushLast(engine->scriptFunctions[func->funcId]); - if (funcTraits.GetTrait(asTRAIT_EXTERNAL) && !func->isExistingShared) + if( funcTraits.GetTrait(asTRAIT_EXTERNAL) && !func->isExistingShared ) { // Mark it as existing shared to avoid compiling it func->isExistingShared = true; @@ -5457,13 +5463,13 @@ int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, } // External shared function must not try to redefine the interface - if (funcTraits.GetTrait(asTRAIT_EXTERNAL) && !(node == 0 || node->tokenType == ttEndStatement || (node->lastChild && node->lastChild->tokenType == ttEndStatement))) + if( funcTraits.GetTrait(asTRAIT_EXTERNAL) && !(node == 0 || node->tokenType == ttEndStatement || (node->lastChild && node->lastChild->tokenType == ttEndStatement)) ) { asCString str; str.Format(TXT_EXTERNAL_SHARED_s_CANNOT_REDEF, name.AddressOf()); WriteError(str, file, node); } - else if (!funcTraits.GetTrait(asTRAIT_EXTERNAL) && (node == 0 || !(node->nodeType == snStatementBlock || (node->lastChild && node->lastChild->nodeType == snStatementBlock))) ) + else if( !funcTraits.GetTrait(asTRAIT_EXTERNAL) && (node == 0 || !(node->nodeType == snStatementBlock || (node->lastChild && node->lastChild->nodeType == snStatementBlock))) ) { asCString str; str.Format(TXT_MISSING_DEFINITION_OF_s, name.AddressOf()); @@ -5472,11 +5478,11 @@ int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, } // Destructors may not have any parameters - if (funcTraits.GetTrait(asTRAIT_DESTRUCTOR) && parameterTypes.GetLength() > 0) + if( funcTraits.GetTrait(asTRAIT_DESTRUCTOR) && parameterTypes.GetLength() > 0 ) WriteError(TXT_DESTRUCTOR_MAY_NOT_HAVE_PARM, file, node); // If a function, class, or interface is shared then only shared types may be used in the signature - if( (objType && objType->IsShared()) || funcTraits.GetTrait(asTRAIT_SHARED)) + if( (objType && objType->IsShared()) || funcTraits.GetTrait(asTRAIT_SHARED) ) { asCTypeInfo *ti = returnType.GetTypeInfo(); if( ti && !ti->IsShared() ) @@ -5582,7 +5588,7 @@ int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, int row = 0, col = 0; if( node ) file->ConvertPosToRowCol(node->tokenPos, &row, &col); - module->AddScriptFunction(file->idx, (row&0xFFFFF)|((col&0xFFF)<<20), funcId, name, returnType, parameterTypes, parameterNames, inOutFlags, defaultArgs, isInterface, objType, isGlobalFunction, funcTraits, ns); + module->AddScriptFunction(file->idx, (row & 0xFFFFF) | ((col & 0xFFF) << 20), funcId, name, returnType, parameterTypes, parameterNames, inOutFlags, defaultArgs, isInterface, objType, isGlobalFunction, funcTraits, ns); } // Make sure the default args are declared correctly @@ -5594,19 +5600,19 @@ int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, asASSERT( !isExistingShared ); engine->scriptFunctions[funcId]->AddRefInternal(); - if(funcTraits.GetTrait(asTRAIT_CONSTRUCTOR)) + if( funcTraits.GetTrait(asTRAIT_CONSTRUCTOR) ) { int factoryId = engine->GetNextScriptFunctionId(); if( parameterTypes.GetLength() == 0 ) { // Overload the default constructor engine->scriptFunctions[objType->beh.construct]->ReleaseInternal(); - objType->beh.construct = funcId; + objType->beh.construct = funcId; objType->beh.constructors[0] = funcId; // Register the default factory as well engine->scriptFunctions[objType->beh.factory]->ReleaseInternal(); - objType->beh.factory = factoryId; + objType->beh.factory = factoryId; objType->beh.factories[0] = factoryId; if( classDecl->isDefaultConstructorDeleted ) @@ -5615,9 +5621,9 @@ int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, else { // The copy constructor needs to be marked for easy finding - if( parameterTypes.GetLength() == 1 && - parameterTypes[0].GetTypeInfo() == objType && - (parameterTypes[0].IsReference() || parameterTypes[0].IsObjectHandle()) ) + if( parameterTypes.GetLength() == 1 && + parameterTypes[0].GetTypeInfo() == objType && + (parameterTypes[0].IsReference() || parameterTypes[0].IsObjectHandle()) ) { // Verify that there are not multiple options matching the copy constructor // TODO: Need a better message, since the parameters can be slightly different, e.g. & vs @ @@ -5625,9 +5631,9 @@ int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, WriteError(TXT_FUNCTION_ALREADY_EXIST, file, node); objType->beh.copyconstruct = funcId; - objType->beh.copyfactory = factoryId; + objType->beh.copyfactory = factoryId; - if (classDecl->isDefaultCopyConstructorDeleted) + if( classDecl->isDefaultCopyConstructorDeleted ) WriteError(TXT_CANNOT_DEFINE_FUNC_THAT_IS_DELETED, file, node); } @@ -5658,21 +5664,21 @@ int asCBuilder::RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, compiler.CompileFactory(this, file, engine->scriptFunctions[factoryId]); engine->scriptFunctions[factoryId]->AddRefInternal(); } - else if(funcTraits.GetTrait(asTRAIT_DESTRUCTOR)) + else if( funcTraits.GetTrait(asTRAIT_DESTRUCTOR) ) objType->beh.destruct = funcId; else { // If the method is the assignment operator we need to replace the default implementation asCScriptFunction *f = engine->scriptFunctions[funcId]; if( f->name == "opAssign" && f->parameterTypes.GetLength() == 1 && - f->parameterTypes[0].GetTypeInfo() == f->objectType && - (f->inOutFlags[0] & asTM_INREF) ) + f->parameterTypes[0].GetTypeInfo() == f->objectType && + (f->inOutFlags[0] & asTM_INREF) ) { engine->scriptFunctions[objType->beh.copy]->ReleaseInternal(); objType->beh.copy = funcId; f->AddRefInternal(); - if (classDecl->isDefaultCopyDeleted) + if( classDecl->isDefaultCopyDeleted ) WriteError(TXT_CANNOT_DEFINE_FUNC_THAT_IS_DELETED, file, node); } @@ -5706,77 +5712,78 @@ int asCBuilder::RegisterVirtualProperty(asCScriptNode *node, asCScriptCode *file ns = engine->nameSpaces[0]; } - bool isPrivate = false, isProtected = false; - asCString emulatedName; + bool isPrivate = false, isProtected = false; + asCString emulatedName; asCDataType emulatedType; asCScriptNode *mainNode = node; - node = node->firstChild; + node = node->firstChild; if( !isGlobalFunction && node->tokenType == ttPrivate ) { isPrivate = true; - node = node->next; + node = node->next; } else if( !isGlobalFunction && node->tokenType == ttProtected ) { isProtected = true; - node = node->next; + node = node->next; } emulatedType = CreateDataTypeFromNode(node, file, ns); emulatedType = ModifyDataTypeFromNode(emulatedType, node->next, file, 0, 0); - node = node->next->next; + node = node->next->next; emulatedName.Assign(&file->code[node->tokenPos], node->tokenLength); if( node->next == 0 ) WriteError(TXT_PROPERTY_WITHOUT_ACCESSOR, file, node); node = node->next; - while (node) + while( node ) { - asCScriptNode *next = node->next; + asCScriptNode *next = node->next; asCScriptNode *funcNode = 0; - bool success = false; + bool success = false; asSFunctionTraits funcTraits; asCDataType returnType; asCArray paramNames; asCArray paramTypes; asCArray paramModifiers; - asCArray defaultArgs; + asCArray defaultArgs; asCString name; funcTraits.SetTrait(asTRAIT_PRIVATE, isPrivate); funcTraits.SetTrait(asTRAIT_PROTECTED, isProtected); funcTraits.SetTrait(asTRAIT_PROPERTY, true); - if (node->firstChild->nodeType == snIdentifier && file->TokenEquals(node->firstChild->tokenPos, node->firstChild->tokenLength, GET_TOKEN)) + if( node->firstChild->nodeType == snIdentifier && file->TokenEquals(node->firstChild->tokenPos, node->firstChild->tokenLength, GET_TOKEN) ) name = "get_"; - else if (node->firstChild->nodeType == snIdentifier && file->TokenEquals(node->firstChild->tokenPos, node->firstChild->tokenLength, SET_TOKEN)) + else if( node->firstChild->nodeType == snIdentifier && file->TokenEquals(node->firstChild->tokenPos, node->firstChild->tokenLength, SET_TOKEN) ) name = "set_"; else WriteError(TXT_UNRECOGNIZED_VIRTUAL_PROPERTY_NODE, file, node); - if (name != "") + if( name != "" ) { - success = true; + success = true; funcNode = node->firstChild->next; - if (funcNode && funcNode->tokenType == ttConst) + if( funcNode && funcNode->tokenType == ttConst ) { funcTraits.SetTrait(asTRAIT_CONST, true); funcNode = funcNode->next; } - while (funcNode && (funcNode->nodeType != snStatementBlock && funcNode->tokenType != ttEndStatement)) + while( funcNode && (funcNode->nodeType != snStatementBlock && funcNode->tokenType != ttEndStatement) ) { - if (funcNode->tokenType == ttIdentifier && file->TokenEquals(funcNode->tokenPos, funcNode->tokenLength, FINAL_TOKEN)) + if( funcNode->tokenType == ttIdentifier && file->TokenEquals(funcNode->tokenPos, funcNode->tokenLength, FINAL_TOKEN) ) funcTraits.SetTrait(asTRAIT_FINAL, true); - else if (funcNode->tokenType == ttIdentifier && file->TokenEquals(funcNode->tokenPos, funcNode->tokenLength, OVERRIDE_TOKEN)) + else if( funcNode->tokenType == ttIdentifier && file->TokenEquals(funcNode->tokenPos, funcNode->tokenLength, OVERRIDE_TOKEN) ) funcTraits.SetTrait(asTRAIT_OVERRIDE, true); else { - asCString msg(&file->code[funcNode->tokenPos], funcNode->tokenLength);; + asCString msg(&file->code[funcNode->tokenPos], funcNode->tokenLength); + ; msg.Format(TXT_UNEXPECTED_TOKEN_s, msg.AddressOf()); WriteError(msg.AddressOf(), file, node); } @@ -5784,10 +5791,10 @@ int asCBuilder::RegisterVirtualProperty(asCScriptNode *node, asCScriptCode *file funcNode = funcNode->next; } - if (funcNode) + if( funcNode ) funcNode->DisconnectParent(); - if ((funcNode == 0 || funcNode->nodeType != snStatementBlock) && (objType == 0 || !objType->IsInterface())) + if( (funcNode == 0 || funcNode->nodeType != snStatementBlock) && (objType == 0 || !objType->IsInterface()) ) { // TODO: getset: If no implementation is supplied the builder should provide an automatically generated implementation // The compiler needs to be able to handle the different types, primitive, value type, and handle @@ -5795,13 +5802,13 @@ int asCBuilder::RegisterVirtualProperty(asCScriptNode *node, asCScriptCode *file WriteError(TXT_PROPERTY_ACCESSOR_MUST_BE_IMPLEMENTED, file, node); } - if (name == "get_") + if( name == "get_" ) { // Setup the signature for the get accessor method returnType = emulatedType; - name = "get_" + emulatedName; + name = "get_" + emulatedName; } - else if (name == "set_") + else if( name == "set_" ) { // Setup the signature for the set accessor method returnType = asCDataType::CreatePrimitive(ttVoid, false); @@ -5811,15 +5818,15 @@ int asCBuilder::RegisterVirtualProperty(asCScriptNode *node, asCScriptCode *file defaultArgs.PushLast(0); name = "set_" + emulatedName; - if (emulatedType.IsReference()) + if( emulatedType.IsReference() ) { paramModifiers[0] = asTM_INOUTREF; - if (!engine->ep.allowUnsafeReferences ) + if( !engine->ep.allowUnsafeReferences ) { // Verify that the base type support &inout parameter types - if (!emulatedType.IsObject() || emulatedType.IsObjectHandle() || - !((emulatedType.GetTypeInfo()->flags & asOBJ_NOCOUNT) || (CastToObjectType(emulatedType.GetTypeInfo())->beh.addref && CastToObjectType(emulatedType.GetTypeInfo())->beh.release))) + if( !emulatedType.IsObject() || emulatedType.IsObjectHandle() || + !((emulatedType.GetTypeInfo()->flags & asOBJ_NOCOUNT) || (CastToObjectType(emulatedType.GetTypeInfo())->beh.addref && CastToObjectType(emulatedType.GetTypeInfo())->beh.release)) ) WriteError(TXT_ONLY_OBJECTS_MAY_USE_REF_INOUT, file, node->firstChild); } } @@ -5841,7 +5848,7 @@ int asCBuilder::RegisterVirtualProperty(asCScriptNode *node, asCScriptCode *file { asCScriptFunction *func = engine->scriptFunctions[objType->methods[n]]; if( func->name == name && - func->IsSignatureExceptNameEqual(returnType, paramTypes, paramModifiers, objType, funcTraits.GetTrait(asTRAIT_CONST), funcTraits.GetTrait(asTRAIT_VARIADIC)) ) + func->IsSignatureExceptNameEqual(returnType, paramTypes, paramModifiers, objType, funcTraits.GetTrait(asTRAIT_CONST), funcTraits.GetTrait(asTRAIT_VARIADIC)) ) { found = true; break; @@ -5895,14 +5902,14 @@ int asCBuilder::RegisterImportedFunction(int importID, asCScriptNode *node, asCS } // Check for invalid function traits - if (funcTraits.GetTrait(asTRAIT_DELETED)) + if( funcTraits.GetTrait(asTRAIT_DELETED) ) WriteError(TXT_CANNOT_DELETE_NON_AUTO_FUNC, file, node); // Read the module name as well asCScriptNode *nd = node->lastChild; asASSERT( nd->nodeType == snConstant && nd->tokenType == ttStringConstant ); asCString moduleName; - moduleName.Assign(&file->code[nd->tokenPos+1], nd->tokenLength-2); + moduleName.Assign(&file->code[nd->tokenPos + 1], nd->tokenLength - 2); node->Destroy(engine); @@ -5940,7 +5947,7 @@ void asCBuilder::GetFunctionDescriptions(const char *name, asCArray &funcs, for( n = 0; n < module->m_bindInformations.GetLength(); n++ ) { if( module->m_bindInformations[n]->importedFunctionSignature->name == name && - module->m_bindInformations[n]->importedFunctionSignature->nameSpace == ns ) + module->m_bindInformations[n]->importedFunctionSignature->nameSpace == ns ) funcs.PushLast(module->m_bindInformations[n]->importedFunctionSignature->id); } @@ -5970,31 +5977,31 @@ void asCBuilder::GetObjectMethodDescriptions(const char *name, asCObjectType *ob // If the scope contains ::identifier, then use the last identifier as the class name and the rest of it as the namespace // TODO: child funcdef: A scope can include a template type, e.g. array - int n = scope.FindLast("::"); - asCString className = n >= 0 ? scope.SubString(n+2) : scope; - asCString nsName = n >= 0 ? scope.SubString(0, n) : asCString(""); + int n = scope.FindLast("::"); + asCString className = n >= 0 ? scope.SubString(n + 2) : scope; + asCString nsName = n >= 0 ? scope.SubString(0, n) : asCString(""); // If a namespace was specifically defined, then this must be used asSNameSpace *ns = 0; - if (n >= 0) + if( n >= 0 ) { - if (nsName == "") + if( nsName == "" ) ns = engine->nameSpaces[0]; else ns = GetNameSpaceByString(nsName, objectType->nameSpace, errNode, script, 0, false); // If the namespace isn't found return silently and let the calling // function report the error if it cannot resolve the symbol - if (ns == 0) + if( ns == 0 ) return; } // Find the base class with the specified scope - while (objectType) + while( objectType ) { // If the name and namespace matches it is the correct class. If no // specific namespace was given, then don't compare the namespace - if (objectType->name == className && (ns == 0 || objectType->nameSpace == ns)) + if( objectType->name == className && (ns == 0 || objectType->nameSpace == ns) ) break; objectType = objectType->derivedFrom; @@ -6011,8 +6018,8 @@ void asCBuilder::GetObjectMethodDescriptions(const char *name, asCObjectType *ob { asCScriptFunction *func = engine->scriptFunctions[objectType->methods[n]]; if( func->name == name && - (!objIsConst || func->IsReadOnly()) && - (func->accessMask & module->m_accessMask) ) + (!objIsConst || func->IsReadOnly()) && + (func->accessMask & module->m_accessMask) ) { // When the scope is defined the returned methods should be the true methods, not the virtual method stubs if( scope == "" ) @@ -6098,19 +6105,19 @@ void asCBuilder::WriteWarning(const asCString &message, asCScriptCode *file, asC // TODO: child funcdef: Should try to eliminate this function. GetNameSpaceFromNode is more complete asCString asCBuilder::GetScopeFromNode(asCScriptNode *node, asCScriptCode *script, asCScriptNode **next) { - if (node->nodeType != snScope) + if( node->nodeType != snScope ) { - if (next) + if( next ) *next = node; return ""; } - asCString scope; + asCString scope; asCScriptNode *sn = node->firstChild; if( sn->tokenType == ttScope ) { scope = "::"; - sn = sn->next; + sn = sn->next; } // TODO: child funcdef: A scope can have a template type as the innermost @@ -6121,7 +6128,7 @@ asCString asCBuilder::GetScopeFromNode(asCScriptNode *node, asCScriptCode *scrip if( scope != "" && scope != "::" ) scope += "::"; scope += tmp; - sn = sn->next->next; + sn = sn->next->next; } if( next ) @@ -6130,49 +6137,49 @@ asCString asCBuilder::GetScopeFromNode(asCScriptNode *node, asCScriptCode *scrip return scope; } -bool asCBuilder::FindObjectTypeOrMixinInNsHierarchy(const asCString& name, asSNameSpace* startNs, bool isExplicitNs, asCScriptNode *errNode, asCScriptCode *script, asCObjectType **outObjType, sMixinClass **outMixin) +bool asCBuilder::FindObjectTypeOrMixinInNsHierarchy(const asCString &name, asSNameSpace *startNs, bool isExplicitNs, asCScriptNode *errNode, asCScriptCode *script, asCObjectType **outObjType, sMixinClass **outMixin) { - if (outObjType) *outObjType = 0; - if (outMixin) *outMixin = 0; + if( outObjType ) *outObjType = 0; + if( outMixin ) *outMixin = 0; - asSNameSpace* ns = startNs; + asSNameSpace *ns = startNs; // If not explicit scope, then search the visible namespaces, then search the parent namespaces - asCArray pendingNamespaces; - asCArray visitedNamespaces; - bool checkAmbiguousSymbols = !isExplicitNs; - asSNameSpace* parentNs = engine->GetParentNameSpace(ns); + asCArray pendingNamespaces; + asCArray visitedNamespaces; + bool checkAmbiguousSymbols = !isExplicitNs; + asSNameSpace *parentNs = engine->GetParentNameSpace(ns); - asCObjectType* objType = 0; - sMixinClass* mixin = 0; - while (ns) + asCObjectType *objType = 0; + sMixinClass *mixin = 0; + while( ns ) { - if (!visitedNamespaces.Exists(ns)) + if( !visitedNamespaces.Exists(ns) ) { visitedNamespaces.PushLast(ns); - if (!checkAmbiguousSymbols) + if( !checkAmbiguousSymbols ) { objType = GetObjectType(name.AddressOf(), ns); #ifndef AS_NO_COMPILER - if (objType == 0 && outMixin) + if( objType == 0 && outMixin ) mixin = GetMixinClass(name.AddressOf(), ns); #endif - if (objType || mixin) + if( objType || mixin ) break; } else { - asCObjectType* ot = GetObjectType(name.AddressOf(), ns); - sMixinClass* m = 0; + asCObjectType *ot = GetObjectType(name.AddressOf(), ns); + sMixinClass *m = 0; #ifndef AS_NO_COMPILER - if (ot == 0 && outMixin) + if( ot == 0 && outMixin ) m = GetMixinClass(name.AddressOf(), ns); #endif - if (ot || m) + if( ot || m ) { - if (objType || mixin) + if( objType || mixin ) { asCString msg; msg.Format(TXT_AMBIGUOUS_SYMBOL_NAME_s, name.AddressOf()); @@ -6181,67 +6188,67 @@ bool asCBuilder::FindObjectTypeOrMixinInNsHierarchy(const asCString& name, asSNa } objType = ot; - mixin = m; + mixin = m; } } } AddVisibleNamespaces(ns, visitedNamespaces, pendingNamespaces); ns = FindNextVisibleNamespace(visitedNamespaces, pendingNamespaces, parentNs, &checkAmbiguousSymbols); - if (ns == parentNs) + if( ns == parentNs ) { // Only move to the parent namespace if the object type hasn't been found yet - if (objType || mixin) + if( objType || mixin ) break; parentNs = engine->GetParentNameSpace(ns); } } - if (outObjType) *outObjType = objType; - if (outMixin) *outMixin = mixin; + if( outObjType ) *outObjType = objType; + if( outMixin ) *outMixin = mixin; return true; } asSNameSpace *asCBuilder::GetNameSpaceFromNode(asCScriptNode *node, asCScriptCode *script, asSNameSpace *implicitNs, asCScriptNode **next, asCObjectType **objType, bool *isExplicitNs) { - if (objType) + if( objType ) *objType = 0; // If no scope has been informed, then return the implicit namespace - if (node->nodeType != snScope) + if( node->nodeType != snScope ) { - if (next) + if( next ) *next = node; - if (isExplicitNs) + if( isExplicitNs ) *isExplicitNs = false; return implicitNs ? implicitNs : engine->nameSpaces[0]; } - if (isExplicitNs) + if( isExplicitNs ) *isExplicitNs = true; - if (next) + if( next ) *next = node->next; - asCString scope; + asCString scope; asCScriptNode *sn = node->firstChild; - if (sn && sn->tokenType == ttScope) + if( sn && sn->tokenType == ttScope ) { scope = "::"; - sn = sn->next; + sn = sn->next; } - while (sn) + while( sn ) { - if (sn->next->tokenType == ttScope) + if( sn->next->tokenType == ttScope ) { asCString tmp; tmp.Assign(&script->code[sn->tokenPos], sn->tokenLength); - if (scope != "" && scope != "::") + if( scope != "" && scope != "::" ) scope += "::"; scope += tmp; - sn = sn->next->next; + sn = sn->next->next; } else { @@ -6249,21 +6256,21 @@ asSNameSpace *asCBuilder::GetNameSpaceFromNode(asCScriptNode *node, asCScriptCod asASSERT(sn->next->nodeType == snDataType); asSNameSpace *ns = implicitNs; - if (scope != "") + if( scope != "" ) ns = engine->FindNameSpace(scope.AddressOf()); asCString templateName(&script->code[sn->tokenPos], sn->tokenLength); - asCObjectType* templateType = 0; - bool ok = FindObjectTypeOrMixinInNsHierarchy(templateName, ns, scope != "", sn->next, script, &templateType, 0); + asCObjectType *templateType = 0; + bool ok = FindObjectTypeOrMixinInNsHierarchy(templateName, ns, scope != "", sn->next, script, &templateType, 0); - if (!ok || templateType == 0 || (templateType->flags & asOBJ_TEMPLATE) == 0) + if( !ok || templateType == 0 || (templateType->flags & asOBJ_TEMPLATE) == 0 ) { // TODO: child funcdef: Report error return ns; } - if (objType) + if( objType ) *objType = GetTemplateInstanceFromNode(sn, script, templateType, implicitNs, 0); // Return no namespace, since this is an object type @@ -6273,17 +6280,17 @@ asSNameSpace *asCBuilder::GetNameSpaceFromNode(asCScriptNode *node, asCScriptCod // If the scope doesn't start with '::' then prepend the implicit scope to give the full scope asCString originalScope = scope; - if (scope.SubString(0, 2) != "::" && implicitNs && implicitNs->name.GetLength() > 0 ) + if( scope.SubString(0, 2) != "::" && implicitNs && implicitNs->name.GetLength() > 0 ) scope = implicitNs->name + "::" + scope; - asCTypeInfo *ti = 0; + asCTypeInfo *ti = 0; asSNameSpace *ns = GetNameSpaceByString(scope, implicitNs ? implicitNs : engine->nameSpaces[0], node, script, &ti, scope == originalScope); // If the namespace wasn't found try again with the original scope as it may be a fully identified scope - if (scope != originalScope && ns == 0) + if( scope != originalScope && ns == 0 ) ns = GetNameSpaceByString(originalScope, implicitNs ? implicitNs : engine->nameSpaces[0], node, script, &ti, true); - if (ti && objType) + if( ti && objType ) *objType = CastToObjectType(ti); return ns; @@ -6300,15 +6307,15 @@ asSNameSpace *asCBuilder::GetNameSpaceByString(const asCString &nsName, asSNameS else if( nsName != "" ) { ns = engine->FindNameSpace(nsName.AddressOf()); - if (ns == 0 && scopeType) + if( ns == 0 && scopeType ) { asCString typeName; asCString searchNs; // Split the scope with at the inner most :: - int pos = nsName.FindLast("::"); + int pos = nsName.FindLast("::"); bool recursive = false; - if (pos >= 0) + if( pos >= 0 ) { // Fully qualified namespace typeName = nsName.SubString(pos + 2); @@ -6317,18 +6324,18 @@ asSNameSpace *asCBuilder::GetNameSpaceByString(const asCString &nsName, asSNameS else { // Partially qualified, use the implicit namespace and then search recursively for the type - typeName = nsName; - searchNs = implicitNs->name; + typeName = nsName; + searchNs = implicitNs->name; recursive = true; } asSNameSpace *nsTmp = searchNs == "::" ? engine->nameSpaces[0] : engine->FindNameSpace(searchNs.AddressOf()); - asCTypeInfo *ti = 0; + asCTypeInfo *ti = 0; while( !ti && nsTmp ) { // Check if the typeName is an existing type in the namespace ti = GetType(typeName.AddressOf(), nsTmp, 0); - if (ti) + if( ti ) { // The informed scope is not a namespace, but it does match a type *scopeType = ti; @@ -6338,7 +6345,7 @@ asSNameSpace *asCBuilder::GetNameSpaceByString(const asCString &nsName, asSNameS } } - if (ns == 0 && isRequired) + if( ns == 0 && isRequired ) { asCString msg; msg.Format(TXT_NAMESPACE_s_DOESNT_EXIST, nsName.AddressOf()); @@ -6349,7 +6356,7 @@ asSNameSpace *asCBuilder::GetNameSpaceByString(const asCString &nsName, asSNameS return ns; } -asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCode *file, asSNameSpace *implicitNamespace, bool acceptHandleForScope, asCObjectType *currentType, bool reportError, bool *isValid, asCArray *templSubTypes, asCArray* scopeVisibleNamespaces) +asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCode *file, asSNameSpace *implicitNamespace, bool acceptHandleForScope, asCObjectType *currentType, bool reportError, bool *isValid, asCArray *templSubTypes, asCArray *scopeVisibleNamespaces) { asASSERT(node->nodeType == snDataType || node->nodeType == snIdentifier || node->nodeType == snScope ); @@ -6357,30 +6364,30 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod asCScriptNode *n = node->firstChild; - if (isValid) + if( isValid ) *isValid = true; // If the informed node is an identifier or scope, then the // datatype should be identified directly from that - if (node->nodeType != snDataType) + if( node->nodeType != snDataType ) n = node; - bool isConst = false; + bool isConst = false; bool isImplicitHandle = false; if( n->tokenType == ttConst ) { isConst = true; - n = n->next; + n = n->next; } // Determine namespace (or parent type) to search for the data type in asCObjectType *parentType = 0; - asSNameSpace *ns = GetNameSpaceFromNode(n, file, implicitNamespace, &n, &parentType); + asSNameSpace *ns = GetNameSpaceFromNode(n, file, implicitNamespace, &n, &parentType); if( ns == 0 && parentType == 0 ) { // The namespace and parent type doesn't exist. Return a dummy type instead. dt = asCDataType::CreatePrimitive(ttInt, false); - if (isValid) + if( isValid ) *isValid = false; return dt; } @@ -6393,49 +6400,49 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod str.Assign(&file->code[n->tokenPos], n->tokenLength); // Recursively search parent namespaces for matching type - asSNameSpace *origNs = ns; - asCObjectType *origParentType = parentType; - asCArray pendingNamespaces; - asCArray visitedNamespaces; - bool checkAmbiguousSymbols = ns == engine->nameSpaces[0]; + asSNameSpace *origNs = ns; + asCObjectType *origParentType = parentType; + asCArray pendingNamespaces; + asCArray visitedNamespaces; + bool checkAmbiguousSymbols = ns == engine->nameSpaces[0]; - if (scopeVisibleNamespaces) + if( scopeVisibleNamespaces ) { pendingNamespaces = *scopeVisibleNamespaces; } - asSNameSpace* parentNs = engine->GetParentNameSpace(ns); - while( (ns || parentType) && (!found || checkAmbiguousSymbols)) + asSNameSpace *parentNs = engine->GetParentNameSpace(ns); + while( (ns || parentType) && (!found || checkAmbiguousSymbols) ) { - if (!visitedNamespaces.Exists(ns) || parentType) + if( !visitedNamespaces.Exists(ns) || parentType ) { visitedNamespaces.PushLast(ns); - asCTypeInfo* ti = 0; - bool canContinue = true; + asCTypeInfo *ti = 0; + bool canContinue = true; - if (templSubTypes) + if( templSubTypes ) { // If a list of templSubTypes is provided then first check if the identifier matches any of them - for (asUINT subtypeIndex = 0; subtypeIndex < templSubTypes->GetLength(); subtypeIndex++) + for( asUINT subtypeIndex = 0; subtypeIndex < templSubTypes->GetLength(); subtypeIndex++ ) { - asCTypeInfo* type = ((*templSubTypes)[subtypeIndex]).GetTypeInfo(); - if (type && str == type->name) + asCTypeInfo *type = ((*templSubTypes)[subtypeIndex]).GetTypeInfo(); + if( type && str == type->name ) { ti = type; break; } } } - if (ti == 0 && currentType) + if( ti == 0 && currentType ) { // If this is for a template type, then we must first determine if the // identifier matches any of the template subtypes - if (currentType->flags & asOBJ_TEMPLATE) + if( currentType->flags & asOBJ_TEMPLATE ) { - for (asUINT subtypeIndex = 0; subtypeIndex < currentType->templateSubTypes.GetLength(); subtypeIndex++) + for( asUINT subtypeIndex = 0; subtypeIndex < currentType->templateSubTypes.GetLength(); subtypeIndex++ ) { - asCTypeInfo* type = currentType->templateSubTypes[subtypeIndex].GetTypeInfo(); - if (type && str == type->name) + asCTypeInfo *type = currentType->templateSubTypes[subtypeIndex].GetTypeInfo(); + if( type && str == type->name ) { ti = type; break; @@ -6443,13 +6450,13 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod } } - if (ti == 0) + if( ti == 0 ) { // Check if the type is a child type of the current type ti = GetFuncDef(str.AddressOf(), 0, currentType); - if (ti) + if( ti ) { - if (dt.GetTypeInfo() != 0) + if( dt.GetTypeInfo() != 0 ) { asCString msg; msg.Format(TXT_AMBIGUOUS_SYMBOL_NAME_s, str.AddressOf()); @@ -6459,21 +6466,21 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod return asCDataType::CreatePrimitive(ttInt, isConst); } - dt = asCDataType::CreateType(ti, false); - found = true; + dt = asCDataType::CreateType(ti, false); + found = true; canContinue = false; } } } - if (ti == 0) + if( ti == 0 ) ti = GetType(str.AddressOf(), ns, parentType); - if (ti == 0 && !module && currentType) + if( ti == 0 && !module && currentType ) ti = GetTypeFromTypesKnownByObject(str.AddressOf(), currentType); - if (ti && (!found || checkAmbiguousSymbols) && canContinue) + if( ti && (!found || checkAmbiguousSymbols) && canContinue ) { - if (dt.GetTypeInfo() != 0) + if( dt.GetTypeInfo() != 0 ) { asCString msg; msg.Format(TXT_AMBIGUOUS_SYMBOL_NAME_s, str.AddressOf()); @@ -6485,13 +6492,13 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod found = true; - if (ti->flags & asOBJ_IMPLICIT_HANDLE) + if( ti->flags & asOBJ_IMPLICIT_HANDLE ) isImplicitHandle = true; // Make sure the module has access to the object type - if (!module || (module->m_accessMask & ti->accessMask)) + if( !module || (module->m_accessMask & ti->accessMask) ) { - if (asOBJ_TYPEDEF == (ti->flags & asOBJ_TYPEDEF)) + if( asOBJ_TYPEDEF == (ti->flags & asOBJ_TYPEDEF) ) { // TODO: typedef: A typedef should be considered different from the original type (though with implicit conversions between the two) // Create primitive data type based on object flags @@ -6500,28 +6507,28 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod } else { - if (ti->flags & asOBJ_TEMPLATE || ti->GetSubTypeCount() ) + if( ti->flags & asOBJ_TEMPLATE || ti->GetSubTypeCount() ) { // For template types, find the template instance. For already instantiated template types, match the subtypes ti = GetTemplateInstanceFromNode(n, file, CastToObjectType(ti), implicitNamespace, currentType, &n); - if (ti == 0) + if( ti == 0 ) { - if (isValid) + if( isValid ) *isValid = false; // Return a dummy return asCDataType::CreatePrimitive(ttInt, false); } } - else if (n && n->next && n->next->nodeType == snDataType && !(node->parent && node->parent->nodeType == snEnum)) + else if( n && n->next && n->next->nodeType == snDataType && !(node->parent && node->parent->nodeType == snEnum) ) { - if (reportError) + if( reportError ) { asCString msg; msg.Format(TXT_TYPE_s_NOT_TEMPLATE, ti->name.AddressOf()); WriteError(msg, file, n); } - if (isValid) + if( isValid ) *isValid = false; // Return a dummy @@ -6529,7 +6536,7 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod } // Create object data type - if (ti) + if( ti ) dt = asCDataType::CreateType(ti, isConst); else dt = asCDataType::CreatePrimitive(ttInt, isConst); @@ -6537,15 +6544,15 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod } else { - if (reportError) + if( reportError ) { asCString msg; - msg.Format(TXT_TYPE_s_NOT_AVAILABLE_FOR_MODULE, (const char*)str.AddressOf()); + msg.Format(TXT_TYPE_s_NOT_AVAILABLE_FOR_MODULE, (const char *)str.AddressOf()); WriteError(msg, file, n); } dt.SetTokenType(ttInt); - if (isValid) + if( isValid ) *isValid = false; // Return a dummy @@ -6557,25 +6564,25 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod if( !found || checkAmbiguousSymbols ) { AddVisibleNamespaces(ns, visitedNamespaces, pendingNamespaces); - + // Try to find it in the parent namespace ns = FindNextVisibleNamespace(visitedNamespaces, pendingNamespaces, parentNs, &checkAmbiguousSymbols); - if (parentNs == ns) + if( parentNs == ns ) parentNs = engine->GetParentNameSpace(ns); - - if (parentType) + + if( parentType ) parentType = 0; } } if( !found ) { - if (reportError) + if( reportError ) { asCString msg; - if (origNs && origNs->name == "") + if( origNs && origNs->name == "" ) msg.Format(TXT_IDENTIFIER_s_NOT_DATA_TYPE_IN_GLOBAL_NS, str.AddressOf()); - else if (origNs) + else if( origNs ) msg.Format(TXT_IDENTIFIER_s_NOT_DATA_TYPE_IN_NS_s, str.AddressOf(), origNs->name.AddressOf()); else { @@ -6587,7 +6594,7 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod } dt = asCDataType::CreatePrimitive(ttInt, isConst); - if (isValid) + if( isValid ) *isValid = false; return dt; } @@ -6608,14 +6615,14 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod { if( n->tokenType == ttOpenBracket ) { - if (isImplicitHandle) + if( isImplicitHandle ) { // Make the type a handle - if (dt.MakeHandle(true, acceptHandleForScope) < 0) + if( dt.MakeHandle(true, acceptHandleForScope) < 0 ) { - if (reportError) + if( reportError ) WriteError(TXT_OBJECT_HANDLE_NOT_SUPPORTED, file, n); - if (isValid) + if( isValid ) *isValid = false; // Return a dummy @@ -6627,12 +6634,12 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod // Make sure the sub type can be instantiated if( !dt.CanBeInstantiated() || dt.IsAuto() || dt.GetTokenType() == ttQuestion ) { - if (reportError) + if( reportError ) { asCString str; - if (dt.IsAbstractClass()) + if( dt.IsAbstractClass() ) str.Format(TXT_ABSTRACT_CLASS_s_CANNOT_BE_INSTANTIATED, dt.Format(ns).AddressOf()); - else if (dt.IsInterface()) + else if( dt.IsInterface() ) str.Format(TXT_INTERFACE_s_CANNOT_BE_INSTANTIATED, dt.Format(ns).AddressOf()); else // TODO: Improve error message to explain why @@ -6640,7 +6647,7 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod WriteError(str, file, n); } - if (isValid) + if( isValid ) *isValid = false; // Return a dummy @@ -6650,10 +6657,10 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod // Make the type an array (or multidimensional array) // TODO: If reportError is false, the errors in MakeArray must be suppressed asCDataType origDt = dt; - int r = dt.MakeArray(engine, module); + int r = dt.MakeArray(engine, module); if( r < 0 ) { - if (reportError && r == asINVALID_TYPE) + if( reportError && r == asINVALID_TYPE ) WriteError(TXT_NO_DEFAULT_ARRAY_TYPE, file, n); else { @@ -6661,7 +6668,7 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod msg.Format(TXT_CANNOT_FORM_ARRAY_OF_s, origDt.Format(ns).AddressOf()); WriteError(msg, file, n); } - if (isValid) + if( isValid ) *isValid = false; // Return a dummy @@ -6675,7 +6682,7 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod { if( reportError ) WriteError(TXT_HANDLE_OF_HANDLE_IS_NOT_ALLOWED, file, n); - if (isValid) + if( isValid ) *isValid = false; // Return a dummy @@ -6687,13 +6694,13 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod { if( reportError ) WriteError(TXT_OBJECT_HANDLE_NOT_SUPPORTED, file, n); - if (isValid) + if( isValid ) *isValid = false; // Return a dummy return asCDataType::CreatePrimitive(ttInt, false); } - + // Check if the handle should be read-only if( n && n->next && n->next->tokenType == ttConst ) dt.MakeReadOnly(true); @@ -6705,11 +6712,11 @@ asCDataType asCBuilder::CreateDataTypeFromNode(asCScriptNode *node, asCScriptCod if( isImplicitHandle ) { // Make the type a handle - if (dt.MakeHandle(true, acceptHandleForScope) < 0) + if( dt.MakeHandle(true, acceptHandleForScope) < 0 ) { if( reportError ) WriteError(TXT_OBJECT_HANDLE_NOT_SUPPORTED, file, n); - if (isValid) + if( isValid ) *isValid = false; // Return a dummy @@ -6728,9 +6735,9 @@ asCObjectType *asCBuilder::GetTemplateInstanceFromNode(asCScriptNode *node, asCS // Only do this for application registered interface, as the // scripts cannot implement templates. asCArray subTypes; - asUINT subtypeIndex; - asCScriptNode *n = node; - while (n && n->next && n->next->nodeType == snDataType) + asUINT subtypeIndex; + asCScriptNode *n = node; + while( n && n->next && n->next->nodeType == snDataType ) { n = n->next; @@ -6741,10 +6748,10 @@ asCObjectType *asCBuilder::GetTemplateInstanceFromNode(asCScriptNode *node, asCS subTypes.PushLast(subType); } - if (next) + if( next ) *next = n; - if (subTypes.GetLength() != templateType->templateSubTypes.GetLength()) + if( subTypes.GetLength() != templateType->templateSubTypes.GetLength() ) { asCString msg; msg.Format(TXT_TMPL_s_EXPECTS_d_SUBTYPES, templateType->name.AddressOf(), int(templateType->templateSubTypes.GetLength())); @@ -6756,22 +6763,22 @@ asCObjectType *asCBuilder::GetTemplateInstanceFromNode(asCScriptNode *node, asCS // Check if any of the given subtypes are different from the template's declared subtypes bool isDifferent = false; - for (subtypeIndex = 0; subtypeIndex < subTypes.GetLength(); subtypeIndex++) + for( subtypeIndex = 0; subtypeIndex < subTypes.GetLength(); subtypeIndex++ ) { - if (subTypes[subtypeIndex].GetTypeInfo() != templateType->templateSubTypes[subtypeIndex].GetTypeInfo()) + if( subTypes[subtypeIndex].GetTypeInfo() != templateType->templateSubTypes[subtypeIndex].GetTypeInfo() ) { isDifferent = true; break; } } - if (isDifferent) + if( isDifferent ) { // This is a template instance // Need to find the correct object type asCObjectType *otInstance = engine->GetTemplateInstanceType(templateType, subTypes, module); - if (otInstance && otInstance->scriptSectionIdx < 0) + if( otInstance && otInstance->scriptSectionIdx < 0 ) { // If this is the first time the template instance is used, store where it was declared from otInstance->scriptSectionIdx = engine->GetScriptSectionNameIndex(file->name.AddressOf()); @@ -6780,10 +6787,10 @@ asCObjectType *asCBuilder::GetTemplateInstanceFromNode(asCScriptNode *node, asCS otInstance->declaredAt = (row & 0xFFFFF) | (column << 20); } - if (!otInstance) + if( !otInstance ) { asCString sub = subTypes[0].Format(templateType->nameSpace); - for (asUINT s = 1; s < subTypes.GetLength(); s++) + for( asUINT s = 1; s < subTypes.GetLength(); s++ ) { sub += ","; sub += subTypes[s].Format(templateType->nameSpace); @@ -6809,7 +6816,7 @@ asCDataType asCBuilder::ModifyDataTypeFromNode(const asCDataType &type, asCScrip asCScriptNode *n = node->firstChild; if( n && n->tokenType == ttAmp ) { - if (dt.GetTokenType() == ttVoid) + if( dt.GetTokenType() == ttVoid ) { asCString msg; msg.Format(TXT_TYPE_s_CANNOT_BE_REFERENCE, type.Format(0).AddressOf()); @@ -6843,12 +6850,12 @@ asCDataType asCBuilder::ModifyDataTypeFromNode(const asCDataType &type, asCScrip } if( !engine->ep.allowUnsafeReferences && - inOutFlags && *inOutFlags == asTM_INOUTREF && - !(dt.GetTypeInfo() && (dt.GetTypeInfo()->flags & asOBJ_TEMPLATE_SUBTYPE)) ) + inOutFlags && *inOutFlags == asTM_INOUTREF && + !(dt.GetTypeInfo() && (dt.GetTypeInfo()->flags & asOBJ_TEMPLATE_SUBTYPE)) ) { // Verify that the base type support &inout parameter types - if( !dt.IsObject() || dt.IsObjectHandle() || - !((dt.GetTypeInfo()->flags & asOBJ_NOCOUNT) || (CastToObjectType(dt.GetTypeInfo())->beh.addref && CastToObjectType(dt.GetTypeInfo())->beh.release)) ) + if( !dt.IsObject() || dt.IsObjectHandle() || + !((dt.GetTypeInfo()->flags & asOBJ_NOCOUNT) || (CastToObjectType(dt.GetTypeInfo())->beh.addref && CastToObjectType(dt.GetTypeInfo())->beh.release)) ) WriteError(TXT_ONLY_OBJECTS_MAY_USE_REF_INOUT, file, node->firstChild); } } @@ -6866,11 +6873,11 @@ asCDataType asCBuilder::ModifyDataTypeFromNode(const asCDataType &type, asCScrip if( autoHandle ) *autoHandle = true; } - if (n && n->tokenType == ttIdentifier) + if( n && n->tokenType == ttIdentifier ) { asCString str; str.Assign(&file->code[n->tokenPos], n->tokenLength); - if (str == IF_HANDLE_TOKEN) + if( str == IF_HANDLE_TOKEN ) dt.SetIfHandleThenConst(true); else { @@ -6888,10 +6895,10 @@ asCTypeInfo *asCBuilder::GetType(const char *type, asSNameSpace *ns, asCObjectTy { asASSERT((ns == 0 && parentType) || (ns && parentType == 0)); - if (ns) + if( ns ) { asCTypeInfo *ti = engine->GetRegisteredType(type, ns); - if (!ti && module) + if( !ti && module ) ti = module->GetType(type, ns); return ti; } @@ -6899,12 +6906,12 @@ asCTypeInfo *asCBuilder::GetType(const char *type, asSNameSpace *ns, asCObjectTy { // Recursively check base classes asCObjectType *currType = parentType; - while (currType) + while( currType ) { - for (asUINT n = 0; n < currType->childFuncDefs.GetLength(); n++) + for( asUINT n = 0; n < currType->childFuncDefs.GetLength(); n++ ) { asCFuncdefType *funcDef = currType->childFuncDefs[n]; - if (funcDef && funcDef->name == type) + if( funcDef && funcDef->name == type ) return funcDef; } currType = currType->derivedFrom; @@ -6936,7 +6943,7 @@ bool asCBuilder::DoesTypeExist(const asCString &type) hasCachedKnownTypes = true; // Add registered types - asSMapNode *cursor; + asSMapNode *cursor; engine->allRegisteredTypes.MoveFirst(&cursor); while( cursor ) { @@ -6946,26 +6953,26 @@ bool asCBuilder::DoesTypeExist(const asCString &type) engine->allRegisteredTypes.MoveNext(&cursor, cursor); } - if (module) + if( module ) { // Add script classes and interfaces - for (n = 0; n < module->m_classTypes.GetLength(); n++) - if (!knownTypes.MoveTo(0, module->m_classTypes[n]->name)) + for( n = 0; n < module->m_classTypes.GetLength(); n++ ) + if( !knownTypes.MoveTo(0, module->m_classTypes[n]->name) ) knownTypes.Insert(module->m_classTypes[n]->name, true); // Add script enums - for (n = 0; n < module->m_enumTypes.GetLength(); n++) - if (!knownTypes.MoveTo(0, module->m_enumTypes[n]->name)) + for( n = 0; n < module->m_enumTypes.GetLength(); n++ ) + if( !knownTypes.MoveTo(0, module->m_enumTypes[n]->name) ) knownTypes.Insert(module->m_enumTypes[n]->name, true); // Add script typedefs - for (n = 0; n < module->m_typeDefs.GetLength(); n++) - if (!knownTypes.MoveTo(0, module->m_typeDefs[n]->name)) + for( n = 0; n < module->m_typeDefs.GetLength(); n++ ) + if( !knownTypes.MoveTo(0, module->m_typeDefs[n]->name) ) knownTypes.Insert(module->m_typeDefs[n]->name, true); // Add script funcdefs - for (n = 0; n < module->m_funcDefs.GetLength(); n++) - if (!knownTypes.MoveTo(0, module->m_funcDefs[n]->name)) + for( n = 0; n < module->m_funcDefs.GetLength(); n++ ) + if( !knownTypes.MoveTo(0, module->m_funcDefs[n]->name) ) knownTypes.Insert(module->m_funcDefs[n]->name, true); } } @@ -6977,36 +6984,36 @@ bool asCBuilder::DoesTypeExist(const asCString &type) asCTypeInfo *asCBuilder::GetTypeFromTypesKnownByObject(const char *type, asCObjectType *currentType) { - if (currentType->name == type) + if( currentType->name == type ) return currentType; asUINT n; asCTypeInfo *found = 0; - for (n = 0; found == 0 && n < currentType->properties.GetLength(); n++) - if (currentType->properties[n]->type.GetTypeInfo() && - currentType->properties[n]->type.GetTypeInfo()->name == type) + for( n = 0; found == 0 && n < currentType->properties.GetLength(); n++ ) + if( currentType->properties[n]->type.GetTypeInfo() && + currentType->properties[n]->type.GetTypeInfo()->name == type ) found = currentType->properties[n]->type.GetTypeInfo(); - for (n = 0; found == 0 && n < currentType->methods.GetLength(); n++) + for( n = 0; found == 0 && n < currentType->methods.GetLength(); n++ ) { asCScriptFunction *func = engine->scriptFunctions[currentType->methods[n]]; - if (func->returnType.GetTypeInfo() && - func->returnType.GetTypeInfo()->name == type) + if( func->returnType.GetTypeInfo() && + func->returnType.GetTypeInfo()->name == type ) found = func->returnType.GetTypeInfo(); - for (asUINT f = 0; found == 0 && f < func->parameterTypes.GetLength(); f++) - if (func->parameterTypes[f].GetTypeInfo() && - func->parameterTypes[f].GetTypeInfo()->name == type) + for( asUINT f = 0; found == 0 && f < func->parameterTypes.GetLength(); f++ ) + if( func->parameterTypes[f].GetTypeInfo() && + func->parameterTypes[f].GetTypeInfo()->name == type ) found = func->parameterTypes[f].GetTypeInfo(); } - if (found) + if( found ) { // In case we find a template instance it mustn't be returned // because it is not known if the subtype is really matching - if (found->flags & asOBJ_TEMPLATE) + if( found->flags & asOBJ_TEMPLATE ) return 0; } @@ -7017,22 +7024,22 @@ asCFuncdefType *asCBuilder::GetFuncDef(const char *type, asSNameSpace *ns, asCOb { asASSERT((ns == 0 && parentType) || (ns && parentType == 0)); - if (ns) + if( ns ) { - for (asUINT n = 0; n < engine->registeredFuncDefs.GetLength(); n++) + for( asUINT n = 0; n < engine->registeredFuncDefs.GetLength(); n++ ) { asCFuncdefType *funcDef = engine->registeredFuncDefs[n]; // TODO: access: Only return the definitions that the module has access to - if (funcDef && funcDef->nameSpace == ns && funcDef->name == type) + if( funcDef && funcDef->nameSpace == ns && funcDef->name == type ) return funcDef; } - if (module) + if( module ) { - for (asUINT n = 0; n < module->m_funcDefs.GetLength(); n++) + for( asUINT n = 0; n < module->m_funcDefs.GetLength(); n++ ) { asCFuncdefType *funcDef = module->m_funcDefs[n]; - if (funcDef && funcDef->nameSpace == ns && funcDef->name == type) + if( funcDef && funcDef->nameSpace == ns && funcDef->name == type ) return funcDef; } } @@ -7041,12 +7048,12 @@ asCFuncdefType *asCBuilder::GetFuncDef(const char *type, asSNameSpace *ns, asCOb { // Recursively check base classes asCObjectType *currType = parentType; - while (currType) + while( currType ) { - for (asUINT n = 0; n < currType->childFuncDefs.GetLength(); n++) + for( asUINT n = 0; n < currType->childFuncDefs.GetLength(); n++ ) { asCFuncdefType *funcDef = currType->childFuncDefs[n]; - if (funcDef && funcDef->name == type) + if( funcDef && funcDef->name == type ) return funcDef; } currType = currType->derivedFrom; @@ -7067,7 +7074,7 @@ int asCBuilder::GetEnumValueFromType(asCEnumType *type, const char *name, asCDat { if( type->enumValues[n]->name == name ) { - outDt = asCDataType::CreateType(type, true); + outDt = asCDataType::CreateType(type, true); outValue = type->enumValues[n]->value; return 1; } diff --git a/sdk/angelscript/source/as_builder.h b/sdk/angelscript/source/as_builder.h index 4dff404d..b64c0bcd 100644 --- a/sdk/angelscript/source/as_builder.h +++ b/sdk/angelscript/source/as_builder.h @@ -60,13 +60,13 @@ struct sGlobalVariableDescription; struct sFunctionDescription { - asCScriptCode *script; - asCScriptNode *node; - asCString name; - asCObjectType *objType; - asCArray paramNames; - int funcId; - bool isExistingShared; + asCScriptCode *script; + asCScriptNode *node; + asCString name; + asCObjectType *objType; + asCArray paramNames; + int funcId; + bool isExistingShared; }; struct sGlobalVariableDescription @@ -87,9 +87,20 @@ struct sGlobalVariableDescription struct sPropertyInitializer { - sPropertyInitializer() : declNode(0), initNode(0), file(0) {} - sPropertyInitializer(const asCString &nm, asCScriptNode *decl, asCScriptNode *init, asCScriptCode *f) : name(nm), declNode(decl), initNode(init), file(f) {} - sPropertyInitializer &operator=(const sPropertyInitializer &o) {name = o.name; declNode = o.declNode; initNode = o.initNode; file = o.file; return *this;} + sPropertyInitializer() : declNode(0), initNode(0), file(0) + { + } + sPropertyInitializer(const asCString &nm, asCScriptNode *decl, asCScriptNode *init, asCScriptCode *f) : name(nm), declNode(decl), initNode(init), file(f) + { + } + sPropertyInitializer &operator=(const sPropertyInitializer &o) + { + name = o.name; + declNode = o.declNode; + initNode = o.initNode; + file = o.file; + return *this; + } asCString name; asCScriptNode *declNode; @@ -99,8 +110,18 @@ struct sPropertyInitializer struct sClassDeclaration { - sClassDeclaration() { script = 0; node = 0; validState = 0; typeInfo = 0; isExistingShared = false; isFinal = false; - isDefaultConstructorDeleted = false; isDefaultCopyConstructorDeleted = false; isDefaultCopyDeleted = false; } + sClassDeclaration() + { + script = 0; + node = 0; + validState = 0; + typeInfo = 0; + isExistingShared = false; + isFinal = false; + isDefaultConstructorDeleted = false; + isDefaultCopyConstructorDeleted = false; + isDefaultCopyDeleted = false; + } asCScriptCode *script; asCScriptNode *node; @@ -153,9 +174,9 @@ class asCBuilder int ValidateVirtualProperty(asCScriptFunction *func); #ifndef AS_NO_COMPILER - int AddCode(const char *name, const char *code, int codeLength, int lineOffset, int sectionIdx, bool makeCopy); + int AddCode(const char *name, const char *code, int codeLength, int lineOffset, int sectionIdx, bool makeCopy); asCScriptCode *FindOrAddCode(const char *name, const char *code, size_t length); - int Build(); + int Build(); int CompileFunction(const char *sectionName, const char *code, int lineOffset, asDWORD compileFlags, asCScriptFunction **outFunc); int CompileGlobalVar(const char *sectionName, const char *code, int lineOffset); @@ -167,59 +188,59 @@ class asCBuilder friend class asCScriptFunction; friend class asCScriptEngine; - void Reset(); + void Reset(); - void WriteInfo(const asCString &scriptname, const asCString &msg, int r, int c, bool preMessage); - void WriteInfo(const asCString &msg, asCScriptCode *file, asCScriptNode *node); - void WriteError(const asCString &scriptname, const asCString &msg, int r, int c); - void WriteError(const asCString &msg, asCScriptCode *file, asCScriptNode *node); - void WriteWarning(const asCString &scriptname, const asCString &msg, int r, int c); - void WriteWarning(const asCString &msg, asCScriptCode *file, asCScriptNode *node); + void WriteInfo(const asCString &scriptname, const asCString &msg, int r, int c, bool preMessage); + void WriteInfo(const asCString &msg, asCScriptCode *file, asCScriptNode *node); + void WriteError(const asCString &scriptname, const asCString &msg, int r, int c); + void WriteError(const asCString &msg, asCScriptCode *file, asCScriptNode *node); + void WriteWarning(const asCString &scriptname, const asCString &msg, int r, int c); + void WriteWarning(const asCString &msg, asCScriptCode *file, asCScriptNode *node); bool DoesGlobalPropertyExist(const char *prop, asSNameSpace *ns, asCGlobalProperty **outProp = 0, sGlobalVariableDescription **outDesc = 0, bool *isAppProp = 0); asCGlobalProperty *GetGlobalProperty(const char *prop, asSNameSpace *ns, bool *isCompiled, bool *isPureConstant, asQWORD *constantValue, bool *isAppProp); int ValidateDefaultArgs(asCScriptCode *script, asCScriptNode *node, asCScriptFunction *func); asCString GetCleanExpressionString(asCScriptNode *n, asCScriptCode *file); - asSNameSpace *GetNameSpaceFromNode(asCScriptNode *node, asCScriptCode *script, asSNameSpace *implicitNs, asCScriptNode **next, asCObjectType **objType = 0, bool *isExplicitNs = 0); - asSNameSpace *GetNameSpaceByString(const asCString &nsName, asSNameSpace *implicitNs, asCScriptNode *errNode, asCScriptCode *script, asCTypeInfo **scopeType = 0, bool isRequired = true); - asCString GetScopeFromNode(asCScriptNode *n, asCScriptCode *script, asCScriptNode **next = 0); + asSNameSpace *GetNameSpaceFromNode(asCScriptNode *node, asCScriptCode *script, asSNameSpace *implicitNs, asCScriptNode **next, asCObjectType **objType = 0, bool *isExplicitNs = 0); + asSNameSpace *GetNameSpaceByString(const asCString &nsName, asSNameSpace *implicitNs, asCScriptNode *errNode, asCScriptCode *script, asCTypeInfo **scopeType = 0, bool isRequired = true); + asCString GetScopeFromNode(asCScriptNode *n, asCScriptCode *script, asCScriptNode **next = 0); - asCTypeInfo *GetType(const char *type, asSNameSpace *ns, asCObjectType *parentType); - asCObjectType *GetObjectType(const char *type, asSNameSpace *ns); - asCFuncdefType *GetFuncDef(const char *type, asSNameSpace *ns, asCObjectType *parentType); - asCTypeInfo *GetTypeFromTypesKnownByObject(const char *type, asCObjectType *currentType); - asCDataType CreateDataTypeFromNode(asCScriptNode *node, asCScriptCode *file, asSNameSpace *implicitNamespace, bool acceptHandleForScope = false, asCObjectType *currentType = 0, bool reportError = true, bool *isValid = 0, asCArray *templateSubType = 0, asCArray* scopeVisibleNamespaces = 0); - asCObjectType *GetTemplateInstanceFromNode(asCScriptNode *node, asCScriptCode *file, asCObjectType *templateType, asSNameSpace *implicitNamespace, asCObjectType *currentType, asCScriptNode **next = 0); - asCDataType ModifyDataTypeFromNode(const asCDataType &type, asCScriptNode *node, asCScriptCode *file, asETypeModifiers *inOutFlag, bool *autoHandle); + asCTypeInfo *GetType(const char *type, asSNameSpace *ns, asCObjectType *parentType); + asCObjectType *GetObjectType(const char *type, asSNameSpace *ns); + asCFuncdefType *GetFuncDef(const char *type, asSNameSpace *ns, asCObjectType *parentType); + asCTypeInfo *GetTypeFromTypesKnownByObject(const char *type, asCObjectType *currentType); + asCDataType CreateDataTypeFromNode(asCScriptNode *node, asCScriptCode *file, asSNameSpace *implicitNamespace, bool acceptHandleForScope = false, asCObjectType *currentType = 0, bool reportError = true, bool *isValid = 0, asCArray *templateSubType = 0, asCArray *scopeVisibleNamespaces = 0); + asCObjectType *GetTemplateInstanceFromNode(asCScriptNode *node, asCScriptCode *file, asCObjectType *templateType, asSNameSpace *implicitNamespace, asCObjectType *currentType, asCScriptNode **next = 0); + asCDataType ModifyDataTypeFromNode(const asCDataType &type, asCScriptNode *node, asCScriptCode *file, asETypeModifiers *inOutFlag, bool *autoHandle); - bool FindObjectTypeOrMixinInNsHierarchy(const asCString& name, asSNameSpace* startNs, bool isExplicitNs, asCScriptNode* errNode, asCScriptCode* script, asCObjectType** outObjType, sMixinClass** outMixin); - void AddVisibleNamespaces(asSNameSpace* ns, const asCArray& visited, asCArray& pending); - asSNameSpace *FindNextVisibleNamespace(const asCArray& visited, asCArray& pending, asSNameSpace* parentNs, bool* checkAmbiguous = 0); + bool FindObjectTypeOrMixinInNsHierarchy(const asCString &name, asSNameSpace *startNs, bool isExplicitNs, asCScriptNode *errNode, asCScriptCode *script, asCObjectType **outObjType, sMixinClass **outMixin); + void AddVisibleNamespaces(asSNameSpace *ns, const asCArray &visited, asCArray &pending); + asSNameSpace *FindNextVisibleNamespace(const asCArray &visited, asCArray &pending, asSNameSpace *parentNs, bool *checkAmbiguous = 0); - int numErrors; - int numWarnings; + int numErrors; + int numWarnings; bool silent; - asCScriptEngine *engine; - asCModule *module; - asCMap< asSNameSpace*, asCArray > namespaceVisibility; + asCScriptEngine *engine; + asCModule *module; + asCMap > namespaceVisibility; #ifndef AS_NO_COMPILER protected: friend class asCCompiler; - int CheckForConflictsDueToDefaultArgs(asCScriptCode *script, asCScriptNode *node, asCScriptFunction *func, asCObjectType *objType); - int GetNamespaceAndNameFromNode(asCScriptNode *n, asCScriptCode *script, asSNameSpace *implicitNs, asSNameSpace *&outNs, asCString &outName, bool *isExplicitNs = 0); - int RegisterMixinClass(asCScriptNode *node, asCScriptCode *file, asSNameSpace *ns); - sMixinClass *GetMixinClass(const char *name, asSNameSpace *ns); - void IncludePropertiesFromMixins(sClassDeclaration *decl); - void IncludeMethodsFromMixins(sClassDeclaration *decl); - void AddInterfaceToClass(sClassDeclaration *decl, asCScriptNode *errNode, asCObjectType *intf); - void AddInterfaceFromMixinToClass(sClassDeclaration *decl, asCScriptNode *errNode, sMixinClass *mixin); + int CheckForConflictsDueToDefaultArgs(asCScriptCode *script, asCScriptNode *node, asCScriptFunction *func, asCObjectType *objType); + int GetNamespaceAndNameFromNode(asCScriptNode *n, asCScriptCode *script, asSNameSpace *implicitNs, asSNameSpace *&outNs, asCString &outName, bool *isExplicitNs = 0); + int RegisterMixinClass(asCScriptNode *node, asCScriptCode *file, asSNameSpace *ns); + sMixinClass *GetMixinClass(const char *name, asSNameSpace *ns); + void IncludePropertiesFromMixins(sClassDeclaration *decl); + void IncludeMethodsFromMixins(sClassDeclaration *decl); + void AddInterfaceToClass(sClassDeclaration *decl, asCScriptNode *errNode, asCObjectType *intf); + void AddInterfaceFromMixinToClass(sClassDeclaration *decl, asCScriptNode *errNode, sMixinClass *mixin); int RegisterScriptFunctionFromNode(asCScriptNode *node, asCScriptCode *file, asCObjectType *object = 0, bool isInterface = false, bool isGlobalFunction = false, asSNameSpace *ns = 0, bool isExistingShared = false, bool isMixin = false, sClassDeclaration *decl = 0); - int RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, asCObjectType *objType, bool isInterface, bool isGlobalFunction, asSNameSpace *ns, bool isExistingShared, bool isMixin, asCString &name, asCDataType &returnType, asCArray ¶meterNames, asCArray ¶meterTypes, asCArray &inOutFlags, asCArray &defaultArgs, asSFunctionTraits funcTraits, sClassDeclaration* decl); + int RegisterScriptFunction(asCScriptNode *node, asCScriptCode *file, asCObjectType *objType, bool isInterface, bool isGlobalFunction, asSNameSpace *ns, bool isExistingShared, bool isMixin, asCString &name, asCDataType &returnType, asCArray ¶meterNames, asCArray ¶meterTypes, asCArray &inOutFlags, asCArray &defaultArgs, asSFunctionTraits funcTraits, sClassDeclaration *decl); int RegisterVirtualProperty(asCScriptNode *node, asCScriptCode *file, asCObjectType *object = 0, bool isInterface = false, bool isGlobalFunction = false, asSNameSpace *ns = 0, bool isExistingShared = false); int RegisterImportedFunction(int funcID, asCScriptNode *node, asCScriptCode *file, asSNameSpace *ns); int RegisterGlobalVar(asCScriptNode *node, asCScriptCode *file, asSNameSpace *ns); @@ -237,7 +258,7 @@ class asCBuilder void GetParsedFunctionDetails(asCScriptNode *node, asCScriptCode *file, asCObjectType *objType, asCString &name, asCDataType &returnType, asCArray ¶meterNames, asCArray ¶meterTypes, asCArray &inOutFlags, asCArray &defaultArgs, asSFunctionTraits &traits, asSNameSpace *implicitNamespace); bool DoesMethodExist(asCObjectType *objType, int methodId, asUINT *methodIndex = 0); void AddDefaultConstructor(asCObjectType *objType, asCScriptCode *file); - void AddDefaultCopyConstructor(asCObjectType *objType, asCScriptCode *file); + void AddDefaultCopyConstructor(asCObjectType *objType, asCScriptCode *file); asCObjectProperty *AddPropertyToClass(sClassDeclaration *c, const asCString &name, const asCDataType &type, bool isPrivate, bool isProtected, bool isInherited, asCScriptCode *file = 0, asCScriptNode *node = 0); int CreateVirtualFunction(asCScriptFunction *func, int idx); void ParseScripts(); @@ -256,14 +277,14 @@ class asCBuilder void EvaluateTemplateInstances(asUINT startIdx, bool keepSilent); void CleanupEnumValues(); - asCArray scripts; - asCArray functions; - asCSymbolTable globVariables; - asCArray classDeclarations; - asCArray interfaceDeclarations; - asCArray namedTypeDeclarations; - asCArray funcDefs; - asCArray mixinClasses; + asCArray scripts; + asCArray functions; + asCSymbolTable globVariables; + asCArray classDeclarations; + asCArray interfaceDeclarations; + asCArray namedTypeDeclarations; + asCArray funcDefs; + asCArray mixinClasses; // For use with the DoesTypeExists() method bool hasCachedKnownTypes; diff --git a/sdk/angelscript/source/as_bytecode.cpp b/sdk/angelscript/source/as_bytecode.cpp index 7cd71a01..0e5f12da 100644 --- a/sdk/angelscript/source/as_bytecode.cpp +++ b/sdk/angelscript/source/as_bytecode.cpp @@ -41,20 +41,20 @@ #ifndef AS_NO_COMPILER -#include "as_bytecode.h" -#include "as_debug.h" // mkdir() -#include "as_array.h" -#include "as_string.h" -#include "as_scriptengine.h" -#include "as_debug.h" + #include "as_bytecode.h" + #include "as_debug.h" // mkdir() + #include "as_array.h" + #include "as_string.h" + #include "as_scriptengine.h" + #include "as_debug.h" BEGIN_AS_NAMESPACE asCByteCode::asCByteCode(asCScriptEngine *engine) { - first = 0; - last = 0; - largestStackUsed = -1; + first = 0; + last = 0; + largestStackUsed = -1; temporaryVariables = 0; this->engine = engine; @@ -94,7 +94,7 @@ void asCByteCode::ClearAll() } first = 0; - last = 0; + last = 0; lineNumbers.SetLength(0); @@ -120,25 +120,25 @@ void asCByteCode::GetVarsUsed(asCArray &vars) InsertIfNotExists(vars, curr->wArg[1]); InsertIfNotExists(vars, curr->wArg[2]); } - else if( asBCInfo[curr->op].type == asBCTYPE_rW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_W_ARG || - asBCInfo[curr->op].type == asBCTYPE_rW_DW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_DW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_QW_ARG || - asBCInfo[curr->op].type == asBCTYPE_rW_W_DW_ARG || - asBCInfo[curr->op].type == asBCTYPE_rW_DW_DW_ARG ) + else if( asBCInfo[curr->op].type == asBCTYPE_rW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_W_ARG || + asBCInfo[curr->op].type == asBCTYPE_rW_DW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_DW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_QW_ARG || + asBCInfo[curr->op].type == asBCTYPE_rW_W_DW_ARG || + asBCInfo[curr->op].type == asBCTYPE_rW_DW_DW_ARG ) { InsertIfNotExists(vars, curr->wArg[0]); } else if( asBCInfo[curr->op].type == asBCTYPE_wW_rW_ARG || - asBCInfo[curr->op].type == asBCTYPE_rW_rW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_rW_DW_ARG ) + asBCInfo[curr->op].type == asBCTYPE_rW_rW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_rW_DW_ARG ) { InsertIfNotExists(vars, curr->wArg[0]); InsertIfNotExists(vars, curr->wArg[1]); } - else if (asBCInfo[curr->op].type == asBCTYPE_W_rW_ARG) + else if( asBCInfo[curr->op].type == asBCTYPE_W_rW_ARG ) { InsertIfNotExists(vars, curr->wArg[1]); } @@ -164,21 +164,21 @@ bool asCByteCode::IsVarUsed(int offset) if( curr->wArg[0] == offset || curr->wArg[1] == offset || curr->wArg[2] == offset ) return true; } - else if( asBCInfo[curr->op].type == asBCTYPE_rW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_W_ARG || - asBCInfo[curr->op].type == asBCTYPE_rW_DW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_DW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_QW_ARG || - asBCInfo[curr->op].type == asBCTYPE_rW_W_DW_ARG || - asBCInfo[curr->op].type == asBCTYPE_rW_DW_DW_ARG ) + else if( asBCInfo[curr->op].type == asBCTYPE_rW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_W_ARG || + asBCInfo[curr->op].type == asBCTYPE_rW_DW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_DW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_QW_ARG || + asBCInfo[curr->op].type == asBCTYPE_rW_W_DW_ARG || + asBCInfo[curr->op].type == asBCTYPE_rW_DW_DW_ARG ) { if( curr->wArg[0] == offset ) return true; } else if( asBCInfo[curr->op].type == asBCTYPE_wW_rW_ARG || - asBCInfo[curr->op].type == asBCTYPE_rW_rW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_rW_DW_ARG ) + asBCInfo[curr->op].type == asBCTYPE_rW_rW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_rW_DW_ARG ) { if( curr->wArg[0] == offset || curr->wArg[1] == offset ) return true; @@ -217,20 +217,20 @@ void asCByteCode::ExchangeVar(int oldOffset, int newOffset) if( curr->wArg[2] == oldOffset ) curr->wArg[2] = (short)newOffset; } - else if( asBCInfo[curr->op].type == asBCTYPE_rW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_W_ARG || - asBCInfo[curr->op].type == asBCTYPE_rW_DW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_DW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_QW_ARG || - asBCInfo[curr->op].type == asBCTYPE_rW_W_DW_ARG || - asBCInfo[curr->op].type == asBCTYPE_rW_DW_DW_ARG ) + else if( asBCInfo[curr->op].type == asBCTYPE_rW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_W_ARG || + asBCInfo[curr->op].type == asBCTYPE_rW_DW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_DW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_QW_ARG || + asBCInfo[curr->op].type == asBCTYPE_rW_W_DW_ARG || + asBCInfo[curr->op].type == asBCTYPE_rW_DW_DW_ARG ) { if( curr->wArg[0] == oldOffset ) curr->wArg[0] = (short)newOffset; } else if( asBCInfo[curr->op].type == asBCTYPE_wW_rW_ARG || - asBCInfo[curr->op].type == asBCTYPE_rW_rW_ARG ) + asBCInfo[curr->op].type == asBCTYPE_rW_rW_ARG ) { if( curr->wArg[0] == oldOffset ) curr->wArg[0] = (short)newOffset; @@ -257,7 +257,7 @@ void asCByteCode::AddPath(asCArray &paths, asCByteInstruct else { // Add the destination to the code paths - instr->marked = true; + instr->marked = true; instr->stackSize = stackSize; paths.PushLast(instr); } @@ -281,7 +281,7 @@ asCByteInstruction *asCByteCode::DeleteFirstChangeNext(asCByteInstruction *curr, asASSERT( curr->next ); asCByteInstruction *instr = curr->next; - instr->op = bc; + instr->op = bc; DeleteInstruction(curr); @@ -298,9 +298,9 @@ void asCByteCode::InsertBefore(asCByteInstruction *before, asCByteInstruction *i asASSERT(instr->prev == 0); if( before->prev ) before->prev->next = instr; - instr->prev = before->prev; + instr->prev = before->prev; before->prev = instr; - instr->next = before; + instr->next = before; if( first == before ) first = instr; } @@ -327,13 +327,13 @@ bool asCByteCode::CanBeSwapped(asCByteInstruction *curr) asCByteInstruction *a = b->prev; if( a->op != asBC_PshNull && - a->op != asBC_PshVPtr && - a->op != asBC_PSF ) + a->op != asBC_PshVPtr && + a->op != asBC_PSF ) return false; if( b->op != asBC_PshNull && - b->op != asBC_PshVPtr && - b->op != asBC_PSF ) + b->op != asBC_PshVPtr && + b->op != asBC_PSF ) return false; return true; @@ -363,7 +363,7 @@ bool asCByteCode::PostponeInitOfTemp(asCByteInstruction *curr, asCByteInstructio // This is not done for pointers if( (curr->op != asBC_SetV4 && curr->op != asBC_SetV8) || - !IsTemporary(curr->wArg[0]) ) return false; + !IsTemporary(curr->wArg[0]) ) return false; // Move the initialization to just before it's use. // Don't move it beyond any labels or jumps. @@ -423,19 +423,19 @@ bool asCByteCode::RemoveUnusedValue(asCByteInstruction *curr, asCByteInstruction // The value isn't used for anything if( curr->op != asBC_FREE && // Can't remove the FREE instruction - (asBCInfo[curr->op].type == asBCTYPE_wW_rW_rW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_rW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_rW_DW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_DW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_QW_ARG) && - IsTemporary(curr->wArg[0]) && - !IsTempVarRead(curr, curr->wArg[0]) ) + (asBCInfo[curr->op].type == asBCTYPE_wW_rW_rW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_rW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_rW_DW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_DW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_QW_ARG) && + IsTemporary(curr->wArg[0]) && + !IsTempVarRead(curr, curr->wArg[0]) ) { if( curr->op == asBC_LdGRdR4 && IsTempRegUsed(curr) ) { curr->op = asBC_LDG; - *next = GoForward(curr); + *next = GoForward(curr); return true; } @@ -450,56 +450,56 @@ bool asCByteCode::RemoveUnusedValue(asCByteInstruction *curr, asCByteInstruction curr->next->op == asBC_CMPf || curr->next->op == asBC_CMPu) && curr->wArg[0] == curr->next->wArg[1] && - IsTemporary(curr->wArg[0]) && // The variable is temporary and never used again + IsTemporary(curr->wArg[0]) && // The variable is temporary and never used again !IsTempVarRead(curr->next, curr->wArg[0]) ) { - if( curr->next->op == asBC_CMPi ) curr->next->op = asBC_CMPIi; + if( curr->next->op == asBC_CMPi ) curr->next->op = asBC_CMPIi; else if( curr->next->op == asBC_CMPf ) curr->next->op = asBC_CMPIf; else if( curr->next->op == asBC_CMPu ) curr->next->op = asBC_CMPIu; - curr->next->size = asBCTypeSize[asBCInfo[asBC_CMPIi].type]; + curr->next->size = asBCTypeSize[asBCInfo[asBC_CMPIi].type]; curr->next->arg[0] = curr->arg[0]; - *next = GoForward(DeleteInstruction(curr)); + *next = GoForward(DeleteInstruction(curr)); return true; } // The value is immediately used and then never again - if( (curr->next->op == asBC_ADDi || - curr->next->op == asBC_SUBi || - curr->next->op == asBC_MULi || - curr->next->op == asBC_ADDf || - curr->next->op == asBC_SUBf || - curr->next->op == asBC_MULf) && - curr->wArg[0] == curr->next->wArg[2] && - (curr->next->wArg[0] == curr->wArg[0] || // The variable is overwritten - (IsTemporary(curr->wArg[0]) && // The variable is temporary and never used again - !IsTempVarRead(curr->next, curr->wArg[0]))) ) + if( (curr->next->op == asBC_ADDi || + curr->next->op == asBC_SUBi || + curr->next->op == asBC_MULi || + curr->next->op == asBC_ADDf || + curr->next->op == asBC_SUBf || + curr->next->op == asBC_MULf) && + curr->wArg[0] == curr->next->wArg[2] && + (curr->next->wArg[0] == curr->wArg[0] || // The variable is overwritten + (IsTemporary(curr->wArg[0]) && // The variable is temporary and never used again + !IsTempVarRead(curr->next, curr->wArg[0]))) ) { - if( curr->next->op == asBC_ADDi ) curr->next->op = asBC_ADDIi; + if( curr->next->op == asBC_ADDi ) curr->next->op = asBC_ADDIi; else if( curr->next->op == asBC_SUBi ) curr->next->op = asBC_SUBIi; else if( curr->next->op == asBC_MULi ) curr->next->op = asBC_MULIi; else if( curr->next->op == asBC_ADDf ) curr->next->op = asBC_ADDIf; else if( curr->next->op == asBC_SUBf ) curr->next->op = asBC_SUBIf; else if( curr->next->op == asBC_MULf ) curr->next->op = asBC_MULIf; - curr->next->size = asBCTypeSize[asBCInfo[asBC_ADDIi].type]; + curr->next->size = asBCTypeSize[asBCInfo[asBC_ADDIi].type]; curr->next->arg[0] = curr->arg[0]; - *next = GoForward(DeleteInstruction(curr)); + *next = GoForward(DeleteInstruction(curr)); return true; } - if( (curr->next->op == asBC_ADDi || - curr->next->op == asBC_MULi || - curr->next->op == asBC_ADDf || - curr->next->op == asBC_MULf) && - curr->wArg[0] == curr->next->wArg[1] && - (curr->next->wArg[0] == curr->wArg[0] || // The variable is overwritten - (IsTemporary(curr->wArg[0]) && // The variable is temporary and never used again - !IsTempVarRead(curr->next, curr->wArg[0]))) ) + if( (curr->next->op == asBC_ADDi || + curr->next->op == asBC_MULi || + curr->next->op == asBC_ADDf || + curr->next->op == asBC_MULf) && + curr->wArg[0] == curr->next->wArg[1] && + (curr->next->wArg[0] == curr->wArg[0] || // The variable is overwritten + (IsTemporary(curr->wArg[0]) && // The variable is temporary and never used again + !IsTempVarRead(curr->next, curr->wArg[0]))) ) { - if( curr->next->op == asBC_ADDi ) curr->next->op = asBC_ADDIi; + if( curr->next->op == asBC_ADDi ) curr->next->op = asBC_ADDIi; else if( curr->next->op == asBC_MULi ) curr->next->op = asBC_MULIi; else if( curr->next->op == asBC_ADDf ) curr->next->op = asBC_ADDIf; else if( curr->next->op == asBC_MULf ) curr->next->op = asBC_MULIf; - curr->next->size = asBCTypeSize[asBCInfo[asBC_ADDIi].type]; + curr->next->size = asBCTypeSize[asBCInfo[asBC_ADDIi].type]; curr->next->arg[0] = curr->arg[0]; // The order of the operands are changed @@ -511,60 +511,60 @@ bool asCByteCode::RemoveUnusedValue(asCByteInstruction *curr, asCByteInstruction // The constant value is immediately moved to another variable and then not used again if( curr->next->op == asBC_CpyVtoV4 && - curr->wArg[0] == curr->next->wArg[1] && - IsTemporary(curr->wArg[0]) && - !IsTempVarRead(curr->next, curr->wArg[0]) ) + curr->wArg[0] == curr->next->wArg[1] && + IsTemporary(curr->wArg[0]) && + !IsTempVarRead(curr->next, curr->wArg[0]) ) { curr->wArg[0] = curr->next->wArg[0]; - *next = GoForward(DeleteInstruction(curr->next)); + *next = GoForward(DeleteInstruction(curr->next)); return true; } // The constant is copied to a temp and then immediately pushed on the stack if( curr->next->op == asBC_PshV4 && - curr->wArg[0] == curr->next->wArg[0] && - IsTemporary(curr->wArg[0]) && - !IsTempVarRead(curr->next, curr->wArg[0]) ) + curr->wArg[0] == curr->next->wArg[0] && + IsTemporary(curr->wArg[0]) && + !IsTempVarRead(curr->next, curr->wArg[0]) ) { - curr->op = asBC_PshC4; + curr->op = asBC_PshC4; curr->stackInc = asBCInfo[asBC_PshC4].stackInc; - *next = GoForward(DeleteInstruction(curr->next)); + *next = GoForward(DeleteInstruction(curr->next)); return true; } // The constant is copied to a global variable and then never used again if( curr->next->op == asBC_CpyVtoG4 && - curr->wArg[0] == curr->next->wArg[0] && - IsTemporary(curr->wArg[0]) && - !IsTempVarRead(curr->next, curr->wArg[0]) ) + curr->wArg[0] == curr->next->wArg[0] && + IsTemporary(curr->wArg[0]) && + !IsTempVarRead(curr->next, curr->wArg[0]) ) { - curr->op = asBC_SetG4; - curr->size = asBCTypeSize[asBCInfo[asBC_SetG4].type]; - *(((asDWORD*)&curr->arg)+AS_PTR_SIZE) = *ARG_DW(curr->arg); - *ARG_PTR(curr->arg) = *ARG_PTR(curr->next->arg); - *next = GoForward(DeleteInstruction(curr->next)); + curr->op = asBC_SetG4; + curr->size = asBCTypeSize[asBCInfo[asBC_SetG4].type]; + *(((asDWORD *)&curr->arg) + AS_PTR_SIZE) = *ARG_DW(curr->arg); + *ARG_PTR(curr->arg) = *ARG_PTR(curr->next->arg); + *next = GoForward(DeleteInstruction(curr->next)); return true; } } // The value is immediately moved to another variable and then not used again if( (asBCInfo[curr->op].type == asBCTYPE_wW_rW_rW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_rW_DW_ARG) && - curr->next && curr->next->op == asBC_CpyVtoV4 && - curr->wArg[0] == curr->next->wArg[1] && - IsTemporary(curr->wArg[0]) && - !IsTempVarRead(curr->next, curr->wArg[0]) ) + asBCInfo[curr->op].type == asBCTYPE_wW_rW_DW_ARG) && + curr->next && curr->next->op == asBC_CpyVtoV4 && + curr->wArg[0] == curr->next->wArg[1] && + IsTemporary(curr->wArg[0]) && + !IsTempVarRead(curr->next, curr->wArg[0]) ) { curr->wArg[0] = curr->next->wArg[0]; - *next = GoForward(DeleteInstruction(curr->next)); + *next = GoForward(DeleteInstruction(curr->next)); return true; } // The register is copied to a temp variable and then back to the register again without being used afterwards if( curr->op == asBC_CpyRtoV4 && curr->next && curr->next->op == asBC_CpyVtoR4 && - curr->wArg[0] == curr->next->wArg[0] && - IsTemporary(curr->wArg[0]) && - !IsTempVarRead(curr->next, curr->wArg[0]) ) + curr->wArg[0] == curr->next->wArg[0] && + IsTemporary(curr->wArg[0]) && + !IsTempVarRead(curr->next, curr->wArg[0]) ) { // Delete both instructions DeleteInstruction(curr->next); @@ -574,27 +574,27 @@ bool asCByteCode::RemoveUnusedValue(asCByteInstruction *curr, asCByteInstruction // The global value is copied to a temp and then immediately pushed on the stack if( curr->op == asBC_CpyGtoV4 && curr->next && curr->next->op == asBC_PshV4 && - curr->wArg[0] == curr->next->wArg[0] && - IsTemporary(curr->wArg[0]) && - !IsTempVarRead(curr->next, curr->wArg[0]) ) + curr->wArg[0] == curr->next->wArg[0] && + IsTemporary(curr->wArg[0]) && + !IsTempVarRead(curr->next, curr->wArg[0]) ) { - curr->op = asBC_PshG4; - curr->size = asBCTypeSize[asBCInfo[asBC_PshG4].type]; + curr->op = asBC_PshG4; + curr->size = asBCTypeSize[asBCInfo[asBC_PshG4].type]; curr->stackInc = asBCInfo[asBC_PshG4].stackInc; - *next = GoForward(DeleteInstruction(curr->next)); + *next = GoForward(DeleteInstruction(curr->next)); return true; } // The constant is assigned to a variable, then the value of the variable // pushed on the stack, and then the variable is never used again if( curr->op == asBC_SetV8 && curr->next && curr->next->op == asBC_PshV8 && - curr->wArg[0] == curr->next->wArg[0] && - IsTemporary(curr->wArg[0]) && - !IsTempVarRead(curr->next, curr->wArg[0]) ) + curr->wArg[0] == curr->next->wArg[0] && + IsTemporary(curr->wArg[0]) && + !IsTempVarRead(curr->next, curr->wArg[0]) ) { - curr->op = asBC_PshC8; + curr->op = asBC_PshC8; curr->stackInc = asBCInfo[asBC_PshC8].stackInc; - *next = GoForward(DeleteInstruction(curr->next)); + *next = GoForward(DeleteInstruction(curr->next)); return true; } @@ -644,7 +644,7 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) while( instr ) { asCByteInstruction *curr = instr; - instr = instr->prev; + instr = instr->prev; // Remove instructions when the result is not used anywhere // This will return true if the instruction is deleted, and @@ -681,12 +681,12 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) { // T??, ClrHi -> T?? if( instr && - (instr->op == asBC_TZ || + (instr->op == asBC_TZ || instr->op == asBC_TNZ || - instr->op == asBC_TS || + instr->op == asBC_TS || instr->op == asBC_TNS || - instr->op == asBC_TP || - instr->op == asBC_TNP) ) + instr->op == asBC_TP || + instr->op == asBC_TNP) ) { // Remove the ClrHi instruction since the test // instructions always clear the top bytes anyway @@ -696,19 +696,19 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) // ClrHi, JZ -> JLowZ if( curr->next && - curr->next->op == asBC_JZ ) + curr->next->op == asBC_JZ ) { curr->next->op = asBC_JLowZ; - instr = GoForward(DeleteInstruction(curr)); + instr = GoForward(DeleteInstruction(curr)); continue; } // ClrHi, JNZ -> JLowNZ if( curr->next && - curr->next->op == asBC_JNZ ) + curr->next->op == asBC_JNZ ) { curr->next->op = asBC_JLowNZ; - instr = GoForward(DeleteInstruction(curr)); + instr = GoForward(DeleteInstruction(curr)); continue; } } @@ -734,8 +734,8 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) // LDG x, WRTV4 y -> CpyVtoG4 y, x if( curr->next->op == asBC_WRTV4 && !IsTempRegUsed(curr->next) ) { - curr->op = asBC_CpyVtoG4; - curr->size = asBCTypeSize[asBCInfo[asBC_CpyVtoG4].type]; + curr->op = asBC_CpyVtoG4; + curr->size = asBCTypeSize[asBCInfo[asBC_CpyVtoG4].type]; curr->wArg[0] = curr->next->wArg[0]; DeleteInstruction(curr->next); instr = GoForward(curr); @@ -747,7 +747,7 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) curr->op = asBC_CpyGtoV4; else curr->op = asBC_LdGRdR4; - curr->size = asBCTypeSize[asBCInfo[asBC_CpyGtoV4].type]; + curr->size = asBCTypeSize[asBCInfo[asBC_CpyGtoV4].type]; curr->wArg[0] = curr->next->wArg[0]; DeleteInstruction(curr->next); instr = GoForward(curr); @@ -758,7 +758,7 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) // CHKREF, ADDSi -> ADDSi // CHKREF, RDSPtr -> RDSPtr if( curr->next && - (curr->next->op == asBC_ADDSi || curr->next->op == asBC_RDSPtr) ) + (curr->next->op == asBC_ADDSi || curr->next->op == asBC_RDSPtr) ) { // As ADDSi & RDSPtr already checks the pointer the CHKREF instruction is unnecessary instr = GoForward(DeleteInstruction(curr)); @@ -767,9 +767,9 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) // PGA, CHKREF -> PGA // PSF, CHKREF -> PSF else if( instr && - (instr->op == asBC_ADDSi || - instr->op == asBC_PGA || - instr->op == asBC_PSF) ) + (instr->op == asBC_ADDSi || + instr->op == asBC_PGA || + instr->op == asBC_PSF) ) { // ADDSi is guaranteed to work on valid pointers so CHKREF is not necessary. // PGA and PSF always pushes a valid address on the stack. @@ -777,7 +777,7 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) } // PGA, ChkRefS, CHKREF -> PGA, ChkRefS else if( instr && instr->op == asBC_ChkRefS && - instr->prev && instr->prev->op == asBC_PGA ) + instr->prev && instr->prev->op == asBC_PGA ) { // Delete CHKREF since PGA always pushes a valid address on the stack instr = GoForward(DeleteInstruction(curr)); @@ -792,12 +792,12 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) } // PshNull, RefCpyV, PopPtr -> FREE else if( instr && instr->op == asBC_RefCpyV && - instr->prev && instr->prev->op == asBC_PshNull ) + instr->prev && instr->prev->op == asBC_PshNull ) { DeleteInstruction(curr); DeleteInstruction(instr->prev); instr->op = asBC_FREE; - instr = GoForward(instr); + instr = GoForward(instr); } // PshVPtr y, PopPtr -> nothing // PSF y , PopPtr -> nothing @@ -805,11 +805,11 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) // PshNull , PopPtr -> nothing // PshRPtr , PopPtr -> nothing else if( instr && - (instr->op == asBC_PshRPtr || - instr->op == asBC_PSF || - instr->op == asBC_VAR || - instr->op == asBC_PshVPtr || - instr->op == asBC_PshNull) ) + (instr->op == asBC_PshRPtr || + instr->op == asBC_PSF || + instr->op == asBC_VAR || + instr->op == asBC_PshVPtr || + instr->op == asBC_PshNull) ) { // A pointer is pushed on the stack then immediately removed // Remove both instructions as they cancel each other @@ -818,10 +818,10 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) } // PSF, ChkRefS, PopPtr -> ChkNullV else if( instr && instr->op == asBC_ChkRefS && - instr->prev && instr->prev->op == asBC_PSF ) + instr->prev && instr->prev->op == asBC_PSF ) { - instr = instr->prev; - instr->op = asBC_ChkNullV; + instr = instr->prev; + instr->op = asBC_ChkNullV; instr->stackInc = 0; // Delete the PopPtr instruction DeleteInstruction(curr); @@ -831,10 +831,10 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) } // PshVPtr, CHKREF, PopPtr -> ChkNullV else if( instr && instr->op == asBC_CHKREF && - instr->prev && instr->prev->op == asBC_PshVPtr ) + instr->prev && instr->prev->op == asBC_PshVPtr ) { - instr = instr->prev; - instr->op = asBC_ChkNullV; + instr = instr->prev; + instr->op = asBC_ChkNullV; instr->stackInc = 0; DeleteInstruction(curr->prev); DeleteInstruction(curr); @@ -848,22 +848,22 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) i = i->prev; if( !i || i->op != asBC_PSF ) continue; short x = i->wArg[0]; - i = i->prev; + i = i->prev; if( !i || i->op != asBC_RDSPtr ) continue; i = i->prev; if( !i || i->op != asBC_PSF ) continue; short y = i->wArg[0]; - i = i->prev; + i = i->prev; if( !i || i->op != asBC_STOREOBJ || i->wArg[0] != y ) continue; // Don't do the substitution if the var y is not a temporary, or if it is used after PopPtr if( !IsTemporary(y) || IsTempVarRead(curr, y) ) continue; // Transform the PopPtr into STOREOBJ - curr->op = asBC_STOREOBJ; + curr->op = asBC_STOREOBJ; curr->stackInc = 0; - curr->wArg[0] = x; - curr->size = i->size; + curr->wArg[0] = x; + curr->size = i->size; // Change arg of the FREE to x // TODO: runtime optimize: The FREE instruction shouldn't be necessary. STOREOBJ should free the previous value by itself @@ -893,23 +893,23 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) { // This exchange removes one pointer dereference, and also // makes it easier to completely remove the CHKREF instruction - curr->op = asBC_CHKREF; + curr->op = asBC_CHKREF; instr->op = asBC_RDSPtr; - instr = GoForward(curr); + instr = GoForward(curr); } // PSF, RDSPtr -> PshVPtr else if( instr && instr->op == asBC_PSF ) { instr->op = asBC_PshVPtr; - instr = GoForward(DeleteInstruction(curr)); + instr = GoForward(DeleteInstruction(curr)); } // PSF, ChkRefS, RDSPtr -> PshVPtr, CHKREF else if( instr && instr->op == asBC_ChkRefS && - instr->prev && instr->prev->op == asBC_PSF ) + instr->prev && instr->prev->op == asBC_PSF ) { instr->prev->op = asBC_PshVPtr; - instr->op = asBC_CHKREF; - instr = GoForward(DeleteInstruction(curr)); + instr->op = asBC_CHKREF; + instr = GoForward(DeleteInstruction(curr)); } } else if( currOp == asBC_PopRPtr ) @@ -926,29 +926,29 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) // TODO: runtime optimize: PshVPtr x, PopRPtr -> LoadRObjR x, 0 // PshVPtr x, ADDSi, PopRPtr -> LoadRObjR else if( instr && instr->op == asBC_ADDSi && - instr->prev && instr->prev->op == asBC_PshVPtr && - instr->prev->wArg[0] != 0 ) + instr->prev && instr->prev->op == asBC_PshVPtr && + instr->prev->wArg[0] != 0 ) { - instr = instr->prev; - instr->op = asBC_LoadRObjR; - instr->size = asBCTypeSize[asBCInfo[asBC_LoadRObjR].type]; - instr->stackInc = asBCInfo[asBC_LoadRObjR].stackInc; - instr->wArg[1] = instr->next->wArg[0]; - *(asDWORD*)&instr->arg = *(asDWORD*)&instr->next->arg; + instr = instr->prev; + instr->op = asBC_LoadRObjR; + instr->size = asBCTypeSize[asBCInfo[asBC_LoadRObjR].type]; + instr->stackInc = asBCInfo[asBC_LoadRObjR].stackInc; + instr->wArg[1] = instr->next->wArg[0]; + *(asDWORD *)&instr->arg = *(asDWORD *)&instr->next->arg; DeleteInstruction(instr->next); DeleteInstruction(curr); instr = GoForward(instr); } // PSF x, ADDSi, PopRPtr -> LoadVObjR else if( instr && instr->op == asBC_ADDSi && - instr->prev && instr->prev->op == asBC_PSF ) + instr->prev && instr->prev->op == asBC_PSF ) { - instr = instr->prev; - instr->op = asBC_LoadVObjR; - instr->size = asBCTypeSize[asBCInfo[asBC_LoadVObjR].type]; - instr->stackInc = asBCInfo[asBC_LoadVObjR].stackInc; - instr->wArg[1] = instr->next->wArg[0]; - *(asDWORD*)&instr->arg = *(asDWORD*)&instr->next->arg; + instr = instr->prev; + instr->op = asBC_LoadVObjR; + instr->size = asBCTypeSize[asBCInfo[asBC_LoadVObjR].type]; + instr->stackInc = asBCInfo[asBC_LoadVObjR].stackInc; + instr->wArg[1] = instr->next->wArg[0]; + *(asDWORD *)&instr->arg = *(asDWORD *)&instr->next->arg; DeleteInstruction(instr->next); DeleteInstruction(curr); instr = GoForward(instr); @@ -959,8 +959,8 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) // PSF x, REFCPY -> RefCpyV x if( instr && instr->op == asBC_PSF ) { - curr->op = asBC_RefCpyV; - curr->wArg[0] = instr->wArg[0]; + curr->op = asBC_RefCpyV; + curr->wArg[0] = instr->wArg[0]; curr->stackInc = asBCInfo[asBC_LoadVObjR].stackInc; DeleteInstruction(instr); instr = GoForward(curr); @@ -973,19 +973,19 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) (instr->op == asBC_TNZ && (currOp == asBC_JNZ || currOp == asBC_JLowNZ)) ) instr = GoForward(DeleteFirstChangeNext(instr, asBC_JNZ)); else if( (instr->op == asBC_TNZ && (currOp == asBC_JZ || currOp == asBC_JLowZ)) || - (instr->op == asBC_TZ && (currOp == asBC_JNZ || currOp == asBC_JLowNZ)) ) + (instr->op == asBC_TZ && (currOp == asBC_JNZ || currOp == asBC_JLowNZ)) ) instr = GoForward(DeleteFirstChangeNext(instr, asBC_JZ)); else if( (instr->op == asBC_TS && (currOp == asBC_JZ || currOp == asBC_JLowZ)) || - (instr->op == asBC_TNS && (currOp == asBC_JNZ || currOp == asBC_JLowNZ)) ) + (instr->op == asBC_TNS && (currOp == asBC_JNZ || currOp == asBC_JLowNZ)) ) instr = GoForward(DeleteFirstChangeNext(instr, asBC_JNS)); else if( (instr->op == asBC_TNS && (currOp == asBC_JZ || currOp == asBC_JLowZ)) || - (instr->op == asBC_TS && (currOp == asBC_JNZ || currOp == asBC_JLowNZ)) ) + (instr->op == asBC_TS && (currOp == asBC_JNZ || currOp == asBC_JLowNZ)) ) instr = GoForward(DeleteFirstChangeNext(instr, asBC_JS)); else if( (instr->op == asBC_TP && (currOp == asBC_JZ || currOp == asBC_JLowZ)) || - (instr->op == asBC_TNP && (currOp == asBC_JNZ || currOp == asBC_JLowNZ)) ) + (instr->op == asBC_TNP && (currOp == asBC_JNZ || currOp == asBC_JLowNZ)) ) instr = GoForward(DeleteFirstChangeNext(instr, asBC_JNP)); else if( (instr->op == asBC_TNP && (currOp == asBC_JZ || currOp == asBC_JLowZ)) || - (instr->op == asBC_TP && (currOp == asBC_JNZ || currOp == asBC_JLowNZ)) ) + (instr->op == asBC_TP && (currOp == asBC_JNZ || currOp == asBC_JLowNZ)) ) instr = GoForward(DeleteFirstChangeNext(instr, asBC_JP)); } else if( currOp == asBC_FREE && instr ) @@ -1016,8 +1016,8 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) { // VAR, PSF, GETOBJREF {PTR_SIZE} -> PshVPtr, PSF if( curr->next && curr->next->op == asBC_PSF && - curr->next->next && curr->next->next->op == asBC_GETOBJREF && - curr->next->next->wArg[0] == AS_PTR_SIZE ) + curr->next->next && curr->next->next->op == asBC_GETOBJREF && + curr->next->next->wArg[0] == AS_PTR_SIZE ) { curr->op = asBC_PshVPtr; DeleteInstruction(curr->next->next); @@ -1037,8 +1037,8 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) } // VAR, PSF, GETREF {PTR_SIZE} -> PSF, PSF if( curr->next && curr->next->op == asBC_PSF && - curr->next->next && curr->next->next->op == asBC_GETREF && - curr->next->next->wArg[0] == AS_PTR_SIZE ) + curr->next->next && curr->next->next->op == asBC_GETREF && + curr->next->next->wArg[0] == AS_PTR_SIZE ) { curr->op = asBC_PSF; DeleteInstruction(curr->next->next); @@ -1056,7 +1056,7 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) // Let's look for a trivial RefCpyV to that temporary variable, and a Free of the original // variable. If this is found, then we can simply load the original value into the register // and avoid both the RefCpy and the Free. - short tempVar = last->wArg[0]; + short tempVar = last->wArg[0]; asCArray freedVars; instr = last->prev; @@ -1081,7 +1081,7 @@ void asCByteCode::OptimizeLocally(const asCArray &tempVariableOffsets) if( instr && instr->op == asBC_PshVPtr && freedVars.Exists(instr->wArg[0]) ) { // Update the LOADOBJ to load the local variable directly - tempVar = instr->wArg[0]; + tempVar = instr->wArg[0]; last->wArg[0] = tempVar; // Remove the copy of the local variable into the temp @@ -1123,7 +1123,7 @@ void asCByteCode::Optimize() while( instr ) { asCByteInstruction *curr = instr; - instr = instr->next; + instr = instr->next; const asEBCInstr currOp = curr->op; @@ -1179,7 +1179,7 @@ void asCByteCode::Optimize() instr = GoBack(DeleteInstruction(curr)); } // LINE, VarDecl, LINE -> VarDecl, LINE - else if (instrOp == asBC_VarDecl && instr->next && instr->next->op == asBC_LINE ) + else if( instrOp == asBC_VarDecl && instr->next && instr->next->op == asBC_LINE ) { // Delete the first instruction instr = GoBack(DeleteInstruction(curr)); @@ -1198,7 +1198,7 @@ void asCByteCode::Optimize() } } // JMP +0 -> remove - else if( currOp == asBC_JMP && instrOp == asBC_LABEL && *(int*)&curr->arg == instr->wArg[0] ) + else if( currOp == asBC_JMP && instrOp == asBC_LABEL && *(int *)&curr->arg == instr->wArg[0] ) instr = GoBack(DeleteInstruction(curr)); } } @@ -1208,25 +1208,25 @@ bool asCByteCode::IsTempVarReadByInstr(asCByteInstruction *curr, int offset) { // Which instructions read from variables? if( asBCInfo[curr->op].type == asBCTYPE_wW_rW_rW_ARG && - (int(curr->wArg[1]) == offset || int(curr->wArg[2]) == offset) ) + (int(curr->wArg[1]) == offset || int(curr->wArg[2]) == offset) ) return true; - else if( (asBCInfo[curr->op].type == asBCTYPE_rW_ARG || - asBCInfo[curr->op].type == asBCTYPE_rW_DW_ARG || - asBCInfo[curr->op].type == asBCTYPE_rW_QW_ARG || - asBCInfo[curr->op].type == asBCTYPE_rW_W_DW_ARG || - asBCInfo[curr->op].type == asBCTYPE_rW_DW_DW_ARG || - curr->op == asBC_FREE) && // FREE both read and write to the variable - int(curr->wArg[0]) == offset ) + else if( (asBCInfo[curr->op].type == asBCTYPE_rW_ARG || + asBCInfo[curr->op].type == asBCTYPE_rW_DW_ARG || + asBCInfo[curr->op].type == asBCTYPE_rW_QW_ARG || + asBCInfo[curr->op].type == asBCTYPE_rW_W_DW_ARG || + asBCInfo[curr->op].type == asBCTYPE_rW_DW_DW_ARG || + curr->op == asBC_FREE) && // FREE both read and write to the variable + int(curr->wArg[0]) == offset ) return true; else if( (asBCInfo[curr->op].type == asBCTYPE_wW_rW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_rW_DW_ARG) && - int(curr->wArg[1]) == offset ) + asBCInfo[curr->op].type == asBCTYPE_wW_rW_DW_ARG) && + int(curr->wArg[1]) == offset ) return true; else if( asBCInfo[curr->op].type == asBCTYPE_rW_rW_ARG && - (int(curr->wArg[0]) == offset || int(curr->wArg[1]) == offset) ) + (int(curr->wArg[0]) == offset || int(curr->wArg[1]) == offset) ) return true; else if( asBCInfo[curr->op].type == asBCTYPE_W_rW_ARG && - int(curr->wArg[1]) == offset ) + int(curr->wArg[1]) == offset ) return true; else if( curr->op == asBC_LoadThisR && offset == 0 ) return true; @@ -1236,17 +1236,17 @@ bool asCByteCode::IsTempVarReadByInstr(asCByteInstruction *curr, int offset) bool asCByteCode::IsInstrJmpOrLabel(asCByteInstruction *curr) { - if( curr->op == asBC_JS || - curr->op == asBC_JNS || - curr->op == asBC_JP || - curr->op == asBC_JNP || - curr->op == asBC_JMPP || - curr->op == asBC_JMP || - curr->op == asBC_JZ || - curr->op == asBC_JNZ || - curr->op == asBC_JLowZ || - curr->op == asBC_JLowNZ || - curr->op == asBC_LABEL ) + if( curr->op == asBC_JS || + curr->op == asBC_JNS || + curr->op == asBC_JP || + curr->op == asBC_JNP || + curr->op == asBC_JMPP || + curr->op == asBC_JMP || + curr->op == asBC_JZ || + curr->op == asBC_JNZ || + curr->op == asBC_JLowZ || + curr->op == asBC_JLowNZ || + curr->op == asBC_LABEL ) return true; return false; @@ -1255,17 +1255,17 @@ bool asCByteCode::IsInstrJmpOrLabel(asCByteInstruction *curr) bool asCByteCode::IsTempVarOverwrittenByInstr(asCByteInstruction *curr, int offset) { // Which instructions overwrite the variable or discard it? - if( curr->op == asBC_RET || - curr->op == asBC_SUSPEND ) + if( curr->op == asBC_RET || + curr->op == asBC_SUSPEND ) return true; else if( (asBCInfo[curr->op].type == asBCTYPE_wW_rW_rW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_rW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_rW_DW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_W_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_DW_ARG || - asBCInfo[curr->op].type == asBCTYPE_wW_QW_ARG) && - int(curr->wArg[0]) == offset ) + asBCInfo[curr->op].type == asBCTYPE_wW_rW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_rW_DW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_W_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_DW_ARG || + asBCInfo[curr->op].type == asBCTYPE_wW_QW_ARG) && + int(curr->wArg[0]) == offset ) return true; return false; @@ -1301,29 +1301,29 @@ bool asCByteCode::IsTempVarRead(asCByteInstruction *curr, int offset) // Find the destination. If it cannot be found it is because we're doing a localized // optimization and the label hasn't been added to the final bytecode yet - int label = *((int*)ARG_DW(curr->arg)); - int r = FindLabel(label, curr, &curr, 0); + int label = *((int *)ARG_DW(curr->arg)); + int r = FindLabel(label, curr, &curr, 0); if( r >= 0 && - !closedPaths.Exists(curr) && - !openPaths.Exists(curr) ) + !closedPaths.Exists(curr) && + !openPaths.Exists(curr) ) openPaths.PushLast(curr); break; } - else if( curr->op == asBC_JZ || curr->op == asBC_JNZ || - curr->op == asBC_JS || curr->op == asBC_JNS || - curr->op == asBC_JP || curr->op == asBC_JNP || - curr->op == asBC_JLowZ || curr->op == asBC_JLowNZ ) + else if( curr->op == asBC_JZ || curr->op == asBC_JNZ || + curr->op == asBC_JS || curr->op == asBC_JNS || + curr->op == asBC_JP || curr->op == asBC_JNP || + curr->op == asBC_JLowZ || curr->op == asBC_JLowNZ ) { // Find the destination. If it cannot be found it is because we're doing a localized // optimization and the label hasn't been added to the final bytecode yet - asCByteInstruction *dest = 0; - int label = *((int*)ARG_DW(curr->arg)); - int r = FindLabel(label, curr, &dest, 0); + asCByteInstruction *dest = 0; + int label = *((int *)ARG_DW(curr->arg)); + int r = FindLabel(label, curr, &dest, 0); if( r >= 0 && - !closedPaths.Exists(dest) && - !openPaths.Exists(dest) ) + !closedPaths.Exists(dest) && + !openPaths.Exists(dest) ) openPaths.PushLast(dest); } else if( curr->op == asBC_JMPP ) @@ -1337,12 +1337,12 @@ bool asCByteCode::IsTempVarRead(asCByteInstruction *curr, int offset) // Find the destination. If it cannot be found it is because we're doing a localized // optimization and the label hasn't been added to the final bytecode yet - asCByteInstruction *dest = 0; - int label = *((int*)ARG_DW(curr->arg)); - int r = FindLabel(label, curr, &dest, 0); + asCByteInstruction *dest = 0; + int label = *((int *)ARG_DW(curr->arg)); + int r = FindLabel(label, curr, &dest, 0); if( r >= 0 && - !closedPaths.Exists(dest) && - !openPaths.Exists(dest) ) + !closedPaths.Exists(dest) && + !openPaths.Exists(dest) ) openPaths.PushLast(dest); curr = curr->next; @@ -1371,73 +1371,73 @@ bool asCByteCode::IsTempRegUsed(asCByteInstruction *curr) curr = curr->next; // Which instructions read from the register? - if( curr->op == asBC_INCi || - curr->op == asBC_INCi16 || - curr->op == asBC_INCi8 || - curr->op == asBC_INCf || - curr->op == asBC_INCd || - curr->op == asBC_DECi || - curr->op == asBC_DECi16 || - curr->op == asBC_DECi8 || - curr->op == asBC_DECf || - curr->op == asBC_DECd || - curr->op == asBC_WRTV1 || - curr->op == asBC_WRTV2 || - curr->op == asBC_WRTV4 || - curr->op == asBC_WRTV8 || - curr->op == asBC_RDR1 || - curr->op == asBC_RDR2 || - curr->op == asBC_RDR4 || - curr->op == asBC_RDR8 || - curr->op == asBC_PshRPtr || - curr->op == asBC_CpyRtoV4 || - curr->op == asBC_CpyRtoV8 || - curr->op == asBC_TZ || - curr->op == asBC_TNZ || - curr->op == asBC_TS || - curr->op == asBC_TNS || - curr->op == asBC_TP || - curr->op == asBC_TNP || - curr->op == asBC_JZ || - curr->op == asBC_JNZ || - curr->op == asBC_JLowZ || - curr->op == asBC_JLowNZ || - curr->op == asBC_JS || - curr->op == asBC_JNS || - curr->op == asBC_JP || - curr->op == asBC_JNP || - curr->op == asBC_JMPP || // TODO: JMP and JMPP cannot be said to read the temporary register. Need to follow the branch to determine what happens next - curr->op == asBC_JMP ) + if( curr->op == asBC_INCi || + curr->op == asBC_INCi16 || + curr->op == asBC_INCi8 || + curr->op == asBC_INCf || + curr->op == asBC_INCd || + curr->op == asBC_DECi || + curr->op == asBC_DECi16 || + curr->op == asBC_DECi8 || + curr->op == asBC_DECf || + curr->op == asBC_DECd || + curr->op == asBC_WRTV1 || + curr->op == asBC_WRTV2 || + curr->op == asBC_WRTV4 || + curr->op == asBC_WRTV8 || + curr->op == asBC_RDR1 || + curr->op == asBC_RDR2 || + curr->op == asBC_RDR4 || + curr->op == asBC_RDR8 || + curr->op == asBC_PshRPtr || + curr->op == asBC_CpyRtoV4 || + curr->op == asBC_CpyRtoV8 || + curr->op == asBC_TZ || + curr->op == asBC_TNZ || + curr->op == asBC_TS || + curr->op == asBC_TNS || + curr->op == asBC_TP || + curr->op == asBC_TNP || + curr->op == asBC_JZ || + curr->op == asBC_JNZ || + curr->op == asBC_JLowZ || + curr->op == asBC_JLowNZ || + curr->op == asBC_JS || + curr->op == asBC_JNS || + curr->op == asBC_JP || + curr->op == asBC_JNP || + curr->op == asBC_JMPP || // TODO: JMP and JMPP cannot be said to read the temporary register. Need to follow the branch to determine what happens next + curr->op == asBC_JMP ) return true; // Which instructions overwrite the register or discard the value? - if( curr->op == asBC_CALL || - curr->op == asBC_PopRPtr || - curr->op == asBC_CALLSYS || - curr->op == asBC_CALLBND || - curr->op == asBC_Thiscall1 || - curr->op == asBC_SUSPEND || - curr->op == asBC_ALLOC || - curr->op == asBC_CpyVtoR4 || - curr->op == asBC_LdGRdR4 || - curr->op == asBC_LDG || - curr->op == asBC_LDV || - curr->op == asBC_TZ || - curr->op == asBC_TNZ || - curr->op == asBC_TS || - curr->op == asBC_TNS || - curr->op == asBC_TP || - curr->op == asBC_TNP || - curr->op == asBC_CMPi || - curr->op == asBC_CMPu || - curr->op == asBC_CMPf || - curr->op == asBC_CMPd || - curr->op == asBC_CMPIi || - curr->op == asBC_CMPIu || - curr->op == asBC_CMPIf || - curr->op == asBC_LoadThisR || - curr->op == asBC_LoadRObjR || - curr->op == asBC_LoadVObjR ) + if( curr->op == asBC_CALL || + curr->op == asBC_PopRPtr || + curr->op == asBC_CALLSYS || + curr->op == asBC_CALLBND || + curr->op == asBC_Thiscall1 || + curr->op == asBC_SUSPEND || + curr->op == asBC_ALLOC || + curr->op == asBC_CpyVtoR4 || + curr->op == asBC_LdGRdR4 || + curr->op == asBC_LDG || + curr->op == asBC_LDV || + curr->op == asBC_TZ || + curr->op == asBC_TNZ || + curr->op == asBC_TS || + curr->op == asBC_TNS || + curr->op == asBC_TP || + curr->op == asBC_TNP || + curr->op == asBC_CMPi || + curr->op == asBC_CMPu || + curr->op == asBC_CMPf || + curr->op == asBC_CMPd || + curr->op == asBC_CMPIi || + curr->op == asBC_CMPIu || + curr->op == asBC_CMPIf || + curr->op == asBC_LoadThisR || + curr->op == asBC_LoadRObjR || + curr->op == asBC_LoadVObjR ) return false; } @@ -1452,15 +1452,15 @@ bool asCByteCode::IsSimpleExpression() while( instr ) { if( instr->op == asBC_ALLOC || - instr->op == asBC_CALL || - instr->op == asBC_CALLSYS || - instr->op == asBC_SUSPEND || - instr->op == asBC_LINE || - instr->op == asBC_FREE || - instr->op == asBC_CallPtr || - instr->op == asBC_CALLINTF || - instr->op == asBC_CALLBND || - instr->op == asBC_Thiscall1 ) + instr->op == asBC_CALL || + instr->op == asBC_CALLSYS || + instr->op == asBC_SUSPEND || + instr->op == asBC_LINE || + instr->op == asBC_FREE || + instr->op == asBC_CallPtr || + instr->op == asBC_CALLINTF || + instr->op == asBC_CALLBND || + instr->op == asBC_Thiscall1 ) return false; instr = instr->next; @@ -1476,13 +1476,13 @@ void asCByteCode::ExtractLineNumbers() TimeIt("asCByteCode::ExtractLineNumbers"); - int lastLinePos = -1; - int pos = 0; - asCByteInstruction *instr = first; + int lastLinePos = -1; + int pos = 0; + asCByteInstruction *instr = first; while( instr ) { asCByteInstruction *curr = instr; - instr = instr->next; + instr = instr->next; if( curr->op == asBC_LINE ) { @@ -1495,15 +1495,15 @@ void asCByteCode::ExtractLineNumbers() lastLinePos = pos; lineNumbers.PushLast(pos); - lineNumbers.PushLast(*(int*)ARG_DW(curr->arg)); - sectionIdxs.PushLast(*((int*)ARG_DW(curr->arg)+1)); + lineNumbers.PushLast(*(int *)ARG_DW(curr->arg)); + sectionIdxs.PushLast(*((int *)ARG_DW(curr->arg) + 1)); // Check if this is the first instruction in the function - asCByteInstruction* c = curr->prev; - while (c && (c->op == asBC_VarDecl || c->op == asBC_ObjInfo)) + asCByteInstruction *c = curr->prev; + while( c && (c->op == asBC_VarDecl || c->op == asBC_ObjInfo) ) c = c->prev; - if (c == 0) + if( c == 0 ) { // Delete the first asBC_SUSPEND instruction in the function since it is not needed, given that // the asCContext::PrepareScriptFunction will anyway call the line callback to allow suspending. @@ -1512,9 +1512,9 @@ void asCByteCode::ExtractLineNumbers() else if( !engine->ep.buildWithoutLineCues ) { // Transform BC_LINE into BC_SUSPEND - curr->op = asBC_SUSPEND; - curr->size = asBCTypeSize[asBCInfo[asBC_SUSPEND].type]; - pos += curr->size; + curr->op = asBC_SUSPEND; + curr->size = asBCTypeSize[asBCInfo[asBC_SUSPEND].type]; + pos += curr->size; } else { @@ -1531,9 +1531,9 @@ void asCByteCode::ExtractObjectVariableInfo(asCScriptFunction *outFunc) { asASSERT( outFunc->scriptData ); - unsigned int pos = 0; - asCByteInstruction *instr = first; - int blockLevel = 0; + unsigned int pos = 0; + asCByteInstruction *instr = first; + int blockLevel = 0; while( instr ) { if( instr->op == asBC_Block ) @@ -1551,8 +1551,8 @@ void asCByteCode::ExtractObjectVariableInfo(asCScriptFunction *outFunc) { blockLevel--; asASSERT( blockLevel >= 0 ); - if( outFunc->scriptData->objVariableInfo[outFunc->scriptData->objVariableInfo.GetLength()-1].option == asBLOCK_BEGIN && - outFunc->scriptData->objVariableInfo[outFunc->scriptData->objVariableInfo.GetLength()-1].programPos == pos ) + if( outFunc->scriptData->objVariableInfo[outFunc->scriptData->objVariableInfo.GetLength() - 1].option == asBLOCK_BEGIN && + outFunc->scriptData->objVariableInfo[outFunc->scriptData->objVariableInfo.GetLength() - 1].programPos == pos ) outFunc->scriptData->objVariableInfo.PopLast(); else outFunc->scriptData->objVariableInfo.PushLast(info); @@ -1563,14 +1563,14 @@ void asCByteCode::ExtractObjectVariableInfo(asCScriptFunction *outFunc) asSObjectVariableInfo info; info.programPos = pos; info.variableOffset = (short)instr->wArg[0]; - info.option = (asEObjVarInfoOption)*(int*)ARG_DW(instr->arg); + info.option = (asEObjVarInfoOption) * (int *)ARG_DW(instr->arg); outFunc->scriptData->objVariableInfo.PushLast(info); } else if( instr->op == asBC_VarDecl ) { // Record the position for debug info outFunc->scriptData->variables[instr->wArg[0]]->declaredAtProgramPos = pos; - + // Record declaration of object variables for try/catch handling // This is used for identifying if handles and objects on the heap should be cleared upon catching an exception // Only extract this info if there is a try/catch block in the function, so we don't use up unnecessary space @@ -1595,11 +1595,11 @@ void asCByteCode::ExtractTryCatchInfo(asCScriptFunction *outFunc) { asASSERT(outFunc->scriptData); - unsigned int pos = 0; + unsigned int pos = 0; asCByteInstruction *instr = first; - while (instr) + while( instr ) { - if (instr->op == asBC_TryBlock) + if( instr->op == asBC_TryBlock ) { asSTryCatchInfo info; info.tryPos = pos; @@ -1608,14 +1608,14 @@ void asCByteCode::ExtractTryCatchInfo(asCScriptFunction *outFunc) outFunc->scriptData->tryCatchInfo.PushLast(info); } - pos += instr->size; - instr = instr->next; + pos += instr->size; + instr = instr->next; } } int asCByteCode::GetSize() { - int size = 0; + int size = 0; asCByteInstruction *instr = first; while( instr ) { @@ -1634,18 +1634,18 @@ void asCByteCode::AddCode(asCByteCode *bc) { if( first == 0 ) { - first = bc->first; - last = bc->last; + first = bc->first; + last = bc->last; bc->first = 0; - bc->last = 0; + bc->last = 0; } else { - last->next = bc->first; + last->next = bc->first; bc->first->prev = last; - last = bc->last; - bc->first = 0; - bc->last = 0; + last = bc->last; + bc->first = 0; + bc->last = 0; } } } @@ -1659,7 +1659,7 @@ int asCByteCode::AddInstruction() return 0; } - asCByteInstruction *instr = new(ptr) asCByteInstruction(); + asCByteInstruction *instr = new (ptr) asCByteInstruction(); if( first == 0 ) { first = last = instr; @@ -1682,7 +1682,7 @@ int asCByteCode::AddInstructionFirst() return 0; } - asCByteInstruction *instr = new(ptr) asCByteInstruction(); + asCByteInstruction *instr = new (ptr) asCByteInstruction(); if( first == 0 ) { first = last = instr; @@ -1703,14 +1703,14 @@ void asCByteCode::Call(asEBCInstr instr, int funcID, int pop, asWORD argCount) asASSERT(asBCInfo[instr].type == asBCTYPE_DW_ARG || asBCInfo[instr].type == asBCTYPE_W_DW_ARG); - last->op = instr; - last->size = asBCTypeSize[asBCInfo[instr].type]; - last->stackInc = -pop; // BC_CALL and BC_CALLBND doesn't pop the argument but when the callee returns the arguments are already popped - *((int*)ARG_DW(last->arg)) = funcID; - last->wArg[0] = argCount; // Store the argument count for variadic functions for bytecode serialization and exception handling + last->op = instr; + last->size = asBCTypeSize[asBCInfo[instr].type]; + last->stackInc = -pop; // BC_CALL and BC_CALLBND doesn't pop the argument but when the callee returns the arguments are already popped + *((int *)ARG_DW(last->arg)) = funcID; + last->wArg[0] = argCount; // Store the argument count for variadic functions for bytecode serialization and exception handling - // Add a JitEntry instruction after function calls so that JIT's can resume execution - InstrPTR(asBC_JitEntry, 0); + // Add a JitEntry instruction after function calls so that JIT's can resume execution + InstrPTR(asBC_JitEntry, 0); } void asCByteCode::CallPtr(asEBCInstr instr, int funcPtrVar, int pop, asWORD argCount) @@ -1720,14 +1720,14 @@ void asCByteCode::CallPtr(asEBCInstr instr, int funcPtrVar, int pop, asWORD argC asASSERT(asBCInfo[instr].type == asBCTYPE_W_rW_ARG); - last->op = instr; - last->size = asBCTypeSize[asBCInfo[instr].type]; + last->op = instr; + last->size = asBCTypeSize[asBCInfo[instr].type]; last->stackInc = -pop; - last->wArg[1] = (short)funcPtrVar; - last->wArg[0] = argCount; // Store the argument count for variadic functions as a hint for bytecode serialization and exception handling + last->wArg[1] = (short)funcPtrVar; + last->wArg[0] = argCount; // Store the argument count for variadic functions as a hint for bytecode serialization and exception handling - // Add a JitEntry instruction after function calls so that JIT's can resume execution - InstrPTR(asBC_JitEntry, 0); + // Add a JitEntry instruction after function calls so that JIT's can resume execution + InstrPTR(asBC_JitEntry, 0); } void asCByteCode::Alloc(asEBCInstr instr, void *objID, int funcID, int pop, asWORD argCount) @@ -1735,17 +1735,17 @@ void asCByteCode::Alloc(asEBCInstr instr, void *objID, int funcID, int pop, asWO if( AddInstruction() < 0 ) return; - last->op = instr; - last->size = asBCTypeSize[asBCInfo[instr].type]; + last->op = instr; + last->size = asBCTypeSize[asBCInfo[instr].type]; last->stackInc = -pop; // BC_ALLOC asASSERT(asBCInfo[instr].type == asBCTYPE_W_PTR_DW_ARG); - *ARG_PTR(last->arg) = (asPWORD)objID; - *((int*)(ARG_DW(last->arg)+AS_PTR_SIZE)) = funcID; - last->wArg[0] = argCount; // Store the argument count for variadic functions for bytecode serialization and exception handling + *ARG_PTR(last->arg) = (asPWORD)objID; + *((int *)(ARG_DW(last->arg) + AS_PTR_SIZE)) = funcID; + last->wArg[0] = argCount; // Store the argument count for variadic functions for bytecode serialization and exception handling - // Add a JitEntry instruction after function calls so that JIT's can resume execution - InstrPTR(asBC_JitEntry, 0); + // Add a JitEntry instruction after function calls so that JIT's can resume execution + InstrPTR(asBC_JitEntry, 0); } void asCByteCode::Ret(int pop) @@ -1755,10 +1755,10 @@ void asCByteCode::Ret(int pop) asASSERT(asBCInfo[asBC_RET].type == asBCTYPE_W_ARG); - last->op = asBC_RET; - last->size = asBCTypeSize[asBCInfo[asBC_RET].type]; + last->op = asBC_RET; + last->size = asBCTypeSize[asBCInfo[asBC_RET].type]; last->stackInc = 0; // The instruction pops the argument, but it doesn't affect current function - last->wArg[0] = (short)pop; + last->wArg[0] = (short)pop; } void asCByteCode::JmpP(int var, asDWORD max) @@ -1793,19 +1793,19 @@ void asCByteCode::Line(int line, int column, int scriptIdx) if( AddInstruction() < 0 ) return; - last->op = asBC_LINE; + last->op = asBC_LINE; // If the build is without line cues these instructions will be removed // otherwise they will be transformed into SUSPEND instructions. if( engine->ep.buildWithoutLineCues ) last->size = 0; else last->size = asBCTypeSize[asBCInfo[asBC_SUSPEND].type]; - last->stackInc = 0; - *((int*)ARG_DW(last->arg)) = (line & 0xFFFFF)|((column & 0xFFF)<<20); - *((int*)ARG_DW(last->arg)+1) = scriptIdx; + last->stackInc = 0; + *((int *)ARG_DW(last->arg)) = (line & 0xFFFFF) | ((column & 0xFFF) << 20); + *((int *)ARG_DW(last->arg) + 1) = scriptIdx; - // Add a JitEntry after the line instruction to allow the JIT function to resume after a suspend - InstrPTR(asBC_JitEntry, 0); + // Add a JitEntry after the line instruction to allow the JIT function to resume after a suspend + InstrPTR(asBC_JitEntry, 0); } void asCByteCode::ObjInfo(int offset, int info) @@ -1815,11 +1815,11 @@ void asCByteCode::ObjInfo(int offset, int info) // Add the special instruction that will be used to tell the exception // handler when an object is initialized and deinitialized. - last->op = asBC_ObjInfo; - last->size = 0; - last->stackInc = 0; - last->wArg[0] = (short)offset; - *((int*)ARG_DW(last->arg)) = info; + last->op = asBC_ObjInfo; + last->size = 0; + last->stackInc = 0; + last->wArg[0] = (short)offset; + *((int *)ARG_DW(last->arg)) = info; } void asCByteCode::Block(bool start) @@ -1835,12 +1835,12 @@ void asCByteCode::Block(bool start) void asCByteCode::TryBlock(short catchLabel) { - if (AddInstruction() < 0) + if( AddInstruction() < 0 ) return; - last->op = asBC_TryBlock; - last->size = 0; - last->stackInc = 0; + last->op = asBC_TryBlock; + last->size = 0; + last->stackInc = 0; *ARG_DW(last->arg) = catchLabel; } @@ -1865,8 +1865,8 @@ int asCByteCode::FindLabel(int label, asCByteInstruction *from, asCByteInstructi asCByteInstruction *labelInstr = from; while( labelInstr ) { - labelPos += labelInstr->GetSize(); - labelInstr = labelInstr->next; + labelPos += labelInstr->GetSize(); + labelInstr = labelInstr->next; if( labelInstr && labelInstr->op == asBC_LABEL ) { @@ -1916,36 +1916,36 @@ int asCByteCode::ResolveJumpAddresses() asCByteInstruction *instr = first; while( instr ) { - if( instr->op == asBC_JMP || - instr->op == asBC_JZ || instr->op == asBC_JNZ || - instr->op == asBC_JLowZ || instr->op == asBC_JLowNZ || - instr->op == asBC_JS || instr->op == asBC_JNS || - instr->op == asBC_JP || instr->op == asBC_JNP ) + if( instr->op == asBC_JMP || + instr->op == asBC_JZ || instr->op == asBC_JNZ || + instr->op == asBC_JLowZ || instr->op == asBC_JLowNZ || + instr->op == asBC_JS || instr->op == asBC_JNS || + instr->op == asBC_JP || instr->op == asBC_JNP ) { - int label = *((int*) ARG_DW(instr->arg)); + int label = *((int *)ARG_DW(instr->arg)); int labelPosOffset; int r = FindLabel(label, instr, 0, &labelPosOffset); if( r == 0 ) - *((int*) ARG_DW(instr->arg)) = labelPosOffset; + *((int *)ARG_DW(instr->arg)) = labelPosOffset; else return -1; } - else if (instr->op == asBC_TryBlock) + else if( instr->op == asBC_TryBlock ) { - int label = *((int*)ARG_DW(instr->arg)); + int label = *((int *)ARG_DW(instr->arg)); int labelPosOffset; int r = FindLabel(label, instr, 0, &labelPosOffset); - if (r == 0) + if( r == 0 ) { // Should store the absolute address so the exception handler doesn't need to figure it out - *((int*)ARG_DW(instr->arg)) = currPos + labelPosOffset; + *((int *)ARG_DW(instr->arg)) = currPos + labelPosOffset; } else return -1; } currPos += instr->GetSize(); - instr = instr->next; + instr = instr->next; } return 0; @@ -1978,69 +1978,69 @@ void asCByteCode::Output(asDWORD *array) { if( instr->GetSize() > 0 ) { - *(asBYTE*)ap = asBYTE(instr->op); - *(((asBYTE*)ap)+1) = 0; // Second byte is always zero + *(asBYTE *)ap = asBYTE(instr->op); + *(((asBYTE *)ap) + 1) = 0; // Second byte is always zero switch( asBCInfo[instr->op].type ) { - case asBCTYPE_NO_ARG: - *(((asWORD*)ap)+1) = 0; // Clear upper bytes - break; - case asBCTYPE_wW_rW_rW_ARG: - *(((asWORD*)ap)+1) = instr->wArg[0]; - *(((asWORD*)ap)+2) = instr->wArg[1]; - *(((asWORD*)ap)+3) = instr->wArg[2]; - break; - case asBCTYPE_wW_DW_ARG: - case asBCTYPE_rW_DW_ARG: - case asBCTYPE_W_DW_ARG: - *(((asWORD*)ap)+1) = instr->wArg[0]; - *(ap+1) = *(asDWORD*)&instr->arg; - break; - case asBCTYPE_wW_rW_DW_ARG: - case asBCTYPE_rW_W_DW_ARG: - *(((asWORD*)ap)+1) = instr->wArg[0]; - *(((asWORD*)ap)+2) = instr->wArg[1]; - *(ap+2) = *(asDWORD*)&instr->arg; - break; - case asBCTYPE_wW_QW_ARG: - case asBCTYPE_rW_QW_ARG: - *(((asWORD*)ap)+1) = instr->wArg[0]; - *(asQWORD*)(ap+1) = *(asQWORD*)&instr->arg; - break; - case asBCTYPE_W_ARG: - case asBCTYPE_rW_ARG: - case asBCTYPE_wW_ARG: - *(((asWORD*)ap)+1) = instr->wArg[0]; - break; - case asBCTYPE_wW_rW_ARG: - case asBCTYPE_rW_rW_ARG: - case asBCTYPE_wW_W_ARG: - case asBCTYPE_W_rW_ARG: - *(((asWORD *)ap)+1) = instr->wArg[0]; - *(((asWORD *)ap)+2) = instr->wArg[1]; - break; - case asBCTYPE_QW_DW_ARG: - case asBCTYPE_DW_DW_ARG: - case asBCTYPE_QW_ARG: - case asBCTYPE_DW_ARG: - *(((asWORD*)ap)+1) = 0; // Clear upper bytes - memcpy(ap+1, &instr->arg, instr->GetSize()*4-4); - break; - case asBCTYPE_rW_DW_DW_ARG: - case asBCTYPE_W_DW_DW_ARG: - case asBCTYPE_W_QW_DW_ARG: - *(((asWORD*)ap)+1) = instr->wArg[0]; - memcpy(ap+1, &instr->arg, instr->GetSize()*4-4); - break; - default: - // How did we get here? - asASSERT(false); - break; + case asBCTYPE_NO_ARG: + *(((asWORD *)ap) + 1) = 0; // Clear upper bytes + break; + case asBCTYPE_wW_rW_rW_ARG: + *(((asWORD *)ap) + 1) = instr->wArg[0]; + *(((asWORD *)ap) + 2) = instr->wArg[1]; + *(((asWORD *)ap) + 3) = instr->wArg[2]; + break; + case asBCTYPE_wW_DW_ARG: + case asBCTYPE_rW_DW_ARG: + case asBCTYPE_W_DW_ARG: + *(((asWORD *)ap) + 1) = instr->wArg[0]; + *(ap + 1) = *(asDWORD *)&instr->arg; + break; + case asBCTYPE_wW_rW_DW_ARG: + case asBCTYPE_rW_W_DW_ARG: + *(((asWORD *)ap) + 1) = instr->wArg[0]; + *(((asWORD *)ap) + 2) = instr->wArg[1]; + *(ap + 2) = *(asDWORD *)&instr->arg; + break; + case asBCTYPE_wW_QW_ARG: + case asBCTYPE_rW_QW_ARG: + *(((asWORD *)ap) + 1) = instr->wArg[0]; + *(asQWORD *)(ap + 1) = *(asQWORD *)&instr->arg; + break; + case asBCTYPE_W_ARG: + case asBCTYPE_rW_ARG: + case asBCTYPE_wW_ARG: + *(((asWORD *)ap) + 1) = instr->wArg[0]; + break; + case asBCTYPE_wW_rW_ARG: + case asBCTYPE_rW_rW_ARG: + case asBCTYPE_wW_W_ARG: + case asBCTYPE_W_rW_ARG: + *(((asWORD *)ap) + 1) = instr->wArg[0]; + *(((asWORD *)ap) + 2) = instr->wArg[1]; + break; + case asBCTYPE_QW_DW_ARG: + case asBCTYPE_DW_DW_ARG: + case asBCTYPE_QW_ARG: + case asBCTYPE_DW_ARG: + *(((asWORD *)ap) + 1) = 0; // Clear upper bytes + memcpy(ap + 1, &instr->arg, instr->GetSize() * 4 - 4); + break; + case asBCTYPE_rW_DW_DW_ARG: + case asBCTYPE_W_DW_DW_ARG: + case asBCTYPE_W_QW_DW_ARG: + *(((asWORD *)ap) + 1) = instr->wArg[0]; + memcpy(ap + 1, &instr->arg, instr->GetSize() * 4 - 4); + break; + default: + // How did we get here? + asASSERT(false); + break; } } - ap += instr->GetSize(); - instr = instr->next; + ap += instr->GetSize(); + instr = instr->next; } } @@ -2060,9 +2060,9 @@ void asCByteCode::PostProcess() asCByteInstruction *instr = first; while( instr ) { - instr->marked = false; + instr->marked = false; instr->stackSize = -1; - instr = instr->next; + instr = instr->next; } // Add the first instruction to the list of unchecked code paths @@ -2072,37 +2072,41 @@ void asCByteCode::PostProcess() // Go through each of the code paths for( asUINT p = 0; p < paths.GetLength(); ++p ) { - instr = paths[p]; + instr = paths[p]; int stackSize = instr->stackSize; while( instr ) { - instr->marked = true; - instr->stackSize = stackSize; - stackSize += instr->stackInc; + instr->marked = true; + instr->stackSize = stackSize; + stackSize += instr->stackInc; if( stackSize > largestStackUsed ) largestStackUsed = stackSize; if( instr->op == asBC_JMP ) { // Find the label that we should jump to - int label = *((int*) ARG_DW(instr->arg)); - asCByteInstruction *dest = 0; - int r = FindLabel(label, instr, &dest, 0); asASSERT( r == 0 ); UNUSED_VAR(r); + int label = *((int *)ARG_DW(instr->arg)); + asCByteInstruction *dest = 0; + int r = FindLabel(label, instr, &dest, 0); + asASSERT( r == 0 ); + UNUSED_VAR(r); AddPath(paths, dest, stackSize); break; } - else if( instr->op == asBC_JZ || instr->op == asBC_JNZ || - instr->op == asBC_JLowZ || instr->op == asBC_JLowNZ || - instr->op == asBC_JS || instr->op == asBC_JNS || - instr->op == asBC_JP || instr->op == asBC_JNP || - instr->op == asBC_TryBlock ) + else if( instr->op == asBC_JZ || instr->op == asBC_JNZ || + instr->op == asBC_JLowZ || instr->op == asBC_JLowNZ || + instr->op == asBC_JS || instr->op == asBC_JNS || + instr->op == asBC_JP || instr->op == asBC_JNP || + instr->op == asBC_TryBlock ) { // Find the label that is being jumped to - int label = *((int*) ARG_DW(instr->arg)); - asCByteInstruction *dest = 0; - int r = FindLabel(label, instr, &dest, 0); asASSERT( r == 0 ); UNUSED_VAR(r); + int label = *((int *)ARG_DW(instr->arg)); + asCByteInstruction *dest = 0; + int r = FindLabel(label, instr, &dest, 0); + asASSERT( r == 0 ); + UNUSED_VAR(r); AddPath(paths, dest, stackSize); @@ -2144,52 +2148,52 @@ void asCByteCode::PostProcess() { // Remove it asCByteInstruction *curr = instr; - instr = instr->next; + instr = instr->next; DeleteInstruction(curr); } else { -#ifndef AS_DEBUG + #ifndef AS_DEBUG // If the stackSize is negative, then there is a problem with the bytecode. // If AS_DEBUG is turned on, this same check is done in DebugOutput. asASSERT( instr->stackSize >= 0 || asBCInfo[instr->op].type == asBCTYPE_INFO ); -#endif + #endif instr = instr->next; } } } -#ifdef AS_DEBUG + #ifdef AS_DEBUG void asCByteCode::DebugOutput(const char *name, asCScriptFunction *func) { - if (engine->ep.noDebugOutput) + if( engine->ep.noDebugOutput ) return; -#ifndef __MINGW32__ + #ifndef __MINGW32__ // _mkdir is broken on mingw _mkdir("AS_DEBUG"); -#endif + #endif - asCString path = "AS_DEBUG/"; - path += name; + asCString path = "AS_DEBUG/"; + path += name; // Anonymous functions created from within class methods will contain :: as part of the name // Replace :: with __ to avoid error when creating the file for debug output - for (asUINT n = 0; n < path.GetLength(); n++) - if (path[n] == ':') path[n] = '_'; + for( asUINT n = 0; n < path.GetLength(); n++ ) + if( path[n] == ':' ) path[n] = '_'; -#if _MSC_VER >= 1500 && !defined(AS_MARMALADE) + #if _MSC_VER >= 1500 && !defined(AS_MARMALADE) FILE *file; fopen_s(&file, path.AddressOf(), "w"); -#else + #else FILE *file = fopen(path.AddressOf(), "w"); -#endif + #endif -#if !defined(AS_XENON) && !defined(__MINGW32__) + #if !defined(AS_XENON) && !defined(__MINGW32__) // XBox 360: When running in DVD Emu, no write is allowed // MinGW: As _mkdir is broken, don't assert on file not created if the AS_DEBUG directory doesn't exist asASSERT( file ); -#endif + #endif if( file == 0 ) return; @@ -2202,7 +2206,7 @@ void asCByteCode::DebugOutput(const char *name, asCScriptFunction *func) for( n = 0; n < temporaryVariables->GetLength(); n++ ) { fprintf(file, "%d", (*temporaryVariables)[n]); - if( n < temporaryVariables->GetLength()-1 ) + if( n < temporaryVariables->GetLength() - 1 ) fprintf(file, ", "); } fprintf(file, "\n\n"); @@ -2218,16 +2222,16 @@ void asCByteCode::DebugOutput(const char *name, asCScriptFunction *func) fprintf(file, "\n\n"); - bool invalidStackSize = false; - int pos = 0; - asUINT lineIndex = 0; - asCByteInstruction *instr = first; + bool invalidStackSize = false; + int pos = 0; + asUINT lineIndex = 0; + asCByteInstruction *instr = first; while( instr ) { if( lineIndex < lineNumbers.GetLength() && lineNumbers[lineIndex] == pos ) { - asDWORD line = lineNumbers[lineIndex+1]; - fprintf(file, "- %d,%d -\n", (int)(line&0xFFFFF), (int)(line>>20)); + asDWORD line = lineNumbers[lineIndex + 1]; + fprintf(file, "- %d,%d -\n", (int)(line & 0xFFFFF), (int)(line >> 20)); lineIndex += 2; } @@ -2247,260 +2251,260 @@ void asCByteCode::DebugOutput(const char *name, asCScriptFunction *func) switch( asBCInfo[instr->op].type ) { - case asBCTYPE_W_ARG: - fprintf(file, " %-8s %d\n", asBCInfo[instr->op].name, instr->wArg[0]); - break; - - case asBCTYPE_wW_ARG: - case asBCTYPE_rW_ARG: - fprintf(file, " %-8s v%d\n", asBCInfo[instr->op].name, instr->wArg[0]); - break; - - case asBCTYPE_wW_rW_ARG: - case asBCTYPE_rW_rW_ARG: - case asBCTYPE_W_rW_ARG: - fprintf(file, " %-8s v%d, v%d\n", asBCInfo[instr->op].name, instr->wArg[0], instr->wArg[1]); - break; + case asBCTYPE_W_ARG: + fprintf(file, " %-8s %d\n", asBCInfo[instr->op].name, instr->wArg[0]); + break; - case asBCTYPE_wW_W_ARG: - fprintf(file, " %-8s v%d, %d\n", asBCInfo[instr->op].name, instr->wArg[0], instr->wArg[1]); - break; + case asBCTYPE_wW_ARG: + case asBCTYPE_rW_ARG: + fprintf(file, " %-8s v%d\n", asBCInfo[instr->op].name, instr->wArg[0]); + break; - case asBCTYPE_wW_rW_DW_ARG: - case asBCTYPE_rW_W_DW_ARG: - switch( instr->op ) - { - case asBC_ADDIf: - case asBC_SUBIf: - case asBC_MULIf: - fprintf(file, " %-8s v%d, v%d, %f\n", asBCInfo[instr->op].name, instr->wArg[0], instr->wArg[1], *((float*) ARG_DW(instr->arg))); + case asBCTYPE_wW_rW_ARG: + case asBCTYPE_rW_rW_ARG: + case asBCTYPE_W_rW_ARG: + fprintf(file, " %-8s v%d, v%d\n", asBCInfo[instr->op].name, instr->wArg[0], instr->wArg[1]); break; - default: - fprintf(file, " %-8s v%d, v%d, %d\n", asBCInfo[instr->op].name, instr->wArg[0], instr->wArg[1], *((int*) ARG_DW(instr->arg))); + + case asBCTYPE_wW_W_ARG: + fprintf(file, " %-8s v%d, %d\n", asBCInfo[instr->op].name, instr->wArg[0], instr->wArg[1]); break; - } - break; - case asBCTYPE_DW_ARG: - switch( instr->op ) - { - case asBC_OBJTYPE: + case asBCTYPE_wW_rW_DW_ARG: + case asBCTYPE_rW_W_DW_ARG: + switch( instr->op ) { - asCObjectType *ot = *(asCObjectType**)ARG_DW(instr->arg); - fprintf(file, " %-8s 0x%x (type:%s)\n", asBCInfo[instr->op].name, (asUINT)*ARG_DW(instr->arg), ot->GetName()); + case asBC_ADDIf: + case asBC_SUBIf: + case asBC_MULIf: + fprintf(file, " %-8s v%d, v%d, %f\n", asBCInfo[instr->op].name, instr->wArg[0], instr->wArg[1], *((float *)ARG_DW(instr->arg))); + break; + default: + fprintf(file, " %-8s v%d, v%d, %d\n", asBCInfo[instr->op].name, instr->wArg[0], instr->wArg[1], *((int *)ARG_DW(instr->arg))); + break; } break; - case asBC_FuncPtr: + case asBCTYPE_DW_ARG: + switch( instr->op ) { - asCScriptFunction *f = *(asCScriptFunction**)ARG_DW(instr->arg); - fprintf(file, " %-8s 0x%x (func:%s)\n", asBCInfo[instr->op].name, (asUINT)*ARG_DW(instr->arg), f->GetDeclaration()); - } - break; + case asBC_OBJTYPE: + { + asCObjectType *ot = *(asCObjectType **)ARG_DW(instr->arg); + fprintf(file, " %-8s 0x%x (type:%s)\n", asBCInfo[instr->op].name, (asUINT)*ARG_DW(instr->arg), ot->GetName()); + } + break; - case asBC_PshC4: - case asBC_Cast: - fprintf(file, " %-8s 0x%x (i:%d, f:%g)\n", asBCInfo[instr->op].name, (asUINT)*ARG_DW(instr->arg), *((int*) ARG_DW(instr->arg)), *((float*) ARG_DW(instr->arg))); - break; + case asBC_FuncPtr: + { + asCScriptFunction *f = *(asCScriptFunction **)ARG_DW(instr->arg); + fprintf(file, " %-8s 0x%x (func:%s)\n", asBCInfo[instr->op].name, (asUINT)*ARG_DW(instr->arg), f->GetDeclaration()); + } + break; - case asBC_TYPEID: - fprintf(file, " %-8s 0x%x '%s'\n", asBCInfo[instr->op].name, (asUINT)*ARG_DW(instr->arg), engine->GetTypeDeclaration((int)*ARG_DW(instr->arg))); - break; + case asBC_PshC4: + case asBC_Cast: + fprintf(file, " %-8s 0x%x (i:%d, f:%g)\n", asBCInfo[instr->op].name, (asUINT)*ARG_DW(instr->arg), *((int *)ARG_DW(instr->arg)), *((float *)ARG_DW(instr->arg))); + break; - case asBC_CALL: - case asBC_CALLSYS: - case asBC_CALLBND: - case asBC_CALLINTF: - case asBC_Thiscall1: - { - int funcID = *(int*)ARG_DW(instr->arg); - asCString decl = engine->GetFunctionDeclaration(funcID); + case asBC_TYPEID: + fprintf(file, " %-8s 0x%x '%s'\n", asBCInfo[instr->op].name, (asUINT)*ARG_DW(instr->arg), engine->GetTypeDeclaration((int)*ARG_DW(instr->arg))); + break; - fprintf(file, " %-8s %d (%s)\n", asBCInfo[instr->op].name, *((int*) ARG_DW(instr->arg)), decl.AddressOf()); - } - break; + case asBC_CALL: + case asBC_CALLSYS: + case asBC_CALLBND: + case asBC_CALLINTF: + case asBC_Thiscall1: + { + int funcID = *(int *)ARG_DW(instr->arg); + asCString decl = engine->GetFunctionDeclaration(funcID); - case asBC_REFCPY: - fprintf(file, " %-8s 0x%x\n", asBCInfo[instr->op].name, *((int*) ARG_DW(instr->arg))); - break; + fprintf(file, " %-8s %d (%s)\n", asBCInfo[instr->op].name, *((int *)ARG_DW(instr->arg)), decl.AddressOf()); + } + break; - case asBC_JMP: - case asBC_JZ: - case asBC_JLowZ: - case asBC_JS: - case asBC_JP: - case asBC_JNZ: - case asBC_JLowNZ: - case asBC_JNS: - case asBC_JNP: - fprintf(file, " %-8s %+d (d:%d)\n", asBCInfo[instr->op].name, *((int*) ARG_DW(instr->arg)), pos+*((int*) ARG_DW(instr->arg))); - break; + case asBC_REFCPY: + fprintf(file, " %-8s 0x%x\n", asBCInfo[instr->op].name, *((int *)ARG_DW(instr->arg))); + break; - default: - fprintf(file, " %-8s %d\n", asBCInfo[instr->op].name, *((int*) ARG_DW(instr->arg))); - break; - } - break; + case asBC_JMP: + case asBC_JZ: + case asBC_JLowZ: + case asBC_JS: + case asBC_JP: + case asBC_JNZ: + case asBC_JLowNZ: + case asBC_JNS: + case asBC_JNP: + fprintf(file, " %-8s %+d (d:%d)\n", asBCInfo[instr->op].name, *((int *)ARG_DW(instr->arg)), pos + *((int *)ARG_DW(instr->arg))); + break; - case asBCTYPE_QW_ARG: - switch( instr->op ) - { - case asBC_OBJTYPE: - { - asCObjectType *ot = *(asCObjectType**)ARG_QW(instr->arg); - fprintf(file, " %-8s 0x%x (type:%s)\n", asBCInfo[instr->op].name, (asUINT)*ARG_QW(instr->arg), ot->GetName()); + default: + fprintf(file, " %-8s %d\n", asBCInfo[instr->op].name, *((int *)ARG_DW(instr->arg))); + break; } break; - case asBC_FuncPtr: + case asBCTYPE_QW_ARG: + switch( instr->op ) { - asCScriptFunction *f = *(asCScriptFunction**)ARG_QW(instr->arg); - fprintf(file, " %-8s 0x%x (func:%s)\n", asBCInfo[instr->op].name, (asUINT)*ARG_QW(instr->arg), f->GetDeclaration()); - } - break; + case asBC_OBJTYPE: + { + asCObjectType *ot = *(asCObjectType **)ARG_QW(instr->arg); + fprintf(file, " %-8s 0x%x (type:%s)\n", asBCInfo[instr->op].name, (asUINT)*ARG_QW(instr->arg), ot->GetName()); + } + break; - case asBC_PGA: - { - void *ptr = *(void**)ARG_QW(instr->arg); - asSMapNode *cursor = 0; - if( engine->varAddressMap.MoveTo(&cursor, ptr) ) + case asBC_FuncPtr: { - fprintf(file, " %-8s 0x%x (var:%s)\n", asBCInfo[instr->op].name, (asUINT)*ARG_QW(instr->arg), cursor->value->name.AddressOf()); + asCScriptFunction *f = *(asCScriptFunction **)ARG_QW(instr->arg); + fprintf(file, " %-8s 0x%x (func:%s)\n", asBCInfo[instr->op].name, (asUINT)*ARG_QW(instr->arg), f->GetDeclaration()); } - else + break; + + case asBC_PGA: { - asUINT length; - engine->stringFactory->GetRawStringData(ptr, 0, &length); - asCString str; - str.SetLength(length); - engine->stringFactory->GetRawStringData(ptr, str.AddressOf(), &length); - if (str.GetLength() > 20) + void *ptr = *(void **)ARG_QW(instr->arg); + asSMapNode *cursor = 0; + if( engine->varAddressMap.MoveTo(&cursor, ptr) ) + { + fprintf(file, " %-8s 0x%x (var:%s)\n", asBCInfo[instr->op].name, (asUINT)*ARG_QW(instr->arg), cursor->value->name.AddressOf()); + } + else { - // TODO: Replace non-visible characters with space or something like it - str.SetLength(20); - str += "..."; + asUINT length; + engine->stringFactory->GetRawStringData(ptr, 0, &length); + asCString str; + str.SetLength(length); + engine->stringFactory->GetRawStringData(ptr, str.AddressOf(), &length); + if( str.GetLength() > 20 ) + { + // TODO: Replace non-visible characters with space or something like it + str.SetLength(20); + str += "..."; + } + fprintf(file, " %-8s 0x%x (str:%s)\n", asBCInfo[instr->op].name, (asUINT)*ARG_QW(instr->arg), str.AddressOf()); } - fprintf(file, " %-8s 0x%x (str:%s)\n", asBCInfo[instr->op].name, (asUINT)*ARG_QW(instr->arg), str.AddressOf()); } + break; + + default: + #ifdef __GNUC__ + #ifdef _LP64 + fprintf(file, " %-8s 0x%lx (i:%ld, f:%g)\n", asBCInfo[instr->op].name, *ARG_QW(instr->arg), *((asINT64 *)ARG_QW(instr->arg)), *((double *)ARG_QW(instr->arg))); + #else + fprintf(file, " %-8s 0x%llx (i:%lld, f:%g)\n", asBCInfo[instr->op].name, *ARG_QW(instr->arg), *((asINT64 *)ARG_QW(instr->arg)), *((double *)ARG_QW(instr->arg))); + #endif + #else + fprintf(file, " %-8s 0x%I64x (i:%I64d, f:%g)\n", asBCInfo[instr->op].name, *ARG_QW(instr->arg), *((asINT64 *)ARG_QW(instr->arg)), *((double *)ARG_QW(instr->arg))); + #endif } break; - - default: -#ifdef __GNUC__ -#ifdef _LP64 - fprintf(file, " %-8s 0x%lx (i:%ld, f:%g)\n", asBCInfo[instr->op].name, *ARG_QW(instr->arg), *((asINT64*) ARG_QW(instr->arg)), *((double*) ARG_QW(instr->arg))); -#else - fprintf(file, " %-8s 0x%llx (i:%lld, f:%g)\n", asBCInfo[instr->op].name, *ARG_QW(instr->arg), *((asINT64*) ARG_QW(instr->arg)), *((double*) ARG_QW(instr->arg))); -#endif -#else - fprintf(file, " %-8s 0x%I64x (i:%I64d, f:%g)\n", asBCInfo[instr->op].name, *ARG_QW(instr->arg), *((asINT64*) ARG_QW(instr->arg)), *((double*) ARG_QW(instr->arg))); -#endif - } - break; - case asBCTYPE_wW_QW_ARG: - case asBCTYPE_rW_QW_ARG: - switch( instr->op ) - { - case asBC_RefCpyV: - case asBC_FREE: + case asBCTYPE_wW_QW_ARG: + case asBCTYPE_rW_QW_ARG: + switch( instr->op ) { - asCObjectType *ot = *(asCObjectType**)ARG_QW(instr->arg); - fprintf(file, " %-8s v%d, 0x%x (type:%s)\n", asBCInfo[instr->op].name, instr->wArg[0], (asUINT)*ARG_QW(instr->arg), ot->GetName()); + case asBC_RefCpyV: + case asBC_FREE: + { + asCObjectType *ot = *(asCObjectType **)ARG_QW(instr->arg); + fprintf(file, " %-8s v%d, 0x%x (type:%s)\n", asBCInfo[instr->op].name, instr->wArg[0], (asUINT)*ARG_QW(instr->arg), ot->GetName()); + } + break; + + default: + #ifdef __GNUC__ + #ifdef _LP64 + fprintf(file, " %-8s v%d, 0x%lx (i:%ld, f:%g)\n", asBCInfo[instr->op].name, instr->wArg[0], *ARG_QW(instr->arg), *((asINT64 *)ARG_QW(instr->arg)), *((double *)ARG_QW(instr->arg))); + #else + fprintf(file, " %-8s v%d, 0x%llx (i:%lld, f:%g)\n", asBCInfo[instr->op].name, instr->wArg[0], *ARG_QW(instr->arg), *((asINT64 *)ARG_QW(instr->arg)), *((double *)ARG_QW(instr->arg))); + #endif + #else + fprintf(file, " %-8s v%d, 0x%I64x (i:%I64d, f:%g)\n", asBCInfo[instr->op].name, instr->wArg[0], *ARG_QW(instr->arg), *((asINT64 *)ARG_QW(instr->arg)), *((double *)ARG_QW(instr->arg))); + #endif } break; - default: -#ifdef __GNUC__ -#ifdef _LP64 - fprintf(file, " %-8s v%d, 0x%lx (i:%ld, f:%g)\n", asBCInfo[instr->op].name, instr->wArg[0], *ARG_QW(instr->arg), *((asINT64*) ARG_QW(instr->arg)), *((double*) ARG_QW(instr->arg))); -#else - fprintf(file, " %-8s v%d, 0x%llx (i:%lld, f:%g)\n", asBCInfo[instr->op].name, instr->wArg[0], *ARG_QW(instr->arg), *((asINT64*) ARG_QW(instr->arg)), *((double*) ARG_QW(instr->arg))); -#endif -#else - fprintf(file, " %-8s v%d, 0x%I64x (i:%I64d, f:%g)\n", asBCInfo[instr->op].name, instr->wArg[0], *ARG_QW(instr->arg), *((asINT64*) ARG_QW(instr->arg)), *((double*) ARG_QW(instr->arg))); -#endif - } - break; - - case asBCTYPE_DW_DW_ARG: - case asBCTYPE_W_DW_DW_ARG: - if( instr->op == asBC_ALLOC ) - { - asCObjectType *ot = *(asCObjectType**)ARG_DW(instr->arg); - asCScriptFunction *f = engine->scriptFunctions[(asWORD)instr->wArg[0]]; - fprintf(file, " %-8s 0x%x, %d (type:%s, %s)\n", asBCInfo[instr->op].name, *(int*)ARG_DW(instr->arg), *(int*)(ARG_DW(instr->arg)+1), ot->GetName(), f ? f->GetDeclaration() : "{no func}"); - } - else - fprintf(file, " %-8s %u, %d\n", asBCInfo[instr->op].name, *(int*)ARG_DW(instr->arg), *(int*)(ARG_DW(instr->arg)+1)); - break; + case asBCTYPE_DW_DW_ARG: + case asBCTYPE_W_DW_DW_ARG: + if( instr->op == asBC_ALLOC ) + { + asCObjectType *ot = *(asCObjectType **)ARG_DW(instr->arg); + asCScriptFunction *f = engine->scriptFunctions[(asWORD)instr->wArg[0]]; + fprintf(file, " %-8s 0x%x, %d (type:%s, %s)\n", asBCInfo[instr->op].name, *(int *)ARG_DW(instr->arg), *(int *)(ARG_DW(instr->arg) + 1), ot->GetName(), f ? f->GetDeclaration() : "{no func}"); + } + else + fprintf(file, " %-8s %u, %d\n", asBCInfo[instr->op].name, *(int *)ARG_DW(instr->arg), *(int *)(ARG_DW(instr->arg) + 1)); + break; - case asBCTYPE_rW_DW_DW_ARG: - fprintf(file, " %-8s v%d, %u, %u\n", asBCInfo[instr->op].name, instr->wArg[0], *(int*)ARG_DW(instr->arg), *(int*)(ARG_DW(instr->arg)+1)); - break; + case asBCTYPE_rW_DW_DW_ARG: + fprintf(file, " %-8s v%d, %u, %u\n", asBCInfo[instr->op].name, instr->wArg[0], *(int *)ARG_DW(instr->arg), *(int *)(ARG_DW(instr->arg) + 1)); + break; - case asBCTYPE_QW_DW_ARG: - case asBCTYPE_W_QW_DW_ARG: - if( instr->op == asBC_ALLOC ) - { - asCObjectType *ot = *(asCObjectType**)ARG_QW(instr->arg); - asCScriptFunction *f = engine->scriptFunctions[(asWORD)instr->wArg[0]]; -#if defined(__GNUC__) && !defined(_MSC_VER) -#ifdef AS_64BIT_PTR - fprintf(file, " %-8s 0x%lx, %d (type:%s, %s)\n", asBCInfo[instr->op].name, *(asINT64*)ARG_QW(instr->arg), *(int*)(ARG_DW(instr->arg)+2), ot->GetName(), f ? f->GetDeclaration() : "{no func}"); -#else - fprintf(file, " %-8s 0x%llx, %d (type:%s, %s)\n", asBCInfo[instr->op].name, *(asINT64*)ARG_QW(instr->arg), *(int*)(ARG_DW(instr->arg)+2), ot->GetName(), f ? f->GetDeclaration() : "{no func}"); -#endif -#else - fprintf(file, " %-8s 0x%I64x, %d (type:%s, %s)\n", asBCInfo[instr->op].name, *(asINT64*)ARG_QW(instr->arg), *(int*)(ARG_DW(instr->arg)+2), ot->GetName(), f ? f->GetDeclaration() : "{no func}"); -#endif - } - else -#if defined(__GNUC__) && !defined(_MSC_VER) -#ifdef AS_64BIT_PTR - fprintf(file, " %-8s %lu, %d\n", asBCInfo[instr->op].name, *(asINT64*)ARG_QW(instr->arg), *(int*)(ARG_DW(instr->arg)+2)); -#else - fprintf(file, " %-8s %llu, %d\n", asBCInfo[instr->op].name, *(asINT64*)ARG_QW(instr->arg), *(int*)(ARG_DW(instr->arg)+2)); -#endif -#else - fprintf(file, " %-8s %I64u, %d\n", asBCInfo[instr->op].name, *(asINT64*)ARG_QW(instr->arg), *(int*)(ARG_DW(instr->arg)+2)); -#endif - break; + case asBCTYPE_QW_DW_ARG: + case asBCTYPE_W_QW_DW_ARG: + if( instr->op == asBC_ALLOC ) + { + asCObjectType *ot = *(asCObjectType **)ARG_QW(instr->arg); + asCScriptFunction *f = engine->scriptFunctions[(asWORD)instr->wArg[0]]; + #if defined(__GNUC__) && !defined(_MSC_VER) + #ifdef AS_64BIT_PTR + fprintf(file, " %-8s 0x%lx, %d (type:%s, %s)\n", asBCInfo[instr->op].name, *(asINT64 *)ARG_QW(instr->arg), *(int *)(ARG_DW(instr->arg) + 2), ot->GetName(), f ? f->GetDeclaration() : "{no func}"); + #else + fprintf(file, " %-8s 0x%llx, %d (type:%s, %s)\n", asBCInfo[instr->op].name, *(asINT64 *)ARG_QW(instr->arg), *(int *)(ARG_DW(instr->arg) + 2), ot->GetName(), f ? f->GetDeclaration() : "{no func}"); + #endif + #else + fprintf(file, " %-8s 0x%I64x, %d (type:%s, %s)\n", asBCInfo[instr->op].name, *(asINT64 *)ARG_QW(instr->arg), *(int *)(ARG_DW(instr->arg) + 2), ot->GetName(), f ? f->GetDeclaration() : "{no func}"); + #endif + } + else + #if defined(__GNUC__) && !defined(_MSC_VER) + #ifdef AS_64BIT_PTR + fprintf(file, " %-8s %lu, %d\n", asBCInfo[instr->op].name, *(asINT64 *)ARG_QW(instr->arg), *(int *)(ARG_DW(instr->arg) + 2)); + #else + fprintf(file, " %-8s %llu, %d\n", asBCInfo[instr->op].name, *(asINT64 *)ARG_QW(instr->arg), *(int *)(ARG_DW(instr->arg) + 2)); + #endif + #else + fprintf(file, " %-8s %I64u, %d\n", asBCInfo[instr->op].name, *(asINT64 *)ARG_QW(instr->arg), *(int *)(ARG_DW(instr->arg) + 2)); + #endif + break; - case asBCTYPE_INFO: - if( instr->op == asBC_LABEL ) - fprintf(file, "%d:\n", instr->wArg[0]); - else if( instr->op == asBC_LINE ) - fprintf(file, " %s\n", asBCInfo[instr->op].name); - else if( instr->op == asBC_Block ) - fprintf(file, "%c\n", instr->wArg[0] ? '{' : '}'); - break; + case asBCTYPE_INFO: + if( instr->op == asBC_LABEL ) + fprintf(file, "%d:\n", instr->wArg[0]); + else if( instr->op == asBC_LINE ) + fprintf(file, " %s\n", asBCInfo[instr->op].name); + else if( instr->op == asBC_Block ) + fprintf(file, "%c\n", instr->wArg[0] ? '{' : '}'); + break; - case asBCTYPE_rW_DW_ARG: - case asBCTYPE_wW_DW_ARG: - case asBCTYPE_W_DW_ARG: - if( instr->op == asBC_SetV1 ) - fprintf(file, " %-8s v%d, 0x%x\n", asBCInfo[instr->op].name, instr->wArg[0], *(asBYTE*)ARG_DW(instr->arg)); - else if( instr->op == asBC_SetV2 ) - fprintf(file, " %-8s v%d, 0x%x\n", asBCInfo[instr->op].name, instr->wArg[0], *(asWORD*)ARG_DW(instr->arg)); - else if( instr->op == asBC_SetV4 ) - fprintf(file, " %-8s v%d, 0x%x (i:%d, f:%g)\n", asBCInfo[instr->op].name, instr->wArg[0], (asUINT)*ARG_DW(instr->arg), *((int*) ARG_DW(instr->arg)), *((float*) ARG_DW(instr->arg))); - else if( instr->op == asBC_CMPIf ) - fprintf(file, " %-8s v%d, %f\n", asBCInfo[instr->op].name, instr->wArg[0], *(float*)ARG_DW(instr->arg)); - else - fprintf(file, " %-8s v%d, %d\n", asBCInfo[instr->op].name, instr->wArg[0], (asUINT)*ARG_DW(instr->arg)); - break; + case asBCTYPE_rW_DW_ARG: + case asBCTYPE_wW_DW_ARG: + case asBCTYPE_W_DW_ARG: + if( instr->op == asBC_SetV1 ) + fprintf(file, " %-8s v%d, 0x%x\n", asBCInfo[instr->op].name, instr->wArg[0], *(asBYTE *)ARG_DW(instr->arg)); + else if( instr->op == asBC_SetV2 ) + fprintf(file, " %-8s v%d, 0x%x\n", asBCInfo[instr->op].name, instr->wArg[0], *(asWORD *)ARG_DW(instr->arg)); + else if( instr->op == asBC_SetV4 ) + fprintf(file, " %-8s v%d, 0x%x (i:%d, f:%g)\n", asBCInfo[instr->op].name, instr->wArg[0], (asUINT)*ARG_DW(instr->arg), *((int *)ARG_DW(instr->arg)), *((float *)ARG_DW(instr->arg))); + else if( instr->op == asBC_CMPIf ) + fprintf(file, " %-8s v%d, %f\n", asBCInfo[instr->op].name, instr->wArg[0], *(float *)ARG_DW(instr->arg)); + else + fprintf(file, " %-8s v%d, %d\n", asBCInfo[instr->op].name, instr->wArg[0], (asUINT)*ARG_DW(instr->arg)); + break; - case asBCTYPE_wW_rW_rW_ARG: - fprintf(file, " %-8s v%d, v%d, v%d\n", asBCInfo[instr->op].name, instr->wArg[0], instr->wArg[1], instr->wArg[2]); - break; + case asBCTYPE_wW_rW_rW_ARG: + fprintf(file, " %-8s v%d, v%d, v%d\n", asBCInfo[instr->op].name, instr->wArg[0], instr->wArg[1], instr->wArg[2]); + break; - case asBCTYPE_NO_ARG: - fprintf(file, " %s\n", asBCInfo[instr->op].name); - break; + case asBCTYPE_NO_ARG: + fprintf(file, " %s\n", asBCInfo[instr->op].name); + break; - default: - asASSERT(false); + default: + asASSERT(false); } instr = instr->next; @@ -2508,12 +2512,12 @@ void asCByteCode::DebugOutput(const char *name, asCScriptFunction *func) fclose(file); - // If the stackSize is negative then there is something wrong with the - // bytecode, i.e. there is a bug in the compiler or in the optimizer. We + // If the stackSize is negative then there is something wrong with the + // bytecode, i.e. there is a bug in the compiler or in the optimizer. We // only check this here to have the bytecode available on file for verification asASSERT( !invalidStackSize ); } -#endif + #endif //============================================================================= @@ -2525,10 +2529,10 @@ int asCByteCode::InsertFirstInstrDWORD(asEBCInstr bc, asDWORD param) if( AddInstructionFirst() < 0 ) return 0; - first->op = bc; + first->op = bc; *ARG_DW(first->arg) = param; - first->size = asBCTypeSize[asBCInfo[bc].type]; - first->stackInc = asBCInfo[bc].stackInc; + first->size = asBCTypeSize[asBCInfo[bc].type]; + first->stackInc = asBCInfo[bc].stackInc; return first->stackInc; } @@ -2541,10 +2545,10 @@ int asCByteCode::InsertFirstInstrQWORD(asEBCInstr bc, asQWORD param) if( AddInstructionFirst() < 0 ) return 0; - first->op = bc; + first->op = bc; *ARG_QW(first->arg) = param; - first->size = asBCTypeSize[asBCInfo[bc].type]; - first->stackInc = asBCInfo[bc].stackInc; + first->size = asBCTypeSize[asBCInfo[bc].type]; + first->stackInc = asBCInfo[bc].stackInc; return first->stackInc; } @@ -2608,11 +2612,11 @@ int asCByteCode::InstrW_PTR(asEBCInstr bc, short a, void *param) if( AddInstruction() < 0 ) return 0; - last->op = bc; - last->wArg[0] = a; + last->op = bc; + last->wArg[0] = a; *ARG_PTR(last->arg) = (asPWORD)param; - last->size = asBCTypeSize[asBCInfo[bc].type]; - last->stackInc = asBCInfo[bc].stackInc; + last->size = asBCTypeSize[asBCInfo[bc].type]; + last->stackInc = asBCInfo[bc].stackInc; return last->stackInc; } @@ -2627,11 +2631,11 @@ int asCByteCode::InstrW_DW(asEBCInstr bc, asWORD a, asDWORD b) if( AddInstruction() < 0 ) return 0; - last->op = bc; - last->wArg[0] = a; - *((int*) ARG_DW(last->arg)) = b; - last->size = asBCTypeSize[asBCInfo[bc].type]; - last->stackInc = asBCInfo[bc].stackInc; + last->op = bc; + last->wArg[0] = a; + *((int *)ARG_DW(last->arg)) = b; + last->size = asBCTypeSize[asBCInfo[bc].type]; + last->stackInc = asBCInfo[bc].stackInc; return last->stackInc; } @@ -2644,12 +2648,12 @@ int asCByteCode::InstrSHORT_DW_DW(asEBCInstr bc, short a, asDWORD b, asDWORD c) if( AddInstruction() < 0 ) return 0; - last->op = bc; - last->wArg[0] = a; - *(int*)ARG_DW(last->arg) = b; - *(int*)(ARG_DW(last->arg)+1) = c; - last->size = asBCTypeSize[asBCInfo[bc].type]; - last->stackInc = asBCInfo[bc].stackInc; + last->op = bc; + last->wArg[0] = a; + *(int *)ARG_DW(last->arg) = b; + *(int *)(ARG_DW(last->arg) + 1) = c; + last->size = asBCTypeSize[asBCInfo[bc].type]; + last->stackInc = asBCInfo[bc].stackInc; return last->stackInc; } @@ -2664,17 +2668,17 @@ int asCByteCode::InstrSHORT_B(asEBCInstr bc, short a, asBYTE b) if( AddInstruction() < 0 ) return 0; - last->op = bc; - last->wArg[0] = a; + last->op = bc; + last->wArg[0] = a; // We'll have to be careful to store the byte correctly, independent of endianess. // Some optimizing compilers may change the order of operations, so we make sure // the value is not overwritten even if that happens. - asBYTE *argPtr = (asBYTE*)ARG_DW(last->arg); - argPtr[0] = b; // The value is always stored in the lower byte - argPtr[1] = 0; // and clear the rest of the DWORD - argPtr[2] = 0; - argPtr[3] = 0; + asBYTE *argPtr = (asBYTE *)ARG_DW(last->arg); + argPtr[0] = b; // The value is always stored in the lower byte + argPtr[1] = 0; // and clear the rest of the DWORD + argPtr[2] = 0; + argPtr[3] = 0; last->size = asBCTypeSize[asBCInfo[bc].type]; last->stackInc = asBCInfo[bc].stackInc; @@ -2692,15 +2696,15 @@ int asCByteCode::InstrSHORT_W(asEBCInstr bc, short a, asWORD b) if( AddInstruction() < 0 ) return 0; - last->op = bc; - last->wArg[0] = a; + last->op = bc; + last->wArg[0] = a; // We'll have to be careful to store the word correctly, independent of endianess. // Some optimizing compilers may change the order of operations, so we make sure // the value is not overwritten even if that happens. - asWORD *argPtr = (asWORD*)ARG_DW(last->arg); - argPtr[0] = b; // The value is always stored in the lower word - argPtr[1] = 0; // and clear the rest of the DWORD + asWORD *argPtr = (asWORD *)ARG_DW(last->arg); + argPtr[0] = b; // The value is always stored in the lower word + argPtr[1] = 0; // and clear the rest of the DWORD last->size = asBCTypeSize[asBCInfo[bc].type]; last->stackInc = asBCInfo[bc].stackInc; @@ -2717,11 +2721,11 @@ int asCByteCode::InstrSHORT_DW(asEBCInstr bc, short a, asDWORD b) if( AddInstruction() < 0 ) return 0; - last->op = bc; - last->wArg[0] = a; - *((int*) ARG_DW(last->arg)) = b; - last->size = asBCTypeSize[asBCInfo[bc].type]; - last->stackInc = asBCInfo[bc].stackInc; + last->op = bc; + last->wArg[0] = a; + *((int *)ARG_DW(last->arg)) = b; + last->size = asBCTypeSize[asBCInfo[bc].type]; + last->stackInc = asBCInfo[bc].stackInc; return last->stackInc; } @@ -2734,11 +2738,11 @@ int asCByteCode::InstrW_QW(asEBCInstr bc, asWORD a, asQWORD b) if( AddInstruction() < 0 ) return 0; - last->op = bc; - last->wArg[0] = a; + last->op = bc; + last->wArg[0] = a; *ARG_QW(last->arg) = b; - last->size = asBCTypeSize[asBCInfo[bc].type]; - last->stackInc = asBCInfo[bc].stackInc; + last->size = asBCTypeSize[asBCInfo[bc].type]; + last->stackInc = asBCInfo[bc].stackInc; return last->stackInc; } @@ -2751,11 +2755,11 @@ int asCByteCode::InstrSHORT_QW(asEBCInstr bc, short a, asQWORD b) if( AddInstruction() < 0 ) return 0; - last->op = bc; - last->wArg[0] = a; + last->op = bc; + last->wArg[0] = a; *ARG_QW(last->arg) = b; - last->size = asBCTypeSize[asBCInfo[bc].type]; - last->stackInc = asBCInfo[bc].stackInc; + last->size = asBCTypeSize[asBCInfo[bc].type]; + last->stackInc = asBCInfo[bc].stackInc; return last->stackInc; } @@ -2768,11 +2772,11 @@ int asCByteCode::InstrW_FLOAT(asEBCInstr bc, asWORD a, float b) if( AddInstruction() < 0 ) return 0; - last->op = bc; - last->wArg[0] = a; - *((float*) ARG_DW(last->arg)) = b; - last->size = asBCTypeSize[asBCInfo[bc].type]; - last->stackInc = asBCInfo[bc].stackInc; + last->op = bc; + last->wArg[0] = a; + *((float *)ARG_DW(last->arg)) = b; + last->size = asBCTypeSize[asBCInfo[bc].type]; + last->stackInc = asBCInfo[bc].stackInc; return last->stackInc; } @@ -2803,10 +2807,10 @@ int asCByteCode::InstrINT(asEBCInstr bc, int param) if( AddInstruction() < 0 ) return 0; - last->op = bc; - *((int*) ARG_DW(last->arg)) = param; - last->size = asBCTypeSize[asBCInfo[bc].type]; - last->stackInc = asBCInfo[bc].stackInc; + last->op = bc; + *((int *)ARG_DW(last->arg)) = param; + last->size = asBCTypeSize[asBCInfo[bc].type]; + last->stackInc = asBCInfo[bc].stackInc; return last->stackInc; } @@ -2819,10 +2823,10 @@ int asCByteCode::InstrDWORD(asEBCInstr bc, asDWORD param) if( AddInstruction() < 0 ) return 0; - last->op = bc; + last->op = bc; *ARG_DW(last->arg) = param; - last->size = asBCTypeSize[asBCInfo[bc].type]; - last->stackInc = asBCInfo[bc].stackInc; + last->size = asBCTypeSize[asBCInfo[bc].type]; + last->stackInc = asBCInfo[bc].stackInc; return last->stackInc; } @@ -2837,8 +2841,8 @@ int asCByteCode::InstrPTR(asEBCInstr bc, void *param) last->op = bc; asASSERT(asBCInfo[bc].type == asBCTYPE_PTR_ARG); *ARG_PTR(last->arg) = (asPWORD)param; - last->size = asBCTypeSize[asBCInfo[bc].type]; - last->stackInc = asBCInfo[bc].stackInc; + last->size = asBCTypeSize[asBCInfo[bc].type]; + last->stackInc = asBCInfo[bc].stackInc; return last->stackInc; } @@ -2851,10 +2855,10 @@ int asCByteCode::InstrQWORD(asEBCInstr bc, asQWORD param) if( AddInstruction() < 0 ) return 0; - last->op = bc; + last->op = bc; *ARG_QW(last->arg) = param; - last->size = asBCTypeSize[asBCInfo[bc].type]; - last->stackInc = asBCInfo[bc].stackInc; + last->size = asBCTypeSize[asBCInfo[bc].type]; + last->stackInc = asBCInfo[bc].stackInc; return last->stackInc; } @@ -2885,10 +2889,10 @@ int asCByteCode::InstrFLOAT(asEBCInstr bc, float param) if( AddInstruction() < 0 ) return 0; - last->op = bc; - *((float*) ARG_DW(last->arg)) = param; - last->size = asBCTypeSize[asBCInfo[bc].type]; - last->stackInc = asBCInfo[bc].stackInc; + last->op = bc; + *((float *)ARG_DW(last->arg)) = param; + last->size = asBCTypeSize[asBCInfo[bc].type]; + last->stackInc = asBCInfo[bc].stackInc; return last->stackInc; } @@ -2901,15 +2905,15 @@ int asCByteCode::InstrDOUBLE(asEBCInstr bc, double param) if( AddInstruction() < 0 ) return 0; - last->op = bc; - *((double*) ARG_QW(last->arg)) = param; - last->size = asBCTypeSize[asBCInfo[bc].type]; - last->stackInc = asBCInfo[bc].stackInc; + last->op = bc; + *((double *)ARG_QW(last->arg)) = param; + last->size = asBCTypeSize[asBCInfo[bc].type]; + last->stackInc = asBCInfo[bc].stackInc; return last->stackInc; } -asCByteInstruction* asCByteCode::GetFirstInstr() +asCByteInstruction *asCByteCode::GetFirstInstr() { return first; } @@ -2929,12 +2933,12 @@ int asCByteCode::RemoveLastInstr() { engine->memoryMgr.FreeByteInstruction(last); first = 0; - last = 0; + last = 0; } else { asCByteInstruction *bc = last; - last = bc->prev; + last = bc->prev; bc->Remove(); engine->memoryMgr.FreeByteInstruction(bc); @@ -2954,20 +2958,20 @@ asDWORD asCByteCode::GetLastInstrValueDW() asCByteInstruction::asCByteInstruction() { - next = 0; - prev = 0; + next = 0; + prev = 0; - op = asBC_LABEL; + op = asBC_LABEL; - arg[0] = 0; - arg[1] = 0; - wArg[0] = 0; - wArg[1] = 0; - wArg[2] = 0; - size = 0; - stackInc = 0; - marked = false; - stackSize = 0; + arg[0] = 0; + arg[1] = 0; + wArg[0] = 0; + wArg[1] = 0; + wArg[2] = 0; + size = 0; + stackInc = 0; + marked = false; + stackSize = 0; } void asCByteInstruction::AddAfter(asCByteInstruction *nextCode) @@ -2977,7 +2981,7 @@ void asCByteInstruction::AddAfter(asCByteInstruction *nextCode) nextCode->next = next; nextCode->prev = this; - next = nextCode; + next = nextCode; } void asCByteInstruction::AddBefore(asCByteInstruction *prevCode) @@ -2987,7 +2991,7 @@ void asCByteInstruction::AddBefore(asCByteInstruction *prevCode) prevCode->prev = prev; prevCode->next = this; - prev = prevCode; + prev = prevCode; } int asCByteInstruction::GetSize() @@ -3011,4 +3015,3 @@ void asCByteInstruction::Remove() END_AS_NAMESPACE #endif // AS_NO_COMPILER - diff --git a/sdk/angelscript/source/as_bytecode.h b/sdk/angelscript/source/as_bytecode.h index 144db8c5..fefc8fdd 100644 --- a/sdk/angelscript/source/as_bytecode.h +++ b/sdk/angelscript/source/as_bytecode.h @@ -44,13 +44,13 @@ #ifndef AS_NO_COMPILER -#include "as_array.h" + #include "as_array.h" BEGIN_AS_NAMESPACE -#define BYTECODE_SIZE 4 -#define MAX_DATA_SIZE 8 -#define MAX_INSTR_SIZE (BYTECODE_SIZE+MAX_DATA_SIZE) + #define BYTECODE_SIZE 4 + #define MAX_DATA_SIZE 8 + #define MAX_INSTR_SIZE (BYTECODE_SIZE + MAX_DATA_SIZE) class asCScriptEngine; class asCScriptFunction; @@ -83,14 +83,14 @@ class asCByteCode void PostProcess(); -#ifdef AS_DEBUG + #ifdef AS_DEBUG void DebugOutput(const char *name, asCScriptFunction *func); -#endif + #endif asCByteInstruction *GetFirstInstr(); - int GetLastInstr(); - int RemoveLastInstr(); - asDWORD GetLastInstrValueDW(); + int GetLastInstr(); + int RemoveLastInstr(); + asDWORD GetLastInstrValueDW(); void InsertIfNotExists(asCArray &vars, int var); void GetVarsUsed(asCArray &vars); @@ -134,33 +134,38 @@ class asCByteCode int InstrW_W(asEBCInstr bc, int w, int b); int InstrSHORT_DW_DW(asEBCInstr bc, short a, asDWORD b, asDWORD c); - asCScriptEngine *GetEngine() const { return engine; }; + asCScriptEngine *GetEngine() const + { + return engine; + }; asCArray lineNumbers; asCArray sectionIdxs; - int largestStackUsed; + int largestStackUsed; protected: // Assignments are not allowed - void operator=(const asCByteCode &) {} + void operator=(const asCByteCode &) + { + } // Helpers for Optimize - bool CanBeSwapped(asCByteInstruction *curr); + bool CanBeSwapped(asCByteInstruction *curr); asCByteInstruction *ChangeFirstDeleteNext(asCByteInstruction *curr, asEBCInstr bc); asCByteInstruction *DeleteFirstChangeNext(asCByteInstruction *curr, asEBCInstr bc); asCByteInstruction *DeleteInstruction(asCByteInstruction *instr); - void RemoveInstruction(asCByteInstruction *instr); + void RemoveInstruction(asCByteInstruction *instr); asCByteInstruction *GoBack(asCByteInstruction *curr); asCByteInstruction *GoForward(asCByteInstruction *curr); - void InsertBefore(asCByteInstruction *before, asCByteInstruction *instr); - bool RemoveUnusedValue(asCByteInstruction *curr, asCByteInstruction **next); - bool IsTemporary(int offset); - bool IsTempRegUsed(asCByteInstruction *curr); - bool IsTempVarRead(asCByteInstruction *curr, int offset); - bool PostponeInitOfTemp(asCByteInstruction *curr, asCByteInstruction **next); - bool IsTempVarReadByInstr(asCByteInstruction *curr, int var); - bool IsTempVarOverwrittenByInstr(asCByteInstruction *curr, int var); - bool IsInstrJmpOrLabel(asCByteInstruction *curr); + void InsertBefore(asCByteInstruction *before, asCByteInstruction *instr); + bool RemoveUnusedValue(asCByteInstruction *curr, asCByteInstruction **next); + bool IsTemporary(int offset); + bool IsTempRegUsed(asCByteInstruction *curr); + bool IsTempVarRead(asCByteInstruction *curr, int offset); + bool PostponeInitOfTemp(asCByteInstruction *curr, asCByteInstruction **next); + bool IsTempVarReadByInstr(asCByteInstruction *curr, int var); + bool IsTempVarOverwrittenByInstr(asCByteInstruction *curr, int var); + bool IsInstrJmpOrLabel(asCByteInstruction *curr); int AddInstruction(); int AddInstructionFirst(); @@ -182,17 +187,17 @@ class asCByteInstruction void AddBefore(asCByteInstruction *nextCode); void Remove(); - int GetSize(); - int GetStackIncrease(); + int GetSize(); + int GetStackIncrease(); asCByteInstruction *next; asCByteInstruction *prev; asEBCInstr op; - asQWORD arg[2]; - short wArg[3]; - int size; - int stackInc; + asQWORD arg[2]; + short wArg[3]; + int size; + int stackInc; // Testing bool marked; diff --git a/sdk/angelscript/source/as_callfunc.cpp b/sdk/angelscript/source/as_callfunc.cpp index 03457e9e..ed37b446 100644 --- a/sdk/angelscript/source/as_callfunc.cpp +++ b/sdk/angelscript/source/as_callfunc.cpp @@ -71,13 +71,13 @@ int DetectCallingConvention(bool isMethod, const asSFuncPtr &ptr, int callConv, } asDWORD base = callConv; - if (base == asCALL_CDECL_OBJFIRST || base == asCALL_CDECL_OBJLAST) + if( base == asCALL_CDECL_OBJFIRST || base == asCALL_CDECL_OBJLAST ) { internal->callConv = - base == asCALL_CDECL_OBJFIRST ? ICC_CDECL_OBJFIRST : ICC_CDECL_OBJLAST; - if (!isMethod) + base == asCALL_CDECL_OBJFIRST ? ICC_CDECL_OBJFIRST : ICC_CDECL_OBJLAST; + if( !isMethod ) { - if (auxiliary == 0) + if( auxiliary == 0 ) return asINVALID_ARG; internal->auxiliary = auxiliary; } @@ -92,16 +92,16 @@ int DetectCallingConvention(bool isMethod, const asSFuncPtr &ptr, int callConv, internal->callConv = ICC_STDCALL; else if( base == asCALL_THISCALL_ASGLOBAL ) { - if(auxiliary == 0) + if( auxiliary == 0 ) return asINVALID_ARG; internal->auxiliary = auxiliary; internal->callConv = ICC_THISCALL; // This is really a thiscall, so it is necessary to check for virtual method pointers - base = asCALL_THISCALL; + base = asCALL_THISCALL; isMethod = true; } - else if (base == asCALL_GENERIC) + else if( base == asCALL_GENERIC ) { internal->callConv = ICC_GENERIC_FUNC; @@ -120,17 +120,17 @@ int DetectCallingConvention(bool isMethod, const asSFuncPtr &ptr, int callConv, internalCallConv thisCallConv; if( base == asCALL_THISCALL ) { - if(callConv != asCALL_THISCALL_ASGLOBAL && auxiliary) + if( callConv != asCALL_THISCALL_ASGLOBAL && auxiliary ) return asINVALID_ARG; thisCallConv = ICC_THISCALL; } else { -#ifdef AS_NO_THISCALL_FUNCTOR_METHOD + #ifdef AS_NO_THISCALL_FUNCTOR_METHOD return asNOT_SUPPORTED; -#else - if(auxiliary == 0) + #else + if( auxiliary == 0 ) return asINVALID_ARG; internal->auxiliary = auxiliary; @@ -138,35 +138,35 @@ int DetectCallingConvention(bool isMethod, const asSFuncPtr &ptr, int callConv, thisCallConv = ICC_THISCALL_OBJFIRST; else //if( base == asCALL_THISCALL_OBJLAST ) thisCallConv = ICC_THISCALL_OBJLAST; -#endif + #endif } internal->callConv = thisCallConv; -#ifdef GNU_STYLE_VIRTUAL_METHOD + #ifdef GNU_STYLE_VIRTUAL_METHOD if( (size_t(ptr.ptr.f.func) & 1) ) internal->callConv = (internalCallConv)(thisCallConv + 2); -#endif - internal->baseOffset = ( int )MULTI_BASE_OFFSET(ptr); -#if (defined(AS_ARM64) || defined(AS_ARM) || defined(AS_MIPS)) && (defined(__GNUC__) || defined(AS_PSVITA)) + #endif + internal->baseOffset = (int)MULTI_BASE_OFFSET(ptr); + #if ( defined(AS_ARM64) || defined(AS_ARM) || defined(AS_MIPS) ) && (defined(__GNUC__) || defined(AS_PSVITA)) // As the least significant bit in func is used to switch to THUMB mode // on ARM processors, the LSB in the __delta variable is used instead of // the one in __pfn on ARM processors. // MIPS also appear to use the base offset to indicate virtual method. if( (size_t(internal->baseOffset) & 1) ) internal->callConv = (internalCallConv)(thisCallConv + 2); -#endif + #endif -#ifdef HAVE_VIRTUAL_BASE_OFFSET + #ifdef HAVE_VIRTUAL_BASE_OFFSET // We don't support virtual inheritance if( VIRTUAL_BASE_OFFSET(ptr) != 0 ) return asNOT_SUPPORTED; -#endif + #endif } else #endif - if (base == asCALL_GENERIC) + if( base == asCALL_GENERIC ) { - internal->callConv = ICC_GENERIC_METHOD; + internal->callConv = ICC_GENERIC_METHOD; internal->auxiliary = auxiliary; } else @@ -193,15 +193,15 @@ int PrepareSystemFunctionGeneric(asCScriptFunction *func, asSSystemFunctionInter if( (dt.IsObject() || dt.IsFuncdef()) && !dt.IsReference() ) { - if (dt.IsFuncdef()) + if( dt.IsFuncdef() ) { // If the generic call mode is set to old behaviour then always release handles // else only release the handle if the function is declared with auto handles - if (engine->ep.genericCallMode == 0 || (internal->paramAutoHandles.GetLength() > n && internal->paramAutoHandles[n])) + if( engine->ep.genericCallMode == 0 || (internal->paramAutoHandles.GetLength() > n && internal->paramAutoHandles[n]) ) { asSSystemFunctionInterface::SClean clean; - clean.op = 0; // call release - clean.ot = &engine->functionBehaviours; + clean.op = 0; // call release + clean.ot = &engine->functionBehaviours; clean.off = short(offset); internal->cleanArgs.PushLast(clean); } @@ -210,17 +210,17 @@ int PrepareSystemFunctionGeneric(asCScriptFunction *func, asSSystemFunctionInter { // If the generic call mode is set to old behaviour then always release handles // else only release the handle if the function is declared with auto handles - if (!dt.IsObjectHandle() || - engine->ep.genericCallMode == 0 || - (internal->paramAutoHandles.GetLength() > n && internal->paramAutoHandles[n]) ) + if( !dt.IsObjectHandle() || + engine->ep.genericCallMode == 0 || + (internal->paramAutoHandles.GetLength() > n && internal->paramAutoHandles[n]) ) { asSTypeBehaviour *beh = &CastToObjectType(dt.GetTypeInfo())->beh; asASSERT((dt.GetTypeInfo()->flags & asOBJ_NOCOUNT) || beh->release); - if (beh->release) + if( beh->release ) { asSSystemFunctionInterface::SClean clean; - clean.op = 0; // call release - clean.ot = CastToObjectType(dt.GetTypeInfo()); + clean.op = 0; // call release + clean.ot = CastToObjectType(dt.GetTypeInfo()); clean.off = short(offset); internal->cleanArgs.PushLast(clean); } @@ -267,7 +267,7 @@ int PrepareSystemFunction(asCScriptFunction *func, asSSystemFunctionInterface *i if( func->returnType.IsReference() || func->returnType.IsObjectHandle() ) { internal->hostReturnInMemory = false; - internal->hostReturnSize = sizeof(void*)/4; + internal->hostReturnSize = sizeof(void *) / 4; internal->hostReturnFloat = false; } // Registered types have special flags that determine how they are returned @@ -292,8 +292,8 @@ int PrepareSystemFunction(asCScriptFunction *func, asSSystemFunctionInterface *i { // Array types are always returned in memory internal->hostReturnInMemory = true; - internal->hostReturnSize = sizeof(void*)/4; - internal->hostReturnFloat = false; + internal->hostReturnSize = sizeof(void *) / 4; + internal->hostReturnFloat = false; } else if( objType & asOBJ_APP_CLASS ) { @@ -301,85 +301,85 @@ int PrepareSystemFunction(asCScriptFunction *func, asSSystemFunctionInterface *i if( objType & COMPLEX_RETURN_MASK ) { internal->hostReturnInMemory = true; - internal->hostReturnSize = sizeof(void*)/4; + internal->hostReturnSize = sizeof(void *) / 4; } else { -#ifdef RETURN_VALUE_MAX_SIZE + #ifdef RETURN_VALUE_MAX_SIZE if( func->returnType.GetSizeInMemoryDWords() > RETURN_VALUE_MAX_SIZE ) -#elif defined(HAS_128_BIT_PRIMITIVES) + #elif defined(HAS_128_BIT_PRIMITIVES) if( func->returnType.GetSizeInMemoryDWords() > 4 ) -#else + #else if( func->returnType.GetSizeInMemoryDWords() > 2 ) -#endif + #endif { internal->hostReturnInMemory = true; - internal->hostReturnSize = sizeof(void*)/4; + internal->hostReturnSize = sizeof(void *) / 4; } else { internal->hostReturnInMemory = false; - internal->hostReturnSize = func->returnType.GetSizeInMemoryDWords(); -#ifdef SPLIT_OBJS_BY_MEMBER_TYPES - if (func->returnType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALLFLOATS) + internal->hostReturnSize = func->returnType.GetSizeInMemoryDWords(); + #ifdef SPLIT_OBJS_BY_MEMBER_TYPES + if( func->returnType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALLFLOATS ) { internal->hostReturnFloat = true; -#ifdef AS_RISCV64 + #ifdef AS_RISCV64 // TODO: There shouldn't be platform specific code in this file. Need to have a better way of controlling this // Perhaps by having a specific RETURN_MAX_FLOAT_REGS in as_config // On RISC-V 64bit & Linux only structures with two float or doubles can be returned in fa0:fa1 - if (!(func->returnType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALIGN8) && func->returnType.GetSizeInMemoryDWords() > 2) + if( !(func->returnType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALIGN8) && func->returnType.GetSizeInMemoryDWords() > 2 ) { // Since asOBJ_APP_ALIGN8 is not set we assume it is floats, and only 2 floats can be returned in registers // In this case the object will not be split by members, and instead it will be returned in a0:a1 internal->hostReturnFloat = false; } // On RISC-V 64bit & Linux floats within unions are not returned in fa0:fa1 - if (func->returnType.GetTypeInfo()->flags & asOBJ_APP_CLASS_UNION) + if( func->returnType.GetTypeInfo()->flags & asOBJ_APP_CLASS_UNION ) { internal->hostReturnFloat = false; } -#endif + #endif } -#endif + #endif } -#ifdef THISCALL_RETURN_SIMPLE_IN_MEMORY - if((internal->callConv == ICC_THISCALL || -#ifdef AS_NO_THISCALL_FUNCTOR_METHOD - internal->callConv == ICC_VIRTUAL_THISCALL) && -#else - internal->callConv == ICC_VIRTUAL_THISCALL || - internal->callConv == ICC_THISCALL_OBJFIRST || - internal->callConv == ICC_THISCALL_OBJLAST) && -#endif - func->returnType.GetSizeInMemoryDWords() >= THISCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE) + #ifdef THISCALL_RETURN_SIMPLE_IN_MEMORY + if( (internal->callConv == ICC_THISCALL || + #ifdef AS_NO_THISCALL_FUNCTOR_METHOD + internal->callConv == ICC_VIRTUAL_THISCALL) && + #else + internal->callConv == ICC_VIRTUAL_THISCALL || + internal->callConv == ICC_THISCALL_OBJFIRST || + internal->callConv == ICC_THISCALL_OBJLAST) && + #endif + func->returnType.GetSizeInMemoryDWords() >= THISCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE ) { internal->hostReturnInMemory = true; - internal->hostReturnSize = sizeof(void*)/4; + internal->hostReturnSize = sizeof(void *) / 4; } -#endif -#ifdef CDECL_RETURN_SIMPLE_IN_MEMORY - if((internal->callConv == ICC_CDECL || - internal->callConv == ICC_CDECL_OBJLAST || - internal->callConv == ICC_CDECL_OBJFIRST) && - func->returnType.GetSizeInMemoryDWords() >= CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE) + #endif + #ifdef CDECL_RETURN_SIMPLE_IN_MEMORY + if( (internal->callConv == ICC_CDECL || + internal->callConv == ICC_CDECL_OBJLAST || + internal->callConv == ICC_CDECL_OBJFIRST) && + func->returnType.GetSizeInMemoryDWords() >= CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE ) { internal->hostReturnInMemory = true; - internal->hostReturnSize = sizeof(void*)/4; + internal->hostReturnSize = sizeof(void *) / 4; } -#endif -#ifdef STDCALL_RETURN_SIMPLE_IN_MEMORY + #endif + #ifdef STDCALL_RETURN_SIMPLE_IN_MEMORY if( internal->callConv == ICC_STDCALL && - func->returnType.GetSizeInMemoryDWords() >= STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE) + func->returnType.GetSizeInMemoryDWords() >= STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE ) { internal->hostReturnInMemory = true; - internal->hostReturnSize = sizeof(void*)/4; + internal->hostReturnSize = sizeof(void *) / 4; } -#endif + #endif } -#ifdef SPLIT_OBJS_BY_MEMBER_TYPES + #ifdef SPLIT_OBJS_BY_MEMBER_TYPES // It's not safe to return objects by value because different registers // will be used depending on the memory layout of the object. // Ref: http://www.x86-64.org/documentation/abi.pdf @@ -395,7 +395,7 @@ int PrepareSystemFunction(asCScriptFunction *func, asSSystemFunctionInterface *i engine->WriteMessage("", 0, 0, asMSGTYPE_ERROR, str.AddressOf()); engine->ConfigError(asINVALID_CONFIGURATION, 0, 0, 0); } -#endif + #endif } else if( objType & asOBJ_APP_PRIMITIVE ) { @@ -411,7 +411,7 @@ int PrepareSystemFunction(asCScriptFunction *func, asSSystemFunctionInterface *i } } // Primitive types can easily be determined -#ifdef HAS_128_BIT_PRIMITIVES + #ifdef HAS_128_BIT_PRIMITIVES else if( func->returnType.GetSizeInMemoryDWords() > 4 ) { // Shouldn't be possible to get here @@ -423,13 +423,13 @@ int PrepareSystemFunction(asCScriptFunction *func, asSSystemFunctionInterface *i internal->hostReturnSize = 4; internal->hostReturnFloat = false; } -#else + #else else if( func->returnType.GetSizeInMemoryDWords() > 2 ) { // Shouldn't be possible to get here asASSERT(false); } -#endif + #endif else if( func->returnType.GetSizeInMemoryDWords() == 2 ) { internal->hostReturnInMemory = false; @@ -473,18 +473,18 @@ int PrepareSystemFunction(asCScriptFunction *func, asSSystemFunctionInterface *i } -#ifdef SPLIT_OBJS_BY_MEMBER_TYPES + #ifdef SPLIT_OBJS_BY_MEMBER_TYPES // It's not safe to pass objects by value because different registers // will be used depending on the memory layout of the object // Ref: http://www.x86-64.org/documentation/abi.pdf // Ref: http://www.agner.org/optimize/calling_conventions.pdf if( -#ifdef COMPLEX_OBJS_PASSED_BY_REF + #ifdef COMPLEX_OBJS_PASSED_BY_REF !(func->parameterTypes[n].GetTypeInfo()->flags & COMPLEX_MASK) && -#endif -#ifdef LARGE_OBJS_PASS_BY_REF + #endif + #ifdef LARGE_OBJS_PASS_BY_REF func->parameterTypes[n].GetSizeInMemoryDWords() < AS_LARGE_OBJ_MIN_SIZE && -#endif + #endif !(func->parameterTypes[n].GetTypeInfo()->flags & (asOBJ_APP_PRIMITIVE | asOBJ_APP_FLOAT | asOBJ_APP_CLASS_ALLINTS | asOBJ_APP_CLASS_ALLFLOATS)) ) { engine->WriteMessage("", 0, 0, asMSGTYPE_INFORMATION, func->GetDeclarationStr().AddressOf()); @@ -494,7 +494,7 @@ int PrepareSystemFunction(asCScriptFunction *func, asSSystemFunctionInterface *i engine->WriteMessage("", 0, 0, asMSGTYPE_ERROR, str.AddressOf()); engine->ConfigError(asINVALID_CONFIGURATION, 0, 0, 0); } -#endif + #endif break; } } @@ -506,43 +506,43 @@ int PrepareSystemFunction(asCScriptFunction *func, asSSystemFunctionInterface *i { asCDataType &dt = func->parameterTypes[n]; -#if defined(COMPLEX_OBJS_PASSED_BY_REF) || defined(AS_LARGE_OBJS_PASSED_BY_REF) + #if defined(COMPLEX_OBJS_PASSED_BY_REF) || defined(AS_LARGE_OBJS_PASSED_BY_REF) bool needFree = false; -#ifdef COMPLEX_OBJS_PASSED_BY_REF + #ifdef COMPLEX_OBJS_PASSED_BY_REF if( dt.GetTypeInfo() && dt.GetTypeInfo()->flags & COMPLEX_MASK ) needFree = true; -#endif -#ifdef AS_LARGE_OBJS_PASSED_BY_REF + #endif + #ifdef AS_LARGE_OBJS_PASSED_BY_REF if( dt.GetSizeInMemoryDWords() >= AS_LARGE_OBJ_MIN_SIZE ) needFree = true; -#endif + #endif if( needFree && - dt.IsObject() && - !dt.IsObjectHandle() && - !dt.IsReference() ) + dt.IsObject() && + !dt.IsObjectHandle() && + !dt.IsReference() ) { asSSystemFunctionInterface::SClean clean; clean.op = 1; // call free clean.ot = CastToObjectType(dt.GetTypeInfo()); clean.off = short(offset); -#ifndef AS_CALLEE_DESTROY_OBJ_BY_VAL + #ifndef AS_CALLEE_DESTROY_OBJ_BY_VAL // If the called function doesn't destroy objects passed by value we must do so here asSTypeBehaviour *beh = &CastToObjectType(dt.GetTypeInfo())->beh; if( beh->destruct ) clean.op = 2; // call destruct, then free -#endif + #endif internal->cleanArgs.PushLast(clean); } -#endif + #endif if( n < internal->paramAutoHandles.GetLength() && internal->paramAutoHandles[n] ) { asSSystemFunctionInterface::SClean clean; - clean.op = 0; // call release - if (dt.IsFuncdef()) + clean.op = 0; // call release + if( dt.IsFuncdef() ) clean.ot = &engine->functionBehaviours; else - clean.ot = CastToObjectType(dt.GetTypeInfo()); + clean.ot = CastToObjectType(dt.GetTypeInfo()); clean.off = short(offset); internal->cleanArgs.PushLast(clean); } @@ -560,10 +560,10 @@ int PrepareSystemFunction(asCScriptFunction *func, asSSystemFunctionInterface *i int CallSystemFunction(int id, asCContext *context) { - asCScriptEngine *engine = context->m_engine; - asCScriptFunction *func = engine->scriptFunctions[id]; - asSSystemFunctionInterface *sysFunc = func->sysFuncIntf; - int callConv = sysFunc->callConv; + asCScriptEngine *engine = context->m_engine; + asCScriptFunction *func = engine->scriptFunctions[id]; + asSSystemFunctionInterface *sysFunc = func->sysFuncIntf; + int callConv = sysFunc->callConv; if( callConv == ICC_GENERIC_FUNC || callConv == ICC_GENERIC_METHOD ) return context->CallGeneric(func); @@ -577,7 +577,7 @@ int CallSystemFunction(int id, asCContext *context) // TODO: cleanup: Should have only a single CallSystemFunctionNative function signature. However changing it requires retesting all different native platforms :( -#ifndef RETURN_VALUE_MAX_SIZE + #ifndef RETURN_VALUE_MAX_SIZE // // CallSystemFunctionNative @@ -601,7 +601,7 @@ int CallSystemFunction(int id, asCContext *context) // The function should return the value that is returned in registers. asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &retQW2, void *secondObj); -#else + #else // // CallSystemFunctionNative @@ -621,7 +621,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // secondObj - This is the object pointer that the proxy method should invoke its method on when the call convention is THISCALL_OBJFIRST/LAST void CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD *retQW, void *secondObj); -#endif + #endif int CallSystemFunction(int id, asCContext *context) @@ -634,27 +634,27 @@ int CallSystemFunction(int id, asCContext *context) if( callConv == ICC_GENERIC_FUNC || callConv == ICC_GENERIC_METHOD ) return context->CallGeneric(descr); -#ifndef RETURN_VALUE_MAX_SIZE - asQWORD retQW[2] = { 0 }; -#else - asQWORD retQW[(RETURN_VALUE_MAX_SIZE + 1) / 2] = { 0 }; -#endif - asDWORD *args = context->m_regs.stackPointer; - void *retPointer = 0; - int popSize = sysFunc->paramSize; + #ifndef RETURN_VALUE_MAX_SIZE + asQWORD retQW[2] = {0}; + #else + asQWORD retQW[(RETURN_VALUE_MAX_SIZE + 1) / 2] = {0}; + #endif + asDWORD *args = context->m_regs.stackPointer; + void *retPointer = 0; + int popSize = sysFunc->paramSize; // TODO: clean-up: CallSystemFunctionNative should have two arguments for object pointers // objForThiscall is the object pointer that should be used for the thiscall // objForArg is the object pointer that should be passed as argument when using OBJFIRST or OBJLAST // Used to save two object pointers with THISCALL_OBJLAST or THISCALL_OBJFIRST - void *obj = 0; + void *obj = 0; void *secondObj = 0; -#ifdef AS_NO_THISCALL_FUNCTOR_METHOD + #ifdef AS_NO_THISCALL_FUNCTOR_METHOD if( callConv >= ICC_THISCALL ) { - if(sysFunc->auxiliary) + if( sysFunc->auxiliary ) { // This class method is being called as if it is a global function obj = sysFunc->auxiliary; @@ -665,7 +665,7 @@ int CallSystemFunction(int id, asCContext *context) popSize += AS_PTR_SIZE; // Check for null pointer - obj = (void*)*(asPWORD*)(args); + obj = (void *)*(asPWORD *)(args); if( obj == 0 ) { context->SetInternalException(TXT_NULL_POINTER_ACCESS); @@ -675,55 +675,55 @@ int CallSystemFunction(int id, asCContext *context) // Skip the object pointer args += AS_PTR_SIZE; } - - // Add the base offset for multiple inheritance -#if (defined(__GNUC__) && (defined(AS_ARM64) || defined(AS_ARM) || defined(AS_MIPS))) || defined(AS_PSVITA) + + // Add the base offset for multiple inheritance + #if ( defined(__GNUC__) && (defined(AS_ARM64) || defined(AS_ARM) || defined(AS_MIPS)) ) || defined(AS_PSVITA) // On GNUC + ARM the lsb of the offset is used to indicate a virtual function // and the whole offset is thus shifted one bit left to keep the original // offset resolution // MIPS also work like ARM in this regard - obj = (void*)(asPWORD(obj) + (sysFunc->baseOffset>>1)); -#else - obj = (void*)(asPWORD(obj) + sysFunc->baseOffset); -#endif + obj = (void *)(asPWORD(obj) + (sysFunc->baseOffset >> 1)); + #else + obj = (void *)(asPWORD(obj) + sysFunc->baseOffset); + #endif } -#else // !defined(AS_NO_THISCALL_FUNCTOR_METHOD) + #else // !defined(AS_NO_THISCALL_FUNCTOR_METHOD) if( callConv >= ICC_THISCALL ) { - bool continueCheck = true; // True if need check objectPointer or context stack for object - int continueCheckIndex = 0; // Index into objectsPtrs to save the object if continueCheck + bool continueCheck = true; // True if need check objectPointer or context stack for object + int continueCheckIndex = 0; // Index into objectsPtrs to save the object if continueCheck if( callConv >= ICC_THISCALL_OBJLAST ) { asASSERT( sysFunc->auxiliary != 0 ); // This class method is being called as object method (sysFunc->auxiliary must be set). - obj = sysFunc->auxiliary; + obj = sysFunc->auxiliary; continueCheckIndex = 1; } - else if(sysFunc->auxiliary) + else if( sysFunc->auxiliary ) { // This class method is being called as if it is a global function - obj = sysFunc->auxiliary; + obj = sysFunc->auxiliary; continueCheck = false; } - + if( obj ) { // For composition we need to add the offset and/or dereference the pointer - obj = (void*)((char*)obj + sysFunc->compositeOffset); - if (sysFunc->isCompositeIndirect) obj = *((void**)obj); + obj = (void *)((char *)obj + sysFunc->compositeOffset); + if( sysFunc->isCompositeIndirect ) obj = *((void **)obj); - // Add the base offset for multiple inheritance -#if (defined(__GNUC__) && (defined(AS_ARM64) || defined(AS_ARM) || defined(AS_MIPS))) || defined(AS_PSVITA) + // Add the base offset for multiple inheritance + #if ( defined(__GNUC__) && (defined(AS_ARM64) || defined(AS_ARM) || defined(AS_MIPS)) ) || defined(AS_PSVITA) // On GNUC + ARM the lsb of the offset is used to indicate a virtual function // and the whole offset is thus shifted one bit left to keep the original // offset resolution // MIPS also work like ARM in this regard - obj = (void*)(asPWORD(obj) + (sysFunc->baseOffset>>1)); -#else - obj = (void*)(asPWORD(obj) + sysFunc->baseOffset); -#endif + obj = (void *)(asPWORD(obj) + (sysFunc->baseOffset >> 1)); + #else + obj = (void *)(asPWORD(obj) + sysFunc->baseOffset); + #endif } if( continueCheck ) @@ -734,7 +734,7 @@ int CallSystemFunction(int id, asCContext *context) popSize += AS_PTR_SIZE; // Check for null pointer - tempPtr = (void*)*(asPWORD*)(args); + tempPtr = (void *)*(asPWORD *)(args); if( tempPtr == 0 ) { context->SetInternalException(TXT_NULL_POINTER_ACCESS); @@ -742,19 +742,19 @@ int CallSystemFunction(int id, asCContext *context) } // For composition we need to add the offset and/or dereference the pointer - tempPtr = (void*)((char*)tempPtr + sysFunc->compositeOffset); - if (sysFunc->isCompositeIndirect) tempPtr = *((void**)tempPtr); + tempPtr = (void *)((char *)tempPtr + sysFunc->compositeOffset); + if( sysFunc->isCompositeIndirect ) tempPtr = *((void **)tempPtr); - // Add the base offset for multiple inheritance -#if (defined(__GNUC__) && (defined(AS_ARM64) || defined(AS_ARM) || defined(AS_MIPS))) || defined(AS_PSVITA) + // Add the base offset for multiple inheritance + #if ( defined(__GNUC__) && (defined(AS_ARM64) || defined(AS_ARM) || defined(AS_MIPS)) ) || defined(AS_PSVITA) // On GNUC + ARM the lsb of the offset is used to indicate a virtual function // and the whole offset is thus shifted one bit left to keep the original // offset resolution // MIPS also work like ARM in this regard - tempPtr = (void*)(asPWORD(tempPtr) + (sysFunc->baseOffset>>1)); -#else - tempPtr = (void*)(asPWORD(tempPtr) + sysFunc->baseOffset); -#endif + tempPtr = (void *)(asPWORD(tempPtr) + (sysFunc->baseOffset >> 1)); + #else + tempPtr = (void *)(asPWORD(tempPtr) + sysFunc->baseOffset); + #endif // Skip the object pointer args += AS_PTR_SIZE; @@ -768,14 +768,14 @@ int CallSystemFunction(int id, asCContext *context) } } } -#endif // AS_NO_THISCALL_FUNCTOR_METHOD + #endif // AS_NO_THISCALL_FUNCTOR_METHOD if( descr->DoesReturnOnStack() ) { // Get the address of the location for the return value from the stack - retPointer = (void*)*(asPWORD*)(args); - popSize += AS_PTR_SIZE; - args += AS_PTR_SIZE; + retPointer = (void *)*(asPWORD *)(args); + popSize += AS_PTR_SIZE; + args += AS_PTR_SIZE; // When returning the value on the location allocated by the called // we shouldn't set the object type in the register @@ -788,14 +788,14 @@ int CallSystemFunction(int id, asCContext *context) } context->m_callingSystemFunction = descr; - bool cppException = false; -#ifdef AS_NO_EXCEPTIONS -#ifndef RETURN_VALUE_MAX_SIZE + bool cppException = false; + #ifdef AS_NO_EXCEPTIONS + #ifndef RETURN_VALUE_MAX_SIZE retQW[0] = CallSystemFunctionNative(context, descr, obj, args, sysFunc->hostReturnInMemory ? retPointer : 0, retQW[1], secondObj); -#else + #else CallSystemFunctionNative(context, descr, obj, args, sysFunc->hostReturnInMemory ? retPointer : 0, retQW, secondObj); -#endif -#else + #endif + #else // This try/catch block is to catch potential exception that may // be thrown by the registered function. The implementation of the // CallSystemFunctionNative() must make sure not to have any manual @@ -803,13 +803,12 @@ int CallSystemFunction(int id, asCContext *context) // executed in case of an exception. try { -#ifndef RETURN_VALUE_MAX_SIZE + #ifndef RETURN_VALUE_MAX_SIZE retQW[0] = CallSystemFunctionNative(context, descr, obj, args, sysFunc->hostReturnInMemory ? retPointer : 0, retQW[1], secondObj); -#else + #else CallSystemFunctionNative(context, descr, obj, args, sysFunc->hostReturnInMemory ? retPointer : 0, retQW, secondObj); -#endif - } - catch(...) + #endif + } catch( ... ) { cppException = true; @@ -817,54 +816,54 @@ int CallSystemFunction(int id, asCContext *context) // properly report the error to the application and then clean up context->HandleAppException(); } -#endif + #endif context->m_callingSystemFunction = 0; // Store the returned value in our stack if( (descr->returnType.IsObject() || descr->returnType.IsFuncdef()) && !descr->returnType.IsReference() ) { - if (descr->returnType.IsObjectHandle()) + if( descr->returnType.IsObjectHandle() ) { -#if defined(AS_BIG_ENDIAN) && AS_PTR_SIZE == 1 + #if defined(AS_BIG_ENDIAN) && AS_PTR_SIZE == 1 // Since we're treating the system function as if it is returning a QWORD we are // actually receiving the value in the high DWORD of retQW[0]. retQW[0] >>= 32; -#endif + #endif - context->m_regs.objectRegister = (void*)(asPWORD)retQW[0]; + context->m_regs.objectRegister = (void *)(asPWORD)retQW[0]; - if (sysFunc->returnAutoHandle && context->m_regs.objectRegister) + if( sysFunc->returnAutoHandle && context->m_regs.objectRegister ) { asASSERT(!(descr->returnType.GetTypeInfo()->flags & asOBJ_NOCOUNT)); engine->CallObjectMethod(context->m_regs.objectRegister, CastToObjectType(descr->returnType.GetTypeInfo())->beh.addref); } } - else if (retPointer) + else if( retPointer ) { - if (!sysFunc->hostReturnInMemory) + if( !sysFunc->hostReturnInMemory ) { // Copy the returned value to the pointer sent by the script engine - if (sysFunc->hostReturnSize == 1) + if( sysFunc->hostReturnSize == 1 ) { -#if defined(AS_BIG_ENDIAN) && AS_PTR_SIZE == 1 + #if defined(AS_BIG_ENDIAN) && AS_PTR_SIZE == 1 // Since we're treating the system function as if it is returning a QWORD we are // actually receiving the value in the high DWORD of retQW[0]. retQW[0] >>= 32; -#endif + #endif - *(asDWORD*)retPointer = (asDWORD)retQW[0]; + *(asDWORD *)retPointer = (asDWORD)retQW[0]; } - else if (sysFunc->hostReturnSize == 2) - *(asQWORD*)retPointer = retQW[0]; - else if (sysFunc->hostReturnSize == 3) + else if( sysFunc->hostReturnSize == 2 ) + *(asQWORD *)retPointer = retQW[0]; + else if( sysFunc->hostReturnSize == 3 ) { - *(asQWORD*)retPointer = retQW[0]; - *(((asDWORD*)retPointer) + 2) = (asDWORD)retQW[1]; + *(asQWORD *)retPointer = retQW[0]; + *(((asDWORD *)retPointer) + 2) = (asDWORD)retQW[1]; } else if( sysFunc->hostReturnSize == 4 ) { - *(asQWORD*)retPointer = retQW[0]; - *(((asQWORD*)retPointer) + 1) = retQW[1]; + *(asQWORD *)retPointer = retQW[0]; + *(((asQWORD *)retPointer) + 1) = retQW[1]; } else { @@ -872,13 +871,13 @@ int CallSystemFunction(int id, asCContext *context) } } - if (context->m_status == asEXECUTION_EXCEPTION && !cppException) + if( context->m_status == asEXECUTION_EXCEPTION && !cppException ) { // If the function raised a script exception it really shouldn't have // initialized the object. However, as it is a soft exception there is // no way for the application to not return a value, so instead we simply // destroy it here, to pretend it was never created. - if (CastToObjectType(descr->returnType.GetTypeInfo())->beh.destruct) + if( CastToObjectType(descr->returnType.GetTypeInfo())->beh.destruct ) engine->CallObjectMethod(retPointer, CastToObjectType(descr->returnType.GetTypeInfo())->beh.destruct); } } @@ -893,7 +892,7 @@ int CallSystemFunction(int id, asCContext *context) // Store value in value register if( sysFunc->hostReturnSize == 1 ) { -#if defined(AS_BIG_ENDIAN) + #if defined(AS_BIG_ENDIAN) // Since we're treating the system function as if it is returning a QWORD we are // actually receiving the value in the high DWORD of retQW[0]. retQW[0] >>= 32; @@ -904,42 +903,42 @@ int CallSystemFunction(int id, asCContext *context) if( descr->returnType.IsReference() ) numBytes = 4; switch( numBytes ) { - case 1: + case 1: { // 8 bits - asBYTE *val = (asBYTE*)&context->m_regs.valueRegister; - val[0] = (asBYTE)retQW[0]; - val[1] = 0; - val[2] = 0; - val[3] = 0; - val[4] = 0; - val[5] = 0; - val[6] = 0; - val[7] = 0; + asBYTE *val = (asBYTE *)&context->m_regs.valueRegister; + val[0] = (asBYTE)retQW[0]; + val[1] = 0; + val[2] = 0; + val[3] = 0; + val[4] = 0; + val[5] = 0; + val[6] = 0; + val[7] = 0; } break; - case 2: + case 2: { // 16 bits - asWORD *val = (asWORD*)&context->m_regs.valueRegister; - val[0] = (asWORD)retQW[0]; - val[1] = 0; - val[2] = 0; - val[3] = 0; + asWORD *val = (asWORD *)&context->m_regs.valueRegister; + val[0] = (asWORD)retQW[0]; + val[1] = 0; + val[2] = 0; + val[3] = 0; } break; - default: + default: { // 32 bits - asDWORD *val = (asDWORD*)&context->m_regs.valueRegister; - val[0] = (asDWORD)retQW[0]; - val[1] = 0; + asDWORD *val = (asDWORD *)&context->m_regs.valueRegister; + val[0] = (asDWORD)retQW[0]; + val[1] = 0; } break; } -#else - *(asDWORD*)&context->m_regs.valueRegister = (asDWORD)retQW[0]; -#endif + #else + *(asDWORD *)&context->m_regs.valueRegister = (asDWORD)retQW[0]; + #endif } else context->m_regs.valueRegister = retQW[0]; @@ -964,7 +963,7 @@ int CallSystemFunction(int id, asCContext *context) asSSystemFunctionInterface::SClean *clean = sysFunc->cleanArgs.AddressOf(); for( asUINT n = 0; n < cleanCount; n++, clean++ ) { - void **addr = (void**)&args[clean->off]; + void **addr = (void **)&args[clean->off]; if( clean->op == 0 ) { if( *addr != 0 ) @@ -992,4 +991,3 @@ int CallSystemFunction(int id, asCContext *context) #endif // AS_MAX_PORTABILITY END_AS_NAMESPACE - diff --git a/sdk/angelscript/source/as_callfunc.h b/sdk/angelscript/source/as_callfunc.h index 8bb6ffe3..d92090ed 100644 --- a/sdk/angelscript/source/as_callfunc.h +++ b/sdk/angelscript/source/as_callfunc.h @@ -61,14 +61,17 @@ inline asPWORD FuncPtrToUInt(asFUNCTION_t func) { // A little trickery as the C++ standard doesn't allow direct // conversion between function pointer and data pointer - union { asFUNCTION_t func; asPWORD idx; } u; + union + { + asFUNCTION_t func; + asPWORD idx; + } u; u.func = func; return u.idx; } -enum internalCallConv -{ +enum internalCallConv { ICC_GENERIC_FUNC, ICC_GENERIC_FUNC_RETURNINMEM, // never used ICC_CDECL, @@ -97,31 +100,31 @@ enum internalCallConv struct asSSystemFunctionInterface { - asFUNCTION_t func; - int baseOffset; - internalCallConv callConv; - bool hostReturnInMemory; - bool hostReturnFloat; - int hostReturnSize; - int paramSize; - bool takesObjByVal; - asCArray paramAutoHandles; // TODO: Should be able to remove this array. Perhaps the flags can be stored together with the inOutFlags in asCScriptFunction? - bool returnAutoHandle; - int compositeOffset; - bool isCompositeIndirect; - void *auxiliary; // can be used for functors, e.g. by asCALL_THISCALL_ASGLOBAL or asCALL_THISCALL_OBJFIRST + asFUNCTION_t func; + int baseOffset; + internalCallConv callConv; + bool hostReturnInMemory; + bool hostReturnFloat; + int hostReturnSize; + int paramSize; + bool takesObjByVal; + asCArray paramAutoHandles; // TODO: Should be able to remove this array. Perhaps the flags can be stored together with the inOutFlags in asCScriptFunction? + bool returnAutoHandle; + int compositeOffset; + bool isCompositeIndirect; + void *auxiliary; // can be used for functors, e.g. by asCALL_THISCALL_ASGLOBAL or asCALL_THISCALL_OBJFIRST struct SClean { - asCObjectType *ot; // argument type for clean up - short op; // clean up operation: 0 = release, 1 = free, 2 = destruct then free - short off; // argument offset on the stack + asCObjectType *ot; // argument type for clean up + short op; // clean up operation: 0 = release, 1 = free, 2 = destruct then free + short off; // argument offset on the stack }; - asCArray cleanArgs; + asCArray cleanArgs; asSSystemFunctionInterface() - { - Clear(); + { + Clear(); } asSSystemFunctionInterface(const asSSystemFunctionInterface &in) @@ -163,8 +166,8 @@ struct asSSystemFunctionInterface isCompositeIndirect = in.isCompositeIndirect; auxiliary = in.auxiliary; - cleanArgs = in.cleanArgs; - paramAutoHandles = in.paramAutoHandles; + cleanArgs = in.cleanArgs; + paramAutoHandles = in.paramAutoHandles; return *this; } @@ -173,4 +176,3 @@ struct asSSystemFunctionInterface END_AS_NAMESPACE #endif - diff --git a/sdk/angelscript/source/as_callfunc_arm.cpp b/sdk/angelscript/source/as_callfunc_arm.cpp index af45818f..21623745 100644 --- a/sdk/angelscript/source/as_callfunc_arm.cpp +++ b/sdk/angelscript/source/as_callfunc_arm.cpp @@ -51,15 +51,15 @@ #include "as_config.h" #ifndef AS_MAX_PORTABILITY -#ifdef AS_ARM + #ifdef AS_ARM -#include "as_callfunc.h" -#include "as_scriptengine.h" -#include "as_texts.h" -#include "as_tokendef.h" -#include "as_context.h" + #include "as_callfunc.h" + #include "as_scriptengine.h" + #include "as_texts.h" + #include "as_tokendef.h" + #include "as_context.h" -#if defined(AS_SOFTFP) + #if defined(AS_SOFTFP) // This code supports the soft-float ABI, i.e. g++ -mfloat-abi=softfp // @@ -67,17 +67,17 @@ BEGIN_AS_NAMESPACE -extern "C" asQWORD armFunc (const asDWORD *, int, asFUNCTION_t); -extern "C" asQWORD armFuncR0 (const asDWORD *, int, asFUNCTION_t, asDWORD r0); -extern "C" asQWORD armFuncR0R1 (const asDWORD *, int, asFUNCTION_t, asDWORD r0, asDWORD r1); -extern "C" asQWORD armFuncObjLast (const asDWORD *, int, asFUNCTION_t, asDWORD obj); -extern "C" asQWORD armFuncR0ObjLast (const asDWORD *, int, asFUNCTION_t, asDWORD r0, asDWORD obj); +extern "C" asQWORD armFunc(const asDWORD *, int, asFUNCTION_t); +extern "C" asQWORD armFuncR0(const asDWORD *, int, asFUNCTION_t, asDWORD r0); +extern "C" asQWORD armFuncR0R1(const asDWORD *, int, asFUNCTION_t, asDWORD r0, asDWORD r1); +extern "C" asQWORD armFuncObjLast(const asDWORD *, int, asFUNCTION_t, asDWORD obj); +extern "C" asQWORD armFuncR0ObjLast(const asDWORD *, int, asFUNCTION_t, asDWORD r0, asDWORD obj); -asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &/*retQW2*/, void *secondObject) +asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD & /*retQW2*/, void *secondObject) { - asCScriptEngine *engine = context->m_engine; - asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; - int callConv = sysFunc->callConv; + asCScriptEngine *engine = context->m_engine; + asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; + int callConv = sysFunc->callConv; asQWORD retQW = 0; asFUNCTION_t func = sysFunc->func; @@ -92,17 +92,17 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, bool isThisCallMethod = callConv >= ICC_THISCALL_OBJLAST; - asDWORD paramBuffer[64+2]; - // Android & Linux needs to align 64bit types on even registers, but this isn't done on iOS or Windows Phone - // TODO: optimize runtime: There should be a check for this in PrepareSystemFunction() so this - // doesn't have to be done for functions that don't have any 64bit types -#if !defined(AS_ANDROID) && !defined(AS_LINUX) + asDWORD paramBuffer[64 + 2]; + // Android & Linux needs to align 64bit types on even registers, but this isn't done on iOS or Windows Phone + // TODO: optimize runtime: There should be a check for this in PrepareSystemFunction() so this + // doesn't have to be done for functions that don't have any 64bit types + #if !defined(AS_ANDROID) && !defined(AS_LINUX) // In cases of thiscall methods, the callstack is configured as a standard thiscall // adding the secondObject as first or last element in callstack if( sysFunc->takesObjByVal || isThisCallMethod ) -#endif + #endif { -#if defined(AS_ANDROID) || defined(AS_LINUX) + #if defined(AS_ANDROID) || defined(AS_LINUX) // mask is used as a toggler to skip uneven registers. int mask = 1; @@ -131,13 +131,13 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // Check for hidden address in case of return by value if( sysFunc->hostReturnInMemory ) mask = !mask; -#endif + #endif paramSize = 0; - int spos = 0; - int dpos = 2; + int spos = 0; + int dpos = 2; if( isThisCallMethod && (callConv >= ICC_THISCALL_OBJFIRST && - callConv <= ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM) ) + callConv <= ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM) ) { // Add the object pointer as the first parameter paramBuffer[dpos++] = (asDWORD)secondObject; @@ -149,48 +149,48 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // TODO: runtime optimize: Declare a reference to descr->parameterTypes[n] so the array doesn't have to be access all the time if( descr->parameterTypes[n].IsObject() && !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() ) { -#ifdef COMPLEX_OBJS_PASSED_BY_REF + #ifdef COMPLEX_OBJS_PASSED_BY_REF if( descr->parameterTypes[n].GetTypeInfo()->flags & COMPLEX_MASK ) { paramBuffer[dpos++] = args[spos++]; paramSize++; } else -#endif + #endif { -#if defined(AS_ANDROID) || defined(AS_LINUX) + #if defined(AS_ANDROID) || defined(AS_LINUX) if( (descr->parameterTypes[n].GetTypeInfo()->flags & asOBJ_APP_CLASS_ALIGN8) && - ((dpos & 1) == mask) ) + ((dpos & 1) == mask) ) { // 64 bit value align dpos++; paramSize++; } -#endif + #endif // Copy the object's memory to the buffer - memcpy(¶mBuffer[dpos], *(void**)(args+spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); + memcpy(¶mBuffer[dpos], *(void **)(args + spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); // Delete the original memory - engine->CallFree(*(char**)(args+spos)); + engine->CallFree(*(char **)(args + spos)); spos++; - dpos += descr->parameterTypes[n].GetSizeInMemoryDWords(); + dpos += descr->parameterTypes[n].GetSizeInMemoryDWords(); paramSize += descr->parameterTypes[n].GetSizeInMemoryDWords(); } } else { -#if defined(AS_ANDROID) || defined(AS_LINUX) + #if defined(AS_ANDROID) || defined(AS_LINUX) // Should an alignment be performed? - if( !descr->parameterTypes[n].IsObjectHandle() && - !descr->parameterTypes[n].IsReference() && - descr->parameterTypes[n].GetSizeOnStackDWords() == 2 && - ((dpos & 1) == mask) ) + if( !descr->parameterTypes[n].IsObjectHandle() && + !descr->parameterTypes[n].IsReference() && + descr->parameterTypes[n].GetSizeOnStackDWords() == 2 && + ((dpos & 1) == mask) ) { // 64 bit value align dpos++; paramSize++; } -#endif + #endif // Copy the value directly paramBuffer[dpos++] = args[spos++]; @@ -201,7 +201,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, } if( isThisCallMethod && (callConv >= ICC_THISCALL_OBJLAST && - callConv <= ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM) ) + callConv <= ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM) ) { // Add the object pointer as the last parameter paramBuffer[dpos++] = (asDWORD)secondObject; @@ -214,62 +214,62 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, switch( callConv ) { - case ICC_CDECL_RETURNINMEM: // fall through - case ICC_STDCALL_RETURNINMEM: - retQW = armFuncR0(args, paramSize<<2, func, (asDWORD)retPointer); - break; - case ICC_CDECL: // fall through - case ICC_STDCALL: - retQW = armFunc(args, paramSize<<2, func); - break; - case ICC_THISCALL: // fall through - case ICC_CDECL_OBJFIRST: - case ICC_THISCALL_OBJFIRST: - case ICC_THISCALL_OBJLAST: - retQW = armFuncR0(args, paramSize<<2, func, (asDWORD)obj); - break; - case ICC_THISCALL_RETURNINMEM: - case ICC_THISCALL_OBJFIRST_RETURNINMEM: - case ICC_THISCALL_OBJLAST_RETURNINMEM: -#ifdef __GNUC__ - // On GNUC the address where the return value will be placed should be put in R0 - retQW = armFuncR0R1(args, paramSize<<2, func, (asDWORD)retPointer, (asDWORD)obj); -#else - // On Windows the R0 should always hold the object pointer, and the address for the return value comes after - retQW = armFuncR0R1(args, paramSize<<2, func, (asDWORD)obj, (asDWORD)retPointer); -#endif - break; - case ICC_CDECL_OBJFIRST_RETURNINMEM: - retQW = armFuncR0R1(args, paramSize<<2, func, (asDWORD)retPointer, (asDWORD)obj); - break; - case ICC_VIRTUAL_THISCALL: - case ICC_VIRTUAL_THISCALL_OBJFIRST: - case ICC_VIRTUAL_THISCALL_OBJLAST: - // Get virtual function table from the object pointer - vftable = *(asFUNCTION_t**)obj; - retQW = armFuncR0(args, paramSize<<2, vftable[FuncPtrToUInt(func)>>2], (asDWORD)obj); - break; - case ICC_VIRTUAL_THISCALL_RETURNINMEM: - case ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM: - case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM: - // Get virtual function table from the object pointer - vftable = *(asFUNCTION_t**)obj; -#ifdef __GNUC__ - // On GNUC the address where the return value will be placed should be put in R0 - retQW = armFuncR0R1(args, (paramSize+1)<<2, vftable[FuncPtrToUInt(func)>>2], (asDWORD)retPointer, (asDWORD)obj); -#else - // On Windows the R0 should always hold the object pointer, and the address for the return value comes after - retQW = armFuncR0R1(args, (paramSize+1)<<2, vftable[FuncPtrToUInt(func)>>2], (asDWORD)obj, (asDWORD)retPointer); -#endif - break; - case ICC_CDECL_OBJLAST: - retQW = armFuncObjLast(args, paramSize<<2, func, (asDWORD)obj); - break; - case ICC_CDECL_OBJLAST_RETURNINMEM: - retQW = armFuncR0ObjLast(args, paramSize<<2, func, (asDWORD)retPointer, (asDWORD)obj); - break; - default: - context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); + case ICC_CDECL_RETURNINMEM: // fall through + case ICC_STDCALL_RETURNINMEM: + retQW = armFuncR0(args, paramSize << 2, func, (asDWORD)retPointer); + break; + case ICC_CDECL: // fall through + case ICC_STDCALL: + retQW = armFunc(args, paramSize << 2, func); + break; + case ICC_THISCALL: // fall through + case ICC_CDECL_OBJFIRST: + case ICC_THISCALL_OBJFIRST: + case ICC_THISCALL_OBJLAST: + retQW = armFuncR0(args, paramSize << 2, func, (asDWORD)obj); + break; + case ICC_THISCALL_RETURNINMEM: + case ICC_THISCALL_OBJFIRST_RETURNINMEM: + case ICC_THISCALL_OBJLAST_RETURNINMEM: + #ifdef __GNUC__ + // On GNUC the address where the return value will be placed should be put in R0 + retQW = armFuncR0R1(args, paramSize << 2, func, (asDWORD)retPointer, (asDWORD)obj); + #else + // On Windows the R0 should always hold the object pointer, and the address for the return value comes after + retQW = armFuncR0R1(args, paramSize << 2, func, (asDWORD)obj, (asDWORD)retPointer); + #endif + break; + case ICC_CDECL_OBJFIRST_RETURNINMEM: + retQW = armFuncR0R1(args, paramSize << 2, func, (asDWORD)retPointer, (asDWORD)obj); + break; + case ICC_VIRTUAL_THISCALL: + case ICC_VIRTUAL_THISCALL_OBJFIRST: + case ICC_VIRTUAL_THISCALL_OBJLAST: + // Get virtual function table from the object pointer + vftable = *(asFUNCTION_t **)obj; + retQW = armFuncR0(args, paramSize << 2, vftable[FuncPtrToUInt(func) >> 2], (asDWORD)obj); + break; + case ICC_VIRTUAL_THISCALL_RETURNINMEM: + case ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM: + case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM: + // Get virtual function table from the object pointer + vftable = *(asFUNCTION_t **)obj; + #ifdef __GNUC__ + // On GNUC the address where the return value will be placed should be put in R0 + retQW = armFuncR0R1(args, (paramSize + 1) << 2, vftable[FuncPtrToUInt(func) >> 2], (asDWORD)retPointer, (asDWORD)obj); + #else + // On Windows the R0 should always hold the object pointer, and the address for the return value comes after + retQW = armFuncR0R1(args, (paramSize + 1) << 2, vftable[FuncPtrToUInt(func) >> 2], (asDWORD)obj, (asDWORD)retPointer); + #endif + break; + case ICC_CDECL_OBJLAST: + retQW = armFuncObjLast(args, paramSize << 2, func, (asDWORD)obj); + break; + case ICC_CDECL_OBJLAST_RETURNINMEM: + retQW = armFuncR0ObjLast(args, paramSize << 2, func, (asDWORD)retPointer, (asDWORD)obj); + break; + default: + context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); } return retQW; @@ -277,28 +277,28 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, END_AS_NAMESPACE -#elif !defined(AS_SOFTFP) + #elif !defined(AS_SOFTFP) -// This code supports the hard-float ABI, i.e. g++ -mfloat-abi=hard -// The main difference is that the floating point values are passed in the fpu registers + // This code supports the hard-float ABI, i.e. g++ -mfloat-abi=hard + // The main difference is that the floating point values are passed in the fpu registers -#define VFP_OFFSET 70 -#define STACK_OFFSET 6 -#define PARAM_BUFFER_SIZE 104 + #define VFP_OFFSET 70 + #define STACK_OFFSET 6 + #define PARAM_BUFFER_SIZE 104 BEGIN_AS_NAMESPACE -extern "C" asQWORD armFunc (const asDWORD *, int, asFUNCTION_t); -extern "C" asQWORD armFuncR0 (const asDWORD *, int, asFUNCTION_t, asDWORD r0); -extern "C" asQWORD armFuncR0R1 (const asDWORD *, int, asFUNCTION_t, asDWORD r0, asDWORD r1); -extern "C" asQWORD armFuncObjLast (const asDWORD *, int, asFUNCTION_t, asDWORD obj); -extern "C" asQWORD armFuncR0ObjLast (const asDWORD *, int, asFUNCTION_t, asDWORD r0, asDWORD obj); +extern "C" asQWORD armFunc(const asDWORD *, int, asFUNCTION_t); +extern "C" asQWORD armFuncR0(const asDWORD *, int, asFUNCTION_t, asDWORD r0); +extern "C" asQWORD armFuncR0R1(const asDWORD *, int, asFUNCTION_t, asDWORD r0, asDWORD r1); +extern "C" asQWORD armFuncObjLast(const asDWORD *, int, asFUNCTION_t, asDWORD obj); +extern "C" asQWORD armFuncR0ObjLast(const asDWORD *, int, asFUNCTION_t, asDWORD r0, asDWORD obj); asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &retQW2, void *secondObject) { - asCScriptEngine *engine = context->m_engine; - asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; - int callConv = sysFunc->callConv; + asCScriptEngine *engine = context->m_engine; + asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; + int callConv = sysFunc->callConv; asQWORD retQW = 0; asFUNCTION_t func = sysFunc->func; @@ -306,10 +306,10 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, asFUNCTION_t *vftable; //---------------------------------------------------------------------------- RPi - int freeFloatSlot = VFP_OFFSET; - int freeDoubleSlot = VFP_OFFSET; - int stackPos = STACK_OFFSET; - int stackSize = 0; + int freeFloatSlot = VFP_OFFSET; + int freeDoubleSlot = VFP_OFFSET; + int stackPos = STACK_OFFSET; + int stackSize = 0; //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- RPi @@ -337,11 +337,11 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, if( sysFunc->hostReturnInMemory ) { // TODO: runtime optimize: This check should be done in PrepareSystemFunction - if ( !( descr->returnType.GetTypeInfo()->flags & COMPLEX_RETURN_MASK ) && - ( descr->returnType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALLFLOATS ) && - descr->returnType.GetSizeInMemoryBytes() <= 16 ) + if( !(descr->returnType.GetTypeInfo()->flags & COMPLEX_RETURN_MASK) && + (descr->returnType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALLFLOATS) && + descr->returnType.GetSizeInMemoryBytes() <= 16 ) callConv--; - + // The return is made in memory callConv++; } @@ -349,7 +349,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, bool isThisCallMethod = callConv >= ICC_THISCALL_OBJLAST; // Linux needs to align 64bit types on even registers, but this isn't done on iOS or Windows Phone - // TODO: optimize runtime: There should be a check for this in PrepareSystemFunction() so this + // TODO: optimize runtime: There should be a check for this in PrepareSystemFunction() so this // doesn't have to be done for functions that don't have any 64bit types { // mask is used as a toggler to skip uneven registers. @@ -381,11 +381,11 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, mask = !mask; paramSize = 0; - int spos = 0; - int dpos = 2; + int spos = 0; + int dpos = 2; if( isThisCallMethod && (callConv >= ICC_THISCALL_OBJFIRST && - callConv <= ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM) ) + callConv <= ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM) ) { // Add the object pointer as the first parameter paramBuffer[dpos++] = (asDWORD)secondObject; @@ -396,27 +396,27 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, { // TODO: runtime optimize: Declare a reference to descr->parameterTypes[n] so the array doesn't have to be access all the time if( descr->parameterTypes[n].IsObject() && !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() && - !(descr->parameterTypes[n].GetTypeInfo()->flags & asOBJ_APP_ARRAY) ) + !(descr->parameterTypes[n].GetTypeInfo()->flags & asOBJ_APP_ARRAY) ) { -#ifdef COMPLEX_OBJS_PASSED_BY_REF + #ifdef COMPLEX_OBJS_PASSED_BY_REF if( descr->parameterTypes[n].GetTypeInfo()->flags & COMPLEX_MASK ) { paramBuffer[dpos++] = args[spos++]; paramSize++; } else -#endif + #endif { if( (descr->parameterTypes[n].GetTypeInfo()->flags & asOBJ_APP_CLASS_ALIGN8) ) { - if ( (dpos & 1) == mask ) + if( (dpos & 1) == mask ) { // 64 bit value align dpos++; paramSize++; } - if ( (stackPos & 1) == mask ) + if( (stackPos & 1) == mask ) { // 64 bit value align stackPos++; @@ -425,34 +425,34 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, } // Copy the object's memory to the buffer - if (descr->parameterTypes[n].GetTypeInfo()->flags & asOBJ_APP_CLASS_ALLFLOATS) + if( descr->parameterTypes[n].GetTypeInfo()->flags & asOBJ_APP_CLASS_ALLFLOATS ) { int target = (freeFloatSlot > freeDoubleSlot) ? freeFloatSlot : freeDoubleSlot; - if ( descr->parameterTypes[n].GetSizeInMemoryDWords() <= ( (VFP_OFFSET + 16) - target) ) + if( descr->parameterTypes[n].GetSizeInMemoryDWords() <= ((VFP_OFFSET + 16) - target) ) { - memcpy(¶mBuffer[target], *(void**)(args+spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); + memcpy(¶mBuffer[target], *(void **)(args + spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); memset(¶mBuffer[target + 18], (asDWORD)1, descr->parameterTypes[n].GetSizeInMemoryDWords()); - target += descr->parameterTypes[n].GetSizeInMemoryDWords(); + target += descr->parameterTypes[n].GetSizeInMemoryDWords(); freeFloatSlot = freeDoubleSlot = target; } else { - memcpy(¶mBuffer[stackPos], *(void**)(args+spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); - stackPos += descr->parameterTypes[n].GetSizeInMemoryDWords(); + memcpy(¶mBuffer[stackPos], *(void **)(args + spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); + stackPos += descr->parameterTypes[n].GetSizeInMemoryDWords(); stackSize += descr->parameterTypes[n].GetSizeOnStackDWords(); } } else { - memcpy(¶mBuffer[dpos], *(void**)(args+spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); - dpos += descr->parameterTypes[n].GetSizeInMemoryDWords(); + memcpy(¶mBuffer[dpos], *(void **)(args + spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); + dpos += descr->parameterTypes[n].GetSizeInMemoryDWords(); paramSize += descr->parameterTypes[n].GetSizeInMemoryDWords(); } // Delete the original memory - engine->CallFree(*(char**)(args+spos)); - spos++; + engine->CallFree(*(char **)(args + spos)); + spos++; } continue; @@ -460,15 +460,15 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, else if( descr->parameterTypes[n].IsFloatType() && !descr->parameterTypes[n].IsReference() ) { // Are there any "s" registers available? - if ( freeFloatSlot < (VFP_OFFSET + 16) ) + if( freeFloatSlot < (VFP_OFFSET + 16) ) { - if (freeFloatSlot == freeDoubleSlot) + if( freeFloatSlot == freeDoubleSlot ) freeDoubleSlot += 2; paramBuffer[freeFloatSlot + 18] = (asDWORD)1; - paramBuffer[freeFloatSlot++] = args[spos++]; + paramBuffer[freeFloatSlot++] = args[spos++]; - while(freeFloatSlot < (VFP_OFFSET + 16) && paramBuffer[freeFloatSlot + 18] != 0) + while( freeFloatSlot < (VFP_OFFSET + 16) && paramBuffer[freeFloatSlot + 18] != 0 ) freeFloatSlot++; } // If not, then store the float arg in the stack area @@ -483,114 +483,114 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, else if( descr->parameterTypes[n].IsDoubleType() && !descr->parameterTypes[n].IsReference() ) { // Are there any "d" registers available? - if ( freeDoubleSlot < (VFP_OFFSET + 15) ) + if( freeDoubleSlot < (VFP_OFFSET + 15) ) { - if (freeFloatSlot == freeDoubleSlot) + if( freeFloatSlot == freeDoubleSlot ) freeFloatSlot += 2; // Copy two dwords for the double paramBuffer[freeDoubleSlot + 18] = (asDWORD)1; paramBuffer[freeDoubleSlot + 19] = (asDWORD)1; - paramBuffer[freeDoubleSlot++] = args[spos++]; - paramBuffer[freeDoubleSlot++] = args[spos++]; + paramBuffer[freeDoubleSlot++] = args[spos++]; + paramBuffer[freeDoubleSlot++] = args[spos++]; - while(freeDoubleSlot < (VFP_OFFSET + 15) && paramBuffer[freeDoubleSlot + 18] != 0) + while( freeDoubleSlot < (VFP_OFFSET + 15) && paramBuffer[freeDoubleSlot + 18] != 0 ) freeDoubleSlot += 2; } // If not, then store the double arg in the stack area else { - if ( (stackPos & 1) == mask ) + if( (stackPos & 1) == mask ) { // 64 bit value align stackPos++; stackSize++; } - paramBuffer[stackPos++] = args[spos++]; - paramBuffer[stackPos++] = args[spos++]; - stackSize += 2; + paramBuffer[stackPos++] = args[spos++]; + paramBuffer[stackPos++] = args[spos++]; + stackSize += 2; } - + continue; } - else if (descr->parameterTypes[n].GetTokenType() == ttQuestion) + else if( descr->parameterTypes[n].GetTokenType() == ttQuestion ) { // Copy the reference and the type id as two separate arguments // Copy the value directly to "r" registers or the stack, checking for alignment - + // First the reference... - if (paramSize < 4) + if( paramSize < 4 ) { - paramBuffer[dpos++] = args[spos++]; - paramSize += 1; + paramBuffer[dpos++] = args[spos++]; + paramSize += 1; } else { - paramBuffer[stackPos++] = args[spos++]; - stackSize += 1; + paramBuffer[stackPos++] = args[spos++]; + stackSize += 1; } // ...then the type id - if (paramSize < 4) + if( paramSize < 4 ) { - paramBuffer[dpos++] = args[spos++]; - paramSize += 1; + paramBuffer[dpos++] = args[spos++]; + paramSize += 1; } else { - paramBuffer[stackPos++] = args[spos++]; - stackSize += 1; + paramBuffer[stackPos++] = args[spos++]; + stackSize += 1; } } else { // Copy the value directly to "r" registers or the stack, checking for alignment - if (paramSize < 4) + if( paramSize < 4 ) { // Should an alignment be performed? - if( (dpos & 1) == mask && descr->parameterTypes[n].GetSizeOnStackDWords() == 2 && - !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() && - !descr->parameterTypes[n].IsAnyType() ) + if( (dpos & 1) == mask && descr->parameterTypes[n].GetSizeOnStackDWords() == 2 && + !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() && + !descr->parameterTypes[n].IsAnyType() ) { // 64 bit value align dpos++; paramSize++; } - paramBuffer[dpos++] = args[spos++]; - paramSize += descr->parameterTypes[n].GetSizeOnStackDWords(); + paramBuffer[dpos++] = args[spos++]; + paramSize += descr->parameterTypes[n].GetSizeOnStackDWords(); } else { // Should an alignment be performed? if( (stackPos & 1) == mask && descr->parameterTypes[n].GetSizeOnStackDWords() == 2 && - !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() && - !descr->parameterTypes[n].IsAnyType() ) + !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() && + !descr->parameterTypes[n].IsAnyType() ) { // 64 bit value align stackPos++; stackSize++; } - paramBuffer[stackPos++] = args[spos++]; - stackSize += descr->parameterTypes[n].GetSizeOnStackDWords(); + paramBuffer[stackPos++] = args[spos++]; + stackSize += descr->parameterTypes[n].GetSizeOnStackDWords(); } if( descr->parameterTypes[n].GetSizeOnStackDWords() > 1 ) { - if (paramSize < 5) + if( paramSize < 5 ) paramBuffer[dpos++] = args[spos++]; else paramBuffer[stackPos++] = args[spos++]; } - }// else... - }// Loop + } // else... + } // Loop if( isThisCallMethod && (callConv >= ICC_THISCALL_OBJLAST && - callConv <= ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM) ) + callConv <= ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM) ) { - if (paramSize < 4) + if( paramSize < 4 ) { paramBuffer[dpos++] = (asDWORD)secondObject; paramSize++; @@ -606,79 +606,79 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, args = ¶mBuffer[2]; } - paramBuffer[69] = static_cast(stackSize<<2); + paramBuffer[69] = static_cast(stackSize << 2); switch( callConv ) { - case ICC_CDECL_RETURNINMEM: // fall through - case ICC_STDCALL_RETURNINMEM: - retQW = armFuncR0(args, paramSize<<2, func, (asDWORD)retPointer); - break; - case ICC_CDECL: // fall through - case ICC_STDCALL: - retQW = armFunc(args, paramSize<<2, func); - break; - case ICC_THISCALL: // fall through - case ICC_CDECL_OBJFIRST: - case ICC_THISCALL_OBJFIRST: - case ICC_THISCALL_OBJLAST: - retQW = armFuncR0(args, paramSize<<2, func, (asDWORD)obj); - break; - case ICC_THISCALL_RETURNINMEM: - case ICC_THISCALL_OBJFIRST_RETURNINMEM: - case ICC_THISCALL_OBJLAST_RETURNINMEM: - // On GNUC the address where the return value will be placed should be put in R0 - retQW = armFuncR0R1(args, paramSize<<2, func, (asDWORD)retPointer, (asDWORD)obj); - break; - case ICC_CDECL_OBJFIRST_RETURNINMEM: - retQW = armFuncR0R1(args, paramSize<<2, func, (asDWORD)retPointer, (asDWORD)obj); - break; - case ICC_VIRTUAL_THISCALL: - case ICC_VIRTUAL_THISCALL_OBJFIRST: - case ICC_VIRTUAL_THISCALL_OBJLAST: - // Get virtual function table from the object pointer - vftable = *(asFUNCTION_t**)obj; - retQW = armFuncR0(args, paramSize<<2, vftable[FuncPtrToUInt(func)>>2], (asDWORD)obj); - break; - case ICC_VIRTUAL_THISCALL_RETURNINMEM: - case ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM: - case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM: - // Get virtual function table from the object pointer - vftable = *(asFUNCTION_t**)obj; - // On GNUC the address where the return value will be placed should be put in R0 - retQW = armFuncR0R1(args, (paramSize+1)<<2, vftable[FuncPtrToUInt(func)>>2], (asDWORD)retPointer, (asDWORD)obj); - break; - case ICC_CDECL_OBJLAST: - retQW = armFuncObjLast(args, paramSize<<2, func, (asDWORD)obj); - break; - case ICC_CDECL_OBJLAST_RETURNINMEM: - retQW = armFuncR0ObjLast(args, paramSize<<2, func, (asDWORD)retPointer, (asDWORD)obj); - break; - default: - context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); + case ICC_CDECL_RETURNINMEM: // fall through + case ICC_STDCALL_RETURNINMEM: + retQW = armFuncR0(args, paramSize << 2, func, (asDWORD)retPointer); + break; + case ICC_CDECL: // fall through + case ICC_STDCALL: + retQW = armFunc(args, paramSize << 2, func); + break; + case ICC_THISCALL: // fall through + case ICC_CDECL_OBJFIRST: + case ICC_THISCALL_OBJFIRST: + case ICC_THISCALL_OBJLAST: + retQW = armFuncR0(args, paramSize << 2, func, (asDWORD)obj); + break; + case ICC_THISCALL_RETURNINMEM: + case ICC_THISCALL_OBJFIRST_RETURNINMEM: + case ICC_THISCALL_OBJLAST_RETURNINMEM: + // On GNUC the address where the return value will be placed should be put in R0 + retQW = armFuncR0R1(args, paramSize << 2, func, (asDWORD)retPointer, (asDWORD)obj); + break; + case ICC_CDECL_OBJFIRST_RETURNINMEM: + retQW = armFuncR0R1(args, paramSize << 2, func, (asDWORD)retPointer, (asDWORD)obj); + break; + case ICC_VIRTUAL_THISCALL: + case ICC_VIRTUAL_THISCALL_OBJFIRST: + case ICC_VIRTUAL_THISCALL_OBJLAST: + // Get virtual function table from the object pointer + vftable = *(asFUNCTION_t **)obj; + retQW = armFuncR0(args, paramSize << 2, vftable[FuncPtrToUInt(func) >> 2], (asDWORD)obj); + break; + case ICC_VIRTUAL_THISCALL_RETURNINMEM: + case ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM: + case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM: + // Get virtual function table from the object pointer + vftable = *(asFUNCTION_t **)obj; + // On GNUC the address where the return value will be placed should be put in R0 + retQW = armFuncR0R1(args, (paramSize + 1) << 2, vftable[FuncPtrToUInt(func) >> 2], (asDWORD)retPointer, (asDWORD)obj); + break; + case ICC_CDECL_OBJLAST: + retQW = armFuncObjLast(args, paramSize << 2, func, (asDWORD)obj); + break; + case ICC_CDECL_OBJLAST_RETURNINMEM: + retQW = armFuncR0ObjLast(args, paramSize << 2, func, (asDWORD)retPointer, (asDWORD)obj); + break; + default: + context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); } - // On Linux with arm the float and double values are returns in the - // floating point registers, s0 and s1. Objects that contain only + // On Linux with arm the float and double values are returns in the + // floating point registers, s0 and s1. Objects that contain only // float types and are not considered complex are also returned in the // floating point registers. if( sysFunc->hostReturnFloat ) { retQW = paramBuffer[VFP_OFFSET]; - if ( sysFunc->hostReturnSize > 1 ) - retQW = *( (asQWORD*)¶mBuffer[VFP_OFFSET] ); - if (sysFunc->hostReturnSize > 2) - retQW2 = *((asQWORD*)¶mBuffer[VFP_OFFSET + 2]); + if( sysFunc->hostReturnSize > 1 ) + retQW = *((asQWORD *)¶mBuffer[VFP_OFFSET]); + if( sysFunc->hostReturnSize > 2 ) + retQW2 = *((asQWORD *)¶mBuffer[VFP_OFFSET + 2]); } - else if ( descr->returnType.IsObject() ) + else if( descr->returnType.IsObject() ) { // TODO: runtime optimize: This should be identified with a flag determined in PrepareSystemFunction - if ( !descr->returnType.IsObjectHandle() && - !descr->returnType.IsReference() && - !(descr->returnType.GetTypeInfo()->flags & COMPLEX_RETURN_MASK) && - (descr->returnType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALLFLOATS) ) - memcpy( retPointer, ¶mBuffer[VFP_OFFSET], descr->returnType.GetSizeInMemoryBytes() ); + if( !descr->returnType.IsObjectHandle() && + !descr->returnType.IsReference() && + !(descr->returnType.GetTypeInfo()->flags & COMPLEX_RETURN_MASK) && + (descr->returnType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALLFLOATS) ) + memcpy(retPointer, ¶mBuffer[VFP_OFFSET], descr->returnType.GetSizeInMemoryBytes()); } return retQW; @@ -686,11 +686,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, END_AS_NAMESPACE -#endif // AS_LINUX - -#endif // AS_ARM -#endif // AS_MAX_PORTABILITY - - - + #endif // AS_LINUX + #endif // AS_ARM +#endif // AS_MAX_PORTABILITY diff --git a/sdk/angelscript/source/as_callfunc_arm64.cpp b/sdk/angelscript/source/as_callfunc_arm64.cpp index ccb054ab..33800e53 100644 --- a/sdk/angelscript/source/as_callfunc_arm64.cpp +++ b/sdk/angelscript/source/as_callfunc_arm64.cpp @@ -38,7 +38,7 @@ // // Adapted for Apple M1/M2 by Sam Tupy in Jan 2024 // -// ref for Apple ABI: https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms +// ref for Apple ABI: https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms // @@ -55,8 +55,8 @@ // ARM64 targets use has no software floating-point ABI, it's all hardware (or totally disabled) -#define HFA_RET_REGISTERS 4 // s0-s3/d0-d3 -#define GP_ARG_REGISTERS 8 // x0-x7 +#define HFA_RET_REGISTERS 4 // s0-s3/d0-d3 +#define GP_ARG_REGISTERS 8 // x0-x7 #define FLOAT_ARG_REGISTERS 8 // v0-v7 BEGIN_AS_NAMESPACE @@ -74,35 +74,30 @@ extern "C" void GetHFAReturnDouble(asQWORD *out1, asQWORD *out2, asQWORD returnS extern "C" void GetHFAReturnFloat(asQWORD *out1, asQWORD *out2, asQWORD returnSize); extern "C" asQWORD CallARM64RetInMemory( - const asQWORD *gpRegArgs, asQWORD numGPRegArgs, - const asQWORD *floatRegArgs, asQWORD numFloatRegArgs, - const asQWORD *stackArgs, asQWORD numStackArgs, - void *retPointer, asFUNCTION_t func -); + const asQWORD *gpRegArgs, asQWORD numGPRegArgs, + const asQWORD *floatRegArgs, asQWORD numFloatRegArgs, + const asQWORD *stackArgs, asQWORD numStackArgs, + void *retPointer, asFUNCTION_t func); extern "C" double CallARM64Double( - const asQWORD *gpRegArgs, asQWORD numGPRegArgs, - const asQWORD *floatRegArgs, asQWORD numFloatRegArgs, - const asQWORD *stackArgs, asQWORD numStackArgs, - asFUNCTION_t func -); + const asQWORD *gpRegArgs, asQWORD numGPRegArgs, + const asQWORD *floatRegArgs, asQWORD numFloatRegArgs, + const asQWORD *stackArgs, asQWORD numStackArgs, + asFUNCTION_t func); extern "C" float CallARM64Float( - const asQWORD *gpRegArgs, asQWORD numGPRegArgs, - const asQWORD *floatRegArgs, asQWORD numFloatRegArgs, - const asQWORD *stackArgs, asQWORD numStackArgs, - asFUNCTION_t func -); + const asQWORD *gpRegArgs, asQWORD numGPRegArgs, + const asQWORD *floatRegArgs, asQWORD numFloatRegArgs, + const asQWORD *stackArgs, asQWORD numStackArgs, + asFUNCTION_t func); extern "C" asQWORD CallARM64( - const asQWORD *gpRegArgs, asQWORD numGPRegArgs, - const asQWORD *floatRegArgs, asQWORD numFloatRegArgs, - const asQWORD *stackArgs, asQWORD numStackArgs, - asFUNCTION_t func -); + const asQWORD *gpRegArgs, asQWORD numGPRegArgs, + const asQWORD *floatRegArgs, asQWORD numFloatRegArgs, + const asQWORD *stackArgs, asQWORD numStackArgs, + asFUNCTION_t func); extern "C" asQWORD CallARM64Ret128( - const asQWORD *gpRegArgs, asQWORD numGPRegArgs, - const asQWORD *floatRegArgs, asQWORD numFloatRegArgs, - const asQWORD *stackArgs, asQWORD numStackArgs, - asQWORD *higherQWORD, asFUNCTION_t func -); + const asQWORD *gpRegArgs, asQWORD numGPRegArgs, + const asQWORD *floatRegArgs, asQWORD numFloatRegArgs, + const asQWORD *stackArgs, asQWORD numStackArgs, + asQWORD *higherQWORD, asFUNCTION_t func); // // If it's possible to fit in registers, @@ -110,15 +105,15 @@ extern "C" asQWORD CallARM64Ret128( // static inline bool IsRegisterHFA(const asCDataType &type) { - const asCTypeInfo *const typeInfo = type.GetTypeInfo(); + const asCTypeInfo * const typeInfo = type.GetTypeInfo(); if( typeInfo == 0 || - (typeInfo->flags & asOBJ_APP_CLASS_ALLFLOATS) == 0 || - type.IsObjectHandle() || type.IsReference() ) + (typeInfo->flags & asOBJ_APP_CLASS_ALLFLOATS) == 0 || + type.IsObjectHandle() || type.IsReference() ) return false; - const bool doubles = (typeInfo->flags & asOBJ_APP_CLASS_ALIGN8) != 0; - const int maxAllowedSize = doubles ? sizeof(double) * HFA_RET_REGISTERS : sizeof(float) * HFA_RET_REGISTERS; + const bool doubles = (typeInfo->flags & asOBJ_APP_CLASS_ALIGN8) != 0; + const int maxAllowedSize = doubles ? sizeof(double) * HFA_RET_REGISTERS : sizeof(float) * HFA_RET_REGISTERS; return type.GetSizeInMemoryBytes() <= maxAllowedSize; } @@ -132,44 +127,44 @@ static inline bool IsRegisterHFAParameter(const asCDataType &type, const asQWORD if( !IsRegisterHFA(type) ) return false; - const bool doubles = (type.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALIGN8) != 0; - const int registersUsed = type.GetSizeInMemoryDWords() / (doubles ? sizeof(double) : sizeof(float)); + const bool doubles = (type.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALIGN8) != 0; + const int registersUsed = type.GetSizeInMemoryDWords() / (doubles ? sizeof(double) : sizeof(float)); return numFloatRegArgs + registersUsed <= FLOAT_ARG_REGISTERS; } #if defined(AS_IPHONE) || defined(AS_MAC) -static inline void PadAppleStack(asQWORD* const argsArray, asQWORD& numArgs, asQWORD& stackDispositionBytes, asUINT argSize) +static inline void PadAppleStack(asQWORD * const argsArray, asQWORD &numArgs, asQWORD &stackDispositionBytes, asUINT argSize) { - if(stackDispositionBytes == 0) return; + if( stackDispositionBytes == 0 ) return; asUINT padBytes = argSize - (stackDispositionBytes % argSize); - if(padBytes > 0 && padBytes != argSize) + if( padBytes > 0 && padBytes != argSize ) { - memset( ((asBYTE*)&argsArray[numArgs]) + stackDispositionBytes, 0, padBytes); + memset(((asBYTE *)&argsArray[numArgs]) + stackDispositionBytes, 0, padBytes); stackDispositionBytes += padBytes; } numArgs += stackDispositionBytes / sizeof(asQWORD); - if(stackDispositionBytes >= sizeof(asQWORD)) - stackDispositionBytes -= sizeof(asQWORD) * (stackDispositionBytes / sizeof(asQWORD) ); + if( stackDispositionBytes >= sizeof(asQWORD) ) + stackDispositionBytes -= sizeof(asQWORD) * (stackDispositionBytes / sizeof(asQWORD)); } #endif asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &retQW2, void *secondObject) { - asCScriptEngine *engine = context->m_engine; - const asSSystemFunctionInterface *const sysFunc = descr->sysFuncIntf; - const asCDataType &retType = descr->returnType; - const asCTypeInfo *const retTypeInfo = retType.GetTypeInfo(); - asFUNCTION_t func = sysFunc->func; - int callConv = sysFunc->callConv; - asQWORD retQW = 0; - - asQWORD gpRegArgs[GP_ARG_REGISTERS]; - asQWORD floatRegArgs[FLOAT_ARG_REGISTERS]; - asQWORD stackArgs[64]; // It's how many x64 users can have - asQWORD numGPRegArgs = 0; - asQWORD numFloatRegArgs = 0; - asQWORD numStackArgs = 0; + asCScriptEngine *engine = context->m_engine; + const asSSystemFunctionInterface * const sysFunc = descr->sysFuncIntf; + const asCDataType &retType = descr->returnType; + const asCTypeInfo * const retTypeInfo = retType.GetTypeInfo(); + asFUNCTION_t func = sysFunc->func; + int callConv = sysFunc->callConv; + asQWORD retQW = 0; + + asQWORD gpRegArgs[GP_ARG_REGISTERS]; + asQWORD floatRegArgs[FLOAT_ARG_REGISTERS]; + asQWORD stackArgs[64]; // It's how many x64 users can have + asQWORD numGPRegArgs = 0; + asQWORD numFloatRegArgs = 0; + asQWORD numStackArgs = 0; #if defined(AS_IPHONE) || defined(AS_MAC) asQWORD stackDispositionBytes = 0; // Apple silikin aligns arguments on the stack by the size of their type instead of by 8 bytes like standard arm. #endif @@ -177,7 +172,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // Optimization to avoid check 12 values (all ICC_ that contains THISCALL) if( (callConv >= ICC_THISCALL && callConv <= ICC_VIRTUAL_THISCALL_RETURNINMEM) || - (callConv >= ICC_THISCALL_OBJLAST && callConv <= ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM) ) + (callConv >= ICC_THISCALL_OBJLAST && callConv <= ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM) ) { // Add the object pointer as the first parameter gpRegArgs[numGPRegArgs++] = (asQWORD)obj; @@ -189,59 +184,59 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, gpRegArgs[numGPRegArgs++] = (asQWORD)obj; } else if( callConv == ICC_THISCALL_OBJFIRST || callConv == ICC_THISCALL_OBJFIRST_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM ) + callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM ) { // Add the object pointer as the first parameter gpRegArgs[numGPRegArgs++] = (asQWORD)secondObject; } if( callConv == ICC_VIRTUAL_THISCALL || callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM || callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || - callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM || callConv == ICC_VIRTUAL_THISCALL_OBJLAST || callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) + callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM || callConv == ICC_VIRTUAL_THISCALL_OBJLAST || callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) { // Get virtual function table from the object pointer - vftable = *(asFUNCTION_t**)obj; - func = vftable[FuncPtrToUInt(func)/sizeof(void*)]; + vftable = *(asFUNCTION_t **)obj; + func = vftable[FuncPtrToUInt(func) / sizeof(void *)]; } asUINT argsPos = 0; for( asUINT n = 0; n < descr->parameterTypes.GetLength(); n++ ) { - const asCDataType &parmType = descr->parameterTypes[n]; - const asCTypeInfo *const parmTypeInfo = parmType.GetTypeInfo(); + const asCDataType &parmType = descr->parameterTypes[n]; + const asCTypeInfo * const parmTypeInfo = parmType.GetTypeInfo(); if( parmType.IsObject() && !parmType.IsObjectHandle() && !parmType.IsReference() ) { const asUINT parmDWords = parmType.GetSizeInMemoryDWords(); const asUINT parmQWords = (parmDWords >> 1) + (parmDWords & 1); - const bool passedAsPointer = parmQWords <= 2; - const bool fitsInRegisters = passedAsPointer ? (numGPRegArgs < GP_ARG_REGISTERS) : (numGPRegArgs + parmQWords <= GP_ARG_REGISTERS); - asQWORD *const argsArray = fitsInRegisters ? gpRegArgs : stackArgs; - asQWORD &numArgs = fitsInRegisters ? numGPRegArgs : numStackArgs; + const bool passedAsPointer = parmQWords <= 2; + const bool fitsInRegisters = passedAsPointer ? (numGPRegArgs < GP_ARG_REGISTERS) : (numGPRegArgs + parmQWords <= GP_ARG_REGISTERS); + asQWORD * const argsArray = fitsInRegisters ? gpRegArgs : stackArgs; + asQWORD &numArgs = fitsInRegisters ? numGPRegArgs : numStackArgs; if( (parmTypeInfo->flags & COMPLEX_MASK) ) { #if defined(AS_IPHONE) || defined(AS_MAC) - if(!fitsInRegisters) PadAppleStack(argsArray, numArgs, stackDispositionBytes, sizeof(asQWORD)); + if( !fitsInRegisters ) PadAppleStack(argsArray, numArgs, stackDispositionBytes, sizeof(asQWORD)); #endif - argsArray[numArgs++] = *(asQWORD*)&args[argsPos]; - argsPos += AS_PTR_SIZE; + argsArray[numArgs++] = *(asQWORD *)&args[argsPos]; + argsPos += AS_PTR_SIZE; } else if( IsRegisterHFAParameter(parmType, numFloatRegArgs) ) { if( (parmTypeInfo->flags & asOBJ_APP_CLASS_ALIGN8) != 0 ) { - const asQWORD *const contents = *(asQWORD**)&args[argsPos]; + const asQWORD * const contents = *(asQWORD **)&args[argsPos]; for( asUINT i = 0; i < parmQWords; i++ ) - floatRegArgs[numFloatRegArgs++] = *(asQWORD*)&contents[i]; + floatRegArgs[numFloatRegArgs++] = *(asQWORD *)&contents[i]; } else { - const asDWORD *const contents = *(asDWORD**)&args[argsPos]; + const asDWORD * const contents = *(asDWORD **)&args[argsPos]; for( asUINT i = 0; i < parmDWords; i++ ) - floatRegArgs[numFloatRegArgs++] = *(asDWORD*)&contents[i]; + floatRegArgs[numFloatRegArgs++] = *(asDWORD *)&contents[i]; } - engine->CallFree(*(char**)(args+argsPos)); + engine->CallFree(*(char **)(args + argsPos)); argsPos += AS_PTR_SIZE; } else @@ -249,22 +244,22 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // Copy the object's memory to the buffer asUINT parmBytes = parmType.GetSizeInMemoryBytes(); #if defined(AS_IPHONE) || defined(AS_MAC) - if(!fitsInRegisters) + if( !fitsInRegisters ) { PadAppleStack(argsArray, numArgs, stackDispositionBytes, parmBytes); - memcpy( ((asBYTE*)&argsArray[numArgs]) + stackDispositionBytes, *(void**)(args+argsPos), parmBytes); + memcpy(((asBYTE *)&argsArray[numArgs]) + stackDispositionBytes, *(void **)(args + argsPos), parmBytes); stackDispositionBytes += parmBytes; // numArgs will be fixed on next call to PadAppleStack. } else #endif { - memcpy(&argsArray[numArgs], *(void**)(args+argsPos), parmBytes); + memcpy(&argsArray[numArgs], *(void **)(args + argsPos), parmBytes); numArgs += parmQWords; } // Delete the original memory - engine->CallFree(*(char**)(args+argsPos)); + engine->CallFree(*(char **)(args + argsPos)); argsPos += AS_PTR_SIZE; } } @@ -274,7 +269,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, #if defined(AS_IPHONE) || defined(AS_MAC) { PadAppleStack(stackArgs, numStackArgs, stackDispositionBytes, sizeof(float)); - memcpy( ((asBYTE*)&stackArgs[numStackArgs]) + stackDispositionBytes, &args[argsPos], sizeof(float)); + memcpy(((asBYTE *)&stackArgs[numStackArgs]) + stackDispositionBytes, &args[argsPos], sizeof(float)); stackDispositionBytes += sizeof(float); } #else @@ -290,56 +285,56 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, #if defined(AS_IPHONE) || defined(AS_MAC) { PadAppleStack(stackArgs, numStackArgs, stackDispositionBytes, sizeof(asQWORD)); - memcpy( ((asBYTE*)&stackArgs[numStackArgs]) + stackDispositionBytes, (asQWORD*)&args[argsPos], sizeof(asQWORD)); + memcpy(((asBYTE *)&stackArgs[numStackArgs]) + stackDispositionBytes, (asQWORD *)&args[argsPos], sizeof(asQWORD)); stackDispositionBytes += sizeof(asQWORD); } #else - stackArgs[numStackArgs++] = *(asQWORD*)&args[argsPos]; + stackArgs[numStackArgs++] = *(asQWORD *)&args[argsPos]; #endif else - floatRegArgs[numFloatRegArgs++] = *(asQWORD*)&args[argsPos]; + floatRegArgs[numFloatRegArgs++] = *(asQWORD *)&args[argsPos]; argsPos += 2; } - else if (parmType.GetTokenType() == ttQuestion) + else if( parmType.GetTokenType() == ttQuestion ) { // Copy the reference and the type id as separate arguments - // + // // First the reference - bool fitsInRegisters = numGPRegArgs + 1 <= GP_ARG_REGISTERS; - asQWORD* argsArray = fitsInRegisters ? gpRegArgs : stackArgs; - asQWORD* numArgs = fitsInRegisters ? &numGPRegArgs : &numStackArgs; + bool fitsInRegisters = numGPRegArgs + 1 <= GP_ARG_REGISTERS; + asQWORD *argsArray = fitsInRegisters ? gpRegArgs : stackArgs; + asQWORD *numArgs = fitsInRegisters ? &numGPRegArgs : &numStackArgs; #if defined(AS_IPHONE) || defined(AS_MAC) - if (!fitsInRegisters) + if( !fitsInRegisters ) { asUINT parmBytes = AS_PTR_SIZE * 4; PadAppleStack(argsArray, *numArgs, stackDispositionBytes, parmBytes); - memcpy(((asBYTE*)&argsArray[*numArgs]) + stackDispositionBytes, (void*)(args + argsPos), parmBytes); + memcpy(((asBYTE *)&argsArray[*numArgs]) + stackDispositionBytes, (void *)(args + argsPos), parmBytes); stackDispositionBytes += parmBytes; } else #endif { - memcpy(&argsArray[*numArgs], (void*)(args + argsPos), AS_PTR_SIZE * 4); + memcpy(&argsArray[*numArgs], (void *)(args + argsPos), AS_PTR_SIZE * 4); (*numArgs) += 1; } argsPos += AS_PTR_SIZE; // Then the type id fitsInRegisters = numGPRegArgs + 1 <= GP_ARG_REGISTERS; - argsArray = fitsInRegisters ? gpRegArgs : stackArgs; - numArgs = fitsInRegisters ? &numGPRegArgs : &numStackArgs; + argsArray = fitsInRegisters ? gpRegArgs : stackArgs; + numArgs = fitsInRegisters ? &numGPRegArgs : &numStackArgs; #if defined(AS_IPHONE) || defined(AS_MAC) - if (!fitsInRegisters) + if( !fitsInRegisters ) { asUINT parmBytes = 4; PadAppleStack(argsArray, *numArgs, stackDispositionBytes, parmBytes); - memcpy(((asBYTE*)&argsArray[*numArgs]) + stackDispositionBytes, (void*)(args + argsPos), parmBytes); + memcpy(((asBYTE *)&argsArray[*numArgs]) + stackDispositionBytes, (void *)(args + argsPos), parmBytes); stackDispositionBytes += parmBytes; } else #endif { - memcpy(&argsArray[*numArgs], (void*)(args + argsPos), 4); + memcpy(&argsArray[*numArgs], (void *)(args + argsPos), 4); (*numArgs) += 1; } argsPos += 1; @@ -350,21 +345,21 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, const asUINT parmDWords = parmType.GetSizeOnStackDWords(); const asUINT parmQWords = (parmDWords >> 1) + (parmDWords & 1); - const bool fitsInRegisters = numGPRegArgs + parmQWords <= GP_ARG_REGISTERS; - asQWORD *const argsArray = fitsInRegisters ? gpRegArgs : stackArgs; - asQWORD &numArgs = fitsInRegisters ? numGPRegArgs : numStackArgs; + const bool fitsInRegisters = numGPRegArgs + parmQWords <= GP_ARG_REGISTERS; + asQWORD * const argsArray = fitsInRegisters ? gpRegArgs : stackArgs; + asQWORD &numArgs = fitsInRegisters ? numGPRegArgs : numStackArgs; #if defined(AS_IPHONE) || defined(AS_MAC) - if(!fitsInRegisters) + if( !fitsInRegisters ) { asUINT parmBytes = parmType.GetSizeInMemoryBytes(); PadAppleStack(argsArray, numArgs, stackDispositionBytes, parmBytes); - memcpy( ((asBYTE*)&argsArray[numArgs]) + stackDispositionBytes, (void*)(args+argsPos), parmBytes); + memcpy(((asBYTE *)&argsArray[numArgs]) + stackDispositionBytes, (void *)(args + argsPos), parmBytes); stackDispositionBytes += parmBytes; } else #endif { - memcpy(&argsArray[numArgs], (void*)(args+argsPos), parmDWords * 4); + memcpy(&argsArray[numArgs], (void *)(args + argsPos), parmDWords * 4); numArgs += parmQWords; } @@ -383,7 +378,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, stackArgs[numStackArgs++] = (asQWORD)obj; } else if( callConv == ICC_THISCALL_OBJLAST || callConv == ICC_THISCALL_OBJLAST_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJLAST || callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) + callConv == ICC_VIRTUAL_THISCALL_OBJLAST || callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) { // Add the object pointer as the last parameter if( numGPRegArgs < GP_ARG_REGISTERS ) @@ -406,7 +401,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, if( structSize <= sizeof(double) * 2 ) GetHFAReturnDouble(&retQW, &retQW2, structSize); else - GetHFAReturnDouble((asQWORD*)retPointer, ((asQWORD*)retPointer) + 1, structSize); + GetHFAReturnDouble((asQWORD *)retPointer, ((asQWORD *)retPointer) + 1, structSize); } else GetHFAReturnFloat(&retQW, &retQW2, structSize); @@ -414,9 +409,9 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, else if( sysFunc->hostReturnFloat ) { if( sysFunc->hostReturnSize == 1 ) - *(float*)&retQW = CallARM64Float(gpRegArgs, numGPRegArgs, floatRegArgs, numFloatRegArgs, stackArgs, numStackArgs, func); + *(float *)&retQW = CallARM64Float(gpRegArgs, numGPRegArgs, floatRegArgs, numFloatRegArgs, stackArgs, numStackArgs, func); else - *(double*)&retQW = CallARM64Double(gpRegArgs, numGPRegArgs, floatRegArgs, numFloatRegArgs, stackArgs, numStackArgs, func); + *(double *)&retQW = CallARM64Double(gpRegArgs, numGPRegArgs, floatRegArgs, numFloatRegArgs, stackArgs, numStackArgs, func); } else if( sysFunc->hostReturnInMemory ) retQW = CallARM64RetInMemory(gpRegArgs, numGPRegArgs, floatRegArgs, numFloatRegArgs, stackArgs, numStackArgs, retPointer, func); @@ -435,7 +430,3 @@ END_AS_NAMESPACE #endif // AS_ARM64 #endif // AS_MAX_PORTABILITY - - - - diff --git a/sdk/angelscript/source/as_callfunc_e2k.cpp b/sdk/angelscript/source/as_callfunc_e2k.cpp index 794a4006..4906355e 100644 --- a/sdk/angelscript/source/as_callfunc_e2k.cpp +++ b/sdk/angelscript/source/as_callfunc_e2k.cpp @@ -37,209 +37,246 @@ #include "as_config.h" #ifndef AS_MAX_PORTABILITY -#ifdef AS_E2K + #ifdef AS_E2K -#include "as_scriptengine.h" -#include "as_texts.h" -#include "as_context.h" + #include "as_scriptengine.h" + #include "as_texts.h" + #include "as_context.h" BEGIN_AS_NAMESPACE -#define E2K_MAX_ARGS 64 - -struct E2KArguments { - asDWORD *m_args; - int m_index = 0; - - E2KArguments(asDWORD *args): m_args(args) {} - - asDWORD *ptr() { - return &m_args[m_index]; - } - - asDWORD takeDWord() { - return m_args[m_index++]; - } - - asQWORD takeQWord() { - asQWORD lo = takeDWord(); - asQWORD hi = takeDWord(); - return (hi << 32) | lo; - } - - asQWORD take(int count) { - switch (count) { - case 1: return takeDWord(); - case 2: return takeQWord(); - default: - asASSERT(0 && "implement me"); - return 0; - } - } + #define E2K_MAX_ARGS 64 + +struct E2KArguments +{ + asDWORD *m_args; + int m_index = 0; + + E2KArguments(asDWORD *args) : m_args(args) + { + } + + asDWORD *ptr() + { + return &m_args[m_index]; + } + + asDWORD takeDWord() + { + return m_args[m_index++]; + } + + asQWORD takeQWord() + { + asQWORD lo = takeDWord(); + asQWORD hi = takeDWord(); + return (hi << 32) | lo; + } + + asQWORD take(int count) + { + switch( count ) + { + case 1: + return takeDWord(); + case 2: + return takeQWord(); + default: + asASSERT(0 && "implement me"); + return 0; + } + } }; -struct E2KBuffer { - int m_count = 0; - asQWORD m_buffer[E2K_MAX_ARGS]; - - const asQWORD *ptr() const { - return m_buffer; - } - - int count() const { - return m_count; - } - - void align() { - m_count += m_count & 1; - } - - void push(asQWORD arg) { - asASSERT(m_count < E2K_MAX_ARGS); - m_buffer[m_count++] = arg; - } - - void push_object(void *parm, int size) { - int c = (size + 7) / 8; - asASSERT(m_count + c <= E2K_MAX_ARGS); - memcpy(&m_buffer[m_count], parm, size); - m_count += c; - } +struct E2KBuffer +{ + int m_count = 0; + asQWORD m_buffer[E2K_MAX_ARGS]; + + const asQWORD *ptr() const + { + return m_buffer; + } + + int count() const + { + return m_count; + } + + void align() + { + m_count += m_count & 1; + } + + void push(asQWORD arg) + { + asASSERT(m_count < E2K_MAX_ARGS); + m_buffer[m_count++] = arg; + } + + void push_object(void *parm, int size) + { + int c = (size + 7) / 8; + asASSERT(m_count + c <= E2K_MAX_ARGS); + memcpy(&m_buffer[m_count], parm, size); + m_count += c; + } }; extern "C" void CallFunctionE2K(asFUNCTION_t func, const asQWORD *args, - int argsCount, void *retPointer, int retSize, int stackSize, bool returnInMemory); + int argsCount, void *retPointer, int retSize, int stackSize, bool returnInMemory); void CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, - void *obj, asDWORD *args, void *retPointer, asQWORD *retQW, void *secondObject) + void *obj, asDWORD *args, void *retPointer, asQWORD *retQW, void *secondObject) { - asCScriptEngine *engine = context->m_engine; - asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; - const asCDataType &retType = descr->returnType; - asFUNCTION_t func = sysFunc->func; - int callConv = sysFunc->callConv; - E2KArguments parms(args); - E2KBuffer buffer; - bool retComplex = retType.IsObject() && (retType.GetTypeInfo()->flags & COMPLEX_RETURN_MASK); - - if (sysFunc->hostReturnInMemory && retComplex) { - // The return is made in memory. - buffer.push((asPWORD) retPointer); - } - - if (obj) { - asFUNCTION_t *vftable; - switch (callConv) { - case ICC_VIRTUAL_THISCALL: - case ICC_VIRTUAL_THISCALL_RETURNINMEM: -#ifndef AS_NO_THISCALL_FUNCTOR_METHOD - case ICC_VIRTUAL_THISCALL_OBJFIRST: - case ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM: - case ICC_VIRTUAL_THISCALL_OBJLAST: - case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM: -#endif - vftable = *((asFUNCTION_t**) obj); - func = vftable[FuncPtrToUInt(asFUNCTION_t(func)) >> 3]; - break; - } - } - - switch (callConv) { - case ICC_CDECL_OBJFIRST: - case ICC_THISCALL: - case ICC_VIRTUAL_THISCALL: - case ICC_CDECL_OBJFIRST_RETURNINMEM: - case ICC_THISCALL_RETURNINMEM: - case ICC_VIRTUAL_THISCALL_RETURNINMEM: -#ifndef AS_NO_THISCALL_FUNCTOR_METHOD - case ICC_THISCALL_OBJLAST: - case ICC_VIRTUAL_THISCALL_OBJLAST: - case ICC_THISCALL_OBJLAST_RETURNINMEM: - case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM: -#endif - buffer.push((asPWORD) obj); - break; -#ifndef AS_NO_THISCALL_FUNCTOR_METHOD - case ICC_THISCALL_OBJFIRST: - case ICC_VIRTUAL_THISCALL_OBJFIRST: - case ICC_THISCALL_OBJFIRST_RETURNINMEM: - case ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM: - buffer.push((asPWORD) obj); - buffer.push((asPWORD) secondObject); - break; -#endif - } - - for (int i = 0; i < descr->parameterTypes.GetLength(); ++i) { - const asCDataType& parmType = descr->parameterTypes[i]; - - if (parmType.GetTokenType() == ttQuestion) { - // The variable args are really two, one pointer and one type id. - buffer.push(parms.takeQWord()); - buffer.push(parms.takeDWord()); - } else if (parmType.IsPrimitive() || parmType.IsReference() || parmType.IsObjectHandle()) { - // Primitive types and references are single slot values. - buffer.push(parms.take(parmType.GetSizeOnStackDWords())); - } else { - // An object is being passed by value. - if ((parmType.GetTypeInfo()->flags & COMPLEX_MASK)) { - // Copy the address of the object. - buffer.push(parms.takeQWord()); - } else { - // Copy the value of the object. - int size = parmType.GetSizeInMemoryBytes(); - void *parm = *(void **) parms.ptr(); - if (size > 8) { - buffer.align(); - buffer.push_object(parm, size); - buffer.align(); - } else { - buffer.push_object(parm, size); - } - // Skip pointer. - parms.takeQWord(); - // Delete the original memory. - engine->CallFree(parm); - } - } - } - - switch (callConv) { - case ICC_CDECL_OBJLAST: - case ICC_CDECL_OBJLAST_RETURNINMEM: - buffer.push((asPWORD) obj); - break; -#ifndef AS_NO_THISCALL_FUNCTOR_METHOD - case ICC_THISCALL_OBJLAST: - case ICC_THISCALL_OBJLAST_RETURNINMEM: - case ICC_VIRTUAL_THISCALL_OBJLAST: - case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM: - buffer.push((asPWORD) secondObject); - break; -#endif - } - - int stackSize = buffer.count() * (sizeof(asQWORD) / sizeof(asDWORD)); - int retSize = sysFunc->hostReturnSize; - bool returnInMemory = sysFunc->hostReturnInMemory && !retComplex; - - if (returnInMemory) { - // Returned on the user stack and copied to retPointer. - retSize = retType.GetSizeInMemoryDWords(); - if (retSize > stackSize) { - stackSize = retSize; - } - } else { - // Returned in registers and copied to retQW. - asASSERT(retSize <= RETURN_VALUE_MAX_SIZE); - retPointer = retQW; - } - - stackSize = (stackSize * sizeof(asDWORD) + 15) & ~15; - CallFunctionE2K(func, buffer.ptr(), buffer.count(), retPointer, retSize, -stackSize, returnInMemory); + asCScriptEngine *engine = context->m_engine; + asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; + const asCDataType &retType = descr->returnType; + asFUNCTION_t func = sysFunc->func; + int callConv = sysFunc->callConv; + E2KArguments parms(args); + E2KBuffer buffer; + bool retComplex = retType.IsObject() && (retType.GetTypeInfo()->flags & COMPLEX_RETURN_MASK); + + if( sysFunc->hostReturnInMemory && retComplex ) + { + // The return is made in memory. + buffer.push((asPWORD)retPointer); + } + + if( obj ) + { + asFUNCTION_t *vftable; + switch( callConv ) + { + case ICC_VIRTUAL_THISCALL: + case ICC_VIRTUAL_THISCALL_RETURNINMEM: + #ifndef AS_NO_THISCALL_FUNCTOR_METHOD + case ICC_VIRTUAL_THISCALL_OBJFIRST: + case ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM: + case ICC_VIRTUAL_THISCALL_OBJLAST: + case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM: + #endif + vftable = *((asFUNCTION_t **)obj); + func = vftable[FuncPtrToUInt(asFUNCTION_t(func)) >> 3]; + break; + } + } + + switch( callConv ) + { + case ICC_CDECL_OBJFIRST: + case ICC_THISCALL: + case ICC_VIRTUAL_THISCALL: + case ICC_CDECL_OBJFIRST_RETURNINMEM: + case ICC_THISCALL_RETURNINMEM: + case ICC_VIRTUAL_THISCALL_RETURNINMEM: + #ifndef AS_NO_THISCALL_FUNCTOR_METHOD + case ICC_THISCALL_OBJLAST: + case ICC_VIRTUAL_THISCALL_OBJLAST: + case ICC_THISCALL_OBJLAST_RETURNINMEM: + case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM: + #endif + buffer.push((asPWORD)obj); + break; + #ifndef AS_NO_THISCALL_FUNCTOR_METHOD + case ICC_THISCALL_OBJFIRST: + case ICC_VIRTUAL_THISCALL_OBJFIRST: + case ICC_THISCALL_OBJFIRST_RETURNINMEM: + case ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM: + buffer.push((asPWORD)obj); + buffer.push((asPWORD)secondObject); + break; + #endif + } + + for( int i = 0; i < descr->parameterTypes.GetLength(); ++i ) + { + const asCDataType &parmType = descr->parameterTypes[i]; + + if( parmType.GetTokenType() == ttQuestion ) + { + // The variable args are really two, one pointer and one type id. + buffer.push(parms.takeQWord()); + buffer.push(parms.takeDWord()); + } + else if( parmType.IsPrimitive() || parmType.IsReference() || parmType.IsObjectHandle() ) + { + // Primitive types and references are single slot values. + buffer.push(parms.take(parmType.GetSizeOnStackDWords())); + } + else + { + // An object is being passed by value. + if( (parmType.GetTypeInfo()->flags & COMPLEX_MASK) ) + { + // Copy the address of the object. + buffer.push(parms.takeQWord()); + } + else + { + // Copy the value of the object. + int size = parmType.GetSizeInMemoryBytes(); + void *parm = *(void **)parms.ptr(); + if( size > 8 ) + { + buffer.align(); + buffer.push_object(parm, size); + buffer.align(); + } + else + { + buffer.push_object(parm, size); + } + // Skip pointer. + parms.takeQWord(); + // Delete the original memory. + engine->CallFree(parm); + } + } + } + + switch( callConv ) + { + case ICC_CDECL_OBJLAST: + case ICC_CDECL_OBJLAST_RETURNINMEM: + buffer.push((asPWORD)obj); + break; + #ifndef AS_NO_THISCALL_FUNCTOR_METHOD + case ICC_THISCALL_OBJLAST: + case ICC_THISCALL_OBJLAST_RETURNINMEM: + case ICC_VIRTUAL_THISCALL_OBJLAST: + case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM: + buffer.push((asPWORD)secondObject); + break; + #endif + } + + int stackSize = buffer.count() * (sizeof(asQWORD) / sizeof(asDWORD)); + int retSize = sysFunc->hostReturnSize; + bool returnInMemory = sysFunc->hostReturnInMemory && !retComplex; + + if( returnInMemory ) + { + // Returned on the user stack and copied to retPointer. + retSize = retType.GetSizeInMemoryDWords(); + if( retSize > stackSize ) + { + stackSize = retSize; + } + } + else + { + // Returned in registers and copied to retQW. + asASSERT(retSize <= RETURN_VALUE_MAX_SIZE); + retPointer = retQW; + } + + stackSize = (stackSize * sizeof(asDWORD) + 15) & ~15; + CallFunctionE2K(func, buffer.ptr(), buffer.count(), retPointer, retSize, -stackSize, returnInMemory); } END_AS_NAMESPACE -#endif // AS_E2K -#endif // AS_MAX_PORTABILITY + #endif // AS_E2K +#endif // AS_MAX_PORTABILITY diff --git a/sdk/angelscript/source/as_callfunc_mips.cpp b/sdk/angelscript/source/as_callfunc_mips.cpp index be7d1895..85eebc39 100644 --- a/sdk/angelscript/source/as_callfunc_mips.cpp +++ b/sdk/angelscript/source/as_callfunc_mips.cpp @@ -44,28 +44,28 @@ #include "as_config.h" #ifndef AS_MAX_PORTABILITY -#ifdef AS_MIPS + #ifdef AS_MIPS -#include "as_callfunc.h" -#include "as_scriptengine.h" -#include "as_texts.h" -#include "as_tokendef.h" -#include "as_context.h" + #include "as_callfunc.h" + #include "as_scriptengine.h" + #include "as_texts.h" + #include "as_tokendef.h" + #include "as_context.h" -#include -#include -#if !defined(AS_ANDROID) -#include -#endif + #include + #include + #if !defined(AS_ANDROID) + #include + #endif BEGIN_AS_NAMESPACE -#if defined(__linux__) && defined(_ABIO32) + #if defined(__linux__) && defined(_ABIO32) // The MIPS ABI used by Linux is implemented here // (Tested on CI20 MIPS Creator with Debian Linux) // -// ref: SYSTEM V +// ref: SYSTEM V // APPLICATION BINARY INTERFACE // MIPS RISC Processor // http://math-atlas.sourceforge.net/devel/assembly/mipsabi32.pdf @@ -75,33 +75,49 @@ BEGIN_AS_NAMESPACE union SFloatRegs { - union { double d0; struct { float f0; asDWORD dummy0; };}; - union { double d1; struct { float f1; asDWORD dummy1; };}; -} ; + union + { + double d0; + struct + { + float f0; + asDWORD dummy0; + }; + }; + union + { + double d1; + struct + { + float f1; + asDWORD dummy1; + }; + }; +}; extern "C" asQWORD mipsFunc(asUINT argSize, asDWORD *argBuffer, void *func, SFloatRegs &floatRegs); -asDWORD GetReturnedFloat(); -asQWORD GetReturnedDouble(); +asDWORD GetReturnedFloat(); +asQWORD GetReturnedDouble(); -asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &/*retQW2*/, void *secondObject) +asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD & /*retQW2*/, void *secondObject) { - asCScriptEngine *engine = context->m_engine; - asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; - int callConv = sysFunc->callConv; + asCScriptEngine *engine = context->m_engine; + asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; + int callConv = sysFunc->callConv; asQWORD retQW = 0; - void *func = (void*)sysFunc->func; + void *func = (void *)sysFunc->func; void **vftable; asDWORD argBuffer[128]; // Ought to be big enough asASSERT( sysFunc->paramSize < 128 ); - + asDWORD argOffset = 0; - + SFloatRegs floatRegs; - asDWORD floatOffset = 0; - + asDWORD floatOffset = 0; + // If the application function returns the value in memory then // the first argument must be the pointer to that memory if( sysFunc->hostReturnInMemory ) @@ -109,26 +125,26 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, asASSERT( retPointer ); argBuffer[argOffset++] = (asPWORD)retPointer; } - + if( callConv == ICC_CDECL_OBJFIRST || callConv == ICC_CDECL_OBJFIRST_RETURNINMEM || - callConv == ICC_THISCALL || callConv == ICC_THISCALL_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL || callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM || - callConv == ICC_THISCALL_OBJFIRST || callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || - callConv == ICC_THISCALL_OBJFIRST_RETURNINMEM || callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM || - callConv == ICC_THISCALL_OBJLAST || callConv == ICC_VIRTUAL_THISCALL_OBJLAST || - callConv == ICC_THISCALL_OBJLAST_RETURNINMEM || callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) + callConv == ICC_THISCALL || callConv == ICC_THISCALL_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL || callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM || + callConv == ICC_THISCALL_OBJFIRST || callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || + callConv == ICC_THISCALL_OBJFIRST_RETURNINMEM || callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM || + callConv == ICC_THISCALL_OBJLAST || callConv == ICC_VIRTUAL_THISCALL_OBJLAST || + callConv == ICC_THISCALL_OBJLAST_RETURNINMEM || callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) { // Add the object pointer as the first argument argBuffer[argOffset++] = (asPWORD)obj; } - + if( callConv == ICC_THISCALL_OBJFIRST || callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || - callConv == ICC_THISCALL_OBJFIRST_RETURNINMEM || callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM ) + callConv == ICC_THISCALL_OBJFIRST_RETURNINMEM || callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM ) { - // Add the second object pointer + // Add the second object pointer argBuffer[argOffset++] = (asPWORD)secondObject; } - + int spos = 0; for( asUINT n = 0; n < descr->parameterTypes.GetLength(); n++ ) { @@ -145,11 +161,11 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // Ensure 8byte alignment for classes that need it if( (paramType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALIGN8) && (argOffset & 1) ) argOffset++; - + // Copy the object's memory to the buffer - memcpy(&argBuffer[argOffset], *(void**)(args+spos), paramType.GetSizeInMemoryBytes()); + memcpy(&argBuffer[argOffset], *(void **)(args + spos), paramType.GetSizeInMemoryBytes()); // Delete the original memory - engine->CallFree(*(char**)(args+spos)); + engine->CallFree(*(char **)(args + spos)); spos++; argOffset += paramType.GetSizeInMemoryDWords(); } @@ -163,41 +179,41 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, else { // The first 2 floats or doubles are loaded into the float registers. - // Actually this is only done if they are the first arguments to the function, - // but it doesn't cause any harm to load them into the registers even if they + // Actually this is only done if they are the first arguments to the function, + // but it doesn't cause any harm to load them into the registers even if they // won't be used so we don't need to check if they really are the first args. if( floatOffset == 0 ) { if( paramType.GetTokenType() == ttFloat ) - floatRegs.f0 = *reinterpret_cast(&args[spos]); + floatRegs.f0 = *reinterpret_cast(&args[spos]); else if( paramType.GetTokenType() == ttDouble ) - floatRegs.d0 = *reinterpret_cast(&args[spos]); + floatRegs.d0 = *reinterpret_cast(&args[spos]); floatOffset++; } else if( floatOffset == 1 ) { if( paramType.GetTokenType() == ttFloat ) - floatRegs.f1 = *reinterpret_cast(&args[spos]); + floatRegs.f1 = *reinterpret_cast(&args[spos]); else if( paramType.GetTokenType() == ttDouble ) - floatRegs.d1 = *reinterpret_cast(&args[spos]); + floatRegs.d1 = *reinterpret_cast(&args[spos]); floatOffset++; } - + // Copy the value directly if( paramType.GetSizeOnStackDWords() > 1 ) { // Make sure the argument is 8byte aligned if( argOffset & 1 ) argOffset++; - *reinterpret_cast(&argBuffer[argOffset]) = *reinterpret_cast(&args[spos]); - argOffset += 2; - spos += 2; + *reinterpret_cast(&argBuffer[argOffset]) = *reinterpret_cast(&args[spos]); + argOffset += 2; + spos += 2; } else argBuffer[argOffset++] = args[spos++]; } } - + if( callConv == ICC_CDECL_OBJLAST || callConv == ICC_CDECL_OBJLAST_RETURNINMEM ) { // Add the object pointer as the last argument @@ -205,50 +221,50 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, } if( callConv == ICC_THISCALL_OBJLAST || callConv == ICC_VIRTUAL_THISCALL_OBJLAST || - callConv == ICC_THISCALL_OBJLAST_RETURNINMEM || callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) + callConv == ICC_THISCALL_OBJLAST_RETURNINMEM || callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) { - // Add the second object pointer + // Add the second object pointer argBuffer[argOffset++] = (asPWORD)secondObject; } switch( callConv ) { - case ICC_CDECL: - case ICC_CDECL_RETURNINMEM: - case ICC_STDCALL: - case ICC_STDCALL_RETURNINMEM: - case ICC_CDECL_OBJLAST: - case ICC_CDECL_OBJLAST_RETURNINMEM: - case ICC_CDECL_OBJFIRST: - case ICC_CDECL_OBJFIRST_RETURNINMEM: - case ICC_THISCALL: - case ICC_THISCALL_RETURNINMEM: - case ICC_THISCALL_OBJFIRST: - case ICC_THISCALL_OBJFIRST_RETURNINMEM: - case ICC_THISCALL_OBJLAST: - case ICC_THISCALL_OBJLAST_RETURNINMEM: - retQW = mipsFunc(argOffset*4, argBuffer, func, floatRegs); - break; - - case ICC_VIRTUAL_THISCALL: - case ICC_VIRTUAL_THISCALL_RETURNINMEM: - case ICC_VIRTUAL_THISCALL_OBJFIRST: - case ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM: - case ICC_VIRTUAL_THISCALL_OBJLAST: - case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM: - // Get virtual function table from the object pointer - vftable = *(void***)obj; - retQW = mipsFunc(argOffset*4, argBuffer, vftable[asPWORD(func)>>2], floatRegs); - break; - default: - context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); + case ICC_CDECL: + case ICC_CDECL_RETURNINMEM: + case ICC_STDCALL: + case ICC_STDCALL_RETURNINMEM: + case ICC_CDECL_OBJLAST: + case ICC_CDECL_OBJLAST_RETURNINMEM: + case ICC_CDECL_OBJFIRST: + case ICC_CDECL_OBJFIRST_RETURNINMEM: + case ICC_THISCALL: + case ICC_THISCALL_RETURNINMEM: + case ICC_THISCALL_OBJFIRST: + case ICC_THISCALL_OBJFIRST_RETURNINMEM: + case ICC_THISCALL_OBJLAST: + case ICC_THISCALL_OBJLAST_RETURNINMEM: + retQW = mipsFunc(argOffset * 4, argBuffer, func, floatRegs); + break; + + case ICC_VIRTUAL_THISCALL: + case ICC_VIRTUAL_THISCALL_RETURNINMEM: + case ICC_VIRTUAL_THISCALL_OBJFIRST: + case ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM: + case ICC_VIRTUAL_THISCALL_OBJLAST: + case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM: + // Get virtual function table from the object pointer + vftable = *(void ***)obj; + retQW = mipsFunc(argOffset * 4, argBuffer, vftable[asPWORD(func) >> 2], floatRegs); + break; + default: + context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); } // If the return is a float value we need to get the value from the FP register if( sysFunc->hostReturnFloat ) { if( sysFunc->hostReturnSize == 1 ) - *(asDWORD*)&retQW = GetReturnedFloat(); + *(asDWORD *)&retQW = GetReturnedFloat(); else retQW = GetReturnedDouble(); } @@ -277,100 +293,99 @@ asQWORD GetReturnedDouble() // asQWORD mipsFunc(asUINT argSize, asDWORD *argBuffer, void *func, SFloatRegs &floatRegs); // $2,$3 $4 $5 $6 $7 asm( -" .text\n" -//" .align 2\n" -" .cfi_startproc\n" -" .global mipsFunc\n" -" .ent mipsFunc\n" -"mipsFunc:\n" -//" .frame $fp,64,$31 # vars= 0, regs= 0/0, args= 0, gp= 0\n" -//" .mask 0x00000000,0\n" -//" .fmask 0x00000000,0\n" -" .set noreorder\n" -" .set nomacro\n" - -// align the stack frame to 8 bytes -" addiu $12, $4, 7\n" // t4 ($12) = argSize ($4) + 7 -" li $13, -8\n" // t5 ($13) = 0xfffffffffffffff8 -" and $12, $12, $13\n" // t4 ($12) &= t5 ($13). t4 holds the size of the argument block -// It is required that the caller reserves space for at least 16 bytes even if there are less than 4 arguments -// and add 8 bytes for the return pointer and s0 ($16) backup -" addiu $13, $12, 24\n" // t5 = t4 + 24. t5 ($13) holds the total size of the stack frame (including return pointer) -// save the s0 register (so we can use it to remember where our return pointer is lives) -" sw $16, -4($sp)\n" // store the s0 register (so we can use it to remember how big our stack frame is) -" .cfi_offset 16, -4\n" -// store the return pointer -" sw $31, -8($sp)\n" -" .cfi_offset 31, -8\n" -// keep original stack pointer -" move $16, $sp\n" -" .cfi_def_cfa_register 16\n" -// push the stack -" subu $sp, $sp, $13\n" - -// store the argument in temporary registers -" addiu $25, $6, 0\n" // t9 ($25) holds the function pointer (must be t9 for position independent code) -" addiu $3, $4, 0\n" // v1 ($3) holds the size of the argument buffer -" move $15, $5\n" // t7 ($15) holds the pointer to the argBuffer -" move $14, $7\n" // t6 ($14) holds the values for the float registers - -// load integer registers -" lw $4, 0($15)\n" // a0 ($4) -" lw $5, 4($15)\n" // a1 ($5) -" lw $6, 8($15)\n" // a2 ($6) -" lw $7, 12($15)\n" // a3 ($7) - -// load float registers -" ldc1 $f12, 8($14)\n" -" ldc1 $f14, 0($14)\n" - -// skip stack parameters if there are 4 or less as they are moved into the registers -" addi $14, $3, -16\n" // The first 4 args were already loaded into registers -" blez $14, andCall\n" -" nop\n" - -// push stack parameters -"pushArgs:\n" -" addi $3, -4\n" -// load from $15 + stack bytes ($3) -" addu $14, $15, $3\n" -" lw $14, 0($14)\n" -// store to $sp + stack bytes ($3) -" addu $13, $sp, $3\n" -" sw $14, 0($13)\n" -// if there are more, loop... -" bne $3, $0, pushArgs\n" -" nop\n" - -// and call the function -"andCall:\n" -" jalr $25\n" -" nop\n" - -// restore original stack pointer -" move $sp, $16\n" -// restore the return pointer -" lw $31, -8($sp)\n" -// restore the original value of $16 -" lw $16, -4($sp)\n" -// and return from the function -" jr $31\n" -" nop\n" - -" .set macro\n" -" .set reorder\n" -" .end mipsFunc\n" -" .cfi_endproc\n" -" .size mipsFunc, .-mipsFunc\n" -); - -#else // !(defined(__linux__) && defined(_ABIO32)) - -// The MIPS ABI used by PSP and PS2 is implemented here - -#define AS_MIPS_MAX_ARGS 32 -#define AS_NUM_REG_FLOATS 8 -#define AS_NUM_REG_INTS 8 + " .text\n" + //" .align 2\n" + " .cfi_startproc\n" + " .global mipsFunc\n" + " .ent mipsFunc\n" + "mipsFunc:\n" + //" .frame $fp,64,$31 # vars= 0, regs= 0/0, args= 0, gp= 0\n" + //" .mask 0x00000000,0\n" + //" .fmask 0x00000000,0\n" + " .set noreorder\n" + " .set nomacro\n" + + // align the stack frame to 8 bytes + " addiu $12, $4, 7\n" // t4 ($12) = argSize ($4) + 7 + " li $13, -8\n" // t5 ($13) = 0xfffffffffffffff8 + " and $12, $12, $13\n" // t4 ($12) &= t5 ($13). t4 holds the size of the argument block + // It is required that the caller reserves space for at least 16 bytes even if there are less than 4 arguments + // and add 8 bytes for the return pointer and s0 ($16) backup + " addiu $13, $12, 24\n" // t5 = t4 + 24. t5 ($13) holds the total size of the stack frame (including return pointer) + // save the s0 register (so we can use it to remember where our return pointer is lives) + " sw $16, -4($sp)\n" // store the s0 register (so we can use it to remember how big our stack frame is) + " .cfi_offset 16, -4\n" + // store the return pointer + " sw $31, -8($sp)\n" + " .cfi_offset 31, -8\n" + // keep original stack pointer + " move $16, $sp\n" + " .cfi_def_cfa_register 16\n" + // push the stack + " subu $sp, $sp, $13\n" + + // store the argument in temporary registers + " addiu $25, $6, 0\n" // t9 ($25) holds the function pointer (must be t9 for position independent code) + " addiu $3, $4, 0\n" // v1 ($3) holds the size of the argument buffer + " move $15, $5\n" // t7 ($15) holds the pointer to the argBuffer + " move $14, $7\n" // t6 ($14) holds the values for the float registers + + // load integer registers + " lw $4, 0($15)\n" // a0 ($4) + " lw $5, 4($15)\n" // a1 ($5) + " lw $6, 8($15)\n" // a2 ($6) + " lw $7, 12($15)\n" // a3 ($7) + + // load float registers + " ldc1 $f12, 8($14)\n" + " ldc1 $f14, 0($14)\n" + + // skip stack parameters if there are 4 or less as they are moved into the registers + " addi $14, $3, -16\n" // The first 4 args were already loaded into registers + " blez $14, andCall\n" + " nop\n" + + // push stack parameters + "pushArgs:\n" + " addi $3, -4\n" + // load from $15 + stack bytes ($3) + " addu $14, $15, $3\n" + " lw $14, 0($14)\n" + // store to $sp + stack bytes ($3) + " addu $13, $sp, $3\n" + " sw $14, 0($13)\n" + // if there are more, loop... + " bne $3, $0, pushArgs\n" + " nop\n" + + // and call the function + "andCall:\n" + " jalr $25\n" + " nop\n" + + // restore original stack pointer + " move $sp, $16\n" + // restore the return pointer + " lw $31, -8($sp)\n" + // restore the original value of $16 + " lw $16, -4($sp)\n" + // and return from the function + " jr $31\n" + " nop\n" + + " .set macro\n" + " .set reorder\n" + " .end mipsFunc\n" + " .cfi_endproc\n" + " .size mipsFunc, .-mipsFunc\n"); + + #else // !(defined(__linux__) && defined(_ABIO32)) + + // The MIPS ABI used by PSP and PS2 is implemented here + + #define AS_MIPS_MAX_ARGS 32 + #define AS_NUM_REG_FLOATS 8 + #define AS_NUM_REG_INTS 8 // The array used to send values to the correct places. // first 0-8 regular values to load into the a0-a3, t0-t3 registers @@ -396,11 +411,11 @@ inline void splitArgs(const asDWORD *args, int argNum, int &numRegIntArgs, int & int i; int argBit = 1; - for (i = 0; i < argNum; i++) + for( i = 0; i < argNum; i++ ) { - if (hostFlags & argBit) + if( hostFlags & argBit ) { - if (numRegFloatArgs < AS_NUM_REG_FLOATS) + if( numRegFloatArgs < AS_NUM_REG_FLOATS ) { // put in float register mipsArgs[AS_NUM_REG_INTS + numRegFloatArgs] = args[i]; @@ -415,7 +430,7 @@ inline void splitArgs(const asDWORD *args, int argNum, int &numRegIntArgs, int & } else { - if (numRegIntArgs < AS_NUM_REG_INTS) + if( numRegIntArgs < AS_NUM_REG_INTS ) { // put in int register mipsArgs[numRegIntArgs] = args[i]; @@ -436,12 +451,12 @@ asQWORD CallCDeclFunction(const asDWORD *args, int argSize, asDWORD func, int fl { int argNum = argSize >> 2; - int intArgs = 0; + int intArgs = 0; int floatArgs = 0; - int restArgs = 0; + int restArgs = 0; // put the arguments in the correct places in the mipsArgs array - if(argNum > 0) + if( argNum > 0 ) splitArgs(args, argNum, intArgs, floatArgs, restArgs, flags); return mipsFunc(intArgs << 2, floatArgs << 2, restArgs << 2, func); @@ -453,14 +468,14 @@ asQWORD CallThisCallFunction(const void *obj, const asDWORD *args, int argSize, { int argNum = argSize >> 2; - int intArgs = 1; + int intArgs = 1; int floatArgs = 0; - int restArgs = 0; + int restArgs = 0; - mipsArgs[0] = (asDWORD) obj; + mipsArgs[0] = (asDWORD)obj; // put the arguments in the correct places in the mipsArgs array - if (argNum > 0) + if( argNum > 0 ) splitArgs(args, argNum, intArgs, floatArgs, restArgs, flags); return mipsFunc(intArgs << 2, floatArgs << 2, restArgs << 2, func); @@ -472,22 +487,22 @@ asQWORD CallThisCallFunction_objLast(const void *obj, const asDWORD *args, int a { int argNum = argSize >> 2; - int intArgs = 0; + int intArgs = 0; int floatArgs = 0; - int restArgs = 0; + int restArgs = 0; // put the arguments in the correct places in the mipsArgs array - if(argNum > 0) + if( argNum > 0 ) splitArgs(args, argNum, intArgs, floatArgs, restArgs, flags); - if(intArgs < AS_NUM_REG_INTS) + if( intArgs < AS_NUM_REG_INTS ) { - mipsArgs[intArgs] = (asDWORD) obj; + mipsArgs[intArgs] = (asDWORD)obj; intArgs++; } else { - mipsArgs[AS_NUM_REG_INTS + AS_NUM_REG_FLOATS + restArgs] = (asDWORD) obj; + mipsArgs[AS_NUM_REG_INTS + AS_NUM_REG_FLOATS + restArgs] = (asDWORD)obj; restArgs++; } @@ -512,36 +527,36 @@ asQWORD GetReturnedDouble() return d; } -asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &/*retQW2*/, void */*secondObject*/) +asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD & /*retQW2*/, void * /*secondObject*/) { - asCScriptEngine *engine = context->m_engine; - asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; - int callConv = sysFunc->callConv; + asCScriptEngine *engine = context->m_engine; + asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; + int callConv = sysFunc->callConv; // TODO: Mips does not yet support THISCALL_OBJFIRST/LAST asQWORD retQW = 0; - void *func = (void*)sysFunc->func; - int paramSize = sysFunc->paramSize; + void *func = (void *)sysFunc->func; + int paramSize = sysFunc->paramSize; asDWORD *vftable; if( descr->returnType.IsObject() && !descr->returnType.IsReference() && !descr->returnType.IsObjectHandle() ) { - mipsArgs[AS_MIPS_MAX_ARGS+1] = (asDWORD) retPointer; + mipsArgs[AS_MIPS_MAX_ARGS + 1] = (asDWORD)retPointer; } asASSERT(descr->parameterTypes.GetLength() <= AS_MIPS_MAX_ARGS); // mark all float arguments - int argBit = 1; + int argBit = 1; int hostFlags = 0; - int intArgs = 0; + int intArgs = 0; for( size_t a = 0; a < descr->parameterTypes.GetLength(); a++ ) { - if (descr->parameterTypes[a].IsFloatType()) + if( descr->parameterTypes[a].IsFloatType() ) hostFlags |= argBit; - else + else intArgs++; argBit <<= 1; } @@ -550,27 +565,27 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, if( sysFunc->takesObjByVal ) { paramSize = 0; - int spos = 0; - int dpos = 1; + int spos = 0; + int dpos = 1; for( asUINT n = 0; n < descr->parameterTypes.GetLength(); n++ ) { if( descr->parameterTypes[n].IsObject() && !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() ) { -#ifdef COMPLEX_OBJS_PASSED_BY_REF + #ifdef COMPLEX_OBJS_PASSED_BY_REF if( descr->parameterTypes[n].GetTypeInfo()->flags & COMPLEX_MASK ) { paramBuffer[dpos++] = args[spos++]; paramSize++; } else -#endif + #endif { // Copy the object's memory to the buffer - memcpy(¶mBuffer[dpos], *(void**)(args+spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); + memcpy(¶mBuffer[dpos], *(void **)(args + spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); // Delete the original memory - engine->CallFree(*(char**)(args+spos)); + engine->CallFree(*(char **)(args + spos)); spos++; - dpos += descr->parameterTypes[n].GetSizeInMemoryDWords(); + dpos += descr->parameterTypes[n].GetSizeInMemoryDWords(); paramSize += descr->parameterTypes[n].GetSizeInMemoryDWords(); } } @@ -589,39 +604,39 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, switch( callConv ) { - case ICC_CDECL: - case ICC_CDECL_RETURNINMEM: - case ICC_STDCALL: - case ICC_STDCALL_RETURNINMEM: - retQW = CallCDeclFunction(args, paramSize<<2, (asDWORD)func, hostFlags); - break; - case ICC_THISCALL: - case ICC_THISCALL_RETURNINMEM: - retQW = CallThisCallFunction(obj, args, paramSize<<2, (asDWORD)func, hostFlags); - break; - case ICC_VIRTUAL_THISCALL: - case ICC_VIRTUAL_THISCALL_RETURNINMEM: - // Get virtual function table from the object pointer - vftable = *(asDWORD**)obj; - retQW = CallThisCallFunction(obj, args, paramSize<<2, vftable[asDWORD(func)>>2], hostFlags); - break; - case ICC_CDECL_OBJLAST: - case ICC_CDECL_OBJLAST_RETURNINMEM: - retQW = CallThisCallFunction_objLast(obj, args, paramSize<<2, (asDWORD)func, hostFlags); - break; - case ICC_CDECL_OBJFIRST: - case ICC_CDECL_OBJFIRST_RETURNINMEM: - retQW = CallThisCallFunction(obj, args, paramSize<<2, (asDWORD)func, hostFlags); - break; - default: - context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); + case ICC_CDECL: + case ICC_CDECL_RETURNINMEM: + case ICC_STDCALL: + case ICC_STDCALL_RETURNINMEM: + retQW = CallCDeclFunction(args, paramSize << 2, (asDWORD)func, hostFlags); + break; + case ICC_THISCALL: + case ICC_THISCALL_RETURNINMEM: + retQW = CallThisCallFunction(obj, args, paramSize << 2, (asDWORD)func, hostFlags); + break; + case ICC_VIRTUAL_THISCALL: + case ICC_VIRTUAL_THISCALL_RETURNINMEM: + // Get virtual function table from the object pointer + vftable = *(asDWORD **)obj; + retQW = CallThisCallFunction(obj, args, paramSize << 2, vftable[asDWORD(func) >> 2], hostFlags); + break; + case ICC_CDECL_OBJLAST: + case ICC_CDECL_OBJLAST_RETURNINMEM: + retQW = CallThisCallFunction_objLast(obj, args, paramSize << 2, (asDWORD)func, hostFlags); + break; + case ICC_CDECL_OBJFIRST: + case ICC_CDECL_OBJFIRST_RETURNINMEM: + retQW = CallThisCallFunction(obj, args, paramSize << 2, (asDWORD)func, hostFlags); + break; + default: + context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); } // If the return is a float value we need to get the value from the FP register if( sysFunc->hostReturnFloat ) { if( sysFunc->hostReturnSize == 1 ) - *(asDWORD*)&retQW = GetReturnedFloat(); + *(asDWORD *)&retQW = GetReturnedFloat(); else retQW = GetReturnedDouble(); } @@ -631,105 +646,100 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, asm( -" .text\n" -//" .align 2\n" -" .global mipsFunc\n" -" .ent mipsFunc\n" -"mipsFunc:\n" -//" .frame $fp,64,$31 # vars= 0, regs= 0/0, args= 0, gp= 0\n" -//" .mask 0x00000000,0\n" -//" .fmask 0x00000000,0\n" -" .set noreorder\n" -" .set nomacro\n" -// align the stack frame to 8 bytes -" addiu $12, $6, 7\n" -" li $13, -8\n" // 0xfffffffffffffff8 -" and $12, $12, $13\n" // t4 holds the size of the argument block -// and add 8 bytes for the return pointer and s0 backup -" addiu $13, $12, 8\n" // t5 holds the total size of the stack frame (including return pointer) -// save the s0 register (so we can use it to remember where our return pointer is lives) -" sw $16, -4($sp)\n" // store the s0 register (so we can use it to remember how big our stack frame is) -// push the stack -" subu $sp, $sp, $13\n" -// find the return address, place in s0 -" addu $16, $sp, $12\n" -// store the return pointer -" sw $31, 0($16)\n" - -// backup our function params -" addiu $2, $7, 0\n" -" addiu $3, $6, 0\n" - -// get global mipsArgs[] array pointer -//" lui $15, %hi(mipsArgs)\n" -//" addiu $15, $15, %lo(mipsArgs)\n" -// we'll use the macro instead because SN Systems doesnt like %hi/%lo -".set macro\n" -" la $15, mipsArgs\n" -".set nomacro\n" -// load register params -" lw $4, 0($15)\n" -" lw $5, 4($15)\n" -" lw $6, 8($15)\n" -" lw $7, 12($15)\n" -" lw $8, 16($15)\n" -" lw $9, 20($15)\n" -" lw $10, 24($15)\n" -" lw $11, 28($15)\n" - -// load float params -" lwc1 $f12, 32($15)\n" -" lwc1 $f13, 36($15)\n" -" lwc1 $f14, 40($15)\n" -" lwc1 $f15, 44($15)\n" -" lwc1 $f16, 48($15)\n" -" lwc1 $f17, 52($15)\n" -" lwc1 $f18, 56($15)\n" -" lwc1 $f19, 60($15)\n" - -// skip stack paramaters if there are none -" beq $3, $0, andCall\n" - -// push stack paramaters -" addiu $15, $15, 64\n" -"pushArgs:\n" -" addiu $3, -4\n" -// load from $15 + stack bytes ($3) -" addu $14, $15, $3\n" -" lw $14, 0($14)\n" -// store to $sp + stack bytes ($3) -" addu $13, $sp, $3\n" -" sw $14, 0($13)\n" -// if there are more, loop... -" bne $3, $0, pushArgs\n" -" nop\n" - -// and call the function -"andCall:\n" -" jal $2\n" -" nop\n" - -// restore the return pointer -" lw $31, 0($16)\n" -// pop the stack pointer (remembering the return pointer was 8 bytes below the top) -" addiu $sp, $16, 8\n" -// and return from the function -" jr $31\n" -// restore the s0 register (in the branch delay slot) -" lw $16, -4($sp)\n" -" .set macro\n" -" .set reorder\n" -" .end mipsFunc\n" -" .size mipsFunc, .-mipsFunc\n" -); - -#endif // PSP and PS2 MIPS ABI - -END_AS_NAMESPACE - -#endif // AS_MIPS -#endif // AS_MAX_PORTABILITY - - + " .text\n" + //" .align 2\n" + " .global mipsFunc\n" + " .ent mipsFunc\n" + "mipsFunc:\n" + //" .frame $fp,64,$31 # vars= 0, regs= 0/0, args= 0, gp= 0\n" + //" .mask 0x00000000,0\n" + //" .fmask 0x00000000,0\n" + " .set noreorder\n" + " .set nomacro\n" + // align the stack frame to 8 bytes + " addiu $12, $6, 7\n" + " li $13, -8\n" // 0xfffffffffffffff8 + " and $12, $12, $13\n" // t4 holds the size of the argument block + // and add 8 bytes for the return pointer and s0 backup + " addiu $13, $12, 8\n" // t5 holds the total size of the stack frame (including return pointer) + // save the s0 register (so we can use it to remember where our return pointer is lives) + " sw $16, -4($sp)\n" // store the s0 register (so we can use it to remember how big our stack frame is) + // push the stack + " subu $sp, $sp, $13\n" + // find the return address, place in s0 + " addu $16, $sp, $12\n" + // store the return pointer + " sw $31, 0($16)\n" + + // backup our function params + " addiu $2, $7, 0\n" + " addiu $3, $6, 0\n" + + // get global mipsArgs[] array pointer + //" lui $15, %hi(mipsArgs)\n" + //" addiu $15, $15, %lo(mipsArgs)\n" + // we'll use the macro instead because SN Systems doesnt like %hi/%lo + ".set macro\n" + " la $15, mipsArgs\n" + ".set nomacro\n" + // load register params + " lw $4, 0($15)\n" + " lw $5, 4($15)\n" + " lw $6, 8($15)\n" + " lw $7, 12($15)\n" + " lw $8, 16($15)\n" + " lw $9, 20($15)\n" + " lw $10, 24($15)\n" + " lw $11, 28($15)\n" + + // load float params + " lwc1 $f12, 32($15)\n" + " lwc1 $f13, 36($15)\n" + " lwc1 $f14, 40($15)\n" + " lwc1 $f15, 44($15)\n" + " lwc1 $f16, 48($15)\n" + " lwc1 $f17, 52($15)\n" + " lwc1 $f18, 56($15)\n" + " lwc1 $f19, 60($15)\n" + + // skip stack paramaters if there are none + " beq $3, $0, andCall\n" + + // push stack paramaters + " addiu $15, $15, 64\n" + "pushArgs:\n" + " addiu $3, -4\n" + // load from $15 + stack bytes ($3) + " addu $14, $15, $3\n" + " lw $14, 0($14)\n" + // store to $sp + stack bytes ($3) + " addu $13, $sp, $3\n" + " sw $14, 0($13)\n" + // if there are more, loop... + " bne $3, $0, pushArgs\n" + " nop\n" + + // and call the function + "andCall:\n" + " jal $2\n" + " nop\n" + + // restore the return pointer + " lw $31, 0($16)\n" + // pop the stack pointer (remembering the return pointer was 8 bytes below the top) + " addiu $sp, $16, 8\n" + // and return from the function + " jr $31\n" + // restore the s0 register (in the branch delay slot) + " lw $16, -4($sp)\n" + " .set macro\n" + " .set reorder\n" + " .end mipsFunc\n" + " .size mipsFunc, .-mipsFunc\n"); + + #endif // PSP and PS2 MIPS ABI +END_AS_NAMESPACE + #endif // AS_MIPS +#endif // AS_MAX_PORTABILITY diff --git a/sdk/angelscript/source/as_callfunc_ppc.cpp b/sdk/angelscript/source/as_callfunc_ppc.cpp index 053221fe..7ef92046 100644 --- a/sdk/angelscript/source/as_callfunc_ppc.cpp +++ b/sdk/angelscript/source/as_callfunc_ppc.cpp @@ -42,23 +42,23 @@ #include "as_config.h" #ifndef AS_MAX_PORTABILITY -#ifdef AS_PPC + #ifdef AS_PPC -#include "as_callfunc.h" -#include "as_scriptengine.h" -#include "as_texts.h" -#include "as_tokendef.h" -#include "as_context.h" + #include "as_callfunc.h" + #include "as_scriptengine.h" + #include "as_texts.h" + #include "as_tokendef.h" + #include "as_context.h" -#include + #include BEGIN_AS_NAMESPACE -// This part was originally written by Pecan Heber, June 2006, for -// use on MacOS X with 32bit PPC processor. He based the code on the -// code in as_callfunc_sh4.cpp + // This part was originally written by Pecan Heber, June 2006, for + // use on MacOS X with 32bit PPC processor. He based the code on the + // code in as_callfunc_sh4.cpp -#define AS_PPC_MAX_ARGS 32 + #define AS_PPC_MAX_ARGS 32 // The array used to send values to the correct places. // Contains a byte of argTypes to indicate the register tYpe to load @@ -69,262 +69,263 @@ BEGIN_AS_NAMESPACE // TODO: multithread: We need to remove these global variables for thread-safety -enum argTypes { ppcENDARG, ppcINTARG, ppcFLOATARG, ppcDOUBLEARG }; -static asDWORD ppcArgs[2*AS_PPC_MAX_ARGS + 1 + 1]; +enum argTypes { ppcENDARG, + ppcINTARG, + ppcFLOATARG, + ppcDOUBLEARG }; +static asDWORD ppcArgs[2 * AS_PPC_MAX_ARGS + 1 + 1]; // Using extern "C" because we use this symbol name in the assembly code -extern "C" -{ - static asBYTE ppcArgsType[2*AS_PPC_MAX_ARGS + 1 + 1 + 1]; +extern "C" { +static asBYTE ppcArgsType[2 * AS_PPC_MAX_ARGS + 1 + 1 + 1]; } -// NOTE: these values are for PowerPC 32 bit. -#define PPC_LINKAGE_SIZE (24) // how big the PPC linkage area is in a stack frame -#define PPC_NUM_REGSTORE (9) // how many registers of the PPC we need to store/restore for ppcFunc() -#define PPC_REGSTORE_SIZE (4*PPC_NUM_REGSTORE) // how many bytes are required for register store/restore -#define EXTRA_STACK_SIZE (PPC_LINKAGE_SIZE + PPC_REGSTORE_SIZE) // memory required, not including parameters, for the stack frame -#define PPC_STACK_SIZE(numParams) (-( ( ((((numParams)<8)?8:(numParams))<<2) + EXTRA_STACK_SIZE + 15 ) & ~15 )) // calculates the total stack size needed for ppcFunc64, must pad to 16bytes + // NOTE: these values are for PowerPC 32 bit. + #define PPC_LINKAGE_SIZE (24) // how big the PPC linkage area is in a stack frame + #define PPC_NUM_REGSTORE (9) // how many registers of the PPC we need to store/restore for ppcFunc() + #define PPC_REGSTORE_SIZE (4 * PPC_NUM_REGSTORE) // how many bytes are required for register store/restore + #define EXTRA_STACK_SIZE (PPC_LINKAGE_SIZE + PPC_REGSTORE_SIZE) // memory required, not including parameters, for the stack frame + #define PPC_STACK_SIZE(numParams) (-((((((numParams) < 8) ? 8 : (numParams)) << 2) + EXTRA_STACK_SIZE + 15) & ~15)) // calculates the total stack size needed for ppcFunc64, must pad to 16bytes // Loads all data into the correct places and calls the function. // ppcArgsType is an array containing a byte type (enum argTypes) for each argument. // stackArgSize is the size in bytes for how much data to put on the stack frame -extern "C" asQWORD ppcFunc(const asDWORD* argsPtr, int StackArgSize, asDWORD func); +extern "C" asQWORD ppcFunc(const asDWORD *argsPtr, int StackArgSize, asDWORD func); asm(" .text\n" - " .align 2\n" // align the code to 1 << 2 = 4 bytes - " .globl _ppcFunc\n" - "_ppcFunc:\n" - - // We're receiving the following parameters - - // r3 : argsPtr - // r4 : StackArgSize - // r5 : func - - // The following registers are used through out the function - - // r31 : the address of the label address, as reference for all other labels - // r30 : temporary variable - // r29 : arg list pointer - // r28 : number of FPR registers used by the parameters - // r27 : the function pointer that will be called - // r26 : the location of the parameters for the call - // r25 : arg type list pointer - // r24 : temporary variable - // r23 : number of GPR registers used by the parameters - // r1 : this is stack pointer - // r0 : temporary variable - // f0 : temporary variable - - // We need to store some of the registers for restoral before returning to caller - - // lr - always stored in 8(r1) - this is the return address - // cr - not required to be stored, but if it is, its place is in 4(r1) - this is the condition register - // r1 - always stored in 0(r1) - this is the stack pointer - // r11 - // r13 to r31 - // f14 to f31 - - // Store register values and setup our stack frame - " mflr r0 \n" // move the return address into r0 - " stw r0, 8(r1) \n" // Store the return address on the stack - " stmw r23, -36(r1) \n" // Store registers r23 to r31 on the stack - " stwux r1, r1, r4 \n" // Increase the stack with the needed space and store the original value in the destination - - // Obtain an address that we'll use as our position of reference when obtaining addresses of other labels - " bl address \n" - "address: \n" - " mflr r31 \n" - - // initial registers for the function - " mr r29, r3 \n" // (r29) args list - " mr r27, r5 \n" // load the function pointer to call. func actually holds the pointer to our function - " addi r26, r1, 24 \n" // setup the pointer to the parameter area to the function we're going to call - " sub r0, r0, r0 \n" // zero out r0 - " mr r23, r0 \n" // zero out r23, which holds the number of used GPR registers - " mr r28, r0 \n" // zero our r22, which holds the number of used float registers - - // load the global ppcArgsType which holds the types of arguments for each argument - " addis r25, r31, ha16(_ppcArgsType - address) \n" // load the upper 16 bits of the address to r25 - " la r25, lo16(_ppcArgsType - address)(r25) \n" // load the lower 16 bits of the address to r25 - " subi r25, r25, 1 \n" // since we increment r25 on its use, we'll pre-decrement it - - // loop through the arguments - "ppcNextArg: \n" - " addi r25, r25, 1 \n" // increment r25, our arg type pointer - // switch based on the current argument type (0:end, 1:int, 2:float 3:double) - " lbz r24, 0(r25) \n" // load the current argument type (it's a byte) - " mulli r24, r24, 4 \n" // our jump table has 4 bytes per case (1 instruction) - " addis r30, r31, ha16(ppcTypeSwitch - address) \n" // load the address of the jump table for the switch - " la r30, lo16(ppcTypeSwitch - address)(r30) \n" - - " add r0, r30, r24 \n" // offset by our argument type - " mtctr r0 \n" // load the jump address into CTR - " bctr \n" // jump into the jump table/switch - " nop \n" - - // the jump table/switch based on the current argument type - "ppcTypeSwitch: \n" - " b ppcArgsEnd \n" - " b ppcArgIsInteger \n" - " b ppcArgIsFloat \n" - " b ppcArgIsDouble \n" - - // when we get here we have finished processing all the arguments - // everything is ready to go to call the function - "ppcArgsEnd: \n" - " mtctr r27 \n" // the function pointer is stored in r27, load that into CTR - " bctrl \n" // call the function. We have to do it this way so that the LR gets the proper - " nop \n" // return value (the next instruction below). So we have to branch from CTR instead of LR. - - // Restore registers and caller's stack frame, then return to caller - " lwz r1, 0(r1) \n" // restore the caller's stack pointer - " lwz r0, 8(r1) \n" // load in the caller's LR - " mtlr r0 \n" // restore the caller's LR - " lmw r23, -36(r1) \n" // restore registers r23 to r31 from the stack - " blr \n" // return back to the caller - " nop \n" - - // Integer argument (GPR register) - "ppcArgIsInteger: \n" - " addis r30, r31, ha16(ppcLoadIntReg - address) \n" // load the address to the jump table for integer registers - " la r30, lo16(ppcLoadIntReg - address)(r30) \n" - " mulli r0, r23, 8 \n" // each item in the jump table is 2 instructions (8 bytes) - " add r0, r0, r30 \n" // calculate ppcLoadIntReg[numUsedGPRRegs] - " lwz r30, 0(r29) \n" // load the next argument from the argument list into r30 - " cmpwi r23, 8 \n" // we can only load GPR3 through GPR10 (8 registers) - " bgt ppcLoadIntRegUpd \n" // if we're beyond 8 GPR registers, we're in the stack, go there - " mtctr r0 \n" // load the address of our ppcLoadIntReg jump table (we're below 8 GPR registers) - " bctr \n" // load the argument into a GPR register - " nop \n" - // jump table for GPR registers, for the first 8 GPR arguments - "ppcLoadIntReg: \n" - " mr r3, r30 \n" // arg0 (to r3) - " b ppcLoadIntRegUpd \n" - " mr r4, r30 \n" // arg1 (to r4) - " b ppcLoadIntRegUpd \n" - " mr r5, r30 \n" // arg2 (to r5) - " b ppcLoadIntRegUpd \n" - " mr r6, r30 \n" // arg3 (to r6) - " b ppcLoadIntRegUpd \n" - " mr r7, r30 \n" // arg4 (to r7) - " b ppcLoadIntRegUpd \n" - " mr r8, r30 \n" // arg5 (to r8) - " b ppcLoadIntRegUpd \n" - " mr r9, r30 \n" // arg6 (to r9) - " b ppcLoadIntRegUpd \n" - " mr r10, r30 \n" // arg7 (to r10) - " b ppcLoadIntRegUpd \n" - // all GPR arguments still go on the stack - "ppcLoadIntRegUpd: \n" - " stw r30, 0(r26) \n" // store the argument into the next slot on the stack's argument list - " addi r23, r23, 1 \n" // count a used GPR register - " addi r29, r29, 4 \n" // move to the next argument on the list - " addi r26, r26, 4 \n" // adjust our argument stack pointer for the next - " b ppcNextArg \n" // next argument - - // single Float argument - "ppcArgIsFloat:\n" - " addis r30, r31, ha16(ppcLoadFloatReg - address) \n" // get the base address of the float register jump table - " la r30, lo16(ppcLoadFloatReg - address)(r30) \n" - " mulli r0, r28, 8 \n" // each jump table entry is 8 bytes - " add r0, r0, r30 \n" // calculate the offset to ppcLoadFloatReg[numUsedFloatReg] - " lfs f0, 0(r29) \n" // load the next argument as a float into f0 - " cmpwi r28, 13 \n" // can't load more than 13 float/double registers - " bgt ppcLoadFloatRegUpd \n" // if we're beyond 13 registers, just fall to inserting into the stack - " mtctr r0 \n" // jump into the float jump table - " bctr \n" - " nop \n" - // jump table for float registers, for the first 13 float arguments - "ppcLoadFloatReg: \n" - " fmr f1, f0 \n" // arg0 (f1) - " b ppcLoadFloatRegUpd \n" - " fmr f2, f0 \n" // arg1 (f2) - " b ppcLoadFloatRegUpd \n" - " fmr f3, f0 \n" // arg2 (f3) - " b ppcLoadFloatRegUpd \n" - " fmr f4, f0 \n" // arg3 (f4) - " b ppcLoadFloatRegUpd \n" - " fmr f5, f0 \n" // arg4 (f5) - " b ppcLoadFloatRegUpd \n" - " fmr f6, f0 \n" // arg5 (f6) - " b ppcLoadFloatRegUpd \n" - " fmr f7, f0 \n" // arg6 (f7) - " b ppcLoadFloatRegUpd \n" - " fmr f8, f0 \n" // arg7 (f8) - " b ppcLoadFloatRegUpd \n" - " fmr f9, f0 \n" // arg8 (f9) - " b ppcLoadFloatRegUpd \n" - " fmr f10, f0 \n" // arg9 (f10) - " b ppcLoadFloatRegUpd \n" - " fmr f11, f0 \n" // arg10 (f11) - " b ppcLoadFloatRegUpd \n" - " fmr f12, f0 \n" // arg11 (f12) - " b ppcLoadFloatRegUpd \n" - " fmr f13, f0 \n" // arg12 (f13) - " b ppcLoadFloatRegUpd \n" - " nop \n" - // all float arguments still go on the stack - "ppcLoadFloatRegUpd: \n" - " stfs f0, 0(r26) \n" // store, as a single float, f0 (current argument) on to the stack argument list - " addi r23, r23, 1 \n" // a float register eats up a GPR register - " addi r28, r28, 1 \n" // ...and, of course, a float register - " addi r29, r29, 4 \n" // move to the next argument in the list - " addi r26, r26, 4 \n" // move to the next stack slot - " b ppcNextArg \n" // on to the next argument - " nop \n" - - // double Float argument - "ppcArgIsDouble: \n" - " addis r30, r31, ha16(ppcLoadDoubleReg - address) \n" // load the base address of the jump table for double registers - " la r30, lo16(ppcLoadDoubleReg - address)(r30) \n" - " mulli r0, r28, 8 \n" // each slot of the jump table is 8 bytes - " add r0, r0, r30 \n" // calculate ppcLoadDoubleReg[numUsedFloatReg] - " lfd f0, 0(r29) \n" // load the next argument, as a double float, into f0 - " cmpwi r28, 13 \n" // the first 13 floats must go into float registers also - " bgt ppcLoadDoubleRegUpd \n" // if we're beyond 13, then just put on to the stack - " mtctr r0 \n" // we're under 13, first load our register - " bctr \n" // jump into the jump table - " nop \n" - // jump table for float registers, for the first 13 float arguments - "ppcLoadDoubleReg: \n" - " fmr f1, f0 \n" // arg0 (f1) - " b ppcLoadDoubleRegUpd \n" - " fmr f2, f0 \n" // arg1 (f2) - " b ppcLoadDoubleRegUpd \n" - " fmr f3, f0 \n" // arg2 (f3) - " b ppcLoadDoubleRegUpd \n" - " fmr f4, f0 \n" // arg3 (f4) - " b ppcLoadDoubleRegUpd \n" - " fmr f5, f0 \n" // arg4 (f5) - " b ppcLoadDoubleRegUpd \n" - " fmr f6, f0 \n" // arg5 (f6) - " b ppcLoadDoubleRegUpd \n" - " fmr f7, f0 \n" // arg6 (f7) - " b ppcLoadDoubleRegUpd \n" - " fmr f8, f0 \n" // arg7 (f8) - " b ppcLoadDoubleRegUpd \n" - " fmr f9, f0 \n" // arg8 (f9) - " b ppcLoadDoubleRegUpd \n" - " fmr f10, f0 \n" // arg9 (f10) - " b ppcLoadDoubleRegUpd \n" - " fmr f11, f0 \n" // arg10 (f11) - " b ppcLoadDoubleRegUpd \n" - " fmr f12, f0 \n" // arg11 (f12) - " b ppcLoadDoubleRegUpd \n" - " fmr f13, f0 \n" // arg12 (f13) - " b ppcLoadDoubleRegUpd \n" - " nop \n" - // all float arguments still go on the stack - "ppcLoadDoubleRegUpd: \n" - " stfd f0, 0(r26) \n" // store f0, as a double, into the argument list on the stack - " addi r23, r23, 2 \n" // a double float eats up two GPRs - " addi r28, r28, 1 \n" // ...and, of course, a float - " addi r29, r29, 8 \n" // increment to our next argument we need to process (8 bytes for the 64bit float) - " addi r26, r26, 8 \n" // increment to the next slot on the argument list on the stack (8 bytes) - " b ppcNextArg \n" // on to the next argument - " nop \n" -); + " .align 2\n" // align the code to 1 << 2 = 4 bytes + " .globl _ppcFunc\n" + "_ppcFunc:\n" + + // We're receiving the following parameters + + // r3 : argsPtr + // r4 : StackArgSize + // r5 : func + + // The following registers are used through out the function + + // r31 : the address of the label address, as reference for all other labels + // r30 : temporary variable + // r29 : arg list pointer + // r28 : number of FPR registers used by the parameters + // r27 : the function pointer that will be called + // r26 : the location of the parameters for the call + // r25 : arg type list pointer + // r24 : temporary variable + // r23 : number of GPR registers used by the parameters + // r1 : this is stack pointer + // r0 : temporary variable + // f0 : temporary variable + + // We need to store some of the registers for restoral before returning to caller + + // lr - always stored in 8(r1) - this is the return address + // cr - not required to be stored, but if it is, its place is in 4(r1) - this is the condition register + // r1 - always stored in 0(r1) - this is the stack pointer + // r11 + // r13 to r31 + // f14 to f31 + + // Store register values and setup our stack frame + " mflr r0 \n" // move the return address into r0 + " stw r0, 8(r1) \n" // Store the return address on the stack + " stmw r23, -36(r1) \n" // Store registers r23 to r31 on the stack + " stwux r1, r1, r4 \n" // Increase the stack with the needed space and store the original value in the destination + + // Obtain an address that we'll use as our position of reference when obtaining addresses of other labels + " bl address \n" + "address: \n" + " mflr r31 \n" + + // initial registers for the function + " mr r29, r3 \n" // (r29) args list + " mr r27, r5 \n" // load the function pointer to call. func actually holds the pointer to our function + " addi r26, r1, 24 \n" // setup the pointer to the parameter area to the function we're going to call + " sub r0, r0, r0 \n" // zero out r0 + " mr r23, r0 \n" // zero out r23, which holds the number of used GPR registers + " mr r28, r0 \n" // zero our r22, which holds the number of used float registers + + // load the global ppcArgsType which holds the types of arguments for each argument + " addis r25, r31, ha16(_ppcArgsType - address) \n" // load the upper 16 bits of the address to r25 + " la r25, lo16(_ppcArgsType - address)(r25) \n" // load the lower 16 bits of the address to r25 + " subi r25, r25, 1 \n" // since we increment r25 on its use, we'll pre-decrement it + + // loop through the arguments + "ppcNextArg: \n" + " addi r25, r25, 1 \n" // increment r25, our arg type pointer + // switch based on the current argument type (0:end, 1:int, 2:float 3:double) + " lbz r24, 0(r25) \n" // load the current argument type (it's a byte) + " mulli r24, r24, 4 \n" // our jump table has 4 bytes per case (1 instruction) + " addis r30, r31, ha16(ppcTypeSwitch - address) \n" // load the address of the jump table for the switch + " la r30, lo16(ppcTypeSwitch - address)(r30) \n" + + " add r0, r30, r24 \n" // offset by our argument type + " mtctr r0 \n" // load the jump address into CTR + " bctr \n" // jump into the jump table/switch + " nop \n" + + // the jump table/switch based on the current argument type + "ppcTypeSwitch: \n" + " b ppcArgsEnd \n" + " b ppcArgIsInteger \n" + " b ppcArgIsFloat \n" + " b ppcArgIsDouble \n" + + // when we get here we have finished processing all the arguments + // everything is ready to go to call the function + "ppcArgsEnd: \n" + " mtctr r27 \n" // the function pointer is stored in r27, load that into CTR + " bctrl \n" // call the function. We have to do it this way so that the LR gets the proper + " nop \n" // return value (the next instruction below). So we have to branch from CTR instead of LR. + + // Restore registers and caller's stack frame, then return to caller + " lwz r1, 0(r1) \n" // restore the caller's stack pointer + " lwz r0, 8(r1) \n" // load in the caller's LR + " mtlr r0 \n" // restore the caller's LR + " lmw r23, -36(r1) \n" // restore registers r23 to r31 from the stack + " blr \n" // return back to the caller + " nop \n" + + // Integer argument (GPR register) + "ppcArgIsInteger: \n" + " addis r30, r31, ha16(ppcLoadIntReg - address) \n" // load the address to the jump table for integer registers + " la r30, lo16(ppcLoadIntReg - address)(r30) \n" + " mulli r0, r23, 8 \n" // each item in the jump table is 2 instructions (8 bytes) + " add r0, r0, r30 \n" // calculate ppcLoadIntReg[numUsedGPRRegs] + " lwz r30, 0(r29) \n" // load the next argument from the argument list into r30 + " cmpwi r23, 8 \n" // we can only load GPR3 through GPR10 (8 registers) + " bgt ppcLoadIntRegUpd \n" // if we're beyond 8 GPR registers, we're in the stack, go there + " mtctr r0 \n" // load the address of our ppcLoadIntReg jump table (we're below 8 GPR registers) + " bctr \n" // load the argument into a GPR register + " nop \n" + // jump table for GPR registers, for the first 8 GPR arguments + "ppcLoadIntReg: \n" + " mr r3, r30 \n" // arg0 (to r3) + " b ppcLoadIntRegUpd \n" + " mr r4, r30 \n" // arg1 (to r4) + " b ppcLoadIntRegUpd \n" + " mr r5, r30 \n" // arg2 (to r5) + " b ppcLoadIntRegUpd \n" + " mr r6, r30 \n" // arg3 (to r6) + " b ppcLoadIntRegUpd \n" + " mr r7, r30 \n" // arg4 (to r7) + " b ppcLoadIntRegUpd \n" + " mr r8, r30 \n" // arg5 (to r8) + " b ppcLoadIntRegUpd \n" + " mr r9, r30 \n" // arg6 (to r9) + " b ppcLoadIntRegUpd \n" + " mr r10, r30 \n" // arg7 (to r10) + " b ppcLoadIntRegUpd \n" + // all GPR arguments still go on the stack + "ppcLoadIntRegUpd: \n" + " stw r30, 0(r26) \n" // store the argument into the next slot on the stack's argument list + " addi r23, r23, 1 \n" // count a used GPR register + " addi r29, r29, 4 \n" // move to the next argument on the list + " addi r26, r26, 4 \n" // adjust our argument stack pointer for the next + " b ppcNextArg \n" // next argument + + // single Float argument + "ppcArgIsFloat:\n" + " addis r30, r31, ha16(ppcLoadFloatReg - address) \n" // get the base address of the float register jump table + " la r30, lo16(ppcLoadFloatReg - address)(r30) \n" + " mulli r0, r28, 8 \n" // each jump table entry is 8 bytes + " add r0, r0, r30 \n" // calculate the offset to ppcLoadFloatReg[numUsedFloatReg] + " lfs f0, 0(r29) \n" // load the next argument as a float into f0 + " cmpwi r28, 13 \n" // can't load more than 13 float/double registers + " bgt ppcLoadFloatRegUpd \n" // if we're beyond 13 registers, just fall to inserting into the stack + " mtctr r0 \n" // jump into the float jump table + " bctr \n" + " nop \n" + // jump table for float registers, for the first 13 float arguments + "ppcLoadFloatReg: \n" + " fmr f1, f0 \n" // arg0 (f1) + " b ppcLoadFloatRegUpd \n" + " fmr f2, f0 \n" // arg1 (f2) + " b ppcLoadFloatRegUpd \n" + " fmr f3, f0 \n" // arg2 (f3) + " b ppcLoadFloatRegUpd \n" + " fmr f4, f0 \n" // arg3 (f4) + " b ppcLoadFloatRegUpd \n" + " fmr f5, f0 \n" // arg4 (f5) + " b ppcLoadFloatRegUpd \n" + " fmr f6, f0 \n" // arg5 (f6) + " b ppcLoadFloatRegUpd \n" + " fmr f7, f0 \n" // arg6 (f7) + " b ppcLoadFloatRegUpd \n" + " fmr f8, f0 \n" // arg7 (f8) + " b ppcLoadFloatRegUpd \n" + " fmr f9, f0 \n" // arg8 (f9) + " b ppcLoadFloatRegUpd \n" + " fmr f10, f0 \n" // arg9 (f10) + " b ppcLoadFloatRegUpd \n" + " fmr f11, f0 \n" // arg10 (f11) + " b ppcLoadFloatRegUpd \n" + " fmr f12, f0 \n" // arg11 (f12) + " b ppcLoadFloatRegUpd \n" + " fmr f13, f0 \n" // arg12 (f13) + " b ppcLoadFloatRegUpd \n" + " nop \n" + // all float arguments still go on the stack + "ppcLoadFloatRegUpd: \n" + " stfs f0, 0(r26) \n" // store, as a single float, f0 (current argument) on to the stack argument list + " addi r23, r23, 1 \n" // a float register eats up a GPR register + " addi r28, r28, 1 \n" // ...and, of course, a float register + " addi r29, r29, 4 \n" // move to the next argument in the list + " addi r26, r26, 4 \n" // move to the next stack slot + " b ppcNextArg \n" // on to the next argument + " nop \n" + + // double Float argument + "ppcArgIsDouble: \n" + " addis r30, r31, ha16(ppcLoadDoubleReg - address) \n" // load the base address of the jump table for double registers + " la r30, lo16(ppcLoadDoubleReg - address)(r30) \n" + " mulli r0, r28, 8 \n" // each slot of the jump table is 8 bytes + " add r0, r0, r30 \n" // calculate ppcLoadDoubleReg[numUsedFloatReg] + " lfd f0, 0(r29) \n" // load the next argument, as a double float, into f0 + " cmpwi r28, 13 \n" // the first 13 floats must go into float registers also + " bgt ppcLoadDoubleRegUpd \n" // if we're beyond 13, then just put on to the stack + " mtctr r0 \n" // we're under 13, first load our register + " bctr \n" // jump into the jump table + " nop \n" + // jump table for float registers, for the first 13 float arguments + "ppcLoadDoubleReg: \n" + " fmr f1, f0 \n" // arg0 (f1) + " b ppcLoadDoubleRegUpd \n" + " fmr f2, f0 \n" // arg1 (f2) + " b ppcLoadDoubleRegUpd \n" + " fmr f3, f0 \n" // arg2 (f3) + " b ppcLoadDoubleRegUpd \n" + " fmr f4, f0 \n" // arg3 (f4) + " b ppcLoadDoubleRegUpd \n" + " fmr f5, f0 \n" // arg4 (f5) + " b ppcLoadDoubleRegUpd \n" + " fmr f6, f0 \n" // arg5 (f6) + " b ppcLoadDoubleRegUpd \n" + " fmr f7, f0 \n" // arg6 (f7) + " b ppcLoadDoubleRegUpd \n" + " fmr f8, f0 \n" // arg7 (f8) + " b ppcLoadDoubleRegUpd \n" + " fmr f9, f0 \n" // arg8 (f9) + " b ppcLoadDoubleRegUpd \n" + " fmr f10, f0 \n" // arg9 (f10) + " b ppcLoadDoubleRegUpd \n" + " fmr f11, f0 \n" // arg10 (f11) + " b ppcLoadDoubleRegUpd \n" + " fmr f12, f0 \n" // arg11 (f12) + " b ppcLoadDoubleRegUpd \n" + " fmr f13, f0 \n" // arg12 (f13) + " b ppcLoadDoubleRegUpd \n" + " nop \n" + // all float arguments still go on the stack + "ppcLoadDoubleRegUpd: \n" + " stfd f0, 0(r26) \n" // store f0, as a double, into the argument list on the stack + " addi r23, r23, 2 \n" // a double float eats up two GPRs + " addi r28, r28, 1 \n" // ...and, of course, a float + " addi r29, r29, 8 \n" // increment to our next argument we need to process (8 bytes for the 64bit float) + " addi r26, r26, 8 \n" // increment to the next slot on the argument list on the stack (8 bytes) + " b ppcNextArg \n" // on to the next argument + " nop \n"); asDWORD GetReturnedFloat() { @@ -341,14 +342,14 @@ asQWORD GetReturnedDouble() } // puts the arguments in the correct place in the stack array. See comments above. -void stackArgs(const asDWORD *args, const asBYTE *argsType, int& numIntArgs, int& numFloatArgs, int& numDoubleArgs) +void stackArgs(const asDWORD *args, const asBYTE *argsType, int &numIntArgs, int &numFloatArgs, int &numDoubleArgs) { int i; - int argWordPos = numIntArgs + numFloatArgs + (numDoubleArgs*2); + int argWordPos = numIntArgs + numFloatArgs + (numDoubleArgs * 2); int typeOffset = numIntArgs + numFloatArgs + numDoubleArgs; int typeIndex; - for( i = 0, typeIndex = 0; ; i++, typeIndex++ ) + for( i = 0, typeIndex = 0;; i++, typeIndex++ ) { // store the type ppcArgsType[typeOffset++] = argsType[typeIndex]; @@ -357,27 +358,27 @@ void stackArgs(const asDWORD *args, const asBYTE *argsType, int& numIntArgs, int switch( argsType[typeIndex] ) { - case ppcFLOATARG: - // stow float - ppcArgs[argWordPos] = args[i]; // it's just a bit copy - numFloatArgs++; - argWordPos++; //add one word - break; - - case ppcDOUBLEARG: - // stow double - memcpy( &ppcArgs[argWordPos], &args[i], sizeof(double) ); // we have to do this because of alignment - numDoubleArgs++; - argWordPos+=2; //add two words - i++;//doubles take up 2 argument slots - break; - - case ppcINTARG: - // stow register - ppcArgs[argWordPos] = args[i]; - numIntArgs++; - argWordPos++; - break; + case ppcFLOATARG: + // stow float + ppcArgs[argWordPos] = args[i]; // it's just a bit copy + numFloatArgs++; + argWordPos++; //add one word + break; + + case ppcDOUBLEARG: + // stow double + memcpy(&ppcArgs[argWordPos], &args[i], sizeof(double)); // we have to do this because of alignment + numDoubleArgs++; + argWordPos += 2; //add two words + i++; //doubles take up 2 argument slots + break; + + case ppcINTARG: + // stow register + ppcArgs[argWordPos] = args[i]; + numIntArgs++; + argWordPos++; + break; } } @@ -385,7 +386,7 @@ void stackArgs(const asDWORD *args, const asBYTE *argsType, int& numIntArgs, int ppcArgsType[typeOffset] = ppcENDARG; } -static asQWORD CallCDeclFunction(const asDWORD* pArgs, const asBYTE *pArgsType, int argSize, asDWORD func, void *retInMemory) +static asQWORD CallCDeclFunction(const asDWORD *pArgs, const asBYTE *pArgsType, int argSize, asDWORD func, void *retInMemory) { int baseArgCount = 0; if( retInMemory ) @@ -402,8 +403,8 @@ static asQWORD CallCDeclFunction(const asDWORD* pArgs, const asBYTE *pArgsType, if( argSize > 0 ) { int intArgs = baseArgCount, floatArgs = 0, doubleArgs = 0; - stackArgs( pArgs, pArgsType, intArgs, floatArgs, doubleArgs ); - numTotalArgs = intArgs + floatArgs + 2*doubleArgs; // doubles occupy two slots + stackArgs(pArgs, pArgsType, intArgs, floatArgs, doubleArgs); + numTotalArgs = intArgs + floatArgs + 2 * doubleArgs; // doubles occupy two slots } else { @@ -412,12 +413,12 @@ static asQWORD CallCDeclFunction(const asDWORD* pArgs, const asBYTE *pArgsType, } // call the function with the arguments - return ppcFunc( ppcArgs, PPC_STACK_SIZE(numTotalArgs), func ); + return ppcFunc(ppcArgs, PPC_STACK_SIZE(numTotalArgs), func); } // This function is identical to CallCDeclFunction, with the only difference that // the value in the first parameter is the object (unless we are returning in memory) -static asQWORD CallThisCallFunction(const void *obj, const asDWORD* pArgs, const asBYTE *pArgsType, int argSize, asDWORD func, void *retInMemory ) +static asQWORD CallThisCallFunction(const void *obj, const asDWORD *pArgs, const asBYTE *pArgsType, int argSize, asDWORD func, void *retInMemory) { int baseArgCount = 0; if( retInMemory ) @@ -426,7 +427,7 @@ static asQWORD CallThisCallFunction(const void *obj, const asDWORD* pArgs, const ppcArgs[0] = (asDWORD)retInMemory; ppcArgsType[0] = ppcINTARG; ppcArgsType[1] = ppcENDARG; - baseArgCount = 1; + baseArgCount = 1; } // the first argument is the 'this' of the object @@ -439,18 +440,18 @@ static asQWORD CallThisCallFunction(const void *obj, const asDWORD* pArgs, const if( argSize > 0 ) { int intArgs = baseArgCount, floatArgs = 0, doubleArgs = 0; - stackArgs( pArgs, pArgsType, intArgs, floatArgs, doubleArgs ); - numTotalArgs = intArgs + floatArgs + 2*doubleArgs; // doubles occupy two slots + stackArgs(pArgs, pArgsType, intArgs, floatArgs, doubleArgs); + numTotalArgs = intArgs + floatArgs + 2 * doubleArgs; // doubles occupy two slots } // call the function with the arguments - return ppcFunc( ppcArgs, PPC_STACK_SIZE(numTotalArgs), func); + return ppcFunc(ppcArgs, PPC_STACK_SIZE(numTotalArgs), func); } // This function is identical to CallCDeclFunction, with the only difference that -// the value in the last parameter is the object +// the value in the last parameter is the object // NOTE: on PPC the order for the args is reversed -static asQWORD CallThisCallFunction_objLast(const void *obj, const asDWORD* pArgs, const asBYTE *pArgsType, int argSize, asDWORD func, void *retInMemory) +static asQWORD CallThisCallFunction_objLast(const void *obj, const asDWORD *pArgs, const asBYTE *pArgsType, int argSize, asDWORD func, void *retInMemory) { UNUSED_VAR(argSize); int baseArgCount = 0; @@ -460,43 +461,43 @@ static asQWORD CallThisCallFunction_objLast(const void *obj, const asDWORD* pArg ppcArgs[0] = (asDWORD)retInMemory; ppcArgsType[0] = ppcINTARG; ppcArgsType[1] = ppcENDARG; - baseArgCount = 1; + baseArgCount = 1; } // stack any of the arguments int intArgs = baseArgCount, floatArgs = 0, doubleArgs = 0; - stackArgs( pArgs, pArgsType, intArgs, floatArgs, doubleArgs ); + stackArgs(pArgs, pArgsType, intArgs, floatArgs, doubleArgs); int numTotalArgs = intArgs + floatArgs + doubleArgs; // can we fit the object in at the end? if( numTotalArgs < AS_PPC_MAX_ARGS ) { // put the object pointer at the end - int argPos = intArgs + floatArgs + (doubleArgs * 2); + int argPos = intArgs + floatArgs + (doubleArgs * 2); ppcArgs[argPos] = (asDWORD)obj; ppcArgsType[numTotalArgs++] = ppcINTARG; ppcArgsType[numTotalArgs] = ppcENDARG; } // call the function with the arguments - return ppcFunc( ppcArgs, PPC_STACK_SIZE(numTotalArgs), func ); + return ppcFunc(ppcArgs, PPC_STACK_SIZE(numTotalArgs), func); } -asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &/*retQW2*/, void */*secondObject*/) +asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD & /*retQW2*/, void * /*secondObject*/) { // TODO: PPC does not yet support THISCALL_OBJFIRST/LAST // use a working array of types, we'll configure the final one in stackArgs - asBYTE argsType[2*AS_PPC_MAX_ARGS + 1 + 1 + 1]; - memset( argsType, 0, sizeof(argsType)); + asBYTE argsType[2 * AS_PPC_MAX_ARGS + 1 + 1 + 1]; + memset(argsType, 0, sizeof(argsType)); asCScriptEngine *engine = context->m_engine; asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; - asQWORD retQW = 0; - void *func = (void*)sysFunc->func; - int paramSize = sysFunc->paramSize; - asDWORD *vftable = NULL; + asQWORD retQW = 0; + void *func = (void *)sysFunc->func; + int paramSize = sysFunc->paramSize; + asDWORD *vftable = NULL; int a, s; // convert the parameters that are < 4 bytes from little endian to big endian @@ -514,23 +515,23 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, asASSERT( numBytes == 1 || numBytes == 2 ); switch( numBytes ) { - case 1: + case 1: { - volatile asBYTE *bPtr = (asBYTE*)ARG_DW(args[argDwordOffset]); - asBYTE t = bPtr[0]; - bPtr[0] = bPtr[3]; - bPtr[3] = t; - t = bPtr[1]; - bPtr[1] = bPtr[2]; - bPtr[2] = t; + volatile asBYTE *bPtr = (asBYTE *)ARG_DW(args[argDwordOffset]); + asBYTE t = bPtr[0]; + bPtr[0] = bPtr[3]; + bPtr[3] = t; + t = bPtr[1]; + bPtr[1] = bPtr[2]; + bPtr[2] = t; } break; - case 2: + case 2: { - volatile asWORD *wPtr = (asWORD*)ARG_DW(args[argDwordOffset]); - asWORD t = wPtr[0]; - wPtr[0] = wPtr[1]; - wPtr[1] = t; + volatile asWORD *wPtr = (asWORD *)ARG_DW(args[argDwordOffset]); + asWORD t = wPtr[0]; + wPtr[0] = wPtr[1]; + wPtr[1] = t; } break; } @@ -567,35 +568,35 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, if( sysFunc->takesObjByVal ) { paramSize = 0; - int spos = 0; - int dpos = 1; + int spos = 0; + int dpos = 1; - int a = 0; + int a = 0; for( asUINT n = 0; n < descr->parameterTypes.GetLength(); n++ ) { if( descr->parameterTypes[n].IsObject() && !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() ) { -#ifdef COMPLEX_OBJS_PASSED_BY_REF + #ifdef COMPLEX_OBJS_PASSED_BY_REF if( descr->parameterTypes[n].GetTypeInfo()->flags & COMPLEX_MASK ) { - argsType[a++] = ppcINTARG; + argsType[a++] = ppcINTARG; paramBuffer[dpos++] = args[spos++]; paramSize++; } else -#endif + #endif { // TODO: Probably have to handle asOBJ_APP_FLOAT as a primitive // Copy the object's memory to the buffer - memcpy( ¶mBuffer[dpos], *(void**)(args+spos), descr->parameterTypes[n].GetSizeInMemoryBytes() ); + memcpy(¶mBuffer[dpos], *(void **)(args + spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); // Delete the original memory - engine->CallFree(*(char**)(args+spos) ); + engine->CallFree(*(char **)(args + spos)); spos++; - asUINT dwords = descr->parameterTypes[n].GetSizeInMemoryDWords(); - dpos += dwords; - paramSize += dwords; + asUINT dwords = descr->parameterTypes[n].GetSizeInMemoryDWords(); + dpos += dwords; + paramSize += dwords; for( asUINT i = 0; i < dwords; i++ ) argsType[a++] = ppcINTARG; } @@ -623,43 +624,43 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // Keep a free location at the beginning args = ¶mBuffer[1]; } - + int callConv = sysFunc->callConv; switch( callConv ) { - case ICC_CDECL: - case ICC_CDECL_RETURNINMEM: - case ICC_STDCALL: - case ICC_STDCALL_RETURNINMEM: - retQW = CallCDeclFunction( args, argsType, paramSize, (asDWORD)func, retPointer ); - break; - case ICC_THISCALL: - case ICC_THISCALL_RETURNINMEM: - retQW = CallThisCallFunction(obj, args, argsType, paramSize, (asDWORD)func, retPointer ); - break; - case ICC_VIRTUAL_THISCALL: - case ICC_VIRTUAL_THISCALL_RETURNINMEM: - // Get virtual function table from the object pointer - vftable = *(asDWORD**)obj; - retQW = CallThisCallFunction( obj, args, argsType, paramSize, vftable[asDWORD(func)>>2], retPointer ); - break; - case ICC_CDECL_OBJLAST: - case ICC_CDECL_OBJLAST_RETURNINMEM: - retQW = CallThisCallFunction_objLast( obj, args, argsType, paramSize, (asDWORD)func, retPointer ); - break; - case ICC_CDECL_OBJFIRST: - case ICC_CDECL_OBJFIRST_RETURNINMEM: - retQW = CallThisCallFunction( obj, args, argsType, paramSize, (asDWORD)func, retPointer ); - break; - default: - context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); + case ICC_CDECL: + case ICC_CDECL_RETURNINMEM: + case ICC_STDCALL: + case ICC_STDCALL_RETURNINMEM: + retQW = CallCDeclFunction(args, argsType, paramSize, (asDWORD)func, retPointer); + break; + case ICC_THISCALL: + case ICC_THISCALL_RETURNINMEM: + retQW = CallThisCallFunction(obj, args, argsType, paramSize, (asDWORD)func, retPointer); + break; + case ICC_VIRTUAL_THISCALL: + case ICC_VIRTUAL_THISCALL_RETURNINMEM: + // Get virtual function table from the object pointer + vftable = *(asDWORD **)obj; + retQW = CallThisCallFunction(obj, args, argsType, paramSize, vftable[asDWORD(func) >> 2], retPointer); + break; + case ICC_CDECL_OBJLAST: + case ICC_CDECL_OBJLAST_RETURNINMEM: + retQW = CallThisCallFunction_objLast(obj, args, argsType, paramSize, (asDWORD)func, retPointer); + break; + case ICC_CDECL_OBJFIRST: + case ICC_CDECL_OBJFIRST_RETURNINMEM: + retQW = CallThisCallFunction(obj, args, argsType, paramSize, (asDWORD)func, retPointer); + break; + default: + context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); } // If the return is a float value we need to get the value from the FP register if( sysFunc->hostReturnFloat ) { if( sysFunc->hostReturnSize == 1 ) - *(asDWORD*)&retQW = GetReturnedFloat(); + *(asDWORD *)&retQW = GetReturnedFloat(); else retQW = GetReturnedDouble(); } @@ -669,6 +670,5 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, END_AS_NAMESPACE -#endif // AS_PPC -#endif // AS_MAX_PORTABILITY - + #endif // AS_PPC +#endif // AS_MAX_PORTABILITY diff --git a/sdk/angelscript/source/as_callfunc_ppc_64.cpp b/sdk/angelscript/source/as_callfunc_ppc_64.cpp index 275f6152..55c1c42d 100644 --- a/sdk/angelscript/source/as_callfunc_ppc_64.cpp +++ b/sdk/angelscript/source/as_callfunc_ppc_64.cpp @@ -40,37 +40,37 @@ #include "as_config.h" #ifndef AS_MAX_PORTABILITY -#ifdef AS_PPC_64 -#if AS_PTR_SIZE == 2 -// TODO: Add support for PPC 64bit platforms with 64bit pointers, for example Linux PPC64 (big endian) and PPC64 (little endian) -#error This code has not been prepared for PPC with 64bit pointers. Most likely the ABI is different -#else + #ifdef AS_PPC_64 + #if AS_PTR_SIZE == 2 + // TODO: Add support for PPC 64bit platforms with 64bit pointers, for example Linux PPC64 (big endian) and PPC64 (little endian) + #error This code has not been prepared for PPC with 64bit pointers. Most likely the ABI is different + #else -#include "as_callfunc.h" -#include "as_scriptengine.h" -#include "as_texts.h" -#include "as_tokendef.h" -#include "as_context.h" + #include "as_callfunc.h" + #include "as_scriptengine.h" + #include "as_texts.h" + #include "as_tokendef.h" + #include "as_context.h" -#include -#include + #include + #include -#ifdef __SNC__ -#include "ppu_asm_intrinsics.h" -#endif + #ifdef __SNC__ + #include "ppu_asm_intrinsics.h" + #endif BEGIN_AS_NAMESPACE -// This part was written and tested by Jeff Slutter -// from Reactor Zero, Abril, 2007, for PlayStation 3, which -// is a PowerPC 64bit based architecture. Even though it is -// 64bit it seems the pointer size is still 32bit. + // This part was written and tested by Jeff Slutter + // from Reactor Zero, Abril, 2007, for PlayStation 3, which + // is a PowerPC 64bit based architecture. Even though it is + // 64bit it seems the pointer size is still 32bit. -// It still remains to be seen how well this code works -// on other PPC platforms, such as XBox 360, GameCube. + // It still remains to be seen how well this code works + // on other PPC platforms, such as XBox 360, GameCube. -#define AS_PPC_MAX_ARGS 32 + #define AS_PPC_MAX_ARGS 32 // The array used to send values to the correct places. // Contains a byte of argTypes to indicate the register type to load @@ -81,321 +81,324 @@ BEGIN_AS_NAMESPACE // TODO: multithread: The global variables must be removed to make the code thread safe -extern "C" -{ - enum argTypes { ppcENDARG = 0, ppcINTARG = 1, ppcFLOATARG = 2, ppcDOUBLEARG = 3, ppcLONGARG = 4 }; - static asBYTE ppcArgsType[AS_PPC_MAX_ARGS + 1 + 1 + 1]; - static asDWORD ppcArgs[2*AS_PPC_MAX_ARGS + 1 + 1]; +extern "C" { +enum argTypes { ppcENDARG = 0, + ppcINTARG = 1, + ppcFLOATARG = 2, + ppcDOUBLEARG = 3, + ppcLONGARG = 4 }; +static asBYTE ppcArgsType[AS_PPC_MAX_ARGS + 1 + 1 + 1]; +static asDWORD ppcArgs[2 * AS_PPC_MAX_ARGS + 1 + 1]; } -// NOTE: these values are for PowerPC 64 bit. I'm sure things are different for PowerPC 32bit, but I don't have one. -// I'm pretty sure that PPC 32bit sets up a stack frame slightly different (only 24 bytes for linkage area for instance) -#define PPC_LINKAGE_SIZE (0x30) // how big the PPC linkage area is in a stack frame -#define PPC_NUM_REGSTORE (10) // how many registers of the PPC we need to store/restore for ppcFunc64() -#define PPC_REGSTORE_SIZE (8*PPC_NUM_REGSTORE) // how many bytes are required for register store/restore -#define EXTRA_STACK_SIZE (PPC_LINKAGE_SIZE + PPC_REGSTORE_SIZE) // memory required, not including parameters, for the stack frame -#define PPC_STACK_SIZE(numParams) ( -(( ( (((numParams)<8)?8:(numParams))<<3) + EXTRA_STACK_SIZE + 15 ) & ~15) ) // calculates the total stack size needed for ppcFunc64, must pad to 16bytes + // NOTE: these values are for PowerPC 64 bit. I'm sure things are different for PowerPC 32bit, but I don't have one. + // I'm pretty sure that PPC 32bit sets up a stack frame slightly different (only 24 bytes for linkage area for instance) + #define PPC_LINKAGE_SIZE (0x30) // how big the PPC linkage area is in a stack frame + #define PPC_NUM_REGSTORE (10) // how many registers of the PPC we need to store/restore for ppcFunc64() + #define PPC_REGSTORE_SIZE (8 * PPC_NUM_REGSTORE) // how many bytes are required for register store/restore + #define EXTRA_STACK_SIZE (PPC_LINKAGE_SIZE + PPC_REGSTORE_SIZE) // memory required, not including parameters, for the stack frame + #define PPC_STACK_SIZE(numParams) (-((((((numParams) < 8) ? 8 : (numParams)) << 3) + EXTRA_STACK_SIZE + 15) & ~15)) // calculates the total stack size needed for ppcFunc64, must pad to 16bytes // This is PowerPC 64 bit specific // Loads all data into the correct places and calls the function. // ppcArgsType is an array containing a byte type (enum argTypes) for each argument. // StackArgSizeInBytes is the size in bytes of the stack frame (takes into account linkage area, etc. must be multiple of 16) -extern "C" asQWORD ppcFunc64(const asDWORD* argsPtr, int StackArgSizeInBytes, asDWORD func); +extern "C" asQWORD ppcFunc64(const asDWORD *argsPtr, int StackArgSizeInBytes, asDWORD func); asm("" - ".text\n" - ".align 4\n" - ".p2align 4,,15\n" - ".globl .ppcFunc64\n" - ".ppcFunc64:\n" - - // function prolog - "std %r22, -0x08(%r1)\n" // we need a register other than r0, to store the old stack pointer - "mr %r22, %r1\n" // store the old stack pointer, for now (to make storing registers easier) - "stdux %r1, %r1, %r4\n" // atomically store and update the stack pointer for the new stack frame (in case of a signal/interrupt) - "mflr %r0\n" // get the caller's LR register - "std %r0, 0x10(%r22)\n" // store the caller's LR register - "std %r23, -0x10(%r22)\n" // - "std %r24, -0x18(%r22)\n" // - "std %r25, -0x20(%r22)\n" // - "std %r26, -0x28(%r22)\n" // - "std %r27, -0x30(%r22)\n" // - "std %r28, -0x38(%r22)\n" // - "std %r29, -0x40(%r22)\n" // - "std %r30, -0x48(%r22)\n" // - "std %r31, -0x50(%r22)\n" // - "std %r3, 0x30(%r22)\n" // save our parameters - "std %r4, 0x38(%r22)\n" // - "std %r5, 0x40(%r22)\n" // - "mr %r31, %r1\n" // functions tend to store the stack pointer here too - - // initial registers for the function - "mr %r29, %r3\n" // (r29) args list - "lwz %r27, 0(%r5)\n" // load the function pointer to call. func actually holds the pointer to our function - "addi %r26, %r1, 0x30\n" // setup the pointer to the parameter area to the function we're going to call - "sub %r0,%r0,%r0\n" // zero out r0 - "mr %r23,%r0\n" // zero out r23, which holds the number of used GPR registers - "mr %r22,%r0\n" // zero our r22, which holds the number of used float registers - - // load the global ppcArgsType which holds the types of arguments for each argument - "lis %r25, ppcArgsType@ha\n" // load the upper 16 bits of the address to r25 - "addi %r25, %r25, ppcArgsType@l\n" // load the lower 16 bits of the address to r25 - "subi %r25, %r25, 1\n" // since we increment r25 on its use, we'll pre-decrement it - - // loop through the arguments - "ppcNextArg:\n" - "addi %r25, %r25, 1\n" // increment r25, our arg type pointer - // switch based on the current argument type (0:end, 1:int, 2:float 3:double) - "lbz %r24, 0(%r25)\n" // load the current argument type (it's a byte) - "mulli %r24, %r24, 4\n" // our jump table has 4 bytes per case (1 instruction) - "lis %r30, ppcTypeSwitch@ha\n" // load the address of the jump table for the switch - "addi %r30, %r30, ppcTypeSwitch@l\n" - "add %r0, %r30, %r24\n" // offset by our argument type - "mtctr %r0\n" // load the jump address into CTR - "bctr\n" // jump into the jump table/switch - "nop\n" - // the jump table/switch based on the current argument type - "ppcTypeSwitch:\n" - "b ppcArgsEnd\n" - "b ppcArgIsInteger\n" - "b ppcArgIsFloat\n" - "b ppcArgIsDouble\n" - "b ppcArgIsLong\n" - - // when we get here we have finished processing all the arguments - // everything is ready to go to call the function - "ppcArgsEnd:\n" - "mtctr %r27\n" // the function pointer is stored in r27, load that into CTR - "bctrl\n" // call the function. We have to do it this way so that the LR gets the proper - "nop\n" // return value (the next instruction below). So we have to branch from CTR instead of LR. - // when we get here, the function has returned, this is the function epilog - "ld %r11,0x00(%r1)\n" // load in the caller's stack pointer - "ld %r0,0x10(%r11)\n" // load in the caller's LR - "mtlr %r0\n" // restore the caller's LR - "ld %r22, -0x08(%r11)\n" // load registers - "ld %r23, -0x10(%r11)\n" // - "ld %r24, -0x18(%r11)\n" // - "ld %r25, -0x20(%r11)\n" // - "ld %r26, -0x28(%r11)\n" // - "ld %r27, -0x30(%r11)\n" // - "ld %r28, -0x38(%r11)\n" // - "ld %r29, -0x40(%r11)\n" // - "ld %r30, -0x48(%r11)\n" // - "ld %r31, -0x50(%r11)\n" // - "mr %r1, %r11\n" // restore the caller's SP - "blr\n" // return back to the caller - "nop\n" - // Integer argument (GPR register) - "ppcArgIsInteger:\n" - "lis %r30,ppcLoadIntReg@ha\n" // load the address to the jump table for integer registers - "addi %r30, %r30, ppcLoadIntReg@l\n" - "mulli %r0, %r23, 8\n" // each item in the jump table is 2 instructions (8 bytes) - "add %r0, %r0, %r30\n" // calculate ppcLoadIntReg[numUsedGPRRegs] - "lwz %r30,0(%r29)\n" // load the next argument from the argument list into r30 - "cmpwi %r23, 8\n" // we can only load GPR3 through GPR10 (8 registers) - "bgt ppcLoadIntRegUpd\n" // if we're beyond 8 GPR registers, we're in the stack, go there - "mtctr %r0\n" // load the address of our ppcLoadIntReg jump table (we're below 8 GPR registers) - "bctr\n" // load the argument into a GPR register - "nop\n" - // jump table for GPR registers, for the first 8 GPR arguments - "ppcLoadIntReg:\n" - "mr %r3,%r30\n" // arg0 (to r3) - "b ppcLoadIntRegUpd\n" - "mr %r4,%r30\n" // arg1 (to r4) - "b ppcLoadIntRegUpd\n" - "mr %r5,%r30\n" // arg2 (to r5) - "b ppcLoadIntRegUpd\n" - "mr %r6,%r30\n" // arg3 (to r6) - "b ppcLoadIntRegUpd\n" - "mr %r7,%r30\n" // arg4 (to r7) - "b ppcLoadIntRegUpd\n" - "mr %r8,%r30\n" // arg5 (to r8) - "b ppcLoadIntRegUpd\n" - "mr %r9,%r30\n" // arg6 (to r9) - "b ppcLoadIntRegUpd\n" - "mr %r10,%r30\n" // arg7 (to r10) - "b ppcLoadIntRegUpd\n" - - // all GPR arguments still go on the stack - "ppcLoadIntRegUpd:\n" - "std %r30,0(%r26)\n" // store the argument into the next slot on the stack's argument list - "addi %r23, %r23, 1\n" // count a used GPR register - "addi %r29, %r29, 4\n" // move to the next argument on the list - "addi %r26, %r26, 8\n" // adjust our argument stack pointer for the next - "b ppcNextArg\n" // next argument - - // single Float argument - "ppcArgIsFloat:\n" - "lis %r30,ppcLoadFloatReg@ha\n" // get the base address of the float register jump table - "addi %r30, %r30, ppcLoadFloatReg@l\n" - "mulli %r0, %r22 ,8\n" // each jump table entry is 8 bytes - "add %r0, %r0, %r30\n" // calculate the offset to ppcLoadFloatReg[numUsedFloatReg] - "lfs 0, 0(%r29)\n" // load the next argument as a float into f0 - "cmpwi %r22, 13\n" // can't load more than 13 float/double registers - "bgt ppcLoadFloatRegUpd\n" // if we're beyond 13 registers, just fall to inserting into the stack - "mtctr %r0\n" // jump into the float jump table - "bctr\n" - "nop\n" - // jump table for float registers, for the first 13 float arguments - "ppcLoadFloatReg:\n" - "fmr 1,0\n" // arg0 (f1) - "b ppcLoadFloatRegUpd\n" - "fmr 2,0\n" // arg1 (f2) - "b ppcLoadFloatRegUpd\n" - "fmr 3,0\n" // arg2 (f3) - "b ppcLoadFloatRegUpd\n" - "fmr 4,0\n" // arg3 (f4) - "b ppcLoadFloatRegUpd\n" - "fmr 5,0\n" // arg4 (f5) - "b ppcLoadFloatRegUpd\n" - "fmr 6,0\n" // arg5 (f6) - "b ppcLoadFloatRegUpd\n" - "fmr 7,0\n" // arg6 (f7) - "b ppcLoadFloatRegUpd\n" - "fmr 8,0\n" // arg7 (f8) - "b ppcLoadFloatRegUpd\n" - "fmr 9,0\n" // arg8 (f9) - "b ppcLoadFloatRegUpd\n" - "fmr 10,0\n" // arg9 (f10) - "b ppcLoadFloatRegUpd\n" - "fmr 11,0\n" // arg10 (f11) - "b ppcLoadFloatRegUpd\n" - "fmr 12,0\n" // arg11 (f12) - "b ppcLoadFloatRegUpd\n" - "fmr 13,0\n" // arg12 (f13) - "b ppcLoadFloatRegUpd\n" - "nop\n" - // all float arguments still go on the stack - "ppcLoadFloatRegUpd:\n" - "stfs 0, 0x04(%r26)\n" // store, as a single float, f0 (current argument) on to the stack argument list - "addi %r23, %r23, 1\n" // a float register eats up a GPR register - "addi %r22, %r22, 1\n" // ...and, of course, a float register - "addi %r29, %r29, 4\n" // move to the next argument in the list - "addi %r26, %r26, 8\n" // move to the next stack slot - "b ppcNextArg\n" // on to the next argument - "nop\n" - // double Float argument - "ppcArgIsDouble:\n" - "lis %r30, ppcLoadDoubleReg@ha\n" // load the base address of the jump table for double registers - "addi %r30, %r30, ppcLoadDoubleReg@l\n" - "mulli %r0, %r22, 8\n" // each slot of the jump table is 8 bytes - "add %r0, %r0, %r30\n" // calculate ppcLoadDoubleReg[numUsedFloatReg] - "lfd 0, 0(%r29)\n" // load the next argument, as a double float, into f0 - "cmpwi %r22,13\n" // the first 13 floats must go into float registers also - "bgt ppcLoadDoubleRegUpd\n" // if we're beyond 13, then just put on to the stack - "mtctr %r0\n" // we're under 13, first load our register - "bctr\n" // jump into the jump table - "nop\n" - // jump table for float registers, for the first 13 float arguments - "ppcLoadDoubleReg:\n" - "fmr 1,0\n" // arg0 (f1) - "b ppcLoadDoubleRegUpd\n" - "fmr 2,0\n" // arg1 (f2) - "b ppcLoadDoubleRegUpd\n" - "fmr 3,0\n" // arg2 (f3) - "b ppcLoadDoubleRegUpd\n" - "fmr 4,0\n" // arg3 (f4) - "b ppcLoadDoubleRegUpd\n" - "fmr 5,0\n" // arg4 (f5) - "b ppcLoadDoubleRegUpd\n" - "fmr 6,0\n" // arg5 (f6) - "b ppcLoadDoubleRegUpd\n" - "fmr 7,0\n" // arg6 (f7) - "b ppcLoadDoubleRegUpd\n" - "fmr 8,0\n" // arg7 (f8) - "b ppcLoadDoubleRegUpd\n" - "fmr 9,0\n" // arg8 (f9) - "b ppcLoadDoubleRegUpd\n" - "fmr 10,0\n" // arg9 (f10) - "b ppcLoadDoubleRegUpd\n" - "fmr 11,0\n" // arg10 (f11) - "b ppcLoadDoubleRegUpd\n" - "fmr 12,0\n" // arg11 (f12) - "b ppcLoadDoubleRegUpd\n" - "fmr 13,0\n" // arg12 (f13) - "b ppcLoadDoubleRegUpd\n" - "nop\n" - // all float arguments still go on the stack - "ppcLoadDoubleRegUpd:\n" - "stfd 0,0(%r26)\n" // store f0, as a double, into the argument list on the stack - "addi %r23, %r23, 1\n" // a double float eats up one GPR - "addi %r22, %r22, 1\n" // ...and, of course, a float - "addi %r29, %r29, 8\n" // increment to our next argument we need to process (8 bytes for the 64bit float) - "addi %r26, %r26, 8\n" // increment to the next slot on the argument list on the stack (8 bytes) - "b ppcNextArg\n" // on to the next argument - "nop\n" - - // Long (64 bit int) argument - "ppcArgIsLong:\n" - "lis %r30,ppcLoadLongReg@ha\n" // load the address to the jump table for integer64 - "addi %r30, %r30, ppcLoadLongReg@l\n" - "mulli %r0, %r23, 8\n" // each item in the jump table is 2 instructions (8 bytes) - "add %r0, %r0, %r30\n" // calculate ppcLoadLongReg[numUsedGPRRegs] - "ld %r30,0(%r29)\n" // load the next argument from the argument list into r30 - "cmpwi %r23, 8\n" // we can only load GPR3 through GPR10 (8 registers) - "bgt ppcLoadLongRegUpd\n" // if we're beyond 8 GPR registers, we're in the stack, go there - "mtctr %r0\n" // load the address of our ppcLoadLongReg jump table (we're below 8 GPR registers) - "bctr\n" // load the argument into a GPR register - "nop\n" - // jump table for GPR registers, for the first 8 GPR arguments - "ppcLoadLongReg:\n" - "mr %r3,%r30\n" // arg0 (to r3) - "b ppcLoadLongRegUpd\n" - "mr %r4,%r30\n" // arg1 (to r4) - "b ppcLoadLongRegUpd\n" - "mr %r5,%r30\n" // arg2 (to r5) - "b ppcLoadLongRegUpd\n" - "mr %r6,%r30\n" // arg3 (to r6) - "b ppcLoadLongRegUpd\n" - "mr %r7,%r30\n" // arg4 (to r7) - "b ppcLoadLongRegUpd\n" - "mr %r8,%r30\n" // arg5 (to r8) - "b ppcLoadLongRegUpd\n" - "mr %r9,%r30\n" // arg6 (to r9) - "b ppcLoadLongRegUpd\n" - "mr %r10,%r30\n" // arg7 (to r10) - "b ppcLoadLongRegUpd\n" - - // all GPR arguments still go on the stack - "ppcLoadLongRegUpd:\n" - "std %r30,0(%r26)\n" // store the argument into the next slot on the stack's argument list - "addi %r23, %r23, 1\n" // count a used GPR register - "addi %r29, %r29, 8\n" // move to the next argument on the list - "addi %r26, %r26, 8\n" // adjust our argument stack pointer for the next - "b ppcNextArg\n" // next argument + ".text\n" + ".align 4\n" + ".p2align 4,,15\n" + ".globl .ppcFunc64\n" + ".ppcFunc64:\n" + + // function prolog + "std %r22, -0x08(%r1)\n" // we need a register other than r0, to store the old stack pointer + "mr %r22, %r1\n" // store the old stack pointer, for now (to make storing registers easier) + "stdux %r1, %r1, %r4\n" // atomically store and update the stack pointer for the new stack frame (in case of a signal/interrupt) + "mflr %r0\n" // get the caller's LR register + "std %r0, 0x10(%r22)\n" // store the caller's LR register + "std %r23, -0x10(%r22)\n" // + "std %r24, -0x18(%r22)\n" // + "std %r25, -0x20(%r22)\n" // + "std %r26, -0x28(%r22)\n" // + "std %r27, -0x30(%r22)\n" // + "std %r28, -0x38(%r22)\n" // + "std %r29, -0x40(%r22)\n" // + "std %r30, -0x48(%r22)\n" // + "std %r31, -0x50(%r22)\n" // + "std %r3, 0x30(%r22)\n" // save our parameters + "std %r4, 0x38(%r22)\n" // + "std %r5, 0x40(%r22)\n" // + "mr %r31, %r1\n" // functions tend to store the stack pointer here too + + // initial registers for the function + "mr %r29, %r3\n" // (r29) args list + "lwz %r27, 0(%r5)\n" // load the function pointer to call. func actually holds the pointer to our function + "addi %r26, %r1, 0x30\n" // setup the pointer to the parameter area to the function we're going to call + "sub %r0,%r0,%r0\n" // zero out r0 + "mr %r23,%r0\n" // zero out r23, which holds the number of used GPR registers + "mr %r22,%r0\n" // zero our r22, which holds the number of used float registers + + // load the global ppcArgsType which holds the types of arguments for each argument + "lis %r25, ppcArgsType@ha\n" // load the upper 16 bits of the address to r25 + "addi %r25, %r25, ppcArgsType@l\n" // load the lower 16 bits of the address to r25 + "subi %r25, %r25, 1\n" // since we increment r25 on its use, we'll pre-decrement it + + // loop through the arguments + "ppcNextArg:\n" + "addi %r25, %r25, 1\n" // increment r25, our arg type pointer + // switch based on the current argument type (0:end, 1:int, 2:float 3:double) + "lbz %r24, 0(%r25)\n" // load the current argument type (it's a byte) + "mulli %r24, %r24, 4\n" // our jump table has 4 bytes per case (1 instruction) + "lis %r30, ppcTypeSwitch@ha\n" // load the address of the jump table for the switch + "addi %r30, %r30, ppcTypeSwitch@l\n" + "add %r0, %r30, %r24\n" // offset by our argument type + "mtctr %r0\n" // load the jump address into CTR + "bctr\n" // jump into the jump table/switch + "nop\n" + // the jump table/switch based on the current argument type + "ppcTypeSwitch:\n" + "b ppcArgsEnd\n" + "b ppcArgIsInteger\n" + "b ppcArgIsFloat\n" + "b ppcArgIsDouble\n" + "b ppcArgIsLong\n" + + // when we get here we have finished processing all the arguments + // everything is ready to go to call the function + "ppcArgsEnd:\n" + "mtctr %r27\n" // the function pointer is stored in r27, load that into CTR + "bctrl\n" // call the function. We have to do it this way so that the LR gets the proper + "nop\n" // return value (the next instruction below). So we have to branch from CTR instead of LR. + // when we get here, the function has returned, this is the function epilog + "ld %r11,0x00(%r1)\n" // load in the caller's stack pointer + "ld %r0,0x10(%r11)\n" // load in the caller's LR + "mtlr %r0\n" // restore the caller's LR + "ld %r22, -0x08(%r11)\n" // load registers + "ld %r23, -0x10(%r11)\n" // + "ld %r24, -0x18(%r11)\n" // + "ld %r25, -0x20(%r11)\n" // + "ld %r26, -0x28(%r11)\n" // + "ld %r27, -0x30(%r11)\n" // + "ld %r28, -0x38(%r11)\n" // + "ld %r29, -0x40(%r11)\n" // + "ld %r30, -0x48(%r11)\n" // + "ld %r31, -0x50(%r11)\n" // + "mr %r1, %r11\n" // restore the caller's SP + "blr\n" // return back to the caller + "nop\n" + // Integer argument (GPR register) + "ppcArgIsInteger:\n" + "lis %r30,ppcLoadIntReg@ha\n" // load the address to the jump table for integer registers + "addi %r30, %r30, ppcLoadIntReg@l\n" + "mulli %r0, %r23, 8\n" // each item in the jump table is 2 instructions (8 bytes) + "add %r0, %r0, %r30\n" // calculate ppcLoadIntReg[numUsedGPRRegs] + "lwz %r30,0(%r29)\n" // load the next argument from the argument list into r30 + "cmpwi %r23, 8\n" // we can only load GPR3 through GPR10 (8 registers) + "bgt ppcLoadIntRegUpd\n" // if we're beyond 8 GPR registers, we're in the stack, go there + "mtctr %r0\n" // load the address of our ppcLoadIntReg jump table (we're below 8 GPR registers) + "bctr\n" // load the argument into a GPR register + "nop\n" + // jump table for GPR registers, for the first 8 GPR arguments + "ppcLoadIntReg:\n" + "mr %r3,%r30\n" // arg0 (to r3) + "b ppcLoadIntRegUpd\n" + "mr %r4,%r30\n" // arg1 (to r4) + "b ppcLoadIntRegUpd\n" + "mr %r5,%r30\n" // arg2 (to r5) + "b ppcLoadIntRegUpd\n" + "mr %r6,%r30\n" // arg3 (to r6) + "b ppcLoadIntRegUpd\n" + "mr %r7,%r30\n" // arg4 (to r7) + "b ppcLoadIntRegUpd\n" + "mr %r8,%r30\n" // arg5 (to r8) + "b ppcLoadIntRegUpd\n" + "mr %r9,%r30\n" // arg6 (to r9) + "b ppcLoadIntRegUpd\n" + "mr %r10,%r30\n" // arg7 (to r10) + "b ppcLoadIntRegUpd\n" + + // all GPR arguments still go on the stack + "ppcLoadIntRegUpd:\n" + "std %r30,0(%r26)\n" // store the argument into the next slot on the stack's argument list + "addi %r23, %r23, 1\n" // count a used GPR register + "addi %r29, %r29, 4\n" // move to the next argument on the list + "addi %r26, %r26, 8\n" // adjust our argument stack pointer for the next + "b ppcNextArg\n" // next argument + + // single Float argument + "ppcArgIsFloat:\n" + "lis %r30,ppcLoadFloatReg@ha\n" // get the base address of the float register jump table + "addi %r30, %r30, ppcLoadFloatReg@l\n" + "mulli %r0, %r22 ,8\n" // each jump table entry is 8 bytes + "add %r0, %r0, %r30\n" // calculate the offset to ppcLoadFloatReg[numUsedFloatReg] + "lfs 0, 0(%r29)\n" // load the next argument as a float into f0 + "cmpwi %r22, 13\n" // can't load more than 13 float/double registers + "bgt ppcLoadFloatRegUpd\n" // if we're beyond 13 registers, just fall to inserting into the stack + "mtctr %r0\n" // jump into the float jump table + "bctr\n" + "nop\n" + // jump table for float registers, for the first 13 float arguments + "ppcLoadFloatReg:\n" + "fmr 1,0\n" // arg0 (f1) + "b ppcLoadFloatRegUpd\n" + "fmr 2,0\n" // arg1 (f2) + "b ppcLoadFloatRegUpd\n" + "fmr 3,0\n" // arg2 (f3) + "b ppcLoadFloatRegUpd\n" + "fmr 4,0\n" // arg3 (f4) + "b ppcLoadFloatRegUpd\n" + "fmr 5,0\n" // arg4 (f5) + "b ppcLoadFloatRegUpd\n" + "fmr 6,0\n" // arg5 (f6) + "b ppcLoadFloatRegUpd\n" + "fmr 7,0\n" // arg6 (f7) + "b ppcLoadFloatRegUpd\n" + "fmr 8,0\n" // arg7 (f8) + "b ppcLoadFloatRegUpd\n" + "fmr 9,0\n" // arg8 (f9) + "b ppcLoadFloatRegUpd\n" + "fmr 10,0\n" // arg9 (f10) + "b ppcLoadFloatRegUpd\n" + "fmr 11,0\n" // arg10 (f11) + "b ppcLoadFloatRegUpd\n" + "fmr 12,0\n" // arg11 (f12) + "b ppcLoadFloatRegUpd\n" + "fmr 13,0\n" // arg12 (f13) + "b ppcLoadFloatRegUpd\n" + "nop\n" + // all float arguments still go on the stack + "ppcLoadFloatRegUpd:\n" + "stfs 0, 0x04(%r26)\n" // store, as a single float, f0 (current argument) on to the stack argument list + "addi %r23, %r23, 1\n" // a float register eats up a GPR register + "addi %r22, %r22, 1\n" // ...and, of course, a float register + "addi %r29, %r29, 4\n" // move to the next argument in the list + "addi %r26, %r26, 8\n" // move to the next stack slot + "b ppcNextArg\n" // on to the next argument + "nop\n" + // double Float argument + "ppcArgIsDouble:\n" + "lis %r30, ppcLoadDoubleReg@ha\n" // load the base address of the jump table for double registers + "addi %r30, %r30, ppcLoadDoubleReg@l\n" + "mulli %r0, %r22, 8\n" // each slot of the jump table is 8 bytes + "add %r0, %r0, %r30\n" // calculate ppcLoadDoubleReg[numUsedFloatReg] + "lfd 0, 0(%r29)\n" // load the next argument, as a double float, into f0 + "cmpwi %r22,13\n" // the first 13 floats must go into float registers also + "bgt ppcLoadDoubleRegUpd\n" // if we're beyond 13, then just put on to the stack + "mtctr %r0\n" // we're under 13, first load our register + "bctr\n" // jump into the jump table + "nop\n" + // jump table for float registers, for the first 13 float arguments + "ppcLoadDoubleReg:\n" + "fmr 1,0\n" // arg0 (f1) + "b ppcLoadDoubleRegUpd\n" + "fmr 2,0\n" // arg1 (f2) + "b ppcLoadDoubleRegUpd\n" + "fmr 3,0\n" // arg2 (f3) + "b ppcLoadDoubleRegUpd\n" + "fmr 4,0\n" // arg3 (f4) + "b ppcLoadDoubleRegUpd\n" + "fmr 5,0\n" // arg4 (f5) + "b ppcLoadDoubleRegUpd\n" + "fmr 6,0\n" // arg5 (f6) + "b ppcLoadDoubleRegUpd\n" + "fmr 7,0\n" // arg6 (f7) + "b ppcLoadDoubleRegUpd\n" + "fmr 8,0\n" // arg7 (f8) + "b ppcLoadDoubleRegUpd\n" + "fmr 9,0\n" // arg8 (f9) + "b ppcLoadDoubleRegUpd\n" + "fmr 10,0\n" // arg9 (f10) + "b ppcLoadDoubleRegUpd\n" + "fmr 11,0\n" // arg10 (f11) + "b ppcLoadDoubleRegUpd\n" + "fmr 12,0\n" // arg11 (f12) + "b ppcLoadDoubleRegUpd\n" + "fmr 13,0\n" // arg12 (f13) + "b ppcLoadDoubleRegUpd\n" + "nop\n" + // all float arguments still go on the stack + "ppcLoadDoubleRegUpd:\n" + "stfd 0,0(%r26)\n" // store f0, as a double, into the argument list on the stack + "addi %r23, %r23, 1\n" // a double float eats up one GPR + "addi %r22, %r22, 1\n" // ...and, of course, a float + "addi %r29, %r29, 8\n" // increment to our next argument we need to process (8 bytes for the 64bit float) + "addi %r26, %r26, 8\n" // increment to the next slot on the argument list on the stack (8 bytes) + "b ppcNextArg\n" // on to the next argument + "nop\n" + + // Long (64 bit int) argument + "ppcArgIsLong:\n" + "lis %r30,ppcLoadLongReg@ha\n" // load the address to the jump table for integer64 + "addi %r30, %r30, ppcLoadLongReg@l\n" + "mulli %r0, %r23, 8\n" // each item in the jump table is 2 instructions (8 bytes) + "add %r0, %r0, %r30\n" // calculate ppcLoadLongReg[numUsedGPRRegs] + "ld %r30,0(%r29)\n" // load the next argument from the argument list into r30 + "cmpwi %r23, 8\n" // we can only load GPR3 through GPR10 (8 registers) + "bgt ppcLoadLongRegUpd\n" // if we're beyond 8 GPR registers, we're in the stack, go there + "mtctr %r0\n" // load the address of our ppcLoadLongReg jump table (we're below 8 GPR registers) + "bctr\n" // load the argument into a GPR register + "nop\n" + // jump table for GPR registers, for the first 8 GPR arguments + "ppcLoadLongReg:\n" + "mr %r3,%r30\n" // arg0 (to r3) + "b ppcLoadLongRegUpd\n" + "mr %r4,%r30\n" // arg1 (to r4) + "b ppcLoadLongRegUpd\n" + "mr %r5,%r30\n" // arg2 (to r5) + "b ppcLoadLongRegUpd\n" + "mr %r6,%r30\n" // arg3 (to r6) + "b ppcLoadLongRegUpd\n" + "mr %r7,%r30\n" // arg4 (to r7) + "b ppcLoadLongRegUpd\n" + "mr %r8,%r30\n" // arg5 (to r8) + "b ppcLoadLongRegUpd\n" + "mr %r9,%r30\n" // arg6 (to r9) + "b ppcLoadLongRegUpd\n" + "mr %r10,%r30\n" // arg7 (to r10) + "b ppcLoadLongRegUpd\n" + + // all GPR arguments still go on the stack + "ppcLoadLongRegUpd:\n" + "std %r30,0(%r26)\n" // store the argument into the next slot on the stack's argument list + "addi %r23, %r23, 1\n" // count a used GPR register + "addi %r29, %r29, 8\n" // move to the next argument on the list + "addi %r26, %r26, 8\n" // adjust our argument stack pointer for the next + "b ppcNextArg\n" // next argument ); static asDWORD GetReturnedFloat(void) { asDWORD f; -#ifdef __SNC__ - __stfs( __freg(1), 0, (void*)&f); -#else + #ifdef __SNC__ + __stfs(__freg(1), 0, (void *)&f); + #else asm(" stfs 1, %0\n" : "=m"(f)); -#endif + #endif return f; } static asQWORD GetReturnedDouble(void) { asQWORD f; -#ifdef __SNC__ - __stfd( __freg(1), 0, (void*)&f); -#else + #ifdef __SNC__ + __stfd(__freg(1), 0, (void *)&f); + #else asm(" stfd 1, %0\n" : "=m"(f)); -#endif + #endif return f; } // puts the arguments in the correct place in the stack array. See comments above. -static void stackArgs( const asDWORD *args, const asBYTE *argsType, int &numIntArgs, int &numFloatArgs, int &numDoubleArgs, int &numLongArgs ) +static void stackArgs(const asDWORD *args, const asBYTE *argsType, int &numIntArgs, int &numFloatArgs, int &numDoubleArgs, int &numLongArgs) { // initialize our offset based on any already placed arguments int i; - int argWordPos = numIntArgs + numFloatArgs + (numDoubleArgs*2) + (numLongArgs*2); + int argWordPos = numIntArgs + numFloatArgs + (numDoubleArgs * 2) + (numLongArgs * 2); int typeOffset = numIntArgs + numFloatArgs + numDoubleArgs + numLongArgs; int typeIndex; - for( i = 0, typeIndex = 0; ; i++, typeIndex++ ) + for( i = 0, typeIndex = 0;; i++, typeIndex++ ) { // store the type ppcArgsType[typeOffset++] = argsType[typeIndex]; @@ -404,7 +407,7 @@ static void stackArgs( const asDWORD *args, const asBYTE *argsType, int &numIntA switch( argsType[typeIndex] ) { - case ppcFLOATARG: + case ppcFLOATARG: { // stow float ppcArgs[argWordPos] = args[i]; // it's just a bit copy @@ -413,17 +416,17 @@ static void stackArgs( const asDWORD *args, const asBYTE *argsType, int &numIntA } break; - case ppcDOUBLEARG: + case ppcDOUBLEARG: { // stow double - memcpy( &ppcArgs[argWordPos], &args[i], sizeof(double) ); // we have to do this because of alignment + memcpy(&ppcArgs[argWordPos], &args[i], sizeof(double)); // we have to do this because of alignment numDoubleArgs++; - argWordPos+=2; //add two words - i++;//doubles take up 2 argument slots + argWordPos += 2; //add two words + i++; //doubles take up 2 argument slots } break; - case ppcINTARG: + case ppcINTARG: { // stow register ppcArgs[argWordPos] = args[i]; @@ -432,13 +435,13 @@ static void stackArgs( const asDWORD *args, const asBYTE *argsType, int &numIntA } break; - case ppcLONGARG: + case ppcLONGARG: { // stow long - memcpy( &ppcArgs[argWordPos], &args[i], 8 ); // for alignment purposes, we use memcpy + memcpy(&ppcArgs[argWordPos], &args[i], 8); // for alignment purposes, we use memcpy numLongArgs++; argWordPos += 2; // add two words - i++; // longs take up 2 argument slots + i++; // longs take up 2 argument slots } break; } @@ -448,7 +451,7 @@ static void stackArgs( const asDWORD *args, const asBYTE *argsType, int &numIntA ppcArgsType[typeOffset] = ppcENDARG; } -static asQWORD CallCDeclFunction(const asDWORD* pArgs, const asBYTE *pArgsType, int argSize, asDWORD func, void *retInMemory) +static asQWORD CallCDeclFunction(const asDWORD *pArgs, const asBYTE *pArgsType, int argSize, asDWORD func, void *retInMemory) { int baseArgCount = 0; if( retInMemory ) @@ -465,7 +468,7 @@ static asQWORD CallCDeclFunction(const asDWORD* pArgs, const asBYTE *pArgsType, if( argSize > 0 ) { int intArgs = baseArgCount, floatArgs = 0, doubleArgs = 0, longArgs = 0; - stackArgs( pArgs, pArgsType, intArgs, floatArgs, doubleArgs, longArgs ); + stackArgs(pArgs, pArgsType, intArgs, floatArgs, doubleArgs, longArgs); numTotalArgs = intArgs + floatArgs + doubleArgs + longArgs; } else @@ -475,12 +478,12 @@ static asQWORD CallCDeclFunction(const asDWORD* pArgs, const asBYTE *pArgsType, } // call the function with the arguments - return ppcFunc64( ppcArgs, PPC_STACK_SIZE(numTotalArgs), func ); + return ppcFunc64(ppcArgs, PPC_STACK_SIZE(numTotalArgs), func); } // This function is identical to CallCDeclFunction, with the only difference that // the value in the first parameter is the object (unless we are returning in memory) -static asQWORD CallThisCallFunction(const void *obj, const asDWORD* pArgs, const asBYTE *pArgsType, int argSize, asDWORD func, void *retInMemory ) +static asQWORD CallThisCallFunction(const void *obj, const asDWORD *pArgs, const asBYTE *pArgsType, int argSize, asDWORD func, void *retInMemory) { int baseArgCount = 0; if( retInMemory ) @@ -502,18 +505,18 @@ static asQWORD CallThisCallFunction(const void *obj, const asDWORD* pArgs, const if( argSize > 0 ) { int intArgs = baseArgCount, floatArgs = 0, doubleArgs = 0, longArgs = 0; - stackArgs( pArgs, pArgsType, intArgs, floatArgs, doubleArgs, longArgs ); + stackArgs(pArgs, pArgsType, intArgs, floatArgs, doubleArgs, longArgs); numTotalArgs = intArgs + floatArgs + doubleArgs + longArgs; } // call the function with the arguments - return ppcFunc64( ppcArgs, PPC_STACK_SIZE(numTotalArgs), func); + return ppcFunc64(ppcArgs, PPC_STACK_SIZE(numTotalArgs), func); } // This function is identical to CallCDeclFunction, with the only difference that -// the value in the last parameter is the object +// the value in the last parameter is the object // NOTE: on PPC the order for the args is reversed -static asQWORD CallThisCallFunction_objLast(const void *obj, const asDWORD* pArgs, const asBYTE *pArgsType, int argSize, asDWORD func, void *retInMemory) +static asQWORD CallThisCallFunction_objLast(const void *obj, const asDWORD *pArgs, const asBYTE *pArgsType, int argSize, asDWORD func, void *retInMemory) { UNUSED_VAR(argSize); int baseArgCount = 0; @@ -523,55 +526,55 @@ static asQWORD CallThisCallFunction_objLast(const void *obj, const asDWORD* pArg ppcArgs[0] = (asDWORD)retInMemory; ppcArgsType[0] = ppcINTARG; ppcArgsType[1] = ppcENDARG; - baseArgCount = 1; + baseArgCount = 1; } // stack any of the arguments int intArgs = baseArgCount, floatArgs = 0, doubleArgs = 0, longArgs = 0; - stackArgs( pArgs, pArgsType, intArgs, floatArgs, doubleArgs, longArgs ); + stackArgs(pArgs, pArgsType, intArgs, floatArgs, doubleArgs, longArgs); int numTotalArgs = intArgs + floatArgs + doubleArgs; // can we fit the object in at the end? if( numTotalArgs < AS_PPC_MAX_ARGS ) { // put the object pointer at the end - int argPos = intArgs + floatArgs + (doubleArgs * 2) + (longArgs *2); + int argPos = intArgs + floatArgs + (doubleArgs * 2) + (longArgs * 2); ppcArgs[argPos] = (asDWORD)obj; ppcArgsType[numTotalArgs++] = ppcINTARG; ppcArgsType[numTotalArgs] = ppcENDARG; } // call the function with the arguments - return ppcFunc64( ppcArgs, PPC_STACK_SIZE(numTotalArgs), func ); + return ppcFunc64(ppcArgs, PPC_STACK_SIZE(numTotalArgs), func); } // returns true if the given parameter is a 'variable argument' -inline bool IsVariableArgument( asCDataType type ) +inline bool IsVariableArgument(asCDataType type) { return (type.GetTokenType() == ttQuestion) ? true : false; } -asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &/*retQW2*/, void */*secondObject*/) +asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD & /*retQW2*/, void * /*secondObject*/) { // TODO: PPC 64 does not yet support THISCALL_OBJFIRST/LAST // use a working array of types, we'll configure the final one in stackArgs asBYTE argsType[AS_PPC_MAX_ARGS + 1 + 1 + 1]; - memset( argsType, 0, sizeof(argsType)); + memset(argsType, 0, sizeof(argsType)); - asCScriptEngine *engine = context->m_engine; + asCScriptEngine *engine = context->m_engine; asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; int callConv = sysFunc->callConv; - asQWORD retQW = 0; - void *func = (void*)sysFunc->func; - int paramSize = sysFunc->paramSize; - asDWORD *vftable = NULL; + asQWORD retQW = 0; + void *func = (void *)sysFunc->func; + int paramSize = sysFunc->paramSize; + asDWORD *vftable = NULL; int a; // convert the parameters that are < 4 bytes from little endian to big endian - int argDwordOffset = 0; + int argDwordOffset = 0; int totalArgumentCount = 0; for( a = 0; a < (int)descr->parameterTypes.GetLength(); ++a ) @@ -583,7 +586,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // is this a variable argument? // for variable arguments, the typeID will always follow...but we know it is 4 bytes // so we can skip that parameter automatically. - bool isVarArg = IsVariableArgument( descr->parameterTypes[a] ); + bool isVarArg = IsVariableArgument(descr->parameterTypes[a]); if( isVarArg ) { ++totalArgumentCount; @@ -600,23 +603,23 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, asASSERT( numBytes == 1 || numBytes == 2 ); switch( numBytes ) { - case 1: + case 1: { - volatile asBYTE *bPtr = (asBYTE*)ARG_DW(args[argDwordOffset]); - asBYTE t = bPtr[0]; - bPtr[0] = bPtr[3]; - bPtr[3] = t; - t = bPtr[1]; - bPtr[1] = bPtr[2]; - bPtr[2] = t; + volatile asBYTE *bPtr = (asBYTE *)ARG_DW(args[argDwordOffset]); + asBYTE t = bPtr[0]; + bPtr[0] = bPtr[3]; + bPtr[3] = t; + t = bPtr[1]; + bPtr[1] = bPtr[2]; + bPtr[2] = t; } break; - case 2: + case 2: { - volatile asWORD *wPtr = (asWORD*)ARG_DW(args[argDwordOffset]); - asWORD t = wPtr[0]; - wPtr[0] = wPtr[1]; - wPtr[1] = t; + volatile asWORD *wPtr = (asWORD *)ARG_DW(args[argDwordOffset]); + asWORD t = wPtr[0]; + wPtr[0] = wPtr[1]; + wPtr[1] = t; } break; } @@ -664,32 +667,32 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, if( sysFunc->takesObjByVal ) { paramSize = 0; - int spos = 0; - int dpos = 1; + int spos = 0; + int dpos = 1; for( asUINT n = 0; n < descr->parameterTypes.GetLength(); n++ ) { if( descr->parameterTypes[n].IsObject() && !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() && - !(descr->parameterTypes[n].GetTypeInfo()->flags & asOBJ_APP_ARRAY) ) + !(descr->parameterTypes[n].GetTypeInfo()->flags & asOBJ_APP_ARRAY) ) { -#ifdef COMPLEX_OBJS_PASSED_BY_REF + #ifdef COMPLEX_OBJS_PASSED_BY_REF if( descr->parameterTypes[n].GetTypeInfo()->flags & COMPLEX_MASK ) { paramBuffer[dpos++] = args[spos++]; ++paramSize; } else -#endif + #endif { // NOTE: we may have to do endian flipping here // Copy the object's memory to the buffer - memcpy( ¶mBuffer[dpos], *(void**)(args+spos), descr->parameterTypes[n].GetSizeInMemoryBytes() ); + memcpy(¶mBuffer[dpos], *(void **)(args + spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); // Delete the original memory - engine->CallFree( *(char**)(args+spos) ); + engine->CallFree(*(char **)(args + spos)); spos++; - dpos += descr->parameterTypes[n].GetSizeInMemoryDWords(); + dpos += descr->parameterTypes[n].GetSizeInMemoryDWords(); paramSize += descr->parameterTypes[n].GetSizeInMemoryDWords(); } } @@ -705,7 +708,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, } // if this was a variable argument parameter, then account for the implicit typeID - if( IsVariableArgument( descr->parameterTypes[n] ) ) + if( IsVariableArgument(descr->parameterTypes[n]) ) { // the TypeID is just a DWORD paramBuffer[dpos++] = args[spos++]; @@ -716,43 +719,43 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // Keep a free location at the beginning args = ¶mBuffer[1]; } - + // one last verification to make sure things are how we expect switch( callConv ) { - case ICC_CDECL: - case ICC_CDECL_RETURNINMEM: - case ICC_STDCALL: - case ICC_STDCALL_RETURNINMEM: - retQW = CallCDeclFunction( args, argsType, paramSize, (asDWORD)func, retPointer ); - break; - case ICC_THISCALL: - case ICC_THISCALL_RETURNINMEM: - retQW = CallThisCallFunction(obj, args, argsType, paramSize, (asDWORD)func, retPointer ); - break; - case ICC_VIRTUAL_THISCALL: - case ICC_VIRTUAL_THISCALL_RETURNINMEM: - // Get virtual function table from the object pointer - vftable = *(asDWORD**)obj; - retQW = CallThisCallFunction( obj, args, argsType, paramSize, vftable[asDWORD(func)>>2], retPointer ); - break; - case ICC_CDECL_OBJLAST: - case ICC_CDECL_OBJLAST_RETURNINMEM: - retQW = CallThisCallFunction_objLast( obj, args, argsType, paramSize, (asDWORD)func, retPointer ); - break; - case ICC_CDECL_OBJFIRST: - case ICC_CDECL_OBJFIRST_RETURNINMEM: - retQW = CallThisCallFunction( obj, args, argsType, paramSize, (asDWORD)func, retPointer ); - break; - default: - context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); + case ICC_CDECL: + case ICC_CDECL_RETURNINMEM: + case ICC_STDCALL: + case ICC_STDCALL_RETURNINMEM: + retQW = CallCDeclFunction(args, argsType, paramSize, (asDWORD)func, retPointer); + break; + case ICC_THISCALL: + case ICC_THISCALL_RETURNINMEM: + retQW = CallThisCallFunction(obj, args, argsType, paramSize, (asDWORD)func, retPointer); + break; + case ICC_VIRTUAL_THISCALL: + case ICC_VIRTUAL_THISCALL_RETURNINMEM: + // Get virtual function table from the object pointer + vftable = *(asDWORD **)obj; + retQW = CallThisCallFunction(obj, args, argsType, paramSize, vftable[asDWORD(func) >> 2], retPointer); + break; + case ICC_CDECL_OBJLAST: + case ICC_CDECL_OBJLAST_RETURNINMEM: + retQW = CallThisCallFunction_objLast(obj, args, argsType, paramSize, (asDWORD)func, retPointer); + break; + case ICC_CDECL_OBJFIRST: + case ICC_CDECL_OBJFIRST_RETURNINMEM: + retQW = CallThisCallFunction(obj, args, argsType, paramSize, (asDWORD)func, retPointer); + break; + default: + context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); } if( sysFunc->hostReturnFloat ) { // If the return is a float value we need to get the value from the FP register if( sysFunc->hostReturnSize == 1 ) - *(asDWORD*)&retQW = GetReturnedFloat(); + *(asDWORD *)&retQW = GetReturnedFloat(); else retQW = GetReturnedDouble(); } @@ -767,7 +770,6 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, END_AS_NAMESPACE -#endif // AS_PTR_SIZE == 2 -#endif // AS_PPC_64 -#endif // AS_MAX_PORTABILITY - + #endif // AS_PTR_SIZE == 2 + #endif // AS_PPC_64 +#endif // AS_MAX_PORTABILITY diff --git a/sdk/angelscript/source/as_callfunc_riscv64.cpp b/sdk/angelscript/source/as_callfunc_riscv64.cpp index 13c1d611..e62348ca 100644 --- a/sdk/angelscript/source/as_callfunc_riscv64.cpp +++ b/sdk/angelscript/source/as_callfunc_riscv64.cpp @@ -32,7 +32,7 @@ // // as_callfunc_riscv64.cpp // -// These functions handle the actual calling of system functions +// These functions handle the actual calling of system functions // on the 64bit RISC-V call convention used for Linux // // ref: https://riscv.org/wp-content/uploads/2017/05/riscv-spec-v2.2.pdf @@ -41,13 +41,13 @@ #include "as_config.h" #ifndef AS_MAX_PORTABILITY -#ifdef AS_RISCV64 + #ifdef AS_RISCV64 -#include "as_callfunc.h" -#include "as_scriptengine.h" -#include "as_texts.h" -#include "as_tokendef.h" -#include "as_context.h" + #include "as_callfunc.h" + #include "as_scriptengine.h" + #include "as_texts.h" + #include "as_tokendef.h" + #include "as_context.h" BEGIN_AS_NAMESPACE @@ -57,7 +57,10 @@ BEGIN_AS_NAMESPACE // numRegularValues holds the number of regular values to put in a0-a7 registers // numFloatValues hold the number of float values to put in fa0-fa7 registers // numStackValues hold the number of values to push on the stack -struct asDBLQWORD { asQWORD qw1, qw2; }; +struct asDBLQWORD +{ + asQWORD qw1, qw2; +}; extern "C" asDBLQWORD CallRiscVFunc(asFUNCTION_t func, int retfloat, asQWORD *argValues, int numRegularValues, int numFloatValues, int numStackValues); // a0-a7 used for non-float values @@ -65,24 +68,24 @@ extern "C" asDBLQWORD CallRiscVFunc(asFUNCTION_t func, int retfloat, asQWORD *ar // if more than 8 float values and there is space left in regular registers then those are used // rest of the values are pushed on the stack const asUINT maxRegularRegisters = 8; -const asUINT maxFloatRegisters = 8; -const asUINT maxValuesOnStack = 48 - maxRegularRegisters - maxFloatRegisters; +const asUINT maxFloatRegisters = 8; +const asUINT maxValuesOnStack = 48 - maxRegularRegisters - maxFloatRegisters; bool PushToFloatRegs(asQWORD val, asQWORD *argValues, asUINT &numFloatRegistersUsed, asUINT &numRegularRegistersUsed, asUINT &numStackValuesUsed) { - asQWORD* stackValues = argValues + maxRegularRegisters + maxFloatRegisters; + asQWORD *stackValues = argValues + maxRegularRegisters + maxFloatRegisters; - if (numFloatRegistersUsed < maxFloatRegisters) + if( numFloatRegistersUsed < maxFloatRegisters ) { argValues[maxRegularRegisters + numFloatRegistersUsed] = val; numFloatRegistersUsed++; } - else if (numRegularRegistersUsed < maxRegularRegisters) + else if( numRegularRegistersUsed < maxRegularRegisters ) { argValues[numRegularRegistersUsed] = val; numRegularRegistersUsed++; } - else if (numStackValuesUsed < maxValuesOnStack) + else if( numStackValuesUsed < maxValuesOnStack ) { stackValues[numStackValuesUsed] = val; numStackValuesUsed++; @@ -98,16 +101,16 @@ bool PushToFloatRegs(asQWORD val, asQWORD *argValues, asUINT &numFloatRegistersU return true; } -bool PushToRegularRegs(asQWORD val, asQWORD* argValues, asUINT& numRegularRegistersUsed, asUINT& numStackValuesUsed) +bool PushToRegularRegs(asQWORD val, asQWORD *argValues, asUINT &numRegularRegistersUsed, asUINT &numStackValuesUsed) { - asQWORD* stackValues = argValues + maxRegularRegisters + maxFloatRegisters; + asQWORD *stackValues = argValues + maxRegularRegisters + maxFloatRegisters; - if (numRegularRegistersUsed < maxRegularRegisters) + if( numRegularRegistersUsed < maxRegularRegisters ) { argValues[numRegularRegistersUsed] = val; numRegularRegistersUsed++; } - else if (numStackValuesUsed < maxValuesOnStack) + else if( numStackValuesUsed < maxValuesOnStack ) { stackValues[numStackValuesUsed] = val; numStackValuesUsed++; @@ -125,130 +128,130 @@ bool PushToRegularRegs(asQWORD val, asQWORD* argValues, asUINT& numRegularRegist asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &retQW2, void *secondObj) { - asCScriptEngine *engine = context->m_engine; - const asSSystemFunctionInterface *const sysFunc = descr->sysFuncIntf; - const asCDataType &retType = descr->returnType; - const asCTypeInfo *const retTypeInfo = retType.GetTypeInfo(); - asFUNCTION_t func = sysFunc->func; - int callConv = sysFunc->callConv; + asCScriptEngine *engine = context->m_engine; + const asSSystemFunctionInterface * const sysFunc = descr->sysFuncIntf; + const asCDataType &retType = descr->returnType; + const asCTypeInfo * const retTypeInfo = retType.GetTypeInfo(); + asFUNCTION_t func = sysFunc->func; + int callConv = sysFunc->callConv; // TODO: retrieve correct function pointer to call (e.g. from virtual function table, auxiliary pointer, etc) // Prepare the values that will be sent to the native function - asQWORD argValues[maxRegularRegisters + maxFloatRegisters + maxValuesOnStack]; - asQWORD* stackValues = argValues + maxRegularRegisters + maxFloatRegisters; - + asQWORD argValues[maxRegularRegisters + maxFloatRegisters + maxValuesOnStack]; + asQWORD *stackValues = argValues + maxRegularRegisters + maxFloatRegisters; + asUINT numRegularRegistersUsed = 0; - asUINT numFloatRegistersUsed = 0; - asUINT numStackValuesUsed = 0; + asUINT numFloatRegistersUsed = 0; + asUINT numStackValuesUsed = 0; // A function returning an object by value must give the // address of the memory to initialize as the first argument - if (sysFunc->hostReturnInMemory) + if( sysFunc->hostReturnInMemory ) { // Set the return pointer as the first argument argValues[numRegularRegistersUsed++] = (asQWORD)retPointer; } // Determine the real function pointer in case of virtual method - if (obj && (callConv == ICC_VIRTUAL_THISCALL || - callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || - callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJLAST || - callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM)) + if( obj && (callConv == ICC_VIRTUAL_THISCALL || + callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || + callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL_OBJLAST || + callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM) ) { - asFUNCTION_t* vftable = *((asFUNCTION_t**)obj); - func = vftable[FuncPtrToUInt(func) / sizeof(void*)]; + asFUNCTION_t *vftable = *((asFUNCTION_t **)obj); + func = vftable[FuncPtrToUInt(func) / sizeof(void *)]; } // Check if the object pointer must be added as the first argument - if (callConv == ICC_CDECL_OBJFIRST || - callConv == ICC_CDECL_OBJFIRST_RETURNINMEM || - callConv == ICC_THISCALL || - callConv == ICC_VIRTUAL_THISCALL || - callConv == ICC_THISCALL_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM || - callConv == ICC_THISCALL_OBJLAST || - callConv == ICC_THISCALL_OBJLAST_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJLAST || - callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM) + if( callConv == ICC_CDECL_OBJFIRST || + callConv == ICC_CDECL_OBJFIRST_RETURNINMEM || + callConv == ICC_THISCALL || + callConv == ICC_VIRTUAL_THISCALL || + callConv == ICC_THISCALL_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM || + callConv == ICC_THISCALL_OBJLAST || + callConv == ICC_THISCALL_OBJLAST_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL_OBJLAST || + callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) { PushToRegularRegs((asPWORD)obj, argValues, numRegularRegistersUsed, numStackValuesUsed); } - else if (callConv == ICC_THISCALL_OBJFIRST || - callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || - callConv == ICC_THISCALL_OBJFIRST_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM) + else if( callConv == ICC_THISCALL_OBJFIRST || + callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || + callConv == ICC_THISCALL_OBJFIRST_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM ) { PushToRegularRegs((asPWORD)obj, argValues, numRegularRegistersUsed, numStackValuesUsed); PushToRegularRegs((asPWORD)secondObj, argValues, numRegularRegistersUsed, numStackValuesUsed); } asUINT argsPos = 0; - for (asUINT n = 0; n < descr->parameterTypes.GetLength(); n++) + for( asUINT n = 0; n < descr->parameterTypes.GetLength(); n++ ) { - const asCDataType& parmType = descr->parameterTypes[n]; - const asUINT parmDWords = parmType.GetSizeOnStackDWords(); + const asCDataType &parmType = descr->parameterTypes[n]; + const asUINT parmDWords = parmType.GetSizeOnStackDWords(); - if (parmType.IsReference() || parmType.IsObjectHandle() || parmType.IsIntegerType() || parmType.IsUnsignedType() || parmType.IsBooleanType() ) + if( parmType.IsReference() || parmType.IsObjectHandle() || parmType.IsIntegerType() || parmType.IsUnsignedType() || parmType.IsBooleanType() ) { // pointers, integers, and booleans go to regular registers - if (parmType.GetTokenType() == ttQuestion) + if( parmType.GetTokenType() == ttQuestion ) { // Copy the reference and type id as two separate arguments - PushToRegularRegs(*(asQWORD*)&args[argsPos], argValues, numRegularRegistersUsed, numStackValuesUsed); + PushToRegularRegs(*(asQWORD *)&args[argsPos], argValues, numRegularRegistersUsed, numStackValuesUsed); PushToRegularRegs((asQWORD)args[argsPos + AS_PTR_SIZE], argValues, numRegularRegistersUsed, numStackValuesUsed); } - else + else { - if (parmDWords == 1) + if( parmDWords == 1 ) PushToRegularRegs((asQWORD)args[argsPos], argValues, numRegularRegistersUsed, numStackValuesUsed); else - PushToRegularRegs(*(asQWORD*)&args[argsPos], argValues, numRegularRegistersUsed, numStackValuesUsed); + PushToRegularRegs(*(asQWORD *)&args[argsPos], argValues, numRegularRegistersUsed, numStackValuesUsed); } } - else if (parmType.IsFloatType() || parmType.IsDoubleType()) + else if( parmType.IsFloatType() || parmType.IsDoubleType() ) { // floats and doubles goes to the float registers // if there are more float/double args than registers, and there are still regular registers available then use those - if (parmDWords == 1) + if( parmDWords == 1 ) PushToFloatRegs(0xFFFFFFFF00000000ull | (asQWORD)args[argsPos], argValues, numFloatRegistersUsed, numRegularRegistersUsed, numStackValuesUsed); else - PushToFloatRegs(*(asQWORD*)&args[argsPos], argValues, numFloatRegistersUsed, numRegularRegistersUsed, numStackValuesUsed); + PushToFloatRegs(*(asQWORD *)&args[argsPos], argValues, numFloatRegistersUsed, numRegularRegistersUsed, numStackValuesUsed); } - else if (parmType.IsObject()) + else if( parmType.IsObject() ) { - if (parmType.GetTypeInfo()->flags & COMPLEX_MASK) + if( parmType.GetTypeInfo()->flags & COMPLEX_MASK ) { // complex object types are passed by address - PushToRegularRegs(*(asQWORD*)&args[argsPos], argValues, numRegularRegistersUsed, numStackValuesUsed); + PushToRegularRegs(*(asQWORD *)&args[argsPos], argValues, numRegularRegistersUsed, numStackValuesUsed); } - else if ((parmType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALLFLOATS) && !(parmType.GetTypeInfo()->flags & asOBJ_APP_CLASS_UNION) && - ((parmType.GetSizeInMemoryDWords() <= 2 && !(parmType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALIGN8)) || - (parmType.GetSizeInMemoryDWords() <= 4 && (parmType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALIGN8))) ) + else if( (parmType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALLFLOATS) && !(parmType.GetTypeInfo()->flags & asOBJ_APP_CLASS_UNION) && + ((parmType.GetSizeInMemoryDWords() <= 2 && !(parmType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALIGN8)) || + (parmType.GetSizeInMemoryDWords() <= 4 && (parmType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALIGN8))) ) { // simple structs with 1 or 2 floats/doubles are loaded into into float registers - if (!(parmType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALIGN8)) + if( !(parmType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALIGN8) ) { // Unpack the floats - asQWORD arg1 = 0xFFFFFFFF00000000ull | **(asDWORD**)&args[argsPos]; - asQWORD arg2 = 0xFFFFFFFF00000000ull | *((*(asDWORD**)&args[argsPos])+1); + asQWORD arg1 = 0xFFFFFFFF00000000ull | **(asDWORD **)&args[argsPos]; + asQWORD arg2 = 0xFFFFFFFF00000000ull | *((*(asDWORD **)&args[argsPos]) + 1); PushToFloatRegs(arg1, argValues, numFloatRegistersUsed, numRegularRegistersUsed, numStackValuesUsed); PushToFloatRegs(arg2, argValues, numFloatRegistersUsed, numRegularRegistersUsed, numStackValuesUsed); } else { // Unpack the doubles - asQWORD arg1 = **(asQWORD**)&args[argsPos]; - asQWORD arg2 = *((*(asQWORD**)&args[argsPos]) + 1); + asQWORD arg1 = **(asQWORD **)&args[argsPos]; + asQWORD arg2 = *((*(asQWORD **)&args[argsPos]) + 1); PushToFloatRegs(arg1, argValues, numFloatRegistersUsed, numRegularRegistersUsed, numStackValuesUsed); PushToFloatRegs(arg2, argValues, numFloatRegistersUsed, numRegularRegistersUsed, numStackValuesUsed); } // Delete the original memory - engine->CallFree(*(void**)&args[argsPos]); + engine->CallFree(*(void **)&args[argsPos]); } else { @@ -256,22 +259,22 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // TODO: what if part of the structure fits in registers but not the other part? would part of the object be pushed on the stack? // TODO: what of large objects? are they passed by value in registers/stack? Or by reference? const asUINT sizeInMemoryDWords = parmType.GetSizeInMemoryDWords(); - const asUINT parmQWords = (sizeInMemoryDWords >> 1) + (sizeInMemoryDWords & 1); + const asUINT parmQWords = (sizeInMemoryDWords >> 1) + (sizeInMemoryDWords & 1); - if ((maxRegularRegisters - numRegularRegistersUsed) > parmQWords) + if( (maxRegularRegisters - numRegularRegistersUsed) > parmQWords ) { - if (sizeInMemoryDWords == 1) - argValues[numRegularRegistersUsed] = (asQWORD) * *(asDWORD**)&args[argsPos]; + if( sizeInMemoryDWords == 1 ) + argValues[numRegularRegistersUsed] = (asQWORD) * *(asDWORD **)&args[argsPos]; else - memcpy(&argValues[numRegularRegistersUsed], *(void**)&args[argsPos], sizeInMemoryDWords * 4); + memcpy(&argValues[numRegularRegistersUsed], *(void **)&args[argsPos], sizeInMemoryDWords * 4); numRegularRegistersUsed += parmQWords; } - else if ((maxValuesOnStack - numStackValuesUsed) > parmQWords) + else if( (maxValuesOnStack - numStackValuesUsed) > parmQWords ) { - if (sizeInMemoryDWords == 1) - stackValues[numStackValuesUsed] = (asQWORD) * *(asDWORD**)&args[argsPos]; + if( sizeInMemoryDWords == 1 ) + stackValues[numStackValuesUsed] = (asQWORD) * *(asDWORD **)&args[argsPos]; else - memcpy(&stackValues[numStackValuesUsed], *(void**)&args[argsPos], sizeInMemoryDWords * 4); + memcpy(&stackValues[numStackValuesUsed], *(void **)&args[argsPos], sizeInMemoryDWords * 4); numStackValuesUsed += parmQWords; } else @@ -282,7 +285,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, } // Delete the original memory - engine->CallFree(*(void**)&args[argsPos]); + engine->CallFree(*(void **)&args[argsPos]); } } @@ -290,12 +293,12 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, } // Check if the object pointer must be added as the last argument - if (callConv == ICC_CDECL_OBJLAST || callConv == ICC_CDECL_OBJLAST_RETURNINMEM) + if( callConv == ICC_CDECL_OBJLAST || callConv == ICC_CDECL_OBJLAST_RETURNINMEM ) { PushToRegularRegs((asPWORD)obj, argValues, numRegularRegistersUsed, numStackValuesUsed); } - else if (callConv == ICC_THISCALL_OBJLAST || callConv == ICC_THISCALL_OBJLAST_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJLAST || callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM) + else if( callConv == ICC_THISCALL_OBJLAST || callConv == ICC_THISCALL_OBJLAST_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL_OBJLAST || callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) { PushToRegularRegs((asPWORD)secondObj, argValues, numRegularRegistersUsed, numStackValuesUsed); } @@ -304,10 +307,10 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // Integer values are returned in a0 and a1, allowing simple structures with up to 128bits to be returned in registers asDBLQWORD ret = CallRiscVFunc(func, retfloat, argValues, numRegularRegistersUsed, numFloatRegistersUsed, numStackValuesUsed); - retQW2 = ret.qw2; + retQW2 = ret.qw2; // Special case for returning a struct with two floats. C++ will return this in fa0:fa1. These needs to be compacted into a single qword - if (retfloat && retTypeInfo && !(retTypeInfo->flags & asOBJ_APP_CLASS_ALIGN8) && retTypeInfo->flags & asOBJ_APP_CLASS_ALLFLOATS) + if( retfloat && retTypeInfo && !(retTypeInfo->flags & asOBJ_APP_CLASS_ALIGN8) && retTypeInfo->flags & asOBJ_APP_CLASS_ALLFLOATS ) { ret.qw1 &= 0xFFFFFFFF; ret.qw1 |= (retQW2 << 32); @@ -318,9 +321,5 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, END_AS_NAMESPACE -#endif // AS_RISCV64 -#endif // AS_MAX_PORTABILITY - - - - + #endif // AS_RISCV64 +#endif // AS_MAX_PORTABILITY diff --git a/sdk/angelscript/source/as_callfunc_sh4.cpp b/sdk/angelscript/source/as_callfunc_sh4.cpp index b24be9a5..af1bc02a 100644 --- a/sdk/angelscript/source/as_callfunc_sh4.cpp +++ b/sdk/angelscript/source/as_callfunc_sh4.cpp @@ -46,20 +46,20 @@ #include "as_config.h" #ifndef AS_MAX_PORTABILITY -#ifdef AS_SH4 + #ifdef AS_SH4 -#include "as_callfunc.h" -#include "as_scriptengine.h" -#include "as_texts.h" -#include "as_tokendef.h" -#include "as_context.h" + #include "as_callfunc.h" + #include "as_scriptengine.h" + #include "as_texts.h" + #include "as_tokendef.h" + #include "as_context.h" -#include -#include + #include + #include BEGIN_AS_NAMESPACE -#define AS_SH4_MAX_ARGS 32 + #define AS_SH4_MAX_ARGS 32 // The array used to send values to the correct places. // first 0-4 regular values to load into the r4-r7 registers // then 0-8 float values to load into the fr4-fr11 registers @@ -77,111 +77,121 @@ static asDWORD sh4Args[AS_SH4_MAX_ARGS + 1 + 1]; extern "C" asQWORD sh4Func(int intArgSize, int floatArgSize, int stackArgSize, asDWORD func); asm("" -" .align 4\n" -" .global _sh4Func\n" -"_sh4Func:\n" -" mov.l r14,@-r15\n" -" mov.l r13,@-r15\n" -" mov.l r12,@-r15\n" -" sts.l pr,@-r15\n" // must be saved since we call a subroutine -" mov r7, r14\n" // func -" mov r6, r13\n" // stackArgSize -" mov.l r5,@-r15\n" // floatArgSize -" mov.l sh4Args,r0\n" -" pref @r0\n" -" mov r4, r1\n" // intArgsize -" mov #33*4,r2\n" -" extu.b r2,r2\n" // make unsigned (33*4 = 132 => 128) -" mov.l @(r0,r2), r2\n" // r2 has adress for when returning in memory -"_sh4f_intarguments:\n" // copy all the int arguments to the respective registers -" mov #4*2*2,r3\n" // calculate how many bytes to skip -" sub r1,r3\n" -" braf r3\n" -" add #-4,r1\n" // we are indexing the array backwards, so subtract one (delayed slot) -" mov.l @(r0,r1),r7\n" // 4 arguments -" add #-4,r1\n" -" mov.l @(r0,r1),r6\n" // 3 arguments -" add #-4,r1\n" -" mov.l @(r0,r1),r5\n" // 2 arguments -" add #-4,r1\n" -" mov.l @(r0,r1),r4\n" // 1 argument -" nop\n" -"_sh4f_floatarguments:\n" // copy all the float arguments to the respective registers -" add #4*4, r0\n" -" mov.l @r15+,r1\n" // floatArgSize -" mov #8*2*2,r3\n" // calculate how many bytes to skip -" sub r1,r3\n" -" braf r3\n" -" add #-4,r1\n" // we are indexing the array backwards, so subtract one (delayed slot) -" fmov.s @(r0,r1),fr11\n" // 8 arguments -" add #-4,r1\n" -" fmov.s @(r0,r1),fr10\n" // 7 arguments -" add #-4,r1\n" -" fmov.s @(r0,r1),fr9\n" // 6 arguments -" add #-4,r1\n" -" fmov.s @(r0,r1),fr8\n" // 5 arguments -" add #-4,r1\n" -" fmov.s @(r0,r1),fr7\n" // 4 arguments -" add #-4,r1\n" -" fmov.s @(r0,r1),fr6\n" // 3 arguments -" add #-4,r1\n" -" fmov.s @(r0,r1),fr5\n" // 2 arguments -" add #-4,r1\n" -" fmov.s @(r0,r1),fr4\n" // 1 argument -" nop\n" -"_sh4f_stackarguments:\n" // copy all the stack argument onto the stack -" add #8*4, r0\n" -" mov r0, r1\n" -" mov #0, r0\n" // init position counter (also used as a 0-check on the line after) -" cmp/eq r0, r13\n" -" bt _sh4f_functioncall\n" // no arguments to push onto the stack -" mov r13, r3\n" // stackArgSize -" sub r3,r15\n" // "allocate" space on the stack -" shlr2 r3\n" // make into a counter -"_sh4f_stackloop:\n" -" mov.l @r1+, r12\n" -" mov.l r12, @(r0, r15)\n" -" add #4, r0\n" -" dt r3\n" -" bf _sh4f_stackloop\n" -"_sh4f_functioncall:\n" -" jsr @r14\n" // no arguments -" nop\n" -" add r13, r15\n" // restore stack position -" lds.l @r15+,pr\n" -" mov.l @r15+, r12\n" -" mov.l @r15+, r13\n" -" rts\n" -" mov.l @r15+, r14\n" // delayed slot -"\n" -" .align 4\n" -"sh4Args:\n" -" .long _sh4Args\n" -); + " .align 4\n" + " .global _sh4Func\n" + "_sh4Func:\n" + " mov.l r14,@-r15\n" + " mov.l r13,@-r15\n" + " mov.l r12,@-r15\n" + " sts.l pr,@-r15\n" // must be saved since we call a subroutine + " mov r7, r14\n" // func + " mov r6, r13\n" // stackArgSize + " mov.l r5,@-r15\n" // floatArgSize + " mov.l sh4Args,r0\n" + " pref @r0\n" + " mov r4, r1\n" // intArgsize + " mov #33*4,r2\n" + " extu.b r2,r2\n" // make unsigned (33*4 = 132 => 128) + " mov.l @(r0,r2), r2\n" // r2 has adress for when returning in memory + "_sh4f_intarguments:\n" // copy all the int arguments to the respective registers + " mov #4*2*2,r3\n" // calculate how many bytes to skip + " sub r1,r3\n" + " braf r3\n" + " add #-4,r1\n" // we are indexing the array backwards, so subtract one (delayed slot) + " mov.l @(r0,r1),r7\n" // 4 arguments + " add #-4,r1\n" + " mov.l @(r0,r1),r6\n" // 3 arguments + " add #-4,r1\n" + " mov.l @(r0,r1),r5\n" // 2 arguments + " add #-4,r1\n" + " mov.l @(r0,r1),r4\n" // 1 argument + " nop\n" + "_sh4f_floatarguments:\n" // copy all the float arguments to the respective registers + " add #4*4, r0\n" + " mov.l @r15+,r1\n" // floatArgSize + " mov #8*2*2,r3\n" // calculate how many bytes to skip + " sub r1,r3\n" + " braf r3\n" + " add #-4,r1\n" // we are indexing the array backwards, so subtract one (delayed slot) + " fmov.s @(r0,r1),fr11\n" // 8 arguments + " add #-4,r1\n" + " fmov.s @(r0,r1),fr10\n" // 7 arguments + " add #-4,r1\n" + " fmov.s @(r0,r1),fr9\n" // 6 arguments + " add #-4,r1\n" + " fmov.s @(r0,r1),fr8\n" // 5 arguments + " add #-4,r1\n" + " fmov.s @(r0,r1),fr7\n" // 4 arguments + " add #-4,r1\n" + " fmov.s @(r0,r1),fr6\n" // 3 arguments + " add #-4,r1\n" + " fmov.s @(r0,r1),fr5\n" // 2 arguments + " add #-4,r1\n" + " fmov.s @(r0,r1),fr4\n" // 1 argument + " nop\n" + "_sh4f_stackarguments:\n" // copy all the stack argument onto the stack + " add #8*4, r0\n" + " mov r0, r1\n" + " mov #0, r0\n" // init position counter (also used as a 0-check on the line after) + " cmp/eq r0, r13\n" + " bt _sh4f_functioncall\n" // no arguments to push onto the stack + " mov r13, r3\n" // stackArgSize + " sub r3,r15\n" // "allocate" space on the stack + " shlr2 r3\n" // make into a counter + "_sh4f_stackloop:\n" + " mov.l @r1+, r12\n" + " mov.l r12, @(r0, r15)\n" + " add #4, r0\n" + " dt r3\n" + " bf _sh4f_stackloop\n" + "_sh4f_functioncall:\n" + " jsr @r14\n" // no arguments + " nop\n" + " add r13, r15\n" // restore stack position + " lds.l @r15+,pr\n" + " mov.l @r15+, r12\n" + " mov.l @r15+, r13\n" + " rts\n" + " mov.l @r15+, r14\n" // delayed slot + "\n" + " .align 4\n" + "sh4Args:\n" + " .long _sh4Args\n"); // puts the arguments in the correct place in the sh4Args-array. See comments above. // This could be done better. -inline void splitArgs(const asDWORD *args, int argNum, int &numRegIntArgs, int &numRegFloatArgs, int &numRestArgs, int hostFlags) { +inline void splitArgs(const asDWORD *args, int argNum, int &numRegIntArgs, int &numRegFloatArgs, int &numRestArgs, int hostFlags) +{ int i; int argBit = 1; - for (i = 0; i < argNum; i++) { - if (hostFlags & argBit) { - if (numRegFloatArgs < 12 - 4) { + for( i = 0; i < argNum; i++ ) + { + if( hostFlags & argBit ) + { + if( numRegFloatArgs < 12 - 4 ) + { // put in float register sh4Args[4 + numRegFloatArgs] = args[i]; numRegFloatArgs++; - } else { + } + else + { // put in stack sh4Args[4 + 8 + numRestArgs] = args[i]; numRestArgs++; } - } else { - if (numRegIntArgs < 8 - 4) { + } + else + { + if( numRegIntArgs < 8 - 4 ) + { // put in int register sh4Args[numRegIntArgs] = args[i]; numRegIntArgs++; - } else { + } + else + { // put in stack sh4Args[4 + 8 + numRestArgs] = args[i]; numRestArgs++; @@ -194,12 +204,12 @@ asQWORD CallCDeclFunction(const asDWORD *args, int argSize, asDWORD func, int fl { int argNum = argSize >> 2; - int intArgs = 0; + int intArgs = 0; int floatArgs = 0; - int restArgs = 0; + int restArgs = 0; // put the arguments in the correct places in the sh4Args array - if (argNum > 0) + if( argNum > 0 ) splitArgs(args, argNum, intArgs, floatArgs, restArgs, flags); return sh4Func(intArgs << 2, floatArgs << 2, restArgs << 2, func); @@ -211,14 +221,14 @@ asQWORD CallThisCallFunction(const void *obj, const asDWORD *args, int argSize, { int argNum = argSize >> 2; - int intArgs = 1; + int intArgs = 1; int floatArgs = 0; - int restArgs = 0; + int restArgs = 0; + + sh4Args[0] = (asDWORD)obj; - sh4Args[0] = (asDWORD) obj; - // put the arguments in the correct places in the sh4Args array - if (argNum >= 1) + if( argNum >= 1 ) splitArgs(args, argNum, intArgs, floatArgs, restArgs, flags); return sh4Func(intArgs << 2, floatArgs << 2, restArgs << 2, func); @@ -229,23 +239,26 @@ asQWORD CallThisCallFunction_objLast(const void *obj, const asDWORD *args, int a { int argNum = argSize >> 2; - int intArgs = 0; + int intArgs = 0; int floatArgs = 0; - int restArgs = 0; + int restArgs = 0; // put the arguments in the correct places in the sh4Args array - if (argNum >= 1) + if( argNum >= 1 ) splitArgs(args, argNum, intArgs, floatArgs, restArgs, flags); - if (intArgs < 4) { - sh4Args[intArgs] = (asDWORD) obj; + if( intArgs < 4 ) + { + sh4Args[intArgs] = (asDWORD)obj; intArgs++; - } else { - sh4Args[4 + 8 + restArgs] = (asDWORD) obj; + } + else + { + sh4Args[4 + 8 + restArgs] = (asDWORD)obj; restArgs++; } - + return sh4Func(intArgs << 2, floatArgs << 2, restArgs << 2, func); } @@ -270,35 +283,38 @@ asQWORD GetReturnedDouble() return d; } -asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &/*retQW2*/, void */*secondObject*/) +asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD & /*retQW2*/, void * /*secondObject*/) { // TODO: SH4 does not yet support THISCALL_OBJFIRST/LAST - asCScriptEngine *engine = context->m_engine; - asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; - int callConv = sysFunc->callConv; + asCScriptEngine *engine = context->m_engine; + asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; + int callConv = sysFunc->callConv; asQWORD retQW = 0; - void *func = (void*)sysFunc->func; - int paramSize = sysFunc->paramSize; + void *func = (void *)sysFunc->func; + int paramSize = sysFunc->paramSize; asDWORD *vftable; if( descr->returnType.IsObject() && !descr->returnType.IsReference() && !descr->returnType.IsObjectHandle() ) { - sh4Args[AS_SH4_MAX_ARGS+1] = (asDWORD) retPointer; + sh4Args[AS_SH4_MAX_ARGS + 1] = (asDWORD)retPointer; } asASSERT(descr->parameterTypes.GetLength() <= 32); // mark all float arguments - int argBit = 1; + int argBit = 1; int hostFlags = 0; - int intArgs = 0; - for( asUINT a = 0; a < descr->parameterTypes.GetLength(); a++ ) { - if (descr->parameterTypes[a].IsFloatType()) { + int intArgs = 0; + for( asUINT a = 0; a < descr->parameterTypes.GetLength(); a++ ) + { + if( descr->parameterTypes[a].IsFloatType() ) + { hostFlags |= argBit; - } else intArgs++; + } + else intArgs++; argBit <<= 1; } @@ -306,27 +322,27 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, if( sysFunc->takesObjByVal ) { paramSize = 0; - int spos = 0; - int dpos = 1; + int spos = 0; + int dpos = 1; for( asUINT n = 0; n < descr->parameterTypes.GetLength(); n++ ) { if( descr->parameterTypes[n].IsObject() && !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() ) { -#ifdef COMPLEX_OBJS_PASSED_BY_REF + #ifdef COMPLEX_OBJS_PASSED_BY_REF if( descr->parameterTypes[n].GetTypeInfo()->flags & COMPLEX_MASK ) { paramBuffer[dpos++] = args[spos++]; paramSize++; } else -#endif + #endif { // Copy the object's memory to the buffer - memcpy(¶mBuffer[dpos], *(void**)(args+spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); + memcpy(¶mBuffer[dpos], *(void **)(args + spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); // Delete the original memory - engine->CallFree(*(char**)(args+spos)); + engine->CallFree(*(char **)(args + spos)); spos++; - dpos += descr->parameterTypes[n].GetSizeInMemoryDWords(); + dpos += descr->parameterTypes[n].GetSizeInMemoryDWords(); paramSize += descr->parameterTypes[n].GetSizeInMemoryDWords(); } } @@ -345,39 +361,39 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, switch( callConv ) { - case ICC_CDECL: - case ICC_CDECL_RETURNINMEM: - case ICC_STDCALL: - case ICC_STDCALL_RETURNINMEM: - retQW = CallCDeclFunction(args, paramSize<<2, (asDWORD)func, hostFlags); - break; - case ICC_THISCALL: - case ICC_THISCALL_RETURNINMEM: - retQW = CallThisCallFunction(obj, args, paramSize<<2, (asDWORD)func, hostFlags); - break; - case ICC_VIRTUAL_THISCALL: - case ICC_VIRTUAL_THISCALL_RETURNINMEM: - // Get virtual function table from the object pointer - vftable = *(asDWORD**)obj; - retQW = CallThisCallFunction(obj, args, paramSize<<2, vftable[asDWORD(func)>>2], hostFlags); - break; - case ICC_CDECL_OBJLAST: - case ICC_CDECL_OBJLAST_RETURNINMEM: - retQW = CallThisCallFunction_objLast(obj, args, paramSize<<2, (asDWORD)func, hostFlags); - break; - case ICC_CDECL_OBJFIRST: - case ICC_CDECL_OBJFIRST_RETURNINMEM: - retQW = CallThisCallFunction(obj, args, paramSize<<2, (asDWORD)func, hostFlags); - break; - default: - context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); + case ICC_CDECL: + case ICC_CDECL_RETURNINMEM: + case ICC_STDCALL: + case ICC_STDCALL_RETURNINMEM: + retQW = CallCDeclFunction(args, paramSize << 2, (asDWORD)func, hostFlags); + break; + case ICC_THISCALL: + case ICC_THISCALL_RETURNINMEM: + retQW = CallThisCallFunction(obj, args, paramSize << 2, (asDWORD)func, hostFlags); + break; + case ICC_VIRTUAL_THISCALL: + case ICC_VIRTUAL_THISCALL_RETURNINMEM: + // Get virtual function table from the object pointer + vftable = *(asDWORD **)obj; + retQW = CallThisCallFunction(obj, args, paramSize << 2, vftable[asDWORD(func) >> 2], hostFlags); + break; + case ICC_CDECL_OBJLAST: + case ICC_CDECL_OBJLAST_RETURNINMEM: + retQW = CallThisCallFunction_objLast(obj, args, paramSize << 2, (asDWORD)func, hostFlags); + break; + case ICC_CDECL_OBJFIRST: + case ICC_CDECL_OBJFIRST_RETURNINMEM: + retQW = CallThisCallFunction(obj, args, paramSize << 2, (asDWORD)func, hostFlags); + break; + default: + context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); } // If the return is a float value we need to get the value from the FP register if( sysFunc->hostReturnFloat ) { if( sysFunc->hostReturnSize == 1 ) - *(asDWORD*)&retQW = GetReturnedFloat(); + *(asDWORD *)&retQW = GetReturnedFloat(); else retQW = GetReturnedDouble(); } @@ -387,7 +403,5 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, END_AS_NAMESPACE -#endif // AS_SH4 -#endif // AS_MAX_PORTABILITY - - + #endif // AS_SH4 +#endif // AS_MAX_PORTABILITY diff --git a/sdk/angelscript/source/as_callfunc_x64_gcc.cpp b/sdk/angelscript/source/as_callfunc_x64_gcc.cpp index 4b308117..7134fb11 100644 --- a/sdk/angelscript/source/as_callfunc_x64_gcc.cpp +++ b/sdk/angelscript/source/as_callfunc_x64_gcc.cpp @@ -41,138 +41,139 @@ // Useful references for the System V AMD64 ABI: // http://eli.thegreenplace.net/2011/09/06/stack-frame-layout-on-x86-64/ // http://math-atlas.sourceforge.net/devel/assembly/abi_sysV_amd64.pdf - + #include "as_config.h" #ifndef AS_MAX_PORTABILITY -#ifdef AS_X64_GCC + #ifdef AS_X64_GCC -#include "as_scriptengine.h" -#include "as_texts.h" -#include "as_context.h" + #include "as_scriptengine.h" + #include "as_texts.h" + #include "as_context.h" BEGIN_AS_NAMESPACE -enum argTypes { x64INTARG = 0, x64FLOATARG = 1 }; -typedef asQWORD ( *funcptr_t )( void ); +enum argTypes { x64INTARG = 0, + x64FLOATARG = 1 }; +typedef asQWORD (*funcptr_t)(void); -#define X64_MAX_ARGS 32 -#define MAX_CALL_INT_REGISTERS 6 -#define MAX_CALL_SSE_REGISTERS 8 -#define X64_CALLSTACK_SIZE ( X64_MAX_ARGS + MAX_CALL_SSE_REGISTERS + 3 ) + #define X64_MAX_ARGS 32 + #define MAX_CALL_INT_REGISTERS 6 + #define MAX_CALL_SSE_REGISTERS 8 + #define X64_CALLSTACK_SIZE (X64_MAX_ARGS + MAX_CALL_SSE_REGISTERS + 3) -// Note to self: Always remember to inform the used registers on the clobber line, +// Note to self: Always remember to inform the used registers on the clobber line, // so that the gcc optimizer doesn't try to use them for other things -static asQWORD __attribute__((noinline)) -#ifndef __clang__ - // On GNUC this code doesn't work properly when optimized, so disable optimization for this function - __attribute__((optimize(0))) -#endif - X64_CallFunction(const asQWORD *args, int cnt, funcptr_t func, asQWORD &retQW2, bool returnFloat) +static asQWORD __attribute__((noinline)) + #ifndef __clang__ +// On GNUC this code doesn't work properly when optimized, so disable optimization for this function +__attribute__((optimize(0))) + #endif +X64_CallFunction(const asQWORD *args, int cnt, funcptr_t func, asQWORD &retQW2, bool returnFloat) { // Need to flag the variable as volatile so the compiler doesn't optimize out the variable volatile asQWORD retQW1 = 0; // Reference: http://www.x86-64.org/documentation/abi.pdf - __asm__ __volatile__ ( - - " movq %0, %%rcx \n" // rcx = cnt - " movq %1, %%r10 \n" // r10 = args - " movq %2, %%r11 \n" // r11 = func - - // Backup stack pointer in R15 that is guaranteed to maintain its value over function calls - " movq %%rsp, %%r15 \n" -#if defined(__clang__) && defined(__OPTIMIZE__) - // Make sure the stack unwind logic knows we've backed up the stack pointer in register r15 - // This should only be done if any optimization is done. If no optimization (-O0) is used, - // then the compiler already backups the rsp before entering the inline assembler code - " .cfi_def_cfa_register r15 \n" -#endif - - // Skip the first 128 bytes on the stack frame, called "red zone", - // that might be used by the compiler to store temporary values - " sub $128, %%rsp \n" - - // Make sure the stack pointer will be aligned to 16 bytes when the function is called - " movq %%rcx, %%rdx \n" - " salq $3, %%rdx \n" - " movq %%rsp, %%rax \n" - " sub %%rdx, %%rax \n" - " and $15, %%rax \n" - " sub %%rax, %%rsp \n" - - // Push the stack parameters, i.e. the arguments that won't be loaded into registers - " movq %%rcx, %%rsi \n" - " testl %%esi, %%esi \n" - " jle Lendstack \n" - " subl $1, %%esi \n" - " xorl %%edx, %%edx \n" - " leaq 8(, %%rsi, 8), %%rcx \n" - "Lloopstack: \n" - " movq 112(%%r10, %%rdx), %%rax \n" - " pushq %%rax \n" - " addq $8, %%rdx \n" - " cmpq %%rcx, %%rdx \n" - " jne Lloopstack \n" - "Lendstack: \n" - - // Populate integer and floating point parameters - " movq %%r10, %%rax \n" - " mov (%%rax), %%rdi \n" - " mov 8(%%rax), %%rsi \n" - " mov 16(%%rax), %%rdx \n" - " mov 24(%%rax), %%rcx \n" - " mov 32(%%rax), %%r8 \n" - " mov 40(%%rax), %%r9 \n" - " add $48, %%rax \n" - " movsd (%%rax), %%xmm0 \n" - " movsd 8(%%rax), %%xmm1 \n" - " movsd 16(%%rax), %%xmm2 \n" - " movsd 24(%%rax), %%xmm3 \n" - " movsd 32(%%rax), %%xmm4 \n" - " movsd 40(%%rax), %%xmm5 \n" - " movsd 48(%%rax), %%xmm6 \n" - " movsd 56(%%rax), %%xmm7 \n" - - // Call the function - " call *%%r11 \n" - - // Restore stack pointer - " mov %%r15, %%rsp \n" -#if defined(__clang__) && defined(__OPTIMIZE__) - // Inform the stack unwind logic that the stack pointer has been restored - // This should only be done if any optimization is done. If no optimization (-O0) is used, - // then the compiler already backups the rsp before entering the inline assembler code - " .cfi_def_cfa_register rsp \n" -#endif - - // Put return value in retQW1 and retQW2, using either RAX:RDX or XMM0:XMM1 depending on type of return value - " movl %5, %%ecx \n" - " testb %%cl, %%cl \n" - " je Lintret \n" - " lea %3, %%rax \n" - " movq %%xmm0, (%%rax) \n" - " lea %4, %%rdx \n" - " movq %%xmm1, (%%rdx) \n" - " jmp Lendcall \n" - "Lintret: \n" - " movq %%rax, %3 \n" - " movq %%rdx, %4 \n" - "Lendcall: \n" - - : : "g" ((asQWORD)cnt), "g" (args), "g" (func), "m" (retQW1), "m" (retQW2), "m" (returnFloat) - : "%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7", - "%rdi", "%rsi", "%rax", "%rdx", "%rcx", "%r8", "%r9", "%r10", "%r11", "%r15"); - + __asm__ __volatile__( + + " movq %0, %%rcx \n" // rcx = cnt + " movq %1, %%r10 \n" // r10 = args + " movq %2, %%r11 \n" // r11 = func + + // Backup stack pointer in R15 that is guaranteed to maintain its value over function calls + " movq %%rsp, %%r15 \n" + #if defined(__clang__) && defined(__OPTIMIZE__) + // Make sure the stack unwind logic knows we've backed up the stack pointer in register r15 + // This should only be done if any optimization is done. If no optimization (-O0) is used, + // then the compiler already backups the rsp before entering the inline assembler code + " .cfi_def_cfa_register r15 \n" + #endif + + // Skip the first 128 bytes on the stack frame, called "red zone", + // that might be used by the compiler to store temporary values + " sub $128, %%rsp \n" + + // Make sure the stack pointer will be aligned to 16 bytes when the function is called + " movq %%rcx, %%rdx \n" + " salq $3, %%rdx \n" + " movq %%rsp, %%rax \n" + " sub %%rdx, %%rax \n" + " and $15, %%rax \n" + " sub %%rax, %%rsp \n" + + // Push the stack parameters, i.e. the arguments that won't be loaded into registers + " movq %%rcx, %%rsi \n" + " testl %%esi, %%esi \n" + " jle Lendstack \n" + " subl $1, %%esi \n" + " xorl %%edx, %%edx \n" + " leaq 8(, %%rsi, 8), %%rcx \n" + "Lloopstack: \n" + " movq 112(%%r10, %%rdx), %%rax \n" + " pushq %%rax \n" + " addq $8, %%rdx \n" + " cmpq %%rcx, %%rdx \n" + " jne Lloopstack \n" + "Lendstack: \n" + + // Populate integer and floating point parameters + " movq %%r10, %%rax \n" + " mov (%%rax), %%rdi \n" + " mov 8(%%rax), %%rsi \n" + " mov 16(%%rax), %%rdx \n" + " mov 24(%%rax), %%rcx \n" + " mov 32(%%rax), %%r8 \n" + " mov 40(%%rax), %%r9 \n" + " add $48, %%rax \n" + " movsd (%%rax), %%xmm0 \n" + " movsd 8(%%rax), %%xmm1 \n" + " movsd 16(%%rax), %%xmm2 \n" + " movsd 24(%%rax), %%xmm3 \n" + " movsd 32(%%rax), %%xmm4 \n" + " movsd 40(%%rax), %%xmm5 \n" + " movsd 48(%%rax), %%xmm6 \n" + " movsd 56(%%rax), %%xmm7 \n" + + // Call the function + " call *%%r11 \n" + + // Restore stack pointer + " mov %%r15, %%rsp \n" + #if defined(__clang__) && defined(__OPTIMIZE__) + // Inform the stack unwind logic that the stack pointer has been restored + // This should only be done if any optimization is done. If no optimization (-O0) is used, + // then the compiler already backups the rsp before entering the inline assembler code + " .cfi_def_cfa_register rsp \n" + #endif + + // Put return value in retQW1 and retQW2, using either RAX:RDX or XMM0:XMM1 depending on type of return value + " movl %5, %%ecx \n" + " testb %%cl, %%cl \n" + " je Lintret \n" + " lea %3, %%rax \n" + " movq %%xmm0, (%%rax) \n" + " lea %4, %%rdx \n" + " movq %%xmm1, (%%rdx) \n" + " jmp Lendcall \n" + "Lintret: \n" + " movq %%rax, %3 \n" + " movq %%rdx, %4 \n" + "Lendcall: \n" + + : : "g"((asQWORD)cnt), "g"(args), "g"(func), "m"(retQW1), "m"(retQW2), "m"(returnFloat) + : "%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7", + "%rdi", "%rsi", "%rax", "%rdx", "%rcx", "%r8", "%r9", "%r10", "%r11", "%r15"); + return retQW1; } // returns true if the given parameter is a 'variable argument' -static inline bool IsVariableArgument( asCDataType type ) +static inline bool IsVariableArgument(asCDataType type) { - return ( type.GetTokenType() == ttQuestion ) ? true : false; + return (type.GetTokenType() == ttQuestion) ? true : false; } asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &retQW2, void *secondObject) @@ -189,90 +190,90 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, int argIndex = 0; funcptr_t func = (funcptr_t)sysFunc->func; - if( sysFunc->hostReturnInMemory ) + if( sysFunc->hostReturnInMemory ) { // The return is made in memory callConv++; } -#ifdef AS_NO_THISCALL_FUNCTOR_METHOD + #ifdef AS_NO_THISCALL_FUNCTOR_METHOD // Determine the real function pointer in case of virtual method - if ( obj && ( callConv == ICC_VIRTUAL_THISCALL || callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM ) ) -#else - if ( obj && ( callConv == ICC_VIRTUAL_THISCALL || - callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || - callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJLAST || - callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM) ) -#endif + if( obj && (callConv == ICC_VIRTUAL_THISCALL || callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM) ) + #else + if( obj && (callConv == ICC_VIRTUAL_THISCALL || + callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || + callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL_OBJLAST || + callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM) ) + #endif { - vftable = *((funcptr_t**)obj); - func = vftable[FuncPtrToUInt(asFUNCTION_t(func)) >> 3]; + vftable = *((funcptr_t **)obj); + func = vftable[FuncPtrToUInt(asFUNCTION_t(func)) >> 3]; } - // Determine the type of the arguments, and prepare the input array for the X64_CallFunction - asQWORD paramBuffer[X64_CALLSTACK_SIZE] = { 0 }; - asBYTE argsType[X64_CALLSTACK_SIZE] = { 0 }; + // Determine the type of the arguments, and prepare the input array for the X64_CallFunction + asQWORD paramBuffer[X64_CALLSTACK_SIZE] = {0}; + asBYTE argsType[X64_CALLSTACK_SIZE] = {0}; -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" - switch ( callConv ) + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" + switch( callConv ) { case ICC_CDECL_RETURNINMEM: - case ICC_STDCALL_RETURNINMEM: + case ICC_STDCALL_RETURNINMEM: { paramBuffer[0] = (asPWORD)retPointer; - argsType[0] = x64INTARG; + argsType[0] = x64INTARG; argIndex = 1; break; } -#ifndef AS_NO_THISCALL_FUNCTOR_METHOD + #ifndef AS_NO_THISCALL_FUNCTOR_METHOD case ICC_THISCALL_OBJLAST: case ICC_VIRTUAL_THISCALL_OBJLAST: param_post = 2; - // fall through -#endif + // fall through + #endif case ICC_THISCALL: case ICC_VIRTUAL_THISCALL: - case ICC_CDECL_OBJFIRST: + case ICC_CDECL_OBJFIRST: { paramBuffer[0] = (asPWORD)obj; - argsType[0] = x64INTARG; + argsType[0] = x64INTARG; argIndex = 1; break; } -#ifndef AS_NO_THISCALL_FUNCTOR_METHOD + #ifndef AS_NO_THISCALL_FUNCTOR_METHOD case ICC_THISCALL_OBJLAST_RETURNINMEM: case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM: param_post = 2; - // fall through -#endif + // fall through + #endif case ICC_THISCALL_RETURNINMEM: case ICC_VIRTUAL_THISCALL_RETURNINMEM: - case ICC_CDECL_OBJFIRST_RETURNINMEM: + case ICC_CDECL_OBJFIRST_RETURNINMEM: { paramBuffer[0] = (asPWORD)retPointer; paramBuffer[1] = (asPWORD)obj; - argsType[0] = x64INTARG; - argsType[1] = x64INTARG; + argsType[0] = x64INTARG; + argsType[1] = x64INTARG; argIndex = 2; break; } -#ifndef AS_NO_THISCALL_FUNCTOR_METHOD + #ifndef AS_NO_THISCALL_FUNCTOR_METHOD case ICC_THISCALL_OBJFIRST: case ICC_VIRTUAL_THISCALL_OBJFIRST: { paramBuffer[0] = (asPWORD)obj; paramBuffer[1] = (asPWORD)secondObject; - argsType[0] = x64INTARG; - argsType[1] = x64INTARG; + argsType[0] = x64INTARG; + argsType[1] = x64INTARG; argIndex = 2; break; @@ -283,60 +284,60 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, paramBuffer[0] = (asPWORD)retPointer; paramBuffer[1] = (asPWORD)obj; paramBuffer[2] = (asPWORD)secondObject; - argsType[0] = x64INTARG; - argsType[1] = x64INTARG; - argsType[2] = x64INTARG; + argsType[0] = x64INTARG; + argsType[1] = x64INTARG; + argsType[2] = x64INTARG; argIndex = 3; break; } -#endif + #endif case ICC_CDECL_OBJLAST: param_post = 1; break; - case ICC_CDECL_OBJLAST_RETURNINMEM: + case ICC_CDECL_OBJLAST_RETURNINMEM: { paramBuffer[0] = (asPWORD)retPointer; - argsType[0] = x64INTARG; + argsType[0] = x64INTARG; - argIndex = 1; + argIndex = 1; param_post = 1; break; } } -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop - int argumentCount = ( int )descr->parameterTypes.GetLength(); - for( int a = 0; a < argumentCount; ++a ) + int argumentCount = (int)descr->parameterTypes.GetLength(); + for( int a = 0; a < argumentCount; ++a ) { const asCDataType &parmType = descr->parameterTypes[a]; - if( parmType.IsFloatType() && !parmType.IsReference() ) + if( parmType.IsFloatType() && !parmType.IsReference() ) { argsType[argIndex] = x64FLOATARG; memcpy(paramBuffer + argIndex, stack_pointer, sizeof(float)); argIndex++; stack_pointer++; } - else if( parmType.IsDoubleType() && !parmType.IsReference() ) + else if( parmType.IsDoubleType() && !parmType.IsReference() ) { argsType[argIndex] = x64FLOATARG; memcpy(paramBuffer + argIndex, stack_pointer, sizeof(double)); argIndex++; stack_pointer += 2; } - else if( IsVariableArgument( parmType ) ) + else if( IsVariableArgument(parmType) ) { // The variable args are really two, one pointer and one type id - argsType[argIndex] = x64INTARG; - argsType[argIndex+1] = x64INTARG; - memcpy(paramBuffer + argIndex, stack_pointer, sizeof(void*)); + argsType[argIndex] = x64INTARG; + argsType[argIndex + 1] = x64INTARG; + memcpy(paramBuffer + argIndex, stack_pointer, sizeof(void *)); memcpy(paramBuffer + argIndex + 1, stack_pointer + 2, sizeof(asDWORD)); - argIndex += 2; + argIndex += 2; stack_pointer += 3; } else if( parmType.IsPrimitive() || - parmType.IsReference() || + parmType.IsReference() || parmType.IsObjectHandle() ) { argsType[argIndex] = x64INTARG; @@ -369,19 +370,19 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // Copy the value of the object if( parmType.GetSizeInMemoryDWords() > 2 ) { - argsType[argIndex] = x64INTARG; - argsType[argIndex+1] = x64INTARG; - memcpy(paramBuffer + argIndex, *(asDWORD**)stack_pointer, parmType.GetSizeInMemoryBytes()); + argsType[argIndex] = x64INTARG; + argsType[argIndex + 1] = x64INTARG; + memcpy(paramBuffer + argIndex, *(asDWORD **)stack_pointer, parmType.GetSizeInMemoryBytes()); argIndex += 2; } else { argsType[argIndex] = x64INTARG; - memcpy(paramBuffer + argIndex, *(asDWORD**)stack_pointer, parmType.GetSizeInMemoryBytes()); + memcpy(paramBuffer + argIndex, *(asDWORD **)stack_pointer, parmType.GetSizeInMemoryBytes()); argIndex++; } // Delete the original memory - engine->CallFree(*(void**)stack_pointer); + engine->CallFree(*(void **)stack_pointer); } else if( (parmType.GetTypeInfo()->flags & asOBJ_APP_CLASS_ALLFLOATS) || (parmType.GetTypeInfo()->flags & asOBJ_APP_FLOAT) ) @@ -389,19 +390,19 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // Copy the value of the object if( parmType.GetSizeInMemoryDWords() > 2 ) { - argsType[argIndex] = x64FLOATARG; - argsType[argIndex+1] = x64FLOATARG; - memcpy(paramBuffer + argIndex, *(asDWORD**)stack_pointer, parmType.GetSizeInMemoryBytes()); + argsType[argIndex] = x64FLOATARG; + argsType[argIndex + 1] = x64FLOATARG; + memcpy(paramBuffer + argIndex, *(asDWORD **)stack_pointer, parmType.GetSizeInMemoryBytes()); argIndex += 2; } else { argsType[argIndex] = x64FLOATARG; - memcpy(paramBuffer + argIndex, *(asDWORD**)stack_pointer, parmType.GetSizeInMemoryBytes()); + memcpy(paramBuffer + argIndex, *(asDWORD **)stack_pointer, parmType.GetSizeInMemoryBytes()); argIndex++; } // Delete the original memory - engine->CallFree(*(void**)stack_pointer); + engine->CallFree(*(void **)stack_pointer); } stack_pointer += 2; } @@ -410,11 +411,11 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // For the CDECL_OBJ_LAST calling convention we need to add the object pointer as the last argument if( param_post ) { -#ifdef AS_NO_THISCALL_FUNCTOR_METHOD + #ifdef AS_NO_THISCALL_FUNCTOR_METHOD paramBuffer[argIndex] = (asPWORD)obj; -#else + #else paramBuffer[argIndex] = (asPWORD)(param_post > 1 ? secondObject : obj); -#endif + #endif argsType[argIndex] = x64INTARG; argIndex++; } @@ -440,48 +441,47 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, * in reverse order so that X64_CallFunction() can simply push them to the stack * without the need to perform further tests */ - asQWORD tempBuff[X64_CALLSTACK_SIZE] = { 0 }; - asBYTE argsSet[X64_CALLSTACK_SIZE] = { 0 }; - int used_int_regs = 0; - int used_sse_regs = 0; - int used_stack_args = 0; - int idx = 0; - for ( n = 0; ( n < totalArgumentCount ) && ( used_int_regs < MAX_CALL_INT_REGISTERS ); n++ ) + asQWORD tempBuff[X64_CALLSTACK_SIZE] = {0}; + asBYTE argsSet[X64_CALLSTACK_SIZE] = {0}; + int used_int_regs = 0; + int used_sse_regs = 0; + int used_stack_args = 0; + int idx = 0; + for( n = 0; (n < totalArgumentCount) && (used_int_regs < MAX_CALL_INT_REGISTERS); n++ ) { - if ( argsType[n] == x64INTARG ) + if( argsType[n] == x64INTARG ) { - argsSet[n] = 1; + argsSet[n] = 1; tempBuff[idx++] = paramBuffer[n]; used_int_regs++; } } idx = MAX_CALL_INT_REGISTERS; - for ( n = 0; ( n < totalArgumentCount ) && ( used_sse_regs < MAX_CALL_SSE_REGISTERS ); n++ ) + for( n = 0; (n < totalArgumentCount) && (used_sse_regs < MAX_CALL_SSE_REGISTERS); n++ ) { - if ( argsType[n] == x64FLOATARG ) + if( argsType[n] == x64FLOATARG ) { - argsSet[n] = 1; + argsSet[n] = 1; tempBuff[idx++] = paramBuffer[n]; used_sse_regs++; } } idx = MAX_CALL_INT_REGISTERS + MAX_CALL_SSE_REGISTERS; - for ( n = totalArgumentCount - 1; n >= 0; n-- ) + for( n = totalArgumentCount - 1; n >= 0; n-- ) { - if ( !argsSet[n] ) + if( !argsSet[n] ) { tempBuff[idx++] = paramBuffer[n]; used_stack_args++; } } - retQW = X64_CallFunction( tempBuff, used_stack_args, func, retQW2, sysFunc->hostReturnFloat ); + retQW = X64_CallFunction(tempBuff, used_stack_args, func, retQW2, sysFunc->hostReturnFloat); return retQW; } END_AS_NAMESPACE -#endif // AS_X64_GCC -#endif // AS_MAX_PORTABILITY - + #endif // AS_X64_GCC +#endif // AS_MAX_PORTABILITY diff --git a/sdk/angelscript/source/as_callfunc_x64_mingw.cpp b/sdk/angelscript/source/as_callfunc_x64_mingw.cpp index 98cc1c6b..3a4f6743 100644 --- a/sdk/angelscript/source/as_callfunc_x64_mingw.cpp +++ b/sdk/angelscript/source/as_callfunc_x64_mingw.cpp @@ -39,12 +39,12 @@ #include "as_config.h" #ifndef AS_MAX_PORTABILITY -#ifdef AS_X64_MINGW + #ifdef AS_X64_MINGW -#include "as_callfunc.h" -#include "as_scriptengine.h" -#include "as_texts.h" -#include "as_context.h" + #include "as_callfunc.h" + #include "as_scriptengine.h" + #include "as_texts.h" + #include "as_context.h" BEGIN_AS_NAMESPACE @@ -52,87 +52,86 @@ static asQWORD __attribute__((noinline)) CallX64(const asQWORD *args, const asQW { volatile asQWORD ret = 0; - __asm__ __volatile__ ( - "# Move the parameters into registers before the rsp is modified\n" - "mov %1, %%r10\n" // r10 = args - "mov %2, %%r11\n" // r11 = floatArgs - "xor %%r12, %%r12\n" - "mov %3, %%r12d\n" - "mov %4, %%r14\n" // r14 = func - - "# Store the stack pointer in r15 since it is guaranteed not to change over a function call\n" - "mov %%rsp, %%r15\n" - - "# Allocate space on the stack for the arguments\n" - "# Make room for at least 4 arguments even if there are less. When\n" - "# the compiler does optimizations for speed it may use these for \n" - "# temporary storage.\n" - "mov %%r12, %%rdi\n" - "add $32,%%edi\n" - - "# Make sure the stack pointer is 16byte aligned so the\n" - "# whole program optimizations will work properly\n" - "# TODO: runtime optimize: Can this be optimized with fewer instructions?\n" - "mov %%rsp,%%rsi\n" - "sub %%rdi,%%rsi\n" - "and $0x8,%%rsi\n" - "add %%rsi,%%rdi\n" - "sub %%rdi,%%rsp\n" - - "# Jump straight to calling the function if no parameters\n" - "cmp $0,%%r12 # Compare paramSize with 0\n" - "je callfunc # Jump to call funtion if (paramSize == 0)\n" - - "# Copy arguments from script stack to application stack\n" - "# Order is (first to last):\n" - "# rcx, rdx, r8, r9 & everything else goes on stack\n" - "movq (%%r10),%%rcx\n" - "movq 8(%%r10),%%rdx\n" - "movq 16(%%r10),%%r8\n" - "movq 24(%%r10),%%r9\n" - - "# Negate the 4 params from the size to be copied\n" - "sub $32,%%r12d\n" - "js copyfloat # Jump if negative result\n" - "jz copyfloat # Jump if zero result\n" - - "# Now copy all remaining params onto stack allowing space for first four\n" - "# params to be flushed back to the stack if required by the callee.\n" - "add $32,%%r10 # Position input pointer 4 args ahead\n" - "mov %%rsp,%%r13 # Put the stack pointer into r13\n" - "add $32,%%r13 # Leave space for first 4 args on stack\n" - - "copyoverflow:\n" - "movq (%%r10),%%rdi # Read param from source stack into rdi\n" - "movq %%rdi,(%%r13) # Copy param to real stack\n" - "add $8,%%r13 # Move virtual stack pointer\n" - "add $8,%%r10 # Move source stack pointer\n" - "sub $8,%%r12d # Decrement remaining count\n" - "jnz copyoverflow # Continue if more params\n" - - "copyfloat:\n" - "# Any floating point params?\n" - "cmp $0,%%r11\n" - "je callfunc\n" - - "movlpd (%%r11),%%xmm0\n" - "movlpd 8(%%r11),%%xmm1\n" - "movlpd 16(%%r11),%%xmm2\n" - "movlpd 24(%%r11),%%xmm3\n" - - "callfunc:\n" - "call *%%r14\n" - - "# restore stack pointer\n" - "mov %%r15, %%rsp\n" - - "lea %0, %%rbx\n" // Load the address of the ret variable into rbx - "movq %%rax,(%%rbx)\n" // Copy the returned value into the ret variable - - : // no output - : "m" (ret), "r" (args), "r" (floatArgs), "r" (paramSize), "r" (func) - : "rdi", "rsi", "rbx", "r10", "r11", "%r12", "r13", "r14", "r15" - ); + __asm__ __volatile__( + "# Move the parameters into registers before the rsp is modified\n" + "mov %1, %%r10\n" // r10 = args + "mov %2, %%r11\n" // r11 = floatArgs + "xor %%r12, %%r12\n" + "mov %3, %%r12d\n" + "mov %4, %%r14\n" // r14 = func + + "# Store the stack pointer in r15 since it is guaranteed not to change over a function call\n" + "mov %%rsp, %%r15\n" + + "# Allocate space on the stack for the arguments\n" + "# Make room for at least 4 arguments even if there are less. When\n" + "# the compiler does optimizations for speed it may use these for \n" + "# temporary storage.\n" + "mov %%r12, %%rdi\n" + "add $32,%%edi\n" + + "# Make sure the stack pointer is 16byte aligned so the\n" + "# whole program optimizations will work properly\n" + "# TODO: runtime optimize: Can this be optimized with fewer instructions?\n" + "mov %%rsp,%%rsi\n" + "sub %%rdi,%%rsi\n" + "and $0x8,%%rsi\n" + "add %%rsi,%%rdi\n" + "sub %%rdi,%%rsp\n" + + "# Jump straight to calling the function if no parameters\n" + "cmp $0,%%r12 # Compare paramSize with 0\n" + "je callfunc # Jump to call funtion if (paramSize == 0)\n" + + "# Copy arguments from script stack to application stack\n" + "# Order is (first to last):\n" + "# rcx, rdx, r8, r9 & everything else goes on stack\n" + "movq (%%r10),%%rcx\n" + "movq 8(%%r10),%%rdx\n" + "movq 16(%%r10),%%r8\n" + "movq 24(%%r10),%%r9\n" + + "# Negate the 4 params from the size to be copied\n" + "sub $32,%%r12d\n" + "js copyfloat # Jump if negative result\n" + "jz copyfloat # Jump if zero result\n" + + "# Now copy all remaining params onto stack allowing space for first four\n" + "# params to be flushed back to the stack if required by the callee.\n" + "add $32,%%r10 # Position input pointer 4 args ahead\n" + "mov %%rsp,%%r13 # Put the stack pointer into r13\n" + "add $32,%%r13 # Leave space for first 4 args on stack\n" + + "copyoverflow:\n" + "movq (%%r10),%%rdi # Read param from source stack into rdi\n" + "movq %%rdi,(%%r13) # Copy param to real stack\n" + "add $8,%%r13 # Move virtual stack pointer\n" + "add $8,%%r10 # Move source stack pointer\n" + "sub $8,%%r12d # Decrement remaining count\n" + "jnz copyoverflow # Continue if more params\n" + + "copyfloat:\n" + "# Any floating point params?\n" + "cmp $0,%%r11\n" + "je callfunc\n" + + "movlpd (%%r11),%%xmm0\n" + "movlpd 8(%%r11),%%xmm1\n" + "movlpd 16(%%r11),%%xmm2\n" + "movlpd 24(%%r11),%%xmm3\n" + + "callfunc:\n" + "call *%%r14\n" + + "# restore stack pointer\n" + "mov %%r15, %%rsp\n" + + "lea %0, %%rbx\n" // Load the address of the ret variable into rbx + "movq %%rax,(%%rbx)\n" // Copy the returned value into the ret variable + + : // no output + : "m"(ret), "r"(args), "r"(floatArgs), "r"(paramSize), "r"(func) + : "rdi", "rsi", "rbx", "r10", "r11", "%r12", "r13", "r14", "r15"); return ret; } @@ -141,13 +140,12 @@ static asDWORD GetReturnedFloat() { volatile asDWORD ret = 0; - __asm__ __volatile__ ( - "lea %0, %%rax\n" - "movss %%xmm0, (%%rax)" - : /* no output */ - : "m" (ret) - : "%rax" - ); + __asm__ __volatile__( + "lea %0, %%rax\n" + "movss %%xmm0, (%%rax)" + : /* no output */ + : "m"(ret) + : "%rax"); return ret; } @@ -156,29 +154,28 @@ static asQWORD GetReturnedDouble() { volatile asQWORD ret = 0; - __asm__ __volatile__ ( - "lea %0, %%rax\n" - "movlpd %%xmm0, (%%rax)" - : /* no optput */ - : "m" (ret) - : "%rax" - ); + __asm__ __volatile__( + "lea %0, %%rax\n" + "movlpd %%xmm0, (%%rax)" + : /* no optput */ + : "m"(ret) + : "%rax"); return ret; } -asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &/*retQW2*/, void *secondObject) +asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD & /*retQW2*/, void *secondObject) { - asCScriptEngine *engine = context->m_engine; + asCScriptEngine *engine = context->m_engine; asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; - asQWORD retQW = 0; - void *func = (void*)sysFunc->func; - asUINT paramSize = 0; // QWords - void **vftable; + asQWORD retQW = 0; + void *func = (void *)sysFunc->func; + asUINT paramSize = 0; // QWords + void **vftable; - asQWORD allArgBuffer[64]; - asQWORD floatArgBuffer[4]; + asQWORD allArgBuffer[64]; + asQWORD floatArgBuffer[4]; int callConv = sysFunc->callConv; @@ -191,53 +188,53 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, allArgBuffer[paramSize++] = (asQWORD)retPointer; } -#ifdef AS_NO_THISCALL_FUNCTOR_METHOD + #ifdef AS_NO_THISCALL_FUNCTOR_METHOD if( callConv == ICC_THISCALL || - callConv == ICC_THISCALL_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL || - callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM ) -#else + callConv == ICC_THISCALL_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL || + callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM ) + #else // Optimization to avoid check 12 values (all ICC_ that contains THISCALL) if( (callConv >= ICC_THISCALL && callConv <= ICC_VIRTUAL_THISCALL_RETURNINMEM) || - (callConv >= ICC_THISCALL_OBJLAST && callConv <= ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM) ) -#endif + (callConv >= ICC_THISCALL_OBJLAST && callConv <= ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM) ) + #endif { // Add the object pointer as the first parameter allArgBuffer[paramSize++] = (asQWORD)obj; } if( callConv == ICC_CDECL_OBJFIRST || - callConv == ICC_CDECL_OBJFIRST_RETURNINMEM ) + callConv == ICC_CDECL_OBJFIRST_RETURNINMEM ) { // Add the object pointer as the first parameter allArgBuffer[paramSize++] = (asQWORD)obj; } -#ifndef AS_NO_THISCALL_FUNCTOR_METHOD + #ifndef AS_NO_THISCALL_FUNCTOR_METHOD else if( callConv == ICC_THISCALL_OBJFIRST || - callConv == ICC_THISCALL_OBJFIRST_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || - callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM ) + callConv == ICC_THISCALL_OBJFIRST_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || + callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM ) { // Add the object pointer as the first parameter allArgBuffer[paramSize++] = (asQWORD)secondObject; } -#endif + #endif -#ifdef AS_NO_THISCALL_FUNCTOR_METHOD + #ifdef AS_NO_THISCALL_FUNCTOR_METHOD if( callConv == ICC_VIRTUAL_THISCALL || - callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM ) -#else + callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM ) + #else if( callConv == ICC_VIRTUAL_THISCALL || - callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || - callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJLAST || - callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) -#endif + callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || + callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL_OBJLAST || + callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) + #endif { // Get the true function pointer from the virtual function table - vftable = *(void***)obj; - func = vftable[asPWORD(func)>>3]; + vftable = *(void ***)obj; + func = vftable[asPWORD(func) >> 3]; } // Move the arguments to the buffer @@ -248,33 +245,33 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, if( descr->parameterTypes[n].IsObject() && !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() ) { if( descr->parameterTypes[n].GetSizeInMemoryDWords() >= AS_LARGE_OBJ_MIN_SIZE || - (descr->parameterTypes[n].GetTypeInfo()->flags & COMPLEX_MASK) ) + (descr->parameterTypes[n].GetTypeInfo()->flags & COMPLEX_MASK) ) { - allArgBuffer[dpos++] = *(asQWORD*)&args[spos]; - spos += AS_PTR_SIZE; + allArgBuffer[dpos++] = *(asQWORD *)&args[spos]; + spos += AS_PTR_SIZE; paramSize++; } else { // Copy the object's memory to the buffer - memcpy(&allArgBuffer[dpos], *(void**)(args+spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); + memcpy(&allArgBuffer[dpos], *(void **)(args + spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); // Delete the original memory - engine->CallFree(*(char**)(args+spos)); - spos += AS_PTR_SIZE; - asUINT dwords = descr->parameterTypes[n].GetSizeInMemoryDWords(); - asUINT qwords = (dwords >> 1) + (dwords & 1); - dpos += qwords; - paramSize += qwords; + engine->CallFree(*(char **)(args + spos)); + spos += AS_PTR_SIZE; + asUINT dwords = descr->parameterTypes[n].GetSizeInMemoryDWords(); + asUINT qwords = (dwords >> 1) + (dwords & 1); + dpos += qwords; + paramSize += qwords; } } else if( descr->parameterTypes[n].GetTokenType() == ttQuestion ) { // Copy the reference and the type id - allArgBuffer[dpos++] = *(asQWORD*)&args[spos]; - spos += 2; - allArgBuffer[dpos++] = args[spos++]; - paramSize += 2; + allArgBuffer[dpos++] = *(asQWORD *)&args[spos]; + spos += 2; + allArgBuffer[dpos++] = args[spos++]; + paramSize += 2; } else { @@ -282,12 +279,12 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, asUINT dwords = descr->parameterTypes[n].GetSizeOnStackDWords(); if( dwords > 1 ) { - allArgBuffer[dpos] = *(asQWORD*)&args[spos]; + allArgBuffer[dpos] = *(asQWORD *)&args[spos]; // Double arguments are moved to a separate buffer in order to be placed in the XMM registers, // though this is only done for first 4 arguments, the rest are placed on the stack if( paramSize < 4 && descr->parameterTypes[n].IsDoubleType() ) - floatArgBuffer[dpos] = *(asQWORD*)&args[spos]; + floatArgBuffer[dpos] = *(asQWORD *)&args[spos]; dpos++; spos += 2; @@ -310,29 +307,29 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, } if( callConv == ICC_CDECL_OBJLAST || - callConv == ICC_CDECL_OBJLAST_RETURNINMEM ) + callConv == ICC_CDECL_OBJLAST_RETURNINMEM ) { // Add the object pointer as the last parameter allArgBuffer[paramSize++] = (asQWORD)obj; } -#ifndef AS_NO_THISCALL_FUNCTOR_METHOD + #ifndef AS_NO_THISCALL_FUNCTOR_METHOD else if( callConv == ICC_THISCALL_OBJLAST || - callConv == ICC_THISCALL_OBJLAST_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJLAST || - callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) + callConv == ICC_THISCALL_OBJLAST_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL_OBJLAST || + callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) { // Add the object pointer as the last parameter allArgBuffer[paramSize++] = (asQWORD)secondObject; } -#endif + #endif - retQW = CallX64(allArgBuffer, floatArgBuffer, paramSize*8, (asPWORD)func); + retQW = CallX64(allArgBuffer, floatArgBuffer, paramSize * 8, (asPWORD)func); // If the return is a float value we need to get the value from the FP register if( sysFunc->hostReturnFloat ) { if( sysFunc->hostReturnSize == 1 ) - *(asDWORD*)&retQW = GetReturnedFloat(); + *(asDWORD *)&retQW = GetReturnedFloat(); else retQW = GetReturnedDouble(); } @@ -342,7 +339,5 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, END_AS_NAMESPACE -#endif // AS_X64_MSVC -#endif // AS_MAX_PORTABILITY - - + #endif // AS_X64_MSVC +#endif // AS_MAX_PORTABILITY diff --git a/sdk/angelscript/source/as_callfunc_x64_msvc.cpp b/sdk/angelscript/source/as_callfunc_x64_msvc.cpp index 8af5adc0..818dcebb 100644 --- a/sdk/angelscript/source/as_callfunc_x64_msvc.cpp +++ b/sdk/angelscript/source/as_callfunc_x64_msvc.cpp @@ -37,12 +37,12 @@ #include "as_config.h" #ifndef AS_MAX_PORTABILITY -#ifdef AS_X64_MSVC + #ifdef AS_X64_MSVC -#include "as_callfunc.h" -#include "as_scriptengine.h" -#include "as_texts.h" -#include "as_context.h" + #include "as_callfunc.h" + #include "as_scriptengine.h" + #include "as_texts.h" + #include "as_context.h" BEGIN_AS_NAMESPACE @@ -51,24 +51,24 @@ extern "C" asQWORD CallX64(const asQWORD *args, const asQWORD *floatArgs, int pa extern "C" asDWORD GetReturnedFloat(); extern "C" asQWORD GetReturnedDouble(); -asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &/*retQW2*/, void *secondObject) +asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD & /*retQW2*/, void *secondObject) { - asCScriptEngine *engine = context->m_engine; + asCScriptEngine *engine = context->m_engine; asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; - asQWORD retQW = 0; - void *func = (void*)sysFunc->func; - asUINT paramSize = 0; // QWords - void **vftable; + asQWORD retQW = 0; + void *func = (void *)sysFunc->func; + asUINT paramSize = 0; // QWords + void **vftable; - asQWORD allArgBuffer[64]; - asQWORD floatArgBuffer[4]; + asQWORD allArgBuffer[64]; + asQWORD floatArgBuffer[4]; int callConv = sysFunc->callConv; // Optimization to avoid check 12 values (all ICC_ that contains THISCALL) if( (callConv >= ICC_THISCALL && callConv <= ICC_VIRTUAL_THISCALL_RETURNINMEM) || - (callConv >= ICC_THISCALL_OBJLAST && callConv <= ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM) ) + (callConv >= ICC_THISCALL_OBJLAST && callConv <= ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM) ) { // Add the object pointer as the first parameter allArgBuffer[paramSize++] = (asQWORD)obj; @@ -84,30 +84,30 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, } if( callConv == ICC_CDECL_OBJFIRST || - callConv == ICC_CDECL_OBJFIRST_RETURNINMEM ) + callConv == ICC_CDECL_OBJFIRST_RETURNINMEM ) { // Add the object pointer as the first parameter allArgBuffer[paramSize++] = (asQWORD)obj; } else if( callConv == ICC_THISCALL_OBJFIRST || - callConv == ICC_THISCALL_OBJFIRST_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || - callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM ) + callConv == ICC_THISCALL_OBJFIRST_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || + callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM ) { // Add the object pointer as the first parameter allArgBuffer[paramSize++] = (asQWORD)secondObject; } if( callConv == ICC_VIRTUAL_THISCALL || - callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || - callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJLAST || - callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) + callConv == ICC_VIRTUAL_THISCALL_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL_OBJFIRST || + callConv == ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL_OBJLAST || + callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) { // Get the true function pointer from the virtual function table - vftable = *(void***)obj; - func = vftable[asPWORD(func)>>2]; + vftable = *(void ***)obj; + func = vftable[asPWORD(func) >> 2]; } // Move the arguments to the buffer @@ -119,33 +119,33 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, if( dt.IsObject() && !dt.IsObjectHandle() && !dt.IsReference() ) { if( dt.GetSizeInMemoryDWords() >= AS_LARGE_OBJ_MIN_SIZE || - (dt.GetTypeInfo()->flags & COMPLEX_MASK) ) + (dt.GetTypeInfo()->flags & COMPLEX_MASK) ) { - allArgBuffer[dpos++] = *(asQWORD*)&args[spos]; - spos += AS_PTR_SIZE; + allArgBuffer[dpos++] = *(asQWORD *)&args[spos]; + spos += AS_PTR_SIZE; paramSize++; } else { // Copy the object's memory to the buffer - memcpy(&allArgBuffer[dpos], *(void**)(args+spos), dt.GetSizeInMemoryBytes()); + memcpy(&allArgBuffer[dpos], *(void **)(args + spos), dt.GetSizeInMemoryBytes()); // Delete the original memory - engine->CallFree(*(char**)(args+spos)); - spos += AS_PTR_SIZE; - asUINT dwords = dt.GetSizeInMemoryDWords(); - asUINT qwords = (dwords >> 1) + (dwords & 1); - dpos += qwords; - paramSize += qwords; + engine->CallFree(*(char **)(args + spos)); + spos += AS_PTR_SIZE; + asUINT dwords = dt.GetSizeInMemoryDWords(); + asUINT qwords = (dwords >> 1) + (dwords & 1); + dpos += qwords; + paramSize += qwords; } } else if( dt.GetTokenType() == ttQuestion ) { // Copy the reference and the type id - allArgBuffer[dpos++] = *(asQWORD*)&args[spos]; - spos += 2; - allArgBuffer[dpos++] = args[spos++]; - paramSize += 2; + allArgBuffer[dpos++] = *(asQWORD *)&args[spos]; + spos += 2; + allArgBuffer[dpos++] = args[spos++]; + paramSize += 2; } else { @@ -153,12 +153,12 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, asUINT dwords = dt.GetSizeOnStackDWords(); if( dwords > 1 ) { - allArgBuffer[dpos] = *(asQWORD*)&args[spos]; + allArgBuffer[dpos] = *(asQWORD *)&args[spos]; // Double arguments are moved to a separate buffer in order to be placed in the XMM registers, // though this is only done for first 4 arguments, the rest are placed on the stack if( paramSize < 4 && dt.IsDoubleType() ) - floatArgBuffer[dpos] = *(asQWORD*)&args[spos]; + floatArgBuffer[dpos] = *(asQWORD *)&args[spos]; dpos++; spos += 2; @@ -171,7 +171,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // though this is only done for first 4 arguments, the rest are placed on the stack if( paramSize < 4 && dt.IsFloatType() ) floatArgBuffer[dpos] = args[spos]; - + dpos++; spos++; } @@ -181,27 +181,27 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, } if( callConv == ICC_CDECL_OBJLAST || - callConv == ICC_CDECL_OBJLAST_RETURNINMEM ) + callConv == ICC_CDECL_OBJLAST_RETURNINMEM ) { // Add the object pointer as the last parameter allArgBuffer[paramSize++] = (asQWORD)obj; } else if( callConv == ICC_THISCALL_OBJLAST || - callConv == ICC_THISCALL_OBJLAST_RETURNINMEM || - callConv == ICC_VIRTUAL_THISCALL_OBJLAST || - callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) + callConv == ICC_THISCALL_OBJLAST_RETURNINMEM || + callConv == ICC_VIRTUAL_THISCALL_OBJLAST || + callConv == ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM ) { // Add the object pointer as the last parameter allArgBuffer[paramSize++] = (asQWORD)secondObject; } - retQW = CallX64(allArgBuffer, floatArgBuffer, paramSize*8, (asPWORD)func); + retQW = CallX64(allArgBuffer, floatArgBuffer, paramSize * 8, (asPWORD)func); // If the return is a float value we need to get the value from the FP register if( sysFunc->hostReturnFloat ) { if( sysFunc->hostReturnSize == 1 ) - *(asDWORD*)&retQW = GetReturnedFloat(); + *(asDWORD *)&retQW = GetReturnedFloat(); else retQW = GetReturnedDouble(); } @@ -211,7 +211,5 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, END_AS_NAMESPACE -#endif // AS_X64_MSVC -#endif // AS_MAX_PORTABILITY - - + #endif // AS_X64_MSVC +#endif // AS_MAX_PORTABILITY diff --git a/sdk/angelscript/source/as_callfunc_x86.cpp b/sdk/angelscript/source/as_callfunc_x86.cpp index 551f41a1..0e44bf7c 100644 --- a/sdk/angelscript/source/as_callfunc_x86.cpp +++ b/sdk/angelscript/source/as_callfunc_x86.cpp @@ -42,38 +42,38 @@ #include "as_config.h" #ifndef AS_MAX_PORTABILITY -#ifdef AS_X86 + #ifdef AS_X86 -#include "as_callfunc.h" -#include "as_scriptengine.h" -#include "as_texts.h" -#include "as_tokendef.h" -#include "as_context.h" + #include "as_callfunc.h" + #include "as_scriptengine.h" + #include "as_texts.h" + #include "as_tokendef.h" + #include "as_context.h" BEGIN_AS_NAMESPACE -// -// With some compile level optimizations the functions don't clear the FPU -// stack themselves. So we have to do it as part of calling the native functions, -// as the compiler will not be able to predict when it is supposed to do it by -// itself due to the dynamic nature of scripts -// -// - fninit clears the FPU stack and the FPU control word -// - emms only clears the FPU stack, while preserving the FPU control word -// -// By default I use fninit as it seems to be what works for most people, -// but some may find it necessary to define this as emms instead. -// -// TODO: Figure out when one or the other must be used, and a way to -// configure this automatically in as_config.h -// -#ifndef CLEAR_FPU_STACK -#define CLEAR_FPU_STACK fninit -#endif - -// These macros are just to allow me to use the above macro in the GNUC style inline assembly -#define _S(x) _TOSTRING(x) -#define _TOSTRING(x) #x + // + // With some compile level optimizations the functions don't clear the FPU + // stack themselves. So we have to do it as part of calling the native functions, + // as the compiler will not be able to predict when it is supposed to do it by + // itself due to the dynamic nature of scripts + // + // - fninit clears the FPU stack and the FPU control word + // - emms only clears the FPU stack, while preserving the FPU control word + // + // By default I use fninit as it seems to be what works for most people, + // but some may find it necessary to define this as emms instead. + // + // TODO: Figure out when one or the other must be used, and a way to + // configure this automatically in as_config.h + // + #ifndef CLEAR_FPU_STACK + #define CLEAR_FPU_STACK fninit + #endif + + // These macros are just to allow me to use the above macro in the GNUC style inline assembly + #define _S(x) _TOSTRING(x) + #define _TOSTRING(x) #x // Prototypes asQWORD CallCDeclFunction(const asDWORD *args, int paramSize, asFUNCTION_t func); @@ -89,28 +89,28 @@ asQWORD CallThisCallFunctionRetByRef(const void *, const asDWORD *, int, asFUNCT asDWORD GetReturnedFloat(); asQWORD GetReturnedDouble(); -asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &/*retQW2*/, void *secondObject) +asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD & /*retQW2*/, void *secondObject) { - asCScriptEngine *engine = context->m_engine; - asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; + asCScriptEngine *engine = context->m_engine; + asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; asQWORD retQW = 0; // Prepare the parameters asDWORD paramBuffer[64]; - int callConv = sysFunc->callConv; + int callConv = sysFunc->callConv; // Changed because need check for ICC_THISCALL_OBJFIRST or // ICC_THISCALL_OBJLAST if sysFunc->takesObjByVal (avoid copy code) // Check if is THISCALL_OBJ* calling convention (in this case needs to add secondObject pointer into stack). bool isThisCallMethod = callConv >= ICC_THISCALL_OBJLAST; - int paramSize = isThisCallMethod || sysFunc->takesObjByVal ? 0 : sysFunc->paramSize; + int paramSize = isThisCallMethod || sysFunc->takesObjByVal ? 0 : sysFunc->paramSize; int dpos = 1; if( isThisCallMethod && - (callConv >= ICC_THISCALL_OBJFIRST && - callConv <= ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM) ) + (callConv >= ICC_THISCALL_OBJFIRST && + callConv <= ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM) ) { // Add the object pointer as the first parameter paramBuffer[dpos++] = (asDWORD)secondObject; @@ -125,14 +125,14 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, { if( descr->parameterTypes[n].IsObject() && !descr->parameterTypes[n].IsObjectHandle() && !descr->parameterTypes[n].IsReference() ) { -#ifdef COMPLEX_OBJS_PASSED_BY_REF + #ifdef COMPLEX_OBJS_PASSED_BY_REF if( descr->parameterTypes[n].GetTypeInfo()->flags & COMPLEX_MASK ) { paramBuffer[dpos++] = args[spos++]; paramSize++; } else -#endif + #endif { // Copy the object's memory to the buffer // TODO: bug: Must call the object's copy constructor instead of doing a memcpy, @@ -143,12 +143,12 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // position and copy the values directly to that location. The assembler // routines then don't need to copy anything, and will just be // responsible for setting up the registers and the stack frame appropriately. - memcpy(¶mBuffer[dpos], *(void**)(args+spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); + memcpy(¶mBuffer[dpos], *(void **)(args + spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); // Delete the original memory - engine->CallFree(*(char**)(args+spos)); + engine->CallFree(*(char **)(args + spos)); spos++; - dpos += descr->parameterTypes[n].GetSizeInMemoryDWords(); + dpos += descr->parameterTypes[n].GetSizeInMemoryDWords(); paramSize += descr->parameterTypes[n].GetSizeInMemoryDWords(); } } @@ -166,8 +166,8 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, } if( isThisCallMethod && - (callConv >= ICC_THISCALL_OBJLAST && - callConv <= ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM) ) + (callConv >= ICC_THISCALL_OBJLAST && + callConv <= ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM) ) { // Add the object pointer as the last parameter paramBuffer[dpos++] = (asDWORD)secondObject; @@ -181,87 +181,87 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, switch( callConv ) { - case ICC_CDECL: - retQW = CallCDeclFunction(args, paramSize<<2, func); - break; - - case ICC_CDECL_RETURNINMEM: - retQW = CallCDeclFunctionRetByRef(args, paramSize<<2, func, retPointer); - break; - - case ICC_STDCALL: - retQW = CallSTDCallFunction(args, paramSize<<2, func); - break; - - case ICC_STDCALL_RETURNINMEM: - // Push the return pointer on the stack - paramSize++; - args--; - *(asPWORD*)args = (size_t)retPointer; - - retQW = CallSTDCallFunction(args, paramSize<<2, func); - break; - - case ICC_THISCALL: - case ICC_THISCALL_OBJFIRST: - case ICC_THISCALL_OBJLAST: - retQW = CallThisCallFunction(obj, args, paramSize<<2, func); - break; - - case ICC_THISCALL_RETURNINMEM: - case ICC_THISCALL_OBJFIRST_RETURNINMEM: - case ICC_THISCALL_OBJLAST_RETURNINMEM: - retQW = CallThisCallFunctionRetByRef(obj, args, paramSize<<2, func, retPointer); - break; - - case ICC_VIRTUAL_THISCALL: - case ICC_VIRTUAL_THISCALL_OBJFIRST: - case ICC_VIRTUAL_THISCALL_OBJLAST: + case ICC_CDECL: + retQW = CallCDeclFunction(args, paramSize << 2, func); + break; + + case ICC_CDECL_RETURNINMEM: + retQW = CallCDeclFunctionRetByRef(args, paramSize << 2, func, retPointer); + break; + + case ICC_STDCALL: + retQW = CallSTDCallFunction(args, paramSize << 2, func); + break; + + case ICC_STDCALL_RETURNINMEM: + // Push the return pointer on the stack + paramSize++; + args--; + *(asPWORD *)args = (size_t)retPointer; + + retQW = CallSTDCallFunction(args, paramSize << 2, func); + break; + + case ICC_THISCALL: + case ICC_THISCALL_OBJFIRST: + case ICC_THISCALL_OBJLAST: + retQW = CallThisCallFunction(obj, args, paramSize << 2, func); + break; + + case ICC_THISCALL_RETURNINMEM: + case ICC_THISCALL_OBJFIRST_RETURNINMEM: + case ICC_THISCALL_OBJLAST_RETURNINMEM: + retQW = CallThisCallFunctionRetByRef(obj, args, paramSize << 2, func, retPointer); + break; + + case ICC_VIRTUAL_THISCALL: + case ICC_VIRTUAL_THISCALL_OBJFIRST: + case ICC_VIRTUAL_THISCALL_OBJLAST: { // Get virtual function table from the object pointer - asFUNCTION_t *vftable = *(asFUNCTION_t**)obj; - retQW = CallThisCallFunction(obj, args, paramSize<<2, vftable[FuncPtrToUInt(func)>>2]); + asFUNCTION_t *vftable = *(asFUNCTION_t **)obj; + retQW = CallThisCallFunction(obj, args, paramSize << 2, vftable[FuncPtrToUInt(func) >> 2]); } break; - case ICC_VIRTUAL_THISCALL_RETURNINMEM: - case ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM: - case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM: + case ICC_VIRTUAL_THISCALL_RETURNINMEM: + case ICC_VIRTUAL_THISCALL_OBJFIRST_RETURNINMEM: + case ICC_VIRTUAL_THISCALL_OBJLAST_RETURNINMEM: { // Get virtual function table from the object pointer - asFUNCTION_t *vftable = *(asFUNCTION_t**)obj; - retQW = CallThisCallFunctionRetByRef(obj, args, paramSize<<2, vftable[FuncPtrToUInt(func)>>2], retPointer); + asFUNCTION_t *vftable = *(asFUNCTION_t **)obj; + retQW = CallThisCallFunctionRetByRef(obj, args, paramSize << 2, vftable[FuncPtrToUInt(func) >> 2], retPointer); } break; - case ICC_CDECL_OBJLAST: - retQW = CallCDeclFunctionObjLast(obj, args, paramSize<<2, func); - break; + case ICC_CDECL_OBJLAST: + retQW = CallCDeclFunctionObjLast(obj, args, paramSize << 2, func); + break; - case ICC_CDECL_OBJLAST_RETURNINMEM: - // Call the system object method as a cdecl with the obj ref as the last parameter - retQW = CallCDeclFunctionRetByRefObjLast(obj, args, paramSize<<2, func, retPointer); - break; + case ICC_CDECL_OBJLAST_RETURNINMEM: + // Call the system object method as a cdecl with the obj ref as the last parameter + retQW = CallCDeclFunctionRetByRefObjLast(obj, args, paramSize << 2, func, retPointer); + break; - case ICC_CDECL_OBJFIRST: - // Call the system object method as a cdecl with the obj ref as the first parameter - retQW = CallCDeclFunctionObjFirst(obj, args, paramSize<<2, func); - break; + case ICC_CDECL_OBJFIRST: + // Call the system object method as a cdecl with the obj ref as the first parameter + retQW = CallCDeclFunctionObjFirst(obj, args, paramSize << 2, func); + break; - case ICC_CDECL_OBJFIRST_RETURNINMEM: - // Call the system object method as a cdecl with the obj ref as the first parameter - retQW = CallCDeclFunctionRetByRefObjFirst(obj, args, paramSize<<2, func, retPointer); - break; + case ICC_CDECL_OBJFIRST_RETURNINMEM: + // Call the system object method as a cdecl with the obj ref as the first parameter + retQW = CallCDeclFunctionRetByRefObjFirst(obj, args, paramSize << 2, func, retPointer); + break; - default: - context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); + default: + context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); } // If the return is a float value we need to get the value from the FP register if( sysFunc->hostReturnFloat ) { if( sysFunc->hostReturnSize == 1 ) - *(asDWORD*)&retQW = GetReturnedFloat(); + *(asDWORD *)&retQW = GetReturnedFloat(); else retQW = GetReturnedDouble(); } @@ -269,21 +269,21 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, return retQW; } -// On GCC we need to prevent the compiler from inlining these assembler routines when -// optimizing for speed (-O3), as the loop labels get duplicated which cause compile errors. + // On GCC we need to prevent the compiler from inlining these assembler routines when + // optimizing for speed (-O3), as the loop labels get duplicated which cause compile errors. -#ifdef __GNUC__ - #define NOINLINE __attribute ((__noinline__)) -#else - #define NOINLINE -#endif + #ifdef __GNUC__ + #define NOINLINE __attribute((__noinline__)) + #else + #define NOINLINE + #endif asQWORD NOINLINE CallCDeclFunction(const asDWORD *args, int paramSize, asFUNCTION_t func) { volatile asQWORD retQW = 0; -#if defined ASM_INTEL + #if defined ASM_INTEL // Copy the data to the real stack. If we fail to do // this we may run into trouble in case of exceptions. @@ -292,11 +292,11 @@ asQWORD NOINLINE CallCDeclFunction(const asDWORD *args, int paramSize, asFUNCTIO // We must save registers that are used push ecx - // Clear the FPU stack, in case the called function doesn't do it by itself + // Clear the FPU stack, in case the called function doesn't do it by itself CLEAR_FPU_STACK - // Copy arguments from script - // stack to application stack + // Copy arguments from script + // stack to application stack mov ecx, paramSize mov eax, args add eax, ecx @@ -315,16 +315,16 @@ asQWORD NOINLINE CallCDeclFunction(const asDWORD *args, int paramSize, asFUNCTIO // Pop arguments from stack add esp, paramSize - // Copy return value from EAX:EDX + // Copy return value from EAX:EDX lea ecx, retQW mov [ecx], eax mov 4[ecx], edx - // Restore registers + // Restore registers pop ecx } -#elif defined ASM_AT_N_T + #elif defined ASM_AT_N_T // It is not possible to rely on ESP or BSP to refer to variables or arguments on the stack // depending on compiler settings BSP may not even be used, and the ESP is not always on the @@ -340,70 +340,70 @@ asQWORD NOINLINE CallCDeclFunction(const asDWORD *args, int paramSize, asFUNCTIO volatile asPWORD a[] = {asPWORD(args), asPWORD(paramSize), asPWORD(func)}; asm __volatile__( -#ifdef __OPTIMIZE__ - // When compiled with optimizations the stack unwind doesn't work properly, - // causing exceptions to crash the application. By adding this prologue - // and the epilogue below, the stack unwind works as it should. - // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below - "pushl %%ebp \n" - ".cfi_adjust_cfa_offset 4 \n" - ".cfi_rel_offset ebp, 0 \n" - "movl %%esp, %%ebp \n" - ".cfi_def_cfa_register ebp \n" -#endif - _S(CLEAR_FPU_STACK) "\n" - "pushl %%ebx \n" - "movl %%edx, %%ebx \n" - - // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. - // It is assumed that when entering this function, the stack pointer is already aligned, so we need - // to calculate how much we will put on the stack during this call. - "movl 4(%%ebx), %%eax \n" // paramSize - "addl $4, %%eax \n" // counting esp that we will push on the stack - "movl %%esp, %%ecx \n" - "subl %%eax, %%ecx \n" - "andl $15, %%ecx \n" - "movl %%esp, %%eax \n" - "subl %%ecx, %%esp \n" - "pushl %%eax \n" // Store the original stack pointer - - // Copy all arguments to the stack and call the function - "movl 4(%%ebx), %%ecx \n" // paramSize - "movl 0(%%ebx), %%eax \n" // args - "addl %%ecx, %%eax \n" // push arguments on the stack - "cmp $0, %%ecx \n" - "je endcopy \n" - "copyloop: \n" - "subl $4, %%eax \n" - "pushl (%%eax) \n" - "subl $4, %%ecx \n" - "jne copyloop \n" - "endcopy: \n" - "call *8(%%ebx) \n" - "addl 4(%%ebx), %%esp \n" // pop arguments - - // Pop the alignment bytes - "popl %%esp \n" - "popl %%ebx \n" -#ifdef __OPTIMIZE__ - // Epilogue - "movl %%ebp, %%esp \n" - ".cfi_def_cfa_register esp \n" - "popl %%ebp \n" - ".cfi_adjust_cfa_offset -4 \n" - ".cfi_restore ebp \n" -#endif - // Copy EAX:EDX to retQW. As the stack pointer has been - // restored it is now safe to access the local variable - "leal %1, %%ecx \n" - "movl %%eax, 0(%%ecx) \n" - "movl %%edx, 4(%%ecx) \n" - : // output - : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument - : "%eax", "%ecx" // clobber - ); - -#endif + #ifdef __OPTIMIZE__ + // When compiled with optimizations the stack unwind doesn't work properly, + // causing exceptions to crash the application. By adding this prologue + // and the epilogue below, the stack unwind works as it should. + // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below + "pushl %%ebp \n" + ".cfi_adjust_cfa_offset 4 \n" + ".cfi_rel_offset ebp, 0 \n" + "movl %%esp, %%ebp \n" + ".cfi_def_cfa_register ebp \n" + #endif + _S(CLEAR_FPU_STACK) "\n" + "pushl %%ebx \n" + "movl %%edx, %%ebx \n" + + // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. + // It is assumed that when entering this function, the stack pointer is already aligned, so we need + // to calculate how much we will put on the stack during this call. + "movl 4(%%ebx), %%eax \n" // paramSize + "addl $4, %%eax \n" // counting esp that we will push on the stack + "movl %%esp, %%ecx \n" + "subl %%eax, %%ecx \n" + "andl $15, %%ecx \n" + "movl %%esp, %%eax \n" + "subl %%ecx, %%esp \n" + "pushl %%eax \n" // Store the original stack pointer + + // Copy all arguments to the stack and call the function + "movl 4(%%ebx), %%ecx \n" // paramSize + "movl 0(%%ebx), %%eax \n" // args + "addl %%ecx, %%eax \n" // push arguments on the stack + "cmp $0, %%ecx \n" + "je endcopy \n" + "copyloop: \n" + "subl $4, %%eax \n" + "pushl (%%eax) \n" + "subl $4, %%ecx \n" + "jne copyloop \n" + "endcopy: \n" + "call *8(%%ebx) \n" + "addl 4(%%ebx), %%esp \n" // pop arguments + + // Pop the alignment bytes + "popl %%esp \n" + "popl %%ebx \n" + #ifdef __OPTIMIZE__ + // Epilogue + "movl %%ebp, %%esp \n" + ".cfi_def_cfa_register esp \n" + "popl %%ebp \n" + ".cfi_adjust_cfa_offset -4 \n" + ".cfi_restore ebp \n" + #endif + // Copy EAX:EDX to retQW. As the stack pointer has been + // restored it is now safe to access the local variable + "leal %1, %%ecx \n" + "movl %%eax, 0(%%ecx) \n" + "movl %%edx, 4(%%ecx) \n" + : // output + : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument + : "%eax", "%ecx" // clobber + ); + + #endif return retQW; } @@ -412,7 +412,7 @@ asQWORD NOINLINE CallCDeclFunctionObjLast(const void *obj, const asDWORD *args, { volatile asQWORD retQW = 0; -#if defined ASM_INTEL + #if defined ASM_INTEL // Copy the data to the real stack. If we fail to do // this we may run into trouble in case of exceptions. @@ -421,14 +421,14 @@ asQWORD NOINLINE CallCDeclFunctionObjLast(const void *obj, const asDWORD *args, // We must save registers that are used push ecx - // Clear the FPU stack, in case the called function doesn't do it by itself + // Clear the FPU stack, in case the called function doesn't do it by itself CLEAR_FPU_STACK - // Push the object pointer as the last argument to the function + // Push the object pointer as the last argument to the function push obj - // Copy arguments from script - // stack to application stack + // Copy arguments from script + // stack to application stack mov ecx, paramSize mov eax, args add eax, ecx @@ -453,80 +453,80 @@ asQWORD NOINLINE CallCDeclFunctionObjLast(const void *obj, const asDWORD *args, mov [ecx], eax mov 4[ecx], edx - // Restore registers + // Restore registers pop ecx } -#elif defined ASM_AT_N_T + #elif defined ASM_AT_N_T volatile asPWORD a[] = {asPWORD(obj), asPWORD(args), asPWORD(paramSize), asPWORD(func)}; - asm __volatile__ ( -#ifdef __OPTIMIZE__ - // When compiled with optimizations the stack unwind doesn't work properly, - // causing exceptions to crash the application. By adding this prologue - // and the epilogue below, the stack unwind works as it should. - // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below - "pushl %%ebp \n" - ".cfi_adjust_cfa_offset 4 \n" - ".cfi_rel_offset ebp, 0 \n" - "movl %%esp, %%ebp \n" - ".cfi_def_cfa_register ebp \n" -#endif - _S(CLEAR_FPU_STACK) "\n" - "pushl %%ebx \n" - "movl %%edx, %%ebx \n" - - // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. - // It is assumed that when entering this function, the stack pointer is already aligned, so we need - // to calculate how much we will put on the stack during this call. - "movl 8(%%ebx), %%eax \n" // paramSize - "addl $8, %%eax \n" // counting esp that we will push on the stack - "movl %%esp, %%ecx \n" - "subl %%eax, %%ecx \n" - "andl $15, %%ecx \n" - "movl %%esp, %%eax \n" - "subl %%ecx, %%esp \n" - "pushl %%eax \n" // Store the original stack pointer - - "pushl 0(%%ebx) \n" // obj - "movl 8(%%ebx), %%ecx \n" // paramSize - "movl 4(%%ebx), %%eax \n" // args - "addl %%ecx, %%eax \n" // push arguments on the stack - "cmp $0, %%ecx \n" - "je endcopy8 \n" - "copyloop8: \n" - "subl $4, %%eax \n" - "pushl (%%eax) \n" - "subl $4, %%ecx \n" - "jne copyloop8 \n" - "endcopy8: \n" - "call *12(%%ebx) \n" - "addl 8(%%ebx), %%esp \n" // pop arguments - "addl $4, %%esp \n" // pop obj - - // Pop the alignment bytes - "popl %%esp \n" - "popl %%ebx \n" -#ifdef __OPTIMIZE__ - // Epilogue - "movl %%ebp, %%esp \n" - ".cfi_def_cfa_register esp \n" - "popl %%ebp \n" - ".cfi_adjust_cfa_offset -4 \n" - ".cfi_restore ebp \n" -#endif - // Copy EAX:EDX to retQW. As the stack pointer has been - // restored it is now safe to access the local variable - "leal %1, %%ecx \n" - "movl %%eax, 0(%%ecx) \n" - "movl %%edx, 4(%%ecx) \n" - : // output - : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument - : "%eax", "%ecx" // clobber - ); - -#endif + asm __volatile__( + #ifdef __OPTIMIZE__ + // When compiled with optimizations the stack unwind doesn't work properly, + // causing exceptions to crash the application. By adding this prologue + // and the epilogue below, the stack unwind works as it should. + // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below + "pushl %%ebp \n" + ".cfi_adjust_cfa_offset 4 \n" + ".cfi_rel_offset ebp, 0 \n" + "movl %%esp, %%ebp \n" + ".cfi_def_cfa_register ebp \n" + #endif + _S(CLEAR_FPU_STACK) "\n" + "pushl %%ebx \n" + "movl %%edx, %%ebx \n" + + // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. + // It is assumed that when entering this function, the stack pointer is already aligned, so we need + // to calculate how much we will put on the stack during this call. + "movl 8(%%ebx), %%eax \n" // paramSize + "addl $8, %%eax \n" // counting esp that we will push on the stack + "movl %%esp, %%ecx \n" + "subl %%eax, %%ecx \n" + "andl $15, %%ecx \n" + "movl %%esp, %%eax \n" + "subl %%ecx, %%esp \n" + "pushl %%eax \n" // Store the original stack pointer + + "pushl 0(%%ebx) \n" // obj + "movl 8(%%ebx), %%ecx \n" // paramSize + "movl 4(%%ebx), %%eax \n" // args + "addl %%ecx, %%eax \n" // push arguments on the stack + "cmp $0, %%ecx \n" + "je endcopy8 \n" + "copyloop8: \n" + "subl $4, %%eax \n" + "pushl (%%eax) \n" + "subl $4, %%ecx \n" + "jne copyloop8 \n" + "endcopy8: \n" + "call *12(%%ebx) \n" + "addl 8(%%ebx), %%esp \n" // pop arguments + "addl $4, %%esp \n" // pop obj + + // Pop the alignment bytes + "popl %%esp \n" + "popl %%ebx \n" + #ifdef __OPTIMIZE__ + // Epilogue + "movl %%ebp, %%esp \n" + ".cfi_def_cfa_register esp \n" + "popl %%ebp \n" + ".cfi_adjust_cfa_offset -4 \n" + ".cfi_restore ebp \n" + #endif + // Copy EAX:EDX to retQW. As the stack pointer has been + // restored it is now safe to access the local variable + "leal %1, %%ecx \n" + "movl %%eax, 0(%%ecx) \n" + "movl %%edx, 4(%%ecx) \n" + : // output + : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument + : "%eax", "%ecx" // clobber + ); + + #endif return retQW; } @@ -535,7 +535,7 @@ asQWORD NOINLINE CallCDeclFunctionObjFirst(const void *obj, const asDWORD *args, { volatile asQWORD retQW = 0; -#if defined ASM_INTEL + #if defined ASM_INTEL // Copy the data to the real stack. If we fail to do // this we may run into trouble in case of exceptions. @@ -544,11 +544,11 @@ asQWORD NOINLINE CallCDeclFunctionObjFirst(const void *obj, const asDWORD *args, // We must save registers that are used push ecx - // Clear the FPU stack, in case the called function doesn't do it by itself + // Clear the FPU stack, in case the called function doesn't do it by itself CLEAR_FPU_STACK - // Copy arguments from script - // stack to application stack + // Copy arguments from script + // stack to application stack mov ecx, paramSize mov eax, args add eax, ecx @@ -564,7 +564,7 @@ asQWORD NOINLINE CallCDeclFunctionObjFirst(const void *obj, const asDWORD *args, // push object as first parameter push obj - // Call function + // Call function call [func] // Pop arguments from stack @@ -576,80 +576,80 @@ asQWORD NOINLINE CallCDeclFunctionObjFirst(const void *obj, const asDWORD *args, mov [ecx], eax mov 4[ecx], edx - // Restore registers + // Restore registers pop ecx } -#elif defined ASM_AT_N_T + #elif defined ASM_AT_N_T volatile asPWORD a[] = {asPWORD(obj), asPWORD(args), asPWORD(paramSize), asPWORD(func)}; - asm __volatile__ ( -#ifdef __OPTIMIZE__ - // When compiled with optimizations the stack unwind doesn't work properly, - // causing exceptions to crash the application. By adding this prologue - // and the epilogue below, the stack unwind works as it should. - // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below - "pushl %%ebp \n" - ".cfi_adjust_cfa_offset 4 \n" - ".cfi_rel_offset ebp, 0 \n" - "movl %%esp, %%ebp \n" - ".cfi_def_cfa_register ebp \n" -#endif - _S(CLEAR_FPU_STACK) "\n" - "pushl %%ebx \n" - "movl %%edx, %%ebx \n" - - // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. - // It is assumed that when entering this function, the stack pointer is already aligned, so we need - // to calculate how much we will put on the stack during this call. - "movl 8(%%ebx), %%eax \n" // paramSize - "addl $8, %%eax \n" // counting esp that we will push on the stack - "movl %%esp, %%ecx \n" - "subl %%eax, %%ecx \n" - "andl $15, %%ecx \n" - "movl %%esp, %%eax \n" - "subl %%ecx, %%esp \n" - "pushl %%eax \n" // Store the original stack pointer - - "movl 8(%%ebx), %%ecx \n" // paramSize - "movl 4(%%ebx), %%eax \n" // args - "addl %%ecx, %%eax \n" // push arguments on the stack - "cmp $0, %%ecx \n" - "je endcopy6 \n" - "copyloop6: \n" - "subl $4, %%eax \n" - "pushl (%%eax) \n" - "subl $4, %%ecx \n" - "jne copyloop6 \n" - "endcopy6: \n" - "pushl 0(%%ebx) \n" // push obj - "call *12(%%ebx) \n" - "addl 8(%%ebx), %%esp \n" // pop arguments - "addl $4, %%esp \n" // pop obj - - // Pop the alignment bytes - "popl %%esp \n" - "popl %%ebx \n" -#ifdef __OPTIMIZE__ - // Epilogue - "movl %%ebp, %%esp \n" - ".cfi_def_cfa_register esp \n" - "popl %%ebp \n" - ".cfi_adjust_cfa_offset -4 \n" - ".cfi_restore ebp \n" -#endif - // Copy EAX:EDX to retQW. As the stack pointer has been - // restored it is now safe to access the local variable - "leal %1, %%ecx \n" - "movl %%eax, 0(%%ecx) \n" - "movl %%edx, 4(%%ecx) \n" - : // output - : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument - : "%eax", "%ecx" // clobber - ); - -#endif + asm __volatile__( + #ifdef __OPTIMIZE__ + // When compiled with optimizations the stack unwind doesn't work properly, + // causing exceptions to crash the application. By adding this prologue + // and the epilogue below, the stack unwind works as it should. + // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below + "pushl %%ebp \n" + ".cfi_adjust_cfa_offset 4 \n" + ".cfi_rel_offset ebp, 0 \n" + "movl %%esp, %%ebp \n" + ".cfi_def_cfa_register ebp \n" + #endif + _S(CLEAR_FPU_STACK) "\n" + "pushl %%ebx \n" + "movl %%edx, %%ebx \n" + + // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. + // It is assumed that when entering this function, the stack pointer is already aligned, so we need + // to calculate how much we will put on the stack during this call. + "movl 8(%%ebx), %%eax \n" // paramSize + "addl $8, %%eax \n" // counting esp that we will push on the stack + "movl %%esp, %%ecx \n" + "subl %%eax, %%ecx \n" + "andl $15, %%ecx \n" + "movl %%esp, %%eax \n" + "subl %%ecx, %%esp \n" + "pushl %%eax \n" // Store the original stack pointer + + "movl 8(%%ebx), %%ecx \n" // paramSize + "movl 4(%%ebx), %%eax \n" // args + "addl %%ecx, %%eax \n" // push arguments on the stack + "cmp $0, %%ecx \n" + "je endcopy6 \n" + "copyloop6: \n" + "subl $4, %%eax \n" + "pushl (%%eax) \n" + "subl $4, %%ecx \n" + "jne copyloop6 \n" + "endcopy6: \n" + "pushl 0(%%ebx) \n" // push obj + "call *12(%%ebx) \n" + "addl 8(%%ebx), %%esp \n" // pop arguments + "addl $4, %%esp \n" // pop obj + + // Pop the alignment bytes + "popl %%esp \n" + "popl %%ebx \n" + #ifdef __OPTIMIZE__ + // Epilogue + "movl %%ebp, %%esp \n" + ".cfi_def_cfa_register esp \n" + "popl %%ebp \n" + ".cfi_adjust_cfa_offset -4 \n" + ".cfi_restore ebp \n" + #endif + // Copy EAX:EDX to retQW. As the stack pointer has been + // restored it is now safe to access the local variable + "leal %1, %%ecx \n" + "movl %%eax, 0(%%ecx) \n" + "movl %%edx, 4(%%ecx) \n" + : // output + : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument + : "%eax", "%ecx" // clobber + ); + + #endif return retQW; } @@ -658,7 +658,7 @@ asQWORD NOINLINE CallCDeclFunctionRetByRefObjFirst(const void *obj, const asDWOR { volatile asQWORD retQW = 0; -#if defined ASM_INTEL + #if defined ASM_INTEL // Copy the data to the real stack. If we fail to do // this we may run into trouble in case of exceptions. @@ -667,11 +667,11 @@ asQWORD NOINLINE CallCDeclFunctionRetByRefObjFirst(const void *obj, const asDWOR // We must save registers that are used push ecx - // Clear the FPU stack, in case the called function doesn't do it by itself + // Clear the FPU stack, in case the called function doesn't do it by itself CLEAR_FPU_STACK - // Copy arguments from script - // stack to application stack + // Copy arguments from script + // stack to application stack mov ecx, paramSize mov eax, args add eax, ecx @@ -687,7 +687,7 @@ asQWORD NOINLINE CallCDeclFunctionRetByRefObjFirst(const void *obj, const asDWOR // Push the object pointer push obj - // Push the return pointer + // Push the return pointer push retPtr; // Call function @@ -696,95 +696,95 @@ asQWORD NOINLINE CallCDeclFunctionRetByRefObjFirst(const void *obj, const asDWOR // Pop arguments from stack add esp, paramSize -#ifndef CALLEE_POPS_HIDDEN_RETURN_POINTER - // Pop the return pointer + #ifndef CALLEE_POPS_HIDDEN_RETURN_POINTER + // Pop the return pointer add esp, 8 -#else + #else add esp, 4 -#endif + #endif // Copy return value from EAX:EDX lea ecx, retQW mov [ecx], eax mov 4[ecx], edx - // Restore registers + // Restore registers pop ecx } -#elif defined ASM_AT_N_T + #elif defined ASM_AT_N_T volatile asPWORD a[] = {asPWORD(obj), asPWORD(args), asPWORD(paramSize), asPWORD(func), asPWORD(retPtr)}; - asm __volatile__ ( -#ifdef __OPTIMIZE__ - // When compiled with optimizations the stack unwind doesn't work properly, - // causing exceptions to crash the application. By adding this prologue - // and the epilogue below, the stack unwind works as it should. - // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below - "pushl %%ebp \n" - ".cfi_adjust_cfa_offset 4 \n" - ".cfi_rel_offset ebp, 0 \n" - "movl %%esp, %%ebp \n" - ".cfi_def_cfa_register ebp \n" -#endif - _S(CLEAR_FPU_STACK) "\n" - "pushl %%ebx \n" - "movl %%edx, %%ebx \n" - - // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. - // It is assumed that when entering this function, the stack pointer is already aligned, so we need - // to calculate how much we will put on the stack during this call. - "movl 8(%%ebx), %%eax \n" // paramSize - "addl $12, %%eax \n" // counting esp that we will push on the stack - "movl %%esp, %%ecx \n" - "subl %%eax, %%ecx \n" - "andl $15, %%ecx \n" - "movl %%esp, %%eax \n" - "subl %%ecx, %%esp \n" - "pushl %%eax \n" // Store the original stack pointer - - "movl 8(%%ebx), %%ecx \n" // paramSize - "movl 4(%%ebx), %%eax \n" // args - "addl %%ecx, %%eax \n" // push arguments on the stack - "cmp $0, %%ecx \n" - "je endcopy5 \n" - "copyloop5: \n" - "subl $4, %%eax \n" - "pushl (%%eax) \n" - "subl $4, %%ecx \n" - "jne copyloop5 \n" - "endcopy5: \n" - "pushl 0(%%ebx) \n" // push object first - "pushl 16(%%ebx) \n" // retPtr - "call *12(%%ebx) \n" // func - "addl 8(%%ebx), %%esp \n" // pop arguments -#ifndef CALLEE_POPS_HIDDEN_RETURN_POINTER - "addl $8, %%esp \n" // Pop the return pointer and object pointer -#else - "addl $4, %%esp \n" // Pop the object pointer -#endif - // Pop the alignment bytes - "popl %%esp \n" - "popl %%ebx \n" -#ifdef __OPTIMIZE__ - // Epilogue - "movl %%ebp, %%esp \n" - ".cfi_def_cfa_register esp \n" - "popl %%ebp \n" - ".cfi_adjust_cfa_offset -4 \n" - ".cfi_restore ebp \n" -#endif - // Copy EAX:EDX to retQW. As the stack pointer has been - // restored it is now safe to access the local variable - "leal %1, %%ecx \n" - "movl %%eax, 0(%%ecx) \n" - "movl %%edx, 4(%%ecx) \n" - : // output - : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument - : "%eax", "%ecx" // clobber - ); -#endif + asm __volatile__( + #ifdef __OPTIMIZE__ + // When compiled with optimizations the stack unwind doesn't work properly, + // causing exceptions to crash the application. By adding this prologue + // and the epilogue below, the stack unwind works as it should. + // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below + "pushl %%ebp \n" + ".cfi_adjust_cfa_offset 4 \n" + ".cfi_rel_offset ebp, 0 \n" + "movl %%esp, %%ebp \n" + ".cfi_def_cfa_register ebp \n" + #endif + _S(CLEAR_FPU_STACK) "\n" + "pushl %%ebx \n" + "movl %%edx, %%ebx \n" + + // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. + // It is assumed that when entering this function, the stack pointer is already aligned, so we need + // to calculate how much we will put on the stack during this call. + "movl 8(%%ebx), %%eax \n" // paramSize + "addl $12, %%eax \n" // counting esp that we will push on the stack + "movl %%esp, %%ecx \n" + "subl %%eax, %%ecx \n" + "andl $15, %%ecx \n" + "movl %%esp, %%eax \n" + "subl %%ecx, %%esp \n" + "pushl %%eax \n" // Store the original stack pointer + + "movl 8(%%ebx), %%ecx \n" // paramSize + "movl 4(%%ebx), %%eax \n" // args + "addl %%ecx, %%eax \n" // push arguments on the stack + "cmp $0, %%ecx \n" + "je endcopy5 \n" + "copyloop5: \n" + "subl $4, %%eax \n" + "pushl (%%eax) \n" + "subl $4, %%ecx \n" + "jne copyloop5 \n" + "endcopy5: \n" + "pushl 0(%%ebx) \n" // push object first + "pushl 16(%%ebx) \n" // retPtr + "call *12(%%ebx) \n" // func + "addl 8(%%ebx), %%esp \n" // pop arguments + #ifndef CALLEE_POPS_HIDDEN_RETURN_POINTER + "addl $8, %%esp \n" // Pop the return pointer and object pointer + #else + "addl $4, %%esp \n" // Pop the object pointer + #endif + // Pop the alignment bytes + "popl %%esp \n" + "popl %%ebx \n" + #ifdef __OPTIMIZE__ + // Epilogue + "movl %%ebp, %%esp \n" + ".cfi_def_cfa_register esp \n" + "popl %%ebp \n" + ".cfi_adjust_cfa_offset -4 \n" + ".cfi_restore ebp \n" + #endif + // Copy EAX:EDX to retQW. As the stack pointer has been + // restored it is now safe to access the local variable + "leal %1, %%ecx \n" + "movl %%eax, 0(%%ecx) \n" + "movl %%edx, 4(%%ecx) \n" + : // output + : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument + : "%eax", "%ecx" // clobber + ); + #endif return retQW; } @@ -793,7 +793,7 @@ asQWORD NOINLINE CallCDeclFunctionRetByRef(const asDWORD *args, int paramSize, a { volatile asQWORD retQW = 0; -#if defined ASM_INTEL + #if defined ASM_INTEL // Copy the data to the real stack. If we fail to do // this we may run into trouble in case of exceptions. @@ -802,11 +802,11 @@ asQWORD NOINLINE CallCDeclFunctionRetByRef(const asDWORD *args, int paramSize, a // We must save registers that are used push ecx - // Clear the FPU stack, in case the called function doesn't do it by itself + // Clear the FPU stack, in case the called function doesn't do it by itself CLEAR_FPU_STACK - // Copy arguments from script - // stack to application stack + // Copy arguments from script + // stack to application stack mov ecx, paramSize mov eax, args add eax, ecx @@ -828,93 +828,93 @@ asQWORD NOINLINE CallCDeclFunctionRetByRef(const asDWORD *args, int paramSize, a // Pop arguments from stack add esp, paramSize -#ifndef CALLEE_POPS_HIDDEN_RETURN_POINTER - // Pop the return pointer + #ifndef CALLEE_POPS_HIDDEN_RETURN_POINTER + // Pop the return pointer add esp, 4 -#endif + #endif // Copy return value from EAX:EDX lea ecx, retQW mov [ecx], eax mov 4[ecx], edx - // Restore registers + // Restore registers pop ecx // return value in EAX or EAX:EDX } -#elif defined ASM_AT_N_T + #elif defined ASM_AT_N_T volatile asPWORD a[] = {asPWORD(args), asPWORD(paramSize), asPWORD(func), asPWORD(retPtr)}; - asm __volatile__ ( -#ifdef __OPTIMIZE__ - // When compiled with optimizations the stack unwind doesn't work properly, - // causing exceptions to crash the application. By adding this prologue - // and the epilogue below, the stack unwind works as it should. - // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below - "pushl %%ebp \n" - ".cfi_adjust_cfa_offset 4 \n" - ".cfi_rel_offset ebp, 0 \n" - "movl %%esp, %%ebp \n" - ".cfi_def_cfa_register ebp \n" -#endif - _S(CLEAR_FPU_STACK) "\n" - "pushl %%ebx \n" - "movl %%edx, %%ebx \n" - - // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. - // It is assumed that when entering this function, the stack pointer is already aligned, so we need - // to calculate how much we will put on the stack during this call. - "movl 4(%%ebx), %%eax \n" // paramSize - "addl $8, %%eax \n" // counting esp that we will push on the stack - "movl %%esp, %%ecx \n" - "subl %%eax, %%ecx \n" - "andl $15, %%ecx \n" - "movl %%esp, %%eax \n" - "subl %%ecx, %%esp \n" - "pushl %%eax \n" // Store the original stack pointer - - "movl 4(%%ebx), %%ecx \n" // paramSize - "movl 0(%%ebx), %%eax \n" // args - "addl %%ecx, %%eax \n" // push arguments on the stack - "cmp $0, %%ecx \n" - "je endcopy7 \n" - "copyloop7: \n" - "subl $4, %%eax \n" - "pushl (%%eax) \n" - "subl $4, %%ecx \n" - "jne copyloop7 \n" - "endcopy7: \n" - "pushl 12(%%ebx) \n" // retPtr - "call *8(%%ebx) \n" // func - "addl 4(%%ebx), %%esp \n" // pop arguments -#ifndef CALLEE_POPS_HIDDEN_RETURN_POINTER - "addl $4, %%esp \n" // Pop the return pointer -#endif - // Pop the alignment bytes - "popl %%esp \n" - "popl %%ebx \n" -#ifdef __OPTIMIZE__ - // Epilogue - "movl %%ebp, %%esp \n" - ".cfi_def_cfa_register esp \n" - "popl %%ebp \n" - ".cfi_adjust_cfa_offset -4 \n" - ".cfi_restore ebp \n" -#endif - // Copy EAX:EDX to retQW. As the stack pointer has been - // restored it is now safe to access the local variable - "leal %1, %%ecx \n" - "movl %%eax, 0(%%ecx) \n" - "movl %%edx, 4(%%ecx) \n" - : // output - : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument - : "%eax", "%ecx" // clobber - ); - -#endif + asm __volatile__( + #ifdef __OPTIMIZE__ + // When compiled with optimizations the stack unwind doesn't work properly, + // causing exceptions to crash the application. By adding this prologue + // and the epilogue below, the stack unwind works as it should. + // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below + "pushl %%ebp \n" + ".cfi_adjust_cfa_offset 4 \n" + ".cfi_rel_offset ebp, 0 \n" + "movl %%esp, %%ebp \n" + ".cfi_def_cfa_register ebp \n" + #endif + _S(CLEAR_FPU_STACK) "\n" + "pushl %%ebx \n" + "movl %%edx, %%ebx \n" + + // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. + // It is assumed that when entering this function, the stack pointer is already aligned, so we need + // to calculate how much we will put on the stack during this call. + "movl 4(%%ebx), %%eax \n" // paramSize + "addl $8, %%eax \n" // counting esp that we will push on the stack + "movl %%esp, %%ecx \n" + "subl %%eax, %%ecx \n" + "andl $15, %%ecx \n" + "movl %%esp, %%eax \n" + "subl %%ecx, %%esp \n" + "pushl %%eax \n" // Store the original stack pointer + + "movl 4(%%ebx), %%ecx \n" // paramSize + "movl 0(%%ebx), %%eax \n" // args + "addl %%ecx, %%eax \n" // push arguments on the stack + "cmp $0, %%ecx \n" + "je endcopy7 \n" + "copyloop7: \n" + "subl $4, %%eax \n" + "pushl (%%eax) \n" + "subl $4, %%ecx \n" + "jne copyloop7 \n" + "endcopy7: \n" + "pushl 12(%%ebx) \n" // retPtr + "call *8(%%ebx) \n" // func + "addl 4(%%ebx), %%esp \n" // pop arguments + #ifndef CALLEE_POPS_HIDDEN_RETURN_POINTER + "addl $4, %%esp \n" // Pop the return pointer + #endif + // Pop the alignment bytes + "popl %%esp \n" + "popl %%ebx \n" + #ifdef __OPTIMIZE__ + // Epilogue + "movl %%ebp, %%esp \n" + ".cfi_def_cfa_register esp \n" + "popl %%ebp \n" + ".cfi_adjust_cfa_offset -4 \n" + ".cfi_restore ebp \n" + #endif + // Copy EAX:EDX to retQW. As the stack pointer has been + // restored it is now safe to access the local variable + "leal %1, %%ecx \n" + "movl %%eax, 0(%%ecx) \n" + "movl %%edx, 4(%%ecx) \n" + : // output + : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument + : "%eax", "%ecx" // clobber + ); + + #endif return retQW; } @@ -923,7 +923,7 @@ asQWORD NOINLINE CallCDeclFunctionRetByRefObjLast(const void *obj, const asDWORD { volatile asQWORD retQW = 0; -#if defined ASM_INTEL + #if defined ASM_INTEL // Copy the data to the real stack. If we fail to do // this we may run into trouble in case of exceptions. @@ -932,13 +932,13 @@ asQWORD NOINLINE CallCDeclFunctionRetByRefObjLast(const void *obj, const asDWORD // We must save registers that are used push ecx - // Clear the FPU stack, in case the called function doesn't do it by itself + // Clear the FPU stack, in case the called function doesn't do it by itself CLEAR_FPU_STACK push obj - // Copy arguments from script - // stack to application stack + // Copy arguments from script + // stack to application stack mov ecx, paramSize mov eax, args add eax, ecx @@ -961,94 +961,94 @@ asQWORD NOINLINE CallCDeclFunctionRetByRefObjLast(const void *obj, const asDWORD add esp, paramSize add esp, 4 -#ifndef CALLEE_POPS_HIDDEN_RETURN_POINTER + #ifndef CALLEE_POPS_HIDDEN_RETURN_POINTER // Pop the return pointer add esp, 4 -#endif + #endif // Copy return value from EAX:EDX lea ecx, retQW mov [ecx], eax mov 4[ecx], edx - // Restore registers + // Restore registers pop ecx } -#elif defined ASM_AT_N_T + #elif defined ASM_AT_N_T volatile asPWORD a[] = {asPWORD(obj), asPWORD(args), asPWORD(paramSize), asPWORD(func), asPWORD(retPtr)}; - asm __volatile__ ( -#ifdef __OPTIMIZE__ - // When compiled with optimizations the stack unwind doesn't work properly, - // causing exceptions to crash the application. By adding this prologue - // and the epilogue below, the stack unwind works as it should. - // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below - "pushl %%ebp \n" - ".cfi_adjust_cfa_offset 4 \n" - ".cfi_rel_offset ebp, 0 \n" - "movl %%esp, %%ebp \n" - ".cfi_def_cfa_register ebp \n" -#endif - _S(CLEAR_FPU_STACK) "\n" - "pushl %%ebx \n" - "movl %%edx, %%ebx \n" - - // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. - // It is assumed that when entering this function, the stack pointer is already aligned, so we need - // to calculate how much we will put on the stack during this call. - "movl 8(%%ebx), %%eax \n" // paramSize - "addl $12, %%eax \n" // counting esp that we will push on the stack - "movl %%esp, %%ecx \n" - "subl %%eax, %%ecx \n" - "andl $15, %%ecx \n" - "movl %%esp, %%eax \n" - "subl %%ecx, %%esp \n" - "pushl %%eax \n" // Store the original stack pointer - - "pushl 0(%%ebx) \n" // obj - "movl 8(%%ebx), %%ecx \n" // paramSize - "movl 4(%%ebx), %%eax \n" // args - "addl %%ecx, %%eax \n" // push arguments on the stack - "cmp $0, %%ecx \n" - "je endcopy4 \n" - "copyloop4: \n" - "subl $4, %%eax \n" - "pushl (%%eax) \n" - "subl $4, %%ecx \n" - "jne copyloop4 \n" - "endcopy4: \n" - "pushl 16(%%ebx) \n" // retPtr - "call *12(%%ebx) \n" // func - "addl 8(%%ebx), %%esp \n" // pop arguments -#ifndef CALLEE_POPS_HIDDEN_RETURN_POINTER - "addl $8, %%esp \n" // Pop the return pointer and object pointer -#else - "addl $4, %%esp \n" // Pop the object pointer -#endif - // Pop the alignment bytes - "popl %%esp \n" - "popl %%ebx \n" -#ifdef __OPTIMIZE__ - // Epilogue - "movl %%ebp, %%esp \n" - ".cfi_def_cfa_register esp \n" - "popl %%ebp \n" - ".cfi_adjust_cfa_offset -4 \n" - ".cfi_restore ebp \n" -#endif - // Copy EAX:EDX to retQW. As the stack pointer has been - // restored it is now safe to access the local variable - "leal %1, %%ecx \n" - "movl %%eax, 0(%%ecx) \n" - "movl %%edx, 4(%%ecx) \n" - : // output - : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument - : "%eax", "%ecx" // clobber - ); - -#endif + asm __volatile__( + #ifdef __OPTIMIZE__ + // When compiled with optimizations the stack unwind doesn't work properly, + // causing exceptions to crash the application. By adding this prologue + // and the epilogue below, the stack unwind works as it should. + // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below + "pushl %%ebp \n" + ".cfi_adjust_cfa_offset 4 \n" + ".cfi_rel_offset ebp, 0 \n" + "movl %%esp, %%ebp \n" + ".cfi_def_cfa_register ebp \n" + #endif + _S(CLEAR_FPU_STACK) "\n" + "pushl %%ebx \n" + "movl %%edx, %%ebx \n" + + // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. + // It is assumed that when entering this function, the stack pointer is already aligned, so we need + // to calculate how much we will put on the stack during this call. + "movl 8(%%ebx), %%eax \n" // paramSize + "addl $12, %%eax \n" // counting esp that we will push on the stack + "movl %%esp, %%ecx \n" + "subl %%eax, %%ecx \n" + "andl $15, %%ecx \n" + "movl %%esp, %%eax \n" + "subl %%ecx, %%esp \n" + "pushl %%eax \n" // Store the original stack pointer + + "pushl 0(%%ebx) \n" // obj + "movl 8(%%ebx), %%ecx \n" // paramSize + "movl 4(%%ebx), %%eax \n" // args + "addl %%ecx, %%eax \n" // push arguments on the stack + "cmp $0, %%ecx \n" + "je endcopy4 \n" + "copyloop4: \n" + "subl $4, %%eax \n" + "pushl (%%eax) \n" + "subl $4, %%ecx \n" + "jne copyloop4 \n" + "endcopy4: \n" + "pushl 16(%%ebx) \n" // retPtr + "call *12(%%ebx) \n" // func + "addl 8(%%ebx), %%esp \n" // pop arguments + #ifndef CALLEE_POPS_HIDDEN_RETURN_POINTER + "addl $8, %%esp \n" // Pop the return pointer and object pointer + #else + "addl $4, %%esp \n" // Pop the object pointer + #endif + // Pop the alignment bytes + "popl %%esp \n" + "popl %%ebx \n" + #ifdef __OPTIMIZE__ + // Epilogue + "movl %%ebp, %%esp \n" + ".cfi_def_cfa_register esp \n" + "popl %%ebp \n" + ".cfi_adjust_cfa_offset -4 \n" + ".cfi_restore ebp \n" + #endif + // Copy EAX:EDX to retQW. As the stack pointer has been + // restored it is now safe to access the local variable + "leal %1, %%ecx \n" + "movl %%eax, 0(%%ecx) \n" + "movl %%edx, 4(%%ecx) \n" + : // output + : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument + : "%eax", "%ecx" // clobber + ); + + #endif return retQW; } @@ -1057,7 +1057,7 @@ asQWORD NOINLINE CallSTDCallFunction(const asDWORD *args, int paramSize, asFUNCT { volatile asQWORD retQW = 0; -#if defined ASM_INTEL + #if defined ASM_INTEL // Copy the data to the real stack. If we fail to do // this we may run into trouble in case of exceptions. @@ -1066,11 +1066,11 @@ asQWORD NOINLINE CallSTDCallFunction(const asDWORD *args, int paramSize, asFUNCT // We must save registers that are used push ecx - // Clear the FPU stack, in case the called function doesn't do it by itself + // Clear the FPU stack, in case the called function doesn't do it by itself CLEAR_FPU_STACK - // Copy arguments from script - // stack to application stack + // Copy arguments from script + // stack to application stack mov ecx, paramSize mov eax, args add eax, ecx @@ -1093,77 +1093,77 @@ asQWORD NOINLINE CallSTDCallFunction(const asDWORD *args, int paramSize, asFUNCT mov [ecx], eax mov 4[ecx], edx - // Restore registers + // Restore registers pop ecx } -#elif defined ASM_AT_N_T + #elif defined ASM_AT_N_T volatile asPWORD a[] = {asPWORD(args), asPWORD(paramSize), asPWORD(func)}; - asm __volatile__ ( -#ifdef __OPTIMIZE__ - // When compiled with optimizations the stack unwind doesn't work properly, - // causing exceptions to crash the application. By adding this prologue - // and the epilogue below, the stack unwind works as it should. - // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below - "pushl %%ebp \n" - ".cfi_adjust_cfa_offset 4 \n" - ".cfi_rel_offset ebp, 0 \n" - "movl %%esp, %%ebp \n" - ".cfi_def_cfa_register ebp \n" -#endif - _S(CLEAR_FPU_STACK) "\n" - "pushl %%ebx \n" - "movl %%edx, %%ebx \n" - - // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. - // It is assumed that when entering this function, the stack pointer is already aligned, so we need - // to calculate how much we will put on the stack during this call. - "movl 4(%%ebx), %%eax \n" // paramSize - "addl $4, %%eax \n" // counting esp that we will push on the stack - "movl %%esp, %%ecx \n" - "subl %%eax, %%ecx \n" - "andl $15, %%ecx \n" - "movl %%esp, %%eax \n" - "subl %%ecx, %%esp \n" - "pushl %%eax \n" // Store the original stack pointer - - "movl 4(%%ebx), %%ecx \n" // paramSize - "movl 0(%%ebx), %%eax \n" // args - "addl %%ecx, %%eax \n" // push arguments on the stack - "cmp $0, %%ecx \n" - "je endcopy2 \n" - "copyloop2: \n" - "subl $4, %%eax \n" - "pushl (%%eax) \n" - "subl $4, %%ecx \n" - "jne copyloop2 \n" - "endcopy2: \n" - "call *8(%%ebx) \n" // callee pops the arguments - - // Pop the alignment bytes - "popl %%esp \n" - "popl %%ebx \n" -#ifdef __OPTIMIZE__ - // Epilogue - "movl %%ebp, %%esp \n" - ".cfi_def_cfa_register esp \n" - "popl %%ebp \n" - ".cfi_adjust_cfa_offset -4 \n" - ".cfi_restore ebp \n" -#endif - // Copy EAX:EDX to retQW. As the stack pointer has been - // restored it is now safe to access the local variable - "leal %1, %%ecx \n" - "movl %%eax, 0(%%ecx) \n" - "movl %%edx, 4(%%ecx) \n" - : // output - : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument - : "%eax", "%ecx" // clobber - ); - -#endif + asm __volatile__( + #ifdef __OPTIMIZE__ + // When compiled with optimizations the stack unwind doesn't work properly, + // causing exceptions to crash the application. By adding this prologue + // and the epilogue below, the stack unwind works as it should. + // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below + "pushl %%ebp \n" + ".cfi_adjust_cfa_offset 4 \n" + ".cfi_rel_offset ebp, 0 \n" + "movl %%esp, %%ebp \n" + ".cfi_def_cfa_register ebp \n" + #endif + _S(CLEAR_FPU_STACK) "\n" + "pushl %%ebx \n" + "movl %%edx, %%ebx \n" + + // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. + // It is assumed that when entering this function, the stack pointer is already aligned, so we need + // to calculate how much we will put on the stack during this call. + "movl 4(%%ebx), %%eax \n" // paramSize + "addl $4, %%eax \n" // counting esp that we will push on the stack + "movl %%esp, %%ecx \n" + "subl %%eax, %%ecx \n" + "andl $15, %%ecx \n" + "movl %%esp, %%eax \n" + "subl %%ecx, %%esp \n" + "pushl %%eax \n" // Store the original stack pointer + + "movl 4(%%ebx), %%ecx \n" // paramSize + "movl 0(%%ebx), %%eax \n" // args + "addl %%ecx, %%eax \n" // push arguments on the stack + "cmp $0, %%ecx \n" + "je endcopy2 \n" + "copyloop2: \n" + "subl $4, %%eax \n" + "pushl (%%eax) \n" + "subl $4, %%ecx \n" + "jne copyloop2 \n" + "endcopy2: \n" + "call *8(%%ebx) \n" // callee pops the arguments + + // Pop the alignment bytes + "popl %%esp \n" + "popl %%ebx \n" + #ifdef __OPTIMIZE__ + // Epilogue + "movl %%ebp, %%esp \n" + ".cfi_def_cfa_register esp \n" + "popl %%ebp \n" + ".cfi_adjust_cfa_offset -4 \n" + ".cfi_restore ebp \n" + #endif + // Copy EAX:EDX to retQW. As the stack pointer has been + // restored it is now safe to access the local variable + "leal %1, %%ecx \n" + "movl %%eax, 0(%%ecx) \n" + "movl %%edx, 4(%%ecx) \n" + : // output + : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument + : "%eax", "%ecx" // clobber + ); + + #endif return retQW; } @@ -1173,7 +1173,7 @@ asQWORD NOINLINE CallThisCallFunction(const void *obj, const asDWORD *args, int { volatile asQWORD retQW = 0; -#if defined ASM_INTEL + #if defined ASM_INTEL // Copy the data to the real stack. If we fail to do // this we may run into trouble in case of exceptions. @@ -1182,11 +1182,11 @@ asQWORD NOINLINE CallThisCallFunction(const void *obj, const asDWORD *args, int // We must save registers that are used push ecx - // Clear the FPU stack, in case the called function doesn't do it by itself + // Clear the FPU stack, in case the called function doesn't do it by itself CLEAR_FPU_STACK - // Copy arguments from script - // stack to application stack + // Copy arguments from script + // stack to application stack mov ecx, paramSize mov eax, args add eax, ecx @@ -1199,111 +1199,111 @@ asQWORD NOINLINE CallThisCallFunction(const void *obj, const asDWORD *args, int jne copyloop endcopy: -#ifdef THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK + #ifdef THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK // Push the object pointer on the stack push obj -#else + #else // Move object pointer to ECX mov ecx, obj -#endif + #endif - // Call function + // Call function call [func] -#ifndef THISCALL_CALLEE_POPS_ARGUMENTS + #ifndef THISCALL_CALLEE_POPS_ARGUMENTS // Pop arguments add esp, paramSize -#ifdef THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK - // Pop object pointer + #ifdef THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK + // Pop object pointer add esp, 4 -#endif -#endif + #endif + #endif // Copy return value from EAX:EDX lea ecx, retQW mov [ecx], eax mov 4[ecx], edx - // Restore registers + // Restore registers pop ecx } -#elif defined ASM_AT_N_T + #elif defined ASM_AT_N_T volatile asPWORD a[] = {asPWORD(obj), asPWORD(args), asPWORD(paramSize), asPWORD(func)}; - asm __volatile__ ( -#ifdef __OPTIMIZE__ - // When compiled with optimizations the stack unwind doesn't work properly, - // causing exceptions to crash the application. By adding this prologue - // and the epilogue below, the stack unwind works as it should. - // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below - "pushl %%ebp \n" - ".cfi_adjust_cfa_offset 4 \n" - ".cfi_rel_offset ebp, 0 \n" - "movl %%esp, %%ebp \n" - ".cfi_def_cfa_register ebp \n" -#endif - _S(CLEAR_FPU_STACK) "\n" - "pushl %%ebx \n" - "movl %%edx, %%ebx \n" - - // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. - // It is assumed that when entering this function, the stack pointer is already aligned, so we need - // to calculate how much we will put on the stack during this call. - "movl 8(%%ebx), %%eax \n" // paramSize - "addl $8, %%eax \n" // counting esp that we will push on the stack - "movl %%esp, %%ecx \n" - "subl %%eax, %%ecx \n" - "andl $15, %%ecx \n" - "movl %%esp, %%eax \n" - "subl %%ecx, %%esp \n" - "pushl %%eax \n" // Store the original stack pointer - - "movl 8(%%ebx), %%ecx \n" // paramSize - "movl 4(%%ebx), %%eax \n" // args - "addl %%ecx, %%eax \n" // push all arguments on the stack - "cmp $0, %%ecx \n" - "je endcopy1 \n" - "copyloop1: \n" - "subl $4, %%eax \n" - "pushl (%%eax) \n" - "subl $4, %%ecx \n" - "jne copyloop1 \n" - "endcopy1: \n" - "movl 0(%%ebx), %%ecx \n" // move obj into ECX -#ifdef THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK - "pushl %%ecx \n" // push obj on the stack -#endif - "call *12(%%ebx) \n" -#ifndef THISCALL_CALLEE_POPS_ARGUMENTS - "addl 8(%%ebx), %%esp \n" // pop arguments -#ifdef THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK - "addl $4, %%esp \n" // pop obj -#endif -#endif - // Pop the alignment bytes - "popl %%esp \n" - "popl %%ebx \n" -#ifdef __OPTIMIZE__ - // Epilogue - "movl %%ebp, %%esp \n" - ".cfi_def_cfa_register esp \n" - "popl %%ebp \n" - ".cfi_adjust_cfa_offset -4 \n" - ".cfi_restore ebp \n" -#endif - // Copy EAX:EDX to retQW. As the stack pointer has been - // restored it is now safe to access the local variable - "leal %1, %%ecx \n" - "movl %%eax, 0(%%ecx) \n" - "movl %%edx, 4(%%ecx) \n" - : // output - : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument - : "%eax", "%ecx" // clobber - ); - -#endif + asm __volatile__( + #ifdef __OPTIMIZE__ + // When compiled with optimizations the stack unwind doesn't work properly, + // causing exceptions to crash the application. By adding this prologue + // and the epilogue below, the stack unwind works as it should. + // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below + "pushl %%ebp \n" + ".cfi_adjust_cfa_offset 4 \n" + ".cfi_rel_offset ebp, 0 \n" + "movl %%esp, %%ebp \n" + ".cfi_def_cfa_register ebp \n" + #endif + _S(CLEAR_FPU_STACK) "\n" + "pushl %%ebx \n" + "movl %%edx, %%ebx \n" + + // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. + // It is assumed that when entering this function, the stack pointer is already aligned, so we need + // to calculate how much we will put on the stack during this call. + "movl 8(%%ebx), %%eax \n" // paramSize + "addl $8, %%eax \n" // counting esp that we will push on the stack + "movl %%esp, %%ecx \n" + "subl %%eax, %%ecx \n" + "andl $15, %%ecx \n" + "movl %%esp, %%eax \n" + "subl %%ecx, %%esp \n" + "pushl %%eax \n" // Store the original stack pointer + + "movl 8(%%ebx), %%ecx \n" // paramSize + "movl 4(%%ebx), %%eax \n" // args + "addl %%ecx, %%eax \n" // push all arguments on the stack + "cmp $0, %%ecx \n" + "je endcopy1 \n" + "copyloop1: \n" + "subl $4, %%eax \n" + "pushl (%%eax) \n" + "subl $4, %%ecx \n" + "jne copyloop1 \n" + "endcopy1: \n" + "movl 0(%%ebx), %%ecx \n" // move obj into ECX + #ifdef THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK + "pushl %%ecx \n" // push obj on the stack + #endif + "call *12(%%ebx) \n" + #ifndef THISCALL_CALLEE_POPS_ARGUMENTS + "addl 8(%%ebx), %%esp \n" // pop arguments + #ifdef THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK + "addl $4, %%esp \n" // pop obj + #endif + #endif + // Pop the alignment bytes + "popl %%esp \n" + "popl %%ebx \n" + #ifdef __OPTIMIZE__ + // Epilogue + "movl %%ebp, %%esp \n" + ".cfi_def_cfa_register esp \n" + "popl %%ebp \n" + ".cfi_adjust_cfa_offset -4 \n" + ".cfi_restore ebp \n" + #endif + // Copy EAX:EDX to retQW. As the stack pointer has been + // restored it is now safe to access the local variable + "leal %1, %%ecx \n" + "movl %%eax, 0(%%ecx) \n" + "movl %%edx, 4(%%ecx) \n" + : // output + : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument + : "%eax", "%ecx" // clobber + ); + + #endif return retQW; } @@ -1312,7 +1312,7 @@ asQWORD NOINLINE CallThisCallFunctionRetByRef(const void *obj, const asDWORD *ar { volatile asQWORD retQW = 0; -#if defined ASM_INTEL + #if defined ASM_INTEL // Copy the data to the real stack. If we fail to do // this we may run into trouble in case of exceptions. @@ -1321,11 +1321,11 @@ asQWORD NOINLINE CallThisCallFunctionRetByRef(const void *obj, const asDWORD *ar // We must save registers that are used push ecx - // Clear the FPU stack, in case the called function doesn't do it by itself + // Clear the FPU stack, in case the called function doesn't do it by itself CLEAR_FPU_STACK - // Copy arguments from script - // stack to application stack + // Copy arguments from script + // stack to application stack mov ecx, paramSize mov eax, args add eax, ecx @@ -1338,132 +1338,132 @@ asQWORD NOINLINE CallThisCallFunctionRetByRef(const void *obj, const asDWORD *ar jne copyloop endcopy: -#ifdef THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK + #ifdef THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK // Push the object pointer on the stack push obj -#else + #else // Move object pointer to ECX mov ecx, obj -#endif + #endif - // Push the return pointer + // Push the return pointer push retPtr - // Call function + // Call function call [func] -#ifndef THISCALL_CALLEE_POPS_HIDDEN_RETURN_POINTER + #ifndef THISCALL_CALLEE_POPS_HIDDEN_RETURN_POINTER // Pop the return pointer add esp, 4 -#endif + #endif -#ifndef THISCALL_CALLEE_POPS_ARGUMENTS + #ifndef THISCALL_CALLEE_POPS_ARGUMENTS // Pop arguments add esp, paramSize -#ifdef THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK - // Pop object pointer + #ifdef THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK + // Pop object pointer add esp, 4 -#endif -#endif + #endif + #endif // Copy return value from EAX:EDX lea ecx, retQW mov [ecx], eax mov 4[ecx], edx - // Restore registers + // Restore registers pop ecx } -#elif defined ASM_AT_N_T + #elif defined ASM_AT_N_T volatile asPWORD a[] = {asPWORD(obj), asPWORD(args), asPWORD(paramSize), asPWORD(func), asPWORD(retPtr)}; - asm __volatile__ ( -#ifdef __OPTIMIZE__ - // When compiled with optimizations the stack unwind doesn't work properly, - // causing exceptions to crash the application. By adding this prologue - // and the epilogue below, the stack unwind works as it should. - // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below - "pushl %%ebp \n" - ".cfi_adjust_cfa_offset 4 \n" - ".cfi_rel_offset ebp, 0 \n" - "movl %%esp, %%ebp \n" - ".cfi_def_cfa_register ebp \n" -#endif - _S(CLEAR_FPU_STACK) "\n" - "pushl %%ebx \n" - "movl %%edx, %%ebx \n" - - // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. - // It is assumed that when entering this function, the stack pointer is already aligned, so we need - // to calculate how much we will put on the stack during this call. - "movl 8(%%ebx), %%eax \n" // paramSize - "addl $12, %%eax \n" // counting esp that we will push on the stack - "movl %%esp, %%ecx \n" - "subl %%eax, %%ecx \n" - "andl $15, %%ecx \n" - "movl %%esp, %%eax \n" - "subl %%ecx, %%esp \n" - "pushl %%eax \n" // Store the original stack pointer - - "movl 8(%%ebx), %%ecx \n" // paramSize - "movl 4(%%ebx), %%eax \n" // args - "addl %%ecx, %%eax \n" // push all arguments to the stack - "cmp $0, %%ecx \n" - "je endcopy3 \n" - "copyloop3: \n" - "subl $4, %%eax \n" - "pushl (%%eax) \n" - "subl $4, %%ecx \n" - "jne copyloop3 \n" - "endcopy3: \n" -#ifdef AS_MINGW47 - // MinGW made some strange choices with 4.7 and the thiscall calling convention, - // returning an object in memory is completely different from when not returning - // in memory - "pushl 0(%%ebx) \n" // push obj on the stack - "movl 16(%%ebx), %%ecx \n" // move the return pointer into ECX - "call *12(%%ebx) \n" // call the function -#else - "movl 0(%%ebx), %%ecx \n" // move obj into ECX -#ifdef THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK - "pushl %%ecx \n" // push obj on the stack -#endif - "pushl 16(%%ebx) \n" // push retPtr on the stack - "call *12(%%ebx) \n" -#ifndef THISCALL_CALLEE_POPS_HIDDEN_RETURN_POINTER - "addl $4, %%esp \n" // pop return pointer -#endif -#ifndef THISCALL_CALLEE_POPS_ARGUMENTS - "addl 8(%%ebx), %%esp \n" // pop arguments -#ifdef THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK - "addl $4, %%esp \n" // pop the object pointer -#endif -#endif -#endif // AS_MINGW47 - // Pop the alignment bytes - "popl %%esp \n" - "popl %%ebx \n" -#ifdef __OPTIMIZE__ - // Epilogue - "movl %%ebp, %%esp \n" - ".cfi_def_cfa_register esp \n" - "popl %%ebp \n" - ".cfi_adjust_cfa_offset -4 \n" - ".cfi_restore ebp \n" -#endif - // Copy EAX:EDX to retQW. As the stack pointer has been - // restored it is now safe to access the local variable - "leal %1, %%ecx \n" - "movl %%eax, 0(%%ecx) \n" - "movl %%edx, 4(%%ecx) \n" - : // output - : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument - : "%eax", "%ecx" // clobber - ); - -#endif + asm __volatile__( + #ifdef __OPTIMIZE__ + // When compiled with optimizations the stack unwind doesn't work properly, + // causing exceptions to crash the application. By adding this prologue + // and the epilogue below, the stack unwind works as it should. + // TODO: runtime optimize: The prologue/epilogue shouldn't be needed if the correct cfi directives are used below + "pushl %%ebp \n" + ".cfi_adjust_cfa_offset 4 \n" + ".cfi_rel_offset ebp, 0 \n" + "movl %%esp, %%ebp \n" + ".cfi_def_cfa_register ebp \n" + #endif + _S(CLEAR_FPU_STACK) "\n" + "pushl %%ebx \n" + "movl %%edx, %%ebx \n" + + // Need to align the stack pointer so that it is aligned to 16 bytes when making the function call. + // It is assumed that when entering this function, the stack pointer is already aligned, so we need + // to calculate how much we will put on the stack during this call. + "movl 8(%%ebx), %%eax \n" // paramSize + "addl $12, %%eax \n" // counting esp that we will push on the stack + "movl %%esp, %%ecx \n" + "subl %%eax, %%ecx \n" + "andl $15, %%ecx \n" + "movl %%esp, %%eax \n" + "subl %%ecx, %%esp \n" + "pushl %%eax \n" // Store the original stack pointer + + "movl 8(%%ebx), %%ecx \n" // paramSize + "movl 4(%%ebx), %%eax \n" // args + "addl %%ecx, %%eax \n" // push all arguments to the stack + "cmp $0, %%ecx \n" + "je endcopy3 \n" + "copyloop3: \n" + "subl $4, %%eax \n" + "pushl (%%eax) \n" + "subl $4, %%ecx \n" + "jne copyloop3 \n" + "endcopy3: \n" + #ifdef AS_MINGW47 + // MinGW made some strange choices with 4.7 and the thiscall calling convention, + // returning an object in memory is completely different from when not returning + // in memory + "pushl 0(%%ebx) \n" // push obj on the stack + "movl 16(%%ebx), %%ecx \n" // move the return pointer into ECX + "call *12(%%ebx) \n" // call the function + #else + "movl 0(%%ebx), %%ecx \n" // move obj into ECX + #ifdef THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK + "pushl %%ecx \n" // push obj on the stack + #endif + "pushl 16(%%ebx) \n" // push retPtr on the stack + "call *12(%%ebx) \n" + #ifndef THISCALL_CALLEE_POPS_HIDDEN_RETURN_POINTER + "addl $4, %%esp \n" // pop return pointer + #endif + #ifndef THISCALL_CALLEE_POPS_ARGUMENTS + "addl 8(%%ebx), %%esp \n" // pop arguments + #ifdef THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK + "addl $4, %%esp \n" // pop the object pointer + #endif + #endif + #endif // AS_MINGW47 + // Pop the alignment bytes + "popl %%esp \n" + "popl %%ebx \n" + #ifdef __OPTIMIZE__ + // Epilogue + "movl %%ebp, %%esp \n" + ".cfi_def_cfa_register esp \n" + "popl %%ebp \n" + ".cfi_adjust_cfa_offset -4 \n" + ".cfi_restore ebp \n" + #endif + // Copy EAX:EDX to retQW. As the stack pointer has been + // restored it is now safe to access the local variable + "leal %1, %%ecx \n" + "movl %%eax, 0(%%ecx) \n" + "movl %%edx, 4(%%ecx) \n" + : // output + : "d"(a), "m"(retQW) // input - pass pointer of args in edx, pass pointer of retQW in memory argument + : "%eax", "%ecx" // clobber + ); + + #endif return retQW; } @@ -1472,43 +1472,39 @@ asDWORD GetReturnedFloat() { asDWORD f; -#if defined ASM_INTEL + #if defined ASM_INTEL // Get the float value from ST0 - __asm fstp dword ptr [f] + __asm fstp dword ptr[f] -#elif defined ASM_AT_N_T + #elif defined ASM_AT_N_T - asm("fstps %0 \n" : "=m" (f)); + asm("fstps %0 \n" : "=m"(f)); -#endif + #endif - return f; + return f; } asQWORD GetReturnedDouble() { asQWORD d; -#if defined ASM_INTEL + #if defined ASM_INTEL // Get the double value from ST0 - __asm fstp qword ptr [d] + __asm fstp qword ptr[d] -#elif defined ASM_AT_N_T + #elif defined ASM_AT_N_T - asm("fstpl %0 \n" : "=m" (d)); + asm("fstpl %0 \n" : "=m"(d)); -#endif + #endif - return d; + return d; } END_AS_NAMESPACE -#endif // AS_X86 -#endif // AS_MAX_PORTABILITY - - - - + #endif // AS_X86 +#endif // AS_MAX_PORTABILITY diff --git a/sdk/angelscript/source/as_callfunc_xenon.cpp b/sdk/angelscript/source/as_callfunc_xenon.cpp index c52055e9..ca89e1be 100644 --- a/sdk/angelscript/source/as_callfunc_xenon.cpp +++ b/sdk/angelscript/source/as_callfunc_xenon.cpp @@ -50,27 +50,27 @@ // XBox 360 calling convention // =========================== -// I've yet to find an official document with the ABI for XBox 360, +// I've yet to find an official document with the ABI for XBox 360, // but I'll describe what I've gathered from the code and tests // performed by the AngelScript community. // // Arguments are passed in the following registers: // r3 - r10 : integer/pointer arguments (each register is 64bit) // fr1 - fr13 : float/double arguments (each register is 64bit) -// +// // Arguments that don't fit in the registers will be pushed on the stack. -// +// // When a float or double is passed as argument, its value will be placed // in the next available float register, but it will also reserve general -// purpose register. -// +// purpose register. +// // Example: void foo(float a, int b). a will be passed in fr1 and b in r4. // -// For each argument passed to a function an 8byte slot is reserved on the +// For each argument passed to a function an 8byte slot is reserved on the // stack, so that the function can offload the value there if needed. The // first slot is at r1+20, the next at r1+28, etc. // -// If the function is a class method, the this pointer is passed as hidden +// If the function is a class method, the this pointer is passed as hidden // first argument. If the function returns an object in memory, the address // for that memory is passed as hidden first argument. // @@ -96,29 +96,28 @@ #include "as_config.h" #ifndef AS_MAX_PORTABILITY -#if defined(AS_XENON) + #if defined(AS_XENON) -#include "as_callfunc.h" -#include "as_scriptengine.h" -#include "as_texts.h" -#include "as_tokendef.h" -#include "as_context.h" + #include "as_callfunc.h" + #include "as_scriptengine.h" + #include "as_texts.h" + #include "as_tokendef.h" + #include "as_context.h" -#include -#include -#include + #include + #include + #include BEGIN_AS_NAMESPACE -#define AS_PPC_MAX_ARGS 32 -#define AS_PPC_THISCALL_REG 1 -#define AS_PPC_RETURNINMEM_REG 1 -#define AS_PPC_ENDOFARGS 1 + #define AS_PPC_MAX_ARGS 32 + #define AS_PPC_THISCALL_REG 1 + #define AS_PPC_RETURNINMEM_REG 1 + #define AS_PPC_ENDOFARGS 1 // The array used to send values to the correct places. // Contains a byte of argTypes to indicate the register type to load, or zero if end of arguments -enum argTypes -{ +enum argTypes { ppcENDARG = 0, ppcINTARG = 1, ppcFLOATARG = 2, @@ -129,7 +128,7 @@ enum argTypes // pArgs is the array of the argument values // pArgTypes is an array containing a byte indicating the type (enum argTypes) for each argument. // dwFunc is the address of the function that will be called -asQWORD __declspec( naked ) ppcFunc(const asQWORD* pArgs, asDWORD dwFunc, const asBYTE* pArgTypes) +asQWORD __declspec(naked) ppcFunc(const asQWORD *pArgs, asDWORD dwFunc, const asBYTE *pArgTypes) { __asm { @@ -154,34 +153,34 @@ asQWORD __declspec( naked ) ppcFunc(const asQWORD* pArgs, asDWORD dwFunc, const // TODO: Should perhaps make this dynamic based on number of arguments stwu r1,-200h(r1) -////////////////////////////////////////////////////////////////////////// -// Initialize local variables -////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + // Initialize local variables + ////////////////////////////////////////////////////////////////////////// // r31 is our pointer into the stack where the arguments will be place // The MSVC optimizer seems to rely on nobody copying the r1 register directly // so we can't just do a simple 'addi r31, r1, 14h' as the optimizer may - // end up moving this instruction to before the update of r1 above. - // Instead we'll read the previous stack pointer from the stack, and then + // end up moving this instruction to before the update of r1 above. + // Instead we'll read the previous stack pointer from the stack, and then // subtract to get the correct offset. lwz r31, 0(r1) - subi r31, r31, 1ECh // prev r1 - 512 + 20 = curr r1 + 20 + subi r31, r31, 1ECh // prev r1 - 512 + 20 = curr r1 + 20 - mr r26, r3 // pArgs - mr r27, r4 // dwFunc - mr r25, r5 // pArgTypes + mr r26, r3 // pArgs + mr r27, r4 // dwFunc + mr r25, r5 // pArgTypes - // Counting of used/assigned GPR's + // Counting of used/assigned GPR's sub r23, r23, r23 - // Counting of used/assigned Float Registers + // Counting of used/assigned Float Registers sub r22, r22, r22 - // Begin loading and stacking registers + // Begin loading and stacking registers subi r25, r25, 1 -////////////////////////////////////////////////////////////////////////// -// Fetch the next argument -////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + // Fetch the next argument + ////////////////////////////////////////////////////////////////////////// ppcNextArg: // Increment rArgTypePtr addi r25, r25, 1 @@ -198,9 +197,9 @@ asQWORD __declspec( naked ) ppcFunc(const asQWORD* pArgs, asDWORD dwFunc, const cmplwi cr6, r24, 3 beq cr6, ppcArgIsDouble -////////////////////////////////////////////////////////////////////////// -// Load and stack integer arguments -////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + // Load and stack integer arguments + ////////////////////////////////////////////////////////////////////////// ppcArgIsInteger: // Get the arg from the stack ld r12, 0(r26) @@ -223,7 +222,7 @@ asQWORD __declspec( naked ) ppcFunc(const asQWORD* pArgs, asDWORD dwFunc, const cmplwi cr6, r23, 7 beq cr6, ppcLoadIntReg7 - // no more than 8 parameters + // no more than 8 parameters b ppcLoadIntRegUpd ppcLoadIntReg0: @@ -252,16 +251,16 @@ asQWORD __declspec( naked ) ppcFunc(const asQWORD* pArgs, asDWORD dwFunc, const b ppcLoadIntRegUpd ppcLoadIntRegUpd: - std r12, 0(r31) // push on the stack - addi r31, r31, 8 // inc stack by 1 reg + std r12, 0(r31) // push on the stack + addi r31, r31, 8 // inc stack by 1 reg - addi r23, r23, 1 // Increment used int register count - addi r26, r26, 8 // Increment pArgs - b ppcNextArg // Call next arg + addi r23, r23, 1 // Increment used int register count + addi r26, r26, 8 // Increment pArgs + b ppcNextArg // Call next arg -////////////////////////////////////////////////////////////////////////// -// Load and stack float arguments -////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + // Load and stack float arguments + ////////////////////////////////////////////////////////////////////////// ppcArgIsFloat: // Get the arg from the stack lfs fr0, 0(r26) @@ -294,7 +293,7 @@ asQWORD __declspec( naked ) ppcFunc(const asQWORD* pArgs, asDWORD dwFunc, const cmplwi cr6, r22, 12 beq cr6, ppcLoadFloatReg12 - // no more than 12 parameters + // no more than 12 parameters b ppcLoadFloatRegUpd ppcLoadFloatReg0: @@ -338,17 +337,17 @@ asQWORD __declspec( naked ) ppcFunc(const asQWORD* pArgs, asDWORD dwFunc, const b ppcLoadFloatRegUpd ppcLoadFloatRegUpd: - stfs fr0, 0(r31) // push on the stack - addi r31, r31, 8 // inc stack by 1 reg + stfs fr0, 0(r31) // push on the stack + addi r31, r31, 8 // inc stack by 1 reg - addi r22, r22, 1 // Increment used float register count - addi r23, r23, 1 // Increment used int register count - a float reg eats up a GPR - addi r26, r26, 4 // Increment pArgs - b ppcNextArg // Call next arg - -////////////////////////////////////////////////////////////////////////// -// Load and stack double float arguments -////////////////////////////////////////////////////////////////////////// + addi r22, r22, 1 // Increment used float register count + addi r23, r23, 1 // Increment used int register count - a float reg eats up a GPR + addi r26, r26, 4 // Increment pArgs + b ppcNextArg // Call next arg + + ////////////////////////////////////////////////////////////////////////// + // Load and stack double float arguments + ////////////////////////////////////////////////////////////////////////// ppcArgIsDouble: // Get the arg from the stack lfd fr0, 0(r26) @@ -381,7 +380,7 @@ asQWORD __declspec( naked ) ppcFunc(const asQWORD* pArgs, asDWORD dwFunc, const cmplwi cr6, r22, 12 beq cr6, ppcLoadDoubleReg12 - // no more than 12 parameters + // no more than 12 parameters b ppcLoadDoubleRegUpd ppcLoadDoubleReg0: @@ -425,24 +424,24 @@ asQWORD __declspec( naked ) ppcFunc(const asQWORD* pArgs, asDWORD dwFunc, const b ppcLoadDoubleRegUpd ppcLoadDoubleRegUpd: - stfd fr0, 0(r31) // push on the stack - addi r31, r31, 8 // inc stack by 1 reg + stfd fr0, 0(r31) // push on the stack + addi r31, r31, 8 // inc stack by 1 reg - addi r22, r22, 1 // Increment used float register count - addi r23, r23, 1 // Increment used int register count - addi r26, r26, 8 // Increment pArgs + addi r22, r22, 1 // Increment used float register count + addi r23, r23, 1 // Increment used int register count + addi r26, r26, 8 // Increment pArgs b ppcNextArg -////////////////////////////////////////////////////////////////////////// -// Finished -////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + // Finished + ////////////////////////////////////////////////////////////////////////// ppcArgsEnd: // Call the function mtctr r27 bctrl - // Epilogue - // Restore callers stack + // Epilogue + // Restore callers stack addi r1, r1, 200h // restore all registers we used in this fct @@ -463,7 +462,7 @@ asQWORD __declspec( naked ) ppcFunc(const asQWORD* pArgs, asDWORD dwFunc, const asDWORD GetReturnedFloat() { - // This variable must be declared volatile so that the + // This variable must be declared volatile so that the // compiler optimizations do not remove its initialization // with the fr1 register due to believing the fr1 register // isn't initialized. @@ -479,7 +478,7 @@ asDWORD GetReturnedFloat() asQWORD GetReturnedDouble() { - // This variable must be declared volatile so that the + // This variable must be declared volatile so that the // compiler optimizations do not remove its initialization // with the fr1 register due to believing the fr1 register // isn't initialized. @@ -494,20 +493,20 @@ asQWORD GetReturnedDouble() } // returns true if the given parameter is a 'variable argument' -inline bool IsVariableArgument( asCDataType type ) +inline bool IsVariableArgument(asCDataType type) { return (type.GetTokenType() == ttQuestion) ? true : false; } -asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD &/*retQW2*/, void */*secondObject*/) +asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, void *obj, asDWORD *args, void *retPointer, asQWORD & /*retQW2*/, void * /*secondObject*/) { // TODO: Xenon does not yet support THISCALL_OBJFIRST/LAST - asCScriptEngine *engine = context->m_engine; - asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; - int callConv = sysFunc->callConv; - asQWORD retQW = 0; - void *func = (void*)sysFunc->func; + asCScriptEngine *engine = context->m_engine; + asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; + int callConv = sysFunc->callConv; + asQWORD retQW = 0; + void *func = (void *)sysFunc->func; asDWORD *vftable; // Pack the arguments into an array that ppcFunc() can use to load each CPU register properly @@ -518,22 +517,22 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // If the function returns an object in memory, we allocate the memory and put the ptr to the front (will go to r3) if( sysFunc->hostReturnInMemory ) { - ppcArgs[argsCnt] = (asDWORD)retPointer; + ppcArgs[argsCnt] = (asDWORD)retPointer; ppcArgsType[argsCnt] = ppcINTARG; argsCnt++; } // If we have an object and it's not objectlast, then we put it as the first arg - if ( obj && - callConv != ICC_CDECL_OBJLAST && - callConv != ICC_CDECL_OBJLAST_RETURNINMEM ) + if( obj && + callConv != ICC_CDECL_OBJLAST && + callConv != ICC_CDECL_OBJLAST_RETURNINMEM ) { - ppcArgs[argsCnt] = (asDWORD)obj; + ppcArgs[argsCnt] = (asDWORD)obj; ppcArgsType[argsCnt] = ppcINTARG; argsCnt++; } - // If the function takes any objects by value, they must be copied + // If the function takes any objects by value, they must be copied // to the stack, shifting the other arguments as necessary. paramBuffer // will then replace the args pointer that was received from the VM. // TODO: Is this really how XBox 360 passes objects by value? @@ -541,33 +540,33 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, if( sysFunc->takesObjByVal ) { int paramSize = 0; - int spos = 0; - int dpos = 1; + int spos = 0; + int dpos = 1; for( asUINT n = 0; n < descr->parameterTypes.GetLength(); n++ ) { // Parameter object by value - if( descr->parameterTypes[n].IsObject() && - !descr->parameterTypes[n].IsObjectHandle() && - !descr->parameterTypes[n].IsReference() ) + if( descr->parameterTypes[n].IsObject() && + !descr->parameterTypes[n].IsObjectHandle() && + !descr->parameterTypes[n].IsReference() ) { -#ifdef COMPLEX_OBJS_PASSED_BY_REF + #ifdef COMPLEX_OBJS_PASSED_BY_REF if( descr->parameterTypes[n].GetTypeInfo()->flags & COMPLEX_MASK ) { paramBuffer[dpos++] = args[spos++]; paramSize++; } else -#endif + #endif { // Copy the object's memory to the buffer - memcpy( ¶mBuffer[dpos], *(void**)(args + spos), descr->parameterTypes[n].GetSizeInMemoryBytes() ); + memcpy(¶mBuffer[dpos], *(void **)(args + spos), descr->parameterTypes[n].GetSizeInMemoryBytes()); // Delete the original memory - engine->CallFree(*(char**)(args + spos)); + engine->CallFree(*(char **)(args + spos)); spos++; - dpos += descr->parameterTypes[n].GetSizeInMemoryDWords(); + dpos += descr->parameterTypes[n].GetSizeInMemoryDWords(); paramSize += descr->parameterTypes[n].GetSizeInMemoryDWords(); } } @@ -581,7 +580,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, } // If this was a variable argument parameter, then account for the implicit typeId - if( IsVariableArgument( descr->parameterTypes[n] ) ) + if( IsVariableArgument(descr->parameterTypes[n]) ) { // the TypeId is just a DWORD paramBuffer[dpos++] = args[spos++]; @@ -598,28 +597,28 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, const asUINT paramCount = (asUINT)descr->parameterTypes.GetLength(); - asBYTE * pCurArgType = (asBYTE*)&ppcArgsType[argsCnt]; - asBYTE * pCurFixedArgValue = (asBYTE*)&ppcArgs[argsCnt]; - asBYTE * pCurStackArgValue = (asBYTE*)args; + asBYTE *pCurArgType = (asBYTE *)&ppcArgsType[argsCnt]; + asBYTE *pCurFixedArgValue = (asBYTE *)&ppcArgs[argsCnt]; + asBYTE *pCurStackArgValue = (asBYTE *)args; for( asUINT n = 0; n < paramCount; n++ ) - { + { argsCnt++; - if (descr->parameterTypes[n].IsFloatType() && !descr->parameterTypes[n].IsReference()) + if( descr->parameterTypes[n].IsFloatType() && !descr->parameterTypes[n].IsReference() ) { *pCurArgType++ = ppcFLOATARG; - *((float*) pCurFixedArgValue) = *((float*) pCurStackArgValue); + *((float *)pCurFixedArgValue) = *((float *)pCurStackArgValue); pCurFixedArgValue += 4; pCurStackArgValue += 4; } - else if (descr->parameterTypes[n].IsDoubleType() && !descr->parameterTypes[n].IsReference()) + else if( descr->parameterTypes[n].IsDoubleType() && !descr->parameterTypes[n].IsReference() ) { *pCurArgType++ = ppcDOUBLEARG; - *((double*) pCurFixedArgValue) = *((double*) pCurStackArgValue); + *((double *)pCurFixedArgValue) = *((double *)pCurStackArgValue); pCurFixedArgValue += 8; pCurStackArgValue += 8; @@ -632,7 +631,7 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, *pCurArgType++ = ppcINTARG; - *((asQWORD*) pCurFixedArgValue) = *((asUINT*) pCurStackArgValue); + *((asQWORD *)pCurFixedArgValue) = *((asUINT *)pCurStackArgValue); if( !descr->parameterTypes[n].IsReference() ) { @@ -640,16 +639,16 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, asUINT numBytes = descr->parameterTypes[n].GetSizeInMemoryBytes(); if( numBytes == 1 ) { - *((asQWORD*) pCurFixedArgValue) = *((asBYTE*) pCurStackArgValue); + *((asQWORD *)pCurFixedArgValue) = *((asBYTE *)pCurStackArgValue); } else if( numBytes == 2 ) { - *((asQWORD*) pCurFixedArgValue) = *((asWORD*) pCurStackArgValue); + *((asQWORD *)pCurFixedArgValue) = *((asWORD *)pCurStackArgValue); } else if( numBytes == 8 ) { - *((asQWORD*) pCurFixedArgValue) = *((asQWORD*) pCurStackArgValue); - pCurStackArgValue += 4; // Increase our cur stack arg value by 4 bytes to = 8 total later + *((asQWORD *)pCurFixedArgValue) = *((asQWORD *)pCurStackArgValue); + pCurStackArgValue += 4; // Increase our cur stack arg value by 4 bytes to = 8 total later } } @@ -659,12 +658,12 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, // if it is a variable argument, account for the typeId // implicitly add another parameter (AFTER the parameter above) for the typeId if( IsVariableArgument(descr->parameterTypes[n]) ) - { + { argsCnt++; *pCurArgType++ = ppcINTARG; - *((int*) pCurFixedArgValue) = *((int*) pCurStackArgValue); + *((int *)pCurFixedArgValue) = *((int *)pCurStackArgValue); pCurFixedArgValue += 4; pCurStackArgValue += 4; @@ -677,45 +676,45 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, switch( callConv ) { - case ICC_CDECL: - case ICC_CDECL_RETURNINMEM: - case ICC_STDCALL: - case ICC_STDCALL_RETURNINMEM: - case ICC_THISCALL: - case ICC_THISCALL_RETURNINMEM: - case ICC_CDECL_OBJFIRST: - case ICC_CDECL_OBJFIRST_RETURNINMEM: - { - retQW = ppcFunc( ppcArgs, (asDWORD)func, ppcArgsType ); - break; - } - case ICC_VIRTUAL_THISCALL: - case ICC_VIRTUAL_THISCALL_RETURNINMEM: - { - // Get virtual function table from the object pointer - vftable = *(asDWORD**)obj; - retQW = ppcFunc( ppcArgs, vftable[asDWORD(func)>>2], ppcArgsType ); - break; - } - case ICC_CDECL_OBJLAST: - case ICC_CDECL_OBJLAST_RETURNINMEM: - { - // Add the object pointer as the last argument - ppcArgsType[argsCnt++] = ppcINTARG; - ppcArgsType[argsCnt] = ppcENDARG; - *((asQWORD*)pCurFixedArgValue) = (asPWORD)obj; - retQW = ppcFunc( ppcArgs, (asDWORD)func, ppcArgsType ); - break; - } - default: - context->SetInternalException( TXT_INVALID_CALLING_CONVENTION ); + case ICC_CDECL: + case ICC_CDECL_RETURNINMEM: + case ICC_STDCALL: + case ICC_STDCALL_RETURNINMEM: + case ICC_THISCALL: + case ICC_THISCALL_RETURNINMEM: + case ICC_CDECL_OBJFIRST: + case ICC_CDECL_OBJFIRST_RETURNINMEM: + { + retQW = ppcFunc(ppcArgs, (asDWORD)func, ppcArgsType); + break; + } + case ICC_VIRTUAL_THISCALL: + case ICC_VIRTUAL_THISCALL_RETURNINMEM: + { + // Get virtual function table from the object pointer + vftable = *(asDWORD **)obj; + retQW = ppcFunc(ppcArgs, vftable[asDWORD(func) >> 2], ppcArgsType); + break; + } + case ICC_CDECL_OBJLAST: + case ICC_CDECL_OBJLAST_RETURNINMEM: + { + // Add the object pointer as the last argument + ppcArgsType[argsCnt++] = ppcINTARG; + ppcArgsType[argsCnt] = ppcENDARG; + *((asQWORD *)pCurFixedArgValue) = (asPWORD)obj; + retQW = ppcFunc(ppcArgs, (asDWORD)func, ppcArgsType); + break; + } + default: + context->SetInternalException(TXT_INVALID_CALLING_CONVENTION); } // If the return is a float value we need to get the value from the FP register if( sysFunc->hostReturnFloat ) { if( sysFunc->hostReturnSize == 1 ) - *(asDWORD*)&retQW = GetReturnedFloat(); + *(asDWORD *)&retQW = GetReturnedFloat(); else retQW = GetReturnedDouble(); } @@ -730,8 +729,5 @@ asQWORD CallSystemFunctionNative(asCContext *context, asCScriptFunction *descr, END_AS_NAMESPACE -#endif // AS_XENON -#endif // AS_MAX_PORTABILITY - - - + #endif // AS_XENON +#endif // AS_MAX_PORTABILITY diff --git a/sdk/angelscript/source/as_compiler.cpp b/sdk/angelscript/source/as_compiler.cpp index 8cd093f4..bc427347 100644 --- a/sdk/angelscript/source/as_compiler.cpp +++ b/sdk/angelscript/source/as_compiler.cpp @@ -38,23 +38,23 @@ #include // fmodf() pow() #ifdef _MSC_VER -// Apparently a bug in MSVC (or perhaps Windows SDK) caused use HUGE_VALF to issue a warning -// ref: https://developercommunity.visualstudio.com/t/C4756-related-issues-in-VS-2022/10697767 -#pragma warning(disable:4756) + // Apparently a bug in MSVC (or perhaps Windows SDK) caused use HUGE_VALF to issue a warning + // ref: https://developercommunity.visualstudio.com/t/C4756-related-issues-in-VS-2022/10697767 + #pragma warning(disable : 4756) #endif #include "as_config.h" #ifndef AS_NO_COMPILER -#include "as_compiler.h" -#include "as_tokendef.h" -#include "as_tokenizer.h" -#include "as_string_util.h" -#include "as_texts.h" -#include "as_parser.h" -#include "as_debug.h" -#include "as_context.h" // as_powi() + #include "as_compiler.h" + #include "as_tokendef.h" + #include "as_tokenizer.h" + #include "as_string_util.h" + #include "as_texts.h" + #include "as_parser.h" + #include "as_debug.h" + #include "as_context.h" // as_powi() BEGIN_AS_NAMESPACE @@ -85,12 +85,12 @@ BEGIN_AS_NAMESPACE asCCompiler::asCCompiler(asCScriptEngine *engine) : byteCode(engine) { builder = 0; - script = 0; + script = 0; - variables = 0; + variables = 0; isProcessingDeferredParams = false; - isCompilingDefaultArg = false; - noCodeOutput = 0; + isCompilingDefaultArg = false; + noCodeOutput = 0; } asCCompiler::~asCCompiler() @@ -98,27 +98,27 @@ asCCompiler::~asCCompiler() while( variables ) { asCVariableScope *var = variables; - variables = variables->parent; + variables = variables->parent; - asDELETE(var,asCVariableScope); + asDELETE(var, asCVariableScope); } // Clean up all the string constants that were allocated. By now the script // functions that were compiled successfully already holds their own references - for (asUINT n = 0; n < usedStringConstants.GetLength(); n++) + for( asUINT n = 0; n < usedStringConstants.GetLength(); n++ ) engine->stringFactory->ReleaseStringConstant(usedStringConstants[n]); usedStringConstants.SetLength(0); // Clean up the temporary script nodes that were allocated during compilation - for (asUINT n = 0; n < nodesToFreeUponComplete.GetLength(); n++) + for( asUINT n = 0; n < nodesToFreeUponComplete.GetLength(); n++ ) nodesToFreeUponComplete[n]->Destroy(engine); } void asCCompiler::Reset(asCBuilder *in_builder, asCScriptCode *in_script, asCScriptFunction *in_outFunc) { this->builder = in_builder; - this->engine = in_builder->engine; - this->script = in_script; + this->engine = in_builder->engine; + this->script = in_script; this->outFunc = in_outFunc; hasCompileErrors = false; @@ -140,7 +140,7 @@ void asCCompiler::Reset(asCBuilder *in_builder, asCScriptCode *in_script, asCScr m_propertyAccessCount.EraseAll(); } -int asCCompiler::CompileDefaultCopyConstructor(asCBuilder* in_builder, asCScriptCode* in_script, asCScriptNode* in_node, asCScriptFunction* in_outFunc, sClassDeclaration* in_classDecl) +int asCCompiler::CompileDefaultCopyConstructor(asCBuilder *in_builder, asCScriptCode *in_script, asCScriptNode *in_node, asCScriptFunction *in_outFunc, sClassDeclaration *in_classDecl) { Reset(in_builder, in_script, in_outFunc); @@ -155,20 +155,20 @@ int asCCompiler::CompileDefaultCopyConstructor(asCBuilder* in_builder, asCScript // in case the member initialization refers to undefined symbols. AddVariableScope(); - // Initialize the class members that are not inherited from a base class first. This will allow the base + // Initialize the class members that are not inherited from a base class first. This will allow the base // class' copy constructor to access these members without worry they will be uninitialized. This can // happen if the base class' copy constructor calls a method that is overridden by the derived class. CompileMemberInitializationCopy(&byteCode); // If the class is derived from another, then the base class' copy constructor must be called - if (outFunc->objectType->derivedFrom) + if( outFunc->objectType->derivedFrom ) { - if (outFunc->objectType->derivedFrom->beh.copyconstruct) + if( outFunc->objectType->derivedFrom->beh.copyconstruct ) { asCExprContext ctx(engine); - asCScriptFunction* copyfunc = engine->scriptFunctions[outFunc->objectType->derivedFrom->beh.copyconstruct]; - if (copyfunc->parameterTypes[0].IsObjectHandle()) + asCScriptFunction *copyfunc = engine->scriptFunctions[outFunc->objectType->derivedFrom->beh.copyconstruct]; + if( copyfunc->parameterTypes[0].IsObjectHandle() ) { int varOffset = AllocateVariable(copyfunc->parameterTypes[0], true); CompileVariableAccess("other", "", &ctx, 0); @@ -197,7 +197,7 @@ int asCCompiler::CompileDefaultCopyConstructor(asCBuilder* in_builder, asCScript } else { - if (outFunc->objectType->derivedFrom->beh.construct == 0 || outFunc->objectType->derivedFrom->beh.copy == 0) + if( outFunc->objectType->derivedFrom->beh.construct == 0 || outFunc->objectType->derivedFrom->beh.copy == 0 ) Error(TXT_BASE_DOESNT_HAVE_CPY_CONSTR_OR_DEF_CONSTR, in_node); else { @@ -223,13 +223,13 @@ int asCCompiler::CompileDefaultCopyConstructor(asCBuilder* in_builder, asCScript byteCode.Label(0); // Call destructors for function parameters (there is only one, the object handle to the other object) - for (int n = (int)variables->variables.GetLength() - 1; n >= 0; n--) + for( int n = (int)variables->variables.GetLength() - 1; n >= 0; n-- ) { - sVariable* v = variables->variables[n]; - if (v->stackOffset <= 0) + sVariable *v = variables->variables[n]; + if( v->stackOffset <= 0 ) { // Call variable destructors here, for variables not yet destroyed - if (v->name != "return") + if( v->name != "return" ) CallDestructor(v->type, v->stackOffset, v->onHeap, &byteCode); } @@ -239,7 +239,7 @@ int asCCompiler::CompileDefaultCopyConstructor(asCBuilder* in_builder, asCScript byteCode.OptimizeLocally(tempVariableOffsets); // If there are compile errors, there is no reason to build the final code - if (hasCompileErrors) + if( hasCompileErrors ) return -1; // Remove the variable scope @@ -249,15 +249,15 @@ int asCCompiler::CompileDefaultCopyConstructor(asCBuilder* in_builder, asCScript byteCode.Ret(AS_PTR_SIZE); // Count total variable size - int varSize = GetVariableOffset((int)variableAllocations.GetLength()) - 1; + int varSize = GetVariableOffset((int)variableAllocations.GetLength()) - 1; outFunc->scriptData->variableSpace = varSize; FinalizeFunction(); -#ifdef AS_DEBUG + #ifdef AS_DEBUG // DEBUG: output byte code byteCode.DebugOutput(("__" + outFunc->objectType->name + "_" + outFunc->name + "__copyconstr.txt").AddressOf(), in_outFunc); -#endif + #endif return 0; } @@ -306,15 +306,15 @@ int asCCompiler::CompileDefaultConstructor(asCBuilder *in_builder, asCScriptCode byteCode.Ret(AS_PTR_SIZE); // Count total variable size - int varSize = GetVariableOffset((int)variableAllocations.GetLength()) - 1; + int varSize = GetVariableOffset((int)variableAllocations.GetLength()) - 1; outFunc->scriptData->variableSpace = varSize; FinalizeFunction(); -#ifdef AS_DEBUG + #ifdef AS_DEBUG // DEBUG: output byte code byteCode.DebugOutput(("__" + outFunc->objectType->name + "_" + outFunc->name + "__defconstr.txt").AddressOf(), in_outFunc); -#endif + #endif return 0; } @@ -327,8 +327,8 @@ int asCCompiler::CompileFactory(asCBuilder *in_builder, asCScriptCode *in_script byteCode.InstrPTR(asBC_JitEntry, 0); // Find the corresponding constructor - asCDataType dt = asCDataType::CreateType(outFunc->returnType.GetTypeInfo(), false); - int constructor = 0; + asCDataType dt = asCDataType::CreateType(outFunc->returnType.GetTypeInfo(), false); + int constructor = 0; for( unsigned int n = 0; n < dt.GetBehaviour()->factories.GetLength(); n++ ) { if( dt.GetBehaviour()->factories[n] == outFunc->id ) @@ -350,7 +350,7 @@ int asCCompiler::CompileFactory(asCBuilder *in_builder, asCScriptCode *in_script for( int a = int(outFunc->parameterTypes.GetLength()) - 1; a >= 0; a-- ) { if( !outFunc->parameterTypes[a].IsPrimitive() || - outFunc->parameterTypes[a].IsReference() ) + outFunc->parameterTypes[a].IsReference() ) { offset -= AS_PTR_SIZE; byteCode.InstrSHORT(asBC_PshVPtr, short(-offset)); @@ -384,7 +384,7 @@ int asCCompiler::CompileFactory(asCBuilder *in_builder, asCScriptCode *in_script // Tell the virtual machine not to clean up parameters on exception outFunc->dontCleanUpOnException = true; -/* + /* #ifdef AS_DEBUG // DEBUG: output byte code asCString args; @@ -403,7 +403,7 @@ void asCCompiler::FinalizeFunction() asUINT n; // Add the type of all temporary variables to the function so this is known to debugger and serializer - for (n = 0; n < tempVariableOffsets.GetLength(); n++) + for( n = 0; n < tempVariableOffsets.GetLength(); n++ ) { int slot = GetVariableSlot(tempVariableOffsets[n]); outFunc->AddVariable("", variableAllocations[slot], tempVariableOffsets[n], variableIsOnHeap[slot]); @@ -414,15 +414,15 @@ void asCCompiler::FinalizeFunction() // location where the value will be stored is pushed on the stack before // the arguments bool isDestructor = (outFunc->name.GetLength() > 0 && outFunc->name[0] == '~') ? true : false; - if (!(isDestructor || m_isConstructor) && outFunc->DoesReturnOnStack()) + if( !(isDestructor || m_isConstructor) && outFunc->DoesReturnOnStack() ) stackPos -= AS_PTR_SIZE; - for (n = 0; n < outFunc->parameterNames.GetLength(); n++) + for( n = 0; n < outFunc->parameterNames.GetLength(); n++ ) { // Get the parameter type - asCDataType& type = outFunc->parameterTypes[n]; + asCDataType &type = outFunc->parameterTypes[n]; // If the parameter has a name then it was already added to the list in SetupParametersAndReturnVariable - if (outFunc->parameterNames[n] == "") + if( outFunc->parameterNames[n] == "" ) { // Object types passed by value are considered to be on heap bool onHeap = !type.IsReference() && type.IsObject() && !type.IsObjectHandle(); @@ -433,7 +433,7 @@ void asCCompiler::FinalizeFunction() stackPos -= type.GetSizeOnStackDWords(); } // Add the return type too at the end if it returns on the stack, which is when it uses a hidden parameter - if (outFunc->DoesReturnOnStack()) + if( outFunc->DoesReturnOnStack() ) { // Though declared as return by value, locally the return value is seen as a reference asCDataType returnType = outFunc->returnType; @@ -444,7 +444,7 @@ void asCCompiler::FinalizeFunction() // Finalize the bytecode byteCode.Finalize(tempVariableOffsets); - // extract the try/catch info before object variable info, as + // extract the try/catch info before object variable info, as // some variable info is not needed if there are no try/catch blocks byteCode.ExtractTryCatchInfo(outFunc); @@ -465,7 +465,7 @@ void asCCompiler::FinalizeFunction() if( byteCode.sectionIdxs[n] != lastIdx ) { lastIdx = byteCode.sectionIdxs[n]; - outFunc->scriptData->sectionIdxs.PushLast(byteCode.lineNumbers[n*2]); + outFunc->scriptData->sectionIdxs.PushLast(byteCode.lineNumbers[n * 2]); outFunc->scriptData->sectionIdxs.PushLast(lastIdx); } } @@ -484,7 +484,7 @@ int asCCompiler::SetupParametersAndReturnVariable(asCArray ¶meter // part of. AddVariableScope(); - bool isDestructor = false; + bool isDestructor = false; asCDataType returnType; // Examine return type @@ -501,9 +501,9 @@ int asCCompiler::SetupParametersAndReturnVariable(asCArray ¶meter // Is the return type allowed? if( returnType != asCDataType::CreatePrimitive(ttVoid, false) && - !returnType.CanBeInstantiated() && - !returnType.IsReference() && - !returnType.IsObjectHandle() ) + !returnType.CanBeInstantiated() && + !returnType.IsReference() && + !returnType.IsObjectHandle() ) { // TODO: Hasn't this been validated by the builder already? asCString str; @@ -524,13 +524,13 @@ int asCCompiler::SetupParametersAndReturnVariable(asCArray ¶meter for( n = 0; n < parameterNames.GetLength(); n++ ) { // Get the parameter type - asCDataType &type = outFunc->parameterTypes[n]; + asCDataType &type = outFunc->parameterTypes[n]; asETypeModifiers inoutFlag = n < outFunc->inOutFlags.GetLength() ? outFunc->inOutFlags[n] : asTM_NONE; // Is the data type allowed? // TODO: Hasn't this been validated by the builder already? if( (type.IsReference() && inoutFlag != asTM_INOUTREF && !type.CanBeInstantiated()) || - (!type.IsReference() && !type.CanBeInstantiated()) ) + (!type.IsReference() && !type.CanBeInstantiated()) ) { asCString parm = type.Format(outFunc->nameSpace); if( inoutFlag == asTM_INREF ) @@ -574,21 +574,21 @@ int asCCompiler::SetupParametersAndReturnVariable(asCArray ¶meter return stackPos; } -void asCCompiler::CompileMemberInitializationCopy(asCByteCode* bc) +void asCCompiler::CompileMemberInitializationCopy(asCByteCode *bc) { asASSERT(m_classDecl); - // Initialize each member in the order they were declared. Skip members inherited + // Initialize each member in the order they were declared. Skip members inherited // from a base class, as they will be taken care of by the base class' constructor - for (asUINT n = 0; n < outFunc->objectType->properties.GetLength(); n++) + for( asUINT n = 0; n < outFunc->objectType->properties.GetLength(); n++ ) { - asCObjectProperty* prop = outFunc->objectType->properties[n]; + asCObjectProperty *prop = outFunc->objectType->properties[n]; // Check if the property is inherited - asCScriptNode* declNode = 0; - for (asUINT m = 0; m < m_classDecl->propInits.GetLength(); m++) + asCScriptNode *declNode = 0; + for( asUINT m = 0; m < m_classDecl->propInits.GetLength(); m++ ) { - if (m_classDecl->propInits[m].name == prop->name) + if( m_classDecl->propInits[m].name == prop->name ) { declNode = m_classDecl->propInits[m].declNode; break; @@ -596,7 +596,7 @@ void asCCompiler::CompileMemberInitializationCopy(asCByteCode* bc) } // If declNode is null then the property was inherited - if (declNode) + if( declNode ) { // Add a line instruction with the position of the declaration LineInstr(bc, declNode->tokenPos); @@ -609,27 +609,27 @@ void asCCompiler::CompileMemberInitializationCopy(asCByteCode* bc) // Code is similar to CompileExprPostOp for the ttDot operator // TODO: cleanup: Make a reusable method for both CompileExprPostOp with ttDot and here ctx.bc.InstrSHORT_DW(asBC_ADDSi, (short)prop->byteOffset, engine->GetTypeIdFromDataType(asCDataType::CreateType(outFunc->objectType, false))); - if (prop->type.IsReference()) + if( prop->type.IsReference() ) ctx.bc.Instr(asBC_RDSPtr); // Reference to primitive must be stored in the temp register - if (prop->type.IsPrimitive()) + if( prop->type.IsPrimitive() ) ctx.bc.Instr(asBC_PopRPtr); // Set the new type and make sure it is not treated as a variable anymore ctx.type.dataType = prop->type; ctx.type.dataType.MakeReference(true); - ctx.type.isVariable = false; + ctx.type.isVariable = false; ctx.type.isTemporary = false; - if ((ctx.type.dataType.IsObject() || ctx.type.dataType.IsFuncdef()) && !ctx.type.dataType.IsObjectHandle()) + if( (ctx.type.dataType.IsObject() || ctx.type.dataType.IsFuncdef()) && !ctx.type.dataType.IsObjectHandle() ) { // Objects that are members are not references ctx.type.dataType.MakeReference(false); // The object is safe (life time guaranteed) if the parent object is also safe } - else if (ctx.type.dataType.IsObjectHandle()) + else if( ctx.type.dataType.IsObjectHandle() ) { // A object accessed through a handle cannot be considered safe, // as it can be cleared at any time @@ -637,8 +637,8 @@ void asCCompiler::CompileMemberInitializationCopy(asCByteCode* bc) } asCExprContext tmp(engine); - asCDataType dt = prop->type; - bool isPodType = (prop->type.GetTypeInfo() && prop->type.GetTypeInfo()->flags & asOBJ_POD); + asCDataType dt = prop->type; + bool isPodType = (prop->type.GetTypeInfo() && prop->type.GetTypeInfo()->flags & asOBJ_POD); CompileInitAsCopy(dt, prop->byteOffset, &tmp, &ctx, declNode, isPodType, asVGM_MEMBER); MergeExprBytecode(&ctx, &tmp); @@ -656,15 +656,15 @@ void asCCompiler::CompileMemberInitialization(asCByteCode *bc, bool onlyDefaults for( asUINT n = 0; n < outFunc->objectType->properties.GetLength(); n++ ) { asCObjectProperty *prop = outFunc->objectType->properties[n]; - + // Don't compile additional member initialization if it has already been explicitly initialized in the body - if (engine->ep.memberInitMode == 1 && m_initializedProperties.IndexOf(prop) >= 0) + if( engine->ep.memberInitMode == 1 && m_initializedProperties.IndexOf(prop) >= 0 ) continue; // Check if the property has an initialization expression - asCParser parser(builder); - asCScriptNode *declNode = 0; - asCScriptNode *initNode = 0; + asCParser parser(builder); + asCScriptNode *declNode = 0; + asCScriptNode *initNode = 0; asCScriptCode *initScript = 0; for( asUINT m = 0; m < m_classDecl->propInits.GetLength(); m++ ) { @@ -686,24 +686,24 @@ void asCCompiler::CompileMemberInitialization(asCByteCode *bc, bool onlyDefaults if( onlyDefaults ) continue; -#ifdef AS_NO_MEMBER_INIT + #ifdef AS_NO_MEMBER_INIT // Give an error as the initialization in the declaration has been disabled asCScriptCode *origScript = script; - script = initScript; + script = initScript; Error("Initialization of members in declaration is not supported", initNode); script = origScript; // Clear the initialization node - initNode = 0; + initNode = 0; initScript = script; -#else + #else // Re-parse the initialization expression as the parser now knows the types, which it didn't earlier int r = parser.ParseVarInit(initScript, initNode); if( r < 0 ) continue; initNode = parser.GetScriptNode(); -#endif + #endif } else { @@ -711,16 +711,16 @@ void asCCompiler::CompileMemberInitialization(asCByteCode *bc, bool onlyDefaults continue; } -#ifdef AS_NO_MEMBER_INIT + #ifdef AS_NO_MEMBER_INIT // The initialization will be done in the asCScriptObject constructor, so // here we should just validate that the member has a default constructor if( prop->type.IsObject() && - !prop->type.IsObjectHandle() && - (((prop->type.GetTypeInfo()->flags & asOBJ_REF) && - prop->type.GetBehaviour()->factory == 0) || - ((prop->type.GetTypeInfo()->flags & asOBJ_VALUE) && - prop->type.GetBehaviour()->construct == 0 && - !(prop->type.GetTypeInfo()->flags & asOBJ_POD))) ) + !prop->type.IsObjectHandle() && + (((prop->type.GetTypeInfo()->flags & asOBJ_REF) && + prop->type.GetBehaviour()->factory == 0) || + ((prop->type.GetTypeInfo()->flags & asOBJ_VALUE) && + prop->type.GetBehaviour()->construct == 0 && + !(prop->type.GetTypeInfo()->flags & asOBJ_POD))) ) { // Class has no default factory/constructor. asCString str; @@ -731,24 +731,24 @@ void asCCompiler::CompileMemberInitialization(asCByteCode *bc, bool onlyDefaults str.Format(TXT_NO_DEFAULT_CONSTRUCTOR_FOR_s, prop->type.GetTypeInfo()->GetName()); Error(str, declNode); } -#else + #else // Temporarily set the script that is being compiled to where the member initialization is declared. // The script can be different when including mixin classes from a different script section asCScriptCode *origScript = script; - script = initScript; + script = initScript; // Add a line instruction with the position of the declaration LineInstr(bc, declNode->tokenPos); // Compile the initialization - asQWORD constantValue; + asQWORD constantValue; asCByteCode bcInit(engine); CompileInitialization(initNode, &bcInit, prop->type, declNode, prop->byteOffset, &constantValue, asVGM_MEMBER); bcInit.OptimizeLocally(tempVariableOffsets); bc->AddCode(&bcInit); script = origScript; -#endif + #endif } } } @@ -764,7 +764,7 @@ int asCCompiler::CompileFunction(asCBuilder *in_builder, asCScriptCode *in_scrip int stackPos = SetupParametersAndReturnVariable(in_parameterNames, in_func); // If there are compile errors, there is no reason to build the final code - if (hasCompileErrors || builder->numErrors != buildErrors) + if( hasCompileErrors || builder->numErrors != buildErrors ) return -1; //-------------------------------------------- @@ -786,14 +786,14 @@ int asCCompiler::CompileFunction(asCBuilder *in_builder, asCScriptCode *in_scrip // TODO: memory: We can parse the statement block one statement at a time, thus save even more memory // TODO: optimize: For large functions, the parsing of the statement block can take a long time. Presumably because a lot of memory needs to be allocated asCParser parser(builder); - int r = parser.ParseStatementBlock(script, blockBegin); + int r = parser.ParseStatementBlock(script, blockBegin); if( r < 0 ) return -1; asCScriptNode *block = parser.GetScriptNode(); // Reserve a label for the cleanup code nextLabel++; - bool hasReturn; + bool hasReturn; asCByteCode bc(engine); LineInstr(&bc, blockBegin->tokenPos); CompileStatementBlock(block, false, &hasReturn, &bc); @@ -813,20 +813,20 @@ int asCCompiler::CompileFunction(asCBuilder *in_builder, asCScriptCode *in_scrip // Insert a JitEntry at the start of the function for JIT compilers byteCode.InstrPTR(asBC_JitEntry, 0); - if(m_isConstructor) + if( m_isConstructor ) { // From 2.38.0 it was implemented the ability to explicitly initialize the members within the body, and with this it // was changed so that any member not explicitly initialized will be automatically initialized in the beginning even if // the base class' constructor is explicitly called in the body. - if (engine->ep.memberInitMode == 1) + if( engine->ep.memberInitMode == 1 ) { // Initialize members without explicit expression first CompileMemberInitialization(&byteCode, true); // Only call the base class' constructor here unless explicitly called in the body - if (!m_isConstructorCalled && outFunc->objectType->derivedFrom) + if( !m_isConstructorCalled && outFunc->objectType->derivedFrom ) { - if (outFunc->objectType->derivedFrom->beh.construct) + if( outFunc->objectType->derivedFrom->beh.construct ) { // Call base class' constructor asCByteCode tmpBC(engine); @@ -843,11 +843,11 @@ int asCCompiler::CompileFunction(asCBuilder *in_builder, asCScriptCode *in_scrip // Add the initialization of the members with explicit expressions CompileMemberInitialization(&byteCode, false); - // If the base class' constructor was explicitly called it must be validated + // If the base class' constructor was explicitly called it must be validated // that the inherited properties weren't accessed before the constructor - if (m_isConstructorCalled) + if( m_isConstructorCalled ) { - asSMapNode* node; + asSMapNode *node; m_inheritedPropertyAccess.MoveFirst(&node); while( node ) { @@ -861,12 +861,12 @@ int asCCompiler::CompileFunction(asCBuilder *in_builder, asCScriptCode *in_scrip else { // Pre 2.38.0, members with init expr in declaration are initialized after super() - if (outFunc->objectType->derivedFrom) + if( outFunc->objectType->derivedFrom ) { // Call the base class' default constructor unless called manually in the code - if (!m_isConstructorCalled) + if( !m_isConstructorCalled ) { - if (outFunc->objectType->derivedFrom->beh.construct) + if( outFunc->objectType->derivedFrom->beh.construct ) { // Initialize members without explicit expression first CompileMemberInitialization(&byteCode, true); @@ -905,7 +905,7 @@ int asCCompiler::CompileFunction(asCBuilder *in_builder, asCScriptCode *in_scrip byteCode.AddCode(&bc); // Count total variable size - int varSize = GetVariableOffset((int)variableAllocations.GetLength()) - 1; + int varSize = GetVariableOffset((int)variableAllocations.GetLength()) - 1; outFunc->scriptData->variableSpace = varSize; // Deallocate all local variables @@ -942,7 +942,7 @@ int asCCompiler::CompileFunction(asCBuilder *in_builder, asCScriptCode *in_scrip } // Check if the number of labels in the functions isn't too many to be handled - if( nextLabel >= (1<<15) ) + if( nextLabel >= (1 << 15) ) Error(TXT_TOO_MANY_JUMP_LABELS, in_func); // If there are compile errors, there is no reason to build the final code @@ -959,13 +959,13 @@ int asCCompiler::CompileFunction(asCBuilder *in_builder, asCScriptCode *in_scrip FinalizeFunction(); -#ifdef AS_DEBUG + #ifdef AS_DEBUG // DEBUG: output byte code if( outFunc->objectType ) byteCode.DebugOutput(("__" + outFunc->objectType->name + "_" + outFunc->name + ".txt").AddressOf(), in_outFunc); else byteCode.DebugOutput(("__" + outFunc->name + ".txt").AddressOf(), in_outFunc); -#endif + #endif return 0; } @@ -978,7 +978,7 @@ int asCCompiler::CallCopyConstructor(asCDataType &type, int offset, bool isObjec // CallCopyConstructor should not be called for object handles. asASSERT( !type.IsObjectHandle() ); - asCArray args; + asCArray args; args.PushLast(arg); // The reference parameter must be pushed on the stack @@ -991,8 +991,8 @@ int asCCompiler::CallCopyConstructor(asCDataType &type, int offset, bool isObjec if( type.GetTypeInfo()->flags & asOBJ_REF ) { - int func = 0; - asSTypeBehaviour *beh = type.GetBehaviour(); + int func = 0; + asSTypeBehaviour *beh = type.GetBehaviour(); if( beh ) func = beh->copyfactory; if( func > 0 ) @@ -1011,7 +1011,7 @@ int asCCompiler::CallCopyConstructor(asCDataType &type, int offset, bool isObjec PerformFunctionCall(func, ctx, false, &args, CastToObjectType(type.GetTypeInfo())); ctx->bc.Instr(asBC_RDSPtr); - if (isVarGlobOrMem == asVGM_GLOBAL) + if( isVarGlobOrMem == asVGM_GLOBAL ) { // Store the returned handle in the global variable ctx->bc.InstrPTR(asBC_PGA, engine->globalProperties[offset]->GetAddressOfValue()); @@ -1034,8 +1034,8 @@ int asCCompiler::CallCopyConstructor(asCDataType &type, int offset, bool isObjec } else { - asSTypeBehaviour *beh = type.GetBehaviour(); - int func = beh ? beh->copyconstruct : 0; + asSTypeBehaviour *beh = type.GetBehaviour(); + int func = beh ? beh->copyconstruct : 0; if( func > 0 ) { // Push the address where the object will be stored on the stack, before the argument @@ -1065,7 +1065,7 @@ int asCCompiler::CallCopyConstructor(asCDataType &type, int offset, bool isObjec ctx->bc.Instr(asBC_RDSPtr); } } - else if (!isObjectOnHeap && isVarGlobOrMem == asVGM_MEMBER) + else if( !isObjectOnHeap && isVarGlobOrMem == asVGM_MEMBER ) { ctx->bc.InstrSHORT(asBC_PSF, 0); ctx->bc.Instr(asBC_RDSPtr); @@ -1101,8 +1101,8 @@ int asCCompiler::CallDefaultConstructor(const asCDataType &type, int offset, boo asCExprContext ctx(engine); ctx.exprNode = node; - int func = 0; - asSTypeBehaviour *beh = type.GetBehaviour(); + int func = 0; + asSTypeBehaviour *beh = type.GetBehaviour(); if( beh ) { func = beh->factory; @@ -1114,7 +1114,7 @@ int asCCompiler::CallDefaultConstructor(const asCDataType &type, int offset, boo { asCScriptFunction *f = engine->scriptFunctions[beh->factories[n]]; if( f->defaultArgs.GetLength() == f->parameterTypes.GetLength() && - f->defaultArgs[0] != 0 ) + f->defaultArgs[0] != 0 ) { func = beh->factories[n]; break; @@ -1126,7 +1126,7 @@ int asCCompiler::CallDefaultConstructor(const asCDataType &type, int offset, boo if( func > 0 ) { asCArray args; - asCScriptFunction *f = engine->scriptFunctions[func]; + asCScriptFunction *f = engine->scriptFunctions[func]; if( f->parameterTypes.GetLength() ) { // Add the default values for arguments not explicitly supplied @@ -1226,7 +1226,7 @@ int asCCompiler::CallDefaultConstructor(const asCDataType &type, int offset, boo { asCScriptFunction *f = engine->scriptFunctions[beh->constructors[n]]; if( f->defaultArgs.GetLength() == f->parameterTypes.GetLength() && - f->defaultArgs[0] != 0 ) + f->defaultArgs[0] != 0 ) { func = beh->constructors[n]; break; @@ -1239,7 +1239,7 @@ int asCCompiler::CallDefaultConstructor(const asCDataType &type, int offset, boo if( func != 0 || (type.GetTypeInfo()->flags & asOBJ_POD) ) { asCArray args; - asCScriptFunction *f = engine->scriptFunctions[func]; + asCScriptFunction *f = engine->scriptFunctions[func]; if( f && f->parameterTypes.GetLength() ) { // Add the default values for arguments not explicitly supplied @@ -1347,7 +1347,7 @@ void asCCompiler::CallDestructor(asCDataType &type, int offset, bool isObjectOnH if( isObjectOnHeap || type.IsObjectHandle() ) { // Free the memory - if (type.IsFuncdef()) + if( type.IsFuncdef() ) bc->InstrW_PTR(asBC_FREE, (short)offset, &engine->functionBehaviours); else bc->InstrW_PTR(asBC_FREE, (short)offset, type.GetTypeInfo()); @@ -1383,10 +1383,10 @@ void asCCompiler::LineInstr(asCByteCode *bc, size_t pos) void asCCompiler::CompileStatementBlock(asCScriptNode *block, bool ownVariableScope, bool *hasReturn, asCByteCode *bc) { - *hasReturn = false; - bool isFinished = false; - bool hasUnreachableCode = false; - bool hasReturnBefore = false; + *hasReturn = false; + bool isFinished = false; + bool hasUnreachableCode = false; + bool hasReturnBefore = false; asUINT visibleNamespaceCount = 0; if( ownVariableScope ) @@ -1398,12 +1398,12 @@ void asCCompiler::CompileStatementBlock(asCScriptNode *block, bool ownVariableSc asCScriptNode *node = block->firstChild; while( node ) { -#ifdef AS_DEBUG + #ifdef AS_DEBUG // Keep the current line in a variable so it will be easier // to determine where in a script an assert is occurring. int currentLine = 0; script->ConvertPosToRowCol(node->tokenPos, ¤tLine, 0); -#endif + #endif if( !hasUnreachableCode && (*hasReturn || isFinished) ) { @@ -1424,27 +1424,27 @@ void asCCompiler::CompileStatementBlock(asCScriptNode *block, bool ownVariableSc asCByteCode statement(engine); if( node->nodeType == snDeclaration ) CompileDeclaration(node, &statement); - else if (node->nodeType == snUsing) + else if( node->nodeType == snUsing ) { - asCScriptNode* n = node->firstChild; - asCString name(&script->code[n->tokenPos], n->tokenLength); + asCScriptNode *n = node->firstChild; + asCString name(&script->code[n->tokenPos], n->tokenLength); while( n->next && n->next->nodeType == snIdentifier ) { - n = n->next; + n = n->next; name += "::"; name += asCString(&script->code[n->tokenPos], n->tokenLength); } - asSNameSpace* visibleNamespace = engine->FindNameSpace(name.AddressOf()); + asSNameSpace *visibleNamespace = engine->FindNameSpace(name.AddressOf()); - if (visibleNamespace == 0) + if( visibleNamespace == 0 ) { asCString msg; msg.Format(TXT_NAMESPACE_s_DOESNT_EXIST, name.AddressOf()); Error(msg, node); } - else if (!m_namespaceVisibility.Exists(visibleNamespace)) + else if( !m_namespaceVisibility.Exists(visibleNamespace) ) { m_namespaceVisibility.PushLast(visibleNamespace); ++visibleNamespaceCount; @@ -1490,7 +1490,7 @@ void asCCompiler::CompileStatementBlock(asCScriptNode *block, bool ownVariableSc RemoveVariableScope(); bc->Block(false); } - + if( visibleNamespaceCount > 0 ) { m_namespaceVisibility.SetLengthNoAllocate(m_namespaceVisibility.GetLength() - visibleNamespaceCount); @@ -1510,21 +1510,21 @@ int asCCompiler::CompileGlobalVariable(asCBuilder *in_builder, asCScriptCode *in // Parse the initialization nodes asCParser parser(builder); - if (in_node) + if( in_node ) { int r = parser.ParseVarInit(in_script, in_node); - if (r < 0) + if( r < 0 ) return r; in_node = parser.GetScriptNode(); } asCExprContext compiledCtx(engine); - bool preCompiled = false; - if (in_gvar->datatype.IsAuto()) + bool preCompiled = false; + if( in_gvar->datatype.IsAuto() ) { preCompiled = CompileAutoType(in_gvar->datatype, compiledCtx, in_node, in_gvar->declaredAtNode); - if (!preCompiled) + if( !preCompiled ) { // If it wasn't possible to determine the type from the expression then there // is no need to continue with the initialization. The error was already reported @@ -1535,19 +1535,19 @@ int asCCompiler::CompileGlobalVariable(asCBuilder *in_builder, asCScriptCode *in if( in_gvar->property == 0 ) { in_gvar->property = builder->module->AllocateGlobalProperty(in_gvar->name.AddressOf(), in_gvar->datatype, in_gvar->ns); - in_gvar->index = in_gvar->property->id; + in_gvar->index = in_gvar->property->id; } // Compile the expression asCExprContext ctx(engine); - asQWORD constantValue = 0; + asQWORD constantValue = 0; if( CompileInitialization(in_node, &ctx.bc, in_gvar->datatype, in_gvar->declaredAtNode, in_gvar->index, &constantValue, asVGM_GLOBAL, preCompiled ? &compiledCtx : 0) ) { // Should the variable be marked as pure constant? if( in_gvar->datatype.IsPrimitive() && in_gvar->datatype.IsReadOnly() ) { in_gvar->isPureConstant = true; - in_gvar->constantValue = constantValue; + in_gvar->constantValue = constantValue; } } @@ -1592,10 +1592,10 @@ int asCCompiler::CompileGlobalVariable(asCBuilder *in_builder, asCScriptCode *in FinalizeFunction(); -#ifdef AS_DEBUG + #ifdef AS_DEBUG // DEBUG: output byte code byteCode.DebugOutput(("___init_" + in_gvar->name + ".txt").AddressOf(), outFunc); -#endif + #endif return 0; } @@ -1607,19 +1607,19 @@ void asCCompiler::DetermineSingleFunc(asCExprContext *ctx, asCScriptNode *node) return; // Determine the namespace - asSNameSpace *ns = 0; - asCString name = ""; - int pos = ctx->methodName.FindLast("::"); + asSNameSpace *ns = 0; + asCString name = ""; + int pos = ctx->methodName.FindLast("::"); if( pos >= 0 ) { - asCString nsName = ctx->methodName.SubString(0, pos+2); + asCString nsName = ctx->methodName.SubString(0, pos + 2); // Cut off the :: if( nsName.GetLength() > 2 ) - nsName.SetLength(nsName.GetLength()-2); + nsName.SetLength(nsName.GetLength() - 2); - ns = DetermineNameSpace(nsName); - name = ctx->methodName.SubString(pos+2); + ns = DetermineNameSpace(nsName); + name = ctx->methodName.SubString(pos + 2); } else { @@ -1645,7 +1645,7 @@ void asCCompiler::DetermineSingleFunc(asCExprContext *ctx, asCScriptNode *node) // A shared object may not access global functions unless they too are shared (e.g. registered functions) if( !builder->GetFunctionDescription(funcs[0])->IsShared() && - outFunc->IsShared() ) + outFunc->IsShared() ) { asCString msg; msg.Format(TXT_SHARED_CANNOT_CALL_NON_SHARED_FUNC_s, builder->GetFunctionDescription(funcs[0])->GetDeclaration()); @@ -1659,7 +1659,7 @@ void asCCompiler::DetermineSingleFunc(asCExprContext *ctx, asCScriptNode *node) ctx->type.Set(asCDataType::CreateType(engine->FindMatchingFuncdef(builder->GetFunctionDescription(funcs[0]), builder->module), false)); ctx->type.dataType.MakeHandle(true); ctx->type.isExplicitHandle = true; - ctx->methodName = ""; + ctx->methodName = ""; } void asCCompiler::CompileInitAsCopy(asCDataType &dt, int offset, asCExprContext *ctx, asCExprContext *arg, asCScriptNode *node, bool derefDestination, EVarGlobOrMem isVarGlobOrMem) @@ -1670,17 +1670,17 @@ void asCCompiler::CompileInitAsCopy(asCDataType &dt, int offset, asCExprContext // Use copy constructor if available. asCObjectType *ot = CastToObjectType(dt.GetTypeInfo()); - if(!dt.IsObjectHandle() && ot && (ot->beh.copyconstruct || ot->beh.copyfactory)) + if( !dt.IsObjectHandle() && ot && (ot->beh.copyconstruct || ot->beh.copyfactory) ) { // Make sure the copy constructor is not flagged as explicit - asCScriptFunction* func = ot->beh.copyconstruct ? engine->scriptFunctions[ot->beh.copyconstruct] : engine->scriptFunctions[ot->beh.copyfactory]; - if (func->traits.GetTrait(asTRAIT_EXPLICIT)) + asCScriptFunction *func = ot->beh.copyconstruct ? engine->scriptFunctions[ot->beh.copyconstruct] : engine->scriptFunctions[ot->beh.copyfactory]; + if( func->traits.GetTrait(asTRAIT_EXPLICIT) ) Error(TXT_CANNOT_IMPLICITLY_CALL_EXPLICIT_COPY_CONSTR, node); - // Consider the argument as non-const already to avoid PrepareForAssignment + // Consider the argument as non-const already to avoid PrepareForAssignment // trying to make another copy, leading to infinite recursive loop arg->type.dataType.MakeReadOnly(false); - + PrepareForAssignment(&dt, arg, node, true); int r = CallCopyConstructor(dt, offset, isObjectOnHeap, ctx, arg, node, isVarGlobOrMem, derefDestination); if( r < 0 && tempVariables.Exists(offset) ) @@ -1693,7 +1693,7 @@ void asCCompiler::CompileInitAsCopy(asCDataType &dt, int offset, asCExprContext // Allocate and construct the temporary object before whatever is already in the bytecode asCByteCode tmpBC(engine); - int r = CallDefaultConstructor(dt, offset, isObjectOnHeap, &tmpBC, node, isVarGlobOrMem, derefDestination); + int r = CallDefaultConstructor(dt, offset, isObjectOnHeap, &tmpBC, node, isVarGlobOrMem, derefDestination); if( r < 0 ) { if( tempVariables.Exists(offset) ) @@ -1704,7 +1704,7 @@ void asCCompiler::CompileInitAsCopy(asCDataType &dt, int offset, asCExprContext tmpBC.AddCode(&ctx->bc); ctx->bc.AddCode(&tmpBC); - // Consider the argument as non-const already to avoid PrepareForAssignment + // Consider the argument as non-const already to avoid PrepareForAssignment // trying to make another copy, leading to infinite recursive loop arg->type.dataType.MakeReadOnly(false); @@ -1722,13 +1722,13 @@ void asCCompiler::CompileInitAsCopy(asCDataType &dt, int offset, asCExprContext if( dt.IsObjectHandle() ) type.isExplicitHandle = true; - if (isVarGlobOrMem == asVGM_VARIABLE) + if( isVarGlobOrMem == asVGM_VARIABLE ) { ctx->bc.InstrSHORT(asBC_PSF, (short)offset); - if (derefDestination) + if( derefDestination ) ctx->bc.Instr(asBC_RDSPtr); } - else if (isVarGlobOrMem == asVGM_MEMBER) + else if( isVarGlobOrMem == asVGM_MEMBER ) { ctx->bc.InstrSHORT(asBC_PSF, 0); ctx->bc.Instr(asBC_RDSPtr); @@ -1780,11 +1780,11 @@ int asCCompiler::PrepareArgument(asCDataType *paramType, asCExprContext *ctx, as // If value assign is disabled for reference types, then make // sure to always pass the handle to ? parameters if( builder->engine->ep.disallowValueAssignForRefType && - ctx->type.dataType.GetTypeInfo() && (ctx->type.dataType.GetTypeInfo()->flags & asOBJ_REF) && !(ctx->type.dataType.GetTypeInfo()->flags & asOBJ_SCOPED) ) + ctx->type.dataType.GetTypeInfo() && (ctx->type.dataType.GetTypeInfo()->flags & asOBJ_REF) && !(ctx->type.dataType.GetTypeInfo()->flags & asOBJ_SCOPED) ) { param.MakeHandle(true); } - + // Ensure the expression is treated as an explicit handle ctx->type.isExplicitHandle = param.IsObjectHandle(); @@ -1814,7 +1814,7 @@ int asCCompiler::PrepareArgument(asCDataType *paramType, asCExprContext *ctx, as asCByteCode tmpBC(engine); // Make sure the type is deterministic - if (param.GetTypeInfo() == &engine->functionBehaviours) + if( param.GetTypeInfo() == &engine->functionBehaviours ) { Error(TXT_INVALID_EXPRESSION_LAMBDA, node); return -1; @@ -1881,7 +1881,7 @@ int asCCompiler::PrepareArgument(asCDataType *paramType, asCExprContext *ctx, as // For parameters expecting a reference to a handle we need to make sure the argument // is really a handle, and not just a reference to the object. Do this check before the // implicit conversion so it can be treated correctly. - if (dt.IsObjectHandle() && !ctx->type.dataType.IsObjectHandle() && !ctx->IsAnonymousInitList() && ctx->type.dataType.SupportHandles()) + if( dt.IsObjectHandle() && !ctx->type.dataType.IsObjectHandle() && !ctx->IsAnonymousInitList() && ctx->type.dataType.SupportHandles() ) { // Make a refCopy into a local handle variable // Allocate a handle variable @@ -1892,7 +1892,7 @@ int asCCompiler::PrepareArgument(asCDataType *paramType, asCExprContext *ctx, as // Copy the handle Dereference(ctx, true); ctx->bc.InstrWORD(asBC_PSF, (asWORD)offset); - if (ctx->type.dataType.IsFuncdef()) + if( ctx->type.dataType.IsFuncdef() ) ctx->bc.InstrPTR(asBC_REFCPY, &engine->functionBehaviours); else ctx->bc.InstrPTR(asBC_REFCPY, ctx->type.dataType.GetTypeInfo()); @@ -1948,7 +1948,7 @@ int asCCompiler::PrepareArgument(asCDataType *paramType, asCExprContext *ctx, as // Copy the handle Dereference(ctx, true); ctx->bc.InstrWORD(asBC_PSF, (asWORD)offset); - if (ctx->type.dataType.IsFuncdef()) + if( ctx->type.dataType.IsFuncdef() ) ctx->bc.InstrPTR(asBC_REFCPY, &engine->functionBehaviours); else ctx->bc.InstrPTR(asBC_REFCPY, ctx->type.dataType.GetTypeInfo()); @@ -1995,10 +1995,10 @@ int asCCompiler::PrepareArgument(asCDataType *paramType, asCExprContext *ctx, as // When calling a function expecting a var arg with a parameter received as reference to handle // then it is necessary to copy the handle to a local variable, otherwise MoveArgsToStack will // not be able to do the correct double dereference to put the reference to the object on the stack. - if (paramType->GetTokenType() == ttQuestion && !param.IsObjectHandle() && ctx->type.isVariable) + if( paramType->GetTokenType() == ttQuestion && !param.IsObjectHandle() && ctx->type.isVariable ) { sVariable *var = variables->GetVariableByOffset(ctx->type.stackOffset); - if (var && var->type.IsReference() && var->type.IsObjectHandle()) + if( var && var->type.IsReference() && var->type.IsObjectHandle() ) { // Copy the handle to local variable @@ -2010,7 +2010,7 @@ int asCCompiler::PrepareArgument(asCDataType *paramType, asCExprContext *ctx, as // Copy the handle Dereference(ctx, true); ctx->bc.InstrWORD(asBC_PSF, (asWORD)offset); - if (ctx->type.dataType.IsFuncdef()) + if( ctx->type.dataType.IsFuncdef() ) ctx->bc.InstrPTR(asBC_REFCPY, &engine->functionBehaviours); else ctx->bc.InstrPTR(asBC_REFCPY, ctx->type.dataType.GetTypeInfo()); @@ -2028,8 +2028,8 @@ int asCCompiler::PrepareArgument(asCDataType *paramType, asCExprContext *ctx, as { // We must guarantee that the address to the value is on the stack if( (ctx->type.dataType.IsObject() || ctx->type.dataType.IsFuncdef()) && - !ctx->type.dataType.IsObjectHandle() && - ctx->type.dataType.IsReference() ) + !ctx->type.dataType.IsObjectHandle() && + ctx->type.dataType.IsReference() ) Dereference(ctx, true); } } @@ -2061,7 +2061,7 @@ int asCCompiler::PrepareArgument(asCDataType *paramType, asCExprContext *ctx, as { // Null handles and void expressions must be marked as explicit // handles for correct treatement in MoveArgsToStack - if (dt.IsNullHandle()) + if( dt.IsNullHandle() ) ctx->type.isExplicitHandle = true; // Make sure the variable is not used in the expression @@ -2090,7 +2090,7 @@ int asCCompiler::PrepareArgument(asCDataType *paramType, asCExprContext *ctx, as type.stackOffset = (short)offset; type.isExplicitHandle = ctx->type.isExplicitHandle; - ctx->type = type; + ctx->type = type; ctx->bc.InstrSHORT(asBC_PSF, (short)offset); if( (dt.IsObject() || dt.IsFuncdef()) && !dt.IsObjectHandle() ) @@ -2122,13 +2122,13 @@ int asCCompiler::PrepareArgument(asCDataType *paramType, asCExprContext *ctx, as // Literal constants cannot be passed to inout ref arguments if( (!ctx->type.isVariable && ctx->type.isConstant) ) { - // Unless the reference is const and it is a string and the string + // Unless the reference is const and it is a string and the string // type support handles or unsafe references are turned on - if (param.IsReadOnly() && (ctx->type.dataType.SupportHandles() || engine->ep.allowUnsafeReferences) ) + if( param.IsReadOnly() && (ctx->type.dataType.SupportHandles() || engine->ep.allowUnsafeReferences) ) { // Since the parameter is a const & make a copy. // This is not necessary for strings, since the literal string const is already a reference - if (ctx->type.dataType.IsPrimitive()) + if( ctx->type.dataType.IsPrimitive() ) { ConvertToTempVariable(ctx); ctx->type.dataType.MakeReadOnly(true); @@ -2144,7 +2144,7 @@ int asCCompiler::PrepareArgument(asCDataType *paramType, asCExprContext *ctx, as // Allow anonymous init lists to be converted to the arg type if( ctx->IsAnonymousInitList() ) ImplicitConversion(ctx, dt, node, asIC_IMPLICIT_CONV, true, true); - + if( (ctx->type.dataType.IsObject() || ctx->type.dataType.IsFuncdef()) && ctx->type.dataType.GetTypeInfo() != dt.GetTypeInfo() ) ImplicitConversion(ctx, dt, node, asIC_IMPLICIT_CONV, true, false); @@ -2153,13 +2153,13 @@ int asCCompiler::PrepareArgument(asCDataType *paramType, asCExprContext *ctx, as // already safe, so there is no need to add an extra // references if( !engine->ep.allowUnsafeReferences && - !ctx->type.isVariable && - (ctx->type.dataType.IsObject() || ctx->type.dataType.IsFuncdef()) && - !ctx->type.dataType.IsObjectHandle() && - ((ctx->type.dataType.GetBehaviour()->addref && - ctx->type.dataType.GetBehaviour()->release) || - (ctx->type.dataType.GetTypeInfo()->flags & asOBJ_NOCOUNT) || - ctx->type.dataType.IsFuncdef()) ) + !ctx->type.isVariable && + (ctx->type.dataType.IsObject() || ctx->type.dataType.IsFuncdef()) && + !ctx->type.dataType.IsObjectHandle() && + ((ctx->type.dataType.GetBehaviour()->addref && + ctx->type.dataType.GetBehaviour()->release) || + (ctx->type.dataType.GetTypeInfo()->flags & asOBJ_NOCOUNT) || + ctx->type.dataType.IsFuncdef()) ) { // Store a handle to the object as local variable asCExprContext tmp(engine); @@ -2239,7 +2239,7 @@ int asCCompiler::PrepareArgument(asCDataType *paramType, asCExprContext *ctx, as if( !ctx->type.dataType.IsEqualExceptRef(dt) ) { asCString str; - if (ctx->IsLambda()) + if( ctx->IsLambda() ) str.Format(TXT_CANT_IMPLICITLY_CONVERT_s_TO_s, BuildLambdaSignature(ctx->exprNode).AddressOf(), dt.Format(outFunc->nameSpace).AddressOf()); else str.Format(TXT_CANT_IMPLICITLY_CONVERT_s_TO_s, ctx->type.dataType.Format(outFunc->nameSpace).AddressOf(), dt.Format(outFunc->nameSpace).AddressOf()); @@ -2265,12 +2265,12 @@ int asCCompiler::PrepareArgument(asCDataType *paramType, asCExprContext *ctx, as // TODO: value on stack: How can we avoid this unnecessary allocation? // Don't make temporary copies of handles if it is going to be used - // for handle assignment anyway, i.e. REFCPY, except if the variable is for a @& + // for handle assignment anyway, i.e. REFCPY, except if the variable is for a @& // parameter in which case the GETOBJREF won't be able to dereference the object handle // TODO: optimize: This would be more efficient if it avoided the use of VAR/GETOBJREF all together - sVariable* var = ctx->type.isVariable ? variables->GetVariableByOffset(ctx->type.stackOffset) : 0; - if( !(!isFunction && isMakingCopy && ctx->type.dataType.IsObjectHandle() && ctx->type.isVariable) || - (var && var->type.IsReference() && var->type.IsObjectHandle()) ) + sVariable *var = ctx->type.isVariable ? variables->GetVariableByOffset(ctx->type.stackOffset) : 0; + if( !(!isFunction && isMakingCopy && ctx->type.dataType.IsObjectHandle() && ctx->type.isVariable) || + (var && var->type.IsReference() && var->type.IsObjectHandle()) ) PrepareTemporaryVariable(node, ctx, true, true); } } @@ -2309,14 +2309,14 @@ int asCCompiler::PrepareFunctionCall(int funcId, asCByteCode *bc, asCArrayparameterTypes.GetLength() == 1 && args.GetLength() == 1 && - descr->parameterTypes[0].IsEqualExceptRefAndConst(args[0]->type.dataType) && - (((descr->name == "opAssign" || descr->name == "$beh0") && descr->objectType && descr->objectType == args[0]->type.dataType.GetTypeInfo()) || - (descr->objectType == 0 && args[0]->type.dataType.GetTypeInfo() && descr->name == args[0]->type.dataType.GetTypeInfo()->name)) ) + descr->parameterTypes[0].IsEqualExceptRefAndConst(args[0]->type.dataType) && + (((descr->name == "opAssign" || descr->name == "$beh0") && descr->objectType && descr->objectType == args[0]->type.dataType.GetTypeInfo()) || + (descr->objectType == 0 && args[0]->type.dataType.GetTypeInfo() && descr->name == args[0]->type.dataType.GetTypeInfo()->name)) ) makingCopy = true; // Add code for arguments asCExprContext e(engine); - for( int n = (int)args.GetLength()-1; n >= 0; n-- ) + for( int n = (int)args.GetLength() - 1; n >= 0; n-- ) { // Make sure PrepareArgument doesn't use any variable that is already // being used by the argument or any of the following argument expressions @@ -2325,16 +2325,16 @@ int asCCompiler::PrepareFunctionCall(int funcId, asCByteCode *bc, asCArraybc.GetVarsUsed(reservedVariables); asUINT realParamIdx = n; - if (descr->IsVariadic()) + if( descr->IsVariadic() ) { - if (n >= (int)descr->parameterTypes.GetLength() - 1) + if( n >= (int)descr->parameterTypes.GetLength() - 1 ) realParamIdx = descr->parameterTypes.GetLength() - 1; } int r = PrepareArgument2(&e, args[n], &descr->parameterTypes[realParamIdx], true, descr->inOutFlags[realParamIdx], makingCopy); reservedVariables.SetLength(l); - if (r < 0) + if( r < 0 ) return r; } @@ -2355,37 +2355,37 @@ void asCCompiler::MoveArgsToStack(int funcId, asCByteCode *bc, asCArrayDoesReturnOnStack() ) offset += AS_PTR_SIZE; - if (descr->IsVariadic()) + if( descr->IsVariadic() ) offset += 1; -#ifdef AS_DEBUG + #ifdef AS_DEBUG // If the function being called is the opAssign or copy constructor for the same type // as the argument, then we should avoid making temporary copy of the argument bool makingCopy = false; if( descr->parameterTypes.GetLength() == 1 && args.GetLength() == 1 && - descr->parameterTypes[0].IsEqualExceptRefAndConst(args[0]->type.dataType) && - (((descr->name == "opAssign" || descr->name == "$beh0") && descr->objectType && descr->objectType == args[0]->type.dataType.GetTypeInfo()) || - (descr->objectType == 0 && args[0]->type.dataType.GetTypeInfo() && descr->name == args[0]->type.dataType.GetTypeInfo()->name)) ) + descr->parameterTypes[0].IsEqualExceptRefAndConst(args[0]->type.dataType) && + (((descr->name == "opAssign" || descr->name == "$beh0") && descr->objectType && descr->objectType == args[0]->type.dataType.GetTypeInfo()) || + (descr->objectType == 0 && args[0]->type.dataType.GetTypeInfo() && descr->name == args[0]->type.dataType.GetTypeInfo()->name)) ) makingCopy = true; -#endif + #endif // Move the objects that are sent by value to the stack just before the call for( asUINT n = 0; n < args.GetLength(); n++ ) { asUINT realParamIdx = n; - if (descr->IsVariadic() && n >= descr->parameterTypes.GetLength() - 1) + if( descr->IsVariadic() && n >= descr->parameterTypes.GetLength() - 1 ) realParamIdx = descr->parameterTypes.GetLength() - 1; - + if( descr->parameterTypes[realParamIdx].IsReference() ) { if( (descr->parameterTypes[realParamIdx].IsObject() || descr->parameterTypes[realParamIdx].IsFuncdef()) && !descr->parameterTypes[realParamIdx].IsObjectHandle() ) { if( descr->inOutFlags[realParamIdx] != asTM_INOUTREF && !args[n]->type.isRefSafe ) { -#ifdef AS_DEBUG + #ifdef AS_DEBUG // This assert is inside AS_DEBUG because of the variable makingCopy which is only defined in debug mode asASSERT( args[n]->type.isVariable || args[n]->type.isTemporary || makingCopy ); -#endif + #endif if( (args[n]->type.isVariable || args[n]->type.isTemporary) ) { @@ -2405,27 +2405,27 @@ void asCCompiler::MoveArgsToStack(int funcId, asCByteCode *bc, asCArraytype.isRefSafe) + if( !args[n]->type.isRefSafe ) { - if (descr->parameterTypes[realParamIdx].GetTokenType() == ttQuestion && - (args[n]->type.dataType.IsObject() || args[n]->type.dataType.IsFuncdef()) && - !args[n]->type.dataType.IsObjectHandle()) + if( descr->parameterTypes[realParamIdx].GetTokenType() == ttQuestion && + (args[n]->type.dataType.IsObject() || args[n]->type.dataType.IsFuncdef()) && + !args[n]->type.dataType.IsObjectHandle() ) { // Send the object as a reference to the object, // and not to the variable holding the object - if (!IsVariableOnHeap(args[n]->type.stackOffset)) + if( !IsVariableOnHeap(args[n]->type.stackOffset) ) // TODO: runtime optimize: Actually the reference can be pushed on the stack directly // as the value allocated on the stack is guaranteed to be safe bc->InstrWORD(asBC_GETREF, (asWORD)offset); else bc->InstrWORD(asBC_GETOBJREF, (asWORD)offset); } - else if (descr->parameterTypes[realParamIdx].GetTokenType() == ttQuestion && - args[n]->type.dataType.IsObjectHandle() && !args[n]->type.isExplicitHandle) + else if( descr->parameterTypes[realParamIdx].GetTokenType() == ttQuestion && + args[n]->type.dataType.IsObjectHandle() && !args[n]->type.isExplicitHandle ) { // The object handle is being passed as an object, so dereference it before // the call so the reference will be to the object rather than to the handle - if (engine->ep.disallowValueAssignForRefType) + if( engine->ep.disallowValueAssignForRefType ) { // With disallow value assign all ref type objects are always passed by handle bc->InstrWORD(asBC_GETREF, (asWORD)offset); @@ -2438,7 +2438,7 @@ void asCCompiler::MoveArgsToStack(int funcId, asCByteCode *bc, asCArrayGetVariableByOffset(args[n]->type.stackOffset); - if (var == 0 || !var->type.IsReference() || !var->type.IsObjectHandle()) + if( var == 0 || !var->type.IsReference() || !var->type.IsObjectHandle() ) bc->InstrWORD(asBC_GETREF, (asWORD)offset); else bc->InstrWORD(asBC_GETOBJREF, (asWORD)offset); @@ -2467,13 +2467,13 @@ void asCCompiler::MoveArgsToStack(int funcId, asCByteCode *bc, asCArray &args, asCArray &namedArgs) +int asCCompiler::CompileArgumentList(asCScriptNode *node, asCArray &args, asCArray &namedArgs) { asASSERT(node->nodeType == snArgList); // Count arguments - asCScriptNode *arg = node->firstChild; - int argCount = 0; + asCScriptNode *arg = node->firstChild; + int argCount = 0; while( arg ) { if( arg->nodeType != snNamedArgument ) @@ -2487,7 +2487,7 @@ int asCCompiler::CompileArgumentList(asCScriptNode *node, asCArrayfirstChild->next; + asgNode = arg->firstChild->next; namedNode = arg->firstChild; asASSERT( namedNode->nodeType == snIdentifier ); @@ -2513,7 +2513,7 @@ int asCCompiler::CompileArgumentList(asCScriptNode *node, asCArraycode[namedNode->tokenPos], namedNode->tokenLength); - namedArg.ctx = ctx; + namedArg.ctx = ctx; // Error out when multiple arguments with the same name are passed for( asUINT a = 0; a < namedArgs.GetLength(); ++a ) @@ -2557,7 +2557,7 @@ int asCCompiler::CompileArgumentList(asCScriptNode *node, asCArray &args, int funcId, asCObjectType *objectType, asCArray *namedArgs) +int asCCompiler::CompileDefaultAndNamedArgs(asCScriptNode *node, asCArray &args, int funcId, asCObjectType *objectType, asCArray *namedArgs) { asCScriptFunction *func = builder->GetFunctionDescription(funcId); if( func == 0 || args.GetLength() >= (func->IsVariadic() ? (asUINT)func->GetParamCount() - 1 : (asUINT)func->GetParamCount()) ) @@ -2571,8 +2571,8 @@ int asCCompiler::CompileDefaultAndNamedArgs(asCScriptNode *node, asCArrayparameterTypes.GetLength() - 1; n >= explicitArgs; n-- ) { if( args[n] != 0 ) continue; - if (n >= (int)func->defaultArgs.GetLength()) { asASSERT(func->IsVariadic()); continue; } - if( func->defaultArgs[n] == 0 ) { anyErrors = true; continue; } + if( n >= (int)func->defaultArgs.GetLength() ) + { + asASSERT(func->IsVariadic()); + continue; + } + if( func->defaultArgs[n] == 0 ) + { + anyErrors = true; + continue; + } // Parse the default arg string - asCParser parser(builder); + asCParser parser(builder); asCScriptCode *code = builder->FindOrAddCode("default arg", func->defaultArgs[n]->AddressOf(), func->defaultArgs[n]->GetLength()); - int r = parser.ParseExpression(code); + int r = parser.ParseExpression(code); if( r < 0 ) { asCString msg; @@ -2636,7 +2644,7 @@ int asCCompiler::CompileDefaultAndNamedArgs(asCScriptNode *node, asCArraynameSpace; - outFunc->nameSpace = func->nameSpace; + outFunc->nameSpace = func->nameSpace; asCExprContext expr(engine); r = CompileExpression(arg, &expr); @@ -2695,7 +2703,7 @@ int asCCompiler::CompileDefaultAndNamedArgs(asCScriptNode *node, asCArrayexprNode) + if( args[n]->exprNode ) { // Disconnect the node from the parser, and tell the compiler to free it when complete args[n]->exprNode->DisconnectParent(); @@ -2707,11 +2715,11 @@ int asCCompiler::CompileDefaultAndNamedArgs(asCScriptNode *node, asCArray &funcs, asCArray &args, asCScriptNode *node, const char *name, asCArray *namedArgs, asCObjectType *objectType, bool isConstMethod, bool silent, bool allowObjectConstruct, const asCString &scope) +asUINT asCCompiler::MatchFunctions(asCArray &funcs, asCArray &args, asCScriptNode *node, const char *name, asCArray *namedArgs, asCObjectType *objectType, bool isConstMethod, bool silent, bool allowObjectConstruct, const asCString &scope) { - asCArray origFuncs = funcs; // Keep the original list for error message - asUINT cost = 0; - asUINT n; + asCArray origFuncs = funcs; // Keep the original list for error message + asUINT cost = 0; + asUINT n; asCArray failedMatches; if( funcs.GetLength() > 0 ) @@ -2723,16 +2731,16 @@ asUINT asCCompiler::MatchFunctions(asCArray &funcs, asCArrayGetFunctionDescription(funcs[n]); - if (desc->IsVariadic()) + bool noMatch = false; + asCScriptFunction *desc = builder->GetFunctionDescription(funcs[n]); + if( desc->IsVariadic() ) { asASSERT(desc->parameterTypes.GetLength() >= 1); asUINT argsWithoutLast = desc->parameterTypes.GetLength() - 1; // TODO: variadic: Handle default args - if (totalArgs < argsWithoutLast) + if( totalArgs < argsWithoutLast ) { failedMatches.PushLast(asSFailedMatch(desc->id, asEFM_NOT_ENOUGH_ARGS)); noMatch = true; @@ -2756,7 +2764,7 @@ asUINT asCCompiler::MatchFunctions(asCArray &funcs, asCArray= desc->parameterTypes.GetLength() - defaultArgs ) noMatch = false; - if (noMatch) + if( noMatch ) failedMatches.PushLast(asSFailedMatch(desc->id, totalArgs > desc->parameterTypes.GetLength() ? asEFM_TOO_MANY_ARGS : asEFM_NOT_ENOUGH_ARGS)); } } @@ -2764,7 +2772,7 @@ asUINT asCCompiler::MatchFunctions(asCArray &funcs, asCArray &funcs, asCArray matchingFuncs; - matchingFuncs.SetLengthNoConstruct( funcs.GetLength() ); - for ( n = 0; n < funcs.GetLength(); ++n ) + matchingFuncs.SetLengthNoConstruct(funcs.GetLength()); + for( n = 0; n < funcs.GetLength(); ++n ) { matchingFuncs[n].funcId = funcs[n]; - matchingFuncs[n].cost = 0; + matchingFuncs[n].cost = 0; } // Match positionally passed arguments @@ -2808,7 +2816,7 @@ asUINT asCCompiler::MatchFunctions(asCArray &funcs, asCArray &funcs, asCArrayGetLength(); ++n ) (*namedArgs)[n].match = asUINT(-1); - bool matchedAll = true; + bool matchedAll = true; asUINT argsToMatch = desc->parameterTypes.GetLength(); - if (desc->IsVariadic()) argsToMatch--; + if( desc->IsVariadic() ) argsToMatch--; for( asUINT j = 0; j < argsToMatch; ++j ) { asUINT match = asUINT(-1); @@ -2842,7 +2850,7 @@ asUINT asCCompiler::MatchFunctions(asCArray &funcs, asCArrayparameterNames[j] == namedArg.name ) { namedArg.match = j; - match = n; + match = n; break; } } @@ -2857,16 +2865,16 @@ asUINT asCCompiler::MatchFunctions(asCArray &funcs, asCArrayGetLength(); ++n) + for( n = 0; n < namedArgs->GetLength(); ++n ) { - asSNamedArgument & namedArg = (*namedArgs)[n]; - asUINT a = 0; - - for (; a < desc->parameterTypes.GetLength(); ++a) - if (desc->parameterNames[a] == namedArg.name) + asSNamedArgument &namedArg = (*namedArgs)[n]; + asUINT a = 0; + + for( ; a < desc->parameterTypes.GetLength(); ++a ) + if( desc->parameterNames[a] == namedArg.name ) break; - - if (a == desc->parameterTypes.GetLength()) + + if( a == desc->parameterTypes.GetLength() ) failedMatches.PushLast(asSFailedMatch(desc->id, asEFM_NAMED_MISSING, namedArg.name.AddressOf())); } @@ -2916,7 +2924,7 @@ asUINT asCCompiler::MatchFunctions(asCArray &funcs, asCArray &funcs, asCArray &funcs, asCArrayIsVariadic() ) { // remove it from the list - if( n == funcs.GetLength()-1 ) + if( n == funcs.GetLength() - 1 ) funcs.PopLast(); else funcs[n] = funcs.PopLast(); @@ -2982,7 +2990,7 @@ asUINT asCCompiler::MatchFunctions(asCArray &funcs, asCArray &funcs, asCArrayIsClassMethod() ) { - attemptsPassingClassMethod = true; - str += args[n]->type.dataType.GetTypeInfo()->GetName(); - str += "::"; + attemptsPassingClassMethod = true; + str += args[n]->type.dataType.GetTypeInfo()->GetName(); + str += "::"; } str += args[n]->methodName; } - else if (args[n]->IsAnonymousInitList()) + else if( args[n]->IsAnonymousInitList() ) { str += "{...}"; } - else if (args[n]->IsLambda()) + else if( args[n]->IsLambda() ) { str += BuildLambdaSignature(args[n]->exprNode); } @@ -3020,9 +3028,9 @@ asUINT asCCompiler::MatchFunctions(asCArray &funcs, asCArray 0 || args.GetLength() ) str += ", "; - asSNamedArgument &named = (*namedArgs)[n]; - str += named.name; - str += ": "; + asSNamedArgument &named = (*namedArgs)[n]; + str += named.name; + str += ": "; if( named.ctx->methodName != "" ) str += named.ctx->methodName; else @@ -3082,7 +3090,7 @@ bool asCCompiler::CompileAutoType(asCDataType &type, asCExprContext &compiledCtx if( r >= 0 ) { // Must not have unused ambiguous names - if (compiledCtx.IsClassMethod() || compiledCtx.IsGlobalFunc()) + if( compiledCtx.IsClassMethod() || compiledCtx.IsGlobalFunc() ) { // TODO: Should mention that the problem is the ambiguous name Error(TXT_CANNOT_RESOLVE_AUTO, errNode); @@ -3090,7 +3098,7 @@ bool asCCompiler::CompileAutoType(asCDataType &type, asCExprContext &compiledCtx } // Must not have unused anonymous functions - if (compiledCtx.IsLambda()) + if( compiledCtx.IsLambda() ) { // TODO: Should mention that the problem is the anonymous function Error(TXT_CANNOT_RESOLVE_AUTO, errNode); @@ -3098,7 +3106,7 @@ bool asCCompiler::CompileAutoType(asCDataType &type, asCExprContext &compiledCtx } // Must not be a null handle - if (compiledCtx.type.dataType.IsNullHandle()) + if( compiledCtx.type.dataType.IsNullHandle() ) { // TODO: Should mention that the problem is the null pointer Error(TXT_CANNOT_RESOLVE_AUTO, errNode); @@ -3108,23 +3116,23 @@ bool asCCompiler::CompileAutoType(asCDataType &type, asCExprContext &compiledCtx asCDataType newType = compiledCtx.type.dataType; // Handle const qualifier on auto - if (type.IsReadOnly()) + if( type.IsReadOnly() ) newType.MakeReadOnly(true); - else if (type.IsHandleToConst()) + else if( type.IsHandleToConst() ) newType.MakeHandleToConst(true); - else if (newType.IsPrimitive()) + else if( newType.IsPrimitive() ) newType.MakeReadOnly(false); // Handle reference/value stuff newType.MakeReference(false); - if (!newType.IsObjectHandle()) + if( !newType.IsObjectHandle() ) { // We got a value object or an object reference. // Turn the variable into a handle if specified // as auto@, otherwise make it a 'value'. - if (type.IsHandleToAuto()) + if( type.IsHandleToAuto() ) { - if (newType.MakeHandle(true) < 0) + if( newType.MakeHandle(true) < 0 ) { Error(TXT_OBJECT_HANDLE_NOT_SUPPORTED, errNode); return false; @@ -3133,11 +3141,11 @@ bool asCCompiler::CompileAutoType(asCDataType &type, asCExprContext &compiledCtx } // Implicit handle types should always be handles - if (newType.GetTypeInfo() && - (newType.GetTypeInfo()->flags & asOBJ_IMPLICIT_HANDLE)) + if( newType.GetTypeInfo() && + (newType.GetTypeInfo()->flags & asOBJ_IMPLICIT_HANDLE) ) newType.MakeHandle(true); - - // For types that support handles auto should prefer handle + + // For types that support handles auto should prefer handle // as it is more efficient than making a copy if( newType.SupportHandles() ) newType.MakeHandle(true); @@ -3167,11 +3175,11 @@ void asCCompiler::CompileDeclaration(asCScriptNode *decl, asCByteCode *bc) { // If this is an auto type, we have to compile the assignment now to figure out the type asCExprContext compiledCtx(engine); - bool preCompiled = false; - if (type.IsAuto()) + bool preCompiled = false; + if( type.IsAuto() ) { preCompiled = CompileAutoType(type, compiledCtx, node->next, node); - if (!preCompiled) + if( !preCompiled ) { // If it wasn't possible to determine the type from the expression then there // is no need to continue with the initialization. The error was already reported @@ -3223,7 +3231,7 @@ void asCCompiler::CompileDeclaration(asCScriptNode *decl, asCByteCode *bc) } int offset = AllocateVariable(type, false); - if (DeclareVariable(name, type, offset, bc, node) < 0) + if( DeclareVariable(name, type, offset, bc, node) < 0 ) return; // Keep the node for the variable decl @@ -3245,9 +3253,9 @@ void asCCompiler::CompileDeclaration(asCScriptNode *decl, asCByteCode *bc) // Check if the variable should be marked as pure constant if( type.IsPrimitive() && type.IsReadOnly() ) { - sVariable *v = variables->GetVariable(name.AddressOf()); + sVariable *v = variables->GetVariable(name.AddressOf()); v->isPureConstant = true; - v->constantValue = constantValue; + v->constantValue = constantValue; } } node = node->next; @@ -3276,7 +3284,7 @@ bool asCCompiler::CompileInitialization(asCScriptNode *node, asCByteCode *bc, co if( CompileArgumentList(node, args, namedArgs) >= 0 ) { // Find all constructors - asCArray funcs; + asCArray funcs; asSTypeBehaviour *beh = type.GetBehaviour(); if( beh ) { @@ -3319,7 +3327,7 @@ bool asCCompiler::CompileInitialization(asCScriptNode *node, asCByteCode *bc, co ctx.bc.InstrSHORT_DW(asBC_ADDSi, (short)offset, engine->GetTypeIdFromDataType(asCDataType::CreateType(outFunc->objectType, false))); } - if (type.GetTypeInfo()->flags & asOBJ_SCOPED) + if( type.GetTypeInfo()->flags & asOBJ_SCOPED ) { // For scoped typed we must move the reference from the local // variable rather than copy it as there is no AddRef behaviour @@ -3328,7 +3336,7 @@ bool asCCompiler::CompileInitialization(asCScriptNode *node, asCByteCode *bc, co // Clear the local variable so the reference isn't released ctx.bc.InstrSHORT(asBC_ClrVPtr, (short)ctx.type.stackOffset); } - else if( type.IsFuncdef()) + else if( type.IsFuncdef() ) ctx.bc.InstrPTR(asBC_REFCPY, &engine->functionBehaviours); else ctx.bc.InstrPTR(asBC_REFCPY, type.GetTypeInfo()); @@ -3374,7 +3382,7 @@ bool asCCompiler::CompileInitialization(asCScriptNode *node, asCByteCode *bc, co PrepareFunctionCall(funcs[0], &ctx.bc, args); // For variadic functions we need to pass the number of arguments in a register - if (builder->GetFunctionDescription(funcs[0])->IsVariadic()) + if( builder->GetFunctionDescription(funcs[0])->IsVariadic() ) { // Argument count ctx.bc.InstrDWORD(asBC_PshC4, (asDWORD)args.GetLength()); @@ -3426,18 +3434,18 @@ bool asCCompiler::CompileInitialization(asCScriptNode *node, asCByteCode *bc, co { asCExprValue ti; ti.Set(type); - ti.isVariable = (isVarGlobOrMem == 0); + ti.isVariable = (isVarGlobOrMem == 0); ti.isTemporary = false; ti.stackOffset = offset; - ti.isLValue = true; + ti.isLValue = true; CompileInitList(&ti, node, bc, isVarGlobOrMem); } else if( node && node->nodeType == snAssignment ) { // Compile the expression - asCExprContext newExpr(engine); - asCExprContext* expr; + asCExprContext newExpr(engine); + asCExprContext *expr; if( preCompiled ) { @@ -3445,15 +3453,15 @@ bool asCCompiler::CompileInitialization(asCScriptNode *node, asCByteCode *bc, co } else { - expr = &newExpr; + expr = &newExpr; int r = CompileAssignment(node, expr); - if (r < 0) + if( r < 0 ) return false; } // handles initialized with null doesn't need any bytecode // since handles will be initialized to null by default anyway - if (type.IsObjectHandle() && expr->type.IsNullConstant() && expr->bc.IsSimpleExpression() ) + if( type.IsObjectHandle() && expr->type.IsNullConstant() && expr->bc.IsSimpleExpression() ) return false; return CompileInitializationWithAssignment(bc, type, errNode, offset, constantValue, isVarGlobOrMem, node, expr); @@ -3479,19 +3487,19 @@ bool asCCompiler::CompileInitialization(asCScriptNode *node, asCByteCode *bc, co return isConstantExpression; } -bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asCDataType& type, asCScriptNode* errNode, int offset, asQWORD* constantValue, EVarGlobOrMem isVarGlobOrMem, asCScriptNode* rnode, asCExprContext* rexpr) +bool asCCompiler::CompileInitializationWithAssignment(asCByteCode *bc, const asCDataType &type, asCScriptNode *errNode, int offset, asQWORD *constantValue, EVarGlobOrMem isVarGlobOrMem, asCScriptNode *rnode, asCExprContext *rexpr) { bool isConstantExpression = false; // Look for appropriate constructor - asCArray funcs; - asCArray args; + asCArray funcs; + asCArray args; // If the rexpr is already a temporary value of the same type, then it should be used directly without making a copy // TODO: This can probably be done for local variables as well // TODO: For value types, stored inline the rexpr would have to be compiled already to initialize the value so the following cannot be used - if ((isVarGlobOrMem == asVGM_MEMBER || isVarGlobOrMem == asVGM_GLOBAL) && - rexpr->type.isTemporary && type.GetTypeInfo() == rexpr->type.dataType.GetTypeInfo() && type.IsObject() && (type.IsObjectHandle() || type.SupportHandles())) + if( (isVarGlobOrMem == asVGM_MEMBER || isVarGlobOrMem == asVGM_GLOBAL) && + rexpr->type.isTemporary && type.GetTypeInfo() == rexpr->type.dataType.GetTypeInfo() && type.IsObject() && (type.IsObjectHandle() || type.SupportHandles()) ) { // Add the rexpr to the bytecode if( !(type.GetTypeInfo()->flags & asOBJ_SCOPED) ) @@ -3499,7 +3507,7 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC bc->AddCode(&rexpr->bc); // Store the returned handle in the member - if (isVarGlobOrMem == asVGM_MEMBER) + if( isVarGlobOrMem == asVGM_MEMBER ) { bc->InstrSHORT(asBC_PSF, 0); bc->Instr(asBC_RDSPtr); @@ -3510,7 +3518,7 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC bc->InstrPTR(asBC_PGA, engine->globalProperties[offset]->GetAddressOfValue()); } - if (type.GetTypeInfo()->flags & asOBJ_SCOPED) + if( type.GetTypeInfo()->flags & asOBJ_SCOPED ) { // For scoped typed we must move the reference from the local // variable rather than copy it as there is no AddRef behaviour @@ -3519,7 +3527,7 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC // Clear the local variable so the reference isn't released bc->InstrSHORT(asBC_ClrVPtr, (short)rexpr->type.stackOffset); } - else if (type.IsFuncdef()) + else if( type.IsFuncdef() ) bc->InstrPTR(asBC_REFCPY, &engine->functionBehaviours); else bc->InstrPTR(asBC_REFCPY, type.GetTypeInfo()); @@ -3536,14 +3544,14 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC // Only do this if the expression is of the same type, as the expression is an assignment // and an initialization constructor may not have the same meaning. // TODO: Should allow initialization constructor if it is declared as allowed for implicit conversions. - if (!type.IsObjectHandle() && !rexpr->type.isExplicitHandle && - !(type.GetTypeInfo() && (type.GetTypeInfo()->GetFlags() & asOBJ_ASHANDLE)) && - type.IsEqualExceptRefAndConst(rexpr->type.dataType)) + if( !type.IsObjectHandle() && !rexpr->type.isExplicitHandle && + !(type.GetTypeInfo() && (type.GetTypeInfo()->GetFlags() & asOBJ_ASHANDLE)) && + type.IsEqualExceptRefAndConst(rexpr->type.dataType) ) { - asSTypeBehaviour* beh = type.GetBehaviour(); - if (beh) + asSTypeBehaviour *beh = type.GetBehaviour(); + if( beh ) { - if (type.GetTypeInfo()->flags & asOBJ_REF) + if( type.GetTypeInfo()->flags & asOBJ_REF ) funcs = beh->factories; else funcs = beh->constructors; @@ -3553,20 +3561,20 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC args.PushLast(rexpr); MatchFunctions(funcs, args, rnode, str.AddressOf(), 0, 0, 0, true); - if (funcs.GetLength() == 1) + if( funcs.GetLength() == 1 ) { - asCScriptFunction* f = engine->scriptFunctions[funcs[0]]; + asCScriptFunction *f = engine->scriptFunctions[funcs[0]]; // Don't allow the constructor to be used if it is marked as explicit - if (f->traits.GetTrait(asTRAIT_EXPLICIT)) + if( f->traits.GetTrait(asTRAIT_EXPLICIT) ) funcs.PopLast(); // Make sure the argument is of the right type (and not just compatible with the expression) - else if (!f->parameterTypes[0].IsEqualExceptRefAndConst(rexpr->type.dataType)) + else if( !f->parameterTypes[0].IsEqualExceptRefAndConst(rexpr->type.dataType) ) funcs.PopLast(); } } - if (funcs.GetLength() == 1) + if( funcs.GetLength() == 1 ) { // Use the constructor @@ -3574,18 +3582,18 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC // Add the default values for arguments not explicitly supplied int r = CompileDefaultAndNamedArgs(rnode, args, funcs[0], CastToObjectType(type.GetTypeInfo())); - if (r == asSUCCESS) + if( r == asSUCCESS ) { asCExprContext ctx(engine); - if (type.GetTypeInfo() && (type.GetTypeInfo()->flags & asOBJ_REF)) + if( type.GetTypeInfo() && (type.GetTypeInfo()->flags & asOBJ_REF) ) { - if (isVarGlobOrMem == asVGM_VARIABLE) + if( isVarGlobOrMem == asVGM_VARIABLE ) MakeFunctionCall(&ctx, funcs[0], 0, args, rnode, true, offset); else { MakeFunctionCall(&ctx, funcs[0], 0, args, rnode); ctx.bc.Instr(asBC_RDSPtr); - if (isVarGlobOrMem == asVGM_GLOBAL) + if( isVarGlobOrMem == asVGM_GLOBAL ) { // Store the returned handle in the global variable ctx.bc.InstrPTR(asBC_PGA, engine->globalProperties[offset]->GetAddressOfValue()); @@ -3597,7 +3605,7 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC ctx.bc.Instr(asBC_RDSPtr); ctx.bc.InstrSHORT_DW(asBC_ADDSi, (short)offset, engine->GetTypeIdFromDataType(asCDataType::CreateType(outFunc->objectType, false))); } - if (type.IsFuncdef()) + if( type.IsFuncdef() ) ctx.bc.InstrPTR(asBC_REFCPY, &engine->functionBehaviours); else ctx.bc.InstrPTR(asBC_REFCPY, type.GetTypeInfo()); @@ -3611,17 +3619,17 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC { bool onHeap = false; - if (isVarGlobOrMem == asVGM_VARIABLE) + if( isVarGlobOrMem == asVGM_VARIABLE ) { // When the object is allocated on the heap, the address where the // reference will be stored must be pushed on the stack before the // arguments. This reference on the stack is safe, even if the script // is suspended during the evaluation of the arguments. onHeap = IsVariableOnHeap(offset); - if (onHeap) + if( onHeap ) ctx.bc.InstrSHORT(asBC_PSF, (short)offset); } - else if (isVarGlobOrMem == asVGM_GLOBAL) + else if( isVarGlobOrMem == asVGM_GLOBAL ) { // Push the address of the location where the variable will be stored on the stack. // This reference is safe, because the addresses of the global variables cannot change. @@ -3632,7 +3640,7 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC { // Value types may be allocated inline if they are POD types onHeap = !(type.IsObject() || type.IsFuncdef()) || type.IsReference() || (type.GetTypeInfo()->flags & asOBJ_REF); - if (onHeap) + if( onHeap ) { ctx.bc.InstrSHORT(asBC_PSF, 0); ctx.bc.Instr(asBC_RDSPtr); @@ -3645,9 +3653,9 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC // When the object is allocated on the stack, the address to the // object is pushed on the stack after the arguments as the object pointer - if (!onHeap) + if( !onHeap ) { - if (isVarGlobOrMem == asVGM_MEMBER) + if( isVarGlobOrMem == asVGM_MEMBER ) { ctx.bc.InstrSHORT(asBC_PSF, 0); ctx.bc.Instr(asBC_RDSPtr); @@ -3661,7 +3669,7 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC PerformFunctionCall(funcs[0], &ctx, onHeap, &args, CastToObjectType(type.GetTypeInfo())); - if (isVarGlobOrMem == asVGM_VARIABLE) + if( isVarGlobOrMem == asVGM_VARIABLE ) { // Mark the object in the local variable as initialized ctx.bc.ObjInfo(offset, asOBJ_INIT); @@ -3677,35 +3685,35 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC asCExprContext ctx(engine); // Call the default constructor here - if (isVarGlobOrMem == asVGM_VARIABLE) + if( isVarGlobOrMem == asVGM_VARIABLE ) CallDefaultConstructor(type, offset, IsVariableOnHeap(offset), &ctx.bc, errNode); - else if (isVarGlobOrMem == asVGM_GLOBAL) + else if( isVarGlobOrMem == asVGM_GLOBAL ) CallDefaultConstructor(type, offset, true, &ctx.bc, errNode, isVarGlobOrMem); - else if (isVarGlobOrMem == asVGM_MEMBER) + else if( isVarGlobOrMem == asVGM_MEMBER ) CallDefaultConstructor(type, offset, type.IsReference(), &ctx.bc, errNode, isVarGlobOrMem); - if (type.IsPrimitive()) + if( type.IsPrimitive() ) { - if (type.IsReadOnly() && rexpr->type.isConstant) + if( type.IsReadOnly() && rexpr->type.isConstant ) { ImplicitConversion(rexpr, type, rnode, asIC_IMPLICIT_CONV); // Tell caller that the expression is a constant so it can mark the variable as pure constant isConstantExpression = true; - *constantValue = rexpr->type.GetConstantData(); + *constantValue = rexpr->type.GetConstantData(); } asCExprContext lctx(engine); - if (isVarGlobOrMem == asVGM_VARIABLE) + if( isVarGlobOrMem == asVGM_VARIABLE ) lctx.type.SetVariable(type, offset, false); - else if (isVarGlobOrMem == asVGM_GLOBAL) + else if( isVarGlobOrMem == asVGM_GLOBAL ) { lctx.type.Set(type); lctx.type.dataType.MakeReference(true); // If it is an enum value, i.e. offset is negative, that is being compiled then // we skip this as the bytecode won't be used anyway, only the constant value - if (offset >= 0) + if( offset >= 0 ) lctx.bc.InstrPTR(asBC_LDG, engine->globalProperties[offset]->GetAddressOfValue()); } else @@ -3734,29 +3742,29 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC asCExprContext lexpr(engine); lexpr.type.Set(type); - if (isVarGlobOrMem == asVGM_VARIABLE) + if( isVarGlobOrMem == asVGM_VARIABLE ) lexpr.type.dataType.MakeReference(IsVariableOnHeap(offset)); - else if (isVarGlobOrMem == asVGM_GLOBAL) + else if( isVarGlobOrMem == asVGM_GLOBAL ) lexpr.type.dataType.MakeReference(true); - else if (isVarGlobOrMem == asVGM_MEMBER) + else if( isVarGlobOrMem == asVGM_MEMBER ) { - if (!lexpr.type.dataType.IsObject() || lexpr.type.dataType.IsFuncdef() || (lexpr.type.dataType.GetTypeInfo()->flags & asOBJ_REF)) + if( !lexpr.type.dataType.IsObject() || lexpr.type.dataType.IsFuncdef() || (lexpr.type.dataType.GetTypeInfo()->flags & asOBJ_REF) ) lexpr.type.dataType.MakeReference(true); } // Allow initialization of constant variables lexpr.type.dataType.MakeReadOnly(false); - if (type.IsObjectHandle()) + if( type.IsObjectHandle() ) lexpr.type.isExplicitHandle = true; - if (isVarGlobOrMem == asVGM_VARIABLE) + if( isVarGlobOrMem == asVGM_VARIABLE ) { lexpr.bc.InstrSHORT(asBC_PSF, (short)offset); lexpr.type.stackOffset = (short)offset; - lexpr.type.isVariable = true; + lexpr.type.isVariable = true; } - else if (isVarGlobOrMem == asVGM_GLOBAL) + else if( isVarGlobOrMem == asVGM_GLOBAL ) { lexpr.bc.InstrPTR(asBC_PGA, engine->globalProperties[offset]->GetAddressOfValue()); } @@ -3777,18 +3785,18 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC // and a simple assignment. bool assigned = false; // Even though an ASHANDLE can be an explicit handle the overloaded operator needs to be called - if ((lexpr.type.dataType.IsObject() || lexpr.type.dataType.IsFuncdef()) && (!lexpr.type.isExplicitHandle || (lexpr.type.dataType.GetTypeInfo() && (lexpr.type.dataType.GetTypeInfo()->flags & asOBJ_ASHANDLE)))) + if( (lexpr.type.dataType.IsObject() || lexpr.type.dataType.IsFuncdef()) && (!lexpr.type.isExplicitHandle || (lexpr.type.dataType.GetTypeInfo() && (lexpr.type.dataType.GetTypeInfo()->flags & asOBJ_ASHANDLE))) ) { bool useHndlAssign = false; - if (lexpr.type.dataType.IsHandleToAsHandleType()) + if( lexpr.type.dataType.IsHandleToAsHandleType() ) { useHndlAssign = true; // Make sure the right hand expression is treated as a handle - if (!rexpr->type.isExplicitHandle && !rexpr->type.IsNullConstant()) + if( !rexpr->type.isExplicitHandle && !rexpr->type.IsNullConstant() ) { // Convert the expression to a handle - if (!rexpr->type.dataType.IsObjectHandle() && rexpr->type.dataType.SupportHandles() && rexpr->type.dataType.GetTypeInfo() && !(rexpr->type.dataType.GetTypeInfo()->flags & asOBJ_ASHANDLE)) + if( !rexpr->type.dataType.IsObjectHandle() && rexpr->type.dataType.SupportHandles() && rexpr->type.dataType.GetTypeInfo() && !(rexpr->type.dataType.GetTypeInfo()->flags & asOBJ_ASHANDLE) ) { asCDataType to = rexpr->type.dataType; to.MakeHandle(true); @@ -3798,13 +3806,13 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC asASSERT(rexpr->type.dataType.IsObjectHandle()); } - else if (rexpr->type.dataType.GetTypeInfo() && rexpr->type.dataType.GetTypeInfo()->flags & asOBJ_ASHANDLE) + else if( rexpr->type.dataType.GetTypeInfo() && rexpr->type.dataType.GetTypeInfo()->flags & asOBJ_ASHANDLE ) { // For the ASHANDLE type we'll simply set the expression as a handle rexpr->type.dataType.MakeHandle(true); } - if (!rexpr->type.dataType.IsObjectHandle() && !rexpr->type.dataType.SupportHandles()) + if( !rexpr->type.dataType.IsObjectHandle() && !rexpr->type.dataType.SupportHandles() ) { Error(TXT_OBJECT_HANDLE_NOT_SUPPORTED, rnode); } @@ -3812,10 +3820,10 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC } } assigned = CompileOverloadedDualOperator(rnode, &lexpr, rexpr, false, &ctx, useHndlAssign); - if (assigned) + if( assigned ) { // Pop the resulting value - if (!ctx.type.dataType.IsPrimitive()) + if( !ctx.type.dataType.IsPrimitive() ) ctx.bc.Instr(asBC_PopPtr); // Release the argument @@ -3826,17 +3834,17 @@ bool asCCompiler::CompileInitializationWithAssignment(asCByteCode* bc, const asC } } - if (!assigned) + if( !assigned ) { PrepareForAssignment(&lexpr.type.dataType, rexpr, rnode, false); // If the expression is constant and the variable also is constant // then mark the variable as pure constant. This will allow the compiler // to optimize expressions with this variable. - if (type.IsReadOnly() && rexpr->type.isConstant) + if( type.IsReadOnly() && rexpr->type.isConstant ) { isConstantExpression = true; - *constantValue = rexpr->type.GetConstantData(); + *constantValue = rexpr->type.GetConstantData(); } // Add expression code to bytecode @@ -3866,8 +3874,8 @@ void asCCompiler::CompileInitList(asCExprValue *var, asCScriptNode *node, asCByt { // Check if the type supports initialization lists if( var->dataType.GetTypeInfo() == 0 || - var->dataType.GetBehaviour() == 0 || - var->dataType.GetBehaviour()->listFactory == 0 ) + var->dataType.GetBehaviour() == 0 || + var->dataType.GetBehaviour()->listFactory == 0 ) { asCString str; str.Format(TXT_INIT_LIST_CANNOT_BE_USED_WITH_s, var->dataType.Format(outFunc->nameSpace).AddressOf()); @@ -3889,17 +3897,17 @@ void asCCompiler::CompileInitList(asCExprValue *var, asCScriptNode *node, asCByt asCObjectType *listPatternType = engine->GetListPatternType(funcId); // Allocate a temporary variable to hold the pointer to the buffer - int bufferVar = AllocateVariable(asCDataType::CreateType(listPatternType, false), true); + int bufferVar = AllocateVariable(asCDataType::CreateType(listPatternType, false), true); asUINT bufferSize = 0; // Evaluate all elements of the list - asCExprContext valueExpr(engine); - asCScriptNode *el = node; - asSListPatternNode *patternNode = engine->scriptFunctions[listPatternType->templateSubTypes[0].GetBehaviour()->listFactory]->listPattern; - int elementsInSubList = -1; - int r = CompileInitListElement(patternNode, el, engine->GetTypeIdFromDataType(asCDataType::CreateType(listPatternType, false)), short(bufferVar), bufferSize, valueExpr.bc, elementsInSubList); + asCExprContext valueExpr(engine); + asCScriptNode *el = node; + asSListPatternNode *patternNode = engine->scriptFunctions[listPatternType->templateSubTypes[0].GetBehaviour()->listFactory]->listPattern; + int elementsInSubList = -1; + int r = CompileInitListElement(patternNode, el, engine->GetTypeIdFromDataType(asCDataType::CreateType(listPatternType, false)), short(bufferVar), bufferSize, valueExpr.bc, elementsInSubList); asASSERT( r || patternNode == 0 ); - if (r < 0) + if( r < 0 ) { asCString msg; msg.Format(TXT_PREV_ERROR_WHILE_COMP_LIST_FOR_TYPE_s, var->dataType.Format(outFunc->nameSpace).AddressOf()); @@ -3916,7 +3924,7 @@ void asCCompiler::CompileInitList(asCExprValue *var, asCScriptNode *node, asCByt // The object itself is the last to be created and will receive the pointer to the buffer asCArray args; - asCExprContext arg1(engine); + asCExprContext arg1(engine); arg1.type.Set(asCDataType::CreatePrimitive(ttUInt, false)); arg1.type.dataType.MakeReference(true); arg1.bc.InstrSHORT(asBC_PshVPtr, short(bufferVar)); @@ -3982,7 +3990,7 @@ void asCCompiler::CompileInitList(asCExprValue *var, asCScriptNode *node, asCByt ctx.bc.Instr(asBC_RDSPtr); ctx.bc.InstrSHORT_DW(asBC_ADDSi, (short)var->stackOffset, engine->GetTypeIdFromDataType(asCDataType::CreateType(outFunc->objectType, false))); } - if (var->dataType.IsFuncdef()) + if( var->dataType.IsFuncdef() ) ctx.bc.InstrPTR(asBC_REFCPY, &engine->functionBehaviours); else ctx.bc.InstrPTR(asBC_REFCPY, var->dataType.GetTypeInfo()); @@ -4041,7 +4049,7 @@ int asCCompiler::CompileInitListElement(asSListPatternNode *&patternNode, asCScr } // Compile all values until asLPT_END - patternNode = patternNode->next; + patternNode = patternNode->next; asCScriptNode *node = valueNode->firstChild; while( patternNode->type != asLPT_END ) { @@ -4053,7 +4061,7 @@ int asCCompiler::CompileInitListElement(asSListPatternNode *&patternNode, asCScr } asCScriptNode *errNode = node; - int r = CompileInitListElement(patternNode, node, bufferTypeId, bufferVar, bufferSize, bcInit, elementsInSubList); + int r = CompileInitListElement(patternNode, node, bufferTypeId, bufferVar, bufferSize, bcInit, elementsInSubList); if( r < 0 ) return r; if( r == 1 ) @@ -4073,7 +4081,7 @@ int asCCompiler::CompileInitListElement(asSListPatternNode *&patternNode, asCScr } // Move to the next node - valueNode = valueNode->next; + valueNode = valueNode->next; patternNode = patternNode->next; } else if( patternNode->type == asLPT_REPEAT || patternNode->type == asLPT_REPEAT_SAME ) @@ -4082,7 +4090,7 @@ int asCCompiler::CompileInitListElement(asSListPatternNode *&patternNode, asCScr // TODO: list: repeat_prev should make sure the list is the same size as the previous asEListPatternNodeType repeatType = patternNode->type; - asCScriptNode *firstValue = valueNode; + asCScriptNode *firstValue = valueNode; // The following values will be repeated N times patternNode = patternNode->next; @@ -4095,18 +4103,18 @@ int asCCompiler::CompileInitListElement(asSListPatternNode *&patternNode, asCScr bufferSize += 4 - (bufferSize & 0x3); // The first dword will hold the number of elements in the list - asDWORD currSize = bufferSize; - bufferSize += 4; - asUINT countElements = 0; + asDWORD currSize = bufferSize; + bufferSize += 4; + asUINT countElements = 0; int elementsInSubSubList = -1; asCExprContext ctx(engine); while( valueNode ) { - patternNode = nextNode; + patternNode = nextNode; asCScriptNode *errNode = valueNode; - int r = CompileInitListElement(patternNode, valueNode, bufferTypeId, bufferVar, bufferSize, ctx.bc, elementsInSubSubList); + int r = CompileInitListElement(patternNode, valueNode, bufferTypeId, bufferVar, bufferSize, ctx.bc, elementsInSubSubList); if( r < 0 ) return r; if( r == 0 ) @@ -4172,7 +4180,7 @@ int asCCompiler::CompileInitListElement(asSListPatternNode *&patternNode, asCScr // Determine the size of the element asUINT size = 0; - asCDataType dt = reinterpret_cast(patternNode)->dataType; + asCDataType dt = reinterpret_cast(patternNode)->dataType; if( valueNode->nodeType == snAssignment || valueNode->nodeType == snInitList ) { @@ -4199,11 +4207,11 @@ int asCCompiler::CompileInitListElement(asSListPatternNode *&patternNode, asCScr bufferSize += 4 - (bufferSize & 0x3); // When value assignment for reference types us disabled, make sure all ref types are passed in as handles - if (engine->ep.disallowValueAssignForRefType && dt.SupportHandles()) + if( engine->ep.disallowValueAssignForRefType && dt.SupportHandles() ) dt.MakeHandle(true); // Make sure the type is deterministic - if (dt.GetTypeInfo() == &engine->functionBehaviours) + if( dt.GetTypeInfo() == &engine->functionBehaviours ) { Error(TXT_INVALID_EXPRESSION_LAMBDA, valueNode); return -1; @@ -4231,7 +4239,7 @@ int asCCompiler::CompileInitListElement(asSListPatternNode *&patternNode, asCScr int offset = AllocateVariable(dt, true); rctx.type.Set(dt); - rctx.type.isVariable = true; + rctx.type.isVariable = true; rctx.type.isTemporary = true; rctx.type.stackOffset = offset; @@ -4249,7 +4257,7 @@ int asCCompiler::CompileInitListElement(asSListPatternNode *&patternNode, asCScr if( dt.IsPrimitive() || (!dt.IsNullHandle() && (dt.GetTypeInfo()->flags & asOBJ_VALUE)) ) size = dt.GetSizeInMemoryBytes(); else - size = AS_PTR_SIZE*4; + size = AS_PTR_SIZE * 4; // Values on the list must be aligned to 32bit boundaries, except if the type is smaller than 32bit. if( size >= 4 && (bufferSize & 0x3) ) @@ -4269,16 +4277,16 @@ int asCCompiler::CompileInitListElement(asSListPatternNode *&patternNode, asCScr lctx.type.isExplicitHandle = true; lctx.type.dataType.MakeReference(true); } - else if (dt.GetTypeInfo()->flags & asOBJ_REF) + else if( dt.GetTypeInfo()->flags & asOBJ_REF ) { - // For reference types stored by value we must make sure the correct type is + // For reference types stored by value we must make sure the correct type is // used even though the expression may be ref cast to the expected type - if ( lctx.type.dataType.GetTypeInfo() != rctx.type.dataType.GetTypeInfo() && - rctx.type.dataType.GetTypeInfo() && - rctx.type.dataType.GetTypeInfo()->DerivesFrom(lctx.type.dataType.GetTypeInfo()) ) + if( lctx.type.dataType.GetTypeInfo() != rctx.type.dataType.GetTypeInfo() && + rctx.type.dataType.GetTypeInfo() && + rctx.type.dataType.GetTypeInfo()->DerivesFrom(lctx.type.dataType.GetTypeInfo()) ) { // Create a new instance of the correct type and assign the value to it - int offset = AllocateVariable(lctx.type.dataType, true); + int offset = AllocateVariable(lctx.type.dataType, true); asCExprContext ctx(engine); CompileInitAsCopy(lctx.type.dataType, offset, &ctx, &rctx, valueNode, false); MergeExprBytecode(&rctx, &ctx); @@ -4297,8 +4305,8 @@ int asCCompiler::CompileInitListElement(asSListPatternNode *&patternNode, asCScr // Make sure the object has been constructed before the assignment // TODO: runtime optimize: Use copy constructor instead of assignment to initialize the objects - asSTypeBehaviour *beh = dt.GetBehaviour(); - int func = 0; + asSTypeBehaviour *beh = dt.GetBehaviour(); + int func = 0; if( beh ) func = beh->construct; if( func == 0 && (dt.GetTypeInfo()->flags & asOBJ_POD) == 0 ) { @@ -4367,8 +4375,8 @@ int asCCompiler::CompileInitListElement(asSListPatternNode *&patternNode, asCScr else if( dt.GetTypeInfo() && dt.GetTypeInfo()->flags & asOBJ_VALUE ) { // For value types with default constructor we need to call the constructor - asSTypeBehaviour *beh = dt.GetBehaviour(); - int func = 0; + asSTypeBehaviour *beh = dt.GetBehaviour(); + int func = 0; if( beh ) func = beh->construct; if( func == 0 && (dt.GetTypeInfo()->flags & asOBJ_POD) == 0 ) { @@ -4393,8 +4401,8 @@ int asCCompiler::CompileInitListElement(asSListPatternNode *&patternNode, asCScr else if( !dt.IsObjectHandle() && dt.GetTypeInfo() && dt.GetTypeInfo()->flags & asOBJ_REF ) { // For ref types (not handles) we need to call the default factory - asSTypeBehaviour *beh = dt.GetBehaviour(); - int func = 0; + asSTypeBehaviour *beh = dt.GetBehaviour(); + int func = 0; if( beh ) func = beh->factory; if( func == 0 ) { @@ -4414,7 +4422,7 @@ int asCCompiler::CompileInitListElement(asSListPatternNode *&patternNode, asCScr asCExprContext lctx(engine); lctx.bc.InstrSHORT_DW(asBC_PshListElmnt, bufferVar, bufferSize); lctx.type.Set(dt); - lctx.type.isLValue = true; + lctx.type.isLValue = true; lctx.type.isExplicitHandle = true; lctx.type.dataType.MakeReference(true); @@ -4441,7 +4449,7 @@ int asCCompiler::CompileInitListElement(asSListPatternNode *&patternNode, asCScr if( dt.IsPrimitive() || (!dt.IsNullHandle() && (dt.GetTypeInfo()->flags & asOBJ_VALUE)) ) size = dt.GetSizeInMemoryBytes(); else - size = AS_PTR_SIZE*4; + size = AS_PTR_SIZE * 4; asASSERT( size <= 4 || (size & 0x3) == 0 ); bufferSize += size; @@ -4449,7 +4457,7 @@ int asCCompiler::CompileInitListElement(asSListPatternNode *&patternNode, asCScr // Move to the next element patternNode = patternNode->next; - valueNode = valueNode->next; + valueNode = valueNode->next; if( isEmpty ) { @@ -4470,29 +4478,29 @@ void asCCompiler::CompileStatement(asCScriptNode *statement, bool *hasReturn, as if( statement->nodeType != snExpressionStatement || statement->firstChild ) *hasReturn = false; - if (statement->nodeType == snStatementBlock) + if( statement->nodeType == snStatementBlock ) CompileStatementBlock(statement, true, hasReturn, bc); - else if (statement->nodeType == snIf) + else if( statement->nodeType == snIf ) CompileIfStatement(statement, hasReturn, bc); - else if (statement->nodeType == snFor) + else if( statement->nodeType == snFor ) CompileForStatement(statement, bc); - else if (statement->nodeType == snForEach) + else if( statement->nodeType == snForEach ) CompileForEachStatement(statement, bc); - else if (statement->nodeType == snWhile) + else if( statement->nodeType == snWhile ) CompileWhileStatement(statement, bc); - else if (statement->nodeType == snDoWhile) + else if( statement->nodeType == snDoWhile ) CompileDoWhileStatement(statement, bc); - else if (statement->nodeType == snExpressionStatement) + else if( statement->nodeType == snExpressionStatement ) CompileExpressionStatement(statement, bc); - else if (statement->nodeType == snBreak) + else if( statement->nodeType == snBreak ) CompileBreakStatement(statement, bc); - else if (statement->nodeType == snContinue) + else if( statement->nodeType == snContinue ) CompileContinueStatement(statement, bc); - else if (statement->nodeType == snSwitch) + else if( statement->nodeType == snSwitch ) CompileSwitchStatement(statement, hasReturn, bc); - else if (statement->nodeType == snTryCatch) + else if( statement->nodeType == snTryCatch ) CompileTryCatch(statement, hasReturn, bc); - else if (statement->nodeType == snReturn) + else if( statement->nodeType == snReturn ) { CompileReturnStatement(statement, bc); *hasReturn = true; @@ -4559,7 +4567,7 @@ void asCCompiler::CompileSwitchStatement(asCScriptNode *snode, bool *hasReturn, // Remember the first label so that we can later pass the // correct label to each CompileCase() int firstCaseLabel = nextLabel; - int defaultLabel = 0; + int defaultLabel = 0; asCArray caseValues; asCArray caseLabels; @@ -4576,21 +4584,21 @@ void asCCompiler::CompileSwitchStatement(asCScriptNode *snode, bool *hasReturn, CompileExpression(cnode->firstChild, &c); // Verify that the result is a literal constant - if (!c.type.isConstant) + if( !c.type.isConstant ) { Error(TXT_SWITCH_CASE_MUST_BE_CONSTANT, cnode->firstChild); c.type.SetConstantData(asCDataType::CreatePrimitive(ttInt, true), 0); } // Verify that the result is an integral number - if (!c.type.dataType.IsIntegerType() && !c.type.dataType.IsUnsignedType()) + if( !c.type.dataType.IsIntegerType() && !c.type.dataType.IsUnsignedType() ) Error(TXT_SWITCH_MUST_BE_INTEGRAL, cnode->firstChild); else { ImplicitConversion(&c, to, cnode->firstChild, asIC_IMPLICIT_CONV, true); // Has this case been declared already? - if (caseValues.IndexOf(c.type.GetConstantDW()) >= 0) + if( caseValues.IndexOf(c.type.GetConstantDW()) >= 0 ) Error(TXT_DUPLICATE_SWITCH_CASE, cnode->firstChild); // TODO: Optimize: We can insert the numbers sorted already @@ -4620,7 +4628,7 @@ void asCCompiler::CompileSwitchStatement(asCScriptNode *snode, bool *hasReturn, } // check for empty switch - if (caseValues.GetLength() == 0) + if( caseValues.GetLength() == 0 ) { Error(TXT_EMPTY_SWITCH, snode); return; @@ -4644,13 +4652,13 @@ void asCCompiler::CompileSwitchStatement(asCScriptNode *snode, bool *hasReturn, if( caseValues[bck] > caseValues[bckp] ) { // Swap the values in both arrays - int swap = caseValues[bckp]; + int swap = caseValues[bckp]; caseValues[bckp] = caseValues[bck]; - caseValues[bck] = swap; + caseValues[bck] = swap; - swap = caseLabels[bckp]; + swap = caseLabels[bckp]; caseLabels[bckp] = caseLabels[bck]; - caseLabels[bck] = swap; + caseLabels[bck] = swap; } else break; @@ -4666,14 +4674,14 @@ void asCCompiler::CompileSwitchStatement(asCScriptNode *snode, bool *hasReturn, // We can join numbers that are less than 5 numbers // apart since the output code will still be smaller // Do this comparison using int64 so we don't get errors with large 32bit numbers - if( asINT64(caseValues[n]) > asINT64(caseValues[n-1]) + 5 ) + if( asINT64(caseValues[n]) > asINT64(caseValues[n - 1]) + 5 ) ranges.PushLast(n); } // If the value is larger than the largest case value, jump to default // TODO: optimize: If the largest value is already the max value of int32, i.e. 2147483647, then there is no need to do this check int tmpOffset = AllocateVariable(asCDataType::CreatePrimitive(ttInt, false), true); - expr.bc.InstrSHORT_DW(asBC_SetV4, (short)tmpOffset, caseValues[caseValues.GetLength()-1]); + expr.bc.InstrSHORT_DW(asBC_SetV4, (short)tmpOffset, caseValues[caseValues.GetLength() - 1]); expr.bc.InstrW_W(asBC_CMPi, offset, tmpOffset); expr.bc.InstrDWORD(asBC_JP, defaultLabel); ReleaseTemporaryVariable(tmpOffset, &expr.bc); @@ -4687,7 +4695,7 @@ void asCCompiler::CompileSwitchStatement(asCScriptNode *snode, bool *hasReturn, { // Find the largest value in this range int maxRange = caseValues[ranges[range]]; - int index = ranges[range]+1; + int index = ranges[range] + 1; for( ; (index < (int)caseValues.GetLength()) && (asINT64(caseValues[index]) <= asINT64(maxRange) + 5); index++ ) maxRange = caseValues[index]; @@ -4722,13 +4730,13 @@ void asCCompiler::CompileSwitchStatement(asCScriptNode *snode, bool *hasReturn, // Add the list of jumps to the correct labels (any holes, jump to default) index = ranges[range]; - for( int i = caseValues[index]; ; i++ ) + for( int i = caseValues[index];; i++ ) { if( caseValues[index] == i ) expr.bc.InstrINT(asBC_JMP, caseLabels[index++]); else expr.bc.InstrINT(asBC_JMP, defaultLabel); - if (i == maxRange) break; + if( i == maxRange ) break; } expr.bc.Label((short)nextRangeLabel); @@ -4757,7 +4765,7 @@ void asCCompiler::CompileSwitchStatement(asCScriptNode *snode, bool *hasReturn, expr.bc.OptimizeLocally(tempVariableOffsets); //---------------------------------- - // Output case implementations + // Output case implementations //---------------------------------- // Switch cases must be able to report if all paths have return too @@ -4779,7 +4787,7 @@ void asCCompiler::CompileSwitchStatement(asCScriptNode *snode, bool *hasReturn, CompileCase(cnode->firstChild->next, &expr.bc, &caseHasReturn, &caseHasBreak); // If the case does not return and have a break, then we know the switch doesn't return in all paths - if (!caseHasReturn && caseHasBreak) + if( !caseHasReturn && caseHasBreak ) *hasReturn = false; } else @@ -4797,7 +4805,7 @@ void asCCompiler::CompileSwitchStatement(asCScriptNode *snode, bool *hasReturn, CompileCase(cnode->firstChild, &expr.bc, &caseHasReturn, &caseHasBreak); // If the default case does not return then we know the switch doesn't return in all paths - if (!caseHasReturn) + if( !caseHasReturn ) *hasReturn = false; } @@ -4805,7 +4813,7 @@ void asCCompiler::CompileSwitchStatement(asCScriptNode *snode, bool *hasReturn, } // If there is no default case, then the switch cannot be said to return in all paths - if (defaultLabel == breakLabel) + if( defaultLabel == breakLabel ) *hasReturn = false; //-------------------------------- @@ -4821,8 +4829,8 @@ void asCCompiler::CompileSwitchStatement(asCScriptNode *snode, bool *hasReturn, void asCCompiler::CompileCase(asCScriptNode *node, asCByteCode *bc, bool *hasReturn, bool *hasBreak) { - *hasBreak = false; - *hasReturn = false; + *hasBreak = false; + *hasReturn = false; bool hasUnreachableCode = false; while( node ) { @@ -4861,10 +4869,10 @@ void asCCompiler::CompileTryCatch(asCScriptNode *node, bool *hasReturn, asCByteC { // We will use one label before and another after the catch statement int beforeCatchLabel = nextLabel++; - int afterCatchLabel = nextLabel++; + int afterCatchLabel = nextLabel++; // Compile the try block - bool hasReturnTry; + bool hasReturnTry; asCByteCode tryBC(engine); CompileStatement(node->firstChild, &hasReturnTry, &tryBC); @@ -4879,7 +4887,7 @@ void asCCompiler::CompileTryCatch(asCScriptNode *node, bool *hasReturn, asCByteC bc->InstrINT(asBC_JMP, afterCatchLabel); // Compile the catch block - bool hasReturnCatch; + bool hasReturnCatch; asCByteCode catchBC(engine); CompileStatement(node->firstChild->next, &hasReturnCatch, &catchBC); @@ -4907,20 +4915,20 @@ void asCCompiler::CompileIfStatement(asCScriptNode *inode, bool *hasReturn, asCB // Compile the expression asCExprContext expr(engine); - int r = CompileAssignment(inode->firstChild, &expr); + int r = CompileAssignment(inode->firstChild, &expr); if( r == 0 ) { - if (ProcessPropertyGetAccessor(&expr, inode) < 0) + if( ProcessPropertyGetAccessor(&expr, inode) < 0 ) return; // If turned on, allow the compiler to use either 'bool opImplConv()' or 'bool opConv()' on the type - if (engine->ep.boolConversionMode == 1) + if( engine->ep.boolConversionMode == 1 ) ImplicitConversion(&expr, asCDataType::CreatePrimitive(ttBool, false), inode, asIC_EXPLICIT_VAL_CAST); // else, allow value types to be converted to bool using 'bool opImplConv()' - else if (expr.type.dataType.GetTypeInfo() && (expr.type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE)) + else if( expr.type.dataType.GetTypeInfo() && (expr.type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE) ) ImplicitConversion(&expr, asCDataType::CreatePrimitive(ttBool, false), inode, asIC_IMPLICIT_CONV); - if (!expr.type.dataType.IsEqualExceptRefAndConst(asCDataType::CreatePrimitive(ttBool, true))) + if( !expr.type.dataType.IsEqualExceptRefAndConst(asCDataType::CreatePrimitive(ttBool, true)) ) { asCString str; str.Format(TXT_EXPR_MUST_BE_BOOL_s, expr.type.dataType.Format(outFunc->nameSpace).AddressOf()); @@ -4942,11 +4950,11 @@ void asCCompiler::CompileIfStatement(asCScriptNode *inode, bool *hasReturn, asCB expr.bc.OptimizeLocally(tempVariableOffsets); bc->AddCode(&expr.bc); } -#if AS_SIZEOF_BOOL == 1 + #if AS_SIZEOF_BOOL == 1 else if( expr.type.GetConstantB() == 0 ) -#else - else if (expr.type.GetConstantDW() == 0) -#endif + #else + else if( expr.type.GetConstantDW() == 0 ) + #endif { // Jump to the else case bc->InstrINT(asBC_JMP, afterLabel); @@ -4958,12 +4966,12 @@ void asCCompiler::CompileIfStatement(asCScriptNode *inode, bool *hasReturn, asCB // Compile the if statement // Backup the call to super() and member initializations - bool origIsConstructorCalled = m_isConstructorCalled; - asCArray origInitializedProperties = m_initializedProperties; - asCMap origPropertyAccessCount = m_propertyAccessCount; - bool origHasReturned = m_hasReturned; + bool origIsConstructorCalled = m_isConstructorCalled; + asCArray origInitializedProperties = m_initializedProperties; + asCMap origPropertyAccessCount = m_propertyAccessCount; + bool origHasReturned = m_hasReturned; - bool hasReturn1; + bool hasReturn1; asCByteCode ifBC(engine); CompileStatement(inode->firstChild->next, &hasReturn1, &ifBC); @@ -4983,19 +4991,19 @@ void asCCompiler::CompileIfStatement(asCScriptNode *inode, bool *hasReturn, asCB bool constructorCall2 = false; if( !origIsConstructorCalled && m_isConstructorCalled ) constructorCall1 = true; - asCArray initializedProperties1 = m_initializedProperties; - asCArray initializedProperties2 = origInitializedProperties; - asCMap propertyAccessCount1 = m_propertyAccessCount; - asCMap propertyAccessCount2 = origPropertyAccessCount; + asCArray initializedProperties1 = m_initializedProperties; + asCArray initializedProperties2 = origInitializedProperties; + asCMap propertyAccessCount1 = m_propertyAccessCount; + asCMap propertyAccessCount2 = origPropertyAccessCount; // Do we have an else statement? if( inode->firstChild->next != inode->lastChild ) { // Reset the constructor called flag and initialized properties so the else statement can also implement these - m_isConstructorCalled = origIsConstructorCalled; + m_isConstructorCalled = origIsConstructorCalled; m_initializedProperties = origInitializedProperties; - m_hasReturned = origHasReturned; - m_propertyAccessCount = origPropertyAccessCount; + m_hasReturned = origHasReturned; + m_propertyAccessCount = origPropertyAccessCount; int afterElse = 0; if( !hasReturn1 ) @@ -5009,7 +5017,7 @@ void asCCompiler::CompileIfStatement(asCScriptNode *inode, bool *hasReturn, asCB // Add label for the else statement bc->Label((short)afterLabel); - bool hasReturn2; + bool hasReturn2; asCByteCode elseBC(engine); CompileStatement(inode->lastChild, &hasReturn2, &elseBC); @@ -5046,7 +5054,7 @@ void asCCompiler::CompileIfStatement(asCScriptNode *inode, bool *hasReturn, asCB // Make sure both or neither conditions call a constructor if( (constructorCall1 && !constructorCall2) || - (constructorCall2 && !constructorCall1) ) + (constructorCall2 && !constructorCall1) ) { Error(TXT_BOTH_CONDITIONS_MUST_CALL_CONSTRUCTOR, inode); } @@ -5054,21 +5062,21 @@ void asCCompiler::CompileIfStatement(asCScriptNode *inode, bool *hasReturn, asCB m_isConstructorCalled = origIsConstructorCalled || constructorCall1 || constructorCall2; // Make sure both paths initialize the same members (if any) - if ( m_isConstructor && initializedProperties1 != initializedProperties2) + if( m_isConstructor && initializedProperties1 != initializedProperties2 ) { // Report errors for each of the members initialized wrongly - for (asUINT n = origInitializedProperties.GetLength(); n < initializedProperties1.GetLength(); n++) + for( asUINT n = origInitializedProperties.GetLength(); n < initializedProperties1.GetLength(); n++ ) { - if (!initializedProperties2.Exists(initializedProperties1[n])) + if( !initializedProperties2.Exists(initializedProperties1[n]) ) { asCString str; str.Format(TXT_BOTH_CONDITIONS_MUST_INIT_MEMBER_s, initializedProperties1[n]->name.AddressOf()); Error(str, inode); } } - for (asUINT n = origInitializedProperties.GetLength(); n < initializedProperties2.GetLength(); n++) + for( asUINT n = origInitializedProperties.GetLength(); n < initializedProperties2.GetLength(); n++ ) { - if (!initializedProperties1.Exists(initializedProperties2[n])) + if( !initializedProperties1.Exists(initializedProperties2[n]) ) { asCString str; str.Format(TXT_BOTH_CONDITIONS_MUST_INIT_MEMBER_s, initializedProperties2[n]->name.AddressOf()); @@ -5077,35 +5085,35 @@ void asCCompiler::CompileIfStatement(asCScriptNode *inode, bool *hasReturn, asCB } // Use the max property access count so a member accessed in only one of the conditions will be considered as well - asSMapNode* node = 0; - if (propertyAccessCount1.MoveFirst(&node)) + asSMapNode *node = 0; + if( propertyAccessCount1.MoveFirst(&node) ) { - asSMapNode* node2; - if (m_propertyAccessCount.MoveTo(&node2, node->key)) + asSMapNode *node2; + if( m_propertyAccessCount.MoveTo(&node2, node->key) ) node2->value = node2->value > node->value ? node2->value : node->value; else m_propertyAccessCount.Insert(node->key, node->value); - - while (propertyAccessCount1.MoveNext(&node, node)) + + while( propertyAccessCount1.MoveNext(&node, node) ) { - if (m_propertyAccessCount.MoveTo(&node2, node->key)) + if( m_propertyAccessCount.MoveTo(&node2, node->key) ) node2->value = node2->value > node->value ? node2->value : node->value; else m_propertyAccessCount.Insert(node->key, node->value); } } - if (propertyAccessCount2.MoveFirst(&node)) + if( propertyAccessCount2.MoveFirst(&node) ) { - asSMapNode* node2; - if (m_propertyAccessCount.MoveTo(&node2, node->key)) + asSMapNode *node2; + if( m_propertyAccessCount.MoveTo(&node2, node->key) ) node2->value = node2->value > node->value ? node2->value : node->value; else m_propertyAccessCount.Insert(node->key, node->value); - while (propertyAccessCount2.MoveNext(&node, node)) + while( propertyAccessCount2.MoveNext(&node, node) ) { - if (m_propertyAccessCount.MoveTo(&node2, node->key)) + if( m_propertyAccessCount.MoveTo(&node2, node->key) ) node2->value = node2->value > node->value ? node2->value : node->value; else m_propertyAccessCount.Insert(node->key, node->value); @@ -5122,9 +5130,9 @@ void asCCompiler::CompileForStatement(asCScriptNode *fnode, asCByteCode *bc) // We will use three labels for the for loop int conditionLabel = nextLabel++; - int afterLabel = nextLabel++; - int continueLabel = nextLabel++; - int insideLabel = nextLabel++; + int afterLabel = nextLabel++; + int continueLabel = nextLabel++; + int insideLabel = nextLabel++; continueLabels.PushLast(continueLabel); breakLabels.PushLast(afterLabel); @@ -5147,17 +5155,17 @@ void asCCompiler::CompileForStatement(asCScriptNode *fnode, asCByteCode *bc) int r = CompileAssignment(second->firstChild, &expr); if( r >= 0 ) { - if (ProcessPropertyGetAccessor(&expr, second) < 0) + if( ProcessPropertyGetAccessor(&expr, second) < 0 ) return; // If turned on, allow the compiler to use either 'bool opImplConv()' or 'bool opConv()' on the type - if (engine->ep.boolConversionMode == 1) + if( engine->ep.boolConversionMode == 1 ) ImplicitConversion(&expr, asCDataType::CreatePrimitive(ttBool, false), second->firstChild, asIC_EXPLICIT_VAL_CAST); // else, allow value types to be converted to bool using 'bool opImplConv()' - else if (expr.type.dataType.GetTypeInfo() && (expr.type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE)) + else if( expr.type.dataType.GetTypeInfo() && (expr.type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE) ) ImplicitConversion(&expr, asCDataType::CreatePrimitive(ttBool, false), second->firstChild, asIC_IMPLICIT_CONV); - if (!expr.type.dataType.IsEqualExceptRefAndConst(asCDataType::CreatePrimitive(ttBool, true))) + if( !expr.type.dataType.IsEqualExceptRefAndConst(asCDataType::CreatePrimitive(ttBool, true)) ) { asCString str; str.Format(TXT_EXPR_MUST_BE_BOOL_s, expr.type.dataType.Format(outFunc->nameSpace).AddressOf()); @@ -5187,7 +5195,7 @@ void asCCompiler::CompileForStatement(asCScriptNode *fnode, asCByteCode *bc) //--------------------------- // Compile the increment statement(s) - asCByteCode nextBC(engine); + asCByteCode nextBC(engine); asCScriptNode *cnode = second->next; while( cnode && cnode->nodeType == snExpressionStatement && cnode != fnode->lastChild ) { @@ -5198,7 +5206,7 @@ void asCCompiler::CompileForStatement(asCScriptNode *fnode, asCByteCode *bc) //------------------------------ // Compile loop statement - bool hasReturn; + bool hasReturn; asCByteCode forBC(engine); CompileStatement(fnode->lastChild, &hasReturn, &forBC); @@ -5249,9 +5257,9 @@ void asCCompiler::CompileForStatement(asCScriptNode *fnode, asCByteCode *bc) bc->Block(false); } -int asCCompiler::DeclareVariable(const asCString& name, const asCDataType& type, int offset, asCByteCode* bc, asCScriptNode *node) +int asCCompiler::DeclareVariable(const asCString &name, const asCDataType &type, int offset, asCByteCode *bc, asCScriptNode *node) { - if (variables->DeclareVariable(name.AddressOf(), type, offset, IsVariableOnHeap(offset)) < 0) + if( variables->DeclareVariable(name.AddressOf(), type, offset, IsVariableOnHeap(offset)) < 0 ) { // TODO: It might be an out-of-memory too @@ -5266,7 +5274,7 @@ int asCCompiler::DeclareVariable(const asCString& name, const asCDataType& type, else { // Warn if this variable hides another variable in a higher scope - if (name != "" && variables->parent && variables->parent->GetVariable(name.AddressOf())) + if( name != "" && variables->parent && variables->parent->GetVariable(name.AddressOf()) ) { asCString str; str.Format(TXT_s_HIDES_VAR_IN_OUTER_SCOPE, name.AddressOf()); @@ -5281,19 +5289,19 @@ int asCCompiler::DeclareVariable(const asCString& name, const asCDataType& type, return 0; } -void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) +void asCCompiler::CompileForEachStatement(asCScriptNode *node, asCByteCode *bc) { - const char* const BEGIN_NAME = "opForBegin"; - const char* const END_NAME = "opForEnd"; - const char* const NEXT_NAME = "opForNext"; - const char* const VALUE_NAME = "opForValue"; + const char * const BEGIN_NAME = "opForBegin"; + const char * const END_NAME = "opForEnd"; + const char * const NEXT_NAME = "opForNext"; + const char * const VALUE_NAME = "opForValue"; - asCArray itemDataTypes; - asCArray itemNodes; // Item identifiers - asUINT itemCount = 0; + asCArray itemDataTypes; + asCArray itemNodes; // Item identifiers + asUINT itemCount = 0; - asCScriptNode* rangeNode = node->firstChild; - while (rangeNode->nodeType != snAssignment) + asCScriptNode *rangeNode = node->firstChild; + while( rangeNode->nodeType != snAssignment ) { ++itemCount; @@ -5312,12 +5320,12 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) //--------------------------------------- // Compile the range expression and store in a local variable asCExprContext rangeExpr(engine); - if (CompileAssignment(rangeNode, &rangeExpr) < 0) + if( CompileAssignment(rangeNode, &rangeExpr) < 0 ) return; bool isConstRange = rangeExpr.type.dataType.IsReadOnly() || rangeExpr.type.dataType.IsHandleToConst(); - asCTypeInfo* rangeTypeInfo = rangeExpr.type.dataType.GetTypeInfo(); - if (!rangeTypeInfo) + asCTypeInfo *rangeTypeInfo = rangeExpr.type.dataType.GetTypeInfo(); + if( !rangeTypeInfo ) { asCString str; str.Format(TXT_s_NOT_A_FOREACH_TYPE, rangeExpr.type.dataType.Format(outFunc->nameSpace).AddressOf()); @@ -5331,9 +5339,9 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) asCDataType rangeDt = rangeExpr.type.dataType; rangeDt.MakeReference(false); - if (rangeDt.SupportHandles()) rangeDt.MakeHandle(true); + if( rangeDt.SupportHandles() ) rangeDt.MakeHandle(true); int rangeOffset = AllocateVariable(rangeDt, false); - if (DeclareVariable("", rangeDt, rangeOffset, &rangeExpr.bc, node) < 0) + if( DeclareVariable("", rangeDt, rangeOffset, &rangeExpr.bc, node) < 0 ) return; CompileInitializationWithAssignment(&rangeExpr.bc, rangeDt, rangeNode, rangeOffset, 0, asVGM_VARIABLE, rangeNode, &rangeExpr); @@ -5343,7 +5351,7 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) //--------------------------------------- // Check for required operators // Method ids - int opForBeginId = 0, opForEndId = 0, opForNextId = 0; + int opForBeginId = 0, opForEndId = 0, opForNextId = 0; asCArray opForValueNIds; // For multiple items // TypeId of the iterator type @@ -5353,15 +5361,15 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) asCArray funcs; builder->GetObjectMethodDescriptions(BEGIN_NAME, CastToObjectType(rangeTypeInfo), funcs, isConstRange); - for (asUINT i = 0; i < funcs.GetLength(); i++) + for( asUINT i = 0; i < funcs.GetLength(); i++ ) { - asIScriptFunction* f = engine->scriptFunctions[funcs[i]]; - if (f->GetParamCount() == 0) + asIScriptFunction *f = engine->scriptFunctions[funcs[i]]; + if( f->GetParamCount() == 0 ) { - if (opForBeginId != 0 && !isConstRange) + if( opForBeginId != 0 && !isConstRange ) { // Is the new function a better match? - if (!f->IsReadOnly()) + if( !f->IsReadOnly() ) opForBeginId = funcs[i]; } else @@ -5369,26 +5377,26 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) } } - if (opForBeginId) + if( opForBeginId ) iterTid = engine->scriptFunctions[opForBeginId]->GetReturnTypeId(); } - if (iterTid) + if( iterTid ) { asCArray funcs; builder->GetObjectMethodDescriptions(END_NAME, CastToObjectType(rangeTypeInfo), funcs, isConstRange); - for (asUINT i = 0; i < funcs.GetLength(); i++) + for( asUINT i = 0; i < funcs.GetLength(); i++ ) { - asIScriptFunction* f = engine->scriptFunctions[funcs[i]]; - asDWORD flags; - int paramTid; - if (f->GetParamCount() == 1 && f->GetReturnTypeId(&flags) == asTYPEID_BOOL && !(flags & asTM_INOUTREF) && f->GetParam(0, ¶mTid) >= 0 && paramTid == iterTid) + asIScriptFunction *f = engine->scriptFunctions[funcs[i]]; + asDWORD flags; + int paramTid; + if( f->GetParamCount() == 1 && f->GetReturnTypeId(&flags) == asTYPEID_BOOL && !(flags & asTM_INOUTREF) && f->GetParam(0, ¶mTid) >= 0 && paramTid == iterTid ) { - if (opForEndId != 0 && !isConstRange) + if( opForEndId != 0 && !isConstRange ) { // Is the new function a better match? - if (!f->IsReadOnly()) + if( !f->IsReadOnly() ) opForEndId = funcs[i]; } else @@ -5397,21 +5405,21 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) } } - if (iterTid) + if( iterTid ) { asCArray funcs; builder->GetObjectMethodDescriptions(NEXT_NAME, CastToObjectType(rangeTypeInfo), funcs, isConstRange); - for (asUINT i = 0; i < funcs.GetLength(); i++) + for( asUINT i = 0; i < funcs.GetLength(); i++ ) { - asIScriptFunction* f = engine->scriptFunctions[funcs[i]]; - int paramTid; - if (f->GetParamCount() == 1 && f->GetReturnTypeId() == iterTid && f->GetParam(0, ¶mTid) >= 0 && paramTid == iterTid) + asIScriptFunction *f = engine->scriptFunctions[funcs[i]]; + int paramTid; + if( f->GetParamCount() == 1 && f->GetReturnTypeId() == iterTid && f->GetParam(0, ¶mTid) >= 0 && paramTid == iterTid ) { - if (opForNextId != 0 && !isConstRange) + if( opForNextId != 0 && !isConstRange ) { // Is the new function a better match? - if (!f->IsReadOnly()) + if( !f->IsReadOnly() ) opForNextId = funcs[i]; } else @@ -5420,12 +5428,12 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) } } - if (iterTid) + if( iterTid ) { // Find the methods and types for each value - if (itemCount > 1 || opForValueNIds.GetLength() == 0) + if( itemCount > 1 || opForValueNIds.GetLength() == 0 ) { - for (asUINT i = 0; i < itemCount; ++i) + for( asUINT i = 0; i < itemCount; ++i ) { int opForValueIdN = 0; @@ -5434,24 +5442,24 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) // Special case for only one item // try the opForValue without an index suffix at first asCString methodName; - if (itemCount == 1) + if( itemCount == 1 ) builder->GetObjectMethodDescriptions(VALUE_NAME, CastToObjectType(rangeTypeInfo), funcs, isConstRange); - if (funcs.GetLength() == 0) + if( funcs.GetLength() == 0 ) { methodName.Format("%s%d", VALUE_NAME, (int)i); builder->GetObjectMethodDescriptions(methodName.AddressOf(), CastToObjectType(rangeTypeInfo), funcs, isConstRange); } - for (asUINT j = 0; j < funcs.GetLength(); j++) + for( asUINT j = 0; j < funcs.GetLength(); j++ ) { - asIScriptFunction* f = engine->scriptFunctions[funcs[j]]; - int paramTid; - if (f->GetParamCount() == 1 && f->GetParam(0, ¶mTid) >= 0 && paramTid == iterTid) + asIScriptFunction *f = engine->scriptFunctions[funcs[j]]; + int paramTid; + if( f->GetParamCount() == 1 && f->GetParam(0, ¶mTid) >= 0 && paramTid == iterTid ) { - if (opForValueIdN != 0 && !isConstRange) + if( opForValueIdN != 0 && !isConstRange ) { // Is the new function a better match? - if (!f->IsReadOnly()) + if( !f->IsReadOnly() ) opForValueIdN = funcs[j]; } else @@ -5459,19 +5467,19 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) } } - if (opForValueIdN == 0) + if( opForValueIdN == 0 ) break; else opForValueNIds.PushLast(opForValueIdN); // Resolve auto using return type of opForValueN - if (itemDataTypes[i].IsAuto()) + if( itemDataTypes[i].IsAuto() ) { asDWORD retFlags; - int retTid = engine->scriptFunctions[opForValueIdN]->GetReturnTypeId(&retFlags); + int retTid = engine->scriptFunctions[opForValueIdN]->GetReturnTypeId(&retFlags); - bool isConst = itemDataTypes[i].IsReadOnly() || (retFlags & asTM_CONST); - asCDataType dt = asCDataType::CreateById(engine, retTid, isConst); + bool isConst = itemDataTypes[i].IsReadOnly() || (retFlags & asTM_CONST); + asCDataType dt = asCDataType::CreateById(engine, retTid, isConst); dt.MakeHandle(true); // Always use handle for auto if possible itemDataTypes[i] = dt; } @@ -5480,13 +5488,13 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) } // Give a clear error message about which part not satisfies the requirement - if (!(opForBeginId && opForEndId && opForNextId && opForValueNIds.GetLength() == itemCount)) + if( !(opForBeginId && opForEndId && opForNextId && opForValueNIds.GetLength() == itemCount) ) { asCString str; str.Format(TXT_s_NOT_A_FOREACH_TYPE, rangeExpr.type.dataType.Format(outFunc->nameSpace).AddressOf()); Error(str, node->lastChild); - if (!opForBeginId) + if( !opForBeginId ) { str.Format(TXT_MISSING_OR_INVALID_DEFINITON_OF_s, BEGIN_NAME); Information(str, node->lastChild); @@ -5494,17 +5502,17 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) else { // Only report the other methods if opForBegin is valid, otherwise the error might be misleading - if (!opForEndId) + if( !opForEndId ) { str.Format(TXT_MISSING_OR_INVALID_DEFINITON_OF_s, END_NAME); Information(str, node->lastChild); } - if (!opForNextId) + if( !opForNextId ) { str.Format(TXT_MISSING_OR_INVALID_DEFINITON_OF_s, NEXT_NAME); Information(str, node->lastChild); } - if (opForValueNIds.GetLength() != itemCount) + if( opForValueNIds.GetLength() != itemCount ) { str.Format(TXT_MISSING_OR_INVALID_DEFINITON_OF_s, (asCString(VALUE_NAME) + "#").AddressOf()); Information(str, node->lastChild); @@ -5518,9 +5526,9 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) // We will use three labels for the for loop int conditionLabel = nextLabel++; - int afterLabel = nextLabel++; - int continueLabel = nextLabel++; - int insideLabel = nextLabel++; + int afterLabel = nextLabel++; + int continueLabel = nextLabel++; + int insideLabel = nextLabel++; continueLabels.PushLast(continueLabel); breakLabels.PushLast(afterLabel); @@ -5529,29 +5537,27 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) // Compile the initialization statement asCByteCode initBC(engine); LineInstr(&initBC, node->firstChild->tokenPos); - asCDataType iterDt = asCDataType::CreateById(engine, iterTid, false); - int iterOffset = AllocateVariable(iterDt, false); - if (DeclareVariable("", iterDt, iterOffset, &initBC, node) < 0) + asCDataType iterDt = asCDataType::CreateById(engine, iterTid, false); + int iterOffset = AllocateVariable(iterDt, false); + if( DeclareVariable("", iterDt, iterOffset, &initBC, node) < 0 ) return; asCExprContext opForBeginExpr(engine); { opForBeginExpr.bc.InstrSHORT(asBC_PshVPtr, short(rangeOffset)); - asCArray args; - int r = MakeFunctionCall( - &opForBeginExpr, - opForBeginId, - CastToObjectType(rangeExpr.type.dataType.GetTypeInfo()), - args, - node->firstChild - ); + asCArray args; + int r = MakeFunctionCall( + &opForBeginExpr, + opForBeginId, + CastToObjectType(rangeExpr.type.dataType.GetTypeInfo()), + args, + node->firstChild); UNUSED_VAR(r); asASSERT(r >= 0); } CompileInitializationWithAssignment( - &initBC, iterDt, node->firstChild, iterOffset, NULL, asVGM_VARIABLE, rangeNode, &opForBeginExpr - ); + &initBC, iterDt, node->firstChild, iterOffset, NULL, asVGM_VARIABLE, rangeNode, &opForBeginExpr); initBC.OptimizeLocally(tempVariableOffsets); //----------------------------------- @@ -5560,25 +5566,24 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) { opForEndExpr.bc.InstrSHORT(asBC_PshVPtr, short(rangeOffset)); - asCArray args; - asCExprContext arg(engine); + asCArray args; + asCExprContext arg(engine); arg.type.SetVariable(iterDt, iterOffset, false); - if (!iterDt.IsPrimitive()) + if( !iterDt.IsPrimitive() ) { arg.bc.InstrSHORT(asBC_PSF, (short)iterOffset); if( iterDt.IsObjectHandle() ) arg.type.dataType.MakeReference(true); } arg.type.isLValue = true; - arg.exprNode = node; + arg.exprNode = node; args.PushLast(&arg); int r = MakeFunctionCall( - &opForEndExpr, - opForEndId, - CastToObjectType(rangeExpr.type.dataType.GetTypeInfo()), - args, - node - ); + &opForEndExpr, + opForEndId, + CastToObjectType(rangeExpr.type.dataType.GetTypeInfo()), + args, + node); UNUSED_VAR(r); asASSERT(r >= 0); @@ -5607,54 +5612,52 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) asCExprContext opForNextExpr(engine); opForNextExpr.bc.InstrSHORT(asBC_PshVPtr, short(rangeOffset)); - asCArray args; - asCExprContext arg(engine); + asCArray args; + asCExprContext arg(engine); arg.type.SetVariable(iterDt, iterOffset, false); - if (!iterDt.IsPrimitive()) + if( !iterDt.IsPrimitive() ) { arg.bc.InstrSHORT(asBC_PSF, (short)iterOffset); - if (iterDt.IsObjectHandle()) arg.type.dataType.MakeReference(true); + if( iterDt.IsObjectHandle() ) arg.type.dataType.MakeReference(true); } arg.type.isLValue = true; - arg.exprNode = node; + arg.exprNode = node; args.PushLast(&arg); int r = MakeFunctionCall( - &opForNextExpr, - opForNextId, - CastToObjectType(rangeExpr.type.dataType.GetTypeInfo()), - args, - node - ); + &opForNextExpr, + opForNextId, + CastToObjectType(rangeExpr.type.dataType.GetTypeInfo()), + args, + node); UNUSED_VAR(r); asASSERT(r >= 0); asCExprContext lhs(engine); lhs.type.SetVariable(iterDt, iterOffset, false); - if (!iterDt.IsPrimitive()) + if( !iterDt.IsPrimitive() ) { lhs.bc.InstrSHORT(asBC_PSF, (short)iterOffset); - if (iterDt.IsObjectHandle()) lhs.type.dataType.MakeReference(true); + if( iterDt.IsObjectHandle() ) lhs.type.dataType.MakeReference(true); } - if (iterDt.IsObjectHandle()) + if( iterDt.IsObjectHandle() ) lhs.type.isExplicitHandle = true; lhs.type.isLValue = true; - lhs.exprNode = node; + lhs.exprNode = node; DoAssignment( - &next, - &lhs, - &opForNextExpr, - node, - node, - ttAssignment, - node - ); + &next, + &lhs, + &opForNextExpr, + node, + node, + ttAssignment, + node); ProcessDeferredParams(&next); ReleaseTemporaryVariable(next.type, &next.bc); // Pop the value from the stack - if (!next.type.dataType.IsPrimitive()) + if( !next.type.dataType.IsPrimitive() ) next.bc.Instr(asBC_PopPtr); next.bc.OptimizeLocally(tempVariableOffsets); @@ -5662,20 +5665,20 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) //------------------------------ // Compile loop statement - bool hasReturn; + bool hasReturn; asCByteCode foreachBC(engine); asCArray itemOffsets; - for (asUINT i = 0; i < itemCount; ++i) + for( asUINT i = 0; i < itemCount; ++i ) { asCByteCode itemNBC(engine); - asCDataType& itemDt = itemDataTypes[i]; - asCScriptNode* itemNode = itemNodes[i]; + asCDataType &itemDt = itemDataTypes[i]; + asCScriptNode *itemNode = itemNodes[i]; - int itemOffset = AllocateVariable(itemDt, false); + int itemOffset = AllocateVariable(itemDt, false); asCString itemName(&script->code[itemNode->tokenPos], itemNode->tokenLength); - if (DeclareVariable(itemName, itemDt, itemOffset, &itemNBC, node) < 0) + if( DeclareVariable(itemName, itemDt, itemOffset, &itemNBC, node) < 0 ) return; itemOffsets.PushLast(itemOffset); @@ -5684,30 +5687,28 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) opForValueNExpr.bc.InstrSHORT(asBC_PshVPtr, short(rangeOffset)); - asCArray args; - asCExprContext arg(engine); + asCArray args; + asCExprContext arg(engine); arg.type.SetVariable(iterDt, iterOffset, false); - if (!iterDt.IsPrimitive()) + if( !iterDt.IsPrimitive() ) { arg.bc.InstrSHORT(asBC_PSF, (short)iterOffset); - if (iterDt.IsObjectHandle()) arg.type.dataType.MakeReference(true); + if( iterDt.IsObjectHandle() ) arg.type.dataType.MakeReference(true); } arg.type.isLValue = true; - arg.exprNode = node; + arg.exprNode = node; args.PushLast(&arg); int r = MakeFunctionCall( - &opForValueNExpr, - opForValueNIds[i], - CastToObjectType(rangeExpr.type.dataType.GetTypeInfo()), - args, - node->firstChild - ); + &opForValueNExpr, + opForValueNIds[i], + CastToObjectType(rangeExpr.type.dataType.GetTypeInfo()), + args, + node->firstChild); UNUSED_VAR(r); asASSERT(r >= 0); CompileInitializationWithAssignment( - &itemNBC, itemDt, itemNode->prev, itemOffset, NULL, asVGM_VARIABLE, rangeNode, &opForValueNExpr - ); + &itemNBC, itemDt, itemNode->prev, itemOffset, NULL, asVGM_VARIABLE, rangeNode, &opForValueNExpr); // Suppress the compiler warning of uninitialized variable variables->GetVariableByOffset(itemOffset)->isInitialized = true; @@ -5721,10 +5722,10 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) // Reversely destruct the items, // we'll re-initialize them in the next iteration - for (asUINT i = itemOffsets.GetLength(); i != 0; --i) + for( asUINT i = itemOffsets.GetLength(); i != 0; --i ) { - int itemOffset = itemOffsets[i - 1]; - asCDataType& itemDt = itemDataTypes[i - 1]; + int itemOffset = itemOffsets[i - 1]; + asCDataType &itemDt = itemDataTypes[i - 1]; CallDestructor(itemDt, itemOffset, IsVariableOnHeap(itemOffset), &foreachBC); // No need to deallocate here, @@ -5759,9 +5760,9 @@ void asCCompiler::CompileForEachStatement(asCScriptNode* node, asCByteCode* bc) breakLabels.PopLast(); // Deallocate variables in this block, in reverse order - for (int n = (int)variables->variables.GetLength() - 1; n >= 0; n--) + for( int n = (int)variables->variables.GetLength() - 1; n >= 0; n-- ) { - sVariable* v = variables->variables[n]; + sVariable *v = variables->variables[n]; // Call variable destructors here, for variables not yet destroyed // The items (values) were already destroyed as part of the loop statement, so don't destroy them again outside the loop @@ -5781,7 +5782,7 @@ void asCCompiler::CompileWhileStatement(asCScriptNode *wnode, asCByteCode *bc) // We will use two labels for the while loop int beforeLabel = nextLabel++; - int afterLabel = nextLabel++; + int afterLabel = nextLabel++; continueLabels.PushLast(beforeLabel); breakLabels.PushLast(afterLabel); @@ -5791,20 +5792,20 @@ void asCCompiler::CompileWhileStatement(asCScriptNode *wnode, asCByteCode *bc) // Compile expression asCExprContext expr(engine); - int r = CompileAssignment(wnode->firstChild, &expr); + int r = CompileAssignment(wnode->firstChild, &expr); if( r == 0 ) { - if (ProcessPropertyGetAccessor(&expr, wnode) < 0) + if( ProcessPropertyGetAccessor(&expr, wnode) < 0 ) return; // If turned on, allow the compiler to use either 'bool opImplConv()' or 'bool opConv()' on the type - if (engine->ep.boolConversionMode == 1) + if( engine->ep.boolConversionMode == 1 ) ImplicitConversion(&expr, asCDataType::CreatePrimitive(ttBool, false), wnode->firstChild, asIC_EXPLICIT_VAL_CAST); // else, allow value types to be converted to bool using 'bool opImplConv()' - else if (expr.type.dataType.GetTypeInfo() && (expr.type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE)) + else if( expr.type.dataType.GetTypeInfo() && (expr.type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE) ) ImplicitConversion(&expr, asCDataType::CreatePrimitive(ttBool, false), wnode->firstChild, asIC_IMPLICIT_CONV); - if (!expr.type.dataType.IsEqualExceptRefAndConst(asCDataType::CreatePrimitive(ttBool, true))) + if( !expr.type.dataType.IsEqualExceptRefAndConst(asCDataType::CreatePrimitive(ttBool, true)) ) { asCString str; str.Format(TXT_EXPR_MUST_BE_BOOL_s, expr.type.dataType.Format(outFunc->nameSpace).AddressOf()); @@ -5832,7 +5833,7 @@ void asCCompiler::CompileWhileStatement(asCScriptNode *wnode, asCByteCode *bc) bc->InstrPTR(asBC_JitEntry, 0); // Compile statement - bool hasReturn; + bool hasReturn; asCByteCode whileBC(engine); CompileStatement(wnode->lastChild, &hasReturn, &whileBC); @@ -5859,8 +5860,8 @@ void asCCompiler::CompileDoWhileStatement(asCScriptNode *wnode, asCByteCode *bc) // We will use two labels for the while loop int beforeLabel = nextLabel++; - int beforeTest = nextLabel++; - int afterLabel = nextLabel++; + int beforeTest = nextLabel++; + int afterLabel = nextLabel++; continueLabels.PushLast(beforeTest); breakLabels.PushLast(afterLabel); @@ -5869,7 +5870,7 @@ void asCCompiler::CompileDoWhileStatement(asCScriptNode *wnode, asCByteCode *bc) bc->Label((short)beforeLabel); // Compile statement - bool hasReturn; + bool hasReturn; asCByteCode whileBC(engine); CompileStatement(wnode->firstChild, &hasReturn, &whileBC); @@ -5892,17 +5893,17 @@ void asCCompiler::CompileDoWhileStatement(asCScriptNode *wnode, asCByteCode *bc) asCExprContext expr(engine); CompileAssignment(wnode->lastChild, &expr); - if (ProcessPropertyGetAccessor(&expr, wnode) < 0) + if( ProcessPropertyGetAccessor(&expr, wnode) < 0 ) return; // If turned on, allow the compiler to use either 'bool opImplConv()' or 'bool opConv()' on the type - if (engine->ep.boolConversionMode == 1) + if( engine->ep.boolConversionMode == 1 ) ImplicitConversion(&expr, asCDataType::CreatePrimitive(ttBool, false), wnode->lastChild, asIC_EXPLICIT_VAL_CAST); // else, allow value types to be converted to bool using 'bool opImplConv()' - else if (expr.type.dataType.GetTypeInfo() && (expr.type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE)) + else if( expr.type.dataType.GetTypeInfo() && (expr.type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE) ) ImplicitConversion(&expr, asCDataType::CreatePrimitive(ttBool, false), wnode->lastChild, asIC_IMPLICIT_CONV); - if (!expr.type.dataType.IsEqualExceptRefAndConst(asCDataType::CreatePrimitive(ttBool, true))) + if( !expr.type.dataType.IsEqualExceptRefAndConst(asCDataType::CreatePrimitive(ttBool, true)) ) { asCString str; str.Format(TXT_EXPR_MUST_BE_BOOL_s, expr.type.dataType.Format(outFunc->nameSpace).AddressOf()); @@ -5912,7 +5913,7 @@ void asCCompiler::CompileDoWhileStatement(asCScriptNode *wnode, asCByteCode *bc) { ConvertToVariable(&expr); ProcessDeferredParams(&expr); - + // Jump to next iteration if expression is true expr.bc.InstrSHORT(asBC_CpyVtoR4, (short)expr.type.stackOffset); expr.bc.Instr(asBC_ClrHi); @@ -5953,7 +5954,7 @@ void asCCompiler::CompileBreakStatement(asCScriptNode *node, asCByteCode *bc) } bc->Block(false); - bc->InstrINT(asBC_JMP, breakLabels[breakLabels.GetLength()-1]); + bc->InstrINT(asBC_JMP, breakLabels[breakLabels.GetLength() - 1]); } void asCCompiler::CompileContinueStatement(asCScriptNode *node, asCByteCode *bc) @@ -5977,7 +5978,7 @@ void asCCompiler::CompileContinueStatement(asCScriptNode *node, asCByteCode *bc) } bc->Block(false); - bc->InstrINT(asBC_JMP, continueLabels[continueLabels.GetLength()-1]); + bc->InstrINT(asBC_JMP, continueLabels[continueLabels.GetLength() - 1]); } void asCCompiler::CompileExpressionStatement(asCScriptNode *enode, asCByteCode *bc) @@ -6026,7 +6027,7 @@ void asCCompiler::PrepareTemporaryVariable(asCScriptNode *node, asCExprContext * // Note, a type can be temporary without being a variable, in which case it is holding off // on releasing a previously used object. if( ctx->type.isTemporary && ctx->type.isVariable && - !(forceOnHeap && !IsVariableOnHeap(ctx->type.stackOffset)) ) + !(forceOnHeap && !IsVariableOnHeap(ctx->type.stackOffset)) ) { // If the temporary object is currently not a reference // the expression needs to be reevaluated to a reference @@ -6041,17 +6042,17 @@ void asCCompiler::PrepareTemporaryVariable(asCScriptNode *node, asCExprContext * } // Allocate temporary variable - asCDataType dt = ctx->type.dataType; - bool isHandle = dt.IsObjectHandle(); - bool isReadOnly = dt.IsReadOnly(); + asCDataType dt = ctx->type.dataType; + bool isHandle = dt.IsObjectHandle(); + bool isReadOnly = dt.IsReadOnly(); // If the type supports handles, then we will always use a handle - if (!forceValueCopy) + if( !forceValueCopy ) { - if (!dt.IsObjectHandle() && dt.SupportHandles()) + if( !dt.IsObjectHandle() && dt.SupportHandles() ) dt.MakeHandle(true); } - + dt.MakeReference(false); dt.MakeReadOnly(false); @@ -6063,10 +6064,10 @@ void asCCompiler::PrepareTemporaryVariable(asCScriptNode *node, asCExprContext * asCExprValue lvalue; lvalue.Set(dt); lvalue.isExplicitHandle = ctx->type.isExplicitHandle; - bool isExplicitHandle = ctx->type.isExplicitHandle; + bool isExplicitHandle = ctx->type.isExplicitHandle; - bool prevIsTemp = ctx->type.isTemporary; - int prevStackOffset = ctx->type.stackOffset; + bool prevIsTemp = ctx->type.isTemporary; + int prevStackOffset = ctx->type.stackOffset; asCExprContext tmp(engine); CompileInitAsCopy(dt, offset, &tmp, ctx, node, false); @@ -6080,17 +6081,17 @@ void asCCompiler::PrepareTemporaryVariable(asCScriptNode *node, asCExprContext * ctx->bc.InstrSHORT(asBC_PSF, (short)offset); ctx->type.Set(dt); - ctx->type.isTemporary = true; - ctx->type.stackOffset = (short)offset; - ctx->type.isVariable = true; + ctx->type.isTemporary = true; + ctx->type.stackOffset = (short)offset; + ctx->type.isVariable = true; ctx->type.isExplicitHandle = isExplicitHandle; ctx->type.dataType.MakeReference(IsVariableOnHeap(offset) || dt.IsObjectHandle()); - if (!forceValueCopy) + if( !forceValueCopy ) { // If the original was not a handle, then the temporary variable should also not be a handle // In this case we don't need to check for null handle, since we original was already known not to be a null handle - if (!isHandle) + if( !isHandle ) ctx->type.dataType.MakeHandle(false); ctx->type.dataType.MakeReadOnly(isReadOnly); } @@ -6121,7 +6122,7 @@ void asCCompiler::CompileReturnStatement(asCScriptNode *rnode, asCByteCode *bc) { // Compile the expression asCExprContext expr(engine); - int r = CompileAssignment(rnode->firstChild, &expr); + int r = CompileAssignment(rnode->firstChild, &expr); if( r < 0 ) return; if( v->type.IsReference() ) @@ -6138,7 +6139,7 @@ void asCCompiler::CompileReturnStatement(asCScriptNode *rnode, asCByteCode *bc) // should be allowed to be returned. if( !(expr.type.dataType.IsReference() || - (expr.type.dataType.IsObject() && !expr.type.dataType.IsObjectHandle())) ) + (expr.type.dataType.IsObject() && !expr.type.dataType.IsObjectHandle())) ) { // Clean up the potential deferred parameters ProcessDeferredParams(&expr); @@ -6162,10 +6163,10 @@ void asCCompiler::CompileReturnStatement(asCScriptNode *rnode, asCByteCode *bc) // The type must match exactly as we cannot convert // the reference without loosing the original value if( !(v->type.IsEqualExceptConst(expr.type.dataType) || - ((expr.type.dataType.IsObject() || expr.type.dataType.IsFuncdef()) && - !expr.type.dataType.IsObjectHandle() && - v->type.IsEqualExceptRefAndConst(expr.type.dataType))) || - (!v->type.IsReadOnly() && expr.type.dataType.IsReadOnly()) ) + ((expr.type.dataType.IsObject() || expr.type.dataType.IsFuncdef()) && + !expr.type.dataType.IsObjectHandle() && + v->type.IsEqualExceptRefAndConst(expr.type.dataType))) || + (!v->type.IsReadOnly() && expr.type.dataType.IsReadOnly()) ) { // Clean up the potential deferred parameters ProcessDeferredParams(&expr); @@ -6227,7 +6228,7 @@ void asCCompiler::CompileReturnStatement(asCScriptNode *rnode, asCByteCode *bc) if( !expr.type.dataType.IsPrimitive() ) { if( !expr.type.dataType.IsObjectHandle() && - expr.type.dataType.IsReference() ) + expr.type.dataType.IsReference() ) expr.bc.Instr(asBC_RDSPtr); expr.bc.Instr(asBC_PopRPtr); @@ -6296,7 +6297,7 @@ void asCCompiler::CompileReturnStatement(asCScriptNode *rnode, asCByteCode *bc) } } - int offset = outFunc->objectType ? -AS_PTR_SIZE : 0; + int offset = outFunc->objectType ? -AS_PTR_SIZE : 0; asCExprContext tmp(engine); CompileInitAsCopy(v->type, offset, &tmp, &expr, rnode->firstChild, true); MergeExprBytecode(&expr, &tmp); @@ -6305,7 +6306,7 @@ void asCCompiler::CompileReturnStatement(asCScriptNode *rnode, asCByteCode *bc) DestroyVariables(&expr.bc); ProcessDeferredParams(&expr); - // If this return statement is within a branch, there might be more statements after this. To avoid having the exception + // If this return statement is within a branch, there might be more statements after this. To avoid having the exception // handler think the object is live in the statements between the return and the end of the function we need to add a marker expr.bc.ObjInfo(offset, asOBJ_UNINIT); } @@ -6384,8 +6385,8 @@ void asCCompiler::RemoveVariableScope() if( variables ) { asCVariableScope *var = variables; - variables = variables->parent; - asDELETE(var,asCVariableScope); + variables = variables->parent; + asDELETE(var, asCVariableScope); } } @@ -6424,7 +6425,7 @@ void asCCompiler::Information(const asCString &msg, asCScriptNode *node) builder->WriteInfo(script->name, msg, r, c, false); } -void asCCompiler::PrintMatchingFuncs(asCArray &funcs, asCScriptNode *node, asCObjectType *inType, asCArray* failedReasons) +void asCCompiler::PrintMatchingFuncs(asCArray &funcs, asCScriptNode *node, asCObjectType *inType, asCArray *failedReasons) { int r = 0, c = 0; asASSERT( node ); @@ -6438,15 +6439,15 @@ void asCCompiler::PrintMatchingFuncs(asCArray &funcs, asCScriptNode *node, builder->WriteInfo(script->name, func->GetDeclaration(true, true, true), r, c, false); - if (func->objectType && (func->objectType->flags & asOBJ_TEMPLATE)) + if( func->objectType && (func->objectType->flags & asOBJ_TEMPLATE) ) { // Check for funcdefs in the arguments that may have been generated by the template instance, so these can be shown to user - for (unsigned int p = 0; p < func->GetParamCount(); p++) + for( unsigned int p = 0; p < func->GetParamCount(); p++ ) { int typeId = 0; func->GetParam(p, &typeId); asITypeInfo *ti = engine->GetTypeInfoById(typeId); - if (ti && (ti->GetFlags() & asOBJ_FUNCDEF)) + if( ti && (ti->GetFlags() & asOBJ_FUNCDEF) ) { asCString msg; msg.Format(TXT_WHERE_s_IS_s, ti->GetName(), ti->GetFuncdefSignature()->GetDeclaration()); @@ -6456,39 +6457,39 @@ void asCCompiler::PrintMatchingFuncs(asCArray &funcs, asCScriptNode *node, } // check if a reason exists for this func - if (failedReasons) + if( failedReasons ) { - for (unsigned int f = 0; f < failedReasons->GetLength(); f++) + for( unsigned int f = 0; f < failedReasons->GetLength(); f++ ) { - if ((*failedReasons)[f].func == funcs[n]) + if( (*failedReasons)[f].func == funcs[n] ) { asCString msg; - switch ((*failedReasons)[f].reason) + switch( (*failedReasons)[f].reason ) { - case asEFM_NOT_ENOUGH_ARGS: - msg.Format(TXT_NOT_ENOUGH_ARGUMENTS); - break; - case asEFM_TOO_MANY_ARGS: - msg.Format(TXT_TOO_MANY_ARGUMENTS); - break; - case asEFM_POSITIONAL_MISMATCH: - if (func->parameterNames.GetLength() <= (*failedReasons)[f].arg || func->parameterNames[(*failedReasons)[f].arg].GetLength() == 0) - msg.Format(TXT_ARGUMENT_TYPE_ERROR_i, (*failedReasons)[f].arg + 1); // use one-indexed parameters, like other compilers (msvc, clang) - else - msg.Format(TXT_ARGUMENT_TYPE_ERROR_s, func->parameterNames[(*failedReasons)[f].arg].AddressOf()); - break; - case asEFM_NAMED_DUPLICATE: - msg.Format(TXT_DUPLICATE_NAMED_ARGUMENT_s, func->parameterNames[(*failedReasons)[f].arg].AddressOf()); - break; - case asEFM_NAMED_MISMATCH: - if ((*failedReasons)[f].argName) - msg.Format(TXT_ARGUMENT_TYPE_ERROR_s, (*failedReasons)[f].argName); - else - msg.Format(TXT_ARGUMENT_TYPE_ERROR_s, func->parameterNames[(*failedReasons)[f].arg].AddressOf()); - break; - case asEFM_NAMED_MISSING: - msg.Format(TXT_MISSING_ARGUMENT_s, (*failedReasons)[f].argName); - break; + case asEFM_NOT_ENOUGH_ARGS: + msg.Format(TXT_NOT_ENOUGH_ARGUMENTS); + break; + case asEFM_TOO_MANY_ARGS: + msg.Format(TXT_TOO_MANY_ARGUMENTS); + break; + case asEFM_POSITIONAL_MISMATCH: + if( func->parameterNames.GetLength() <= (*failedReasons)[f].arg || func->parameterNames[(*failedReasons)[f].arg].GetLength() == 0 ) + msg.Format(TXT_ARGUMENT_TYPE_ERROR_i, (*failedReasons)[f].arg + 1); // use one-indexed parameters, like other compilers (msvc, clang) + else + msg.Format(TXT_ARGUMENT_TYPE_ERROR_s, func->parameterNames[(*failedReasons)[f].arg].AddressOf()); + break; + case asEFM_NAMED_DUPLICATE: + msg.Format(TXT_DUPLICATE_NAMED_ARGUMENT_s, func->parameterNames[(*failedReasons)[f].arg].AddressOf()); + break; + case asEFM_NAMED_MISMATCH: + if( (*failedReasons)[f].argName ) + msg.Format(TXT_ARGUMENT_TYPE_ERROR_s, (*failedReasons)[f].argName); + else + msg.Format(TXT_ARGUMENT_TYPE_ERROR_s, func->parameterNames[(*failedReasons)[f].arg].AddressOf()); + break; + case asEFM_NAMED_MISSING: + msg.Format(TXT_MISSING_ARGUMENT_s, (*failedReasons)[f].argName); + break; } builder->WriteInfo(script->name, msg.AddressOf(), r, c, false); break; @@ -6523,7 +6524,7 @@ int asCCompiler::AllocateVariable(const asCDataType &type, bool isTemporary, boo bool isOnHeap = true; if( t.IsPrimitive() || - (t.GetTypeInfo() && (t.GetTypeInfo()->GetFlags() & asOBJ_VALUE) && !forceOnHeap && !asReference) ) + (t.GetTypeInfo() && (t.GetTypeInfo()->GetFlags() & asOBJ_VALUE) && !forceOnHeap && !asReference) ) { // Primitives and value types (unless overridden) are allocated on the stack isOnHeap = false; @@ -6535,8 +6536,8 @@ int asCCompiler::AllocateVariable(const asCDataType &type, bool isTemporary, boo int slot = freeVariables[n]; if( variableAllocations[slot].IsEqualExceptConst(t) && - variableIsTemporary[slot] == isTemporary && - variableIsOnHeap[slot] == isOnHeap ) + variableIsTemporary[slot] == isTemporary && + variableIsOnHeap[slot] == isOnHeap ) { // We can't return by slot, must count variable sizes int offset = GetVariableOffset(slot); @@ -6565,7 +6566,7 @@ int asCCompiler::AllocateVariable(const asCDataType &type, bool isTemporary, boo variableIsTemporary.PushLast(isTemporary); variableIsOnHeap.PushLast(isOnHeap); - int offset = GetVariableOffset((int)variableAllocations.GetLength()-1); + int offset = GetVariableOffset((int)variableAllocations.GetLength() - 1); if( isTemporary ) { @@ -6604,7 +6605,7 @@ int asCCompiler::GetVariableOffset(int varIndex) else size = variableAllocations[varIndex].GetSizeOnStackDWords(); if( size > 1 ) - varOffset += size-1; + varOffset += size - 1; } return varOffset; @@ -6650,7 +6651,7 @@ void asCCompiler::DeallocateVariable(int offset) { if( offset == tempVariables[n] ) { - if( n == (int)tempVariables.GetLength()-1 ) + if( n == (int)tempVariables.GetLength() - 1 ) tempVariables.PopLast(); else tempVariables[n] = tempVariables.PopLast(); @@ -6694,8 +6695,8 @@ void asCCompiler::ReleaseTemporaryVariable(int offset, asCByteCode *bc) asASSERT( n >= 0 ); if( n >= 0 ) { - asCDataType dt = variableAllocations[n]; - bool isOnHeap = variableIsOnHeap[n]; + asCDataType dt = variableAllocations[n]; + bool isOnHeap = variableIsOnHeap[n]; // Call destructor CallDestructor(dt, offset, isOnHeap, bc); @@ -6779,7 +6780,7 @@ void asCCompiler::PrepareForAssignment(asCDataType *lvalue, asCExprContext *rctx return; // Don't allow any operators on void expressions - if (rctx->type.IsVoid()) + if( rctx->type.IsVoid() ) { asCString str; str.Format(TXT_DATA_TYPE_CANT_BE_s, "void"); @@ -6809,7 +6810,7 @@ void asCCompiler::PrepareForAssignment(asCDataType *lvalue, asCExprContext *rctx if( !lvalue->IsEqualExceptRefAndConst(rctx->type.dataType) ) { asCString str; - if (rctx->IsLambda()) + if( rctx->IsLambda() ) str.Format(TXT_CANT_IMPLICITLY_CONVERT_s_TO_s, BuildLambdaSignature(rctx->exprNode).AddressOf(), lvalue->Format(outFunc->nameSpace).AddressOf()); else str.Format(TXT_CANT_IMPLICITLY_CONVERT_s_TO_s, rctx->type.dataType.Format(outFunc->nameSpace).AddressOf(), lvalue->Format(outFunc->nameSpace).AddressOf()); @@ -6830,14 +6831,14 @@ void asCCompiler::PrepareForAssignment(asCDataType *lvalue, asCExprContext *rctx // TODO: ImplicitConversion should know to do this by itself // First convert to a handle which will do a reference cast if( !lvalue->IsObjectHandle() && - (lvalue->GetTypeInfo()->flags & asOBJ_SCRIPT_OBJECT) ) + (lvalue->GetTypeInfo()->flags & asOBJ_SCRIPT_OBJECT) ) to.MakeHandle(true); // Don't allow the implicit conversion to create an object ImplicitConversion(rctx, to, node, asIC_IMPLICIT_CONV, true, !toTemporary); if( !lvalue->IsObjectHandle() && - (lvalue->GetTypeInfo()->flags & asOBJ_SCRIPT_OBJECT) ) + (lvalue->GetTypeInfo()->flags & asOBJ_SCRIPT_OBJECT) ) { // Then convert to a reference, which will validate the handle to.MakeHandle(false); @@ -6848,7 +6849,7 @@ void asCCompiler::PrepareForAssignment(asCDataType *lvalue, asCExprContext *rctx if( !lvalue->IsEqualExceptRefAndConst(rctx->type.dataType) ) { asCString str; - if (rctx->IsLambda()) + if( rctx->IsLambda() ) str.Format(TXT_CANT_IMPLICITLY_CONVERT_s_TO_s, BuildLambdaSignature(rctx->exprNode).AddressOf(), lvalue->Format(outFunc->nameSpace).AddressOf()); else str.Format(TXT_CANT_IMPLICITLY_CONVERT_s_TO_s, rctx->type.dataType.Format(outFunc->nameSpace).AddressOf(), lvalue->Format(outFunc->nameSpace).AddressOf()); @@ -6939,14 +6940,14 @@ int asCCompiler::PerformAssignment(asCExprValue *lvalue, asCExprValue *rvalue, a // a reference to the object. // TODO: Avoid this special case by implementing a copystub for // script classes that uses the default copy operator - bc->Call(asBC_CALLSYS, beh->copy, 2*AS_PTR_SIZE, 0); + bc->Call(asBC_CALLSYS, beh->copy, 2 * AS_PTR_SIZE, 0); bc->Instr(asBC_PshRPtr); } else { // Default copy operator if( lvalue->dataType.GetSizeInMemoryDWords() == 0 || - !(lvalue->dataType.GetTypeInfo()->flags & asOBJ_POD) ) + !(lvalue->dataType.GetTypeInfo()->flags & asOBJ_POD) ) { asCString msg; msg.Format(TXT_NO_DEFAULT_COPY_OP_FOR_s, lvalue->dataType.GetTypeInfo()->name.AddressOf()); @@ -6999,10 +7000,10 @@ bool asCCompiler::CompileRefCast(asCExprContext *ctx, const asCDataType &to, boo { asCScriptFunction *func = engine->scriptFunctions[ot->methods[n]]; if( (isExplicit && func->name == "opCast") || - func->name == "opImplCast" ) + func->name == "opImplCast" ) { // Skip functions with arguments as they are not valid cast operators - if (func->parameterTypes.GetLength() > 0) + if( func->parameterTypes.GetLength() > 0 ) continue; // Is the operator for the output type? @@ -7021,17 +7022,17 @@ bool asCCompiler::CompileRefCast(asCExprContext *ctx, const asCDataType &to, boo FilterConst(ops, !isConst); // If there is multiple matches, then pick the most appropriate one - if (ops.GetLength() > 1) + if( ops.GetLength() > 1 ) { // This should only happen if an explicit cast is compiled // and the type has both the opCast and opImplCast asASSERT(isExplicit); asASSERT(ops.GetLength() == 2); - for (asUINT n = 0; n < ops.GetLength(); n++) + for( asUINT n = 0; n < ops.GetLength(); n++ ) { asCScriptFunction *func = engine->scriptFunctions[ops[n]]; - if (func->name == "opImplCast") + if( func->name == "opImplCast" ) { ops.RemoveIndex(n); n--; @@ -7054,13 +7055,13 @@ bool asCCompiler::CompileRefCast(asCExprContext *ctx, const asCDataType &to, boo // functions with 1 parameter, even though they should still be // registered with RegisterObjectBehaviour() - if ((ctx->type.dataType.GetTypeInfo()->flags & asOBJ_REF) && !(ctx->type.dataType.GetTypeInfo()->flags & asOBJ_NOHANDLE)) + if( (ctx->type.dataType.GetTypeInfo()->flags & asOBJ_REF) && !(ctx->type.dataType.GetTypeInfo()->flags & asOBJ_NOHANDLE) ) { // Add code to avoid calling the cast behaviour if the handle is already null, // because that will raise a null pointer exception due to the cast behaviour // being a class method, and the this pointer cannot be null. - if (!ctx->type.isVariable) + if( !ctx->type.isVariable ) { Dereference(ctx, true); ConvertToVariable(ctx); @@ -7084,11 +7085,11 @@ bool asCCompiler::CompileRefCast(asCExprContext *ctx, const asCDataType &to, boo ctx->bc.Instr(asBC_RDSPtr); ctx->type.dataType.MakeReference(false); - asCArray args; + asCArray args; // Verify that the opImplCast isn't returning a type by value - asCScriptFunction* func = engine->scriptFunctions[ops[0]]; - if (!func->returnType.IsReference() && !func->returnType.IsObjectHandle()) + asCScriptFunction *func = engine->scriptFunctions[ops[0]]; + if( !func->returnType.IsReference() && !func->returnType.IsObjectHandle() ) { asCString msg; msg.Format(TXT_ILLEGAL_RETURN_BY_VALUE_FOR_s, func->GetDeclarationStr().AddressOf()); @@ -7137,13 +7138,13 @@ bool asCCompiler::CompileRefCast(asCExprContext *ctx, const asCDataType &to, boo { asCScriptFunction *func = engine->scriptFunctions[ot->methods[n]]; if( (isExplicit && func->name == "opCast") || - func->name == "opImplCast" ) + func->name == "opImplCast" ) { // Does the operator take the ?&out parameter? if( func->returnType.GetTokenType() != ttVoid || - func->parameterTypes.GetLength() != 1 || - func->parameterTypes[0].GetTokenType() != ttQuestion || - func->inOutFlags[0] != asTM_OUTREF ) + func->parameterTypes.GetLength() != 1 || + func->parameterTypes[0].GetTokenType() != ttQuestion || + func->inOutFlags[0] != asTM_OUTREF ) continue; ops.PushLast(func->id); @@ -7154,17 +7155,17 @@ bool asCCompiler::CompileRefCast(asCExprContext *ctx, const asCDataType &to, boo FilterConst(ops, !isConst); // If there is multiple matches, then pick the most appropriate one - if (ops.GetLength() > 1) + if( ops.GetLength() > 1 ) { // This should only happen if an explicit cast is compiled // and the type has both the opCast and opImplCast asASSERT(isExplicit); asASSERT(ops.GetLength() == 2); - for (asUINT n = 0; n < ops.GetLength(); n++) + for( asUINT n = 0; n < ops.GetLength(); n++ ) { asCScriptFunction *func = engine->scriptFunctions[ops[n]]; - if (func->name == "opImplCast") + if( func->name == "opImplCast" ) { ops.RemoveIndex(n); n--; @@ -7177,11 +7178,11 @@ bool asCCompiler::CompileRefCast(asCExprContext *ctx, const asCDataType &to, boo conversionDone = true; if( generateCode ) { - int afterLabel = 0; - bool doNullCheck = false; - bool releaseTempVariable = false; + int afterLabel = 0; + bool doNullCheck = false; + bool releaseTempVariable = false; asCExprContext tmp(engine); - if ((ctx->type.dataType.GetTypeInfo()->flags & asOBJ_REF) && !(ctx->type.dataType.GetTypeInfo()->flags & asOBJ_NOHANDLE)) + if( (ctx->type.dataType.GetTypeInfo()->flags & asOBJ_REF) && !(ctx->type.dataType.GetTypeInfo()->flags & asOBJ_NOHANDLE) ) { tmp.bc.AddCode(&ctx->bc); tmp.Merge(ctx); @@ -7190,7 +7191,7 @@ bool asCCompiler::CompileRefCast(asCExprContext *ctx, const asCDataType &to, boo // because that will raise a null pointer exception due to the cast behaviour // being a class method, and the this pointer cannot be null. doNullCheck = true; - if (!ctx->type.isVariable) + if( !ctx->type.isVariable ) { Dereference(&tmp, true); ConvertToVariable(&tmp); @@ -7222,18 +7223,18 @@ bool asCCompiler::CompileRefCast(asCExprContext *ctx, const asCDataType &to, boo asCDataType toRef(to); toRef.MakeReference(true); asCArray args; - asCExprContext arg(engine); + asCExprContext arg(engine); arg.bc.InstrSHORT(asBC_PSF, (short)stackOffset); // Don't mark the variable as temporary, so it won't be freed too early arg.type.SetVariable(toRef, stackOffset, false); - arg.type.isLValue = true; + arg.type.isLValue = true; arg.type.isExplicitHandle = true; args.PushLast(&arg); // Call the behaviour method MakeFunctionCall(ctx, ops[0], CastToObjectType(ctx->type.dataType.GetTypeInfo()), args, node); - if (doNullCheck) + if( doNullCheck ) { // Add the call after the null check tmp.bc.AddCode(&ctx->bc); @@ -7251,7 +7252,7 @@ bool asCCompiler::CompileRefCast(asCExprContext *ctx, const asCDataType &to, boo // If a temporary variable was allocated in the tmp to convert // the input expression to a variable, it must be released here - if (releaseTempVariable && tmp.type.isTemporary) + if( releaseTempVariable && tmp.type.isTemporary ) ReleaseTemporaryVariable(tmp.type.stackOffset, &ctx->bc); // Use the reference to the variable as the result of the expression @@ -7345,14 +7346,14 @@ asUINT asCCompiler::ImplicitConvPrimitiveToPrimitive(asCExprContext *ctx, const { // Attempt to resolve an ambiguous enum value asCDataType out; - asINT64 value; + asINT64 value; if( builder->GetEnumValueFromType(CastToEnumType(to.GetTypeInfo()), ctx->enumValue.AddressOf(), out, value) ) { - if (out.GetSizeInMemoryBytes() == 1) + if( out.GetSizeInMemoryBytes() == 1 ) ctx->type.SetConstantB(out, asBYTE(value)); - else if (out.GetSizeInMemoryBytes() == 2) + else if( out.GetSizeInMemoryBytes() == 2 ) ctx->type.SetConstantW(out, asWORD(value)); - else if (out.GetSizeInMemoryBytes() == 4) + else if( out.GetSizeInMemoryBytes() == 4 ) ctx->type.SetConstantDW(out, asDWORD(value)); else ctx->type.SetConstantQW(out, value); @@ -7376,7 +7377,7 @@ asUINT asCCompiler::ImplicitConvPrimitiveToPrimitive(asCExprContext *ctx, const // Determine the cost of this conversion asUINT cost = asCC_NO_CONV; - if (to.IsBooleanType() || ctx->type.dataType.IsBooleanType()) + if( to.IsBooleanType() || ctx->type.dataType.IsBooleanType() ) { // conversions to/from bool are not allowed. A ternary (expr?1:0) should be used instead // If at any time support for this is added, then remember that booleans can be different size on different platforms @@ -7384,11 +7385,11 @@ asUINT asCCompiler::ImplicitConvPrimitiveToPrimitive(asCExprContext *ctx, const } else if( (to.IsIntegerType() || to.IsUnsignedType()) && (ctx->type.dataType.IsFloatType() || ctx->type.dataType.IsDoubleType()) ) cost = asCC_FLOAT_TO_INT_CONV; - else if ((to.IsFloatType() || to.IsDoubleType()) && (ctx->type.dataType.IsIntegerType() || ctx->type.dataType.IsUnsignedType())) + else if( (to.IsFloatType() || to.IsDoubleType()) && (ctx->type.dataType.IsIntegerType() || ctx->type.dataType.IsUnsignedType()) ) cost = asCC_INT_TO_FLOAT_CONV; - else if (ctx->type.dataType.IsEnumType() && ((ctx->type.dataType.IsIntegerType() && to.IsIntegerType()) || (ctx->type.dataType.IsUnsignedType() && to.IsUnsignedType())) && to.GetSizeInMemoryBytes() == ctx->type.dataType.GetSizeInMemoryBytes()) + else if( ctx->type.dataType.IsEnumType() && ((ctx->type.dataType.IsIntegerType() && to.IsIntegerType()) || (ctx->type.dataType.IsUnsignedType() && to.IsUnsignedType())) && to.GetSizeInMemoryBytes() == ctx->type.dataType.GetSizeInMemoryBytes() ) cost = asCC_ENUM_SAME_SIZE_CONV; - else if (ctx->type.dataType.IsEnumType() && ((ctx->type.dataType.IsIntegerType() && to.IsIntegerType()) || (ctx->type.dataType.IsUnsignedType() && to.IsUnsignedType())) && to.GetSizeInMemoryBytes() != ctx->type.dataType.GetSizeInMemoryBytes()) + else if( ctx->type.dataType.IsEnumType() && ((ctx->type.dataType.IsIntegerType() && to.IsIntegerType()) || (ctx->type.dataType.IsUnsignedType() && to.IsUnsignedType())) && to.GetSizeInMemoryBytes() != ctx->type.dataType.GetSizeInMemoryBytes() ) cost = asCC_ENUM_DIFF_SIZE_CONV; else if( to.IsUnsignedType() && ctx->type.dataType.IsIntegerType() ) cost = asCC_SIGNED_TO_UNSIGNED_CONV; @@ -7396,7 +7397,7 @@ asUINT asCCompiler::ImplicitConvPrimitiveToPrimitive(asCExprContext *ctx, const cost = asCC_UNSIGNED_TO_SIGNED_CONV; else if( to.GetSizeInMemoryBytes() > ctx->type.dataType.GetSizeInMemoryBytes() ) cost = asCC_PRIMITIVE_SIZE_UP_CONV; - else if (to.GetSizeInMemoryBytes() < ctx->type.dataType.GetSizeInMemoryBytes()) + else if( to.GetSizeInMemoryBytes() < ctx->type.dataType.GetSizeInMemoryBytes() ) cost = asCC_PRIMITIVE_SIZE_DOWN_CONV; // Start by implicitly converting constant values @@ -7435,51 +7436,51 @@ asUINT asCCompiler::ImplicitConvPrimitiveToPrimitive(asCExprContext *ctx, const } } - if (to.IsEnumType() && convType == asIC_EXPLICIT_VAL_CAST) + if( to.IsEnumType() && convType == asIC_EXPLICIT_VAL_CAST ) { - if (ctx->type.dataType.IsIntegerType() || - ctx->type.dataType.IsUnsignedType()) + if( ctx->type.dataType.IsIntegerType() || + ctx->type.dataType.IsUnsignedType() ) { ctx->type.dataType.SetTokenType(to.GetTokenType()); ctx->type.dataType.SetTypeInfo(to.GetTypeInfo()); } - else if (ctx->type.dataType.IsFloatType()) + else if( ctx->type.dataType.IsFloatType() ) { ConvertToTempVariable(ctx); ctx->bc.InstrSHORT(to.GetSizeInMemoryDWords() == 2 ? asBC_fTOi64 : asBC_fTOi, (short)ctx->type.stackOffset); ctx->type.dataType.SetTokenType(to.GetTokenType()); ctx->type.dataType.SetTypeInfo(to.GetTypeInfo()); - - if (convType != asIC_EXPLICIT_VAL_CAST) + + if( convType != asIC_EXPLICIT_VAL_CAST ) Warning(TXT_FLOAT_CONV_TO_INT_CAUSE_TRUNC, node); } - else if (ctx->type.dataType.IsDoubleType()) + else if( ctx->type.dataType.IsDoubleType() ) { ConvertToTempVariable(ctx); ReleaseTemporaryVariable(ctx->type, &ctx->bc); int offset = AllocateVariable(to, true); ctx->bc.InstrW_W(to.GetSizeInMemoryDWords() == 2 ? asBC_dTOi64 : asBC_dTOi, offset, ctx->type.stackOffset); ctx->type.SetVariable(to, offset, true); - - if (convType != asIC_EXPLICIT_VAL_CAST) + + if( convType != asIC_EXPLICIT_VAL_CAST ) Warning(TXT_FLOAT_CONV_TO_INT_CAUSE_TRUNC, node); } - + // Convert to smaller integer if necessary s = to.GetSizeInMemoryBytes(); - if (s < 4) + if( s < 4 ) { - ConvertToTempVariable(ctx); - if (s == 1) - ctx->bc.InstrSHORT(asBC_iTOb, (short)ctx->type.stackOffset); - else if (s == 2) - ctx->bc.InstrSHORT(asBC_iTOw, (short)ctx->type.stackOffset); + ConvertToTempVariable(ctx); + if( s == 1 ) + ctx->bc.InstrSHORT(asBC_iTOb, (short)ctx->type.stackOffset); + else if( s == 2 ) + ctx->bc.InstrSHORT(asBC_iTOw, (short)ctx->type.stackOffset); } } - else if ((to.IsIntegerType() && to.GetSizeInMemoryDWords() == 1 && !to.IsEnumType())) + else if( (to.IsIntegerType() && to.GetSizeInMemoryDWords() == 1 && !to.IsEnumType()) ) { if( ctx->type.dataType.IsIntegerType() || - ctx->type.dataType.IsUnsignedType() ) + ctx->type.dataType.IsUnsignedType() ) { if( ctx->type.dataType.GetSizeInMemoryDWords() == 1 ) { @@ -7528,10 +7529,10 @@ asUINT asCCompiler::ImplicitConvPrimitiveToPrimitive(asCExprContext *ctx, const ctx->bc.InstrSHORT(asBC_iTOw, (short)ctx->type.stackOffset); } } - else if (to.IsIntegerType() && to.GetSizeInMemoryDWords() == 2 && !to.IsEnumType()) + else if( to.IsIntegerType() && to.GetSizeInMemoryDWords() == 2 && !to.IsEnumType() ) { if( ctx->type.dataType.IsIntegerType() || - ctx->type.dataType.IsUnsignedType() ) + ctx->type.dataType.IsUnsignedType() ) { if( ctx->type.dataType.GetSizeInMemoryDWords() == 2 ) { @@ -7572,10 +7573,10 @@ asUINT asCCompiler::ImplicitConvPrimitiveToPrimitive(asCExprContext *ctx, const Warning(TXT_FLOAT_CONV_TO_INT_CAUSE_TRUNC, node); } } - else if (to.IsUnsignedType() && to.GetSizeInMemoryDWords() == 1 && !to.IsEnumType()) + else if( to.IsUnsignedType() && to.GetSizeInMemoryDWords() == 1 && !to.IsEnumType() ) { if( ctx->type.dataType.IsIntegerType() || - ctx->type.dataType.IsUnsignedType() ) + ctx->type.dataType.IsUnsignedType() ) { if( ctx->type.dataType.GetSizeInMemoryDWords() == 1 ) { @@ -7624,10 +7625,10 @@ asUINT asCCompiler::ImplicitConvPrimitiveToPrimitive(asCExprContext *ctx, const ctx->bc.InstrSHORT(asBC_iTOw, (short)ctx->type.stackOffset); } } - else if (to.IsUnsignedType() && to.GetSizeInMemoryDWords() == 2 && !to.IsEnumType()) + else if( to.IsUnsignedType() && to.GetSizeInMemoryDWords() == 2 && !to.IsEnumType() ) { if( ctx->type.dataType.IsIntegerType() || - ctx->type.dataType.IsUnsignedType() ) + ctx->type.dataType.IsUnsignedType() ) { if( ctx->type.dataType.GetSizeInMemoryDWords() == 2 ) { @@ -7753,11 +7754,11 @@ asUINT asCCompiler::ImplicitConvPrimitiveToPrimitive(asCExprContext *ctx, const } else { - if ((((to.IsIntegerType() || to.IsUnsignedType()) && !to.IsEnumType()) || - to.IsFloatType() || to.IsDoubleType() || - (to.IsEnumType() && convType == asIC_EXPLICIT_VAL_CAST)) && - (ctx->type.dataType.IsIntegerType() || ctx->type.dataType.IsUnsignedType() || - ctx->type.dataType.IsFloatType() || ctx->type.dataType.IsDoubleType()) ) + if( (((to.IsIntegerType() || to.IsUnsignedType()) && !to.IsEnumType()) || + to.IsFloatType() || to.IsDoubleType() || + (to.IsEnumType() && convType == asIC_EXPLICIT_VAL_CAST)) && + (ctx->type.dataType.IsIntegerType() || ctx->type.dataType.IsUnsignedType() || + ctx->type.dataType.IsFloatType() || ctx->type.dataType.IsDoubleType()) ) { ctx->type.dataType.SetTokenType(to.GetTokenType()); ctx->type.dataType.SetTypeInfo(to.GetTypeInfo()); @@ -7769,24 +7770,24 @@ asUINT asCCompiler::ImplicitConvPrimitiveToPrimitive(asCExprContext *ctx, const return cost; } -asCString asCCompiler::BuildLambdaSignature(asCScriptNode* node) +asCString asCCompiler::BuildLambdaSignature(asCScriptNode *node) { - asUINT count = 0; - asCScriptNode* argNode = node->firstChild; + asUINT count = 0; + asCScriptNode *argNode = node->firstChild; - asCArray lambdaParamTypes; + asCArray lambdaParamTypes; asCArray lambdaInOutFlags; - while (argNode->nodeType != snStatementBlock) + while( argNode->nodeType != snStatementBlock ) { // There will be one node for each parameter. There will be 0, 1, or 2 children in the node with datatype and/or name - if (argNode->nodeType == snUndefined) + if( argNode->nodeType == snUndefined ) { - asCScriptNode* typeNode = argNode->firstChild; + asCScriptNode *typeNode = argNode->firstChild; // Check if the specified parameter types match the funcdef - if (typeNode->nodeType == snDataType) + if( typeNode->nodeType == snDataType ) { - asCDataType dt = builder->CreateDataTypeFromNode(typeNode, script, outFunc->nameSpace, false, outFunc->objectType, true, 0, 0, &m_namespaceVisibility); + asCDataType dt = builder->CreateDataTypeFromNode(typeNode, script, outFunc->nameSpace, false, outFunc->objectType, true, 0, 0, &m_namespaceVisibility); asETypeModifiers inOutFlag; dt = builder->ModifyDataTypeFromNode(dt, typeNode->next, script, &inOutFlag, 0); @@ -7806,13 +7807,13 @@ asCString asCCompiler::BuildLambdaSignature(asCScriptNode* node) // build the lambda function declaration for the error message asCString decl = " lambda("; - for (asUINT n = 0; n < lambdaParamTypes.GetLength(); n++) + for( asUINT n = 0; n < lambdaParamTypes.GetLength(); n++ ) { - if (n > 0) decl += ", "; + if( n > 0 ) decl += ", "; decl += lambdaParamTypes[n].Format(outFunc->nameSpace); } decl += ")"; - + return decl; } @@ -7823,25 +7824,25 @@ asUINT asCCompiler::ImplicitConvLambdaToFunc(asCExprContext *ctx, const asCDataT asCScriptFunction *funcDef = CastToFuncdefType(to.GetTypeInfo())->funcdef; // Check that the lambda has the correct amount of arguments - asUINT count = 0; + asUINT count = 0; asCScriptNode *argNode = ctx->exprNode->firstChild; while( argNode->nodeType != snStatementBlock ) { // There will be one node for each parameter. There will be 0, 1, or 2 children in the node with datatype and/or name - if (argNode->nodeType == snUndefined) + if( argNode->nodeType == snUndefined ) { - asCScriptNode* typeNode = argNode->firstChild; + asCScriptNode *typeNode = argNode->firstChild; // Check if the specified parameter types match the funcdef - if (typeNode->nodeType == snDataType) + if( typeNode->nodeType == snDataType ) { - asCDataType dt = builder->CreateDataTypeFromNode(typeNode, script, outFunc->nameSpace, false, outFunc->objectType, true, 0, 0, &m_namespaceVisibility); + asCDataType dt = builder->CreateDataTypeFromNode(typeNode, script, outFunc->nameSpace, false, outFunc->objectType, true, 0, 0, &m_namespaceVisibility); asETypeModifiers inOutFlag; dt = builder->ModifyDataTypeFromNode(dt, typeNode->next, script, &inOutFlag, 0); - if (count >= funcDef->parameterTypes.GetLength() || - funcDef->parameterTypes[count] != dt || - funcDef->inOutFlags[count] != inOutFlag) + if( count >= funcDef->parameterTypes.GetLength() || + funcDef->parameterTypes[count] != dt || + funcDef->inOutFlags[count] != inOutFlag ) return asCC_NO_CONV; } @@ -7850,7 +7851,7 @@ asUINT asCCompiler::ImplicitConvLambdaToFunc(asCExprContext *ctx, const asCDataT argNode = argNode->next; } - if (funcDef->parameterTypes.GetLength() != count) + if( funcDef->parameterTypes.GetLength() != count ) return asCC_NO_CONV; asASSERT(argNode->nodeType == snStatementBlock); @@ -7862,16 +7863,16 @@ asUINT asCCompiler::ImplicitConvLambdaToFunc(asCExprContext *ctx, const asCDataT { // Build a unique name for the anonymous function asCString name; - for (int iterations = 0;; iterations++) + for( int iterations = 0;; iterations++ ) { name.Format(iterations == 0 ? "$%s$%d" : "$%s$%d(%d)", m_globalVar ? m_globalVar->name.AddressOf() : outFunc->GetDeclaration(), numLambdas, iterations); - // Check if a function with the same name already exists (this can happen if the function - // that declares the lambda has been removed and then is compiled again with + // Check if a function with the same name already exists (this can happen if the function + // that declares the lambda has been removed and then is compiled again with // asIScriptModule::CompileFunction) asCArray funcs; builder->GetFunctionDescriptions(name.AddressOf(), funcs, outFunc->nameSpace); - if (funcs.GetLength() == 0) + if( funcs.GetLength() == 0 ) break; } numLambdas++; @@ -7895,17 +7896,17 @@ asUINT asCCompiler::ImplicitConversion(asCExprContext *ctx, const asCDataType &t ctx->IsAnonymousInitList() ); // No conversion to null handle - if (to.IsNullHandle()) + if( to.IsNullHandle() ) return asCC_NO_CONV; if( to.IsFuncdef() && ctx->IsLambda() ) return ImplicitConvLambdaToFunc(ctx, to, node, convType, generateCode); - if (ctx->IsAnonymousInitList()) + if( ctx->IsAnonymousInitList() ) { - if (to.GetBehaviour() && to.GetBehaviour()->listFactory) + if( to.GetBehaviour() && to.GetBehaviour()->listFactory ) { - if (generateCode) + if( generateCode ) CompileAnonymousInitList(ctx->exprNode, ctx, to); else ctx->type.dataType = to; @@ -7966,7 +7967,7 @@ asUINT asCCompiler::ImplicitConvObjectToPrimitive(asCExprContext *ctx, const asC // Find matching value cast behaviours // Here we're only interested in those that convert the type to a primitive type - asCArray funcs; + asCArray funcs; asCObjectType *ot = CastToObjectType(ctx->type.dataType.GetTypeInfo()); if( ot == 0 ) { @@ -7987,8 +7988,8 @@ asUINT asCCompiler::ImplicitConvObjectToPrimitive(asCExprContext *ctx, const asC // accept both implicit and explicit cast asCScriptFunction *mthd = engine->scriptFunctions[ot->methods[n]]; if( (mthd->name == "opConv" || mthd->name == "opImplConv") && - mthd->parameterTypes.GetLength() == 0 && - mthd->returnType.IsPrimitive() ) + mthd->parameterTypes.GetLength() == 0 && + mthd->returnType.IsPrimitive() ) funcs.PushLast(ot->methods[n]); } } @@ -7999,8 +8000,8 @@ asUINT asCCompiler::ImplicitConvObjectToPrimitive(asCExprContext *ctx, const asC // accept only implicit cast asCScriptFunction *mthd = engine->scriptFunctions[ot->methods[n]]; if( mthd->name == "opImplConv" && - mthd->parameterTypes.GetLength() == 0 && - mthd->returnType.IsPrimitive() ) + mthd->parameterTypes.GetLength() == 0 && + mthd->returnType.IsPrimitive() ) funcs.PushLast(ot->methods[n]); } } @@ -8013,18 +8014,18 @@ asUINT asCCompiler::ImplicitConvObjectToPrimitive(asCExprContext *ctx, const asC // This matrix describes the priorities of the types to search for, for each target type // The first column is the target type, the priorities goes from left to right eTokenType matchMtx[10][10] = - { - {ttDouble, ttFloat, ttInt64, ttUInt64, ttInt, ttUInt, ttInt16, ttUInt16, ttInt8, ttUInt8}, - {ttFloat, ttDouble, ttInt64, ttUInt64, ttInt, ttUInt, ttInt16, ttUInt16, ttInt8, ttUInt8}, - {ttInt64, ttUInt64, ttInt, ttUInt, ttInt16, ttUInt16, ttInt8, ttUInt8, ttDouble, ttFloat}, - {ttUInt64, ttInt64, ttUInt, ttInt, ttUInt16, ttInt16, ttUInt8, ttInt8, ttDouble, ttFloat}, - {ttInt, ttUInt, ttInt64, ttUInt64, ttInt16, ttUInt16, ttInt8, ttUInt8, ttDouble, ttFloat}, - {ttUInt, ttInt, ttUInt64, ttInt64, ttUInt16, ttInt16, ttUInt8, ttInt8, ttDouble, ttFloat}, - {ttInt16, ttUInt16, ttInt, ttUInt, ttInt64, ttUInt64, ttInt8, ttUInt8, ttDouble, ttFloat}, - {ttUInt16, ttInt16, ttUInt, ttInt, ttUInt64, ttInt64, ttUInt8, ttInt8, ttDouble, ttFloat}, - {ttInt8, ttUInt8, ttInt16, ttUInt16, ttInt, ttUInt, ttInt64, ttUInt64, ttDouble, ttFloat}, - {ttUInt8, ttInt8, ttUInt16, ttInt16, ttUInt, ttInt, ttUInt64, ttInt64, ttDouble, ttFloat}, - }; + { + {ttDouble, ttFloat, ttInt64, ttUInt64, ttInt, ttUInt, ttInt16, ttUInt16, ttInt8, ttUInt8}, + {ttFloat, ttDouble, ttInt64, ttUInt64, ttInt, ttUInt, ttInt16, ttUInt16, ttInt8, ttUInt8}, + {ttInt64, ttUInt64, ttInt, ttUInt, ttInt16, ttUInt16, ttInt8, ttUInt8, ttDouble, ttFloat}, + {ttUInt64, ttInt64, ttUInt, ttInt, ttUInt16, ttInt16, ttUInt8, ttInt8, ttDouble, ttFloat}, + {ttInt, ttUInt, ttInt64, ttUInt64, ttInt16, ttUInt16, ttInt8, ttUInt8, ttDouble, ttFloat}, + {ttUInt, ttInt, ttUInt64, ttInt64, ttUInt16, ttInt16, ttUInt8, ttInt8, ttDouble, ttFloat}, + {ttInt16, ttUInt16, ttInt, ttUInt, ttInt64, ttUInt64, ttInt8, ttUInt8, ttDouble, ttFloat}, + {ttUInt16, ttInt16, ttUInt, ttInt, ttUInt64, ttInt64, ttUInt8, ttInt8, ttDouble, ttFloat}, + {ttInt8, ttUInt8, ttInt16, ttUInt16, ttInt, ttUInt, ttInt64, ttUInt64, ttDouble, ttFloat}, + {ttUInt8, ttInt8, ttUInt16, ttInt16, ttUInt, ttInt, ttUInt64, ttInt64, ttDouble, ttFloat}, + }; // Which row to use? eTokenType *row = 0; @@ -8097,13 +8098,13 @@ asUINT asCCompiler::ImplicitConvObjectToPrimitive(asCExprContext *ctx, const asC { asCScriptFunction *func = engine->scriptFunctions[ot->methods[n]]; if( ((convType == asIC_EXPLICIT_VAL_CAST) && func->name == "opConv") || - func->name == "opImplConv" ) + func->name == "opImplConv" ) { // Does the operator take the ?&out parameter? if( func->returnType != asCDataType::CreatePrimitive(ttVoid, false) || - func->parameterTypes.GetLength() != 1 || - func->parameterTypes[0].GetTokenType() != ttQuestion || - func->inOutFlags[0] != asTM_OUTREF ) + func->parameterTypes.GetLength() != 1 || + func->parameterTypes[0].GetTokenType() != ttQuestion || + func->inOutFlags[0] != asTM_OUTREF ) continue; funcs.PushLast(ot->methods[n]); @@ -8113,17 +8114,17 @@ asUINT asCCompiler::ImplicitConvObjectToPrimitive(asCExprContext *ctx, const asC FilterConst(funcs, !ctx->type.dataType.IsReadOnly()); // If there are multiple valid value casts, then we must choose the most appropriate one - if (funcs.GetLength() > 1) + if( funcs.GetLength() > 1 ) { // This should only happen in case of explicit value cast and // the application has registered both opImplConv and opConv asASSERT(convType == asIC_EXPLICIT_VAL_CAST); asASSERT(funcs.GetLength() == 2); - for (asUINT n = 0; n < funcs.GetLength(); n++) + for( asUINT n = 0; n < funcs.GetLength(); n++ ) { asCScriptFunction *func = engine->scriptFunctions[funcs[n]]; - if (func->name == "opImplConv") + if( func->name == "opImplConv" ) { funcs.RemoveIndex(n); n--; @@ -8144,11 +8145,11 @@ asUINT asCCompiler::ImplicitConvObjectToPrimitive(asCExprContext *ctx, const asC toRef.MakeReference(true); toRef.MakeReadOnly(false); asCArray args; - asCExprContext arg(engine); + asCExprContext arg(engine); // Don't mark the variable as temporary, so it won't be freed too early arg.type.SetVariable(toRef, stackOffset, false); arg.type.isLValue = true; - arg.exprNode = node; + arg.exprNode = node; args.PushLast(&arg); // Call the behaviour method @@ -8223,9 +8224,9 @@ asUINT asCCompiler::ImplicitConvObjectRef(asCExprContext *ctx, const asCDataType { // If the input expression is already a funcdef, check if it can be converted if( ctx->type.dataType.IsFuncdef() && - to.GetTypeInfo() != ctx->type.dataType.GetTypeInfo() ) + to.GetTypeInfo() != ctx->type.dataType.GetTypeInfo() ) { - asCScriptFunction *toFunc = CastToFuncdefType(to.GetTypeInfo())->funcdef; + asCScriptFunction *toFunc = CastToFuncdefType(to.GetTypeInfo())->funcdef; asCScriptFunction *fromFunc = CastToFuncdefType(ctx->type.dataType.GetTypeInfo())->funcdef; if( toFunc->IsSignatureExceptNameEqual(fromFunc) ) { @@ -8238,17 +8239,17 @@ asUINT asCCompiler::ImplicitConvObjectRef(asCExprContext *ctx, const asCDataType if( ctx->methodName != "" ) { // Determine the namespace - asSNameSpace *ns = 0; - asCString name = ""; - int pos = ctx->methodName.FindLast("::"); + asSNameSpace *ns = 0; + asCString name = ""; + int pos = ctx->methodName.FindLast("::"); if( pos >= 0 ) { - asCString nsName = ctx->methodName.SubString(0, pos+2); + asCString nsName = ctx->methodName.SubString(0, pos + 2); // Trim off the last :: if( nsName.GetLength() > 2 ) - nsName.SetLength(nsName.GetLength()-2); - ns = DetermineNameSpace(nsName); - name = ctx->methodName.SubString(pos+2); + nsName.SetLength(nsName.GetLength() - 2); + ns = DetermineNameSpace(nsName); + name = ctx->methodName.SubString(pos + 2); } else { @@ -8311,9 +8312,9 @@ asUINT asCCompiler::ImplicitConvObjectValue(asCExprContext *ctx, const asCDataTy // accept both implicit and explicit cast if( (func->name == "opConv" || - func->name == "opImplConv") && - func->returnType.GetTypeInfo() == to.GetTypeInfo() && - func->parameterTypes.GetLength() == 0 ) + func->name == "opImplConv") && + func->returnType.GetTypeInfo() == to.GetTypeInfo() && + func->parameterTypes.GetLength() == 0 ) funcs.PushLast(ot->methods[n]); } } @@ -8325,8 +8326,8 @@ asUINT asCCompiler::ImplicitConvObjectValue(asCExprContext *ctx, const asCDataTy // accept only implicit cast if( func->name == "opImplConv" && - func->returnType.GetTypeInfo() == to.GetTypeInfo() && - func->parameterTypes.GetLength() == 0 ) + func->returnType.GetTypeInfo() == to.GetTypeInfo() && + func->parameterTypes.GetLength() == 0 ) funcs.PushLast(ot->methods[n]); } } @@ -8334,17 +8335,17 @@ asUINT asCCompiler::ImplicitConvObjectValue(asCExprContext *ctx, const asCDataTy FilterConst(funcs, !ctx->type.dataType.IsReadOnly()); // If there are multiple valid value casts, then we must choose the most appropriate one - if (funcs.GetLength() > 1) + if( funcs.GetLength() > 1 ) { // This should only happen in case of explicit value cast and // the application has registered both opImplConv and opConv asASSERT(convType == asIC_EXPLICIT_VAL_CAST); asASSERT(funcs.GetLength() == 2); - for (asUINT n = 0; n < funcs.GetLength(); n++) + for( asUINT n = 0; n < funcs.GetLength(); n++ ) { asCScriptFunction *func = engine->scriptFunctions[funcs[n]]; - if (func->name == "opImplConv") + if( func->name == "opImplConv" ) { funcs.RemoveIndex(n); n--; @@ -8390,13 +8391,13 @@ asUINT asCCompiler::ImplicitConvObjectValue(asCExprContext *ctx, const asCDataTy { asCScriptFunction *func = engine->scriptFunctions[ot->methods[n]]; if( ((convType == asIC_EXPLICIT_VAL_CAST) && func->name == "opConv") || - func->name == "opImplConv" ) + func->name == "opImplConv" ) { // Does the operator take the ?&out parameter? if( func->returnType != asCDataType::CreatePrimitive(ttVoid, false) || - func->parameterTypes.GetLength() != 1 || - func->parameterTypes[0].GetTokenType() != ttQuestion || - func->inOutFlags[0] != asTM_OUTREF ) + func->parameterTypes.GetLength() != 1 || + func->parameterTypes[0].GetTokenType() != ttQuestion || + func->inOutFlags[0] != asTM_OUTREF ) continue; funcs.PushLast(ot->methods[n]); @@ -8406,17 +8407,17 @@ asUINT asCCompiler::ImplicitConvObjectValue(asCExprContext *ctx, const asCDataTy FilterConst(funcs, !ctx->type.dataType.IsReadOnly()); // If there are multiple valid value casts, then we must choose the most appropriate one - if (funcs.GetLength() > 1) + if( funcs.GetLength() > 1 ) { // This should only happen in case of explicit value cast and // the application has registered both opImplConv and opConv asASSERT(convType == asIC_EXPLICIT_VAL_CAST); asASSERT(funcs.GetLength() == 2); - for (asUINT n = 0; n < funcs.GetLength(); n++) + for( asUINT n = 0; n < funcs.GetLength(); n++ ) { asCScriptFunction *func = engine->scriptFunctions[funcs[n]]; - if (func->name == "opImplConv") + if( func->name == "opImplConv" ) { funcs.RemoveIndex(n); n--; @@ -8430,7 +8431,7 @@ asUINT asCCompiler::ImplicitConvObjectValue(asCExprContext *ctx, const asCDataTy if( generateCode ) { // Allocate a temporary variable of the requested type - int stackOffset = AllocateVariableNotIn(to, true, false, ctx); + int stackOffset = AllocateVariableNotIn(to, true, false, ctx); asCExprContext arg(engine); CallDefaultConstructor(to, stackOffset, IsVariableOnHeap(stackOffset), &arg.bc, node); @@ -8446,7 +8447,7 @@ asUINT asCCompiler::ImplicitConvObjectValue(asCExprContext *ctx, const asCDataTy // Don't mark the variable as temporary, so it won't be freed too early arg.type.SetVariable(toRef, stackOffset, false); arg.type.isLValue = true; - arg.exprNode = node; + arg.exprNode = node; // Mark the argument as clean, so that MakeFunctionCall knows it // doesn't have to make a copy of it in order to protect the value @@ -8477,7 +8478,7 @@ asUINT asCCompiler::ImplicitConvObjectValue(asCExprContext *ctx, const asCDataTy funcs = CastToObjectType(to.GetTypeInfo())->beh.constructors; // If not explicit cast, remove any explicit conversion constructors - for (asUINT n = 0; n < funcs.GetLength(); n++) + for( asUINT n = 0; n < funcs.GetLength(); n++ ) { asCScriptFunction *f = engine->scriptFunctions[funcs[n]]; if( f == 0 || f->parameterTypes.GetLength() != 1 || (convType != asIC_EXPLICIT_VAL_CAST && f->IsExplicit()) ) @@ -8491,43 +8492,43 @@ asUINT asCCompiler::ImplicitConvObjectValue(asCExprContext *ctx, const asCDataTy cost = asCC_TO_OBJECT_CONV + MatchFunctions(funcs, args, node, 0, 0, 0, false, true, false); // Did we find a matching constructor? - if (funcs.GetLength() == 1) + if( funcs.GetLength() == 1 ) { - if (generateCode) + if( generateCode ) { // TODO: This should really reuse the code from CompileConstructCall // Allocate the new object - asCExprValue tempObj; + asCExprValue tempObj; asCExprContext e(engine); - bool onHeap = false; - if (to.GetTypeInfo()->flags & asOBJ_VALUE) + bool onHeap = false; + if( to.GetTypeInfo()->flags & asOBJ_VALUE ) { tempObj.dataType = to; tempObj.dataType.MakeReference(false); tempObj.stackOffset = (short)AllocateVariable(tempObj.dataType, true); tempObj.dataType.MakeReference(true); tempObj.isTemporary = true; - tempObj.isVariable = true; + tempObj.isVariable = true; onHeap = IsVariableOnHeap(tempObj.stackOffset); // Push the address of the object on the stack - if (onHeap) + if( onHeap ) e.bc.InstrSHORT(asBC_VAR, (short)tempObj.stackOffset); } PrepareFunctionCall(funcs[0], &e.bc, args); MoveArgsToStack(funcs[0], &e.bc, args, false); - if (to.GetTypeInfo()->flags & asOBJ_VALUE) + if( to.GetTypeInfo()->flags & asOBJ_VALUE ) { // If the object is allocated on the stack, then call the constructor as a normal function - if (onHeap) + if( onHeap ) { - int offset = 0; - asCScriptFunction *descr = builder->GetFunctionDescription(funcs[0]); - offset = descr->parameterTypes[0].GetSizeOnStackDWords(); + int offset = 0; + asCScriptFunction *descr = builder->GetFunctionDescription(funcs[0]); + offset = descr->parameterTypes[0].GetSizeOnStackDWords(); e.bc.InstrWORD(asBC_GETREF, (asWORD)offset); } @@ -8537,7 +8538,7 @@ asUINT asCCompiler::ImplicitConvObjectValue(asCExprContext *ctx, const asCDataTy PerformFunctionCall(funcs[0], &e, onHeap, &args, CastToObjectType(tempObj.dataType.GetTypeInfo())); - if (to.GetTypeInfo()->flags & asOBJ_VALUE) + if( to.GetTypeInfo()->flags & asOBJ_VALUE ) { // Add tag that the object has been initialized e.bc.ObjInfo(tempObj.stackOffset, asOBJ_INIT); @@ -8546,7 +8547,7 @@ asUINT asCCompiler::ImplicitConvObjectValue(asCExprContext *ctx, const asCDataTy // so we have to manually inform the type of // the return value e.type = tempObj; - if (!onHeap) + if( !onHeap ) e.type.dataType.MakeReference(false); // Push the address of the object on the stack again @@ -8580,12 +8581,12 @@ asUINT asCCompiler::ImplicitConvObjectToObject(asCExprContext *ctx, const asCDat funcs = CastToObjectType(to.GetTypeInfo())->beh.constructors; // Don't allow use of explicit constructors/factories in implicit conversions - if (convType == asIC_IMPLICIT_CONV) + if( convType == asIC_IMPLICIT_CONV ) { - for (asUINT n = 0; n < funcs.GetLength(); n++) + for( asUINT n = 0; n < funcs.GetLength(); n++ ) { - asCScriptFunction* desc = builder->GetFunctionDescription(funcs[n]); - if (desc->IsExplicit()) + asCScriptFunction *desc = builder->GetFunctionDescription(funcs[n]); + if( desc->IsExplicit() ) funcs.RemoveIndex(n--); } } @@ -8627,7 +8628,7 @@ asUINT asCCompiler::ImplicitConvObjectToObject(asCExprContext *ctx, const asCDat tempObj.stackOffset = (short)AllocateVariable(tempObj.dataType, true); tempObj.dataType.MakeReference(true); tempObj.isTemporary = true; - tempObj.isVariable = true; + tempObj.isVariable = true; bool onHeap = IsVariableOnHeap(tempObj.stackOffset); @@ -8642,9 +8643,9 @@ asUINT asCCompiler::ImplicitConvObjectToObject(asCExprContext *ctx, const asCDat // If the object is allocated on the stack, then call the constructor as a normal function if( onHeap ) { - int offset = 0; - asCScriptFunction *descr = builder->GetFunctionDescription(funcs[0]); - offset = descr->parameterTypes[0].GetSizeOnStackDWords(); + int offset = 0; + asCScriptFunction *descr = builder->GetFunctionDescription(funcs[0]); + offset = descr->parameterTypes[0].GetSizeOnStackDWords(); e.bc.InstrWORD(asBC_GETREF, (asWORD)offset); } @@ -8701,13 +8702,13 @@ asUINT asCCompiler::ImplicitConvObjectToObject(asCExprContext *ctx, const asCDat // object -> reference to handle if( (!ctx->type.dataType.IsObjectHandle() && ctx->type.dataType.IsReadOnly() && !to.IsHandleToConst()) || - (ctx->type.dataType.IsObjectHandle() && ctx->type.dataType.IsHandleToConst() && !to.IsHandleToConst()) ) + (ctx->type.dataType.IsObjectHandle() && ctx->type.dataType.IsHandleToConst() && !to.IsHandleToConst()) ) { // String literals can be implicitly converted to temporary local variables in order to pass them to functions expecting non-const // TODO: NEWSTRING: Should have an engine property to warn or error on this - if (ctx->type.isConstant && ctx->type.dataType.IsEqualExceptRefAndConst(engine->stringType)) + if( ctx->type.isConstant && ctx->type.dataType.IsEqualExceptRefAndConst(engine->stringType) ) { - if (generateCode) + if( generateCode ) PrepareTemporaryVariable(node, ctx, false, true); else { @@ -8769,7 +8770,7 @@ asUINT asCCompiler::ImplicitConvObjectToObject(asCExprContext *ctx, const asCDat if( ctx->type.dataType.IsReference() ) ctx->bc.Instr(asBC_RDSPtr); ctx->bc.InstrSHORT(asBC_PSF, (short)offset); - if (dt.IsFuncdef()) + if( dt.IsFuncdef() ) ctx->bc.InstrPTR(asBC_REFCPY, &engine->functionBehaviours); else ctx->bc.InstrPTR(asBC_REFCPY, dt.GetTypeInfo()); @@ -8798,7 +8799,7 @@ asUINT asCCompiler::ImplicitConvObjectToObject(asCExprContext *ctx, const asCDat { // A handle to non-const can be converted to a // handle to const, but not the other way - if (to.IsHandleToConst() && !ctx->type.dataType.IsHandleToConst()) + if( to.IsHandleToConst() && !ctx->type.dataType.IsHandleToConst() ) { ctx->type.dataType.MakeHandleToConst(true); @@ -8820,7 +8821,7 @@ asUINT asCCompiler::ImplicitConvObjectToObject(asCExprContext *ctx, const asCDat asASSERT( ctx->type.dataType.IsObjectHandle() ); // If the input type is a handle, then a simple ref copy is enough - bool isExplicitHandle = ctx->type.isExplicitHandle; + bool isExplicitHandle = ctx->type.isExplicitHandle; ctx->type.isExplicitHandle = ctx->type.dataType.IsObjectHandle(); // If the input type is read-only we'll need to temporarily @@ -8940,9 +8941,9 @@ asUINT asCCompiler::ImplicitConvObjectToObject(asCExprContext *ctx, const asCDat } // A reference to a non-const can be converted to a reference to a const - if (to.IsReadOnly() ) + if( to.IsReadOnly() ) { - if (!ctx->type.dataType.IsReadOnly()) + if( !ctx->type.dataType.IsReadOnly() ) { ctx->type.dataType.MakeReadOnly(true); @@ -8996,8 +8997,8 @@ asUINT asCCompiler::ImplicitConvObjectToObject(asCExprContext *ctx, const asCDat // by it not being a reference. But it can be handled as // reference by pushing the pointer on the stack if( (ctx->type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE) && - (ctx->type.isVariable || ctx->type.isTemporary) && - !IsVariableOnHeap(ctx->type.stackOffset) ) + (ctx->type.isVariable || ctx->type.isTemporary) && + !IsVariableOnHeap(ctx->type.stackOffset) ) { // Actually the pointer is already pushed on the stack in // CompileVariableAccess, so we don't need to do anything else @@ -9028,7 +9029,7 @@ asUINT asCCompiler::ImplicitConvObjectToObject(asCExprContext *ctx, const asCDat ctx->type.dataType.MakeReference(IsVariableOnHeap(ctx->type.stackOffset)); } - if (to.IsReadOnly() && !ctx->type.dataType.IsReadOnly() ) + if( to.IsReadOnly() && !ctx->type.dataType.IsReadOnly() ) { // This doesn't cost anything ctx->type.dataType.MakeReadOnly(true); @@ -9037,14 +9038,14 @@ asUINT asCCompiler::ImplicitConvObjectToObject(asCExprContext *ctx, const asCDat cost += asCC_CONST_CONV; } - if (!to.IsReadOnly() && ctx->type.dataType.IsReadOnly()) + if( !to.IsReadOnly() && ctx->type.dataType.IsReadOnly() ) { // A const object can be converted to a non-const object through a copy - if (allowObjectConstruct || convType == asIC_EXPLICIT_VAL_CAST) + if( allowObjectConstruct || convType == asIC_EXPLICIT_VAL_CAST ) { ctx->type.dataType.MakeReadOnly(false); - if (generateCode) + if( generateCode ) { // Make a temporary copy of the object in order to make it non-const PrepareTemporaryVariable(node, ctx); @@ -9056,9 +9057,9 @@ asUINT asCCompiler::ImplicitConvObjectToObject(asCExprContext *ctx, const asCDat // String literals can be implicitly converted to temporary local variables in order to pass them to functions expecting non-const // TODO: NEWSTRING: Should have an engine property to warn or error on this - if (ctx->type.isConstant && ctx->type.dataType.IsEqualExceptRefAndConst(engine->stringType)) + if( ctx->type.isConstant && ctx->type.dataType.IsEqualExceptRefAndConst(engine->stringType) ) { - if (generateCode) + if( generateCode ) PrepareTemporaryVariable(node, ctx); else { @@ -9084,35 +9085,35 @@ asUINT asCCompiler::ImplicitConvPrimitiveToObject(asCExprContext *ctx, const asC if( !objType ) return asCC_NO_CONV; - if (!allowObjectConstruct) + if( !allowObjectConstruct ) return asCC_NO_CONV; asCArray funcs; - if (objType->flags & asOBJ_VALUE) + if( objType->flags & asOBJ_VALUE ) { // For value types the object must have a constructor that takes a single primitive argument either by value or as input reference - for (asUINT n = 0; n < objType->beh.constructors.GetLength(); n++) + for( asUINT n = 0; n < objType->beh.constructors.GetLength(); n++ ) { asCScriptFunction *func = engine->scriptFunctions[objType->beh.constructors[n]]; - if (func->parameterTypes.GetLength() == 1 && - func->parameterTypes[0].IsPrimitive() && - !(func->inOutFlags[0] & asTM_OUTREF) && - (isExplicit == asIC_EXPLICIT_VAL_CAST || !func->IsExplicit()) ) + if( func->parameterTypes.GetLength() == 1 && + func->parameterTypes[0].IsPrimitive() && + !(func->inOutFlags[0] & asTM_OUTREF) && + (isExplicit == asIC_EXPLICIT_VAL_CAST || !func->IsExplicit()) ) { funcs.PushLast(func->id); } } } - else if (objType->flags & asOBJ_REF) + else if( objType->flags & asOBJ_REF ) { // For ref types the object must have a factory that takes a single primitive argument either by value or as input reference - for (asUINT n = 0; n < objType->beh.factories.GetLength(); n++) + for( asUINT n = 0; n < objType->beh.factories.GetLength(); n++ ) { asCScriptFunction *func = engine->scriptFunctions[objType->beh.factories[n]]; - if (func->parameterTypes.GetLength() == 1 && - func->parameterTypes[0].IsPrimitive() && - !(func->inOutFlags[0] & asTM_OUTREF) && - (isExplicit == asIC_EXPLICIT_VAL_CAST || !func->IsExplicit())) + if( func->parameterTypes.GetLength() == 1 && + func->parameterTypes[0].IsPrimitive() && + !(func->inOutFlags[0] & asTM_OUTREF) && + (isExplicit == asIC_EXPLICIT_VAL_CAST || !func->IsExplicit()) ) { funcs.PushLast(func->id); } @@ -9124,9 +9125,9 @@ asUINT asCCompiler::ImplicitConvPrimitiveToObject(asCExprContext *ctx, const asC // Check if it is possible to choose a best match asCExprContext arg(engine); - arg.type = ctx->type; + arg.type = ctx->type; arg.exprNode = ctx->exprNode; // Use the same node for compiler messages - asCArray args; + asCArray args; args.PushLast(&arg); asUINT cost = asCC_TO_OBJECT_CONV + MatchFunctions(funcs, args, 0, 0, 0, objType, false, true, false); if( funcs.GetLength() != 1 ) @@ -9145,20 +9146,20 @@ asUINT asCCompiler::ImplicitConvPrimitiveToObject(asCExprContext *ctx, const asC // Value types and script types are allocated through the constructor asCExprValue tempObj; - bool onHeap = false; + bool onHeap = false; - if (!(objType->flags & asOBJ_REF)) + if( !(objType->flags & asOBJ_REF) ) { - tempObj.dataType = to; + tempObj.dataType = to; tempObj.stackOffset = (short)AllocateVariable(to, true); tempObj.dataType.MakeReference(true); tempObj.isTemporary = true; - tempObj.isVariable = true; + tempObj.isVariable = true; onHeap = IsVariableOnHeap(tempObj.stackOffset); // Push the address of the object on the stack - if (onHeap) + if( onHeap ) ctx->bc.InstrSHORT(asBC_VAR, (short)tempObj.stackOffset); } @@ -9170,8 +9171,8 @@ asUINT asCCompiler::ImplicitConvPrimitiveToObject(asCExprContext *ctx, const asC // If the object is allocated on the stack, then call the constructor as a normal function if( onHeap ) { - int offset = 0; - asCScriptFunction *descr = builder->GetFunctionDescription(funcs[0]); + int offset = 0; + asCScriptFunction *descr = builder->GetFunctionDescription(funcs[0]); for( asUINT n = 0; n < args.GetLength(); n++ ) offset += descr->parameterTypes[n].GetSizeOnStackDWords(); @@ -9221,110 +9222,110 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData // References cannot be constants if( from->type.dataType.IsReference() ) return; - if((to.IsEnumType() && convType == asIC_EXPLICIT_VAL_CAST)) + if( (to.IsEnumType() && convType == asIC_EXPLICIT_VAL_CAST) ) { if( from->type.dataType.IsFloatType() || - from->type.dataType.IsDoubleType() || - from->type.dataType.IsUnsignedType() || - from->type.dataType.IsIntegerType() ) + from->type.dataType.IsDoubleType() || + from->type.dataType.IsUnsignedType() || + from->type.dataType.IsIntegerType() ) { // Transform the value // Float constants can be implicitly converted to int - if (from->type.dataType.IsFloatType()) + if( from->type.dataType.IsFloatType() ) { - float fc = from->type.GetConstantF(); + float fc = from->type.GetConstantF(); asINT64 ic = asINT64(fc); - - if (asINT64(ic) != fc) + + if( asINT64(ic) != fc ) { - if (convType != asIC_EXPLICIT_VAL_CAST && node) + if( convType != asIC_EXPLICIT_VAL_CAST && node ) Warning(TXT_NOT_EXACT, node); } - - if (to.GetSizeInMemoryBytes() == 1) + + if( to.GetSizeInMemoryBytes() == 1 ) from->type.SetConstantB(to, asBYTE(ic)); - else if (to.GetSizeInMemoryBytes() == 2) + else if( to.GetSizeInMemoryBytes() == 2 ) from->type.SetConstantW(to, asWORD(ic)); - else if (to.GetSizeInMemoryBytes() == 4) + else if( to.GetSizeInMemoryBytes() == 4 ) from->type.SetConstantDW(to, asDWORD(ic)); else from->type.SetConstantQW(to, ic); } // Double constants can be implicitly converted to int - else if (from->type.dataType.IsDoubleType()) + else if( from->type.dataType.IsDoubleType() ) { - double fc = from->type.GetConstantD(); + double fc = from->type.GetConstantD(); asINT64 ic = asINT64(fc); - - if (asINT64(ic) != fc) + + if( asINT64(ic) != fc ) { - if (convType != asIC_EXPLICIT_VAL_CAST && node) + if( convType != asIC_EXPLICIT_VAL_CAST && node ) Warning(TXT_NOT_EXACT, node); } - - if (to.GetSizeInMemoryBytes() == 1) + + if( to.GetSizeInMemoryBytes() == 1 ) from->type.SetConstantB(to, asBYTE(ic)); - else if (to.GetSizeInMemoryBytes() == 2) + else if( to.GetSizeInMemoryBytes() == 2 ) from->type.SetConstantW(to, asWORD(ic)); - else if (to.GetSizeInMemoryBytes() == 4) + else if( to.GetSizeInMemoryBytes() == 4 ) from->type.SetConstantDW(to, asDWORD(ic)); else from->type.SetConstantQW(to, ic); } - else if (from->type.dataType.IsUnsignedType()) + else if( from->type.dataType.IsUnsignedType() ) { asQWORD qw; - - if (from->type.dataType.GetSizeInMemoryBytes() == 1) + + if( from->type.dataType.GetSizeInMemoryBytes() == 1 ) qw = from->type.GetConstantB(); - else if (from->type.dataType.GetSizeInMemoryBytes() == 2) + else if( from->type.dataType.GetSizeInMemoryBytes() == 2 ) qw = from->type.GetConstantW(); - else if (from->type.dataType.GetSizeInMemoryBytes() == 4) + else if( from->type.dataType.GetSizeInMemoryBytes() == 4 ) qw = from->type.GetConstantDW(); else qw = from->type.GetConstantQW(); - + // Convert to `to` - if (to.GetSizeInMemoryBytes() == 1) + if( to.GetSizeInMemoryBytes() == 1 ) from->type.SetConstantB(to, (asBYTE)qw); - else if (to.GetSizeInMemoryBytes() == 2) + else if( to.GetSizeInMemoryBytes() == 2 ) from->type.SetConstantW(to, (asWORD)qw); - else if (to.GetSizeInMemoryBytes() == 4) + else if( to.GetSizeInMemoryBytes() == 4 ) from->type.SetConstantDW(to, (asDWORD)qw); else from->type.SetConstantQW(to, (asQWORD)qw); } - else if (from->type.dataType.IsIntegerType()) + else if( from->type.dataType.IsIntegerType() ) { asINT64 qw; - - if (from->type.dataType.GetSizeInMemoryBytes() == 1) + + if( from->type.dataType.GetSizeInMemoryBytes() == 1 ) qw = from->type.GetConstantB(); - else if (from->type.dataType.GetSizeInMemoryBytes() == 2) + else if( from->type.dataType.GetSizeInMemoryBytes() == 2 ) qw = from->type.GetConstantW(); - else if (from->type.dataType.GetSizeInMemoryBytes() == 4) + else if( from->type.dataType.GetSizeInMemoryBytes() == 4 ) qw = from->type.GetConstantDW(); else qw = from->type.GetConstantQW(); - + // Convert to `to` - if (to.GetSizeInMemoryBytes() == 1) + if( to.GetSizeInMemoryBytes() == 1 ) from->type.SetConstantB(to, (asINT8)qw); - else if (to.GetSizeInMemoryBytes() == 2) + else if( to.GetSizeInMemoryBytes() == 2 ) from->type.SetConstantW(to, (asINT16)qw); - else if (to.GetSizeInMemoryBytes() == 4) + else if( to.GetSizeInMemoryBytes() == 4 ) from->type.SetConstantDW(to, (asINT32)qw); else from->type.SetConstantQW(to, (asINT64)qw); } } } - else if ((to.IsIntegerType() && to.GetSizeInMemoryDWords() == 1 && !to.IsEnumType())) + else if( (to.IsIntegerType() && to.GetSizeInMemoryDWords() == 1 && !to.IsEnumType()) ) { - if (from->type.dataType.IsFloatType() || - from->type.dataType.IsDoubleType() || - from->type.dataType.IsUnsignedType() || - from->type.dataType.IsIntegerType()) + if( from->type.dataType.IsFloatType() || + from->type.dataType.IsDoubleType() || + from->type.dataType.IsUnsignedType() || + from->type.dataType.IsIntegerType() ) { asCDataType targetDt = asCDataType::CreatePrimitive(ttInt, true); @@ -9332,20 +9333,20 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData // Float constants can be implicitly converted to int if( from->type.dataType.IsFloatType() ) { - float fc = from->type.GetConstantF(); + float fc = from->type.GetConstantF(); asINT64 ic = int(fc); if( float(ic) != fc ) { - if( convType != asIC_EXPLICIT_VAL_CAST && node ) + if( convType != asIC_EXPLICIT_VAL_CAST && node ) Warning(TXT_NOT_EXACT, node); } - if (targetDt.GetSizeInMemoryBytes() == 1) + if( targetDt.GetSizeInMemoryBytes() == 1 ) from->type.SetConstantB(targetDt, asBYTE(ic)); - else if (targetDt.GetSizeInMemoryBytes() == 2) + else if( targetDt.GetSizeInMemoryBytes() == 2 ) from->type.SetConstantW(targetDt, asWORD(ic)); - else if (targetDt.GetSizeInMemoryBytes() == 4) + else if( targetDt.GetSizeInMemoryBytes() == 4 ) from->type.SetConstantDW(targetDt, asDWORD(ic)); else from->type.SetConstantQW(targetDt, ic); @@ -9353,20 +9354,20 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData // Double constants can be implicitly converted to int else if( from->type.dataType.IsDoubleType() ) { - double fc = from->type.GetConstantD(); + double fc = from->type.GetConstantD(); asINT64 ic = int(fc); if( double(ic) != fc ) { - if( convType != asIC_EXPLICIT_VAL_CAST && node ) + if( convType != asIC_EXPLICIT_VAL_CAST && node ) Warning(TXT_NOT_EXACT, node); } - if (targetDt.GetSizeInMemoryBytes() == 1) + if( targetDt.GetSizeInMemoryBytes() == 1 ) from->type.SetConstantB(targetDt, asBYTE(ic)); - else if (targetDt.GetSizeInMemoryBytes() == 2) + else if( targetDt.GetSizeInMemoryBytes() == 2 ) from->type.SetConstantW(targetDt, asWORD(ic)); - else if (targetDt.GetSizeInMemoryBytes() == 4) + else if( targetDt.GetSizeInMemoryBytes() == 4 ) from->type.SetConstantDW(targetDt, asDWORD(ic)); else from->type.SetConstantQW(targetDt, ic); @@ -9375,42 +9376,42 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData { // Verify that it is possible to convert to signed without getting negative if( from->type.dataType.GetSizeInMemoryBytes() == 4 && - int(from->type.GetConstantDW()) < 0 && - convType != asIC_EXPLICIT_VAL_CAST && - node != 0 ) + int(from->type.GetConstantDW()) < 0 && + convType != asIC_EXPLICIT_VAL_CAST && + node != 0 ) Warning(TXT_CHANGE_SIGN, node); // Convert to 32bit - if(targetDt.GetSizeInMemoryBytes() == 1) + if( targetDt.GetSizeInMemoryBytes() == 1 ) from->type.SetConstantDW(targetDt, from->type.GetConstantB()); - else if (targetDt.GetSizeInMemoryBytes() == 2) + else if( targetDt.GetSizeInMemoryBytes() == 2 ) from->type.SetConstantDW(targetDt, from->type.GetConstantW()); else from->type.dataType = targetDt; } else if( from->type.dataType.IsUnsignedType() && from->type.dataType.GetSizeInMemoryDWords() == 2 ) { - if (asQWORD(from->type.GetConstantQW()) >> 31) - if (convType != asIC_EXPLICIT_VAL_CAST && node) Warning(TXT_VALUE_TOO_LARGE_FOR_TYPE, node); + if( asQWORD(from->type.GetConstantQW()) >> 31 ) + if( convType != asIC_EXPLICIT_VAL_CAST && node ) Warning(TXT_VALUE_TOO_LARGE_FOR_TYPE, node); // Convert to 32bit from->type.SetConstantDW(targetDt, int(from->type.GetConstantQW())); } - else if (from->type.dataType.IsIntegerType() && from->type.dataType.GetSizeInMemoryDWords() == 2) + else if( from->type.dataType.IsIntegerType() && from->type.dataType.GetSizeInMemoryDWords() == 2 ) { - if (int(from->type.GetConstantQW()) != asINT64(from->type.GetConstantQW())) - if (convType != asIC_EXPLICIT_VAL_CAST && node) Warning(TXT_VALUE_TOO_LARGE_FOR_TYPE, node); + if( int(from->type.GetConstantQW()) != asINT64(from->type.GetConstantQW()) ) + if( convType != asIC_EXPLICIT_VAL_CAST && node ) Warning(TXT_VALUE_TOO_LARGE_FOR_TYPE, node); // Convert to 32bit from->type.SetConstantDW(targetDt, int(from->type.GetConstantQW())); } - else if (from->type.dataType.IsIntegerType() && - from->type.dataType.GetSizeInMemoryBytes() < 4) + else if( from->type.dataType.IsIntegerType() && + from->type.dataType.GetSizeInMemoryBytes() < 4 ) { // Convert to 32bit - if (from->type.dataType.GetSizeInMemoryBytes() == 1) + if( from->type.dataType.GetSizeInMemoryBytes() == 1 ) from->type.SetConstantDW(targetDt, (asINT8)from->type.GetConstantB()); - else if (from->type.dataType.GetSizeInMemoryBytes() == 2) + else if( from->type.dataType.GetSizeInMemoryBytes() == 2 ) from->type.SetConstantDW(targetDt, (asINT16)from->type.GetConstantW()); } else @@ -9427,7 +9428,7 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData // Check if a downsize is necessary if( to.IsIntegerType() && - from->type.dataType.IsIntegerType() && + from->type.dataType.IsIntegerType() && from->type.dataType.GetSizeInMemoryBytes() > to.GetSizeInMemoryBytes() ) { // Verify if it is possible @@ -9447,12 +9448,12 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData } } } - else if (to.IsIntegerType() && to.GetSizeInMemoryDWords() == 2 && !to.IsEnumType()) + else if( to.IsIntegerType() && to.GetSizeInMemoryDWords() == 2 && !to.IsEnumType() ) { // Float constants can be implicitly converted to int if( from->type.dataType.IsFloatType() ) { - float fc = from->type.GetConstantF(); + float fc = from->type.GetConstantF(); asINT64 ic = asINT64(fc); if( float(ic) != fc ) @@ -9465,7 +9466,7 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData // Double constants can be implicitly converted to int else if( from->type.dataType.IsDoubleType() ) { - double fc = from->type.GetConstantD(); + double fc = from->type.GetConstantD(); asINT64 ic = asINT64(fc); if( double(ic) != fc ) @@ -9504,7 +9505,7 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData from->type.SetConstantQW(asCDataType::CreatePrimitive(ttInt64, true), (int)from->type.GetConstantDW()); } } - else if (to.IsUnsignedType() && to.GetSizeInMemoryDWords() == 1 && !to.IsEnumType()) + else if( to.IsUnsignedType() && to.GetSizeInMemoryDWords() == 1 && !to.IsEnumType() ) { asCDataType targetDt = asCDataType::CreatePrimitive(ttUInt, true); if( from->type.dataType.IsFloatType() ) @@ -9545,9 +9546,9 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData { // Verify that it is possible to convert to unsigned without loosing negative if( (from->type.dataType.GetSizeInMemoryBytes() > 4 && asINT64(from->type.GetConstantQW()) < 0) || - (from->type.dataType.GetSizeInMemoryBytes() == 4 && int(from->type.GetConstantDW()) < 0) || - (from->type.dataType.GetSizeInMemoryBytes() == 2 && asINT16(from->type.GetConstantW()) < 0) || - (from->type.dataType.GetSizeInMemoryBytes() == 1 && asINT8(from->type.GetConstantB()) < 0)) + (from->type.dataType.GetSizeInMemoryBytes() == 4 && int(from->type.GetConstantDW()) < 0) || + (from->type.dataType.GetSizeInMemoryBytes() == 2 && asINT16(from->type.GetConstantW()) < 0) || + (from->type.dataType.GetSizeInMemoryBytes() == 1 && asINT8(from->type.GetConstantB()) < 0) ) { if( convType != asIC_EXPLICIT_VAL_CAST && node ) Warning(TXT_CHANGE_SIGN, node); } @@ -9563,7 +9564,7 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData from->type.SetConstantDW(asCDataType::CreatePrimitive(ttUInt, true), (asINT8)from->type.GetConstantB()); else if( from->type.dataType.GetSizeInMemoryBytes() == 2 ) from->type.SetConstantDW(asCDataType::CreatePrimitive(ttUInt, true), (asINT16)from->type.GetConstantW()); - else if (from->type.dataType.GetSizeInMemoryBytes() == 4 ) + else if( from->type.dataType.GetSizeInMemoryBytes() == 4 ) from->type.SetConstantDW(asCDataType::CreatePrimitive(ttUInt, true), (int)from->type.GetConstantDW()); else from->type.SetConstantDW(asCDataType::CreatePrimitive(ttUInt, true), (int)(asINT64)from->type.GetConstantQW()); @@ -9590,32 +9591,32 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData if( to.GetSizeInMemoryBytes() == 1 ) { if( (from->type.dataType.GetSizeInMemoryBytes() == 2 && asBYTE(from->type.GetConstantW()) != from->type.GetConstantW()) || - (from->type.dataType.GetSizeInMemoryBytes() == 4 && asBYTE(from->type.GetConstantDW()) != from->type.GetConstantDW()) || - (from->type.dataType.GetSizeInMemoryBytes() == 8 && asBYTE(from->type.GetConstantQW()) != from->type.GetConstantQW()) ) + (from->type.dataType.GetSizeInMemoryBytes() == 4 && asBYTE(from->type.GetConstantDW()) != from->type.GetConstantDW()) || + (from->type.dataType.GetSizeInMemoryBytes() == 8 && asBYTE(from->type.GetConstantQW()) != from->type.GetConstantQW()) ) if( convType != asIC_EXPLICIT_VAL_CAST && node ) Warning(TXT_VALUE_TOO_LARGE_FOR_TYPE, node); if( from->type.dataType.GetSizeInMemoryBytes() == 2 ) from->type.SetConstantB(to.IsEnumType() ? CastToEnumType(to.GetTypeInfo())->enumType : asCDataType::CreatePrimitive(to.GetTokenType(), true), asBYTE(from->type.GetConstantW())); - else if (from->type.dataType.GetSizeInMemoryBytes() == 4) + else if( from->type.dataType.GetSizeInMemoryBytes() == 4 ) from->type.SetConstantB(to.IsEnumType() ? CastToEnumType(to.GetTypeInfo())->enumType : asCDataType::CreatePrimitive(to.GetTokenType(), true), asBYTE(from->type.GetConstantDW())); - else if (from->type.dataType.GetSizeInMemoryBytes() == 8) + else if( from->type.dataType.GetSizeInMemoryBytes() == 8 ) from->type.SetConstantB(to.IsEnumType() ? CastToEnumType(to.GetTypeInfo())->enumType : asCDataType::CreatePrimitive(to.GetTokenType(), true), asBYTE(from->type.GetConstantQW())); } else if( to.GetSizeInMemoryBytes() == 2 ) { if( (from->type.dataType.GetSizeInMemoryBytes() == 4 && asWORD(from->type.GetConstantDW()) != from->type.GetConstantDW()) || - (from->type.dataType.GetSizeInMemoryBytes() == 8 && asWORD(from->type.GetConstantQW()) != from->type.GetConstantQW()) ) + (from->type.dataType.GetSizeInMemoryBytes() == 8 && asWORD(from->type.GetConstantQW()) != from->type.GetConstantQW()) ) if( convType != asIC_EXPLICIT_VAL_CAST && node ) Warning(TXT_VALUE_TOO_LARGE_FOR_TYPE, node); - if (from->type.dataType.GetSizeInMemoryBytes() == 4) + if( from->type.dataType.GetSizeInMemoryBytes() == 4 ) from->type.SetConstantW(to.IsEnumType() ? CastToEnumType(to.GetTypeInfo())->enumType : asCDataType::CreatePrimitive(to.GetTokenType(), true), asWORD(from->type.GetConstantDW())); - else if (from->type.dataType.GetSizeInMemoryBytes() == 8) + else if( from->type.dataType.GetSizeInMemoryBytes() == 8 ) from->type.SetConstantW(to.IsEnumType() ? CastToEnumType(to.GetTypeInfo())->enumType : asCDataType::CreatePrimitive(to.GetTokenType(), true), asWORD(from->type.GetConstantQW())); } - else if (to.GetSizeInMemoryBytes() == 4) + else if( to.GetSizeInMemoryBytes() == 4 ) { - if( asDWORD(from->type.GetConstantQW()) != from->type.GetConstantQW()) - if (convType != asIC_EXPLICIT_VAL_CAST && node) Warning(TXT_VALUE_TOO_LARGE_FOR_TYPE, node); + if( asDWORD(from->type.GetConstantQW()) != from->type.GetConstantQW() ) + if( convType != asIC_EXPLICIT_VAL_CAST && node ) Warning(TXT_VALUE_TOO_LARGE_FOR_TYPE, node); from->type.SetConstantDW(to.IsEnumType() ? CastToEnumType(to.GetTypeInfo())->enumType : asCDataType::CreatePrimitive(to.GetTokenType(), true), asDWORD(from->type.GetConstantQW())); } @@ -9627,11 +9628,11 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData asASSERT((from->type.dataType.GetTokenType() == ttUInt || from->type.dataType.IsEnumType()) && from->type.dataType.GetSizeInMemoryBytes() == 4); - + from->type.dataType = targetDt; } } - else if (to.IsUnsignedType() && to.GetSizeInMemoryDWords() == 2 && !to.IsEnumType()) + else if( to.IsUnsignedType() && to.GetSizeInMemoryDWords() == 2 && !to.IsEnumType() ) { if( from->type.dataType.IsFloatType() ) { @@ -9639,13 +9640,13 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData // Convert first to int64 then to uint64 to avoid negative float becoming 0 on gnuc base compilers asQWORD uic = asQWORD(asINT64(fc)); -#if !defined(_MSC_VER) || _MSC_VER > 1200 // MSVC++ 6 + #if !defined(_MSC_VER) || _MSC_VER > 1200 // MSVC++ 6 // MSVC6 doesn't support this conversion if( float(uic) != fc ) { if( convType != asIC_EXPLICIT_VAL_CAST && node ) Warning(TXT_NOT_EXACT, node); } -#endif + #endif from->type.SetConstantQW(asCDataType::CreatePrimitive(ttUInt64, true), uic); } @@ -9655,13 +9656,13 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData // Convert first to int64 then to uint64 to avoid negative float becoming 0 on gnuc base compilers asQWORD uic = asQWORD(asINT64(fc)); -#if !defined(_MSC_VER) || _MSC_VER > 1200 // MSVC++ 6 + #if !defined(_MSC_VER) || _MSC_VER > 1200 // MSVC++ 6 // MSVC6 doesn't support this conversion if( double(uic) != fc ) { if( convType != asIC_EXPLICIT_VAL_CAST && node ) Warning(TXT_NOT_EXACT, node); } -#endif + #endif from->type.SetConstantQW(asCDataType::CreatePrimitive(ttUInt64, true), uic); } @@ -9702,7 +9703,7 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData from->type.SetConstantQW(asCDataType::CreatePrimitive(ttUInt64, true), from->type.GetConstantW()); else if( from->type.dataType.GetSizeInMemoryBytes() == 4 ) from->type.SetConstantQW(asCDataType::CreatePrimitive(ttUInt64, true), from->type.GetConstantDW()); - else if (from->type.dataType.GetSizeInMemoryBytes() == 8) + else if( from->type.dataType.GetSizeInMemoryBytes() == 8 ) from->type.SetConstantQW(asCDataType::CreatePrimitive(ttUInt64, true), from->type.GetConstantQW()); } } @@ -9711,7 +9712,7 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData if( from->type.dataType.IsDoubleType() ) { double ic = from->type.GetConstantD(); - float fc = float(ic); + float fc = float(ic); from->type.SetConstantF(asCDataType::CreatePrimitive(to.GetTokenType(), true), fc); } @@ -9767,7 +9768,7 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData { float fc = float((asINT64)from->type.GetConstantQW()); - if( asQWORD(fc) != from->type.GetConstantQW()) + if( asQWORD(fc) != from->type.GetConstantQW() ) { if( convType != asIC_EXPLICIT_VAL_CAST && node ) Warning(TXT_NOT_EXACT, node); } @@ -9779,7 +9780,7 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData { if( from->type.dataType.IsFloatType() ) { - float ic = from->type.GetConstantF(); + float ic = from->type.GetConstantF(); double fc = double(ic); from->type.SetConstantD(asCDataType::CreatePrimitive(to.GetTokenType(), true), fc); @@ -9837,7 +9838,7 @@ void asCCompiler::ImplicitConversionConstant(asCExprContext *from, const asCData { double fc = double((asINT64)from->type.GetConstantQW()); - if( asQWORD(fc) != from->type.GetConstantQW()) + if( asQWORD(fc) != from->type.GetConstantQW() ) { if( convType != asIC_EXPLICIT_VAL_CAST && node ) Warning(TXT_NOT_EXACT, node); } @@ -9858,7 +9859,7 @@ int asCCompiler::DoAssignment(asCExprContext *ctx, asCExprContext *lctx, asCExpr } // Implicit handle types should always be treated as handles in assignments - if (lctx->type.dataType.GetTypeInfo() && (lctx->type.dataType.GetTypeInfo()->flags & asOBJ_IMPLICIT_HANDLE) ) + if( lctx->type.dataType.GetTypeInfo() && (lctx->type.dataType.GetTypeInfo()->flags & asOBJ_IMPLICIT_HANDLE) ) { lctx->type.dataType.MakeHandle(true); lctx->type.isExplicitHandle = true; @@ -9869,7 +9870,7 @@ int asCCompiler::DoAssignment(asCExprContext *ctx, asCExprContext *lctx, asCExpr // the property accessor is for a handle property, and the operation is a value // assignment. if( (lctx->property_get || lctx->property_set) && - !(lctx->type.dataType.IsObjectHandle() && !lctx->type.isExplicitHandle) ) + !(lctx->type.dataType.IsObjectHandle() && !lctx->type.isExplicitHandle) ) { if( op != ttAssignment ) { @@ -9882,8 +9883,8 @@ int asCCompiler::DoAssignment(asCExprContext *ctx, asCExprContext *lctx, asCExpr if( lctx->property_set && lctx->type.isExplicitHandle ) { // set_opIndex has 2 arguments, where as normal setters have only 1 - asCArray& parameterTypes = - builder->GetFunctionDescription(lctx->property_set)->parameterTypes; + asCArray ¶meterTypes = + builder->GetFunctionDescription(lctx->property_set)->parameterTypes; if( !parameterTypes[parameterTypes.GetLength() - 1].IsObjectHandle() ) { // Process the property to free the memory @@ -9907,46 +9908,46 @@ int asCCompiler::DoAssignment(asCExprContext *ctx, asCExprContext *lctx, asCExpr // If a constructor is being compiled, then check if this is the first time a member properties is // assigned, in which case it should be considered an initialization instead of an ordinary assignment - if (engine->ep.memberInitMode == 1 && m_isConstructor) + if( engine->ep.memberInitMode == 1 && m_isConstructor ) { // Is the left expression a member property of this object? // TODO: Should probably have a boolean on asCExprContext to indicate that it is a property, and have it set in CompilerVariableAccess, and then cleared if any pre/post operation is done it asCByteInstruction *instr = lctx->bc.GetFirstInstr(); if( instr && instr->op == asBC_PSF && instr->wArg[0] == 0 && - instr->next && instr->next->op == asBC_RDSPtr && - instr->next->next && instr->next->next->op == asBC_ADDSi && - ((instr->next->next->next && instr->next->next->next->op == asBC_RDSPtr && instr->next->next->next->next == 0) || - (instr->next->next->next && instr->next->next->next->op == asBC_RDSPtr && instr->next->next->next->next && instr->next->next->next->next->op == asBC_PopRPtr && instr->next->next->next->next->next == 0) || - (instr->next->next->next && instr->next->next->next->op == asBC_PopRPtr && instr->next->next->next->next == 0)) ) + instr->next && instr->next->op == asBC_RDSPtr && + instr->next->next && instr->next->next->op == asBC_ADDSi && + ((instr->next->next->next && instr->next->next->next->op == asBC_RDSPtr && instr->next->next->next->next == 0) || + (instr->next->next->next && instr->next->next->next->op == asBC_RDSPtr && instr->next->next->next->next && instr->next->next->next->next->op == asBC_PopRPtr && instr->next->next->next->next->next == 0) || + (instr->next->next->next && instr->next->next->next->op == asBC_PopRPtr && instr->next->next->next->next == 0)) ) { // Which property? - int offset = instr->next->next->wArg[0]; - asCObjectProperty* prop = 0; + int offset = instr->next->next->wArg[0]; + asCObjectProperty *prop = 0; for( asUINT p = 0; p < outFunc->objectType->properties.GetLength(); p++ ) - if (outFunc->objectType->properties[p]->byteOffset == offset) + if( outFunc->objectType->properties[p]->byteOffset == offset ) { prop = outFunc->objectType->properties[p]; break; } // Cannot initialize inherited properties, as those will be initialized by base class - if ( !(prop && prop->isInherited) ) + if( !(prop && prop->isInherited) ) { // Verify if the property has already been initialized in this constructor // If not already initialized then add it to the m_initializedProperties, and // then compile the assignment as initialization instead of a normal assignment // TODO: Need to keep track of the code path, as the initialization may have been in a different if-else scope - if (prop && m_initializedProperties.IndexOf(prop) < 0) + if( prop && m_initializedProperties.IndexOf(prop) < 0 ) { m_initializedProperties.PushLast(prop); // Give an error if the initialization is happening inside a loop or switch statement - if (continueLabels.GetLength() > 0) + if( continueLabels.GetLength() > 0 ) { // If a continue label is set we are in a loop Error(TXT_CANNOT_INIT_MEMBERS_IN_LOOPS, opNode); } - else if (breakLabels.GetLength() > 0) + else if( breakLabels.GetLength() > 0 ) { // TODO: Should eventually allow initialization in switch statements // If a break label is set we are either in a loop or a switch statements @@ -9954,8 +9955,8 @@ int asCCompiler::DoAssignment(asCExprContext *ctx, asCExprContext *lctx, asCExpr } // Give an error if the member has been accessed before - asSMapNode* node; - if (m_propertyAccessCount.MoveTo(&node, prop) && node->value > 1) + asSMapNode *node; + if( m_propertyAccessCount.MoveTo(&node, prop) && node->value > 1 ) { asCString msg; msg.Format(TXT_MEMBER_s_ACCESSED_BEFORE_INIT, prop->name.AddressOf()); @@ -9963,7 +9964,7 @@ int asCCompiler::DoAssignment(asCExprContext *ctx, asCExprContext *lctx, asCExpr } // Give error if a return has already been compiled - if (m_hasReturned) + if( m_hasReturned ) Error(TXT_ALL_CODE_PATHS_MUST_INIT_MEMBER, opNode); asQWORD constantValue; @@ -10050,7 +10051,7 @@ int asCCompiler::DoAssignment(asCExprContext *ctx, asCExprContext *lctx, asCExpr // Make sure the right hand value is a handle if( !rctx->type.isExplicitHandle && - !(rctx->type.dataType.GetTypeInfo() && (rctx->type.dataType.GetTypeInfo()->flags & asOBJ_ASHANDLE)) ) + !(rctx->type.dataType.GetTypeInfo() && (rctx->type.dataType.GetTypeInfo()->flags & asOBJ_ASHANDLE)) ) { // Function names can be considered handles already if( rctx->methodName == "" ) @@ -10069,7 +10070,7 @@ int asCCompiler::DoAssignment(asCExprContext *ctx, asCExprContext *lctx, asCExpr } } - if (!rctx->type.dataType.IsObjectHandle() && !rctx->type.dataType.SupportHandles()) + if( !rctx->type.dataType.IsObjectHandle() && !rctx->type.dataType.SupportHandles() ) { Error(TXT_OBJECT_HANDLE_NOT_SUPPORTED, rexpr); return -1; @@ -10099,7 +10100,7 @@ int asCCompiler::DoAssignment(asCExprContext *ctx, asCExprContext *lctx, asCExpr dt.MakeReference(false); int r = PrepareArgument(&dt, rctx, rexpr, false, asTM_INREF, true); - if (r < 0) return r; + if( r < 0 ) return r; if( !dt.IsEqualExceptRefAndConst(rctx->type.dataType) ) { asCString str; @@ -10111,7 +10112,7 @@ int asCCompiler::DoAssignment(asCExprContext *ctx, asCExprContext *lctx, asCExpr MergeExprBytecode(ctx, rctx); MergeExprBytecode(ctx, lctx); - if(!rctx->type.isRefSafe) + if( !rctx->type.isRefSafe ) ctx->bc.InstrWORD(asBC_GETOBJREF, AS_PTR_SIZE); PerformAssignment(&lctx->type, &rctx->type, &ctx->bc, opNode); @@ -10142,12 +10143,12 @@ int asCCompiler::DoAssignment(asCExprContext *ctx, asCExprContext *lctx, asCExpr // TODO: It must be possible to register specific types that should be allowed to be treated as lvalue even if they are temporary // These can for example be used by types that are really proxies for more complex types. When it is possible to do so // I can reintroduce this check to prevent accidental bugs with assigning value to temporary objects - if (lctx->type.dataType.IsObject() && !lctx->type.dataType.IsObjectHandle()) + if( lctx->type.dataType.IsObject() && !lctx->type.dataType.IsObjectHandle() ) { lctx->type.isLValue = true; } - - if (!lctx->type.isLValue) + + if( !lctx->type.isLValue ) { Error(TXT_NOT_LVALUE, lexpr); return -1; @@ -10188,20 +10189,20 @@ int asCCompiler::DoAssignment(asCExprContext *ctx, asCExprContext *lctx, asCExpr bool needConversion = false; if( !lctx->type.dataType.IsEqualExceptRefAndConst(rctx->type.dataType) ) needConversion = true; - + if( !simpleExpr || needConversion ) { - if( rctx->type.dataType.IsObjectHandle() && !rctx->type.isExplicitHandle && + if( rctx->type.dataType.IsObjectHandle() && !rctx->type.isExplicitHandle && !lctx->type.dataType.IsObjectHandle() && rctx->type.dataType.GetTypeInfo() == lctx->type.dataType.GetTypeInfo() ) { - // Make the conversion from handle to non-handle without creating + // Make the conversion from handle to non-handle without creating // a copy of the object (otherwise done by PrepareArgument) asCDataType dt = rctx->type.dataType; dt.MakeHandle(false); ImplicitConversion(rctx, dt, rexpr, asIC_IMPLICIT_CONV); needConversion = false; } - + asCDataType dt = lctx->type.dataType; dt.MakeReference(true); // A funcdef can be accessed by ref, but only as read-only @@ -10264,8 +10265,8 @@ int asCCompiler::CompileAssignment(asCScriptNode *expr, asCExprContext *ctx) { // Compile the two expression terms asCExprContext lctx(engine), rctx(engine); - int rr = CompileAssignment(lexpr->next->next, &rctx); - int lr = CompileCondition(lexpr, &lctx); + int rr = CompileAssignment(lexpr->next->next, &rctx); + int lr = CompileCondition(lexpr, &lctx); if( lr >= 0 && rr >= 0 ) return DoAssignment(ctx, &lctx, &rctx, lexpr, lexpr->next->next, lexpr->next->tokenType, lexpr->next); @@ -10287,22 +10288,22 @@ int asCCompiler::CompileCondition(asCScriptNode *expr, asCExprContext *ctx) if( cexpr->next ) { ctx->exprNode = expr; - + //------------------------------- // Compile the condition asCExprContext e(engine); - int r = CompileExpression(cexpr, &e); + int r = CompileExpression(cexpr, &e); if( r < 0 ) e.type.SetConstantB(asCDataType::CreatePrimitive(ttBool, true), true); - if (ProcessPropertyGetAccessor(&e, cexpr) < 0) + if( ProcessPropertyGetAccessor(&e, cexpr) < 0 ) return -1; // If turned on, allow the compiler to use either 'bool opImplConv()' or 'bool opConv()' on the type - if (engine->ep.boolConversionMode == 1) + if( engine->ep.boolConversionMode == 1 ) ImplicitConversion(&e, asCDataType::CreatePrimitive(ttBool, false), cexpr, asIC_EXPLICIT_VAL_CAST); // else, allow value types to be converted to bool using 'bool opImplConv()' - else if (e.type.dataType.GetTypeInfo() && (e.type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE)) + else if( e.type.dataType.GetTypeInfo() && (e.type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE) ) ImplicitConversion(&e, asCDataType::CreatePrimitive(ttBool, false), cexpr, asIC_IMPLICIT_CONV); if( r >= 0 && !e.type.dataType.IsEqualExceptRefAndConst(asCDataType::CreatePrimitive(ttBool, true)) ) @@ -10320,7 +10321,7 @@ int asCCompiler::CompileCondition(asCScriptNode *expr, asCExprContext *ctx) //------------------------------- // Compile the left expression asCExprContext le(engine); - int lr = CompileAssignment(cexpr->next, &le); + int lr = CompileAssignment(cexpr->next, &le); // Resolve any function names already DetermineSingleFunc(&le, cexpr->next); @@ -10328,34 +10329,34 @@ int asCCompiler::CompileCondition(asCScriptNode *expr, asCExprContext *ctx) //------------------------------- // Compile the right expression asCExprContext re(engine); - int rr = CompileAssignment(cexpr->next->next, &re); + int rr = CompileAssignment(cexpr->next->next, &re); DetermineSingleFunc(&re, cexpr->next->next); - if (lr >= 0 && rr >= 0) + if( lr >= 0 && rr >= 0 ) { // Don't allow any operators on expressions that take address of class method - if (le.IsClassMethod() || re.IsClassMethod()) + if( le.IsClassMethod() || re.IsClassMethod() ) { Error(TXT_INVALID_OP_ON_METHOD, expr); return -1; } - if (ProcessPropertyGetAccessor(&le, cexpr->next) < 0) + if( ProcessPropertyGetAccessor(&le, cexpr->next) < 0 ) return -1; - if (ProcessPropertyGetAccessor(&re, cexpr->next->next) < 0) + if( ProcessPropertyGetAccessor(&re, cexpr->next->next) < 0 ) return -1; bool isExplicitHandle = le.type.isExplicitHandle || re.type.isExplicitHandle; // Allow an anonymous initialization list to be converted to the type in the other condition - if (le.IsAnonymousInitList() && re.type.dataType.GetBehaviour() && re.type.dataType.GetBehaviour()->listFactory) + if( le.IsAnonymousInitList() && re.type.dataType.GetBehaviour() && re.type.dataType.GetBehaviour()->listFactory ) { asCDataType to = re.type.dataType; to.MakeReference(false); to.MakeReadOnly(false); ImplicitConversion(&le, to, cexpr->next, asIC_IMPLICIT_CONV); } - else if (re.IsAnonymousInitList() && le.type.dataType.GetBehaviour() && le.type.dataType.GetBehaviour()->listFactory) + else if( re.IsAnonymousInitList() && le.type.dataType.GetBehaviour() && le.type.dataType.GetBehaviour()->listFactory ) { asCDataType to = le.type.dataType; to.MakeReference(false); @@ -10363,12 +10364,12 @@ int asCCompiler::CompileCondition(asCScriptNode *expr, asCExprContext *ctx) ImplicitConversion(&re, to, cexpr->next->next, asIC_IMPLICIT_CONV); } - if (le.IsAnonymousInitList()) + if( le.IsAnonymousInitList() ) { Error(TXT_CANNOT_RESOLVE_AUTO, cexpr->next); return -1; } - else if (re.IsAnonymousInitList()) + else if( re.IsAnonymousInitList() ) { Error(TXT_CANNOT_RESOLVE_AUTO, cexpr->next->next); return -1; @@ -10376,29 +10377,29 @@ int asCCompiler::CompileCondition(asCScriptNode *expr, asCExprContext *ctx) // Try to perform an implicit cast to make the two operands of the same type // Choose the conversion that is the least costly - if (le.type.dataType != re.type.dataType) + if( le.type.dataType != re.type.dataType ) { asCExprContext tmp(engine); tmp.type = le.type; tmp.type.dataType.MakeReference(false); asUINT costAtoB = ImplicitConversion(&tmp, re.type.dataType, cexpr->next, asIC_IMPLICIT_CONV, false); - if (!tmp.type.dataType.IsEqualExceptRef(re.type.dataType)) + if( !tmp.type.dataType.IsEqualExceptRef(re.type.dataType) ) costAtoB = 0xFFFFFFFF; tmp.type = re.type; tmp.type.dataType.MakeReference(false); asUINT costBtoA = ImplicitConversion(&tmp, le.type.dataType, cexpr->next->next, asIC_IMPLICIT_CONV, false); - if (!tmp.type.dataType.IsEqualExceptRef(le.type.dataType)) + if( !tmp.type.dataType.IsEqualExceptRef(le.type.dataType) ) costBtoA = 0xFFFFFFFF; - if (costAtoB < costBtoA && costAtoB != 0xFFFFFFFF) + if( costAtoB < costBtoA && costAtoB != 0xFFFFFFFF ) { - if (le.type.dataType.IsObject()) + if( le.type.dataType.IsObject() ) Dereference(&le, true); else ConvertToVariable(&le); ImplicitConversion(&le, re.type.dataType, cexpr->next, asIC_IMPLICIT_CONV, true); } - else if (costAtoB > costBtoA && costBtoA != 0xFFFFFFFF) + else if( costAtoB > costBtoA && costBtoA != 0xFFFFFFFF ) { if( re.type.dataType.IsObject() ) Dereference(&re, true); @@ -10407,19 +10408,19 @@ int asCCompiler::CompileCondition(asCScriptNode *expr, asCExprContext *ctx) ImplicitConversion(&re, le.type.dataType, cexpr->next->next, asIC_IMPLICIT_CONV, true); } - // If the cost for conversion is the same in both directions we have an ambigious situation, + // If the cost for conversion is the same in both directions we have an ambigious situation, // which we do not resolve. In that case the script need to perform an explicit conversion } // Allow a 0 to be implicitly converted to the other type - if (le.type.isConstant && le.type.GetConstantData() == 0 && le.type.dataType.IsIntegerType()) + if( le.type.isConstant && le.type.GetConstantData() == 0 && le.type.dataType.IsIntegerType() ) { asCDataType to = re.type.dataType; to.MakeReference(false); to.MakeReadOnly(true); ImplicitConversionConstant(&le, to, cexpr->next, asIC_IMPLICIT_CONV); } - else if( re.type.isConstant && re.type.GetConstantData() == 0 && re.type.dataType.IsIntegerType()) + else if( re.type.isConstant && re.type.GetConstantData() == 0 && re.type.dataType.IsIntegerType() ) { asCDataType to = le.type.dataType; to.MakeReference(false); @@ -10428,13 +10429,13 @@ int asCCompiler::CompileCondition(asCScriptNode *expr, asCExprContext *ctx) } // Allow expression to be converted to handle if the other is handle - if (!le.type.dataType.IsObjectHandle() && re.type.dataType.IsObjectHandle() && le.type.dataType.GetTypeInfo() == re.type.dataType.GetTypeInfo() ) + if( !le.type.dataType.IsObjectHandle() && re.type.dataType.IsObjectHandle() && le.type.dataType.GetTypeInfo() == re.type.dataType.GetTypeInfo() ) { asCDataType dt = le.type.dataType; dt.MakeHandle(true); ImplicitConversion(&le, dt, cexpr->next, asIC_IMPLICIT_CONV); } - if (!re.type.dataType.IsObjectHandle() && le.type.dataType.IsObjectHandle() && le.type.dataType.GetTypeInfo() == re.type.dataType.GetTypeInfo()) + if( !re.type.dataType.IsObjectHandle() && le.type.dataType.IsObjectHandle() && le.type.dataType.GetTypeInfo() == re.type.dataType.GetTypeInfo() ) { asCDataType dt = re.type.dataType; dt.MakeHandle(true); @@ -10442,7 +10443,7 @@ int asCCompiler::CompileCondition(asCScriptNode *expr, asCExprContext *ctx) } // If the type of the expressions can be handle, then make them so for efficiency - if (le.type.dataType.SupportHandles() && re.type.dataType.SupportHandles()) + if( le.type.dataType.SupportHandles() && re.type.dataType.SupportHandles() ) { asCDataType dt = le.type.dataType; dt.MakeHandle(true); @@ -10460,7 +10461,7 @@ int asCCompiler::CompileCondition(asCScriptNode *expr, asCExprContext *ctx) } // Make sure both expressions have the same type - if (!le.type.dataType.IsEqualExceptRefAndConst(re.type.dataType)) + if( !le.type.dataType.IsEqualExceptRefAndConst(re.type.dataType) ) { Error(TXT_BOTH_MUST_BE_SAME, expr); return -1; @@ -10469,7 +10470,7 @@ int asCCompiler::CompileCondition(asCScriptNode *expr, asCExprContext *ctx) //--------------------------------- // Output the byte code int afterLabel = nextLabel++; - int elseLabel = nextLabel++; + int elseLabel = nextLabel++; // If left expression is void, then we don't need to store the result if( le.type.dataType.IsEqualExceptConst(asCDataType::CreatePrimitive(ttVoid, false)) ) @@ -10497,7 +10498,7 @@ int asCCompiler::CompileCondition(asCScriptNode *expr, asCExprContext *ctx) // Set the type of the result ctx->type = le.type; } - else if (le.type.IsNullConstant() && re.type.IsNullConstant()) + else if( le.type.IsNullConstant() && re.type.IsNullConstant() ) { // Special case for when both results are 'null' // TODO: Other expressions where both results are identical literal constants can probably also be handled this way @@ -10534,9 +10535,9 @@ int asCCompiler::CompileCondition(asCScriptNode *expr, asCExprContext *ctx) // with a stack offset (i.e. it will not be allowed to use asBC_VAR) if( le.type.isLValue && re.type.isLValue && - le.deferredParams.GetLength() == 0 && re.deferredParams.GetLength() == 0 && - !le.type.isTemporary && !re.type.isTemporary && - le.type.dataType == re.type.dataType ) + le.deferredParams.GetLength() == 0 && re.deferredParams.GetLength() == 0 && + !le.type.isTemporary && !re.type.isTemporary && + le.type.dataType == re.type.dataType ) { // Put the code for the condition expression on the output MergeExprBytecode(ctx, &e); @@ -10589,7 +10590,7 @@ int asCCompiler::CompileCondition(asCScriptNode *expr, asCExprContext *ctx) ctx->type.dataType.MakeReference(false); // It can't be a treated as a variable, since we don't know which one was used - ctx->type.isVariable = false; + ctx->type.isVariable = false; ctx->type.isTemporary = false; // Must remember if the reference was to a local variable, since it must not be allowed to be returned @@ -10683,7 +10684,7 @@ int asCCompiler::CompileCondition(asCScriptNode *expr, asCExprContext *ctx) ctx->bc.Label((short)afterLabel); // Set the temporary variable as output - ctx->type = rtemp; + ctx->type = rtemp; ctx->type.isExplicitHandle = isExplicitHandle; if( !ctx->type.dataType.IsPrimitive() ) @@ -10728,8 +10729,8 @@ void asCCompiler::ConvertToPostFix(asCScriptNode *expr, asCArrayfirstChild; + int count = 0; + asCScriptNode *node = expr->firstChild; while( node ) { count++; @@ -10746,7 +10747,7 @@ void asCCompiler::ConvertToPostFix(asCScriptNode *expr, asCArray 0 && - precedence <= GetPrecedence(stackA[stackA.GetLength()-1]) ) + precedence <= GetPrecedence(stackA[stackA.GetLength() - 1]) ) stackB.PushLast(stackA.PopLast()); stackA.PushLast(node); @@ -10768,9 +10769,9 @@ int asCCompiler::CompilePostFixExpression(asCArray *postfix, as ctx->type.SetDummy(); // Evaluate the operands and operators - asCArray free; - asCArray expr; - int ret = 0; + asCArray free; + asCArray expr; + int ret = 0; for( asUINT n = 0; ret == 0 && n < postfix->GetLength(); n++ ) { asCScriptNode *node = (*postfix)[n]; @@ -10779,7 +10780,7 @@ int asCCompiler::CompilePostFixExpression(asCArray *postfix, as asCExprContext *e = free.GetLength() ? free.PopLast() : asNEW(asCExprContext)(engine); expr.PushLast(e); e->exprNode = node; - ret = CompileExpressionTerm(node, e); + ret = CompileExpressionTerm(node, e); } else { @@ -10788,7 +10789,7 @@ int asCCompiler::CompilePostFixExpression(asCArray *postfix, as // Now compile the operator asCExprContext *e = free.GetLength() ? free.PopLast() : asNEW(asCExprContext)(engine); - ret = CompileOperator(node, l, r, e); + ret = CompileOperator(node, l, r, e); expr.PushLast(e); @@ -10822,8 +10823,8 @@ int asCCompiler::CompileAnonymousInitList(asCScriptNode *node, asCExprContext *c asASSERT(node->nodeType == snInitList); // Do not allow constructing non-shared types in shared functions - if (outFunc->IsShared() && - dt.GetTypeInfo() && !dt.GetTypeInfo()->IsShared()) + if( outFunc->IsShared() && + dt.GetTypeInfo() && !dt.GetTypeInfo()->IsShared() ) { asCString msg; msg.Format(TXT_SHARED_CANNOT_USE_NON_SHARED_TYPE_s, dt.GetTypeInfo()->name.AddressOf()); @@ -10832,7 +10833,7 @@ int asCCompiler::CompileAnonymousInitList(asCScriptNode *node, asCExprContext *c // If this is compiled from a default arg, then use the script code for the default arg asCScriptCode *origCode = script; - if (ctx->origCode) + if( ctx->origCode ) script = ctx->origCode; // Allocate and initialize the temporary object @@ -10846,13 +10847,13 @@ int asCCompiler::CompileAnonymousInitList(asCScriptNode *node, asCExprContext *c // If the variable is allocated on the heap we have a reference, // otherwise the actual object pointer is pushed on the stack. - if (IsVariableOnHeap(offset)) + if( IsVariableOnHeap(offset) ) ctx->type.dataType.MakeReference(true); // Clear the flag for anonymous initalization list as it is no // longer true now that the object has been initialized. ctx->isAnonymousInitList = false; - ctx->origCode = 0; + ctx->origCode = 0; script = origCode; @@ -10865,16 +10866,16 @@ int asCCompiler::CompileExpressionTerm(asCScriptNode *node, asCExprContext *ctx) asASSERT(ctx->bc.GetLastInstr() == -1); // Check if this is an initialization of a temp object with an initialization list - if (node->firstChild ) + if( node->firstChild ) { - if (node->firstChild->nodeType == snDataType) + if( node->firstChild->nodeType == snDataType ) { // Determine the type of the temporary object asCDataType dt = builder->CreateDataTypeFromNode(node->firstChild, script, outFunc->nameSpace, false, 0, true, 0, 0, &m_namespaceVisibility); return CompileAnonymousInitList(node->lastChild, ctx, dt); } - else if (node->firstChild->nodeType == snInitList) + else if( node->firstChild->nodeType == snInitList ) { // As the type is not yet known, the init list will be compiled at a // later time when the type can be determined from the destination @@ -10895,16 +10896,16 @@ int asCCompiler::CompileExpressionTerm(asCScriptNode *node, asCExprContext *ctx) return -1; asCExprContext v(engine); - int r = CompileExpressionValue(vnode, &v); - if( r < 0 ) + int r = CompileExpressionValue(vnode, &v); + if( r < 0 ) return r; // Compile post fix operators asCScriptNode *pnode = vnode->next; while( pnode ) { - r = CompileExpressionPostOp(pnode, &v); - if( r < 0 ) + r = CompileExpressionPostOp(pnode, &v); + if( r < 0 ) return r; pnode = pnode->next; } @@ -10913,8 +10914,8 @@ int asCCompiler::CompileExpressionTerm(asCScriptNode *node, asCExprContext *ctx) pnode = vnode->prev; while( pnode ) { - r = CompileExpressionPreOp(pnode, &v); - if( r < 0 ) + r = CompileExpressionPreOp(pnode, &v); + if( r < 0 ) return r; pnode = pnode->prev; } @@ -10932,11 +10933,11 @@ int asCCompiler::CompileExpressionTerm(asCScriptNode *node, asCExprContext *ctx) asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookupLocalVar(const asCString &name, asCExprContext *outResult) { sVariable *v = 0; - if (variables) + if( variables ) v = variables->GetVariable(name.AddressOf()); - if (v) + if( v ) { - if (v->isPureConstant) + if( v->isPureConstant ) { outResult->type.SetConstantData(v->type, v->constantValue); return SL_LOCALCONST; @@ -10966,13 +10967,13 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookupMember(const asCString &name, a // Indexed property access asCExprContext dummyArg(engine); r = FindPropertyAccessor(name, &access, &dummyArg, 0, 0, true); - if (r == 0) + if( r == 0 ) { // Normal property access r = FindPropertyAccessor(name, &access, 0, 0, true); } - if (r <= -3) return SL_ERROR; - if (r != 0) + if( r <= -3 ) return SL_ERROR; + if( r != 0 ) { // The symbol matches getters/setters (though not necessarily a compilable match) MergeExprBytecodeAndType(outResult, &access); @@ -10982,9 +10983,9 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookupMember(const asCString &name, a // Look for matching properties asCDataType dt; - dt = asCDataType::CreateType(objType, false); + dt = asCDataType::CreateType(objType, false); asCObjectProperty *prop = builder->GetObjectProperty(dt, name.AddressOf()); - if (prop) + if( prop ) { outResult->type.dataType.SetTypeInfo(objType); return SL_CLASSPROP; @@ -10992,11 +10993,11 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookupMember(const asCString &name, a // If it is not a property, it may still be the name of a method asCObjectType *ot = objType; - for (asUINT n = 0; n < ot->methods.GetLength(); n++) + for( asUINT n = 0; n < ot->methods.GetLength(); n++ ) { asCScriptFunction *f = engine->scriptFunctions[ot->methods[n]]; - if (f->name == name && - (builder->module->m_accessMask & f->accessMask)) + if( f->name == name && + (builder->module->m_accessMask & f->accessMask) ) { outResult->type.dataType.SetTypeInfo(objType); return SL_CLASSMETHOD; @@ -11004,9 +11005,9 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookupMember(const asCString &name, a } // If it is not a method, then it can still be a child type - for (asUINT n = 0; n < ot->childFuncDefs.GetLength(); n++) + for( asUINT n = 0; n < ot->childFuncDefs.GetLength(); n++ ) { - if (ot->childFuncDefs[n]->name == name) + if( ot->childFuncDefs[n]->name == name ) { outResult->type.dataType.SetTypeInfo(objType); return SL_CLASSTYPE; @@ -11016,9 +11017,9 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookupMember(const asCString &name, a return SL_NOMATCH; } -bool asCCompiler::isAmbiguousSymbol(const asCString &name, asCScriptNode* errNode, SYMBOLTYPE& currentType, SYMBOLTYPE nextType) +bool asCCompiler::isAmbiguousSymbol(const asCString &name, asCScriptNode *errNode, SYMBOLTYPE ¤tType, SYMBOLTYPE nextType) { - if (currentType != SL_NOMATCH && currentType != nextType) + if( currentType != SL_NOMATCH && currentType != nextType ) { asCString msg; msg.Format(TXT_AMBIGUOUS_SYMBOL_NAME_s, name.AddressOf()); @@ -11053,24 +11054,24 @@ bool asCCompiler::isAmbiguousSymbol(const asCString &name, asCScriptNode* errNod // SL_GLOBALTYPE = type, lookupResult->dataType holds the type // SL_ENUMVAL = enum value, lookupResult->dataType holds the enum type, unless ambigious. lookupResult->symbolNamespace holds the namespace where the symbol was identified // SL_ERROR = error -asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookup(const asCString &name, const asCString &scope, asCObjectType *objType, asCExprContext *outResult, asCScriptNode* errNode) +asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookup(const asCString &name, const asCString &scope, asCObjectType *objType, asCExprContext *outResult, asCScriptNode *errNode) { asASSERT(outResult); // It is a local variable or parameter? // This is not accessible by default arg expressions - if (!isCompilingDefaultArg && scope == "" && !objType ) + if( !isCompilingDefaultArg && scope == "" && !objType ) { SYMBOLTYPE r = SymbolLookupLocalVar(name, outResult); - if (r != 0) + if( r != 0 ) return r; } // Is it a class member? - if (scope == "" && ((objType) || (outFunc && outFunc->objectType))) + if( scope == "" && ((objType) || (outFunc && outFunc->objectType)) ) { // 'this' is not accessible by default arg expressions - if (name == THIS_TOKEN && !objType && !isCompilingDefaultArg) + if( name == THIS_TOKEN && !objType && !isCompilingDefaultArg ) { asCDataType dt = asCDataType::CreateType(outFunc->objectType, outFunc->IsReadOnly()); @@ -11080,10 +11081,10 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookup(const asCString &name, const a } // 'super' is not accessible by default arg expressions - if (m_isConstructor && name == SUPER_TOKEN && !objType && !isCompilingDefaultArg) + if( m_isConstructor && name == SUPER_TOKEN && !objType && !isCompilingDefaultArg ) { // If the class is derived from another class, then super can be used to call the base' class constructor - if (outFunc && outFunc->objectType->derivedFrom) + if( outFunc && outFunc->objectType->derivedFrom ) { outResult->type.dataType.SetTypeInfo(outFunc->objectType->derivedFrom); return SL_CLASSMETHOD; @@ -11091,26 +11092,26 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookup(const asCString &name, const a } // Look for members in the type - // class members are only accessible in default arg expressions as post op '.' + // class members are only accessible in default arg expressions as post op '.' if( !isCompilingDefaultArg || (isCompilingDefaultArg && objType) ) { SYMBOLTYPE r = SymbolLookupMember(name, objType ? objType : outFunc->objectType, outResult); - if (r != 0) + if( r != 0 ) return r; } } // Recursively search parent namespaces for global entities - asCArray pendingNamespaces = m_namespaceVisibility; - asCArray visitedNamespaces; - asSNameSpace *currNamespace = DetermineNameSpace(""); - SYMBOLTYPE resultSymbolType = SL_NOMATCH; - + asCArray pendingNamespaces = m_namespaceVisibility; + asCArray visitedNamespaces; + asSNameSpace *currNamespace = DetermineNameSpace(""); + SYMBOLTYPE resultSymbolType = SL_NOMATCH; + bool checkAmbiguousSymbols = currNamespace == engine->nameSpaces[0]; // Keep track of the parent namespace - asSNameSpace* parentNamespace = engine->GetParentNameSpace(currNamespace); - + asSNameSpace *parentNamespace = engine->GetParentNameSpace(currNamespace); + while( !objType && currNamespace ) { if( !visitedNamespaces.Exists(currNamespace) ) @@ -11120,26 +11121,26 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookup(const asCString &name, const a // If the scope contains ::identifier, then use the last identifier as the class name and the rest of it as the namespace // TODO: child funcdef: A scope can include a template type, e.g. array - int n = currScope.FindLast("::"); + int n = currScope.FindLast("::"); asCString typeName = n >= 0 ? currScope.SubString(n + 2) : currScope; - asCString nsName = n >= 0 ? currScope.SubString(0, n) : asCString(""); + asCString nsName = n >= 0 ? currScope.SubString(0, n) : asCString(""); // If the scope represents a type that the current class inherits // from then that should be used instead of going through the namespaces - if (nsName == "" && (outFunc && outFunc->objectType)) + if( nsName == "" && (outFunc && outFunc->objectType) ) { - asCObjectType* ot = outFunc->objectType; - while (ot) + asCObjectType *ot = outFunc->objectType; + while( ot ) { - if (ot->name == typeName) + if( ot->name == typeName ) { SYMBOLTYPE r = SymbolLookupMember(name, ot, outResult); - if (r != 0) + if( r != 0 ) { - if (!checkAmbiguousSymbols) + if( !checkAmbiguousSymbols ) return r; - if (isAmbiguousSymbol(name, errNode, resultSymbolType, r)) + if( isAmbiguousSymbol(name, errNode, resultSymbolType, r) ) return SL_ERROR; } } @@ -11149,11 +11150,11 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookup(const asCString &name, const a } // If the scope starts with :: then search from the global scope - if (currScope.GetLength() < 2 || currScope[0] != ':') + if( currScope.GetLength() < 2 || currScope[0] != ':' ) { - if (nsName != "") + if( nsName != "" ) { - if (currNamespace->name != "") + if( currNamespace->name != "" ) nsName = currNamespace->name + "::" + nsName; } else @@ -11163,51 +11164,51 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookup(const asCString &name, const a nsName = nsName.SubString(2); // Get the namespace for this scope - asSNameSpace* ns = engine->FindNameSpace(nsName.AddressOf()); - if (ns) + asSNameSpace *ns = engine->FindNameSpace(nsName.AddressOf()); + if( ns ) { // Is there a type with typeName in the namespace? - asCTypeInfo* scopeType = builder->GetType(typeName.AddressOf(), ns, 0); + asCTypeInfo *scopeType = builder->GetType(typeName.AddressOf(), ns, 0); // Check if the symbol is a member of that type - if (scopeType) + if( scopeType ) { // Is it an object type? - if (CastToObjectType(scopeType)) + if( CastToObjectType(scopeType) ) { SYMBOLTYPE r = SymbolLookupMember(name, CastToObjectType(scopeType), outResult); - if (r != 0) + if( r != 0 ) { - if (!checkAmbiguousSymbols) + if( !checkAmbiguousSymbols ) return r; - if (isAmbiguousSymbol(name, errNode, resultSymbolType, r)) + if( isAmbiguousSymbol(name, errNode, resultSymbolType, r) ) return SL_ERROR; } } // Is it an enum type? - if (CastToEnumType(scopeType)) + if( CastToEnumType(scopeType) ) { - asINT64 value = 0; + asINT64 value = 0; asCDataType dt; - if (builder->GetEnumValueFromType(CastToEnumType(scopeType), name.AddressOf(), dt, value)) + if( builder->GetEnumValueFromType(CastToEnumType(scopeType), name.AddressOf(), dt, value) ) { - if (isAmbiguousSymbol(name, errNode, resultSymbolType, SL_ENUMVAL)) + if( isAmbiguousSymbol(name, errNode, resultSymbolType, SL_ENUMVAL) ) return SL_ERROR; // an enum value was resolved - if (dt.GetSizeInMemoryBytes() == 1) + if( dt.GetSizeInMemoryBytes() == 1 ) outResult->type.SetConstantB(dt, asBYTE(value)); - else if (dt.GetSizeInMemoryBytes() == 2) + else if( dt.GetSizeInMemoryBytes() == 2 ) outResult->type.SetConstantW(dt, asWORD(value)); - else if (dt.GetSizeInMemoryBytes() == 4) + else if( dt.GetSizeInMemoryBytes() == 4 ) outResult->type.SetConstantDW(dt, asDWORD(value)); else outResult->type.SetConstantQW(dt, value); outResult->symbolNamespace = ns; - if (!checkAmbiguousSymbols) + if( !checkAmbiguousSymbols ) return resultSymbolType; } } @@ -11218,11 +11219,11 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookup(const asCString &name, const a nsName = currScope; // If the scope starts with :: then search from the global scope - if (currScope.GetLength() < 2 || currScope[0] != ':') + if( currScope.GetLength() < 2 || currScope[0] != ':' ) { - if (nsName != "") + if( nsName != "" ) { - if (currNamespace->name != "") + if( currNamespace->name != "" ) nsName = currNamespace->name + "::" + nsName; } else @@ -11234,68 +11235,68 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookup(const asCString &name, const a ns = engine->FindNameSpace(nsName.AddressOf()); // Is it a global property? - if (ns) + if( ns ) { // See if there are any matching global property accessors asCExprContext access(engine); - int r = 0; + int r = 0; // Indexed property access asCExprContext dummyArg(engine); r = FindPropertyAccessor(name, &access, &dummyArg, 0, ns); - if (r == 0) + if( r == 0 ) { // Normal property access r = FindPropertyAccessor(name, &access, 0, ns); } - if (r <= -3) return SL_ERROR; - if (r != 0) + if( r <= -3 ) return SL_ERROR; + if( r != 0 ) { - if (isAmbiguousSymbol(name, errNode, resultSymbolType, SL_GLOBALPROPACCESS)) + if( isAmbiguousSymbol(name, errNode, resultSymbolType, SL_GLOBALPROPACCESS) ) return SL_ERROR; // The symbol matches getters/setters (though not necessarily a compilable match) MergeExprBytecodeAndType(outResult, &access); outResult->symbolNamespace = ns; - if (!checkAmbiguousSymbols) + if( !checkAmbiguousSymbols ) return resultSymbolType; } // Property accessors hides real properties of the same name - if (resultSymbolType != SL_GLOBALPROPACCESS) + if( resultSymbolType != SL_GLOBALPROPACCESS ) { // See if there is any matching global property - bool isCompiled = true; - bool isPureConstant = false; - bool isAppProp = false; - asQWORD constantValue = 0; - asCGlobalProperty* prop = builder->GetGlobalProperty(name.AddressOf(), ns, &isCompiled, &isPureConstant, &constantValue, &isAppProp); - if (prop) + bool isCompiled = true; + bool isPureConstant = false; + bool isAppProp = false; + asQWORD constantValue = 0; + asCGlobalProperty *prop = builder->GetGlobalProperty(name.AddressOf(), ns, &isCompiled, &isPureConstant, &constantValue, &isAppProp); + if( prop ) { // If the global property is a pure constant // we can allow the compiler to optimize it. Pure // constants are global constant variables that were // initialized by literal constants. - if (isPureConstant) + if( isPureConstant ) { - if (isAmbiguousSymbol(name, errNode, resultSymbolType, SL_GLOBALCONST)) + if( isAmbiguousSymbol(name, errNode, resultSymbolType, SL_GLOBALCONST) ) return SL_ERROR; outResult->type.SetConstantData(prop->type, constantValue); outResult->symbolNamespace = ns; - if (!checkAmbiguousSymbols) + if( !checkAmbiguousSymbols ) return resultSymbolType; } else { - if (isAmbiguousSymbol(name, errNode, resultSymbolType, SL_GLOBALVAR)) + if( isAmbiguousSymbol(name, errNode, resultSymbolType, SL_GLOBALVAR) ) return SL_ERROR; outResult->type.Set(prop->type); outResult->symbolNamespace = ns; - if (!checkAmbiguousSymbols) + if( !checkAmbiguousSymbols ) return resultSymbolType; } } @@ -11303,29 +11304,29 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookup(const asCString &name, const a } // Is it the name of a global function? - if (ns) + if( ns ) { asCArray funcs; builder->GetFunctionDescriptions(name.AddressOf(), funcs, ns); - if (funcs.GetLength() > 0) + if( funcs.GetLength() > 0 ) { bool needCreateChild = resultSymbolType != SL_NOMATCH; - if (isAmbiguousSymbol(name, errNode, resultSymbolType, SL_GLOBALFUNC)) + if( isAmbiguousSymbol(name, errNode, resultSymbolType, SL_GLOBALFUNC) ) return SL_ERROR; - if (needCreateChild) + if( needCreateChild ) { outResult->next = asNEW(asCExprContext)(engine); - outResult = outResult->next; + outResult = outResult->next; } // Defer the evaluation of which function until it is actually used // Store the namespace and name of the function for later outResult->type.SetUndefinedFuncHandle(engine); - outResult->methodName = ns ? ns->name + "::" + name : name; + outResult->methodName = ns ? ns->name + "::" + name : name; outResult->symbolNamespace = ns; // TODO: using: Should this have if(!checkAmbiguousSymbols) return resultSymbolType); @@ -11334,33 +11335,33 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookup(const asCString &name, const a } // Check for type names - if (ns) + if( ns ) { - asCTypeInfo* type = builder->GetType(name.AddressOf(), ns, 0); - if (type) + asCTypeInfo *type = builder->GetType(name.AddressOf(), ns, 0); + if( type ) { - if (isAmbiguousSymbol(name, errNode, resultSymbolType, SL_GLOBALTYPE)) + if( isAmbiguousSymbol(name, errNode, resultSymbolType, SL_GLOBALTYPE) ) return SL_ERROR; outResult->type.dataType = asCDataType::CreateType(type, false); - if (!checkAmbiguousSymbols) + if( !checkAmbiguousSymbols ) return resultSymbolType; } } // Is it an enum value? Only do this if a symbol hasn't already been found, since it would hide the enum value - if (ns && !engine->ep.requireEnumScope && resultSymbolType == SL_NOMATCH) + if( ns && !engine->ep.requireEnumScope && resultSymbolType == SL_NOMATCH ) { // Look for the enum value without explicitly informing the enum type - asINT64 value = 0; + asINT64 value = 0; asCDataType dt; - int e = builder->GetEnumValue(name.AddressOf(), dt, value, ns); - if (e) + int e = builder->GetEnumValue(name.AddressOf(), dt, value, ns); + if( e ) { - if (isAmbiguousSymbol(name, errNode, resultSymbolType, SL_ENUMVAL)) + if( isAmbiguousSymbol(name, errNode, resultSymbolType, SL_ENUMVAL) ) return SL_ERROR; - if (e == 2) + if( e == 2 ) { // Ambiguous enum value: Save the name for resolution later. // The ambiguity could be resolved now, but I hesitate @@ -11375,25 +11376,25 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookup(const asCString &name, const a else { // an enum value was resolved - if (dt.GetSizeInMemoryBytes() == 1) + if( dt.GetSizeInMemoryBytes() == 1 ) outResult->type.SetConstantB(dt, asBYTE(value)); - else if (dt.GetSizeInMemoryBytes() == 2) + else if( dt.GetSizeInMemoryBytes() == 2 ) outResult->type.SetConstantW(dt, asWORD(value)); - else if (dt.GetSizeInMemoryBytes() == 4) + else if( dt.GetSizeInMemoryBytes() == 4 ) outResult->type.SetConstantDW(dt, asDWORD(value)); else outResult->type.SetConstantQW(dt, value); outResult->symbolNamespace = ns; } - if (!checkAmbiguousSymbols) + if( !checkAmbiguousSymbols ) return resultSymbolType; } } } // If the given scope starts with '::' then the search starts from global scope - if (scope.GetLength() >= 2 && scope[0] == ':') + if( scope.GetLength() >= 2 && scope[0] == ':' ) break; builder->AddVisibleNamespaces(currNamespace, visitedNamespaces, pendingNamespaces); @@ -11403,10 +11404,10 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookup(const asCString &name, const a // Move up to next namespace currNamespace = builder->FindNextVisibleNamespace(visitedNamespaces, pendingNamespaces, parentNamespace, &checkAmbiguousSymbols); - if (currNamespace == parentNamespace) + if( currNamespace == parentNamespace ) { parentNamespace = engine->GetParentNameSpace(currNamespace); - if (resultSymbolType != SL_NOMATCH) + if( resultSymbolType != SL_NOMATCH ) break; } } @@ -11418,27 +11419,27 @@ asCCompiler::SYMBOLTYPE asCCompiler::SymbolLookup(const asCString &name, const a int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &scope, asCExprContext *ctx, asCScriptNode *errNode, bool isOptional, asCObjectType *objType) { asCExprContext lookupResult(engine); - SYMBOLTYPE symbolType = SymbolLookup(name, scope, objType, &lookupResult, errNode); - if (symbolType < 0) + SYMBOLTYPE symbolType = SymbolLookup(name, scope, objType, &lookupResult, errNode); + if( symbolType < 0 ) { // Give dummy value ctx->type.SetDummy(); return -1; } - if (symbolType == SL_NOMATCH) + if( symbolType == SL_NOMATCH ) { // Give dummy value ctx->type.SetDummy(); - if (!isOptional) + if( !isOptional ) { // No matching symbol asCString msg; asCString smbl; - if (scope == "::") + if( scope == "::" ) smbl = scope; - else if (scope != "") + else if( scope != "" ) smbl = scope + "::"; smbl += name; msg.Format(TXT_NO_MATCHING_SYMBOL_s, smbl.AddressOf()); @@ -11493,7 +11494,7 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s ctx->type.isRefSafe = true; // Set as lvalue unless it is a const variable - if (!v->type.IsReadOnly()) + if( !v->type.IsReadOnly() ) ctx->type.isLValue = true; } @@ -11501,12 +11502,12 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s } // Is it a class member? - if (symbolType == SL_CLASSPROPACCESS || symbolType == SL_CLASSPROP || symbolType == SL_CLASSMETHOD || symbolType == SL_THISPTR) + if( symbolType == SL_CLASSPROPACCESS || symbolType == SL_CLASSPROP || symbolType == SL_CLASSMETHOD || symbolType == SL_THISPTR ) { // This is not accessible by default arg expressions asASSERT(!isCompilingDefaultArg); - if (symbolType == SL_THISPTR) + if( symbolType == SL_THISPTR ) { asASSERT(name == THIS_TOKEN && !objType && scope == ""); asCDataType dt = asCDataType::CreateType(outFunc->objectType, outFunc->IsReadOnly()); @@ -11523,9 +11524,9 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s return 0; } - if (symbolType == SL_CLASSPROPACCESS) + if( symbolType == SL_CLASSPROPACCESS ) { - if (scope != "") + if( scope != "" ) { // Cannot access non-static members like this asCString msg; @@ -11536,30 +11537,30 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s // See if there are any matching property accessors asCExprContext access(engine); - if (objType) + if( objType ) access.type.Set(asCDataType::CreateType(objType, false)); else access.type.Set(asCDataType::CreateType(outFunc->objectType, outFunc->IsReadOnly())); access.type.dataType.MakeReference(true); int r = 0; - if (errNode->next && errNode->next->tokenType == ttOpenBracket) + if( errNode->next && errNode->next->tokenType == ttOpenBracket ) { // This is an index access, check if there is a property accessor that takes an index arg asCExprContext dummyArg(engine); r = FindPropertyAccessor(name, &access, &dummyArg, errNode, 0, true); } - if (r == 0) + if( r == 0 ) { // Normal property access r = FindPropertyAccessor(name, &access, errNode, 0, true); } - if (r < 0) return -1; + if( r < 0 ) return -1; - if (access.property_get == 0 && access.property_set == 0) + if( access.property_get == 0 && access.property_set == 0 ) { // Even though the symbol was identified in SymbolLookup, it doesn't match the arguments asCString msg; - if (errNode->next && errNode->next->tokenType == ttOpenBracket) + if( errNode->next && errNode->next->tokenType == ttOpenBracket ) msg.Format(TXT_PROP_ACCESS_s_DOES_NOT_EXPECT_INDEX, name.AddressOf()); else msg.Format(TXT_PROP_ACCESS_s_EXPECTS_INDEX, name.AddressOf()); @@ -11567,7 +11568,7 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s return -1; } - if (!objType) + if( !objType ) { // Prepare the bytecode for the member access // This is only done when accessing through the implicit this pointer @@ -11578,9 +11579,9 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s return 0; } - if (symbolType == SL_CLASSPROP) + if( symbolType == SL_CLASSPROP ) { - if (scope != "") + if( scope != "" ) { // Cannot access non-static members like this asCString msg; @@ -11590,7 +11591,7 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s } asCDataType dt; - if (objType) + if( objType ) dt = asCDataType::CreateType(objType, false); else dt = asCDataType::CreateType(outFunc->objectType, false); @@ -11598,10 +11599,10 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s asASSERT(prop); // Count the access, so it can be determined if the access happens before initialization in constructors - if (m_isConstructor) + if( m_isConstructor ) { - asSMapNode *node; - if (m_propertyAccessCount.MoveTo(&node, prop)) + asSMapNode *node; + if( m_propertyAccessCount.MoveTo(&node, prop) ) node->value++; else m_propertyAccessCount.Insert(prop, 1); @@ -11609,18 +11610,18 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s // Give error if attempting to access inherited property before the parent constructor is called // This validation will be deferred to later, since it is not known with the parent constructor will // be called implicitly at the beginning of the constructor or explicitly later - if (prop->isInherited && !m_isConstructorCalled) + if( prop->isInherited && !m_isConstructorCalled ) { - asSMapNode *node2; - if (!m_inheritedPropertyAccess.MoveTo(&node2, prop)) + asSMapNode *node2; + if( !m_inheritedPropertyAccess.MoveTo(&node2, prop) ) m_inheritedPropertyAccess.Insert(prop, errNode); } } // Is the property access allowed? - if (prop->isPrivate && prop->isInherited) + if( prop->isPrivate && prop->isInherited ) { - if (engine->ep.privatePropAsProtected) + if( engine->ep.privatePropAsProtected ) { // The application is allowing inherited classes to access private properties of the parent // class. This option is allowed to provide backwards compatibility with pre-2.30.0 versions @@ -11637,7 +11638,7 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s } } - if (!objType) + if( !objType ) { // The object pointer is located at stack position 0 // This is only done when accessing through the implicit this pointer @@ -11651,11 +11652,11 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s // Put the offset on the stack ctx->bc.InstrSHORT_DW(asBC_ADDSi, (short)prop->byteOffset, engine->GetTypeIdFromDataType(dt)); - if (prop->type.IsReference()) + if( prop->type.IsReference() ) ctx->bc.Instr(asBC_RDSPtr); // Reference to primitive must be stored in the temp register - if (prop->type.IsPrimitive()) + if( prop->type.IsPrimitive() ) { // TODO: runtime optimize: The ADD offset command should store the reference in the register directly ctx->bc.Instr(asBC_PopRPtr); @@ -11665,18 +11666,18 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s ctx->type.dataType = prop->type; ctx->type.dataType.MakeReference(true); ctx->type.isVariable = false; - ctx->type.isLValue = true; + ctx->type.isLValue = true; - if (ctx->type.dataType.IsObject() && !ctx->type.dataType.IsObjectHandle()) + if( ctx->type.dataType.IsObject() && !ctx->type.dataType.IsObjectHandle() ) { // Objects that are members are not references ctx->type.dataType.MakeReference(false); // Objects that are members but not handles are safe as long as the parent object is safe - if (!objType || ctx->type.isRefSafe) + if( !objType || ctx->type.isRefSafe ) ctx->type.isRefSafe = true; } - else if (ctx->type.dataType.IsObjectHandle()) + else if( ctx->type.dataType.IsObjectHandle() ) { // Objects accessed through handles cannot be considered safe // as the handle can be cleared at any time @@ -11689,9 +11690,9 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s return 0; } - if (symbolType == SL_CLASSMETHOD) + if( symbolType == SL_CLASSMETHOD ) { - if (scope != "") + if( scope != "" ) { // Cannot access non-static members like this asCString msg; @@ -11700,15 +11701,15 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s return -1; } -#if AS_DEBUG + #if AS_DEBUG // If it is not a property, it may still be the name of a method which can be used to create delegates - asCObjectType *ot = outFunc->objectType; + asCObjectType *ot = outFunc->objectType; asCScriptFunction *func = 0; - for (asUINT n = 0; n < ot->methods.GetLength(); n++) + for( asUINT n = 0; n < ot->methods.GetLength(); n++ ) { asCScriptFunction *f = engine->scriptFunctions[ot->methods[n]]; - if (f->name == name && - (builder->module->m_accessMask & f->accessMask)) + if( f->name == name && + (builder->module->m_accessMask & f->accessMask) ) { func = f; break; @@ -11716,14 +11717,14 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s } asASSERT(func); -#endif + #endif // An object method was found. Keep the name of the method in the expression, but // don't actually modify the bytecode at this point since it is not yet known what // the method will be used for, or even what overloaded method should be used. ctx->methodName = name; // Place the object pointer on the stack, as if the expression was this.func - if (!objType) + if( !objType ) { // The object pointer is located at stack position 0 // This is only done when accessing through the implicit this pointer @@ -11737,34 +11738,34 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s } } - if (symbolType == SL_GLOBALCONST || symbolType == SL_GLOBALPROPACCESS || symbolType == SL_GLOBALVAR || symbolType == SL_GLOBALFUNC || symbolType == SL_ENUMVAL) + if( symbolType == SL_GLOBALCONST || symbolType == SL_GLOBALPROPACCESS || symbolType == SL_GLOBALVAR || symbolType == SL_GLOBALFUNC || symbolType == SL_ENUMVAL ) { // Get the namespace from SymbolLookup asSNameSpace *ns = lookupResult.symbolNamespace; - if (symbolType == SL_GLOBALPROPACCESS) + if( symbolType == SL_GLOBALPROPACCESS ) { // See if there are any matching global property accessors asCExprContext access(engine); - int r = 0; - if (errNode->next && errNode->next->tokenType == ttOpenBracket) + int r = 0; + if( errNode->next && errNode->next->tokenType == ttOpenBracket ) { // This is an index access, check if there is a property accessor that takes an index arg asCExprContext dummyArg(engine); r = FindPropertyAccessor(name, &access, &dummyArg, errNode, ns); } - if (r == 0) + if( r == 0 ) { // Normal property access r = FindPropertyAccessor(name, &access, errNode, ns); } - if (r < 0) return -1; + if( r < 0 ) return -1; - if (access.property_get == 0 && access.property_set == 0) + if( access.property_get == 0 && access.property_set == 0 ) { // Even though the symbol was identified in SymbolLookup, it doesn't match the arguments asCString msg; - if (errNode->next && errNode->next->tokenType == ttOpenBracket) + if( errNode->next && errNode->next->tokenType == ttOpenBracket ) msg.Format(TXT_PROP_ACCESS_s_DOES_NOT_EXPECT_INDEX, name.AddressOf()); else msg.Format(TXT_PROP_ACCESS_s_EXPECTS_INDEX, name.AddressOf()); @@ -11778,17 +11779,17 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s return 0; } - if (symbolType == SL_GLOBALCONST || symbolType == SL_GLOBALVAR) + if( symbolType == SL_GLOBALCONST || symbolType == SL_GLOBALVAR ) { - bool isCompiled = true; - bool isPureConstant = false; - bool isAppProp = false; - asQWORD constantValue = 0; - asCGlobalProperty *prop = builder->GetGlobalProperty(name.AddressOf(), ns, &isCompiled, &isPureConstant, &constantValue, &isAppProp); + bool isCompiled = true; + bool isPureConstant = false; + bool isAppProp = false; + asQWORD constantValue = 0; + asCGlobalProperty *prop = builder->GetGlobalProperty(name.AddressOf(), ns, &isCompiled, &isPureConstant, &constantValue, &isAppProp); asASSERT(prop); // Verify that the global property has been compiled already - if (!isCompiled) + if( !isCompiled ) { asCString str; str.Format(TXT_UNINITIALIZED_GLOBAL_VAR_s, prop->name.AddressOf()); @@ -11800,15 +11801,15 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s // we can allow the compiler to optimize it. Pure // constants are global constant variables that were // initialized by literal constants. - if (isPureConstant) + if( isPureConstant ) ctx->type.SetConstantData(prop->type, constantValue); else { // A shared type must not access global vars, unless they // too are shared, e.g. application registered vars - if (outFunc->IsShared()) + if( outFunc->IsShared() ) { - if (!isAppProp) + if( !isAppProp ) { asCString str; str.Format(TXT_SHARED_CANNOT_ACCESS_NON_SHARED_VAR_s, prop->name.AddressOf()); @@ -11821,7 +11822,7 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s ctx->type.Set(prop->type); ctx->type.isLValue = true; - if (ctx->type.dataType.IsPrimitive()) + if( ctx->type.dataType.IsPrimitive() ) { // Load the address of the variable into the register ctx->bc.InstrPTR(asBC_LDG, prop->GetAddressOfValue()); @@ -11838,9 +11839,9 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s // before it is initialized. // This check is not needed for application registered properties, since they // are guaranteed to be valid by the application itself. - if (!isAppProp && - ((ctx->type.dataType.GetTypeInfo()->flags & asOBJ_VALUE) || - !ctx->type.dataType.IsObjectHandle())) + if( !isAppProp && + ((ctx->type.dataType.GetTypeInfo()->flags & asOBJ_VALUE) || + !ctx->type.dataType.IsObjectHandle()) ) { ctx->bc.Instr(asBC_ChkRefS); } @@ -11848,8 +11849,8 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s // If the address pushed on the stack is to a value type or an object // handle, then mark the expression as a reference. Addresses to a reference // type aren't marked as references to get correct behaviour - if ((ctx->type.dataType.GetTypeInfo()->flags & asOBJ_VALUE) || - ctx->type.dataType.IsObjectHandle()) + if( (ctx->type.dataType.GetTypeInfo()->flags & asOBJ_VALUE) || + ctx->type.dataType.IsObjectHandle() ) { ctx->type.dataType.MakeReference(true); } @@ -11866,14 +11867,14 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s return 0; } - if (symbolType == SL_GLOBALFUNC) + if( symbolType == SL_GLOBALFUNC ) { asCArray funcs; builder->GetFunctionDescriptions(name.AddressOf(), funcs, ns); asASSERT(funcs.GetLength() > 0); - if (funcs.GetLength() > 0) + if( funcs.GetLength() > 0 ) { // Defer the evaluation of which function until it is actually used // Store the namespace and name of the function for later @@ -11884,16 +11885,16 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s return 0; } - if (symbolType == SL_ENUMVAL) + if( symbolType == SL_ENUMVAL ) { // The enum type and namespace must be returned from SymbolLookup asCDataType dt = lookupResult.type.dataType; - if (!dt.IsEnumType()) + if( !dt.IsEnumType() ) { asASSERT(!engine->ep.requireEnumScope); // It is an ambigious enum value. The evaluation needs to be deferred for when the type is known - ctx->enumValue = name.AddressOf(); + ctx->enumValue = name.AddressOf(); ctx->symbolNamespace = lookupResult.symbolNamespace; // We cannot set a dummy value because it will pass through @@ -11909,11 +11910,11 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s // the use of the values are still allowed, since they are treated as constants. // an enum value was resolved - if (dt.GetSizeInMemoryBytes() == 1) + if( dt.GetSizeInMemoryBytes() == 1 ) ctx->type.SetConstantB(dt, asBYTE(value)); - else if (dt.GetSizeInMemoryBytes() == 2) + else if( dt.GetSizeInMemoryBytes() == 2 ) ctx->type.SetConstantW(dt, asWORD(value)); - else if (dt.GetSizeInMemoryBytes() == 4) + else if( dt.GetSizeInMemoryBytes() == 4 ) ctx->type.SetConstantDW(dt, asDWORD(value)); else ctx->type.SetConstantQW(dt, value); @@ -11922,7 +11923,7 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s } // The result must have been identified above - if (symbolType == SL_GLOBALTYPE || symbolType == SL_CLASSTYPE) + if( symbolType == SL_GLOBALTYPE || symbolType == SL_CLASSTYPE ) { // Give dummy value ctx->type.SetDummy(); @@ -11930,9 +11931,9 @@ int asCCompiler::CompileVariableAccess(const asCString &name, const asCString &s // The symbol matches a type asCString msg; asCString smbl; - if (scope == "::") + if( scope == "::" ) smbl = scope; - else if (scope != "") + else if( scope != "" ) smbl = scope + "::"; smbl += name; msg.Format(TXT_EXPR_s_IS_DATA_TYPE, smbl.AddressOf()); @@ -11951,7 +11952,7 @@ int asCCompiler::CompileExpressionValue(asCScriptNode *node, asCExprContext *ctx asASSERT(ctx->bc.GetLastInstr() == -1); asCScriptNode *vnode = node->firstChild; - ctx->exprNode = vnode; + ctx->exprNode = vnode; if( vnode->nodeType == snVariableAccess ) { // Determine the scope resolution of the variable @@ -11969,11 +11970,11 @@ int asCCompiler::CompileExpressionValue(asCScriptNode *node, asCExprContext *ctx { asCString value(&script->code[vnode->tokenPos], vnode->tokenLength); - bool overflow = false; - asQWORD val = asStringScanUInt64(value.AddressOf(), 10, 0, &overflow); + bool overflow = false; + asQWORD val = asStringScanUInt64(value.AddressOf(), 10, 0, &overflow); // Is the number bigger than a 64bit word? - if (overflow) + if( overflow ) { Error(TXT_VALUE_TOO_LARGE_FOR_TYPE, vnode); @@ -11984,10 +11985,10 @@ int asCCompiler::CompileExpressionValue(asCScriptNode *node, asCExprContext *ctx // Do we need 64 bits? // If the 31st bit is set we'll treat the value as a signed 64bit number to avoid // incorrect warnings about changing signs if the value is assigned to a 64bit variable - if( val>>31 ) + if( val >> 31 ) { // Only if the value uses the last bit of a 64bit word do we consider the number unsigned - if( val>>63 ) + if( val >> 63 ) ctx->type.SetConstantQW(asCDataType::CreatePrimitive(ttUInt64, true), val); else ctx->type.SetConstantQW(asCDataType::CreatePrimitive(ttInt64, true), val); @@ -12000,11 +12001,11 @@ int asCCompiler::CompileExpressionValue(asCScriptNode *node, asCExprContext *ctx asCString value(&script->code[vnode->tokenPos], vnode->tokenLength); // Let the function determine the radix from the prefix 0x = 16, 0d = 10, 0o = 8, or 0b = 2 - bool overflow = false; - asQWORD val = asStringScanUInt64(value.AddressOf(), 0, 0, &overflow); + bool overflow = false; + asQWORD val = asStringScanUInt64(value.AddressOf(), 0, 0, &overflow); // Is the number bigger than a 64bit word? - if (overflow) + if( overflow ) { Error(TXT_VALUE_TOO_LARGE_FOR_TYPE, vnode); @@ -12013,7 +12014,7 @@ int asCCompiler::CompileExpressionValue(asCScriptNode *node, asCExprContext *ctx } // Do we need 64 bits? - if( val>>32 ) + if( val >> 32 ) ctx->type.SetConstantQW(asCDataType::CreatePrimitive(ttUInt64, true), val); else ctx->type.SetConstantDW(asCDataType::CreatePrimitive(ttUInt, true), asDWORD(val)); @@ -12025,12 +12026,12 @@ int asCCompiler::CompileExpressionValue(asCScriptNode *node, asCExprContext *ctx // TODO: Check for overflow size_t numScanned; - float v = float(asStringScanDouble(value.AddressOf(), &numScanned)); + float v = float(asStringScanDouble(value.AddressOf(), &numScanned)); ctx->type.SetConstantF(asCDataType::CreatePrimitive(ttFloat, true), v); -#ifndef AS_USE_DOUBLE_AS_FLOAT + #ifndef AS_USE_DOUBLE_AS_FLOAT // Don't check this if we have double as float, because then the whole token would be scanned (i.e. no f suffix) asASSERT(numScanned == vnode->tokenLength - 1); -#endif + #endif } else if( vnode->tokenType == ttDoubleConstant ) { @@ -12044,24 +12045,24 @@ int asCCompiler::CompileExpressionValue(asCScriptNode *node, asCExprContext *ctx asASSERT(numScanned == vnode->tokenLength); } else if( vnode->tokenType == ttTrue || - vnode->tokenType == ttFalse ) + vnode->tokenType == ttFalse ) { -#if AS_SIZEOF_BOOL == 1 + #if AS_SIZEOF_BOOL == 1 ctx->type.SetConstantB(asCDataType::CreatePrimitive(ttBool, true), vnode->tokenType == ttTrue ? VALUE_OF_BOOLEAN_TRUE : 0); -#else + #else ctx->type.SetConstantDW(asCDataType::CreatePrimitive(ttBool, true), vnode->tokenType == ttTrue ? VALUE_OF_BOOLEAN_TRUE : 0); -#endif + #endif } else if( vnode->tokenType == ttStringConstant || - vnode->tokenType == ttMultilineStringConstant || - vnode->tokenType == ttHeredocStringConstant ) + vnode->tokenType == ttMultilineStringConstant || + vnode->tokenType == ttHeredocStringConstant ) { - asCString str; + asCString str; asCScriptNode *snode = vnode->firstChild; if( script->code[snode->tokenPos] == '\'' && engine->ep.useCharacterLiterals ) { // Treat the single quoted string as a single character literal - str.Assign(&script->code[snode->tokenPos+1], snode->tokenLength-2); + str.Assign(&script->code[snode->tokenPos + 1], snode->tokenLength - 2); asDWORD val = 0; if( str.GetLength() && (asBYTE)str[0] > 127 && engine->ep.scanner == 1 ) @@ -12088,7 +12089,7 @@ int asCCompiler::CompileExpressionValue(asCScriptNode *node, asCExprContext *ctx asCString cat; if( snode->tokenType == ttStringConstant ) { - cat.Assign(&script->code[snode->tokenPos+1], snode->tokenLength-2); + cat.Assign(&script->code[snode->tokenPos + 1], snode->tokenLength - 2); ProcessStringConstant(cat, snode); } else if( snode->tokenType == ttMultilineStringConstant ) @@ -12096,12 +12097,12 @@ int asCCompiler::CompileExpressionValue(asCScriptNode *node, asCExprContext *ctx if( !engine->ep.allowMultilineStrings ) Error(TXT_MULTILINE_STRINGS_NOT_ALLOWED, snode); - cat.Assign(&script->code[snode->tokenPos+1], snode->tokenLength-2); + cat.Assign(&script->code[snode->tokenPos + 1], snode->tokenLength - 2); ProcessStringConstant(cat, snode); } else if( snode->tokenType == ttHeredocStringConstant ) { - cat.Assign(&script->code[snode->tokenPos+3], snode->tokenLength-6); + cat.Assign(&script->code[snode->tokenPos + 3], snode->tokenLength - 6); ProcessHeredocStringConstant(cat, snode); } @@ -12111,7 +12112,7 @@ int asCCompiler::CompileExpressionValue(asCScriptNode *node, asCExprContext *ctx } // Call the string factory function to create a string object - if(engine->stringFactory == 0 ) + if( engine->stringFactory == 0 ) { // Error Error(TXT_STRINGS_NOT_RECOGNIZED, vnode); @@ -12122,8 +12123,8 @@ int asCCompiler::CompileExpressionValue(asCScriptNode *node, asCExprContext *ctx } else { - void *strPtr = const_cast(engine->stringFactory->GetStringConstant(str.AddressOf(), (asUINT)str.GetLength())); - if (strPtr == 0) + void *strPtr = const_cast(engine->stringFactory->GetStringConstant(str.AddressOf(), (asUINT)str.GetLength())); + if( strPtr == 0 ) { // TODO: A better message is needed Error(TXT_NULL_POINTER_ACCESS, vnode); @@ -12173,7 +12174,7 @@ int asCCompiler::CompileExpressionValue(asCScriptNode *node, asCExprContext *ctx else if( vnode->nodeType == snAssignment ) { asCExprContext e(engine); - int r = CompileAssignment(vnode, &e); + int r = CompileAssignment(vnode, &e); if( r < 0 ) { ctx->type.SetDummy(); @@ -12213,7 +12214,7 @@ asUINT asCCompiler::ProcessStringConstant(asCString &cstr, asCScriptNode *node, for( asUINT n = 0; n < cstr.GetLength(); n++ ) { -#ifdef AS_DOUBLEBYTE_CHARSET + #ifdef AS_DOUBLEBYTE_CHARSET // Double-byte charset is only allowed for ASCII and not UTF16 encoded strings if( (cstr[n] & 0x80) && engine->ep.scanner == 0 && engine->ep.stringEncoding != 1 ) { @@ -12224,7 +12225,7 @@ asUINT asCCompiler::ProcessStringConstant(asCString &cstr, asCScriptNode *node, str.PushLast(cstr[n]); continue; } -#endif + #endif asUINT val; @@ -12246,16 +12247,16 @@ asUINT asCCompiler::ProcessStringConstant(asCString &cstr, asCScriptNode *node, ++n; if( n == cstr.GetLength() ) break; - val = 0; + val = 0; int c = engine->ep.stringEncoding == 1 ? 4 : 2; for( ; c > 0 && n < cstr.GetLength(); c--, n++ ) { if( cstr[n] >= '0' && cstr[n] <= '9' ) - val = val*16 + cstr[n] - '0'; + val = val * 16 + cstr[n] - '0'; else if( cstr[n] >= 'a' && cstr[n] <= 'f' ) - val = val*16 + cstr[n] - 'a' + 10; + val = val * 16 + cstr[n] - 'a' + 10; else if( cstr[n] >= 'A' && cstr[n] <= 'F' ) - val = val*16 + cstr[n] - 'A' + 10; + val = val * 16 + cstr[n] - 'A' + 10; else break; } @@ -12270,13 +12271,13 @@ asUINT asCCompiler::ProcessStringConstant(asCString &cstr, asCScriptNode *node, } else { -#ifndef AS_BIG_ENDIAN + #ifndef AS_BIG_ENDIAN str.PushLast((asBYTE)val); - str.PushLast((asBYTE)(val>>8)); -#else - str.PushLast((asBYTE)(val>>8)); + str.PushLast((asBYTE)(val >> 8)); + #else + str.PushLast((asBYTE)(val >> 8)); str.PushLast((asBYTE)val); -#endif + #endif } if( charLiteral == -1 ) charLiteral = val; continue; @@ -12286,7 +12287,7 @@ asUINT asCCompiler::ProcessStringConstant(asCString &cstr, asCScriptNode *node, // \u expects 4 hex digits // \U expects 8 hex digits bool expect2 = cstr[n] == 'u'; - int c = expect2 ? 4 : 8; + int c = expect2 ? 4 : 8; val = 0; @@ -12296,11 +12297,11 @@ asUINT asCCompiler::ProcessStringConstant(asCString &cstr, asCScriptNode *node, if( n == cstr.GetLength() ) break; if( cstr[n] >= '0' && cstr[n] <= '9' ) - val = val*16 + cstr[n] - '0'; + val = val * 16 + cstr[n] - '0'; else if( cstr[n] >= 'a' && cstr[n] <= 'f' ) - val = val*16 + cstr[n] - 'a' + 10; + val = val * 16 + cstr[n] - 'a' + 10; else if( cstr[n] >= 'A' && cstr[n] <= 'F' ) - val = val*16 + cstr[n] - 'A' + 10; + val = val * 16 + cstr[n] - 'A' + 10; else break; } @@ -12353,7 +12354,7 @@ asUINT asCCompiler::ProcessStringConstant(asCString &cstr, asCScriptNode *node, val = (unsigned char)cstr[n]; } else - n += len-1; + n += len - 1; } else val = (unsigned char)cstr[n]; @@ -12361,7 +12362,7 @@ asUINT asCCompiler::ProcessStringConstant(asCString &cstr, asCScriptNode *node, // Add the character to the final string char encodedValue[5]; - int len; + int len; if( engine->ep.scanner == 1 && engine->ep.stringEncoding == 0 ) { // Convert to UTF8 encoded @@ -12376,7 +12377,7 @@ asUINT asCCompiler::ProcessStringConstant(asCString &cstr, asCScriptNode *node, { // Do not convert ASCII characters encodedValue[0] = (asBYTE)val; - len = 1; + len = 1; } if( len < 0 ) @@ -12401,7 +12402,7 @@ void asCCompiler::ProcessHeredocStringConstant(asCString &str, asCScriptNode *no { // Remove first line if it only contains whitespace bool isMultiline = false; - int start; + int start; for( start = 0; start < (int)str.GetLength(); start++ ) { if( str[start] == '\n' ) @@ -12413,9 +12414,9 @@ void asCCompiler::ProcessHeredocStringConstant(asCString &str, asCScriptNode *no break; } - if( str[start] != ' ' && - str[start] != '\t' && - str[start] != '\r' ) + if( str[start] != ' ' && + str[start] != '\t' && + str[start] != '\r' ) { // Don't remove anything start = 0; @@ -12434,9 +12435,9 @@ void asCCompiler::ProcessHeredocStringConstant(asCString &str, asCScriptNode *no break; } - if( str[end] != ' ' && - str[end] != '\t' && - str[end] != '\r' ) + if( str[end] != ' ' && + str[end] != '\t' && + str[end] != '\r' ) { // Don't remove anything end = (int)str.GetLength(); @@ -12447,12 +12448,12 @@ void asCCompiler::ProcessHeredocStringConstant(asCString &str, asCScriptNode *no if( end < 0 ) end = 0; asCString tmp; - if (end > start || engine->ep.heredocTrimMode != 2 ) + if( end > start || engine->ep.heredocTrimMode != 2 ) { // if heredocTrimMode == 0 the string shouldn't be trimmed // if heredocTrimMode == 1 the string should only be trimmed if it is multiline // if heredocTrimMode == 2 the string should always be trimmed - if (engine->ep.heredocTrimMode == 2 || (isMultiline && engine->ep.heredocTrimMode == 1)) + if( engine->ep.heredocTrimMode == 2 || (isMultiline && engine->ep.heredocTrimMode == 1) ) tmp.Assign(&str[start], end - start); else tmp = str; @@ -12466,23 +12467,23 @@ void asCCompiler::ProcessHeredocStringConstant(asCString &str, asCScriptNode *no int asCCompiler::CompileConversion(asCScriptNode *node, asCExprContext *ctx) { asCExprContext expr(engine); - asCDataType to; - bool anyErrors = false; - EImplicitConv convType; + asCDataType to; + bool anyErrors = false; + EImplicitConv convType; if( node->nodeType == snConstructCall || node->nodeType == snFunctionCall ) { convType = asIC_EXPLICIT_VAL_CAST; // Verify that there is only one argument if( node->lastChild->firstChild == 0 || - node->lastChild->firstChild != node->lastChild->lastChild ) + node->lastChild->firstChild != node->lastChild->lastChild ) { Error(TXT_ONLY_ONE_ARGUMENT_IN_CAST, node->lastChild); expr.type.SetDummy(); anyErrors = true; } - else if (node->lastChild->firstChild && - node->lastChild->firstChild->nodeType == snNamedArgument) + else if( node->lastChild->firstChild && + node->lastChild->firstChild->nodeType == snNamedArgument ) { Error(TXT_INVALID_USE_OF_NAMED_ARGS, node->lastChild); expr.type.SetDummy(); @@ -12530,7 +12531,7 @@ int asCCompiler::CompileConversion(asCScriptNode *node, asCExprContext *ctx) // Do not allow casting to non shared type if we're compiling a shared method if( outFunc->IsShared() && - to.GetTypeInfo() && !to.GetTypeInfo()->IsShared() ) + to.GetTypeInfo() && !to.GetTypeInfo()->IsShared() ) { asCString msg; msg.Format(TXT_SHARED_CANNOT_USE_NON_SHARED_TYPE_s, to.GetTypeInfo()->name.AddressOf()); @@ -12595,8 +12596,8 @@ int asCCompiler::CompileConversion(asCScriptNode *node, asCExprContext *ctx) ConvertToTempVariable(&expr); if( to.IsObjectHandle() && - expr.type.dataType.IsObjectHandle() && - !(!to.IsHandleToConst() && expr.type.dataType.IsHandleToConst()) ) + expr.type.dataType.IsObjectHandle() && + !(!to.IsHandleToConst() && expr.type.dataType.IsHandleToConst()) ) { conversionOK = CompileRefCast(&expr, to, true, node); @@ -12614,7 +12615,7 @@ int asCCompiler::CompileConversion(asCScriptNode *node, asCExprContext *ctx) asCString strTo, strFrom; strTo = to.Format(outFunc->nameSpace); - if (expr.IsAnonymousInitList()) + if( expr.IsAnonymousInitList() ) strFrom = ""; else strFrom = expr.type.dataType.Format(outFunc->nameSpace); @@ -12626,7 +12627,7 @@ int asCCompiler::CompileConversion(asCScriptNode *node, asCExprContext *ctx) return -1; } -void asCCompiler::AfterFunctionCall(int funcID, asCArray &args, asCExprContext *ctx, bool deferAll) +void asCCompiler::AfterFunctionCall(int funcID, asCArray &args, asCExprContext *ctx, bool deferAll) { // deferAll is set to true if for example the function returns a reference, since in // this case the function might be returning a reference to one of the arguments. @@ -12641,26 +12642,26 @@ void asCCompiler::AfterFunctionCall(int funcID, asCArray &args, for( ; n >= 0; n-- ) { asUINT realParamIdx = n; - if (descr->IsVariadic() && n >= (int)descr->parameterTypes.GetLength() - 1) + if( descr->IsVariadic() && n >= (int)descr->parameterTypes.GetLength() - 1 ) realParamIdx = descr->parameterTypes.GetLength() - 1; - + // All &out arguments must be deferred, except if the argument is clean, in which case the actual reference was passed in to the function // If deferAll is set all objects passed by reference or handle must be deferred if( (descr->parameterTypes[realParamIdx].IsReference() && (descr->inOutFlags[realParamIdx] & asTM_OUTREF) && !args[realParamIdx]->isCleanArg) || - (descr->parameterTypes[realParamIdx].IsObject() && deferAll && (descr->parameterTypes[realParamIdx].IsReference() || descr->parameterTypes[realParamIdx].IsObjectHandle())) ) + (descr->parameterTypes[realParamIdx].IsObject() && deferAll && (descr->parameterTypes[realParamIdx].IsReference() || descr->parameterTypes[realParamIdx].IsObjectHandle())) ) { asASSERT( !(descr->parameterTypes[realParamIdx].IsReference() && (descr->inOutFlags[realParamIdx] == asTM_OUTREF) && !args[realParamIdx]->isCleanArg) || args[realParamIdx]->origExpr ); // For &inout, only store the argument if it is for a temporary variable if( engine->ep.allowUnsafeReferences || - descr->inOutFlags[realParamIdx] != asTM_INOUTREF || args[realParamIdx]->type.isTemporary ) + descr->inOutFlags[realParamIdx] != asTM_INOUTREF || args[realParamIdx]->type.isTemporary ) { // Store the argument for later processing asSDeferredParam outParam; - outParam.argNode = args[n]->exprNode; - outParam.argType = args[n]->type; + outParam.argNode = args[n]->exprNode; + outParam.argType = args[n]->type; outParam.argInOutFlags = descr->inOutFlags[realParamIdx]; - outParam.origExpr = args[n]->origExpr; + outParam.origExpr = args[n]->origExpr; ctx->deferredParams.PushLast(outParam); } @@ -12701,7 +12702,7 @@ void asCCompiler::ProcessDeferredParams(asCExprContext *ctx, bool processOnlyOut { // Assign the value returned in the output reference parameter to the expression passed as argument asCExprContext *expr = outParam.origExpr; - outParam.origExpr = 0; + outParam.origExpr = 0; if( outParam.argType.dataType.IsObjectHandle() ) { @@ -12746,7 +12747,7 @@ void asCCompiler::ProcessDeferredParams(asCExprContext *ctx, bool processOnlyOut // Give an error, except if the argument is void, null or 0 which indicate the argument is explicitly to be ignored if( !expr->IsVoidExpression() && !expr->type.IsNullConstant() && - !(expr->type.isConstant && expr->type.dataType.IsPrimitive() && expr->type.GetConstantData() == 0) ) + !(expr->type.isConstant && expr->type.dataType.IsPrimitive() && expr->type.GetConstantData() == 0) ) Error(TXT_ARG_NOT_LVALUE, outParam.argNode); ReleaseTemporaryVariable(outParam.argType, &ctx->bc); @@ -12766,9 +12767,9 @@ void asCCompiler::ProcessDeferredParams(asCExprContext *ctx, bool processOnlyOut else if( !outParam.argType.isVariable ) { if( outParam.argType.dataType.IsObject() && !outParam.argType.IsNullConstant() && - ((outParam.argType.dataType.GetBehaviour()->addref && - outParam.argType.dataType.GetBehaviour()->release) || - (outParam.argType.dataType.GetTypeInfo()->flags & asOBJ_NOCOUNT)) ) + ((outParam.argType.dataType.GetBehaviour()->addref && + outParam.argType.dataType.GetBehaviour()->release) || + (outParam.argType.dataType.GetTypeInfo()->flags & asOBJ_NOCOUNT)) ) { // Release the object handle that was taken to guarantee the reference ReleaseTemporaryVariable(outParam.argType, &ctx->bc); @@ -12786,11 +12787,11 @@ void asCCompiler::ProcessDeferredParams(asCExprContext *ctx, bool processOnlyOut int asCCompiler::CompileConstructCall(asCScriptNode *node, asCExprContext *ctx) { // The first node is a datatype node - asCString name; - asCExprValue tempObj; - bool onHeap = true; + asCString name; + asCExprValue tempObj; + bool onHeap = true; asCArray funcs; - bool error = false; + bool error = false; // It is possible that the name is really a constructor asCDataType dt; @@ -12837,7 +12838,7 @@ int asCCompiler::CompileConstructCall(asCScriptNode *node, asCExprContext *ctx) // Do not allow constructing non-shared types in shared functions if( outFunc->IsShared() && - dt.GetTypeInfo() && !dt.GetTypeInfo()->IsShared() ) + dt.GetTypeInfo() && !dt.GetTypeInfo()->IsShared() ) { asCString msg; msg.Format(TXT_SHARED_CANNOT_USE_NON_SHARED_TYPE_s, dt.GetTypeInfo()->name.AddressOf()); @@ -12848,8 +12849,8 @@ int asCCompiler::CompileConstructCall(asCScriptNode *node, asCExprContext *ctx) // Compile the arguments asCArray args; asCArray namedArgs; - asCArray temporaryVariables; - asCExprContext tempCtx(engine); + asCArray temporaryVariables; + asCExprContext tempCtx(engine); tempCtx.exprNode = node; if( CompileArgumentList(node->lastChild, args, namedArgs) >= 0 ) { @@ -12863,16 +12864,16 @@ int asCCompiler::CompileConstructCall(asCScriptNode *node, asCExprContext *ctx) funcs = beh->constructors; // Value types and script types are allocated through the constructor - tempObj.dataType = dt; + tempObj.dataType = dt; tempObj.stackOffset = (short)AllocateVariable(dt, true); tempObj.dataType.MakeReference(true); tempObj.isTemporary = true; - tempObj.isVariable = true; + tempObj.isVariable = true; onHeap = IsVariableOnHeap(tempObj.stackOffset); // Push the address of the object on the stack - if (onHeap) + if( onHeap ) tempCtx.bc.InstrSHORT(asBC_VAR, (short)tempObj.stackOffset); } else if( beh ) @@ -12917,7 +12918,7 @@ int asCCompiler::CompileConstructCall(asCScriptNode *node, asCExprContext *ctx) { // It is possible that the argument returns a function pointer already, in which // case no object delegate will be created, but instead a delegate for a function pointer - if (args[0]->type.IsUndefinedFuncHandle()) + if( args[0]->type.IsUndefinedFuncHandle() ) { int r = ImplicitConversion(args[0], dt, node->lastChild, asIC_EXPLICIT_VAL_CAST); @@ -12940,9 +12941,9 @@ int asCCompiler::CompileConstructCall(asCScriptNode *node, asCExprContext *ctx) else { // Filter the available object methods to find the one that matches the func def - asCObjectType *type = CastToObjectType(args[0]->type.dataType.GetTypeInfo()); - asCScriptFunction *bestMethod = 0; - bool nonConstMethodHidden = false; + asCObjectType *type = CastToObjectType(args[0]->type.dataType.GetTypeInfo()); + asCScriptFunction *bestMethod = 0; + bool nonConstMethodHidden = false; for( asUINT n = 0; n < type->methods.GetLength(); n++ ) { asCScriptFunction *func = engine->scriptFunctions[type->methods[n]]; @@ -12951,7 +12952,7 @@ int asCCompiler::CompileConstructCall(asCScriptNode *node, asCExprContext *ctx) continue; // If the expression is for a const object, then only const methods should be accepted - if (args[0]->type.dataType.IsReadOnly() && !func->IsReadOnly()) + if( args[0]->type.dataType.IsReadOnly() && !func->IsReadOnly() ) { nonConstMethodHidden = true; continue; @@ -12979,7 +12980,7 @@ int asCCompiler::CompileConstructCall(asCScriptNode *node, asCExprContext *ctx) asCArray delegateFuncs; builder->GetFunctionDescriptions(DELEGATE_FACTORY, delegateFuncs, engine->nameSpaces[0]); asASSERT(delegateFuncs.GetLength() == 1 ); - tempCtx.bc.Call(asBC_CALLSYS , delegateFuncs[0], 2*AS_PTR_SIZE, 0); + tempCtx.bc.Call(asBC_CALLSYS, delegateFuncs[0], 2 * AS_PTR_SIZE, 0); // Store the returned delegate in a temporary variable int returnOffset = AllocateVariable(dt, true, false); @@ -13001,7 +13002,7 @@ int asCCompiler::CompileConstructCall(asCScriptNode *node, asCExprContext *ctx) msg.Format(TXT_NO_MATCHING_SIGNATURES_TO_s, CastToFuncdefType(dt.GetTypeInfo())->funcdef->GetDeclaration()); Information(msg.AddressOf(), node); - if (nonConstMethodHidden) + if( nonConstMethodHidden ) Information(TXT_POTENTIAL_MATCHING_NON_CONST_METHOD_HIDDEN, node); error = true; @@ -13022,30 +13023,30 @@ int asCCompiler::CompileConstructCall(asCScriptNode *node, asCExprContext *ctx) { // No appropriate constructor was found // Release the temporary object if it was created was a value type - if (!(dt.GetTypeInfo()->flags & asOBJ_REF) && !dt.IsFuncdef()) + if( !(dt.GetTypeInfo()->flags & asOBJ_REF) && !dt.IsFuncdef() ) ReleaseTemporaryVariable(tempObj.stackOffset, &tempCtx.bc); - + // Check for a value cast behaviour - if (args.GetLength() == 1 && namedArgs.GetLength() == 0) + if( args.GetLength() == 1 && namedArgs.GetLength() == 0 ) { asCExprContext conv(engine); conv.Copy(args[0]); asUINT cost = ImplicitConversion(&conv, dt, node->lastChild, asIC_EXPLICIT_VAL_CAST, false); - // Clean the property_arg in the temporary copy so + // Clean the property_arg in the temporary copy so // it isn't deleted when conv goes out of scope conv.property_arg = 0; // Don't use this if the cost is 0 because it would mean that nothing // is done and the script wants a new value to be constructed - if (conv.type.dataType.IsEqualExceptRef(dt) && cost > 0) + if( conv.type.dataType.IsEqualExceptRef(dt) && cost > 0 ) { // Make sure the result is a reference, just as if to a local variable - if (!dt.IsFuncdef()) + if( !dt.IsFuncdef() ) dt.MakeReference(true); // Make sure any property accessor is already evaluated - if (ProcessPropertyGetAccessor(args[0], args[0]->exprNode) < 0) + if( ProcessPropertyGetAccessor(args[0], args[0]->exprNode) < 0 ) return -1; ImplicitConversion(args[0], dt, node->lastChild, asIC_EXPLICIT_VAL_CAST); @@ -13075,13 +13076,13 @@ int asCCompiler::CompileConstructCall(asCScriptNode *node, asCExprContext *ctx) { MakeFunctionCall(&tempCtx, funcs[0], 0, args, node, false, tempObj.stackOffset, 0, onHeap); - if (!(dt.GetTypeInfo()->flags & asOBJ_REF)) + if( !(dt.GetTypeInfo()->flags & asOBJ_REF) ) { // The constructor doesn't return anything, // so we have to manually inform the type of // the return value tempCtx.type = tempObj; - if (!onHeap) + if( !onHeap ) tempCtx.type.dataType.MakeReference(false); } @@ -13110,21 +13111,21 @@ int asCCompiler::CompileConstructCall(asCScriptNode *node, asCExprContext *ctx) } -int asCCompiler::InstantiateTemplateFunctions(asCArray& funcs, asCScriptNode* types) +int asCCompiler::InstantiateTemplateFunctions(asCArray &funcs, asCScriptNode *types) { - asCScriptNode* startNode = types; - for ( asUINT i = 0; i < funcs.GetLength(); i++ ) + asCScriptNode *startNode = types; + for( asUINT i = 0; i < funcs.GetLength(); i++ ) { - asCScriptFunction* func = builder->GetFunctionDescription(funcs[i]); - asUINT numTypes = func->templateSubTypes.GetLength(); + asCScriptFunction *func = builder->GetFunctionDescription(funcs[i]); + asUINT numTypes = func->templateSubTypes.GetLength(); // TODO: If types for template instance has been given in the node, and no matching template function exists then an error must be given - if (numTypes == 0) continue; + if( numTypes == 0 ) continue; asCArray dataTypes; // TODO: If there is more than one template function with the same name, then use only the one that matches - for (asUINT j = 0; j < numTypes; j++) + for( asUINT j = 0; j < numTypes; j++ ) { - // If the number of types doesn't match the template then give an error - if (types == 0 || types->nodeType == snArgList) + // If the number of types doesn't match the template then give an error + if( types == 0 || types->nodeType == snArgList ) { asCString msg; msg.Format(TXT_TMPL_s_EXPECTS_d_SUBTYPES, func->GetName(), numTypes); @@ -13135,7 +13136,7 @@ int asCCompiler::InstantiateTemplateFunctions(asCArray& funcs, asCScriptNod types = types->next; } // Check that there isn't additional types - if (types == 0 || types->nodeType != snArgList) + if( types == 0 || types->nodeType != snArgList ) { asCString msg; msg.Format(TXT_TMPL_s_EXPECTS_d_SUBTYPES, func->GetName(), numTypes); @@ -13151,32 +13152,32 @@ int asCCompiler::InstantiateTemplateFunctions(asCArray& funcs, asCScriptNod int asCCompiler::CompileFunctionCall(asCScriptNode *node, asCExprContext *ctx, asCObjectType *objectType, bool objIsConst, const asCString &scope) { - asCExprValue tempObj; - asCArray funcs; - int localVar = -1; - bool initializeMembers = false; + asCExprValue tempObj; + asCArray funcs; + int localVar = -1; + bool initializeMembers = false; asCExprContext funcExpr(engine); // Skip over the optional scope to get the name of the function - asCScriptNode* nm = node->firstChild; - if (nm->nodeType == snScope) nm = nm->next; + asCScriptNode *nm = node->firstChild; + if( nm->nodeType == snScope ) nm = nm->next; asASSERT(nm->tokenType == ttIdentifier); asCString name(&script->code[nm->tokenPos], nm->tokenLength); // Find the matching entities // If objectType is set then this is a post op expression and we shouldn't look for local variables asCExprContext lookupResult(engine); - SYMBOLTYPE symbolType = SymbolLookup(name, scope, objectType, &lookupResult, node); - if (symbolType < 0) + SYMBOLTYPE symbolType = SymbolLookup(name, scope, objectType, &lookupResult, node); + if( symbolType < 0 ) return -1; - if (symbolType == SL_NOMATCH) + if( symbolType == SL_NOMATCH ) { // No matching symbol asCString msg; asCString smbl; - if (scope == "::") + if( scope == "::" ) smbl = scope; - else if (scope != "") + else if( scope != "" ) smbl = scope + "::"; smbl += name; msg.Format(TXT_NO_MATCHING_SYMBOL_s, smbl.AddressOf()); @@ -13185,42 +13186,42 @@ int asCCompiler::CompileFunctionCall(asCScriptNode *node, asCExprContext *ctx, a } // Is the symbol matching a variable/property? - if (symbolType == SL_LOCALCONST || symbolType == SL_LOCALVAR || - symbolType == SL_THISPTR || symbolType == SL_CLASSPROPACCESS || symbolType == SL_CLASSPROP || - symbolType == SL_GLOBALPROPACCESS || symbolType == SL_GLOBALCONST || symbolType == SL_GLOBALVAR || symbolType == SL_ENUMVAL) + if( symbolType == SL_LOCALCONST || symbolType == SL_LOCALVAR || + symbolType == SL_THISPTR || symbolType == SL_CLASSPROPACCESS || symbolType == SL_CLASSPROP || + symbolType == SL_GLOBALPROPACCESS || symbolType == SL_GLOBALCONST || symbolType == SL_GLOBALVAR || symbolType == SL_ENUMVAL ) { // Variables/properties can be used as functions if they have the opCall - + // Compile the variable // TODO: Take advantage of the known symbol, so it doesn't have to be looked up again localVar = CompileVariableAccess(name, scope, &funcExpr, node, false, objectType); if( localVar < 0 ) return -1; - if (funcExpr.type.dataType.IsFuncdef()) + if( funcExpr.type.dataType.IsFuncdef() ) { funcs.PushLast(CastToFuncdefType(funcExpr.type.dataType.GetTypeInfo())->funcdef->id); } - else if (funcExpr.type.dataType.IsObject()) + else if( funcExpr.type.dataType.IsObject() ) { // Keep information about temporary variables as deferred expression so it can be properly cleaned up after the call - if (ctx->type.isTemporary) + if( ctx->type.isTemporary ) { asASSERT(objectType); asSDeferredParam deferred; - deferred.origExpr = 0; + deferred.origExpr = 0; deferred.argInOutFlags = asTM_INREF; - deferred.argNode = 0; + deferred.argNode = 0; deferred.argType.SetVariable(ctx->type.dataType, ctx->type.stackOffset, true); ctx->deferredParams.PushLast(deferred); } - if (funcExpr.property_get == 0) + if( funcExpr.property_get == 0 ) Dereference(ctx, true); // Add the bytecode for accessing the object on which opCall will be called - if (ctx->type.dataType.IsObject()) + if( ctx->type.dataType.IsObject() ) { // Make sure the ProcessPropertyGetAccess knows whether or not to // dereference the original object before calling the get accessor @@ -13234,7 +13235,7 @@ int asCCompiler::CompileFunctionCall(asCScriptNode *node, asCExprContext *ctx, a objectType = CastToObjectType(funcExpr.type.dataType.GetTypeInfo()); // Get the opCall methods from the object type - if (funcExpr.type.dataType.IsObjectHandle()) + if( funcExpr.type.dataType.IsObjectHandle() ) objIsConst = funcExpr.type.dataType.IsHandleToConst(); else objIsConst = funcExpr.type.dataType.IsReadOnly(); @@ -13252,31 +13253,31 @@ int asCCompiler::CompileFunctionCall(asCScriptNode *node, asCExprContext *ctx, a } // Is the symbol matching a class method? - if (symbolType == SL_CLASSMETHOD) + if( symbolType == SL_CLASSMETHOD ) { // If we're compiling a constructor and the name of the function is super then // the constructor of the base class is being called. // super cannot be prefixed with a scope operator - if (scope == "" && m_isConstructor && name == SUPER_TOKEN) + if( scope == "" && m_isConstructor && name == SUPER_TOKEN ) { // If the class is not derived from anyone else, calling super should give an error - if (outFunc && outFunc->objectType->derivedFrom) + if( outFunc && outFunc->objectType->derivedFrom ) funcs = outFunc->objectType->derivedFrom->beh.constructors; // Must not allow calling base class' constructor multiple times - if (continueLabels.GetLength() > 0) + if( continueLabels.GetLength() > 0 ) { // If a continue label is set we are in a loop Error(TXT_CANNOT_CALL_CONSTRUCTOR_IN_LOOPS, node); } - else if (breakLabels.GetLength() > 0) + else if( breakLabels.GetLength() > 0 ) { // TODO: inheritance: Should eventually allow constructors in switch statements // If a break label is set we are either in a loop or a switch statements Error(TXT_CANNOT_CALL_CONSTRUCTOR_IN_SWITCH, node); } - // Only set the m_isConstructorCalled after the call is actually made, so that we + // Only set the m_isConstructorCalled after the call is actually made, so that we // can detect if the arguments access any inherited members too early // m_isConstructorCalled = true; @@ -13290,20 +13291,20 @@ int asCCompiler::CompileFunctionCall(asCScriptNode *node, asCExprContext *ctx, a // Instantiate all template functions int r = InstantiateTemplateFunctions(funcs, node->firstChild->next); - if (r < 0) return r; + if( r < 0 ) return r; } // If a class method is being called implicitly, then add the this pointer for the call - if (funcs.GetLength() && !objectType && outFunc->objectType) + if( funcs.GetLength() && !objectType && outFunc->objectType ) { // Verify that the identified function is actually part of the class hierarchy - if (!outFunc->objectType->DerivesFrom(lookupResult.type.dataType.GetTypeInfo())) + if( !outFunc->objectType->DerivesFrom(lookupResult.type.dataType.GetTypeInfo()) ) { asCString msg; asCString mthd; - if (scope == "") + if( scope == "" ) mthd = name; - else if (scope == "::") + else if( scope == "::" ) mthd = scope + name; else mthd = scope + "::" + name; @@ -13324,7 +13325,7 @@ int asCCompiler::CompileFunctionCall(asCScriptNode *node, asCExprContext *ctx, a Dereference(ctx, true); } - else if (funcs.GetLength() && !objectType && !outFunc->objectType) + else if( funcs.GetLength() && !objectType && !outFunc->objectType ) { // Cannot call class methods directly without the object asCString msg; @@ -13335,30 +13336,30 @@ int asCCompiler::CompileFunctionCall(asCScriptNode *node, asCExprContext *ctx, a } // Is it a global function? - if (symbolType == SL_GLOBALFUNC) + if( symbolType == SL_GLOBALFUNC ) { // The symbol lookup identified the namespace to use - for (asCExprContext* exprCtx = &lookupResult; exprCtx; exprCtx = exprCtx->next) + for( asCExprContext *exprCtx = &lookupResult; exprCtx; exprCtx = exprCtx->next ) { - int n = exprCtx->methodName.FindLast("::"); - asSNameSpace* ns = engine->FindNameSpace(exprCtx->methodName.SubString(0, n).AddressOf()); + int n = exprCtx->methodName.FindLast("::"); + asSNameSpace *ns = engine->FindNameSpace(exprCtx->methodName.SubString(0, n).AddressOf()); builder->GetFunctionDescriptions(name.AddressOf(), funcs, ns); } - + // Instantiate all template functions - asCScriptNode* datatypeNode = node->firstChild->next; - if (datatypeNode->nodeType == snIdentifier) datatypeNode = datatypeNode->next; + asCScriptNode *datatypeNode = node->firstChild->next; + if( datatypeNode->nodeType == snIdentifier ) datatypeNode = datatypeNode->next; int r = InstantiateTemplateFunctions(funcs, datatypeNode); - if (r < 0) return r; + if( r < 0 ) return r; } // Is it a type? - if (symbolType == SL_CLASSTYPE || symbolType == SL_GLOBALTYPE) + if( symbolType == SL_CLASSTYPE || symbolType == SL_GLOBALTYPE ) { - bool isValid = false; - asCDataType dt = builder->CreateDataTypeFromNode(node->firstChild, script, outFunc->nameSpace, false, outFunc->objectType, false, &isValid, 0, &m_namespaceVisibility); - if (isValid) + bool isValid = false; + asCDataType dt = builder->CreateDataTypeFromNode(node->firstChild, script, outFunc->nameSpace, false, outFunc->objectType, false, &isValid, 0, &m_namespaceVisibility); + if( isValid ) return CompileConstructCall(node, ctx); } @@ -13438,10 +13439,10 @@ int asCCompiler::CompileFunctionCall(asCScriptNode *node, asCExprContext *ctx, a ctx->type.SetDummy(); isOK = false; } - - if (m_isConstructor && name == SUPER_TOKEN) + + if( m_isConstructor && name == SUPER_TOKEN ) { - if (m_isConstructorCalled) + if( m_isConstructorCalled ) Error(TXT_CANNOT_CALL_CONSTRUCTOR_TWICE, node); m_isConstructorCalled = true; } @@ -13559,8 +13560,8 @@ int asCCompiler::CompileExpressionPreOp(asCScriptNode *node, asCExprContext *ctx // Objects that are not local variables are not references // Objects allocated on the stack are also not marked as references if( !ctx->type.dataType.IsReference() && - !((ctx->type.dataType.IsObject() || ctx->type.dataType.IsFuncdef()) && !ctx->type.isVariable) && - !(ctx->type.isVariable && !IsVariableOnHeap(ctx->type.stackOffset)) ) + !((ctx->type.dataType.IsObject() || ctx->type.dataType.IsFuncdef()) && !ctx->type.isVariable) && + !(ctx->type.isVariable && !IsVariableOnHeap(ctx->type.stackOffset)) ) { Error(TXT_NOT_VALID_REFERENCE, node); return -1; @@ -13595,10 +13596,18 @@ int asCCompiler::CompileExpressionPreOp(asCScriptNode *node, asCExprContext *ctx const char *opName = 0; switch( op ) { - case ttMinus: opName = "opNeg"; break; - case ttBitNot: opName = "opCom"; break; - case ttInc: opName = "opPreInc"; break; - case ttDec: opName = "opPreDec"; break; + case ttMinus: + opName = "opNeg"; + break; + case ttBitNot: + opName = "opCom"; + break; + case ttInc: + opName = "opPreInc"; + break; + case ttDec: + opName = "opPreDec"; + break; } if( opName ) @@ -13610,15 +13619,15 @@ int asCCompiler::CompileExpressionPreOp(asCScriptNode *node, asCExprContext *ctx // TODO: If the value isn't const, then first try to find the non const method, and if not found try to find the const method // Find the correct method - bool isConst = ctx->type.dataType.IsObjectConst(); - asCArray funcs; + bool isConst = ctx->type.dataType.IsObjectConst(); + asCArray funcs; asCObjectType *ot = CastToObjectType(ctx->type.dataType.GetTypeInfo()); for( asUINT n = 0; n < ot->methods.GetLength(); n++ ) { asCScriptFunction *func = engine->scriptFunctions[ot->methods[n]]; if( func->name == opName && - func->parameterTypes.GetLength() == 0 && - (!isConst || func->IsReadOnly()) ) + func->parameterTypes.GetLength() == 0 && + (!isConst || func->IsReadOnly()) ) { funcs.PushLast(func->id); } @@ -13662,10 +13671,10 @@ int asCCompiler::CompileExpressionPreOp(asCScriptNode *node, asCExprContext *ctx // This is only for primitives. Objects are treated in the above block // Make sure the type is a math type - if( !(ctx->type.dataType.IsIntegerType() || - ctx->type.dataType.IsUnsignedType() || - ctx->type.dataType.IsFloatType() || - ctx->type.dataType.IsDoubleType() ) ) + if( !(ctx->type.dataType.IsIntegerType() || + ctx->type.dataType.IsUnsignedType() || + ctx->type.dataType.IsFloatType() || + ctx->type.dataType.IsDoubleType()) ) { Error(TXT_ILLEGAL_OPERATION, node); return -1; @@ -13727,15 +13736,15 @@ int asCCompiler::CompileExpressionPreOp(asCScriptNode *node, asCExprContext *ctx { if( op == ttMinus ) { - if (ctx->type.dataType.IsIntegerType()) + if( ctx->type.dataType.IsIntegerType() ) { - if (ctx->type.dataType.GetSizeInMemoryBytes() == 4) + if( ctx->type.dataType.GetSizeInMemoryBytes() == 4 ) ctx->type.SetConstantDW(-(int)ctx->type.GetConstantDW()); - else if (ctx->type.dataType.GetSizeInMemoryBytes() == 2) + else if( ctx->type.dataType.GetSizeInMemoryBytes() == 2 ) ctx->type.SetConstantW(-(asINT16)ctx->type.GetConstantW()); - else if (ctx->type.dataType.GetSizeInMemoryBytes() == 1) + else if( ctx->type.dataType.GetSizeInMemoryBytes() == 1 ) ctx->type.SetConstantB(-(asINT8)ctx->type.GetConstantB()); - else if (ctx->type.dataType.GetSizeInMemoryBytes() == 8) + else if( ctx->type.dataType.GetSizeInMemoryBytes() == 8 ) ctx->type.SetConstantQW(-(asINT64)ctx->type.GetConstantQW()); } else if( ctx->type.dataType.IsFloatType() ) @@ -13755,21 +13764,21 @@ int asCCompiler::CompileExpressionPreOp(asCScriptNode *node, asCExprContext *ctx else if( op == ttNot ) { // If turned on, allow the compiler to use either 'bool opImplConv()' or 'bool opConv()' on the type - if (engine->ep.boolConversionMode == 1) + if( engine->ep.boolConversionMode == 1 ) ImplicitConversion(ctx, asCDataType::CreatePrimitive(ttBool, false), node, asIC_EXPLICIT_VAL_CAST); // else, allow value types to be converted to bool using 'bool opImplConv()' - else if (ctx->type.dataType.GetTypeInfo() && (ctx->type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE)) + else if( ctx->type.dataType.GetTypeInfo() && (ctx->type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE) ) ImplicitConversion(ctx, asCDataType::CreatePrimitive(ttBool, false), node, asIC_IMPLICIT_CONV); if( ctx->type.dataType.IsEqualExceptRefAndConst(asCDataType::CreatePrimitive(ttBool, true)) ) { if( ctx->type.isConstant ) { - #if AS_SIZEOF_BOOL == 1 - ctx->type.SetConstantB(ctx->type.GetConstantB() == 0 ? VALUE_OF_BOOLEAN_TRUE : 0); - #else - ctx->type.SetConstantDW(ctx->type.GetConstantDW() == 0 ? VALUE_OF_BOOLEAN_TRUE : 0); - #endif + #if AS_SIZEOF_BOOL == 1 + ctx->type.SetConstantB(ctx->type.GetConstantB() == 0 ? VALUE_OF_BOOLEAN_TRUE : 0); + #else + ctx->type.SetConstantDW(ctx->type.GetConstantDW() == 0 ? VALUE_OF_BOOLEAN_TRUE : 0); + #endif return 0; } @@ -13820,9 +13829,9 @@ int asCCompiler::CompileExpressionPreOp(asCScriptNode *node, asCExprContext *ctx { if( ctx->type.dataType.GetSizeInMemoryBytes() == 1 ) ctx->type.SetConstantB(~ctx->type.GetConstantB()); - else if (ctx->type.dataType.GetSizeInMemoryBytes() == 2) + else if( ctx->type.dataType.GetSizeInMemoryBytes() == 2 ) ctx->type.SetConstantW(~ctx->type.GetConstantW()); - else if (ctx->type.dataType.GetSizeInMemoryBytes() == 4) + else if( ctx->type.dataType.GetSizeInMemoryBytes() == 4 ) ctx->type.SetConstantDW(~ctx->type.GetConstantDW()); else ctx->type.SetConstantQW(~ctx->type.GetConstantQW()); @@ -13879,7 +13888,7 @@ int asCCompiler::CompileExpressionPreOp(asCScriptNode *node, asCExprContext *ctx } if( ctx->type.dataType.IsEqualExceptRef(asCDataType::CreatePrimitive(ttInt64, false)) || - ctx->type.dataType.IsEqualExceptRef(asCDataType::CreatePrimitive(ttUInt64, false)) ) + ctx->type.dataType.IsEqualExceptRef(asCDataType::CreatePrimitive(ttUInt64, false)) ) { if( op == ttInc ) ctx->bc.Instr(asBC_INCi64); @@ -13887,7 +13896,7 @@ int asCCompiler::CompileExpressionPreOp(asCScriptNode *node, asCExprContext *ctx ctx->bc.Instr(asBC_DECi64); } else if( ctx->type.dataType.IsEqualExceptRef(asCDataType::CreatePrimitive(ttInt, false)) || - ctx->type.dataType.IsEqualExceptRef(asCDataType::CreatePrimitive(ttUInt, false)) ) + ctx->type.dataType.IsEqualExceptRef(asCDataType::CreatePrimitive(ttUInt, false)) ) { if( op == ttInc ) ctx->bc.Instr(asBC_INCi); @@ -13895,7 +13904,7 @@ int asCCompiler::CompileExpressionPreOp(asCScriptNode *node, asCExprContext *ctx ctx->bc.Instr(asBC_DECi); } else if( ctx->type.dataType.IsEqualExceptRef(asCDataType::CreatePrimitive(ttInt16, false)) || - ctx->type.dataType.IsEqualExceptRef(asCDataType::CreatePrimitive(ttUInt16, false)) ) + ctx->type.dataType.IsEqualExceptRef(asCDataType::CreatePrimitive(ttUInt16, false)) ) { if( op == ttInc ) ctx->bc.Instr(asBC_INCi16); @@ -13903,7 +13912,7 @@ int asCCompiler::CompileExpressionPreOp(asCScriptNode *node, asCExprContext *ctx ctx->bc.Instr(asBC_DECi16); } else if( ctx->type.dataType.IsEqualExceptRef(asCDataType::CreatePrimitive(ttInt8, false)) || - ctx->type.dataType.IsEqualExceptRef(asCDataType::CreatePrimitive(ttUInt8, false)) ) + ctx->type.dataType.IsEqualExceptRef(asCDataType::CreatePrimitive(ttUInt8, false)) ) { if( op == ttInc ) ctx->bc.Instr(asBC_INCi8); @@ -13965,16 +13974,16 @@ int asCCompiler::FindPropertyAccessor(const asCString &name, asCExprContext *ctx { // TODO: With asEP_PROPERTY_ACCESSOR_MODE == 3 this method doesn't need to validate the // getter/setter as it is done at the time of declaration. Should deprecate the other options - + if( engine->ep.propertyAccessorMode == 0 ) { // Property accessors have been disabled by the application return 0; } - int getId = 0, setId = 0; - asCString getName = "get_" + name; - asCString setName = "set_" + name; + int getId = 0, setId = 0; + asCString getName = "get_" + name; + asCString setName = "set_" + name; asCArray multipleGetFuncs, multipleSetFuncs; if( ctx->type.dataType.IsObject() ) @@ -13984,19 +13993,19 @@ int asCCompiler::FindPropertyAccessor(const asCString &name, asCExprContext *ctx // Don't look for property accessors in script classes if the script // property accessors have been disabled by the application if( !(ctx->type.dataType.GetTypeInfo()->flags & asOBJ_SCRIPT_OBJECT) || - engine->ep.propertyAccessorMode >= 2 ) + engine->ep.propertyAccessorMode >= 2 ) { // Check if the object has any methods with the corresponding accessor name(s) asCObjectType *ot = CastToObjectType(ctx->type.dataType.GetTypeInfo()); for( asUINT n = 0; n < ot->methods.GetLength(); n++ ) { asCScriptFunction *f = engine->scriptFunctions[ot->methods[n]]; - + if( engine->ep.propertyAccessorMode == 3 && !f->IsProperty() ) continue; - + // TODO: The type of the parameter should match the argument (unless the arg is a dummy) - if( f->name == getName && (int)f->parameterTypes.GetLength() == (arg?1:0) ) + if( f->name == getName && (int)f->parameterTypes.GetLength() == (arg ? 1 : 0) ) { if( getId == 0 ) getId = ot->methods[n]; @@ -14009,7 +14018,7 @@ int asCCompiler::FindPropertyAccessor(const asCString &name, asCExprContext *ctx } } // TODO: getset: If the parameter is a reference, it must not be an out reference. Should we allow inout ref? - if( f->name == setName && (int)f->parameterTypes.GetLength() == (arg?2:1) ) + if( f->name == setName && (int)f->parameterTypes.GetLength() == (arg ? 2 : 1) ) { if( setId == 0 ) setId = ot->methods[n]; @@ -14030,7 +14039,7 @@ int asCCompiler::FindPropertyAccessor(const asCString &name, asCExprContext *ctx // Look for appropriate global functions. asCArray funcs; - asUINT n; + asUINT n; builder->GetFunctionDescriptions(getName.AddressOf(), funcs, ns); for( n = 0; n < funcs.GetLength(); n++ ) { @@ -14038,13 +14047,13 @@ int asCCompiler::FindPropertyAccessor(const asCString &name, asCExprContext *ctx if( engine->ep.propertyAccessorMode == 3 && !f->IsProperty() ) continue; - + // Ignore script functions, if the application has disabled script defined property accessors if( engine->ep.propertyAccessorMode == 1 && f->funcType == asFUNC_SCRIPT ) continue; - + // TODO: The type of the parameter should match the argument (unless the arg is a dummy) - if( (int)f->parameterTypes.GetLength() == (arg?1:0) ) + if( (int)f->parameterTypes.GetLength() == (arg ? 1 : 0) ) { if( getId == 0 ) getId = funcs[n]; @@ -14066,13 +14075,13 @@ int asCCompiler::FindPropertyAccessor(const asCString &name, asCExprContext *ctx if( engine->ep.propertyAccessorMode == 3 && !f->IsProperty() ) continue; - + // Ignore script functions, if the application has disabled script defined property accessors if( engine->ep.propertyAccessorMode == 1 && f->funcType == asFUNC_SCRIPT ) continue; - + // TODO: getset: If the parameter is a reference, it must not be an out reference. Should we allow inout ref? - if( (int)f->parameterTypes.GetLength() == (arg?2:1) ) + if( (int)f->parameterTypes.GetLength() == (arg ? 2 : 1) ) { if( setId == 0 ) setId = funcs[n]; @@ -14097,7 +14106,7 @@ int asCCompiler::FindPropertyAccessor(const asCString &name, asCExprContext *ctx if( multipleGetFuncs.GetLength() > 1 ) { - if (node) + if( node ) { asCString str; str.Format(TXT_MULTIPLE_PROP_GET_ACCESSOR_FOR_s, name.AddressOf()); @@ -14122,7 +14131,7 @@ int asCCompiler::FindPropertyAccessor(const asCString &name, asCExprContext *ctx if( multipleSetFuncs.GetLength() > 1 ) { - if (node) + if( node ) { asCString str; str.Format(TXT_MULTIPLE_PROP_SET_ACCESSOR_FOR_s, name.AddressOf()); @@ -14147,12 +14156,12 @@ int asCCompiler::FindPropertyAccessor(const asCString &name, asCExprContext *ctx asCScriptFunction *setFunc = builder->GetFunctionDescription(setId); // It is permitted for a getter to return a handle and the setter to take a reference - int idx = (arg?1:0); + int idx = (arg ? 1 : 0); if( !getFunc->returnType.IsEqualExceptRefAndConst(setFunc->parameterTypes[idx]) && - !((getFunc->returnType.IsObjectHandle() && !setFunc->parameterTypes[idx].IsObjectHandle()) && - (getFunc->returnType.GetTypeInfo() == setFunc->parameterTypes[idx].GetTypeInfo())) ) + !((getFunc->returnType.IsObjectHandle() && !setFunc->parameterTypes[idx].IsObjectHandle()) && + (getFunc->returnType.GetTypeInfo() == setFunc->parameterTypes[idx].GetTypeInfo())) ) { - if (node) + if( node ) { asCString str; str.Format(TXT_GET_SET_ACCESSOR_TYPE_MISMATCH_FOR_s, name.AddressOf()); @@ -14177,21 +14186,21 @@ int asCCompiler::FindPropertyAccessor(const asCString &name, asCExprContext *ctx // The property accessors would be virtual functions, so we need to find the real implementation asCScriptFunction *getFunc = getId ? builder->GetFunctionDescription(getId) : 0; if( getFunc && - getFunc->funcType == asFUNC_VIRTUAL && - outFunc->objectType->DerivesFrom(getFunc->objectType) ) + getFunc->funcType == asFUNC_VIRTUAL && + outFunc->objectType->DerivesFrom(getFunc->objectType) ) realGetId = outFunc->objectType->virtualFunctionTable[getFunc->vfTableIdx]->id; asCScriptFunction *setFunc = setId ? builder->GetFunctionDescription(setId) : 0; if( setFunc && - setFunc->funcType == asFUNC_VIRTUAL && - outFunc->objectType->DerivesFrom(setFunc->objectType) ) + setFunc->funcType == asFUNC_VIRTUAL && + outFunc->objectType->DerivesFrom(setFunc->objectType) ) realSetId = outFunc->objectType->virtualFunctionTable[setFunc->vfTableIdx]->id; } // Avoid recursive call by not treating this as a property accessor call. // This will also allow having the real property with the same name as the accessors. if( (isThisAccess || outFunc->objectType == 0) && - ((realGetId && realGetId == outFunc->id) || - (realSetId && realSetId == outFunc->id)) ) + ((realGetId && realGetId == outFunc->id) || + (realSetId && realSetId == outFunc->id)) ) { getId = 0; setId = 0; @@ -14211,7 +14220,7 @@ int asCCompiler::FindPropertyAccessor(const asCString &name, asCExprContext *ctx { // If the object is read-only then we need to remember that if( (!ctx->type.dataType.IsObjectHandle() && ctx->type.dataType.IsReadOnly()) || - (ctx->type.dataType.IsObjectHandle() && ctx->type.dataType.IsHandleToConst()) ) + (ctx->type.dataType.IsObjectHandle() && ctx->type.dataType.IsHandleToConst()) ) ctx->property_const = true; else ctx->property_const = false; @@ -14225,18 +14234,18 @@ int asCCompiler::FindPropertyAccessor(const asCString &name, asCExprContext *ctx // unless only the getter is available asCDataType dt; if( setId ) - dt = builder->GetFunctionDescription(setId)->parameterTypes[(arg?1:0)]; + dt = builder->GetFunctionDescription(setId)->parameterTypes[(arg ? 1 : 0)]; else dt = builder->GetFunctionDescription(getId)->returnType; // Just change the type, the context must still maintain information // about previous variable offset and the indicator of temporary variable. - int offset = ctx->type.stackOffset; + int offset = ctx->type.stackOffset; bool isTemp = ctx->type.isTemporary; ctx->type.Set(dt); ctx->type.stackOffset = (short)offset; ctx->type.isTemporary = isTemp; - ctx->exprNode = node; + ctx->exprNode = node; // Remember if the object is safe, so the invocation of the property // accessor doesn't needlessly make a safe copy of the handle @@ -14298,7 +14307,7 @@ int asCCompiler::ProcessPropertySetAccessor(asCExprContext *ctx, asCExprContext // Setup the context with the original type so the method call gets built correctly ctx->type.dataType = asCDataType::CreateType(func->objectType, ctx->property_const); if( ctx->property_handle ) ctx->type.dataType.MakeHandle(true); - if( ctx->property_ref ) ctx->type.dataType.MakeReference(true); + if( ctx->property_ref ) ctx->type.dataType.MakeReference(true); // Don't allow the call if the object is read-only and the property accessor is not const if( ctx->property_const && !func->IsReadOnly() ) @@ -14362,22 +14371,48 @@ int asCCompiler::ProcessPropertyGetSetAccessor(asCExprContext *ctx, asCExprConte // Translate the compound assignment to the corresponding dual operator switch( op ) { - case ttAddAssign: op = ttPlus; break; - case ttSubAssign: op = ttMinus; break; - case ttMulAssign: op = ttStar; break; - case ttDivAssign: op = ttSlash; break; - case ttModAssign: op = ttPercent; break; - case ttPowAssign: op = ttStarStar; break; + case ttAddAssign: + op = ttPlus; + break; + case ttSubAssign: + op = ttMinus; + break; + case ttMulAssign: + op = ttStar; + break; + case ttDivAssign: + op = ttSlash; + break; + case ttModAssign: + op = ttPercent; + break; + case ttPowAssign: + op = ttStarStar; + break; - case ttAndAssign: op = ttAmp; break; - case ttOrAssign: op = ttBitOr; break; - case ttXorAssign: op = ttBitXor; break; + case ttAndAssign: + op = ttAmp; + break; + case ttOrAssign: + op = ttBitOr; + break; + case ttXorAssign: + op = ttBitXor; + break; - case ttShiftLeftAssign: op = ttBitShiftLeft; break; - case ttShiftRightAAssign: op = ttBitShiftRightArith; break; - case ttShiftRightLAssign: op = ttBitShiftRight; break; + case ttShiftLeftAssign: + op = ttBitShiftLeft; + break; + case ttShiftRightAAssign: + op = ttBitShiftRightArith; + break; + case ttShiftRightLAssign: + op = ttBitShiftRight; + break; - default: op = ttUnrecognizedToken; break; + default: + op = ttUnrecognizedToken; + break; } if( op == ttUnrecognizedToken ) @@ -14391,7 +14426,7 @@ int asCCompiler::ProcessPropertyGetSetAccessor(asCExprContext *ctx, asCExprConte } asCExprContext before(engine); - if( func->objectType && (func->objectType->flags & (asOBJ_REF|asOBJ_SCOPED)) == asOBJ_REF ) + if( func->objectType && (func->objectType->flags & (asOBJ_REF | asOBJ_SCOPED)) == asOBJ_REF ) { // Keep a reference to the object in a local variable before.bc.AddCode(&lctx->bc); @@ -14400,8 +14435,8 @@ int asCCompiler::ProcessPropertyGetSetAccessor(asCExprContext *ctx, asCExprConte rctx->bc.GetVarsUsed(reservedVariables); before.bc.GetVarsUsed(reservedVariables); - asCDataType dt = asCDataType::CreateObjectHandle(func->objectType, false); - int offset = AllocateVariable(dt, true); + asCDataType dt = asCDataType::CreateObjectHandle(func->objectType, false); + int offset = AllocateVariable(dt, true); reservedVariables.SetLength(len); @@ -14417,9 +14452,9 @@ int asCCompiler::ProcessPropertyGetSetAccessor(asCExprContext *ctx, asCExprConte { // Add the release of the temporary variable as a deferred expression asSDeferredParam deferred; - deferred.origExpr = 0; + deferred.origExpr = 0; deferred.argInOutFlags = asTM_INREF; - deferred.argNode = 0; + deferred.argNode = 0; deferred.argType.SetVariable(ctx->type.dataType, lctx->type.stackOffset, true); before.deferredParams.PushLast(deferred); } @@ -14427,7 +14462,7 @@ int asCCompiler::ProcessPropertyGetSetAccessor(asCExprContext *ctx, asCExprConte // Update the left expression to use the local variable lctx->bc.InstrSHORT(asBC_PSF, (short)offset); lctx->type.stackOffset = (short)offset; - lctx->property_ref = true; + lctx->property_ref = true; // Don't release the temporary variable too early lctx->type.isTemporary = false; @@ -14437,7 +14472,7 @@ int asCCompiler::ProcessPropertyGetSetAccessor(asCExprContext *ctx, asCExprConte // Keep the original information on the property asCExprContext llctx(engine); - llctx.type = lctx->type; + llctx.type = lctx->type; llctx.property_arg = lctx->property_arg; llctx.property_const = lctx->property_const; llctx.property_get = lctx->property_get; @@ -14479,8 +14514,8 @@ int asCCompiler::ProcessPropertyGetAccessor(asCExprContext *ctx, asCScriptNode * return -1; } - asCExprValue objType = ctx->type; - asCScriptFunction *func = builder->GetFunctionDescription(ctx->property_get); + asCExprValue objType = ctx->type; + asCScriptFunction *func = builder->GetFunctionDescription(ctx->property_get); // Make sure the arg match the property asCArray funcs; @@ -14534,7 +14569,7 @@ int asCCompiler::ProcessPropertyGetAccessor(asCExprContext *ctx, asCScriptNode * asDELETE(ctx->property_arg, asCExprContext); ctx->property_arg = 0; } - + return r; } @@ -14563,8 +14598,12 @@ int asCCompiler::CompileExpressionPostOp(asCScriptNode *node, asCExprContext *ct const char *opName = 0; switch( op ) { - case ttInc: opName = "opPostInc"; break; - case ttDec: opName = "opPostDec"; break; + case ttInc: + opName = "opPostInc"; + break; + case ttDec: + opName = "opPostDec"; + break; } if( opName ) @@ -14576,15 +14615,15 @@ int asCCompiler::CompileExpressionPostOp(asCScriptNode *node, asCExprContext *ct // TODO: If the value isn't const, then first try to find the non const method, and if not found try to find the const method // Find the correct method - bool isConst = ctx->type.dataType.IsObjectConst(); - asCArray funcs; + bool isConst = ctx->type.dataType.IsObjectConst(); + asCArray funcs; asCObjectType *ot = CastToObjectType(ctx->type.dataType.GetTypeInfo()); for( asUINT n = 0; n < ot->methods.GetLength(); n++ ) { asCScriptFunction *func = engine->scriptFunctions[ot->methods[n]]; if( func->name == opName && - func->parameterTypes.GetLength() == 0 && - (!isConst || func->IsReadOnly()) ) + func->parameterTypes.GetLength() == 0 && + (!isConst || func->IsReadOnly()) ) { funcs.PushLast(func->id); } @@ -14692,7 +14731,8 @@ int asCCompiler::CompileExpressionPostOp(asCScriptNode *node, asCExprContext *ct return -1; } - if( op == ttInc ) ctx->bc.Instr(iInc); else ctx->bc.Instr(iDec); + if( op == ttInc ) ctx->bc.Instr(iInc); + else ctx->bc.Instr(iDec); } else if( op == ttDot ) { @@ -14756,7 +14796,7 @@ int asCCompiler::CompileExpressionPostOp(asCScriptNode *node, asCExprContext *ct // This must always be done even if the offset is 0 because the asCWriter needs the meta data in ADDSi to identify the composite property if( prop->compositeOffset || prop->isCompositeIndirect ) ctx->bc.InstrSHORT_DW(asBC_ADDSi, (short)prop->compositeOffset, engine->GetTypeIdFromDataType(asCDataType::CreateType(ctx->type.dataType.GetTypeInfo(), false))); - if (prop->isCompositeIndirect) + if( prop->isCompositeIndirect ) ctx->bc.Instr(asBC_RDSPtr); // Put the offset on the stack @@ -14775,9 +14815,9 @@ int asCCompiler::CompileExpressionPostOp(asCScriptNode *node, asCExprContext *ct { // Add the release of this reference, as a deferred expression asSDeferredParam deferred; - deferred.origExpr = 0; + deferred.origExpr = 0; deferred.argInOutFlags = asTM_INREF; - deferred.argNode = 0; + deferred.argNode = 0; deferred.argType.SetVariable(ctx->type.dataType, ctx->type.stackOffset, true); ctx->deferredParams.PushLast(deferred); @@ -14786,7 +14826,7 @@ int asCCompiler::CompileExpressionPostOp(asCScriptNode *node, asCExprContext *ct // Set the new type and make sure it is not treated as a variable anymore ctx->type.dataType = prop->type; ctx->type.dataType.MakeReference(true); - ctx->type.isVariable = false; + ctx->type.isVariable = false; ctx->type.isTemporary = false; if( (ctx->type.dataType.IsObject() || ctx->type.dataType.IsFuncdef()) && !ctx->type.dataType.IsObjectHandle() ) @@ -14796,7 +14836,7 @@ int asCCompiler::CompileExpressionPostOp(asCScriptNode *node, asCExprContext *ct // The object is safe (life time guaranteed) if the parent object is also safe } - else if (ctx->type.dataType.IsObjectHandle()) + else if( ctx->type.dataType.IsObjectHandle() ) { // A object accessed through a handle cannot be considered safe, // as it can be cleared at any time @@ -14810,7 +14850,7 @@ int asCCompiler::CompileExpressionPostOp(asCScriptNode *node, asCExprContext *ct // If the name is not a property, the compiler must check if the name matches // a method, which can be used for constructing delegates asIScriptFunction *func = 0; - asCObjectType *ot = CastToObjectType(ctx->type.dataType.GetTypeInfo()); + asCObjectType *ot = CastToObjectType(ctx->type.dataType.GetTypeInfo()); for( asUINT n = 0; n < ot->methods.GetLength(); n++ ) { if( engine->scriptFunctions[ot->methods[n]]->name == name ) @@ -14870,11 +14910,11 @@ int asCCompiler::CompileExpressionPostOp(asCScriptNode *node, asCExprContext *ct // then we should use that instead of processing it now. If the argument has already been // evaluated, then we should process the property accessor as a get access now as the new // index operator is on the result of that accessor. - asCString propertyName; + asCString propertyName; asSNameSpace *ns = 0; if( ((ctx->property_get && builder->GetFunctionDescription(ctx->property_get)->GetParamCount() == 1) || - (ctx->property_set && builder->GetFunctionDescription(ctx->property_set)->GetParamCount() == 2)) && - (ctx->property_arg && ctx->property_arg->type.dataType.GetTokenType() == ttUnrecognizedToken) ) + (ctx->property_set && builder->GetFunctionDescription(ctx->property_set)->GetParamCount() == 2)) && + (ctx->property_arg && ctx->property_arg->type.dataType.GetTokenType() == ttUnrecognizedToken) ) { // Determine the name of the property accessor asCScriptFunction *func = 0; @@ -14890,7 +14930,7 @@ int asCCompiler::CompileExpressionPostOp(asCScriptNode *node, asCExprContext *ct { ctx->type.dataType = asCDataType::CreateType(func->objectType, ctx->property_const); if( ctx->property_handle ) ctx->type.dataType.MakeHandle(true); - if( ctx->property_ref ) ctx->type.dataType.MakeReference(true); + if( ctx->property_ref ) ctx->type.dataType.MakeReference(true); } else { @@ -14922,14 +14962,14 @@ int asCCompiler::CompileExpressionPostOp(asCScriptNode *node, asCExprContext *ct } // Compile the expression - bool isOK = true; + bool isOK = true; asCArray args; asCArray namedArgs; asASSERT( node->firstChild->nodeType == snArgList ); if( CompileArgumentList(node->firstChild, args, namedArgs) >= 0 ) { // TODO: Add support for named args on index operator too - if (namedArgs.GetLength() > 0) + if( namedArgs.GetLength() > 0 ) { Error(TXT_INVALID_USE_OF_NAMED_ARGS, node); isOK = false; @@ -14939,7 +14979,7 @@ int asCCompiler::CompileExpressionPostOp(asCScriptNode *node, asCExprContext *ct bool lookForProperty = true; if( propertyName == "" ) { - bool isConst = ctx->type.dataType.IsObjectConst(); + bool isConst = ctx->type.dataType.IsObjectConst(); asCObjectType *objectType = CastToObjectType(ctx->type.dataType.GetTypeInfo()); asCArray funcs; @@ -14984,17 +15024,17 @@ int asCCompiler::CompileExpressionPostOp(asCScriptNode *node, asCExprContext *ct // Check for accessors methods for the opIndex, either as get/set_opIndex or as get/set with the property name int r = FindPropertyAccessor(propertyName == "" ? "opIndex" : propertyName.AddressOf(), &lctx, args[0], node, ns); - if (r == 0) + if( r == 0 ) { asCString str; str.Format(TXT_OBJECT_DOESNT_SUPPORT_INDEX_OP, ctx->type.dataType.Format(outFunc->nameSpace).AddressOf()); Error(str, node); isOK = false; } - else if (r < 0) + else if( r < 0 ) isOK = false; - if (isOK) + if( isOK ) MergeExprBytecodeAndType(ctx, &lctx); } } @@ -15006,8 +15046,8 @@ int asCCompiler::CompileExpressionPostOp(asCScriptNode *node, asCExprContext *ct for( asUINT n = 0; n < args.GetLength(); n++ ) if( args[n] ) asDELETE(args[n], asCExprContext); - for (asUINT n = 0; n < namedArgs.GetLength(); n++) - if (namedArgs[n].ctx) + for( asUINT n = 0; n < namedArgs.GetLength(); n++ ) + if( namedArgs[n].ctx ) asDELETE(namedArgs[n].ctx, asCExprContext); if( !isOK ) @@ -15025,7 +15065,7 @@ int asCCompiler::CompileExpressionPostOp(asCScriptNode *node, asCExprContext *ct } // Compile arguments - bool isOK = true; + bool isOK = true; asCArray args; asCArray namedArgs; if( CompileArgumentList(node->lastChild, args, namedArgs) >= 0 ) @@ -15092,7 +15132,7 @@ int asCCompiler::CompileExpressionPostOp(asCScriptNode *node, asCExprContext *ct for( asUINT n = 0; n < namedArgs.GetLength(); n++ ) if( namedArgs[n].ctx ) asDELETE(namedArgs[n].ctx, asCExprContext); - + if( !isOK ) return -1; } @@ -15131,8 +15171,8 @@ int asCCompiler::GetPrecedence(asCScriptNode *op) return -2; if( tokenType == ttBitShiftLeft || - tokenType == ttBitShiftRight || - tokenType == ttBitShiftRightArith ) + tokenType == ttBitShiftRight || + tokenType == ttBitShiftRightArith ) return -3; if( tokenType == ttAmp ) @@ -15145,9 +15185,9 @@ int asCCompiler::GetPrecedence(asCScriptNode *op) return -6; if( tokenType == ttLessThanOrEqual || - tokenType == ttLessThan || - tokenType == ttGreaterThanOrEqual || - tokenType == ttGreaterThan ) + tokenType == ttLessThan || + tokenType == ttGreaterThanOrEqual || + tokenType == ttGreaterThan ) return -7; if( tokenType == ttEqual || tokenType == ttNotEqual || tokenType == ttXor || tokenType == ttIs || tokenType == ttNotIs ) @@ -15175,12 +15215,12 @@ asUINT asCCompiler::MatchArgument(asCArray &funcs, asCArrayparameterTypes.GetLength(); - if (desc->IsVariadic()) + if( desc->IsVariadic() ) { asASSERT(paramCount >= 1); paramCount -= 1; } - if( (int)paramCount <= paramNum && !desc->IsVariadic()) + if( (int)paramCount <= paramNum && !desc->IsVariadic() ) continue; int cost = MatchArgument(desc, argExpr, paramNum, allowObjectConstruct); @@ -15193,7 +15233,7 @@ asUINT asCCompiler::MatchArgument(asCArray &funcs, asCArrayIsVariadic() && paramNum >= (int)desc->parameterTypes.GetLength() - 1) + if( desc->IsVariadic() && paramNum >= (int)desc->parameterTypes.GetLength() - 1 ) { paramNum = (int)desc->parameterTypes.GetLength() - 1; } @@ -15207,11 +15247,11 @@ int asCCompiler::MatchArgument(asCScriptFunction *desc, const asCExprContext *ar } // Anonymous init lists can only match parameters that can be initialized with a list - if (argExpr->IsAnonymousInitList()) + if( argExpr->IsAnonymousInitList() ) { if( (desc->parameterTypes[paramNum].IsReference() && (desc->inOutFlags[paramNum] & asTM_INREF) == 0) || - desc->parameterTypes[paramNum].GetBehaviour() == 0 || - desc->parameterTypes[paramNum].GetBehaviour()->listFactory == 0 ) + desc->parameterTypes[paramNum].GetBehaviour() == 0 || + desc->parameterTypes[paramNum].GetBehaviour()->listFactory == 0 ) { return -1; } @@ -15220,77 +15260,77 @@ int asCCompiler::MatchArgument(asCScriptFunction *desc, const asCExprContext *ar // For &out references, ensure no match is given for impossible conversion from param type to arg type // The cost for this conversion is not used, as we still want to use the same order of prioritization as for input arguments - if (desc->parameterTypes[paramNum].IsReference() && desc->inOutFlags[paramNum] == asTM_OUTREF && - desc->parameterTypes[paramNum].GetTokenType() != ttQuestion && - !argExpr->type.IsNullConstant() && !argExpr->IsVoidExpression() ) + if( desc->parameterTypes[paramNum].IsReference() && desc->inOutFlags[paramNum] == asTM_OUTREF && + desc->parameterTypes[paramNum].GetTokenType() != ttQuestion && + !argExpr->type.IsNullConstant() && !argExpr->IsVoidExpression() ) { // For out references that are not vartype, the type of argument must be convertible to the type of the argument asCExprContext ti(engine); - asCExprValue type; + asCExprValue type; type.dataType = desc->parameterTypes[paramNum]; - ti.type = type; - ti.exprNode = argExpr->exprNode; + ti.type = type; + ti.exprNode = argExpr->exprNode; ImplicitConversion(&ti, argExpr->type.dataType, 0, asIC_IMPLICIT_CONV, false, allowObjectConstruct); - if (!argExpr->type.dataType.IsEqualExceptRef(ti.type.dataType)) + if( !argExpr->type.dataType.IsEqualExceptRef(ti.type.dataType) ) return -1; } // Can we make the match by implicit conversion? - int cost = -1; + int cost = -1; asCExprContext ti(engine); - ti.type = argExpr->type; + ti.type = argExpr->type; ti.methodName = argExpr->methodName; - ti.enumValue = argExpr->enumValue; - ti.exprNode = argExpr->exprNode; - if (argExpr->type.dataType.IsPrimitive()) + ti.enumValue = argExpr->enumValue; + ti.exprNode = argExpr->exprNode; + if( argExpr->type.dataType.IsPrimitive() ) ti.type.dataType.MakeReference(false); // Don't allow the implicit conversion to make a copy in case the argument is expecting a reference to the true value - if (desc->parameterTypes[paramNum].IsReference() && desc->inOutFlags[paramNum] == asTM_INOUTREF) + if( desc->parameterTypes[paramNum].IsReference() && desc->inOutFlags[paramNum] == asTM_INOUTREF ) allowObjectConstruct = false; cost = ImplicitConversion(&ti, desc->parameterTypes[paramNum], 0, asIC_IMPLICIT_CONV, false, allowObjectConstruct); - if (!desc->parameterTypes[paramNum].IsEqualExceptRef(ti.type.dataType)) + if( !desc->parameterTypes[paramNum].IsEqualExceptRef(ti.type.dataType) ) return -1; // If the function parameter is an inout-reference then it must not be possible to call the // function with an incorrect argument type, even though the type can normally be converted. - if (desc->parameterTypes[paramNum].IsReference() && - desc->inOutFlags[paramNum] == asTM_INOUTREF && - desc->parameterTypes[paramNum].GetTokenType() != ttQuestion) + if( desc->parameterTypes[paramNum].IsReference() && + desc->inOutFlags[paramNum] == asTM_INOUTREF && + desc->parameterTypes[paramNum].GetTokenType() != ttQuestion ) { // Observe, that the below checks are only necessary for when unsafe references have been // enabled by the application. Without this the &inout reference form wouldn't be allowed // for these value types. // Don't allow a primitive to be converted to a reference of another primitive type - if (desc->parameterTypes[paramNum].IsPrimitive() && - desc->parameterTypes[paramNum].GetTokenType() != argExpr->type.dataType.GetTokenType()) + if( desc->parameterTypes[paramNum].IsPrimitive() && + desc->parameterTypes[paramNum].GetTokenType() != argExpr->type.dataType.GetTokenType() ) { asASSERT(engine->ep.allowUnsafeReferences); return -1; } // Don't allow an enum to be converted to a reference of another enum type - if (desc->parameterTypes[paramNum].IsEnumType() && - desc->parameterTypes[paramNum].GetTypeInfo() != argExpr->type.dataType.GetTypeInfo()) + if( desc->parameterTypes[paramNum].IsEnumType() && + desc->parameterTypes[paramNum].GetTypeInfo() != argExpr->type.dataType.GetTypeInfo() ) { asASSERT(engine->ep.allowUnsafeReferences); return -1; } // Don't allow a non-handle expression to be converted to a reference to a handle - if (desc->parameterTypes[paramNum].IsObjectHandle() && - !argExpr->type.dataType.IsObjectHandle()) + if( desc->parameterTypes[paramNum].IsObjectHandle() && + !argExpr->type.dataType.IsObjectHandle() ) { asASSERT(engine->ep.allowUnsafeReferences); return -1; } // Don't allow a value type to be converted - if ((desc->parameterTypes[paramNum].GetTypeInfo() && (desc->parameterTypes[paramNum].GetTypeInfo()->GetFlags() & asOBJ_VALUE)) && - (desc->parameterTypes[paramNum].GetTypeInfo() != argExpr->type.dataType.GetTypeInfo())) + if( (desc->parameterTypes[paramNum].GetTypeInfo() && (desc->parameterTypes[paramNum].GetTypeInfo()->GetFlags() & asOBJ_VALUE)) && + (desc->parameterTypes[paramNum].GetTypeInfo() != argExpr->type.dataType.GetTypeInfo()) ) { asASSERT(engine->ep.allowUnsafeReferences); return -1; @@ -15318,7 +15358,7 @@ int asCCompiler::PrepareArgument2(asCExprContext *ctx, asCExprContext *arg, asCD } int r = PrepareArgument(paramType, arg, arg->exprNode, isFunction, refType, isMakingCopy); - if (r < 0) + if( r < 0 ) return r; // arg still holds the original expression for output parameters @@ -15347,13 +15387,13 @@ bool asCCompiler::CompileOverloadedDualOperator(asCScriptNode *node, asCExprCont // boolean operators are not overloadable if( token == ttAnd || - token == ttOr || - token == ttXor ) + token == ttOr || + token == ttXor ) return false; // Dual operators can also be implemented as class methods if( token == ttEqual || - token == ttNotEqual ) + token == ttNotEqual ) { // TODO: Should evaluate which of the two have the best match. If both have equal match, the first version should be used // Find the matching opEquals method @@ -15381,11 +15421,11 @@ bool asCCompiler::CompileOverloadedDualOperator(asCScriptNode *node, asCExprCont } if( token == ttEqual || - token == ttNotEqual || - token == ttLessThan || - token == ttLessThanOrEqual || - token == ttGreaterThan || - token == ttGreaterThanOrEqual ) + token == ttNotEqual || + token == ttLessThan || + token == ttLessThanOrEqual || + token == ttGreaterThan || + token == ttGreaterThanOrEqual ) { bool swappedOrder = false; @@ -15396,7 +15436,7 @@ bool asCCompiler::CompileOverloadedDualOperator(asCScriptNode *node, asCExprCont { // Try again by switching the order of the operands swappedOrder = true; - r = CompileOverloadedDualOperator2(node, "opCmp", rctx, lctx, !leftToRight, ctx, true, asCDataType::CreatePrimitive(ttInt, false)); + r = CompileOverloadedDualOperator2(node, "opCmp", rctx, lctx, !leftToRight, ctx, true, asCDataType::CreatePrimitive(ttInt, false)); } if( r == 1 ) @@ -15412,16 +15452,16 @@ bool asCCompiler::CompileOverloadedDualOperator(asCScriptNode *node, asCExprCont else if( token == ttNotEqual ) ctx->bc.Instr(asBC_TNZ); else if( (token == ttLessThan && !swappedOrder) || - (token == ttGreaterThan && swappedOrder) ) + (token == ttGreaterThan && swappedOrder) ) ctx->bc.Instr(asBC_TS); else if( (token == ttLessThanOrEqual && !swappedOrder) || - (token == ttGreaterThanOrEqual && swappedOrder) ) + (token == ttGreaterThanOrEqual && swappedOrder) ) ctx->bc.Instr(asBC_TNP); else if( (token == ttGreaterThan && !swappedOrder) || - (token == ttLessThan && swappedOrder) ) + (token == ttLessThan && swappedOrder) ) ctx->bc.Instr(asBC_TP); else if( (token == ttGreaterThanOrEqual && !swappedOrder) || - (token == ttLessThanOrEqual && swappedOrder) ) + (token == ttLessThanOrEqual && swappedOrder) ) ctx->bc.Instr(asBC_TNS); ctx->bc.InstrSHORT(asBC_CpyRtoV4, (short)a); @@ -15433,12 +15473,12 @@ bool asCCompiler::CompileOverloadedDualOperator(asCScriptNode *node, asCExprCont } else if( r < 0 ) { - // Compiler error, don't continue - #if AS_SIZEOF_BOOL == 1 - ctx->type.SetConstantB(asCDataType::CreatePrimitive(ttBool, true), true); - #else - ctx->type.SetConstantDW(asCDataType::CreatePrimitive(ttBool, true), true); - #endif + // Compiler error, don't continue + #if AS_SIZEOF_BOOL == 1 + ctx->type.SetConstantB(asCDataType::CreatePrimitive(ttBool, true), true); + #else + ctx->type.SetConstantDW(asCDataType::CreatePrimitive(ttBool, true), true); + #endif return true; } } @@ -15447,18 +15487,54 @@ bool asCCompiler::CompileOverloadedDualOperator(asCScriptNode *node, asCExprCont const char *op = 0, *op_r = 0; switch( int(token) ) // convert to int to avoid warning in gnuc that not all values are tested { - case ttPlus: op = "opAdd"; op_r = "opAdd_r"; break; - case ttMinus: op = "opSub"; op_r = "opSub_r"; break; - case ttStar: op = "opMul"; op_r = "opMul_r"; break; - case ttSlash: op = "opDiv"; op_r = "opDiv_r"; break; - case ttPercent: op = "opMod"; op_r = "opMod_r"; break; - case ttStarStar: op = "opPow"; op_r = "opPow_r"; break; - case ttBitOr: op = "opOr"; op_r = "opOr_r"; break; - case ttAmp: op = "opAnd"; op_r = "opAnd_r"; break; - case ttBitXor: op = "opXor"; op_r = "opXor_r"; break; - case ttBitShiftLeft: op = "opShl"; op_r = "opShl_r"; break; - case ttBitShiftRight: op = "opShr"; op_r = "opShr_r"; break; - case ttBitShiftRightArith: op = "opUShr"; op_r = "opUShr_r"; break; + case ttPlus: + op = "opAdd"; + op_r = "opAdd_r"; + break; + case ttMinus: + op = "opSub"; + op_r = "opSub_r"; + break; + case ttStar: + op = "opMul"; + op_r = "opMul_r"; + break; + case ttSlash: + op = "opDiv"; + op_r = "opDiv_r"; + break; + case ttPercent: + op = "opMod"; + op_r = "opMod_r"; + break; + case ttStarStar: + op = "opPow"; + op_r = "opPow_r"; + break; + case ttBitOr: + op = "opOr"; + op_r = "opOr_r"; + break; + case ttAmp: + op = "opAnd"; + op_r = "opAnd_r"; + break; + case ttBitXor: + op = "opXor"; + op_r = "opXor_r"; + break; + case ttBitShiftLeft: + op = "opShl"; + op_r = "opShl_r"; + break; + case ttBitShiftRight: + op = "opShr"; + op_r = "opShr_r"; + break; + case ttBitShiftRightArith: + op = "opUShr"; + op_r = "opUShr_r"; + break; } // TODO: Might be interesting to support a concatenation operator, e.g. ~ @@ -15502,26 +15578,52 @@ bool asCCompiler::CompileOverloadedDualOperator(asCScriptNode *node, asCExprCont { switch( int(token) ) // convert to int to avoid warning in gnuc that not all values are tested { - case ttAssignment: op = "opAssign"; break; - case ttAddAssign: op = "opAddAssign"; break; - case ttSubAssign: op = "opSubAssign"; break; - case ttMulAssign: op = "opMulAssign"; break; - case ttDivAssign: op = "opDivAssign"; break; - case ttModAssign: op = "opModAssign"; break; - case ttPowAssign: op = "opPowAssign"; break; - case ttOrAssign: op = "opOrAssign"; break; - case ttAndAssign: op = "opAndAssign"; break; - case ttXorAssign: op = "opXorAssign"; break; - case ttShiftLeftAssign: op = "opShlAssign"; break; - case ttShiftRightLAssign: op = "opShrAssign"; break; - case ttShiftRightAAssign: op = "opUShrAssign"; break; + case ttAssignment: + op = "opAssign"; + break; + case ttAddAssign: + op = "opAddAssign"; + break; + case ttSubAssign: + op = "opSubAssign"; + break; + case ttMulAssign: + op = "opMulAssign"; + break; + case ttDivAssign: + op = "opDivAssign"; + break; + case ttModAssign: + op = "opModAssign"; + break; + case ttPowAssign: + op = "opPowAssign"; + break; + case ttOrAssign: + op = "opOrAssign"; + break; + case ttAndAssign: + op = "opAndAssign"; + break; + case ttXorAssign: + op = "opXorAssign"; + break; + case ttShiftLeftAssign: + op = "opShlAssign"; + break; + case ttShiftRightLAssign: + op = "opShrAssign"; + break; + case ttShiftRightAAssign: + op = "opUShrAssign"; + break; } } if( op ) { if( builder->engine->ep.disallowValueAssignForRefType && - lctx->type.dataType.GetTypeInfo() && (lctx->type.dataType.GetTypeInfo()->flags & asOBJ_REF) && !(lctx->type.dataType.GetTypeInfo()->flags & asOBJ_SCOPED) ) + lctx->type.dataType.GetTypeInfo() && (lctx->type.dataType.GetTypeInfo()->flags & asOBJ_REF) && !(lctx->type.dataType.GetTypeInfo()->flags & asOBJ_SCOPED) ) { if( token == ttAssignment ) Error(TXT_DISALLOW_ASSIGN_ON_REF_TYPE, node); @@ -15561,16 +15663,16 @@ int asCCompiler::CompileOverloadedDualOperator2(asCScriptNode *node, const char { // Find the matching method if( lctx->type.dataType.IsObject() && - (!lctx->type.isExplicitHandle || - lctx->type.dataType.GetTypeInfo()->flags & asOBJ_ASHANDLE) && - !lctx->type.IsNullConstant() ) + (!lctx->type.isExplicitHandle || + lctx->type.dataType.GetTypeInfo()->flags & asOBJ_ASHANDLE) && + !lctx->type.IsNullConstant() ) { asUINT n; // Is the left value a const? bool isConst = lctx->type.dataType.IsObjectConst(); - asCArray funcs; + asCArray funcs; asCObjectType *ot = CastToObjectType(lctx->type.dataType.GetTypeInfo()); asASSERT(ot); for( n = 0; ot && n < ot->methods.GetLength(); n++ ) @@ -15578,9 +15680,9 @@ int asCCompiler::CompileOverloadedDualOperator2(asCScriptNode *node, const char asCScriptFunction *func = engine->scriptFunctions[ot->methods[n]]; asASSERT( func ); if( func && func->name == methodName && - (!specificReturn || func->returnType == returnType) && - func->parameterTypes.GetLength() == 1 && - (!isConst || func->IsReadOnly()) ) + (!specificReturn || func->returnType == returnType) && + func->parameterTypes.GetLength() == 1 && + (!isConst || func->IsReadOnly()) ) { // Make sure the method is accessible by the module if( builder->module->m_accessMask & func->accessMask ) @@ -15596,7 +15698,7 @@ int asCCompiler::CompileOverloadedDualOperator2(asCScriptNode *node, const char // Find the lowest cost operator(s) asCArray ops; - asUINT bestCost = asUINT(-1); + asUINT bestCost = asUINT(-1); for( n = 0; n < tempFuncs.GetLength(); ++n ) { asUINT cost = tempFuncs[n].cost; @@ -15628,18 +15730,18 @@ int asCCompiler::CompileOverloadedDualOperator2(asCScriptNode *node, const char reservedVariables.SetLength(l); asCExprContext tmpCtx(engine); - if (leftToRight) + if( leftToRight ) { // Make sure lctx is in fact a variable. If it is a reference there is no // guarantee that the reference will stay alive throughout the evaluation of rctx - if (!lctx->type.isVariable) + if( !lctx->type.isVariable ) { // Reserve the variables used in the right expression so the new temporary // variable allocated for the left operand isn't accidentally overwritten. l = int(reservedVariables.GetLength()); rctx->bc.GetVarsUsed(reservedVariables); - if (engine->ep.allowUnsafeReferences && lctx->type.dataType.IsObject() && (lctx->type.dataType.GetTypeInfo()->flags & asOBJ_VALUE)) + if( engine->ep.allowUnsafeReferences && lctx->type.dataType.IsObject() && (lctx->type.dataType.GetTypeInfo()->flags & asOBJ_VALUE) ) { // If the application allows unsafe references, then it is not necessary to // make a copy of the object, just store the reference as a local variable @@ -15653,7 +15755,7 @@ int asCCompiler::CompileOverloadedDualOperator2(asCScriptNode *node, const char // Copy the pointer to the temporary variable lctx->bc.InstrSHORT(asBC_PSF, (short)offset); - if (lctx->type.dataType.IsFuncdef()) + if( lctx->type.dataType.IsFuncdef() ) lctx->bc.InstrPTR(asBC_REFCPY, &engine->functionBehaviours); else lctx->bc.InstrPTR(asBC_REFCPY, lctx->type.dataType.GetTypeInfo()); @@ -15662,7 +15764,7 @@ int asCCompiler::CompileOverloadedDualOperator2(asCScriptNode *node, const char } else { - if (lctx->type.dataType.SupportHandles()) + if( lctx->type.dataType.SupportHandles() ) lctx->type.dataType.MakeHandle(true); PrepareTemporaryVariable(node, lctx); } @@ -15681,7 +15783,7 @@ int asCCompiler::CompileOverloadedDualOperator2(asCScriptNode *node, const char // Implicitly dereference handle parameters sent by reference sVariable *v = variables->GetVariableByOffset(lctx->type.stackOffset); - if (v && v->type.IsReference() && (!v->type.IsObject() || v->type.IsObjectHandle())) + if( v && v->type.IsReference() && (!v->type.IsObject() || v->type.IsObjectHandle()) ) lctx->bc.Instr(asBC_RDSPtr); } else @@ -15691,17 +15793,17 @@ int asCCompiler::CompileOverloadedDualOperator2(asCScriptNode *node, const char asCArray usedVars; lctx->bc.GetVarsUsed(usedVars); asUINT oldReservedVars = reservedVariables.GetLength(); - for (n = 0; n < rctx->deferredParams.GetLength(); n++) + for( n = 0; n < rctx->deferredParams.GetLength(); n++ ) { - if (rctx->deferredParams[n].argType.isTemporary && - usedVars.Exists(rctx->deferredParams[n].argType.stackOffset)) + if( rctx->deferredParams[n].argType.isTemporary && + usedVars.Exists(rctx->deferredParams[n].argType.stackOffset) ) { - if (reservedVariables.GetLength() == oldReservedVars) + if( reservedVariables.GetLength() == oldReservedVars ) reservedVariables.Concatenate(usedVars); // Allocate a new variable for the deferred argument - int offset = AllocateVariableNotIn(rctx->deferredParams[n].argType.dataType, true, false, rctx); - int oldVar = rctx->deferredParams[n].argType.stackOffset; + int offset = AllocateVariableNotIn(rctx->deferredParams[n].argType.dataType, true, false, rctx); + int oldVar = rctx->deferredParams[n].argType.stackOffset; rctx->deferredParams[n].argType.stackOffset = short(offset); rctx->bc.ExchangeVar(oldVar, offset); ReleaseTemporaryVariable(oldVar, 0); @@ -15719,7 +15821,7 @@ int asCCompiler::CompileOverloadedDualOperator2(asCScriptNode *node, const char return -1; // Rearrange the bytecode so the left argument is computed first - if (leftToRight) + if( leftToRight ) { tmpCtx.bc.AddCode(&ctx->bc); ctx->bc.AddCode(&tmpCtx.bc); @@ -15744,12 +15846,12 @@ int asCCompiler::CompileOverloadedDualOperator2(asCScriptNode *node, const char return 0; } -int asCCompiler::MakeFunctionCall(asCExprContext *ctx, int funcId, asCObjectType *objectType, asCArray &args, asCScriptNode *node, bool useVariable, int stackOffset, int funcPtrVar, bool onHeap) +int asCCompiler::MakeFunctionCall(asCExprContext *ctx, int funcId, asCObjectType *objectType, asCArray &args, asCScriptNode *node, bool useVariable, int stackOffset, int funcPtrVar, bool onHeap) { if( objectType ) Dereference(ctx, true); - asCScriptFunction* descr = builder->GetFunctionDescription(funcId); + asCScriptFunction *descr = builder->GetFunctionDescription(funcId); // Store the expression node for error reporting if( ctx->exprNode == 0 ) @@ -15759,10 +15861,10 @@ int asCCompiler::MakeFunctionCall(asCExprContext *ctx, int funcId, asCObjectType objBC.AddCode(&ctx->bc); int r = PrepareFunctionCall(funcId, &ctx->bc, args); - if (r < 0) + if( r < 0 ) return r; - if (descr->IsVariadic()) + if( descr->IsVariadic() ) { // Argument count ctx->bc.InstrDWORD(asBC_PshC4, (asDWORD)args.GetLength()); @@ -15797,17 +15899,17 @@ int asCCompiler::MakeFunctionCall(asCExprContext *ctx, int funcId, asCObjectType } // Constructors for value types needs to be treated differently - if (descr->name == "$beh0" && descr->objectType && !(descr->objectType->flags & asOBJ_REF)) + if( descr->name == "$beh0" && descr->objectType && !(descr->objectType->flags & asOBJ_REF) ) { ctx->bc.AddCode(&objBC); MoveArgsToStack(funcId, &ctx->bc, args, false); // If the object is allocated on the stack, then call the constructor as a normal function - if (onHeap) + if( onHeap ) { int offset = 0; - for (n = 0; n < args.GetLength(); n++) + for( n = 0; n < args.GetLength(); n++ ) offset += descr->parameterTypes[n].GetSizeOnStackDWords(); ctx->bc.InstrWORD(asBC_GETREF, (asWORD)offset); @@ -15842,7 +15944,7 @@ int asCCompiler::MakeFunctionCall(asCExprContext *ctx, int funcId, asCObjectType MoveArgsToStack(funcId, &ctx->bc, args, objectType ? true : false); PerformFunctionCall(funcId, ctx, false, &args, 0, useVariable, stackOffset, funcPtrVar); - + return 0; } @@ -15869,8 +15971,8 @@ int asCCompiler::CompileOperator(asCScriptNode *node, asCExprContext *lctx, asCE IsVariableInitialized(&rctx->type, node); if( lctx->type.isExplicitHandle || rctx->type.isExplicitHandle || - lctx->type.IsNullConstant() || rctx->type.IsNullConstant() || - op == ttIs || op == ttNotIs ) + lctx->type.IsNullConstant() || rctx->type.IsNullConstant() || + op == ttIs || op == ttNotIs ) { CompileOperatorOnHandles(node, lctx, rctx, ctx, op); return 0; @@ -15911,12 +16013,12 @@ int asCCompiler::CompileOperator(asCScriptNode *node, asCExprContext *lctx, asCE // Math operators // + - * / % ** += -= *= /= %= **= - if( op == ttPlus || op == ttAddAssign || - op == ttMinus || op == ttSubAssign || - op == ttStar || op == ttMulAssign || - op == ttSlash || op == ttDivAssign || - op == ttPercent || op == ttModAssign || - op == ttStarStar || op == ttPowAssign ) + if( op == ttPlus || op == ttAddAssign || + op == ttMinus || op == ttSubAssign || + op == ttStar || op == ttMulAssign || + op == ttSlash || op == ttDivAssign || + op == ttPercent || op == ttModAssign || + op == ttStarStar || op == ttPowAssign ) { CompileMathOperator(node, lctx, rctx, ctx, op); return 0; @@ -15924,12 +16026,12 @@ int asCCompiler::CompileOperator(asCScriptNode *node, asCExprContext *lctx, asCE // Bitwise operators // << >> >>> & | ^ <<= >>= >>>= &= |= ^= - if( op == ttAmp || op == ttAndAssign || - op == ttBitOr || op == ttOrAssign || - op == ttBitXor || op == ttXorAssign || - op == ttBitShiftLeft || op == ttShiftLeftAssign || - op == ttBitShiftRight || op == ttShiftRightLAssign || - op == ttBitShiftRightArith || op == ttShiftRightAAssign ) + if( op == ttAmp || op == ttAndAssign || + op == ttBitOr || op == ttOrAssign || + op == ttBitXor || op == ttXorAssign || + op == ttBitShiftLeft || op == ttShiftLeftAssign || + op == ttBitShiftRight || op == ttShiftRightLAssign || + op == ttBitShiftRightArith || op == ttShiftRightAAssign ) { CompileBitwiseOperator(node, lctx, rctx, ctx, op); return 0; @@ -15937,9 +16039,9 @@ int asCCompiler::CompileOperator(asCScriptNode *node, asCExprContext *lctx, asCE // Comparison operators // == != < > <= >= - if( op == ttEqual || op == ttNotEqual || - op == ttLessThan || op == ttLessThanOrEqual || - op == ttGreaterThan || op == ttGreaterThanOrEqual ) + if( op == ttEqual || op == ttNotEqual || + op == ttLessThan || op == ttLessThanOrEqual || + op == ttGreaterThan || op == ttGreaterThanOrEqual ) { CompileComparisonOperator(node, lctx, rctx, ctx, op); return 0; @@ -15999,8 +16101,8 @@ void asCCompiler::ConvertToVariable(asCExprContext *ctx) int offset; if( !ctx->type.isVariable && - (ctx->type.dataType.IsObjectHandle() || - (ctx->type.dataType.IsObject() && ctx->type.dataType.SupportHandles())) ) + (ctx->type.dataType.IsObjectHandle() || + (ctx->type.dataType.IsObject() && ctx->type.dataType.SupportHandles())) ) { offset = AllocateVariable(ctx->type.dataType, true); if( ctx->type.IsNullConstant() ) @@ -16031,7 +16133,7 @@ void asCCompiler::ConvertToVariable(asCExprContext *ctx) ctx->type.dataType.MakeReference(true); } else if( (!ctx->type.isVariable || ctx->type.dataType.IsReference()) && - ctx->type.dataType.IsPrimitive() ) + ctx->type.dataType.IsPrimitive() ) { if( ctx->type.isConstant ) { @@ -16082,7 +16184,7 @@ void asCCompiler::ConvertToVariableNotIn(asCExprContext *ctx, asCExprContext *ex void asCCompiler::ImplicitConvObjectToBestMathType(asCExprContext *ctx, asCScriptNode *node) { - asCArray funcs; + asCArray funcs; asCObjectType *ot = CastToObjectType(ctx->type.dataType.GetTypeInfo()); if( ot ) { @@ -16091,8 +16193,8 @@ void asCCompiler::ImplicitConvObjectToBestMathType(asCExprContext *ctx, asCScrip // Consider only implicit casts asCScriptFunction *func = engine->scriptFunctions[ot->methods[n]]; if( func->name == "opImplConv" && - func->returnType.IsPrimitive() && - func->parameterTypes.GetLength() == 0 ) + func->returnType.IsPrimitive() && + func->parameterTypes.GetLength() == 0 ) funcs.PushLast(ot->methods[n]); } @@ -16101,7 +16203,7 @@ void asCCompiler::ImplicitConvObjectToBestMathType(asCExprContext *ctx, asCScrip while( funcs.GetLength() > 1 ) { eTokenType returnType = builder->GetFunctionDescription(funcs[0])->returnType.GetTokenType(); - int value1 = 11, value2 = 11; + int value1 = 11, value2 = 11; for( asUINT i = 0; i < 10; i++ ) { if( returnType == match[i] ) @@ -16143,7 +16245,7 @@ void asCCompiler::ImplicitConvObjectToBestMathType(asCExprContext *ctx, asCScrip } } -void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, asCExprContext *rctx, asCExprContext *ctx, eTokenType op) +void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, asCExprContext *rctx, asCExprContext *ctx, eTokenType op) { // TODO: If a constant is only using 32bits, then a 32bit operation is preferred @@ -16175,7 +16277,7 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, { // Convert to int64 if both are signed or if one is non-constant and signed if( (lctx->type.dataType.IsIntegerType() && !lctx->type.isConstant) || - (rctx->type.dataType.IsIntegerType() && !rctx->type.isConstant) ) + (rctx->type.dataType.IsIntegerType() && !rctx->type.isConstant) ) to.SetTokenType(ttInt64); else if( lctx->type.dataType.IsUnsignedType() || rctx->type.dataType.IsUnsignedType() ) to.SetTokenType(ttUInt64); @@ -16186,7 +16288,7 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, { // Convert to int32 if both are signed or if one is non-constant and signed if( (lctx->type.dataType.IsIntegerType() && !lctx->type.isConstant) || - (rctx->type.dataType.IsIntegerType() && !rctx->type.isConstant) ) + (rctx->type.dataType.IsIntegerType() && !rctx->type.isConstant) ) to.SetTokenType(ttInt); else if( lctx->type.dataType.IsUnsignedType() || rctx->type.dataType.IsUnsignedType() ) to.SetTokenType(ttUInt); @@ -16196,7 +16298,7 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, // If doing an operation with double constant and float variable, the constant should be converted to float if( (lctx->type.isConstant && lctx->type.dataType.IsDoubleType() && !rctx->type.isConstant && rctx->type.dataType.IsFloatType()) || - (rctx->type.isConstant && rctx->type.dataType.IsDoubleType() && !lctx->type.isConstant && lctx->type.dataType.IsFloatType()) ) + (rctx->type.isConstant && rctx->type.dataType.IsDoubleType() && !lctx->type.isConstant && lctx->type.dataType.IsFloatType()) ) to.SetTokenType(ttFloat); if( op == ttUnrecognizedToken ) @@ -16204,8 +16306,8 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, // If integer division is disabled, convert to floating-point if( engine->ep.disableIntegerDivision && - (op == ttSlash || op == ttDivAssign) && - (to.IsIntegerType() || to.IsUnsignedType()) ) + (op == ttSlash || op == ttDivAssign) && + (to.IsIntegerType() || to.IsUnsignedType()) ) { // Use double to avoid losing precision when dividing with 32bit ints // For 64bit ints there is unfortunately no greater type so with those @@ -16228,9 +16330,9 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, // ttStarStar allows an integer, right-hand operand and a double // left-hand operand. if( (op == ttStarStar || op == ttPowAssign) && - lctx->type.dataType.IsDoubleType() && - (rctx->type.dataType.IsIntegerType() || - rctx->type.dataType.IsUnsignedType()) ) + lctx->type.dataType.IsDoubleType() && + (rctx->type.dataType.IsIntegerType() || + rctx->type.dataType.IsUnsignedType()) ) { to.SetTokenType(ttInt); ImplicitConversion(rctx, to, node, asIC_IMPLICIT_CONV, true); @@ -16246,9 +16348,9 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, // Verify that the conversion was successful if( !lctx->type.dataType.IsIntegerType() && - !lctx->type.dataType.IsUnsignedType() && - !lctx->type.dataType.IsFloatType() && - !lctx->type.dataType.IsDoubleType() ) + !lctx->type.dataType.IsUnsignedType() && + !lctx->type.dataType.IsFloatType() && + !lctx->type.dataType.IsDoubleType() ) { asCString str; str.Format(TXT_NO_CONVERSION_s_TO_MATH_TYPE, lctx->type.dataType.Format(outFunc->nameSpace).AddressOf()); @@ -16259,9 +16361,9 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, } if( !rctx->type.dataType.IsIntegerType() && - !rctx->type.dataType.IsUnsignedType() && - !rctx->type.dataType.IsFloatType() && - !rctx->type.dataType.IsDoubleType() ) + !rctx->type.dataType.IsUnsignedType() && + !rctx->type.dataType.IsFloatType() && + !rctx->type.dataType.IsDoubleType() ) { asCString str; str.Format(TXT_NO_CONVERSION_s_TO_MATH_TYPE, rctx->type.dataType.Format(outFunc->nameSpace).AddressOf()); @@ -16275,12 +16377,12 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, // Verify if we are dividing with a constant zero if( rctx->type.isConstant && - (op == ttSlash || op == ttDivAssign || - op == ttPercent || op == ttModAssign) && - ((rctx->type.dataType.GetSizeInMemoryBytes() == 4 && rctx->type.GetConstantDW() == 0) || - (rctx->type.dataType.GetSizeInMemoryBytes() == 8 && rctx->type.GetConstantQW() == 0) || - (rctx->type.dataType.GetSizeInMemoryBytes() == 1 && rctx->type.GetConstantB() == 0) || - (rctx->type.dataType.GetSizeInMemoryBytes() == 2 && rctx->type.GetConstantW() == 0)) ) + (op == ttSlash || op == ttDivAssign || + op == ttPercent || op == ttModAssign) && + ((rctx->type.dataType.GetSizeInMemoryBytes() == 4 && rctx->type.GetConstantDW() == 0) || + (rctx->type.dataType.GetSizeInMemoryBytes() == 8 && rctx->type.GetConstantQW() == 0) || + (rctx->type.dataType.GetSizeInMemoryBytes() == 1 && rctx->type.GetConstantB() == 0) || + (rctx->type.dataType.GetSizeInMemoryBytes() == 2 && rctx->type.GetConstantW() == 0)) ) { Error(TXT_DIVIDE_BY_ZERO, node); } @@ -16293,8 +16395,8 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, ReleaseTemporaryVariable(rctx->type, &rctx->bc); if( op == ttAddAssign || op == ttSubAssign || - op == ttMulAssign || op == ttDivAssign || - op == ttModAssign || op == ttPowAssign ) + op == ttMulAssign || op == ttDivAssign || + op == ttModAssign || op == ttPowAssign ) { // Merge the operands in the different order so that they are evaluated correctly MergeExprBytecode(ctx, rctx); @@ -16313,7 +16415,7 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, asEBCInstr instruction = asBC_ADDi; if( lctx->type.dataType.IsIntegerType() || - lctx->type.dataType.IsUnsignedType() ) + lctx->type.dataType.IsUnsignedType() ) { if( lctx->type.dataType.GetSizeInMemoryDWords() == 1 ) { @@ -16400,7 +16502,7 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, if( op == ttStarStar || op == ttPowAssign ) instruction = asBC_POWdi; else - asASSERT(false); // Should not be possible + asASSERT(false); // Should not be possible } else { @@ -16437,7 +16539,7 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, { // Both values are constants if( lctx->type.dataType.IsIntegerType() || - lctx->type.dataType.IsUnsignedType() ) + lctx->type.dataType.IsUnsignedType() ) { if( lctx->type.dataType.GetSizeInMemoryDWords() == 1 ) { @@ -16453,22 +16555,20 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, // TODO: Should probably report an error, rather than silently convert the value to 0 if( rctx->type.GetConstantDW() == 0 || (int(rctx->type.GetConstantDW()) == -1 && lctx->type.GetConstantDW() == 0x80000000) ) v = 0; + else if( lctx->type.dataType.IsIntegerType() ) + v = int(lctx->type.GetConstantDW()) / int(rctx->type.GetConstantDW()); else - if( lctx->type.dataType.IsIntegerType() ) - v = int(lctx->type.GetConstantDW()) / int(rctx->type.GetConstantDW()); - else - v = lctx->type.GetConstantDW() / rctx->type.GetConstantDW(); + v = lctx->type.GetConstantDW() / rctx->type.GetConstantDW(); } else if( op == ttPercent ) { // TODO: Should probably report an error, rather than silently convert the value to 0 if( rctx->type.GetConstantDW() == 0 || (int(rctx->type.GetConstantDW()) == -1 && lctx->type.GetConstantDW() == 0x80000000) ) v = 0; + else if( lctx->type.dataType.IsIntegerType() ) + v = int(lctx->type.GetConstantDW()) % int(rctx->type.GetConstantDW()); else - if( lctx->type.dataType.IsIntegerType() ) - v = int(lctx->type.GetConstantDW()) % int(rctx->type.GetConstantDW()); - else - v = lctx->type.GetConstantDW() % rctx->type.GetConstantDW(); + v = lctx->type.GetConstantDW() % rctx->type.GetConstantDW(); } else if( op == ttStarStar ) { @@ -16485,7 +16585,7 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, ctx->type.SetConstantDW(lctx->type.dataType, v); // If the right value is greater than the left value in a minus operation, then we need to convert the type to int - if( lctx->type.dataType.GetTokenType() == ttUInt && op == ttMinus && lctx->type.GetConstantDW() < rctx->type.GetConstantDW()) + if( lctx->type.dataType.GetTokenType() == ttUInt && op == ttMinus && lctx->type.GetConstantDW() < rctx->type.GetConstantDW() ) ctx->type.dataType.SetTokenType(ttInt); } else @@ -16500,24 +16600,22 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, else if( op == ttSlash ) { // TODO: Should probably report an error, rather than silently convert the value to 0 - if( rctx->type.GetConstantQW() == 0 || (rctx->type.GetConstantQW() == asQWORD(-1) && lctx->type.GetConstantQW() == (asQWORD(1)<<63)) ) + if( rctx->type.GetConstantQW() == 0 || (rctx->type.GetConstantQW() == asQWORD(-1) && lctx->type.GetConstantQW() == (asQWORD(1) << 63)) ) v = 0; + else if( lctx->type.dataType.IsIntegerType() ) + v = asINT64(lctx->type.GetConstantQW()) / asINT64(rctx->type.GetConstantQW()); else - if( lctx->type.dataType.IsIntegerType() ) - v = asINT64(lctx->type.GetConstantQW()) / asINT64(rctx->type.GetConstantQW()); - else - v = lctx->type.GetConstantQW() / rctx->type.GetConstantQW(); + v = lctx->type.GetConstantQW() / rctx->type.GetConstantQW(); } else if( op == ttPercent ) { - // TODO: Should probably report an error, rather than silently convert the value to 0 - if( rctx->type.GetConstantQW() == 0 || (rctx->type.GetConstantQW() == asQWORD(-1) && lctx->type.GetConstantQW() == (asQWORD(1)<<63)) ) + // TODO: Should probably report an error, rather than silently convert the value to 0 + if( rctx->type.GetConstantQW() == 0 || (rctx->type.GetConstantQW() == asQWORD(-1) && lctx->type.GetConstantQW() == (asQWORD(1) << 63)) ) v = 0; + else if( lctx->type.dataType.IsIntegerType() ) + v = asINT64(lctx->type.GetConstantQW()) % asINT64(rctx->type.GetConstantQW()); else - if( lctx->type.dataType.IsIntegerType() ) - v = asINT64(lctx->type.GetConstantQW()) % asINT64(rctx->type.GetConstantQW()); - else - v = lctx->type.GetConstantQW() % rctx->type.GetConstantQW(); + v = lctx->type.GetConstantQW() % rctx->type.GetConstantQW(); } else if( op == ttStarStar ) { @@ -16534,7 +16632,7 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, ctx->type.SetConstantQW(lctx->type.dataType, v); // If the right value is greater than the left value in a minus operation, then we need to convert the type to int - if( lctx->type.dataType.GetTokenType() == ttUInt64 && op == ttMinus && lctx->type.GetConstantQW() < rctx->type.GetConstantQW()) + if( lctx->type.dataType.GetTokenType() == ttUInt64 && op == ttMinus && lctx->type.GetConstantQW() < rctx->type.GetConstantQW() ) ctx->type.dataType.SetTokenType(ttInt64); } } @@ -16584,7 +16682,7 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, Error(TXT_POW_OVERFLOW, node); } else - asASSERT(false); // Should not be possible + asASSERT(false); // Should not be possible } else { @@ -16611,7 +16709,7 @@ void asCCompiler::CompileMathOperator(asCScriptNode *node, asCExprContext *lctx, else if( op == ttStarStar ) { v = pow(lctx->type.GetConstantD(), rctx->type.GetConstantD()); - if( v == HUGE_VAL || isinf(v)) + if( v == HUGE_VAL || isinf(v) ) Error(TXT_POW_OVERFLOW, node); } } @@ -16631,14 +16729,14 @@ void asCCompiler::CompileBitwiseOperator(asCScriptNode *node, asCExprContext *lc // TODO: If a constant is only using 32bits, then a 32bit operation is preferred // If either operand is a non-primitive then use the primitive type - if (!lctx->type.dataType.IsPrimitive()) + if( !lctx->type.dataType.IsPrimitive() ) { int l = int(reservedVariables.GetLength()); rctx->bc.GetVarsUsed(reservedVariables); ImplicitConvObjectToBestMathType(lctx, node); reservedVariables.SetLength(l); } - if (!rctx->type.dataType.IsPrimitive()) + if( !rctx->type.dataType.IsPrimitive() ) { int l = int(reservedVariables.GetLength()); lctx->bc.GetVarsUsed(reservedVariables); @@ -16648,13 +16746,13 @@ void asCCompiler::CompileBitwiseOperator(asCScriptNode *node, asCExprContext *lc if( op == ttUnrecognizedToken ) op = node->tokenType; - if( op == ttAmp || op == ttAndAssign || - op == ttBitOr || op == ttOrAssign || - op == ttBitXor || op == ttXorAssign ) + if( op == ttAmp || op == ttAndAssign || + op == ttBitOr || op == ttOrAssign || + op == ttBitXor || op == ttXorAssign ) { // Also do not permit float/double to be implicitly converted to integer in this case // as the user may think the result is a bitwise operation on the float value but it's not - if (lctx->type.dataType.IsFloatType() || lctx->type.dataType.IsDoubleType()) + if( lctx->type.dataType.IsFloatType() || lctx->type.dataType.IsDoubleType() ) { asCString str; str.Format(TXT_ILLEGAL_OPERATION_ON_s, lctx->type.dataType.Format(outFunc->nameSpace).AddressOf()); @@ -16664,7 +16762,7 @@ void asCCompiler::CompileBitwiseOperator(asCScriptNode *node, asCExprContext *lc ctx->type.SetConstantDW(asCDataType::CreatePrimitive(ttInt, true), 0); return; } - if (rctx->type.dataType.IsFloatType() || rctx->type.dataType.IsDoubleType()) + if( rctx->type.dataType.IsFloatType() || rctx->type.dataType.IsDoubleType() ) { asCString str; str.Format(TXT_ILLEGAL_OPERATION_ON_s, rctx->type.dataType.Format(outFunc->nameSpace).AddressOf()); @@ -16678,7 +16776,7 @@ void asCCompiler::CompileBitwiseOperator(asCScriptNode *node, asCExprContext *lc // Convert left hand operand to integer if it's not already one asCDataType to; if( lctx->type.dataType.GetSizeInMemoryDWords() == 2 || - rctx->type.dataType.GetSizeInMemoryDWords() == 2 ) + rctx->type.dataType.GetSizeInMemoryDWords() == 2 ) to.SetTokenType(ttInt64); else to.SetTokenType(ttInt); @@ -16687,9 +16785,9 @@ void asCCompiler::CompileBitwiseOperator(asCScriptNode *node, asCExprContext *lc int l = int(reservedVariables.GetLength()); rctx->bc.GetVarsUsed(reservedVariables); if( lctx->type.dataType.IsUnsignedType() ) - to.SetTokenType( to.GetSizeOnStackDWords() == 1 ? ttUInt : ttUInt64 ); + to.SetTokenType(to.GetSizeOnStackDWords() == 1 ? ttUInt : ttUInt64); else - to.SetTokenType( to.GetSizeOnStackDWords() == 1 ? ttInt : ttInt64 ); + to.SetTokenType(to.GetSizeOnStackDWords() == 1 ? ttInt : ttInt64); ImplicitConversion(lctx, to, node, asIC_IMPLICIT_CONV, true); reservedVariables.SetLength(l); @@ -16709,9 +16807,9 @@ void asCCompiler::CompileBitwiseOperator(asCScriptNode *node, asCExprContext *lc l = int(reservedVariables.GetLength()); lctx->bc.GetVarsUsed(reservedVariables); if( rctx->type.dataType.IsUnsignedType() ) - to.SetTokenType( to.GetSizeOnStackDWords() == 1 ? ttUInt : ttUInt64 ); + to.SetTokenType(to.GetSizeOnStackDWords() == 1 ? ttUInt : ttUInt64); else - to.SetTokenType( to.GetSizeOnStackDWords() == 1 ? ttInt : ttInt64 ); + to.SetTokenType(to.GetSizeOnStackDWords() == 1 ? ttInt : ttInt64); ImplicitConversion(rctx, to, node, asIC_IMPLICIT_CONV, true); reservedVariables.SetLength(l); if( rctx->type.dataType != to ) @@ -16806,9 +16904,9 @@ void asCCompiler::CompileBitwiseOperator(asCScriptNode *node, asCExprContext *lc } } } - else if( op == ttBitShiftLeft || op == ttShiftLeftAssign || - op == ttBitShiftRight || op == ttShiftRightLAssign || - op == ttBitShiftRightArith || op == ttShiftRightAAssign ) + else if( op == ttBitShiftLeft || op == ttShiftLeftAssign || + op == ttBitShiftRight || op == ttShiftRightLAssign || + op == ttBitShiftRightArith || op == ttShiftRightAAssign ) { // Don't permit object to primitive conversion, since we don't know which integer type is the correct one // Also do not permit float/double to be implicitly converted to integer in this case @@ -16826,14 +16924,14 @@ void asCCompiler::CompileBitwiseOperator(asCScriptNode *node, asCExprContext *lc // Convert left hand operand to integer if it's not already one asCDataType to = lctx->type.dataType; if( lctx->type.dataType.IsUnsignedType() && - lctx->type.dataType.GetSizeInMemoryBytes() < 4 ) + lctx->type.dataType.GetSizeInMemoryBytes() < 4 ) { // Upgrade to 32bit to = asCDataType::CreatePrimitive(ttUInt, false); } else if( !lctx->type.dataType.IsUnsignedType() ) { - if (lctx->type.dataType.GetSizeInMemoryDWords() == 2) + if( lctx->type.dataType.GetSizeInMemoryDWords() == 2 ) to = asCDataType::CreatePrimitive(ttInt64, false); else to = asCDataType::CreatePrimitive(ttInt, false); @@ -16984,7 +17082,7 @@ void asCCompiler::CompileComparisonOperator(asCScriptNode *node, asCExprContext { // Convert to int64 if both are signed or if one is non-constant and signed if( (lctx->type.dataType.IsIntegerType() && !lctx->type.isConstant) || - (rctx->type.dataType.IsIntegerType() && !rctx->type.isConstant) ) + (rctx->type.dataType.IsIntegerType() && !rctx->type.isConstant) ) to.SetTokenType(ttInt64); else if( lctx->type.dataType.IsUnsignedType() || rctx->type.dataType.IsUnsignedType() ) to.SetTokenType(ttUInt64); @@ -16995,7 +17093,7 @@ void asCCompiler::CompileComparisonOperator(asCScriptNode *node, asCExprContext { // Convert to int32 if both are signed or if one is non-constant and signed if( (lctx->type.dataType.IsIntegerType() && !lctx->type.isConstant) || - (rctx->type.dataType.IsIntegerType() && !rctx->type.isConstant) ) + (rctx->type.dataType.IsIntegerType() && !rctx->type.isConstant) ) to.SetTokenType(ttInt); else if( lctx->type.dataType.IsUnsignedType() || rctx->type.dataType.IsUnsignedType() ) to.SetTokenType(ttUInt); @@ -17007,7 +17105,7 @@ void asCCompiler::CompileComparisonOperator(asCScriptNode *node, asCExprContext // If doing an operation with double constant and float variable, the constant should be converted to float if( (lctx->type.isConstant && lctx->type.dataType.IsDoubleType() && !rctx->type.isConstant && rctx->type.dataType.IsFloatType()) || - (rctx->type.isConstant && rctx->type.dataType.IsDoubleType() && !lctx->type.isConstant && lctx->type.dataType.IsFloatType()) ) + (rctx->type.isConstant && rctx->type.dataType.IsDoubleType() && !lctx->type.isConstant && lctx->type.dataType.IsFloatType()) ) to.SetTokenType(ttFloat); asASSERT( to.GetTokenType() != ttUnrecognizedToken ); @@ -17025,29 +17123,29 @@ void asCCompiler::CompileComparisonOperator(asCScriptNode *node, asCExprContext if( opCtx->type.isConstant ) { eTokenType tokenType; - if (opCtx->type.dataType.IsEnumType()) + if( opCtx->type.dataType.IsEnumType() ) tokenType = CastToEnumType(opCtx->type.dataType.GetTypeInfo())->enumType.GetTokenType(); else tokenType = opCtx->type.dataType.GetTokenType(); - - if (tokenType == ttUInt64 || tokenType == ttInt64) + + if( tokenType == ttUInt64 || tokenType == ttInt64 ) { - if( !(opCtx->type.GetConstantQW() & (asQWORD(1)<<63)) ) + if( !(opCtx->type.GetConstantQW() & (asQWORD(1) << 63)) ) signMismatch = false; } - else if (tokenType == ttUInt || tokenType == ttInt) + else if( tokenType == ttUInt || tokenType == ttInt ) { - if( !(opCtx->type.GetConstantDW() & (1<<31)) ) + if( !(opCtx->type.GetConstantDW() & (1 << 31)) ) signMismatch = false; } - else if (tokenType == ttUInt16 || tokenType == ttInt16) + else if( tokenType == ttUInt16 || tokenType == ttInt16 ) { - if (!(opCtx->type.GetConstantW() & (1 << 15))) + if( !(opCtx->type.GetConstantW() & (1 << 15)) ) signMismatch = false; } - else if (tokenType == ttUInt8 || tokenType == ttInt8) + else if( tokenType == ttUInt8 || tokenType == ttInt8 ) { - if (!(opCtx->type.GetConstantB() & (1 << 7))) + if( !(opCtx->type.GetConstantB() & (1 << 7)) ) signMismatch = false; } @@ -17102,11 +17200,11 @@ void asCCompiler::CompileComparisonOperator(asCScriptNode *node, asCExprContext { // It wasn't possible to get two valid operands, so we just return // a boolean result and let the compiler continue. -#if AS_SIZEOF_BOOL == 1 + #if AS_SIZEOF_BOOL == 1 ctx->type.SetConstantB(asCDataType::CreatePrimitive(ttBool, true), true); -#else + #else ctx->type.SetConstantDW(asCDataType::CreatePrimitive(ttBool, true), true); -#endif + #endif return; } @@ -17141,13 +17239,13 @@ void asCCompiler::CompileComparisonOperator(asCScriptNode *node, asCExprContext if( op == ttEqual ) { - ctx->bc.InstrW_W(asBC_CMPi,b,c); + ctx->bc.InstrW_W(asBC_CMPi, b, c); ctx->bc.Instr(asBC_TZ); ctx->bc.InstrSHORT(asBC_CpyRtoV4, (short)a); } else if( op == ttNotEqual ) { - ctx->bc.InstrW_W(asBC_CMPi,b,c); + ctx->bc.InstrW_W(asBC_CMPi, b, c); ctx->bc.Instr(asBC_TNZ); ctx->bc.InstrSHORT(asBC_CpyRtoV4, (short)a); } @@ -17158,11 +17256,11 @@ void asCCompiler::CompileComparisonOperator(asCScriptNode *node, asCExprContext { // TODO: Use TXT_ILLEGAL_OPERATION_ON Error(TXT_ILLEGAL_OPERATION, node); -#if AS_SIZEOF_BOOL == 1 + #if AS_SIZEOF_BOOL == 1 ctx->type.SetConstantB(asCDataType::CreatePrimitive(ttBool, true), 0); -#else + #else ctx->type.SetConstantDW(asCDataType::CreatePrimitive(ttBool, true), 0); -#endif + #endif } } else @@ -17224,29 +17322,29 @@ void asCCompiler::CompileComparisonOperator(asCScriptNode *node, asCExprContext if( op == ttEqual || op == ttNotEqual ) { asDWORD lv, rv; - #if AS_SIZEOF_BOOL == 1 - lv = lctx->type.GetConstantB(); - rv = rctx->type.GetConstantB(); - #else - lv = lctx->type.GetConstantDW(); - rv = rctx->type.GetConstantDW(); - #endif + #if AS_SIZEOF_BOOL == 1 + lv = lctx->type.GetConstantB(); + rv = rctx->type.GetConstantB(); + #else + lv = lctx->type.GetConstantDW(); + rv = rctx->type.GetConstantDW(); + #endif // Make sure they are equal if not false - if (lv != 0) lv = VALUE_OF_BOOLEAN_TRUE; - if (rv != 0) rv = VALUE_OF_BOOLEAN_TRUE; + if( lv != 0 ) lv = VALUE_OF_BOOLEAN_TRUE; + if( rv != 0 ) rv = VALUE_OF_BOOLEAN_TRUE; asDWORD v = 0; - if (op == ttEqual) + if( op == ttEqual ) v = (lv == rv) ? VALUE_OF_BOOLEAN_TRUE : 0; - else if (op == ttNotEqual) + else if( op == ttNotEqual ) v = (lv != rv) ? VALUE_OF_BOOLEAN_TRUE : 0; - #if AS_SIZEOF_BOOL == 1 - ctx->type.SetConstantB(asCDataType::CreatePrimitive(ttBool, true), (asBYTE)v); - #else - ctx->type.SetConstantDW(asCDataType::CreatePrimitive(ttBool, true), v); - #endif + #if AS_SIZEOF_BOOL == 1 + ctx->type.SetConstantB(asCDataType::CreatePrimitive(ttBool, true), (asBYTE)v); + #else + ctx->type.SetConstantDW(asCDataType::CreatePrimitive(ttBool, true), v); + #endif } else { @@ -17310,11 +17408,11 @@ void asCCompiler::CompileComparisonOperator(asCScriptNode *node, asCExprContext else if( op == ttGreaterThanOrEqual ) i = (i >= 0 ? VALUE_OF_BOOLEAN_TRUE : 0); - #if AS_SIZEOF_BOOL == 1 - ctx->type.SetConstantB(asCDataType::CreatePrimitive(ttBool, true), (asBYTE)i); - #else - ctx->type.SetConstantDW(asCDataType::CreatePrimitive(ttBool, true), i); - #endif + #if AS_SIZEOF_BOOL == 1 + ctx->type.SetConstantB(asCDataType::CreatePrimitive(ttBool, true), (asBYTE)i); + #else + ctx->type.SetConstantDW(asCDataType::CreatePrimitive(ttBool, true), i); + #endif } } } @@ -17348,16 +17446,16 @@ void asCCompiler::CompileBooleanOperator(asCScriptNode *node, asCExprContext *lc lctx->bc.GetVarsUsed(reservedVariables); // If turned on, allow the compiler to use either 'bool opImplConv()' or 'bool opConv()' on the type - if (engine->ep.boolConversionMode == 1) + if( engine->ep.boolConversionMode == 1 ) ImplicitConversion(lctx, to, node, asIC_EXPLICIT_VAL_CAST); // else, allow value types to be converted to bool using 'bool opImplConv()' - else if (lctx->type.dataType.GetTypeInfo() && (lctx->type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE)) + else if( lctx->type.dataType.GetTypeInfo() && (lctx->type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE) ) ImplicitConversion(lctx, to, node, asIC_IMPLICIT_CONV); // The same goes for the right hand expression - if (engine->ep.boolConversionMode == 1) + if( engine->ep.boolConversionMode == 1 ) ImplicitConversion(rctx, to, node, asIC_EXPLICIT_VAL_CAST); - else if (rctx->type.dataType.GetTypeInfo() && (rctx->type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE)) + else if( rctx->type.dataType.GetTypeInfo() && (rctx->type.dataType.GetTypeInfo()->GetFlags() & asOBJ_VALUE) ) ImplicitConversion(rctx, to, node, asIC_IMPLICIT_CONV); reservedVariables.SetLength(l); @@ -17410,38 +17508,40 @@ void asCCompiler::CompileBooleanOperator(asCScriptNode *node, asCExprContext *lc int b = lctx->type.stackOffset; int c = rctx->type.stackOffset; - ctx->bc.InstrW_W_W(asBC_BXOR,a,b,c); + ctx->bc.InstrW_W_W(asBC_BXOR, a, b, c); ctx->type.SetVariable(asCDataType::CreatePrimitive(ttBool, true), a, true); } else { // Make sure they are equal if not false -#if AS_SIZEOF_BOOL == 1 + #if AS_SIZEOF_BOOL == 1 if( lctx->type.GetConstantB() != 0 ) lctx->type.SetConstantB(VALUE_OF_BOOLEAN_TRUE); if( rctx->type.GetConstantB() != 0 ) rctx->type.SetConstantB(VALUE_OF_BOOLEAN_TRUE); asBYTE v = 0; - v = lctx->type.GetConstantB() - rctx->type.GetConstantB(); - if( v != 0 ) v = VALUE_OF_BOOLEAN_TRUE; else v = 0; + v = lctx->type.GetConstantB() - rctx->type.GetConstantB(); + if( v != 0 ) v = VALUE_OF_BOOLEAN_TRUE; + else v = 0; ctx->type.isConstant = true; ctx->type.SetConstantB(v); -#else + #else if( lctx->type.GetConstantDW() != 0 ) lctx->type.SetConstantDW(VALUE_OF_BOOLEAN_TRUE); if( rctx->type.GetConstantDW() != 0 ) rctx->type.SetConstantDW(VALUE_OF_BOOLEAN_TRUE); asDWORD v = 0; - v = lctx->type.GetConstantDW() - rctx->type.GetConstantDW(); - if( v != 0 ) v = VALUE_OF_BOOLEAN_TRUE; else v = 0; + v = lctx->type.GetConstantDW() - rctx->type.GetConstantDW(); + if( v != 0 ) v = VALUE_OF_BOOLEAN_TRUE; + else v = 0; ctx->type.isConstant = true; ctx->type.SetConstantDW(v); -#endif + #endif } } else if( op == ttAnd || - op == ttOr ) + op == ttOr ) { if( !isConstant ) { @@ -17467,11 +17567,11 @@ void asCCompiler::CompileBooleanOperator(asCScriptNode *node, asCExprContext *lc else if( op == ttOr ) { ctx->bc.InstrDWORD(asBC_JZ, label1); -#if AS_SIZEOF_BOOL == 1 + #if AS_SIZEOF_BOOL == 1 ctx->bc.InstrSHORT_B(asBC_SetV1, (short)offset, VALUE_OF_BOOLEAN_TRUE); -#else + #else ctx->bc.InstrSHORT_DW(asBC_SetV4, (short)offset, VALUE_OF_BOOLEAN_TRUE); -#endif + #endif ctx->bc.InstrINT(asBC_JMP, label2); } @@ -17480,10 +17580,10 @@ void asCCompiler::CompileBooleanOperator(asCScriptNode *node, asCExprContext *lc ReleaseTemporaryVariable(rctx->type, &rctx->bc); rctx->bc.InstrW_W(asBC_CpyVtoV4, offset, rctx->type.stackOffset); - // Make sure temporary variables created within this expression are destroyed within it. + // Make sure temporary variables created within this expression are destroyed within it. // Without this, the compiler would add the code to clean-up the temporary variables after the label, // which means the clean-up code might be executed without the variables actually being created first. - // This is especially true when unsafe references is turned on as then destruction of temporaries + // This is especially true when unsafe references is turned on as then destruction of temporaries // will be deferred to the end of expressions by default. ProcessDeferredParams(rctx); @@ -17502,11 +17602,11 @@ void asCCompiler::CompileBooleanOperator(asCScriptNode *node, asCExprContext *lc // Remember the result ctx->type.isConstant = true; -#if AS_SIZEOF_BOOL == 1 + #if AS_SIZEOF_BOOL == 1 ctx->type.SetConstantB(v); -#else + #else ctx->type.SetConstantDW(v); -#endif + #endif } } } @@ -17537,17 +17637,17 @@ void asCCompiler::CompileOperatorOnHandles(asCScriptNode *node, asCExprContext * // Warn if not both operands are explicit handles or null handles if( (opToken == ttEqual || opToken == ttNotEqual) && - ((!(lctx->type.isExplicitHandle || lctx->type.IsNullConstant()) && !(lctx->type.dataType.GetTypeInfo() && (lctx->type.dataType.GetTypeInfo()->flags & asOBJ_IMPLICIT_HANDLE))) || - (!(rctx->type.isExplicitHandle || rctx->type.IsNullConstant()) && !(rctx->type.dataType.GetTypeInfo() && (rctx->type.dataType.GetTypeInfo()->flags & asOBJ_IMPLICIT_HANDLE)))) ) + ((!(lctx->type.isExplicitHandle || lctx->type.IsNullConstant()) && !(lctx->type.dataType.GetTypeInfo() && (lctx->type.dataType.GetTypeInfo()->flags & asOBJ_IMPLICIT_HANDLE))) || + (!(rctx->type.isExplicitHandle || rctx->type.IsNullConstant()) && !(rctx->type.dataType.GetTypeInfo() && (rctx->type.dataType.GetTypeInfo()->flags & asOBJ_IMPLICIT_HANDLE)))) ) { Warning(TXT_HANDLE_COMPARISON, node); } // If one of the operands is a value type used as handle, we should look for the opEquals method if( ((lctx->type.dataType.GetTypeInfo() && (lctx->type.dataType.GetTypeInfo()->flags & asOBJ_ASHANDLE)) || - (rctx->type.dataType.GetTypeInfo() && (rctx->type.dataType.GetTypeInfo()->flags & asOBJ_ASHANDLE))) && - (opToken == ttEqual || opToken == ttIs || - opToken == ttNotEqual || opToken == ttNotIs) ) + (rctx->type.dataType.GetTypeInfo() && (rctx->type.dataType.GetTypeInfo()->flags & asOBJ_ASHANDLE))) && + (opToken == ttEqual || opToken == ttIs || + opToken == ttNotEqual || opToken == ttNotIs) ) { // TODO: Should evaluate which of the two have the best match. If both have equal match, the first version should be used // Find the matching opEquals method @@ -17573,11 +17673,11 @@ void asCCompiler::CompileOperatorOnHandles(asCScriptNode *node, asCExprContext * } // Compiler error, don't continue -#if AS_SIZEOF_BOOL == 1 + #if AS_SIZEOF_BOOL == 1 ctx->type.SetConstantB(asCDataType::CreatePrimitive(ttBool, true), true); -#else + #else ctx->type.SetConstantDW(asCDataType::CreatePrimitive(ttBool, true), true); -#endif + #endif return; } @@ -17617,11 +17717,11 @@ void asCCompiler::CompileOperatorOnHandles(asCScriptNode *node, asCExprContext * { // Compiler error, don't continue Error(TXT_OPERANDS_MUST_BE_HANDLES, node); -#if AS_SIZEOF_BOOL == 1 + #if AS_SIZEOF_BOOL == 1 ctx->type.SetConstantB(asCDataType::CreatePrimitive(ttBool, true), true); -#else + #else ctx->type.SetConstantDW(asCDataType::CreatePrimitive(ttBool, true), true); -#endif + #endif return; } @@ -17701,16 +17801,16 @@ void asCCompiler::CompileOperatorOnHandles(asCScriptNode *node, asCExprContext * } -void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isConstructor, asCArray *args, asCObjectType *objType, bool useVariable, int varOffset, int funcPtrVar) +void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isConstructor, asCArray *args, asCObjectType *objType, bool useVariable, int varOffset, int funcPtrVar) { asCScriptFunction *descr = builder->GetFunctionDescription(funcId); // A constructor for POD value type doesn't require a function, as it will only allocate the memory in this case int argSize = 0; - if (descr) + if( descr ) { // A shared object may not call non-shared functions - if (outFunc->IsShared() && !descr->IsShared()) + if( outFunc->IsShared() && !descr->IsShared() ) { asCString msg; msg.Format(TXT_SHARED_CANNOT_CALL_NON_SHARED_FUNC_s, descr->GetDeclarationStr().AddressOf()); @@ -17718,30 +17818,30 @@ void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isCo } // Check if the function is private or protected - if (descr->IsPrivate()) + if( descr->IsPrivate() ) { - asCObjectType* type = descr->objectType; - if (type == 0 && descr->traits.GetTrait(asTRAIT_CONSTRUCTOR)) + asCObjectType *type = descr->objectType; + if( type == 0 && descr->traits.GetTrait(asTRAIT_CONSTRUCTOR) ) type = CastToObjectType(descr->returnType.GetTypeInfo()); asASSERT(type); - if ((type != outFunc->GetObjectType())) + if( (type != outFunc->GetObjectType()) ) { asCString msg; msg.Format(TXT_PRIVATE_METHOD_CALL_s, descr->GetDeclarationStr().AddressOf()); Error(msg, ctx->exprNode); } } - else if (descr->IsProtected()) + else if( descr->IsProtected() ) { - asCObjectType* type = descr->objectType; - if (type == 0 && descr->traits.GetTrait(asTRAIT_CONSTRUCTOR)) + asCObjectType *type = descr->objectType; + if( type == 0 && descr->traits.GetTrait(asTRAIT_CONSTRUCTOR) ) type = CastToObjectType(descr->returnType.GetTypeInfo()); asASSERT(type); - if (!(type == outFunc->objectType || (outFunc->objectType && outFunc->objectType->DerivesFrom(type)))) + if( !(type == outFunc->objectType || (outFunc->objectType && outFunc->objectType->DerivesFrom(type))) ) { asCString msg; msg.Format(TXT_PROTECTED_METHOD_CALL_s, descr->GetDeclarationStr().AddressOf()); @@ -17750,11 +17850,11 @@ void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isCo } argSize = descr->GetSpaceNeededForArguments(); - if (descr->IsVariadic()) + if( descr->IsVariadic() ) { // Compute the additional space used for the variadic args - asCDataType variadicType = descr->parameterTypes[descr->parameterTypes.GetLength() - 1]; - int sizeOfVariadicArg = variadicType.GetSizeOnStackDWords(); + asCDataType variadicType = descr->parameterTypes[descr->parameterTypes.GetLength() - 1]; + int sizeOfVariadicArg = variadicType.GetSizeOnStackDWords(); // GetSpaceNeededForArguments already added one variadic arg for the ..., but there might not actually be any argSize -= sizeOfVariadicArg; @@ -17771,13 +17871,13 @@ void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isCo // be done for any methods that return references, and any calls on script objects. // Application registered objects are assumed to know to keep themselves alive even // if the method doesn't return a reference. - if (!ctx->type.isRefSafe && - descr->objectType && - (ctx->type.dataType.IsObjectHandle() || ctx->type.dataType.SupportHandles()) && - (descr->returnType.IsReference() || (ctx->type.dataType.GetTypeInfo()->GetFlags() & asOBJ_SCRIPT_OBJECT)) && - !(ctx->type.isVariable || ctx->type.isTemporary) && - !(ctx->type.dataType.GetTypeInfo()->GetFlags() & asOBJ_SCOPED) && - !(ctx->type.dataType.GetTypeInfo()->GetFlags() & asOBJ_ASHANDLE)) + if( !ctx->type.isRefSafe && + descr->objectType && + (ctx->type.dataType.IsObjectHandle() || ctx->type.dataType.SupportHandles()) && + (descr->returnType.IsReference() || (ctx->type.dataType.GetTypeInfo()->GetFlags() & asOBJ_SCRIPT_OBJECT)) && + !(ctx->type.isVariable || ctx->type.isTemporary) && + !(ctx->type.dataType.GetTypeInfo()->GetFlags() & asOBJ_SCOPED) && + !(ctx->type.dataType.GetTypeInfo()->GetFlags() & asOBJ_ASHANDLE) ) { // TODO: runtime optimize: Avoid this for global variables, by storing a reference to the global variable once in a // local variable and then refer to the same for each call. An alias for the global variable @@ -17791,9 +17891,9 @@ void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isCo // Add the release of this reference as a deferred expression asSDeferredParam deferred; - deferred.origExpr = 0; + deferred.origExpr = 0; deferred.argInOutFlags = asTM_INREF; - deferred.argNode = 0; + deferred.argNode = 0; deferred.argType.SetVariable(ctx->type.dataType, tempRef, true); ctx->deferredParams.PushLast(deferred); @@ -17802,15 +17902,15 @@ void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isCo } // Check if there is a need to add a hidden pointer for when the function returns an object by value - if (descr->DoesReturnOnStack() && !useVariable) + if( descr->DoesReturnOnStack() && !useVariable ) { useVariable = true; - varOffset = AllocateVariable(descr->returnType, true); + varOffset = AllocateVariable(descr->returnType, true); // Push the pointer to the pre-allocated space for the return value ctx->bc.InstrSHORT(asBC_PSF, short(varOffset)); - if (descr->objectType) + if( descr->objectType ) { // The object pointer is already on the stack, but should be the top // one, so we need to swap the pointers in order to get the correct @@ -17819,28 +17919,28 @@ void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isCo } } - if (isConstructor) + if( isConstructor ) { // Sometimes the value types are allocated on the heap, // which is when this way of constructing them is used. asASSERT(useVariable == false); - if ((objType->flags & asOBJ_TEMPLATE)) + if( (objType->flags & asOBJ_TEMPLATE) ) { asASSERT(descr && descr->funcType == asFUNC_SCRIPT); // Find the id of the real constructor and not the generated stub - asUINT id = 0; - asDWORD* bc = descr->scriptData->byteCode.AddressOf(); - while (bc) + asUINT id = 0; + asDWORD *bc = descr->scriptData->byteCode.AddressOf(); + while( bc ) { - if ((*(asBYTE*)bc) == asBC_CALLSYS) + if( (*(asBYTE *)bc) == asBC_CALLSYS ) { id = asBC_INTARG(bc); break; } - bc += asBCTypeSize[asBCInfo[*(asBYTE*)bc].type]; + bc += asBCTypeSize[asBCInfo[*(asBYTE *)bc].type]; } asASSERT(id); @@ -17856,21 +17956,21 @@ void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isCo ctx->type.isLValue = false; // Clean up arguments - if (args) + if( args ) AfterFunctionCall(funcId, *args, ctx, false); ProcessDeferredParams(ctx); return; } - else if (descr) + else if( descr ) { - if (descr->objectType) + if( descr->objectType ) argSize += AS_PTR_SIZE; // If the function returns an object by value the address of the location // where the value should be stored is passed as an argument too - if (descr->DoesReturnOnStack()) + if( descr->DoesReturnOnStack() ) argSize += AS_PTR_SIZE; // TODO: runtime optimize: If it is known that a class method cannot be overridden the call @@ -17880,42 +17980,42 @@ void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isCo // at compile time the true type of the object. The first should be // quite easy to determine, but the latter will be quite complex and possibly // not worth it. - if (descr->funcType == asFUNC_IMPORTED) + if( descr->funcType == asFUNC_IMPORTED ) ctx->bc.Call(asBC_CALLBND, descr->id, argSize, 0); // TODO: Maybe we need two different byte codes - else if (descr->funcType == asFUNC_INTERFACE || descr->funcType == asFUNC_VIRTUAL) + else if( descr->funcType == asFUNC_INTERFACE || descr->funcType == asFUNC_VIRTUAL ) ctx->bc.Call(asBC_CALLINTF, descr->id, argSize, 0); - else if (descr->funcType == asFUNC_SCRIPT) + else if( descr->funcType == asFUNC_SCRIPT ) ctx->bc.Call(asBC_CALL, descr->id, argSize, 0); - else if (descr->funcType == asFUNC_SYSTEM) + else if( descr->funcType == asFUNC_SYSTEM ) { // Check if we can use the faster asBC_Thiscall1 instruction, i.e. one of // type &obj::func(int) // type &obj::func(uint) - if (descr->GetObjectType() && descr->returnType.IsReference() && - descr->parameterTypes.GetLength() == 1 && - (descr->parameterTypes[0].IsIntegerType() || descr->parameterTypes[0].IsUnsignedType()) && - descr->parameterTypes[0].GetSizeInMemoryBytes() == 4 && - !descr->parameterTypes[0].IsReference()) + if( descr->GetObjectType() && descr->returnType.IsReference() && + descr->parameterTypes.GetLength() == 1 && + (descr->parameterTypes[0].IsIntegerType() || descr->parameterTypes[0].IsUnsignedType()) && + descr->parameterTypes[0].GetSizeInMemoryBytes() == 4 && + !descr->parameterTypes[0].IsReference() ) ctx->bc.Call(asBC_Thiscall1, descr->id, argSize, 0); else ctx->bc.Call(asBC_CALLSYS, descr->id, argSize, asWORD(args ? args->GetLength() : 0)); } - else if (descr->funcType == asFUNC_FUNCDEF) + else if( descr->funcType == asFUNC_FUNCDEF ) ctx->bc.CallPtr(asBC_CallPtr, funcPtrVar, argSize, asWORD(args ? args->GetLength() : 0)); } else asASSERT(false); - if (descr) + if( descr ) { - if ((descr->returnType.IsObject() || descr->returnType.IsFuncdef()) && !descr->returnType.IsReference()) + if( (descr->returnType.IsObject() || descr->returnType.IsFuncdef()) && !descr->returnType.IsReference() ) { int returnOffset = 0; asCExprValue tmpExpr = ctx->type; - if (descr->DoesReturnOnStack()) + if( descr->DoesReturnOnStack() ) { asASSERT(useVariable); @@ -17928,7 +18028,7 @@ void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isCo } else { - if (useVariable) + if( useVariable ) { // Use the given variable returnOffset = varOffset; @@ -17949,13 +18049,13 @@ void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isCo // If the context holds a variable that needs cleanup and the application uses unsafe // references then store it as a deferred parameter so it will be cleaned up afterwards. - if (tmpExpr.isTemporary && engine->ep.allowUnsafeReferences) + if( tmpExpr.isTemporary && engine->ep.allowUnsafeReferences ) { asSDeferredParam defer; - defer.argNode = 0; - defer.argType = tmpExpr; + defer.argNode = 0; + defer.argType = tmpExpr; defer.argInOutFlags = asTM_INOUTREF; - defer.origExpr = 0; + defer.origExpr = 0; ctx->deferredParams.PushLast(defer); } else @@ -17967,21 +18067,21 @@ void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isCo // Clean up arguments // If application is using unsafe references, then don't clean up arguments yet because // the returned object might be referencing one of the arguments. - if (args) + if( args ) AfterFunctionCall(funcId, *args, ctx, engine->ep.allowUnsafeReferences ? true : false); - if (!engine->ep.allowUnsafeReferences) + if( !engine->ep.allowUnsafeReferences ) ProcessDeferredParams(ctx); ctx->bc.InstrSHORT(asBC_PSF, (short)returnOffset); } - else if (descr->returnType.IsReference()) + else if( descr->returnType.IsReference() ) { asASSERT(useVariable == false); // We cannot clean up the arguments yet, because the // reference might be pointing to one of them. - if (args) + if( args ) AfterFunctionCall(funcId, *args, ctx, true); // Do not process the output parameters yet, because it @@ -17990,22 +18090,22 @@ void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isCo // If the context holds a variable that needs cleanup // store it as a deferred parameter so it will be cleaned up // afterwards. - if (ctx->type.isTemporary) + if( ctx->type.isTemporary ) { asSDeferredParam defer; - defer.argNode = 0; - defer.argType = ctx->type; + defer.argNode = 0; + defer.argType = ctx->type; defer.argInOutFlags = asTM_INOUTREF; - defer.origExpr = 0; + defer.origExpr = 0; ctx->deferredParams.PushLast(defer); } ctx->type.Set(descr->returnType); - if (!descr->returnType.IsPrimitive()) + if( !descr->returnType.IsPrimitive() ) { ctx->bc.Instr(asBC_PshRPtr); - if (descr->returnType.IsObject() && - !descr->returnType.IsObjectHandle()) + if( descr->returnType.IsObject() && + !descr->returnType.IsObjectHandle() ) { // We are getting the pointer to the object // not a pointer to a object variable @@ -18020,20 +18120,20 @@ void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isCo { asCExprValue tmpExpr = ctx->type; - if (descr->returnType.GetSizeInMemoryBytes()) + if( descr->returnType.GetSizeInMemoryBytes() ) { int offset; - if (useVariable) + if( useVariable ) offset = varOffset; else { // Allocate a temporary variable to hold the value, but make sure // the temporary variable isn't used in any of the deferred arguments int l = int(reservedVariables.GetLength()); - for (asUINT n = 0; args && n < args->GetLength(); n++) + for( asUINT n = 0; args && n < args->GetLength(); n++ ) { - asCExprContext* expr = (*args)[n]->origExpr; - if (expr) + asCExprContext *expr = (*args)[n]->origExpr; + if( expr ) expr->bc.GetVarsUsed(reservedVariables); } offset = AllocateVariable(descr->returnType, true); @@ -18043,9 +18143,9 @@ void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isCo ctx->type.SetVariable(descr->returnType, offset, true); // Move the value from the return register to the variable - if (descr->returnType.GetSizeOnStackDWords() == 1) + if( descr->returnType.GetSizeOnStackDWords() == 1 ) ctx->bc.InstrSHORT(asBC_CpyRtoV4, (short)offset); - else if (descr->returnType.GetSizeOnStackDWords() == 2) + else if( descr->returnType.GetSizeOnStackDWords() == 2 ) ctx->bc.InstrSHORT(asBC_CpyRtoV8, (short)offset); } else @@ -18053,13 +18153,13 @@ void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isCo // If the context holds a variable that needs cleanup and the application uses unsafe // references then store it as a deferred parameter so it will be cleaned up afterwards. - if (tmpExpr.isTemporary && engine->ep.allowUnsafeReferences) + if( tmpExpr.isTemporary && engine->ep.allowUnsafeReferences ) { asSDeferredParam defer; - defer.argNode = 0; - defer.argType = tmpExpr; + defer.argNode = 0; + defer.argType = tmpExpr; defer.argInOutFlags = asTM_INOUTREF; - defer.origExpr = 0; + defer.origExpr = 0; ctx->deferredParams.PushLast(defer); } else @@ -18070,10 +18170,10 @@ void asCCompiler::PerformFunctionCall(int funcId, asCExprContext *ctx, bool isCo // Clean up arguments // If application is using unsafe references, then don't clean up arguments yet because // the returned value might represent a reference to one of the arguments, e.g. an integer might in truth be a pointer - if (args) + if( args ) AfterFunctionCall(funcId, *args, ctx, engine->ep.allowUnsafeReferences ? true : false); - // If unsafe references is enabled we only process the &out parameters after the function call, + // If unsafe references is enabled we only process the &out parameters after the function call, // so that other deferred parameters (destruction of temporaries) can be left to the end of the statement ProcessDeferredParams(ctx, engine->ep.allowUnsafeReferences); } @@ -18112,7 +18212,7 @@ void asCCompiler::FilterConst(asCArray &funcs, bool removeConst) // Check if there are any non-const matches asUINT n; - bool foundNonConst = false; + bool foundNonConst = false; for( n = 0; n < funcs.GetLength(); n++ ) { desc = builder->GetFunctionDescription(funcs[n]); @@ -18146,37 +18246,37 @@ void asCCompiler::FilterConst(asCArray &funcs, bool removeConst) asCExprValue::asCExprValue() { - isTemporary = false; - stackOffset = 0; - isConstant = false; - isVariable = false; + isTemporary = false; + stackOffset = 0; + isConstant = false; + isVariable = false; isExplicitHandle = false; - qwordValue = 0; - isLValue = false; - isRefToLocal = false; - isRefSafe = false; + qwordValue = 0; + isLValue = false; + isRefToLocal = false; + isRefSafe = false; } void asCExprValue::Set(const asCDataType &dt) { dataType = dt; - isTemporary = false; - stackOffset = 0; - isConstant = false; - isVariable = false; + isTemporary = false; + stackOffset = 0; + isConstant = false; + isVariable = false; isExplicitHandle = false; - qwordValue = 0; - isLValue = false; - isRefToLocal = false; - isRefSafe = false; + qwordValue = 0; + isLValue = false; + isRefToLocal = false; + isRefSafe = false; } void asCExprValue::SetVariable(const asCDataType &in_dt, int in_stackOffset, bool in_isTemporary) { Set(in_dt); - this->isVariable = true; + this->isVariable = true; this->isTemporary = in_isTemporary; this->stackOffset = (short)in_stackOffset; } @@ -18309,11 +18409,11 @@ void asCExprValue::SetConstantData(const asCDataType &dt, asQWORD qw) // This code is necessary to guarantee that the code // works on both big endian and little endian CPUs. - if (dataType.GetSizeInMemoryBytes() == 1) + if( dataType.GetSizeInMemoryBytes() == 1 ) byteValue = (asBYTE)qw; - if (dataType.GetSizeInMemoryBytes() == 2) + if( dataType.GetSizeInMemoryBytes() == 2 ) wordValue = (asWORD)qw; - if (dataType.GetSizeInMemoryBytes() == 4) + if( dataType.GetSizeInMemoryBytes() == 4 ) dwordValue = (asDWORD)qw; else qwordValue = qw; @@ -18324,11 +18424,11 @@ asQWORD asCExprValue::GetConstantData() asQWORD qw = 0; // This code is necessary to guarantee that the code // works on both big endian and little endian CPUs. - if (dataType.GetSizeInMemoryBytes() == 1) + if( dataType.GetSizeInMemoryBytes() == 1 ) qw = byteValue; - if (dataType.GetSizeInMemoryBytes() == 2) + if( dataType.GetSizeInMemoryBytes() == 2 ) qw = wordValue; - if (dataType.GetSizeInMemoryBytes() == 4) + if( dataType.GetSizeInMemoryBytes() == 4 ) qw = dwordValue; else qw = qwordValue; @@ -18343,20 +18443,20 @@ void asCExprValue::SetUndefinedFuncHandle(asCScriptEngine *engine) // to determine the exact function when the signature is // known. Set(asCDataType::CreateObjectHandle(&engine->functionBehaviours, true)); - isConstant = true; + isConstant = true; isExplicitHandle = false; - qwordValue = 1; // Set to a different value than 0 to differentiate from null constant - isLValue = false; + qwordValue = 1; // Set to a different value than 0 to differentiate from null constant + isLValue = false; } bool asCExprValue::IsUndefinedFuncHandle() const { - if (isConstant == false) return false; - if (qwordValue == 0) return false; - if (isLValue) return false; - if (dataType.GetTypeInfo() == 0) return false; - if (dataType.GetTypeInfo()->name != "$func") return false; - if (dataType.IsFuncdef()) return false; + if( isConstant == false ) return false; + if( qwordValue == 0 ) return false; + if( isLValue ) return false; + if( dataType.GetTypeInfo() == 0 ) return false; + if( dataType.GetTypeInfo()->name != "$func" ) return false; + if( dataType.IsFuncdef() ) return false; return true; } @@ -18364,16 +18464,16 @@ bool asCExprValue::IsUndefinedFuncHandle() const void asCExprValue::SetNullConstant() { Set(asCDataType::CreateNullHandle()); - isConstant = true; + isConstant = true; isExplicitHandle = false; - qwordValue = 0; - isLValue = false; + qwordValue = 0; + isLValue = false; } bool asCExprValue::IsNullConstant() const { // We can't check the actual object type, because the null constant may have been cast to another type - if (isConstant && dataType.IsObjectHandle() && qwordValue == 0) + if( isConstant && dataType.IsObjectHandle() && qwordValue == 0 ) return true; return false; @@ -18382,13 +18482,13 @@ bool asCExprValue::IsNullConstant() const void asCExprValue::SetVoid() { Set(asCDataType::CreatePrimitive(ttVoid, false)); - isLValue = false; + isLValue = false; isConstant = true; } bool asCExprValue::IsVoid() const { - if (dataType.GetTokenType() == ttVoid) + if( dataType.GetTokenType() == ttVoid ) return true; return false; @@ -18404,17 +18504,17 @@ void asCExprValue::SetDummy() asCExprContext::asCExprContext(asCScriptEngine *engine) : bc(engine) { property_arg = 0; - next = 0; + next = 0; Clear(); } asCExprContext::~asCExprContext() { - if (property_arg) + if( property_arg ) asDELETE(property_arg, asCExprContext); - - if (next) + + if( next ) asDELETE(next, asCExprContext); } @@ -18423,44 +18523,44 @@ void asCExprContext::Clear() bc.ClearAll(); type.Set(asCDataType()); deferredParams.SetLength(0); - if (property_arg) + if( property_arg ) asDELETE(property_arg, asCExprContext); - property_arg = 0; - exprNode = 0; - origExpr = 0; - property_get = 0; - property_set = 0; - property_const = false; - property_handle = false; - property_ref = false; - methodName = ""; - enumValue = ""; - symbolNamespace = 0; - isVoidExpression = false; - isCleanArg = false; + property_arg = 0; + exprNode = 0; + origExpr = 0; + property_get = 0; + property_set = 0; + property_const = false; + property_handle = false; + property_ref = false; + methodName = ""; + enumValue = ""; + symbolNamespace = 0; + isVoidExpression = false; + isCleanArg = false; isAnonymousInitList = false; - origCode = 0; - - if (next) + origCode = 0; + + if( next ) asDELETE(next, asCExprContext); next = 0; } bool asCExprContext::IsClassMethod() const { - if (type.dataType.GetTypeInfo() == 0) return false; - if (methodName == "") return false; - if (type.dataType.GetTypeInfo() == &type.dataType.GetTypeInfo()->engine->functionBehaviours) return false; - if (isAnonymousInitList) return false; + if( type.dataType.GetTypeInfo() == 0 ) return false; + if( methodName == "" ) return false; + if( type.dataType.GetTypeInfo() == &type.dataType.GetTypeInfo()->engine->functionBehaviours ) return false; + if( isAnonymousInitList ) return false; return true; } bool asCExprContext::IsGlobalFunc() const { - if (type.dataType.GetTypeInfo() == 0) return false; - if (methodName == "") return false; - if (type.dataType.GetTypeInfo() != &type.dataType.GetTypeInfo()->engine->functionBehaviours) return false; - if (isAnonymousInitList) return false; + if( type.dataType.GetTypeInfo() == 0 ) return false; + if( methodName == "" ) return false; + if( type.dataType.GetTypeInfo() != &type.dataType.GetTypeInfo()->engine->functionBehaviours ) return false; + if( isAnonymousInitList ) return false; return true; } @@ -18476,7 +18576,7 @@ void asCExprContext::SetLambda(asCScriptNode *funcDecl) bool asCExprContext::IsLambda() const { - if (type.IsUndefinedFuncHandle() && exprNode && exprNode->nodeType == snFunction) + if( type.IsUndefinedFuncHandle() && exprNode && exprNode->nodeType == snFunction ) return true; return false; @@ -18491,7 +18591,7 @@ void asCExprContext::SetVoidExpression() bool asCExprContext::IsVoidExpression() const { - if (isVoidExpression && type.IsVoid() && exprNode == 0) + if( isVoidExpression && type.IsVoid() && exprNode == 0 ) return true; return false; @@ -18500,14 +18600,14 @@ bool asCExprContext::IsVoidExpression() const void asCExprContext::SetAnonymousInitList(asCScriptNode *initList, asCScriptCode *script) { Clear(); - exprNode = initList; - origCode = script; + exprNode = initList; + origCode = script; isAnonymousInitList = true; } bool asCExprContext::IsAnonymousInitList() const { - if (isAnonymousInitList && exprNode && exprNode->nodeType == snInitList) + if( isAnonymousInitList && exprNode && exprNode->nodeType == snInitList ) return true; return false; @@ -18538,7 +18638,7 @@ void asCExprContext::Merge(asCExprContext *after) // Overwrite properties with the expression that comes after Copy(after); - // Clean the properties in 'after' that have now moved into + // Clean the properties in 'after' that have now moved into // this structure so they are not cleaned up accidentally after->property_arg = 0; } @@ -18548,6 +18648,3 @@ void asCExprContext::Merge(asCExprContext *after) END_AS_NAMESPACE #endif // AS_NO_COMPILER - - - diff --git a/sdk/angelscript/source/as_compiler.h b/sdk/angelscript/source/as_compiler.h index 9169f508..f25a71c9 100644 --- a/sdk/angelscript/source/as_compiler.h +++ b/sdk/angelscript/source/as_compiler.h @@ -44,36 +44,36 @@ #ifndef AS_NO_COMPILER -#include "as_builder.h" -#include "as_scriptfunction.h" -#include "as_variablescope.h" -#include "as_bytecode.h" -#include "as_array.h" -#include "as_datatype.h" + #include "as_builder.h" + #include "as_scriptfunction.h" + #include "as_variablescope.h" + #include "as_bytecode.h" + #include "as_array.h" + #include "as_datatype.h" BEGIN_AS_NAMESPACE // This class represents the value of an expression as evaluated by the compiler. -// It holds information such as the type of the value, stack offset for a local +// It holds information such as the type of the value, stack offset for a local // variable, value of constants, whether the value can be modified (i.e. lvalue), etc. struct asCExprValue { asCExprValue(); void Set(const asCDataType &dataType); - void SetVariable(const asCDataType &dataType, int stackOffset, bool isTemporary); - void SetConstantB(const asCDataType &dataType, asBYTE value); - void SetConstantQW(const asCDataType &dataType, asQWORD value); - void SetConstantDW(const asCDataType &dataType, asDWORD value); - void SetConstantW(const asCDataType &dataType, asWORD value); - void SetConstantF(const asCDataType &dataType, float value); - void SetConstantD(const asCDataType &dataType, double value); - void SetConstantB(asBYTE value); - void SetConstantW(asWORD value); - void SetConstantQW(asQWORD value); - void SetConstantDW(asDWORD value); - void SetConstantF(float value); - void SetConstantD(double value); + void SetVariable(const asCDataType &dataType, int stackOffset, bool isTemporary); + void SetConstantB(const asCDataType &dataType, asBYTE value); + void SetConstantQW(const asCDataType &dataType, asQWORD value); + void SetConstantDW(const asCDataType &dataType, asDWORD value); + void SetConstantW(const asCDataType &dataType, asWORD value); + void SetConstantF(const asCDataType &dataType, float value); + void SetConstantD(const asCDataType &dataType, double value); + void SetConstantB(asBYTE value); + void SetConstantW(asWORD value); + void SetConstantQW(asQWORD value); + void SetConstantDW(asDWORD value); + void SetConstantF(float value); + void SetConstantD(double value); asBYTE GetConstantB(); asWORD GetConstantW(); asQWORD GetConstantQW(); @@ -81,7 +81,7 @@ struct asCExprValue float GetConstantF(); double GetConstantD(); - void SetConstantData(const asCDataType &dataType, asQWORD value); + void SetConstantData(const asCDataType &dataType, asQWORD value); asQWORD GetConstantData(); void SetNullConstant(); @@ -94,15 +94,15 @@ struct asCExprValue bool IsVoid() const; asCDataType dataType; - bool isLValue : 1; // Can this value be updated in assignment, or increment operators, etc - bool isTemporary : 1; - bool isConstant : 1; - bool isVariable : 1; - bool isExplicitHandle : 1; - bool isRefToLocal : 1; // The reference may be to a local variable - bool isRefSafe : 1; // the life-time of the ref is guaranteed for the duration of the access - short dummy : 9; - int stackOffset; // used both for stack offset and indexing global variables + bool isLValue : 1; // Can this value be updated in assignment, or increment operators, etc + bool isTemporary : 1; + bool isConstant : 1; + bool isVariable : 1; + bool isExplicitHandle : 1; + bool isRefToLocal : 1; // The reference may be to a local variable + bool isRefSafe : 1; // the life-time of the ref is guaranteed for the duration of the access + short dummy : 9; + int stackOffset; // used both for stack offset and indexing global variables private: // These values must not be accessed directly in order to avoid problems with endianess. @@ -120,11 +120,13 @@ struct asCExprValue struct asCExprContext; -// This class holds information for arguments that needs to be +// This class holds information for arguments that needs to be // cleaned up after the result of a function has been evaluated. struct asSDeferredParam { - asSDeferredParam() : argNode(0), argInOutFlags(0), origExpr(0) {} + asSDeferredParam() : argNode(0), argInOutFlags(0), origExpr(0) + { + } asCScriptNode *argNode; asCExprValue argType; @@ -153,53 +155,57 @@ struct asCExprContext void SetAnonymousInitList(asCScriptNode *initList, asCScriptCode *script); bool IsAnonymousInitList() const; - asCByteCode bc; - asCExprValue type; - int property_get; - int property_set; - bool property_const; // If the object that is being accessed through property accessor is read-only - bool property_handle; // If the property accessor is called on an object stored in a handle - bool property_ref; // If the property accessor is called on a reference - bool isVoidExpression; // Set to true if the expression is an explicit 'void', e.g. used to ignore out parameters in func calls - bool isCleanArg; // Set to true if the expression has only been initialized with default constructor - asCExprContext *property_arg; + asCByteCode bc; + asCExprValue type; + int property_get; + int property_set; + bool property_const; // If the object that is being accessed through property accessor is read-only + bool property_handle; // If the property accessor is called on an object stored in a handle + bool property_ref; // If the property accessor is called on a reference + bool isVoidExpression; // Set to true if the expression is an explicit 'void', e.g. used to ignore out parameters in func calls + bool isCleanArg; // Set to true if the expression has only been initialized with default constructor + asCExprContext *property_arg; asCArray deferredParams; - asCScriptNode *exprNode; - asCExprContext *origExpr; - asCScriptCode *origCode; - asCExprContext* next; + asCScriptNode *exprNode; + asCExprContext *origExpr; + asCScriptCode *origCode; + asCExprContext *next; // TODO: cleanup: use ambiguousName and an enum to say if it is a method, global func, or enum value - asCString methodName; - asCString enumValue; - asSNameSpace *symbolNamespace; // The namespace in which the ambiguous symbol was found - bool isAnonymousInitList; // Set to true if the expression is an init list for which the type has not yet been determined + asCString methodName; + asCString enumValue; + asSNameSpace *symbolNamespace; // The namespace in which the ambiguous symbol was found + bool isAnonymousInitList; // Set to true if the expression is an init list for which the type has not yet been determined }; struct asSOverloadCandidate { - asSOverloadCandidate() : funcId(0), cost(0) {} - asSOverloadCandidate(int _id, asUINT _cost) : funcId(_id), cost(_cost) {} - int funcId; + asSOverloadCandidate() : funcId(0), cost(0) + { + } + asSOverloadCandidate(int _id, asUINT _cost) : funcId(_id), cost(_cost) + { + } + int funcId; asUINT cost; }; struct asSNamedArgument { - asSNamedArgument() : ctx(0), match(0) {} - asCString name; + asSNamedArgument() : ctx(0), match(0) + { + } + asCString name; asCExprContext *ctx; - asUINT match; + asUINT match; }; -enum EImplicitConv -{ +enum EImplicitConv { asIC_IMPLICIT_CONV, asIC_EXPLICIT_REF_CAST, asIC_EXPLICIT_VAL_CAST }; -enum EConvCost -{ +enum EConvCost { asCC_NO_CONV = 0, asCC_CONST_CONV = 1, asCC_ENUM_SAME_SIZE_CONV = 2, @@ -212,32 +218,30 @@ enum EConvCost asCC_FLOAT_TO_INT_CONV = 9, asCC_REF_CONV = 10, // REF_CONV + CONST_CONV = 11, - asCC_OBJ_TO_PRIMITIVE_CONV = 12, + asCC_OBJ_TO_PRIMITIVE_CONV = 12, // OBJ_TO_PRIM + CONST_CONV = 13, - asCC_TO_OBJECT_CONV = 14, + asCC_TO_OBJECT_CONV = 14, // TO_OBJ_CONV + CONST_CONV = 15, - asCC_VARIABLE_CONV = 16 + asCC_VARIABLE_CONV = 16 }; -enum EVarGlobOrMem -{ +enum EVarGlobOrMem { asVGM_VARIABLE = 0, asVGM_GLOBAL = 1, asVGM_MEMBER = 2 }; -enum asEFailedMatchReason -{ +enum asEFailedMatchReason { // pre-condition checks asEFM_NOT_ENOUGH_ARGS, asEFM_TOO_MANY_ARGS, - + // "arg" is set to the argument // that reported the error asEFM_POSITIONAL_MISMATCH, // positional parameter type mismatch - asEFM_NAMED_DUPLICATE, // named parameter duplicate - asEFM_NAMED_MISMATCH, // named parameter type mismatch - + asEFM_NAMED_DUPLICATE, // named parameter duplicate + asEFM_NAMED_MISMATCH, // named parameter type mismatch + // "argName" is set to the named // argument that doesn't exist asEFM_NAMED_MISSING // named parameter missing @@ -247,17 +251,21 @@ struct asSFailedMatch { int func; asEFailedMatchReason reason; - + // for asEFM_POSITIONAL_MISMATCH, asEFM_NAMED_DUPLICATE: arg id - asUINT arg; + asUINT arg; // for asEFM_NAMED_MISSING, asEFM_NAMED_MISMATCH, asEFM_NAMED_DUPLICATE: ptr to argument string - const char* argName; - - asSFailedMatch() : func(0), reason(asEFM_NOT_ENOUGH_ARGS), arg(0), argName(0) {} - asSFailedMatch(int func, asEFailedMatchReason reason, asUINT arg = -1) : - func(func), reason(reason), arg(arg), argName(NULL) {} - asSFailedMatch(int func, asEFailedMatchReason reason, const char* argName) : - func(func), reason(reason), arg(asUINT(-1)), argName(argName) { } + const char *argName; + + asSFailedMatch() : func(0), reason(asEFM_NOT_ENOUGH_ARGS), arg(0), argName(0) + { + } + asSFailedMatch(int func, asEFailedMatchReason reason, asUINT arg = -1) : func(func), reason(reason), arg(arg), argName(NULL) + { + } + asSFailedMatch(int func, asEFailedMatchReason reason, const char *argName) : func(func), reason(reason), arg(asUINT(-1)), argName(argName) + { + } }; class asCCompiler @@ -285,7 +293,7 @@ class asCCompiler void CompileSwitchStatement(asCScriptNode *node, bool *hasReturn, asCByteCode *bc); void CompileCase(asCScriptNode *node, asCByteCode *bc, bool *hasReturn, bool *hasBreak); void CompileForStatement(asCScriptNode *node, asCByteCode *bc); - void CompileForEachStatement(asCScriptNode* node, asCByteCode* bc); + void CompileForEachStatement(asCScriptNode *node, asCByteCode *bc); void CompileWhileStatement(asCScriptNode *node, asCByteCode *bc); void CompileDoWhileStatement(asCScriptNode *node, asCByteCode *bc); void CompileBreakStatement(asCScriptNode *node, asCByteCode *bc); @@ -323,59 +331,58 @@ class asCCompiler int CallCopyConstructor(asCDataType &type, int offset, bool isObjectOnHeap, asCExprContext *ctx, asCExprContext *arg, asCScriptNode *node, EVarGlobOrMem isVarGlobOrMem = asVGM_VARIABLE, bool derefDestination = false); void CallDestructor(asCDataType &type, int offset, bool isObjectOnHeap, asCByteCode *bc); int CompileArgumentList(asCScriptNode *node, asCArray &args, asCArray &namedArgs); - int CompileDefaultAndNamedArgs(asCScriptNode *node, asCArray &args, int funcId, asCObjectType *type, asCArray *namedArgs = 0); + int CompileDefaultAndNamedArgs(asCScriptNode *node, asCArray &args, int funcId, asCObjectType *type, asCArray *namedArgs = 0); int CompileVariableAccess(const asCString &name, const asCString &scope, asCExprContext *ctx, asCScriptNode *errNode, bool isOptional = false, asCObjectType *objType = 0); void CompileMemberInitialization(asCByteCode *bc, bool onlyDefaults); - void CompileMemberInitializationCopy(asCByteCode* bc); + void CompileMemberInitializationCopy(asCByteCode *bc); bool CompileAutoType(asCDataType &autoType, asCExprContext &compiledCtx, asCScriptNode *exprNode, asCScriptNode *errNode); bool CompileInitialization(asCScriptNode *node, asCByteCode *bc, const asCDataType &type, asCScriptNode *errNode, int offset, asQWORD *constantValue, EVarGlobOrMem isVarGlobOrMem, asCExprContext *preCompiled = 0); - bool CompileInitializationWithAssignment(asCByteCode* bc, const asCDataType &type, asCScriptNode *errNode, int offset, asQWORD* constantValue, EVarGlobOrMem isVarGlobOrMem, asCScriptNode* rnode, asCExprContext* rexpr); + bool CompileInitializationWithAssignment(asCByteCode *bc, const asCDataType &type, asCScriptNode *errNode, int offset, asQWORD *constantValue, EVarGlobOrMem isVarGlobOrMem, asCScriptNode *rnode, asCExprContext *rexpr); void CompileInitAsCopy(asCDataType &type, int offset, asCExprContext *ctx, asCExprContext *arg, asCScriptNode *node, bool derefDestination, EVarGlobOrMem isVarGlobOrMem = asVGM_VARIABLE); // Helper functions - void ConvertToPostFix(asCScriptNode *expr, asCArray &postfix); - int ProcessPropertyGetAccessor(asCExprContext *ctx, asCScriptNode *node); - int ProcessPropertySetAccessor(asCExprContext *ctx, asCExprContext *arg, asCScriptNode *node); - int ProcessPropertyGetSetAccessor(asCExprContext *ctx, asCExprContext *lctx, asCExprContext *rctx, eTokenType op, asCScriptNode *errNode); - int FindPropertyAccessor(const asCString &name, asCExprContext *ctx, asCScriptNode *node, asSNameSpace *ns, bool isThisAccess = false); - int FindPropertyAccessor(const asCString &name, asCExprContext *ctx, asCExprContext *arg, asCScriptNode *node, asSNameSpace *ns, bool isThisAccess = false); - void PrepareTemporaryVariable(asCScriptNode *node, asCExprContext *ctx, bool forceOnHeap = false, bool forceValueCopy = false); - void PrepareOperand(asCExprContext *ctx, asCScriptNode *node); - void PrepareForAssignment(asCDataType *lvalue, asCExprContext *rvalue, asCScriptNode *node, bool toTemporary, asCExprContext *lvalueExpr = 0); - int PerformAssignment(asCExprValue *lvalue, asCExprValue *rvalue, asCByteCode *bc, asCScriptNode *node); - bool IsVariableInitialized(asCExprValue *type, asCScriptNode *node); - void Dereference(asCExprContext *ctx, bool generateCode); - bool CompileRefCast(asCExprContext *ctx, const asCDataType &to, bool isExplicit, asCScriptNode *node, bool generateCode = true); - asUINT MatchFunctions(asCArray& funcs, asCArray& args, asCScriptNode* node, const char* name, asCArray* namedArgs = NULL, asCObjectType* objectType = NULL, bool isConstMethod = false, bool silent = false, bool allowObjectConstruct = true, const asCString& scope = ""); - asUINT MatchArgument(asCArray &funcs, asCArray &matches, const asCExprContext *argExpr, int paramNum, bool allowObjectConstruct = true); - int MatchArgument(asCScriptFunction *desc, const asCExprContext *argExpr, int paramNum, bool allowObjectConstruct = true); - void PerformFunctionCall(int funcId, asCExprContext *out, bool isConstructor = false, asCArray *args = 0, asCObjectType *objTypeForConstruct = 0, bool useVariable = false, int varOffset = 0, int funcPtrVar = 0); - void MoveArgsToStack(int funcId, asCByteCode *bc, asCArray &args, bool addOneToOffset); - int MakeFunctionCall(asCExprContext *ctx, int funcId, asCObjectType *objectType, asCArray &args, asCScriptNode *node, bool useVariable = false, int stackOffset = 0, int funcPtrVar = 0, bool onHeap = false); - int PrepareFunctionCall(int funcId, asCByteCode *bc, asCArray &args); - void AfterFunctionCall(int funcId, asCArray &args, asCExprContext *ctx, bool deferAll); - void ProcessDeferredParams(asCExprContext *ctx, bool processOnlyOutRef = false); - int PrepareArgument(asCDataType *paramType, asCExprContext *ctx, asCScriptNode *node, bool isFunction = false, int refType = 0, bool isMakingCopy = false); - int PrepareArgument2(asCExprContext *ctx, asCExprContext *arg, asCDataType *paramType, bool isFunction = false, int refType = 0, bool isMakingCopy = false); - bool IsLValue(asCExprValue &type); - int DoAssignment(asCExprContext *out, asCExprContext *lctx, asCExprContext *rctx, asCScriptNode *lexpr, asCScriptNode *rexpr, eTokenType op, asCScriptNode *opNode); - void MergeExprBytecode(asCExprContext *before, asCExprContext *after); - void MergeExprBytecodeAndType(asCExprContext *before, asCExprContext *after); - void FilterConst(asCArray &funcs, bool removeConst = true); - void ConvertToVariable(asCExprContext *ctx); - void ConvertToVariableNotIn(asCExprContext *ctx, asCExprContext *exclude); - void ConvertToTempVariable(asCExprContext *ctx); - void ConvertToTempVariableNotIn(asCExprContext *ctx, asCExprContext *exclude); - void ConvertToReference(asCExprContext *ctx); - void PushVariableOnStack(asCExprContext *ctx, bool asReference); - void DestroyVariables(asCByteCode *bc); + void ConvertToPostFix(asCScriptNode *expr, asCArray &postfix); + int ProcessPropertyGetAccessor(asCExprContext *ctx, asCScriptNode *node); + int ProcessPropertySetAccessor(asCExprContext *ctx, asCExprContext *arg, asCScriptNode *node); + int ProcessPropertyGetSetAccessor(asCExprContext *ctx, asCExprContext *lctx, asCExprContext *rctx, eTokenType op, asCScriptNode *errNode); + int FindPropertyAccessor(const asCString &name, asCExprContext *ctx, asCScriptNode *node, asSNameSpace *ns, bool isThisAccess = false); + int FindPropertyAccessor(const asCString &name, asCExprContext *ctx, asCExprContext *arg, asCScriptNode *node, asSNameSpace *ns, bool isThisAccess = false); + void PrepareTemporaryVariable(asCScriptNode *node, asCExprContext *ctx, bool forceOnHeap = false, bool forceValueCopy = false); + void PrepareOperand(asCExprContext *ctx, asCScriptNode *node); + void PrepareForAssignment(asCDataType *lvalue, asCExprContext *rvalue, asCScriptNode *node, bool toTemporary, asCExprContext *lvalueExpr = 0); + int PerformAssignment(asCExprValue *lvalue, asCExprValue *rvalue, asCByteCode *bc, asCScriptNode *node); + bool IsVariableInitialized(asCExprValue *type, asCScriptNode *node); + void Dereference(asCExprContext *ctx, bool generateCode); + bool CompileRefCast(asCExprContext *ctx, const asCDataType &to, bool isExplicit, asCScriptNode *node, bool generateCode = true); + asUINT MatchFunctions(asCArray &funcs, asCArray &args, asCScriptNode *node, const char *name, asCArray *namedArgs = NULL, asCObjectType *objectType = NULL, bool isConstMethod = false, bool silent = false, bool allowObjectConstruct = true, const asCString &scope = ""); + asUINT MatchArgument(asCArray &funcs, asCArray &matches, const asCExprContext *argExpr, int paramNum, bool allowObjectConstruct = true); + int MatchArgument(asCScriptFunction *desc, const asCExprContext *argExpr, int paramNum, bool allowObjectConstruct = true); + void PerformFunctionCall(int funcId, asCExprContext *out, bool isConstructor = false, asCArray *args = 0, asCObjectType *objTypeForConstruct = 0, bool useVariable = false, int varOffset = 0, int funcPtrVar = 0); + void MoveArgsToStack(int funcId, asCByteCode *bc, asCArray &args, bool addOneToOffset); + int MakeFunctionCall(asCExprContext *ctx, int funcId, asCObjectType *objectType, asCArray &args, asCScriptNode *node, bool useVariable = false, int stackOffset = 0, int funcPtrVar = 0, bool onHeap = false); + int PrepareFunctionCall(int funcId, asCByteCode *bc, asCArray &args); + void AfterFunctionCall(int funcId, asCArray &args, asCExprContext *ctx, bool deferAll); + void ProcessDeferredParams(asCExprContext *ctx, bool processOnlyOutRef = false); + int PrepareArgument(asCDataType *paramType, asCExprContext *ctx, asCScriptNode *node, bool isFunction = false, int refType = 0, bool isMakingCopy = false); + int PrepareArgument2(asCExprContext *ctx, asCExprContext *arg, asCDataType *paramType, bool isFunction = false, int refType = 0, bool isMakingCopy = false); + bool IsLValue(asCExprValue &type); + int DoAssignment(asCExprContext *out, asCExprContext *lctx, asCExprContext *rctx, asCScriptNode *lexpr, asCScriptNode *rexpr, eTokenType op, asCScriptNode *opNode); + void MergeExprBytecode(asCExprContext *before, asCExprContext *after); + void MergeExprBytecodeAndType(asCExprContext *before, asCExprContext *after); + void FilterConst(asCArray &funcs, bool removeConst = true); + void ConvertToVariable(asCExprContext *ctx); + void ConvertToVariableNotIn(asCExprContext *ctx, asCExprContext *exclude); + void ConvertToTempVariable(asCExprContext *ctx); + void ConvertToTempVariableNotIn(asCExprContext *ctx, asCExprContext *exclude); + void ConvertToReference(asCExprContext *ctx); + void PushVariableOnStack(asCExprContext *ctx, bool asReference); + void DestroyVariables(asCByteCode *bc); asSNameSpace *DetermineNameSpace(const asCString &scope); - int SetupParametersAndReturnVariable(asCArray ¶meterNames, asCScriptNode *func); - int InstantiateTemplateFunctions(asCArray& funcs, asCScriptNode* node); - asCString BuildLambdaSignature(asCScriptNode* node); + int SetupParametersAndReturnVariable(asCArray ¶meterNames, asCScriptNode *func); + int InstantiateTemplateFunctions(asCArray &funcs, asCScriptNode *node); + asCString BuildLambdaSignature(asCScriptNode *node); - enum SYMBOLTYPE - { + enum SYMBOLTYPE { SL_NOMATCH, SL_LOCALCONST, SL_LOCALVAR, @@ -393,8 +400,8 @@ class asCCompiler SL_ERROR = -1 }; - bool isAmbiguousSymbol(const asCString &name, asCScriptNode* errNode, SYMBOLTYPE& currentType, SYMBOLTYPE nextType); - SYMBOLTYPE SymbolLookup(const asCString &name, const asCString &scope, asCObjectType *objType, asCExprContext *outResult, asCScriptNode* errNode); + bool isAmbiguousSymbol(const asCString &name, asCScriptNode *errNode, SYMBOLTYPE ¤tType, SYMBOLTYPE nextType); + SYMBOLTYPE SymbolLookup(const asCString &name, const asCString &scope, asCObjectType *objType, asCExprContext *outResult, asCScriptNode *errNode); SYMBOLTYPE SymbolLookupLocalVar(const asCString &name, asCExprContext *outResult); SYMBOLTYPE SymbolLookupMember(const asCString &name, asCObjectType *objType, asCExprContext *outResult); @@ -415,15 +422,15 @@ class asCCompiler void LineInstr(asCByteCode *bc, size_t pos); asUINT ProcessStringConstant(asCString &str, asCScriptNode *node, bool processEscapeSequences = true); - void ProcessHeredocStringConstant(asCString &str, asCScriptNode *node); - int GetPrecedence(asCScriptNode *op); - void Error(const asCString &msg, asCScriptNode *node); - void Warning(const asCString &msg, asCScriptNode *node); - void Information(const asCString &msg, asCScriptNode *node); - void PrintMatchingFuncs(asCArray &funcs, asCScriptNode *node, asCObjectType *inType = 0, asCArray* failedReasons = NULL); - void AddVariableScope(bool isBreakScope = false, bool isContinueScope = false); - void RemoveVariableScope(); - void FinalizeFunction(); + void ProcessHeredocStringConstant(asCString &str, asCScriptNode *node); + int GetPrecedence(asCScriptNode *op); + void Error(const asCString &msg, asCScriptNode *node); + void Warning(const asCString &msg, asCScriptNode *node); + void Information(const asCString &msg, asCScriptNode *node); + void PrintMatchingFuncs(asCArray &funcs, asCScriptNode *node, asCObjectType *inType = 0, asCArray *failedReasons = NULL); + void AddVariableScope(bool isBreakScope = false, bool isContinueScope = false); + void RemoveVariableScope(); + void FinalizeFunction(); asCByteCode byteCode; @@ -438,56 +445,56 @@ class asCCompiler asCScriptCode *script; asCScriptFunction *outFunc; - bool m_isConstructor; - bool m_isConstructorCalled; - bool m_hasReturned; - asCArray m_initializedProperties; // Doesn't hold reference - asCArray m_namespaceVisibility; - asCMap m_propertyAccessCount; // Doesn't hold reference - asCMap m_inheritedPropertyAccess; // Doesn't hold reference - sClassDeclaration *m_classDecl; - sGlobalVariableDescription *m_globalVar; + bool m_isConstructor; + bool m_isConstructorCalled; + bool m_hasReturned; + asCArray m_initializedProperties; // Doesn't hold reference + asCArray m_namespaceVisibility; + asCMap m_propertyAccessCount; // Doesn't hold reference + asCMap m_inheritedPropertyAccess; // Doesn't hold reference + sClassDeclaration *m_classDecl; + sGlobalVariableDescription *m_globalVar; asCArray breakLabels; asCArray continueLabels; - int AllocateVariable(const asCDataType &type, bool isTemporary, bool forceOnHeap = false, bool asReference = false); - int AllocateVariableNotIn(const asCDataType &type, bool isTemporary, bool forceOnHeap, asCExprContext *ctx); - int GetVariableOffset(int varIndex); - int GetVariableSlot(int varOffset); + int AllocateVariable(const asCDataType &type, bool isTemporary, bool forceOnHeap = false, bool asReference = false); + int AllocateVariableNotIn(const asCDataType &type, bool isTemporary, bool forceOnHeap, asCExprContext *ctx); + int GetVariableOffset(int varIndex); + int GetVariableSlot(int varOffset); void DeallocateVariable(int pos); void ReleaseTemporaryVariable(asCExprValue &t, asCByteCode *bc); void ReleaseTemporaryVariable(int offset, asCByteCode *bc); bool IsVariableOnHeap(int offset); - int DeclareVariable(const asCString &name, const asCDataType &type, int offset, asCByteCode *bc, asCScriptNode *node); + int DeclareVariable(const asCString &name, const asCDataType &type, int offset, asCByteCode *bc, asCScriptNode *node); // This ordered array indicates the type of each variable asCArray variableAllocations; // This ordered array indicates which variables are temporaries or not - asCArray variableIsTemporary; + asCArray variableIsTemporary; // This unordered array gives the offsets of all temporary variables, whether currently allocated or not - asCArray tempVariableOffsets; + asCArray tempVariableOffsets; // This ordered array indicated if the variable is on the heap or not - asCArray variableIsOnHeap; + asCArray variableIsOnHeap; // This unordered array gives the indexes of the currently unused variables - asCArray freeVariables; + asCArray freeVariables; // This array holds the offsets of the currently allocated temporary variables - asCArray tempVariables; + asCArray tempVariables; // This array holds the indices of variables that must not be used in an allocation - asCArray reservedVariables; + asCArray reservedVariables; - // This array holds the string constants that were allocated during the compilation, + // This array holds the string constants that were allocated during the compilation, // so they can be released upon completion, whether the compilation was successful or not. - asCArray usedStringConstants; + asCArray usedStringConstants; // This array holds the nodes that have been allocated temporarily - asCArray nodesToFreeUponComplete; + asCArray nodesToFreeUponComplete; bool isCompilingDefaultArg; bool isProcessingDeferredParams; diff --git a/sdk/angelscript/source/as_config.h b/sdk/angelscript/source/as_config.h index d5b40c2e..3a39b8b8 100644 --- a/sdk/angelscript/source/as_config.h +++ b/sdk/angelscript/source/as_config.h @@ -174,7 +174,7 @@ // GNU C based compilers // __GNUC__ is defined -// CLang/LLVM +// CLang/LLVM // __clang__ is defined // Embarcadero C++Builder @@ -374,7 +374,7 @@ //------------------------------------------------ -#define VALUE_OF_BOOLEAN_TRUE 1 +#define VALUE_OF_BOOLEAN_TRUE 1 #define STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 0 #define CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 0 #define THISCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 0 @@ -387,23 +387,23 @@ // Emscripten compiler toolchain // ref: https://emscripten.org/ #if defined(__EMSCRIPTEN__) - #define AS_MAX_PORTABILITY + #define AS_MAX_PORTABILITY #endif // Embarcadero C++Builder #if defined(__BORLANDC__) - #ifndef _Windows - #error "Configuration doesn't yet support BCC for Linux or Mac OS." - #endif - #if defined(_M_X64) - #error "Configuration doesn't yet support BCC for AMD64." - #endif - - #define MULTI_BASE_OFFSET(x) (*((const asDWORD*)(&x)+1)) + #ifndef _Windows + #error "Configuration doesn't yet support BCC for Linux or Mac OS." + #endif + #if defined(_M_X64) + #error "Configuration doesn't yet support BCC for AMD64." + #endif + + #define MULTI_BASE_OFFSET(x) (*((const asDWORD *)(&x) + 1)) #define HAVE_VIRTUAL_BASE_OFFSET - #define VIRTUAL_BASE_OFFSET(x) (*((const asDWORD*)(&x)+2)) + #define VIRTUAL_BASE_OFFSET(x) (*((const asDWORD *)(&x) + 2)) #define THISCALL_RETURN_SIMPLE_IN_MEMORY #define CDECL_RETURN_SIMPLE_IN_MEMORY #define STDCALL_RETURN_SIMPLE_IN_MEMORY @@ -428,7 +428,7 @@ #define asVSNPRINTF(a, b, c, d) _vsnprintf(a, b, c, d) - #define fmodf(a,b) fmod(a,b) + #define fmodf(a, b) fmod(a, b) #define UNREACHABLE_RETURN #endif @@ -439,15 +439,15 @@ #if _MSC_VER <= 1200 // MSVC6 // Disable the useless warnings about truncated symbol names for template instances - #pragma warning( disable : 4786 ) + #pragma warning(disable : 4786) #endif #ifdef _M_X64 - #define MULTI_BASE_OFFSET(x) (*((const asDWORD*)(&x)+2)) - #define VIRTUAL_BASE_OFFSET(x) (*((const asDWORD*)(&x)+4)) + #define MULTI_BASE_OFFSET(x) (*((const asDWORD *)(&x) + 2)) + #define VIRTUAL_BASE_OFFSET(x) (*((const asDWORD *)(&x) + 4)) #else - #define MULTI_BASE_OFFSET(x) (*((const asDWORD*)(&x)+1)) - #define VIRTUAL_BASE_OFFSET(x) (*((const asDWORD*)(&x)+3)) + #define MULTI_BASE_OFFSET(x) (*((const asDWORD *)(&x) + 1)) + #define VIRTUAL_BASE_OFFSET(x) (*((const asDWORD *)(&x) + 3)) #endif #define HAVE_VIRTUAL_BASE_OFFSET #define THISCALL_RETURN_SIMPLE_IN_MEMORY @@ -477,7 +477,7 @@ #define AS_X86 #endif #else - #if _MSC_VER < 1500 // MSVC++ 9 (aka MSVC++ .NET 2008) + #if _MSC_VER < 1500 // MSVC++ 9 (aka MSVC++ .NET 2008) #define asVSNPRINTF(a, b, c, d) _vsnprintf(a, b, c, d) #else #define asVSNPRINTF(a, b, c, d) vsnprintf_s(a, b, _TRUNCATE, c, d) @@ -491,7 +491,7 @@ #define AS_SIZEOF_BOOL 1 #define COMPLEX_OBJS_PASSED_BY_REF - #define ASM_INTEL // Intel style for inline assembly on microsoft compilers + #define ASM_INTEL // Intel style for inline assembly on microsoft compilers #if defined(WIN32) || defined(_WIN32) || defined(_WIN64) #define AS_WIN @@ -508,7 +508,7 @@ #ifndef _XBOX // Not tested with xbox (only enabled if is Windows) #undef AS_NO_THISCALL_FUNCTOR_METHOD - #endif + #endif #elif defined(_M_X64) #define AS_X64_MSVC #undef AS_NO_THISCALL_FUNCTOR_METHOD @@ -527,7 +527,7 @@ #define STDCALL_RETURN_SIMPLE_IN_MEMORY #define COMPLEX_MASK (asOBJ_APP_CLASS_ASSIGNMENT | asOBJ_APP_ARRAY) #define COMPLEX_RETURN_MASK (asOBJ_APP_CLASS_ASSIGNMENT | asOBJ_APP_ARRAY) - + // Windows CE uses softfp calling convention, while Windows RT uses hardfp calling convention // ref: http://stackoverflow.com/questions/16375355/what-is-the-windows-rt-on-arm-native-code-calling-convention #if defined(_WIN32_WCE) @@ -538,7 +538,7 @@ #if defined(_M_ARM64) #define AS_ARM64 - // TODO: MORE HERE + // TODO: MORE HERE #endif #ifndef COMPLEX_MASK @@ -554,9 +554,9 @@ // Metrowerks CodeWarrior (experimental, let me know if something isn't working) #if defined(__MWERKS__) && !defined(EPPC) // JWC -- If Wii DO NOT use this even when using Metrowerks Compiler. Even though they are called Freescale... - #define MULTI_BASE_OFFSET(x) (*((const asDWORD*)(&x)+1)) + #define MULTI_BASE_OFFSET(x) (*((const asDWORD *)(&x) + 1)) #define HAVE_VIRTUAL_BASE_OFFSET - #define VIRTUAL_BASE_OFFSET(x) (*((const asDWORD*)(&x)+3)) + #define VIRTUAL_BASE_OFFSET(x) (*((const asDWORD *)(&x) + 3)) #define THISCALL_RETURN_SIMPLE_IN_MEMORY #define THISCALL_PASS_OBJECT_POINTER_IN_ECX #define asVSNPRINTF(a, b, c, d) _vsnprintf(a, b, c, d) @@ -570,7 +570,7 @@ // Support native calling conventions on x86, but not 64bit yet #if defined(_M_IX86) && !defined(__LP64__) #define AS_X86 - #define ASM_INTEL // Intel style for inline assembly + #define ASM_INTEL // Intel style for inline assembly #endif #define UNREACHABLE_RETURN @@ -593,7 +593,7 @@ #define STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 2 #else #define GNU_STYLE_VIRTUAL_METHOD - #define ASM_AT_N_T // AT&T style inline assembly + #define ASM_AT_N_T // AT&T style inline assembly #define COMPLEX_MASK (asOBJ_APP_CLASS_DESTRUCTOR) #define COMPLEX_RETURN_MASK (asOBJ_APP_CLASS_DESTRUCTOR) #endif @@ -614,7 +614,7 @@ #endif // Support native calling conventions on x86, but not 64bit yet - #if (defined(i386) || defined(__i386) || defined(__i386__)) && !defined(__LP64__) + #if ( defined(i386) || defined(__i386) || defined(__i386__) ) && !defined(__LP64__) #define AS_X86 // PS3 #elif (defined(__PPC__) || defined(__ppc__)) && defined(__PPU__) @@ -646,9 +646,9 @@ // GNU C (and MinGW or Cygwin on Windows) // Use the following command to determine predefined macros: echo . | g++ -dM -E - // MSVC2015 can now use CLang too, but it shouldn't go in here -#if (defined(__GNUC__) && !defined(__SNC__) && !defined(_MSC_VER)) || defined(EPPC) || defined(__CYGWIN__) // JWC -- use this instead for Wii +#if ( defined(__GNUC__) && !defined(__SNC__) && !defined(_MSC_VER) ) || defined(EPPC) || defined(__CYGWIN__) // JWC -- use this instead for Wii #define GNU_STYLE_VIRTUAL_METHOD - #define MULTI_BASE_OFFSET(x) (*((const asPWORD*)(&x)+1)) + #define MULTI_BASE_OFFSET(x) (*((const asPWORD *)(&x) + 1)) #define asVSNPRINTF(a, b, c, d) vsnprintf(a, b, c, d) #define CALLEE_POPS_HIDDEN_RETURN_POINTER #define COMPLEX_OBJS_PASSED_BY_REF @@ -665,7 +665,7 @@ #define AS_USE_COMPUTED_GOTOS 1 // Also in clang 5.0 but how do i test for that? Should use __has_extension, but I don't know the name of the labels as values extension - #elif defined(__clang__) + #elif defined(__clang__) #define AS_USE_COMPUTED_GOTOS 1 #endif #endif @@ -678,12 +678,12 @@ #define AS_MAX_PORTABILITY // Nintendo Switch - // Note, __SWITCH__ is not an official define in the Nintendo dev kit. + // Note, __SWITCH__ is not an official define in the Nintendo dev kit. // You need to manually add this to the project when compiling for Switch. #elif defined(__SWITCH__) #define AS_NINTENDOSWITCH - #if (!defined(__LP64__)) + #if ( !defined(__LP64__) ) #error write me #else #define AS_ARM64 @@ -704,8 +704,8 @@ #undef STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE #define THISCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 - #define CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 - #define STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 + #define CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 + #define STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 #endif // Marmalade is a cross platform SDK. It uses g++ to compile for iOS and Android @@ -779,7 +779,7 @@ #define AS_SIZEOF_BOOL 1 #endif - #if (defined(_ARM_) || defined(__arm__)) + #if ( defined(_ARM_) || defined(__arm__) ) // iOS use ARM processor #define AS_ARM #undef AS_NO_THISCALL_FUNCTOR_METHOD @@ -831,8 +831,8 @@ #undef STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE #define THISCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 - #define CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 - #define STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 + #define CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 + #define STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 #undef COMPLEX_MASK #define COMPLEX_MASK (asOBJ_APP_CLASS_DESTRUCTOR | asOBJ_APP_CLASS_COPY_CONSTRUCTOR | asOBJ_APP_ARRAY) @@ -896,23 +896,23 @@ #undef COMPLEX_RETURN_MASK #define COMPLEX_RETURN_MASK (asOBJ_APP_CLASS_DESTRUCTOR | asOBJ_APP_CLASS_COPY_CONSTRUCTOR | asOBJ_APP_ARRAY) - #if (defined(i386) || defined(__i386) || defined(__i386__)) && !defined(__LP64__) + #if ( defined(i386) || defined(__i386) || defined(__i386__) ) && !defined(__LP64__) // Support native calling conventions on Intel 32bit CPU #define AS_X86 #undef AS_NO_THISCALL_FUNCTOR_METHOD // As of version 4.7 MinGW changed the ABI, presumably // to be better aligned with how MSVC works - #if (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) || __GNUC__ > 4 + #if ( __GNUC__ == 4 && __GNUC_MINOR__ >= 7 ) || __GNUC__ > 4 #define AS_MINGW47 #endif - - #if (__clang_major__ == 3 && __clang_minor__ > 4) || __clang_major > 3 + + #if ( __clang_major__ == 3 && __clang_minor__ > 4 ) || __clang_major > 3 #define AS_MINGW47 #endif #ifdef AS_MINGW47 - #undef CALLEE_POPS_HIDDEN_RETURN_POINTER + #undef CALLEE_POPS_HIDDEN_RETURN_POINTER #define THISCALL_CALLEE_POPS_ARGUMENTS #else // Earlier versions than 4.7 @@ -939,7 +939,7 @@ #undef COMPLEX_RETURN_MASK #define COMPLEX_RETURN_MASK (asOBJ_APP_CLASS_DESTRUCTOR | asOBJ_APP_CLASS_COPY_CONSTRUCTOR | asOBJ_APP_ARRAY) - #if (defined(i386) || defined(__i386) || defined(__i386__)) && !defined(__LP64__) + #if ( defined(i386) || defined(__i386) || defined(__i386__) ) && !defined(__LP64__) // x86 32bit #define THISCALL_RETURN_SIMPLE_IN_MEMORY #define CDECL_RETURN_SIMPLE_IN_MEMORY @@ -961,7 +961,7 @@ #undef STDCALL #define STDCALL #elif defined(__ARMEL__) || defined(__arm__) || defined(__aarch64__) || defined(__AARCH64EL__) - // arm + // arm // The assembler code currently doesn't support arm v4 #if !defined(__ARM_ARCH_4__) && !defined(__ARM_ARCH_4T__) && !defined(__LP64__) @@ -986,14 +986,14 @@ #define STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 2 #ifndef AS_MAX_PORTABILITY - // Make a few checks against incompatible ABI combinations - #if defined(__FAST_MATH__) && __FAST_MATH__ == 1 - #error -ffast-math is not supported with native calling conventions - #endif + // Make a few checks against incompatible ABI combinations + #if defined(__FAST_MATH__) && __FAST_MATH__ == 1 + #error -ffast-math is not supported with native calling conventions + #endif #endif // Verify if soft-float or hard-float ABI is used - #if (defined(__SOFTFP__) && __SOFTFP__ == 1) || defined(__ARM_PCS) + #if ( defined(__SOFTFP__) && __SOFTFP__ == 1 ) || defined(__ARM_PCS) // -ffloat-abi=softfp or -ffloat-abi=soft #define AS_SOFTFP #endif @@ -1020,8 +1020,8 @@ #undef STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE #define THISCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 - #define CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 - #define STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 + #define CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 + #define STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 #endif #elif defined(__mips__) @@ -1036,7 +1036,7 @@ // All structures are returned in memory regardless of size or complexity #define THISCALL_RETURN_SIMPLE_IN_MEMORY - #define THISCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 0 + #define THISCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 0 #define CDECL_RETURN_SIMPLE_IN_MEMORY #define CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 0 #define STDCALL_RETURN_SIMPLE_IN_MEMORY @@ -1049,7 +1049,7 @@ #elif defined(__PPC64__) // PPC 64bit - // The code in as_callfunc_ppc_64.cpp was built for PS3 and XBox 360, that + // The code in as_callfunc_ppc_64.cpp was built for PS3 and XBox 360, that // although use 64bit PPC only uses 32bit pointers. // TODO: Add support for native calling conventions on Linux with PPC 64bit #define AS_MAX_PORTABILITY @@ -1057,7 +1057,7 @@ // 64bit MCST E2K (Elbrus 2000) CPU // ref: https://en.wikipedia.org/wiki/Elbrus_2000 #define AS_E2K - + #undef AS_NO_THISCALL_FUNCTOR_METHOD #define RETURN_VALUE_MAX_SIZE 16 @@ -1087,13 +1087,13 @@ #undef STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE #define THISCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 - #define CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 - #define STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 + #define CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 + #define STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 #else // 32-bit #define AS_MAX_PORTABILITY #endif - + // STDCALL is not available on RISC-V Linux #undef STDCALL #define STDCALL @@ -1103,7 +1103,7 @@ #define AS_LINUX #define AS_POSIX_THREADS - #if !( ( (__GNUC__ == 4) && (__GNUC_MINOR__ >= 1) || __GNUC__ > 4) ) + #if !(((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1) || __GNUC__ > 4)) // Only with GCC 4.1 was the atomic instructions available #define AS_NO_ATOMIC #endif @@ -1111,7 +1111,7 @@ // Free BSD #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) #define AS_BSD - #if (defined(i386) || defined(__i386) || defined(__i386__)) && !defined(__LP64__) + #if ( defined(i386) || defined(__i386) || defined(__i386__) ) && !defined(__LP64__) #undef COMPLEX_MASK #define COMPLEX_MASK (asOBJ_APP_CLASS_DESTRUCTOR | asOBJ_APP_CLASS_COPY_CONSTRUCTOR | asOBJ_APP_ARRAY) #undef COMPLEX_RETURN_MASK @@ -1134,7 +1134,7 @@ #define AS_MAX_PORTABILITY #endif #define AS_POSIX_THREADS - #if !( ( (__GNUC__ == 4) && (__GNUC_MINOR__ >= 1) || __GNUC__ > 4) ) + #if !(((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1) || __GNUC__ > 4)) // Only with GCC 4.1 was the atomic instructions available #define AS_NO_ATOMIC #endif @@ -1142,7 +1142,7 @@ // PSP and PS2 #elif defined(__PSP__) || defined(__psp__) || defined(_EE_) || defined(_PSP) || defined(_PS2) // Support native calling conventions on MIPS architecture - #if (defined(_MIPS_ARCH) || defined(_mips) || defined(__MIPSEL__)) && !defined(__LP64__) + #if ( defined(_MIPS_ARCH) || defined(_mips) || defined(__MIPSEL__) ) && !defined(__LP64__) #define AS_MIPS #define AS_USE_DOUBLE_AS_FLOAT #else @@ -1194,7 +1194,7 @@ #undef COMPLEX_RETURN_MASK #define COMPLEX_RETURN_MASK (asOBJ_APP_CLASS_DESTRUCTOR | asOBJ_APP_CLASS_COPY_CONSTRUCTOR | asOBJ_APP_ARRAY) - #if (defined(_ARM_) || defined(__arm__) || defined(__aarch64__) || defined(__AARCH64EL__)) + #if ( defined(_ARM_) || defined(__arm__) || defined(__aarch64__) || defined(__AARCH64EL__) ) // Android ARM #undef THISCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE @@ -1208,7 +1208,7 @@ #undef GNU_STYLE_VIRTUAL_METHOD #undef AS_NO_THISCALL_FUNCTOR_METHOD - #if (!defined(__LP64__)) + #if ( !defined(__LP64__) ) // TODO: The stack unwind on exceptions currently fails due to the assembler code in as_callfunc_arm_gcc.S #define AS_NO_EXCEPTIONS @@ -1225,8 +1225,8 @@ #define HAS_128_BIT_PRIMITIVES #define THISCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 - #define CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 - #define STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 + #define CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 + #define STDCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 5 #endif #elif (defined(i386) || defined(__i386) || defined(__i386__)) && !defined(__LP64__) // Android Intel x86 (same config as Linux x86). Tested with Intel x86 Atom System Image. @@ -1256,7 +1256,7 @@ // All structures are returned in memory regardless of size or complexity #define THISCALL_RETURN_SIMPLE_IN_MEMORY - #define THISCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 0 + #define THISCALL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 0 #define CDECL_RETURN_SIMPLE_IN_MEMORY #define CDECL_RETURN_SIMPLE_IN_MEMORY_MIN_SIZE 0 #define STDCALL_RETURN_SIMPLE_IN_MEMORY @@ -1271,7 +1271,7 @@ // Haiku OS #elif __HAIKU__ #define AS_HAIKU - #if (defined(i386) || defined(__i386) || defined(__i386__)) && !defined(__LP64__) + #if ( defined(i386) || defined(__i386) || defined(__i386__) ) && !defined(__LP64__) #define AS_X86 #define THISCALL_PASS_OBJECT_POINTER_ON_THE_STACK #define THISCALL_RETURN_SIMPLE_IN_MEMORY @@ -1295,7 +1295,7 @@ // Illumos #elif defined(__sun) - #if (defined(i386) || defined(__i386) || defined(__i386__)) && !defined(__LP64__) + #if ( defined(i386) || defined(__i386) || defined(__i386__) ) && !defined(__LP64__) #define THISCALL_RETURN_SIMPLE_IN_MEMORY #define CDECL_RETURN_SIMPLE_IN_MEMORY #define STDCALL_RETURN_SIMPLE_IN_MEMORY @@ -1316,7 +1316,7 @@ #define AS_ILLUMOS #define AS_POSIX_THREADS - #if !( ( (__GNUC__ == 4) && (__GNUC_MINOR__ >= 1) || __GNUC__ > 4) ) + #if !(((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1) || __GNUC__ > 4)) // Only with GCC 4.1 was the atomic instructions available #define AS_NO_ATOMIC #endif @@ -1342,7 +1342,7 @@ #endif // I presume Sun CC uses a similar structure of method pointers as gnuc - #define MULTI_BASE_OFFSET(x) (*((const asPWORD*)(&x)+1)) + #define MULTI_BASE_OFFSET(x) (*((const asPWORD *)(&x) + 1)) #if !defined(AS_SIZEOF_BOOL) #define AS_SIZEOF_BOOL 1 // sizeof(bool) == 1 @@ -1365,26 +1365,26 @@ // Big endian CPU target? // see: http://sourceforge.net/p/predef/wiki/Endianness/ -#if !defined(AS_BIG_ENDIAN) && \ - defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || \ - defined(__BIG_ENDIAN__) || \ - defined(__ARMEB__) || \ - defined(__THUMBEB__) || \ - defined(__AARCH64EB__) || \ - defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__) - #define AS_BIG_ENDIAN +#if !defined(AS_BIG_ENDIAN) && \ + defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || \ + defined(__BIG_ENDIAN__) || \ + defined(__ARMEB__) || \ + defined(__THUMBEB__) || \ + defined(__AARCH64EB__) || \ + defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__) + #define AS_BIG_ENDIAN #endif // Dreamcast and Gamecube use only 32bit floats, so treat doubles as floats #if defined(__SH4_SINGLE_ONLY__) || defined(_GC) - #define AS_USE_DOUBLE_AS_FLOAT // use 32bit floats instead of doubles + #define AS_USE_DOUBLE_AS_FLOAT // use 32bit floats instead of doubles #endif // If there are no current support for native calling // conventions, then compile with AS_MAX_PORTABILITY -#if (!defined(AS_X86) && !defined(AS_SH4) && !defined(AS_MIPS) && !defined(AS_PPC) && \ - !defined(AS_PPC_64) && !defined(AS_XENON) && !defined(AS_X64_GCC) && !defined(AS_X64_MSVC) && \ - !defined(AS_ARM) && !defined(AS_ARM64) && !defined(AS_X64_MINGW) && !defined(AS_RISCV64) && !defined(AS_E2K)) +#if ( !defined(AS_X86) && !defined(AS_SH4) && !defined(AS_MIPS) && !defined(AS_PPC) && \ + !defined(AS_PPC_64) && !defined(AS_XENON) && !defined(AS_X64_GCC) && !defined(AS_X64_MSVC) && \ + !defined(AS_ARM) && !defined(AS_ARM64) && !defined(AS_X64_MINGW) && !defined(AS_RISCV64) && !defined(AS_E2K) ) #ifndef AS_MAX_PORTABILITY #define AS_MAX_PORTABILITY #endif @@ -1409,13 +1409,15 @@ #if defined(AS_DEBUG) #include #include - #define asASSERT(x) \ - do { \ - if (!(x)) { \ - __android_log_print(ANDROID_LOG_ERROR, "AngelScript", "Assert failed at %s:%d - %s", __FILE__, __LINE__, #x); \ - exit(1); \ - } \ - } while (0) + #define asASSERT(x) \ + do \ + { \ + if( !(x) ) \ + { \ + __android_log_print(ANDROID_LOG_ERROR, "AngelScript", "Assert failed at %s:%d - %s", __FILE__, __LINE__, #x); \ + exit(1); \ + } \ + } while( 0 ) #else #define asASSERT(x) #endif @@ -1430,14 +1432,14 @@ // Internal defines (do not change these) //---------------------------------------------------------------- -#define ARG_W(b) ((asWORD*)&b) -#define ARG_DW(b) ((asDWORD*)&b) -#define ARG_QW(b) ((asQWORD*)&b) -#define ARG_PTR(b) ((asPWORD*)&b) -#define BCARG_W(b) ((asWORD*)&(b)[1]) -#define BCARG_DW(b) ((asDWORD*)&(b)[1]) -#define BCARG_QW(b) ((asQWORD*)&(b)[1]) -#define BCARG_PTR(b) ((asPWORD*)&(b)[1]) +#define ARG_W(b) ((asWORD *)&b) +#define ARG_DW(b) ((asDWORD *)&b) +#define ARG_QW(b) ((asQWORD *)&b) +#define ARG_PTR(b) ((asPWORD *)&b) +#define BCARG_W(b) ((asWORD *)&(b)[1]) +#define BCARG_DW(b) ((asDWORD *)&(b)[1]) +#define BCARG_QW(b) ((asQWORD *)&(b)[1]) +#define BCARG_PTR(b) ((asPWORD *)&(b)[1]) // This macro is used to avoid warnings about unused variables. // Usually where the variables are only used in debug mode. diff --git a/sdk/angelscript/source/as_configgroup.cpp b/sdk/angelscript/source/as_configgroup.cpp index eb66572b..06c438a2 100644 --- a/sdk/angelscript/source/as_configgroup.cpp +++ b/sdk/angelscript/source/as_configgroup.cpp @@ -103,40 +103,40 @@ void asCConfigGroup::AddReferencesForType(asCScriptEngine *engine, asCTypeInfo * RefConfigGroup(engine->FindConfigGroupForTypeInfo(type)); // Keep track of which generated template instances the config group uses - if ((type->flags & asOBJ_TEMPLATE) && engine->generatedTemplateTypes.Exists(CastToObjectType(type)) && !generatedTemplateInstances.Exists(CastToObjectType(type))) + if( (type->flags & asOBJ_TEMPLATE) && engine->generatedTemplateTypes.Exists(CastToObjectType(type)) && !generatedTemplateInstances.Exists(CastToObjectType(type)) ) { generatedTemplateInstances.PushLast(CastToObjectType(type)); // Enumerate through the members of the template instance and register other template instances also used. // This is needed when a template instance refers to another template instance, and thus is created at the same time. // Without adding the reference to the referred template instance, it may be deleted when the module deletes the top template instance. - asCObjectType* ot = CastToObjectType(type); - for (asUINT n = 0; n < ot->beh.constructors.GetLength(); n++) + asCObjectType *ot = CastToObjectType(type); + for( asUINT n = 0; n < ot->beh.constructors.GetLength(); n++ ) { - asCScriptFunction* f = engine->scriptFunctions[ot->beh.constructors[n]]; - if (!f) continue; + asCScriptFunction *f = engine->scriptFunctions[ot->beh.constructors[n]]; + if( !f ) continue; - for (asUINT p = 0; p < f->parameterTypes.GetLength(); p++) + for( asUINT p = 0; p < f->parameterTypes.GetLength(); p++ ) { - asCTypeInfo* ti = f->parameterTypes[p].GetTypeInfo(); - if (ti && (ti->flags & asOBJ_TEMPLATE) && engine->generatedTemplateTypes.Exists(CastToObjectType(ti)) && !generatedTemplateInstances.Exists(CastToObjectType(ti))) + asCTypeInfo *ti = f->parameterTypes[p].GetTypeInfo(); + if( ti && (ti->flags & asOBJ_TEMPLATE) && engine->generatedTemplateTypes.Exists(CastToObjectType(ti)) && !generatedTemplateInstances.Exists(CastToObjectType(ti)) ) AddReferencesForType(engine, ti); } } - for (asUINT n = 0; n < ot->methods.GetLength(); n++) + for( asUINT n = 0; n < ot->methods.GetLength(); n++ ) { - asCScriptFunction* f = engine->scriptFunctions[ot->methods[n]]; - if (!f) continue; + asCScriptFunction *f = engine->scriptFunctions[ot->methods[n]]; + if( !f ) continue; - asCTypeInfo* ti = f->returnType.GetTypeInfo(); - if (ti && (ti->flags & asOBJ_TEMPLATE) && engine->generatedTemplateTypes.Exists(CastToObjectType(ti)) && !generatedTemplateInstances.Exists(CastToObjectType(ti))) + asCTypeInfo *ti = f->returnType.GetTypeInfo(); + if( ti && (ti->flags & asOBJ_TEMPLATE) && engine->generatedTemplateTypes.Exists(CastToObjectType(ti)) && !generatedTemplateInstances.Exists(CastToObjectType(ti)) ) AddReferencesForType(engine, ti); - for (asUINT p = 0; p < f->parameterTypes.GetLength(); p++) + for( asUINT p = 0; p < f->parameterTypes.GetLength(); p++ ) { ti = f->parameterTypes[p].GetTypeInfo(); - if (ti && (ti->flags & asOBJ_TEMPLATE) && engine->generatedTemplateTypes.Exists(CastToObjectType(ti)) && !generatedTemplateInstances.Exists(CastToObjectType(ti))) + if( ti && (ti->flags & asOBJ_TEMPLATE) && engine->generatedTemplateTypes.Exists(CastToObjectType(ti)) && !generatedTemplateInstances.Exists(CastToObjectType(ti)) ) AddReferencesForType(engine, ti); } } @@ -195,10 +195,10 @@ void asCConfigGroup::RemoveConfiguration(asCScriptEngine *engine, bool notUsed) for( n = asUINT(types.GetLength()); n-- > 0; ) { asCTypeInfo *t = types[n]; - if (!t) continue; - asSMapNode *cursor; + if( !t ) continue; + asSMapNode *cursor; if( engine->allRegisteredTypes.MoveTo(&cursor, asSNameSpaceNamePair(t->nameSpace, t->name)) && - cursor->value == t ) + cursor->value == t ) { engine->allRegisteredTypes.Erase(cursor); @@ -209,9 +209,9 @@ void asCConfigGroup::RemoveConfiguration(asCScriptEngine *engine, bool notUsed) engine->registeredTypeDefs.RemoveValue(CastToTypedefType(t)); else if( t->flags & asOBJ_ENUM ) engine->registeredEnums.RemoveValue(CastToEnumType(t)); - else if (t->flags & asOBJ_TEMPLATE) + else if( t->flags & asOBJ_TEMPLATE ) engine->registeredTemplateTypes.RemoveValue(CastToObjectType(t)); - else if (t->flags & asOBJ_FUNCDEF) + else if( t->flags & asOBJ_FUNCDEF ) { engine->registeredFuncDefs.RemoveValue(CastToFuncdefType(t)); engine->RemoveFuncdef(CastToFuncdefType(t)); diff --git a/sdk/angelscript/source/as_configgroup.h b/sdk/angelscript/source/as_configgroup.h index 48720301..6db835a4 100644 --- a/sdk/angelscript/source/as_configgroup.h +++ b/sdk/angelscript/source/as_configgroup.h @@ -58,7 +58,7 @@ class asCConfigGroup int Release(); asCTypeInfo *FindType(const char *name); - void RefConfigGroup(asCConfigGroup *group); + void RefConfigGroup(asCConfigGroup *group); bool HasLiveObjects(); void RemoveConfiguration(asCScriptEngine *engine, bool notUsed = false); @@ -67,16 +67,16 @@ class asCConfigGroup void AddReferencesForType(asCScriptEngine *engine, asCTypeInfo *type); asCString groupName; - int refCount; + int refCount; - asCArray types; - asCArray scriptFunctions; - asCArray globalProps; - asCArray referencedConfigGroups; + asCArray types; + asCArray scriptFunctions; + asCArray globalProps; + asCArray referencedConfigGroups; - // This array holds the generated template instances that are used + // This array holds the generated template instances that are used // by the config group as part of function signature or property - asCArray generatedTemplateInstances; + asCArray generatedTemplateInstances; }; END_AS_NAMESPACE diff --git a/sdk/angelscript/source/as_context.cpp b/sdk/angelscript/source/as_context.cpp index 32fefecf..085d75db 100644 --- a/sdk/angelscript/source/as_context.cpp +++ b/sdk/angelscript/source/as_context.cpp @@ -49,18 +49,18 @@ #include "as_scriptobject.h" #ifdef _MSC_VER -#pragma warning(disable:4702) // unreachable code + #pragma warning(disable : 4702) // unreachable code -// Apparently a bug in MSVC (or perhaps Windows SDK) caused use HUGE_VALF to issue a warning -// ref: https://developercommunity.visualstudio.com/t/C4756-related-issues-in-VS-2022/10697767 -#pragma warning(disable:4756) + // Apparently a bug in MSVC (or perhaps Windows SDK) caused use HUGE_VALF to issue a warning + // ref: https://developercommunity.visualstudio.com/t/C4756-related-issues-in-VS-2022/10697767 + #pragma warning(disable : 4756) #endif //make compiler shut up #if __cplusplus >= 201703L -#define FALLTHROUGH [[fallthrough]]; + #define FALLTHROUGH [[fallthrough]]; #else -#define FALLTHROUGH // fall through + #define FALLTHROUGH // fall through #endif BEGIN_AS_NAMESPACE @@ -74,7 +74,7 @@ class asCDebugStats { memset(instrCount, 0, sizeof(instrCount)); memset(instrCount2, 0, sizeof(instrCount2)); - lastBC = 255; + lastBC = 255; outputDebug = false; } @@ -82,18 +82,18 @@ class asCDebugStats { // This code writes out some statistics for the VM. // It's useful for determining what needs to be optimized. - if (!outputDebug) return; + if( !outputDebug ) return; -#ifndef __MINGW32__ + #ifndef __MINGW32__ // _mkdir is broken on mingw _mkdir("AS_DEBUG"); -#endif - #if _MSC_VER >= 1500 && !defined(AS_MARMALADE) - FILE *f; - fopen_s(&f, "AS_DEBUG/stats.txt", "wt"); - #else - FILE *f = fopen("AS_DEBUG/stats.txt", "wt"); - #endif + #endif + #if _MSC_VER >= 1500 && !defined(AS_MARMALADE) + FILE *f; + fopen_s(&f, "AS_DEBUG/stats.txt", "wt"); + #else + FILE *f = fopen("AS_DEBUG/stats.txt", "wt"); + #endif if( f ) { // Output instruction statistics @@ -132,15 +132,15 @@ class asCDebugStats { ++instrCount[bc]; ++instrCount2[lastBC][bc]; - lastBC = bc; + lastBC = bc; outputDebug = writeDebug; } // Instruction statistics double instrCount[256]; double instrCount2[256][256]; - int lastBC; - bool outputDebug; + int lastBC; + bool outputDebug; } stats; #endif @@ -160,7 +160,7 @@ AS_API asIScriptContext *asGetActiveContext() if( tld == 0 || tld->activeContexts.GetLength() == 0 ) return 0; - return tld->activeContexts[tld->activeContexts.GetLength()-1]; + return tld->activeContexts[tld->activeContexts.GetLength() - 1]; } // internal @@ -179,7 +179,7 @@ void asPopActiveContext(asCThreadLocalData *tld, asIScriptContext *ctx) { UNUSED_VAR(ctx); asASSERT(tld && tld->activeContexts[tld->activeContexts.GetLength() - 1] == ctx); - if (tld) + if( tld ) tld->activeContexts.PopLast(); } @@ -245,7 +245,7 @@ bool asCContext::IsNested(asUINT *nestCount) const // and then we need to subtract one more to get the base of each frame for( asUINT n = 2; n <= c; n++ ) { - const asPWORD *s = m_callStack.AddressOf() + (c - n)*CALLSTACK_FRAME_SIZE; + const asPWORD *s = m_callStack.AddressOf() + (c - n) * CALLSTACK_FRAME_SIZE; if( s && s[0] == 0 ) { if( nestCount ) @@ -274,7 +274,7 @@ int asCContext::Release() const if( r == 0 ) { - asDELETE(const_cast(this),asCContext); + asDELETE(const_cast(this), asCContext); return 0; } @@ -287,7 +287,7 @@ void asCContext::DetachEngine() if( m_engine == 0 ) return; // Clean up all calls, included nested ones - while (IsNested()) + while( IsNested() ) { // Abort any execution Abort(); @@ -314,7 +314,7 @@ void asCContext::DetachEngine() // Clean the user data for( asUINT n = 0; n < m_userData.GetLength(); n += 2 ) { - if( m_userData[n+1] ) + if( m_userData[n + 1] ) { for( asUINT c = 0; c < m_engine->cleanContextFuncs.GetLength(); c++ ) if( m_engine->cleanContextFuncs[c].type == m_userData[n] ) @@ -349,8 +349,8 @@ void *asCContext::SetUserData(void *data, asPWORD type) { if( m_userData[n] == type ) { - void *oldData = reinterpret_cast(m_userData[n+1]); - m_userData[n+1] = reinterpret_cast(data); + void *oldData = reinterpret_cast(m_userData[n + 1]); + m_userData[n + 1] = reinterpret_cast(data); RELEASEEXCLUSIVE(m_engine->engineRWLock); @@ -378,7 +378,7 @@ void *asCContext::GetUserData(asPWORD type) const if( m_userData[n] == type ) { RELEASESHARED(m_engine->engineRWLock); - return reinterpret_cast(m_userData[n+1]); + return reinterpret_cast(m_userData[n + 1]); } } @@ -396,7 +396,7 @@ asIScriptFunction *asCContext::GetSystemFunction() // interface int asCContext::PushFunction(asIScriptFunction *func, void *object) { - asCScriptFunction *realFunc = static_cast(func); + asCScriptFunction *realFunc = static_cast(func); if( realFunc == 0 ) { @@ -428,19 +428,19 @@ int asCContext::PushFunction(asIScriptFunction *func, void *object) { m_status = asEXECUTION_UNINITIALIZED; Prepare(realFunc); - if(object) - *(asPWORD*)&m_regs.stackFramePointer[0] = (asPWORD)object; + if( object ) + *(asPWORD *)&m_regs.stackFramePointer[0] = (asPWORD)object; m_status = asEXECUTION_DESERIALIZATION; } else { - if(realFunc->funcType == asFUNC_INTERFACE || realFunc->funcType == asFUNC_VIRTUAL) + if( realFunc->funcType == asFUNC_INTERFACE || realFunc->funcType == asFUNC_VIRTUAL ) CallInterfaceMethod(realFunc); else CallScriptFunction(realFunc); - if(object) - *(asPWORD*)&m_regs.stackFramePointer[0] = (asPWORD)object; + if( object ) + *(asPWORD *)&m_regs.stackFramePointer[0] = (asPWORD)object; } asASSERT(m_currentFunction->funcType != asFUNC_DELEGATE); @@ -451,15 +451,15 @@ int asCContext::PushFunction(asIScriptFunction *func, void *object) // interface int asCContext::GetStateRegisters(asUINT stackLevel, asIScriptFunction **_callingSystemFunction, asIScriptFunction **_initialFunction, asDWORD *_originalStackPointer, asDWORD *_argumentSize, asQWORD *_valueRegister, void **_objectRegister, asITypeInfo **_objectRegisterType) { - asIScriptFunction * callingSystemFunction; - asIScriptFunction * initialFunction; - asDWORD * originalStackPointer; - int argumentsSize; - asQWORD valueRegister; - void * objectRegister; - asITypeInfo * objectType; - - if (stackLevel >= GetCallstackSize()) + asIScriptFunction *callingSystemFunction; + asIScriptFunction *initialFunction; + asDWORD *originalStackPointer; + int argumentsSize; + asQWORD valueRegister; + void *objectRegister; + asITypeInfo *objectType; + + if( stackLevel >= GetCallstackSize() ) return asINVALID_ARG; if( stackLevel == 0 ) @@ -470,40 +470,40 @@ int asCContext::GetStateRegisters(asUINT stackLevel, asIScriptFunction **_callin argumentsSize = m_argumentsSize; // Need to push the value of registers so they can be restored - valueRegister = m_regs.valueRegister; - objectRegister = m_regs.objectRegister; - objectType = m_regs.objectType; + valueRegister = m_regs.valueRegister; + objectRegister = m_regs.objectRegister; + objectType = m_regs.objectType; } else { - asPWORD const *tmp = &m_callStack[m_callStack.GetLength() - CALLSTACK_FRAME_SIZE*stackLevel]; + const asPWORD *tmp = &m_callStack[m_callStack.GetLength() - CALLSTACK_FRAME_SIZE * stackLevel]; // Only return state registers for a nested call, see PushState() if( tmp[0] != 0 ) return asNO_FUNCTION; // Restore the previous initial function and the associated values - callingSystemFunction = reinterpret_cast(tmp[1]); - initialFunction = reinterpret_cast(tmp[2]); - originalStackPointer = (asDWORD*)tmp[3]; + callingSystemFunction = reinterpret_cast(tmp[1]); + initialFunction = reinterpret_cast(tmp[2]); + originalStackPointer = (asDWORD *)tmp[3]; argumentsSize = (int)tmp[4]; valueRegister = asQWORD(asDWORD(tmp[5])); - valueRegister |= asQWORD(tmp[6])<<32; - objectRegister = (void*)tmp[7]; - objectType = (asITypeInfo*)tmp[8]; + valueRegister |= asQWORD(tmp[6]) << 32; + objectRegister = (void *)tmp[7]; + objectType = (asITypeInfo *)tmp[8]; } - if(_callingSystemFunction) *_callingSystemFunction = callingSystemFunction; - if(_initialFunction) *_initialFunction = initialFunction; + if( _callingSystemFunction ) *_callingSystemFunction = callingSystemFunction; + if( _initialFunction ) *_initialFunction = initialFunction; asDWORD sp = SerializeStackPointer(originalStackPointer); - if (_originalStackPointer) *_originalStackPointer = sp; - if(_argumentSize) *_argumentSize = argumentsSize; - if(_valueRegister) *_valueRegister = valueRegister; - if(_objectRegister) *_objectRegister = objectRegister; - if(_objectRegisterType) *_objectRegisterType = objectType; + if( _originalStackPointer ) *_originalStackPointer = sp; + if( _argumentSize ) *_argumentSize = argumentsSize; + if( _valueRegister ) *_valueRegister = valueRegister; + if( _objectRegister ) *_objectRegister = objectRegister; + if( _objectRegisterType ) *_objectRegisterType = objectType; - if (int(sp) < 0) + if( int(sp) < 0 ) return asERROR; return asSUCCESS; @@ -518,7 +518,7 @@ int asCContext::GetCallStateRegisters(asUINT stackLevel, asDWORD *_stackFramePoi asDWORD *stackPointer; int stackIndex; - if (stackLevel >= GetCallstackSize()) + if( stackLevel >= GetCallstackSize() ) return asINVALID_ARG; if( stackLevel == 0 ) @@ -531,12 +531,12 @@ int asCContext::GetCallStateRegisters(asUINT stackLevel, asDWORD *_stackFramePoi } else { - asPWORD const*s = &m_callStack[m_callStack.GetLength() - CALLSTACK_FRAME_SIZE*stackLevel]; + const asPWORD *s = &m_callStack[m_callStack.GetLength() - CALLSTACK_FRAME_SIZE * stackLevel]; - stackFramePointer = (asDWORD*)s[0]; - currentFunction = (asCScriptFunction*)s[1]; - programPointer = (asDWORD*)s[2]; - stackPointer = (asDWORD*)s[3]; + stackFramePointer = (asDWORD *)s[0]; + currentFunction = (asCScriptFunction *)s[1]; + programPointer = (asDWORD *)s[2]; + stackPointer = (asDWORD *)s[3]; stackIndex = (int)s[4]; } @@ -544,14 +544,14 @@ int asCContext::GetCallStateRegisters(asUINT stackLevel, asDWORD *_stackFramePoi return asNO_FUNCTION; // It just means that the stackLevel represent a pushed state asDWORD sfp = SerializeStackPointer(stackFramePointer); - if(_stackFramePointer) *_stackFramePointer = sfp; // TODO: Calculate stack frame pointer as delta from previous stack frame pointer (Or perhaps it will always be the same as the stack pointer in previous function?) - if(_currentFunction) *_currentFunction = currentFunction; - if(_programPointer) *_programPointer = programPointer != 0? asUINT(programPointer - currentFunction->scriptData->byteCode.AddressOf()) : -1; + if( _stackFramePointer ) *_stackFramePointer = sfp; // TODO: Calculate stack frame pointer as delta from previous stack frame pointer (Or perhaps it will always be the same as the stack pointer in previous function?) + if( _currentFunction ) *_currentFunction = currentFunction; + if( _programPointer ) *_programPointer = programPointer != 0 ? asUINT(programPointer - currentFunction->scriptData->byteCode.AddressOf()) : -1; asDWORD sp = SerializeStackPointer(stackPointer); - if(_stackPointer) *_stackPointer = sp; // TODO: Calculate the stack pointer as offset from the stack frame pointer - if(_stackIndex) *_stackIndex = stackIndex; // TODO: This shouldn't be returned, as it should be calculated during deserialization + if( _stackPointer ) *_stackPointer = sp; // TODO: Calculate the stack pointer as offset from the stack frame pointer + if( _stackIndex ) *_stackIndex = stackIndex; // TODO: This shouldn't be returned, as it should be calculated during deserialization - if (int(sfp) < 0 || int(sp) < 0) + if( int(sfp) < 0 || int(sp) < 0 ) return asERROR; return asSUCCESS; @@ -560,7 +560,7 @@ int asCContext::GetCallStateRegisters(asUINT stackLevel, asDWORD *_stackFramePoi // interface int asCContext::SetStateRegisters(asUINT stackLevel, asIScriptFunction *callingSystemFunction, asIScriptFunction *initialFunction, asDWORD originalStackPointer, asDWORD argumentsSize, asQWORD valueRegister, void *objectRegister, asITypeInfo *objectType) { - if( m_status != asEXECUTION_DESERIALIZATION) + if( m_status != asEXECUTION_DESERIALIZATION ) { asCString str; str.Format(TXT_FAILED_IN_FUNC_s_s_d, "SetStateRegisters", errorNames[-asCONTEXT_ACTIVE], asCONTEXT_ACTIVE); @@ -568,23 +568,23 @@ int asCContext::SetStateRegisters(asUINT stackLevel, asIScriptFunction *callingS return asCONTEXT_ACTIVE; } - if (stackLevel >= GetCallstackSize()) + if( stackLevel >= GetCallstackSize() ) return asINVALID_ARG; if( stackLevel == 0 ) { - m_callingSystemFunction = reinterpret_cast(callingSystemFunction); - m_initialFunction = reinterpret_cast(initialFunction); + m_callingSystemFunction = reinterpret_cast(callingSystemFunction); + m_initialFunction = reinterpret_cast(initialFunction); m_originalStackPointer = DeserializeStackPointer(originalStackPointer); m_originalStackIndex = DetermineStackIndex(m_originalStackPointer); - if (m_originalStackIndex >= m_stackBlocks.GetLength()) + if( m_originalStackIndex >= m_stackBlocks.GetLength() ) { asCString str; str.Format(TXT_FAILED_IN_FUNC_s_s_d, "SetStateRegisters", errorNames[-asCONTEXT_ACTIVE], asCONTEXT_ACTIVE); m_engine->WriteMessage("", 0, 0, asMSGTYPE_ERROR, str.AddressOf()); return asINVALID_ARG; } - m_argumentsSize = argumentsSize; // TODO: Calculate this from the initialFunction so it doesn't need to be serialized + m_argumentsSize = argumentsSize; // TODO: Calculate this from the initialFunction so it doesn't need to be serialized // Need to push the value of registers so they can be restored m_regs.valueRegister = valueRegister; @@ -593,9 +593,9 @@ int asCContext::SetStateRegisters(asUINT stackLevel, asIScriptFunction *callingS } else { - asPWORD *tmp = &m_callStack[m_callStack.GetLength() - CALLSTACK_FRAME_SIZE*stackLevel]; + asPWORD *tmp = &m_callStack[m_callStack.GetLength() - CALLSTACK_FRAME_SIZE * stackLevel]; - if(tmp[0] != 0) + if( tmp[0] != 0 ) return asERROR; // TODO: This is not really an error. It just means that the stackLevel doesn't represent a pushed state tmp[0] = 0; @@ -606,7 +606,7 @@ int asCContext::SetStateRegisters(asUINT stackLevel, asIScriptFunction *callingS // Need to push the value of registers so they can be restored tmp[5] = (asPWORD)asDWORD(valueRegister); - tmp[6] = (asPWORD)asDWORD(valueRegister>>32); + tmp[6] = (asPWORD)asDWORD(valueRegister >> 32); tmp[7] = (asPWORD)objectRegister; tmp[8] = (asPWORD)objectType; } @@ -617,7 +617,7 @@ int asCContext::SetStateRegisters(asUINT stackLevel, asIScriptFunction *callingS // interface int asCContext::SetCallStateRegisters(asUINT stackLevel, asDWORD stackFramePointer, asIScriptFunction *_currentFunction, asDWORD _programPointer, asDWORD stackPointer, asDWORD stackIndex) { - if( m_status != asEXECUTION_DESERIALIZATION) + if( m_status != asEXECUTION_DESERIALIZATION ) { asCString str; str.Format(TXT_FAILED_IN_FUNC_s_s_d, "SetCallStateRegisters", errorNames[-asCONTEXT_ACTIVE], asCONTEXT_ACTIVE); @@ -625,11 +625,11 @@ int asCContext::SetCallStateRegisters(asUINT stackLevel, asDWORD stackFramePoint return asCONTEXT_ACTIVE; } - if (stackLevel >= GetCallstackSize()) + if( stackLevel >= GetCallstackSize() ) return asINVALID_ARG; // TODO: The arg _currentFunction is just used in debug mode to validate that it is the same that is already given in m_currentFunction or on the call stack. Do we really need to take this argument? - asCScriptFunction *currentFunction = static_cast(_currentFunction); + asCScriptFunction *currentFunction = static_cast(_currentFunction); if( currentFunction->funcType == asFUNC_DELEGATE ) { @@ -642,7 +642,7 @@ int asCContext::SetCallStateRegisters(asUINT stackLevel, asDWORD stackFramePoint currentFunction = m_currentFunction; asDWORD *programPointer = currentFunction->scriptData->byteCode.AddressOf(); - if(currentFunction->scriptData->byteCode.GetLength() > _programPointer) + if( currentFunction->scriptData->byteCode.GetLength() > _programPointer ) { programPointer += _programPointer; } @@ -654,19 +654,19 @@ int asCContext::SetCallStateRegisters(asUINT stackLevel, asDWORD stackFramePoint } else { - asPWORD *tmp = &m_callStack[m_callStack.GetLength() - CALLSTACK_FRAME_SIZE*stackLevel]; + asPWORD *tmp = &m_callStack[m_callStack.GetLength() - CALLSTACK_FRAME_SIZE * stackLevel]; asASSERT(currentFunction->signatureId == ((asCScriptFunction*)tmp[1])->signatureId); - currentFunction = ((asCScriptFunction*)tmp[1]); + currentFunction = ((asCScriptFunction *)tmp[1]); asDWORD *programPointer = currentFunction->scriptData->byteCode.AddressOf(); - if(currentFunction->scriptData->byteCode.GetLength() > _programPointer) + if( currentFunction->scriptData->byteCode.GetLength() > _programPointer ) { programPointer += _programPointer; } tmp[0] = (asPWORD)DeserializeStackPointer(stackFramePointer); - // tmp[1] = (asPWORD)(currentFunction); + // tmp[1] = (asPWORD)(currentFunction); tmp[2] = (asPWORD)programPointer; tmp[3] = (asPWORD)DeserializeStackPointer(stackPointer); tmp[4] = (asPWORD)stackIndex; @@ -676,13 +676,13 @@ int asCContext::SetCallStateRegisters(asUINT stackLevel, asDWORD stackFramePoint } // internal -int asCContext::DetermineStackIndex(asDWORD* ptr) const +int asCContext::DetermineStackIndex(asDWORD *ptr) const { - for (asUINT n = 0; n < m_stackBlocks.GetLength(); n++) + for( asUINT n = 0; n < m_stackBlocks.GetLength(); n++ ) { - asUINT blockSize = m_engine->ep.initContextStackSize << n; - asINT64 delta = ptr - m_stackBlocks[n]; - if (delta <= blockSize && delta > 0) + asUINT blockSize = m_engine->ep.initContextStackSize << n; + asINT64 delta = ptr - m_stackBlocks[n]; + if( delta <= blockSize && delta > 0 ) return n; } @@ -716,21 +716,21 @@ int asCContext::Prepare(asIScriptFunction *func) CleanReturnObject(); // Check if there has been a previous function prepared - if (m_initialFunction) + if( m_initialFunction ) { // Release the previous object, if it is a script object - if (m_initialFunction && m_initialFunction->objectType && (m_initialFunction->objectType->flags & asOBJ_SCRIPT_OBJECT)) + if( m_initialFunction && m_initialFunction->objectType && (m_initialFunction->objectType->flags & asOBJ_SCRIPT_OBJECT) ) { - asCScriptObject* obj = *(asCScriptObject**)&m_regs.stackFramePointer[0]; - if (obj) + asCScriptObject *obj = *(asCScriptObject **)&m_regs.stackFramePointer[0]; + if( obj ) obj->Release(); - *(asPWORD*)&m_regs.stackFramePointer[0] = 0; + *(asPWORD *)&m_regs.stackFramePointer[0] = 0; } // Reset stack pointer m_regs.stackPointer = m_originalStackPointer; - m_stackIndex = m_originalStackIndex; + m_stackIndex = m_originalStackIndex; asASSERT(int(m_stackIndex) == DetermineStackIndex(m_regs.stackPointer)); } @@ -765,8 +765,8 @@ int asCContext::Prepare(asIScriptFunction *func) // Reserve space for the arguments and return value if( m_currentFunction->DoesReturnOnStack() ) { - m_returnValueSize = m_currentFunction->returnType.GetSizeInMemoryDWords(); - m_argumentsSize += AS_PTR_SIZE; + m_returnValueSize = m_currentFunction->returnType.GetSizeInMemoryDWords(); + m_argumentsSize += AS_PTR_SIZE; } else m_returnValueSize = 0; @@ -781,7 +781,7 @@ int asCContext::Prepare(asIScriptFunction *func) return asOUT_OF_MEMORY; // Set up the call stack too - if (m_callStack.GetCapacity() < m_engine->ep.initCallStackSize) + if( m_callStack.GetCapacity() < m_engine->ep.initCallStackSize ) m_callStack.AllocateNoConstruct(m_engine->ep.initCallStackSize * CALLSTACK_FRAME_SIZE, true); } @@ -790,12 +790,12 @@ int asCContext::Prepare(asIScriptFunction *func) ClearException(); if( m_status != asEXECUTION_FINISHED ) { - m_doAbort = false; - m_doSuspend = false; - m_regs.doProcessSuspend = m_lineCallback; - m_externalSuspendRequest = false; + m_doAbort = false; + m_doSuspend = false; + m_regs.doProcessSuspend = m_lineCallback; + m_externalSuspendRequest = false; } - m_status = asEXECUTION_PREPARED; + m_status = asEXECUTION_PREPARED; m_regs.programPointer = 0; // Reserve space for the arguments and return value @@ -805,7 +805,7 @@ int asCContext::Prepare(asIScriptFunction *func) m_regs.stackPointer = m_regs.stackFramePointer; // Set arguments to 0 - memset(m_regs.stackPointer, 0, 4*m_argumentsSize); + memset(m_regs.stackPointer, 0, 4 * m_argumentsSize); if( m_returnValueSize ) { @@ -814,7 +814,7 @@ int asCContext::Prepare(asIScriptFunction *func) if( m_currentFunction->objectType ) ptr += AS_PTR_SIZE; - *(void**)ptr = (void*)(m_regs.stackFramePointer + m_argumentsSize); + *(void **)ptr = (void *)(m_regs.stackFramePointer + m_argumentsSize); } return asSUCCESS; @@ -823,10 +823,10 @@ int asCContext::Prepare(asIScriptFunction *func) // internal void asCContext::ClearException() { - m_exceptionString = ""; - m_exceptionFunction = 0; - m_exceptionLine = -1; - m_exceptionColumn = -1; + m_exceptionString = ""; + m_exceptionFunction = 0; + m_exceptionLine = -1; + m_exceptionColumn = -1; m_exceptionSectionIdx = 0; } @@ -837,13 +837,13 @@ int asCContext::Unprepare() return asCONTEXT_ACTIVE; // Set the context as active so that any clean up code can use access it if desired - asCThreadLocalData *tld = asPushActiveContext((asIScriptContext *)this); - asDWORD count = m_refCount.get(); + asCThreadLocalData *tld = asPushActiveContext((asIScriptContext *)this); + asDWORD count = m_refCount.get(); UNUSED_VAR(count); // Only clean the stack if the context was prepared but not executed until the end if( m_status != asEXECUTION_UNINITIALIZED && - m_status != asEXECUTION_FINISHED ) + m_status != asEXECUTION_FINISHED ) CleanStack(); asASSERT( m_needToCleanupArgs == false ); @@ -859,7 +859,7 @@ int asCContext::Unprepare() // Release the object if it is a script object if( m_initialFunction && m_initialFunction->objectType && (m_initialFunction->objectType->flags & asOBJ_SCRIPT_OBJECT) ) { - asCScriptObject *obj = *(asCScriptObject**)&m_regs.stackFramePointer[0]; + asCScriptObject *obj = *(asCScriptObject **)&m_regs.stackFramePointer[0]; if( obj ) obj->Release(); } @@ -871,13 +871,13 @@ int asCContext::Unprepare() // Reset stack pointer m_regs.stackPointer = m_originalStackPointer; - m_stackIndex = m_originalStackIndex; + m_stackIndex = m_originalStackIndex; } // Clear function pointers ClearException(); - m_initialFunction = 0; - m_currentFunction = 0; + m_initialFunction = 0; + m_currentFunction = 0; m_regs.programPointer = 0; // Reset status @@ -896,7 +896,7 @@ asBYTE asCContext::GetReturnByte() if( dt->IsObject() || dt->IsFuncdef() || dt->IsReference() ) return 0; - return *(asBYTE*)&m_regs.valueRegister; + return *(asBYTE *)&m_regs.valueRegister; } asWORD asCContext::GetReturnWord() @@ -907,7 +907,7 @@ asWORD asCContext::GetReturnWord() if( dt->IsObject() || dt->IsFuncdef() || dt->IsReference() ) return 0; - return *(asWORD*)&m_regs.valueRegister; + return *(asWORD *)&m_regs.valueRegister; } asDWORD asCContext::GetReturnDWord() @@ -918,7 +918,7 @@ asDWORD asCContext::GetReturnDWord() if( dt->IsObject() || dt->IsFuncdef() || dt->IsReference() ) return 0; - return *(asDWORD*)&m_regs.valueRegister; + return *(asDWORD *)&m_regs.valueRegister; } asQWORD asCContext::GetReturnQWord() @@ -940,7 +940,7 @@ float asCContext::GetReturnFloat() if( dt->IsObject() || dt->IsFuncdef() || dt->IsReference() ) return 0; - return *(float*)&m_regs.valueRegister; + return *(float *)&m_regs.valueRegister; } double asCContext::GetReturnDouble() @@ -951,7 +951,7 @@ double asCContext::GetReturnDouble() if( dt->IsObject() || dt->IsFuncdef() || dt->IsReference() ) return 0; - return *(double*)&m_regs.valueRegister; + return *(double *)&m_regs.valueRegister; } void *asCContext::GetReturnAddress() @@ -961,7 +961,7 @@ void *asCContext::GetReturnAddress() asCDataType *dt = &m_initialFunction->returnType; if( dt->IsReference() ) - return *(void**)&m_regs.valueRegister; + return *(void **)&m_regs.valueRegister; else if( dt->IsObject() || dt->IsFuncdef() ) { if( m_initialFunction->DoesReturnOnStack() ) @@ -971,7 +971,7 @@ void *asCContext::GetReturnAddress() if( m_initialFunction->objectType ) offset += AS_PTR_SIZE; - return *(void**)(&m_regs.stackFramePointer[offset]); + return *(void **)(&m_regs.stackFramePointer[offset]); } return m_regs.objectRegister; @@ -989,7 +989,7 @@ void *asCContext::GetReturnObject() if( !dt->IsObject() && !dt->IsFuncdef() ) return 0; if( dt->IsReference() ) - return *(void**)(asPWORD)m_regs.valueRegister; + return *(void **)(asPWORD)m_regs.valueRegister; else { if( m_initialFunction->DoesReturnOnStack() ) @@ -999,7 +999,7 @@ void *asCContext::GetReturnObject() if( m_initialFunction->objectType ) offset += AS_PTR_SIZE; - return *(void**)(&m_regs.stackFramePointer[offset]); + return *(void **)(&m_regs.stackFramePointer[offset]); } return m_regs.objectRegister; @@ -1025,10 +1025,10 @@ void *asCContext::GetAddressOfReturnValue() if( m_initialFunction->objectType ) offset += AS_PTR_SIZE; - return *(void**)(&m_regs.stackFramePointer[offset]); + return *(void **)(&m_regs.stackFramePointer[offset]); } - return *(void**)&m_regs.objectRegister; + return *(void **)&m_regs.objectRegister; } return &m_regs.objectRegister; } @@ -1050,12 +1050,12 @@ int asCContext::SetObject(void *obj) asASSERT( *(asPWORD*)&m_regs.stackFramePointer[0] == 0 ); - *(asPWORD*)&m_regs.stackFramePointer[0] = (asPWORD)obj; + *(asPWORD *)&m_regs.stackFramePointer[0] = (asPWORD)obj; // TODO: This should be optional by having a flag where the application can chose whether it should be done or not // The flag could be named something like takeOwnership and have default value of true if( obj && (m_initialFunction->objectType->flags & asOBJ_SCRIPT_OBJECT) ) - reinterpret_cast(obj)->AddRef(); + reinterpret_cast(obj)->AddRef(); return 0; } @@ -1098,7 +1098,7 @@ int asCContext::SetArgByte(asUINT arg, asBYTE value) offset += m_initialFunction->parameterTypes[n].GetSizeOnStackDWords(); // Set the value - *(asBYTE*)&m_regs.stackFramePointer[offset] = value; + *(asBYTE *)&m_regs.stackFramePointer[offset] = value; return 0; } @@ -1141,7 +1141,7 @@ int asCContext::SetArgWord(asUINT arg, asWORD value) offset += m_initialFunction->parameterTypes[n].GetSizeOnStackDWords(); // Set the value - *(asWORD*)&m_regs.stackFramePointer[offset] = value; + *(asWORD *)&m_regs.stackFramePointer[offset] = value; return 0; } @@ -1184,7 +1184,7 @@ int asCContext::SetArgDWord(asUINT arg, asDWORD value) offset += m_initialFunction->parameterTypes[n].GetSizeOnStackDWords(); // Set the value - *(asDWORD*)&m_regs.stackFramePointer[offset] = value; + *(asDWORD *)&m_regs.stackFramePointer[offset] = value; return 0; } @@ -1227,7 +1227,7 @@ int asCContext::SetArgQWord(asUINT arg, asQWORD value) offset += m_initialFunction->parameterTypes[n].GetSizeOnStackDWords(); // Set the value - *(asQWORD*)(&m_regs.stackFramePointer[offset]) = value; + *(asQWORD *)(&m_regs.stackFramePointer[offset]) = value; return 0; } @@ -1270,7 +1270,7 @@ int asCContext::SetArgFloat(asUINT arg, float value) offset += m_initialFunction->parameterTypes[n].GetSizeOnStackDWords(); // Set the value - *(float*)(&m_regs.stackFramePointer[offset]) = value; + *(float *)(&m_regs.stackFramePointer[offset]) = value; return 0; } @@ -1313,7 +1313,7 @@ int asCContext::SetArgDouble(asUINT arg, double value) offset += m_initialFunction->parameterTypes[n].GetSizeOnStackDWords(); // Set the value - *(double*)(&m_regs.stackFramePointer[offset]) = value; + *(double *)(&m_regs.stackFramePointer[offset]) = value; return 0; } @@ -1350,7 +1350,7 @@ int asCContext::SetArgAddress(asUINT arg, void *value) offset += m_initialFunction->parameterTypes[n].GetSizeOnStackDWords(); // Set the value - *(asPWORD*)(&m_regs.stackFramePointer[offset]) = (asPWORD)value; + *(asPWORD *)(&m_regs.stackFramePointer[offset]) = (asPWORD)value; return 0; } @@ -1380,12 +1380,12 @@ int asCContext::SetArgObject(asUINT arg, void *obj) if( dt->IsObjectHandle() ) { // Increase the reference counter - if (obj && dt->IsFuncdef()) - ((asIScriptFunction*)obj)->AddRef(); + if( obj && dt->IsFuncdef() ) + ((asIScriptFunction *)obj)->AddRef(); else { asSTypeBehaviour *beh = &CastToObjectType(dt->GetTypeInfo())->beh; - if (obj && beh->addref) + if( obj && beh->addref ) m_engine->CallObjectMethod(obj, beh->addref); } } @@ -1408,7 +1408,7 @@ int asCContext::SetArgObject(asUINT arg, void *obj) offset += m_initialFunction->parameterTypes[n].GetSizeOnStackDWords(); // Set the value - *(asPWORD*)(&m_regs.stackFramePointer[offset]) = (asPWORD)obj; + *(asPWORD *)(&m_regs.stackFramePointer[offset]) = (asPWORD)obj; return 0; } @@ -1445,9 +1445,9 @@ int asCContext::SetArgVarType(asUINT arg, void *ptr, int typeId) offset += m_initialFunction->parameterTypes[n].GetSizeOnStackDWords(); // Set the typeId and pointer - *(asPWORD*)(&m_regs.stackFramePointer[offset]) = (asPWORD)ptr; - offset += AS_PTR_SIZE; - *(int*)(&m_regs.stackFramePointer[offset]) = typeId; + *(asPWORD *)(&m_regs.stackFramePointer[offset]) = (asPWORD)ptr; + offset += AS_PTR_SIZE; + *(int *)(&m_regs.stackFramePointer[offset]) = typeId; return 0; } @@ -1492,10 +1492,10 @@ int asCContext::Abort() if( m_status == asEXECUTION_SUSPENDED ) m_status = asEXECUTION_ABORTED; - m_doSuspend = true; - m_regs.doProcessSuspend = true; + m_doSuspend = true; + m_regs.doProcessSuspend = true; m_externalSuspendRequest = true; - m_doAbort = true; + m_doAbort = true; return 0; } @@ -1509,9 +1509,9 @@ int asCContext::Suspend() if( m_engine == 0 ) return asERROR; - m_doSuspend = true; + m_doSuspend = true; m_externalSuspendRequest = true; - m_regs.doProcessSuspend = true; + m_regs.doProcessSuspend = true; return 0; } @@ -1535,7 +1535,7 @@ int asCContext::Execute() // Make sure there are not too many nested calls, as it could crash the application // by filling up the thread call stack - if (tld->activeContexts.GetLength() > m_engine->ep.maxNestedCalls) + if( tld->activeContexts.GetLength() > m_engine->ep.maxNestedCalls ) SetInternalException(TXT_TOO_MANY_NESTED_CALLS); else if( m_regs.programPointer == 0 ) SetProgramPointer(); @@ -1544,13 +1544,13 @@ int asCContext::Execute() if( m_engine->ep.autoGarbageCollect ) m_engine->gc.GetStatistics(&gcPreObjects, 0, 0, 0, 0); - while (m_status == asEXECUTION_ACTIVE) + while( m_status == asEXECUTION_ACTIVE ) { ExecuteNext(); // If an exception was raised that will be caught, then unwind the stack // and move the program pointer to the catch block before proceeding - if (m_status == asEXECUTION_EXCEPTION && m_exceptionWillBeCaught) + if( m_status == asEXECUTION_EXCEPTION && m_exceptionWillBeCaught ) CleanStack(true); } @@ -1609,15 +1609,15 @@ int asCContext::Execute() } // internal -asCScriptFunction *asCContext::GetRealFunc(asCScriptFunction * currentFunction, void ** _This) +asCScriptFunction *asCContext::GetRealFunc(asCScriptFunction *currentFunction, void **_This) { if( currentFunction->funcType == asFUNC_VIRTUAL || - currentFunction->funcType == asFUNC_INTERFACE ) + currentFunction->funcType == asFUNC_INTERFACE ) { // The currentFunction is a virtual method // Determine the true function from the object - asCScriptObject *obj = *(asCScriptObject**)_This; + asCScriptObject *obj = *(asCScriptObject **)_This; if( obj == 0 ) { @@ -1625,8 +1625,8 @@ asCScriptFunction *asCContext::GetRealFunc(asCScriptFunction * currentFunction, } else { - asCObjectType *objType = obj->objType; - asCScriptFunction * realFunc = 0; + asCObjectType *objType = obj->objType; + asCScriptFunction *realFunc = 0; if( currentFunction->funcType == asFUNC_VIRTUAL ) { @@ -1685,15 +1685,15 @@ void asCContext::SetProgramPointer() { // Push the object pointer onto the stack asASSERT( m_regs.stackPointer - AS_PTR_SIZE >= m_stackBlocks[m_stackIndex] ); - m_regs.stackPointer -= AS_PTR_SIZE; - m_regs.stackFramePointer -= AS_PTR_SIZE; - *(asPWORD*)m_regs.stackPointer = asPWORD(m_currentFunction->objForDelegate); + m_regs.stackPointer -= AS_PTR_SIZE; + m_regs.stackFramePointer -= AS_PTR_SIZE; + *(asPWORD *)m_regs.stackPointer = asPWORD(m_currentFunction->objForDelegate); // Make the call to the delegated object method m_currentFunction = m_currentFunction->funcForDelegate; } - m_currentFunction = GetRealFunc(m_currentFunction, (void**)m_regs.stackFramePointer); + m_currentFunction = GetRealFunc(m_currentFunction, (void **)m_regs.stackFramePointer); if( m_currentFunction->funcType == asFUNC_SCRIPT ) { @@ -1736,9 +1736,9 @@ int asCContext::PushState() } // Allocate space on the callstack for at least two states - if (m_callStack.GetLength() >= m_callStack.GetCapacity() - 2*CALLSTACK_FRAME_SIZE) + if( m_callStack.GetLength() >= m_callStack.GetCapacity() - 2 * CALLSTACK_FRAME_SIZE ) { - if (m_engine->ep.maxCallStackSize > 0 && m_callStack.GetLength() >= m_engine->ep.maxCallStackSize*CALLSTACK_FRAME_SIZE) + if( m_engine->ep.maxCallStackSize > 0 && m_callStack.GetLength() >= m_engine->ep.maxCallStackSize * CALLSTACK_FRAME_SIZE ) { // The call stack is too big to grow further // If an error occurs, no change to the context should be done @@ -1759,15 +1759,15 @@ int asCContext::PushState() // Need to push m_initialFunction as it must be restored later asPWORD *tmp = m_callStack.AddressOf() + m_callStack.GetLength() - CALLSTACK_FRAME_SIZE; - tmp[0] = 0; - tmp[1] = (asPWORD)m_callingSystemFunction; - tmp[2] = (asPWORD)m_initialFunction; - tmp[3] = (asPWORD)m_originalStackPointer; - tmp[4] = (asPWORD)m_argumentsSize; + tmp[0] = 0; + tmp[1] = (asPWORD)m_callingSystemFunction; + tmp[2] = (asPWORD)m_initialFunction; + tmp[3] = (asPWORD)m_originalStackPointer; + tmp[4] = (asPWORD)m_argumentsSize; // Need to push the value of registers so they can be restored tmp[5] = (asPWORD)asDWORD(m_regs.valueRegister); - tmp[6] = (asPWORD)asDWORD(m_regs.valueRegister>>32); + tmp[6] = (asPWORD)asDWORD(m_regs.valueRegister >> 32); tmp[7] = (asPWORD)m_regs.objectRegister; tmp[8] = (asPWORD)m_regs.objectType; @@ -1781,7 +1781,7 @@ int asCContext::PushState() m_callingSystemFunction = 0; m_regs.objectRegister = 0; - m_regs.objectType = 0; + m_regs.objectType = 0; // Set the status to uninitialized as application // should call Prepare() after this to reuse the context @@ -1804,23 +1804,23 @@ int asCContext::PopState() asASSERT( m_callStack[m_callStack.GetLength() - CALLSTACK_FRAME_SIZE] == 0 ); // Restore the previous state - asPWORD *tmp = &m_callStack[m_callStack.GetLength() - CALLSTACK_FRAME_SIZE]; - m_callingSystemFunction = reinterpret_cast(tmp[1]); + asPWORD *tmp = &m_callStack[m_callStack.GetLength() - CALLSTACK_FRAME_SIZE]; + m_callingSystemFunction = reinterpret_cast(tmp[1]); m_callStack.SetLength(m_callStack.GetLength() - CALLSTACK_FRAME_SIZE); // Restore the previous initial function and the associated values - m_initialFunction = reinterpret_cast(tmp[2]); - m_originalStackPointer = (asDWORD*)tmp[3]; + m_initialFunction = reinterpret_cast(tmp[2]); + m_originalStackPointer = (asDWORD *)tmp[3]; m_originalStackIndex = DetermineStackIndex(m_originalStackPointer); m_argumentsSize = (int)tmp[4]; m_regs.valueRegister = asQWORD(asDWORD(tmp[5])); - m_regs.valueRegister |= asQWORD(tmp[6])<<32; - m_regs.objectRegister = (void*)tmp[7]; - m_regs.objectType = (asITypeInfo*)tmp[8]; + m_regs.valueRegister |= asQWORD(tmp[6]) << 32; + m_regs.objectRegister = (void *)tmp[7]; + m_regs.objectType = (asITypeInfo *)tmp[8]; // Calculate the returnValueSize - if(m_initialFunction && m_initialFunction->DoesReturnOnStack() ) + if( m_initialFunction && m_initialFunction->DoesReturnOnStack() ) m_returnValueSize = m_initialFunction->returnType.GetSizeInMemoryDWords(); else m_returnValueSize = 0; @@ -1839,28 +1839,28 @@ int asCContext::PushCallState() // PushCallState is called whenever we already have m_callStack n*CALLSTACK_FRAME_SIZE memory // We only need to increment it if it is full (old_length >= m_callStack.maxLength) // Here we assume that AllocateNoConstruct will always execute and allocate us extra memory, - // so we can use the faster m_callStack.SetLengthNoAllocate since it is already known the capacity + // so we can use the faster m_callStack.SetLengthNoAllocate since it is already known the capacity // is enough. asUINT oldLength = m_callStack.GetLength(); - if (oldLength >= m_callStack.GetCapacity()) - { - if (m_engine->ep.maxCallStackSize > 0 && oldLength >= m_engine->ep.maxCallStackSize * CALLSTACK_FRAME_SIZE) - { + if( oldLength >= m_callStack.GetCapacity() ) + { + if( m_engine->ep.maxCallStackSize > 0 && oldLength >= m_engine->ep.maxCallStackSize * CALLSTACK_FRAME_SIZE ) + { // The call stack is too big to grow further - SetInternalException(TXT_STACK_OVERFLOW); - return asERROR; - } - m_callStack.AllocateNoConstruct(oldLength + 10 * CALLSTACK_FRAME_SIZE, true); - } + SetInternalException(TXT_STACK_OVERFLOW); + return asERROR; + } + m_callStack.AllocateNoConstruct(oldLength + 10 * CALLSTACK_FRAME_SIZE, true); + } m_callStack.SetLengthNoAllocate(oldLength + CALLSTACK_FRAME_SIZE); - // Separating the loads and stores limits data cache trash, and with a smart compiler - // could turn into SIMD style loading/storing if available. - // The compiler can't do this itself due to potential pointer aliasing between the pointers, - // ie writing to tmp could overwrite the data contained in registers.stackFramePointer for example - // for all the compiler knows. So introducing the local variable s, which is never referred to by - // its address we avoid this issue. + // Separating the loads and stores limits data cache trash, and with a smart compiler + // could turn into SIMD style loading/storing if available. + // The compiler can't do this itself due to potential pointer aliasing between the pointers, + // ie writing to tmp could overwrite the data contained in registers.stackFramePointer for example + // for all the compiler knows. So introducing the local variable s, which is never referred to by + // its address we avoid this issue. asPWORD s[5]; s[0] = (asPWORD)m_regs.stackFramePointer; @@ -1870,11 +1870,11 @@ int asCContext::PushCallState() s[4] = m_stackIndex; asPWORD *tmp = m_callStack.AddressOf() + oldLength; - tmp[0] = s[0]; - tmp[1] = s[1]; - tmp[2] = s[2]; - tmp[3] = s[3]; - tmp[4] = s[4]; + tmp[0] = s[0]; + tmp[1] = s[1]; + tmp[2] = s[2]; + tmp[3] = s[3]; + tmp[4] = s[4]; return asSUCCESS; } @@ -1886,27 +1886,27 @@ void asCContext::PopCallState() asUINT newLength = m_callStack.GetLength() - CALLSTACK_FRAME_SIZE; asPWORD *tmp = m_callStack.array + newLength; - asPWORD s[5]; + asPWORD s[5]; s[0] = tmp[0]; s[1] = tmp[1]; s[2] = tmp[2]; s[3] = tmp[3]; s[4] = tmp[4]; - m_regs.stackFramePointer = (asDWORD*)s[0]; - m_currentFunction = (asCScriptFunction*)s[1]; - m_regs.programPointer = (asDWORD*)s[2]; - m_regs.stackPointer = (asDWORD*)s[3]; + m_regs.stackFramePointer = (asDWORD *)s[0]; + m_currentFunction = (asCScriptFunction *)s[1]; + m_regs.programPointer = (asDWORD *)s[2]; + m_regs.stackPointer = (asDWORD *)s[3]; m_stackIndex = (int)s[4]; // Here we reduce the length, so we can use the faster SetLengtNoAllocate. - m_callStack.SetLengthNoAllocate(newLength); + m_callStack.SetLengthNoAllocate(newLength); } // interface asUINT asCContext::GetCallstackSize() const { - if (m_currentFunction == 0 && m_callStack.GetLength() <= CALLSTACK_FRAME_SIZE) return 0; + if( m_currentFunction == 0 && m_callStack.GetLength() <= CALLSTACK_FRAME_SIZE ) return 0; // The current function is accessed at stackLevel 0 return asUINT(1 + m_callStack.GetLength() / CALLSTACK_FRAME_SIZE); @@ -1919,8 +1919,8 @@ asIScriptFunction *asCContext::GetFunction(asUINT stackLevel) if( stackLevel == 0 ) return m_currentFunction; - asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize() - stackLevel - 1)*CALLSTACK_FRAME_SIZE; - asCScriptFunction *func = (asCScriptFunction*)s[1]; + asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize() - stackLevel - 1) * CALLSTACK_FRAME_SIZE; + asCScriptFunction *func = (asCScriptFunction *)s[1]; return func; } @@ -1931,7 +1931,7 @@ int asCContext::GetLineNumber(asUINT stackLevel, int *column, const char **secti if( stackLevel >= GetCallstackSize() ) return asINVALID_ARG; asCScriptFunction *func; - asDWORD *bytePos; + asDWORD *bytePos; if( stackLevel == 0 ) { func = m_currentFunction; @@ -1940,10 +1940,10 @@ int asCContext::GetLineNumber(asUINT stackLevel, int *column, const char **secti } else { - asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize()-stackLevel-1)*CALLSTACK_FRAME_SIZE; - func = (asCScriptFunction*)s[1]; + asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize() - stackLevel - 1) * CALLSTACK_FRAME_SIZE; + func = (asCScriptFunction *)s[1]; if( func->scriptData == 0 ) return 0; - bytePos = (asDWORD*)s[2]; + bytePos = (asDWORD *)s[2]; // Subract 1 from the bytePos, because we want the line where // the call was made, and not the instruction after the call @@ -1958,15 +1958,15 @@ int asCContext::GetLineNumber(asUINT stackLevel, int *column, const char **secti return 0; } - if (bytePos == 0) + if( bytePos == 0 ) { - // If the context has been Prepared but Execute hasn't been called yet the - // programPointer will be zero. In this case simply use the address of the + // If the context has been Prepared but Execute hasn't been called yet the + // programPointer will be zero. In this case simply use the address of the // bytecode as starting point bytePos = func->scriptData->byteCode.AddressOf(); } - int sectionIdx; + int sectionIdx; asDWORD line = func->GetLineNumber(int(bytePos - func->scriptData->byteCode.AddressOf()), §ionIdx); if( column ) *column = (line >> 20); if( sectionName ) @@ -1986,7 +1986,7 @@ bool asCContext::ReserveStackSpace(asUINT size) #ifdef WIP_16BYTE_ALIGN // Pad size to a multiple of MAX_TYPE_ALIGNMENT. const asUINT remainder = size % MAX_TYPE_ALIGNMENT; - if(remainder != 0) + if( remainder != 0 ) { size = size + (MAX_TYPE_ALIGNMENT - (size % MAX_TYPE_ALIGNMENT)); } @@ -1999,7 +1999,7 @@ bool asCContext::ReserveStackSpace(asUINT size) asASSERT( m_stackBlockSize > 0 ); #ifndef WIP_16BYTE_ALIGN - asDWORD *stack = asNEWARRAY(asDWORD,m_stackBlockSize); + asDWORD *stack = asNEWARRAY(asDWORD, m_stackBlockSize); #else asDWORD *stack = asNEWARRAYALIGNED(asDWORD, m_stackBlockSize, MAX_TYPE_ALIGNMENT); #endif @@ -2014,12 +2014,12 @@ bool asCContext::ReserveStackSpace(asUINT size) #endif m_stackBlocks.PushLast(stack); - m_stackIndex = 0; + m_stackIndex = 0; m_regs.stackPointer = m_stackBlocks[0] + m_stackBlockSize; #ifdef WIP_16BYTE_ALIGN // Align the stack pointer. This is necessary as the m_stackBlockSize is not necessarily evenly divisable with the max alignment - ((asPWORD&)m_regs.stackPointer) &= ~(MAX_TYPE_ALIGNMENT-1); + ((asPWORD &)m_regs.stackPointer) &= ~(MAX_TYPE_ALIGNMENT - 1); asASSERT( isAligned(m_regs.stackPointer, MAX_TYPE_ALIGNMENT) ); #endif @@ -2033,7 +2033,7 @@ bool asCContext::ReserveStackSpace(asUINT size) if( m_engine->ep.maximumContextStackSize ) { // This test will only stop growth once it is on or already crossed the limit - if( m_stackBlockSize * ((1 << (m_stackIndex+1)) - 1) >= m_engine->ep.maximumContextStackSize ) + if( m_stackBlockSize * ((1 << (m_stackIndex + 1)) - 1) >= m_engine->ep.maximumContextStackSize ) { m_isStackMemoryNotAllocated = true; @@ -2076,14 +2076,14 @@ bool asCContext::ReserveStackSpace(asUINT size) // Update the stack pointer to point to the new block. // Leave enough room above the stackpointer to copy the arguments from the previous stackblock m_regs.stackPointer = m_stackBlocks[m_stackIndex] + - (m_stackBlockSize<GetSpaceNeededForArguments() - - (m_currentFunction->objectType ? AS_PTR_SIZE : 0) - - (m_currentFunction->DoesReturnOnStack() ? AS_PTR_SIZE : 0); + (m_stackBlockSize << m_stackIndex) - + m_currentFunction->GetSpaceNeededForArguments() - + (m_currentFunction->objectType ? AS_PTR_SIZE : 0) - + (m_currentFunction->DoesReturnOnStack() ? AS_PTR_SIZE : 0); #ifdef WIP_16BYTE_ALIGN // Align the stack pointer - (asPWORD&)m_regs.stackPointer &= ~(MAX_TYPE_ALIGNMENT-1); + (asPWORD &)m_regs.stackPointer &= ~(MAX_TYPE_ALIGNMENT - 1); asASSERT( isAligned(m_regs.stackPointer, MAX_TYPE_ALIGNMENT) ); #endif @@ -2098,12 +2098,12 @@ void asCContext::CallScriptFunction(asCScriptFunction *func) asASSERT( func->scriptData ); // Push the framepointer, function id and programCounter on the stack - if (PushCallState() < 0) + if( PushCallState() < 0 ) return; // Update the current function and program position before increasing the stack // so the exception handler will know what to do if there is a stack overflow - m_currentFunction = func; + m_currentFunction = func; m_regs.programPointer = m_currentFunction->scriptData->byteCode.AddressOf(); PrepareScriptFunction(); @@ -2115,11 +2115,11 @@ void asCContext::PrepareScriptFunction() // Make sure there is space on the stack to execute the function asDWORD *oldStackPointer = m_regs.stackPointer; - asUINT needSize = m_currentFunction->scriptData->stackNeeded; + asUINT needSize = m_currentFunction->scriptData->stackNeeded; // With a quick check we know right away that we don't need to call ReserveStackSpace and do other checks inside it - if (m_stackBlocks.GetLength() == 0 || - oldStackPointer - (needSize + RESERVE_STACK) < m_stackBlocks[m_stackIndex]) + if( m_stackBlocks.GetLength() == 0 || + oldStackPointer - (needSize + RESERVE_STACK) < m_stackBlocks[m_stackIndex] ) { if( !ReserveStackSpace(needSize) ) return; @@ -2129,7 +2129,7 @@ void asCContext::PrepareScriptFunction() int numDwords = m_currentFunction->GetSpaceNeededForArguments() + (m_currentFunction->objectType ? AS_PTR_SIZE : 0) + (m_currentFunction->DoesReturnOnStack() ? AS_PTR_SIZE : 0); - memcpy(m_regs.stackPointer, oldStackPointer, sizeof(asDWORD)*numDwords); + memcpy(m_regs.stackPointer, oldStackPointer, sizeof(asDWORD) * numDwords); } } @@ -2139,16 +2139,16 @@ void asCContext::PrepareScriptFunction() // Set all object variables to 0 to guarantee that they are null before they are used // Only variables on the heap should be cleared. The rest will be cleared by calling the constructor // TODO: Need a fast way to iterate over this list (perhaps a pointer in variables to give index of next object var, or perhaps just order the array with object types first) - for (asUINT n = m_currentFunction->scriptData->variables.GetLength(); n-- > 0; ) + for( asUINT n = m_currentFunction->scriptData->variables.GetLength(); n-- > 0; ) { asSScriptVariable *var = m_currentFunction->scriptData->variables[n]; // Don't clear the function arguments - if (var->stackOffset <= 0) + if( var->stackOffset <= 0 ) continue; if( var->onHeap && (var->type.IsObject() || var->type.IsFuncdef()) ) - *(asPWORD*)&m_regs.stackFramePointer[-var->stackOffset] = 0; + *(asPWORD *)&m_regs.stackFramePointer[-var->stackOffset] = 0; } // Initialize the stack pointer with the space needed for local variables @@ -2168,7 +2168,7 @@ void asCContext::PrepareScriptFunction() void asCContext::CallInterfaceMethod(asCScriptFunction *func) { // Resolve the interface method using the current script type - asCScriptObject *obj = *(asCScriptObject**)(asPWORD*)m_regs.stackPointer; + asCScriptObject *obj = *(asCScriptObject **)(asPWORD *)m_regs.stackPointer; if( obj == 0 ) { // Tell the exception handler to clean up the arguments to this method @@ -2184,8 +2184,8 @@ void asCContext::CallInterfaceMethod(asCScriptFunction *func) if( func->funcType == asFUNC_INTERFACE ) { // Find the offset for the interface's virtual function table chunk - asUINT offset = 0; - bool found = false; + asUINT offset = 0; + bool found = false; asCObjectType *findInterface = func->objectType; // TODO: runtime optimize: The list of interfaces should be ordered by the address @@ -2196,7 +2196,7 @@ void asCContext::CallInterfaceMethod(asCScriptFunction *func) if( objType->interfaces[n] == findInterface ) { offset = objType->interfaceVFTOffsets[n]; - found = true; + found = true; break; } } @@ -2228,937 +2228,817 @@ void asCContext::CallInterfaceMethod(asCScriptFunction *func) } #if AS_USE_COMPUTED_GOTOS -#define INSTRUCTION(x) case_##x -#define NEXT_INSTRUCTION() goto *(const void*) dispatch_table[*(asBYTE*)l_bc] -#define BEGIN() NEXT_INSTRUCTION(); + #define INSTRUCTION(x) case_##x + #define NEXT_INSTRUCTION() goto *(const void *)dispatch_table[*(asBYTE *)l_bc] + #define BEGIN() NEXT_INSTRUCTION(); #else -#define INSTRUCTION(x) case x -#define NEXT_INSTRUCTION() break -#define BEGIN() switch( *(const asBYTE*)l_bc ) + #define INSTRUCTION(x) case x + #define NEXT_INSTRUCTION() break + #define BEGIN() switch( *(const asBYTE *)l_bc ) #endif void asCContext::ExecuteNext() { #if AS_USE_COMPUTED_GOTOS -static const void *const dispatch_table[256] = { -&&INSTRUCTION(asBC_PopPtr), &&INSTRUCTION(asBC_PshGPtr), &&INSTRUCTION(asBC_PshC4), &&INSTRUCTION(asBC_PshV4), -&&INSTRUCTION(asBC_PSF), &&INSTRUCTION(asBC_SwapPtr), &&INSTRUCTION(asBC_NOT), &&INSTRUCTION(asBC_PshG4), -&&INSTRUCTION(asBC_LdGRdR4), &&INSTRUCTION(asBC_CALL), &&INSTRUCTION(asBC_RET), &&INSTRUCTION(asBC_JMP), -&&INSTRUCTION(asBC_JZ), &&INSTRUCTION(asBC_JNZ), &&INSTRUCTION(asBC_JS), &&INSTRUCTION(asBC_JNS), -&&INSTRUCTION(asBC_JP), &&INSTRUCTION(asBC_JNP), &&INSTRUCTION(asBC_TZ), &&INSTRUCTION(asBC_TNZ), -&&INSTRUCTION(asBC_TS), &&INSTRUCTION(asBC_TNS), &&INSTRUCTION(asBC_TP), &&INSTRUCTION(asBC_TNP), -&&INSTRUCTION(asBC_NEGi), &&INSTRUCTION(asBC_NEGf), &&INSTRUCTION(asBC_NEGd), &&INSTRUCTION(asBC_INCi16), -&&INSTRUCTION(asBC_INCi8), &&INSTRUCTION(asBC_DECi16), &&INSTRUCTION(asBC_DECi8), &&INSTRUCTION(asBC_INCi), -&&INSTRUCTION(asBC_DECi), &&INSTRUCTION(asBC_INCf), &&INSTRUCTION(asBC_DECf), &&INSTRUCTION(asBC_INCd), -&&INSTRUCTION(asBC_DECd), &&INSTRUCTION(asBC_IncVi), &&INSTRUCTION(asBC_DecVi), &&INSTRUCTION(asBC_BNOT), -&&INSTRUCTION(asBC_BAND), &&INSTRUCTION(asBC_BOR), &&INSTRUCTION(asBC_BXOR), &&INSTRUCTION(asBC_BSLL), -&&INSTRUCTION(asBC_BSRL), &&INSTRUCTION(asBC_BSRA), &&INSTRUCTION(asBC_COPY), &&INSTRUCTION(asBC_PshC8), -&&INSTRUCTION(asBC_PshVPtr), &&INSTRUCTION(asBC_RDSPtr), &&INSTRUCTION(asBC_CMPd), &&INSTRUCTION(asBC_CMPu), -&&INSTRUCTION(asBC_CMPf), &&INSTRUCTION(asBC_CMPi), &&INSTRUCTION(asBC_CMPIi), &&INSTRUCTION(asBC_CMPIf), -&&INSTRUCTION(asBC_CMPIu), &&INSTRUCTION(asBC_JMPP), &&INSTRUCTION(asBC_PopRPtr), &&INSTRUCTION(asBC_PshRPtr), -&&INSTRUCTION(asBC_STR), &&INSTRUCTION(asBC_CALLSYS), &&INSTRUCTION(asBC_CALLBND), &&INSTRUCTION(asBC_SUSPEND), -&&INSTRUCTION(asBC_ALLOC), &&INSTRUCTION(asBC_FREE), &&INSTRUCTION(asBC_LOADOBJ), &&INSTRUCTION(asBC_STOREOBJ), -&&INSTRUCTION(asBC_GETOBJ), &&INSTRUCTION(asBC_REFCPY), &&INSTRUCTION(asBC_CHKREF), &&INSTRUCTION(asBC_GETOBJREF), -&&INSTRUCTION(asBC_GETREF), &&INSTRUCTION(asBC_PshNull), &&INSTRUCTION(asBC_ClrVPtr), &&INSTRUCTION(asBC_OBJTYPE), -&&INSTRUCTION(asBC_TYPEID), &&INSTRUCTION(asBC_SetV4), &&INSTRUCTION(asBC_SetV8), &&INSTRUCTION(asBC_ADDSi), -&&INSTRUCTION(asBC_CpyVtoV4), &&INSTRUCTION(asBC_CpyVtoV8), &&INSTRUCTION(asBC_CpyVtoR4), &&INSTRUCTION(asBC_CpyVtoR8), -&&INSTRUCTION(asBC_CpyVtoG4), &&INSTRUCTION(asBC_CpyRtoV4), &&INSTRUCTION(asBC_CpyRtoV8), &&INSTRUCTION(asBC_CpyGtoV4), -&&INSTRUCTION(asBC_WRTV1), &&INSTRUCTION(asBC_WRTV2), &&INSTRUCTION(asBC_WRTV4), &&INSTRUCTION(asBC_WRTV8), -&&INSTRUCTION(asBC_RDR1), &&INSTRUCTION(asBC_RDR2), &&INSTRUCTION(asBC_RDR4), &&INSTRUCTION(asBC_RDR8), -&&INSTRUCTION(asBC_LDG), &&INSTRUCTION(asBC_LDV), &&INSTRUCTION(asBC_PGA), &&INSTRUCTION(asBC_CmpPtr), -&&INSTRUCTION(asBC_VAR), &&INSTRUCTION(asBC_iTOf), &&INSTRUCTION(asBC_fTOi), &&INSTRUCTION(asBC_uTOf), -&&INSTRUCTION(asBC_fTOu), &&INSTRUCTION(asBC_sbTOi), &&INSTRUCTION(asBC_swTOi), &&INSTRUCTION(asBC_ubTOi), -&&INSTRUCTION(asBC_uwTOi), &&INSTRUCTION(asBC_dTOi), &&INSTRUCTION(asBC_dTOu), &&INSTRUCTION(asBC_dTOf), -&&INSTRUCTION(asBC_iTOd), &&INSTRUCTION(asBC_uTOd), &&INSTRUCTION(asBC_fTOd), &&INSTRUCTION(asBC_ADDi), -&&INSTRUCTION(asBC_SUBi), &&INSTRUCTION(asBC_MULi), &&INSTRUCTION(asBC_DIVi), &&INSTRUCTION(asBC_MODi), -&&INSTRUCTION(asBC_ADDf), &&INSTRUCTION(asBC_SUBf), &&INSTRUCTION(asBC_MULf), &&INSTRUCTION(asBC_DIVf), -&&INSTRUCTION(asBC_MODf), &&INSTRUCTION(asBC_ADDd), &&INSTRUCTION(asBC_SUBd), &&INSTRUCTION(asBC_MULd), -&&INSTRUCTION(asBC_DIVd), &&INSTRUCTION(asBC_MODd), &&INSTRUCTION(asBC_ADDIi), &&INSTRUCTION(asBC_SUBIi), -&&INSTRUCTION(asBC_MULIi), &&INSTRUCTION(asBC_ADDIf), &&INSTRUCTION(asBC_SUBIf), &&INSTRUCTION(asBC_MULIf), -&&INSTRUCTION(asBC_SetG4), &&INSTRUCTION(asBC_ChkRefS), &&INSTRUCTION(asBC_ChkNullV), &&INSTRUCTION(asBC_CALLINTF), -&&INSTRUCTION(asBC_iTOb), &&INSTRUCTION(asBC_iTOw), &&INSTRUCTION(asBC_SetV1), &&INSTRUCTION(asBC_SetV2), -&&INSTRUCTION(asBC_Cast), &&INSTRUCTION(asBC_i64TOi), &&INSTRUCTION(asBC_uTOi64), &&INSTRUCTION(asBC_iTOi64), -&&INSTRUCTION(asBC_fTOi64), &&INSTRUCTION(asBC_dTOi64), &&INSTRUCTION(asBC_fTOu64), &&INSTRUCTION(asBC_dTOu64), -&&INSTRUCTION(asBC_i64TOf), &&INSTRUCTION(asBC_u64TOf), &&INSTRUCTION(asBC_i64TOd), &&INSTRUCTION(asBC_u64TOd), -&&INSTRUCTION(asBC_NEGi64), &&INSTRUCTION(asBC_INCi64), &&INSTRUCTION(asBC_DECi64), &&INSTRUCTION(asBC_BNOT64), -&&INSTRUCTION(asBC_ADDi64), &&INSTRUCTION(asBC_SUBi64), &&INSTRUCTION(asBC_MULi64), &&INSTRUCTION(asBC_DIVi64), -&&INSTRUCTION(asBC_MODi64), &&INSTRUCTION(asBC_BAND64), &&INSTRUCTION(asBC_BOR64), &&INSTRUCTION(asBC_BXOR64), -&&INSTRUCTION(asBC_BSLL64), &&INSTRUCTION(asBC_BSRL64), &&INSTRUCTION(asBC_BSRA64), &&INSTRUCTION(asBC_CMPi64), -&&INSTRUCTION(asBC_CMPu64), &&INSTRUCTION(asBC_ChkNullS), &&INSTRUCTION(asBC_ClrHi), &&INSTRUCTION(asBC_JitEntry), -&&INSTRUCTION(asBC_CallPtr), &&INSTRUCTION(asBC_FuncPtr), &&INSTRUCTION(asBC_LoadThisR), &&INSTRUCTION(asBC_PshV8), -&&INSTRUCTION(asBC_DIVu), &&INSTRUCTION(asBC_MODu), &&INSTRUCTION(asBC_DIVu64), &&INSTRUCTION(asBC_MODu64), -&&INSTRUCTION(asBC_LoadRObjR), &&INSTRUCTION(asBC_LoadVObjR), &&INSTRUCTION(asBC_RefCpyV), &&INSTRUCTION(asBC_JLowZ), -&&INSTRUCTION(asBC_JLowNZ), &&INSTRUCTION(asBC_AllocMem), &&INSTRUCTION(asBC_SetListSize),&&INSTRUCTION(asBC_PshListElmnt), -&&INSTRUCTION(asBC_SetListType),&&INSTRUCTION(asBC_POWi), &&INSTRUCTION(asBC_POWu), &&INSTRUCTION(asBC_POWf), -&&INSTRUCTION(asBC_POWd), &&INSTRUCTION(asBC_POWdi), &&INSTRUCTION(asBC_POWi64), &&INSTRUCTION(asBC_POWu64), -&&INSTRUCTION(asBC_Thiscall1), - - &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), -&&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), -&&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), -&&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), -&&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), -&&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), -&&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), -&&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), -&&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), -&&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), -&&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), -&&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), -&&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), -&&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT) -}; + static const void * const dispatch_table[256] = { + &&INSTRUCTION(asBC_PopPtr), &&INSTRUCTION(asBC_PshGPtr), &&INSTRUCTION(asBC_PshC4), &&INSTRUCTION(asBC_PshV4), + &&INSTRUCTION(asBC_PSF), &&INSTRUCTION(asBC_SwapPtr), &&INSTRUCTION(asBC_NOT), &&INSTRUCTION(asBC_PshG4), + &&INSTRUCTION(asBC_LdGRdR4), &&INSTRUCTION(asBC_CALL), &&INSTRUCTION(asBC_RET), &&INSTRUCTION(asBC_JMP), + &&INSTRUCTION(asBC_JZ), &&INSTRUCTION(asBC_JNZ), &&INSTRUCTION(asBC_JS), &&INSTRUCTION(asBC_JNS), + &&INSTRUCTION(asBC_JP), &&INSTRUCTION(asBC_JNP), &&INSTRUCTION(asBC_TZ), &&INSTRUCTION(asBC_TNZ), + &&INSTRUCTION(asBC_TS), &&INSTRUCTION(asBC_TNS), &&INSTRUCTION(asBC_TP), &&INSTRUCTION(asBC_TNP), + &&INSTRUCTION(asBC_NEGi), &&INSTRUCTION(asBC_NEGf), &&INSTRUCTION(asBC_NEGd), &&INSTRUCTION(asBC_INCi16), + &&INSTRUCTION(asBC_INCi8), &&INSTRUCTION(asBC_DECi16), &&INSTRUCTION(asBC_DECi8), &&INSTRUCTION(asBC_INCi), + &&INSTRUCTION(asBC_DECi), &&INSTRUCTION(asBC_INCf), &&INSTRUCTION(asBC_DECf), &&INSTRUCTION(asBC_INCd), + &&INSTRUCTION(asBC_DECd), &&INSTRUCTION(asBC_IncVi), &&INSTRUCTION(asBC_DecVi), &&INSTRUCTION(asBC_BNOT), + &&INSTRUCTION(asBC_BAND), &&INSTRUCTION(asBC_BOR), &&INSTRUCTION(asBC_BXOR), &&INSTRUCTION(asBC_BSLL), + &&INSTRUCTION(asBC_BSRL), &&INSTRUCTION(asBC_BSRA), &&INSTRUCTION(asBC_COPY), &&INSTRUCTION(asBC_PshC8), + &&INSTRUCTION(asBC_PshVPtr), &&INSTRUCTION(asBC_RDSPtr), &&INSTRUCTION(asBC_CMPd), &&INSTRUCTION(asBC_CMPu), + &&INSTRUCTION(asBC_CMPf), &&INSTRUCTION(asBC_CMPi), &&INSTRUCTION(asBC_CMPIi), &&INSTRUCTION(asBC_CMPIf), + &&INSTRUCTION(asBC_CMPIu), &&INSTRUCTION(asBC_JMPP), &&INSTRUCTION(asBC_PopRPtr), &&INSTRUCTION(asBC_PshRPtr), + &&INSTRUCTION(asBC_STR), &&INSTRUCTION(asBC_CALLSYS), &&INSTRUCTION(asBC_CALLBND), &&INSTRUCTION(asBC_SUSPEND), + &&INSTRUCTION(asBC_ALLOC), &&INSTRUCTION(asBC_FREE), &&INSTRUCTION(asBC_LOADOBJ), &&INSTRUCTION(asBC_STOREOBJ), + &&INSTRUCTION(asBC_GETOBJ), &&INSTRUCTION(asBC_REFCPY), &&INSTRUCTION(asBC_CHKREF), &&INSTRUCTION(asBC_GETOBJREF), + &&INSTRUCTION(asBC_GETREF), &&INSTRUCTION(asBC_PshNull), &&INSTRUCTION(asBC_ClrVPtr), &&INSTRUCTION(asBC_OBJTYPE), + &&INSTRUCTION(asBC_TYPEID), &&INSTRUCTION(asBC_SetV4), &&INSTRUCTION(asBC_SetV8), &&INSTRUCTION(asBC_ADDSi), + &&INSTRUCTION(asBC_CpyVtoV4), &&INSTRUCTION(asBC_CpyVtoV8), &&INSTRUCTION(asBC_CpyVtoR4), &&INSTRUCTION(asBC_CpyVtoR8), + &&INSTRUCTION(asBC_CpyVtoG4), &&INSTRUCTION(asBC_CpyRtoV4), &&INSTRUCTION(asBC_CpyRtoV8), &&INSTRUCTION(asBC_CpyGtoV4), + &&INSTRUCTION(asBC_WRTV1), &&INSTRUCTION(asBC_WRTV2), &&INSTRUCTION(asBC_WRTV4), &&INSTRUCTION(asBC_WRTV8), + &&INSTRUCTION(asBC_RDR1), &&INSTRUCTION(asBC_RDR2), &&INSTRUCTION(asBC_RDR4), &&INSTRUCTION(asBC_RDR8), + &&INSTRUCTION(asBC_LDG), &&INSTRUCTION(asBC_LDV), &&INSTRUCTION(asBC_PGA), &&INSTRUCTION(asBC_CmpPtr), + &&INSTRUCTION(asBC_VAR), &&INSTRUCTION(asBC_iTOf), &&INSTRUCTION(asBC_fTOi), &&INSTRUCTION(asBC_uTOf), + &&INSTRUCTION(asBC_fTOu), &&INSTRUCTION(asBC_sbTOi), &&INSTRUCTION(asBC_swTOi), &&INSTRUCTION(asBC_ubTOi), + &&INSTRUCTION(asBC_uwTOi), &&INSTRUCTION(asBC_dTOi), &&INSTRUCTION(asBC_dTOu), &&INSTRUCTION(asBC_dTOf), + &&INSTRUCTION(asBC_iTOd), &&INSTRUCTION(asBC_uTOd), &&INSTRUCTION(asBC_fTOd), &&INSTRUCTION(asBC_ADDi), + &&INSTRUCTION(asBC_SUBi), &&INSTRUCTION(asBC_MULi), &&INSTRUCTION(asBC_DIVi), &&INSTRUCTION(asBC_MODi), + &&INSTRUCTION(asBC_ADDf), &&INSTRUCTION(asBC_SUBf), &&INSTRUCTION(asBC_MULf), &&INSTRUCTION(asBC_DIVf), + &&INSTRUCTION(asBC_MODf), &&INSTRUCTION(asBC_ADDd), &&INSTRUCTION(asBC_SUBd), &&INSTRUCTION(asBC_MULd), + &&INSTRUCTION(asBC_DIVd), &&INSTRUCTION(asBC_MODd), &&INSTRUCTION(asBC_ADDIi), &&INSTRUCTION(asBC_SUBIi), + &&INSTRUCTION(asBC_MULIi), &&INSTRUCTION(asBC_ADDIf), &&INSTRUCTION(asBC_SUBIf), &&INSTRUCTION(asBC_MULIf), + &&INSTRUCTION(asBC_SetG4), &&INSTRUCTION(asBC_ChkRefS), &&INSTRUCTION(asBC_ChkNullV), &&INSTRUCTION(asBC_CALLINTF), + &&INSTRUCTION(asBC_iTOb), &&INSTRUCTION(asBC_iTOw), &&INSTRUCTION(asBC_SetV1), &&INSTRUCTION(asBC_SetV2), + &&INSTRUCTION(asBC_Cast), &&INSTRUCTION(asBC_i64TOi), &&INSTRUCTION(asBC_uTOi64), &&INSTRUCTION(asBC_iTOi64), + &&INSTRUCTION(asBC_fTOi64), &&INSTRUCTION(asBC_dTOi64), &&INSTRUCTION(asBC_fTOu64), &&INSTRUCTION(asBC_dTOu64), + &&INSTRUCTION(asBC_i64TOf), &&INSTRUCTION(asBC_u64TOf), &&INSTRUCTION(asBC_i64TOd), &&INSTRUCTION(asBC_u64TOd), + &&INSTRUCTION(asBC_NEGi64), &&INSTRUCTION(asBC_INCi64), &&INSTRUCTION(asBC_DECi64), &&INSTRUCTION(asBC_BNOT64), + &&INSTRUCTION(asBC_ADDi64), &&INSTRUCTION(asBC_SUBi64), &&INSTRUCTION(asBC_MULi64), &&INSTRUCTION(asBC_DIVi64), + &&INSTRUCTION(asBC_MODi64), &&INSTRUCTION(asBC_BAND64), &&INSTRUCTION(asBC_BOR64), &&INSTRUCTION(asBC_BXOR64), + &&INSTRUCTION(asBC_BSLL64), &&INSTRUCTION(asBC_BSRL64), &&INSTRUCTION(asBC_BSRA64), &&INSTRUCTION(asBC_CMPi64), + &&INSTRUCTION(asBC_CMPu64), &&INSTRUCTION(asBC_ChkNullS), &&INSTRUCTION(asBC_ClrHi), &&INSTRUCTION(asBC_JitEntry), + &&INSTRUCTION(asBC_CallPtr), &&INSTRUCTION(asBC_FuncPtr), &&INSTRUCTION(asBC_LoadThisR), &&INSTRUCTION(asBC_PshV8), + &&INSTRUCTION(asBC_DIVu), &&INSTRUCTION(asBC_MODu), &&INSTRUCTION(asBC_DIVu64), &&INSTRUCTION(asBC_MODu64), + &&INSTRUCTION(asBC_LoadRObjR), &&INSTRUCTION(asBC_LoadVObjR), &&INSTRUCTION(asBC_RefCpyV), &&INSTRUCTION(asBC_JLowZ), + &&INSTRUCTION(asBC_JLowNZ), &&INSTRUCTION(asBC_AllocMem), &&INSTRUCTION(asBC_SetListSize), &&INSTRUCTION(asBC_PshListElmnt), + &&INSTRUCTION(asBC_SetListType), &&INSTRUCTION(asBC_POWi), &&INSTRUCTION(asBC_POWu), &&INSTRUCTION(asBC_POWf), + &&INSTRUCTION(asBC_POWd), &&INSTRUCTION(asBC_POWdi), &&INSTRUCTION(asBC_POWi64), &&INSTRUCTION(asBC_POWu64), + &&INSTRUCTION(asBC_Thiscall1), + + &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), + &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), + &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), + &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), + &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), + &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), + &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), + &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), + &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), + &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), + &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), + &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), + &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), + &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT), &&INSTRUCTION(FAULT)}; #endif asDWORD *l_bc = m_regs.programPointer; asDWORD *l_sp = m_regs.stackPointer; asDWORD *l_fp = m_regs.stackFramePointer; - for(;;) + for( ;; ) { #ifdef AS_DEBUG - // Gather statistics on executed bytecode - stats.Instr(*(asBYTE*)l_bc, !m_engine->ep.noDebugOutput); + // Gather statistics on executed bytecode + stats.Instr(*(asBYTE *)l_bc, !m_engine->ep.noDebugOutput); - // Used to verify that the size of the instructions are correct - asDWORD *old = l_bc; + // Used to verify that the size of the instructions are correct + asDWORD *old = l_bc; #endif - // Remember to keep the cases in order and without - // gaps, because that will make the switch faster. - // It will be faster since only one lookup will be - // made to find the correct jump destination. If not - // in order, the switch will make two lookups. - BEGIN() - { -//-------------- -// memory access functions - - INSTRUCTION(asBC_PopPtr): - // Pop a pointer from the stack - l_sp += AS_PTR_SIZE; - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_PshGPtr): - // Replaces PGA + RDSPtr - l_sp -= AS_PTR_SIZE; - *(asPWORD*)l_sp = *(asPWORD*)asBC_PTRARG(l_bc); - l_bc += 1 + AS_PTR_SIZE; - NEXT_INSTRUCTION(); - - // Push a dword value on the stack - INSTRUCTION(asBC_PshC4): - --l_sp; - *l_sp = asBC_DWORDARG(l_bc); - l_bc += 2; - NEXT_INSTRUCTION(); - - // Push the dword value of a variable on the stack - INSTRUCTION(asBC_PshV4): - --l_sp; - *l_sp = *(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - // Push the address of a variable on the stack - INSTRUCTION(asBC_PSF): - l_sp -= AS_PTR_SIZE; - *(asPWORD*)l_sp = asPWORD(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - // Swap the top 2 pointers on the stack - INSTRUCTION(asBC_SwapPtr): - { - asPWORD p = *(asPWORD*)l_sp; - *(asPWORD*)l_sp = *(asPWORD*)(l_sp+AS_PTR_SIZE); - *(asPWORD*)(l_sp+AS_PTR_SIZE) = p; - l_bc++; - } - NEXT_INSTRUCTION(); - - // Do a boolean not operation, modifying the value of the variable - INSTRUCTION(asBC_NOT): -#if AS_SIZEOF_BOOL == 1 - { - // Set the value to true if it is equal to 0 - - // We need to use volatile here to tell the compiler it cannot - // change the order of read and write operations on the pointer. - - volatile asBYTE *ptr = (asBYTE*)(l_fp - asBC_SWORDARG0(l_bc)); - asBYTE val = (ptr[0] == 0) ? VALUE_OF_BOOLEAN_TRUE : 0; - ptr[0] = val; // The result is stored in the lower byte - ptr[1] = 0; // Make sure the rest of the DWORD is 0 - ptr[2] = 0; - ptr[3] = 0; - } -#else - *(l_fp - asBC_SWORDARG0(l_bc)) = (*(l_fp - asBC_SWORDARG0(l_bc)) == 0 ? VALUE_OF_BOOLEAN_TRUE : 0); -#endif - l_bc++; - NEXT_INSTRUCTION(); - - // Push the dword value of a global variable on the stack - INSTRUCTION(asBC_PshG4): - --l_sp; - *l_sp = *(asDWORD*)asBC_PTRARG(l_bc); - l_bc += 1 + AS_PTR_SIZE; - NEXT_INSTRUCTION(); - - // Load the address of a global variable in the register, then - // copy the value of the global variable into a local variable - INSTRUCTION(asBC_LdGRdR4): - *(void**)&m_regs.valueRegister = (void*)asBC_PTRARG(l_bc); - *(l_fp - asBC_SWORDARG0(l_bc)) = **(asDWORD**)&m_regs.valueRegister; - l_bc += 1+AS_PTR_SIZE; - NEXT_INSTRUCTION(); - -//---------------- -// path control instructions - - // Begin execution of a script function - INSTRUCTION(asBC_CALL): + // Remember to keep the cases in order and without + // gaps, because that will make the switch faster. + // It will be faster since only one lookup will be + // made to find the correct jump destination. If not + // in order, the switch will make two lookups. + BEGIN() { - int i = asBC_INTARG(l_bc); - l_bc += 2; - - asASSERT( i >= 0 ); - asASSERT( (i & FUNC_IMPORTED) == 0 ); - - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + //-------------- + // memory access functions - CallScriptFunction(m_engine->scriptFunctions[i]); - - // Extract the values from the context again - l_bc = m_regs.programPointer; - l_sp = m_regs.stackPointer; - l_fp = m_regs.stackFramePointer; + INSTRUCTION(asBC_PopPtr) : // Pop a pointer from the stack + l_sp += AS_PTR_SIZE; + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_PshGPtr) : // Replaces PGA + RDSPtr + l_sp -= AS_PTR_SIZE; + *(asPWORD *)l_sp = *(asPWORD *)asBC_PTRARG(l_bc); + l_bc += 1 + AS_PTR_SIZE; + NEXT_INSTRUCTION(); + + // Push a dword value on the stack + INSTRUCTION(asBC_PshC4) : --l_sp; + *l_sp = asBC_DWORDARG(l_bc); + l_bc += 2; + NEXT_INSTRUCTION(); + + // Push the dword value of a variable on the stack + INSTRUCTION(asBC_PshV4) : --l_sp; + *l_sp = *(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); - // If status isn't active anymore then we must stop - if( m_status != asEXECUTION_ACTIVE ) - return; - } - NEXT_INSTRUCTION(); + // Push the address of a variable on the stack + INSTRUCTION(asBC_PSF) : l_sp -= AS_PTR_SIZE; + *(asPWORD *)l_sp = asPWORD(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); - // Return to the caller, and remove the arguments from the stack - INSTRUCTION(asBC_RET): - { - // Return if this was the first function, or a nested execution - if( m_callStack.GetLength() == 0 || - m_callStack[m_callStack.GetLength() - CALLSTACK_FRAME_SIZE] == 0 ) + // Swap the top 2 pointers on the stack + INSTRUCTION(asBC_SwapPtr) : { - m_status = asEXECUTION_FINISHED; - return; + asPWORD p = *(asPWORD *)l_sp; + *(asPWORD *)l_sp = *(asPWORD *)(l_sp + AS_PTR_SIZE); + *(asPWORD *)(l_sp + AS_PTR_SIZE) = p; + l_bc++; } + NEXT_INSTRUCTION(); - asWORD w = asBC_WORDARG0(l_bc); + // Do a boolean not operation, modifying the value of the variable + INSTRUCTION(asBC_NOT) : +#if AS_SIZEOF_BOOL == 1 + { + // Set the value to true if it is equal to 0 - // Read the old framepointer, functionid, and programCounter from the call stack - PopCallState(); + // We need to use volatile here to tell the compiler it cannot + // change the order of read and write operations on the pointer. - // Extract the values from the context again - l_bc = m_regs.programPointer; - l_sp = m_regs.stackPointer; - l_fp = m_regs.stackFramePointer; + volatile asBYTE *ptr = (asBYTE *)(l_fp - asBC_SWORDARG0(l_bc)); + asBYTE val = (ptr[0] == 0) ? VALUE_OF_BOOLEAN_TRUE : 0; + ptr[0] = val; // The result is stored in the lower byte + ptr[1] = 0; // Make sure the rest of the DWORD is 0 + ptr[2] = 0; + ptr[3] = 0; + } +#else + *(l_fp - asBC_SWORDARG0(l_bc)) = (*(l_fp - asBC_SWORDARG0(l_bc)) == 0 ? VALUE_OF_BOOLEAN_TRUE : 0); +#endif + l_bc++; + NEXT_INSTRUCTION(); + + // Push the dword value of a global variable on the stack + INSTRUCTION(asBC_PshG4) : --l_sp; + *l_sp = *(asDWORD *)asBC_PTRARG(l_bc); + l_bc += 1 + AS_PTR_SIZE; + NEXT_INSTRUCTION(); + + // Load the address of a global variable in the register, then + // copy the value of the global variable into a local variable + INSTRUCTION(asBC_LdGRdR4) : *(void **)&m_regs.valueRegister = (void *)asBC_PTRARG(l_bc); + *(l_fp - asBC_SWORDARG0(l_bc)) = **(asDWORD **)&m_regs.valueRegister; + l_bc += 1 + AS_PTR_SIZE; + NEXT_INSTRUCTION(); + + //---------------- + // path control instructions + + // Begin execution of a script function + INSTRUCTION(asBC_CALL) : + { + int i = asBC_INTARG(l_bc); + l_bc += 2; - // Pop arguments from stack - l_sp += w; - } - NEXT_INSTRUCTION(); + asASSERT( i >= 0 ); + asASSERT( (i & FUNC_IMPORTED) == 0 ); - // Jump to a relative position - INSTRUCTION(asBC_JMP): - l_bc += 2 + asBC_INTARG(l_bc); - NEXT_INSTRUCTION(); + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; -//---------------- -// Conditional jumps + CallScriptFunction(m_engine->scriptFunctions[i]); - // Jump to a relative position if the value in the register is 0 - INSTRUCTION(asBC_JZ): - if( *(int*)&m_regs.valueRegister == 0 ) - l_bc += asBC_INTARG(l_bc) + 2; - else - l_bc += 2; - NEXT_INSTRUCTION(); + // Extract the values from the context again + l_bc = m_regs.programPointer; + l_sp = m_regs.stackPointer; + l_fp = m_regs.stackFramePointer; - // Jump to a relative position if the value in the register is not 0 - INSTRUCTION(asBC_JNZ): - if( *(int*)&m_regs.valueRegister != 0 ) - l_bc += asBC_INTARG(l_bc) + 2; - else - l_bc += 2; - NEXT_INSTRUCTION(); + // If status isn't active anymore then we must stop + if( m_status != asEXECUTION_ACTIVE ) + return; + } + NEXT_INSTRUCTION(); - // Jump to a relative position if the value in the register is negative - INSTRUCTION(asBC_JS): - if( *(int*)&m_regs.valueRegister < 0 ) - l_bc += asBC_INTARG(l_bc) + 2; - else - l_bc += 2; - NEXT_INSTRUCTION(); + // Return to the caller, and remove the arguments from the stack + INSTRUCTION(asBC_RET) : + { + // Return if this was the first function, or a nested execution + if( m_callStack.GetLength() == 0 || + m_callStack[m_callStack.GetLength() - CALLSTACK_FRAME_SIZE] == 0 ) + { + m_status = asEXECUTION_FINISHED; + return; + } - // Jump to a relative position if the value in the register it not negative - INSTRUCTION(asBC_JNS): - if( *(int*)&m_regs.valueRegister >= 0 ) - l_bc += asBC_INTARG(l_bc) + 2; - else - l_bc += 2; - NEXT_INSTRUCTION(); + asWORD w = asBC_WORDARG0(l_bc); - // Jump to a relative position if the value in the register is greater than 0 - INSTRUCTION(asBC_JP): - if( *(int*)&m_regs.valueRegister > 0 ) - l_bc += asBC_INTARG(l_bc) + 2; - else - l_bc += 2; - NEXT_INSTRUCTION(); + // Read the old framepointer, functionid, and programCounter from the call stack + PopCallState(); - // Jump to a relative position if the value in the register is not greater than 0 - INSTRUCTION(asBC_JNP): - if( *(int*)&m_regs.valueRegister <= 0 ) - l_bc += asBC_INTARG(l_bc) + 2; - else - l_bc += 2; - NEXT_INSTRUCTION(); -//-------------------- -// test instructions + // Extract the values from the context again + l_bc = m_regs.programPointer; + l_sp = m_regs.stackPointer; + l_fp = m_regs.stackFramePointer; - // If the value in the register is 0, then set the register to 1, else to 0 - INSTRUCTION(asBC_TZ): + // Pop arguments from stack + l_sp += w; + } + NEXT_INSTRUCTION(); + + // Jump to a relative position + INSTRUCTION(asBC_JMP) : l_bc += 2 + asBC_INTARG(l_bc); + NEXT_INSTRUCTION(); + + //---------------- + // Conditional jumps + + // Jump to a relative position if the value in the register is 0 + INSTRUCTION(asBC_JZ) : if( *(int *)&m_regs.valueRegister == 0 ) + l_bc += asBC_INTARG(l_bc) + 2; + else l_bc += 2; + NEXT_INSTRUCTION(); + + // Jump to a relative position if the value in the register is not 0 + INSTRUCTION(asBC_JNZ) : if( *(int *)&m_regs.valueRegister != 0 ) + l_bc += asBC_INTARG(l_bc) + 2; + else l_bc += 2; + NEXT_INSTRUCTION(); + + // Jump to a relative position if the value in the register is negative + INSTRUCTION(asBC_JS) : if( *(int *)&m_regs.valueRegister < 0 ) + l_bc += asBC_INTARG(l_bc) + 2; + else l_bc += 2; + NEXT_INSTRUCTION(); + + // Jump to a relative position if the value in the register it not negative + INSTRUCTION(asBC_JNS) : if( *(int *)&m_regs.valueRegister >= 0 ) + l_bc += asBC_INTARG(l_bc) + 2; + else l_bc += 2; + NEXT_INSTRUCTION(); + + // Jump to a relative position if the value in the register is greater than 0 + INSTRUCTION(asBC_JP) : if( *(int *)&m_regs.valueRegister > 0 ) + l_bc += asBC_INTARG(l_bc) + 2; + else l_bc += 2; + NEXT_INSTRUCTION(); + + // Jump to a relative position if the value in the register is not greater than 0 + INSTRUCTION(asBC_JNP) : if( *(int *)&m_regs.valueRegister <= 0 ) + l_bc += asBC_INTARG(l_bc) + 2; + else l_bc += 2; + NEXT_INSTRUCTION(); + //-------------------- + // test instructions + + // If the value in the register is 0, then set the register to 1, else to 0 + INSTRUCTION(asBC_TZ) : #if AS_SIZEOF_BOOL == 1 - { - // Set the value to true if it is equal to 0 - - // We need to use volatile here to tell the compiler it cannot - // change the order of read and write operations on valueRegister. - - volatile int *regPtr = (int*)&m_regs.valueRegister; - volatile asBYTE *regBptr = (asBYTE*)&m_regs.valueRegister; - asBYTE val = (regPtr[0] == 0) ? VALUE_OF_BOOLEAN_TRUE : 0; - regBptr[0] = val; // The result is stored in the lower byte - regBptr[1] = 0; // Make sure the rest of the register is 0 - regBptr[2] = 0; - regBptr[3] = 0; - regBptr[4] = 0; - regBptr[5] = 0; - regBptr[6] = 0; - regBptr[7] = 0; - } + { + // Set the value to true if it is equal to 0 + + // We need to use volatile here to tell the compiler it cannot + // change the order of read and write operations on valueRegister. + + volatile int *regPtr = (int *)&m_regs.valueRegister; + volatile asBYTE *regBptr = (asBYTE *)&m_regs.valueRegister; + asBYTE val = (regPtr[0] == 0) ? VALUE_OF_BOOLEAN_TRUE : 0; + regBptr[0] = val; // The result is stored in the lower byte + regBptr[1] = 0; // Make sure the rest of the register is 0 + regBptr[2] = 0; + regBptr[3] = 0; + regBptr[4] = 0; + regBptr[5] = 0; + regBptr[6] = 0; + regBptr[7] = 0; + } #else - *(int*)&m_regs.valueRegister = (*(int*)&m_regs.valueRegister == 0 ? VALUE_OF_BOOLEAN_TRUE : 0); + *(int *)&m_regs.valueRegister = (*(int *)&m_regs.valueRegister == 0 ? VALUE_OF_BOOLEAN_TRUE : 0); #endif - l_bc++; - NEXT_INSTRUCTION(); + l_bc++; + NEXT_INSTRUCTION(); - // If the value in the register is not 0, then set the register to 1, else to 0 - INSTRUCTION(asBC_TNZ): + // If the value in the register is not 0, then set the register to 1, else to 0 + INSTRUCTION(asBC_TNZ) : #if AS_SIZEOF_BOOL == 1 - { - // Set the value to true if it is not equal to 0 - - // We need to use volatile here to tell the compiler it cannot - // change the order of read and write operations on valueRegister. - - volatile int *regPtr = (int*)&m_regs.valueRegister; - volatile asBYTE *regBptr = (asBYTE*)&m_regs.valueRegister; - asBYTE val = (regPtr[0] == 0) ? 0 : VALUE_OF_BOOLEAN_TRUE; - regBptr[0] = val; // The result is stored in the lower byte - regBptr[1] = 0; // Make sure the rest of the register is 0 - regBptr[2] = 0; - regBptr[3] = 0; - regBptr[4] = 0; - regBptr[5] = 0; - regBptr[6] = 0; - regBptr[7] = 0; - } + { + // Set the value to true if it is not equal to 0 + + // We need to use volatile here to tell the compiler it cannot + // change the order of read and write operations on valueRegister. + + volatile int *regPtr = (int *)&m_regs.valueRegister; + volatile asBYTE *regBptr = (asBYTE *)&m_regs.valueRegister; + asBYTE val = (regPtr[0] == 0) ? 0 : VALUE_OF_BOOLEAN_TRUE; + regBptr[0] = val; // The result is stored in the lower byte + regBptr[1] = 0; // Make sure the rest of the register is 0 + regBptr[2] = 0; + regBptr[3] = 0; + regBptr[4] = 0; + regBptr[5] = 0; + regBptr[6] = 0; + regBptr[7] = 0; + } #else - *(int*)&m_regs.valueRegister = (*(int*)&m_regs.valueRegister == 0 ? 0 : VALUE_OF_BOOLEAN_TRUE); + *(int *)&m_regs.valueRegister = (*(int *)&m_regs.valueRegister == 0 ? 0 : VALUE_OF_BOOLEAN_TRUE); #endif - l_bc++; - NEXT_INSTRUCTION(); + l_bc++; + NEXT_INSTRUCTION(); - // If the value in the register is negative, then set the register to 1, else to 0 - INSTRUCTION(asBC_TS): + // If the value in the register is negative, then set the register to 1, else to 0 + INSTRUCTION(asBC_TS) : #if AS_SIZEOF_BOOL == 1 - { - // Set the value to true if it is less than 0 - - // We need to use volatile here to tell the compiler it cannot - // change the order of read and write operations on valueRegister. - - volatile int *regPtr = (int*)&m_regs.valueRegister; - volatile asBYTE *regBptr = (asBYTE*)&m_regs.valueRegister; - asBYTE val = (regPtr[0] < 0) ? VALUE_OF_BOOLEAN_TRUE : 0; - regBptr[0] = val; // The result is stored in the lower byte - regBptr[1] = 0; // Make sure the rest of the register is 0 - regBptr[2] = 0; - regBptr[3] = 0; - regBptr[4] = 0; - regBptr[5] = 0; - regBptr[6] = 0; - regBptr[7] = 0; - } + { + // Set the value to true if it is less than 0 + + // We need to use volatile here to tell the compiler it cannot + // change the order of read and write operations on valueRegister. + + volatile int *regPtr = (int *)&m_regs.valueRegister; + volatile asBYTE *regBptr = (asBYTE *)&m_regs.valueRegister; + asBYTE val = (regPtr[0] < 0) ? VALUE_OF_BOOLEAN_TRUE : 0; + regBptr[0] = val; // The result is stored in the lower byte + regBptr[1] = 0; // Make sure the rest of the register is 0 + regBptr[2] = 0; + regBptr[3] = 0; + regBptr[4] = 0; + regBptr[5] = 0; + regBptr[6] = 0; + regBptr[7] = 0; + } #else - *(int*)&m_regs.valueRegister = (*(int*)&m_regs.valueRegister < 0 ? VALUE_OF_BOOLEAN_TRUE : 0); + *(int *)&m_regs.valueRegister = (*(int *)&m_regs.valueRegister < 0 ? VALUE_OF_BOOLEAN_TRUE : 0); #endif - l_bc++; - NEXT_INSTRUCTION(); + l_bc++; + NEXT_INSTRUCTION(); - // If the value in the register is not negative, then set the register to 1, else to 0 - INSTRUCTION(asBC_TNS): + // If the value in the register is not negative, then set the register to 1, else to 0 + INSTRUCTION(asBC_TNS) : #if AS_SIZEOF_BOOL == 1 - { - // Set the value to true if it is not less than 0 - - // We need to use volatile here to tell the compiler it cannot - // change the order of read and write operations on valueRegister. - - volatile int *regPtr = (int*)&m_regs.valueRegister; - volatile asBYTE *regBptr = (asBYTE*)&m_regs.valueRegister; - asBYTE val = (regPtr[0] >= 0) ? VALUE_OF_BOOLEAN_TRUE : 0; - regBptr[0] = val; // The result is stored in the lower byte - regBptr[1] = 0; // Make sure the rest of the register is 0 - regBptr[2] = 0; - regBptr[3] = 0; - regBptr[4] = 0; - regBptr[5] = 0; - regBptr[6] = 0; - regBptr[7] = 0; - } + { + // Set the value to true if it is not less than 0 + + // We need to use volatile here to tell the compiler it cannot + // change the order of read and write operations on valueRegister. + + volatile int *regPtr = (int *)&m_regs.valueRegister; + volatile asBYTE *regBptr = (asBYTE *)&m_regs.valueRegister; + asBYTE val = (regPtr[0] >= 0) ? VALUE_OF_BOOLEAN_TRUE : 0; + regBptr[0] = val; // The result is stored in the lower byte + regBptr[1] = 0; // Make sure the rest of the register is 0 + regBptr[2] = 0; + regBptr[3] = 0; + regBptr[4] = 0; + regBptr[5] = 0; + regBptr[6] = 0; + regBptr[7] = 0; + } #else - *(int*)&m_regs.valueRegister = (*(int*)&m_regs.valueRegister < 0 ? 0 : VALUE_OF_BOOLEAN_TRUE); + *(int *)&m_regs.valueRegister = (*(int *)&m_regs.valueRegister < 0 ? 0 : VALUE_OF_BOOLEAN_TRUE); #endif - l_bc++; - NEXT_INSTRUCTION(); + l_bc++; + NEXT_INSTRUCTION(); - // If the value in the register is greater than 0, then set the register to 1, else to 0 - INSTRUCTION(asBC_TP): + // If the value in the register is greater than 0, then set the register to 1, else to 0 + INSTRUCTION(asBC_TP) : #if AS_SIZEOF_BOOL == 1 - { - // Set the value to true if it is greater than 0 - - // We need to use volatile here to tell the compiler it cannot - // change the order of read and write operations on valueRegister. - - volatile int *regPtr = (int*)&m_regs.valueRegister; - volatile asBYTE *regBptr = (asBYTE*)&m_regs.valueRegister; - asBYTE val = (regPtr[0] > 0) ? VALUE_OF_BOOLEAN_TRUE : 0; - regBptr[0] = val; // The result is stored in the lower byte - regBptr[1] = 0; // Make sure the rest of the register is 0 - regBptr[2] = 0; - regBptr[3] = 0; - regBptr[4] = 0; - regBptr[5] = 0; - regBptr[6] = 0; - regBptr[7] = 0; - } + { + // Set the value to true if it is greater than 0 + + // We need to use volatile here to tell the compiler it cannot + // change the order of read and write operations on valueRegister. + + volatile int *regPtr = (int *)&m_regs.valueRegister; + volatile asBYTE *regBptr = (asBYTE *)&m_regs.valueRegister; + asBYTE val = (regPtr[0] > 0) ? VALUE_OF_BOOLEAN_TRUE : 0; + regBptr[0] = val; // The result is stored in the lower byte + regBptr[1] = 0; // Make sure the rest of the register is 0 + regBptr[2] = 0; + regBptr[3] = 0; + regBptr[4] = 0; + regBptr[5] = 0; + regBptr[6] = 0; + regBptr[7] = 0; + } #else - *(int*)&m_regs.valueRegister = (*(int*)&m_regs.valueRegister > 0 ? VALUE_OF_BOOLEAN_TRUE : 0); + *(int *)&m_regs.valueRegister = (*(int *)&m_regs.valueRegister > 0 ? VALUE_OF_BOOLEAN_TRUE : 0); #endif - l_bc++; - NEXT_INSTRUCTION(); + l_bc++; + NEXT_INSTRUCTION(); - // If the value in the register is not greater than 0, then set the register to 1, else to 0 - INSTRUCTION(asBC_TNP): + // If the value in the register is not greater than 0, then set the register to 1, else to 0 + INSTRUCTION(asBC_TNP) : #if AS_SIZEOF_BOOL == 1 - { - // Set the value to true if it is not greater than 0 - - // We need to use volatile here to tell the compiler it cannot - // change the order of read and write operations on valueRegister. - - volatile int *regPtr = (int*)&m_regs.valueRegister; - volatile asBYTE *regBptr = (asBYTE*)&m_regs.valueRegister; - asBYTE val = (regPtr[0] <= 0) ? VALUE_OF_BOOLEAN_TRUE : 0; - regBptr[0] = val; // The result is stored in the lower byte - regBptr[1] = 0; // Make sure the rest of the register is 0 - regBptr[2] = 0; - regBptr[3] = 0; - regBptr[4] = 0; - regBptr[5] = 0; - regBptr[6] = 0; - regBptr[7] = 0; - } + { + // Set the value to true if it is not greater than 0 + + // We need to use volatile here to tell the compiler it cannot + // change the order of read and write operations on valueRegister. + + volatile int *regPtr = (int *)&m_regs.valueRegister; + volatile asBYTE *regBptr = (asBYTE *)&m_regs.valueRegister; + asBYTE val = (regPtr[0] <= 0) ? VALUE_OF_BOOLEAN_TRUE : 0; + regBptr[0] = val; // The result is stored in the lower byte + regBptr[1] = 0; // Make sure the rest of the register is 0 + regBptr[2] = 0; + regBptr[3] = 0; + regBptr[4] = 0; + regBptr[5] = 0; + regBptr[6] = 0; + regBptr[7] = 0; + } #else - *(int*)&m_regs.valueRegister = (*(int*)&m_regs.valueRegister > 0 ? 0 : VALUE_OF_BOOLEAN_TRUE); + *(int *)&m_regs.valueRegister = (*(int *)&m_regs.valueRegister > 0 ? 0 : VALUE_OF_BOOLEAN_TRUE); #endif - l_bc++; - NEXT_INSTRUCTION(); - -//-------------------- -// negate value - - // Negate the integer value in the variable - INSTRUCTION(asBC_NEGi): - *(l_fp - asBC_SWORDARG0(l_bc)) = asDWORD(-int(*(l_fp - asBC_SWORDARG0(l_bc)))); - l_bc++; - NEXT_INSTRUCTION(); - - // Negate the float value in the variable - INSTRUCTION(asBC_NEGf): - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = -*(float*)(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - // Negate the double value in the variable - INSTRUCTION(asBC_NEGd): - *(double*)(l_fp - asBC_SWORDARG0(l_bc)) = -*(double*)(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - -//------------------------- -// Increment value pointed to by address in register - - // Increment the short value pointed to by the register - INSTRUCTION(asBC_INCi16): - (**(short**)&m_regs.valueRegister)++; - l_bc++; - NEXT_INSTRUCTION(); - - // Increment the byte value pointed to by the register - INSTRUCTION(asBC_INCi8): - (**(char**)&m_regs.valueRegister)++; - l_bc++; - NEXT_INSTRUCTION(); - - // Decrement the short value pointed to by the register - INSTRUCTION(asBC_DECi16): - (**(short**)&m_regs.valueRegister)--; - l_bc++; - NEXT_INSTRUCTION(); - - // Decrement the byte value pointed to by the register - INSTRUCTION(asBC_DECi8): - (**(char**)&m_regs.valueRegister)--; - l_bc++; - NEXT_INSTRUCTION(); - - // Increment the integer value pointed to by the register - INSTRUCTION(asBC_INCi): - ++(**(int**)&m_regs.valueRegister); - l_bc++; - NEXT_INSTRUCTION(); - - // Decrement the integer value pointed to by the register - INSTRUCTION(asBC_DECi): - --(**(int**)&m_regs.valueRegister); - l_bc++; - NEXT_INSTRUCTION(); - - // Increment the float value pointed to by the register - INSTRUCTION(asBC_INCf): - ++(**(float**)&m_regs.valueRegister); - l_bc++; - NEXT_INSTRUCTION(); - - // Decrement the float value pointed to by the register - INSTRUCTION(asBC_DECf): - --(**(float**)&m_regs.valueRegister); - l_bc++; - NEXT_INSTRUCTION(); - - // Increment the double value pointed to by the register - INSTRUCTION(asBC_INCd): - ++(**(double**)&m_regs.valueRegister); - l_bc++; - NEXT_INSTRUCTION(); - - // Decrement the double value pointed to by the register - INSTRUCTION(asBC_DECd): - --(**(double**)&m_regs.valueRegister); - l_bc++; - NEXT_INSTRUCTION(); - - // Increment the local integer variable - INSTRUCTION(asBC_IncVi): - (*(int*)(l_fp - asBC_SWORDARG0(l_bc)))++; - l_bc++; - NEXT_INSTRUCTION(); - - // Decrement the local integer variable - INSTRUCTION(asBC_DecVi): - (*(int*)(l_fp - asBC_SWORDARG0(l_bc)))--; - l_bc++; - NEXT_INSTRUCTION(); - -//-------------------- -// bits instructions - - // Do a bitwise not on the value in the variable - INSTRUCTION(asBC_BNOT): - *(l_fp - asBC_SWORDARG0(l_bc)) = ~*(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - // Do a bitwise and of two variables and store the result in a third variable - INSTRUCTION(asBC_BAND): - *(l_fp - asBC_SWORDARG0(l_bc)) = *(l_fp - asBC_SWORDARG1(l_bc)) & *(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - // Do a bitwise or of two variables and store the result in a third variable - INSTRUCTION(asBC_BOR): - *(l_fp - asBC_SWORDARG0(l_bc)) = *(l_fp - asBC_SWORDARG1(l_bc)) | *(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - // Do a bitwise xor of two variables and store the result in a third variable - INSTRUCTION(asBC_BXOR): - *(l_fp - asBC_SWORDARG0(l_bc)) = *(l_fp - asBC_SWORDARG1(l_bc)) ^ *(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - // Do a logical shift left of two variables and store the result in a third variable - INSTRUCTION(asBC_BSLL): - *(l_fp - asBC_SWORDARG0(l_bc)) = *(l_fp - asBC_SWORDARG1(l_bc)) << *(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - // Do a logical shift right of two variables and store the result in a third variable - INSTRUCTION(asBC_BSRL): - *(l_fp - asBC_SWORDARG0(l_bc)) = *(l_fp - asBC_SWORDARG1(l_bc)) >> *(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - // Do an arithmetic shift right of two variables and store the result in a third variable - INSTRUCTION(asBC_BSRA): - *(l_fp - asBC_SWORDARG0(l_bc)) = int(*(l_fp - asBC_SWORDARG1(l_bc))) >> *(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_COPY): - { - void *d = (void*)*(asPWORD*)l_sp; l_sp += AS_PTR_SIZE; - void *s = (void*)*(asPWORD*)l_sp; - if( s == 0 || d == 0 ) - { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + l_bc++; + NEXT_INSTRUCTION(); - // Raise exception - SetInternalException(TXT_NULL_POINTER_ACCESS); - return; - } - memcpy(d, s, asBC_WORDARG0(l_bc)*4); + //-------------------- + // negate value - // replace the pointer on the stack with the lvalue - *(asPWORD**)l_sp = (asPWORD*)d; - } - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_PshC8): - l_sp -= 2; - *(asQWORD*)l_sp = asBC_QWORDARG(l_bc); - l_bc += 3; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_PshVPtr): - l_sp -= AS_PTR_SIZE; - *(asPWORD*)l_sp = *(asPWORD*)(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_RDSPtr): - { - // The pointer must not be null - asPWORD a = *(asPWORD*)l_sp; - if( a == 0 ) - { - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + // Negate the integer value in the variable + INSTRUCTION(asBC_NEGi) : *(l_fp - asBC_SWORDARG0(l_bc)) = asDWORD(-int(*(l_fp - asBC_SWORDARG0(l_bc)))); + l_bc++; + NEXT_INSTRUCTION(); - SetInternalException(TXT_NULL_POINTER_ACCESS); - return; - } - // Pop an address from the stack, read a pointer from that address and push it on the stack - *(asPWORD*)l_sp = *(asPWORD*)a; - } - l_bc++; - NEXT_INSTRUCTION(); + // Negate the float value in the variable + INSTRUCTION(asBC_NEGf) : *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = -*(float *)(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); - //---------------------------- - // Comparisons - INSTRUCTION(asBC_CMPd): - { - // Do a comparison of the values, rather than a subtraction - // in order to get proper behaviour for infinity values. - double dbl1 = *(double*)(l_fp - asBC_SWORDARG0(l_bc)); - double dbl2 = *(double*)(l_fp - asBC_SWORDARG1(l_bc)); - if( dbl1 == dbl2 ) *(int*)&m_regs.valueRegister = 0; - else if( dbl1 < dbl2 ) *(int*)&m_regs.valueRegister = -1; - else *(int*)&m_regs.valueRegister = 1; - l_bc += 2; - } - NEXT_INSTRUCTION(); + // Negate the double value in the variable + INSTRUCTION(asBC_NEGd) : *(double *)(l_fp - asBC_SWORDARG0(l_bc)) = -*(double *)(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_CMPu): - { - asDWORD d1 = *(asDWORD*)(l_fp - asBC_SWORDARG0(l_bc)); - asDWORD d2 = *(asDWORD*)(l_fp - asBC_SWORDARG1(l_bc)); - if( d1 == d2 ) *(int*)&m_regs.valueRegister = 0; - else if( d1 < d2 ) *(int*)&m_regs.valueRegister = -1; - else *(int*)&m_regs.valueRegister = 1; - l_bc += 2; - } - NEXT_INSTRUCTION(); + //------------------------- + // Increment value pointed to by address in register - INSTRUCTION(asBC_CMPf): - { - // Do a comparison of the values, rather than a subtraction - // in order to get proper behaviour for infinity values. - float f1 = *(float*)(l_fp - asBC_SWORDARG0(l_bc)); - float f2 = *(float*)(l_fp - asBC_SWORDARG1(l_bc)); - if( f1 == f2 ) *(int*)&m_regs.valueRegister = 0; - else if( f1 < f2 ) *(int*)&m_regs.valueRegister = -1; - else *(int*)&m_regs.valueRegister = 1; - l_bc += 2; - } - NEXT_INSTRUCTION(); + // Increment the short value pointed to by the register + INSTRUCTION(asBC_INCi16) : (**(short **)&m_regs.valueRegister)++; + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_CMPi): - { - int i1 = *(int*)(l_fp - asBC_SWORDARG0(l_bc)); - int i2 = *(int*)(l_fp - asBC_SWORDARG1(l_bc)); - if( i1 == i2 ) *(int*)&m_regs.valueRegister = 0; - else if( i1 < i2 ) *(int*)&m_regs.valueRegister = -1; - else *(int*)&m_regs.valueRegister = 1; - l_bc += 2; - } - NEXT_INSTRUCTION(); + // Increment the byte value pointed to by the register + INSTRUCTION(asBC_INCi8) : (**(char **)&m_regs.valueRegister)++; + l_bc++; + NEXT_INSTRUCTION(); - //---------------------------- - // Comparisons with constant value - INSTRUCTION(asBC_CMPIi): - { - int i1 = *(int*)(l_fp - asBC_SWORDARG0(l_bc)); - int i2 = asBC_INTARG(l_bc); - if( i1 == i2 ) *(int*)&m_regs.valueRegister = 0; - else if( i1 < i2 ) *(int*)&m_regs.valueRegister = -1; - else *(int*)&m_regs.valueRegister = 1; - l_bc += 2; - } - NEXT_INSTRUCTION(); + // Decrement the short value pointed to by the register + INSTRUCTION(asBC_DECi16) : (**(short **)&m_regs.valueRegister)--; + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_CMPIf): - { - // Do a comparison of the values, rather than a subtraction - // in order to get proper behaviour for infinity values. - float f1 = *(float*)(l_fp - asBC_SWORDARG0(l_bc)); - float f2 = asBC_FLOATARG(l_bc); - if( f1 == f2 ) *(int*)&m_regs.valueRegister = 0; - else if( f1 < f2 ) *(int*)&m_regs.valueRegister = -1; - else *(int*)&m_regs.valueRegister = 1; - l_bc += 2; - } - NEXT_INSTRUCTION(); + // Decrement the byte value pointed to by the register + INSTRUCTION(asBC_DECi8) : (**(char **)&m_regs.valueRegister)--; + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_CMPIu): - { - asDWORD d1 = *(asDWORD*)(l_fp - asBC_SWORDARG0(l_bc)); - asDWORD d2 = asBC_DWORDARG(l_bc); - if( d1 == d2 ) *(int*)&m_regs.valueRegister = 0; - else if( d1 < d2 ) *(int*)&m_regs.valueRegister = -1; - else *(int*)&m_regs.valueRegister = 1; - l_bc += 2; - } - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_JMPP): - l_bc += 1 + (*(int*)(l_fp - asBC_SWORDARG0(l_bc)))*2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_PopRPtr): - *(asPWORD*)&m_regs.valueRegister = *(asPWORD*)l_sp; - l_sp += AS_PTR_SIZE; - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_PshRPtr): - l_sp -= AS_PTR_SIZE; - *(asPWORD*)l_sp = *(asPWORD*)&m_regs.valueRegister; - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_STR): - // TODO: NEWSTRING: Deprecate this instruction - asASSERT(false); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_CALLSYS): - { - // Get function ID from the argument - int i = asBC_INTARG(l_bc); + // Increment the integer value pointed to by the register + INSTRUCTION(asBC_INCi) : ++(**(int **)&m_regs.valueRegister); + l_bc++; + NEXT_INSTRUCTION(); + + // Decrement the integer value pointed to by the register + INSTRUCTION(asBC_DECi) : --(**(int **)&m_regs.valueRegister); + l_bc++; + NEXT_INSTRUCTION(); - // Need to move the values back to the context as the called functions - // may use the debug interface to inspect the registers - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + // Increment the float value pointed to by the register + INSTRUCTION(asBC_INCf) : ++(**(float **)&m_regs.valueRegister); + l_bc++; + NEXT_INSTRUCTION(); - l_sp += CallSystemFunction(i, this); + // Decrement the float value pointed to by the register + INSTRUCTION(asBC_DECf) : --(**(float **)&m_regs.valueRegister); + l_bc++; + NEXT_INSTRUCTION(); - // Update the program position after the call so that line number is correct - l_bc += 2; + // Increment the double value pointed to by the register + INSTRUCTION(asBC_INCd) : ++(**(double **)&m_regs.valueRegister); + l_bc++; + NEXT_INSTRUCTION(); - if( m_regs.doProcessSuspend ) + // Decrement the double value pointed to by the register + INSTRUCTION(asBC_DECd) : --(**(double **)&m_regs.valueRegister); + l_bc++; + NEXT_INSTRUCTION(); + + // Increment the local integer variable + INSTRUCTION(asBC_IncVi) : (*(int *)(l_fp - asBC_SWORDARG0(l_bc)))++; + l_bc++; + NEXT_INSTRUCTION(); + + // Decrement the local integer variable + INSTRUCTION(asBC_DecVi) : (*(int *)(l_fp - asBC_SWORDARG0(l_bc)))--; + l_bc++; + NEXT_INSTRUCTION(); + + //-------------------- + // bits instructions + + // Do a bitwise not on the value in the variable + INSTRUCTION(asBC_BNOT) : *(l_fp - asBC_SWORDARG0(l_bc)) = ~*(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); + + // Do a bitwise and of two variables and store the result in a third variable + INSTRUCTION(asBC_BAND) : *(l_fp - asBC_SWORDARG0(l_bc)) = *(l_fp - asBC_SWORDARG1(l_bc)) & *(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + // Do a bitwise or of two variables and store the result in a third variable + INSTRUCTION(asBC_BOR) : *(l_fp - asBC_SWORDARG0(l_bc)) = *(l_fp - asBC_SWORDARG1(l_bc)) | *(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + // Do a bitwise xor of two variables and store the result in a third variable + INSTRUCTION(asBC_BXOR) : *(l_fp - asBC_SWORDARG0(l_bc)) = *(l_fp - asBC_SWORDARG1(l_bc)) ^ *(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + // Do a logical shift left of two variables and store the result in a third variable + INSTRUCTION(asBC_BSLL) : *(l_fp - asBC_SWORDARG0(l_bc)) = *(l_fp - asBC_SWORDARG1(l_bc)) << *(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + // Do a logical shift right of two variables and store the result in a third variable + INSTRUCTION(asBC_BSRL) : *(l_fp - asBC_SWORDARG0(l_bc)) = *(l_fp - asBC_SWORDARG1(l_bc)) >> *(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + // Do an arithmetic shift right of two variables and store the result in a third variable + INSTRUCTION(asBC_BSRA) : *(l_fp - asBC_SWORDARG0(l_bc)) = int(*(l_fp - asBC_SWORDARG1(l_bc))) >> *(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_COPY) : { - // Should the execution be suspended? - if( m_doSuspend ) + void *d = (void *)*(asPWORD *)l_sp; + l_sp += AS_PTR_SIZE; + void *s = (void *)*(asPWORD *)l_sp; + if( s == 0 || d == 0 ) { + // Need to move the values back to the context m_regs.programPointer = l_bc; m_regs.stackPointer = l_sp; m_regs.stackFramePointer = l_fp; - m_status = asEXECUTION_SUSPENDED; + // Raise exception + SetInternalException(TXT_NULL_POINTER_ACCESS); return; } - // An exception might have been raised - if( m_status != asEXECUTION_ACTIVE ) + memcpy(d, s, asBC_WORDARG0(l_bc) * 4); + + // replace the pointer on the stack with the lvalue + *(asPWORD **)l_sp = (asPWORD *)d; + } + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_PshC8) : l_sp -= 2; + *(asQWORD *)l_sp = asBC_QWORDARG(l_bc); + l_bc += 3; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_PshVPtr) : l_sp -= AS_PTR_SIZE; + *(asPWORD *)l_sp = *(asPWORD *)(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_RDSPtr) : + { + // The pointer must not be null + asPWORD a = *(asPWORD *)l_sp; + if( a == 0 ) { m_regs.programPointer = l_bc; m_regs.stackPointer = l_sp; m_regs.stackFramePointer = l_fp; + SetInternalException(TXT_NULL_POINTER_ACCESS); return; } + // Pop an address from the stack, read a pointer from that address and push it on the stack + *(asPWORD *)l_sp = *(asPWORD *)a; } - } - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_CALLBND): - { - // TODO: Clean-up: This code is very similar to asBC_CallPtr. Create a shared method for them - // Get the function ID from the stack - int i = asBC_INTARG(l_bc); + l_bc++; + NEXT_INSTRUCTION(); - asASSERT( i >= 0 ); - asASSERT( i & FUNC_IMPORTED ); + //---------------------------- + // Comparisons + INSTRUCTION(asBC_CMPd) : + { + // Do a comparison of the values, rather than a subtraction + // in order to get proper behaviour for infinity values. + double dbl1 = *(double *)(l_fp - asBC_SWORDARG0(l_bc)); + double dbl2 = *(double *)(l_fp - asBC_SWORDARG1(l_bc)); + if( dbl1 == dbl2 ) *(int *)&m_regs.valueRegister = 0; + else if( dbl1 < dbl2 ) *(int *)&m_regs.valueRegister = -1; + else *(int *)&m_regs.valueRegister = 1; + l_bc += 2; + } + NEXT_INSTRUCTION(); - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + INSTRUCTION(asBC_CMPu) : + { + asDWORD d1 = *(asDWORD *)(l_fp - asBC_SWORDARG0(l_bc)); + asDWORD d2 = *(asDWORD *)(l_fp - asBC_SWORDARG1(l_bc)); + if( d1 == d2 ) *(int *)&m_regs.valueRegister = 0; + else if( d1 < d2 ) *(int *)&m_regs.valueRegister = -1; + else *(int *)&m_regs.valueRegister = 1; + l_bc += 2; + } + NEXT_INSTRUCTION(); - int funcId = m_engine->importedFunctions[i & ~FUNC_IMPORTED]->boundFunctionId; - if( funcId == -1 ) + INSTRUCTION(asBC_CMPf) : { - // Need to update the program pointer for the exception handler - m_regs.programPointer += 2; + // Do a comparison of the values, rather than a subtraction + // in order to get proper behaviour for infinity values. + float f1 = *(float *)(l_fp - asBC_SWORDARG0(l_bc)); + float f2 = *(float *)(l_fp - asBC_SWORDARG1(l_bc)); + if( f1 == f2 ) *(int *)&m_regs.valueRegister = 0; + else if( f1 < f2 ) *(int *)&m_regs.valueRegister = -1; + else *(int *)&m_regs.valueRegister = 1; + l_bc += 2; + } + NEXT_INSTRUCTION(); - // Tell the exception handler to clean up the arguments to this function - m_needToCleanupArgs = true; - SetInternalException(TXT_UNBOUND_FUNCTION); - return; + INSTRUCTION(asBC_CMPi) : + { + int i1 = *(int *)(l_fp - asBC_SWORDARG0(l_bc)); + int i2 = *(int *)(l_fp - asBC_SWORDARG1(l_bc)); + if( i1 == i2 ) *(int *)&m_regs.valueRegister = 0; + else if( i1 < i2 ) *(int *)&m_regs.valueRegister = -1; + else *(int *)&m_regs.valueRegister = 1; + l_bc += 2; } - else + NEXT_INSTRUCTION(); + + //---------------------------- + // Comparisons with constant value + INSTRUCTION(asBC_CMPIi) : { - asCScriptFunction *func = m_engine->GetScriptFunction(funcId); - if( func->funcType == asFUNC_SCRIPT ) - { - m_regs.programPointer += 2; - CallScriptFunction(func); - } - else if( func->funcType == asFUNC_SYSTEM ) - { - m_regs.stackPointer += CallSystemFunction(func->id, this); + int i1 = *(int *)(l_fp - asBC_SWORDARG0(l_bc)); + int i2 = asBC_INTARG(l_bc); + if( i1 == i2 ) *(int *)&m_regs.valueRegister = 0; + else if( i1 < i2 ) *(int *)&m_regs.valueRegister = -1; + else *(int *)&m_regs.valueRegister = 1; + l_bc += 2; + } + NEXT_INSTRUCTION(); - // Update program position after the call so the line number - // is correct in case the system function queries it - m_regs.programPointer += 2; - } - else - { - asASSERT(func->funcType == asFUNC_DELEGATE); + INSTRUCTION(asBC_CMPIf) : + { + // Do a comparison of the values, rather than a subtraction + // in order to get proper behaviour for infinity values. + float f1 = *(float *)(l_fp - asBC_SWORDARG0(l_bc)); + float f2 = asBC_FLOATARG(l_bc); + if( f1 == f2 ) *(int *)&m_regs.valueRegister = 0; + else if( f1 < f2 ) *(int *)&m_regs.valueRegister = -1; + else *(int *)&m_regs.valueRegister = 1; + l_bc += 2; + } + NEXT_INSTRUCTION(); - // Delegates cannot be bound to imported functions as the delegates do not have a function id - asASSERT(false); - } + INSTRUCTION(asBC_CMPIu) : + { + asDWORD d1 = *(asDWORD *)(l_fp - asBC_SWORDARG0(l_bc)); + asDWORD d2 = asBC_DWORDARG(l_bc); + if( d1 == d2 ) *(int *)&m_regs.valueRegister = 0; + else if( d1 < d2 ) *(int *)&m_regs.valueRegister = -1; + else *(int *)&m_regs.valueRegister = 1; + l_bc += 2; } + NEXT_INSTRUCTION(); - // Extract the values from the context again - l_bc = m_regs.programPointer; - l_sp = m_regs.stackPointer; - l_fp = m_regs.stackFramePointer; + INSTRUCTION(asBC_JMPP) : l_bc += 1 + (*(int *)(l_fp - asBC_SWORDARG0(l_bc))) * 2; + NEXT_INSTRUCTION(); - // If status isn't active anymore then we must stop - if( m_status != asEXECUTION_ACTIVE ) - return; - } - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_PopRPtr) : *(asPWORD *)&m_regs.valueRegister = *(asPWORD *)l_sp; + l_sp += AS_PTR_SIZE; + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_SUSPEND): - if( m_regs.doProcessSuspend ) - { - if( m_lineCallback ) + INSTRUCTION(asBC_PshRPtr) : l_sp -= AS_PTR_SIZE; + *(asPWORD *)l_sp = *(asPWORD *)&m_regs.valueRegister; + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_STR) : // TODO: NEWSTRING: Deprecate this instruction + asASSERT(false); + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_CALLSYS) : { + // Get function ID from the argument + int i = asBC_INTARG(l_bc); + + // Need to move the values back to the context as the called functions + // may use the debug interface to inspect the registers m_regs.programPointer = l_bc; m_regs.stackPointer = l_sp; m_regs.stackFramePointer = l_fp; - CallLineCallback(); + l_sp += CallSystemFunction(i, this); + + // Update the program position after the call so that line number is correct + l_bc += 2; + + if( m_regs.doProcessSuspend ) + { + // Should the execution be suspended? + if( m_doSuspend ) + { + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; + + m_status = asEXECUTION_SUSPENDED; + return; + } + // An exception might have been raised + if( m_status != asEXECUTION_ACTIVE ) + { + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; + + return; + } + } } - if( m_doSuspend ) + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_CALLBND) : { - l_bc++; + // TODO: Clean-up: This code is very similar to asBC_CallPtr. Create a shared method for them + // Get the function ID from the stack + int i = asBC_INTARG(l_bc); + + asASSERT( i >= 0 ); + asASSERT( i & FUNC_IMPORTED ); // Need to move the values back to the context m_regs.programPointer = l_bc; m_regs.stackPointer = l_sp; m_regs.stackFramePointer = l_fp; - m_status = asEXECUTION_SUSPENDED; - return; - } - } - - l_bc++; - NEXT_INSTRUCTION(); + int funcId = m_engine->importedFunctions[i & ~FUNC_IMPORTED]->boundFunctionId; + if( funcId == -1 ) + { + // Need to update the program pointer for the exception handler + m_regs.programPointer += 2; - INSTRUCTION(asBC_ALLOC): - { - asCObjectType *objType = (asCObjectType*)asBC_PTRARG(l_bc); - int func = asBC_INTARG(l_bc+AS_PTR_SIZE); - - if( objType->flags & asOBJ_SCRIPT_OBJECT ) - { - // Need to move the values back to the context as the construction - // of the script object may reuse the context for nested calls. - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; - - // Pre-allocate the memory - asDWORD *mem = (asDWORD*)m_engine->CallAlloc(objType); - - // Pre-initialize the memory by calling the constructor for asCScriptObject - ScriptObject_Construct(objType, (asCScriptObject*)mem); - - // Call the constructor to initalize the memory - asCScriptFunction *f = m_engine->scriptFunctions[func]; - - asDWORD **a = (asDWORD**)*(asPWORD*)(m_regs.stackPointer + f->GetSpaceNeededForArguments()); - if( a ) *a = mem; - - // Push the object pointer on the stack - m_regs.stackPointer -= AS_PTR_SIZE; - *(asPWORD*)m_regs.stackPointer = (asPWORD)mem; + // Tell the exception handler to clean up the arguments to this function + m_needToCleanupArgs = true; + SetInternalException(TXT_UNBOUND_FUNCTION); + return; + } + else + { + asCScriptFunction *func = m_engine->GetScriptFunction(funcId); + if( func->funcType == asFUNC_SCRIPT ) + { + m_regs.programPointer += 2; + CallScriptFunction(func); + } + else if( func->funcType == asFUNC_SYSTEM ) + { + m_regs.stackPointer += CallSystemFunction(func->id, this); - m_regs.programPointer += 2+AS_PTR_SIZE; + // Update program position after the call so the line number + // is correct in case the system function queries it + m_regs.programPointer += 2; + } + else + { + asASSERT(func->funcType == asFUNC_DELEGATE); - CallScriptFunction(f); + // Delegates cannot be bound to imported functions as the delegates do not have a function id + asASSERT(false); + } + } // Extract the values from the context again l_bc = m_regs.programPointer; @@ -3169,1022 +3049,644 @@ static const void *const dispatch_table[256] = { if( m_status != asEXECUTION_ACTIVE ) return; } - else + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_SUSPEND) : if( m_regs.doProcessSuspend ) { - // Pre-allocate the memory - asDWORD *mem = (asDWORD*)m_engine->CallAlloc(objType); + if( m_lineCallback ) + { + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - if( func ) + CallLineCallback(); + } + if( m_doSuspend ) { - // Push the object pointer on the stack (it will be popped by the function) - l_sp -= AS_PTR_SIZE; - *(asPWORD*)l_sp = (asPWORD)mem; + l_bc++; - // Need to move the values back to the context as the called functions - // may use the debug interface to inspect the registers + // Need to move the values back to the context m_regs.programPointer = l_bc; m_regs.stackPointer = l_sp; m_regs.stackFramePointer = l_fp; - l_sp += CallSystemFunction(func, this); + m_status = asEXECUTION_SUSPENDED; + return; } + } - // Pop the variable address from the stack - asDWORD **a = (asDWORD**)*(asPWORD*)l_sp; - l_sp += AS_PTR_SIZE; - if( a ) *a = mem; + l_bc++; + NEXT_INSTRUCTION(); - l_bc += 2+AS_PTR_SIZE; + INSTRUCTION(asBC_ALLOC) : + { + asCObjectType *objType = (asCObjectType *)asBC_PTRARG(l_bc); + int func = asBC_INTARG(l_bc + AS_PTR_SIZE); - if( m_regs.doProcessSuspend ) + if( objType->flags & asOBJ_SCRIPT_OBJECT ) { - // Should the execution be suspended? - if( m_doSuspend ) - { - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + // Need to move the values back to the context as the construction + // of the script object may reuse the context for nested calls. + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - m_status = asEXECUTION_SUSPENDED; - return; - } - // An exception might have been raised - if( m_status != asEXECUTION_ACTIVE ) - { - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + // Pre-allocate the memory + asDWORD *mem = (asDWORD *)m_engine->CallAlloc(objType); - m_engine->CallFree(mem); - if( a ) *a = 0; + // Pre-initialize the memory by calling the constructor for asCScriptObject + ScriptObject_Construct(objType, (asCScriptObject *)mem); - return; - } - } - } - } - NEXT_INSTRUCTION(); + // Call the constructor to initalize the memory + asCScriptFunction *f = m_engine->scriptFunctions[func]; - INSTRUCTION(asBC_FREE): - { - // Get the variable that holds the object handle/reference - asPWORD *a = (asPWORD*)asPWORD(l_fp - asBC_SWORDARG0(l_bc)); - if( *a ) - { - asCObjectType *objType = (asCObjectType*)asBC_PTRARG(l_bc); - asSTypeBehaviour *beh = &objType->beh; + asDWORD **a = (asDWORD **)*(asPWORD *)(m_regs.stackPointer + f->GetSpaceNeededForArguments()); + if( a ) *a = mem; - // Need to move the values back to the context as the called functions - // may use the debug interface to inspect the registers - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + // Push the object pointer on the stack + m_regs.stackPointer -= AS_PTR_SIZE; + *(asPWORD *)m_regs.stackPointer = (asPWORD)mem; - if( objType->flags & asOBJ_REF ) - { - asASSERT( (objType->flags & asOBJ_NOCOUNT) || beh->release ); - if( beh->release ) - m_engine->CallObjectMethod((void*)(asPWORD)*a, beh->release); + m_regs.programPointer += 2 + AS_PTR_SIZE; + + CallScriptFunction(f); + + // Extract the values from the context again + l_bc = m_regs.programPointer; + l_sp = m_regs.stackPointer; + l_fp = m_regs.stackFramePointer; + + // If status isn't active anymore then we must stop + if( m_status != asEXECUTION_ACTIVE ) + return; } else { - if( beh->destruct ) - m_engine->CallObjectMethod((void*)(asPWORD)*a, beh->destruct); - else if( objType->flags & asOBJ_LIST_PATTERN ) - m_engine->DestroyList((asBYTE*)(asPWORD)*a, objType); - - m_engine->CallFree((void*)(asPWORD)*a); - } + // Pre-allocate the memory + asDWORD *mem = (asDWORD *)m_engine->CallAlloc(objType); - // Clear the variable - *a = 0; - } - } - l_bc += 1+AS_PTR_SIZE; - NEXT_INSTRUCTION(); + if( func ) + { + // Push the object pointer on the stack (it will be popped by the function) + l_sp -= AS_PTR_SIZE; + *(asPWORD *)l_sp = (asPWORD)mem; - INSTRUCTION(asBC_LOADOBJ): - { - // Move the object pointer from the object variable into the object register - void **a = (void**)(l_fp - asBC_SWORDARG0(l_bc)); - m_regs.objectType = 0; - m_regs.objectRegister = *a; - *a = 0; - } - l_bc++; - NEXT_INSTRUCTION(); + // Need to move the values back to the context as the called functions + // may use the debug interface to inspect the registers + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - INSTRUCTION(asBC_STOREOBJ): - // Move the object pointer from the object register to the object variable - *(asPWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = asPWORD(m_regs.objectRegister); - m_regs.objectRegister = 0; - l_bc++; - NEXT_INSTRUCTION(); + l_sp += CallSystemFunction(func, this); + } - INSTRUCTION(asBC_GETOBJ): - { - // Read variable index from location on stack - asPWORD *a = (asPWORD*)(l_sp + asBC_WORDARG0(l_bc)); - asPWORD offset = *a; - // Move pointer from variable to the same location on the stack - asPWORD *v = (asPWORD*)(l_fp - offset); - *a = *v; - // Clear variable - *v = 0; - } - l_bc++; - NEXT_INSTRUCTION(); + // Pop the variable address from the stack + asDWORD **a = (asDWORD **)*(asPWORD *)l_sp; + l_sp += AS_PTR_SIZE; + if( a ) *a = mem; - INSTRUCTION(asBC_REFCPY): - { - asCObjectType *objType = (asCObjectType*)asBC_PTRARG(l_bc); - asSTypeBehaviour *beh = &objType->beh; + l_bc += 2 + AS_PTR_SIZE; - // Pop address of destination pointer from the stack - void **d = (void**)*(asPWORD*)l_sp; - l_sp += AS_PTR_SIZE; + if( m_regs.doProcessSuspend ) + { + // Should the execution be suspended? + if( m_doSuspend ) + { + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - // Read wanted pointer from the stack - void *s = (void*)*(asPWORD*)l_sp; + m_status = asEXECUTION_SUSPENDED; + return; + } + // An exception might have been raised + if( m_status != asEXECUTION_ACTIVE ) + { + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - // Need to move the values back to the context as the called functions - // may use the debug interface to inspect the registers - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + m_engine->CallFree(mem); + if( a ) *a = 0; - // Update ref counter for object types that require it - if( !(objType->flags & (asOBJ_NOCOUNT | asOBJ_VALUE)) ) - { - // Release previous object held by destination pointer - if( *d != 0 && beh->release ) - m_engine->CallObjectMethod(*d, beh->release); - // Increase ref counter of wanted object - if( s != 0 && beh->addref ) - m_engine->CallObjectMethod(s, beh->addref); + return; + } + } + } } + NEXT_INSTRUCTION(); - // Set the new object in the destination - *d = s; - } - l_bc += 1+AS_PTR_SIZE; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_CHKREF): - { - // Verify if the pointer on the stack is null - // This is used when validating a pointer that an operator will work on - asPWORD a = *(asPWORD*)l_sp; - if( a == 0 ) + INSTRUCTION(asBC_FREE) : { - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; - - SetInternalException(TXT_NULL_POINTER_ACCESS); - return; - } - } - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_GETOBJREF): - { - // Get the location on the stack where the reference will be placed - asPWORD *a = (asPWORD*)(l_sp + asBC_WORDARG0(l_bc)); + // Get the variable that holds the object handle/reference + asPWORD *a = (asPWORD *)asPWORD(l_fp - asBC_SWORDARG0(l_bc)); + if( *a ) + { + asCObjectType *objType = (asCObjectType *)asBC_PTRARG(l_bc); + asSTypeBehaviour *beh = &objType->beh; - // Replace the variable index with the object handle held in the variable - *(asPWORD**)a = *(asPWORD**)(l_fp - *a); - } - l_bc++; - NEXT_INSTRUCTION(); + // Need to move the values back to the context as the called functions + // may use the debug interface to inspect the registers + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - INSTRUCTION(asBC_GETREF): - { - // Get the location on the stack where the reference will be placed - asPWORD *a = (asPWORD*)(l_sp + asBC_WORDARG0(l_bc)); + if( objType->flags & asOBJ_REF ) + { + asASSERT( (objType->flags & asOBJ_NOCOUNT) || beh->release ); + if( beh->release ) + m_engine->CallObjectMethod((void *)(asPWORD)*a, beh->release); + } + else + { + if( beh->destruct ) + m_engine->CallObjectMethod((void *)(asPWORD)*a, beh->destruct); + else if( objType->flags & asOBJ_LIST_PATTERN ) + m_engine->DestroyList((asBYTE *)(asPWORD)*a, objType); - // Replace the variable index with the address of the variable - *(asPWORD**)a = (asPWORD*)(l_fp - (int)*a); - } - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_PshNull): - // Push a null pointer on the stack - l_sp -= AS_PTR_SIZE; - *(asPWORD*)l_sp = 0; - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_ClrVPtr): - // TODO: runtime optimize: Is this instruction really necessary? - // CallScriptFunction() can clear the null handles upon entry, just as is done for - // all other object variables - // Clear pointer variable - *(asPWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = 0; - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_OBJTYPE): - // Push the object type on the stack - l_sp -= AS_PTR_SIZE; - *(asPWORD*)l_sp = asBC_PTRARG(l_bc); - l_bc += 1+AS_PTR_SIZE; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_TYPEID): - // Equivalent to PshC4, but kept as separate instruction for bytecode serialization - --l_sp; - *l_sp = asBC_DWORDARG(l_bc); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_SetV4): - *(l_fp - asBC_SWORDARG0(l_bc)) = asBC_DWORDARG(l_bc); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_SetV8): - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = asBC_QWORDARG(l_bc); - l_bc += 3; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_ADDSi): - { - // The pointer must not be null - asPWORD a = *(asPWORD*)l_sp; - if( a == 0 ) - { - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + m_engine->CallFree((void *)(asPWORD)*a); + } - SetInternalException(TXT_NULL_POINTER_ACCESS); - return; + // Clear the variable + *a = 0; + } } - // Add an offset to the pointer - *(asPWORD*)l_sp = a + asBC_SWORDARG0(l_bc); - } - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_CpyVtoV4): - *(l_fp - asBC_SWORDARG0(l_bc)) = *(l_fp - asBC_SWORDARG1(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_CpyVtoV8): - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD*)(l_fp - asBC_SWORDARG1(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_CpyVtoR4): - *(asDWORD*)&m_regs.valueRegister = *(asDWORD*)(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_CpyVtoR8): - *(asQWORD*)&m_regs.valueRegister = *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_CpyVtoG4): - *(asDWORD*)asBC_PTRARG(l_bc) = *(asDWORD*)(l_fp - asBC_SWORDARG0(l_bc)); - l_bc += 1 + AS_PTR_SIZE; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_CpyRtoV4): - *(asDWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asDWORD*)&m_regs.valueRegister; - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_CpyRtoV8): - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = m_regs.valueRegister; - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_CpyGtoV4): - *(asDWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asDWORD*)asBC_PTRARG(l_bc); - l_bc += 1 + AS_PTR_SIZE; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_WRTV1): - // The pointer in the register points to a byte, and *(l_fp - offset) too - **(asBYTE**)&m_regs.valueRegister = *(asBYTE*)(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_WRTV2): - // The pointer in the register points to a word, and *(l_fp - offset) too - **(asWORD**)&m_regs.valueRegister = *(asWORD*)(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_WRTV4): - **(asDWORD**)&m_regs.valueRegister = *(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_WRTV8): - **(asQWORD**)&m_regs.valueRegister = *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_RDR1): - { - // The pointer in the register points to a byte, and *(l_fp - offset) will also point to a byte - asBYTE *bPtr = (asBYTE*)(l_fp - asBC_SWORDARG0(l_bc)); - bPtr[0] = **(asBYTE**)&m_regs.valueRegister; // read the byte - bPtr[1] = 0; // 0 the rest of the DWORD - bPtr[2] = 0; - bPtr[3] = 0; - } - l_bc++; - NEXT_INSTRUCTION(); + l_bc += 1 + AS_PTR_SIZE; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_RDR2): - { - // The pointer in the register points to a word, and *(l_fp - offset) will also point to a word - asWORD *wPtr = (asWORD*)(l_fp - asBC_SWORDARG0(l_bc)); - wPtr[0] = **(asWORD**)&m_regs.valueRegister; // read the word - wPtr[1] = 0; // 0 the rest of the DWORD - } - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_RDR4): - *(asDWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = **(asDWORD**)&m_regs.valueRegister; - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_RDR8): - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = **(asQWORD**)&m_regs.valueRegister; - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_LDG): - *(asPWORD*)&m_regs.valueRegister = asBC_PTRARG(l_bc); - l_bc += 1+AS_PTR_SIZE; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_LDV): - *(asDWORD**)&m_regs.valueRegister = (l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_PGA): - l_sp -= AS_PTR_SIZE; - *(asPWORD*)l_sp = asBC_PTRARG(l_bc); - l_bc += 1+AS_PTR_SIZE; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_CmpPtr): - { - // TODO: runtime optimize: This instruction should really just be an equals, and return true or false. - // The instruction is only used for is and !is tests anyway. - asPWORD p1 = *(asPWORD*)(l_fp - asBC_SWORDARG0(l_bc)); - asPWORD p2 = *(asPWORD*)(l_fp - asBC_SWORDARG1(l_bc)); - if( p1 == p2 ) *(int*)&m_regs.valueRegister = 0; - else if( p1 < p2 ) *(int*)&m_regs.valueRegister = -1; - else *(int*)&m_regs.valueRegister = 1; - l_bc += 2; - } - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_VAR): - l_sp -= AS_PTR_SIZE; - *(asPWORD*)l_sp = (asPWORD)asBC_SWORDARG0(l_bc); - l_bc++; - NEXT_INSTRUCTION(); - - //---------------------------- - // Type conversions - INSTRUCTION(asBC_iTOf): - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = float(*(int*)(l_fp - asBC_SWORDARG0(l_bc))); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_fTOi): - *(l_fp - asBC_SWORDARG0(l_bc)) = int(*(float*)(l_fp - asBC_SWORDARG0(l_bc))); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_uTOf): - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = float(*(l_fp - asBC_SWORDARG0(l_bc))); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_fTOu): - { - float f = *(float*)(l_fp - asBC_SWORDARG0(l_bc)); - if (f < 0) + INSTRUCTION(asBC_LOADOBJ) : { - // For consistency across compilers and target systems we must cast to int first, - // because on some compilers the cast of a negative float value to uint result in 0 - *(l_fp - asBC_SWORDARG0(l_bc)) = asUINT(int(f)); + // Move the object pointer from the object variable into the object register + void **a = (void **)(l_fp - asBC_SWORDARG0(l_bc)); + m_regs.objectType = 0; + m_regs.objectRegister = *a; + *a = 0; } - else - *(l_fp - asBC_SWORDARG0(l_bc)) = asUINT(f); - } - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_sbTOi): - // *(l_fp - offset) points to a char, and will point to an int afterwards - *(l_fp - asBC_SWORDARG0(l_bc)) = *(signed char*)(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_swTOi): - // *(l_fp - offset) points to a short, and will point to an int afterwards - *(l_fp - asBC_SWORDARG0(l_bc)) = *(short*)(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_ubTOi): - // (l_fp - offset) points to a byte, and will point to an int afterwards - *(l_fp - asBC_SWORDARG0(l_bc)) = *(asBYTE*)(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_uwTOi): - // *(l_fp - offset) points to a word, and will point to an int afterwards - *(l_fp - asBC_SWORDARG0(l_bc)) = *(asWORD*)(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_dTOi): - *(l_fp - asBC_SWORDARG0(l_bc)) = int(*(double*)(l_fp - asBC_SWORDARG1(l_bc))); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_dTOu): - { - double d = *(double*)(l_fp - asBC_SWORDARG1(l_bc)); - if (d < 0) + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_STOREOBJ) : // Move the object pointer from the object register to the object variable + *(asPWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = asPWORD(m_regs.objectRegister); + m_regs.objectRegister = 0; + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_GETOBJ) : { - // For consistency across compilers and target systems we must cast to int first, - // because on some compilers the cast of a negative float value to uint result in 0 - *(l_fp - asBC_SWORDARG0(l_bc)) = asUINT(int(d)); + // Read variable index from location on stack + asPWORD *a = (asPWORD *)(l_sp + asBC_WORDARG0(l_bc)); + asPWORD offset = *a; + // Move pointer from variable to the same location on the stack + asPWORD *v = (asPWORD *)(l_fp - offset); + *a = *v; + // Clear variable + *v = 0; } - else - *(l_fp - asBC_SWORDARG0(l_bc)) = asUINT(d); - } - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_dTOf): - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = float(*(double*)(l_fp - asBC_SWORDARG1(l_bc))); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_iTOd): - *(double*)(l_fp - asBC_SWORDARG0(l_bc)) = double(*(int*)(l_fp - asBC_SWORDARG1(l_bc))); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_uTOd): - *(double*)(l_fp - asBC_SWORDARG0(l_bc)) = double(*(asUINT*)(l_fp - asBC_SWORDARG1(l_bc))); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_fTOd): - *(double*)(l_fp - asBC_SWORDARG0(l_bc)) = double(*(float*)(l_fp - asBC_SWORDARG1(l_bc))); - l_bc += 2; - NEXT_INSTRUCTION(); - - //------------------------------ - // Math operations - INSTRUCTION(asBC_ADDi): - *(int*)(l_fp - asBC_SWORDARG0(l_bc)) = *(int*)(l_fp - asBC_SWORDARG1(l_bc)) + *(int*)(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_SUBi): - *(int*)(l_fp - asBC_SWORDARG0(l_bc)) = *(int*)(l_fp - asBC_SWORDARG1(l_bc)) - *(int*)(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_MULi): - *(int*)(l_fp - asBC_SWORDARG0(l_bc)) = *(int*)(l_fp - asBC_SWORDARG1(l_bc)) * *(int*)(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_DIVi): - { - int divider = *(int*)(l_fp - asBC_SWORDARG2(l_bc)); - if( divider == 0 ) + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_REFCPY) : { - // Need to move the values back to the context + asCObjectType *objType = (asCObjectType *)asBC_PTRARG(l_bc); + asSTypeBehaviour *beh = &objType->beh; + + // Pop address of destination pointer from the stack + void **d = (void **)*(asPWORD *)l_sp; + l_sp += AS_PTR_SIZE; + + // Read wanted pointer from the stack + void *s = (void *)*(asPWORD *)l_sp; + + // Need to move the values back to the context as the called functions + // may use the debug interface to inspect the registers m_regs.programPointer = l_bc; m_regs.stackPointer = l_sp; m_regs.stackFramePointer = l_fp; - // Raise exception - SetInternalException(TXT_DIVIDE_BY_ZERO); - return; + // Update ref counter for object types that require it + if( !(objType->flags & (asOBJ_NOCOUNT | asOBJ_VALUE)) ) + { + // Release previous object held by destination pointer + if( *d != 0 && beh->release ) + m_engine->CallObjectMethod(*d, beh->release); + // Increase ref counter of wanted object + if( s != 0 && beh->addref ) + m_engine->CallObjectMethod(s, beh->addref); + } + + // Set the new object in the destination + *d = s; } - else if( divider == -1 ) + l_bc += 1 + AS_PTR_SIZE; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_CHKREF) : { - // Need to check if the value that is divided is 0x80000000 - // as dividing it with -1 will cause an overflow exception - if( *(int*)(l_fp - asBC_SWORDARG1(l_bc)) == int(0x80000000) ) + // Verify if the pointer on the stack is null + // This is used when validating a pointer that an operator will work on + asPWORD a = *(asPWORD *)l_sp; + if( a == 0 ) { - // Need to move the values back to the context m_regs.programPointer = l_bc; m_regs.stackPointer = l_sp; m_regs.stackFramePointer = l_fp; - // Raise exception - SetInternalException(TXT_DIVIDE_OVERFLOW); + SetInternalException(TXT_NULL_POINTER_ACCESS); return; } } - *(int*)(l_fp - asBC_SWORDARG0(l_bc)) = *(int*)(l_fp - asBC_SWORDARG1(l_bc)) / divider; - } - l_bc += 2; - NEXT_INSTRUCTION(); + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_MODi): - { - int divider = *(int*)(l_fp - asBC_SWORDARG2(l_bc)); - if( divider == 0 ) + INSTRUCTION(asBC_GETOBJREF) : { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + // Get the location on the stack where the reference will be placed + asPWORD *a = (asPWORD *)(l_sp + asBC_WORDARG0(l_bc)); + + // Replace the variable index with the object handle held in the variable + *(asPWORD **)a = *(asPWORD **)(l_fp - *a); + } + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_GETREF) : + { + // Get the location on the stack where the reference will be placed + asPWORD *a = (asPWORD *)(l_sp + asBC_WORDARG0(l_bc)); - // Raise exception - SetInternalException(TXT_DIVIDE_BY_ZERO); - return; + // Replace the variable index with the address of the variable + *(asPWORD **)a = (asPWORD *)(l_fp - (int)*a); } - else if( divider == -1 ) + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_PshNull) : // Push a null pointer on the stack + l_sp -= AS_PTR_SIZE; + *(asPWORD *)l_sp = 0; + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_ClrVPtr) : // TODO: runtime optimize: Is this instruction really necessary? + // CallScriptFunction() can clear the null handles upon entry, just as is done for + // all other object variables + // Clear pointer variable + *(asPWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = 0; + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_OBJTYPE) : // Push the object type on the stack + l_sp -= AS_PTR_SIZE; + *(asPWORD *)l_sp = asBC_PTRARG(l_bc); + l_bc += 1 + AS_PTR_SIZE; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_TYPEID) : // Equivalent to PshC4, but kept as separate instruction for bytecode serialization + --l_sp; + *l_sp = asBC_DWORDARG(l_bc); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_SetV4) : *(l_fp - asBC_SWORDARG0(l_bc)) = asBC_DWORDARG(l_bc); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_SetV8) : *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = asBC_QWORDARG(l_bc); + l_bc += 3; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_ADDSi) : { - // Need to check if the value that is divided is 0x80000000 - // as dividing it with -1 will cause an overflow exception - if( *(int*)(l_fp - asBC_SWORDARG1(l_bc)) == int(0x80000000) ) + // The pointer must not be null + asPWORD a = *(asPWORD *)l_sp; + if( a == 0 ) { - // Need to move the values back to the context m_regs.programPointer = l_bc; m_regs.stackPointer = l_sp; m_regs.stackFramePointer = l_fp; - // Raise exception - SetInternalException(TXT_DIVIDE_OVERFLOW); + SetInternalException(TXT_NULL_POINTER_ACCESS); return; } + // Add an offset to the pointer + *(asPWORD *)l_sp = a + asBC_SWORDARG0(l_bc); } - *(int*)(l_fp - asBC_SWORDARG0(l_bc)) = *(int*)(l_fp - asBC_SWORDARG1(l_bc)) % divider; - } - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_ADDf): - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = *(float*)(l_fp - asBC_SWORDARG1(l_bc)) + *(float*)(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); + l_bc += 2; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_SUBf): - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = *(float*)(l_fp - asBC_SWORDARG1(l_bc)) - *(float*)(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_CpyVtoV4) : *(l_fp - asBC_SWORDARG0(l_bc)) = *(l_fp - asBC_SWORDARG1(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_MULf): - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = *(float*)(l_fp - asBC_SWORDARG1(l_bc)) * *(float*)(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_CpyVtoV8) : *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD *)(l_fp - asBC_SWORDARG1(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_DIVf): - { - float divider = *(float*)(l_fp - asBC_SWORDARG2(l_bc)); - if( divider == 0 ) - { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + INSTRUCTION(asBC_CpyVtoR4) : *(asDWORD *)&m_regs.valueRegister = *(asDWORD *)(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); - // Raise exception - SetInternalException(TXT_DIVIDE_BY_ZERO); - return; - } - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = *(float*)(l_fp - asBC_SWORDARG1(l_bc)) / divider; - } - l_bc += 2; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_CpyVtoR8) : *(asQWORD *)&m_regs.valueRegister = *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_MODf): - { - float divider = *(float*)(l_fp - asBC_SWORDARG2(l_bc)); - if( divider == 0 ) - { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + INSTRUCTION(asBC_CpyVtoG4) : *(asDWORD *)asBC_PTRARG(l_bc) = *(asDWORD *)(l_fp - asBC_SWORDARG0(l_bc)); + l_bc += 1 + AS_PTR_SIZE; + NEXT_INSTRUCTION(); - // Raise exception - SetInternalException(TXT_DIVIDE_BY_ZERO); - return; - } - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = fmodf(*(float*)(l_fp - asBC_SWORDARG1(l_bc)), divider); - } - l_bc += 2; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_CpyRtoV4) : *(asDWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asDWORD *)&m_regs.valueRegister; + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_ADDd): - *(double*)(l_fp - asBC_SWORDARG0(l_bc)) = *(double*)(l_fp - asBC_SWORDARG1(l_bc)) + *(double*)(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_CpyRtoV8) : *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = m_regs.valueRegister; + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_SUBd): - *(double*)(l_fp - asBC_SWORDARG0(l_bc)) = *(double*)(l_fp - asBC_SWORDARG1(l_bc)) - *(double*)(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_CpyGtoV4) : *(asDWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asDWORD *)asBC_PTRARG(l_bc); + l_bc += 1 + AS_PTR_SIZE; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_MULd): - *(double*)(l_fp - asBC_SWORDARG0(l_bc)) = *(double*)(l_fp - asBC_SWORDARG1(l_bc)) * *(double*)(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_WRTV1) : // The pointer in the register points to a byte, and *(l_fp - offset) too + **(asBYTE **)&m_regs.valueRegister = *(asBYTE *)(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_DIVd): - { - double divider = *(double*)(l_fp - asBC_SWORDARG2(l_bc)); - if( divider == 0 ) - { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + INSTRUCTION(asBC_WRTV2) : // The pointer in the register points to a word, and *(l_fp - offset) too + **(asWORD **)&m_regs.valueRegister = *(asWORD *)(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); - // Raise exception - SetInternalException(TXT_DIVIDE_BY_ZERO); - return; - } + INSTRUCTION(asBC_WRTV4) : **(asDWORD **)&m_regs.valueRegister = *(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); - *(double*)(l_fp - asBC_SWORDARG0(l_bc)) = *(double*)(l_fp - asBC_SWORDARG1(l_bc)) / divider; - l_bc += 2; - } - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_WRTV8) : **(asQWORD **)&m_regs.valueRegister = *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_MODd): - { - double divider = *(double*)(l_fp - asBC_SWORDARG2(l_bc)); - if( divider == 0 ) + INSTRUCTION(asBC_RDR1) : { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; - - // Raise exception - SetInternalException(TXT_DIVIDE_BY_ZERO); - return; + // The pointer in the register points to a byte, and *(l_fp - offset) will also point to a byte + asBYTE *bPtr = (asBYTE *)(l_fp - asBC_SWORDARG0(l_bc)); + bPtr[0] = **(asBYTE **)&m_regs.valueRegister; // read the byte + bPtr[1] = 0; // 0 the rest of the DWORD + bPtr[2] = 0; + bPtr[3] = 0; } + l_bc++; + NEXT_INSTRUCTION(); - *(double*)(l_fp - asBC_SWORDARG0(l_bc)) = fmod(*(double*)(l_fp - asBC_SWORDARG1(l_bc)), divider); - l_bc += 2; - } - NEXT_INSTRUCTION(); - - //------------------------------ - // Math operations with constant value - INSTRUCTION(asBC_ADDIi): - *(int*)(l_fp - asBC_SWORDARG0(l_bc)) = *(int*)(l_fp - asBC_SWORDARG1(l_bc)) + asBC_INTARG(l_bc+1); - l_bc += 3; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_SUBIi): - *(int*)(l_fp - asBC_SWORDARG0(l_bc)) = *(int*)(l_fp - asBC_SWORDARG1(l_bc)) - asBC_INTARG(l_bc+1); - l_bc += 3; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_MULIi): - *(int*)(l_fp - asBC_SWORDARG0(l_bc)) = *(int*)(l_fp - asBC_SWORDARG1(l_bc)) * asBC_INTARG(l_bc+1); - l_bc += 3; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_ADDIf): - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = *(float*)(l_fp - asBC_SWORDARG1(l_bc)) + asBC_FLOATARG(l_bc+1); - l_bc += 3; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_SUBIf): - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = *(float*)(l_fp - asBC_SWORDARG1(l_bc)) - asBC_FLOATARG(l_bc+1); - l_bc += 3; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_MULIf): - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = *(float*)(l_fp - asBC_SWORDARG1(l_bc)) * asBC_FLOATARG(l_bc+1); - l_bc += 3; - NEXT_INSTRUCTION(); - - //----------------------------------- - INSTRUCTION(asBC_SetG4): - *(asDWORD*)asBC_PTRARG(l_bc) = asBC_DWORDARG(l_bc+AS_PTR_SIZE); - l_bc += 2 + AS_PTR_SIZE; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_ChkRefS): - { - // Verify if the pointer on the stack refers to a non-null value - // This is used to validate a reference to a handle - asPWORD *a = (asPWORD*)*(asPWORD*)l_sp; - if( *a == 0 ) + INSTRUCTION(asBC_RDR2) : { - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; - - SetInternalException(TXT_NULL_POINTER_ACCESS); - return; + // The pointer in the register points to a word, and *(l_fp - offset) will also point to a word + asWORD *wPtr = (asWORD *)(l_fp - asBC_SWORDARG0(l_bc)); + wPtr[0] = **(asWORD **)&m_regs.valueRegister; // read the word + wPtr[1] = 0; // 0 the rest of the DWORD } - } - l_bc++; - NEXT_INSTRUCTION(); + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_ChkNullV): - { - // Verify if variable (on the stack) is not null - asDWORD *a = *(asDWORD**)(l_fp - asBC_SWORDARG0(l_bc)); - if( a == 0 ) - { - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + INSTRUCTION(asBC_RDR4) : *(asDWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = **(asDWORD **)&m_regs.valueRegister; + l_bc++; + NEXT_INSTRUCTION(); - SetInternalException(TXT_NULL_POINTER_ACCESS); - return; - } - } - l_bc++; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_RDR8) : *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = **(asQWORD **)&m_regs.valueRegister; + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_CALLINTF): - { - int i = asBC_INTARG(l_bc); - l_bc += 2; + INSTRUCTION(asBC_LDG) : *(asPWORD *)&m_regs.valueRegister = asBC_PTRARG(l_bc); + l_bc += 1 + AS_PTR_SIZE; + NEXT_INSTRUCTION(); - asASSERT( i >= 0 ); - asASSERT( (i & FUNC_IMPORTED) == 0 ); + INSTRUCTION(asBC_LDV) : *(asDWORD **)&m_regs.valueRegister = (l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + INSTRUCTION(asBC_PGA) : l_sp -= AS_PTR_SIZE; + *(asPWORD *)l_sp = asBC_PTRARG(l_bc); + l_bc += 1 + AS_PTR_SIZE; + NEXT_INSTRUCTION(); - CallInterfaceMethod(m_engine->GetScriptFunction(i)); + INSTRUCTION(asBC_CmpPtr) : + { + // TODO: runtime optimize: This instruction should really just be an equals, and return true or false. + // The instruction is only used for is and !is tests anyway. + asPWORD p1 = *(asPWORD *)(l_fp - asBC_SWORDARG0(l_bc)); + asPWORD p2 = *(asPWORD *)(l_fp - asBC_SWORDARG1(l_bc)); + if( p1 == p2 ) *(int *)&m_regs.valueRegister = 0; + else if( p1 < p2 ) *(int *)&m_regs.valueRegister = -1; + else *(int *)&m_regs.valueRegister = 1; + l_bc += 2; + } + NEXT_INSTRUCTION(); - // Extract the values from the context again - l_bc = m_regs.programPointer; - l_sp = m_regs.stackPointer; - l_fp = m_regs.stackFramePointer; + INSTRUCTION(asBC_VAR) : l_sp -= AS_PTR_SIZE; + *(asPWORD *)l_sp = (asPWORD)asBC_SWORDARG0(l_bc); + l_bc++; + NEXT_INSTRUCTION(); - // If status isn't active anymore then we must stop - if( m_status != asEXECUTION_ACTIVE ) - return; - } - NEXT_INSTRUCTION(); + //---------------------------- + // Type conversions + INSTRUCTION(asBC_iTOf) : *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = float(*(int *)(l_fp - asBC_SWORDARG0(l_bc))); + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_iTOb): - { - // *(l_fp - offset) points to an int, and will point to a byte afterwards - - // We need to use volatile here to tell the compiler not to rearrange - // read and write operations during optimizations. - volatile asDWORD val = *(l_fp - asBC_SWORDARG0(l_bc)); - volatile asBYTE *bPtr = (asBYTE*)(l_fp - asBC_SWORDARG0(l_bc)); - bPtr[0] = (asBYTE)val; // write the byte - bPtr[1] = 0; // 0 the rest of the DWORD - bPtr[2] = 0; - bPtr[3] = 0; - } - l_bc++; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_fTOi) : *(l_fp - asBC_SWORDARG0(l_bc)) = int(*(float *)(l_fp - asBC_SWORDARG0(l_bc))); + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_iTOw): - { - // *(l_fp - offset) points to an int, and will point to word afterwards - - // We need to use volatile here to tell the compiler not to rearrange - // read and write operations during optimizations. - volatile asDWORD val = *(l_fp - asBC_SWORDARG0(l_bc)); - volatile asWORD *wPtr = (asWORD*)(l_fp - asBC_SWORDARG0(l_bc)); - wPtr[0] = (asWORD)val; // write the word - wPtr[1] = 0; // 0 the rest of the DWORD - } - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_SetV1): - // TODO: This is exactly the same as SetV4. This is a left over from the time - // when the bytecode instructions were more tightly packed. It can now - // be removed. When removing it, make sure the value is correctly converted - // on big-endian CPUs. - - // The byte is already stored correctly in the argument - *(l_fp - asBC_SWORDARG0(l_bc)) = asBC_DWORDARG(l_bc); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_SetV2): - // TODO: This is exactly the same as SetV4. This is a left over from the time - // when the bytecode instructions were more tightly packed. It can now - // be removed. When removing it, make sure the value is correctly converted - // on big-endian CPUs. - - // The word is already stored correctly in the argument - *(l_fp - asBC_SWORDARG0(l_bc)) = asBC_DWORDARG(l_bc); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_Cast): - // Cast the handle at the top of the stack to the type in the argument - { - asDWORD **a = (asDWORD**)*(asPWORD*)l_sp; - if( a && *a ) + INSTRUCTION(asBC_uTOf) : *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = float(*(l_fp - asBC_SWORDARG0(l_bc))); + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_fTOu) : { - asDWORD typeId = asBC_DWORDARG(l_bc); + float f = *(float *)(l_fp - asBC_SWORDARG0(l_bc)); + if( f < 0 ) + { + // For consistency across compilers and target systems we must cast to int first, + // because on some compilers the cast of a negative float value to uint result in 0 + *(l_fp - asBC_SWORDARG0(l_bc)) = asUINT(int(f)); + } + else + *(l_fp - asBC_SWORDARG0(l_bc)) = asUINT(f); + } + l_bc++; + NEXT_INSTRUCTION(); - asCScriptObject *obj = (asCScriptObject *)* a; - asCObjectType *objType = obj->objType; - asCObjectType *to = m_engine->GetObjectTypeFromTypeId(typeId); + INSTRUCTION(asBC_sbTOi) : // *(l_fp - offset) points to a char, and will point to an int afterwards + *(l_fp - asBC_SWORDARG0(l_bc)) = *(signed char *)(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); - // This instruction can only be used with script classes and interfaces - asASSERT( objType->flags & asOBJ_SCRIPT_OBJECT ); - asASSERT( to->flags & asOBJ_SCRIPT_OBJECT ); + INSTRUCTION(asBC_swTOi) : // *(l_fp - offset) points to a short, and will point to an int afterwards + *(l_fp - asBC_SWORDARG0(l_bc)) = *(short *)(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_ubTOi) : // (l_fp - offset) points to a byte, and will point to an int afterwards + *(l_fp - asBC_SWORDARG0(l_bc)) = *(asBYTE *)(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); - if( objType->Implements(to) || objType->DerivesFrom(to) ) + INSTRUCTION(asBC_uwTOi) : // *(l_fp - offset) points to a word, and will point to an int afterwards + *(l_fp - asBC_SWORDARG0(l_bc)) = *(asWORD *)(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_dTOi) : *(l_fp - asBC_SWORDARG0(l_bc)) = int(*(double *)(l_fp - asBC_SWORDARG1(l_bc))); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_dTOu) : + { + double d = *(double *)(l_fp - asBC_SWORDARG1(l_bc)); + if( d < 0 ) { - m_regs.objectType = 0; - m_regs.objectRegister = obj; - obj->AddRef(); + // For consistency across compilers and target systems we must cast to int first, + // because on some compilers the cast of a negative float value to uint result in 0 + *(l_fp - asBC_SWORDARG0(l_bc)) = asUINT(int(d)); } else - { - // The object register should already be null, so there - // is no need to clear it if the cast is unsuccessful - asASSERT( m_regs.objectRegister == 0 ); - } + *(l_fp - asBC_SWORDARG0(l_bc)) = asUINT(d); } - l_sp += AS_PTR_SIZE; - } - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_i64TOi): - *(l_fp - asBC_SWORDARG0(l_bc)) = int(*(asINT64*)(l_fp - asBC_SWORDARG1(l_bc))); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_uTOi64): - *(asINT64*)(l_fp - asBC_SWORDARG0(l_bc)) = asINT64(*(asUINT*)(l_fp - asBC_SWORDARG1(l_bc))); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_iTOi64): - *(asINT64*)(l_fp - asBC_SWORDARG0(l_bc)) = asINT64(*(int*)(l_fp - asBC_SWORDARG1(l_bc))); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_fTOi64): - *(asINT64*)(l_fp - asBC_SWORDARG0(l_bc)) = asINT64(*(float*)(l_fp - asBC_SWORDARG1(l_bc))); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_dTOi64): - *(asINT64*)(l_fp - asBC_SWORDARG0(l_bc)) = asINT64(*(double*)(l_fp - asBC_SWORDARG0(l_bc))); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_fTOu64): - { - float f = *(float*)(l_fp - asBC_SWORDARG1(l_bc)); - if (f < 0) + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_dTOf) : *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = float(*(double *)(l_fp - asBC_SWORDARG1(l_bc))); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_iTOd) : *(double *)(l_fp - asBC_SWORDARG0(l_bc)) = double(*(int *)(l_fp - asBC_SWORDARG1(l_bc))); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_uTOd) : *(double *)(l_fp - asBC_SWORDARG0(l_bc)) = double(*(asUINT *)(l_fp - asBC_SWORDARG1(l_bc))); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_fTOd) : *(double *)(l_fp - asBC_SWORDARG0(l_bc)) = double(*(float *)(l_fp - asBC_SWORDARG1(l_bc))); + l_bc += 2; + NEXT_INSTRUCTION(); + + //------------------------------ + // Math operations + INSTRUCTION(asBC_ADDi) : *(int *)(l_fp - asBC_SWORDARG0(l_bc)) = *(int *)(l_fp - asBC_SWORDARG1(l_bc)) + *(int *)(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_SUBi) : *(int *)(l_fp - asBC_SWORDARG0(l_bc)) = *(int *)(l_fp - asBC_SWORDARG1(l_bc)) - *(int *)(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_MULi) : *(int *)(l_fp - asBC_SWORDARG0(l_bc)) = *(int *)(l_fp - asBC_SWORDARG1(l_bc)) * *(int *)(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_DIVi) : { - // For consistency across compilers and target systems we must cast to int first, - // because on some compilers the cast of a negative float value to uint result in 0 - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = asQWORD(asINT64(f)); + int divider = *(int *)(l_fp - asBC_SWORDARG2(l_bc)); + if( divider == 0 ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; + + // Raise exception + SetInternalException(TXT_DIVIDE_BY_ZERO); + return; + } + else if( divider == -1 ) + { + // Need to check if the value that is divided is 0x80000000 + // as dividing it with -1 will cause an overflow exception + if( *(int *)(l_fp - asBC_SWORDARG1(l_bc)) == int(0x80000000) ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; + + // Raise exception + SetInternalException(TXT_DIVIDE_OVERFLOW); + return; + } + } + *(int *)(l_fp - asBC_SWORDARG0(l_bc)) = *(int *)(l_fp - asBC_SWORDARG1(l_bc)) / divider; } - else - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = asQWORD(f); - } - l_bc += 2; - NEXT_INSTRUCTION(); + l_bc += 2; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_dTOu64): - { - double d = *(double*)(l_fp - asBC_SWORDARG0(l_bc)); - if (d < 0) + INSTRUCTION(asBC_MODi) : { - // For consistency across compilers and target systems we must cast to int first, - // because on some compilers the cast of a negative float value to uint result in 0 - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = asQWORD(asINT64(d)); + int divider = *(int *)(l_fp - asBC_SWORDARG2(l_bc)); + if( divider == 0 ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; + + // Raise exception + SetInternalException(TXT_DIVIDE_BY_ZERO); + return; + } + else if( divider == -1 ) + { + // Need to check if the value that is divided is 0x80000000 + // as dividing it with -1 will cause an overflow exception + if( *(int *)(l_fp - asBC_SWORDARG1(l_bc)) == int(0x80000000) ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; + + // Raise exception + SetInternalException(TXT_DIVIDE_OVERFLOW); + return; + } + } + *(int *)(l_fp - asBC_SWORDARG0(l_bc)) = *(int *)(l_fp - asBC_SWORDARG1(l_bc)) % divider; } - else - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = asQWORD(d); - } - l_bc++; - NEXT_INSTRUCTION(); + l_bc += 2; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_i64TOf): - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = float(*(asINT64*)(l_fp - asBC_SWORDARG1(l_bc))); - l_bc += 2; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_ADDf) : *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = *(float *)(l_fp - asBC_SWORDARG1(l_bc)) + *(float *)(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_u64TOf): -#if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC6 - { - // MSVC6 doesn't permit UINT64 to double - asINT64 v = *(asINT64*)(l_fp - asBC_SWORDARG1(l_bc)); - if( v < 0 ) - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = 18446744073709551615.0f+float(v); - else - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = float(v); - } -#else - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = float(*(asQWORD*)(l_fp - asBC_SWORDARG1(l_bc))); -#endif - l_bc += 2; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_SUBf) : *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = *(float *)(l_fp - asBC_SWORDARG1(l_bc)) - *(float *)(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_i64TOd): - *(double*)(l_fp - asBC_SWORDARG0(l_bc)) = double(*(asINT64*)(l_fp - asBC_SWORDARG0(l_bc))); - l_bc++; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_MULf) : *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = *(float *)(l_fp - asBC_SWORDARG1(l_bc)) * *(float *)(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_u64TOd): -#if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC6 - { - // MSVC6 doesn't permit UINT64 to double - asINT64 v = *(asINT64*)(l_fp - asBC_SWORDARG0(l_bc)); - if( v < 0 ) - *(double*)(l_fp - asBC_SWORDARG0(l_bc)) = 18446744073709551615.0+double(v); - else - *(double*)(l_fp - asBC_SWORDARG0(l_bc)) = double(v); - } -#else - *(double*)(l_fp - asBC_SWORDARG0(l_bc)) = double(*(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc))); -#endif - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_NEGi64): - *(asINT64*)(l_fp - asBC_SWORDARG0(l_bc)) = -*(asINT64*)(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_INCi64): - ++(**(asQWORD**)&m_regs.valueRegister); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_DECi64): - --(**(asQWORD**)&m_regs.valueRegister); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_BNOT64): - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = ~*(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_ADDi64): - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD*)(l_fp - asBC_SWORDARG1(l_bc)) + *(asQWORD*)(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_SUBi64): - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD*)(l_fp - asBC_SWORDARG1(l_bc)) - *(asQWORD*)(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_MULi64): - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD*)(l_fp - asBC_SWORDARG1(l_bc)) * *(asQWORD*)(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_DIVi64): - { - asINT64 divider = *(asINT64*)(l_fp - asBC_SWORDARG2(l_bc)); - if( divider == 0 ) + INSTRUCTION(asBC_DIVf) : { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + float divider = *(float *)(l_fp - asBC_SWORDARG2(l_bc)); + if( divider == 0 ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - // Raise exception - SetInternalException(TXT_DIVIDE_BY_ZERO); - return; + // Raise exception + SetInternalException(TXT_DIVIDE_BY_ZERO); + return; + } + *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = *(float *)(l_fp - asBC_SWORDARG1(l_bc)) / divider; } - else if( divider == -1 ) + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_MODf) : { - // Need to check if the value that is divided is 1<<63 - // as dividing it with -1 will cause an overflow exception - if( *(asINT64*)(l_fp - asBC_SWORDARG1(l_bc)) == (asINT64(1)<<63) ) + float divider = *(float *)(l_fp - asBC_SWORDARG2(l_bc)); + if( divider == 0 ) { // Need to move the values back to the context m_regs.programPointer = l_bc; @@ -4192,35 +3694,50 @@ static const void *const dispatch_table[256] = { m_regs.stackFramePointer = l_fp; // Raise exception - SetInternalException(TXT_DIVIDE_OVERFLOW); + SetInternalException(TXT_DIVIDE_BY_ZERO); return; } + *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = fmodf(*(float *)(l_fp - asBC_SWORDARG1(l_bc)), divider); } + l_bc += 2; + NEXT_INSTRUCTION(); - *(asINT64*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asINT64*)(l_fp - asBC_SWORDARG1(l_bc)) / divider; - } - l_bc += 2; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_ADDd) : *(double *)(l_fp - asBC_SWORDARG0(l_bc)) = *(double *)(l_fp - asBC_SWORDARG1(l_bc)) + *(double *)(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_MODi64): - { - asINT64 divider = *(asINT64*)(l_fp - asBC_SWORDARG2(l_bc)); - if( divider == 0 ) + INSTRUCTION(asBC_SUBd) : *(double *)(l_fp - asBC_SWORDARG0(l_bc)) = *(double *)(l_fp - asBC_SWORDARG1(l_bc)) - *(double *)(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_MULd) : *(double *)(l_fp - asBC_SWORDARG0(l_bc)) = *(double *)(l_fp - asBC_SWORDARG1(l_bc)) * *(double *)(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_DIVd) : { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + double divider = *(double *)(l_fp - asBC_SWORDARG2(l_bc)); + if( divider == 0 ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; + + // Raise exception + SetInternalException(TXT_DIVIDE_BY_ZERO); + return; + } - // Raise exception - SetInternalException(TXT_DIVIDE_BY_ZERO); - return; + *(double *)(l_fp - asBC_SWORDARG0(l_bc)) = *(double *)(l_fp - asBC_SWORDARG1(l_bc)) / divider; + l_bc += 2; } - else if( divider == -1 ) + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_MODd) : { - // Need to check if the value that is divided is 1<<63 - // as dividing it with -1 will cause an overflow exception - if( *(asINT64*)(l_fp - asBC_SWORDARG1(l_bc)) == (asINT64(1)<<63) ) + double divider = *(double *)(l_fp - asBC_SWORDARG2(l_bc)); + if( divider == 0 ) { // Need to move the values back to the context m_regs.programPointer = l_bc; @@ -4228,800 +3745,1207 @@ static const void *const dispatch_table[256] = { m_regs.stackFramePointer = l_fp; // Raise exception - SetInternalException(TXT_DIVIDE_OVERFLOW); + SetInternalException(TXT_DIVIDE_BY_ZERO); return; } + + *(double *)(l_fp - asBC_SWORDARG0(l_bc)) = fmod(*(double *)(l_fp - asBC_SWORDARG1(l_bc)), divider); + l_bc += 2; } - *(asINT64*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asINT64*)(l_fp - asBC_SWORDARG1(l_bc)) % divider; - } - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_BAND64): - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD*)(l_fp - asBC_SWORDARG1(l_bc)) & *(asQWORD*)(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_BOR64): - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD*)(l_fp - asBC_SWORDARG1(l_bc)) | *(asQWORD*)(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_BXOR64): - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD*)(l_fp - asBC_SWORDARG1(l_bc)) ^ *(asQWORD*)(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_BSLL64): - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD*)(l_fp - asBC_SWORDARG1(l_bc)) << *(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_BSRL64): - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD*)(l_fp - asBC_SWORDARG1(l_bc)) >> *(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_BSRA64): - *(asINT64*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asINT64*)(l_fp - asBC_SWORDARG1(l_bc)) >> *(l_fp - asBC_SWORDARG2(l_bc)); - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_CMPi64): - { - asINT64 i1 = *(asINT64*)(l_fp - asBC_SWORDARG0(l_bc)); - asINT64 i2 = *(asINT64*)(l_fp - asBC_SWORDARG1(l_bc)); - if( i1 == i2 ) *(int*)&m_regs.valueRegister = 0; - else if( i1 < i2 ) *(int*)&m_regs.valueRegister = -1; - else *(int*)&m_regs.valueRegister = 1; - l_bc += 2; - } - NEXT_INSTRUCTION(); + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_CMPu64): - { - asQWORD d1 = *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)); - asQWORD d2 = *(asQWORD*)(l_fp - asBC_SWORDARG1(l_bc)); - if( d1 == d2 ) *(int*)&m_regs.valueRegister = 0; - else if( d1 < d2 ) *(int*)&m_regs.valueRegister = -1; - else *(int*)&m_regs.valueRegister = 1; - l_bc += 2; - } - NEXT_INSTRUCTION(); + //------------------------------ + // Math operations with constant value + INSTRUCTION(asBC_ADDIi) : *(int *)(l_fp - asBC_SWORDARG0(l_bc)) = *(int *)(l_fp - asBC_SWORDARG1(l_bc)) + asBC_INTARG(l_bc + 1); + l_bc += 3; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_ChkNullS): - { - // Verify if the pointer on the stack is null - // This is used for example when validating handles passed as function arguments - asPWORD a = *(asPWORD*)(l_sp + asBC_WORDARG0(l_bc)); - if( a == 0 ) - { - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + INSTRUCTION(asBC_SUBIi) : *(int *)(l_fp - asBC_SWORDARG0(l_bc)) = *(int *)(l_fp - asBC_SWORDARG1(l_bc)) - asBC_INTARG(l_bc + 1); + l_bc += 3; + NEXT_INSTRUCTION(); - SetInternalException(TXT_NULL_POINTER_ACCESS); - return; - } - } - l_bc++; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_MULIi) : *(int *)(l_fp - asBC_SWORDARG0(l_bc)) = *(int *)(l_fp - asBC_SWORDARG1(l_bc)) * asBC_INTARG(l_bc + 1); + l_bc += 3; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_ClrHi): -#if AS_SIZEOF_BOOL == 1 - { - // Clear the upper bytes, so that trash data don't interfere with boolean operations + INSTRUCTION(asBC_ADDIf) : *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = *(float *)(l_fp - asBC_SWORDARG1(l_bc)) + asBC_FLOATARG(l_bc + 1); + l_bc += 3; + NEXT_INSTRUCTION(); - // We need to use volatile here to tell the compiler it cannot - // change the order of read and write operations on the pointer. + INSTRUCTION(asBC_SUBIf) : *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = *(float *)(l_fp - asBC_SWORDARG1(l_bc)) - asBC_FLOATARG(l_bc + 1); + l_bc += 3; + NEXT_INSTRUCTION(); - volatile asBYTE *ptr = (asBYTE*)&m_regs.valueRegister; - ptr[1] = 0; // The boolean value is stored in the lower byte, so we clear the rest - ptr[2] = 0; - ptr[3] = 0; - } -#else - // We don't have anything to do here -#endif - l_bc++; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_MULIf) : *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = *(float *)(l_fp - asBC_SWORDARG1(l_bc)) * asBC_FLOATARG(l_bc + 1); + l_bc += 3; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_JitEntry): - { - if( m_currentFunction->scriptData->jitFunction ) - { - asPWORD jitArg = asBC_PTRARG(l_bc); + //----------------------------------- + INSTRUCTION(asBC_SetG4) : *(asDWORD *)asBC_PTRARG(l_bc) = asBC_DWORDARG(l_bc + AS_PTR_SIZE); + l_bc += 2 + AS_PTR_SIZE; + NEXT_INSTRUCTION(); - if( jitArg ) + INSTRUCTION(asBC_ChkRefS) : + { + // Verify if the pointer on the stack refers to a non-null value + // This is used to validate a reference to a handle + asPWORD *a = (asPWORD *)*(asPWORD *)l_sp; + if( *a == 0 ) { - // Resume JIT operation m_regs.programPointer = l_bc; m_regs.stackPointer = l_sp; m_regs.stackFramePointer = l_fp; - (m_currentFunction->scriptData->jitFunction)(&m_regs, jitArg); - - l_bc = m_regs.programPointer; - l_sp = m_regs.stackPointer; - l_fp = m_regs.stackFramePointer; + SetInternalException(TXT_NULL_POINTER_ACCESS); + return; + } + } + l_bc++; + NEXT_INSTRUCTION(); - // If status isn't active anymore then we must stop - if( m_status != asEXECUTION_ACTIVE ) - return; + INSTRUCTION(asBC_ChkNullV) : + { + // Verify if variable (on the stack) is not null + asDWORD *a = *(asDWORD **)(l_fp - asBC_SWORDARG0(l_bc)); + if( a == 0 ) + { + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - NEXT_INSTRUCTION(); + SetInternalException(TXT_NULL_POINTER_ACCESS); + return; } } + l_bc++; + NEXT_INSTRUCTION(); - // Not a JIT resume point, treat as nop - l_bc += 1+AS_PTR_SIZE; - } - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_CALLINTF) : + { + int i = asBC_INTARG(l_bc); + l_bc += 2; - INSTRUCTION(asBC_CallPtr): - { - // Get the function pointer from the local variable - asCScriptFunction *func = *(asCScriptFunction**)(l_fp - asBC_SWORDARG1(l_bc)); + asASSERT( i >= 0 ); + asASSERT( (i & FUNC_IMPORTED) == 0 ); + + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + CallInterfaceMethod(m_engine->GetScriptFunction(i)); - if( func == 0 ) - { - // Need to update the program pointer anyway for the exception handler - m_regs.programPointer += 2; + // Extract the values from the context again + l_bc = m_regs.programPointer; + l_sp = m_regs.stackPointer; + l_fp = m_regs.stackFramePointer; - // Tell the exception handler to clean up the arguments to this method - m_needToCleanupArgs = true; + // If status isn't active anymore then we must stop + if( m_status != asEXECUTION_ACTIVE ) + return; + } + NEXT_INSTRUCTION(); - // TODO: funcdef: Should we have a different exception string? - SetInternalException(TXT_UNBOUND_FUNCTION); - return; + INSTRUCTION(asBC_iTOb) : + { + // *(l_fp - offset) points to an int, and will point to a byte afterwards + + // We need to use volatile here to tell the compiler not to rearrange + // read and write operations during optimizations. + volatile asDWORD val = *(l_fp - asBC_SWORDARG0(l_bc)); + volatile asBYTE *bPtr = (asBYTE *)(l_fp - asBC_SWORDARG0(l_bc)); + bPtr[0] = (asBYTE)val; // write the byte + bPtr[1] = 0; // 0 the rest of the DWORD + bPtr[2] = 0; + bPtr[3] = 0; } - else + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_iTOw) : { - if (func->funcType == asFUNC_SCRIPT) - { - m_regs.programPointer += 2; - CallScriptFunction(func); - } - else if (func->funcType == asFUNC_DELEGATE) + // *(l_fp - offset) points to an int, and will point to word afterwards + + // We need to use volatile here to tell the compiler not to rearrange + // read and write operations during optimizations. + volatile asDWORD val = *(l_fp - asBC_SWORDARG0(l_bc)); + volatile asWORD *wPtr = (asWORD *)(l_fp - asBC_SWORDARG0(l_bc)); + wPtr[0] = (asWORD)val; // write the word + wPtr[1] = 0; // 0 the rest of the DWORD + } + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_SetV1) : // TODO: This is exactly the same as SetV4. This is a left over from the time + // when the bytecode instructions were more tightly packed. It can now + // be removed. When removing it, make sure the value is correctly converted + // on big-endian CPUs. + + // The byte is already stored correctly in the argument + *(l_fp - asBC_SWORDARG0(l_bc)) = asBC_DWORDARG(l_bc); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_SetV2) : // TODO: This is exactly the same as SetV4. This is a left over from the time + // when the bytecode instructions were more tightly packed. It can now + // be removed. When removing it, make sure the value is correctly converted + // on big-endian CPUs. + + // The word is already stored correctly in the argument + *(l_fp - asBC_SWORDARG0(l_bc)) = asBC_DWORDARG(l_bc); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_Cast) : + // Cast the handle at the top of the stack to the type in the argument + { + asDWORD **a = (asDWORD **)*(asPWORD *)l_sp; + if( a && *a ) { - // Push the object pointer on the stack. There is always a reserved space for this so - // we don't don't need to worry about overflowing the allocated memory buffer - asASSERT(m_regs.stackPointer - AS_PTR_SIZE >= m_stackBlocks[m_stackIndex]); - m_regs.stackPointer -= AS_PTR_SIZE; - *(asPWORD*)m_regs.stackPointer = asPWORD(func->objForDelegate); - - // Call the delegated method - if (func->funcForDelegate->funcType == asFUNC_SYSTEM) - { - m_regs.stackPointer += CallSystemFunction(func->funcForDelegate->id, this); + asDWORD typeId = asBC_DWORDARG(l_bc); - // Update program position after the call so the line number - // is correct in case the system function queries it - m_regs.programPointer += 2; + asCScriptObject *obj = (asCScriptObject *)*a; + asCObjectType *objType = obj->objType; + asCObjectType *to = m_engine->GetObjectTypeFromTypeId(typeId); + + // This instruction can only be used with script classes and interfaces + asASSERT( objType->flags & asOBJ_SCRIPT_OBJECT ); + asASSERT( to->flags & asOBJ_SCRIPT_OBJECT ); + + if( objType->Implements(to) || objType->DerivesFrom(to) ) + { + m_regs.objectType = 0; + m_regs.objectRegister = obj; + obj->AddRef(); } else { - m_regs.programPointer += 2; - - // TODO: run-time optimize: The true method could be figured out when creating the delegate - CallInterfaceMethod(func->funcForDelegate); + // The object register should already be null, so there + // is no need to clear it if the cast is unsuccessful + asASSERT( m_regs.objectRegister == 0 ); } } - else if (func->funcType == asFUNC_SYSTEM) - { - m_regs.stackPointer += CallSystemFunction(func->id, this); + l_sp += AS_PTR_SIZE; + } + l_bc += 2; + NEXT_INSTRUCTION(); - // Update program position after the call so the line number - // is correct in case the system function queries it - m_regs.programPointer += 2; - } - else if (func->funcType == asFUNC_IMPORTED) - { - m_regs.programPointer += 2; - int funcId = m_engine->importedFunctions[func->id & ~FUNC_IMPORTED]->boundFunctionId; - if (funcId > 0) - CallScriptFunction(m_engine->scriptFunctions[funcId]); - else - { - // Tell the exception handler to clean up the arguments to this method - m_needToCleanupArgs = true; + INSTRUCTION(asBC_i64TOi) : *(l_fp - asBC_SWORDARG0(l_bc)) = int(*(asINT64 *)(l_fp - asBC_SWORDARG1(l_bc))); + l_bc += 2; + NEXT_INSTRUCTION(); - SetInternalException(TXT_UNBOUND_FUNCTION); - } + INSTRUCTION(asBC_uTOi64) : *(asINT64 *)(l_fp - asBC_SWORDARG0(l_bc)) = asINT64(*(asUINT *)(l_fp - asBC_SWORDARG1(l_bc))); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_iTOi64) : *(asINT64 *)(l_fp - asBC_SWORDARG0(l_bc)) = asINT64(*(int *)(l_fp - asBC_SWORDARG1(l_bc))); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_fTOi64) : *(asINT64 *)(l_fp - asBC_SWORDARG0(l_bc)) = asINT64(*(float *)(l_fp - asBC_SWORDARG1(l_bc))); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_dTOi64) : *(asINT64 *)(l_fp - asBC_SWORDARG0(l_bc)) = asINT64(*(double *)(l_fp - asBC_SWORDARG0(l_bc))); + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_fTOu64) : + { + float f = *(float *)(l_fp - asBC_SWORDARG1(l_bc)); + if( f < 0 ) + { + // For consistency across compilers and target systems we must cast to int first, + // because on some compilers the cast of a negative float value to uint result in 0 + *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = asQWORD(asINT64(f)); } else + *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = asQWORD(f); + } + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_dTOu64) : + { + double d = *(double *)(l_fp - asBC_SWORDARG0(l_bc)); + if( d < 0 ) { - // Should not get here - asASSERT(false); + // For consistency across compilers and target systems we must cast to int first, + // because on some compilers the cast of a negative float value to uint result in 0 + *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = asQWORD(asINT64(d)); } + else + *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = asQWORD(d); } + l_bc++; + NEXT_INSTRUCTION(); - // Extract the values from the context again - l_bc = m_regs.programPointer; - l_sp = m_regs.stackPointer; - l_fp = m_regs.stackFramePointer; + INSTRUCTION(asBC_i64TOf) : *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = float(*(asINT64 *)(l_fp - asBC_SWORDARG1(l_bc))); + l_bc += 2; + NEXT_INSTRUCTION(); - // If status isn't active anymore then we must stop - if( m_status != asEXECUTION_ACTIVE ) - return; - } - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_u64TOf) : +#if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC6 + { + // MSVC6 doesn't permit UINT64 to double + asINT64 v = *(asINT64 *)(l_fp - asBC_SWORDARG1(l_bc)); + if( v < 0 ) + *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = 18446744073709551615.0f + float(v); + else + *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = float(v); + } +#else + *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = float(*(asQWORD *)(l_fp - asBC_SWORDARG1(l_bc))); +#endif + l_bc += 2; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_FuncPtr): - // Push the function pointer on the stack. The pointer is in the argument - l_sp -= AS_PTR_SIZE; - *(asPWORD*)l_sp = asBC_PTRARG(l_bc); - l_bc += 1+AS_PTR_SIZE; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_i64TOd) : *(double *)(l_fp - asBC_SWORDARG0(l_bc)) = double(*(asINT64 *)(l_fp - asBC_SWORDARG0(l_bc))); + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_LoadThisR): - { - // PshVPtr 0 - asPWORD tmp = *(asPWORD*)l_fp; + INSTRUCTION(asBC_u64TOd) : +#if defined(_MSC_VER) && _MSC_VER <= 1200 // MSVC6 + { + // MSVC6 doesn't permit UINT64 to double + asINT64 v = *(asINT64 *)(l_fp - asBC_SWORDARG0(l_bc)); + if( v < 0 ) + *(double *)(l_fp - asBC_SWORDARG0(l_bc)) = 18446744073709551615.0 + double(v); + else + *(double *)(l_fp - asBC_SWORDARG0(l_bc)) = double(v); + } +#else + *(double *)(l_fp - asBC_SWORDARG0(l_bc)) = double(*(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc))); +#endif + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_NEGi64) : *(asINT64 *)(l_fp - asBC_SWORDARG0(l_bc)) = -*(asINT64 *)(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_INCi64) : ++(**(asQWORD **)&m_regs.valueRegister); + l_bc++; + NEXT_INSTRUCTION(); - // Make sure the pointer is not null - if( tmp == 0 ) + INSTRUCTION(asBC_DECi64) : --(**(asQWORD **)&m_regs.valueRegister); + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_BNOT64) : *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = ~*(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_ADDi64) : *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD *)(l_fp - asBC_SWORDARG1(l_bc)) + *(asQWORD *)(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_SUBi64) : *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD *)(l_fp - asBC_SWORDARG1(l_bc)) - *(asQWORD *)(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_MULi64) : *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD *)(l_fp - asBC_SWORDARG1(l_bc)) * *(asQWORD *)(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_DIVi64) : { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + asINT64 divider = *(asINT64 *)(l_fp - asBC_SWORDARG2(l_bc)); + if( divider == 0 ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - // Raise exception - SetInternalException(TXT_NULL_POINTER_ACCESS); - return; + // Raise exception + SetInternalException(TXT_DIVIDE_BY_ZERO); + return; + } + else if( divider == -1 ) + { + // Need to check if the value that is divided is 1<<63 + // as dividing it with -1 will cause an overflow exception + if( *(asINT64 *)(l_fp - asBC_SWORDARG1(l_bc)) == (asINT64(1) << 63) ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; + + // Raise exception + SetInternalException(TXT_DIVIDE_OVERFLOW); + return; + } + } + + *(asINT64 *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asINT64 *)(l_fp - asBC_SWORDARG1(l_bc)) / divider; } + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_MODi64) : + { + asINT64 divider = *(asINT64 *)(l_fp - asBC_SWORDARG2(l_bc)); + if( divider == 0 ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - // ADDSi - tmp = tmp + asBC_SWORDARG0(l_bc); + // Raise exception + SetInternalException(TXT_DIVIDE_BY_ZERO); + return; + } + else if( divider == -1 ) + { + // Need to check if the value that is divided is 1<<63 + // as dividing it with -1 will cause an overflow exception + if( *(asINT64 *)(l_fp - asBC_SWORDARG1(l_bc)) == (asINT64(1) << 63) ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - // PopRPtr - *(asPWORD*)&m_regs.valueRegister = tmp; + // Raise exception + SetInternalException(TXT_DIVIDE_OVERFLOW); + return; + } + } + *(asINT64 *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asINT64 *)(l_fp - asBC_SWORDARG1(l_bc)) % divider; + } l_bc += 2; - } - NEXT_INSTRUCTION(); + NEXT_INSTRUCTION(); - // Push the qword value of a variable on the stack - INSTRUCTION(asBC_PshV8): - l_sp -= 2; - *(asQWORD*)l_sp = *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)); - l_bc++; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_BAND64) : *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD *)(l_fp - asBC_SWORDARG1(l_bc)) & *(asQWORD *)(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_DIVu): - { - asUINT divider = *(asUINT*)(l_fp - asBC_SWORDARG2(l_bc)); - if( divider == 0 ) + INSTRUCTION(asBC_BOR64) : *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD *)(l_fp - asBC_SWORDARG1(l_bc)) | *(asQWORD *)(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_BXOR64) : *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD *)(l_fp - asBC_SWORDARG1(l_bc)) ^ *(asQWORD *)(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_BSLL64) : *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD *)(l_fp - asBC_SWORDARG1(l_bc)) << *(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_BSRL64) : *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD *)(l_fp - asBC_SWORDARG1(l_bc)) >> *(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_BSRA64) : *(asINT64 *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asINT64 *)(l_fp - asBC_SWORDARG1(l_bc)) >> *(l_fp - asBC_SWORDARG2(l_bc)); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_CMPi64) : { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + asINT64 i1 = *(asINT64 *)(l_fp - asBC_SWORDARG0(l_bc)); + asINT64 i2 = *(asINT64 *)(l_fp - asBC_SWORDARG1(l_bc)); + if( i1 == i2 ) *(int *)&m_regs.valueRegister = 0; + else if( i1 < i2 ) *(int *)&m_regs.valueRegister = -1; + else *(int *)&m_regs.valueRegister = 1; + l_bc += 2; + } + NEXT_INSTRUCTION(); - // Raise exception - SetInternalException(TXT_DIVIDE_BY_ZERO); - return; + INSTRUCTION(asBC_CMPu64) : + { + asQWORD d1 = *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)); + asQWORD d2 = *(asQWORD *)(l_fp - asBC_SWORDARG1(l_bc)); + if( d1 == d2 ) *(int *)&m_regs.valueRegister = 0; + else if( d1 < d2 ) *(int *)&m_regs.valueRegister = -1; + else *(int *)&m_regs.valueRegister = 1; + l_bc += 2; } - *(asUINT*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asUINT*)(l_fp - asBC_SWORDARG1(l_bc)) / divider; - } - l_bc += 2; - NEXT_INSTRUCTION(); + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_MODu): - { - asUINT divider = *(asUINT*)(l_fp - asBC_SWORDARG2(l_bc)); - if( divider == 0 ) + INSTRUCTION(asBC_ChkNullS) : { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + // Verify if the pointer on the stack is null + // This is used for example when validating handles passed as function arguments + asPWORD a = *(asPWORD *)(l_sp + asBC_WORDARG0(l_bc)); + if( a == 0 ) + { + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - // Raise exception - SetInternalException(TXT_DIVIDE_BY_ZERO); - return; + SetInternalException(TXT_NULL_POINTER_ACCESS); + return; + } } - *(asUINT*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asUINT*)(l_fp - asBC_SWORDARG1(l_bc)) % divider; - } - l_bc += 2; - NEXT_INSTRUCTION(); + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_DIVu64): - { - asQWORD divider = *(asQWORD*)(l_fp - asBC_SWORDARG2(l_bc)); - if( divider == 0 ) + INSTRUCTION(asBC_ClrHi) : +#if AS_SIZEOF_BOOL == 1 { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + // Clear the upper bytes, so that trash data don't interfere with boolean operations + + // We need to use volatile here to tell the compiler it cannot + // change the order of read and write operations on the pointer. - // Raise exception - SetInternalException(TXT_DIVIDE_BY_ZERO); - return; + volatile asBYTE *ptr = (asBYTE *)&m_regs.valueRegister; + ptr[1] = 0; // The boolean value is stored in the lower byte, so we clear the rest + ptr[2] = 0; + ptr[3] = 0; } - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD*)(l_fp - asBC_SWORDARG1(l_bc)) / divider; - } - l_bc += 2; - NEXT_INSTRUCTION(); +#else + // We don't have anything to do here +#endif + l_bc++; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_MODu64): - { - asQWORD divider = *(asQWORD*)(l_fp - asBC_SWORDARG2(l_bc)); - if( divider == 0 ) + INSTRUCTION(asBC_JitEntry) : { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + if( m_currentFunction->scriptData->jitFunction ) + { + asPWORD jitArg = asBC_PTRARG(l_bc); - // Raise exception - SetInternalException(TXT_DIVIDE_BY_ZERO); - return; - } - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD*)(l_fp - asBC_SWORDARG1(l_bc)) % divider; - } - l_bc += 2; - NEXT_INSTRUCTION(); + if( jitArg ) + { + // Resume JIT operation + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - INSTRUCTION(asBC_LoadRObjR): - { - // PshVPtr x - asPWORD tmp = *(asPWORD*)(l_fp - asBC_SWORDARG0(l_bc)); + (m_currentFunction->scriptData->jitFunction)(&m_regs, jitArg); + + l_bc = m_regs.programPointer; + l_sp = m_regs.stackPointer; + l_fp = m_regs.stackFramePointer; + + // If status isn't active anymore then we must stop + if( m_status != asEXECUTION_ACTIVE ) + return; + + NEXT_INSTRUCTION(); + } + } - // Make sure the pointer is not null - if( tmp == 0 ) + // Not a JIT resume point, treat as nop + l_bc += 1 + AS_PTR_SIZE; + } + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_CallPtr) : { + // Get the function pointer from the local variable + asCScriptFunction *func = *(asCScriptFunction **)(l_fp - asBC_SWORDARG1(l_bc)); + // Need to move the values back to the context m_regs.programPointer = l_bc; m_regs.stackPointer = l_sp; m_regs.stackFramePointer = l_fp; - // Raise exception - SetInternalException(TXT_NULL_POINTER_ACCESS); - return; - } + if( func == 0 ) + { + // Need to update the program pointer anyway for the exception handler + m_regs.programPointer += 2; - // ADDSi y - tmp = tmp + asBC_SWORDARG1(l_bc); + // Tell the exception handler to clean up the arguments to this method + m_needToCleanupArgs = true; - // PopRPtr - *(asPWORD*)&m_regs.valueRegister = tmp; - l_bc += 3; - } - NEXT_INSTRUCTION(); + // TODO: funcdef: Should we have a different exception string? + SetInternalException(TXT_UNBOUND_FUNCTION); + return; + } + else + { + if( func->funcType == asFUNC_SCRIPT ) + { + m_regs.programPointer += 2; + CallScriptFunction(func); + } + else if( func->funcType == asFUNC_DELEGATE ) + { + // Push the object pointer on the stack. There is always a reserved space for this so + // we don't don't need to worry about overflowing the allocated memory buffer + asASSERT(m_regs.stackPointer - AS_PTR_SIZE >= m_stackBlocks[m_stackIndex]); + m_regs.stackPointer -= AS_PTR_SIZE; + *(asPWORD *)m_regs.stackPointer = asPWORD(func->objForDelegate); + + // Call the delegated method + if( func->funcForDelegate->funcType == asFUNC_SYSTEM ) + { + m_regs.stackPointer += CallSystemFunction(func->funcForDelegate->id, this); - INSTRUCTION(asBC_LoadVObjR): - { - // PSF x - asPWORD tmp = (asPWORD)(l_fp - asBC_SWORDARG0(l_bc)); + // Update program position after the call so the line number + // is correct in case the system function queries it + m_regs.programPointer += 2; + } + else + { + m_regs.programPointer += 2; - // ADDSi y - tmp = tmp + asBC_SWORDARG1(l_bc); + // TODO: run-time optimize: The true method could be figured out when creating the delegate + CallInterfaceMethod(func->funcForDelegate); + } + } + else if( func->funcType == asFUNC_SYSTEM ) + { + m_regs.stackPointer += CallSystemFunction(func->id, this); - // PopRPtr - *(asPWORD*)&m_regs.valueRegister = tmp; - l_bc += 3; - } - NEXT_INSTRUCTION(); + // Update program position after the call so the line number + // is correct in case the system function queries it + m_regs.programPointer += 2; + } + else if( func->funcType == asFUNC_IMPORTED ) + { + m_regs.programPointer += 2; + int funcId = m_engine->importedFunctions[func->id & ~FUNC_IMPORTED]->boundFunctionId; + if( funcId > 0 ) + CallScriptFunction(m_engine->scriptFunctions[funcId]); + else + { + // Tell the exception handler to clean up the arguments to this method + m_needToCleanupArgs = true; - INSTRUCTION(asBC_RefCpyV): - // Same as PSF v, REFCPY - { - asCObjectType *objType = (asCObjectType*)asBC_PTRARG(l_bc); - asSTypeBehaviour *beh = &objType->beh; + SetInternalException(TXT_UNBOUND_FUNCTION); + } + } + else + { + // Should not get here + asASSERT(false); + } + } + + // Extract the values from the context again + l_bc = m_regs.programPointer; + l_sp = m_regs.stackPointer; + l_fp = m_regs.stackFramePointer; + + // If status isn't active anymore then we must stop + if( m_status != asEXECUTION_ACTIVE ) + return; + } + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_FuncPtr) : // Push the function pointer on the stack. The pointer is in the argument + l_sp -= AS_PTR_SIZE; + *(asPWORD *)l_sp = asBC_PTRARG(l_bc); + l_bc += 1 + AS_PTR_SIZE; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_LoadThisR) : + { + // PshVPtr 0 + asPWORD tmp = *(asPWORD *)l_fp; + + // Make sure the pointer is not null + if( tmp == 0 ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - // Determine destination from argument - void **d = (void**)asPWORD(l_fp - asBC_SWORDARG0(l_bc)); + // Raise exception + SetInternalException(TXT_NULL_POINTER_ACCESS); + return; + } + + // ADDSi + tmp = tmp + asBC_SWORDARG0(l_bc); - // Read wanted pointer from the stack - void *s = (void*)*(asPWORD*)l_sp; + // PopRPtr + *(asPWORD *)&m_regs.valueRegister = tmp; + l_bc += 2; + } + NEXT_INSTRUCTION(); - // Need to move the values back to the context as the called functions - // may use the debug interface to inspect the registers - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + // Push the qword value of a variable on the stack + INSTRUCTION(asBC_PshV8) : l_sp -= 2; + *(asQWORD *)l_sp = *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)); + l_bc++; + NEXT_INSTRUCTION(); - // Update ref counter for object types that require it - if( !(objType->flags & (asOBJ_NOCOUNT | asOBJ_VALUE)) ) + INSTRUCTION(asBC_DIVu) : { - // Release previous object held by destination pointer - if( *d != 0 && beh->release ) - m_engine->CallObjectMethod(*d, beh->release); - // Increase ref counter of wanted object - if( s != 0 && beh->addref ) - m_engine->CallObjectMethod(s, beh->addref); + asUINT divider = *(asUINT *)(l_fp - asBC_SWORDARG2(l_bc)); + if( divider == 0 ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; + + // Raise exception + SetInternalException(TXT_DIVIDE_BY_ZERO); + return; + } + *(asUINT *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asUINT *)(l_fp - asBC_SWORDARG1(l_bc)) / divider; } + l_bc += 2; + NEXT_INSTRUCTION(); - // Set the new object in the destination - *d = s; - } - l_bc += 1+AS_PTR_SIZE; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_MODu) : + { + asUINT divider = *(asUINT *)(l_fp - asBC_SWORDARG2(l_bc)); + if( divider == 0 ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - INSTRUCTION(asBC_JLowZ): - if( *(asBYTE*)&m_regs.valueRegister == 0 ) - l_bc += asBC_INTARG(l_bc) + 2; - else + // Raise exception + SetInternalException(TXT_DIVIDE_BY_ZERO); + return; + } + *(asUINT *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asUINT *)(l_fp - asBC_SWORDARG1(l_bc)) % divider; + } l_bc += 2; - NEXT_INSTRUCTION(); + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_JLowNZ): - if( *(asBYTE*)&m_regs.valueRegister != 0 ) - l_bc += asBC_INTARG(l_bc) + 2; - else + INSTRUCTION(asBC_DIVu64) : + { + asQWORD divider = *(asQWORD *)(l_fp - asBC_SWORDARG2(l_bc)); + if( divider == 0 ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; + + // Raise exception + SetInternalException(TXT_DIVIDE_BY_ZERO); + return; + } + *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD *)(l_fp - asBC_SWORDARG1(l_bc)) / divider; + } l_bc += 2; - NEXT_INSTRUCTION(); + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_AllocMem): - // Allocate a buffer and store the pointer in the local variable - { - // TODO: runtime optimize: As the list buffers are going to be short lived, it may be interesting - // to use a memory pool to avoid reallocating the memory all the time + INSTRUCTION(asBC_MODu64) : + { + asQWORD divider = *(asQWORD *)(l_fp - asBC_SWORDARG2(l_bc)); + if( divider == 0 ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - asUINT size = asBC_DWORDARG(l_bc); - asBYTE **var = (asBYTE**)(l_fp - asBC_SWORDARG0(l_bc)); -#ifndef WIP_16BYTE_ALIGN - *var = asNEWARRAY(asBYTE, size); -#else - *var = asNEWARRAYALIGNED(asBYTE, size, MAX_TYPE_ALIGNMENT); -#endif + // Raise exception + SetInternalException(TXT_DIVIDE_BY_ZERO); + return; + } + *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = *(asQWORD *)(l_fp - asBC_SWORDARG1(l_bc)) % divider; + } + l_bc += 2; + NEXT_INSTRUCTION(); - // Clear the buffer for the pointers that will be placed in it - memset(*var, 0, size); - } - l_bc += 2; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_LoadRObjR) : + { + // PshVPtr x + asPWORD tmp = *(asPWORD *)(l_fp - asBC_SWORDARG0(l_bc)); + + // Make sure the pointer is not null + if( tmp == 0 ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - INSTRUCTION(asBC_SetListSize): - { - // Set the size element in the buffer - asBYTE *var = *(asBYTE**)(l_fp - asBC_SWORDARG0(l_bc)); - asUINT off = asBC_DWORDARG(l_bc); - asUINT size = asBC_DWORDARG(l_bc+1); + // Raise exception + SetInternalException(TXT_NULL_POINTER_ACCESS); + return; + } - asASSERT( var ); + // ADDSi y + tmp = tmp + asBC_SWORDARG1(l_bc); - *(asUINT*)(var+off) = size; - } - l_bc += 3; - NEXT_INSTRUCTION(); + // PopRPtr + *(asPWORD *)&m_regs.valueRegister = tmp; + l_bc += 3; + } + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_PshListElmnt): - { - // Push the pointer to the list element on the stack - // In essence it does the same as PSF, RDSPtr, ADDSi - asBYTE *var = *(asBYTE**)(l_fp - asBC_SWORDARG0(l_bc)); - asUINT off = asBC_DWORDARG(l_bc); + INSTRUCTION(asBC_LoadVObjR) : + { + // PSF x + asPWORD tmp = (asPWORD)(l_fp - asBC_SWORDARG0(l_bc)); - asASSERT( var ); + // ADDSi y + tmp = tmp + asBC_SWORDARG1(l_bc); - l_sp -= AS_PTR_SIZE; - *(asPWORD*)l_sp = asPWORD(var+off); - } - l_bc += 2; - NEXT_INSTRUCTION(); + // PopRPtr + *(asPWORD *)&m_regs.valueRegister = tmp; + l_bc += 3; + } + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_SetListType): - { - // Set the type id in the buffer - asBYTE *var = *(asBYTE**)(l_fp - asBC_SWORDARG0(l_bc)); - asUINT off = asBC_DWORDARG(l_bc); - asUINT type = asBC_DWORDARG(l_bc+1); + INSTRUCTION(asBC_RefCpyV) : + // Same as PSF v, REFCPY + { + asCObjectType *objType = (asCObjectType *)asBC_PTRARG(l_bc); + asSTypeBehaviour *beh = &objType->beh; - asASSERT( var ); + // Determine destination from argument + void **d = (void **)asPWORD(l_fp - asBC_SWORDARG0(l_bc)); - *(asUINT*)(var+off) = type; - } - l_bc += 3; - NEXT_INSTRUCTION(); + // Read wanted pointer from the stack + void *s = (void *)*(asPWORD *)l_sp; - //------------------------------ - // Exponent operations - INSTRUCTION(asBC_POWi): - { - bool isOverflow; - *(int*)(l_fp - asBC_SWORDARG0(l_bc)) = as_powi(*(int*)(l_fp - asBC_SWORDARG1(l_bc)), *(int*)(l_fp - asBC_SWORDARG2(l_bc)), isOverflow); - if( isOverflow ) - { - // Need to move the values back to the context + // Need to move the values back to the context as the called functions + // may use the debug interface to inspect the registers m_regs.programPointer = l_bc; m_regs.stackPointer = l_sp; m_regs.stackFramePointer = l_fp; - // Raise exception - SetInternalException(TXT_POW_OVERFLOW); - return; + // Update ref counter for object types that require it + if( !(objType->flags & (asOBJ_NOCOUNT | asOBJ_VALUE)) ) + { + // Release previous object held by destination pointer + if( *d != 0 && beh->release ) + m_engine->CallObjectMethod(*d, beh->release); + // Increase ref counter of wanted object + if( s != 0 && beh->addref ) + m_engine->CallObjectMethod(s, beh->addref); + } + + // Set the new object in the destination + *d = s; } - } - l_bc += 2; - NEXT_INSTRUCTION(); + l_bc += 1 + AS_PTR_SIZE; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_POWu): - { - bool isOverflow; - *(asDWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = as_powu(*(asDWORD*)(l_fp - asBC_SWORDARG1(l_bc)), *(asDWORD*)(l_fp - asBC_SWORDARG2(l_bc)), isOverflow); - if( isOverflow ) - { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + INSTRUCTION(asBC_JLowZ) : if( *(asBYTE *)&m_regs.valueRegister == 0 ) + l_bc += asBC_INTARG(l_bc) + 2; + else l_bc += 2; + NEXT_INSTRUCTION(); - // Raise exception - SetInternalException(TXT_POW_OVERFLOW); - return; - } - } - l_bc += 2; - NEXT_INSTRUCTION(); + INSTRUCTION(asBC_JLowNZ) : if( *(asBYTE *)&m_regs.valueRegister != 0 ) + l_bc += asBC_INTARG(l_bc) + 2; + else l_bc += 2; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_POWf): - { - float r = powf(*(float*)(l_fp - asBC_SWORDARG1(l_bc)), *(float*)(l_fp - asBC_SWORDARG2(l_bc))); - *(float*)(l_fp - asBC_SWORDARG0(l_bc)) = r; - if( r == HUGE_VALF || isinf(r) ) + INSTRUCTION(asBC_AllocMem) : + // Allocate a buffer and store the pointer in the local variable { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + // TODO: runtime optimize: As the list buffers are going to be short lived, it may be interesting + // to use a memory pool to avoid reallocating the memory all the time + + asUINT size = asBC_DWORDARG(l_bc); + asBYTE **var = (asBYTE **)(l_fp - asBC_SWORDARG0(l_bc)); +#ifndef WIP_16BYTE_ALIGN + *var = asNEWARRAY(asBYTE, size); +#else + *var = asNEWARRAYALIGNED(asBYTE, size, MAX_TYPE_ALIGNMENT); +#endif - // Raise exception - SetInternalException(TXT_POW_OVERFLOW); - return; + // Clear the buffer for the pointers that will be placed in it + memset(*var, 0, size); } - } - l_bc += 2; - NEXT_INSTRUCTION(); + l_bc += 2; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_POWd): - { - double r = pow(*(double*)(l_fp - asBC_SWORDARG1(l_bc)), *(double*)(l_fp - asBC_SWORDARG2(l_bc))); - *(double*)(l_fp - asBC_SWORDARG0(l_bc)) = r; - if( r == HUGE_VAL || isinf(r) ) + INSTRUCTION(asBC_SetListSize) : { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + // Set the size element in the buffer + asBYTE *var = *(asBYTE **)(l_fp - asBC_SWORDARG0(l_bc)); + asUINT off = asBC_DWORDARG(l_bc); + asUINT size = asBC_DWORDARG(l_bc + 1); - // Raise exception - SetInternalException(TXT_POW_OVERFLOW); - return; + asASSERT( var ); + + *(asUINT *)(var + off) = size; } - } - l_bc += 2; - NEXT_INSTRUCTION(); + l_bc += 3; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_POWdi): - { - double r = pow(*(double*)(l_fp - asBC_SWORDARG1(l_bc)), *(int*)(l_fp - asBC_SWORDARG2(l_bc))); - *(double*)(l_fp - asBC_SWORDARG0(l_bc)) = r; - if( r == HUGE_VAL || isinf(r) ) + INSTRUCTION(asBC_PshListElmnt) : { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + // Push the pointer to the list element on the stack + // In essence it does the same as PSF, RDSPtr, ADDSi + asBYTE *var = *(asBYTE **)(l_fp - asBC_SWORDARG0(l_bc)); + asUINT off = asBC_DWORDARG(l_bc); - // Raise exception - SetInternalException(TXT_POW_OVERFLOW); - return; + asASSERT( var ); + + l_sp -= AS_PTR_SIZE; + *(asPWORD *)l_sp = asPWORD(var + off); } l_bc += 2; - } - NEXT_INSTRUCTION(); + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_POWi64): - { - bool isOverflow; - *(asINT64*)(l_fp - asBC_SWORDARG0(l_bc)) = as_powi64(*(asINT64*)(l_fp - asBC_SWORDARG1(l_bc)), *(asINT64*)(l_fp - asBC_SWORDARG2(l_bc)), isOverflow); - if( isOverflow ) + INSTRUCTION(asBC_SetListType) : { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + // Set the type id in the buffer + asBYTE *var = *(asBYTE **)(l_fp - asBC_SWORDARG0(l_bc)); + asUINT off = asBC_DWORDARG(l_bc); + asUINT type = asBC_DWORDARG(l_bc + 1); + + asASSERT( var ); - // Raise exception - SetInternalException(TXT_POW_OVERFLOW); - return; + *(asUINT *)(var + off) = type; } - } - l_bc += 2; - NEXT_INSTRUCTION(); + l_bc += 3; + NEXT_INSTRUCTION(); - INSTRUCTION(asBC_POWu64): - { - bool isOverflow; - *(asQWORD*)(l_fp - asBC_SWORDARG0(l_bc)) = as_powu64(*(asQWORD*)(l_fp - asBC_SWORDARG1(l_bc)), *(asQWORD*)(l_fp - asBC_SWORDARG2(l_bc)), isOverflow); - if( isOverflow ) + //------------------------------ + // Exponent operations + INSTRUCTION(asBC_POWi) : { - // Need to move the values back to the context - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; + bool isOverflow; + *(int *)(l_fp - asBC_SWORDARG0(l_bc)) = as_powi(*(int *)(l_fp - asBC_SWORDARG1(l_bc)), *(int *)(l_fp - asBC_SWORDARG2(l_bc)), isOverflow); + if( isOverflow ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - // Raise exception - SetInternalException(TXT_POW_OVERFLOW); - return; + // Raise exception + SetInternalException(TXT_POW_OVERFLOW); + return; + } } - } - l_bc += 2; - NEXT_INSTRUCTION(); - - INSTRUCTION(asBC_Thiscall1): - // This instruction is a faster version of asBC_CALLSYS. It is faster because - // it has much less runtime overhead with determining the calling convention - // and no dynamic code for loading the parameters. The instruction can only - // be used to call functions with the following signatures: - // - // type &obj::func(int) - // type &obj::func(uint) - // void obj::func(int) - // void obj::func(uint) - { - // Get function ID from the argument - int i = asBC_INTARG(l_bc); - - // Need to move the values back to the context as the called functions - // may use the debug interface to inspect the registers - m_regs.programPointer = l_bc; - m_regs.stackPointer = l_sp; - m_regs.stackFramePointer = l_fp; - - // Pop the thispointer from the stack - void *obj = *(void**)l_sp; - if (obj == 0) - SetInternalException(TXT_NULL_POINTER_ACCESS); - else + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_POWu) : { - // Only update the stack pointer if all is OK so the - // exception handler can properly clean up the stack - l_sp += AS_PTR_SIZE; + bool isOverflow; + *(asDWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = as_powu(*(asDWORD *)(l_fp - asBC_SWORDARG1(l_bc)), *(asDWORD *)(l_fp - asBC_SWORDARG2(l_bc)), isOverflow); + if( isOverflow ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; - // Pop the int arg from the stack - int arg = *(int*)l_sp; - l_sp++; + // Raise exception + SetInternalException(TXT_POW_OVERFLOW); + return; + } + } + l_bc += 2; + NEXT_INSTRUCTION(); - // Call the method - m_callingSystemFunction = m_engine->scriptFunctions[i]; - void *ptr = 0; -#ifdef AS_NO_EXCEPTIONS - ptr = m_engine->CallObjectMethodRetPtr(obj, arg, m_callingSystemFunction); -#else - // This try/catch block is to catch potential exception that may - // be thrown by the registered function. - try + INSTRUCTION(asBC_POWf) : + { + float r = powf(*(float *)(l_fp - asBC_SWORDARG1(l_bc)), *(float *)(l_fp - asBC_SWORDARG2(l_bc))); + *(float *)(l_fp - asBC_SWORDARG0(l_bc)) = r; + if( r == HUGE_VALF || isinf(r) ) { - ptr = m_engine->CallObjectMethodRetPtr(obj, arg, m_callingSystemFunction); + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; + + // Raise exception + SetInternalException(TXT_POW_OVERFLOW); + return; } - catch (...) + } + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_POWd) : + { + double r = pow(*(double *)(l_fp - asBC_SWORDARG1(l_bc)), *(double *)(l_fp - asBC_SWORDARG2(l_bc))); + *(double *)(l_fp - asBC_SWORDARG0(l_bc)) = r; + if( r == HUGE_VAL || isinf(r) ) { - // Convert the exception to a script exception so the VM can - // properly report the error to the application and then clean up - HandleAppException(); + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; + + // Raise exception + SetInternalException(TXT_POW_OVERFLOW); + return; } -#endif - m_callingSystemFunction = 0; - *(asPWORD*)&m_regs.valueRegister = (asPWORD)ptr; } - - // Update the program position after the call so that line number is correct l_bc += 2; + NEXT_INSTRUCTION(); - if( m_regs.doProcessSuspend ) + INSTRUCTION(asBC_POWdi) : { - // Should the execution be suspended? - if( m_doSuspend ) + double r = pow(*(double *)(l_fp - asBC_SWORDARG1(l_bc)), *(int *)(l_fp - asBC_SWORDARG2(l_bc))); + *(double *)(l_fp - asBC_SWORDARG0(l_bc)) = r; + if( r == HUGE_VAL || isinf(r) ) { + // Need to move the values back to the context m_regs.programPointer = l_bc; m_regs.stackPointer = l_sp; m_regs.stackFramePointer = l_fp; - m_status = asEXECUTION_SUSPENDED; + // Raise exception + SetInternalException(TXT_POW_OVERFLOW); return; } - // An exception might have been raised - if( m_status != asEXECUTION_ACTIVE ) + l_bc += 2; + } + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_POWi64) : + { + bool isOverflow; + *(asINT64 *)(l_fp - asBC_SWORDARG0(l_bc)) = as_powi64(*(asINT64 *)(l_fp - asBC_SWORDARG1(l_bc)), *(asINT64 *)(l_fp - asBC_SWORDARG2(l_bc)), isOverflow); + if( isOverflow ) { + // Need to move the values back to the context m_regs.programPointer = l_bc; m_regs.stackPointer = l_sp; m_regs.stackFramePointer = l_fp; + // Raise exception + SetInternalException(TXT_POW_OVERFLOW); return; } } - } - NEXT_INSTRUCTION(); + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_POWu64) : + { + bool isOverflow; + *(asQWORD *)(l_fp - asBC_SWORDARG0(l_bc)) = as_powu64(*(asQWORD *)(l_fp - asBC_SWORDARG1(l_bc)), *(asQWORD *)(l_fp - asBC_SWORDARG2(l_bc)), isOverflow); + if( isOverflow ) + { + // Need to move the values back to the context + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; + + // Raise exception + SetInternalException(TXT_POW_OVERFLOW); + return; + } + } + l_bc += 2; + NEXT_INSTRUCTION(); + + INSTRUCTION(asBC_Thiscall1) : + // This instruction is a faster version of asBC_CALLSYS. It is faster because + // it has much less runtime overhead with determining the calling convention + // and no dynamic code for loading the parameters. The instruction can only + // be used to call functions with the following signatures: + // + // type &obj::func(int) + // type &obj::func(uint) + // void obj::func(int) + // void obj::func(uint) + { + // Get function ID from the argument + int i = asBC_INTARG(l_bc); + + // Need to move the values back to the context as the called functions + // may use the debug interface to inspect the registers + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; + + // Pop the thispointer from the stack + void *obj = *(void **)l_sp; + if( obj == 0 ) + SetInternalException(TXT_NULL_POINTER_ACCESS); + else + { + // Only update the stack pointer if all is OK so the + // exception handler can properly clean up the stack + l_sp += AS_PTR_SIZE; + + // Pop the int arg from the stack + int arg = *(int *)l_sp; + l_sp++; + + // Call the method + m_callingSystemFunction = m_engine->scriptFunctions[i]; + void *ptr = 0; +#ifdef AS_NO_EXCEPTIONS + ptr = m_engine->CallObjectMethodRetPtr(obj, arg, m_callingSystemFunction); +#else + // This try/catch block is to catch potential exception that may + // be thrown by the registered function. + try + { + ptr = m_engine->CallObjectMethodRetPtr(obj, arg, m_callingSystemFunction); + } catch( ... ) + { + // Convert the exception to a script exception so the VM can + // properly report the error to the application and then clean up + HandleAppException(); + } +#endif + m_callingSystemFunction = 0; + *(asPWORD *)&m_regs.valueRegister = (asPWORD)ptr; + } + + // Update the program position after the call so that line number is correct + l_bc += 2; + + if( m_regs.doProcessSuspend ) + { + // Should the execution be suspended? + if( m_doSuspend ) + { + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; + + m_status = asEXECUTION_SUSPENDED; + return; + } + // An exception might have been raised + if( m_status != asEXECUTION_ACTIVE ) + { + m_regs.programPointer = l_bc; + m_regs.stackPointer = l_sp; + m_regs.stackFramePointer = l_fp; + + return; + } + } + } + NEXT_INSTRUCTION(); - // Don't let the optimizer optimize for size, - // since it requires extra conditions and jumps + // Don't let the optimizer optimize for size, + // since it requires extra conditions and jumps #if AS_USE_COMPUTED_GOTOS == 0 - INSTRUCTION(201): l_bc = (asDWORD*)201; goto case_FAULT; - INSTRUCTION(202): l_bc = (asDWORD*)202; goto case_FAULT; - INSTRUCTION(203): l_bc = (asDWORD*)203; goto case_FAULT; - INSTRUCTION(204): l_bc = (asDWORD*)204; goto case_FAULT; - INSTRUCTION(205): l_bc = (asDWORD*)205; goto case_FAULT; - INSTRUCTION(206): l_bc = (asDWORD*)206; goto case_FAULT; - INSTRUCTION(207): l_bc = (asDWORD*)207; goto case_FAULT; - INSTRUCTION(208): l_bc = (asDWORD*)208; goto case_FAULT; - INSTRUCTION(209): l_bc = (asDWORD*)209; goto case_FAULT; - INSTRUCTION(210): l_bc = (asDWORD*)210; goto case_FAULT; - INSTRUCTION(211): l_bc = (asDWORD*)211; goto case_FAULT; - INSTRUCTION(212): l_bc = (asDWORD*)212; goto case_FAULT; - INSTRUCTION(213): l_bc = (asDWORD*)213; goto case_FAULT; - INSTRUCTION(214): l_bc = (asDWORD*)214; goto case_FAULT; - INSTRUCTION(215): l_bc = (asDWORD*)215; goto case_FAULT; - INSTRUCTION(216): l_bc = (asDWORD*)216; goto case_FAULT; - INSTRUCTION(217): l_bc = (asDWORD*)217; goto case_FAULT; - INSTRUCTION(218): l_bc = (asDWORD*)218; goto case_FAULT; - INSTRUCTION(219): l_bc = (asDWORD*)219; goto case_FAULT; - INSTRUCTION(220): l_bc = (asDWORD*)220; goto case_FAULT; - INSTRUCTION(221): l_bc = (asDWORD*)221; goto case_FAULT; - INSTRUCTION(222): l_bc = (asDWORD*)222; goto case_FAULT; - INSTRUCTION(223): l_bc = (asDWORD*)223; goto case_FAULT; - INSTRUCTION(224): l_bc = (asDWORD*)224; goto case_FAULT; - INSTRUCTION(225): l_bc = (asDWORD*)225; goto case_FAULT; - INSTRUCTION(226): l_bc = (asDWORD*)226; goto case_FAULT; - INSTRUCTION(227): l_bc = (asDWORD*)227; goto case_FAULT; - INSTRUCTION(228): l_bc = (asDWORD*)228; goto case_FAULT; - INSTRUCTION(229): l_bc = (asDWORD*)229; goto case_FAULT; - INSTRUCTION(230): l_bc = (asDWORD*)230; goto case_FAULT; - INSTRUCTION(231): l_bc = (asDWORD*)231; goto case_FAULT; - INSTRUCTION(232): l_bc = (asDWORD*)232; goto case_FAULT; - INSTRUCTION(233): l_bc = (asDWORD*)233; goto case_FAULT; - INSTRUCTION(234): l_bc = (asDWORD*)234; goto case_FAULT; - INSTRUCTION(235): l_bc = (asDWORD*)235; goto case_FAULT; - INSTRUCTION(236): l_bc = (asDWORD*)236; goto case_FAULT; - INSTRUCTION(237): l_bc = (asDWORD*)237; goto case_FAULT; - INSTRUCTION(238): l_bc = (asDWORD*)238; goto case_FAULT; - INSTRUCTION(239): l_bc = (asDWORD*)239; goto case_FAULT; - INSTRUCTION(240): l_bc = (asDWORD*)240; goto case_FAULT; - INSTRUCTION(241): l_bc = (asDWORD*)241; goto case_FAULT; - INSTRUCTION(242): l_bc = (asDWORD*)242; goto case_FAULT; - INSTRUCTION(243): l_bc = (asDWORD*)243; goto case_FAULT; - INSTRUCTION(244): l_bc = (asDWORD*)244; goto case_FAULT; - INSTRUCTION(245): l_bc = (asDWORD*)245; goto case_FAULT; - INSTRUCTION(246): l_bc = (asDWORD*)246; goto case_FAULT; - INSTRUCTION(247): l_bc = (asDWORD*)247; goto case_FAULT; - INSTRUCTION(248): l_bc = (asDWORD*)248; goto case_FAULT; - INSTRUCTION(249): l_bc = (asDWORD*)249; goto case_FAULT; - INSTRUCTION(250): l_bc = (asDWORD*)250; goto case_FAULT; - INSTRUCTION(251): l_bc = (asDWORD*)251; goto case_FAULT; - INSTRUCTION(252): l_bc = (asDWORD*)252; goto case_FAULT; - INSTRUCTION(253): l_bc = (asDWORD*)253; goto case_FAULT; - INSTRUCTION(254): l_bc = (asDWORD*)254; goto case_FAULT; - INSTRUCTION(255): l_bc = (asDWORD*)255; goto case_FAULT; + INSTRUCTION(201) : l_bc = (asDWORD *)201; + goto case_FAULT; + INSTRUCTION(202) : l_bc = (asDWORD *)202; + goto case_FAULT; + INSTRUCTION(203) : l_bc = (asDWORD *)203; + goto case_FAULT; + INSTRUCTION(204) : l_bc = (asDWORD *)204; + goto case_FAULT; + INSTRUCTION(205) : l_bc = (asDWORD *)205; + goto case_FAULT; + INSTRUCTION(206) : l_bc = (asDWORD *)206; + goto case_FAULT; + INSTRUCTION(207) : l_bc = (asDWORD *)207; + goto case_FAULT; + INSTRUCTION(208) : l_bc = (asDWORD *)208; + goto case_FAULT; + INSTRUCTION(209) : l_bc = (asDWORD *)209; + goto case_FAULT; + INSTRUCTION(210) : l_bc = (asDWORD *)210; + goto case_FAULT; + INSTRUCTION(211) : l_bc = (asDWORD *)211; + goto case_FAULT; + INSTRUCTION(212) : l_bc = (asDWORD *)212; + goto case_FAULT; + INSTRUCTION(213) : l_bc = (asDWORD *)213; + goto case_FAULT; + INSTRUCTION(214) : l_bc = (asDWORD *)214; + goto case_FAULT; + INSTRUCTION(215) : l_bc = (asDWORD *)215; + goto case_FAULT; + INSTRUCTION(216) : l_bc = (asDWORD *)216; + goto case_FAULT; + INSTRUCTION(217) : l_bc = (asDWORD *)217; + goto case_FAULT; + INSTRUCTION(218) : l_bc = (asDWORD *)218; + goto case_FAULT; + INSTRUCTION(219) : l_bc = (asDWORD *)219; + goto case_FAULT; + INSTRUCTION(220) : l_bc = (asDWORD *)220; + goto case_FAULT; + INSTRUCTION(221) : l_bc = (asDWORD *)221; + goto case_FAULT; + INSTRUCTION(222) : l_bc = (asDWORD *)222; + goto case_FAULT; + INSTRUCTION(223) : l_bc = (asDWORD *)223; + goto case_FAULT; + INSTRUCTION(224) : l_bc = (asDWORD *)224; + goto case_FAULT; + INSTRUCTION(225) : l_bc = (asDWORD *)225; + goto case_FAULT; + INSTRUCTION(226) : l_bc = (asDWORD *)226; + goto case_FAULT; + INSTRUCTION(227) : l_bc = (asDWORD *)227; + goto case_FAULT; + INSTRUCTION(228) : l_bc = (asDWORD *)228; + goto case_FAULT; + INSTRUCTION(229) : l_bc = (asDWORD *)229; + goto case_FAULT; + INSTRUCTION(230) : l_bc = (asDWORD *)230; + goto case_FAULT; + INSTRUCTION(231) : l_bc = (asDWORD *)231; + goto case_FAULT; + INSTRUCTION(232) : l_bc = (asDWORD *)232; + goto case_FAULT; + INSTRUCTION(233) : l_bc = (asDWORD *)233; + goto case_FAULT; + INSTRUCTION(234) : l_bc = (asDWORD *)234; + goto case_FAULT; + INSTRUCTION(235) : l_bc = (asDWORD *)235; + goto case_FAULT; + INSTRUCTION(236) : l_bc = (asDWORD *)236; + goto case_FAULT; + INSTRUCTION(237) : l_bc = (asDWORD *)237; + goto case_FAULT; + INSTRUCTION(238) : l_bc = (asDWORD *)238; + goto case_FAULT; + INSTRUCTION(239) : l_bc = (asDWORD *)239; + goto case_FAULT; + INSTRUCTION(240) : l_bc = (asDWORD *)240; + goto case_FAULT; + INSTRUCTION(241) : l_bc = (asDWORD *)241; + goto case_FAULT; + INSTRUCTION(242) : l_bc = (asDWORD *)242; + goto case_FAULT; + INSTRUCTION(243) : l_bc = (asDWORD *)243; + goto case_FAULT; + INSTRUCTION(244) : l_bc = (asDWORD *)244; + goto case_FAULT; + INSTRUCTION(245) : l_bc = (asDWORD *)245; + goto case_FAULT; + INSTRUCTION(246) : l_bc = (asDWORD *)246; + goto case_FAULT; + INSTRUCTION(247) : l_bc = (asDWORD *)247; + goto case_FAULT; + INSTRUCTION(248) : l_bc = (asDWORD *)248; + goto case_FAULT; + INSTRUCTION(249) : l_bc = (asDWORD *)249; + goto case_FAULT; + INSTRUCTION(250) : l_bc = (asDWORD *)250; + goto case_FAULT; + INSTRUCTION(251) : l_bc = (asDWORD *)251; + goto case_FAULT; + INSTRUCTION(252) : l_bc = (asDWORD *)252; + goto case_FAULT; + INSTRUCTION(253) : l_bc = (asDWORD *)253; + goto case_FAULT; + INSTRUCTION(254) : l_bc = (asDWORD *)254; + goto case_FAULT; + INSTRUCTION(255) : l_bc = (asDWORD *)255; + goto case_FAULT; #endif #if defined(AS_DEBUG) && !defined(AS_USE_COMPUTED_GOTOS) - default: - asASSERT(false); - SetInternalException(TXT_UNRECOGNIZED_BYTE_CODE); + default: + asASSERT(false); + SetInternalException(TXT_UNRECOGNIZED_BYTE_CODE); #endif #if defined(_MSC_VER) && !defined(AS_DEBUG) && !defined(AS_USE_COMPUTED_GOTOS) - default: - // This Microsoft specific code allows the - // compiler to optimize the switch case as - // it will know that the code will never - // reach this point - __assume(0); + default: + // This Microsoft specific code allows the + // compiler to optimize the switch case as + // it will know that the code will never + // reach this point + __assume(0); #endif - } // end of switch + } // end of switch #ifdef AS_DEBUG - asDWORD instr = *(asBYTE*)old; + asDWORD instr = *(asBYTE *)old; if( instr != asBC_JMP && instr != asBC_JMPP && (instr < asBC_JZ || instr > asBC_JNP) && instr != asBC_JLowZ && instr != asBC_JLowNZ && - instr != asBC_CALL && instr != asBC_CALLBND && instr != asBC_CALLINTF && instr != asBC_RET && instr != asBC_ALLOC && instr != asBC_CallPtr && - instr != asBC_JitEntry ) + instr != asBC_CALL && instr != asBC_CALLBND && instr != asBC_CALLINTF && instr != asBC_RET && instr != asBC_ALLOC && instr != asBC_CallPtr && + instr != asBC_JitEntry ) { asASSERT( (l_bc - old) == asBCTypeSize[asBCInfo[instr].type] ); } @@ -5054,14 +4978,14 @@ void asCContext::SetInternalException(const char *descr, bool allowCatch) if( m_inExceptionHandler ) { asASSERT(false); // Shouldn't happen - return; // but if it does, at least this will not crash the application + return; // but if it does, at least this will not crash the application } m_status = asEXECUTION_EXCEPTION; m_regs.doProcessSuspend = true; - m_exceptionString = descr; - m_exceptionFunction = m_currentFunction->id; + m_exceptionString = descr; + m_exceptionFunction = m_currentFunction->id; if( m_currentFunction->scriptData ) { @@ -5094,7 +5018,7 @@ void asCContext::CleanReturnObject() if( m_initialFunction && m_initialFunction->DoesReturnOnStack() && m_status == asEXECUTION_FINISHED ) { // If function returns on stack we need to call the destructor on the returned object - if(CastToObjectType(m_initialFunction->returnType.GetTypeInfo())->beh.destruct ) + if( CastToObjectType(m_initialFunction->returnType.GetTypeInfo())->beh.destruct ) m_engine->CallObjectMethod(GetReturnObject(), CastToObjectType(m_initialFunction->returnType.GetTypeInfo())->beh.destruct); return; @@ -5106,28 +5030,28 @@ void asCContext::CleanReturnObject() if( m_regs.objectType ) { - if (m_regs.objectType->GetFlags() & asOBJ_FUNCDEF) + if( m_regs.objectType->GetFlags() & asOBJ_FUNCDEF ) { // Release the function pointer - reinterpret_cast(m_regs.objectRegister)->Release(); + reinterpret_cast(m_regs.objectRegister)->Release(); m_regs.objectRegister = 0; } else { // Call the destructor on the object - asSTypeBehaviour *beh = &(CastToObjectType(reinterpret_cast(m_regs.objectType))->beh); - if (m_regs.objectType->GetFlags() & asOBJ_REF) + asSTypeBehaviour *beh = &(CastToObjectType(reinterpret_cast(m_regs.objectType))->beh); + if( m_regs.objectType->GetFlags() & asOBJ_REF ) { asASSERT(beh->release || (m_regs.objectType->GetFlags() & asOBJ_NOCOUNT)); - if (beh->release) + if( beh->release ) m_engine->CallObjectMethod(m_regs.objectRegister, beh->release); m_regs.objectRegister = 0; } else { - if (beh->destruct) + if( beh->destruct ) m_engine->CallObjectMethod(m_regs.objectRegister, beh->destruct); // Free the memory @@ -5151,11 +5075,11 @@ void asCContext::CleanStack(bool catchException) // do this after the first CleanStackFrame() is done. m_status = asEXECUTION_EXCEPTION; - while (!caught && m_callStack.GetLength() > 0) + while( !caught && m_callStack.GetLength() > 0 ) { // Only clean up until the top most marker for a nested call asPWORD *s = m_callStack.AddressOf() + m_callStack.GetLength() - CALLSTACK_FRAME_SIZE; - if (s[0] == 0) + if( s[0] == 0 ) break; PopCallState(); @@ -5166,7 +5090,7 @@ void asCContext::CleanStack(bool catchException) // If the exception was caught, then move the status to // active as is now possible to resume the execution - if (caught) + if( caught ) m_status = asEXECUTION_ACTIVE; m_inExceptionHandler = false; @@ -5181,7 +5105,7 @@ bool asCContext::IsVarInScope(asUINT varIndex, asUINT stackLevel) if( stackLevel >= GetCallstackSize() ) return false; asCScriptFunction *func; - asUINT pos; + asUINT pos; if( stackLevel == 0 ) { @@ -5191,10 +5115,10 @@ bool asCContext::IsVarInScope(asUINT varIndex, asUINT stackLevel) } else { - asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize()-stackLevel-1)*CALLSTACK_FRAME_SIZE; - func = (asCScriptFunction*)s[1]; + asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize() - stackLevel - 1) * CALLSTACK_FRAME_SIZE; + func = (asCScriptFunction *)s[1]; if( func->scriptData == 0 ) return false; - pos = asUINT((asDWORD*)s[2] - func->scriptData->byteCode.AddressOf()); + pos = asUINT((asDWORD *)s[2] - func->scriptData->byteCode.AddressOf()); } // First determine if the program position is after the variable declaration @@ -5210,7 +5134,7 @@ bool asCContext::IsVarInScope(asUINT varIndex, asUINT stackLevel) // Temporary variables aren't explicitly declared, they are just reserved slots available throughout the function call. // So we'll consider that the variable declaration is found at the very beginning - if (func->scriptData->variables[varIndex]->name.GetLength() == 0) + if( func->scriptData->variables[varIndex]->name.GetLength() == 0 ) foundVarDecl = true; for( int n = 0; n < (int)func->scriptData->objVariableInfo.GetLength(); n++ ) @@ -5218,11 +5142,11 @@ bool asCContext::IsVarInScope(asUINT varIndex, asUINT stackLevel) // Find the varDecl if( func->scriptData->objVariableInfo[n].programPos >= declaredAt ) { - // skip instructions at the same program position, but before the varDecl. + // skip instructions at the same program position, but before the varDecl. // Note, varDecl will only be in the objVariableInfo for object types - if (func->scriptData->objVariableInfo[n].programPos == declaredAt && - !foundVarDecl && - func->scriptData->objVariableInfo[n].option != asOBJ_VARDECL) + if( func->scriptData->objVariableInfo[n].programPos == declaredAt && + !foundVarDecl && + func->scriptData->objVariableInfo[n].option != asOBJ_VARDECL ) continue; foundVarDecl = true; @@ -5254,7 +5178,7 @@ void asCContext::DetermineLiveObjects(asCArray &liveObjects, asUINT stackLe asASSERT( stackLevel < GetCallstackSize() ); asCScriptFunction *func; - asUINT pos; + asUINT pos; if( stackLevel == 0 ) { @@ -5274,12 +5198,12 @@ void asCContext::DetermineLiveObjects(asCArray &liveObjects, asUINT stackLe } else { - asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize()-stackLevel-1)*CALLSTACK_FRAME_SIZE; - func = (asCScriptFunction*)s[1]; + asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize() - stackLevel - 1) * CALLSTACK_FRAME_SIZE; + func = (asCScriptFunction *)s[1]; if( func->scriptData == 0 ) return; - pos = asUINT((asDWORD*)s[2] - func->scriptData->byteCode.AddressOf()); + pos = asUINT((asDWORD *)s[2] - func->scriptData->byteCode.AddressOf()); // Don't consider the last instruction as executed, as the function that was called by it // is still being executed. If we consider it as executed already, then a value object @@ -5289,7 +5213,7 @@ void asCContext::DetermineLiveObjects(asCArray &liveObjects, asUINT stackLe // Determine which object variables that are really live ones liveObjects.SetLength(func->scriptData->variables.GetLength()); - memset(liveObjects.AddressOf(), 0, sizeof(int)*liveObjects.GetLength()); + memset(liveObjects.AddressOf(), 0, sizeof(int) * liveObjects.GetLength()); for( int n = 0; n < (int)func->scriptData->objVariableInfo.GetLength(); n++ ) { // Find the first variable info with a larger position than the current @@ -5303,14 +5227,14 @@ void asCContext::DetermineLiveObjects(asCArray &liveObjects, asUINT stackLe { switch( func->scriptData->objVariableInfo[n].option ) { - case asOBJ_UNINIT: // Object was destroyed + case asOBJ_UNINIT: // Object was destroyed { // TODO: optimize: This should have been done by the compiler already // Which variable is this? Use IsVarInScope to get the correct variable in case there are multiple variables sharing the same offset asUINT var = asUINT(-1); - for (asUINT v = 0; v < func->scriptData->variables.GetLength(); v++) - if (func->scriptData->variables[v]->stackOffset == func->scriptData->objVariableInfo[n].variableOffset && - IsVarInScope(v, stackLevel) ) + for( asUINT v = 0; v < func->scriptData->variables.GetLength(); v++ ) + if( func->scriptData->variables[v]->stackOffset == func->scriptData->objVariableInfo[n].variableOffset && + IsVarInScope(v, stackLevel) ) { var = v; break; @@ -5319,13 +5243,13 @@ void asCContext::DetermineLiveObjects(asCArray &liveObjects, asUINT stackLe liveObjects[var] -= 1; } break; - case asOBJ_INIT: // Object was created + case asOBJ_INIT: // Object was created { // Which variable is this? Use IsVarInScope to get the correct variable in case there are multiple variables sharing the same offset asUINT var = asUINT(-1); - for (asUINT v = 0; v < func->scriptData->variables.GetLength(); v++) - if (func->scriptData->variables[v]->stackOffset == func->scriptData->objVariableInfo[n].variableOffset && - IsVarInScope(v, stackLevel) ) + for( asUINT v = 0; v < func->scriptData->variables.GetLength(); v++ ) + if( func->scriptData->variables[v]->stackOffset == func->scriptData->objVariableInfo[n].variableOffset && + IsVarInScope(v, stackLevel) ) { var = v; break; @@ -5334,28 +5258,28 @@ void asCContext::DetermineLiveObjects(asCArray &liveObjects, asUINT stackLe liveObjects[var] += 1; } break; - case asBLOCK_BEGIN: // Start block - // We should ignore start blocks, since it just means the - // program was within the block when the exception occurred - break; - case asBLOCK_END: // End block - // We need to skip the entire block, as the objects created - // and destroyed inside this block are already out of scope - { - int nested = 1; - while( nested > 0 ) + case asBLOCK_BEGIN: // Start block + // We should ignore start blocks, since it just means the + // program was within the block when the exception occurred + break; + case asBLOCK_END: // End block + // We need to skip the entire block, as the objects created + // and destroyed inside this block are already out of scope { - int option = func->scriptData->objVariableInfo[--n].option; - if( option == 3 ) - nested++; - if( option == 2 ) - nested--; + int nested = 1; + while( nested > 0 ) + { + int option = func->scriptData->objVariableInfo[--n].option; + if( option == 3 ) + nested++; + if( option == 2 ) + nested--; + } } - } - break; - case asOBJ_VARDECL: // A variable was declared - // We don't really care about the variable declarations at this moment - break; + break; + case asOBJ_VARDECL: // A variable was declared + // We don't really care about the variable declarations at this moment + break; } } @@ -5373,31 +5297,31 @@ void asCContext::CleanArgsOnStack() asASSERT( m_currentFunction->scriptData ); // Find the instruction just before the current program pointer - asDWORD *instr = m_currentFunction->scriptData->byteCode.AddressOf(); + asDWORD *instr = m_currentFunction->scriptData->byteCode.AddressOf(); asDWORD *prevInstr = 0; while( instr < m_regs.programPointer ) { - prevInstr = instr; - instr += asBCTypeSize[asBCInfo[*(asBYTE*)(instr)].type]; + prevInstr = instr; + instr += asBCTypeSize[asBCInfo[*(asBYTE *)(instr)].type]; } // Determine what function was being called asCScriptFunction *func = 0; - asBYTE bc = prevInstr ? *(asBYTE*)prevInstr : 0; + asBYTE bc = prevInstr ? *(asBYTE *)prevInstr : 0; if( bc == asBC_CALL || bc == asBC_CALLSYS || bc == asBC_CALLINTF ) { int funcId = asBC_INTARG(prevInstr); - func = m_engine->scriptFunctions[funcId]; + func = m_engine->scriptFunctions[funcId]; } else if( bc == asBC_CALLBND ) { int funcId = asBC_INTARG(prevInstr); - func = m_engine->importedFunctions[funcId & ~FUNC_IMPORTED]->importedFunctionSignature; + func = m_engine->importedFunctions[funcId & ~FUNC_IMPORTED]->importedFunctionSignature; } else if( bc == asBC_CallPtr ) { asUINT v; - int var = asBC_SWORDARG1(prevInstr); + int var = asBC_SWORDARG1(prevInstr); // Find the funcdef from the local variable for( v = 0; v < m_currentFunction->scriptData->variables.GetLength(); v++ ) @@ -5420,7 +5344,7 @@ void asCContext::CleanArgsOnStack() { if( var == paramPos ) { - if (m_currentFunction->parameterTypes[v].IsFuncdef()) + if( m_currentFunction->parameterTypes[v].IsFuncdef() ) func = CastToFuncdefType(m_currentFunction->parameterTypes[v].GetTypeInfo())->funcdef; break; } @@ -5444,30 +5368,30 @@ void asCContext::CleanArgsOnStack() if( (func->parameterTypes[n].IsObject() || func->parameterTypes[n].IsFuncdef()) && !func->parameterTypes[n].IsReference() ) { // TODO: cleanup: This logic is repeated twice in CleanStackFrame too. Should create a common function to share the code - if( *(asPWORD*)&m_regs.stackPointer[offset] ) + if( *(asPWORD *)&m_regs.stackPointer[offset] ) { // Call the object's destructor asSTypeBehaviour *beh = func->parameterTypes[n].GetBehaviour(); - if (func->parameterTypes[n].GetTypeInfo()->flags & asOBJ_FUNCDEF) + if( func->parameterTypes[n].GetTypeInfo()->flags & asOBJ_FUNCDEF ) { - (*(asCScriptFunction**)&m_regs.stackPointer[offset])->Release(); + (*(asCScriptFunction **)&m_regs.stackPointer[offset])->Release(); } else if( func->parameterTypes[n].GetTypeInfo()->flags & asOBJ_REF ) { asASSERT( (func->parameterTypes[n].GetTypeInfo()->flags & asOBJ_NOCOUNT) || beh->release ); if( beh->release ) - m_engine->CallObjectMethod((void*)*(asPWORD*)&m_regs.stackPointer[offset], beh->release); + m_engine->CallObjectMethod((void *)*(asPWORD *)&m_regs.stackPointer[offset], beh->release); } else { if( beh->destruct ) - m_engine->CallObjectMethod((void*)*(asPWORD*)&m_regs.stackPointer[offset], beh->destruct); + m_engine->CallObjectMethod((void *)*(asPWORD *)&m_regs.stackPointer[offset], beh->destruct); // Free the memory - m_engine->CallFree((void*)*(asPWORD*)&m_regs.stackPointer[offset]); + m_engine->CallFree((void *)*(asPWORD *)&m_regs.stackPointer[offset]); } - *(asPWORD*)&m_regs.stackPointer[offset] = 0; + *(asPWORD *)&m_regs.stackPointer[offset] = 0; } } @@ -5484,29 +5408,29 @@ bool asCContext::FindExceptionTryCatch() { // Check each of the script functions on the callstack to see if // the current program position is within a try/catch block - if (m_currentFunction && m_currentFunction->scriptData) + if( m_currentFunction && m_currentFunction->scriptData ) { asUINT currPos = asUINT(m_regs.programPointer - m_currentFunction->scriptData->byteCode.AddressOf()); - for (asUINT n = 0; n < m_currentFunction->scriptData->tryCatchInfo.GetLength(); n++) + for( asUINT n = 0; n < m_currentFunction->scriptData->tryCatchInfo.GetLength(); n++ ) { - if (currPos >= m_currentFunction->scriptData->tryCatchInfo[n].tryPos && - currPos < m_currentFunction->scriptData->tryCatchInfo[n].catchPos) + if( currPos >= m_currentFunction->scriptData->tryCatchInfo[n].tryPos && + currPos < m_currentFunction->scriptData->tryCatchInfo[n].catchPos ) return true; } } int stackSize = GetCallstackSize(); - for (int level = 1; level < stackSize; level++) + for( int level = 1; level < stackSize; level++ ) { - asPWORD *s = m_callStack.AddressOf() + (stackSize - level - 1)*CALLSTACK_FRAME_SIZE; - asCScriptFunction *func = (asCScriptFunction*)s[1]; - if (func && func->scriptData) + asPWORD *s = m_callStack.AddressOf() + (stackSize - level - 1) * CALLSTACK_FRAME_SIZE; + asCScriptFunction *func = (asCScriptFunction *)s[1]; + if( func && func->scriptData ) { - asUINT currPos = asUINT((asDWORD*)s[2] - func->scriptData->byteCode.AddressOf()); - for (asUINT n = 0; n < func->scriptData->tryCatchInfo.GetLength(); n++) + asUINT currPos = asUINT((asDWORD *)s[2] - func->scriptData->byteCode.AddressOf()); + for( asUINT n = 0; n < func->scriptData->tryCatchInfo.GetLength(); n++ ) { - if (currPos >= func->scriptData->tryCatchInfo[n].tryPos && - currPos < func->scriptData->tryCatchInfo[n].catchPos) + if( currPos >= func->scriptData->tryCatchInfo[n].tryPos && + currPos < func->scriptData->tryCatchInfo[n].catchPos ) return true; } } @@ -5517,13 +5441,13 @@ bool asCContext::FindExceptionTryCatch() bool asCContext::CleanStackFrame(bool catchException) { - bool exceptionCaught = false; - asSTryCatchInfo *tryCatchInfo = 0; + bool exceptionCaught = false; + asSTryCatchInfo *tryCatchInfo = 0; - if (m_currentFunction == 0) + if( m_currentFunction == 0 ) return false; - if (m_currentFunction->funcType == asFUNC_SCRIPT && m_currentFunction->scriptData == 0) + if( m_currentFunction->funcType == asFUNC_SCRIPT && m_currentFunction->scriptData == 0 ) { asCString msg; msg.Format(TXT_FUNC_s_RELEASED_BEFORE_CLEANUP, m_currentFunction->name.AddressOf()); @@ -5542,19 +5466,19 @@ bool asCContext::CleanStackFrame(bool catchException) // Check if this function will catch the exception // Try blocks can be nested, so use the innermost block - if (catchException && m_currentFunction->scriptData) + if( catchException && m_currentFunction->scriptData ) { asUINT currPos = asUINT(m_regs.programPointer - m_currentFunction->scriptData->byteCode.AddressOf()); - for (asUINT n = 0; n < m_currentFunction->scriptData->tryCatchInfo.GetLength(); n++) + for( asUINT n = 0; n < m_currentFunction->scriptData->tryCatchInfo.GetLength(); n++ ) { - if (currPos >= m_currentFunction->scriptData->tryCatchInfo[n].tryPos && - currPos < m_currentFunction->scriptData->tryCatchInfo[n].catchPos) + if( currPos >= m_currentFunction->scriptData->tryCatchInfo[n].tryPos && + currPos < m_currentFunction->scriptData->tryCatchInfo[n].catchPos ) { - tryCatchInfo = &m_currentFunction->scriptData->tryCatchInfo[n]; + tryCatchInfo = &m_currentFunction->scriptData->tryCatchInfo[n]; exceptionCaught = true; } - if (currPos < m_currentFunction->scriptData->tryCatchInfo[n].tryPos) + if( currPos < m_currentFunction->scriptData->tryCatchInfo[n].tryPos ) break; } } @@ -5567,12 +5491,12 @@ bool asCContext::CleanStackFrame(bool catchException) asCArray liveObjects; DetermineLiveObjects(liveObjects, 0); - for (asUINT n = 0; n < m_currentFunction->scriptData->variables.GetLength(); n++) + for( asUINT n = 0; n < m_currentFunction->scriptData->variables.GetLength(); n++ ) { int pos = m_currentFunction->scriptData->variables[n]->stackOffset; // If the exception was caught, then only clean up objects within the try block - if (exceptionCaught) + if( exceptionCaught ) { // Find out where the variable was declared, and skip cleaning of those that were declared before the try catch // Multiple variables in different scopes may occupy the same slot on the stack so it is necessary to search @@ -5581,11 +5505,11 @@ bool asCContext::CleanStackFrame(bool catchException) for( asUINT p = 0; p < m_currentFunction->scriptData->objVariableInfo.GetLength(); p++ ) { asSObjectVariableInfo &info = m_currentFunction->scriptData->objVariableInfo[p]; - if (info.variableOffset == pos && - info.option == asOBJ_VARDECL ) + if( info.variableOffset == pos && + info.option == asOBJ_VARDECL ) { asUINT progPos = info.programPos; - if (progPos < tryCatchInfo->tryPos ) + if( progPos < tryCatchInfo->tryPos ) { if( skipClean >= 0 ) skipClean = 1; @@ -5603,14 +5527,14 @@ bool asCContext::CleanStackFrame(bool catchException) // within the try block and variables whose declaration was not identified (temporary objects) // will not be skipped. // TODO: What if a temporary variable reuses a slot from a declared variable that is no longer in scope? - if (skipClean > 0) + if( skipClean > 0 ) continue; } if( m_currentFunction->scriptData->variables[n]->onHeap ) { // Check if the pointer is initialized - if( *(asPWORD*)&m_regs.stackFramePointer[-pos] ) + if( *(asPWORD *)&m_regs.stackFramePointer[-pos] ) { // Skip pointers with unknown types, as this is either a null pointer or just a reference that is not owned by function if( m_currentFunction->scriptData->variables[n]->type.GetTypeInfo() && !m_currentFunction->scriptData->variables[n]->type.IsReference() ) @@ -5618,28 +5542,28 @@ bool asCContext::CleanStackFrame(bool catchException) // Call the object's destructor if( m_currentFunction->scriptData->variables[n]->type.GetTypeInfo()->flags & asOBJ_FUNCDEF ) { - (*(asCScriptFunction**)&m_regs.stackFramePointer[-pos])->Release(); + (*(asCScriptFunction **)&m_regs.stackFramePointer[-pos])->Release(); } - else if (m_currentFunction->scriptData->variables[n]->type.GetTypeInfo()->flags & asOBJ_REF) + else if( m_currentFunction->scriptData->variables[n]->type.GetTypeInfo()->flags & asOBJ_REF ) { - asSTypeBehaviour* beh = &CastToObjectType(m_currentFunction->scriptData->variables[n]->type.GetTypeInfo())->beh; + asSTypeBehaviour *beh = &CastToObjectType(m_currentFunction->scriptData->variables[n]->type.GetTypeInfo())->beh; asASSERT((m_currentFunction->scriptData->variables[n]->type.GetTypeInfo()->flags & asOBJ_NOCOUNT) || beh->release); if( beh->release ) - m_engine->CallObjectMethod((void*)*(asPWORD*)&m_regs.stackFramePointer[-pos], beh->release); + m_engine->CallObjectMethod((void *)*(asPWORD *)&m_regs.stackFramePointer[-pos], beh->release); } else { - asSTypeBehaviour* beh = &CastToObjectType(m_currentFunction->scriptData->variables[n]->type.GetTypeInfo())->beh; - if (beh->destruct) - m_engine->CallObjectMethod((void*)*(asPWORD*)&m_regs.stackFramePointer[-pos], beh->destruct); - else if (m_currentFunction->scriptData->variables[n]->type.GetTypeInfo()->flags & asOBJ_LIST_PATTERN) - m_engine->DestroyList((asBYTE*)*(asPWORD*)&m_regs.stackFramePointer[-pos], CastToObjectType(m_currentFunction->scriptData->variables[n]->type.GetTypeInfo())); + asSTypeBehaviour *beh = &CastToObjectType(m_currentFunction->scriptData->variables[n]->type.GetTypeInfo())->beh; + if( beh->destruct ) + m_engine->CallObjectMethod((void *)*(asPWORD *)&m_regs.stackFramePointer[-pos], beh->destruct); + else if( m_currentFunction->scriptData->variables[n]->type.GetTypeInfo()->flags & asOBJ_LIST_PATTERN ) + m_engine->DestroyList((asBYTE *)*(asPWORD *)&m_regs.stackFramePointer[-pos], CastToObjectType(m_currentFunction->scriptData->variables[n]->type.GetTypeInfo())); // Free the memory - m_engine->CallFree((void*)*(asPWORD*)&m_regs.stackFramePointer[-pos]); + m_engine->CallFree((void *)*(asPWORD *)&m_regs.stackFramePointer[-pos]); } } - *(asPWORD*)&m_regs.stackFramePointer[-pos] = 0; + *(asPWORD *)&m_regs.stackFramePointer[-pos] = 0; } } else @@ -5649,9 +5573,9 @@ bool asCContext::CleanStackFrame(bool catchException) { asASSERT(m_currentFunction->scriptData->variables[n]->type.GetTypeInfo() && m_currentFunction->scriptData->variables[n]->type.GetTypeInfo()->GetFlags() & asOBJ_VALUE); - asSTypeBehaviour* beh = &CastToObjectType(m_currentFunction->scriptData->variables[n]->type.GetTypeInfo())->beh; + asSTypeBehaviour *beh = &CastToObjectType(m_currentFunction->scriptData->variables[n]->type.GetTypeInfo())->beh; if( beh->destruct ) - m_engine->CallObjectMethod((void*)(asPWORD*)&m_regs.stackFramePointer[-pos], beh->destruct); + m_engine->CallObjectMethod((void *)(asPWORD *)&m_regs.stackFramePointer[-pos], beh->destruct); } } } @@ -5660,9 +5584,9 @@ bool asCContext::CleanStackFrame(bool catchException) m_isStackMemoryNotAllocated = false; // If the exception was caught then move the program position and stack pointer to the catch block then stop the unwinding - if (exceptionCaught) + if( exceptionCaught ) { - m_regs.stackPointer = m_regs.stackFramePointer - tryCatchInfo->stackSize - m_currentFunction->scriptData->variableSpace; + m_regs.stackPointer = m_regs.stackFramePointer - tryCatchInfo->stackSize - m_currentFunction->scriptData->variableSpace; m_regs.programPointer = m_currentFunction->scriptData->byteCode.AddressOf() + tryCatchInfo->catchPos; return exceptionCaught; } @@ -5679,32 +5603,32 @@ bool asCContext::CleanStackFrame(bool catchException) offset += AS_PTR_SIZE; for( asUINT n = 0; n < m_currentFunction->parameterTypes.GetLength(); n++ ) { - if( (m_currentFunction->parameterTypes[n].IsObject() ||m_currentFunction->parameterTypes[n].IsFuncdef()) && !m_currentFunction->parameterTypes[n].IsReference() ) + if( (m_currentFunction->parameterTypes[n].IsObject() || m_currentFunction->parameterTypes[n].IsFuncdef()) && !m_currentFunction->parameterTypes[n].IsReference() ) { - if( *(asPWORD*)&m_regs.stackFramePointer[offset] ) + if( *(asPWORD *)&m_regs.stackFramePointer[offset] ) { // Call the object's destructor asSTypeBehaviour *beh = m_currentFunction->parameterTypes[n].GetBehaviour(); - if (m_currentFunction->parameterTypes[n].GetTypeInfo()->flags & asOBJ_FUNCDEF) + if( m_currentFunction->parameterTypes[n].GetTypeInfo()->flags & asOBJ_FUNCDEF ) { - (*(asCScriptFunction**)&m_regs.stackFramePointer[offset])->Release(); + (*(asCScriptFunction **)&m_regs.stackFramePointer[offset])->Release(); } else if( m_currentFunction->parameterTypes[n].GetTypeInfo()->flags & asOBJ_REF ) { asASSERT( (m_currentFunction->parameterTypes[n].GetTypeInfo()->flags & asOBJ_NOCOUNT) || beh->release ); if( beh->release ) - m_engine->CallObjectMethod((void*)*(asPWORD*)&m_regs.stackFramePointer[offset], beh->release); + m_engine->CallObjectMethod((void *)*(asPWORD *)&m_regs.stackFramePointer[offset], beh->release); } else { if( beh->destruct ) - m_engine->CallObjectMethod((void*)*(asPWORD*)&m_regs.stackFramePointer[offset], beh->destruct); + m_engine->CallObjectMethod((void *)*(asPWORD *)&m_regs.stackFramePointer[offset], beh->destruct); // Free the memory - m_engine->CallFree((void*)*(asPWORD*)&m_regs.stackFramePointer[offset]); + m_engine->CallFree((void *)*(asPWORD *)&m_regs.stackFramePointer[offset]); } - *(asPWORD*)&m_regs.stackFramePointer[offset] = 0; + *(asPWORD *)&m_regs.stackFramePointer[offset] = 0; } } @@ -5766,7 +5690,7 @@ int asCContext::SetLineCallback(const asSFuncPtr &callback, void *obj, int callC m_lineCallback = false; m_lineCallbackObj = obj; - bool isObj = false; + bool isObj = false; if( (unsigned)callConv == asCALL_GENERIC || (unsigned)callConv == asCALL_THISCALL_OBJFIRST || (unsigned)callConv == asCALL_THISCALL_OBJLAST ) { m_regs.doProcessSuspend = m_doSuspend; @@ -5805,9 +5729,9 @@ void asCContext::CallLineCallback() // interface int asCContext::SetExceptionCallback(const asSFuncPtr &callback, void *obj, int callConv) { - m_exceptionCallback = true; + m_exceptionCallback = true; m_exceptionCallbackObj = obj; - bool isObj = false; + bool isObj = false; if( (unsigned)callConv == asCALL_GENERIC || (unsigned)callConv == asCALL_THISCALL_OBJFIRST || (unsigned)callConv == asCALL_THISCALL_OBJLAST ) return asNOT_SUPPORTED; if( (unsigned)callConv >= asCALL_THISCALL ) @@ -5837,10 +5761,10 @@ void asCContext::CallExceptionCallback() void asCContext::HandleAppException() { // This method is called from within a catch(...) block - if (m_engine->translateExceptionCallback) + if( m_engine->translateExceptionCallback ) { // Allow the application to translate the application exception to a proper exception string - if (m_engine->translateExceptionCallbackFunc.callConv < ICC_THISCALL) + if( m_engine->translateExceptionCallbackFunc.callConv < ICC_THISCALL ) m_engine->CallGlobalFunction(this, m_engine->translateExceptionCallbackObj, &m_engine->translateExceptionCallbackFunc, 0); else m_engine->CallObjectMethod(m_engine->translateExceptionCallbackObj, this, &m_engine->translateExceptionCallbackFunc, 0); @@ -5855,7 +5779,7 @@ void asCContext::HandleAppException() // interface void asCContext::ClearLineCallback() { - m_lineCallback = false; + m_lineCallback = false; m_regs.doProcessSuspend = m_doSuspend; } @@ -5868,9 +5792,9 @@ void asCContext::ClearExceptionCallback() int asCContext::CallGeneric(asCScriptFunction *descr) { asSSystemFunctionInterface *sysFunc = descr->sysFuncIntf; - void (*func)(asIScriptGeneric*) = (void (*)(asIScriptGeneric*))sysFunc->func; - int popSize = sysFunc->paramSize; - asDWORD *args = m_regs.stackPointer; + void (*func)(asIScriptGeneric *) = (void (*)(asIScriptGeneric *))sysFunc->func; + int popSize = sysFunc->paramSize; + asDWORD *args = m_regs.stackPointer; // Verify the object pointer if it is a class method void *currentObject = 0; @@ -5881,7 +5805,7 @@ int asCContext::CallGeneric(asCScriptFunction *descr) popSize += AS_PTR_SIZE; // Check for null pointer - currentObject = (void*)*(asPWORD*)(args); + currentObject = (void *)*(asPWORD *)(args); if( currentObject == 0 ) { SetInternalException(TXT_NULL_POINTER_ACCESS); @@ -5897,21 +5821,21 @@ int asCContext::CallGeneric(asCScriptFunction *descr) if( descr->DoesReturnOnStack() ) { // Skip the address where the return value will be stored - args += AS_PTR_SIZE; + args += AS_PTR_SIZE; popSize += AS_PTR_SIZE; } asDWORD varArgCount = 0; - if (descr->IsVariadic()) + if( descr->IsVariadic() ) { varArgCount = *args; - args += 1; + args += 1; popSize += 1; // Calculate the arguments that need to be popped - asCDataType variadicType = descr->parameterTypes[descr->parameterTypes.GetLength() - 1]; - int sizeOfVariadicArg = variadicType.GetSizeOnStackDWords(); + asCDataType variadicType = descr->parameterTypes[descr->parameterTypes.GetLength() - 1]; + int sizeOfVariadicArg = variadicType.GetSizeOnStackDWords(); // sysFunc->paramSize already added one variadic arg for the ..., but there might not actually be any popSize -= sizeOfVariadicArg; @@ -5921,10 +5845,10 @@ int asCContext::CallGeneric(asCScriptFunction *descr) } // TODO: variadic: Put them in different branch. Do we really need a separate object for variadics? - asCGeneric genOrdinary(m_engine, descr, currentObject, args); + asCGeneric genOrdinary(m_engine, descr, currentObject, args); asCGenericVariadic genVar(m_engine, descr, currentObject, args, varArgCount); - asCGeneric& gen = descr->IsVariadic() ? genVar : genOrdinary; + asCGeneric &gen = descr->IsVariadic() ? genVar : genOrdinary; m_callingSystemFunction = descr; #ifdef AS_NO_EXCEPTIONS @@ -5935,8 +5859,7 @@ int asCContext::CallGeneric(asCScriptFunction *descr) try { func(&gen); - } - catch (...) + } catch( ... ) { // Convert the exception to a script exception so the VM can // properly report the error to the application and then clean up @@ -5945,13 +5868,13 @@ int asCContext::CallGeneric(asCScriptFunction *descr) #endif m_callingSystemFunction = 0; - m_regs.valueRegister = gen.returnVal; + m_regs.valueRegister = gen.returnVal; m_regs.objectRegister = gen.objectRegister; - m_regs.objectType = descr->returnType.GetTypeInfo(); + m_regs.objectType = descr->returnType.GetTypeInfo(); // Increase the returned handle if the function has been declared with autohandles // and the engine is not set to use the old mode for the generic calling convention - if (sysFunc->returnAutoHandle && m_engine->ep.genericCallMode == 1 && m_regs.objectRegister) + if( sysFunc->returnAutoHandle && m_engine->ep.genericCallMode == 1 && m_regs.objectRegister ) { asASSERT(!(descr->returnType.GetTypeInfo()->flags & asOBJ_NOCOUNT)); m_engine->CallObjectMethod(m_regs.objectRegister, CastToObjectType(descr->returnType.GetTypeInfo())->beh.addref); @@ -5964,7 +5887,7 @@ int asCContext::CallGeneric(asCScriptFunction *descr) asSSystemFunctionInterface::SClean *clean = sysFunc->cleanArgs.AddressOf(); for( asUINT n = 0; n < cleanCount; n++, clean++ ) { - void **addr = (void**)&args[clean->off]; + void **addr = (void **)&args[clean->off]; if( clean->op == 0 ) { if( *addr != 0 ) @@ -6000,45 +5923,45 @@ int asCContext::GetVarCount(asUINT stackLevel) } // interface -int asCContext::GetVar(asUINT varIndex, asUINT stackLevel, const char** name, int* typeId, asETypeModifiers* typeModifiers, bool* isVarOnHeap, int* stackOffset) +int asCContext::GetVar(asUINT varIndex, asUINT stackLevel, const char **name, int *typeId, asETypeModifiers *typeModifiers, bool *isVarOnHeap, int *stackOffset) { - asCScriptFunction* func = reinterpret_cast(GetFunction(stackLevel)); - if (func == 0) return asINVALID_ARG; + asCScriptFunction *func = reinterpret_cast(GetFunction(stackLevel)); + if( func == 0 ) return asINVALID_ARG; int r = func->GetVar(varIndex, name, typeId); - if (r < 0) + if( r < 0 ) return r; - if (isVarOnHeap) + if( isVarOnHeap ) *isVarOnHeap = func->scriptData->variables[varIndex]->onHeap; if( stackOffset ) *stackOffset = func->scriptData->variables[varIndex]->stackOffset; - if (typeModifiers) + if( typeModifiers ) { *typeModifiers = asTM_NONE; - if (func->scriptData && func->scriptData->variables[varIndex]->type.IsReference()) + if( func->scriptData && func->scriptData->variables[varIndex]->type.IsReference() ) { // Find the function argument if it is not a local variable int pos = func->scriptData->variables[varIndex]->stackOffset; - if (pos <= 0) + if( pos <= 0 ) { int stackPos = 0; - if (func->objectType) + if( func->objectType ) stackPos -= AS_PTR_SIZE; - if (func->DoesReturnOnStack()) + if( func->DoesReturnOnStack() ) { - if (stackPos == pos) + if( stackPos == pos ) *typeModifiers = asTM_INOUTREF; stackPos -= AS_PTR_SIZE; } - for (asUINT n = 0; n < func->parameterTypes.GetLength(); n++) + for( asUINT n = 0; n < func->parameterTypes.GetLength(); n++ ) { - if (stackPos == pos) + if( stackPos == pos ) { // The right argument was found. Is this a reference parameter? *typeModifiers = func->inOutFlags[n]; @@ -6051,8 +5974,8 @@ int asCContext::GetVar(asUINT varIndex, asUINT stackLevel, const char** name, in *typeModifiers = asTM_INOUTREF; } - if (func->scriptData && - func->scriptData->variables[varIndex]->type.IsReadOnly()) + if( func->scriptData && + func->scriptData->variables[varIndex]->type.IsReadOnly() ) { *typeModifiers = (asETypeModifiers)(*typeModifiers | asTM_CONST); } @@ -6069,7 +5992,7 @@ const char *asCContext::GetVarName(asUINT varIndex, asUINT stackLevel) if( func == 0 ) return 0; const char *name = 0; - int r = func->GetVar(varIndex, &name); + int r = func->GetVar(varIndex, &name); return r >= 0 ? name : 0; } #endif @@ -6087,12 +6010,12 @@ const char *asCContext::GetVarDeclaration(asUINT varIndex, asUINT stackLevel, bo // interface int asCContext::GetVarTypeId(asUINT varIndex, asUINT stackLevel) { - asCScriptFunction *func = reinterpret_cast(GetFunction(stackLevel)); + asCScriptFunction *func = reinterpret_cast(GetFunction(stackLevel)); if( func == 0 ) return asINVALID_ARG; int typeId; int r = func->GetVar(varIndex, 0, &typeId); - if (r < 0) + if( r < 0 ) return r; return typeId; @@ -6108,17 +6031,17 @@ void *asCContext::GetAddressOfVar(asUINT varIndex, asUINT stackLevel, bool dontD if( stackLevel >= GetCallstackSize() ) return 0; asCScriptFunction *func; - asDWORD *sf; + asDWORD *sf; if( stackLevel == 0 ) { func = m_currentFunction; - sf = m_regs.stackFramePointer; + sf = m_regs.stackFramePointer; } else { - asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize()-stackLevel-1)*CALLSTACK_FRAME_SIZE; - func = (asCScriptFunction*)s[1]; - sf = (asDWORD*)s[0]; + asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize() - stackLevel - 1) * CALLSTACK_FRAME_SIZE; + func = (asCScriptFunction *)s[1]; + sf = (asDWORD *)s[0]; } if( func == 0 ) @@ -6138,18 +6061,18 @@ void *asCContext::GetAddressOfVar(asUINT varIndex, asUINT stackLevel, bool dontD // Determine if the object is really on the heap bool onHeap = func->scriptData->variables[varIndex]->onHeap; if( func->scriptData->variables[varIndex]->type.IsObject() && - !func->scriptData->variables[varIndex]->type.IsObjectHandle() && - !func->scriptData->variables[varIndex]->type.IsReference() ) + !func->scriptData->variables[varIndex]->type.IsObjectHandle() && + !func->scriptData->variables[varIndex]->type.IsReference() ) { if( func->scriptData->variables[varIndex]->type.GetTypeInfo()->GetFlags() & asOBJ_VALUE ) { - if (!onHeap && !returnAddressOfUnitializedObjects) + if( !onHeap && !returnAddressOfUnitializedObjects ) { // If the object on the stack is not initialized return a null pointer instead asCArray liveObjects; DetermineLiveObjects(liveObjects, stackLevel); - if (liveObjects[varIndex] <= 0) + if( liveObjects[varIndex] <= 0 ) return 0; } } @@ -6158,13 +6081,13 @@ void *asCContext::GetAddressOfVar(asUINT varIndex, asUINT stackLevel, bool dontD // If it wasn't an object on the heap, then check if it is a reference parameter if( !onHeap && pos <= 0 ) { - if (func->scriptData->variables[varIndex]->type.IsReference()) + if( func->scriptData->variables[varIndex]->type.IsReference() ) onHeap = true; } // If dontDereference is true then the application wants the address of the reference, rather than the value it refers to if( onHeap && !dontDereference ) - return *(void**)(sf - func->scriptData->variables[varIndex]->stackOffset); + return *(void **)(sf - func->scriptData->variables[varIndex]->stackOffset); } return sf - func->scriptData->variables[varIndex]->stackOffset; @@ -6182,7 +6105,7 @@ int asCContext::GetThisTypeId(asUINT stackLevel) return 0; // not in a method // create a datatype - asCDataType dt = asCDataType::CreateType((asCObjectType*)func->GetObjectType(), false); + asCDataType dt = asCDataType::CreateType((asCObjectType *)func->GetObjectType(), false); // return a typeId from the data type return m_engine->GetTypeIdFromDataType(dt); @@ -6197,24 +6120,24 @@ void *asCContext::GetThisPointer(asUINT stackLevel) return 0; asCScriptFunction *func; - asDWORD *sf; + asDWORD *sf; if( stackLevel == 0 ) { func = m_currentFunction; - sf = m_regs.stackFramePointer; + sf = m_regs.stackFramePointer; } else { - asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize()-stackLevel-1)*CALLSTACK_FRAME_SIZE; - func = (asCScriptFunction*)s[1]; - sf = (asDWORD*)s[0]; + asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize() - stackLevel - 1) * CALLSTACK_FRAME_SIZE; + func = (asCScriptFunction *)s[1]; + sf = (asDWORD *)s[0]; } // sf is null if this is for a nested state if( sf == 0 || func == 0 || func->objectType == 0 ) return 0; - void *thisPointer = (void*)*(asPWORD*)(sf); + void *thisPointer = (void *)*(asPWORD *)(sf); if( thisPointer == 0 ) { return 0; @@ -6248,12 +6171,12 @@ int asCContext::DeserializeProgramPointer(int programPointer, asCScriptFunction realFunc = currentFunction; if( currentFunction->funcType == asFUNC_VIRTUAL || - currentFunction->funcType == asFUNC_INTERFACE ) + currentFunction->funcType == asFUNC_INTERFACE ) { // The currentFunction is a virtual method // Determine the true function from the object - asCScriptObject *obj = *(asCScriptObject**)(asPWORD*)object; + asCScriptObject *obj = *(asCScriptObject **)(asPWORD *)object; if( obj == 0 ) { @@ -6261,7 +6184,7 @@ int asCContext::DeserializeProgramPointer(int programPointer, asCScriptFunction } else { - realFunc = GetRealFunc(m_currentFunction, (void**)&obj); + realFunc = GetRealFunc(m_currentFunction, (void **)&obj); if( realFunc && realFunc->signatureId == m_currentFunction->signatureId ) m_currentFunction = realFunc; @@ -6291,7 +6214,7 @@ int asCContext::FinishDeserialization() } // Sanity test - if (m_currentFunction == 0) + if( m_currentFunction == 0 ) { asCString str; str.Format(TXT_FAILED_IN_FUNC_s_WITH_s_s_d, "FinishDeserialization", "No function set", errorNames[-asCONTEXT_NOT_PREPARED], asCONTEXT_NOT_PREPARED); @@ -6302,7 +6225,7 @@ int asCContext::FinishDeserialization() return asCONTEXT_NOT_PREPARED; } - + m_status = asEXECUTION_SUSPENDED; return asSUCCESS; @@ -6312,7 +6235,7 @@ int asCContext::FinishDeserialization() asDWORD *asCContext::DeserializeStackPointer(asDWORD v) { // TODO: This function should find the correct stack block and then get the address within that stack block. It must not be expected that the same initContextStackSize was used when the stack pointer was serialized - int block = (v >> (32-6)) & 0x3F; + int block = (v >> (32 - 6)) & 0x3F; asDWORD offset = v & 0x03FFFFFF; asASSERT((asUINT)block < m_stackBlocks.GetLength()); @@ -6331,14 +6254,14 @@ asDWORD asCContext::SerializeStackPointer(asDWORD *v) const // Find the stack block that is used, and the offset into that block asUINT stackIndex = DetermineStackIndex(v); asASSERT(int(stackIndex) >= 0); - if (stackIndex >= m_stackBlocks.GetLength()) + if( stackIndex >= m_stackBlocks.GetLength() ) return asUINT(asERROR); - asQWORD offset = asQWORD(v - m_stackBlocks[stackIndex]); + asQWORD offset = asQWORD(v - m_stackBlocks[stackIndex]); asASSERT(offset < 0x03FFFFFF && (asUINT)stackIndex < 0x3F); // Return the seriaized pointer as the offset in the lower 26 bits + the index of the stack block in the upper 6 bits - return (offset & 0x03FFFFFF) | ((stackIndex & 0x3F) << (32-6)); + return (offset & 0x03FFFFFF) | ((stackIndex & 0x3F) << (32 - 6)); } // interface @@ -6347,54 +6270,54 @@ int asCContext::GetArgsOnStackCount(asUINT stackLevel) // Clear cache m_argsOnStackCache.SetLength(0); m_argsOnStackCacheProgPos = 0; - m_argsOnStackCacheFunc = 0; + m_argsOnStackCacheFunc = 0; // Don't return anything if there is no bytecode, e.g. before calling Execute() - if (m_regs.programPointer == 0) return asERROR; + if( m_regs.programPointer == 0 ) return asERROR; - if (stackLevel >= GetCallstackSize()) return asINVALID_ARG; + if( stackLevel >= GetCallstackSize() ) return asINVALID_ARG; - asCScriptFunction* func; - asDWORD* sf; - asDWORD* sp; - asDWORD* progPointer; - if (stackLevel == 0) + asCScriptFunction *func; + asDWORD *sf; + asDWORD *sp; + asDWORD *progPointer; + if( stackLevel == 0 ) { - func = m_currentFunction; - sf = m_regs.stackFramePointer; - sp = m_regs.stackPointer; + func = m_currentFunction; + sf = m_regs.stackFramePointer; + sp = m_regs.stackPointer; progPointer = m_regs.programPointer; } else { - asPWORD* s = m_callStack.AddressOf() + (GetCallstackSize() - stackLevel - 1) * CALLSTACK_FRAME_SIZE; - func = (asCScriptFunction*)s[1]; - sf = (asDWORD*)s[0]; - sp = (asDWORD*)s[3]; - progPointer = (asDWORD*)s[2]; + asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize() - stackLevel - 1) * CALLSTACK_FRAME_SIZE; + func = (asCScriptFunction *)s[1]; + sf = (asDWORD *)s[0]; + sp = (asDWORD *)s[3]; + progPointer = (asDWORD *)s[2]; } // Determine the highest stack position for local variables // asCScriptFunction::variableSpace give this value // If the stack pointer is higher than that, then there are data pushed on the stack asUINT stackPos = asDWORD(sf - sp) - func->scriptData->variableSpace; - if (stackPos == 0) + if( stackPos == 0 ) return 0; // If a function is already being called at a higher call stack position, subtract the args for that function - asCScriptFunction* calledFunc = 0; - if (stackLevel == 1) + asCScriptFunction *calledFunc = 0; + if( stackLevel == 1 ) calledFunc = m_currentFunction; else if( stackLevel > 1 ) { asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize() - stackLevel - 2) * CALLSTACK_FRAME_SIZE; - calledFunc = (asCScriptFunction*)s[1]; + calledFunc = (asCScriptFunction *)s[1]; } if( calledFunc ) stackPos -= calledFunc->GetSpaceNeededForArguments() + (calledFunc->DoesReturnOnStack() ? AS_PTR_SIZE : 0) + (calledFunc->GetObjectType() ? AS_PTR_SIZE : 0); // Cache the list of arg types by func pointer and program position - m_argsOnStackCacheFunc = func; + m_argsOnStackCacheFunc = func; m_argsOnStackCacheProgPos = asUINT(progPointer - &func->scriptData->byteCode[0]); // Iteratively search for functions that will be called until all values on the arg has been determined @@ -6403,44 +6326,44 @@ int asCContext::GetArgsOnStackCount(asUINT stackLevel) { // Find the next function that will be called to determine the arg types and sizes int stackDelta = 0; - calledFunc = func->FindNextFunctionCalled(progPos, &stackDelta, &progPos); + calledFunc = func->FindNextFunctionCalled(progPos, &stackDelta, &progPos); // Determine which args have not yet been pushed on the stack based on the stackDelta - if (stackDelta > 0 && calledFunc->DoesReturnOnStack()) + if( stackDelta > 0 && calledFunc->DoesReturnOnStack() ) stackDelta -= AS_PTR_SIZE; - if (stackDelta > 0 && calledFunc->GetObjectType()) + if( stackDelta > 0 && calledFunc->GetObjectType() ) stackDelta -= AS_PTR_SIZE; int param = -1; - while (stackDelta > 0 && ++param < int(calledFunc->GetParamCount())) + while( stackDelta > 0 && ++param < int(calledFunc->GetParamCount()) ) { - int typeId; + int typeId; asDWORD flags; calledFunc->GetParam(param, &typeId, &flags); // TODO: When enums can be of different sizes this needs to be adjusted - if ((flags & asTM_INOUTREF) || (typeId & asTYPEID_MASK_OBJECT)) + if( (flags & asTM_INOUTREF) || (typeId & asTYPEID_MASK_OBJECT) ) stackDelta -= AS_PTR_SIZE; - else if (typeId == asTYPEID_UINT64 || typeId == asTYPEID_INT64 || typeId == asTYPEID_DOUBLE) + else if( typeId == asTYPEID_UINT64 || typeId == asTYPEID_INT64 || typeId == asTYPEID_DOUBLE ) stackDelta -= 2; else stackDelta -= 1; } // Determine the args already pushed on the stack - while (stackPos > 0) + while( stackPos > 0 ) { - if (++param < int(calledFunc->GetParamCount())) + if( ++param < int(calledFunc->GetParamCount()) ) { - int typeId; + int typeId; asDWORD flags; calledFunc->GetParam(param, &typeId, &flags); - if ((flags & asTM_INOUTREF) || (typeId & asTYPEID_MASK_OBJECT)) + if( (flags & asTM_INOUTREF) || (typeId & asTYPEID_MASK_OBJECT) ) { // TODO: The value pushed on the stack here can be just the offset of the variable, not the actual pointer stackPos -= AS_PTR_SIZE; } - else if (typeId == asTYPEID_UINT64 || typeId == asTYPEID_INT64 || typeId == asTYPEID_DOUBLE) + else if( typeId == asTYPEID_UINT64 || typeId == asTYPEID_INT64 || typeId == asTYPEID_DOUBLE ) stackPos -= 2; else stackPos -= 1; @@ -6461,66 +6384,66 @@ int asCContext::GetArgsOnStackCount(asUINT stackLevel) } // interface -int asCContext::GetArgOnStack(asUINT stackLevel, asUINT arg, int* outTypeId, asUINT* outFlags, void** outAddress) +int asCContext::GetArgOnStack(asUINT stackLevel, asUINT arg, int *outTypeId, asUINT *outFlags, void **outAddress) { // Don't return anything if there is no bytecode, e.g. before calling Execute() - if (m_regs.programPointer == 0) return asERROR; + if( m_regs.programPointer == 0 ) return asERROR; - if (stackLevel >= GetCallstackSize()) return asINVALID_ARG; + if( stackLevel >= GetCallstackSize() ) return asINVALID_ARG; - asCScriptFunction* func; - asDWORD* sp; - asDWORD* progPointer; - if (stackLevel == 0) + asCScriptFunction *func; + asDWORD *sp; + asDWORD *progPointer; + if( stackLevel == 0 ) { - func = m_currentFunction; - sp = m_regs.stackPointer; + func = m_currentFunction; + sp = m_regs.stackPointer; progPointer = m_regs.programPointer; } else { - asPWORD* s = m_callStack.AddressOf() + (GetCallstackSize() - stackLevel - 1) * CALLSTACK_FRAME_SIZE; - func = (asCScriptFunction*)s[1]; - sp = (asDWORD*)s[3]; - progPointer = (asDWORD*)s[2]; + asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize() - stackLevel - 1) * CALLSTACK_FRAME_SIZE; + func = (asCScriptFunction *)s[1]; + sp = (asDWORD *)s[3]; + progPointer = (asDWORD *)s[2]; } // If a function is already being called at a higher call stack position, subtract the args for that function - asCScriptFunction* calledFunc = 0; - if (stackLevel == 1) + asCScriptFunction *calledFunc = 0; + if( stackLevel == 1 ) calledFunc = m_currentFunction; - else if (stackLevel > 1) + else if( stackLevel > 1 ) { - asPWORD* s = m_callStack.AddressOf() + (GetCallstackSize() - stackLevel - 2) * CALLSTACK_FRAME_SIZE; - calledFunc = (asCScriptFunction*)s[1]; + asPWORD *s = m_callStack.AddressOf() + (GetCallstackSize() - stackLevel - 2) * CALLSTACK_FRAME_SIZE; + calledFunc = (asCScriptFunction *)s[1]; } - if (calledFunc) + if( calledFunc ) sp += calledFunc->GetSpaceNeededForArguments() + (calledFunc->DoesReturnOnStack() ? AS_PTR_SIZE : 0) + (calledFunc->GetObjectType() ? AS_PTR_SIZE : 0); // Check that the cache for GetArgsOnStack is up-to-date - if (m_argsOnStackCacheFunc != func || m_argsOnStackCacheProgPos != asUINT(progPointer - &func->scriptData->byteCode[0])) + if( m_argsOnStackCacheFunc != func || m_argsOnStackCacheProgPos != asUINT(progPointer - &func->scriptData->byteCode[0]) ) GetArgsOnStackCount(stackLevel); // The arg types in the array are stored from top to bottom, so we'll go through them in the inverse order // TODO: Check that arg is not too high - arg = m_argsOnStackCache.GetLength() / 2 - arg - 1; + arg = m_argsOnStackCache.GetLength() / 2 - arg - 1; asUINT stackDelta = 0; - for (asUINT n = 0; n < arg; n++) + for( asUINT n = 0; n < arg; n++ ) { - int typeId = m_argsOnStackCache[n * 2]; - asUINT flags = m_argsOnStackCache[n * 2 + 1]; + int typeId = m_argsOnStackCache[n * 2]; + asUINT flags = m_argsOnStackCache[n * 2 + 1]; - if ((flags & asTM_INOUTREF) || (typeId & asTYPEID_MASK_OBJECT)) + if( (flags & asTM_INOUTREF) || (typeId & asTYPEID_MASK_OBJECT) ) stackDelta += AS_PTR_SIZE; - else if (typeId == asTYPEID_UINT64 || typeId == asTYPEID_INT64 || typeId == asTYPEID_DOUBLE) + else if( typeId == asTYPEID_UINT64 || typeId == asTYPEID_INT64 || typeId == asTYPEID_DOUBLE ) stackDelta += 2; else stackDelta += 1; } - if (outAddress) *outAddress = sp + stackDelta; - if (outTypeId) *outTypeId = m_argsOnStackCache[arg * 2]; - if (outFlags) *outFlags = m_argsOnStackCache[arg * 2 + 1]; + if( outAddress ) *outAddress = sp + stackDelta; + if( outTypeId ) *outTypeId = m_argsOnStackCache[arg * 2]; + if( outFlags ) *outFlags = m_argsOnStackCache[arg * 2 + 1]; return asSUCCESS; } @@ -6537,74 +6460,74 @@ struct POW_INFO }; const POW_INFO pow_info[] = -{ - { 0ULL, 0UL, 0, 0, 0 }, // 0 is a special case - { 0ULL, 0UL, 0, 0, 1 }, // 1 is a special case - { 3037000499ULL, 2147483647UL, 65535, 46340, 2 }, // 2 - { 2097152ULL, 1664510UL, 1625, 1290, 2 }, // 3 - { 55108ULL, 46340UL, 255, 215, 3 }, // 4 - { 6208ULL, 5404UL, 84, 73, 3 }, // 5 - { 1448ULL, 1290UL, 40, 35, 3 }, // 6 - { 511ULL, 463UL, 23, 21, 3 }, // 7 - { 234ULL, 215UL, 15, 14, 4 }, // 8 - { 128ULL, 118UL, 11, 10, 4 }, // 9 - { 78ULL, 73UL, 9, 8, 4 }, // 10 - { 52ULL, 49UL, 7, 7, 4 }, // 11 - { 38ULL, 35UL, 6, 5, 4 }, // 12 - { 28ULL, 27UL, 5, 5, 4 }, // 13 - { 22ULL, 21UL, 4, 4, 4 }, // 14 - { 18ULL, 17UL, 4, 4, 4 }, // 15 - { 15ULL, 14UL, 3, 3, 5 }, // 16 - { 13ULL, 12UL, 3, 3, 5 }, // 17 - { 11ULL, 10UL, 3, 3, 5 }, // 18 - { 9ULL, 9UL, 3, 3, 5 }, // 19 - { 8ULL, 8UL, 3, 2, 5 }, // 20 - { 8ULL, 7UL, 2, 2, 5 }, // 21 - { 7ULL, 7UL, 2, 2, 5 }, // 22 - { 6ULL, 6UL, 2, 2, 5 }, // 23 - { 6ULL, 5UL, 2, 2, 5 }, // 24 - { 5ULL, 5UL, 2, 2, 5 }, // 25 - { 5ULL, 5UL, 2, 2, 5 }, // 26 - { 5ULL, 4UL, 2, 2, 5 }, // 27 - { 4ULL, 4UL, 2, 2, 5 }, // 28 - { 4ULL, 4UL, 2, 2, 5 }, // 29 - { 4ULL, 4UL, 2, 2, 5 }, // 30 - { 4ULL, 4UL, 2, 1, 5 }, // 31 - { 3ULL, 3UL, 1, 1, 6 }, // 32 - { 3ULL, 3UL, 1, 1, 6 }, // 33 - { 3ULL, 3UL, 1, 1, 6 }, // 34 - { 3ULL, 3UL, 1, 1, 6 }, // 35 - { 3ULL, 3UL, 1, 1, 6 }, // 36 - { 3ULL, 3UL, 1, 1, 6 }, // 37 - { 3ULL, 3UL, 1, 1, 6 }, // 38 - { 3ULL, 3UL, 1, 1, 6 }, // 39 - { 2ULL, 2UL, 1, 1, 6 }, // 40 - { 2ULL, 2UL, 1, 1, 6 }, // 41 - { 2ULL, 2UL, 1, 1, 6 }, // 42 - { 2ULL, 2UL, 1, 1, 6 }, // 43 - { 2ULL, 2UL, 1, 1, 6 }, // 44 - { 2ULL, 2UL, 1, 1, 6 }, // 45 - { 2ULL, 2UL, 1, 1, 6 }, // 46 - { 2ULL, 2UL, 1, 1, 6 }, // 47 - { 2ULL, 2UL, 1, 1, 6 }, // 48 - { 2ULL, 2UL, 1, 1, 6 }, // 49 - { 2ULL, 2UL, 1, 1, 6 }, // 50 - { 2ULL, 2UL, 1, 1, 6 }, // 51 - { 2ULL, 2UL, 1, 1, 6 }, // 52 - { 2ULL, 2UL, 1, 1, 6 }, // 53 - { 2ULL, 2UL, 1, 1, 6 }, // 54 - { 2ULL, 2UL, 1, 1, 6 }, // 55 - { 2ULL, 2UL, 1, 1, 6 }, // 56 - { 2ULL, 2UL, 1, 1, 6 }, // 57 - { 2ULL, 2UL, 1, 1, 6 }, // 58 - { 2ULL, 2UL, 1, 1, 6 }, // 59 - { 2ULL, 2UL, 1, 1, 6 }, // 60 - { 2ULL, 2UL, 1, 1, 6 }, // 61 - { 2ULL, 2UL, 1, 1, 6 }, // 62 - { 2ULL, 1UL, 1, 1, 6 }, // 63 + { + {0ULL, 0UL, 0, 0, 0}, // 0 is a special case + {0ULL, 0UL, 0, 0, 1}, // 1 is a special case + {3037000499ULL, 2147483647UL, 65535, 46340, 2}, // 2 + {2097152ULL, 1664510UL, 1625, 1290, 2}, // 3 + {55108ULL, 46340UL, 255, 215, 3}, // 4 + {6208ULL, 5404UL, 84, 73, 3}, // 5 + {1448ULL, 1290UL, 40, 35, 3}, // 6 + {511ULL, 463UL, 23, 21, 3}, // 7 + {234ULL, 215UL, 15, 14, 4}, // 8 + {128ULL, 118UL, 11, 10, 4}, // 9 + {78ULL, 73UL, 9, 8, 4}, // 10 + {52ULL, 49UL, 7, 7, 4}, // 11 + {38ULL, 35UL, 6, 5, 4}, // 12 + {28ULL, 27UL, 5, 5, 4}, // 13 + {22ULL, 21UL, 4, 4, 4}, // 14 + {18ULL, 17UL, 4, 4, 4}, // 15 + {15ULL, 14UL, 3, 3, 5}, // 16 + {13ULL, 12UL, 3, 3, 5}, // 17 + {11ULL, 10UL, 3, 3, 5}, // 18 + {9ULL, 9UL, 3, 3, 5}, // 19 + {8ULL, 8UL, 3, 2, 5}, // 20 + {8ULL, 7UL, 2, 2, 5}, // 21 + {7ULL, 7UL, 2, 2, 5}, // 22 + {6ULL, 6UL, 2, 2, 5}, // 23 + {6ULL, 5UL, 2, 2, 5}, // 24 + {5ULL, 5UL, 2, 2, 5}, // 25 + {5ULL, 5UL, 2, 2, 5}, // 26 + {5ULL, 4UL, 2, 2, 5}, // 27 + {4ULL, 4UL, 2, 2, 5}, // 28 + {4ULL, 4UL, 2, 2, 5}, // 29 + {4ULL, 4UL, 2, 2, 5}, // 30 + {4ULL, 4UL, 2, 1, 5}, // 31 + {3ULL, 3UL, 1, 1, 6}, // 32 + {3ULL, 3UL, 1, 1, 6}, // 33 + {3ULL, 3UL, 1, 1, 6}, // 34 + {3ULL, 3UL, 1, 1, 6}, // 35 + {3ULL, 3UL, 1, 1, 6}, // 36 + {3ULL, 3UL, 1, 1, 6}, // 37 + {3ULL, 3UL, 1, 1, 6}, // 38 + {3ULL, 3UL, 1, 1, 6}, // 39 + {2ULL, 2UL, 1, 1, 6}, // 40 + {2ULL, 2UL, 1, 1, 6}, // 41 + {2ULL, 2UL, 1, 1, 6}, // 42 + {2ULL, 2UL, 1, 1, 6}, // 43 + {2ULL, 2UL, 1, 1, 6}, // 44 + {2ULL, 2UL, 1, 1, 6}, // 45 + {2ULL, 2UL, 1, 1, 6}, // 46 + {2ULL, 2UL, 1, 1, 6}, // 47 + {2ULL, 2UL, 1, 1, 6}, // 48 + {2ULL, 2UL, 1, 1, 6}, // 49 + {2ULL, 2UL, 1, 1, 6}, // 50 + {2ULL, 2UL, 1, 1, 6}, // 51 + {2ULL, 2UL, 1, 1, 6}, // 52 + {2ULL, 2UL, 1, 1, 6}, // 53 + {2ULL, 2UL, 1, 1, 6}, // 54 + {2ULL, 2UL, 1, 1, 6}, // 55 + {2ULL, 2UL, 1, 1, 6}, // 56 + {2ULL, 2UL, 1, 1, 6}, // 57 + {2ULL, 2UL, 1, 1, 6}, // 58 + {2ULL, 2UL, 1, 1, 6}, // 59 + {2ULL, 2UL, 1, 1, 6}, // 60 + {2ULL, 2UL, 1, 1, 6}, // 61 + {2ULL, 2UL, 1, 1, 6}, // 62 + {2ULL, 1UL, 1, 1, 6}, // 63 }; -int as_powi(int base, int exponent, bool& isOverflow) +int as_powi(int base, int exponent, bool &isOverflow) { if( exponent < 0 ) { @@ -6627,72 +6550,72 @@ int as_powi(int base, int exponent, bool& isOverflow) { switch( base ) { - case -1: - isOverflow = false; - return exponent & 1 ? -1 : 1; - case 0: - isOverflow = false; - break; - case 1: - isOverflow = false; - return 1; - default: - isOverflow = true; - break; + case -1: + isOverflow = false; + return exponent & 1 ? -1 : 1; + case 0: + isOverflow = false; + break; + case 1: + isOverflow = false; + return 1; + default: + isOverflow = true; + break; } return 0; } else { const asWORD max_base = pow_info[exponent].MaxBasei32; - const char high_bit = pow_info[exponent].HighBit; + const char high_bit = pow_info[exponent].HighBit; if( max_base != 0 && max_base < (base < 0 ? -base : base) ) { isOverflow = true; - return 0; // overflow + return 0; // overflow } #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" #endif int result = 1; switch( high_bit ) { - case 5: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 4: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 3: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 2: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 1: - if( exponent ) result *= base; - FALLTHROUGH - default: - isOverflow = false; - return result; + case 5: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 4: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 3: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 2: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 1: + if( exponent ) result *= base; + FALLTHROUGH + default: + isOverflow = false; + return result; } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif } } -asDWORD as_powu(asDWORD base, asDWORD exponent, bool& isOverflow) +asDWORD as_powu(asDWORD base, asDWORD exponent, bool &isOverflow) { if( exponent == 0 && base == 0 ) { @@ -6704,69 +6627,69 @@ asDWORD as_powu(asDWORD base, asDWORD exponent, bool& isOverflow) { switch( base ) { - case 0: - isOverflow = false; - break; - case 1: - isOverflow = false; - return 1; - default: - isOverflow = true; - break; + case 0: + isOverflow = false; + break; + case 1: + isOverflow = false; + return 1; + default: + isOverflow = true; + break; } return 0; } else { const asWORD max_base = pow_info[exponent].MaxBaseu32; - const char high_bit = pow_info[exponent].HighBit; + const char high_bit = pow_info[exponent].HighBit; if( max_base != 0 && max_base < base ) { isOverflow = true; - return 0; // overflow + return 0; // overflow } #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" #endif asDWORD result = 1; switch( high_bit ) { - case 5: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 4: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 3: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 2: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 1: - if( exponent ) result *= base; - FALLTHROUGH - default: - isOverflow = false; - return result; + case 5: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 4: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 3: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 2: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 1: + if( exponent ) result *= base; + FALLTHROUGH + default: + isOverflow = false; + return result; } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif } } -asINT64 as_powi64(asINT64 base, asINT64 exponent, bool& isOverflow) +asINT64 as_powi64(asINT64 base, asINT64 exponent, bool &isOverflow) { if( exponent < 0 ) { @@ -6789,77 +6712,77 @@ asINT64 as_powi64(asINT64 base, asINT64 exponent, bool& isOverflow) { switch( base ) { - case -1: - isOverflow = false; - return exponent & 1 ? -1 : 1; - case 0: - isOverflow = false; - break; - case 1: - isOverflow = false; - return 1; - default: - isOverflow = true; - break; + case -1: + isOverflow = false; + return exponent & 1 ? -1 : 1; + case 0: + isOverflow = false; + break; + case 1: + isOverflow = false; + return 1; + default: + isOverflow = true; + break; } return 0; } else { const asDWORD max_base = pow_info[exponent].MaxBasei64; - const char high_bit = pow_info[exponent].HighBit; + const char high_bit = pow_info[exponent].HighBit; if( max_base != 0 && max_base < (base < 0 ? -base : base) ) { isOverflow = true; - return 0; // overflow + return 0; // overflow } #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" #endif asINT64 result = 1; switch( high_bit ) { - case 6: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 5: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 4: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 3: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 2: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 1: - if( exponent ) result *= base; - FALLTHROUGH - default: - isOverflow = false; - return result; + case 6: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 5: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 4: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 3: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 2: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 1: + if( exponent ) result *= base; + FALLTHROUGH + default: + isOverflow = false; + return result; } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif } } -asQWORD as_powu64(asQWORD base, asQWORD exponent, bool& isOverflow) +asQWORD as_powu64(asQWORD base, asQWORD exponent, bool &isOverflow) { if( exponent == 0 && base == 0 ) { @@ -6871,74 +6794,71 @@ asQWORD as_powu64(asQWORD base, asQWORD exponent, bool& isOverflow) { switch( base ) { - case 0: - isOverflow = false; - break; - case 1: - isOverflow = false; - return 1; - default: - isOverflow = true; - break; + case 0: + isOverflow = false; + break; + case 1: + isOverflow = false; + return 1; + default: + isOverflow = true; + break; } return 0; } else { const asQWORD max_base = pow_info[exponent].MaxBaseu64; - const char high_bit = pow_info[exponent].HighBit; + const char high_bit = pow_info[exponent].HighBit; if( max_base != 0 && max_base < base ) { isOverflow = true; - return 0; // overflow + return 0; // overflow } #ifdef __GNUC__ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wimplicit-fallthrough" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wimplicit-fallthrough" #endif asQWORD result = 1; switch( high_bit ) { - case 6: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 5: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 4: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 3: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 2: - if( exponent & 1 ) result *= base; - exponent >>= 1; - base *= base; - FALLTHROUGH - case 1: - if( exponent ) result *= base; - FALLTHROUGH - default: - isOverflow = false; - return result; + case 6: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 5: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 4: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 3: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 2: + if( exponent & 1 ) result *= base; + exponent >>= 1; + base *= base; + FALLTHROUGH + case 1: + if( exponent ) result *= base; + FALLTHROUGH + default: + isOverflow = false; + return result; } #ifdef __GNUC__ -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop #endif } } END_AS_NAMESPACE - - - diff --git a/sdk/angelscript/source/as_context.h b/sdk/angelscript/source/as_context.h index f7caea7d..2eaf57a4 100644 --- a/sdk/angelscript/source/as_context.h +++ b/sdk/angelscript/source/as_context.h @@ -55,8 +55,8 @@ class asCContext : public asIScriptContext { public: // Memory management - int AddRef() const; - int Release() const; + int AddRef() const; + int Release() const; // Miscellaneous asIScriptEngine *GetEngine() const; @@ -102,7 +102,7 @@ class asCContext : public asIScriptContext int SetException(const char *descr, bool allowCatch = true); int GetExceptionLineNumber(int *column, const char **sectionName); asIScriptFunction *GetExceptionFunction(); - const char * GetExceptionString(); + const char *GetExceptionString(); bool WillExceptionBeCaught(); int SetExceptionCallback(const asSFuncPtr &callback, void *obj, int callConv); void ClearExceptionCallback(); @@ -114,18 +114,18 @@ class asCContext : public asIScriptContext asIScriptFunction *GetFunction(asUINT stackLevel); int GetLineNumber(asUINT stackLevel, int *column, const char **sectionName); int GetVarCount(asUINT stackLevel); - int GetVar(asUINT varIndex, asUINT stackLevel, const char** name, int* typeId, asETypeModifiers* typeModifiers, bool* isVarOnHeap, int* stackOffset); + int GetVar(asUINT varIndex, asUINT stackLevel, const char **name, int *typeId, asETypeModifiers *typeModifiers, bool *isVarOnHeap, int *stackOffset); #ifdef AS_DEPRECATED - const char *GetVarName(asUINT varIndex, asUINT stackLevel); + const char *GetVarName(asUINT varIndex, asUINT stackLevel); #endif - const char *GetVarDeclaration(asUINT varIndex, asUINT stackLevel, bool includeNamespace); + const char *GetVarDeclaration(asUINT varIndex, asUINT stackLevel, bool includeNamespace); #ifdef AS_DEPRECATED - int GetVarTypeId(asUINT varIndex, asUINT stackLevel); + int GetVarTypeId(asUINT varIndex, asUINT stackLevel); #endif void *GetAddressOfVar(asUINT varIndex, asUINT stackLevel, bool dontDereference, bool returnAddressOfUnitializedObjects); bool IsVarInScope(asUINT varIndex, asUINT stackLevel); int GetThisTypeId(asUINT stackLevel); - void *GetThisPointer(asUINT stackLevel); + void *GetThisPointer(asUINT stackLevel); asIScriptFunction *GetSystemFunction(); // User data @@ -136,27 +136,27 @@ class asCContext : public asIScriptContext int StartDeserialization(); int FinishDeserialization(); int PushFunction(asIScriptFunction *func, void *obj); - int GetStateRegisters(asUINT stackLevel, asIScriptFunction** callingSystemFunction, asIScriptFunction** initialFunction, asDWORD* origStackPointer, asDWORD* argumentsSize, asQWORD* valueRegister, void** objectRegister, asITypeInfo** objectTypeRegister); - int GetCallStateRegisters(asUINT stackLevel, asDWORD* stackFramePointer, asIScriptFunction** currentFunction, asDWORD* programPointer, asDWORD* stackPointer, asDWORD* stackIndex); - int SetStateRegisters(asUINT stackLevel, asIScriptFunction* callingSystemFunction, asIScriptFunction* initialFunction, asDWORD origStackPointer, asDWORD argumentsSize, asQWORD valueRegister, void* objectRegister, asITypeInfo* objectTypeRegister); - int SetCallStateRegisters(asUINT stackLevel, asDWORD stackFramePointer, asIScriptFunction* currentFunction, asDWORD programPointer, asDWORD stackPointer, asDWORD stackIndex); + int GetStateRegisters(asUINT stackLevel, asIScriptFunction **callingSystemFunction, asIScriptFunction **initialFunction, asDWORD *origStackPointer, asDWORD *argumentsSize, asQWORD *valueRegister, void **objectRegister, asITypeInfo **objectTypeRegister); + int GetCallStateRegisters(asUINT stackLevel, asDWORD *stackFramePointer, asIScriptFunction **currentFunction, asDWORD *programPointer, asDWORD *stackPointer, asDWORD *stackIndex); + int SetStateRegisters(asUINT stackLevel, asIScriptFunction *callingSystemFunction, asIScriptFunction *initialFunction, asDWORD origStackPointer, asDWORD argumentsSize, asQWORD valueRegister, void *objectRegister, asITypeInfo *objectTypeRegister); + int SetCallStateRegisters(asUINT stackLevel, asDWORD stackFramePointer, asIScriptFunction *currentFunction, asDWORD programPointer, asDWORD stackPointer, asDWORD stackIndex); int GetArgsOnStackCount(asUINT stackLevel); - int GetArgOnStack(asUINT stackLevel, asUINT arg, int* typeId, asUINT *flags, void** address); + int GetArgOnStack(asUINT stackLevel, asUINT arg, int *typeId, asUINT *flags, void **address); public: // Internal public functions asCContext(asCScriptEngine *engine, bool holdRef); virtual ~asCContext(); - asCScriptFunction *GetRealFunc(asCScriptFunction * m_currentFunction, void ** objType); - int DeserializeProgramPointer(int programPointer, asCScriptFunction * currentFunction, void * object, asDWORD *& p, asCScriptFunction *& realFunc); + asCScriptFunction *GetRealFunc(asCScriptFunction *m_currentFunction, void **objType); + int DeserializeProgramPointer(int programPointer, asCScriptFunction *currentFunction, void *object, asDWORD *&p, asCScriptFunction *&realFunc); -//protected: + //protected: friend class asCScriptEngine; void CallLineCallback(); void CallExceptionCallback(); - int CallGeneric(asCScriptFunction *func); + int CallGeneric(asCScriptFunction *func); #ifndef AS_NO_EXCEPTIONS void HandleAppException(); #endif @@ -178,7 +178,7 @@ class asCContext : public asIScriptContext void SetProgramPointer(); bool ReserveStackSpace(asUINT size); - int DetermineStackIndex(asDWORD *ptr) const; + int DetermineStackIndex(asDWORD *ptr) const; asDWORD *DeserializeStackPointer(asDWORD); asDWORD SerializeStackPointer(asDWORD *) const; @@ -202,7 +202,7 @@ class asCContext : public asIScriptContext asCScriptFunction *m_callingSystemFunction; // The call stack holds program pointer, stack pointer, etc for caller functions - asCArray m_callStack; + asCArray m_callStack; // Dynamically growing local stack asCArray m_stackBlocks; @@ -230,16 +230,16 @@ class asCContext : public asIScriptContext // Cache for GetArgsOnStack asCArray m_argsOnStackCache; asUINT m_argsOnStackCacheProgPos; - asCScriptFunction* m_argsOnStackCacheFunc; + asCScriptFunction *m_argsOnStackCacheFunc; // callbacks bool m_lineCallback; asSSystemFunctionInterface m_lineCallbackFunc; - void * m_lineCallbackObj; + void *m_lineCallbackObj; bool m_exceptionCallback; asSSystemFunctionInterface m_exceptionCallbackFunc; - void * m_exceptionCallbackObj; + void *m_exceptionCallbackObj; asCArray m_userData; @@ -255,10 +255,10 @@ const int RESERVE_STACK = 2 * AS_PTR_SIZE; const int CALLSTACK_FRAME_SIZE = 9; // TODO: Move these to as_utils.h -int as_powi(int base, int exponent, bool& isOverflow); -asDWORD as_powu(asDWORD base, asDWORD exponent, bool& isOverflow); -asINT64 as_powi64(asINT64 base, asINT64 exponent, bool& isOverflow); -asQWORD as_powu64(asQWORD base, asQWORD exponent, bool& isOverflow); +int as_powi(int base, int exponent, bool &isOverflow); +asDWORD as_powu(asDWORD base, asDWORD exponent, bool &isOverflow); +asINT64 as_powi64(asINT64 base, asINT64 exponent, bool &isOverflow); +asQWORD as_powu64(asQWORD base, asQWORD exponent, bool &isOverflow); // Optional template version of powi if overflow detection is not used. #if 0 diff --git a/sdk/angelscript/source/as_criticalsection.h b/sdk/angelscript/source/as_criticalsection.h index 2e15288a..711b5daf 100644 --- a/sdk/angelscript/source/as_criticalsection.h +++ b/sdk/angelscript/source/as_criticalsection.h @@ -45,36 +45,39 @@ BEGIN_AS_NAMESPACE #ifdef AS_NO_THREADS -#define DECLARECRITICALSECTION(x) -#define ENTERCRITICALSECTION(x) -#define LEAVECRITICALSECTION(x) + #define DECLARECRITICALSECTION(x) + #define ENTERCRITICALSECTION(x) + #define LEAVECRITICALSECTION(x) -inline bool tryEnter() { return true; } -#define TRYENTERCRITICALSECTION(x) tryEnter() +inline bool tryEnter() +{ + return true; +} + #define TRYENTERCRITICALSECTION(x) tryEnter() -#define DECLAREREADWRITELOCK(x) -#define ACQUIREEXCLUSIVE(x) -#define RELEASEEXCLUSIVE(x) -#define ACQUIRESHARED(x) -#define RELEASESHARED(x) + #define DECLAREREADWRITELOCK(x) + #define ACQUIREEXCLUSIVE(x) + #define RELEASEEXCLUSIVE(x) + #define ACQUIRESHARED(x) + #define RELEASESHARED(x) #else -#define DECLARECRITICALSECTION(x) asCThreadCriticalSection x; -#define ENTERCRITICALSECTION(x) x.Enter() -#define LEAVECRITICALSECTION(x) x.Leave() -#define TRYENTERCRITICALSECTION(x) x.TryEnter() + #define DECLARECRITICALSECTION(x) asCThreadCriticalSection x; + #define ENTERCRITICALSECTION(x) x.Enter() + #define LEAVECRITICALSECTION(x) x.Leave() + #define TRYENTERCRITICALSECTION(x) x.TryEnter() -#define DECLAREREADWRITELOCK(x) asCThreadReadWriteLock x; -#define ACQUIREEXCLUSIVE(x) x.AcquireExclusive() -#define RELEASEEXCLUSIVE(x) x.ReleaseExclusive() -#define ACQUIRESHARED(x) x.AcquireShared() -#define RELEASESHARED(x) x.ReleaseShared() + #define DECLAREREADWRITELOCK(x) asCThreadReadWriteLock x; + #define ACQUIREEXCLUSIVE(x) x.AcquireExclusive() + #define RELEASEEXCLUSIVE(x) x.ReleaseExclusive() + #define ACQUIRESHARED(x) x.AcquireShared() + #define RELEASESHARED(x) x.ReleaseShared() -#ifdef AS_POSIX_THREADS + #ifdef AS_POSIX_THREADS END_AS_NAMESPACE -#include + #include BEGIN_AS_NAMESPACE class asCThreadCriticalSection @@ -109,25 +112,25 @@ class asCThreadReadWriteLock pthread_rwlock_t lock; }; -#elif defined(AS_WINDOWS_THREADS) + #elif defined(AS_WINDOWS_THREADS) END_AS_NAMESPACE -#ifdef AS_XBOX360 -#include -#else -#ifndef WIN32_LEAN_AND_MEAN - #define WIN32_LEAN_AND_MEAN -#endif -#ifndef _WIN32_WINNT - #define _WIN32_WINNT 0x0600 // We need this to get the declaration for Windows Phone compatible Ex functions -#endif -#include -#endif + #ifdef AS_XBOX360 + #include + #else + #ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #endif + #ifndef _WIN32_WINNT + #define _WIN32_WINNT 0x0600 // We need this to get the declaration for Windows Phone compatible Ex functions + #endif + #include + #endif BEGIN_AS_NAMESPACE -// Undefine macros that cause problems in our code -#undef GetObject -#undef RegisterClass + // Undefine macros that cause problems in our code + #undef GetObject + #undef RegisterClass class asCThreadCriticalSection { @@ -162,7 +165,7 @@ class asCThreadReadWriteLock // Critical sections and semaphores are available on Windows XP and onwards. // Windows XP is oldest version we support with multithreading. - + // The implementation is based on the following article, that shows // how to implement a fair read/write lock that doesn't risk starving // the writers: @@ -171,19 +174,18 @@ class asCThreadReadWriteLock // TODO: Allow use of SRWLOCK through configuration in as_config.h - CRITICAL_SECTION writeLock; - HANDLE readLocks; + CRITICAL_SECTION writeLock; + HANDLE readLocks; }; // This constant really should be a member of asCThreadReadWriteLock, // but it gives a compiler error on MSVC6 so I'm leaving it outside static const asUINT maxReaders = 10; -#endif + #endif #endif END_AS_NAMESPACE #endif - diff --git a/sdk/angelscript/source/as_datatype.cpp b/sdk/angelscript/source/as_datatype.cpp index 404d8fe8..3acf8d38 100644 --- a/sdk/angelscript/source/as_datatype.cpp +++ b/sdk/angelscript/source/as_datatype.cpp @@ -78,7 +78,7 @@ asCDataType::~asCDataType() bool asCDataType::IsValid() const { if( tokenType == ttUnrecognizedToken && - !isObjectHandle ) + !isObjectHandle ) return false; return true; @@ -88,42 +88,68 @@ asCDataType asCDataType::CreateType(asCTypeInfo *ti, bool isConst) { asCDataType dt; - dt.tokenType = ttIdentifier; - dt.typeInfo = ti; - dt.isReadOnly = isConst; + dt.tokenType = ttIdentifier; + dt.typeInfo = ti; + dt.isReadOnly = isConst; return dt; } -asCDataType asCDataType::CreateById(asCScriptEngine* engine, int typeId, bool isConst) +asCDataType asCDataType::CreateById(asCScriptEngine *engine, int typeId, bool isConst) { - if (typeId & asTYPEID_OBJHANDLE) + if( typeId & asTYPEID_OBJHANDLE ) { - return CreateObjectHandle((asCTypeInfo*)engine->GetTypeInfoById(typeId), isConst); + return CreateObjectHandle((asCTypeInfo *)engine->GetTypeInfoById(typeId), isConst); } - else if (typeId & ~asTYPEID_MASK_SEQNBR) + else if( typeId & ~asTYPEID_MASK_SEQNBR ) { - return CreateType((asCTypeInfo*)engine->GetTypeInfoById(typeId), isConst); + return CreateType((asCTypeInfo *)engine->GetTypeInfoById(typeId), isConst); } else { eTokenType tt; - switch (typeId) + switch( typeId ) { - case asTYPEID_VOID: tt = ttVoid; break; - case asTYPEID_BOOL: tt = ttBool; break; - case asTYPEID_INT8: tt = ttInt8; break; - case asTYPEID_INT16: tt = ttInt16; break; - case asTYPEID_INT32: tt = ttInt; break; - case asTYPEID_INT64: tt = ttInt64; break; - case asTYPEID_UINT8: tt = ttUInt8; break; - case asTYPEID_UINT16: tt = ttUInt16; break; - case asTYPEID_UINT32: tt = ttUInt; break; - case asTYPEID_UINT64: tt = ttUInt64; break; - case asTYPEID_FLOAT: tt = ttFloat; break; - case asTYPEID_DOUBLE: tt = ttDouble; break; - default: tt = ttInt; break; + case asTYPEID_VOID: + tt = ttVoid; + break; + case asTYPEID_BOOL: + tt = ttBool; + break; + case asTYPEID_INT8: + tt = ttInt8; + break; + case asTYPEID_INT16: + tt = ttInt16; + break; + case asTYPEID_INT32: + tt = ttInt; + break; + case asTYPEID_INT64: + tt = ttInt64; + break; + case asTYPEID_UINT8: + tt = ttUInt8; + break; + case asTYPEID_UINT16: + tt = ttUInt16; + break; + case asTYPEID_UINT32: + tt = ttUInt; + break; + case asTYPEID_UINT64: + tt = ttUInt64; + break; + case asTYPEID_FLOAT: + tt = ttFloat; + break; + case asTYPEID_DOUBLE: + tt = ttDouble; + break; + default: + tt = ttInt; + break; } return CreatePrimitive(tt, isConst); @@ -134,9 +160,9 @@ asCDataType asCDataType::CreateAuto(bool isConst) { asCDataType dt; - dt.tokenType = ttIdentifier; - dt.isReadOnly = isConst; - dt.isAuto = true; + dt.tokenType = ttIdentifier; + dt.isReadOnly = isConst; + dt.isAuto = true; return dt; } @@ -147,10 +173,10 @@ asCDataType asCDataType::CreateObjectHandle(asCTypeInfo *ot, bool isConst) asASSERT(CastToObjectType(ot)); - dt.tokenType = ttIdentifier; - dt.typeInfo = ot; - dt.isObjectHandle = true; - dt.isConstHandle = isConst; + dt.tokenType = ttIdentifier; + dt.typeInfo = ot; + dt.isObjectHandle = true; + dt.isConstHandle = isConst; return dt; } @@ -159,8 +185,8 @@ asCDataType asCDataType::CreatePrimitive(eTokenType tt, bool isConst) { asCDataType dt; - dt.tokenType = tt; - dt.isReadOnly = isConst; + dt.tokenType = tt; + dt.isReadOnly = isConst; return dt; } @@ -169,10 +195,10 @@ asCDataType asCDataType::CreateNullHandle() { asCDataType dt; - dt.tokenType = ttUnrecognizedToken; - dt.isReadOnly = true; + dt.tokenType = ttUnrecognizedToken; + dt.isReadOnly = true; dt.isObjectHandle = true; - dt.isConstHandle = true; + dt.isConstHandle = true; return dt; } @@ -180,8 +206,8 @@ asCDataType asCDataType::CreateNullHandle() bool asCDataType::IsNullHandle() const { if( tokenType == ttUnrecognizedToken && - typeInfo == 0 && - isObjectHandle ) + typeInfo == 0 && + isObjectHandle ) return true; return false; @@ -197,19 +223,19 @@ asCString asCDataType::Format(asSNameSpace *currNs, bool includeNamespace) const if( isReadOnly ) str = "const "; - // If the type is not declared in the current namespace, then the namespace + // If the type is not declared in the current namespace, then the namespace // must always be informed to guarantee that the correct type is informed - if (includeNamespace || (typeInfo && typeInfo->nameSpace != currNs)) + if( includeNamespace || (typeInfo && typeInfo->nameSpace != currNs) ) { - if (typeInfo && typeInfo->nameSpace && typeInfo->nameSpace->name != "") + if( typeInfo && typeInfo->nameSpace && typeInfo->nameSpace->name != "" ) str += typeInfo->nameSpace->name + "::"; } - if (typeInfo && typeInfo->nameSpace == 0) + if( typeInfo && typeInfo->nameSpace == 0 ) { - // If funcDef->nameSpace is null it means the funcDef was declared as member of + // If funcDef->nameSpace is null it means the funcDef was declared as member of // another type, in which case the scope should be built with the name of that type - asCDataType dt = asCDataType::CreateType(CastToFuncdefType(typeInfo)->parentClass, false); - str += dt.Format(currNs, includeNamespace) + "::"; + asCDataType dt = asCDataType::CreateType(CastToFuncdefType(typeInfo)->parentClass, false); + str += dt.Format(currNs, includeNamespace) + "::"; } if( tokenType != ttIdentifier ) @@ -223,9 +249,9 @@ asCString asCDataType::Format(asSNameSpace *currNs, bool includeNamespace) const str += ot->templateSubTypes[0].Format(currNs, includeNamespace); str += "[]"; } - else if(typeInfo) + else if( typeInfo ) { - if (typeInfo->name == "$func") + if( typeInfo->name == "$func" ) str += ""; // use a more friendly name for funcdefs and lambdas else str += typeInfo->name; @@ -236,7 +262,7 @@ asCString asCDataType::Format(asSNameSpace *currNs, bool includeNamespace) const for( asUINT subtypeIndex = 0; subtypeIndex < ot->templateSubTypes.GetLength(); subtypeIndex++ ) { str += ot->templateSubTypes[subtypeIndex].Format(currNs, includeNamespace); - if( subtypeIndex != ot->templateSubTypes.GetLength()-1 ) + if( subtypeIndex != ot->templateSubTypes.GetLength() - 1 ) str += ","; } str += ">"; @@ -264,7 +290,7 @@ asCString asCDataType::Format(asSNameSpace *currNs, bool includeNamespace) const return str; } -asCDataType &asCDataType::operator =(const asCDataType &dt) +asCDataType &asCDataType::operator=(const asCDataType &dt) { tokenType = dt.tokenType; isReference = dt.isReference; @@ -283,8 +309,8 @@ int asCDataType::MakeHandle(bool b, bool acceptHandleForScope) { if( !b ) { - isObjectHandle = false; - isConstHandle = false; + isObjectHandle = false; + isConstHandle = false; isHandleToAsHandleType = false; } else @@ -295,24 +321,24 @@ int asCDataType::MakeHandle(bool b, bool acceptHandleForScope) } else if( !isObjectHandle ) { - // Only reference types are allowed to be handles, - // but not nohandle reference types, and not scoped references + // Only reference types are allowed to be handles, + // but not nohandle reference types, and not scoped references // (except when returned from registered function) // funcdefs are special reference types and support handles // value types with asOBJ_ASHANDLE are treated as a handle if( (!typeInfo || - !((typeInfo->flags & asOBJ_REF) || (typeInfo->flags & asOBJ_TEMPLATE_SUBTYPE) || (typeInfo->flags & asOBJ_ASHANDLE) || (typeInfo->flags & asOBJ_FUNCDEF)) || - (typeInfo->flags & asOBJ_NOHANDLE) || - ((typeInfo->flags & asOBJ_SCOPED) && !acceptHandleForScope)) ) + !((typeInfo->flags & asOBJ_REF) || (typeInfo->flags & asOBJ_TEMPLATE_SUBTYPE) || (typeInfo->flags & asOBJ_ASHANDLE) || (typeInfo->flags & asOBJ_FUNCDEF)) || + (typeInfo->flags & asOBJ_NOHANDLE) || + ((typeInfo->flags & asOBJ_SCOPED) && !acceptHandleForScope)) ) return -1; isObjectHandle = b; - isConstHandle = false; + isConstHandle = false; // ASHANDLE supports being handle, but as it really is a value type it will not be marked as a handle if( (typeInfo->flags & asOBJ_ASHANDLE) ) { - isObjectHandle = false; + isObjectHandle = false; isHandleToAsHandleType = true; } } @@ -327,19 +353,19 @@ int asCDataType::MakeArray(asCScriptEngine *engine, asCModule *module) return asINVALID_TYPE; bool tmpIsReadOnly = isReadOnly; - isReadOnly = false; + isReadOnly = false; asCArray subTypes; subTypes.PushLast(*this); asCObjectType *at = engine->GetTemplateInstanceType(engine->defaultArrayObjectType, subTypes, module); - if (at == 0) + if( at == 0 ) return asNOT_SUPPORTED; isReadOnly = tmpIsReadOnly; isObjectHandle = false; - isConstHandle = false; - - typeInfo = at; + isConstHandle = false; + + typeInfo = at; tokenType = ttIdentifier; return 0; @@ -375,9 +401,9 @@ int asCDataType::MakeHandleToConst(bool b) bool asCDataType::SupportHandles() const { if( typeInfo && - (typeInfo->flags & (asOBJ_REF | asOBJ_ASHANDLE | asOBJ_FUNCDEF)) && - !(typeInfo->flags & asOBJ_NOHANDLE) && - !isObjectHandle ) + (typeInfo->flags & (asOBJ_REF | asOBJ_ASHANDLE | asOBJ_FUNCDEF)) && + !(typeInfo->flags & asOBJ_NOHANDLE) && + !isObjectHandle ) return true; return false; @@ -389,9 +415,9 @@ bool asCDataType::CanBeInstantiated() const return false; if( !IsObject() && !IsFuncdef() ) // Primitives - return true; + return true; - if (IsNullHandle()) // null + if( IsNullHandle() ) // null return false; if( IsObjectHandle() && !(typeInfo->flags & asOBJ_NOHANDLE) ) // Handles @@ -399,7 +425,7 @@ bool asCDataType::CanBeInstantiated() const // Funcdefs cannot be instantiated without being handles // The exception being delegates, but these can only be created as temporary objects - if (IsFuncdef()) + if( IsFuncdef() ) return false; asCObjectType *ot = CastToObjectType(typeInfo); @@ -419,7 +445,7 @@ bool asCDataType::IsAbstractClass() const bool asCDataType::IsInterface() const { - if (typeInfo == 0) + if( typeInfo == 0 ) return false; asCObjectType *ot = CastToObjectType(typeInfo); @@ -440,8 +466,8 @@ bool asCDataType::CanBeCopied() const // It must have a default constructor or factory and the opAssign // Alternatively it must have the copy constructor asCObjectType *ot = CastToObjectType(typeInfo); - if (ot && (((ot->beh.construct != 0 || ot->beh.factory != 0) && ot->beh.copy != 0) || - (ot->beh.copyconstruct != 0 || ot->beh.copyfactory != 0)) ) + if( ot && (((ot->beh.construct != 0 || ot->beh.factory != 0) && ot->beh.copy != 0) || + (ot->beh.copyconstruct != 0 || ot->beh.copyfactory != 0)) ) return true; return false; @@ -475,7 +501,7 @@ bool asCDataType::IsArrayType() const // This is only true if the type used is the default array type, i.e. the one used for the [] syntax form if( typeInfo && typeInfo->engine->defaultArrayObjectType ) return typeInfo->name == typeInfo->engine->defaultArrayObjectType->name; - + return false; } @@ -503,12 +529,12 @@ asCDataType asCDataType::GetSubType(asUINT subtypeIndex) const } -bool asCDataType::operator !=(const asCDataType &dt) const +bool asCDataType::operator!=(const asCDataType &dt) const { return !(*this == dt); } -bool asCDataType::operator ==(const asCDataType &dt) const +bool asCDataType::operator==(const asCDataType &dt) const { if( !IsEqualExceptRefAndConst(dt) ) return false; if( isReference != dt.isReference ) return false; @@ -567,8 +593,8 @@ bool asCDataType::IsPrimitive() const bool asCDataType::IsMathType() const { if( tokenType == ttInt || tokenType == ttInt8 || tokenType == ttInt16 || tokenType == ttInt64 || - tokenType == ttUInt || tokenType == ttUInt8 || tokenType == ttUInt16 || tokenType == ttUInt64 || - tokenType == ttFloat || tokenType == ttDouble ) + tokenType == ttUInt || tokenType == ttUInt8 || tokenType == ttUInt16 || tokenType == ttUInt64 || + tokenType == ttFloat || tokenType == ttDouble ) return true; return false; @@ -577,36 +603,36 @@ bool asCDataType::IsMathType() const bool asCDataType::IsIntegerType() const { if( tokenType == ttInt || - tokenType == ttInt8 || - tokenType == ttInt16 || - tokenType == ttInt64 ) + tokenType == ttInt8 || + tokenType == ttInt16 || + tokenType == ttInt64 ) return true; // Enums can also be integer types - if (IsEnumType()) + if( IsEnumType() ) { - asCEnumType * enumType = CastToEnumType(typeInfo); + asCEnumType *enumType = CastToEnumType(typeInfo); return enumType->enumType.IsIntegerType(); } - + return false; } bool asCDataType::IsUnsignedType() const { if( tokenType == ttUInt || - tokenType == ttUInt8 || - tokenType == ttUInt16 || - tokenType == ttUInt64 ) + tokenType == ttUInt8 || + tokenType == ttUInt16 || + tokenType == ttUInt64 ) return true; // Enums can also be unsigned integer types - if (IsEnumType()) + if( IsEnumType() ) { - asCEnumType * enumType = CastToEnumType(typeInfo); + asCEnumType *enumType = CastToEnumType(typeInfo); return enumType->enumType.IsUnsignedType(); } - + return false; } @@ -649,7 +675,7 @@ bool asCDataType::IsObject() const bool asCDataType::IsFuncdef() const { - if (typeInfo && (typeInfo->flags & asOBJ_FUNCDEF)) + if( typeInfo && (typeInfo->flags & asOBJ_FUNCDEF) ) return true; return false; @@ -667,28 +693,28 @@ int asCDataType::GetSizeInMemoryBytes() const return 0; if( tokenType == ttInt8 || - tokenType == ttUInt8 ) + tokenType == ttUInt8 ) return 1; if( tokenType == ttInt16 || - tokenType == ttUInt16 ) + tokenType == ttUInt16 ) return 2; if( tokenType == ttDouble || - tokenType == ttInt64 || - tokenType == ttUInt64 ) + tokenType == ttInt64 || + tokenType == ttUInt64 ) return 8; if( tokenType == ttBool ) return AS_SIZEOF_BOOL; - // ?& is actually a reference + an int - if (tokenType == ttQuestion) + // ?& is actually a reference + an int + if( tokenType == ttQuestion ) return AS_PTR_SIZE * 4 + 4; // null handle if( tokenType == ttUnrecognizedToken ) - return 4*AS_PTR_SIZE; + return 4 * AS_PTR_SIZE; return 4; } @@ -698,12 +724,12 @@ int asCDataType::GetSizeInMemoryDWords() const int s = GetSizeInMemoryBytes(); if( s == 0 ) return 0; if( s <= 4 ) return 1; - + // Pad the size to 4 bytes if( s & 0x3 ) s += 4 - (s & 0x3); - return s/4; + return s / 4; } int asCDataType::GetSizeOnStackDWords() const @@ -722,7 +748,7 @@ int asCDataType::GetSizeOnStackDWords() const } #ifdef WIP_16BYTE_ALIGN -int asCDataType::GetAlignment() const +int asCDataType::GetAlignment() const { if( typeInfo == NULL ) { @@ -736,9 +762,9 @@ int asCDataType::GetAlignment() const asSTypeBehaviour *asCDataType::GetBehaviour() const { - if (!typeInfo) return 0; + if( !typeInfo ) return 0; asCObjectType *ot = CastToObjectType(typeInfo); - return ot ? &ot->beh : 0; + return ot ? &ot->beh : 0; } bool asCDataType::IsEnumType() const @@ -746,11 +772,10 @@ bool asCDataType::IsEnumType() const // Do a sanity check on the objectType, to verify that we aren't trying to access memory after it has been released asASSERT(typeInfo == 0 || typeInfo->name.GetLength() < 100); - if (typeInfo && (typeInfo->flags & asOBJ_ENUM)) + if( typeInfo && (typeInfo->flags & asOBJ_ENUM) ) return true; return false; } END_AS_NAMESPACE - diff --git a/sdk/angelscript/source/as_datatype.h b/sdk/angelscript/source/as_datatype.h index 8ff058bd..06273619 100644 --- a/sdk/angelscript/source/as_datatype.h +++ b/sdk/angelscript/source/as_datatype.h @@ -70,72 +70,108 @@ class asCDataType static asCDataType CreatePrimitive(eTokenType tt, bool isConst); static asCDataType CreateType(asCTypeInfo *ti, bool isConst); - static asCDataType CreateById(asCScriptEngine* engine, int typeId, bool isConst); + static asCDataType CreateById(asCScriptEngine *engine, int typeId, bool isConst); static asCDataType CreateAuto(bool isConst); static asCDataType CreateObjectHandle(asCTypeInfo *ot, bool isConst); static asCDataType CreateNullHandle(); - int MakeHandle(bool b, bool acceptHandleForScope = false); - int MakeArray(asCScriptEngine *engine, asCModule *requestingModule); - int MakeReference(bool b); - int MakeReadOnly(bool b); - int MakeHandleToConst(bool b); - void SetIfHandleThenConst(bool b) { ifHandleThenConst = b; } - bool HasIfHandleThenConst() const { return ifHandleThenConst; } - - bool IsTemplate() const; - bool IsScriptObject() const; - bool IsPrimitive() const; - bool IsMathType() const; - bool IsObject() const; - bool IsReference() const {return isReference;} - bool IsAuto() const {return isAuto;} - bool IsReadOnly() const; - bool IsIntegerType() const; - bool IsUnsignedType() const; - bool IsFloatType() const; - bool IsDoubleType() const; - bool IsBooleanType() const; - bool IsObjectHandle() const {return isObjectHandle;} - bool IsHandleToAuto() const {return isAuto && isObjectHandle;} - bool IsHandleToConst() const; - bool IsArrayType() const; - bool IsEnumType() const; - bool IsAnyType() const {return tokenType == ttQuestion;} - bool IsHandleToAsHandleType() const {return isHandleToAsHandleType;} - bool IsAbstractClass() const; - bool IsInterface() const; - bool IsFuncdef() const; - - bool IsObjectConst() const; - - bool IsEqualExceptRef(const asCDataType &) const; - bool IsEqualExceptRefAndConst(const asCDataType &) const; - bool IsEqualExceptConst(const asCDataType &) const; - bool IsNullHandle() const; + int MakeHandle(bool b, bool acceptHandleForScope = false); + int MakeArray(asCScriptEngine *engine, asCModule *requestingModule); + int MakeReference(bool b); + int MakeReadOnly(bool b); + int MakeHandleToConst(bool b); + void SetIfHandleThenConst(bool b) + { + ifHandleThenConst = b; + } + bool HasIfHandleThenConst() const + { + return ifHandleThenConst; + } + + bool IsTemplate() const; + bool IsScriptObject() const; + bool IsPrimitive() const; + bool IsMathType() const; + bool IsObject() const; + bool IsReference() const + { + return isReference; + } + bool IsAuto() const + { + return isAuto; + } + bool IsReadOnly() const; + bool IsIntegerType() const; + bool IsUnsignedType() const; + bool IsFloatType() const; + bool IsDoubleType() const; + bool IsBooleanType() const; + bool IsObjectHandle() const + { + return isObjectHandle; + } + bool IsHandleToAuto() const + { + return isAuto && isObjectHandle; + } + bool IsHandleToConst() const; + bool IsArrayType() const; + bool IsEnumType() const; + bool IsAnyType() const + { + return tokenType == ttQuestion; + } + bool IsHandleToAsHandleType() const + { + return isHandleToAsHandleType; + } + bool IsAbstractClass() const; + bool IsInterface() const; + bool IsFuncdef() const; + + bool IsObjectConst() const; + + bool IsEqualExceptRef(const asCDataType &) const; + bool IsEqualExceptRefAndConst(const asCDataType &) const; + bool IsEqualExceptConst(const asCDataType &) const; + bool IsNullHandle() const; bool SupportHandles() const; bool CanBeInstantiated() const; bool CanBeCopied() const; - bool operator ==(const asCDataType &) const; - bool operator !=(const asCDataType &) const; - - asCDataType GetSubType(asUINT subtypeIndex = 0) const; - eTokenType GetTokenType() const {return tokenType;} - asCTypeInfo *GetTypeInfo() const { return typeInfo; } - - int GetSizeOnStackDWords() const; - int GetSizeInMemoryBytes() const; - int GetSizeInMemoryDWords() const; + bool operator==(const asCDataType &) const; + bool operator!=(const asCDataType &) const; + + asCDataType GetSubType(asUINT subtypeIndex = 0) const; + eTokenType GetTokenType() const + { + return tokenType; + } + asCTypeInfo *GetTypeInfo() const + { + return typeInfo; + } + + int GetSizeOnStackDWords() const; + int GetSizeInMemoryBytes() const; + int GetSizeInMemoryDWords() const; #ifdef WIP_16BYTE_ALIGN - int GetAlignment() const; + int GetAlignment() const; #endif - void SetTokenType(eTokenType tt) {tokenType = tt;} - void SetTypeInfo(asCTypeInfo *ti) {typeInfo = ti;} + void SetTokenType(eTokenType tt) + { + tokenType = tt; + } + void SetTypeInfo(asCTypeInfo *ti) + { + typeInfo = ti; + } - asCDataType &operator =(const asCDataType &); + asCDataType &operator=(const asCDataType &); asSTypeBehaviour *GetBehaviour() const; @@ -150,7 +186,7 @@ class asCDataType bool isConstHandle : 1; bool isAuto : 1; bool isHandleToAsHandleType : 1; // Used by the compiler to know how to initialize the object - bool ifHandleThenConst : 1; // Used when creating template instances to determine if a handle should be const or not + bool ifHandleThenConst : 1; // Used when creating template instances to determine if a handle should be const or not char dummy : 1; // Behaviour type diff --git a/sdk/angelscript/source/as_debug.h b/sdk/angelscript/source/as_debug.h index e67d8b3a..33bc0682 100644 --- a/sdk/angelscript/source/as_debug.h +++ b/sdk/angelscript/source/as_debug.h @@ -51,19 +51,19 @@ #if !defined(_MSC_VER) && (defined(__GNUC__) || defined(AS_MARMALADE)) -#ifdef __ghs__ -// WIIU defines __GNUC__ but types are not defined here in 'conventional' way +#ifdef __ghs__ +// WIIU defines __GNUC__ but types are not defined here in 'conventional' way #include -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef signed short int16_t; -typedef unsigned short uint16_t; -typedef signed int int32_t; -typedef unsigned int uint32_t; -typedef signed long long int64_t; +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed int int32_t; +typedef unsigned int uint32_t; +typedef signed long long int64_t; typedef unsigned long long uint64_t; -typedef float float32_t; -typedef double float64_t; +typedef float float32_t; +typedef double float64_t; #else // Define mkdir for GNUC #include @@ -131,10 +131,10 @@ class CProfiler __int64 ticks; QueryPerformanceCounter((LARGE_INTEGER *)&ticks); - return double(ticks)/ticksPerSecond - timeOffset; + return double(ticks) / ticksPerSecond - timeOffset; } - - return double(timeGetTime())/1000.0 - timeOffset; + + return double(timeGetTime()) / 1000.0 - timeOffset; } double Begin(const char *name) @@ -164,9 +164,9 @@ class CProfiler { cursor->value.time += elapsed; cursor->value.count++; - if( cursor->value.max < elapsed ) + if( cursor->value.max < elapsed ) cursor->value.max = elapsed; - if( cursor->value.min > elapsed ) + if( cursor->value.min > elapsed ) cursor->value.min = elapsed; } else @@ -185,18 +185,18 @@ class CProfiler // Compensate for the time spent writing to the file timeOffset += GetTime() - time; } - + protected: void WriteSummary() { // Write the analyzed info into a file for inspection _mkdir("AS_DEBUG"); FILE *fp; - #if _MSC_VER >= 1500 && !defined(AS_MARMALADE) - fopen_s(&fp, "AS_DEBUG/profiling_summary.txt", "wt"); - #else - fp = fopen("AS_DEBUG/profiling_summary.txt", "wt"); - #endif +#if _MSC_VER >= 1500 && !defined(AS_MARMALADE) + fopen_s(&fp, "AS_DEBUG/profiling_summary.txt", "wt"); +#else + fp = fopen("AS_DEBUG/profiling_summary.txt", "wt"); +#endif if( fp == 0 ) return; @@ -207,11 +207,11 @@ class CProfiler while( cursor ) { asCString key = cursor->key; - int count; - int n = key.FindLast("|", &count); + int count; + int n = key.FindLast("|", &count); if( count ) { - key = asCString(" ", count) + key.SubString(n+1); + key = asCString(" ", count) + key.SubString(n + 1); } fprintf(fp, "%-60s %10d %15.6f %15.6f %15.6f %15.6f\n", key.AddressOf(), cursor->value.count, cursor->value.time, cursor->value.time / cursor->value.count, cursor->value.max, cursor->value.min); @@ -222,9 +222,9 @@ class CProfiler fclose(fp); } - double timeOffset; - double ticksPerSecond; - bool usePerformance; + double timeOffset; + double ticksPerSecond; + bool usePerformance; asCString key; asCMap map; @@ -238,7 +238,7 @@ class CProfilerScope CProfilerScope(const char *name) { this->name = name; - beginTime = g_profiler.Begin(name); + beginTime = g_profiler.Begin(name); } ~CProfilerScope() @@ -258,7 +258,7 @@ END_AS_NAMESPACE #else // !(_MSC_VER && AS_PROFILE) // Define it so nothing is done -#define TimeIt(x) +#define TimeIt(x) #endif // !(_MSC_VER && AS_PROFILE) @@ -266,5 +266,3 @@ END_AS_NAMESPACE #endif // defined(AS_DEBUG_H) - - diff --git a/sdk/angelscript/source/as_gc.cpp b/sdk/angelscript/source/as_gc.cpp index d6004e38..17603d0b 100644 --- a/sdk/angelscript/source/as_gc.cpp +++ b/sdk/angelscript/source/as_gc.cpp @@ -88,7 +88,7 @@ int asCGarbageCollector::AddScriptObjectToGC(void *obj, asCObjectType *objType) // Invoke the garbage collector to destroy a little garbage as new comes in // This will maintain the number of objects in the GC at a maintainable level without - // halting the application, and without burdening the application with manually invoking the + // halting the application, and without burdening the application with manually invoking the // garbage collector. if( engine->ep.autoGarbageCollect && gcNewObjects.GetLength() ) { @@ -100,7 +100,7 @@ int asCGarbageCollector::AddScriptObjectToGC(void *obj, asCObjectType *objType) { isProcessing = true; - // TODO: The number of iterations should be dynamic, and increase + // TODO: The number of iterations should be dynamic, and increase // if the number of objects in the garbage collector grows high // Run one step of DetectGarbage @@ -136,24 +136,24 @@ int asCGarbageCollector::AddScriptObjectToGC(void *obj, asCObjectType *objType) int asCGarbageCollector::GetObjectInGC(asUINT idx, asUINT *seqNbr, void **obj, asITypeInfo **type) { if( seqNbr ) *seqNbr = 0; - if( obj ) *obj = 0; - if( type ) *type = 0; + if( obj ) *obj = 0; + if( type ) *type = 0; ENTERCRITICALSECTION(gcCritical); - asSObjTypePair *o = 0; - asUINT newObjs = asUINT(gcNewObjects.GetLength()); + asSObjTypePair *o = 0; + asUINT newObjs = asUINT(gcNewObjects.GetLength()); if( idx < newObjs ) o = &gcNewObjects[idx]; else if( idx < gcOldObjects.GetLength() + newObjs ) - o = &gcOldObjects[idx-newObjs]; + o = &gcOldObjects[idx - newObjs]; else { LEAVECRITICALSECTION(gcCritical); return asINVALID_ARG; } if( seqNbr ) *seqNbr = o->seqNbr; - if( obj ) *obj = o->obj; - if( type ) *type = o->type; + if( obj ) *obj = o->obj; + if( type ) *type = o->type; LEAVECRITICALSECTION(gcCritical); return asSUCCESS; @@ -162,7 +162,7 @@ int asCGarbageCollector::GetObjectInGC(asUINT idx, asUINT *seqNbr, void **obj, a // TODO: Should have a flag to tell the garbage collector to automatically determine how many iterations are needed // It should then gather statistics such as how many objects has been created since last run, and how many objects // are destroyed per iteration, and how many objects are detected as cyclic garbage per iteration. -// It should try to reach a stable number of objects, i.e. so that on average the number of objects added to +// It should try to reach a stable number of objects, i.e. so that on average the number of objects added to // the garbage collector is the same as the number of objects destroyed. And it should try to minimize the number // of iterations of detections that must be executed per cycle while still identifying the cyclic garbage // These variables should also be available for inspection through the gcstatistics. @@ -172,15 +172,15 @@ int asCGarbageCollector::GarbageCollect(asDWORD flags, asUINT iterations) if( TRYENTERCRITICALSECTION(gcCollecting) ) { // If the GC is already processing in this thread, then don't enter here again - if( isProcessing ) - { + if( isProcessing ) + { LEAVECRITICALSECTION(gcCollecting); return 1; } isProcessing = true; - bool doDetect = (flags & asGC_DETECT_GARBAGE) || !(flags & asGC_DESTROY_GARBAGE); + bool doDetect = (flags & asGC_DETECT_GARBAGE) || !(flags & asGC_DESTROY_GARBAGE); bool doDestroy = (flags & asGC_DESTROY_GARBAGE) || !(flags & asGC_DETECT_GARBAGE); if( flags & asGC_FULL_CYCLE ) @@ -190,7 +190,7 @@ int asCGarbageCollector::GarbageCollect(asDWORD flags, asUINT iterations) { // Move all new objects to the old list, so we guarantee that all is detected MoveAllObjectsToOldList(); - detectState = clearCounters_init; + detectState = clearCounters_init; } if( doDestroy ) { @@ -202,7 +202,7 @@ int asCGarbageCollector::GarbageCollect(asDWORD flags, asUINT iterations) // set of objects scanned for garbage is fixed even if new objects are added // by other threads in parallel. unsigned int count = (unsigned int)(gcOldObjects.GetLength()); - for(;;) + for( ;; ) { // Detect all garbage with cyclic references if( doDetect ) @@ -247,7 +247,7 @@ int asCGarbageCollector::GarbageCollect(asDWORD flags, asUINT iterations) isProcessing = false; LEAVECRITICALSECTION(gcCollecting); } - + // Return 1 to indicate that the cycle wasn't finished return 1; } @@ -316,7 +316,7 @@ void asCGarbageCollector::RemoveNewObjectAtIdx(int idx) // We need to protect this update with a critical section as // another thread might be appending an object at the same time ENTERCRITICALSECTION(gcCritical); - if( idx == (int)gcNewObjects.GetLength() - 1) + if( idx == (int)gcNewObjects.GetLength() - 1 ) gcNewObjects.PopLast(); else gcNewObjects[idx] = gcNewObjects.PopLast(); @@ -328,7 +328,7 @@ void asCGarbageCollector::RemoveOldObjectAtIdx(int idx) // We need to protect this update with a critical section as // another thread might be appending an object at the same time ENTERCRITICALSECTION(gcCritical); - if( idx == (int)gcOldObjects.GetLength() - 1) + if( idx == (int)gcOldObjects.GetLength() - 1 ) gcOldObjects.PopLast(); else gcOldObjects[idx] = gcOldObjects.PopLast(); @@ -341,7 +341,7 @@ void asCGarbageCollector::MoveObjectToOldList(int idx) // another thread might be appending an object at the same time ENTERCRITICALSECTION(gcCritical); gcOldObjects.PushLast(gcNewObjects[idx]); - if( idx == (int)gcNewObjects.GetLength() - 1) + if( idx == (int)gcNewObjects.GetLength() - 1 ) gcNewObjects.PopLast(); else gcNewObjects[idx] = gcNewObjects.PopLast(); @@ -363,106 +363,106 @@ int asCGarbageCollector::DestroyNewGarbage() // This function will only be called within the critical section gcCollecting asASSERT(isProcessing); - for(;;) + for( ;; ) { switch( destroyNewState ) { - case destroyGarbage_init: - { - // If there are no objects to be freed then don't start - if( gcNewObjects.GetLength() == 0 ) - return 0; - - // Update the seqAtSweepStart which is used to determine when - // to move an object from the new set to the old set - seqAtSweepStart[0] = seqAtSweepStart[1]; - seqAtSweepStart[1] = seqAtSweepStart[2]; - seqAtSweepStart[2] = numAdded; - - destroyNewIdx = (asUINT)-1; - destroyNewState = destroyGarbage_loop; - } - break; + case destroyGarbage_init: + { + // If there are no objects to be freed then don't start + if( gcNewObjects.GetLength() == 0 ) + return 0; - case destroyGarbage_loop: - case destroyGarbage_haveMore: - { - // If the refCount has reached 1, then only the GC still holds a - // reference to the object, thus we don't need to worry about the - // application touching the objects during collection. - - // Destroy all objects that have refCount == 1. If any objects are - // destroyed, go over the list again, because it may have made more - // objects reach refCount == 1. - if( ++destroyNewIdx < gcNewObjects.GetLength() ) + // Update the seqAtSweepStart which is used to determine when + // to move an object from the new set to the old set + seqAtSweepStart[0] = seqAtSweepStart[1]; + seqAtSweepStart[1] = seqAtSweepStart[2]; + seqAtSweepStart[2] = numAdded; + + destroyNewIdx = (asUINT)-1; + destroyNewState = destroyGarbage_loop; + } + break; + + case destroyGarbage_loop: + case destroyGarbage_haveMore: { - asSObjTypePair gcObj = GetNewObjectAtIdx(destroyNewIdx); - if( engine->CallObjectMethodRetInt(gcObj.obj, gcObj.type->beh.gcGetRefCount) == 1 ) + // If the refCount has reached 1, then only the GC still holds a + // reference to the object, thus we don't need to worry about the + // application touching the objects during collection. + + // Destroy all objects that have refCount == 1. If any objects are + // destroyed, go over the list again, because it may have made more + // objects reach refCount == 1. + if( ++destroyNewIdx < gcNewObjects.GetLength() ) { - // Release the object immediately - - // Make sure the refCount is really 0, because the - // destructor may have increased the refCount again. - bool addRef = false; - if( gcObj.type->flags & asOBJ_SCRIPT_OBJECT ) + asSObjTypePair gcObj = GetNewObjectAtIdx(destroyNewIdx); + if( engine->CallObjectMethodRetInt(gcObj.obj, gcObj.type->beh.gcGetRefCount) == 1 ) { - // Script objects may actually be resurrected in the destructor - int refCount = ((asCScriptObject*)gcObj.obj)->Release(); - if( refCount > 0 ) addRef = true; + // Release the object immediately + + // Make sure the refCount is really 0, because the + // destructor may have increased the refCount again. + bool addRef = false; + if( gcObj.type->flags & asOBJ_SCRIPT_OBJECT ) + { + // Script objects may actually be resurrected in the destructor + int refCount = ((asCScriptObject *)gcObj.obj)->Release(); + if( refCount > 0 ) addRef = true; + } + else + engine->CallObjectMethod(gcObj.obj, gcObj.type->beh.release); + + // Was the object really destroyed? + if( !addRef ) + { + numDestroyed++; + numNewDestroyed++; + RemoveNewObjectAtIdx(destroyNewIdx); + destroyNewIdx--; + } + else + { + // Since the object was resurrected in the + // destructor, we must add our reference again + engine->CallObjectMethod(gcObj.obj, gcObj.type->beh.addref); + } + + destroyNewState = destroyGarbage_haveMore; } - else - engine->CallObjectMethod(gcObj.obj, gcObj.type->beh.release); - - // Was the object really destroyed? - if( !addRef ) + // Check if this object has been inspected 3 times already, and if so move it to the + // set of old objects that are less likely to become garbage in a short time + // TODO: Is 3 really a good value? Should the number of times be dynamic? + else if( gcObj.seqNbr < seqAtSweepStart[0] ) { - numDestroyed++; - numNewDestroyed++; - RemoveNewObjectAtIdx(destroyNewIdx); + // We've already verified this object multiple times. It is likely + // to live for quite a long time so we'll move it to the list if old objects + MoveObjectToOldList(destroyNewIdx); destroyNewIdx--; } - else - { - // Since the object was resurrected in the - // destructor, we must add our reference again - engine->CallObjectMethod(gcObj.obj, gcObj.type->beh.addref); - } - - destroyNewState = destroyGarbage_haveMore; - } - // Check if this object has been inspected 3 times already, and if so move it to the - // set of old objects that are less likely to become garbage in a short time - // TODO: Is 3 really a good value? Should the number of times be dynamic? - else if( gcObj.seqNbr < seqAtSweepStart[0] ) - { - // We've already verified this object multiple times. It is likely - // to live for quite a long time so we'll move it to the list if old objects - MoveObjectToOldList(destroyNewIdx); - destroyNewIdx--; - } - // Allow the application to work a little - return 1; - } - else - { - if( destroyNewState == destroyGarbage_haveMore ) - { - // Restart the cycle - destroyNewState = destroyGarbage_init; + // Allow the application to work a little + return 1; } else { - // Restart the cycle - destroyNewState = destroyGarbage_init; + if( destroyNewState == destroyGarbage_haveMore ) + { + // Restart the cycle + destroyNewState = destroyGarbage_init; + } + else + { + // Restart the cycle + destroyNewState = destroyGarbage_init; - // Return 0 to tell the application that there - // is no more garbage to destroy at the moment - return 0; + // Return 0 to tell the application that there + // is no more garbage to destroy at the moment + return 0; + } } } - } - break; + break; } } @@ -493,12 +493,12 @@ int asCGarbageCollector::ReportAndReleaseUndestroyedObjects() { // Unfortunately we can't show the function declaration here, because the engine may have released the parameter list already so the declaration would only be misleading // We need to show the function type too as for example delegates do not have a name - msg.Format(TXT_PREV_FUNC_IS_NAMED_s_TYPE_IS_d, reinterpret_cast(gcObj.obj)->GetName(), reinterpret_cast(gcObj.obj)->GetFuncType()); + msg.Format(TXT_PREV_FUNC_IS_NAMED_s_TYPE_IS_d, reinterpret_cast(gcObj.obj)->GetName(), reinterpret_cast(gcObj.obj)->GetFuncType()); engine->WriteMessage("", 0, 0, asMSGTYPE_INFORMATION, msg.AddressOf()); } else if( gcObj.type->name == "$obj" ) { - msg.Format(TXT_PREV_TYPE_IS_NAMED_s, reinterpret_cast(gcObj.obj)->GetName()); + msg.Format(TXT_PREV_TYPE_IS_NAMED_s, reinterpret_cast(gcObj.obj)->GetName()); engine->WriteMessage("", 0, 0, asMSGTYPE_INFORMATION, msg.AddressOf()); } @@ -516,106 +516,106 @@ int asCGarbageCollector::DestroyOldGarbage() // This function will only be called within the critical section gcCollecting asASSERT(isProcessing); - for(;;) + for( ;; ) { switch( destroyOldState ) { - case destroyGarbage_init: - { - // If there are no objects to be freed then don't start - if( gcOldObjects.GetLength() == 0 ) - return 0; + case destroyGarbage_init: + { + // If there are no objects to be freed then don't start + if( gcOldObjects.GetLength() == 0 ) + return 0; - destroyOldIdx = (asUINT)-1; - destroyOldState = destroyGarbage_loop; - } - break; + destroyOldIdx = (asUINT)-1; + destroyOldState = destroyGarbage_loop; + } + break; - case destroyGarbage_loop: - case destroyGarbage_haveMore: - { - // If the refCount has reached 1, then only the GC still holds a - // reference to the object, thus we don't need to worry about the - // application touching the objects during collection. - - // Destroy all objects that have refCount == 1. If any objects are - // destroyed, go over the list again, because it may have made more - // objects reach refCount == 1. - if( ++destroyOldIdx < gcOldObjects.GetLength() ) + case destroyGarbage_loop: + case destroyGarbage_haveMore: { - asSObjTypePair gcObj = GetOldObjectAtIdx(destroyOldIdx); - - if( gcObj.type->beh.gcGetRefCount == 0 ) - { - // If circular references are formed with registered types that hasn't - // registered the GC behaviours, then the engine may be forced to free - // the object type before the actual object instance. In this case we - // will be forced to skip the destruction of the objects, so as not to - // crash the application. - asCString msg; - msg.Format(TXT_d_GC_CANNOT_FREE_OBJ_OF_TYPE_s, gcObj.seqNbr, gcObj.type->name.AddressOf()); - engine->WriteMessage("", 0, 0, asMSGTYPE_ERROR, msg.AddressOf()); - - // Just remove the object, as we will not bother to destroy it - numDestroyed++; - RemoveOldObjectAtIdx(destroyOldIdx); - destroyOldIdx--; - } - else if( engine->CallObjectMethodRetInt(gcObj.obj, gcObj.type->beh.gcGetRefCount) == 1 ) + // If the refCount has reached 1, then only the GC still holds a + // reference to the object, thus we don't need to worry about the + // application touching the objects during collection. + + // Destroy all objects that have refCount == 1. If any objects are + // destroyed, go over the list again, because it may have made more + // objects reach refCount == 1. + if( ++destroyOldIdx < gcOldObjects.GetLength() ) { - // Release the object immediately + asSObjTypePair gcObj = GetOldObjectAtIdx(destroyOldIdx); - // Make sure the refCount is really 0, because the - // destructor may have increased the refCount again. - bool addRef = false; - if( gcObj.type->flags & asOBJ_SCRIPT_OBJECT ) - { - // Script objects may actually be resurrected in the destructor - int refCount = ((asCScriptObject*)gcObj.obj)->Release(); - if( refCount > 0 ) addRef = true; - } - else - engine->CallObjectMethod(gcObj.obj, gcObj.type->beh.release); - - // Was the object really destroyed? - if( !addRef ) + if( gcObj.type->beh.gcGetRefCount == 0 ) { + // If circular references are formed with registered types that hasn't + // registered the GC behaviours, then the engine may be forced to free + // the object type before the actual object instance. In this case we + // will be forced to skip the destruction of the objects, so as not to + // crash the application. + asCString msg; + msg.Format(TXT_d_GC_CANNOT_FREE_OBJ_OF_TYPE_s, gcObj.seqNbr, gcObj.type->name.AddressOf()); + engine->WriteMessage("", 0, 0, asMSGTYPE_ERROR, msg.AddressOf()); + + // Just remove the object, as we will not bother to destroy it numDestroyed++; RemoveOldObjectAtIdx(destroyOldIdx); destroyOldIdx--; } - else + else if( engine->CallObjectMethodRetInt(gcObj.obj, gcObj.type->beh.gcGetRefCount) == 1 ) { - // Since the object was resurrected in the - // destructor, we must add our reference again - engine->CallObjectMethod(gcObj.obj, gcObj.type->beh.addref); + // Release the object immediately + + // Make sure the refCount is really 0, because the + // destructor may have increased the refCount again. + bool addRef = false; + if( gcObj.type->flags & asOBJ_SCRIPT_OBJECT ) + { + // Script objects may actually be resurrected in the destructor + int refCount = ((asCScriptObject *)gcObj.obj)->Release(); + if( refCount > 0 ) addRef = true; + } + else + engine->CallObjectMethod(gcObj.obj, gcObj.type->beh.release); + + // Was the object really destroyed? + if( !addRef ) + { + numDestroyed++; + RemoveOldObjectAtIdx(destroyOldIdx); + destroyOldIdx--; + } + else + { + // Since the object was resurrected in the + // destructor, we must add our reference again + engine->CallObjectMethod(gcObj.obj, gcObj.type->beh.addref); + } + + destroyOldState = destroyGarbage_haveMore; } - destroyOldState = destroyGarbage_haveMore; - } - - // Allow the application to work a little - return 1; - } - else - { - if( destroyOldState == destroyGarbage_haveMore ) - { - // Restart the cycle - destroyOldState = destroyGarbage_init; + // Allow the application to work a little + return 1; } else { - // Restart the cycle - destroyOldState = destroyGarbage_init; + if( destroyOldState == destroyGarbage_haveMore ) + { + // Restart the cycle + destroyOldState = destroyGarbage_init; + } + else + { + // Restart the cycle + destroyOldState = destroyGarbage_init; - // Return 0 to tell the application that there - // is no more garbage to destroy at the moment - return 0; + // Return 0 to tell the application that there + // is no more garbage to destroy at the moment + return 0; + } } } - } - break; + break; } } @@ -628,306 +628,306 @@ int asCGarbageCollector::IdentifyGarbageWithCyclicRefs() // This function will only be called within the critical section gcCollecting asASSERT(isProcessing); - for(;;) + for( ;; ) { switch( detectState ) { - case clearCounters_init: - detectState = clearCounters_loop; - break; + case clearCounters_init: + detectState = clearCounters_loop; + break; - case clearCounters_loop: - { - // Decrease reference counter for all objects removed from the map - asSMapNode *cursor = 0; - gcMap.MoveFirst(&cursor); - if( cursor ) + case clearCounters_loop: { - void *obj = gcMap.GetKey(cursor); - asSIntTypePair it = gcMap.GetValue(cursor); + // Decrease reference counter for all objects removed from the map + asSMapNode *cursor = 0; + gcMap.MoveFirst(&cursor); + if( cursor ) + { + void *obj = gcMap.GetKey(cursor); + asSIntTypePair it = gcMap.GetValue(cursor); - engine->CallObjectMethod(obj, it.type->beh.release); + engine->CallObjectMethod(obj, it.type->beh.release); - ReturnNode(gcMap.Remove(cursor)); + ReturnNode(gcMap.Remove(cursor)); - return 1; - } + return 1; + } - detectState = buildMap_init; - } - break; + detectState = buildMap_init; + } + break; - case buildMap_init: - detectIdx = 0; - detectState = buildMap_loop; - break; + case buildMap_init: + detectIdx = 0; + detectState = buildMap_loop; + break; - case buildMap_loop: - { - // Build a map of objects that will be checked, the map will - // hold the object pointer as key, and the gcCount and the - // object's type as value. As objects are added to the map the - // gcFlag must be set in the objects, so we can be verify if - // the object is accessed during the GC cycle. - - // If an object is removed from the gcObjects list during the - // iteration of this step, it is possible that an object won't - // be used during the analyzing for cyclic references. This - // isn't a problem, as the next time the GC cycle starts the - // object will be verified. - if( detectIdx < gcOldObjects.GetLength() ) + case buildMap_loop: { - // Add the gc count for this object - asSObjTypePair gcObj = GetOldObjectAtIdx(detectIdx); - - int refCount = 0; - if( gcObj.type->beh.gcGetRefCount ) - refCount = engine->CallObjectMethodRetInt(gcObj.obj, gcObj.type->beh.gcGetRefCount); - - if( refCount > 1 ) + // Build a map of objects that will be checked, the map will + // hold the object pointer as key, and the gcCount and the + // object's type as value. As objects are added to the map the + // gcFlag must be set in the objects, so we can be verify if + // the object is accessed during the GC cycle. + + // If an object is removed from the gcObjects list during the + // iteration of this step, it is possible that an object won't + // be used during the analyzing for cyclic references. This + // isn't a problem, as the next time the GC cycle starts the + // object will be verified. + if( detectIdx < gcOldObjects.GetLength() ) { - asSIntTypePair it = {refCount-1, gcObj.type}; + // Add the gc count for this object + asSObjTypePair gcObj = GetOldObjectAtIdx(detectIdx); - gcMap.Insert(GetNode(gcObj.obj, it)); + int refCount = 0; + if( gcObj.type->beh.gcGetRefCount ) + refCount = engine->CallObjectMethodRetInt(gcObj.obj, gcObj.type->beh.gcGetRefCount); - // Increment the object's reference counter when putting it in the map - engine->CallObjectMethod(gcObj.obj, gcObj.type->beh.addref); + if( refCount > 1 ) + { + asSIntTypePair it = {refCount - 1, gcObj.type}; - // Mark the object so that we can - // see if it has changed since read - engine->CallObjectMethod(gcObj.obj, gcObj.type->beh.gcSetFlag); - } + gcMap.Insert(GetNode(gcObj.obj, it)); - detectIdx++; + // Increment the object's reference counter when putting it in the map + engine->CallObjectMethod(gcObj.obj, gcObj.type->beh.addref); - // Let the application work a little - return 1; - } - else - detectState = countReferences_init; - } - break; + // Mark the object so that we can + // see if it has changed since read + engine->CallObjectMethod(gcObj.obj, gcObj.type->beh.gcSetFlag); + } - case countReferences_init: - { - gcMap.MoveFirst(&gcMapCursor); - detectState = countReferences_loop; - } - break; + detectIdx++; - case countReferences_loop: - { - // Call EnumReferences on all objects in the map to count the number - // of references reachable from between objects in the map. If all - // references for an object in the map is reachable from other objects - // in the map, then we know that no outside references are held for - // this object, thus it is a potential dead object in a circular reference. - - // If the gcFlag is cleared for an object we consider the object alive - // and referenced from outside the GC, thus we don't enumerate its references. - - // Any new objects created after this step in the GC cycle won't be - // in the map, and is thus automatically considered alive. - if( gcMapCursor ) + // Let the application work a little + return 1; + } + else + detectState = countReferences_init; + } + break; + + case countReferences_init: { - void *obj = gcMap.GetKey(gcMapCursor); - asCObjectType *type = gcMap.GetValue(gcMapCursor).type; - gcMap.MoveNext(&gcMapCursor, gcMapCursor); + gcMap.MoveFirst(&gcMapCursor); + detectState = countReferences_loop; + } + break; - if( engine->CallObjectMethodRetBool(obj, type->beh.gcGetFlag) ) + case countReferences_loop: + { + // Call EnumReferences on all objects in the map to count the number + // of references reachable from between objects in the map. If all + // references for an object in the map is reachable from other objects + // in the map, then we know that no outside references are held for + // this object, thus it is a potential dead object in a circular reference. + + // If the gcFlag is cleared for an object we consider the object alive + // and referenced from outside the GC, thus we don't enumerate its references. + + // Any new objects created after this step in the GC cycle won't be + // in the map, and is thus automatically considered alive. + if( gcMapCursor ) { - engine->CallObjectMethod(obj, engine, type->beh.gcEnumReferences); + void *obj = gcMap.GetKey(gcMapCursor); + asCObjectType *type = gcMap.GetValue(gcMapCursor).type; + gcMap.MoveNext(&gcMapCursor, gcMapCursor); + + if( engine->CallObjectMethodRetBool(obj, type->beh.gcGetFlag) ) + { + engine->CallObjectMethod(obj, engine, type->beh.gcEnumReferences); + } + + // Allow the application to work a little + return 1; } + else + detectState = detectGarbage_init; + } + break; - // Allow the application to work a little - return 1; + case detectGarbage_init: + { + gcMap.MoveFirst(&gcMapCursor); + liveObjects.SetLength(0); + detectState = detectGarbage_loop1; } - else - detectState = detectGarbage_init; - } - break; + break; - case detectGarbage_init: - { - gcMap.MoveFirst(&gcMapCursor); - liveObjects.SetLength(0); - detectState = detectGarbage_loop1; - } - break; + case detectGarbage_loop1: + { + // All objects that are known not to be dead must be removed from the map, + // along with all objects they reference. What remains in the map after + // this pass is sure to be dead objects in circular references. - case detectGarbage_loop1: - { - // All objects that are known not to be dead must be removed from the map, - // along with all objects they reference. What remains in the map after - // this pass is sure to be dead objects in circular references. + // An object is considered alive if its gcFlag is cleared, or all the + // references were not found in the map. - // An object is considered alive if its gcFlag is cleared, or all the - // references were not found in the map. + // Add all alive objects from the map to the liveObjects array + if( gcMapCursor ) + { + asSMapNode *cursor = gcMapCursor; + gcMap.MoveNext(&gcMapCursor, gcMapCursor); - // Add all alive objects from the map to the liveObjects array - if( gcMapCursor ) - { - asSMapNode *cursor = gcMapCursor; - gcMap.MoveNext(&gcMapCursor, gcMapCursor); + void *obj = gcMap.GetKey(cursor); + asSIntTypePair it = gcMap.GetValue(cursor); - void *obj = gcMap.GetKey(cursor); - asSIntTypePair it = gcMap.GetValue(cursor); + bool gcFlag = engine->CallObjectMethodRetBool(obj, it.type->beh.gcGetFlag); + if( !gcFlag || it.i > 0 ) + { + liveObjects.PushLast(obj); + } - bool gcFlag = engine->CallObjectMethodRetBool(obj, it.type->beh.gcGetFlag); - if( !gcFlag || it.i > 0 ) - { - liveObjects.PushLast(obj); + // Allow the application to work a little + return 1; } - - // Allow the application to work a little - return 1; + else + detectState = detectGarbage_loop2; } - else - detectState = detectGarbage_loop2; - } - break; + break; - case detectGarbage_loop2: - { - // In this step we are actually removing the alive objects from the map. - // As the object is removed, all the objects it references are added to the - // liveObjects list, by calling EnumReferences. Only objects still in the map - // will be added to the liveObjects list. - if( liveObjects.GetLength() ) + case detectGarbage_loop2: { - void *gcObj = liveObjects.PopLast(); - asCObjectType *type = 0; - - // Remove the object from the map to mark it as alive - asSMapNode *cursor = 0; - if( gcMap.MoveTo(&cursor, gcObj) ) + // In this step we are actually removing the alive objects from the map. + // As the object is removed, all the objects it references are added to the + // liveObjects list, by calling EnumReferences. Only objects still in the map + // will be added to the liveObjects list. + if( liveObjects.GetLength() ) { - type = gcMap.GetValue(cursor).type; - ReturnNode(gcMap.Remove(cursor)); + void *gcObj = liveObjects.PopLast(); + asCObjectType *type = 0; - // We need to decrease the reference count again as we remove the object from the map - engine->CallObjectMethod(gcObj, type->beh.release); + // Remove the object from the map to mark it as alive + asSMapNode *cursor = 0; + if( gcMap.MoveTo(&cursor, gcObj) ) + { + type = gcMap.GetValue(cursor).type; + ReturnNode(gcMap.Remove(cursor)); - // Enumerate all the object's references so that they too can be marked as alive - engine->CallObjectMethod(gcObj, engine, type->beh.gcEnumReferences); - } + // We need to decrease the reference count again as we remove the object from the map + engine->CallObjectMethod(gcObj, type->beh.release); - // Allow the application to work a little - return 1; - } - else - detectState = verifyUnmarked_init; - } - break; + // Enumerate all the object's references so that they too can be marked as alive + engine->CallObjectMethod(gcObj, engine, type->beh.gcEnumReferences); + } - case verifyUnmarked_init: - gcMap.MoveFirst(&gcMapCursor); - detectState = verifyUnmarked_loop; + // Allow the application to work a little + return 1; + } + else + detectState = verifyUnmarked_init; + } break; - case verifyUnmarked_loop: - { - // In this step we must make sure that none of the objects still in the map - // has been touched by the application. If they have then we must run the - // detectGarbage loop once more. - if( gcMapCursor ) - { - void *gcObj = gcMap.GetKey(gcMapCursor); - asCObjectType *type = gcMap.GetValue(gcMapCursor).type; + case verifyUnmarked_init: + gcMap.MoveFirst(&gcMapCursor); + detectState = verifyUnmarked_loop; + break; - bool gcFlag = engine->CallObjectMethodRetBool(gcObj, type->beh.gcGetFlag); - if( !gcFlag ) + case verifyUnmarked_loop: + { + // In this step we must make sure that none of the objects still in the map + // has been touched by the application. If they have then we must run the + // detectGarbage loop once more. + if( gcMapCursor ) { - // The unmarked object was touched, rerun the detectGarbage loop - detectState = detectGarbage_init; + void *gcObj = gcMap.GetKey(gcMapCursor); + asCObjectType *type = gcMap.GetValue(gcMapCursor).type; + + bool gcFlag = engine->CallObjectMethodRetBool(gcObj, type->beh.gcGetFlag); + if( !gcFlag ) + { + // The unmarked object was touched, rerun the detectGarbage loop + detectState = detectGarbage_init; + } + else + gcMap.MoveNext(&gcMapCursor, gcMapCursor); + + // Allow the application to work a little + return 1; } else - gcMap.MoveNext(&gcMapCursor, gcMapCursor); - - // Allow the application to work a little - return 1; - } - else - { - // No unmarked object was touched, we can now be sure - // that objects that have gcCount == 0 really is garbage - detectState = breakCircles_init; + { + // No unmarked object was touched, we can now be sure + // that objects that have gcCount == 0 really is garbage + detectState = breakCircles_init; + } } - } - break; + break; - case breakCircles_init: - { - gcMap.MoveFirst(&gcMapCursor); - detectState = breakCircles_loop; - - // If the application has requested a callback for detected circular references, - // then make that callback now for all the objects in the list. This step is not - // done in incremental steps as it is only meant for debugging purposes and thus - // doesn't require interactivity - if (gcMapCursor && circularRefDetectCallbackFunc) + case breakCircles_init: { - while (gcMapCursor) + gcMap.MoveFirst(&gcMapCursor); + detectState = breakCircles_loop; + + // If the application has requested a callback for detected circular references, + // then make that callback now for all the objects in the list. This step is not + // done in incremental steps as it is only meant for debugging purposes and thus + // doesn't require interactivity + if( gcMapCursor && circularRefDetectCallbackFunc ) { - void *gcObj = gcMap.GetKey(gcMapCursor); - asCObjectType *type = gcMap.GetValue(gcMapCursor).type; - circularRefDetectCallbackFunc(type, gcObj, circularRefDetectCallbackParam); + while( gcMapCursor ) + { + void *gcObj = gcMap.GetKey(gcMapCursor); + asCObjectType *type = gcMap.GetValue(gcMapCursor).type; + circularRefDetectCallbackFunc(type, gcObj, circularRefDetectCallbackParam); - gcMap.MoveNext(&gcMapCursor, gcMapCursor); - } + gcMap.MoveNext(&gcMapCursor, gcMapCursor); + } - // Reset iterator - gcMap.MoveFirst(&gcMapCursor); + // Reset iterator + gcMap.MoveFirst(&gcMapCursor); + } } - } - break; + break; - case breakCircles_loop: - case breakCircles_haveGarbage: - { - // All objects in the map are now known to be dead objects - // kept alive through circular references. To be able to free - // these objects we need to force the breaking of the circle - // by having the objects release their references. - if( gcMapCursor ) + case breakCircles_loop: + case breakCircles_haveGarbage: { - numDetected++; - void *gcObj = gcMap.GetKey(gcMapCursor); - asCObjectType *type = gcMap.GetValue(gcMapCursor).type; - if( type->flags & asOBJ_SCRIPT_OBJECT ) + // All objects in the map are now known to be dead objects + // kept alive through circular references. To be able to free + // these objects we need to force the breaking of the circle + // by having the objects release their references. + if( gcMapCursor ) { - // For script objects we must call the class destructor before - // releasing the references, otherwise the destructor may not - // be able to perform the necessary clean-up as the handles will - // be null. - reinterpret_cast(gcObj)->CallDestructor(); - } - engine->CallObjectMethod(gcObj, engine, type->beh.gcReleaseAllReferences); + numDetected++; + void *gcObj = gcMap.GetKey(gcMapCursor); + asCObjectType *type = gcMap.GetValue(gcMapCursor).type; + if( type->flags & asOBJ_SCRIPT_OBJECT ) + { + // For script objects we must call the class destructor before + // releasing the references, otherwise the destructor may not + // be able to perform the necessary clean-up as the handles will + // be null. + reinterpret_cast(gcObj)->CallDestructor(); + } + engine->CallObjectMethod(gcObj, engine, type->beh.gcReleaseAllReferences); - gcMap.MoveNext(&gcMapCursor, gcMapCursor); + gcMap.MoveNext(&gcMapCursor, gcMapCursor); - detectState = breakCircles_haveGarbage; + detectState = breakCircles_haveGarbage; - // Allow the application to work a little - return 1; - } - else - { - // If no garbage was detected we can finish now - if( detectState != breakCircles_haveGarbage ) - { - // Restart the GC - detectState = clearCounters_init; - return 0; + // Allow the application to work a little + return 1; } else { - // Restart the GC - detectState = clearCounters_init; - return 1; + // If no garbage was detected we can finish now + if( detectState != breakCircles_haveGarbage ) + { + // Restart the GC + detectState = clearCounters_init; + return 0; + } + else + { + // Restart the GC + detectState = clearCounters_init; + return 1; + } } } - } } // switch } @@ -952,7 +952,7 @@ asCGarbageCollector::asSMapNode_t *asCGarbageCollector::GetNode(void *obj, asSIn return 0; } } - + node->Init(obj, it); return node; } @@ -974,7 +974,7 @@ void asCGarbageCollector::GCEnumCallback(void *reference) if( detectState == countReferences_loop ) { // Find the reference in the map - asSMapNode *cursor = 0; + asSMapNode *cursor = 0; if( gcMap.MoveTo(&cursor, reference) ) { // Decrease the counter in the map for the reference @@ -984,7 +984,7 @@ void asCGarbageCollector::GCEnumCallback(void *reference) else if( detectState == detectGarbage_loop2 ) { // Find the reference in the map - asSMapNode *cursor = 0; + asSMapNode *cursor = 0; if( gcMap.MoveTo(&cursor, reference) ) { // Add the object to the list of objects to mark as alive @@ -994,4 +994,3 @@ void asCGarbageCollector::GCEnumCallback(void *reference) } END_AS_NAMESPACE - diff --git a/sdk/angelscript/source/as_gc.h b/sdk/angelscript/source/as_gc.h index 76f27357..b0b0194d 100644 --- a/sdk/angelscript/source/as_gc.h +++ b/sdk/angelscript/source/as_gc.h @@ -56,34 +56,41 @@ class asCGarbageCollector asCGarbageCollector(); ~asCGarbageCollector(); - int GarbageCollect(asDWORD flags, asUINT iterations); - void GetStatistics(asUINT *currentSize, asUINT *totalDestroyed, asUINT *totalDetected, asUINT *newObjects, asUINT *totalNewDestroyed) const; - void GCEnumCallback(void *reference); - int AddScriptObjectToGC(void *obj, asCObjectType *objType); - int GetObjectInGC(asUINT idx, asUINT *seqNbr, void **obj, asITypeInfo **type); + int GarbageCollect(asDWORD flags, asUINT iterations); + void GetStatistics(asUINT *currentSize, asUINT *totalDestroyed, asUINT *totalDetected, asUINT *newObjects, asUINT *totalNewDestroyed) const; + void GCEnumCallback(void *reference); + int AddScriptObjectToGC(void *obj, asCObjectType *objType); + int GetObjectInGC(asUINT idx, asUINT *seqNbr, void **obj, asITypeInfo **type); - int ReportAndReleaseUndestroyedObjects(); + int ReportAndReleaseUndestroyedObjects(); asCScriptEngine *engine; // Callback for when circular reference are detected asCIRCULARREFFUNC_t circularRefDetectCallbackFunc; - void * circularRefDetectCallbackParam; + void *circularRefDetectCallbackParam; protected: - struct asSObjTypePair {void *obj; asCObjectType *type; asUINT seqNbr;}; - struct asSIntTypePair {int i; asCObjectType *type;}; - typedef asSMapNode asSMapNode_t; - - enum egcDestroyState + struct asSObjTypePair + { + void *obj; + asCObjectType *type; + asUINT seqNbr; + }; + struct asSIntTypePair { + int i; + asCObjectType *type; + }; + typedef asSMapNode asSMapNode_t; + + enum egcDestroyState { destroyGarbage_init = 0, destroyGarbage_loop, destroyGarbage_haveMore }; - enum egcDetectState - { + enum egcDetectState { clearCounters_init = 0, clearCounters_loop, buildMap_init, @@ -111,35 +118,35 @@ class asCGarbageCollector void MoveAllObjectsToOldList(); // Holds all the objects known by the garbage collector - asCArray gcNewObjects; - asCArray gcOldObjects; + asCArray gcNewObjects; + asCArray gcOldObjects; // This array temporarily holds references to objects known to be live objects - asCArray liveObjects; + asCArray liveObjects; - // This map holds objects currently being searched for cyclic references, it also holds a + // This map holds objects currently being searched for cyclic references, it also holds a // counter that gives the number of references to the object that the GC can't reach - asCMap gcMap; + asCMap gcMap; // State variables - egcDestroyState destroyNewState; - egcDestroyState destroyOldState; - asUINT destroyNewIdx; - asUINT destroyOldIdx; - asUINT numDestroyed; - asUINT numNewDestroyed; - egcDetectState detectState; - asUINT detectIdx; - asUINT numDetected; - asUINT numAdded; - asUINT seqAtSweepStart[3]; - asSMapNode_t *gcMapCursor; - bool isProcessing; + egcDestroyState destroyNewState; + egcDestroyState destroyOldState; + asUINT destroyNewIdx; + asUINT destroyOldIdx; + asUINT numDestroyed; + asUINT numNewDestroyed; + egcDetectState detectState; + asUINT detectIdx; + asUINT numDetected; + asUINT numAdded; + asUINT seqAtSweepStart[3]; + asSMapNode_t *gcMapCursor; + bool isProcessing; // We'll keep a pool of nodes to avoid allocating memory all the time asSMapNode_t *GetNode(void *obj, asSIntTypePair it); void ReturnNode(asSMapNode_t *node); - asCArray freeNodes; + asCArray freeNodes; // Critical section for multithreaded access DECLARECRITICALSECTION(gcCritical) // Used for adding/removing objects diff --git a/sdk/angelscript/source/as_generic.cpp b/sdk/angelscript/source/as_generic.cpp index e3bf1eb0..e063b4ed 100644 --- a/sdk/angelscript/source/as_generic.cpp +++ b/sdk/angelscript/source/as_generic.cpp @@ -43,19 +43,19 @@ BEGIN_AS_NAMESPACE -// TODO: runtime optimize: The access to the arguments should be optimized so that code +// TODO: runtime optimize: The access to the arguments should be optimized so that code // doesn't have to count the position of the argument with every call // internal asCGeneric::asCGeneric(asCScriptEngine *engine, asCScriptFunction *sysFunction, void *currentObject, asDWORD *stackPointer) { - this->engine = engine; - this->sysFunction = sysFunction; + this->engine = engine; + this->sysFunction = sysFunction; this->currentObject = currentObject; - this->stackPointer = stackPointer; - + this->stackPointer = stackPointer; + objectRegister = 0; - returnVal = 0; + returnVal = 0; } // internal @@ -72,7 +72,7 @@ void *asCGeneric::GetAuxiliary() const // interface asIScriptEngine *asCGeneric::GetEngine() const { - return (asIScriptEngine*)engine; + return (asIScriptEngine *)engine; } // interface @@ -120,7 +120,7 @@ asBYTE asCGeneric::GetArgByte(asUINT arg) offset += sysFunction->parameterTypes[n].GetSizeOnStackDWords(); // Get the value - return *(asBYTE*)&stackPointer[offset]; + return *(asBYTE *)&stackPointer[offset]; } // interface @@ -143,7 +143,7 @@ asWORD asCGeneric::GetArgWord(asUINT arg) offset += sysFunction->parameterTypes[n].GetSizeOnStackDWords(); // Get the value - return *(asWORD*)&stackPointer[offset]; + return *(asWORD *)&stackPointer[offset]; } // interface @@ -166,7 +166,7 @@ asDWORD asCGeneric::GetArgDWord(asUINT arg) offset += sysFunction->parameterTypes[n].GetSizeOnStackDWords(); // Get the value - return *(asDWORD*)&stackPointer[offset]; + return *(asDWORD *)&stackPointer[offset]; } // interface @@ -189,7 +189,7 @@ asQWORD asCGeneric::GetArgQWord(asUINT arg) offset += sysFunction->parameterTypes[n].GetSizeOnStackDWords(); // Get the value - return *(asQWORD*)(&stackPointer[offset]); + return *(asQWORD *)(&stackPointer[offset]); } // interface @@ -212,7 +212,7 @@ float asCGeneric::GetArgFloat(asUINT arg) offset += sysFunction->parameterTypes[n].GetSizeOnStackDWords(); // Get the value - return *(float*)(&stackPointer[offset]); + return *(float *)(&stackPointer[offset]); } // interface @@ -235,7 +235,7 @@ double asCGeneric::GetArgDouble(asUINT arg) offset += sysFunction->parameterTypes[n].GetSizeOnStackDWords(); // Get the value - return *(double*)(&stackPointer[offset]); + return *(double *)(&stackPointer[offset]); } // interface @@ -255,7 +255,7 @@ void *asCGeneric::GetArgAddress(asUINT arg) offset += sysFunction->parameterTypes[n].GetSizeOnStackDWords(); // Get the value - return (void*)*(asPWORD*)(&stackPointer[offset]); + return (void *)*(asPWORD *)(&stackPointer[offset]); } // interface @@ -275,7 +275,7 @@ void *asCGeneric::GetArgObject(asUINT arg) offset += sysFunction->parameterTypes[n].GetSizeOnStackDWords(); // Get the value - return *(void**)(&stackPointer[offset]); + return *(void **)(&stackPointer[offset]); } // interface @@ -290,10 +290,10 @@ void *asCGeneric::GetAddressOfArg(asUINT arg) offset += sysFunction->parameterTypes[n].GetSizeOnStackDWords(); // For object variables it's necessary to dereference the pointer to get the address of the value - if( !sysFunction->parameterTypes[arg].IsReference() && - sysFunction->parameterTypes[arg].IsObject() && - !sysFunction->parameterTypes[arg].IsObjectHandle() ) - return *(void**)&stackPointer[offset]; + if( !sysFunction->parameterTypes[arg].IsReference() && + sysFunction->parameterTypes[arg].IsObject() && + !sysFunction->parameterTypes[arg].IsObjectHandle() ) + return *(void **)&stackPointer[offset]; // Get the address of the value return &stackPointer[offset]; @@ -307,7 +307,7 @@ int asCGeneric::GetArgTypeId(asUINT arg, asDWORD *flags) const if( flags ) { - *flags = sysFunction->inOutFlags[arg]; + *flags = sysFunction->inOutFlags[arg]; *flags |= sysFunction->parameterTypes[arg].IsReadOnly() ? asTM_CONST : 0; } @@ -339,7 +339,7 @@ int asCGeneric::SetReturnByte(asBYTE val) return asINVALID_TYPE; // Store the value - *(asBYTE*)&returnVal = val; + *(asBYTE *)&returnVal = val; return 0; } @@ -355,7 +355,7 @@ int asCGeneric::SetReturnWord(asWORD val) return asINVALID_TYPE; // Store the value - *(asWORD*)&returnVal = val; + *(asWORD *)&returnVal = val; return 0; } @@ -371,7 +371,7 @@ int asCGeneric::SetReturnDWord(asDWORD val) return asINVALID_TYPE; // Store the value - *(asDWORD*)&returnVal = val; + *(asDWORD *)&returnVal = val; return 0; } @@ -403,7 +403,7 @@ int asCGeneric::SetReturnFloat(float val) return asINVALID_TYPE; // Store the value - *(float*)&returnVal = val; + *(float *)&returnVal = val; return 0; } @@ -419,7 +419,7 @@ int asCGeneric::SetReturnDouble(double val) return asINVALID_TYPE; // Store the value - *(double*)&returnVal = val; + *(double *)&returnVal = val; return 0; } @@ -431,7 +431,7 @@ int asCGeneric::SetReturnAddress(void *val) if( sysFunction->returnType.IsReference() ) { // Store the value - *(void**)&returnVal = val; + *(void **)&returnVal = val; return 0; } else if( sysFunction->returnType.IsObjectHandle() ) @@ -453,22 +453,22 @@ int asCGeneric::SetReturnObject(void *obj) if( dt->IsReference() ) { - *(void**)&returnVal = obj; + *(void **)&returnVal = obj; return 0; } if( dt->IsObjectHandle() ) { // Increase the reference counter - if (dt->IsFuncdef()) + if( dt->IsFuncdef() ) { - if (obj) - reinterpret_cast(obj)->AddRef(); + if( obj ) + reinterpret_cast(obj)->AddRef(); } else { asSTypeBehaviour *beh = &CastToObjectType(dt->GetTypeInfo())->beh; - if (obj && beh && beh->addref) + if( obj && beh && beh->addref ) engine->CallObjectMethod(obj, beh->addref); } } @@ -477,7 +477,7 @@ int asCGeneric::SetReturnObject(void *obj) // If function returns object by value the memory is already allocated. // Here we should just initialize that memory by calling the copy constructor // or the default constructor followed by the assignment operator - void *mem = (void*)*(asPWORD*)&stackPointer[-AS_PTR_SIZE]; + void *mem = (void *)*(asPWORD *)&stackPointer[-AS_PTR_SIZE]; engine->ConstructScriptObjectCopy(mem, obj, CastToObjectType(dt->GetTypeInfo())); return 0; } @@ -492,9 +492,9 @@ void *asCGeneric::GetReturnPointer() { asCDataType &dt = sysFunction->returnType; - if( (dt.IsObject() ||dt.IsFuncdef()) && !dt.IsReference() ) + if( (dt.IsObject() || dt.IsFuncdef()) && !dt.IsReference() ) { - // This function doesn't support returning on the stack but the use of + // This function doesn't support returning on the stack but the use of // the function doesn't require it so we don't need to implement it here. asASSERT( !sysFunction->DoesReturnOnStack() ); @@ -515,7 +515,7 @@ void *asCGeneric::GetAddressOfReturnLocation() { // The memory is already preallocated on the stack, // and the pointer to the location is found before the first arg - return (void*)*(asPWORD*)&stackPointer[-AS_PTR_SIZE]; + return (void *)*(asPWORD *)&stackPointer[-AS_PTR_SIZE]; } // Reference types store the handle in the objectReference @@ -532,8 +532,8 @@ int asCGeneric::GetReturnTypeId(asDWORD *flags) const return sysFunction->GetReturnTypeId(flags); } -asCGenericVariadic::asCGenericVariadic(asCScriptEngine* engine, asCScriptFunction* sysFunction, void* currentObject, asDWORD* stackPointer, asDWORD stackArgCount) - : asCGeneric(engine, sysFunction, currentObject, stackPointer), argCount(stackArgCount) +asCGenericVariadic::asCGenericVariadic(asCScriptEngine *engine, asCScriptFunction *sysFunction, void *currentObject, asDWORD *stackPointer, asDWORD stackArgCount) + : asCGeneric(engine, sysFunction, currentObject, stackPointer), argCount(stackArgCount) { } @@ -542,20 +542,20 @@ int asCGenericVariadic::GetArgCount() const return argCount; } -int asCGenericVariadic::GetArgTypeId(asUINT arg, asDWORD* flags) const +int asCGenericVariadic::GetArgTypeId(asUINT arg, asDWORD *flags) const { asUINT idx = arg; - if (idx >= sysFunction->parameterTypes.GetLength() - 1) + if( idx >= sysFunction->parameterTypes.GetLength() - 1 ) idx = sysFunction->parameterTypes.GetLength() - 1; - if (flags) + if( flags ) { - *flags = sysFunction->inOutFlags[idx]; + *flags = sysFunction->inOutFlags[idx]; *flags |= sysFunction->parameterTypes[idx].IsReadOnly() ? asTM_CONST : 0; } - asCDataType* dt = GetArgDataType(idx); - if (dt->GetTokenType() != ttQuestion) + asCDataType *dt = GetArgDataType(idx); + if( dt->GetTokenType() != ttQuestion ) return engine->GetTypeIdFromDataType(*dt); else { @@ -572,143 +572,143 @@ int asCGenericVariadic::GetArgTypeId(asUINT arg, asDWORD* flags) const asBYTE asCGenericVariadic::GetArgByte(asUINT arg) { // Verify that the type is correct - asCDataType* dt = GetArgDataType(arg); - if ((dt->IsObject() || dt->IsFuncdef()) || dt->IsReference()) + asCDataType *dt = GetArgDataType(arg); + if( (dt->IsObject() || dt->IsFuncdef()) || dt->IsReference() ) return 0; - if (dt->GetSizeInMemoryBytes() != 1) + if( dt->GetSizeInMemoryBytes() != 1 ) return 0; int offset = GetArgOffsetOnStack(arg); // Get the value - return *(asBYTE*)&stackPointer[offset]; + return *(asBYTE *)&stackPointer[offset]; } asWORD asCGenericVariadic::GetArgWord(asUINT arg) { // Verify that the type is correct - asCDataType* dt = GetArgDataType(arg); - if ((dt->IsObject() || dt->IsFuncdef()) || dt->IsReference()) + asCDataType *dt = GetArgDataType(arg); + if( (dt->IsObject() || dt->IsFuncdef()) || dt->IsReference() ) return 0; - if (dt->GetSizeInMemoryBytes() != 2) + if( dt->GetSizeInMemoryBytes() != 2 ) return 0; int offset = GetArgOffsetOnStack(arg); // Get the value - return *(asWORD*)&stackPointer[offset]; + return *(asWORD *)&stackPointer[offset]; } asDWORD asCGenericVariadic::GetArgDWord(asUINT arg) { // Verify that the type is correct - asCDataType* dt = GetArgDataType(arg); - if ((dt->IsObject() || dt->IsFuncdef()) || dt->IsReference()) + asCDataType *dt = GetArgDataType(arg); + if( (dt->IsObject() || dt->IsFuncdef()) || dt->IsReference() ) return 0; - if (dt->GetSizeInMemoryBytes() != 4) - return 0; + if( dt->GetSizeInMemoryBytes() != 4 ) + return 0; - int offset = GetArgOffsetOnStack(arg); - // Get the value - return *(asDWORD*)&stackPointer[offset]; + int offset = GetArgOffsetOnStack(arg); + // Get the value + return *(asDWORD *)&stackPointer[offset]; } asQWORD asCGenericVariadic::GetArgQWord(asUINT arg) { // Verify that the type is correct - asCDataType* dt = GetArgDataType(arg); - if ((dt->IsObject() || dt->IsFuncdef()) || dt->IsReference()) + asCDataType *dt = GetArgDataType(arg); + if( (dt->IsObject() || dt->IsFuncdef()) || dt->IsReference() ) return 0; - if (dt->GetSizeInMemoryBytes() != 8) + if( dt->GetSizeInMemoryBytes() != 8 ) return 0; int offset = GetArgOffsetOnStack(arg); // Get the value - return *(asQWORD*)&stackPointer[offset]; + return *(asQWORD *)&stackPointer[offset]; } float asCGenericVariadic::GetArgFloat(asUINT arg) { // Verify that the type is correct - asCDataType* dt = GetArgDataType(arg); - if ((dt->IsObject() || dt->IsFuncdef()) || dt->IsReference()) + asCDataType *dt = GetArgDataType(arg); + if( (dt->IsObject() || dt->IsFuncdef()) || dt->IsReference() ) return 0; - if (dt->GetSizeInMemoryBytes() != 4) + if( dt->GetSizeInMemoryBytes() != 4 ) return 0; int offset = GetArgOffsetOnStack(arg); // Get the value - return *(float*)&stackPointer[offset]; + return *(float *)&stackPointer[offset]; } double asCGenericVariadic::GetArgDouble(asUINT arg) { // Verify that the type is correct - asCDataType* dt = GetArgDataType(arg); - if ((dt->IsObject() || dt->IsFuncdef()) || dt->IsReference()) + asCDataType *dt = GetArgDataType(arg); + if( (dt->IsObject() || dt->IsFuncdef()) || dt->IsReference() ) return 0; - if (dt->GetSizeInMemoryBytes() != 8) + if( dt->GetSizeInMemoryBytes() != 8 ) return 0; int offset = GetArgOffsetOnStack(arg); // Get the value - return *(double*)&stackPointer[offset]; + return *(double *)&stackPointer[offset]; } -void* asCGenericVariadic::GetArgAddress(asUINT arg) +void *asCGenericVariadic::GetArgAddress(asUINT arg) { // Verify that the type is correct - asCDataType* dt = GetArgDataType(arg); - if (!dt->IsReference() && !dt->IsObjectHandle()) + asCDataType *dt = GetArgDataType(arg); + if( !dt->IsReference() && !dt->IsObjectHandle() ) return 0; int offset = GetArgOffsetOnStack(arg); // Get the value - return (void*)*(asPWORD*)&stackPointer[offset]; + return (void *)*(asPWORD *)&stackPointer[offset]; } -void* asCGenericVariadic::GetArgObject(asUINT arg) +void *asCGenericVariadic::GetArgObject(asUINT arg) { // Verify that the type is correct - asCDataType* dt = GetArgDataType(arg); - if (!dt->IsObject() && !dt->IsFuncdef()) + asCDataType *dt = GetArgDataType(arg); + if( !dt->IsObject() && !dt->IsFuncdef() ) return 0; int offset = GetArgOffsetOnStack(arg); // Get the value - return *(void**)(&stackPointer[offset]); + return *(void **)(&stackPointer[offset]); } -void* asCGenericVariadic::GetAddressOfArg(asUINT arg) +void *asCGenericVariadic::GetAddressOfArg(asUINT arg) { // Determine the position of the argument int offset = GetArgOffsetOnStack(arg); // For object variables it's necessary to dereference the pointer to get the address of the value - if (!sysFunction->parameterTypes[arg].IsReference() && - sysFunction->parameterTypes[arg].IsObject() && - !sysFunction->parameterTypes[arg].IsObjectHandle()) - return *(void**)&stackPointer[offset]; + if( !sysFunction->parameterTypes[arg].IsReference() && + sysFunction->parameterTypes[arg].IsObject() && + !sysFunction->parameterTypes[arg].IsObjectHandle() ) + return *(void **)&stackPointer[offset]; // Get the address of the value return &stackPointer[offset]; } -void* asCGenericVariadic::GetAddressOfReturnLocation() +void *asCGenericVariadic::GetAddressOfReturnLocation() { - asCDataType& dt = sysFunction->returnType; + asCDataType &dt = sysFunction->returnType; - if ((dt.IsObject() || dt.IsFuncdef()) && !dt.IsReference()) + if( (dt.IsObject() || dt.IsFuncdef()) && !dt.IsReference() ) { - if (sysFunction->DoesReturnOnStack()) + if( sysFunction->DoesReturnOnStack() ) { // The memory is already preallocated on the stack, // and the pointer to the location is found before the first arg - return (void*)*(asPWORD*)&stackPointer[-(AS_PTR_SIZE + 1)]; + return (void *)*(asPWORD *)&stackPointer[-(AS_PTR_SIZE + 1)]; } // Reference types store the handle in the objectReference @@ -719,30 +719,30 @@ void* asCGenericVariadic::GetAddressOfReturnLocation() return &returnVal; } -int asCGenericVariadic::SetReturnObject(void* obj) +int asCGenericVariadic::SetReturnObject(void *obj) { - asCDataType* dt = &sysFunction->returnType; - if (!dt->IsObject() && !dt->IsFuncdef()) + asCDataType *dt = &sysFunction->returnType; + if( !dt->IsObject() && !dt->IsFuncdef() ) return asINVALID_TYPE; - if (dt->IsReference()) + if( dt->IsReference() ) { - *(void**)&returnVal = obj; + *(void **)&returnVal = obj; return 0; } - if (dt->IsObjectHandle()) + if( dt->IsObjectHandle() ) { // Increase the reference counter - if (dt->IsFuncdef()) + if( dt->IsFuncdef() ) { - if (obj) - reinterpret_cast(obj)->AddRef(); + if( obj ) + reinterpret_cast(obj)->AddRef(); } else { - asSTypeBehaviour* beh = &CastToObjectType(dt->GetTypeInfo())->beh; - if (obj && beh && beh->addref) + asSTypeBehaviour *beh = &CastToObjectType(dt->GetTypeInfo())->beh; + if( obj && beh && beh->addref ) engine->CallObjectMethod(obj, beh->addref); } } @@ -751,7 +751,7 @@ int asCGenericVariadic::SetReturnObject(void* obj) // If function returns object by value the memory is already allocated. // Here we should just initialize that memory by calling the copy constructor // or the default constructor followed by the assignment operator - void* mem = (void*)*(asPWORD*)&stackPointer[-(AS_PTR_SIZE + 1)]; + void *mem = (void *)*(asPWORD *)&stackPointer[-(AS_PTR_SIZE + 1)]; engine->ConstructScriptObjectCopy(mem, obj, CastToObjectType(dt->GetTypeInfo())); return 0; } @@ -761,9 +761,9 @@ int asCGenericVariadic::SetReturnObject(void* obj) return 0; } -asCDataType* asCGenericVariadic::GetArgDataType(asUINT arg) const +asCDataType *asCGenericVariadic::GetArgDataType(asUINT arg) const { - if (arg >= sysFunction->parameterTypes.GetLength() - 1) + if( arg >= sysFunction->parameterTypes.GetLength() - 1 ) arg = sysFunction->parameterTypes.GetLength() - 1; return &sysFunction->parameterTypes[arg]; @@ -773,12 +773,12 @@ int asCGenericVariadic::GetArgOffsetOnStack(asUINT arg) const { // Determine the position of the argument int offset = 0; - for (asUINT n = 0; n < arg; n++) + for( asUINT n = 0; n < arg; n++ ) { - if (n >= sysFunction->parameterTypes.GetLength() - 1) + if( n >= sysFunction->parameterTypes.GetLength() - 1 ) { - asUINT idx = sysFunction->parameterTypes.GetLength() - 1; - offset += sysFunction->parameterTypes[idx].GetSizeOnStackDWords(); + asUINT idx = sysFunction->parameterTypes.GetLength() - 1; + offset += sysFunction->parameterTypes[idx].GetSizeOnStackDWords(); } else offset += sysFunction->parameterTypes[n].GetSizeOnStackDWords(); diff --git a/sdk/angelscript/source/as_generic.h b/sdk/angelscript/source/as_generic.h index ad88f4ba..0abc2ae4 100644 --- a/sdk/angelscript/source/as_generic.h +++ b/sdk/angelscript/source/as_generic.h @@ -49,17 +49,17 @@ class asCScriptFunction; class asCGeneric : public asIScriptGeneric { public: -//------------------------------ -// asIScriptGeneric -//------------------------------ + //------------------------------ + // asIScriptGeneric + //------------------------------ // Miscellaneous asIScriptEngine *GetEngine() const; asIScriptFunction *GetFunction() const; void *GetAuxiliary() const; // Object - void *GetObject(); - int GetObjectTypeId() const; + void *GetObject(); + int GetObjectTypeId() const; // Arguments int GetArgCount() const; @@ -75,30 +75,30 @@ class asCGeneric : public asIScriptGeneric void *GetAddressOfArg(asUINT arg); // Return value - int GetReturnTypeId(asDWORD *flags = 0) const; - int SetReturnByte(asBYTE val); - int SetReturnWord(asWORD val); - int SetReturnDWord(asDWORD val); - int SetReturnQWord(asQWORD val); - int SetReturnFloat(float val); - int SetReturnDouble(double val); - int SetReturnAddress(void *addr); - int SetReturnObject(void *obj); - void *GetAddressOfReturnLocation(); - -//------------------------ -// internal -//------------------------- + int GetReturnTypeId(asDWORD *flags = 0) const; + int SetReturnByte(asBYTE val); + int SetReturnWord(asWORD val); + int SetReturnDWord(asDWORD val); + int SetReturnQWord(asQWORD val); + int SetReturnFloat(float val); + int SetReturnDouble(double val); + int SetReturnAddress(void *addr); + int SetReturnObject(void *obj); + void *GetAddressOfReturnLocation(); + + //------------------------ + // internal + //------------------------- asCGeneric(asCScriptEngine *engine, asCScriptFunction *sysFunction, void *currentObject, asDWORD *stackPointer); virtual ~asCGeneric(); void *GetReturnPointer(); - asCScriptEngine *engine; + asCScriptEngine *engine; asCScriptFunction *sysFunction; - void *currentObject; - asDWORD *stackPointer; - void *objectRegister; + void *currentObject; + asDWORD *stackPointer; + void *objectRegister; asQWORD returnVal; }; @@ -106,30 +106,30 @@ class asCGeneric : public asIScriptGeneric class asCGenericVariadic : public asCGeneric { public: - asCGenericVariadic(asCScriptEngine* engine, asCScriptFunction* sysFunction, void* currentObject, asDWORD* stackPointer, asDWORD stackArgCount); + asCGenericVariadic(asCScriptEngine *engine, asCScriptFunction *sysFunction, void *currentObject, asDWORD *stackPointer, asDWORD stackArgCount); int GetArgCount() const; - int GetArgTypeId(asUINT arg, asDWORD* flags = 0) const; + int GetArgTypeId(asUINT arg, asDWORD *flags = 0) const; asBYTE GetArgByte(asUINT arg); asWORD GetArgWord(asUINT arg); asDWORD GetArgDWord(asUINT arg); asQWORD GetArgQWord(asUINT arg); float GetArgFloat(asUINT arg); double GetArgDouble(asUINT arg); - void* GetArgAddress(asUINT arg); - void* GetArgObject(asUINT arg); - void* GetAddressOfArg(asUINT arg); + void *GetArgAddress(asUINT arg); + void *GetArgObject(asUINT arg); + void *GetAddressOfArg(asUINT arg); - int SetReturnObject(void* obj); - void* GetAddressOfReturnLocation(); + int SetReturnObject(void *obj); + void *GetAddressOfReturnLocation(); -//------------------------ -// internal -//------------------------- + //------------------------ + // internal + //------------------------- asDWORD argCount; - asCDataType* GetArgDataType(asUINT arg) const; - int GetArgOffsetOnStack(asUINT arg) const; + asCDataType *GetArgDataType(asUINT arg) const; + int GetArgOffsetOnStack(asUINT arg) const; }; END_AS_NAMESPACE diff --git a/sdk/angelscript/source/as_globalproperty.cpp b/sdk/angelscript/source/as_globalproperty.cpp index 677a6f9a..8a118678 100644 --- a/sdk/angelscript/source/as_globalproperty.cpp +++ b/sdk/angelscript/source/as_globalproperty.cpp @@ -37,14 +37,14 @@ BEGIN_AS_NAMESPACE -asCGlobalProperty::asCGlobalProperty() -{ +asCGlobalProperty::asCGlobalProperty() +{ id = 0; nameSpace = 0; storage = 0; - memory = &storage; - memoryAllocated = false; - realAddress = 0; + memory = &storage; + memoryAllocated = false; + realAddress = 0; initFunc = 0; accessMask = 0xFFFFFFFF; @@ -52,11 +52,11 @@ asCGlobalProperty::asCGlobalProperty() } asCGlobalProperty::~asCGlobalProperty() -{ +{ #ifndef WIP_16BYTE_ALIGNED - if( memoryAllocated ) { asDELETEARRAY(memory); } + if( memoryAllocated ) { asDELETEARRAY(memory); } #else - if( memoryAllocated ) { asDELETEARRAYALIGNED(memory); } + if( memoryAllocated ) { asDELETEARRAYALIGNED(memory); } #endif if( initFunc ) @@ -84,7 +84,7 @@ void asCGlobalProperty::DestroyInternal() } void *asCGlobalProperty::GetAddressOfValue() -{ +{ return memory; } @@ -92,30 +92,30 @@ void *asCGlobalProperty::GetAddressOfValue() // method for script declared variables. Each allocation is independent of // other global properties, so that variables can be added and removed at // any time. -void asCGlobalProperty::AllocateMemory() -{ - if( type.GetSizeOnStackDWords() > 2 ) - { +void asCGlobalProperty::AllocateMemory() +{ + if( type.GetSizeOnStackDWords() > 2 ) + { #ifndef WIP_16BYTE_ALIGNED - memory = asNEWARRAY(asDWORD, type.GetSizeOnStackDWords()); + memory = asNEWARRAY(asDWORD, type.GetSizeOnStackDWords()); #else // TODO: Avoid aligned allocation if not needed to reduce the waste of memory for the alignment - memory = asNEWARRAYALIGNED(asDWORD, type.GetSizeOnStackDWords(), type.GetAlignment()); + memory = asNEWARRAYALIGNED(asDWORD, type.GetSizeOnStackDWords(), type.GetAlignment()); #endif - memoryAllocated = true; - } + memoryAllocated = true; + } } -void asCGlobalProperty::SetRegisteredAddress(void *p) -{ +void asCGlobalProperty::SetRegisteredAddress(void *p) +{ realAddress = p; if( type.IsObject() && !type.IsReference() && !type.IsObjectHandle() ) { - // The global property is a pointer to a pointer + // The global property is a pointer to a pointer memory = &realAddress; - } + } else - memory = p; + memory = p; } void *asCGlobalProperty::GetRegisteredAddress() const diff --git a/sdk/angelscript/source/as_map.h b/sdk/angelscript/source/as_map.h index 508d3d67..6a66e244 100644 --- a/sdk/angelscript/source/as_map.h +++ b/sdk/angelscript/source/as_map.h @@ -46,45 +46,45 @@ template class asCMap public: asCMap(); ~asCMap(); - asCMap(const asCMap&); - asCMap& operator=(const asCMap&); + asCMap(const asCMap &); + asCMap &operator=(const asCMap &); - int Insert(const KEY &key, const VAL &value); - int Insert(asSMapNode *node); - int GetCount() const; - - const KEY &GetKey(const asSMapNode *cursor) const; - const VAL &GetValue(const asSMapNode *cursor) const; - VAL &GetValue(asSMapNode *cursor); + int Insert(const KEY &key, const VAL &value); + int Insert(asSMapNode *node); + int GetCount() const; - void Erase(asSMapNode *cursor); - asSMapNode *Remove(asSMapNode *cursor); - void EraseAll(); + const KEY &GetKey(const asSMapNode *cursor) const; + const VAL &GetValue(const asSMapNode *cursor) const; + VAL &GetValue(asSMapNode *cursor); - void SwapWith(asCMap &other); + void Erase(asSMapNode *cursor); + asSMapNode *Remove(asSMapNode *cursor); + void EraseAll(); + + void SwapWith(asCMap &other); // Returns true as long as cursor is valid - bool MoveTo(asSMapNode **out, const KEY &key) const; - bool MoveFirst(asSMapNode **out) const; - bool MoveLast(asSMapNode **out) const; - bool MoveNext(asSMapNode **out, asSMapNode *cursor) const; - bool MovePrev(asSMapNode **out, asSMapNode *cursor) const; + bool MoveTo(asSMapNode **out, const KEY &key) const; + bool MoveFirst(asSMapNode **out) const; + bool MoveLast(asSMapNode **out) const; + bool MoveNext(asSMapNode **out, asSMapNode *cursor) const; + bool MovePrev(asSMapNode **out, asSMapNode *cursor) const; // For debugging only - int CheckIntegrity(asSMapNode *node) const; + int CheckIntegrity(asSMapNode *node) const; protected: - void BalanceInsert(asSMapNode *node); - void BalanceErase(asSMapNode *child, asSMapNode *parent); + void BalanceInsert(asSMapNode *node); + void BalanceErase(asSMapNode *child, asSMapNode *parent); - int EraseAll(asSMapNode *node); - int RotateLeft(asSMapNode *node); - int RotateRight(asSMapNode *node); + int EraseAll(asSMapNode *node); + int RotateLeft(asSMapNode *node); + int RotateRight(asSMapNode *node); - asSMapNode *root; - asSMapNode dummy; + asSMapNode *root; + asSMapNode dummy; int count; }; @@ -104,13 +104,23 @@ template class asCMap template struct asSMapNode { - asSMapNode() : parent(0), left(0), right(0), isRed(true), key(), value() {} - void Init(KEY k, VAL v) {key = k; value = v; parent = 0; left = 0; right = 0; isRed = true;} + asSMapNode() : parent(0), left(0), right(0), isRed(true), key(), value() + { + } + void Init(KEY k, VAL v) + { + key = k; + value = v; + parent = 0; + left = 0; + right = 0; + isRed = true; + } asSMapNode *parent; asSMapNode *left; asSMapNode *right; - bool isRed; + bool isRed; KEY key; VAL value; @@ -128,20 +138,20 @@ asCMap::~asCMap() } template -asCMap::asCMap(const asCMap& other) : root(0), count(0) +asCMap::asCMap(const asCMap &other) : root(0), count(0) { *this = other; } template -asCMap& asCMap::operator=(const asCMap& other) +asCMap &asCMap::operator=(const asCMap &other) { EraseAll(); - asSMapNode* node = 0; - if (other.MoveFirst(&node)) + asSMapNode *node = 0; + if( other.MoveFirst(&node) ) { Insert(node->key, node->value); - while (other.MoveNext(&node, node)) + while( other.MoveNext(&node, node) ) Insert(node->key, node->value); } @@ -149,10 +159,10 @@ asCMap& asCMap::operator=(const asCMap& other) } template -void asCMap::SwapWith(asCMap &other) +void asCMap::SwapWith(asCMap &other) { - asSMapNode *tmpRoot = root; - int tmpCount = count; + asSMapNode *tmpRoot = root; + int tmpCount = count; root = other.root; count = other.count; @@ -173,11 +183,11 @@ int asCMap::EraseAll(asSMapNode *p) { if( p == 0 ) return -1; - EraseAll( p->left ); - EraseAll( p->right ); + EraseAll(p->left); + EraseAll(p->right); - typedef asSMapNode node_t; - asDELETE(p,node_t); + typedef asSMapNode node_t; + asDELETE(p, node_t); count--; @@ -193,8 +203,8 @@ int asCMap::GetCount() const template int asCMap::Insert(const KEY &key, const VAL &value) { - typedef asSMapNode node_t; - asSMapNode *nnode = asNEW(node_t); + typedef asSMapNode node_t; + asSMapNode *nnode = asNEW(node_t); if( nnode == 0 ) { // Out of memory @@ -208,22 +218,22 @@ int asCMap::Insert(const KEY &key, const VAL &value) } template -int asCMap::Insert(asSMapNode *nnode) +int asCMap::Insert(asSMapNode *nnode) { // Insert the node if( root == 0 ) root = nnode; else { - asSMapNode *p = root; - for(;;) + asSMapNode *p = root; + for( ;; ) { if( nnode->key < p->key ) { if( p->left == 0 ) { nnode->parent = p; - p->left = nnode; + p->left = nnode; break; } else @@ -234,7 +244,7 @@ int asCMap::Insert(asSMapNode *nnode) if( p->right == 0 ) { nnode->parent = p; - p->right = nnode; + p->right = nnode; break; } else @@ -256,10 +266,10 @@ void asCMap::BalanceInsert(asSMapNode *node) // The node, that is red, can't have a red parent while( node != root && node->parent->isRed ) { - // Check color of uncle + // Check color of uncle if( node->parent == node->parent->parent->left ) { - asSMapNode *uncle = node->parent->parent->right; + asSMapNode *uncle = node->parent->parent->right; if( ISRED(uncle) ) { // B @@ -267,8 +277,8 @@ void asCMap::BalanceInsert(asSMapNode *node) // N // Change color on parent, uncle, and grand parent - node->parent->isRed = false; - uncle->isRed = false; + node->parent->isRed = false; + uncle->isRed = false; node->parent->parent->isRed = true; // Continue balancing from grand parent @@ -280,7 +290,7 @@ void asCMap::BalanceInsert(asSMapNode *node) // R B // N - if( node == node->parent->right ) + if( node == node->parent->right ) { // Make the node a left child node = node->parent; @@ -289,14 +299,14 @@ void asCMap::BalanceInsert(asSMapNode *node) // Change color on parent and grand parent // Then rotate grand parent to the right - node->parent->isRed = false; + node->parent->isRed = false; node->parent->parent->isRed = true; RotateRight(node->parent->parent); } } else { - asSMapNode *uncle = node->parent->parent->left; + asSMapNode *uncle = node->parent->parent->left; if( ISRED(uncle) ) { // B @@ -306,9 +316,9 @@ void asCMap::BalanceInsert(asSMapNode *node) // Change color on parent, uncle, and grand parent // Continue balancing from grand parent node->parent->isRed = false; - uncle->isRed = false; - node = node->parent->parent; - node->isRed = true; + uncle->isRed = false; + node = node->parent->parent; + node->isRed = true; } else { @@ -316,16 +326,16 @@ void asCMap::BalanceInsert(asSMapNode *node) // B R // N - if( node == node->parent->left ) + if( node == node->parent->left ) { // Make the node a right child node = node->parent; RotateRight(node); } - + // Change color on parent and grand parent // Then rotate grand parent to the right - node->parent->isRed = false; + node->parent->isRed = false; node->parent->parent->isRed = true; RotateLeft(node->parent->parent); } @@ -339,9 +349,9 @@ void asCMap::BalanceInsert(asSMapNode *node) template int asCMap::CheckIntegrity(asSMapNode *node) const { - if( node == 0 ) + if( node == 0 ) { - if( root == 0 ) + if( root == 0 ) return 0; else if( ISRED(root) ) return -1; @@ -355,20 +365,20 @@ int asCMap::CheckIntegrity(asSMapNode *node) const if( node->right ) right = CheckIntegrity(node->right); - if( left != right || left == -1 ) + if( left != right || left == -1 ) return -1; - + if( ISBLACK(node) ) - return left+1; + return left + 1; return left; } // Returns true if successful template -bool asCMap::MoveTo(asSMapNode **out, const KEY &key) const +bool asCMap::MoveTo(asSMapNode **out, const KEY &key) const { - asSMapNode *p = root; + asSMapNode *p = root; while( p ) { if( key < p->key ) @@ -378,7 +388,7 @@ bool asCMap::MoveTo(asSMapNode **out, const KEY &key) const if( out ) *out = p; return true; } - else + else p = p->right; } @@ -387,36 +397,37 @@ bool asCMap::MoveTo(asSMapNode **out, const KEY &key) const } template -void asCMap::Erase(asSMapNode *cursor) +void asCMap::Erase(asSMapNode *cursor) { - asSMapNode *node = Remove(cursor); + asSMapNode *node = Remove(cursor); asASSERT( node == cursor ); - typedef asSMapNode node_t; - asDELETE(node,node_t); + typedef asSMapNode node_t; + asDELETE(node, node_t); } template -asSMapNode *asCMap::Remove(asSMapNode *cursor) +asSMapNode *asCMap::Remove(asSMapNode *cursor) { if( cursor == 0 ) return 0; - asSMapNode *node = cursor; + asSMapNode *node = cursor; //--------------------------------------------------- // Choose the node that will replace the erased one - asSMapNode *remove; + asSMapNode *remove; if( node->left == 0 || node->right == 0 ) remove = node; else { remove = node->right; - while( remove->left ) remove = remove->left; + while( remove->left ) + remove = remove->left; } //-------------------------------------------------- // Remove the node - asSMapNode *child; + asSMapNode *child; if( remove->left ) child = remove->left; else @@ -457,7 +468,7 @@ asSMapNode *asCMap::Remove(asSMapNode *cursor) remove->left = node->left; if( remove->left ) remove->left->parent = remove; remove->right = node->right; - if( remove->right ) remove->right->parent = remove; + if( remove->right ) remove->right->parent = remove; } count--; @@ -471,14 +482,14 @@ template void asCMap::BalanceErase(asSMapNode *child, asSMapNode *parent) { // If child is red - // Color child black + // Color child black // Terminate // These tests assume brother is to the right. // 1. Brother is red // Color parent red and brother black - // Rotate parent left + // Rotate parent left // Transforms to 2b // 2a. Parent and brother is black, brother's children are black // Color brother red @@ -501,13 +512,13 @@ void asCMap::BalanceErase(asSMapNode *child, asSMapNodeleft ) { - asSMapNode *brother = parent->right; + asSMapNode *brother = parent->right; // Case 1 if( ISRED(brother) ) { brother->isRed = false; - parent->isRed = true; + parent->isRed = true; RotateLeft(parent); brother = parent->right; } @@ -519,14 +530,14 @@ void asCMap::BalanceErase(asSMapNode *child, asSMapNodeisRed = false; + parent->isRed = false; brother->isRed = true; break; } brother->isRed = true; - child = parent; - parent = child->parent; + child = parent; + parent = child->parent; } else { @@ -534,14 +545,14 @@ void asCMap::BalanceErase(asSMapNode *child, asSMapNoderight) ) { brother->left->isRed = false; - brother->isRed = true; + brother->isRed = true; RotateRight(brother); brother = parent->right; } // Case 4 - brother->isRed = parent->isRed; - parent->isRed = false; + brother->isRed = parent->isRed; + parent->isRed = false; brother->right->isRed = false; RotateLeft(parent); break; @@ -549,13 +560,13 @@ void asCMap::BalanceErase(asSMapNode *child, asSMapNode *brother = parent->left; - + asSMapNode *brother = parent->left; + // Case 1 if( ISRED(brother) ) { brother->isRed = false; - parent->isRed = true; + parent->isRed = true; RotateRight(parent); brother = parent->left; } @@ -567,14 +578,14 @@ void asCMap::BalanceErase(asSMapNode *child, asSMapNodeisRed = false; + parent->isRed = false; brother->isRed = true; break; } brother->isRed = true; - child = parent; - parent = child->parent; + child = parent; + parent = child->parent; } else { @@ -582,14 +593,14 @@ void asCMap::BalanceErase(asSMapNode *child, asSMapNodeleft) ) { brother->right->isRed = false; - brother->isRed = true; + brother->isRed = true; RotateLeft(brother); brother = parent->left; } // Case 4 - brother->isRed = parent->isRed; - parent->isRed = false; + brother->isRed = parent->isRed; + parent->isRed = false; brother->left->isRed = false; RotateRight(parent); break; @@ -612,12 +623,12 @@ int asCMap::RotateRight(asSMapNode *node) if( node->left == 0 ) return -1; - asSMapNode *left = node->left; + asSMapNode *left = node->left; // Update parent if( node->parent ) { - asSMapNode *parent = node->parent; + asSMapNode *parent = node->parent; if( parent->left == node ) parent->left = left; else @@ -627,7 +638,7 @@ int asCMap::RotateRight(asSMapNode *node) } else { - root = left; + root = left; left->parent = 0; } @@ -636,7 +647,7 @@ int asCMap::RotateRight(asSMapNode *node) if( node->left ) node->left->parent = node; // Put node as left's right child - left->right = node; + left->right = node; node->parent = left; return 0; @@ -653,12 +664,12 @@ int asCMap::RotateLeft(asSMapNode *node) if( node->right == 0 ) return -1; - asSMapNode *right = node->right; + asSMapNode *right = node->right; // Update parent if( node->parent ) { - asSMapNode *parent = node->parent; + asSMapNode *parent = node->parent; if( parent->right == node ) parent->right = right; else @@ -668,7 +679,7 @@ int asCMap::RotateLeft(asSMapNode *node) } else { - root = right; + root = right; right->parent = 0; } @@ -677,32 +688,32 @@ int asCMap::RotateLeft(asSMapNode *node) if( node->right ) node->right->parent = node; // Put node as right's left child - right->left = node; + right->left = node; node->parent = right; return 0; } template -const VAL &asCMap::GetValue(const asSMapNode *cursor) const +const VAL &asCMap::GetValue(const asSMapNode *cursor) const { - if( cursor == 0 ) + if( cursor == 0 ) return dummy.value; return cursor->value; } template -VAL &asCMap::GetValue(asSMapNode *cursor) +VAL &asCMap::GetValue(asSMapNode *cursor) { - if( cursor == 0 ) + if( cursor == 0 ) return dummy.value; return cursor->value; } template -const KEY &asCMap::GetKey(const asSMapNode *cursor) const +const KEY &asCMap::GetKey(const asSMapNode *cursor) const { if( cursor == 0 ) return dummy.key; @@ -711,31 +722,31 @@ const KEY &asCMap::GetKey(const asSMapNode *cursor) const } template -bool asCMap::MoveFirst(asSMapNode **out) const +bool asCMap::MoveFirst(asSMapNode **out) const { *out = root; if( root == 0 ) return false; - while( (*out)->left ) + while( (*out)->left ) *out = (*out)->left; return true; } template -bool asCMap::MoveLast(asSMapNode **out) const +bool asCMap::MoveLast(asSMapNode **out) const { *out = root; if( root == 0 ) return false; - while( (*out)->right ) + while( (*out)->right ) *out = (*out)->right; return true; } template -bool asCMap::MoveNext(asSMapNode **out, asSMapNode *cursor) const +bool asCMap::MoveNext(asSMapNode **out, asSMapNode *cursor) const { if( cursor == 0 ) { @@ -743,22 +754,22 @@ bool asCMap::MoveNext(asSMapNode **out, asSMapNode * return false; } - if( cursor->right == 0 ) + if( cursor->right == 0 ) { // Move upwards until we find a parent node to the right while( cursor->parent && cursor->parent->right == cursor ) cursor = cursor->parent; cursor = cursor->parent; - *out = cursor; - if( cursor == 0 ) + *out = cursor; + if( cursor == 0 ) return false; return true; } cursor = cursor->right; - while( cursor->left ) + while( cursor->left ) cursor = cursor->left; *out = cursor; @@ -766,9 +777,9 @@ bool asCMap::MoveNext(asSMapNode **out, asSMapNode * } template -bool asCMap::MovePrev(asSMapNode **out, asSMapNode *cursor) const +bool asCMap::MovePrev(asSMapNode **out, asSMapNode *cursor) const { - if( cursor == 0 ) + if( cursor == 0 ) { *out = 0; return false; @@ -801,4 +812,3 @@ bool asCMap::MovePrev(asSMapNode **out, asSMapNode * #endif - diff --git a/sdk/angelscript/source/as_memory.cpp b/sdk/angelscript/source/as_memory.cpp index 5914658b..c4ae8056 100644 --- a/sdk/angelscript/source/as_memory.cpp +++ b/sdk/angelscript/source/as_memory.cpp @@ -60,7 +60,7 @@ BEGIN_AS_NAMESPACE // ok - Script global properties must allocate memory on 16byte boundaries if holding these types (asCGlobalProperty::AllocateMemory) // TODO - The script compiler must make sure to allocate the local variables on 16byte boundaries (asCCompiler::AllocateVariable) // TODO - The script compiler must add pad bytes on the stack for all function calls to guarantee that the stack position is 16byte aligned on entry in the called function (asCCompiler) -// TODO - The bytecode serializer must be capable of adjusting these pad bytes to guarantee platform independent saved bytecode. Remember that the registered type may not be 16byte aligned on all platforms (asCWriter & asCReader) +// TODO - The bytecode serializer must be capable of adjusting these pad bytes to guarantee platform independent saved bytecode. Remember that the registered type may not be 16byte aligned on all platforms (asCWriter & asCReader) // TODO - The bytecode serializer must also be prepared to adjust the position of the local variables according to the need fro 16byte alignment (asCWriter & asCReader) // TODO - The code for the native calling conventions must be adjusted for all platforms that should support 16byte aligned types (as_callfunc...) // ok - When the context needs to grow the local stack memory it must copy the function arguments so that the stack entry position is 16byte aligned (asCContext::CallScriptFunction) @@ -73,34 +73,34 @@ BEGIN_AS_NAMESPACE // Wrappers for aligned allocations void *debugAlignedMalloc(size_t size, size_t align, const char *file, int line) { - void *mem = ((asALLOCFUNCDEBUG_t)userAlloc)(size + (align-1) + sizeof(void*), file, line); + void *mem = ((asALLOCFUNCDEBUG_t)userAlloc)(size + (align - 1) + sizeof(void *), file, line); - char *amem = ((char*)mem) + sizeof(void*); + char *amem = ((char *)mem) + sizeof(void *); if( (uintptr_t)amem & (align - 1) ) amem += align - ((uintptr_t)amem & (align - 1)); - ((void**)amem)[-1] = mem; + ((void **)amem)[-1] = mem; return amem; } void *alignedMalloc(size_t size, size_t align) { - void *mem = userAlloc(size + (align-1) + sizeof(void*)); + void *mem = userAlloc(size + (align - 1) + sizeof(void *)); - char *amem = ((char*)mem) + sizeof(void*); + char *amem = ((char *)mem) + sizeof(void *); if( (uintptr_t)amem & (align - 1) ) amem += align - ((uintptr_t)amem & (align - 1)); - ((void**)amem)[-1] = mem; + ((void **)amem)[-1] = mem; return amem; } void alignedFree(void *mem) { - userFree( ((void**)mem)[-1] ); + userFree(((void **)mem)[-1]); } -bool isAligned(const void* const pointer, asUINT alignment) +bool isAligned(const void * const pointer, asUINT alignment) { return (uintptr_t(pointer) % alignment) == 0; } @@ -114,7 +114,7 @@ bool isAligned(const void* const pointer, asUINT alignment) #ifdef _MSC_VER // MSVC let's us choose between a couple of different initialization orders. -#pragma warning(disable: 4073) +#pragma warning(disable : 4073) #pragma init_seg(lib) asALLOCFUNC_t userAlloc = malloc; asFREEFUNC_t userFree = free; @@ -124,7 +124,7 @@ asALLOCALIGNEDFUNC_t userAllocAligned = (asALLOCALIGNEDFUNC_t)debugAlignedMalloc #else asALLOCALIGNEDFUNC_t userAllocAligned = alignedMalloc; #endif -asFREEALIGNEDFUNC_t userFreeAligned = alignedFree; +asFREEALIGNEDFUNC_t userFreeAligned = alignedFree; #endif #else // Other compilers will just have to rely on luck. @@ -136,13 +136,12 @@ asFREEALIGNEDFUNC_t userFreeAligned = alignedFree; #endif #endif -extern "C" -{ +extern "C" { // interface int asSetGlobalMemoryFunctions(asALLOCFUNC_t allocFunc, asFREEFUNC_t freeFunc) { - // Clean-up thread local memory before changing the allocation routines to avoid + // Clean-up thread local memory before changing the allocation routines to avoid // potential problem with trying to free memory using a different allocation // routine than used when allocating it. asThreadCleanup(); @@ -156,7 +155,7 @@ int asSetGlobalMemoryFunctions(asALLOCFUNC_t allocFunc, asFREEFUNC_t freeFunc) // interface int asResetGlobalMemoryFunctions() { - // Clean-up thread local memory before changing the allocation routines to avoid + // Clean-up thread local memory before changing the allocation routines to avoid // potential problem with trying to free memory using a different allocation // routine than used when allocating it. asThreadCleanup(); @@ -192,7 +191,7 @@ asCMemoryMgr::~asCMemoryMgr() void asCMemoryMgr::FreeUnusedMemory() { - // It's necessary to protect the scriptNodePool from multiple + // It's necessary to protect the scriptNodePool from multiple // simultaneous accesses, as the parser is used by several methods // that can be executed simultaneously. ENTERCRITICALSECTION(cs); @@ -204,8 +203,8 @@ void asCMemoryMgr::FreeUnusedMemory() LEAVECRITICALSECTION(cs); - // The engine already protects against multiple threads - // compiling scripts simultaneously so this pool doesn't have + // The engine already protects against multiple threads + // compiling scripts simultaneously so this pool doesn't have // to be protected again. for( n = 0; n < (signed)byteInstructionPool.GetLength(); n++ ) userFree(byteInstructionPool[n]); @@ -225,7 +224,7 @@ void *asCMemoryMgr::AllocScriptNode() LEAVECRITICALSECTION(cs); -#if defined(AS_DEBUG) +#if defined(AS_DEBUG) return ((asALLOCFUNCDEBUG_t)(userAlloc))(sizeof(asCScriptNode), __FILE__, __LINE__); #else return userAlloc(sizeof(asCScriptNode)); @@ -241,7 +240,7 @@ void asCMemoryMgr::FreeScriptNode(void *ptr) scriptNodePool.Allocate(100, 0); scriptNodePool.PushLast(ptr); - + #ifdef AS_DEBUG // clear the memory to facilitate identification of use after free memset(ptr, 0xCDCDCDCD, sizeof(asCScriptNode)); @@ -255,11 +254,11 @@ void asCMemoryMgr::FreeScriptNode(void *ptr) void *asCMemoryMgr::AllocByteInstruction() { // This doesn't need a critical section because, only one compilation is allowed at a time - + if( byteInstructionPool.GetLength() ) return byteInstructionPool.PopLast(); -#if defined(AS_DEBUG) +#if defined(AS_DEBUG) return ((asALLOCFUNCDEBUG_t)(userAlloc))(sizeof(asCByteInstruction), __FILE__, __LINE__); #else return userAlloc(sizeof(asCByteInstruction)); @@ -273,7 +272,7 @@ void asCMemoryMgr::FreeByteInstruction(void *ptr) byteInstructionPool.Allocate(100, 0); byteInstructionPool.PushLast(ptr); - + #ifdef AS_DEBUG // clear the memory to facilitate identification of use after free memset(ptr, 0xCDCDCDCD, sizeof(asCByteInstruction)); @@ -283,6 +282,3 @@ void asCMemoryMgr::FreeByteInstruction(void *ptr) #endif // AS_NO_COMPILER END_AS_NAMESPACE - - - diff --git a/sdk/angelscript/source/as_memory.h b/sdk/angelscript/source/as_memory.h index ac884f71..329133f3 100644 --- a/sdk/angelscript/source/as_memory.h +++ b/sdk/angelscript/source/as_memory.h @@ -63,7 +63,7 @@ typedef void *(*asALLOCALIGNEDFUNCDEBUG_t)(size_t, size_t, const char *, unsigne const int MAX_TYPE_ALIGNMENT = 16; // Utility function used for assertions. -bool isAligned(const void* const pointer, asUINT alignment); +bool isAligned(const void * const pointer, asUINT alignment); #endif // WIP_16BYTE_ALIGN @@ -71,39 +71,49 @@ bool isAligned(const void* const pointer, asUINT alignment); #ifndef AS_DEBUG - #define asNEW(x) new(userAlloc(sizeof(x))) x - #define asDELETE(ptr,x) {void *tmp = ptr; (ptr)->~x(); userFree(tmp);} + #define asNEW(x) new (userAlloc(sizeof(x))) x + #define asDELETE(ptr, x) \ + { \ + void *tmp = ptr; \ + (ptr)->~x(); \ + userFree(tmp); \ + } - #define asNEWARRAY(x,cnt) (x*)userAlloc(sizeof(x)*cnt) + #define asNEWARRAY(x, cnt) (x *)userAlloc(sizeof(x) * cnt) #define asDELETEARRAY(ptr) userFree(ptr) -#ifdef WIP_16BYTE_ALIGN - #define asNEWARRAYALIGNED(x,cnt, alignment) (x*)userAllocAligned(sizeof(x)*cnt, alignment) - #define asDELETEARRAYALIGNED(ptr) userFreeAligned(ptr) -#endif + #ifdef WIP_16BYTE_ALIGN + #define asNEWARRAYALIGNED(x, cnt, alignment) (x *)userAllocAligned(sizeof(x) * cnt, alignment) + #define asDELETEARRAYALIGNED(ptr) userFreeAligned(ptr) + #endif #else #ifdef __GNUC__ - // Disable the warning about casting to incompatible function type - // This is a bit of a hack, but it works perfectly because we're just passing - // a couple of primitives extra, and the called function can safely ignore them if not needed - #pragma GCC diagnostic ignored "-Wcast-function-type" + // Disable the warning about casting to incompatible function type + // This is a bit of a hack, but it works perfectly because we're just passing + // a couple of primitives extra, and the called function can safely ignore them if not needed + #pragma GCC diagnostic ignored "-Wcast-function-type" #endif - typedef void *(*asALLOCFUNCDEBUG_t)(size_t, const char *, unsigned int); +typedef void *(*asALLOCFUNCDEBUG_t)(size_t, const char *, unsigned int); - #define asNEW(x) new((reinterpret_cast(userAlloc))(sizeof(x), __FILE__, __LINE__)) x - #define asDELETE(ptr,x) {void *tmp = ptr; (ptr)->~x(); userFree(tmp);} + #define asNEW(x) new ((reinterpret_cast(userAlloc))(sizeof(x), __FILE__, __LINE__)) x + #define asDELETE(ptr, x) \ + { \ + void *tmp = ptr; \ + (ptr)->~x(); \ + userFree(tmp); \ + } - #define asNEWARRAY(x,cnt) (x*)(reinterpret_cast(userAlloc))(sizeof(x)*cnt, __FILE__, __LINE__) + #define asNEWARRAY(x, cnt) (x *)(reinterpret_cast(userAlloc))(sizeof(x) * cnt, __FILE__, __LINE__) #define asDELETEARRAY(ptr) userFree(ptr) -#ifdef WIP_16BYTE_ALIGN - //TODO: Equivalent of debug allocation function with alignment? - #define asNEWARRAYALIGNED(x,cnt, alignment) (x*)userAllocAligned(sizeof(x)*cnt, alignment) - #define asDELETEARRAYALIGNED(ptr) userFreeAligned(ptr) -#endif + #ifdef WIP_16BYTE_ALIGN + //TODO: Equivalent of debug allocation function with alignment? + #define asNEWARRAYALIGNED(x, cnt, alignment) (x *)userAllocAligned(sizeof(x) * cnt, alignment) + #define asDELETEARRAYALIGNED(ptr) userFreeAligned(ptr) + #endif #endif @@ -124,11 +134,11 @@ class asCMemoryMgr void FreeUnusedMemory(); void *AllocScriptNode(); - void FreeScriptNode(void *ptr); + void FreeScriptNode(void *ptr); #ifndef AS_NO_COMPILER void *AllocByteInstruction(); - void FreeByteInstruction(void *ptr); + void FreeByteInstruction(void *ptr); #endif protected: diff --git a/sdk/angelscript/source/as_module.cpp b/sdk/angelscript/source/as_module.cpp index 3fd900ff..b98c4ae1 100644 --- a/sdk/angelscript/source/as_module.cpp +++ b/sdk/angelscript/source/as_module.cpp @@ -50,10 +50,10 @@ BEGIN_AS_NAMESPACE // internal asCModule::asCModule(const char *name, asCScriptEngine *engine) { - m_name = name; - m_engine = engine; + m_name = name; + m_engine = engine; - m_builder = 0; + m_builder = 0; m_isGlobalVarInitialized = false; m_accessMask = 1; @@ -70,7 +70,7 @@ asCModule::~asCModule() // sections that will be built, so we need to explictly remove it now if it exists if( m_builder ) { - asDELETE(m_builder,asCBuilder); + asDELETE(m_builder, asCBuilder); m_builder = 0; } @@ -79,7 +79,7 @@ asCModule::~asCModule() // Clean the user data for( asUINT n = 0; n < m_userData.GetLength(); n += 2 ) { - if( m_userData[n+1] ) + if( m_userData[n + 1] ) { for( asUINT c = 0; c < m_engine->cleanModuleFuncs.GetLength(); c++ ) if( m_engine->cleanModuleFuncs[c].type == m_userData[n] ) @@ -148,8 +148,8 @@ void *asCModule::SetUserData(void *data, asPWORD type) { if( m_userData[n] == type ) { - void *oldData = reinterpret_cast(m_userData[n+1]); - m_userData[n+1] = reinterpret_cast(data); + void *oldData = reinterpret_cast(m_userData[n + 1]); + m_userData[n + 1] = reinterpret_cast(data); RELEASEEXCLUSIVE(m_engine->engineRWLock); @@ -176,7 +176,7 @@ void *asCModule::GetUserData(asPWORD type) const { if( m_userData[n] == type ) { - void *ud = reinterpret_cast(m_userData[n+1]); + void *ud = reinterpret_cast(m_userData[n + 1]); RELEASESHARED(m_engine->engineRWLock); return ud; } @@ -215,11 +215,11 @@ const char *asCModule::GetDefaultNamespace() const int asCModule::SetDefaultNamespace(const char *nameSpace) { asCArray nsStrings; - int r = m_engine->ParseNamespace(nameSpace, nsStrings); - if (r < 0) + int r = m_engine->ParseNamespace(nameSpace, nsStrings); + if( r < 0 ) return r; - for (asUINT n = 0; n < nsStrings.GetLength(); n++) + for( asUINT n = 0; n < nsStrings.GetLength(); n++ ) m_defaultNamespace = m_engine->AddNameSpace(nsStrings[n].AddressOf()); return 0; @@ -252,7 +252,7 @@ void asCModule::JITCompile() if( !m_engine->jitCompiler ) return; - for (unsigned int i = 0; i < m_scriptFunctions.GetLength(); i++) + for( unsigned int i = 0; i < m_scriptFunctions.GetLength(); i++ ) m_scriptFunctions[i]->JITCompile(); } @@ -297,7 +297,7 @@ int asCModule::Build() // Compile the script r = m_builder->Build(); - asDELETE(m_builder,asCBuilder); + asDELETE(m_builder, asCBuilder); m_builder = 0; if( r < 0 ) @@ -313,7 +313,7 @@ int asCModule::Build() m_engine->PrepareEngine(); -#ifdef AS_DEBUG + #ifdef AS_DEBUG // Verify that there are no unwanted gaps in the scriptFunctions array. for( asUINT n = 1; n < m_engine->scriptFunctions.GetLength(); n++ ) { @@ -321,7 +321,7 @@ int asCModule::Build() if( m_engine->scriptFunctions[n] == 0 && !m_engine->freeScriptFunctionIds.Exists(id) ) asASSERT( false ); } -#endif + #endif m_engine->BuildCompleted(); @@ -345,7 +345,7 @@ int asCModule::ResetGlobalVars(asIScriptContext *ctx) // interface asIScriptFunction *asCModule::GetFunctionByIndex(asUINT index) const { - return const_cast(m_globalFunctions.Get(index)); + return const_cast(m_globalFunctions.Get(index)); } // internal @@ -359,14 +359,14 @@ int asCModule::CallInit(asIScriptContext *myCtx) while( it ) { asCGlobalProperty *desc = *it; - memset(desc->GetAddressOfValue(), 0, sizeof(asDWORD)*desc->type.GetSizeOnStackDWords()); + memset(desc->GetAddressOfValue(), 0, sizeof(asDWORD) * desc->type.GetSizeOnStackDWords()); it++; } // Call the init function for each of the global variables asIScriptContext *ctx = myCtx; - int r = asEXECUTION_FINISHED; - it = m_scriptGlobals.List(); + int r = asEXECUTION_FINISHED; + it = m_scriptGlobals.List(); while( it && r == asEXECUTION_FINISHED ) { asCGlobalProperty *desc = *it; @@ -408,7 +408,7 @@ int asCModule::InitGlobalProp(asCGlobalProperty *prop, asIScriptContext *myCtx) { // Call the init function for each of the global variables asIScriptContext *ctx = myCtx; - int r = asEXECUTION_FINISHED; + int r = asEXECUTION_FINISHED; if( prop->GetInitFunc() ) { if( ctx == 0 ) @@ -428,14 +428,14 @@ int asCModule::InitGlobalProp(asCGlobalProperty *prop, asIScriptContext *myCtx) msg.Format(TXT_FAILED_TO_INITIALIZE_s, prop->name.AddressOf()); asCScriptFunction *func = prop->GetInitFunc(); - const char* scriptSection = 0; - int row, col; + const char *scriptSection = 0; + int row, col; func->GetDeclaredAt(&scriptSection, &row, &col); m_engine->WriteMessage(scriptSection ? scriptSection : "", - row, - col, - asMSGTYPE_ERROR, - msg.AddressOf()); + row, + col, + asMSGTYPE_ERROR, + msg.AddressOf()); if( r == asEXECUTION_EXCEPTION ) { @@ -445,10 +445,10 @@ int asCModule::InitGlobalProp(asCGlobalProperty *prop, asIScriptContext *myCtx) function->GetDeclaredAt(&scriptSection, 0, 0); m_engine->WriteMessage(scriptSection ? scriptSection : "", - ctx->GetExceptionLineNumber(), - 0, - asMSGTYPE_INFORMATION, - msg.AddressOf()); + ctx->GetExceptionLineNumber(), + 0, + asMSGTYPE_INFORMATION, + msg.AddressOf()); } } } @@ -475,25 +475,25 @@ int asCModule::InitGlobalProp(asCGlobalProperty *prop, asIScriptContext *myCtx) // internal void asCModule::UninitializeGlobalProp(asCGlobalProperty *prop) { - if (prop == 0) + if( prop == 0 ) return; - if (prop->type.IsObject()) + if( prop->type.IsObject() ) { - void **obj = (void**)prop->GetAddressOfValue(); - if (*obj) + void **obj = (void **)prop->GetAddressOfValue(); + if( *obj ) { asCObjectType *ot = CastToObjectType(prop->type.GetTypeInfo()); - if (ot->flags & asOBJ_REF) + if( ot->flags & asOBJ_REF ) { asASSERT((ot->flags & asOBJ_NOCOUNT) || ot->beh.release); - if (ot->beh.release) + if( ot->beh.release ) m_engine->CallObjectMethod(*obj, ot->beh.release); } else { - if (ot->beh.destruct) + if( ot->beh.destruct ) m_engine->CallObjectMethod(*obj, ot->beh.destruct); m_engine->CallFree(*obj); @@ -503,10 +503,10 @@ void asCModule::UninitializeGlobalProp(asCGlobalProperty *prop) *obj = 0; } } - else if (prop->type.IsFuncdef()) + else if( prop->type.IsFuncdef() ) { - asCScriptFunction **func = (asCScriptFunction**)prop->GetAddressOfValue(); - if (*func) + asCScriptFunction **func = (asCScriptFunction **)prop->GetAddressOfValue(); + if( *func ) { (*func)->Release(); *func = 0; @@ -536,10 +536,10 @@ bool asCModule::HasExternalReferences(bool shuttingDown) // If there are any external references the module cannot be deleted yet. asCSymbolTableIterator it = m_scriptGlobals.List(); - while (it) + while( it ) { asCGlobalProperty *desc = *it; - if (desc->GetInitFunc() && desc->GetInitFunc()->externalRefCount.get()) + if( desc->GetInitFunc() && desc->GetInitFunc()->externalRefCount.get() ) { if( !shuttingDown ) return true; @@ -558,16 +558,16 @@ bool asCModule::HasExternalReferences(bool shuttingDown) it++; } - for (asUINT n = 0; n < m_scriptFunctions.GetLength(); n++) + for( asUINT n = 0; n < m_scriptFunctions.GetLength(); n++ ) { asCScriptFunction *func = m_scriptFunctions[n]; - if (func && func->externalRefCount.get()) + if( func && func->externalRefCount.get() ) { // If the func is shared and can be moved to another module then this is not a reason to keep the module alive - if (func->IsShared() && m_engine->FindNewOwnerForSharedFunc(func, this) != this) + if( func->IsShared() && m_engine->FindNewOwnerForSharedFunc(func, this) != this ) continue; - if (!shuttingDown) + if( !shuttingDown ) return true; else { @@ -581,16 +581,16 @@ bool asCModule::HasExternalReferences(bool shuttingDown) } } - for (asUINT n = 0; n < m_classTypes.GetLength(); n++) + for( asUINT n = 0; n < m_classTypes.GetLength(); n++ ) { asCObjectType *obj = m_classTypes[n]; - if (obj && obj->externalRefCount.get()) + if( obj && obj->externalRefCount.get() ) { // If the obj is shared and can be moved to another module then this is not a reason to keep the module alive - if (obj->IsShared() && m_engine->FindNewOwnerForSharedType(obj, this) != this) + if( obj->IsShared() && m_engine->FindNewOwnerForSharedType(obj, this) != this ) continue; - if (!shuttingDown) + if( !shuttingDown ) return true; else { @@ -604,16 +604,16 @@ bool asCModule::HasExternalReferences(bool shuttingDown) } } - for (asUINT n = 0; n < m_funcDefs.GetLength(); n++) + for( asUINT n = 0; n < m_funcDefs.GetLength(); n++ ) { asCFuncdefType *func = m_funcDefs[n]; - if (func && func->externalRefCount.get()) + if( func && func->externalRefCount.get() ) { // If the funcdef is shared and can be moved to another module then this is not a reason to keep the module alive - if (func->IsShared() && m_engine->FindNewOwnerForSharedType(func, this) != this) + if( func->IsShared() && m_engine->FindNewOwnerForSharedType(func, this) != this ) continue; - if (!shuttingDown) + if( !shuttingDown ) return true; else { @@ -627,16 +627,16 @@ bool asCModule::HasExternalReferences(bool shuttingDown) } } - for (asUINT n = 0; n < m_templateInstances.GetLength(); n++) + for( asUINT n = 0; n < m_templateInstances.GetLength(); n++ ) { asCObjectType *obj = m_templateInstances[n]; - if (obj && obj->externalRefCount.get()) + if( obj && obj->externalRefCount.get() ) { // If the template can be moved to another module then this is not a reason to keep the module alive - if (obj->IsShared() && m_engine->FindNewOwnerForSharedType(obj, this) != this) + if( obj->IsShared() && m_engine->FindNewOwnerForSharedType(obj, this) != this ) continue; - if (!shuttingDown) + if( !shuttingDown ) return true; else { @@ -839,11 +839,11 @@ void asCModule::InternalReset() // interface asIScriptFunction *asCModule::GetFunctionByName(const char *in_name) const { - asCString name; + asCString name; asSNameSpace *ns = 0; if( m_engine->DetermineNameAndNamespace(in_name, m_defaultNamespace, name, ns) < 0 ) return 0; - + // Search recursively in the given namespace, moving up to parent namespace until the function is found while( ns ) { @@ -853,7 +853,7 @@ asIScriptFunction *asCModule::GetFunctionByName(const char *in_name) const const asIScriptFunction *func = m_globalFunctions.Get(idxs[0]); if( func ) - return const_cast(func); + return const_cast(func); // Recursively search parent namespaces ns = m_engine->GetParentNameSpace(ns); @@ -871,12 +871,12 @@ asUINT asCModule::GetImportedFunctionCount() const // interface int asCModule::GetImportedFunctionIndexByDecl(const char *decl) const { - asCBuilder bld(m_engine, const_cast(this)); + asCBuilder bld(m_engine, const_cast(this)); // Don't write parser errors to the message callback bld.silent = true; - asCScriptFunction func(m_engine, const_cast(this), asFUNC_DUMMY); + asCScriptFunction func(m_engine, const_cast(this), asFUNC_DUMMY); bld.ParseFunctionDeclaration(0, decl, &func, false, 0, 0, m_defaultNamespace); // TODO: optimize: Improve linear search @@ -885,8 +885,8 @@ int asCModule::GetImportedFunctionIndexByDecl(const char *decl) const for( asUINT n = 0; n < m_bindInformations.GetLength(); ++n ) { if( func.name == m_bindInformations[n]->importedFunctionSignature->name && - func.returnType == m_bindInformations[n]->importedFunctionSignature->returnType && - func.parameterTypes.GetLength() == m_bindInformations[n]->importedFunctionSignature->parameterTypes.GetLength() ) + func.returnType == m_bindInformations[n]->importedFunctionSignature->returnType && + func.parameterTypes.GetLength() == m_bindInformations[n]->importedFunctionSignature->parameterTypes.GetLength() ) { bool match = true; for( asUINT p = 0; p < func.parameterTypes.GetLength(); ++p ) @@ -922,13 +922,13 @@ asUINT asCModule::GetFunctionCount() const // interface asIScriptFunction *asCModule::GetFunctionByDecl(const char *decl) const { - asCBuilder bld(m_engine, const_cast(this)); + asCBuilder bld(m_engine, const_cast(this)); // Don't write parser errors to the message callback bld.silent = true; - asCScriptFunction func(m_engine, const_cast(this), asFUNC_DUMMY); - int r = bld.ParseFunctionDeclaration(0, decl, &func, false, 0, 0, m_defaultNamespace); + asCScriptFunction func(m_engine, const_cast(this), asFUNC_DUMMY); + int r = bld.ParseFunctionDeclaration(0, decl, &func, false, 0, 0, m_defaultNamespace); if( r < 0 ) { // Invalid declaration @@ -942,15 +942,14 @@ asIScriptFunction *asCModule::GetFunctionByDecl(const char *decl) const // Search script functions for matching interface while( ns ) { - asIScriptFunction *f = 0; + asIScriptFunction *f = 0; const asCArray &idxs = m_globalFunctions.GetIndexes(ns, func.name); for( unsigned int n = 0; n < idxs.GetLength(); n++ ) { const asCScriptFunction *funcPtr = m_globalFunctions.Get(idxs[n]); if( funcPtr->objectType == 0 && - func.returnType == funcPtr->returnType && - func.parameterTypes.GetLength() == funcPtr->parameterTypes.GetLength() - ) + func.returnType == funcPtr->returnType && + func.parameterTypes.GetLength() == funcPtr->parameterTypes.GetLength() ) { bool match = true; for( asUINT p = 0; p < func.parameterTypes.GetLength(); ++p ) @@ -965,7 +964,7 @@ asIScriptFunction *asCModule::GetFunctionByDecl(const char *decl) const if( match ) { if( f == 0 ) - f = const_cast(funcPtr); + f = const_cast(funcPtr); else // Multiple functions return 0; @@ -994,11 +993,11 @@ asUINT asCModule::GetGlobalVarCount() const // interface int asCModule::GetGlobalVarIndexByName(const char *in_name) const { - asCString name; + asCString name; asSNameSpace *ns = 0; if( m_engine->DetermineNameAndNamespace(in_name, m_defaultNamespace, name, ns) < 0 ) return asINVALID_ARG; - + // Find the global var id while( ns ) { @@ -1019,9 +1018,9 @@ int asCModule::RemoveGlobalVar(asUINT index) if( !prop ) return asINVALID_ARG; - // If the global variables have already been initialized + // If the global variables have already been initialized // then uninitialize the variable before it is removed - if (m_isGlobalVarInitialized) + if( m_isGlobalVarInitialized ) UninitializeGlobalProp(prop); // Destroy the internal of the global variable (removes the initialization function) @@ -1042,15 +1041,15 @@ int asCModule::RemoveGlobalVar(asUINT index) // interface int asCModule::GetGlobalVarIndexByDecl(const char *decl) const { - asCBuilder bld(m_engine, const_cast(this)); + asCBuilder bld(m_engine, const_cast(this)); // Don't write parser errors to the message callback bld.silent = true; - asCString declName; + asCString declName; asSNameSpace *nameSpace; - asCDataType dt; - int r = bld.ParseVariableDeclaration(decl, m_defaultNamespace, declName, nameSpace, dt); + asCDataType dt; + int r = bld.ParseVariableDeclaration(decl, m_defaultNamespace, declName, nameSpace, dt); if( r < 0 ) return r; @@ -1077,21 +1076,21 @@ void *asCModule::GetAddressOfGlobalVar(asUINT index) // For object variables it's necessary to dereference the pointer to get the address of the value if( prop->type.IsObject() && - !prop->type.IsObjectHandle() ) - return *(void**)(prop->GetAddressOfValue()); + !prop->type.IsObjectHandle() ) + return *(void **)(prop->GetAddressOfValue()); - return (void*)(prop->GetAddressOfValue()); + return (void *)(prop->GetAddressOfValue()); } // interface const char *asCModule::GetGlobalVarDeclaration(asUINT index, bool includeNamespace) const { const asCGlobalProperty *prop = m_scriptGlobals.Get(index); - if (!prop) return 0; + if( !prop ) return 0; - asCString *tempString = &asCThreadManager::GetLocalData()->string; - *tempString = prop->type.Format(m_defaultNamespace); - *tempString += " "; + asCString *tempString = &asCThreadManager::GetLocalData()->string; + *tempString = prop->type.Format(m_defaultNamespace); + *tempString += " "; if( includeNamespace && prop->nameSpace->name != "" ) *tempString += prop->nameSpace->name + "::"; *tempString += prop->name; @@ -1103,7 +1102,7 @@ const char *asCModule::GetGlobalVarDeclaration(asUINT index, bool includeNamespa int asCModule::GetGlobalVar(asUINT index, const char **out_name, const char **out_nameSpace, int *out_typeId, bool *out_isConst) const { const asCGlobalProperty *prop = m_scriptGlobals.Get(index); - if (!prop) return asINVALID_ARG; + if( !prop ) return asINVALID_ARG; if( out_name ) *out_name = prop->name.AddressOf(); @@ -1135,15 +1134,15 @@ asITypeInfo *asCModule::GetObjectTypeByIndex(asUINT index) const // interface asITypeInfo *asCModule::GetTypeInfoByName(const char *in_name) const { - asCString name; + asCString name; asSNameSpace *ns = 0; if( m_engine->DetermineNameAndNamespace(in_name, m_defaultNamespace, name, ns) < 0 ) return 0; - - while (ns) + + while( ns ) { - asITypeInfo* info = GetType(name, ns); - if(info) + asITypeInfo *info = GetType(name, ns); + if( info ) { return info; } @@ -1161,7 +1160,7 @@ int asCModule::GetTypeIdByDecl(const char *decl) const asCDataType dt; // This const cast is safe since we know the engine won't be modified - asCBuilder bld(m_engine, const_cast(this)); + asCBuilder bld(m_engine, const_cast(this)); // Don't write parser errors to the message callback bld.silent = true; @@ -1179,13 +1178,13 @@ asITypeInfo *asCModule::GetTypeInfoByDecl(const char *decl) const asCDataType dt; // This const cast is safe since we know the engine won't be modified - asCBuilder bld(m_engine, const_cast(this)); + asCBuilder bld(m_engine, const_cast(this)); // Don't write parser errors to the message callback bld.silent = true; int r = bld.ParseDataType(decl, &dt, m_defaultNamespace); - if (r < 0) + if( r < 0 ) return 0; return dt.GetTypeInfo(); @@ -1226,7 +1225,7 @@ int asCModule::GetNextImportedFunctionId() { // TODO: multithread: This will break if one thread if freeing a module, while another is being compiled if( m_engine->freeImportedFunctionIdxs.GetLength() ) - return FUNC_IMPORTED | (asUINT)m_engine->freeImportedFunctionIdxs[m_engine->freeImportedFunctionIdxs.GetLength()-1]; + return FUNC_IMPORTED | (asUINT)m_engine->freeImportedFunctionIdxs[m_engine->freeImportedFunctionIdxs.GetLength() - 1]; return FUNC_IMPORTED | (asUINT)m_engine->importedFunctions.GetLength(); } @@ -1256,23 +1255,23 @@ int asCModule::AddScriptFunction(int sectionIdx, int declaredAt, int id, const a if( objType && objType->IsShared() ) funcTraits.SetTrait(asTRAIT_SHARED, true); - func->name = funcName; - func->nameSpace = ns; - func->id = id; - func->returnType = returnType; + func->name = funcName; + func->nameSpace = ns; + func->id = id; + func->returnType = returnType; if( func->funcType == asFUNC_SCRIPT ) { func->scriptData->scriptSectionIdx = sectionIdx; - func->scriptData->declaredAt = declaredAt; + func->scriptData->declaredAt = declaredAt; } - func->parameterTypes = params; - func->parameterNames = paramNames; - func->inOutFlags = inOutFlags; - func->defaultArgs = defaultArgs; - func->objectType = objType; + func->parameterTypes = params; + func->parameterNames = paramNames; + func->inOutFlags = inOutFlags; + func->defaultArgs = defaultArgs; + func->objectType = objType; if( objType ) objType->AddRefInternal(); - func->traits = funcTraits; + func->traits = funcTraits; asASSERT( params.GetLength() == inOutFlags.GetLength() && params.GetLength() == defaultArgs.GetLength() ); @@ -1309,14 +1308,14 @@ int asCModule::AddScriptFunction(asCScriptFunction *func) { // Loop through the byte code and check all the // asBC_FuncPtr instructions for anonymous functions - asDWORD *bc = func->scriptData->byteCode.AddressOf(); - asUINT bcLength = (asUINT)func->scriptData->byteCode.GetLength(); + asDWORD *bc = func->scriptData->byteCode.AddressOf(); + asUINT bcLength = (asUINT)func->scriptData->byteCode.GetLength(); for( asUINT n = 0; n < bcLength; ) { - int c = *(asBYTE*)&bc[n]; + int c = *(asBYTE *)&bc[n]; if( c == asBC_FuncPtr ) { - asCScriptFunction *f = reinterpret_cast(asBC_PTRARG(&bc[n])); + asCScriptFunction *f = reinterpret_cast(asBC_PTRARG(&bc[n])); // Anonymous functions start with $ // There are never two equal anonymous functions so it is not necessary to look for duplicates if( f && f->name[0] == '$' ) @@ -1403,7 +1402,7 @@ int asCModule::BindImportedFunction(asUINT index, asIScriptFunction *func) // Only script functions and registered functions can be bound // Class methods, delegates, other imported functions are not allowed - if (func->GetFuncType() != asFUNC_SCRIPT && func->GetFuncType() != asFUNC_SYSTEM) + if( func->GetFuncType() != asFUNC_SCRIPT && func->GetFuncType() != asFUNC_SYSTEM ) return asNOT_SUPPORTED; asCScriptFunction *src = m_engine->GetScriptFunction(func->GetId()); @@ -1411,7 +1410,7 @@ int asCModule::BindImportedFunction(asUINT index, asIScriptFunction *func) return asNO_FUNCTION; // Verify function signature - if (!dst->IsSignatureExceptNameEqual(src)) + if( !dst->IsSignatureExceptNameEqual(src) ) return asINVALID_INTERFACE; m_bindInformations[index]->boundFunctionId = src->GetId(); @@ -1480,8 +1479,8 @@ int asCModule::BindAllImportedFunctions() const char *moduleName = GetImportedFunctionSourceModule(n); if( moduleName == 0 ) return asERROR; - asCModule *srcMod = m_engine->GetModule(moduleName, false); - asIScriptFunction *func = 0; + asCModule *srcMod = m_engine->GetModule(moduleName, false); + asIScriptFunction *func = 0; if( srcMod ) func = srcMod->GetFunctionByDecl(str.AddressOf()); @@ -1511,44 +1510,44 @@ int asCModule::UnbindAllImportedFunctions() } // internal -void asCModule::AddClassType(asCObjectType* type) +void asCModule::AddClassType(asCObjectType *type) { m_classTypes.PushLast(type); m_typeLookup.Insert(asSNameSpaceNamePair(type->nameSpace, type->name), type); } // internal -void asCModule::AddEnumType(asCEnumType* type) +void asCModule::AddEnumType(asCEnumType *type) { m_enumTypes.PushLast(type); m_typeLookup.Insert(asSNameSpaceNamePair(type->nameSpace, type->name), type); } // internal -void asCModule::AddTypeDef(asCTypedefType* type) +void asCModule::AddTypeDef(asCTypedefType *type) { m_typeDefs.PushLast(type); m_typeLookup.Insert(asSNameSpaceNamePair(type->nameSpace, type->name), type); } // internal -void asCModule::AddFuncDef(asCFuncdefType* type) +void asCModule::AddFuncDef(asCFuncdefType *type) { m_funcDefs.PushLast(type); m_typeLookup.Insert(asSNameSpaceNamePair(type->nameSpace, type->name), type); } // internal -void asCModule::ReplaceFuncDef(asCFuncdefType* type, asCFuncdefType* newType) +void asCModule::ReplaceFuncDef(asCFuncdefType *type, asCFuncdefType *newType) { int i = m_funcDefs.IndexOf(type); if( i >= 0 ) { m_funcDefs[i] = newType; - + // Replace it in the lookup map too - asSMapNode* result = 0; - if(m_typeLookup.MoveTo(&result, asSNameSpaceNamePair(type->nameSpace, type->name))) + asSMapNode *result = 0; + if( m_typeLookup.MoveTo(&result, asSNameSpaceNamePair(type->nameSpace, type->name)) ) { asASSERT( result->value == type ); result->value = newType; @@ -1559,8 +1558,8 @@ void asCModule::ReplaceFuncDef(asCFuncdefType* type, asCFuncdefType* newType) // internal asCTypeInfo *asCModule::GetType(const asCString &type, asSNameSpace *ns) const { - asSMapNode* result = 0; - if(m_typeLookup.MoveTo(&result, asSNameSpaceNamePair(ns, type))) + asSMapNode *result = 0; + if( m_typeLookup.MoveTo(&result, asSNameSpaceNamePair(ns, type)) ) { return result->value; } @@ -1570,12 +1569,12 @@ asCTypeInfo *asCModule::GetType(const asCString &type, asSNameSpace *ns) const // internal asCObjectType *asCModule::GetObjectType(const char *type, asSNameSpace *ns) const { - asSMapNode* result = 0; - if(m_typeLookup.MoveTo(&result, asSNameSpaceNamePair(ns, type))) + asSMapNode *result = 0; + if( m_typeLookup.MoveTo(&result, asSNameSpaceNamePair(ns, type)) ) { return CastToObjectType(result->value); } - + return 0; } @@ -1583,8 +1582,8 @@ asCObjectType *asCModule::GetObjectType(const char *type, asSNameSpace *ns) cons asCGlobalProperty *asCModule::AllocateGlobalProperty(const char *propName, const asCDataType &dt, asSNameSpace *ns) { asCGlobalProperty *prop = m_engine->AllocateGlobalProperty(); - prop->name = propName; - prop->nameSpace = ns; + prop->name = propName; + prop->nameSpace = ns; // Allocate the memory for this property based on its type prop->type = dt; @@ -1603,14 +1602,14 @@ asCGlobalProperty *asCModule::AllocateGlobalProperty(const char *propName, const // internal bool asCModule::IsEmpty() const { - if( m_scriptFunctions.GetLength() ) return false; - if( m_globalFunctions.GetSize() ) return false; + if( m_scriptFunctions.GetLength() ) return false; + if( m_globalFunctions.GetSize() ) return false; if( m_bindInformations.GetLength() ) return false; - if( m_scriptGlobals.GetSize() ) return false; - if( m_classTypes.GetLength() ) return false; - if( m_enumTypes.GetLength() ) return false; - if( m_typeDefs.GetLength() ) return false; - if( m_funcDefs.GetLength() ) return false; + if( m_scriptGlobals.GetSize() ) return false; + if( m_classTypes.GetLength() ) return false; + if( m_enumTypes.GetLength() ) return false; + if( m_typeDefs.GetLength() ) return false; + if( m_funcDefs.GetLength() ) return false; return true; } @@ -1629,7 +1628,7 @@ int asCModule::SaveByteCode(asIBinaryStream *out, bool stripDebugInfo) const if( IsEmpty() ) return asERROR; - asCWriter write(const_cast(this), out, m_engine, stripDebugInfo); + asCWriter write(const_cast(this), out, m_engine, stripDebugInfo); return write.Write(); #endif } @@ -1655,7 +1654,7 @@ int asCModule::LoadByteCode(asIBinaryStream *in, bool *wasDebugInfoStripped) asCReader read(this, in, m_engine); r = read.Read(wasDebugInfoStripped); - if (r < 0) + if( r < 0 ) { m_engine->BuildCompleted(); return r; @@ -1708,8 +1707,8 @@ int asCModule::CompileGlobalVar(const char *sectionName, const char *code, int l // Compile the global variable and add it to the module scope asCBuilder varBuilder(m_engine, this); - asCString str = code; - r = varBuilder.CompileGlobalVar(sectionName, str.AddressOf(), lineOffset); + asCString str = code; + r = varBuilder.CompileGlobalVar(sectionName, str.AddressOf(), lineOffset); m_engine->BuildCompleted(); @@ -1720,7 +1719,7 @@ int asCModule::CompileGlobalVar(const char *sectionName, const char *code, int l asCGlobalProperty *prop = m_scriptGlobals.GetLast(); if( prop ) { - memset(prop->GetAddressOfValue(), 0, sizeof(asDWORD)*prop->type.GetSizeOnStackDWords()); + memset(prop->GetAddressOfValue(), 0, sizeof(asDWORD) * prop->type.GetSizeOnStackDWords()); } if( prop && m_engine->ep.initGlobalVarsAfterBuild ) @@ -1737,11 +1736,11 @@ int asCModule::CompileGlobalVar(const char *sectionName, const char *code, int l } // interface -int asCModule::CompileFunction(const char* sectionName, const char* code, int lineOffset, asDWORD compileFlags, asIScriptFunction** outFunc) +int asCModule::CompileFunction(const char *sectionName, const char *code, int lineOffset, asDWORD compileFlags, asIScriptFunction **outFunc) { // Make sure the outFunc is null if the function fails, so the // application doesn't attempt to release a non-existent function - if (outFunc) + if( outFunc ) *outFunc = 0; #ifdef AS_NO_COMPILER @@ -1752,19 +1751,19 @@ int asCModule::CompileFunction(const char* sectionName, const char* code, int li return asNOT_SUPPORTED; #else // Validate arguments - if (code == 0 || - (compileFlags != 0 && compileFlags != asCOMP_ADD_TO_MODULE)) + if( code == 0 || + (compileFlags != 0 && compileFlags != asCOMP_ADD_TO_MODULE) ) return asINVALID_ARG; // Only one thread may build at one time // TODO: It should be possible to have multiple threads perform compilations int r = m_engine->RequestBuild(); - if (r < 0) + if( r < 0 ) return r; // Prepare the engine m_engine->PrepareEngine(); - if (m_engine->configFailed) + if( m_engine->configFailed ) { m_engine->WriteMessage("", 0, 0, asMSGTYPE_ERROR, TXT_INVALID_CONFIGURATION); m_engine->BuildCompleted(); @@ -1772,15 +1771,15 @@ int asCModule::CompileFunction(const char* sectionName, const char* code, int li } // Compile the single function - asCBuilder funcBuilder(m_engine, this); - asCString str = code; - asCScriptFunction* func = 0; - r = funcBuilder.CompileFunction(sectionName, str.AddressOf(), lineOffset, compileFlags, &func); + asCBuilder funcBuilder(m_engine, this); + asCString str = code; + asCScriptFunction *func = 0; + r = funcBuilder.CompileFunction(sectionName, str.AddressOf(), lineOffset, compileFlags, &func); - if (r >= 0) + if( r >= 0 ) { // Invoke the JIT compiler if it has been set - if (m_engine->jitCompiler) + if( m_engine->jitCompiler ) func->JITCompile(); } @@ -1805,8 +1804,8 @@ int asCModule::CompileFunction(const char* sectionName, const char* code, int li int asCModule::RemoveFunction(asIScriptFunction *func) { // Find the global function - asCScriptFunction *f = static_cast(func); - int idx = m_globalFunctions.GetIndex(f); + asCScriptFunction *f = static_cast(func); + int idx = m_globalFunctions.GetIndex(f); if( idx >= 0 ) { m_globalFunctions.Erase(idx); @@ -1826,7 +1825,7 @@ int asCModule::AddFuncDef(const asCString &funcName, asSNameSpace *ns, asCObject asASSERT((ns == 0 && parent) || (ns && parent == 0)); asCScriptFunction *func = asNEW(asCScriptFunction)(m_engine, 0, asFUNC_FUNCDEF); - if (func == 0) + if( func == 0 ) return asOUT_OF_MEMORY; func->name = funcName; @@ -1840,23 +1839,22 @@ int asCModule::AddFuncDef(const asCString &funcName, asSNameSpace *ns, asCObject func->id = m_engine->GetNextScriptFunctionId(); m_engine->AddScriptFunction(func); - if (parent) + if( parent ) { parent->childFuncDefs.PushLast(fdt); fdt->parentClass = parent; } - return (int)m_funcDefs.GetLength()-1; + return (int)m_funcDefs.GetLength() - 1; } #endif // interface asDWORD asCModule::SetAccessMask(asDWORD mask) { - asDWORD old = m_accessMask; + asDWORD old = m_accessMask; m_accessMask = mask; return old; } END_AS_NAMESPACE - diff --git a/sdk/angelscript/source/as_module.h b/sdk/angelscript/source/as_module.h index b6caac14..71dad208 100644 --- a/sdk/angelscript/source/as_module.h +++ b/sdk/angelscript/source/as_module.h @@ -64,7 +64,9 @@ struct asSNameSpace; struct sBindInfo { - sBindInfo() : importedFunctionSignature(0), boundFunctionId(-1) {} + sBindInfo() : importedFunctionSignature(0), boundFunctionId(-1) + { + } asCScriptFunction *importedFunctionSignature; asCString importFromModule; int boundFunctionId; @@ -95,9 +97,9 @@ struct sObjectTypePair class asCModule : public asIScriptModule { -//------------------------------------------- -// Public interface -//-------------------------------------------- + //------------------------------------------- + // Public interface + //-------------------------------------------- public: virtual asIScriptEngine *GetEngine() const; virtual void SetName(const char *name); @@ -132,11 +134,11 @@ class asCModule : public asIScriptModule virtual int RemoveGlobalVar(asUINT index); // Type identification - virtual asUINT GetObjectTypeCount() const; - virtual asITypeInfo *GetObjectTypeByIndex(asUINT index) const; - virtual int GetTypeIdByDecl(const char *decl) const; - virtual asITypeInfo *GetTypeInfoByName(const char *name) const; - virtual asITypeInfo *GetTypeInfoByDecl(const char *decl) const; + virtual asUINT GetObjectTypeCount() const; + virtual asITypeInfo *GetObjectTypeByIndex(asUINT index) const; + virtual int GetTypeIdByDecl(const char *decl) const; + virtual asITypeInfo *GetTypeInfoByName(const char *name) const; + virtual asITypeInfo *GetTypeInfoByDecl(const char *decl) const; // Enums virtual asUINT GetEnumCount() const; @@ -164,13 +166,13 @@ class asCModule : public asIScriptModule virtual void *SetUserData(void *data, asPWORD type); virtual void *GetUserData(asPWORD type) const; -//----------------------------------------------- -// Internal -//----------------------------------------------- + //----------------------------------------------- + // Internal + //----------------------------------------------- asCModule(const char *name, asCScriptEngine *engine); ~asCModule(); -//protected: + //protected: friend class asCScriptEngine; friend class asCBuilder; friend class asCCompiler; @@ -188,10 +190,10 @@ class asCModule : public asIScriptModule void JITCompile(); #ifndef AS_NO_COMPILER - int AddScriptFunction(int sectionIdx, int declaredAt, int id, const asCString &name, const asCDataType &returnType, const asCArray ¶ms, const asCArray ¶mNames, const asCArray &inOutFlags, const asCArray &defaultArgs, bool isInterface, asCObjectType *objType = 0, bool isGlobalFunction = false, asSFunctionTraits funcTraits = asSFunctionTraits(), asSNameSpace *ns = 0); - int AddScriptFunction(asCScriptFunction *func); - int AddImportedFunction(int id, const asCString &name, const asCDataType &returnType, const asCArray ¶ms, const asCArray &inOutFlags, const asCArray &defaultArgs, asSFunctionTraits funcTraits, asSNameSpace *ns, const asCString &moduleName); - int AddFuncDef(const asCString &name, asSNameSpace *ns, asCObjectType *parent); + int AddScriptFunction(int sectionIdx, int declaredAt, int id, const asCString &name, const asCDataType &returnType, const asCArray ¶ms, const asCArray ¶mNames, const asCArray &inOutFlags, const asCArray &defaultArgs, bool isInterface, asCObjectType *objType = 0, bool isGlobalFunction = false, asSFunctionTraits funcTraits = asSFunctionTraits(), asSNameSpace *ns = 0); + int AddScriptFunction(asCScriptFunction *func); + int AddImportedFunction(int id, const asCString &name, const asCDataType &returnType, const asCArray ¶ms, const asCArray &inOutFlags, const asCArray &defaultArgs, asSFunctionTraits funcTraits, asSNameSpace *ns, const asCString &moduleName); + int AddFuncDef(const asCString &name, asSNameSpace *ns, asCObjectType *parent); #endif int GetNextImportedFunctionId(); @@ -200,17 +202,17 @@ class asCModule : public asIScriptModule asCObjectType *GetObjectType(const char *type, asSNameSpace *ns) const; asCGlobalProperty *AllocateGlobalProperty(const char *name, const asCDataType &dt, asSNameSpace *ns); void UninitializeGlobalProp(asCGlobalProperty *prop); - + // Adds the class type to the module. The module assumes ownership of the reference without increasing it - void AddClassType(asCObjectType*); + void AddClassType(asCObjectType *); // Adds the enum type to the module. The module assumes ownership of the reference without increasing it - void AddEnumType(asCEnumType*); + void AddEnumType(asCEnumType *); // Adds the typedef to the module. The module assumes ownership of the reference without increasing it - void AddTypeDef(asCTypedefType*); + void AddTypeDef(asCTypedefType *); // Adds the funcdef to the module. The module assumes ownership of the reference without increasing it - void AddFuncDef(asCFuncdefType*); + void AddFuncDef(asCFuncdefType *); // Replaces an existing funcdef with another (used for shared funcdefs). Doesn't add or release refCounts - void ReplaceFuncDef(asCFuncdefType *oldType, asCFuncdefType *newType); + void ReplaceFuncDef(asCFuncdefType *oldType, asCFuncdefType *newType); asCString m_name; asCScriptEngine *m_engine; @@ -221,36 +223,36 @@ class asCModule : public asIScriptModule // This array holds all functions, class members, factories, etc that were compiled with the module. // These references hold an internal reference to the function object. - asCArray m_scriptFunctions; // increases ref count + asCArray m_scriptFunctions; // increases ref count // This array holds global functions declared in the module. These references are not counted, // as the same pointer is always present in the scriptFunctions array too. asCSymbolTable m_globalFunctions; // doesn't increase ref count // This array holds imported functions in the module. - asCArray m_bindInformations; // increases ref count + asCArray m_bindInformations; // increases ref count // This array holds template instance types created for the module's object types - asCArray m_templateInstances; // increases ref count + asCArray m_templateInstances; // increases ref count // This array holds the global variables declared in the script asCSymbolTable m_scriptGlobals; // increases ref count bool m_isGlobalVarInitialized; // This array holds class and interface types - asCArray m_classTypes; // increases ref count + asCArray m_classTypes; // increases ref count // This array holds enum types - asCArray m_enumTypes; // increases ref count + asCArray m_enumTypes; // increases ref count // This array holds typedefs - asCArray m_typeDefs; // increases ref count + asCArray m_typeDefs; // increases ref count // This array holds the funcdefs declared in the module - asCArray m_funcDefs; // increases ref count + asCArray m_funcDefs; // increases ref count // This map contains all the types (also contained in the arrays above) for quick lookup // TODO: memory: Can we eliminate the arrays above? - asCMap m_typeLookup; // doesn't increase ref count + asCMap m_typeLookup; // doesn't increase ref count // This array holds types that have been explicitly declared with 'external' - asCArray m_externalTypes; // doesn't increase ref count + asCArray m_externalTypes; // doesn't increase ref count // This array holds functions that have been explicitly declared with 'external' - asCArray m_externalFunctions; // doesn't increase ref count + asCArray m_externalFunctions; // doesn't increase ref count }; END_AS_NAMESPACE diff --git a/sdk/angelscript/source/as_namespace.h b/sdk/angelscript/source/as_namespace.h index ae384e7a..1df9a6bc 100644 --- a/sdk/angelscript/source/as_namespace.h +++ b/sdk/angelscript/source/as_namespace.h @@ -50,8 +50,12 @@ struct asSNameSpaceNamePair const asSNameSpace *ns; asCString name; - asSNameSpaceNamePair() : ns(0) {} - asSNameSpaceNamePair(const asSNameSpace *_ns, const asCString &_name) : ns(_ns), name(_name) {} + asSNameSpaceNamePair() : ns(0) + { + } + asSNameSpaceNamePair(const asSNameSpace *_ns, const asCString &_name) : ns(_ns), name(_name) + { + } asSNameSpaceNamePair &operator=(const asSNameSpaceNamePair &other) { @@ -74,4 +78,3 @@ struct asSNameSpaceNamePair END_AS_NAMESPACE #endif - diff --git a/sdk/angelscript/source/as_objecttype.cpp b/sdk/angelscript/source/as_objecttype.cpp index f19e26fc..8d3e58d9 100644 --- a/sdk/angelscript/source/as_objecttype.cpp +++ b/sdk/angelscript/source/as_objecttype.cpp @@ -53,19 +53,19 @@ asCObjectType::asCObjectType() : asCTypeInfo() acceptRefSubType = true; #ifdef WIP_16BYTE_ALIGN - alignment = 4; + alignment = 4; #endif } asCObjectType::asCObjectType(asCScriptEngine *in_engine) : asCTypeInfo(in_engine) { - derivedFrom = 0; + derivedFrom = 0; acceptValueSubType = true; - acceptRefSubType = true; + acceptRefSubType = true; #ifdef WIP_16BYTE_ALIGN - alignment = 4; + alignment = 4; #endif } @@ -78,7 +78,7 @@ asUINT asCObjectType::GetChildFuncdefCount() const // interface asITypeInfo *asCObjectType::GetChildFuncdef(asUINT index) const { - if (index >= childFuncDefs.GetLength()) + if( index >= childFuncDefs.GetLength() ) return 0; return childFuncDefs[index]; @@ -107,18 +107,18 @@ void asCObjectType::DestroyInternal() templateSubTypes.SetLength(0); // Clear the child types - for (asUINT n = 0; n < childFuncDefs.GetLength(); n++) + for( asUINT n = 0; n < childFuncDefs.GetLength(); n++ ) { asCFuncdefType *func = childFuncDefs[n]; - if (func) + if( func ) { func->parentClass = 0; - if (isTemplateInstance) + if( isTemplateInstance ) { - // Any child funcdefs that have been created as part of the template + // Any child funcdefs that have been created as part of the template // instantiation must be destroyed too // TODO: Before destroying the funcdef, make sure no external references to it is held - if (func->externalRefCount.get() == 0) + if( func->externalRefCount.get() == 0 ) { func->DestroyInternal(); engine->RemoveFuncdef(func); @@ -311,12 +311,12 @@ asIScriptFunction *asCObjectType::GetMethodByDecl(const char *decl, bool getVirt // Get the module from one of the methods, but it will only be // used to allow the parsing of types not already known by the object. - // It is possible for object types to be orphaned, e.g. by discarding - // the module that created it. In this case it is still possible to + // It is possible for object types to be orphaned, e.g. by discarding + // the module that created it. In this case it is still possible to // find the methods, but any type not known by the object will result in // an invalid declaration. asCModule *mod = engine->scriptFunctions[methods[0]]->module; - int id = engine->GetMethodIdByDecl(this, decl, mod); + int id = engine->GetMethodIdByDecl(this, decl, mod); if( id <= 0 ) return 0; @@ -357,11 +357,11 @@ int asCObjectType::GetProperty(asUINT index, const char **out_name, int *out_typ *out_isReference = prop->type.IsReference(); if( out_accessMask ) *out_accessMask = prop->accessMask; - if (out_compositeOffset) + if( out_compositeOffset ) *out_compositeOffset = prop->compositeOffset; - if (out_isCompositeIndirect) + if( out_isCompositeIndirect ) *out_isCompositeIndirect = prop->isCompositeIndirect; - if (out_isConst) + if( out_isConst ) *out_isConst = prop->type.IsReadOnly(); return 0; @@ -389,25 +389,25 @@ const char *asCObjectType::GetPropertyDeclaration(asUINT index, bool includeName asITypeInfo *asCObjectType::GetBaseType() const { - return derivedFrom; + return derivedFrom; } asUINT asCObjectType::GetBehaviourCount() const { // Count the number of behaviours (except factory functions) asUINT count = 0; - - if( beh.destruct ) count++; - if( beh.addref ) count++; - if( beh.release ) count++; - if( beh.gcGetRefCount ) count++; - if( beh.gcSetFlag ) count++; - if( beh.gcGetFlag ) count++; - if( beh.gcEnumReferences ) count++; - if( beh.gcReleaseAllReferences ) count++; - if( beh.templateCallback ) count++; - if( beh.listFactory ) count++; - if( beh.getWeakRefFlag ) count++; + + if( beh.destruct ) count++; + if( beh.addref ) count++; + if( beh.release ) count++; + if( beh.gcGetRefCount ) count++; + if( beh.gcSetFlag ) count++; + if( beh.gcGetFlag ) count++; + if( beh.gcEnumReferences ) count++; + if( beh.gcReleaseAllReferences ) count++; + if( beh.templateCallback ) count++; + if( beh.listFactory ) count++; + if( beh.getWeakRefFlag ) count++; // For reference types, the factories are also stored in the constructor // list, so it is sufficient to enumerate only those @@ -422,7 +422,7 @@ asIScriptFunction *asCObjectType::GetBehaviourByIndex(asUINT index, asEBehaviour asUINT count = 0; if( beh.destruct && count++ == index ) // only increase count if the behaviour is registered - { + { if( outBehaviour ) *outBehaviour = asBEHAVE_DESTRUCT; return engine->scriptFunctions[beh.destruct]; } @@ -477,7 +477,7 @@ asIScriptFunction *asCObjectType::GetBehaviourByIndex(asUINT index, asEBehaviour if( beh.listFactory && count++ == index ) { - if( outBehaviour ) + if( outBehaviour ) { if( flags & asOBJ_VALUE ) *outBehaviour = asBEHAVE_LIST_CONSTRUCT; @@ -501,7 +501,7 @@ asIScriptFunction *asCObjectType::GetBehaviourByIndex(asUINT index, asEBehaviour if( outBehaviour ) *outBehaviour = asBEHAVE_CONSTRUCT; return engine->scriptFunctions[beh.constructors[index - count]]; } - else + else count += (asUINT)beh.constructors.GetLength(); return 0; @@ -539,12 +539,12 @@ asCObjectProperty *asCObjectType::AddPropertyToClass(const asCString &propName, propSize = dt.GetSizeInMemoryBytes(); else { - propSize = dt.GetSizeOnStackDWords()*4; + propSize = dt.GetSizeOnStackDWords() * 4; if( !dt.IsObjectHandle() ) prop->type.MakeReference(true); } } - else if (dt.IsFuncdef()) + else if( dt.IsFuncdef() ) { // Funcdefs don't have a size, as they must always be stored as handles asASSERT(dt.IsObjectHandle()); @@ -558,8 +558,8 @@ asCObjectProperty *asCObjectType::AddPropertyToClass(const asCString &propName, if( propSize == 2 && (size & 1) ) size += 1; if( propSize > 2 && (size & 3) ) size += 4 - (size & 3); #else - asUINT alignment = dt.GetAlignment(); - const asUINT propSizeAlignmentDifference = size & (alignment-1); + asUINT alignment = dt.GetAlignment(); + const asUINT propSizeAlignmentDifference = size & (alignment - 1); if( propSizeAlignmentDifference != 0 ) { size += (alignment - propSizeAlignmentDifference); @@ -568,8 +568,8 @@ asCObjectProperty *asCObjectType::AddPropertyToClass(const asCString &propName, asASSERT((size % alignment) == 0); #endif - prop->byteOffset = size; - size += propSize; + prop->byteOffset = size; + size += propSize; properties.PushLast(prop); @@ -590,7 +590,7 @@ void asCObjectType::ReleaseAllProperties() { for( asUINT n = 0; n < properties.GetLength(); n++ ) { - if( properties[n] ) + if( properties[n] ) { if( flags & asOBJ_SCRIPT_OBJECT ) { @@ -611,7 +611,7 @@ void asCObjectType::ReleaseAllProperties() type->ReleaseInternal(); } - asDELETE(properties[n],asCObjectProperty); + asDELETE(properties[n], asCObjectProperty); } } @@ -625,7 +625,7 @@ void asCObjectType::ReleaseAllFunctions() beh.copyfactory = 0; for( asUINT a = 0; a < beh.factories.GetLength(); a++ ) { - if( engine->scriptFunctions[beh.factories[a]] ) + if( engine->scriptFunctions[beh.factories[a]] ) engine->scriptFunctions[beh.factories[a]]->ReleaseInternal(); } beh.factories.SetLength(0); @@ -634,7 +634,7 @@ void asCObjectType::ReleaseAllFunctions() beh.copyconstruct = 0; for( asUINT b = 0; b < beh.constructors.GetLength(); b++ ) { - if( engine->scriptFunctions[beh.constructors[b]] ) + if( engine->scriptFunctions[beh.constructors[b]] ) engine->scriptFunctions[beh.constructors[b]]->ReleaseInternal(); } beh.constructors.SetLength(0); @@ -649,7 +649,7 @@ void asCObjectType::ReleaseAllFunctions() if( beh.destruct ) engine->scriptFunctions[beh.destruct]->ReleaseInternal(); - beh.destruct = 0; + beh.destruct = 0; if( beh.copy ) engine->scriptFunctions[beh.copy]->ReleaseInternal(); @@ -657,7 +657,7 @@ void asCObjectType::ReleaseAllFunctions() for( asUINT c = 0; c < methods.GetLength(); c++ ) { - if( engine->scriptFunctions[methods[c]] ) + if( engine->scriptFunctions[methods[c]] ) engine->scriptFunctions[methods[c]]->ReleaseInternal(); } methods.SetLength(0); @@ -698,12 +698,9 @@ void asCObjectType::ReleaseAllFunctions() engine->scriptFunctions[beh.gcSetFlag]->ReleaseInternal(); beh.gcSetFlag = 0; - if ( beh.getWeakRefFlag ) + if( beh.getWeakRefFlag ) engine->scriptFunctions[beh.getWeakRefFlag]->ReleaseInternal(); beh.getWeakRefFlag = 0; } END_AS_NAMESPACE - - - diff --git a/sdk/angelscript/source/as_objecttype.h b/sdk/angelscript/source/as_objecttype.h index dcb3107f..b1e78b6d 100644 --- a/sdk/angelscript/source/as_objecttype.h +++ b/sdk/angelscript/source/as_objecttype.h @@ -50,24 +50,24 @@ BEGIN_AS_NAMESPACE struct asSTypeBehaviour { - asSTypeBehaviour() + asSTypeBehaviour() { - factory = 0; - listFactory = 0; - copyfactory = 0; - construct = 0; - copyconstruct = 0; - destruct = 0; - copy = 0; - addref = 0; - release = 0; - gcGetRefCount = 0; - gcSetFlag = 0; - gcGetFlag = 0; - gcEnumReferences = 0; + factory = 0; + listFactory = 0; + copyfactory = 0; + construct = 0; + copyconstruct = 0; + destruct = 0; + copy = 0; + addref = 0; + release = 0; + gcGetRefCount = 0; + gcSetFlag = 0; + gcGetFlag = 0; + gcEnumReferences = 0; gcReleaseAllReferences = 0; - templateCallback = 0; - getWeakRefFlag = 0; + templateCallback = 0; + getWeakRefFlag = 0; } int factory; @@ -134,28 +134,28 @@ class asCObjectType : public asCTypeInfo bool IsInterface() const; asCObjectProperty *AddPropertyToClass(const asCString &name, const asCDataType &dt, bool isPrivate, bool isProtected, bool isInherited); - void ReleaseAllProperties(); + void ReleaseAllProperties(); #ifdef WIP_16BYTE_ALIGN - int alignment; + int alignment; #endif - asCArray properties; - asCArray methods; + asCArray properties; + asCArray methods; // TODO: These are not used by template types. Should perhaps create a derived class to save memory on ordinary object types - asCArray interfaces; - asCArray interfaceVFTOffsets; - asCObjectType * derivedFrom; - asCArray virtualFunctionTable; + asCArray interfaces; + asCArray interfaceVFTOffsets; + asCObjectType *derivedFrom; + asCArray virtualFunctionTable; // Used for funcdefs declared as members of class. // TODO: child funcdef: Should be possible to enumerate these from application - asCArray childFuncDefs; + asCArray childFuncDefs; asSTypeBehaviour beh; // Used for template types - asCArray templateSubTypes; // increases refCount for typeinfo held in datatype + asCArray templateSubTypes; // increases refCount for typeinfo held in datatype bool acceptValueSubType; bool acceptRefSubType; diff --git a/sdk/angelscript/source/as_outputbuffer.cpp b/sdk/angelscript/source/as_outputbuffer.cpp index 433f820f..f2df6ac2 100644 --- a/sdk/angelscript/source/as_outputbuffer.cpp +++ b/sdk/angelscript/source/as_outputbuffer.cpp @@ -40,8 +40,8 @@ #ifndef AS_NO_COMPILER -#include "as_outputbuffer.h" -#include "as_scriptengine.h" + #include "as_outputbuffer.h" + #include "as_scriptengine.h" BEGIN_AS_NAMESPACE @@ -54,9 +54,9 @@ void asCOutputBuffer::Clear() { for( asUINT n = 0; n < messages.GetLength(); n++ ) { - if( messages[n] ) + if( messages[n] ) { - asDELETE(messages[n],message_t); + asDELETE(messages[n], message_t); } } messages.SetLength(0); @@ -69,10 +69,10 @@ void asCOutputBuffer::Callback(asSMessageInfo *msg) return; msgInfo->section = msg->section; - msgInfo->row = msg->row; - msgInfo->col = msg->col; - msgInfo->type = msg->type; - msgInfo->msg = msg->message; + msgInfo->row = msg->row; + msgInfo->col = msg->col; + msgInfo->type = msg->type; + msgInfo->msg = msg->message; messages.PushLast(msgInfo); } @@ -106,4 +106,3 @@ void asCOutputBuffer::SendToCallback(asCScriptEngine *engine, asSSystemFunctionI END_AS_NAMESPACE #endif // AS_NO_COMPILER - diff --git a/sdk/angelscript/source/as_outputbuffer.h b/sdk/angelscript/source/as_outputbuffer.h index 41af0cd7..fb4b6b05 100644 --- a/sdk/angelscript/source/as_outputbuffer.h +++ b/sdk/angelscript/source/as_outputbuffer.h @@ -44,8 +44,8 @@ #ifndef AS_NO_COMPILER -#include "as_string.h" -#include "as_array.h" + #include "as_string.h" + #include "as_array.h" BEGIN_AS_NAMESPACE @@ -55,24 +55,29 @@ class asCScriptEngine; class asCOutputBuffer { public: - ~asCOutputBuffer (); - void Clear(); - void Callback(asSMessageInfo *msg); - static void CDeclCallback(asSMessageInfo* msg, asCOutputBuffer* buf) { buf->Callback(msg); } + ~asCOutputBuffer(); + void Clear(); + void Callback(asSMessageInfo *msg); + static void CDeclCallback(asSMessageInfo *msg, asCOutputBuffer *buf) + { + buf->Callback(msg); + } void Append(asCOutputBuffer &in); void SendToCallback(asCScriptEngine *engine, asSSystemFunctionInterface *func, void *obj); struct message_t { - message_t() : row(0), col(0), type(asMSGTYPE_INFORMATION) {} - asCString section; - int row; - int col; + message_t() : row(0), col(0), type(asMSGTYPE_INFORMATION) + { + } + asCString section; + int row; + int col; asEMsgType type; - asCString msg; + asCString msg; }; - asCArray messages; + asCArray messages; }; END_AS_NAMESPACE diff --git a/sdk/angelscript/source/as_parser.cpp b/sdk/angelscript/source/as_parser.cpp index 6d29712d..4962d9cd 100644 --- a/sdk/angelscript/source/as_parser.cpp +++ b/sdk/angelscript/source/as_parser.cpp @@ -56,15 +56,15 @@ #include "as_debug.h" #ifdef _MSC_VER -#pragma warning(disable:4702) // unreachable code + #pragma warning(disable : 4702) // unreachable code #endif BEGIN_AS_NAMESPACE asCParser::asCParser(asCBuilder *builder) : lastToken() { - this->builder = builder; - this->engine = builder->engine; + this->builder = builder; + this->engine = builder->engine; script = 0; scriptNode = 0; @@ -149,7 +149,7 @@ asCScriptNode *asCParser::CreateNode(eScriptNode type) return 0; } - return new(ptr) asCScriptNode(type); + return new (ptr) asCScriptNode(type); } int asCParser::ParseDataType(asCScriptCode *in_script, bool in_isReturnType) @@ -192,14 +192,14 @@ int asCParser::ParseTemplateDecl(asCScriptCode *in_script) Reset(); this->script = in_script; - scriptNode = CreateNode(snUndefined); + scriptNode = CreateNode(snUndefined); if( scriptNode == 0 ) return -1; scriptNode->AddChildLast(ParseIdentifier()); if( isSyntaxError ) return -1; ParseTemplateDeclTypeList(scriptNode, true); - if (isSyntaxError) return -1; + if( isSyntaxError ) return -1; sToken t; GetToken(&t); @@ -282,15 +282,15 @@ void asCParser::ParseOptionalScope(asCScriptNode *node) if( t1.type == ttIdentifier && t2.type == ttLessThan ) { tempString.Assign(&script->code[t1.pos], t1.length); - if (engine->IsTemplateType(tempString.AddressOf())) + if( engine->IsTemplateType(tempString.AddressOf()) ) { RewindTo(&t1); asCScriptNode *restore = scope->lastChild; scope->AddChildLast(ParseIdentifier()); - if (ParseTemplTypeList(scope, false)) + if( ParseTemplTypeList(scope, false) ) { GetToken(&t2); - if (t2.type == ttScope) + if( t2.type == ttScope ) { // Template type is part of the scope // Nothing more needs to be done @@ -304,7 +304,7 @@ void asCParser::ParseOptionalScope(asCScriptNode *node) RewindTo(&t1); // Restore the previously parsed node - while (scope->lastChild != restore) + while( scope->lastChild != restore ) { asCScriptNode *last = scope->lastChild; last->DisconnectParent(); @@ -323,14 +323,14 @@ void asCParser::ParseOptionalScope(asCScriptNode *node) // The identifier is not part of the scope RewindTo(&t1); - if (scope->lastChild) + if( scope->lastChild ) node->AddChildLast(scope); else scope->Destroy(engine); } // Parse '<' 'class'? IDENTIFIER (',' 'class'? IDENTIFIER)? '>' -bool asCParser::ParseTemplateDeclTypeList(asCScriptNode* node, bool required) +bool asCParser::ParseTemplateDeclTypeList(asCScriptNode *node, bool required) { // Backup initial position sToken init; @@ -338,16 +338,16 @@ bool asCParser::ParseTemplateDeclTypeList(asCScriptNode* node, bool required) RewindTo(&init); sToken t; - bool isValid = true; + bool isValid = true; // Remember the last child, so we can restore the state if needed asCScriptNode *last = node->lastChild; // Starts with '<' GetToken(&t); - if (t.type != ttLessThan) + if( t.type != ttLessThan ) { - if (required) + if( required ) { Error(ExpectedToken(asCTokenizer::GetDefinition(ttLessThan)), &t); Error(InsteadFound(t), &t); @@ -356,29 +356,29 @@ bool asCParser::ParseTemplateDeclTypeList(asCScriptNode* node, bool required) return false; } GetToken(&t); - if(t.type != ttClass) + if( t.type != ttClass ) RewindTo(&t); node->AddChildLast(ParseIdentifier()); - if (isSyntaxError) return false; + if( isSyntaxError ) return false; GetToken(&t); - while (t.type == ttListSeparator) + while( t.type == ttListSeparator ) { GetToken(&t); - if(t.type != ttClass) + if( t.type != ttClass ) RewindTo(&t); node->AddChildLast(ParseIdentifier()); - if (isSyntaxError) return false; + if( isSyntaxError ) return false; GetToken(&t); } // End with '>' // Accept >> and >>> tokens too. But then force the tokenizer to move // only 1 character ahead (thus splitting the token in two). - if (script->code[t.pos] != '>') + if( script->code[t.pos] != '>' ) { - if (required) + if( required ) { Error(ExpectedToken(asCTokenizer::GetDefinition(ttGreaterThan)), &t); Error(InsteadFound(t), &t); @@ -392,10 +392,10 @@ bool asCParser::ParseTemplateDeclTypeList(asCScriptNode* node, bool required) SetPos(t.pos + 1); } - if (!required && !isValid) + if( !required && !isValid ) { // Restore the original state before returning - while (node->lastChild != last) + while( node->lastChild != last ) { asCScriptNode *n = node->lastChild; n->DisconnectParent(); @@ -425,7 +425,7 @@ asCScriptNode *asCParser::ParseFunctionDefinition() node->AddChildLast(ParseIdentifier()); if( isSyntaxError ) return node; - + // Parse optional template sub types ParseTemplateDeclTypeList(node, false); @@ -486,10 +486,10 @@ asCScriptNode *asCParser::ParseTypeMod(bool isParam) // Parse possible if_handle_then_const token GetToken(&t); RewindTo(&t); - if (IdentifierIs(t, IF_HANDLE_TOKEN)) + if( IdentifierIs(t, IF_HANDLE_TOKEN) ) { node->AddChildLast(ParseToken(ttIdentifier)); - if (isSyntaxError) return node; + if( isSyntaxError ) return node; } return node; @@ -529,13 +529,13 @@ asCScriptNode *asCParser::ParseType(bool allowConst, bool allowVariableType, boo if( engine->IsTemplateType(tempString.AddressOf()) && t.type == ttLessThan ) { ParseTemplTypeList(node); - if (isSyntaxError) return node; + if( isSyntaxError ) return node; } // Parse [] and @ GetToken(&t); RewindTo(&t); - while( t.type == ttOpenBracket || t.type == ttHandle) + while( t.type == ttOpenBracket || t.type == ttHandle ) { if( t.type == ttOpenBracket ) { @@ -581,19 +581,19 @@ bool asCParser::ParseTemplTypeList(asCScriptNode *node, bool required) // Backup original position sToken init; GetToken(&init); - RewindTo(&init); + RewindTo(&init); sToken t; - bool isValid = true; + bool isValid = true; // Remember the last child, so we can restore the state if needed asCScriptNode *last = node->lastChild; // Starts with '<' GetToken(&t); - if (t.type != ttLessThan) + if( t.type != ttLessThan ) { - if (required) + if( required ) { Error(ExpectedToken(asCTokenizer::GetDefinition(ttLessThan)), &t); Error(InsteadFound(t), &t); @@ -605,25 +605,25 @@ bool asCParser::ParseTemplTypeList(asCScriptNode *node, bool required) // At least one type // TODO: child funcdef: Make this work with !required node->AddChildLast(ParseType(true, false)); - if (isSyntaxError) return false; + if( isSyntaxError ) return false; GetToken(&t); // Parse template types by list separator - while (t.type == ttListSeparator) + while( t.type == ttListSeparator ) { // TODO: child funcdef: Make this work with !required node->AddChildLast(ParseType(true, false)); - if (isSyntaxError) return false; + if( isSyntaxError ) return false; GetToken(&t); } // End with '>' // Accept >> and >>> tokens too. But then force the tokenizer to move // only 1 character ahead (thus splitting the token in two). - if (script->code[t.pos] != '>') + if( script->code[t.pos] != '>' ) { - if (required) + if( required ) { Error(ExpectedToken(asCTokenizer::GetDefinition(ttGreaterThan)), &t); Error(InsteadFound(t), &t); @@ -637,10 +637,10 @@ bool asCParser::ParseTemplTypeList(asCScriptNode *node, bool required) SetPos(t.pos + 1); } - if (!required && !isValid) + if( !required && !isValid ) { // Restore the original state before returning - while (node->lastChild != last) + while( node->lastChild != last ) { asCScriptNode *n = node->lastChild; n->DisconnectParent(); @@ -791,7 +791,7 @@ asCScriptNode *asCParser::ParseParameterList() sToken t1; GetToken(&t1); - if( t1.type != ttOpenParenthesis) + if( t1.type != ttOpenParenthesis ) { Error(ExpectedToken("("), &t1); Error(InsteadFound(t1), &t1); @@ -815,7 +815,7 @@ asCScriptNode *asCParser::ParseParameterList() { sToken t2; GetToken(&t2); - if( t2.type == ttCloseParenthesis) + if( t2.type == ttCloseParenthesis ) { node->UpdateSourcePos(t2.pos, t2.length); return node; @@ -824,7 +824,7 @@ asCScriptNode *asCParser::ParseParameterList() RewindTo(&t1); - for(;;) + for( ;; ) { // Parse data type node->AddChildLast(ParseType(true, isParsingAppInterface)); @@ -836,15 +836,15 @@ asCScriptNode *asCParser::ParseParameterList() GetToken(&t1); // Variadic - if (t1.type == ttVariadic) + if( t1.type == ttVariadic ) { node->AddChildLast(CreateNode(snVariadic)); - + sToken t2; GetToken(&t2); // Variadic must be the last argument - if (t2.type == ttCloseParenthesis) + if( t2.type == ttCloseParenthesis ) { node->UpdateSourcePos(t2.pos, t2.length); @@ -883,7 +883,7 @@ asCScriptNode *asCParser::ParseParameterList() } // Check if list continues - if( t1.type == ttCloseParenthesis) + if( t1.type == ttCloseParenthesis ) { node->UpdateSourcePos(t1.pos, t1.length); @@ -915,14 +915,14 @@ asCScriptNode *asCParser::SuperficiallyParseExpression() RewindTo(&start); asCString stack; - sToken t; - for(;;) + sToken t; + for( ;; ) { GetToken(&t); - if( t.type == ttOpenParenthesis) + if( t.type == ttOpenParenthesis ) stack += "("; - else if( t.type == ttCloseParenthesis) + else if( t.type == ttCloseParenthesis ) { if( stack == "" ) { @@ -930,10 +930,10 @@ asCScriptNode *asCParser::SuperficiallyParseExpression() RewindTo(&t); break; } - else if( stack[stack.GetLength()-1] == '(' ) + else if( stack[stack.GetLength() - 1] == '(' ) { // Group has ended - stack.SetLength(stack.GetLength()-1); + stack.SetLength(stack.GetLength() - 1); } else { @@ -958,7 +958,7 @@ asCScriptNode *asCParser::SuperficiallyParseExpression() stack += "{"; else if( t.type == ttEndStatementBlock ) { - if( stack == "" || stack[stack.GetLength()-1] != '{' ) + if( stack == "" || stack[stack.GetLength() - 1] != '{' ) { // Wrong syntax RewindTo(&t); @@ -970,7 +970,7 @@ asCScriptNode *asCParser::SuperficiallyParseExpression() else { // Group has ended - stack.SetLength(stack.GetLength()-1); + stack.SetLength(stack.GetLength() - 1); } } else if( t.type == ttEndStatement ) @@ -1011,12 +1011,12 @@ void asCParser::GetToken(sToken *token) // Check if the token has already been parsed if( lastToken.pos == sourcePos ) { - *token = lastToken; + *token = lastToken; sourcePos += token->length; if( token->type == ttWhiteSpace || - token->type == ttOnelineComment || - token->type == ttMultilineComment ) + token->type == ttOnelineComment || + token->type == ttMultilineComment ) GetToken(token); return; @@ -1028,7 +1028,7 @@ void asCParser::GetToken(sToken *token) { if( sourcePos >= sourceLength ) { - token->type = ttEnd; + token->type = ttEnd; token->length = 0; } else @@ -1041,14 +1041,14 @@ void asCParser::GetToken(sToken *token) } // Filter out whitespace and comments while( token->type == ttWhiteSpace || - token->type == ttOnelineComment || - token->type == ttMultilineComment ); + token->type == ttOnelineComment || + token->type == ttMultilineComment ); } void asCParser::SetPos(size_t pos) { lastToken.pos = size_t(-1); - sourcePos = pos; + sourcePos = pos; } void asCParser::RewindTo(const sToken *token) @@ -1104,17 +1104,17 @@ void asCParser::Info(const asCString &text, sToken *token) bool asCParser::IsRealType(int tokenType) { if( tokenType == ttVoid || - tokenType == ttInt || - tokenType == ttInt8 || - tokenType == ttInt16 || - tokenType == ttInt64 || - tokenType == ttUInt || - tokenType == ttUInt8 || - tokenType == ttUInt16 || - tokenType == ttUInt64 || - tokenType == ttFloat || - tokenType == ttBool || - tokenType == ttDouble ) + tokenType == ttInt || + tokenType == ttInt8 || + tokenType == ttInt16 || + tokenType == ttInt64 || + tokenType == ttUInt || + tokenType == ttUInt8 || + tokenType == ttUInt16 || + tokenType == ttUInt64 || + tokenType == ttFloat || + tokenType == ttBool || + tokenType == ttDouble ) return true; return false; @@ -1168,7 +1168,7 @@ asCString asCParser::ExpectedOneOf(int *tokens, int count) for( int n = 0; n < count; n++ ) { str += asCTokenizer::GetDefinition(tokens[n]); - if( n < count-1 ) + if( n < count - 1 ) str += ", "; } @@ -1183,7 +1183,7 @@ asCString asCParser::ExpectedOneOf(const char **tokens, int count) for( int n = 0; n < count; n++ ) { str += tokens[n]; - if( n < count-1 ) + if( n < count - 1 ) str += ", "; } @@ -1226,7 +1226,7 @@ asCScriptNode *asCParser::ParseListPattern() sToken start = t1; bool isBeginning = true; - bool afterType = false; + bool afterType = false; while( !isSyntaxError ) { GetToken(&t1); @@ -1243,7 +1243,7 @@ asCScriptNode *asCParser::ParseListPattern() { if( afterType ) { - Error(ExpectedTokens(",","}"), &t1); + Error(ExpectedTokens(",", "}"), &t1); Error(InsteadFound(t1), &t1); } RewindTo(&t1); @@ -1310,16 +1310,16 @@ void asCParser::ParseMethodAttributes(asCScriptNode *funcNode) { sToken t1; - for(;;) + for( ;; ) { GetToken(&t1); RewindTo(&t1); - if( IdentifierIs(t1, FINAL_TOKEN) || - IdentifierIs(t1, OVERRIDE_TOKEN) || - IdentifierIs(t1, EXPLICIT_TOKEN) || - IdentifierIs(t1, PROPERTY_TOKEN) || - IdentifierIs(t1, DELETE_TOKEN) ) + if( IdentifierIs(t1, FINAL_TOKEN) || + IdentifierIs(t1, OVERRIDE_TOKEN) || + IdentifierIs(t1, EXPLICIT_TOKEN) || + IdentifierIs(t1, PROPERTY_TOKEN) || + IdentifierIs(t1, DELETE_TOKEN) ) funcNode->AddChildLast(ParseIdentifier()); else break; @@ -1339,35 +1339,35 @@ bool asCParser::FindTokenAfterType(sToken &nextToken) // A type can start with a const t1 = t; - if (t1.type == ttConst) + if( t1.type == ttConst ) GetToken(&t1); sToken t2; - if (t1.type != ttAuto) + if( t1.type != ttAuto ) { // The type may be initiated with the scope operator - if (t1.type == ttScope) + if( t1.type == ttScope ) GetToken(&t1); // The type may be preceded with a multilevel scope GetToken(&t2); - while (t1.type == ttIdentifier) + while( t1.type == ttIdentifier ) { - if (t2.type == ttScope) + if( t2.type == ttScope ) { GetToken(&t1); GetToken(&t2); continue; } - else if (t2.type == ttLessThan) + else if( t2.type == ttLessThan ) { // Template types can also be used as scope identifiers RewindTo(&t2); - if (CheckTemplateType(t1)) + if( CheckTemplateType(t1) ) { sToken t3; GetToken(&t3); - if (t3.type == ttScope) + if( t3.type == ttScope ) { GetToken(&t1); GetToken(&t2); @@ -1385,13 +1385,13 @@ bool asCParser::FindTokenAfterType(sToken &nextToken) // as it may wrongly identify the statement as a non-declaration if the user typed // the name incorrectly. The real type is validated in ParseDeclaration where a // proper error message can be given. - if (!IsRealType(t1.type) && t1.type != ttIdentifier && t1.type != ttAuto) + if( !IsRealType(t1.type) && t1.type != ttIdentifier && t1.type != ttAuto ) { RewindTo(&t); return false; } - if (!CheckTemplateType(t1)) + if( !CheckTemplateType(t1) ) { RewindTo(&t); return false; @@ -1401,31 +1401,31 @@ bool asCParser::FindTokenAfterType(sToken &nextToken) // Even though declaring variables with & is invalid we'll accept // it here to give an appropriate error message later GetToken(&t2); - while (t2.type == ttHandle || t2.type == ttAmp || t2.type == ttOpenBracket) + while( t2.type == ttHandle || t2.type == ttAmp || t2.type == ttOpenBracket ) { if( t2.type == ttHandle ) { // A handle can optionally be read-only sToken t3; GetToken(&t3); - if(t3.type != ttConst ) + if( t3.type != ttConst ) RewindTo(&t3); } - else if (t2.type == ttOpenBracket) + else if( t2.type == ttOpenBracket ) { GetToken(&t2); - if (t2.type != ttCloseBracket) + if( t2.type != ttCloseBracket ) { RewindTo(&t); return false; } } - else if (t2.type == ttAmp) + else if( t2.type == ttAmp ) { // & can be followed by in, out, or inout sToken t3; GetToken(&t3); - if (t3.type != ttIn && t3.type != ttOut && t3.type != ttInOut) + if( t3.type != ttIn && t3.type != ttOut && t3.type != ttInOut ) RewindTo(&t3); } @@ -1449,27 +1449,27 @@ bool asCParser::IsTemplateTypeList(sToken start, sToken *after) GetToken(&restore); RewindTo(&start); - bool isTemplateTypeList = true; + bool isTemplateTypeList = true; sToken t1; GetToken(&t1); - if (t1.type != ttLessThan) + if( t1.type != ttLessThan ) isTemplateTypeList = false; - for (; isTemplateTypeList;) + for( ; isTemplateTypeList; ) { // There might optionally be a 'const' GetToken(&t1); - if (t1.type == ttConst) + if( t1.type == ttConst ) GetToken(&t1); // The type may be initiated with the scope operator - if (t1.type == ttScope) + if( t1.type == ttScope ) GetToken(&t1); // There may be multiple levels of scope operators sToken t2; GetToken(&t2); - while (t1.type == ttIdentifier && t2.type == ttScope) + while( t1.type == ttIdentifier && t2.type == ttScope ) { GetToken(&t1); GetToken(&t2); @@ -1477,28 +1477,28 @@ bool asCParser::IsTemplateTypeList(sToken start, sToken *after) RewindTo(&t2); // Now there must be a data type - if (!IsDataType(t1)) + if( !IsDataType(t1) ) isTemplateTypeList = false; - if (!CheckTemplateType(t1)) + if( !CheckTemplateType(t1) ) isTemplateTypeList = false; GetToken(&t1); // Is it a handle or array? - while (t1.type == ttHandle || t1.type == ttOpenBracket) + while( t1.type == ttHandle || t1.type == ttOpenBracket ) { - if (t1.type == ttOpenBracket) + if( t1.type == ttOpenBracket ) { GetToken(&t1); - if (t1.type != ttCloseBracket) + if( t1.type != ttCloseBracket ) isTemplateTypeList = false; } - else if (t1.type == ttHandle) + else if( t1.type == ttHandle ) { // after @ there can be a const GetToken(&t1); - if (t1.type != ttConst) + if( t1.type != ttConst ) RewindTo(&t1); } @@ -1506,24 +1506,24 @@ bool asCParser::IsTemplateTypeList(sToken start, sToken *after) } // Was this the last template subtype? - if (t1.type != ttListSeparator) + if( t1.type != ttListSeparator ) break; } // Accept >> and >>> tokens too. But then force the tokenizer to move // only 1 character ahead (thus splitting the token in two). - if (script->code[t1.pos] != '>') + if( script->code[t1.pos] != '>' ) isTemplateTypeList = false; - if (after) + if( after ) { // Set the after position to after the first > - if (t1.length > 1) + if( t1.length > 1 ) SetPos(t1.pos + 1); GetToken(after); - if (!isTemplateTypeList) + if( !isTemplateTypeList ) *after = start; } @@ -1542,14 +1542,14 @@ bool asCParser::CheckTemplateType(const sToken &t) { sToken t1; GetToken(&t1); - if (t1.type != ttLessThan) + if( t1.type != ttLessThan ) { RewindTo(&t1); return true; } sToken after; - if (IsTemplateTypeList(t1, &after)) + if( IsTemplateTypeList(t1, &after) ) { RewindTo(&after); return true; @@ -1597,7 +1597,7 @@ asCScriptNode *asCParser::ParseCast() } GetToken(&t1); - if( t1.type != ttOpenParenthesis) + if( t1.type != ttOpenParenthesis ) { Error(ExpectedToken("("), &t1); Error(InsteadFound(t1), &t1); @@ -1608,7 +1608,7 @@ asCScriptNode *asCParser::ParseCast() if( isSyntaxError ) return node; GetToken(&t1); - if( t1.type != ttCloseParenthesis) + if( t1.type != ttCloseParenthesis ) { Error(ExpectedToken(")"), &t1); Error(InsteadFound(t1), &t1); @@ -1651,12 +1651,12 @@ asCScriptNode *asCParser::ParseExprValue() // Get The token after the identifier to determine if it is an [ sToken t; - GetToken(&t); + GetToken(&t); GetToken(&t); - bool isDataType = IsDataType(t2); + bool isDataType = IsDataType(t2); bool isTemplateType = false; - bool isTemplateFn = false; + bool isTemplateFn = false; if( isDataType ) { // Is this a template type? @@ -1664,7 +1664,7 @@ asCScriptNode *asCParser::ParseExprValue() if( engine->IsTemplateType(tempString.AddressOf()) ) isTemplateType = true; } - else + else { tempString.Assign(&script->code[t2.pos], t2.length); if( engine->IsTemplateFn(tempString.AddressOf()) ) @@ -1678,9 +1678,9 @@ asCScriptNode *asCParser::ParseExprValue() // Check if this is a construct call // Just 'type()' isn't considered a construct call, because type may just be a function/method name. // The compiler will have to sort this out, since the parser doesn't have enough information. - if( isDataType && (t.type == ttOpenBracket && t2.type == ttCloseBracket) ) // type[]() + if( isDataType && (t.type == ttOpenBracket && t2.type == ttCloseBracket) ) // type[]() node->AddChildLast(ParseConstructCall()); - else if( isTemplateType && t.type == ttLessThan ) // type() + else if( isTemplateType && t.type == ttLessThan ) // type() node->AddChildLast(ParseConstructCall()); else if( IsFunctionCall(isTemplateFn) ) node->AddChildLast(ParseFunctionCall()); @@ -1692,7 +1692,7 @@ asCScriptNode *asCParser::ParseExprValue() node->AddChildLast(ParseCast()); else if( IsConstant(t1.type) ) node->AddChildLast(ParseConstant()); - else if( t1.type == ttOpenParenthesis) + else if( t1.type == ttOpenParenthesis ) { GetToken(&t1); node->UpdateSourcePos(t1.pos, t1.length); @@ -1701,7 +1701,7 @@ asCScriptNode *asCParser::ParseExprValue() if( isSyntaxError ) return node; GetToken(&t1); - if( t1.type != ttCloseParenthesis) + if( t1.type != ttCloseParenthesis ) { Error(ExpectedToken(")"), &t1); Error(InsteadFound(t1), &t1); @@ -1759,14 +1759,14 @@ asCScriptNode *asCParser::ParseConstant() bool asCParser::IsLambda() { - bool isLambda = false; + bool isLambda = false; sToken t; GetToken(&t); if( t.type == ttIdentifier && IdentifierIs(t, FUNCTION_TOKEN) ) { sToken t2; GetToken(&t2); - if( t2.type == ttOpenParenthesis) + if( t2.type == ttOpenParenthesis ) { // Skip until ) while( t2.type != ttCloseParenthesis && t2.type != ttEnd ) @@ -1786,7 +1786,7 @@ bool asCParser::IsLambda() // Finds the last identifier in a multiscope sequence. // Doesn't move the cursor. // Returns false if the sequence is not a scope, nor a identifier without scope. -bool asCParser::FindIdentifierAfterScope(sToken& identifierToken) +bool asCParser::FindIdentifierAfterScope(sToken &identifierToken) { sToken t1, t2, t3; @@ -1795,9 +1795,9 @@ bool asCParser::FindIdentifierAfterScope(sToken& identifierToken) GetToken(&t2); RewindTo(&t1); - if (t1.type != ttScope && t2.type != ttScope) + if( t1.type != ttScope && t2.type != ttScope ) { - if (t1.type == ttIdentifier) + if( t1.type == ttIdentifier ) { identifierToken = t1; return true; @@ -1805,14 +1805,15 @@ bool asCParser::FindIdentifierAfterScope(sToken& identifierToken) return false; } - if (t1.type == ttScope) t3 = t2; else t3 = t1; + if( t1.type == ttScope ) t3 = t2; + else t3 = t1; RewindTo(&t3); GetToken(&t2); - while (t3.type == ttIdentifier) + while( t3.type == ttIdentifier ) { t2 = t3; GetToken(&t3); - if (t3.type == ttScope) + if( t3.type == ttScope ) GetToken(&t3); else break; @@ -1839,25 +1840,25 @@ asCScriptNode *asCParser::ParseLambda() } GetToken(&t); - if( t.type != ttOpenParenthesis) + if( t.type != ttOpenParenthesis ) { Error(ExpectedToken("("), &t); return node; } GetToken(&t); - while (t.type != ttCloseParenthesis && t.type != ttEnd ) + while( t.type != ttCloseParenthesis && t.type != ttEnd ) { RewindTo(&t); // Create node to represent the parameter, the datatype and identifier must be children of the node. // If no datatype or identifier is given then the node is still there to be counted as the arg - asCScriptNode* param = CreateNode(snUndefined); + asCScriptNode *param = CreateNode(snUndefined); node->AddChildLast(param); // Skip 'const' for the next check sToken t1, t2 = t; - if (t.type == ttConst) + if( t.type == ttConst ) GetToken(&t1); // Determine the last identifier after scope in order to check if it is a type @@ -1865,33 +1866,33 @@ asCScriptNode *asCParser::ParseLambda() RewindTo(&t); // Parse optional type before parameter name - if (IsDataType(t2) && CheckTemplateType(t2) && FindTokenAfterType(t) && (t.type == ttIdentifier || t.type == ttListSeparator || t.type == ttCloseParenthesis)) + if( IsDataType(t2) && CheckTemplateType(t2) && FindTokenAfterType(t) && (t.type == ttIdentifier || t.type == ttListSeparator || t.type == ttCloseParenthesis) ) { param->AddChildLast(ParseType(true)); - if (isSyntaxError) return node; + if( isSyntaxError ) return node; param->AddChildLast(ParseTypeMod(true)); - if (isSyntaxError) return node; + if( isSyntaxError ) return node; } // Parse optional parameter name - if (t.type == ttIdentifier) + if( t.type == ttIdentifier ) { param->AddChildLast(ParseIdentifier()); - if (isSyntaxError) return node; + if( isSyntaxError ) return node; } GetToken(&t); - if (t.type == ttListSeparator) + if( t.type == ttListSeparator ) GetToken(&t); - else if (t.type != ttCloseParenthesis) + else if( t.type != ttCloseParenthesis ) { - const char *tokens[] = { ",", ")" }; + const char *tokens[] = {",", ")"}; Error(ExpectedOneOf(tokens, 2), &t); return node; } } - if( t.type != ttCloseParenthesis) + if( t.type != ttCloseParenthesis ) { Error(ExpectedToken(")"), &t); return node; @@ -1984,7 +1985,7 @@ asCScriptNode *asCParser::ParseArgList(bool withParenthesis) if( withParenthesis ) { GetToken(&t1); - if( t1.type != ttOpenParenthesis) + if( t1.type != ttOpenParenthesis ) { Error(ExpectedToken("("), &t1); Error(InsteadFound(t1), &t1); @@ -1999,7 +2000,7 @@ asCScriptNode *asCParser::ParseArgList(bool withParenthesis) { if( withParenthesis ) { - if( t1.type == ttCloseParenthesis) + if( t1.type == ttCloseParenthesis ) node->UpdateSourcePos(t1.pos, t1.length); else { @@ -2019,7 +2020,7 @@ asCScriptNode *asCParser::ParseArgList(bool withParenthesis) { RewindTo(&t1); - for(;;) + for( ;; ) { // Determine if this is a named argument sToken tl, t2; @@ -2059,7 +2060,7 @@ asCScriptNode *asCParser::ParseArgList(bool withParenthesis) { if( withParenthesis ) { - if( t1.type == ttCloseParenthesis) + if( t1.type == ttCloseParenthesis ) node->UpdateSourcePos(t1.pos, t1.length); else { @@ -2105,12 +2106,12 @@ bool asCParser::IsFunctionCall(bool isTemplate) RewindTo(&s); return false; } - if( isTemplate && t2.type == ttLessThan) + if( isTemplate && t2.type == ttLessThan ) { RewindTo(&s); return true; } - if( t2.type == ttOpenParenthesis) + if( t2.type == ttOpenParenthesis ) { RewindTo(&s); return true; @@ -2187,7 +2188,7 @@ asCScriptNode *asCParser::ParseExpression() node->AddChildLast(ParseExprTerm()); if( isSyntaxError ) return node; - for(;;) + for( ;; ) { sToken t; GetToken(&t); @@ -2216,7 +2217,7 @@ asCScriptNode *asCParser::ParseExprTerm() GetToken(&t); sToken t2 = t, t3; RewindTo(&t); - if (IsDataType(t2) && CheckTemplateType(t2) && FindTokenAfterType(t2)) + if( IsDataType(t2) && CheckTemplateType(t2) && FindTokenAfterType(t2) ) { // Move to token after the type RewindTo(&t2); @@ -2224,7 +2225,7 @@ asCScriptNode *asCParser::ParseExprTerm() // The next token must be a = followed by a { GetToken(&t2); GetToken(&t3); - if (t2.type == ttAssignment && t3.type == ttStartStatementBlock) + if( t2.type == ttAssignment && t3.type == ttStartStatementBlock ) { // It is an initialization, now parse it for real RewindTo(&t); @@ -2245,7 +2246,7 @@ asCScriptNode *asCParser::ParseExprTerm() // It wasn't an initialization, so it must be an ordinary expression term RewindTo(&t); - for(;;) + for( ;; ) { GetToken(&t); RewindTo(&t); @@ -2260,7 +2261,7 @@ asCScriptNode *asCParser::ParseExprTerm() if( isSyntaxError ) return node; - for(;;) + for( ;; ) { GetToken(&t); RewindTo(&t); @@ -2318,7 +2319,7 @@ asCScriptNode *asCParser::ParseExprPostOp() GetToken(&t1); GetToken(&t2); RewindTo(&t1); - if (t2.type == ttOpenParenthesis || IsTemplateTypeList(t2)) + if( t2.type == ttOpenParenthesis || IsTemplateTypeList(t2) ) node->AddChildLast(ParseFunctionCall()); else node->AddChildLast(ParseIdentifier()); @@ -2337,7 +2338,7 @@ asCScriptNode *asCParser::ParseExprPostOp() node->UpdateSourcePos(t.pos, t.length); } - else if( t.type == ttOpenParenthesis) + else if( t.type == ttOpenParenthesis ) { RewindTo(&t); node->AddChildLast(ParseArgList()); @@ -2395,28 +2396,28 @@ asCScriptNode *asCParser::ParseAssignOperator() bool asCParser::IsOperator(int tokenType) { if( tokenType == ttPlus || - tokenType == ttMinus || - tokenType == ttStar || - tokenType == ttSlash || - tokenType == ttPercent || - tokenType == ttStarStar || - tokenType == ttAnd || - tokenType == ttOr || - tokenType == ttXor || - tokenType == ttEqual || - tokenType == ttNotEqual || - tokenType == ttLessThan || - tokenType == ttLessThanOrEqual || - tokenType == ttGreaterThan || - tokenType == ttGreaterThanOrEqual || - tokenType == ttAmp || - tokenType == ttBitOr || - tokenType == ttBitXor || - tokenType == ttBitShiftLeft || - tokenType == ttBitShiftRight || - tokenType == ttBitShiftRightArith || - tokenType == ttIs || - tokenType == ttNotIs ) + tokenType == ttMinus || + tokenType == ttStar || + tokenType == ttSlash || + tokenType == ttPercent || + tokenType == ttStarStar || + tokenType == ttAnd || + tokenType == ttOr || + tokenType == ttXor || + tokenType == ttEqual || + tokenType == ttNotEqual || + tokenType == ttLessThan || + tokenType == ttLessThanOrEqual || + tokenType == ttGreaterThan || + tokenType == ttGreaterThanOrEqual || + tokenType == ttAmp || + tokenType == ttBitOr || + tokenType == ttBitXor || + tokenType == ttBitShiftLeft || + tokenType == ttBitShiftRight || + tokenType == ttBitShiftRightArith || + tokenType == ttIs || + tokenType == ttNotIs ) return true; return false; @@ -2425,18 +2426,18 @@ bool asCParser::IsOperator(int tokenType) bool asCParser::IsAssignOperator(int tokenType) { if( tokenType == ttAssignment || - tokenType == ttAddAssign || - tokenType == ttSubAssign || - tokenType == ttMulAssign || - tokenType == ttDivAssign || - tokenType == ttModAssign || - tokenType == ttPowAssign || - tokenType == ttAndAssign || - tokenType == ttOrAssign || - tokenType == ttXorAssign || - tokenType == ttShiftLeftAssign || - tokenType == ttShiftRightLAssign || - tokenType == ttShiftRightAAssign ) + tokenType == ttAddAssign || + tokenType == ttSubAssign || + tokenType == ttMulAssign || + tokenType == ttDivAssign || + tokenType == ttModAssign || + tokenType == ttPowAssign || + tokenType == ttAndAssign || + tokenType == ttOrAssign || + tokenType == ttXorAssign || + tokenType == ttShiftLeftAssign || + tokenType == ttShiftRightLAssign || + tokenType == ttShiftRightAAssign ) return true; return false; @@ -2445,12 +2446,12 @@ bool asCParser::IsAssignOperator(int tokenType) bool asCParser::IsPreOperator(int tokenType) { if( tokenType == ttMinus || - tokenType == ttPlus || - tokenType == ttNot || - tokenType == ttInc || - tokenType == ttDec || - tokenType == ttBitNot || - tokenType == ttHandle ) + tokenType == ttPlus || + tokenType == ttNot || + tokenType == ttInc || + tokenType == ttDec || + tokenType == ttBitNot || + tokenType == ttHandle ) return true; return false; } @@ -2458,10 +2459,10 @@ bool asCParser::IsPreOperator(int tokenType) bool asCParser::IsPostOperator(int tokenType) { if( tokenType == ttInc || // post increment - tokenType == ttDec || // post decrement - tokenType == ttDot || // member access - tokenType == ttOpenBracket || // index operator - tokenType == ttOpenParenthesis) // argument list for call on function pointer + tokenType == ttDec || // post decrement + tokenType == ttDot || // member access + tokenType == ttOpenBracket || // index operator + tokenType == ttOpenParenthesis ) // argument list for call on function pointer return true; return false; } @@ -2469,15 +2470,15 @@ bool asCParser::IsPostOperator(int tokenType) bool asCParser::IsConstant(int tokenType) { if( tokenType == ttIntConstant || - tokenType == ttFloatConstant || - tokenType == ttDoubleConstant || - tokenType == ttStringConstant || - tokenType == ttMultilineStringConstant || - tokenType == ttHeredocStringConstant || - tokenType == ttTrue || - tokenType == ttFalse || - tokenType == ttBitsConstant || - tokenType == ttNull ) + tokenType == ttFloatConstant || + tokenType == ttDoubleConstant || + tokenType == ttStringConstant || + tokenType == ttMultilineStringConstant || + tokenType == ttHeredocStringConstant || + tokenType == ttTrue || + tokenType == ttFalse || + tokenType == ttBitsConstant || + tokenType == ttNull ) return true; return false; @@ -2497,7 +2498,7 @@ int asCParser::ParseScript(asCScriptCode *in_script) // TODO: Should allow application to request this warning to be generated. // It should be off by default, since pre-processor may remove all // code from a section while still being meant as valid code -/* + /* // Warn in case there isn't anything in the script if( scriptNode->firstChild == 0 ) { @@ -2598,7 +2599,7 @@ asCScriptNode *asCParser::ParseScript(bool inBlock) if( node == 0 ) return 0; // Determine type of node - for(;;) + for( ;; ) { while( !isSyntaxError ) { @@ -2607,19 +2608,19 @@ asCScriptNode *asCParser::ParseScript(bool inBlock) // Optimize by skipping tokens 'shared', 'external', 'final', 'abstract' so they don't have to be checked in every condition sToken t1 = tStart; - while (IdentifierIs(t1, SHARED_TOKEN) || - IdentifierIs(t1, EXTERNAL_TOKEN) || - IdentifierIs(t1, FINAL_TOKEN) || - IdentifierIs(t1, ABSTRACT_TOKEN)) + while( IdentifierIs(t1, SHARED_TOKEN) || + IdentifierIs(t1, EXTERNAL_TOKEN) || + IdentifierIs(t1, FINAL_TOKEN) || + IdentifierIs(t1, ABSTRACT_TOKEN) ) GetToken(&t1); RewindTo(&tStart); if( t1.type == ttImport ) node->AddChildLast(ParseImport()); else if( t1.type == ttEnum ) - node->AddChildLast(ParseEnumeration()); // Handle enumerations + node->AddChildLast(ParseEnumeration()); // Handle enumerations else if( t1.type == ttTypedef ) - node->AddChildLast(ParseTypedef()); // Handle primitive typedefs + node->AddChildLast(ParseTypedef()); // Handle primitive typedefs else if( t1.type == ttClass ) node->AddChildLast(ParseClass()); else if( t1.type == ttMixin ) @@ -2652,7 +2653,7 @@ asCScriptNode *asCParser::ParseScript(bool inBlock) return node; else { - asCString str; + asCString str; const char *t = asCTokenizer::GetDefinition(t1.type); if( t == 0 ) t = ""; @@ -2668,7 +2669,7 @@ asCScriptNode *asCParser::ParseScript(bool inBlock) sToken t1; GetToken(&t1); while( t1.type != ttEndStatement && t1.type != ttEnd && - t1.type != ttStartStatementBlock ) + t1.type != ttStartStatementBlock ) GetToken(&t1); if( t1.type == ttStartStatementBlock ) @@ -2711,11 +2712,11 @@ asCScriptNode *asCParser::ParseUsing() do { node->AddChildLast(ParseIdentifier()); - if (isSyntaxError) + if( isSyntaxError ) return node; GetToken(&t); - } while (t.type == ttScope); + } while( t.type == ttScope ); if( t.type != ttEndStatement ) { @@ -2749,27 +2750,27 @@ asCScriptNode *asCParser::ParseNamespace() asCScriptNode *lowestNode = node; GetToken(&t1); - while (t1.type == ttScope) + while( t1.type == ttScope ) { lowestNode->UpdateSourcePos(t1.pos, t1.length); asCScriptNode *scopeNode = CreateNode(snScript); - if (scopeNode == 0) + if( scopeNode == 0 ) return 0; lowestNode->AddChildLast(scopeNode); lowestNode = CreateNode(snNamespace); - if (lowestNode == 0) + if( lowestNode == 0 ) return 0; scopeNode->AddChildLast(lowestNode); lowestNode->AddChildLast(ParseIdentifier()); - if (isSyntaxError) + if( isSyntaxError ) return node; GetToken(&t1); } - + if( t1.type == ttStartStatementBlock ) node->UpdateSourcePos(t1.pos, t1.length); else @@ -2815,7 +2816,7 @@ int asCParser::ParseStatementBlock(asCScriptCode *in_script, asCScriptNode *in_b checkValidTypes = true; this->script = in_script; - sourcePos = in_block->tokenPos; + sourcePos = in_block->tokenPos; scriptNode = ParseStatementBlock(); @@ -2840,7 +2841,7 @@ asCScriptNode *asCParser::ParseEnumeration() // Optional 'shared' and 'external' token GetToken(&token); while( IdentifierIs(token, SHARED_TOKEN) || - IdentifierIs(token, EXTERNAL_TOKEN) ) + IdentifierIs(token, EXTERNAL_TOKEN) ) { RewindTo(&token); node->AddChildLast(ParseIdentifier()); @@ -2862,7 +2863,7 @@ asCScriptNode *asCParser::ParseEnumeration() // Get the identifier GetToken(&token); - if(ttIdentifier != token.type) + if( ttIdentifier != token.type ) { Error(TXT_EXPECTED_IDENTIFIER, &token); Error(InsteadFound(token), &token); @@ -2882,33 +2883,33 @@ asCScriptNode *asCParser::ParseEnumeration() dataType->AddChildLast(ident); GetToken(&token); - + // Check for underlying type - if (token.type == ttColon) + if( token.type == ttColon ) { GetToken(&token); - - if (!((token.type >= ttInt && token.type <= ttInt64) || - (token.type >= ttUInt && token.type <= ttUInt64))) + + if( !((token.type >= ttInt && token.type <= ttInt64) || + (token.type >= ttUInt && token.type <= ttUInt64)) ) { - int tokens[] = { ttInt, ttInt8, ttInt16, ttInt64, ttUInt, ttUInt8, ttUInt16, ttUInt64 }; + int tokens[] = {ttInt, ttInt8, ttInt16, ttInt64, ttUInt, ttUInt8, ttUInt16, ttUInt64}; Error(ExpectedOneOf(tokens, 2), &token); Error(InsteadFound(token), &token); return node; } - + ident = CreateNode(snDataType); - if (ident == 0) return node; - + if( ident == 0 ) return node; + ident->SetToken(&token); ident->UpdateSourcePos(token.pos, token.length); dataType->AddChildLast(ident); - + GetToken(&token); } - + // External shared declarations are ended with ';' - if (token.type == ttEndStatement) + if( token.type == ttEndStatement ) { RewindTo(&token); node->AddChildLast(ParseToken(ttEndStatement)); @@ -2919,13 +2920,13 @@ asCScriptNode *asCParser::ParseEnumeration() if( token.type != ttStartStatementBlock ) { RewindTo(&token); - int tokens[] = { ttStartStatementBlock, ttEndStatement }; + int tokens[] = {ttStartStatementBlock, ttEndStatement}; Error(ExpectedOneOf(tokens, 2), &token); Error(InsteadFound(token), &token); return node; } - while(ttEnd != token.type) + while( ttEnd != token.type ) { GetToken(&token); @@ -2935,7 +2936,7 @@ asCScriptNode *asCParser::ParseEnumeration() break; } - if(ttIdentifier != token.type) + if( ttIdentifier != token.type ) { Error(TXT_EXPECTED_IDENTIFIER, &token); Error(InsteadFound(token), &token); @@ -2954,7 +2955,7 @@ asCScriptNode *asCParser::ParseEnumeration() if( token.type == ttAssignment ) { - asCScriptNode *tmp; + asCScriptNode *tmp; RewindTo(&token); @@ -2965,7 +2966,7 @@ asCScriptNode *asCParser::ParseEnumeration() GetToken(&token); } - if(ttListSeparator != token.type) + if( ttListSeparator != token.type ) { RewindTo(&token); break; @@ -2999,7 +3000,7 @@ bool asCParser::IsVarDecl() RewindTo(&t1); // A variable decl starts with the type - if (!FindTokenAfterType(t1)) + if( !FindTokenAfterType(t1) ) { RewindTo(&t); return false; @@ -3008,7 +3009,7 @@ bool asCParser::IsVarDecl() // Jump to the token after the type RewindTo(&t1); GetToken(&t1); - + // The declaration needs to have a name if( t1.type != ttIdentifier ) { @@ -3023,18 +3024,18 @@ bool asCParser::IsVarDecl() RewindTo(&t); return true; } - if( t1.type == ttOpenParenthesis) + if( t1.type == ttOpenParenthesis ) { - // If the closing parenthesis is followed by a statement block, - // function decorator, or end-of-file, then treat it as a function. - // A function decl may have nested parenthesis so we need to check + // If the closing parenthesis is followed by a statement block, + // function decorator, or end-of-file, then treat it as a function. + // A function decl may have nested parenthesis so we need to check // for this too. int nest = 0; while( t1.type != ttEnd ) { - if( t1.type == ttOpenParenthesis) + if( t1.type == ttOpenParenthesis ) nest++; - else if( t1.type == ttCloseParenthesis) + else if( t1.type == ttCloseParenthesis ) { nest--; if( nest == 0 ) @@ -3043,7 +3044,7 @@ bool asCParser::IsVarDecl() GetToken(&t1); } - if (t1.type == ttEnd) + if( t1.type == ttEnd ) { RewindTo(&t); return false; @@ -3052,9 +3053,9 @@ bool asCParser::IsVarDecl() { GetToken(&t1); RewindTo(&t); - if( t1.type == ttStartStatementBlock || - t1.type == ttIdentifier || // function decorator - t1.type == ttEnd ) + if( t1.type == ttStartStatementBlock || + t1.type == ttIdentifier || // function decorator + t1.type == ttEnd ) return false; } @@ -3080,7 +3081,7 @@ bool asCParser::IsVirtualPropertyDecl() RewindTo(&t1); // A variable decl starts with the type - if (!FindTokenAfterType(t1)) + if( !FindTokenAfterType(t1) ) { RewindTo(&t); return false; @@ -3138,7 +3139,7 @@ bool asCParser::IsFuncDecl(bool isMethod) // A function decl starts with a type sToken t1; - if (!FindTokenAfterType(t1)) + if( !FindTokenAfterType(t1) ) { RewindTo(&t); return false; @@ -3162,7 +3163,7 @@ bool asCParser::IsFuncDecl(bool isMethod) } GetToken(&t1); - if( t1.type == ttOpenParenthesis) + if( t1.type == ttOpenParenthesis ) { // If the closing parenthesis is not followed by a // statement block then it is not a function. @@ -3172,9 +3173,9 @@ bool asCParser::IsFuncDecl(bool isMethod) GetToken(&t1); while( (nest || t1.type != ttCloseParenthesis) && t1.type != ttEnd ) { - if( t1.type == ttOpenParenthesis) + if( t1.type == ttOpenParenthesis ) nest++; - if( t1.type == ttCloseParenthesis) + if( t1.type == ttCloseParenthesis ) nest--; GetToken(&t1); @@ -3194,25 +3195,25 @@ bool asCParser::IsFuncDecl(bool isMethod) // A function may also have any number of additional attributes bool hasAttribs = false; - for( ; ; ) + for( ;; ) { GetToken(&t1); - if( !IdentifierIs(t1, FINAL_TOKEN) && - !IdentifierIs(t1, OVERRIDE_TOKEN) && - !IdentifierIs(t1, EXPLICIT_TOKEN) && - !IdentifierIs(t1, PROPERTY_TOKEN) && - !IdentifierIs(t1, DELETE_TOKEN) ) + if( !IdentifierIs(t1, FINAL_TOKEN) && + !IdentifierIs(t1, OVERRIDE_TOKEN) && + !IdentifierIs(t1, EXPLICIT_TOKEN) && + !IdentifierIs(t1, PROPERTY_TOKEN) && + !IdentifierIs(t1, DELETE_TOKEN) ) { RewindTo(&t1); break; } hasAttribs = true; } - + GetToken(&t1); RewindTo(&t); - // If the function has an attribute, e.g. delete, it can be terminated with a ; if no + // If the function has an attribute, e.g. delete, it can be terminated with a ; if no // implementation is expected otherwise it must have a statement block if( (t1.type == ttEndStatement && hasAttribs) || t1.type == ttStartStatementBlock ) return true; @@ -3235,12 +3236,12 @@ asCScriptNode *asCParser::ParseFuncDef() // Allow keywords 'external' and 'shared' before 'interface' sToken t1; GetToken(&t1); - while (IdentifierIs(t1, SHARED_TOKEN) || - IdentifierIs(t1, EXTERNAL_TOKEN)) + while( IdentifierIs(t1, SHARED_TOKEN) || + IdentifierIs(t1, EXTERNAL_TOKEN) ) { RewindTo(&t1); node->AddChildLast(ParseIdentifier()); - if (isSyntaxError) return node; + if( isSyntaxError ) return node; GetToken(&t1); } @@ -3287,17 +3288,17 @@ asCScriptNode *asCParser::ParseFunction(bool isMethod) // TODO: Why isn't ParseFunctionDefinition used? sToken t1; GetToken(&t1); - if (!isMethod) + if( !isMethod ) { // A global function can be marked as shared and external - while (t1.type == ttIdentifier) + while( t1.type == ttIdentifier ) { - if (IdentifierIs(t1, SHARED_TOKEN) || - IdentifierIs(t1, EXTERNAL_TOKEN)) + if( IdentifierIs(t1, SHARED_TOKEN) || + IdentifierIs(t1, EXTERNAL_TOKEN) ) { RewindTo(&t1); node->AddChildLast(ParseIdentifier()); - if (isSyntaxError) return node; + if( isSyntaxError ) return node; } else break; @@ -3307,13 +3308,13 @@ asCScriptNode *asCParser::ParseFunction(bool isMethod) } // A class method can start with 'private' or 'protected' - if (isMethod && t1.type == ttPrivate) + if( isMethod && t1.type == ttPrivate ) { RewindTo(&t1); node->AddChildLast(ParseToken(ttPrivate)); GetToken(&t1); } - else if (isMethod && t1.type == ttProtected) + else if( isMethod && t1.type == ttProtected ) { RewindTo(&t1); node->AddChildLast(ParseToken(ttProtected)); @@ -3364,7 +3365,7 @@ asCScriptNode *asCParser::ParseFunction(bool isMethod) // External shared functions must be ended with ';' GetToken(&t1); RewindTo(&t1); - if (t1.type == ttEndStatement) + if( t1.type == ttEndStatement ) { node->AddChildLast(ParseToken(ttEndStatement)); return node; @@ -3421,7 +3422,7 @@ asCScriptNode *asCParser::ParseVirtualPropertyDecl(bool isMethod, bool isInterfa asCScriptNode *node = CreateNode(snVirtualProperty); if( node == 0 ) return 0; - sToken t1,t2; + sToken t1, t2; GetToken(&t1); GetToken(&t2); RewindTo(&t1); @@ -3450,7 +3451,7 @@ asCScriptNode *asCParser::ParseVirtualPropertyDecl(bool isMethod, bool isInterfa return node; } - for(;;) + for( ;; ) { GetToken(&t1); asCScriptNode *accessorNode = 0; @@ -3488,11 +3489,11 @@ asCScriptNode *asCParser::ParseVirtualPropertyDecl(bool isMethod, bool isInterfa accessorNode->AddChildLast(SuperficiallyParseStatementBlock()); if( isSyntaxError ) return node; } - else if (t1.type == ttEndStatement) + else if( t1.type == ttEndStatement ) { RewindTo(&t1); accessorNode->AddChildLast(ParseToken(ttEndStatement)); - if (isSyntaxError) return node; + if( isSyntaxError ) return node; } else { @@ -3504,11 +3505,11 @@ asCScriptNode *asCParser::ParseVirtualPropertyDecl(bool isMethod, bool isInterfa else { GetToken(&t1); - if (t1.type == ttEndStatement) + if( t1.type == ttEndStatement ) { RewindTo(&t1); accessorNode->AddChildLast(ParseToken(ttEndStatement)); - if (isSyntaxError) return node; + if( isSyntaxError ) return node; } else { @@ -3522,7 +3523,7 @@ asCScriptNode *asCParser::ParseVirtualPropertyDecl(bool isMethod, bool isInterfa break; else { - const char *tokens[] = { GET_TOKEN, SET_TOKEN, asCTokenizer::GetDefinition(ttEndStatementBlock) }; + const char *tokens[] = {GET_TOKEN, SET_TOKEN, asCTokenizer::GetDefinition(ttEndStatementBlock)}; Error(ExpectedOneOf(tokens, 3), &t1); Error(InsteadFound(t1), &t1); return node; @@ -3543,11 +3544,11 @@ asCScriptNode *asCParser::ParseInterface() // Allow keywords 'external' and 'shared' before 'interface' GetToken(&t); while( IdentifierIs(t, SHARED_TOKEN) || - IdentifierIs(t, EXTERNAL_TOKEN) ) + IdentifierIs(t, EXTERNAL_TOKEN) ) { RewindTo(&t); node->AddChildLast(ParseIdentifier()); - if (isSyntaxError) return node; + if( isSyntaxError ) return node; GetToken(&t); } @@ -3564,7 +3565,7 @@ asCScriptNode *asCParser::ParseInterface() // External shared declarations are ended with ';' GetToken(&t); - if (t.type == ttEndStatement) + if( t.type == ttEndStatement ) { RewindTo(&t); node->AddChildLast(ParseToken(ttEndStatement)); @@ -3666,9 +3667,9 @@ asCScriptNode *asCParser::ParseClass() // Allow the keywords 'shared', 'abstract', 'final', and 'external' before 'class' while( IdentifierIs(t, SHARED_TOKEN) || - IdentifierIs(t, ABSTRACT_TOKEN) || - IdentifierIs(t, FINAL_TOKEN) || - IdentifierIs(t, EXTERNAL_TOKEN) ) + IdentifierIs(t, ABSTRACT_TOKEN) || + IdentifierIs(t, FINAL_TOKEN) || + IdentifierIs(t, EXTERNAL_TOKEN) ) { RewindTo(&t); node->AddChildLast(ParseIdentifier()); @@ -3689,7 +3690,7 @@ asCScriptNode *asCParser::ParseClass() // Parse 'implicit handle class' construct GetToken(&t); - if ( t.type == ttHandle ) + if( t.type == ttHandle ) node->SetToken(&t); else RewindTo(&t); @@ -3699,7 +3700,7 @@ asCScriptNode *asCParser::ParseClass() // External shared declarations are ended with ';' GetToken(&t); - if (t.type == ttEndStatement) + if( t.type == ttEndStatement ) { RewindTo(&t); node->AddChildLast(ParseToken(ttEndStatement)); @@ -3739,7 +3740,7 @@ asCScriptNode *asCParser::ParseClass() while( t.type != ttEndStatementBlock && t.type != ttEnd ) { // Is it a property or a method? - if (t.type == ttFuncDef) + if( t.type == ttFuncDef ) node->AddChildLast(ParseFuncDef()); else if( IsFuncDecl(true) ) node->AddChildLast(ParseFunction(true)); @@ -3784,7 +3785,7 @@ int asCParser::ParseVarInit(asCScriptCode *in_script, asCScriptNode *in_init) checkValidTypes = true; this->script = in_script; - sourcePos = in_init->tokenPos; + sourcePos = in_init->tokenPos; // If next token is assignment, parse expression sToken t; @@ -3798,14 +3799,14 @@ int asCParser::ParseVarInit(asCScriptCode *in_script, asCScriptNode *in_init) else scriptNode = ParseAssignment(); } - else if( t.type == ttOpenParenthesis) + else if( t.type == ttOpenParenthesis ) { RewindTo(&t); scriptNode = ParseArgList(); } else { - int tokens[] = {ttAssignment, ttOpenParenthesis }; + int tokens[] = {ttAssignment, ttOpenParenthesis}; Error(ExpectedOneOf(tokens, 2), &t); Error(InsteadFound(t), &t); } @@ -3845,15 +3846,15 @@ asCScriptNode *asCParser::SuperficiallyParseVarInit() while( indentParan || indentBrace || (t.type != ttListSeparator && t.type != ttEndStatement && t.type != ttEndStatementBlock) ) { sToken after; - if (t.type == ttOpenParenthesis) + if( t.type == ttOpenParenthesis ) indentParan++; - else if (t.type == ttCloseParenthesis) + else if( t.type == ttCloseParenthesis ) indentParan--; - else if (t.type == ttStartStatementBlock) + else if( t.type == ttStartStatementBlock ) indentBrace++; - else if (t.type == ttEndStatementBlock) + else if( t.type == ttEndStatementBlock ) indentBrace--; - else if (t.type == ttLessThan && IsTemplateTypeList(t, &after)) + else if( t.type == ttLessThan && IsTemplateTypeList(t, &after) ) RewindTo(&after); else if( t.type == ttNonTerminatedStringConstant ) { @@ -3872,7 +3873,7 @@ asCScriptNode *asCParser::SuperficiallyParseVarInit() // Rewind so that the next token read is the list separator, end statement, or end statement block RewindTo(&t); } - else if( t.type == ttOpenParenthesis) + else if( t.type == ttOpenParenthesis ) { sToken start = t; @@ -3881,9 +3882,9 @@ asCScriptNode *asCParser::SuperficiallyParseVarInit() while( indent ) { GetToken(&t); - if( t.type == ttOpenParenthesis) + if( t.type == ttOpenParenthesis ) indent++; - else if( t.type == ttCloseParenthesis) + else if( t.type == ttCloseParenthesis ) indent--; else if( t.type == ttNonTerminatedStringConstant ) { @@ -3900,7 +3901,7 @@ asCScriptNode *asCParser::SuperficiallyParseVarInit() } else { - int tokens[] = {ttAssignment, ttOpenParenthesis }; + int tokens[] = {ttAssignment, ttOpenParenthesis}; Error(ExpectedOneOf(tokens, 2), &t); Error(InsteadFound(t), &t); } @@ -3974,7 +3975,7 @@ asCScriptNode *asCParser::ParseStatementBlock() node->UpdateSourcePos(t1.pos, t1.length); - for(;;) + for( ;; ) { while( !isSyntaxError ) { @@ -4007,7 +4008,7 @@ asCScriptNode *asCParser::ParseStatementBlock() // Search for either ';', '{', '}', or end GetToken(&t1); while( t1.type != ttEndStatement && t1.type != ttEnd && - t1.type != ttStartStatementBlock && t1.type != ttEndStatementBlock ) + t1.type != ttStartStatementBlock && t1.type != ttEndStatementBlock ) { GetToken(&t1); } @@ -4071,7 +4072,7 @@ asCScriptNode *asCParser::ParseInitList() else { RewindTo(&t1); - for(;;) + for( ;; ) { GetToken(&t1); if( t1.type == ttListSeparator ) @@ -4173,7 +4174,7 @@ asCScriptNode *asCParser::ParseDeclaration(bool isClassProp, bool isGlobalVar) node->AddChildLast(ParseType(true, false, !isClassProp)); if( isSyntaxError ) return node; - for(;;) + for( ;; ) { // Parse identifier node->AddChildLast(ParseIdentifier()); @@ -4184,7 +4185,7 @@ asCScriptNode *asCParser::ParseDeclaration(bool isClassProp, bool isGlobalVar) // Only superficially parse the initialization info for the class property GetToken(&t); RewindTo(&t); - if( t.type == ttAssignment || t.type == ttOpenParenthesis) + if( t.type == ttAssignment || t.type == ttOpenParenthesis ) { node->AddChildLast(SuperficiallyParseVarInit()); if( isSyntaxError ) return node; @@ -4194,7 +4195,7 @@ asCScriptNode *asCParser::ParseDeclaration(bool isClassProp, bool isGlobalVar) { // If next token is assignment, parse expression GetToken(&t); - if( t.type == ttOpenParenthesis) + if( t.type == ttOpenParenthesis ) { RewindTo(&t); node->AddChildLast(ParseArgList()); @@ -4247,27 +4248,27 @@ asCScriptNode *asCParser::ParseStatement() GetToken(&t1); RewindTo(&t1); - if (t1.type == ttIf) + if( t1.type == ttIf ) return ParseIf(); - else if (t1.type == ttFor) + else if( t1.type == ttFor ) return ParseFor(); - else if (t1.type == ttForEach) + else if( t1.type == ttForEach ) return ParseForEach(); - else if (t1.type == ttWhile) + else if( t1.type == ttWhile ) return ParseWhile(); - else if (t1.type == ttReturn) + else if( t1.type == ttReturn ) return ParseReturn(); - else if (t1.type == ttStartStatementBlock) + else if( t1.type == ttStartStatementBlock ) return ParseStatementBlock(); - else if (t1.type == ttBreak) + else if( t1.type == ttBreak ) return ParseBreak(); - else if (t1.type == ttContinue) + else if( t1.type == ttContinue ) return ParseContinue(); - else if (t1.type == ttDo) + else if( t1.type == ttDo ) return ParseDoWhile(); - else if (t1.type == ttSwitch) + else if( t1.type == ttSwitch ) return ParseSwitch(); - else if (t1.type == ttTry) + else if( t1.type == ttTry ) return ParseTryCatch(); else { @@ -4331,7 +4332,7 @@ asCScriptNode *asCParser::ParseSwitch() node->UpdateSourcePos(t.pos, t.length); GetToken(&t); - if( t.type != ttOpenParenthesis) + if( t.type != ttOpenParenthesis ) { Error(ExpectedToken("("), &t); Error(InsteadFound(t), &t); @@ -4342,7 +4343,7 @@ asCScriptNode *asCParser::ParseSwitch() if( isSyntaxError ) return node; GetToken(&t); - if( t.type != ttCloseParenthesis) + if( t.type != ttCloseParenthesis ) { Error(ExpectedToken(")"), &t); Error(InsteadFound(t), &t); @@ -4405,7 +4406,7 @@ asCScriptNode *asCParser::ParseCase() node->UpdateSourcePos(t.pos, t.length); - if(t.type == ttCase) + if( t.type == ttCase ) { node->AddChildLast(ParseExpression()); } @@ -4422,9 +4423,9 @@ asCScriptNode *asCParser::ParseCase() GetToken(&t); RewindTo(&t); while( t.type != ttCase && - t.type != ttDefault && - t.type != ttEndStatementBlock && - t.type != ttBreak ) + t.type != ttDefault && + t.type != ttEndStatementBlock && + t.type != ttBreak ) { if( IsVarDecl() ) // Variable declarations are not allowed, but we parse it anyway to give a good error message @@ -4462,7 +4463,7 @@ asCScriptNode *asCParser::ParseIf() node->UpdateSourcePos(t.pos, t.length); GetToken(&t); - if( t.type != ttOpenParenthesis) + if( t.type != ttOpenParenthesis ) { Error(ExpectedToken("("), &t); Error(InsteadFound(t), &t); @@ -4473,7 +4474,7 @@ asCScriptNode *asCParser::ParseIf() if( isSyntaxError ) return node; GetToken(&t); - if( t.type != ttCloseParenthesis) + if( t.type != ttCloseParenthesis ) { Error(ExpectedToken(")"), &t); Error(InsteadFound(t), &t); @@ -4500,11 +4501,11 @@ asCScriptNode *asCParser::ParseIf() asCScriptNode *asCParser::ParseTryCatch() { asCScriptNode *node = CreateNode(snTryCatch); - if (node == 0) return 0; + if( node == 0 ) return 0; sToken t; GetToken(&t); - if (t.type != ttTry) + if( t.type != ttTry ) { Error(ExpectedToken("try"), &t); Error(InsteadFound(t), &t); @@ -4514,10 +4515,10 @@ asCScriptNode *asCParser::ParseTryCatch() node->UpdateSourcePos(t.pos, t.length); node->AddChildLast(ParseStatementBlock()); - if (isSyntaxError) return node; + if( isSyntaxError ) return node; GetToken(&t); - if (t.type != ttCatch) + if( t.type != ttCatch ) { Error(ExpectedToken("catch"), &t); Error(InsteadFound(t), &t); @@ -4525,7 +4526,7 @@ asCScriptNode *asCParser::ParseTryCatch() } node->AddChildLast(ParseStatementBlock()); - if (isSyntaxError) return node; + if( isSyntaxError ) return node; return node; } @@ -4548,7 +4549,7 @@ asCScriptNode *asCParser::ParseFor() node->UpdateSourcePos(t.pos, t.length); GetToken(&t); - if( t.type != ttOpenParenthesis) + if( t.type != ttOpenParenthesis ) { Error(ExpectedToken("("), &t); Error(InsteadFound(t), &t); @@ -4565,12 +4566,12 @@ asCScriptNode *asCParser::ParseFor() if( isSyntaxError ) return node; GetToken(&t); - if( t.type != ttCloseParenthesis) + if( t.type != ttCloseParenthesis ) { RewindTo(&t); // Parse N increment statements separated by , - for(;;) + for( ;; ) { asCScriptNode *n = CreateNode(snExpressionStatement); if( n == 0 ) return 0; @@ -4581,7 +4582,7 @@ asCScriptNode *asCParser::ParseFor() GetToken(&t); if( t.type == ttListSeparator ) continue; - else if( t.type == ttCloseParenthesis) + else if( t.type == ttCloseParenthesis ) break; else { @@ -4601,12 +4602,12 @@ asCScriptNode *asCParser::ParseFor() // BNF:8: FOREACH ::= 'foreach' '(' TYPE IDENTIFIER (',' TYPE INDENTIFIER)* ':' ASSIGN ')' STATEMENT asCScriptNode *asCParser::ParseForEach() { - asCScriptNode* node = CreateNode(snForEach); - if (node == 0) return 0; + asCScriptNode *node = CreateNode(snForEach); + if( node == 0 ) return 0; sToken t; GetToken(&t); - if (t.type != ttForEach) + if( t.type != ttForEach ) { Error(ExpectedToken("foreach"), &t); Error(InsteadFound(t), &t); @@ -4616,7 +4617,7 @@ asCScriptNode *asCParser::ParseForEach() node->UpdateSourcePos(t.pos, t.length); GetToken(&t); - if (t.type != ttOpenParenthesis) + if( t.type != ttOpenParenthesis ) { Error(ExpectedToken("("), &t); Error(InsteadFound(t), &t); @@ -4624,7 +4625,7 @@ asCScriptNode *asCParser::ParseForEach() } // Item(s) - for (;;) + for( ;; ) { // Item type node->AddChildLast(ParseType(true, false, true)); @@ -4633,15 +4634,15 @@ asCScriptNode *asCParser::ParseForEach() // Identifier of item node->AddChildLast(ParseIdentifier()); - + GetToken(&t); - if (t.type == ttListSeparator) + if( t.type == ttListSeparator ) { continue; } - else if (t.type != ttColon) + else if( t.type != ttColon ) { - const char* tokens[] = { ",", ":" }; + const char *tokens[] = {",", ":"}; Error(ExpectedOneOf(tokens, 2), &t); Error(InsteadFound(t), &t); return node; @@ -4654,7 +4655,7 @@ asCScriptNode *asCParser::ParseForEach() node->AddChildLast(ParseAssignment()); GetToken(&t); - if (t.type != ttCloseParenthesis) + if( t.type != ttCloseParenthesis ) { Error(ExpectedToken(")"), &t); Error(InsteadFound(t), &t); @@ -4684,7 +4685,7 @@ asCScriptNode *asCParser::ParseWhile() node->UpdateSourcePos(t.pos, t.length); GetToken(&t); - if( t.type != ttOpenParenthesis) + if( t.type != ttOpenParenthesis ) { Error(ExpectedToken("("), &t); Error(InsteadFound(t), &t); @@ -4695,7 +4696,7 @@ asCScriptNode *asCParser::ParseWhile() if( isSyntaxError ) return node; GetToken(&t); - if( t.type != ttCloseParenthesis) + if( t.type != ttCloseParenthesis ) { Error(ExpectedToken(")"), &t); Error(InsteadFound(t), &t); @@ -4736,7 +4737,7 @@ asCScriptNode *asCParser::ParseDoWhile() } GetToken(&t); - if( t.type != ttOpenParenthesis) + if( t.type != ttOpenParenthesis ) { Error(ExpectedToken("("), &t); Error(InsteadFound(t), &t); @@ -4747,7 +4748,7 @@ asCScriptNode *asCParser::ParseDoWhile() if( isSyntaxError ) return node; GetToken(&t); - if( t.type != ttCloseParenthesis) + if( t.type != ttCloseParenthesis ) { Error(ExpectedToken(")"), &t); Error(InsteadFound(t), &t); @@ -4874,10 +4875,10 @@ asCScriptNode *asCParser::ParseTypedef() asCScriptNode *node = CreateNode(snTypedef); if( node == 0 ) return 0; - sToken token; + sToken token; GetToken(&token); - if( token.type != ttTypedef) + if( token.type != ttTypedef ) { Error(ExpectedToken(asCTokenizer::GetDefinition(ttTypedef)), &token); Error(InsteadFound(token), &token); @@ -4918,5 +4919,3 @@ asCScriptNode *asCParser::ParseTypedef() #endif END_AS_NAMESPACE - - diff --git a/sdk/angelscript/source/as_parser.h b/sdk/angelscript/source/as_parser.h index 0e1571e9..a8049d5a 100644 --- a/sdk/angelscript/source/as_parser.h +++ b/sdk/angelscript/source/as_parser.h @@ -91,7 +91,7 @@ class asCParser asCScriptNode *ParseDataType(bool allowVariableType = false, bool allowAuto = false); asCScriptNode *ParseIdentifier(); bool ParseTemplTypeList(asCScriptNode *node, bool required = true); - bool ParseTemplateDeclTypeList(asCScriptNode* node, bool required); + bool ParseTemplateDeclTypeList(asCScriptNode *node, bool required); void ParseMethodAttributes(asCScriptNode *funcNode); asCScriptNode *ParseListPattern(); @@ -135,12 +135,12 @@ class asCParser asCScriptNode *ParseVirtualPropertyDecl(bool isMethod, bool isInterface); asCScriptNode *ParseEnumeration(); asCScriptNode *ParseTypedef(); - bool IsVarDecl(); - bool IsVirtualPropertyDecl(); - bool IsFuncDecl(bool isMethod); - bool IsLambda(); - bool IsFunctionCall(bool isTemplate); - bool IsTemplateTypeList(sToken startFrom, sToken *after = 0); + bool IsVarDecl(); + bool IsVirtualPropertyDecl(); + bool IsFuncDecl(bool isMethod); + bool IsLambda(); + bool IsFunctionCall(bool isTemplate); + bool IsTemplateTypeList(sToken startFrom, sToken *after = 0); // Expressions asCScriptNode *ParseAssignment(); @@ -162,7 +162,7 @@ class asCParser asCScriptNode *ParseLambda(); bool FindTokenAfterType(sToken &nextToken); - bool FindIdentifierAfterScope(sToken& nextToken); + bool FindIdentifierAfterScope(sToken &nextToken); bool IsConstant(int tokenType); bool IsOperator(int tokenType); bool IsPreOperator(int tokenType); @@ -193,8 +193,8 @@ class asCParser asCString tempString; // Used for reduzing amount of dynamic allocations - sToken lastToken; - size_t sourcePos; + sToken lastToken; + size_t sourcePos; }; END_AS_NAMESPACE diff --git a/sdk/angelscript/source/as_property.h b/sdk/angelscript/source/as_property.h index c318ec4a..7de757be 100644 --- a/sdk/angelscript/source/as_property.h +++ b/sdk/angelscript/source/as_property.h @@ -53,8 +53,12 @@ struct asSNameSpace; class asCObjectProperty { public: - asCObjectProperty() : byteOffset(0), accessMask(0xFFFFFFFF), compositeOffset(0), isCompositeIndirect(false), isPrivate(false), isProtected(false), isInherited(false) {} - asCObjectProperty(const asCObjectProperty &o) : name(o.name), type(o.type), byteOffset(o.byteOffset), accessMask(o.accessMask), compositeOffset(o.compositeOffset), isCompositeIndirect(o.isCompositeIndirect), isPrivate(o.isPrivate), isProtected(o.isProtected), isInherited(o.isInherited) {} + asCObjectProperty() : byteOffset(0), accessMask(0xFFFFFFFF), compositeOffset(0), isCompositeIndirect(false), isPrivate(false), isProtected(false), isInherited(false) + { + } + asCObjectProperty(const asCObjectProperty &o) : name(o.name), type(o.type), byteOffset(o.byteOffset), accessMask(o.accessMask), compositeOffset(o.compositeOffset), isCompositeIndirect(o.isCompositeIndirect), isPrivate(o.isPrivate), isProtected(o.isProtected), isInherited(o.isInherited) + { + } asCString name; asCDataType type; int byteOffset; @@ -81,21 +85,21 @@ class asCGlobalProperty void SetRegisteredAddress(void *p); void *GetRegisteredAddress() const; - asCString name; - asCDataType type; - asUINT id; - asSNameSpace *nameSpace; + asCString name; + asCDataType type; + asUINT id; + asSNameSpace *nameSpace; - void SetInitFunc(asCScriptFunction *initFunc); + void SetInitFunc(asCScriptFunction *initFunc); asCScriptFunction *GetInitFunc(); -//protected: + //protected: // This is only stored for registered properties, and keeps the pointer given by the application - void *realAddress; + void *realAddress; - bool memoryAllocated; - void *memory; - asQWORD storage; + bool memoryAllocated; + void *memory; + asQWORD storage; asCScriptFunction *initFunc; @@ -111,17 +115,22 @@ class asCCompGlobPropType : public asIFilter public: const asCDataType &m_type; - asCCompGlobPropType(const asCDataType &type) : m_type(type) {} + asCCompGlobPropType(const asCDataType &type) : m_type(type) + { + } bool operator()(const void *p) const { - const asCGlobalProperty* prop = reinterpret_cast(p); + const asCGlobalProperty *prop = reinterpret_cast(p); return prop->type == m_type; } private: // The assignment operator is required for MSVC9, otherwise it will complain that it is not possible to auto generate the operator - asCCompGlobPropType &operator=(const asCCompGlobPropType &) {return *this;} + asCCompGlobPropType &operator=(const asCCompGlobPropType &) + { + return *this; + } }; END_AS_NAMESPACE diff --git a/sdk/angelscript/source/as_restore.cpp b/sdk/angelscript/source/as_restore.cpp index f94567c7..eb3e54f7 100644 --- a/sdk/angelscript/source/as_restore.cpp +++ b/sdk/angelscript/source/as_restore.cpp @@ -48,8 +48,8 @@ BEGIN_AS_NAMESPACE #define SAVE_TO_BIT(dst, val, bit) ((dst) |= ((val) << (bit))) #define LOAD_FROM_BIT(dst, val, bit) ((dst) = ((val) >> (bit)) & 1) -asCReader::asCReader(asCModule* _module, asIBinaryStream* _stream, asCScriptEngine* _engine) - : module(_module), stream(_stream), engine(_engine), noDebugInfo(false), error(false), bytesRead(0), lastCompositeProp(0) +asCReader::asCReader(asCModule *_module, asIBinaryStream *_stream, asCScriptEngine *_engine) + : module(_module), stream(_stream), engine(_engine), noDebugInfo(false), error(false), bytesRead(0), lastCompositeProp(0) { } @@ -59,12 +59,12 @@ int asCReader::ReadData(void *data, asUINT size) int ret = 0; #if defined(AS_BIG_ENDIAN) for( asUINT n = 0; ret >= 0 && n < size; n++ ) - ret = stream->Read(((asBYTE*)data)+n, 1); + ret = stream->Read(((asBYTE *)data) + n, 1); #else - for( int n = size-1; ret >= 0 && n >= 0; n-- ) - ret = stream->Read(((asBYTE*)data)+n, 1); + for( int n = size - 1; ret >= 0 && n >= 0; n-- ) + ret = stream->Read(((asBYTE *)data) + n, 1); #endif - if (ret < 0) + if( ret < 0 ) Error(TXT_UNEXPECTED_END_OF_FILE); bytesRead += size; return ret; @@ -115,7 +115,7 @@ int asCReader::Read(bool *wasDebugInfoStripped) } // Clean up the loaded string constants - for (asUINT n = 0; n < usedStringConstants.GetLength(); n++) + for( asUINT n = 0; n < usedStringConstants.GetLength(); n++ ) engine->stringFactory->ReleaseStringConstant(usedStringConstants[n]); usedStringConstants.SetLength(0); @@ -146,8 +146,8 @@ int asCReader::ReadInner() engine->deferValidationOfTemplateTypes = true; - unsigned long i, count; - asCScriptFunction* func; + unsigned long i, count; + asCScriptFunction *func; // Read the flag as 1 byte even on platforms with 4byte booleans noDebugInfo = ReadEncodedUInt() ? VALUE_OF_BOOLEAN_TRUE : 0; @@ -175,20 +175,20 @@ int asCReader::ReadInner() { asCTypeInfo *t = engine->sharedScriptTypes[n]; if( t && - t->IsShared() && - t->name == et->name && - t->nameSpace == et->nameSpace && - (t->flags & asOBJ_ENUM) ) + t->IsShared() && + t->name == et->name && + t->nameSpace == et->nameSpace && + (t->flags & asOBJ_ENUM) ) { asDELETE(et, asCEnumType); - et = CastToEnumType(t); + et = CastToEnumType(t); sharedExists = true; break; } } } - if (isExternal && !sharedExists) + if( isExternal && !sharedExists ) { asCString msg; msg.Format(TXT_EXTERNAL_SHARED_s_NOT_FOUND, et->name.AddressOf()); @@ -216,7 +216,7 @@ int asCReader::ReadInner() } module->AddEnumType(et); - if (isExternal) + if( isExternal ) module->m_externalTypes.PushLast(et); ReadTypeDeclaration(et, 2); @@ -246,23 +246,23 @@ int asCReader::ReadInner() { for( asUINT n = 0; n < engine->sharedScriptTypes.GetLength(); n++ ) { - asCTypeInfo *ti = engine->sharedScriptTypes[n]; - asCObjectType *t = CastToObjectType(ti); + asCTypeInfo *ti = engine->sharedScriptTypes[n]; + asCObjectType *t = CastToObjectType(ti); if( t && - t->IsShared() && - t->name == ot->name && - t->nameSpace == ot->nameSpace && - t->IsInterface() == ot->IsInterface() ) + t->IsShared() && + t->name == ot->name && + t->nameSpace == ot->nameSpace && + t->IsInterface() == ot->IsInterface() ) { asDELETE(ot, asCObjectType); - ot = CastToObjectType(t); + ot = CastToObjectType(t); sharedExists = true; break; } } } - if (isExternal && !sharedExists) + if( isExternal && !sharedExists ) { asCString msg; msg.Format(TXT_EXTERNAL_SHARED_s_NOT_FOUND, ot->name.AddressOf()); @@ -290,7 +290,7 @@ int asCReader::ReadInner() } module->AddClassType(ot); - if (isExternal) + if( isExternal ) module->m_externalTypes.PushLast(ot); } @@ -301,21 +301,21 @@ int asCReader::ReadInner() module->m_funcDefs.Allocate(count, false); for( i = 0; i < count && !error; i++ ) { - bool isNew, isExternal; + bool isNew, isExternal; asCScriptFunction *funcDef = ReadFunction(isNew, false, true, true, &isExternal); - if(funcDef) + if( funcDef ) { funcDef->module = module; asCFuncdefType *fdt = funcDef->funcdefType; - fdt->module = module; + fdt->module = module; module->AddFuncDef(fdt); engine->funcDefs.PushLast(fdt); // TODO: clean up: This is also done by the builder. It should probably be moved to a method in the module // Check if there is another identical funcdef from another module and if so reuse that instead - if(funcDef->IsShared()) + if( funcDef->IsShared() ) { for( asUINT n = 0; n < engine->funcDefs.GetLength(); n++ ) { @@ -327,22 +327,22 @@ int asCReader::ReadInner() continue; if( f2->name == fdt->name && - f2->nameSpace == fdt->nameSpace && - f2->parentClass == fdt->parentClass && - f2->funcdef->IsSignatureExceptNameEqual(funcDef) ) + f2->nameSpace == fdt->nameSpace && + f2->parentClass == fdt->parentClass && + f2->funcdef->IsSignatureExceptNameEqual(funcDef) ) { // Replace our funcdef for the existing one module->ReplaceFuncDef(fdt, f2); f2->AddRefInternal(); - if (isExternal) + if( isExternal ) module->m_externalTypes.PushLast(f2); engine->funcDefs.RemoveValue(fdt); savedFunctions[savedFunctions.IndexOf(funcDef)] = f2->funcdef; - if (fdt->parentClass) + if( fdt->parentClass ) { // The real funcdef should already be in the object asASSERT(fdt->parentClass->childFuncDefs.IndexOf(f2) >= 0); @@ -358,11 +358,11 @@ int asCReader::ReadInner() } // Add the funcdef to the parentClass if this is a child funcdef - if (funcDef && fdt->parentClass) + if( funcDef && fdt->parentClass ) fdt->parentClass->childFuncDefs.PushLast(fdt); // Check if an external shared funcdef was really found - if (isExternal && funcDef) + if( isExternal && funcDef ) { asCString msg; msg.Format(TXT_EXTERNAL_SHARED_s_NOT_FOUND, funcDef->name.AddressOf()); @@ -437,7 +437,7 @@ int asCReader::ReadInner() for( i = 0; i < count && !error; ++i ) { size_t len = module->m_scriptFunctions.GetLength(); - bool isNew, isExternal; + bool isNew, isExternal; func = ReadFunction(isNew, true, true, true, &isExternal); if( func == 0 ) { @@ -454,21 +454,21 @@ int asCReader::ReadInner() { asCScriptFunction *realFunc = engine->scriptFunctions[n]; if( realFunc && - realFunc != func && - realFunc->IsShared() && - realFunc->nameSpace == func->nameSpace && - realFunc->IsSignatureEqual(func) ) + realFunc != func && + realFunc->IsShared() && + realFunc->nameSpace == func->nameSpace && + realFunc->IsSignatureEqual(func) ) { // Replace the recently created function with the pre-existing function - module->m_scriptFunctions[module->m_scriptFunctions.GetLength()-1] = realFunc; + module->m_scriptFunctions[module->m_scriptFunctions.GetLength() - 1] = realFunc; realFunc->AddRefInternal(); - savedFunctions[savedFunctions.GetLength()-1] = realFunc; + savedFunctions[savedFunctions.GetLength() - 1] = realFunc; engine->RemoveScriptFunction(func); // Insert the function in the dontTranslate array dontTranslate.Insert(realFunc, true); - if (isExternal) + if( isExternal ) module->m_externalFunctions.PushLast(realFunc); // Release the function, but make sure nothing else is released @@ -483,7 +483,7 @@ int asCReader::ReadInner() } // Check if an external shared func was really found - if (isExternal && func) + if( isExternal && func ) { asCString msg; msg.Format(TXT_EXTERNAL_SHARED_s_NOT_FOUND, func->name.AddressOf()); @@ -535,9 +535,9 @@ int asCReader::ReadInner() if( engine->freeImportedFunctionIdxs.GetLength() ) { - int id = engine->freeImportedFunctionIdxs.PopLast(); + int id = engine->freeImportedFunctionIdxs.PopLast(); info->importedFunctionSignature->id = int(FUNC_IMPORTED + id); - engine->importedFunctions[id] = info; + engine->importedFunctions[id] = info; } else { @@ -587,12 +587,12 @@ int asCReader::ReadInner() { asCObjectType *ot = CastToObjectType(usedTypes[i]); if( !ot || - !(ot->flags & asOBJ_TEMPLATE) || - !ot->beh.templateCallback ) + !(ot->flags & asOBJ_TEMPLATE) || + !ot->beh.templateCallback ) continue; - bool dontGarbageCollect = false; - asCScriptFunction *callback = engine->scriptFunctions[ot->beh.templateCallback]; + bool dontGarbageCollect = false; + asCScriptFunction *callback = engine->scriptFunctions[ot->beh.templateCallback]; if( !engine->CallGlobalFunctionRetBool(ot, &dontGarbageCollect, callback->sysFuncIntf, callback) ) { asCString sub = ot->templateSubTypes[0].Format(ot->nameSpace); @@ -660,7 +660,7 @@ void asCReader::ReadUsedStringConstants() asUINT count; count = SanityCheck(ReadEncodedUInt(), 1000000); - if (count > 0 && engine->stringFactory == 0) + if( count > 0 && engine->stringFactory == 0 ) { Error(TXT_STRINGS_NOT_RECOGNIZED); return; @@ -670,7 +670,7 @@ void asCReader::ReadUsedStringConstants() for( asUINT i = 0; i < count; ++i ) { ReadString(&str); - usedStringConstants.PushLast(const_cast(engine->stringFactory->GetStringConstant(str.AddressOf(), (asUINT)str.GetLength()))); + usedStringConstants.PushLast(const_cast(engine->stringFactory->GetStringConstant(str.AddressOf(), (asUINT)str.GetLength()))); } } @@ -687,7 +687,7 @@ void asCReader::ReadUsedFunctions() error = true; return; } - memset(usedFunctions.AddressOf(), 0, sizeof(asCScriptFunction *)*count); + memset(usedFunctions.AddressOf(), 0, sizeof(asCScriptFunction *) * count); for( asUINT n = 0; n < usedFunctions.GetLength(); n++ ) { @@ -706,7 +706,7 @@ void asCReader::ReadUsedFunctions() else { asCScriptFunction func(engine, c == 'm' ? module : 0, asFUNC_DUMMY); - asCObjectType *parentClass = 0; + asCObjectType *parentClass = 0; ReadFunctionSignature(&func, &parentClass); if( error ) { @@ -725,9 +725,9 @@ void asCReader::ReadUsedFunctions() { asCScriptFunction *f = module->m_bindInformations[i]->importedFunctionSignature; if( func.objectType != f->objectType || - func.funcType != f->funcType || - func.nameSpace != f->nameSpace || - !func.IsSignatureEqual(f) ) + func.funcType != f->funcType || + func.nameSpace != f->nameSpace || + !func.IsSignatureEqual(f) ) continue; usedFunctions[n] = f; @@ -741,9 +741,9 @@ void asCReader::ReadUsedFunctions() { asCScriptFunction *f = funcs[i]->funcdef; if( f == 0 || - func.name != f->name || - !func.IsSignatureExceptNameAndObjectTypeEqual(f) || - funcs[i]->parentClass != parentClass ) + func.name != f->name || + !func.IsSignatureExceptNameAndObjectTypeEqual(f) || + funcs[i]->parentClass != parentClass ) continue; asASSERT( f->objectType == 0 ); @@ -761,9 +761,9 @@ void asCReader::ReadUsedFunctions() { asCScriptFunction *f = module->m_scriptFunctions[i]; if( func.objectType != f->objectType || - func.funcType != f->funcType || - func.nameSpace != f->nameSpace || - !func.IsSignatureEqual(f) ) + func.funcType != f->funcType || + func.nameSpace != f->nameSpace || + !func.IsSignatureEqual(f) ) continue; usedFunctions[n] = f; @@ -771,22 +771,22 @@ void asCReader::ReadUsedFunctions() } } } - else if (c == 's') + else if( c == 's' ) { asASSERT(func.templateSubTypes.GetLength() == 0); // Look for shared entities in the engine, as they may not necessarily be part // of the scope of the module if they have been inhereted from other modules. - if (func.funcType == asFUNC_FUNCDEF) + if( func.funcType == asFUNC_FUNCDEF ) { const asCArray &funcs = engine->funcDefs; - for (asUINT i = 0; i < funcs.GetLength(); i++) + for( asUINT i = 0; i < funcs.GetLength(); i++ ) { asCScriptFunction *f = funcs[i]->funcdef; - if (f == 0 || - func.name != f->name || - !func.IsSignatureExceptNameAndObjectTypeEqual(f) || - funcs[i]->parentClass != parentClass) + if( f == 0 || + func.name != f->name || + !func.IsSignatureExceptNameAndObjectTypeEqual(f) || + funcs[i]->parentClass != parentClass ) continue; asASSERT(f->objectType == 0); @@ -797,14 +797,14 @@ void asCReader::ReadUsedFunctions() } else { - for (asUINT i = 0; i < engine->scriptFunctions.GetLength(); i++) + for( asUINT i = 0; i < engine->scriptFunctions.GetLength(); i++ ) { asCScriptFunction *f = engine->scriptFunctions[i]; - if (f == 0 || !f->IsShared() || - func.objectType != f->objectType || - func.funcType != f->funcType || - func.nameSpace != f->nameSpace || - !func.IsSignatureEqual(f)) + if( f == 0 || !f->IsShared() || + func.objectType != f->objectType || + func.funcType != f->funcType || + func.nameSpace != f->nameSpace || + !func.IsSignatureEqual(f) ) continue; usedFunctions[n] = f; @@ -838,30 +838,30 @@ void asCReader::ReadUsedFunctions() if( func.name == "$beh0" && func.objectType ) { - if (func.objectType->flags & asOBJ_TEMPLATE) + if( func.objectType->flags & asOBJ_TEMPLATE ) { // Look for the matching constructor inside the factory stubs generated for the template instance // See asCCompiler::PerformFunctionCall - for (asUINT i = 0; i < func.objectType->beh.constructors.GetLength(); i++) + for( asUINT i = 0; i < func.objectType->beh.constructors.GetLength(); i++ ) { asCScriptFunction *f = engine->scriptFunctions[func.objectType->beh.constructors[i]]; - + // Find the id of the real constructor and not the generated stub - asUINT id = 0; + asUINT id = 0; asDWORD *bc = f->scriptData->byteCode.AddressOf(); - while (bc) + while( bc ) { - if ((*(asBYTE*)bc) == asBC_CALLSYS) + if( (*(asBYTE *)bc) == asBC_CALLSYS ) { id = asBC_INTARG(bc); break; } - bc += asBCTypeSize[asBCInfo[*(asBYTE*)bc].type]; + bc += asBCTypeSize[asBCInfo[*(asBYTE *)bc].type]; } f = engine->scriptFunctions[id]; - if (f == 0 || - !func.IsSignatureExceptNameAndObjectTypeEqual(f)) + if( f == 0 || + !func.IsSignatureExceptNameAndObjectTypeEqual(f) ) continue; usedFunctions[n] = f; @@ -872,11 +872,11 @@ void asCReader::ReadUsedFunctions() if( usedFunctions[n] == 0 ) { // This is a class constructor, so we can search directly in the object type's constructors - for (asUINT i = 0; i < func.objectType->beh.constructors.GetLength(); i++) + for( asUINT i = 0; i < func.objectType->beh.constructors.GetLength(); i++ ) { asCScriptFunction *f = engine->scriptFunctions[func.objectType->beh.constructors[i]]; - if (f == 0 || - !func.IsSignatureExceptNameAndObjectTypeEqual(f)) + if( f == 0 || + !func.IsSignatureExceptNameAndObjectTypeEqual(f) ) continue; usedFunctions[n] = f; @@ -894,7 +894,7 @@ void asCReader::ReadUsedFunctions() { asCScriptFunction *f = engine->scriptFunctions[objType->beh.factories[i]]; if( f == 0 || - !func.IsSignatureExceptNameAndObjectTypeEqual(f) ) + !func.IsSignatureExceptNameAndObjectTypeEqual(f) ) continue; usedFunctions[n] = f; @@ -939,15 +939,15 @@ void asCReader::ReadUsedFunctions() } else if( func.objectType == 0 ) { - if (func.templateSubTypes.GetLength() == 0) + if( func.templateSubTypes.GetLength() == 0 ) { // This is a global function - const asCArray& funcs = engine->registeredGlobalFuncs.GetIndexes(func.nameSpace, func.name); - for (asUINT i = 0; i < funcs.GetLength(); i++) + const asCArray &funcs = engine->registeredGlobalFuncs.GetIndexes(func.nameSpace, func.name); + for( asUINT i = 0; i < funcs.GetLength(); i++ ) { - asCScriptFunction* f = engine->registeredGlobalFuncs.Get(funcs[i]); - if (f == 0 || - !func.IsSignatureExceptNameAndObjectTypeEqual(f)) + asCScriptFunction *f = engine->registeredGlobalFuncs.Get(funcs[i]); + if( f == 0 || + !func.IsSignatureExceptNameAndObjectTypeEqual(f) ) continue; usedFunctions[n] = f; @@ -957,24 +957,24 @@ void asCReader::ReadUsedFunctions() else { // This is a template function - asCScriptFunction* templFunc = 0; - for (asUINT i = 0; i < engine->registeredTemplateGlobalFuncs.GetLength(); i++) + asCScriptFunction *templFunc = 0; + for( asUINT i = 0; i < engine->registeredTemplateGlobalFuncs.GetLength(); i++ ) { - asCScriptFunction* f = engine->registeredTemplateGlobalFuncs[i]; - if (f->name == func.name && - f->nameSpace == func.nameSpace && - f->parameterTypes.GetLength() == func.parameterTypes.GetLength() && - f->templateSubTypes.GetLength() == func.templateSubTypes.GetLength()) + asCScriptFunction *f = engine->registeredTemplateGlobalFuncs[i]; + if( f->name == func.name && + f->nameSpace == func.nameSpace && + f->parameterTypes.GetLength() == func.parameterTypes.GetLength() && + f->templateSubTypes.GetLength() == func.templateSubTypes.GetLength() ) { templFunc = f; break; } } - if (templFunc) + if( templFunc ) { int r = engine->GetTemplateFunctionInstance(templFunc, func.templateSubTypes); - if (r >= 0) + if( r >= 0 ) { templFunc = engine->scriptFunctions[r]; asASSERT(templFunc->IsSignatureEqual(&func)); @@ -986,15 +986,15 @@ void asCReader::ReadUsedFunctions() } else if( func.objectType ) { - if (func.templateSubTypes.GetLength() == 0) + if( func.templateSubTypes.GetLength() == 0 ) { // It is a class member, so we can search directly in the object type's members // TODO: virtual function is different that implemented method - for (asUINT i = 0; i < func.objectType->methods.GetLength(); i++) + for( asUINT i = 0; i < func.objectType->methods.GetLength(); i++ ) { - asCScriptFunction* f = engine->scriptFunctions[func.objectType->methods[i]]; - if (f == 0 || - !func.IsSignatureEqual(f)) + asCScriptFunction *f = engine->scriptFunctions[func.objectType->methods[i]]; + if( f == 0 || + !func.IsSignatureEqual(f) ) continue; usedFunctions[n] = f; @@ -1004,25 +1004,25 @@ void asCReader::ReadUsedFunctions() else { // This is a template function - asCScriptFunction* templFunc = 0; - for (asUINT i = 0; i < func.objectType->methods.GetLength(); i++) + asCScriptFunction *templFunc = 0; + for( asUINT i = 0; i < func.objectType->methods.GetLength(); i++ ) { - asCScriptFunction* f = engine->scriptFunctions[func.objectType->methods[i]]; - if (f->name == func.name && - f->nameSpace == func.nameSpace && - f->IsReadOnly() == func.IsReadOnly() && - f->parameterTypes.GetLength() == func.parameterTypes.GetLength() && - f->templateSubTypes.GetLength() == func.templateSubTypes.GetLength()) + asCScriptFunction *f = engine->scriptFunctions[func.objectType->methods[i]]; + if( f->name == func.name && + f->nameSpace == func.nameSpace && + f->IsReadOnly() == func.IsReadOnly() && + f->parameterTypes.GetLength() == func.parameterTypes.GetLength() && + f->templateSubTypes.GetLength() == func.templateSubTypes.GetLength() ) { templFunc = f; break; } } - if (templFunc) + if( templFunc ) { int r = engine->GetTemplateFunctionInstance(templFunc, func.templateSubTypes); - if (r >= 0) + if( r >= 0 ) { templFunc = engine->scriptFunctions[r]; asASSERT(templFunc->IsSignatureEqual(&func)); @@ -1048,9 +1048,9 @@ void asCReader::ReadUsedFunctions() void asCReader::ReadFunctionSignature(asCScriptFunction *func, asCObjectType **parentClass) { - asUINT i, count; + asUINT i, count; asCDataType dt; - int num; + int num; ReadString(&func->name); if( func->name == DELEGATE_FACTORY ) @@ -1084,52 +1084,52 @@ void asCReader::ReadFunctionSignature(asCScriptFunction *func, asCObjectType **p error = true; return; } - memset(func->inOutFlags.AddressOf(), 0, sizeof(asETypeModifiers)*func->inOutFlags.GetLength()); - if (func->parameterTypes.GetLength() > 0) + memset(func->inOutFlags.AddressOf(), 0, sizeof(asETypeModifiers) * func->inOutFlags.GetLength()); + if( func->parameterTypes.GetLength() > 0 ) { count = ReadEncodedUInt(); - if (count > func->parameterTypes.GetLength()) + if( count > func->parameterTypes.GetLength() ) { // Cannot be more than the number of arguments Error(TXT_INVALID_BYTECODE_d); return; } - for (i = 0; i < count; ++i) + for( i = 0; i < count; ++i ) { - num = ReadEncodedUInt(); + num = ReadEncodedUInt(); func->inOutFlags[i] = static_cast(num); } } - asUINT val = (asEFuncType)ReadEncodedUInt(); - bool isTemplateFunc = (val & 128) ? true : false; - val &= ~128; - func->funcType = asEFuncType(val); + asUINT val = (asEFuncType)ReadEncodedUInt(); + bool isTemplateFunc = (val & 128) ? true : false; + val &= ~128; + func->funcType = asEFuncType(val); // Read the default args, from last to first - if (func->parameterTypes.GetLength() > 0) + if( func->parameterTypes.GetLength() > 0 ) { count = ReadEncodedUInt(); - if (count > func->parameterTypes.GetLength()) + if( count > func->parameterTypes.GetLength() ) { // Cannot be more than the number of arguments Error(TXT_INVALID_BYTECODE_d); return; } - if (count) + if( count ) { func->defaultArgs.SetLength(func->parameterTypes.GetLength()); - if (func->defaultArgs.GetLength() != func->parameterTypes.GetLength()) + if( func->defaultArgs.GetLength() != func->parameterTypes.GetLength() ) { // Out of memory error = true; return; } - memset(func->defaultArgs.AddressOf(), 0, sizeof(asCString*)*func->defaultArgs.GetLength()); - for (i = 0; i < count; i++) + memset(func->defaultArgs.AddressOf(), 0, sizeof(asCString *) * func->defaultArgs.GetLength()); + for( i = 0; i < count; i++ ) { asCString *str = asNEW(asCString); - if (str == 0) + if( str == 0 ) { // Out of memory error = true; @@ -1142,7 +1142,7 @@ void asCReader::ReadFunctionSignature(asCScriptFunction *func, asCObjectType **p } func->objectType = CastToObjectType(ReadTypeInfo()); - if (func->objectType) + if( func->objectType ) { func->objectType->AddRefInternal(); func->nameSpace = func->objectType->nameSpace; @@ -1159,21 +1159,21 @@ void asCReader::ReadFunctionSignature(asCScriptFunction *func, asCObjectType **p func->SetProperty((b & 64) ? true : false); func->SetVariadic((b & 128) ? true : false); - if (!func->objectType) + if( !func->objectType ) { - if (func->funcType == asFUNC_FUNCDEF) + if( func->funcType == asFUNC_FUNCDEF ) { ReadData(&b, 1); - if (b == 'n') + if( b == 'n' ) { asCString ns; ReadString(&ns); func->nameSpace = engine->AddNameSpace(ns.AddressOf()); } - else if (b == 'o') + else if( b == 'o' ) { func->nameSpace = 0; - if (parentClass) + if( parentClass ) *parentClass = CastToObjectType(ReadTypeInfo()); else error = true; @@ -1189,14 +1189,14 @@ void asCReader::ReadFunctionSignature(asCScriptFunction *func, asCObjectType **p } } - if (isTemplateFunc) + if( isTemplateFunc ) { count = ReadEncodedUInt(); func->templateSubTypes.SetLength(count); - for (asUINT n = 0; n < count; n++) + for( asUINT n = 0; n < count; n++ ) { ReadDataType(&func->templateSubTypes[n]); - if(func->templateSubTypes[n].GetTypeInfo()) + if( func->templateSubTypes[n].GetTypeInfo() ) func->templateSubTypes[n].GetTypeInfo()->AddRefInternal(); } } @@ -1205,7 +1205,7 @@ void asCReader::ReadFunctionSignature(asCScriptFunction *func, asCObjectType **p asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool addToEngine, bool addToGC, bool *isExternal) { isNew = false; - if (isExternal) *isExternal = false; + if( isExternal ) *isExternal = false; if( error ) return 0; char c; @@ -1231,8 +1231,8 @@ asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool a } // Load the new function - isNew = true; - asCScriptFunction *func = asNEW(asCScriptFunction)(engine,0,asFUNC_DUMMY); + isNew = true; + asCScriptFunction *func = asNEW(asCScriptFunction)(engine, 0, asFUNC_DUMMY); if( func == 0 ) { // Out of memory @@ -1241,7 +1241,7 @@ asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool a } savedFunctions.PushLast(func); - int i; + int i; asCDataType dt; asCObjectType *parentClass = 0; @@ -1256,19 +1256,19 @@ asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool a if( func->funcType == asFUNC_SCRIPT ) { // Skip this for external shared entities - if (module->m_externalTypes.IndexOf(func->objectType) >= 0) + if( module->m_externalTypes.IndexOf(func->objectType) >= 0 ) { // Replace with the real function from the existing entity isNew = false; asCObjectType *ot = func->objectType; - for (asUINT n = 0; n < ot->methods.GetLength(); n++) + for( asUINT n = 0; n < ot->methods.GetLength(); n++ ) { asCScriptFunction *func2 = engine->scriptFunctions[ot->methods[n]]; - if (func2->funcType == asFUNC_VIRTUAL) + if( func2->funcType == asFUNC_VIRTUAL ) func2 = ot->virtualFunctionTable[func2->vfTableIdx]; - if (func->IsSignatureEqual(func2)) + if( func->IsSignatureEqual(func2) ) { func->DestroyHalfCreated(); @@ -1290,14 +1290,14 @@ asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool a func->SetShared((bits & 1) ? true : false); func->SetExplicit((bits & 32) ? true : false); func->dontCleanUpOnException = (bits & 2) ? true : false; - if ((bits & 4) && isExternal) + if( (bits & 4) && isExternal ) *isExternal = true; // for external shared functions the rest is not needed - if (!(bits & 4)) + if( !(bits & 4) ) { func->AllocateScriptFunctionData(); - if (func->scriptData == 0) + if( func->scriptData == 0 ) { // Out of memory error = true; @@ -1305,28 +1305,28 @@ asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool a return 0; } - if (addToGC && !addToModule) + if( addToGC && !addToModule ) engine->gc.AddScriptObjectToGC(func, &engine->functionBehaviours); ReadByteCode(func); func->scriptData->variableSpace = SanityCheck(ReadEncodedUInt(), 1000000); - if (bits & 8) + if( bits & 8 ) { int length = SanityCheck(ReadEncodedUInt(), 1000000); func->scriptData->objVariableInfo.SetLength(length); - for (i = 0; i < length; ++i) + for( i = 0; i < length; ++i ) { - func->scriptData->objVariableInfo[i].programPos = SanityCheck(ReadEncodedUInt(), 1000000); + func->scriptData->objVariableInfo[i].programPos = SanityCheck(ReadEncodedUInt(), 1000000); func->scriptData->objVariableInfo[i].variableOffset = SanityCheck(ReadEncodedInt(), 10000); - asEObjVarInfoOption option = (asEObjVarInfoOption)ReadEncodedUInt(); - func->scriptData->objVariableInfo[i].option = option; - if (option != asOBJ_INIT && - option != asOBJ_UNINIT && - option != asBLOCK_BEGIN && - option != asBLOCK_END && - option != asOBJ_VARDECL) + asEObjVarInfoOption option = (asEObjVarInfoOption)ReadEncodedUInt(); + func->scriptData->objVariableInfo[i].option = option; + if( option != asOBJ_INIT && + option != asOBJ_UNINIT && + option != asBLOCK_BEGIN && + option != asBLOCK_END && + option != asOBJ_VARDECL ) { error = true; func->DestroyHalfCreated(); @@ -1335,49 +1335,49 @@ asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool a } } - if (bits & 16) + if( bits & 16 ) { // Read info on try/catch blocks int length = SanityCheck(ReadEncodedUInt(), 1000000); func->scriptData->tryCatchInfo.SetLength(length); - for (i = 0; i < length; ++i) + for( i = 0; i < length; ++i ) { // The program position must be adjusted to be in number of instructions - func->scriptData->tryCatchInfo[i].tryPos = SanityCheck(ReadEncodedUInt(), 1000000); + func->scriptData->tryCatchInfo[i].tryPos = SanityCheck(ReadEncodedUInt(), 1000000); func->scriptData->tryCatchInfo[i].catchPos = SanityCheck(ReadEncodedUInt(), 1000000); - + // The stack position must be adjusted to be according to the size of the variables func->scriptData->tryCatchInfo[i].stackSize = SanityCheck(ReadEncodedUInt(), 100000); } } - if (!noDebugInfo) + if( !noDebugInfo ) { int length = SanityCheck(ReadEncodedUInt(), 1000000); func->scriptData->lineNumbers.SetLength(length); - if (int(func->scriptData->lineNumbers.GetLength()) != length) + if( int(func->scriptData->lineNumbers.GetLength()) != length ) { // Out of memory error = true; func->DestroyHalfCreated(); return 0; } - for (i = 0; i < length; ++i) + for( i = 0; i < length; ++i ) func->scriptData->lineNumbers[i] = ReadEncodedUInt(); // Read the array of script sections length = SanityCheck(ReadEncodedUInt(), 1000000); func->scriptData->sectionIdxs.SetLength(length); - if (int(func->scriptData->sectionIdxs.GetLength()) != length) + if( int(func->scriptData->sectionIdxs.GetLength()) != length ) { // Out of memory error = true; func->DestroyHalfCreated(); return 0; } - for (i = 0; i < length; ++i) + for( i = 0; i < length; ++i ) { - if ((i & 1) == 0) + if( (i & 1) == 0 ) func->scriptData->sectionIdxs[i] = ReadEncodedUInt(); else { @@ -1391,10 +1391,10 @@ asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool a // Read the variable information int length = SanityCheck(ReadEncodedUInt(), 1000000); func->scriptData->variables.Allocate(length, false); - for (i = 0; i < length; i++) + for( i = 0; i < length; i++ ) { asSScriptVariable *var = asNEW(asSScriptVariable); - if (var == 0) + if( var == 0 ) { // Out of memory error = true; @@ -1403,7 +1403,7 @@ asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool a } func->scriptData->variables.PushLast(var); - if (!noDebugInfo) + if( !noDebugInfo ) { var->declaredAtProgramPos = ReadEncodedUInt(); ReadString(&var->name); @@ -1411,12 +1411,12 @@ asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool a else var->declaredAtProgramPos = 0; - var->stackOffset = SanityCheck(ReadEncodedInt(),10000); - var->onHeap = var->stackOffset & 1; + var->stackOffset = SanityCheck(ReadEncodedInt(), 10000); + var->onHeap = var->stackOffset & 1; var->stackOffset >>= 1; ReadDataType(&var->type); - if (error) + if( error ) { // No need to continue (the error has already been reported before) func->DestroyHalfCreated(); @@ -1425,26 +1425,26 @@ asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool a } // Read script section name - if (!noDebugInfo) + if( !noDebugInfo ) { asCString name; ReadString(&name); func->scriptData->scriptSectionIdx = engine->GetScriptSectionNameIndex(name.AddressOf()); - func->scriptData->declaredAt = ReadEncodedUInt(); + func->scriptData->declaredAt = ReadEncodedUInt(); } // Read parameter names - if (!noDebugInfo) + if( !noDebugInfo ) { asUINT countParam = asUINT(ReadEncodedUInt64()); - if (countParam > func->parameterTypes.GetLength()) + if( countParam > func->parameterTypes.GetLength() ) { error = true; func->DestroyHalfCreated(); return 0; } func->parameterNames.SetLength(countParam); - for (asUINT n = 0; n < countParam; n++) + for( asUINT n = 0; n < countParam; n++ ) ReadString(&func->parameterNames[n]); } } @@ -1460,12 +1460,12 @@ asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool a ReadData(&bits, 1); if( bits & 1 ) func->SetShared(true); - if ((bits & 2) && isExternal) + if( (bits & 2) && isExternal ) *isExternal = true; // The asCFuncdefType constructor adds itself to the func->funcdefType member asCFuncdefType *fdt = asNEW(asCFuncdefType)(engine, func); - fdt->parentClass = parentClass; + fdt->parentClass = parentClass; } // Methods loaded for shared objects, owned by other modules should not be created as new functions @@ -1473,7 +1473,7 @@ asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool a { // Return the real function from the object asCScriptFunction *realFunc = 0; - bool found = false; + bool found = false; if( func->funcType == asFUNC_SCRIPT ) { realFunc = engine->scriptFunctions[func->objectType->beh.destruct]; @@ -1489,7 +1489,7 @@ asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool a found = true; break; } - } + } for( asUINT n = 0; !found && n < func->objectType->beh.factories.GetLength(); n++ ) { realFunc = engine->scriptFunctions[func->objectType->beh.factories[n]]; @@ -1498,7 +1498,7 @@ asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool a found = true; break; } - } + } for( asUINT n = 0; !found && n < func->objectType->methods.GetLength(); n++ ) { realFunc = engine->scriptFunctions[func->objectType->methods[n]]; @@ -1543,18 +1543,18 @@ asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool a if( realFunc->funcType == asFUNC_VIRTUAL && addToModule ) { - // Virtual methods must be added to the module's script functions array, + // Virtual methods must be added to the module's script functions array, // even if they are not owned by the module module->m_scriptFunctions.PushLast(realFunc); - realFunc->AddRefInternal(); - } + realFunc->AddRefInternal(); + } } else { asCString str; str.Format(TXT_SHARED_s_DOESNT_MATCH_ORIGINAL_s, func->objectType->GetName(), func->objectType->GetModule() ? func->objectType->GetModule()->GetName() : ""); engine->WriteMessage("", 0, 0, asMSGTYPE_ERROR, str.AddressOf()); - + Error(TXT_INVALID_BYTECODE_d); savedFunctions.PopLast(); realFunc = 0; @@ -1563,10 +1563,10 @@ asCScriptFunction *asCReader::ReadFunction(bool &isNew, bool addToModule, bool a // Destroy the newly created function instance since it has been replaced by an existing function isNew = false; func->DestroyHalfCreated(); - + // As it is an existing function it shouldn't be added to the module or the engine return realFunc; - } + } if( addToModule ) { @@ -1590,7 +1590,7 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern if( phase == 1 ) { asASSERT(isExternal); - if (isExternal) + if( isExternal ) *isExternal = false; // Read the initial attributes @@ -1602,9 +1602,9 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern type->nameSpace = engine->AddNameSpace(ns.AddressOf()); // Verify that the flags match the asCTypeInfo - if ((CastToEnumType(type) && !(type->flags & asOBJ_ENUM)) || - (CastToFuncdefType(type) && !(type->flags & asOBJ_FUNCDEF)) || - (CastToObjectType(type) && !(type->flags & (asOBJ_REF | asOBJ_VALUE)))) + if( (CastToEnumType(type) && !(type->flags & asOBJ_ENUM)) || + (CastToFuncdefType(type) && !(type->flags & asOBJ_FUNCDEF)) || + (CastToObjectType(type) && !(type->flags & (asOBJ_REF | asOBJ_VALUE))) ) { error = true; return; @@ -1615,14 +1615,14 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern type->size = sizeof(asCScriptObject); asCObjectType *ot = CastToObjectType(type); - if (ot) + if( ot ) { // Use the default script class behaviours - ot->beh = engine->scriptTypeBehaviours.beh; + ot->beh = engine->scriptTypeBehaviours.beh; ot->beh.construct = 0; - ot->beh.factory = 0; + ot->beh.factory = 0; ot->beh.constructors.PopLast(); // These will be read from the file - ot->beh.factories.PopLast(); // These will be read from the file + ot->beh.factories.PopLast(); // These will be read from the file engine->scriptFunctions[ot->beh.addref]->AddRefInternal(); engine->scriptFunctions[ot->beh.release]->AddRefInternal(); engine->scriptFunctions[ot->beh.gcEnumReferences]->AddRefInternal(); @@ -1636,13 +1636,13 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern } // external shared flag - if (type->flags & asOBJ_SHARED) + if( type->flags & asOBJ_SHARED ) { char c; ReadData(&c, 1); - if (c == 'e') + if( c == 'e' ) *isExternal = true; - else if (c != ' ') + else if( c != ' ' ) { error = true; return; @@ -1652,15 +1652,15 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern else if( phase == 2 ) { // external shared types doesn't store this - if ((type->flags & asOBJ_SHARED) && module->m_externalTypes.IndexOf(type) >= 0) + if( (type->flags & asOBJ_SHARED) && module->m_externalTypes.IndexOf(type) >= 0 ) return; if( type->flags & asOBJ_ENUM ) { - asCEnumType *t = CastToEnumType(type); - eTokenType tt = (eTokenType)ReadEncodedUInt(); + asCEnumType *t = CastToEnumType(type); + eTokenType tt = (eTokenType)ReadEncodedUInt(); if( !((tt >= ttInt && tt <= ttInt64) || - (tt >= ttUInt && tt <= ttUInt64)) ) + (tt >= ttUInt && tt <= ttUInt64)) ) { // Only 32 bit enums are supported Error(TXT_INVALID_BYTECODE_d); @@ -1668,7 +1668,7 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern } t->enumType = asCDataType::CreatePrimitive(tt, false); - int count = SanityCheck(ReadEncodedUInt(), 1000000); + int count = SanityCheck(ReadEncodedUInt(), 1000000); bool sharedExists = existingShared.MoveTo(0, type); if( !sharedExists ) { @@ -1691,7 +1691,7 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern { // Verify that the enum values exists in the original asCString name; - int value; + int value; for( int n = 0; n < count; n++ ) { ReadString(&name); @@ -1700,7 +1700,7 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern for( asUINT e = 0; e < t->enumValues.GetLength(); e++ ) { if( t->enumValues[e]->name == name && - t->enumValues[e]->value == value ) + t->enumValues[e]->value == value ) { found = true; break; @@ -1720,7 +1720,7 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern { asCTypedefType *td = CastToTypedefType(type); asASSERT(td); - eTokenType t = (eTokenType)ReadEncodedUInt(); + eTokenType t = (eTokenType)ReadEncodedUInt(); td->aliasForType = asCDataType::CreatePrimitive(t, false); } else @@ -1756,7 +1756,7 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern for( int n = 0; n < size; n++ ) { asCObjectType *intf = CastToObjectType(ReadTypeInfo()); - if (!ot->IsInterface()) + if( !ot->IsInterface() ) ReadEncodedUInt(); if( !type->Implements(intf) ) @@ -1778,7 +1778,7 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern asCObjectType *intf = CastToObjectType(ReadTypeInfo()); ot->interfaces.PushLast(intf); - if (!ot->IsInterface()) + if( !ot->IsInterface() ) { asUINT offset = SanityCheck(ReadEncodedUInt(), 1000000); ot->interfaceVFTOffsets.PushLast(offset); @@ -1789,7 +1789,7 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern // behaviours if( !ot->IsInterface() && type->flags != asOBJ_TYPEDEF && type->flags != asOBJ_ENUM ) { - bool isNew; + bool isNew; asCScriptFunction *func = ReadFunction(isNew, !sharedExists, !sharedExists, !sharedExists); if( sharedExists ) { @@ -1798,8 +1798,8 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern if( (realFunc == 0 && func == 0) || realFunc->IsSignatureEqual(func) ) { // If the function is not the last, then the substitution has already occurred before - if( func && savedFunctions[savedFunctions.GetLength()-1] == func ) - savedFunctions[savedFunctions.GetLength()-1] = realFunc; + if( func && savedFunctions[savedFunctions.GetLength() - 1] == func ) + savedFunctions[savedFunctions.GetLength() - 1] = realFunc; } else { @@ -1847,8 +1847,8 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern if( realFunc->IsSignatureEqual(func) ) { // If the function is not the last, then the substitution has already occurred before - if( savedFunctions[savedFunctions.GetLength()-1] == func ) - savedFunctions[savedFunctions.GetLength()-1] = realFunc; + if( savedFunctions[savedFunctions.GetLength() - 1] == func ) + savedFunctions[savedFunctions.GetLength() - 1] = realFunc; found = true; dontTranslate.Insert(realFunc, true); break; @@ -1896,8 +1896,8 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern if( realFunc->IsSignatureEqual(func) ) { // If the function is not the last, then the substitution has already occurred before - if( savedFunctions[savedFunctions.GetLength()-1] == func ) - savedFunctions[savedFunctions.GetLength()-1] = realFunc; + if( savedFunctions[savedFunctions.GetLength() - 1] == func ) + savedFunctions[savedFunctions.GetLength() - 1] = realFunc; found = true; dontTranslate.Insert(realFunc, true); break; @@ -1939,7 +1939,7 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern int n; for( n = 0; n < size; n++ ) { - bool isNew; + bool isNew; asCScriptFunction *func = ReadFunction(isNew, !sharedExists, !sharedExists, !sharedExists); if( func ) { @@ -1953,8 +1953,8 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern if( realFunc->IsSignatureEqual(func) ) { // If the function is not the last, then the substitution has already occurred before - if( savedFunctions[savedFunctions.GetLength()-1] == func ) - savedFunctions[savedFunctions.GetLength()-1] = realFunc; + if( savedFunctions[savedFunctions.GetLength() - 1] == func ) + savedFunctions[savedFunctions.GetLength() - 1] = realFunc; found = true; dontTranslate.Insert(realFunc, true); break; @@ -1982,8 +1982,8 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern { // If the method is the assignment operator we need to replace the default implementation if( func->name == "opAssign" && func->parameterTypes.GetLength() == 1 && - func->parameterTypes[0].GetTypeInfo() == func->objectType && - (func->inOutFlags[0] & asTM_INREF) ) + func->parameterTypes[0].GetTypeInfo() == func->objectType && + (func->inOutFlags[0] & asTM_INREF) ) { engine->scriptFunctions[ot->beh.copy]->ReleaseInternal(); ot->beh.copy = func->id; @@ -2004,7 +2004,7 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern size = SanityCheck(ReadEncodedUInt(), 1000000); for( n = 0; n < size; n++ ) { - bool isNew; + bool isNew; asCScriptFunction *func = ReadFunction(isNew, !sharedExists, !sharedExists, !sharedExists); if( func ) { @@ -2018,8 +2018,8 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern if( realFunc->IsSignatureEqual(func) ) { // If the function is not the last, then the substitution has already occurred before - if( savedFunctions[savedFunctions.GetLength()-1] == func ) - savedFunctions[savedFunctions.GetLength()-1] = realFunc; + if( savedFunctions[savedFunctions.GetLength() - 1] == func ) + savedFunctions[savedFunctions.GetLength() - 1] = realFunc; found = true; dontTranslate.Insert(realFunc, true); break; @@ -2057,7 +2057,7 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern else if( phase == 3 ) { // external shared types doesn't store this - if ((type->flags & asOBJ_SHARED) && module->m_externalTypes.IndexOf(type) >= 0) + if( (type->flags & asOBJ_SHARED) && module->m_externalTypes.IndexOf(type) >= 0 ) return; asCObjectType *ot = CastToObjectType(type); @@ -2075,7 +2075,7 @@ void asCReader::ReadTypeDeclaration(asCTypeInfo *type, int phase, bool *isExtern asWORD asCReader::ReadEncodedUInt16() { asDWORD dw = ReadEncodedUInt(); - if( (dw>>16) != 0 && (dw>>16) != 0xFFFF ) + if( (dw >> 16) != 0 && (dw >> 16) != 0xFFFF ) { Error(TXT_INVALID_BYTECODE_d); } @@ -2086,7 +2086,7 @@ asWORD asCReader::ReadEncodedUInt16() asUINT asCReader::ReadEncodedUInt() { asQWORD qw = ReadEncodedUInt64(); - if( (qw>>32) != 0 && (qw>>32) != 0xFFFFFFFF ) + if( (qw >> 32) != 0 && (qw >> 32) != 0xFFFFFFFF ) { Error(TXT_INVALID_BYTECODE_d); } @@ -2102,66 +2102,95 @@ int asCReader::ReadEncodedInt() asQWORD asCReader::ReadEncodedUInt64() { asQWORD i = 0; - asBYTE b = 0xFF; // set to 0xFF to better catch if the stream doesn't update the value + asBYTE b = 0xFF; // set to 0xFF to better catch if the stream doesn't update the value ReadData(&b, 1); - bool isNegative = ( b & 0x80 ) ? true : false; - b &= 0x7F; + bool isNegative = (b & 0x80) ? true : false; + b &= 0x7F; if( (b & 0x7F) == 0x7F ) { - ReadData(&b, 1); i = asQWORD(b) << 56; - ReadData(&b, 1); i += asQWORD(b) << 48; - ReadData(&b, 1); i += asQWORD(b) << 40; - ReadData(&b, 1); i += asQWORD(b) << 32; - ReadData(&b, 1); i += asQWORD(b) << 24; - ReadData(&b, 1); i += asQWORD(b) << 16; - ReadData(&b, 1); i += asQWORD(b) << 8; - ReadData(&b, 1); i += b; + ReadData(&b, 1); + i = asQWORD(b) << 56; + ReadData(&b, 1); + i += asQWORD(b) << 48; + ReadData(&b, 1); + i += asQWORD(b) << 40; + ReadData(&b, 1); + i += asQWORD(b) << 32; + ReadData(&b, 1); + i += asQWORD(b) << 24; + ReadData(&b, 1); + i += asQWORD(b) << 16; + ReadData(&b, 1); + i += asQWORD(b) << 8; + ReadData(&b, 1); + i += b; } else if( (b & 0x7E) == 0x7E ) { i = asQWORD(b & 0x01) << 48; - ReadData(&b, 1); i += asQWORD(b) << 40; - ReadData(&b, 1); i += asQWORD(b) << 32; - ReadData(&b, 1); i += asQWORD(b) << 24; - ReadData(&b, 1); i += asQWORD(b) << 16; - ReadData(&b, 1); i += asQWORD(b) << 8; - ReadData(&b, 1); i += b; + ReadData(&b, 1); + i += asQWORD(b) << 40; + ReadData(&b, 1); + i += asQWORD(b) << 32; + ReadData(&b, 1); + i += asQWORD(b) << 24; + ReadData(&b, 1); + i += asQWORD(b) << 16; + ReadData(&b, 1); + i += asQWORD(b) << 8; + ReadData(&b, 1); + i += b; } else if( (b & 0x7C) == 0x7C ) { i = asQWORD(b & 0x03) << 40; - ReadData(&b, 1); i += asQWORD(b) << 32; - ReadData(&b, 1); i += asQWORD(b) << 24; - ReadData(&b, 1); i += asQWORD(b) << 16; - ReadData(&b, 1); i += asQWORD(b) << 8; - ReadData(&b, 1); i += b; + ReadData(&b, 1); + i += asQWORD(b) << 32; + ReadData(&b, 1); + i += asQWORD(b) << 24; + ReadData(&b, 1); + i += asQWORD(b) << 16; + ReadData(&b, 1); + i += asQWORD(b) << 8; + ReadData(&b, 1); + i += b; } else if( (b & 0x78) == 0x78 ) { i = asQWORD(b & 0x07) << 32; - ReadData(&b, 1); i += asQWORD(b) << 24; - ReadData(&b, 1); i += asQWORD(b) << 16; - ReadData(&b, 1); i += asQWORD(b) << 8; - ReadData(&b, 1); i += b; + ReadData(&b, 1); + i += asQWORD(b) << 24; + ReadData(&b, 1); + i += asQWORD(b) << 16; + ReadData(&b, 1); + i += asQWORD(b) << 8; + ReadData(&b, 1); + i += b; } else if( (b & 0x70) == 0x70 ) { i = asQWORD(b & 0x0F) << 24; - ReadData(&b, 1); i += asQWORD(b) << 16; - ReadData(&b, 1); i += asQWORD(b) << 8; - ReadData(&b, 1); i += b; + ReadData(&b, 1); + i += asQWORD(b) << 16; + ReadData(&b, 1); + i += asQWORD(b) << 8; + ReadData(&b, 1); + i += b; } else if( (b & 0x60) == 0x60 ) { i = asQWORD(b & 0x1F) << 16; - ReadData(&b, 1); i += asQWORD(b) << 8; - ReadData(&b, 1); i += b; + ReadData(&b, 1); + i += asQWORD(b) << 8; + ReadData(&b, 1); + i += b; } else if( (b & 0x40) == 0x40 ) { i = asQWORD(b & 0x3F) << 8; - ReadData(&b, 1); i += b; + ReadData(&b, 1); + i += b; } else { @@ -2175,7 +2204,7 @@ asQWORD asCReader::ReadEncodedUInt64() asUINT asCReader::SanityCheck(asUINT val, asUINT max) { - if (val > max) + if( val > max ) { Error(TXT_INVALID_BYTECODE_d); @@ -2188,7 +2217,7 @@ asUINT asCReader::SanityCheck(asUINT val, asUINT max) int asCReader::SanityCheck(int val, asUINT max) { - if (val > int(max) || val < -int(max)) + if( val > int(max) || val < -int(max) ) { Error(TXT_INVALID_BYTECODE_d); @@ -2199,12 +2228,12 @@ int asCReader::SanityCheck(int val, asUINT max) return val; } -void asCReader::ReadString(asCString* str) +void asCReader::ReadString(asCString *str) { asUINT len = SanityCheck(ReadEncodedUInt(), 1000000); if( len & 1 ) { - asUINT idx = len/2; + asUINT idx = len / 2; if( idx < savedStrings.GetLength() ) *str = savedStrings[idx]; else @@ -2215,7 +2244,7 @@ void asCReader::ReadString(asCString* str) len /= 2; str->SetLength(len); int r = stream->Read(str->AddressOf(), len); - if (r < 0) + if( r < 0 ) Error(TXT_UNEXPECTED_END_OF_FILE); savedStrings.PushLast(*str); @@ -2226,7 +2255,7 @@ void asCReader::ReadString(asCString* str) void asCReader::ReadGlobalProperty() { - asCString name; + asCString name; asCDataType type; ReadString(&name); @@ -2260,8 +2289,8 @@ void asCReader::ReadObjectProperty(asCObjectType *ot) ReadString(&name); asCDataType dt; ReadDataType(&dt); - int flags = ReadEncodedUInt(); - bool isPrivate = (flags & 1) ? true : false; + int flags = ReadEncodedUInt(); + bool isPrivate = (flags & 1) ? true : false; bool isProtected = (flags & 2) ? true : false; bool isInherited = (flags & 4) ? true : false; @@ -2277,14 +2306,14 @@ void asCReader::ReadDataType(asCDataType *dt) asUINT idx = ReadEncodedUInt(); if( idx != 0 ) { - if (idx-1 >= savedDataTypes.GetLength()) + if( idx - 1 >= savedDataTypes.GetLength() ) { Error(TXT_INVALID_BYTECODE_d); return; } // Get the datatype from the cache - *dt = savedDataTypes[idx-1]; + *dt = savedDataTypes[idx - 1]; return; } @@ -2325,17 +2354,17 @@ void asCReader::ReadDataType(asCDataType *dt) dt->MakeReadOnly(isReadOnly ? true : false); dt->MakeReference(isReference ? true : false); - if (tokenType == ttUnrecognizedToken && isObjectHandle && ti == 0) + if( tokenType == ttUnrecognizedToken && isObjectHandle && ti == 0 ) *dt = asCDataType::CreateNullHandle(); // Update the previously saved slot savedDataTypes[saveSlot] = *dt; } -asCTypeInfo* asCReader::ReadTypeInfo() +asCTypeInfo *asCReader::ReadTypeInfo() { asCTypeInfo *ot = 0; - char ch; + char ch; ReadData(&ch, 1); if( ch == 'a' ) { @@ -2345,7 +2374,7 @@ asCTypeInfo* asCReader::ReadTypeInfo() ReadString(&ns); asSNameSpace *nameSpace = engine->AddNameSpace(ns.AddressOf()); - asCTypeInfo *tmp = engine->GetRegisteredType(typeName.AddressOf(), nameSpace); + asCTypeInfo *tmp = engine->GetRegisteredType(typeName.AddressOf(), nameSpace); asCObjectType *tmpl = CastToObjectType(tmp); if( tmpl == 0 ) { @@ -2356,7 +2385,7 @@ asCTypeInfo* asCReader::ReadTypeInfo() return 0; } - asUINT numSubTypes = SanityCheck(ReadEncodedUInt(), 100); + asUINT numSubTypes = SanityCheck(ReadEncodedUInt(), 100); asCArray subTypes; for( asUINT n = 0; n < numSubTypes; n++ ) { @@ -2369,8 +2398,8 @@ asCTypeInfo* asCReader::ReadTypeInfo() } else { - eTokenType tokenType = (eTokenType)ReadEncodedUInt(); - asCDataType dt = asCDataType::CreatePrimitive(tokenType, false); + eTokenType tokenType = (eTokenType)ReadEncodedUInt(); + asCDataType dt = asCDataType::CreatePrimitive(tokenType, false); subTypes.PushLast(dt); } } @@ -2448,7 +2477,7 @@ asCTypeInfo* asCReader::ReadTypeInfo() { // Find the object type ot = module->GetType(typeName.AddressOf(), nameSpace); - if (!ot) + if( !ot ) ot = engine->GetRegisteredType(typeName.AddressOf(), nameSpace); if( ot == 0 ) @@ -2471,7 +2500,7 @@ asCTypeInfo* asCReader::ReadTypeInfo() else asASSERT( false ); } - else if (ch == 'c') + else if( ch == 'c' ) { // Read the object type name asCString typeName, ns; @@ -2479,20 +2508,20 @@ asCTypeInfo* asCReader::ReadTypeInfo() // Read the parent class asCObjectType *parentClass = CastToObjectType(ReadTypeInfo()); - if (parentClass == 0) + if( parentClass == 0 ) { Error(TXT_INVALID_BYTECODE_d); return 0; } // Find the child type in the parentClass - for (asUINT n = 0; n < parentClass->childFuncDefs.GetLength(); n++) + for( asUINT n = 0; n < parentClass->childFuncDefs.GetLength(); n++ ) { - if (parentClass->childFuncDefs[n]->name == typeName) + if( parentClass->childFuncDefs[n]->name == typeName ) ot = parentClass->childFuncDefs[n]; } - if (ot == 0) + if( ot == 0 ) { asCString str; str.Format(TXT_OBJECT_TYPE_s_DOESNT_EXIST, typeName.AddressOf()); @@ -2529,13 +2558,13 @@ void asCReader::ReadByteCode(asCScriptFunction *func) ReadData(&b, 1); // Allocate the space for the instruction - asUINT len = asBCTypeSize[asBCInfo[b].type]; + asUINT len = asBCTypeSize[asBCInfo[b].type]; asUINT newSize = asUINT(func->scriptData->byteCode.GetLength()) + len; if( func->scriptData->byteCode.GetCapacity() < newSize ) { asUINT size = newSize; // Determine the average size of the loaded instructions and re-estimate the final size - if (total != numInstructions) + if( total != numInstructions ) size = asUINT(float(newSize) / (total - numInstructions) * total) + 1; func->scriptData->byteCode.AllocateNoConstruct(size, true); } @@ -2546,57 +2575,57 @@ void asCReader::ReadByteCode(asCScriptFunction *func) return; } - asDWORD *bc = func->scriptData->byteCode.AddressOf() + pos; - pos += len; + asDWORD *bc = func->scriptData->byteCode.AddressOf() + pos; + pos += len; switch( asBCInfo[b].type ) { - case asBCTYPE_NO_ARG: + case asBCTYPE_NO_ARG: { - *(asBYTE*)(bc) = b; + *(asBYTE *)(bc) = b; bc++; } break; - case asBCTYPE_W_ARG: - case asBCTYPE_wW_ARG: - case asBCTYPE_rW_ARG: + case asBCTYPE_W_ARG: + case asBCTYPE_wW_ARG: + case asBCTYPE_rW_ARG: { - *(asBYTE*)(bc) = b; + *(asBYTE *)(bc) = b; // Read the argument - asWORD w = ReadEncodedUInt16(); - *(((asWORD*)bc)+1) = w; + asWORD w = ReadEncodedUInt16(); + *(((asWORD *)bc) + 1) = w; bc++; } break; - case asBCTYPE_rW_DW_ARG: - case asBCTYPE_wW_DW_ARG: - case asBCTYPE_W_DW_ARG: + case asBCTYPE_rW_DW_ARG: + case asBCTYPE_wW_DW_ARG: + case asBCTYPE_W_DW_ARG: { - *(asBYTE*)(bc) = b; + *(asBYTE *)(bc) = b; // Read the word argument - asWORD w = ReadEncodedUInt16(); - *(((asWORD*)bc)+1) = w; + asWORD w = ReadEncodedUInt16(); + *(((asWORD *)bc) + 1) = w; bc++; // Read the dword argument *bc++ = ReadEncodedUInt(); } break; - case asBCTYPE_DW_ARG: + case asBCTYPE_DW_ARG: { - *(asBYTE*)(bc) = b; + *(asBYTE *)(bc) = b; bc++; // Read the argument *bc++ = ReadEncodedUInt(); } break; - case asBCTYPE_DW_DW_ARG: + case asBCTYPE_DW_DW_ARG: { - *(asBYTE*)(bc) = b; + *(asBYTE *)(bc) = b; bc++; // Read the first argument @@ -2606,134 +2635,134 @@ void asCReader::ReadByteCode(asCScriptFunction *func) *bc++ = ReadEncodedUInt(); } break; - case asBCTYPE_wW_rW_rW_ARG: + case asBCTYPE_wW_rW_rW_ARG: { - *(asBYTE*)(bc) = b; + *(asBYTE *)(bc) = b; // Read the first argument - asWORD w = ReadEncodedUInt16(); - *(((asWORD*)bc)+1) = w; + asWORD w = ReadEncodedUInt16(); + *(((asWORD *)bc) + 1) = w; bc++; // Read the second argument - w = ReadEncodedUInt16(); - *(asWORD*)bc = w; + w = ReadEncodedUInt16(); + *(asWORD *)bc = w; // Read the third argument - w = ReadEncodedUInt16(); - *(((asWORD*)bc)+1) = w; + w = ReadEncodedUInt16(); + *(((asWORD *)bc) + 1) = w; bc++; } break; - case asBCTYPE_wW_rW_ARG: - case asBCTYPE_rW_rW_ARG: - case asBCTYPE_wW_W_ARG: - case asBCTYPE_W_rW_ARG: + case asBCTYPE_wW_rW_ARG: + case asBCTYPE_rW_rW_ARG: + case asBCTYPE_wW_W_ARG: + case asBCTYPE_W_rW_ARG: { - *(asBYTE*)(bc) = b; + *(asBYTE *)(bc) = b; // Read the first argument - asWORD w = ReadEncodedUInt16(); - *(((asWORD*)bc)+1) = w; + asWORD w = ReadEncodedUInt16(); + *(((asWORD *)bc) + 1) = w; bc++; // Read the second argument - w = ReadEncodedUInt16(); - *(asWORD*)bc = w; + w = ReadEncodedUInt16(); + *(asWORD *)bc = w; bc++; } break; - case asBCTYPE_wW_rW_DW_ARG: - case asBCTYPE_rW_W_DW_ARG: + case asBCTYPE_wW_rW_DW_ARG: + case asBCTYPE_rW_W_DW_ARG: { - *(asBYTE*)(bc) = b; + *(asBYTE *)(bc) = b; // Read the first argument - asWORD w = ReadEncodedUInt16(); - *(((asWORD*)bc)+1) = w; + asWORD w = ReadEncodedUInt16(); + *(((asWORD *)bc) + 1) = w; bc++; // Read the second argument - w = ReadEncodedUInt16(); - *(asWORD*)bc = w; + w = ReadEncodedUInt16(); + *(asWORD *)bc = w; bc++; // Read the third argument asDWORD dw = ReadEncodedUInt(); - *bc++ = dw; + *bc++ = dw; } break; - case asBCTYPE_QW_ARG: + case asBCTYPE_QW_ARG: { - *(asBYTE*)(bc) = b; + *(asBYTE *)(bc) = b; bc++; // Read the argument - asQWORD qw = ReadEncodedUInt64(); - *(asQWORD*)bc = qw; - bc += 2; + asQWORD qw = ReadEncodedUInt64(); + *(asQWORD *)bc = qw; + bc += 2; } break; - case asBCTYPE_QW_DW_ARG: + case asBCTYPE_QW_DW_ARG: { - *(asBYTE*)(bc) = b; + *(asBYTE *)(bc) = b; bc++; // Read the first argument - asQWORD qw = ReadEncodedUInt64(); - *(asQWORD*)bc = qw; - bc += 2; + asQWORD qw = ReadEncodedUInt64(); + *(asQWORD *)bc = qw; + bc += 2; // Read the second argument asDWORD dw = ReadEncodedUInt(); - *bc++ = dw; + *bc++ = dw; } break; - case asBCTYPE_W_QW_DW_ARG: + case asBCTYPE_W_QW_DW_ARG: { - *(asBYTE*)(bc) = b; + *(asBYTE *)(bc) = b; // Read the first argument - asWORD w = ReadEncodedUInt16(); - *(((asWORD*)bc) + 1) = w; + asWORD w = ReadEncodedUInt16(); + *(((asWORD *)bc) + 1) = w; bc++; // Read the second argument - asQWORD qw = ReadEncodedUInt64(); - *(asQWORD*)bc = qw; - bc += 2; + asQWORD qw = ReadEncodedUInt64(); + *(asQWORD *)bc = qw; + bc += 2; // Read the third argument asDWORD dw = ReadEncodedUInt(); - *bc++ = dw; + *bc++ = dw; } break; - case asBCTYPE_rW_QW_ARG: - case asBCTYPE_wW_QW_ARG: + case asBCTYPE_rW_QW_ARG: + case asBCTYPE_wW_QW_ARG: { - *(asBYTE*)(bc) = b; + *(asBYTE *)(bc) = b; // Read the first argument - asWORD w = ReadEncodedUInt16(); - *(((asWORD*)bc)+1) = w; + asWORD w = ReadEncodedUInt16(); + *(((asWORD *)bc) + 1) = w; bc++; // Read the argument - asQWORD qw = ReadEncodedUInt64(); - *(asQWORD*)bc = qw; - bc += 2; + asQWORD qw = ReadEncodedUInt64(); + *(asQWORD *)bc = qw; + bc += 2; } break; - case asBCTYPE_rW_DW_DW_ARG: - case asBCTYPE_W_DW_DW_ARG: + case asBCTYPE_rW_DW_DW_ARG: + case asBCTYPE_W_DW_DW_ARG: { - *(asBYTE*)(bc) = b; + *(asBYTE *)(bc) = b; // Read the 1st argument - asWORD w = ReadEncodedUInt16(); - *(((asWORD*)bc)+1) = w; + asWORD w = ReadEncodedUInt16(); + *(((asWORD *)bc) + 1) = w; bc++; // Read the 2nd argument @@ -2743,27 +2772,34 @@ void asCReader::ReadByteCode(asCScriptFunction *func) *bc++ = ReadEncodedUInt(); } break; - default: + default: { // This should never happen asASSERT(false); // Read the next 3 bytes - asDWORD c; asBYTE t; + asDWORD c; + asBYTE t; #if defined(AS_BIG_ENDIAN) c = b << 24; - ReadData(&t, 1); c += t << 16; - ReadData(&t, 1); c += t << 8; - ReadData(&t, 1); c += t; + ReadData(&t, 1); + c += t << 16; + ReadData(&t, 1); + c += t << 8; + ReadData(&t, 1); + c += t; #else c = b; - ReadData(&t, 1); c += t << 8; - ReadData(&t, 1); c += t << 16; - ReadData(&t, 1); c += t << 24; + ReadData(&t, 1); + c += t << 8; + ReadData(&t, 1); + c += t << 16; + ReadData(&t, 1); + c += t << 24; #endif *bc++ = c; - c = *(asBYTE*)&c; + c = *(asBYTE *)&c; // Read the bc as is for( int n = 1; n < asBCTypeSize[asBCInfo[c].type]; n++ ) @@ -2802,9 +2838,9 @@ void asCReader::ReadUsedGlobalProps() for( int n = 0; n < c; n++ ) { - asCString name, ns; + asCString name, ns; asCDataType type; - char moduleProp; + char moduleProp; ReadString(&name); ReadString(&ns); @@ -2859,8 +2895,8 @@ void asCReader::ReadUsedObjectProps() if( objType->properties[p]->name == name ) { usedObjectProperties[n].objType = objType; - usedObjectProperties[n].prop = objType->properties[p]; - found = true; + usedObjectProperties[n].prop = objType->properties[p]; + found = true; break; } } @@ -2875,15 +2911,15 @@ void asCReader::ReadUsedObjectProps() short asCReader::FindObjectPropOffset(asWORD index) { - if (lastCompositeProp) + if( lastCompositeProp ) { - if (index != 0) + if( index != 0 ) { Error(TXT_INVALID_BYTECODE_d); return 0; } - short offset = (short)lastCompositeProp->byteOffset; + short offset = (short)lastCompositeProp->byteOffset; lastCompositeProp = 0; return offset; } @@ -2894,7 +2930,7 @@ short asCReader::FindObjectPropOffset(asWORD index) return 0; } - if (usedObjectProperties[index].prop->compositeOffset || usedObjectProperties[index].prop->isCompositeIndirect) + if( usedObjectProperties[index].prop->compositeOffset || usedObjectProperties[index].prop->isCompositeIndirect ) { lastCompositeProp = usedObjectProperties[index].prop; return (short)lastCompositeProp->compositeOffset; @@ -2921,14 +2957,14 @@ void asCReader::TranslateFunction(asCScriptFunction *func) asASSERT( func->scriptData ); // Pre-compute the size of each instruction in order to translate jump offsets - asUINT n; - asDWORD *bc = func->scriptData->byteCode.AddressOf(); - asUINT bcLength = (asUINT)func->scriptData->byteCode.GetLength(); + asUINT n; + asDWORD *bc = func->scriptData->byteCode.AddressOf(); + asUINT bcLength = (asUINT)func->scriptData->byteCode.GetLength(); asCArray bcSizes(bcLength); asCArray instructionNbrToPos(bcLength); for( n = 0; n < bcLength; ) { - int c = *(asBYTE*)&bc[n]; + int c = *(asBYTE *)&bc[n]; asUINT size = asBCTypeSize[asBCInfo[c].type]; if( size == 0 ) { @@ -2943,57 +2979,57 @@ void asCReader::TranslateFunction(asCScriptFunction *func) asUINT bcNum = 0; for( n = 0; n < bcLength; bcNum++ ) { - int c = *(asBYTE*)&bc[n]; + int c = *(asBYTE *)&bc[n]; if( c == asBC_REFCPY || - c == asBC_RefCpyV || - c == asBC_OBJTYPE ) + c == asBC_RefCpyV || + c == asBC_OBJTYPE ) { // Translate the index to the true object type - asPWORD *ot = (asPWORD*)&bc[n+1]; - *(asCObjectType**)ot = CastToObjectType(FindType(int(*ot))); + asPWORD *ot = (asPWORD *)&bc[n + 1]; + *(asCObjectType **)ot = CastToObjectType(FindType(int(*ot))); } else if( c == asBC_TYPEID || - c == asBC_Cast ) + c == asBC_Cast ) { // Translate the index to the type id - int *tid = (int*)&bc[n+1]; - *tid = FindTypeId(*tid); + int *tid = (int *)&bc[n + 1]; + *tid = FindTypeId(*tid); } else if( c == asBC_ADDSi || - c == asBC_LoadThisR ) + c == asBC_LoadThisR ) { // Translate the index to the type id - int *tid = (int*)&bc[n+1]; - *tid = FindTypeId(*tid); + int *tid = (int *)&bc[n + 1]; + *tid = FindTypeId(*tid); // Translate the prop index into the property offset - *(((short*)&bc[n])+1) = FindObjectPropOffset(*(((short*)&bc[n])+1)); + *(((short *)&bc[n]) + 1) = FindObjectPropOffset(*(((short *)&bc[n]) + 1)); } else if( c == asBC_LoadRObjR || - c == asBC_LoadVObjR ) + c == asBC_LoadVObjR ) { // Translate the index to the type id - int *tid = (int*)&bc[n+2]; - *tid = FindTypeId(*tid); + int *tid = (int *)&bc[n + 2]; + *tid = FindTypeId(*tid); asCObjectType *ot = engine->GetObjectTypeFromTypeId(*tid); if( ot && (ot->flags & asOBJ_LIST_PATTERN) ) { // List patterns have a different way of adjusting the offsets - SListAdjuster *listAdj = listAdjusters[listAdjusters.GetLength()-1]; - *(((short*)&bc[n])+2) = (short)listAdj->AdjustOffset(*(((short*)&bc[n])+2)); + SListAdjuster *listAdj = listAdjusters[listAdjusters.GetLength() - 1]; + *(((short *)&bc[n]) + 2) = (short)listAdj->AdjustOffset(*(((short *)&bc[n]) + 2)); } else { // Translate the prop index into the property offset - *(((short*)&bc[n])+2) = FindObjectPropOffset(*(((short*)&bc[n])+2)); + *(((short *)&bc[n]) + 2) = FindObjectPropOffset(*(((short *)&bc[n]) + 2)); } } else if( c == asBC_COPY ) { // Translate the index to the type id - int *tid = (int*)&bc[n+1]; - *tid = FindTypeId(*tid); + int *tid = (int *)&bc[n + 1]; + *tid = FindTypeId(*tid); // COPY is used to copy POD types that don't have the opAssign method. It is // also used to copy references to scoped types during variable initializations. @@ -3023,13 +3059,13 @@ void asCReader::TranslateFunction(asCScriptFunction *func) asBC_WORDARG0(&bc[n]) = dw; } else if( c == asBC_CALL || - c == asBC_CALLINTF || - c == asBC_CALLSYS || - c == asBC_Thiscall1 ) + c == asBC_CALLINTF || + c == asBC_CALLSYS || + c == asBC_Thiscall1 ) { // Translate the index to the func id - int *fid = (int*)&bc[n+1]; - asCScriptFunction *f = FindFunction(*fid); + int *fid = (int *)&bc[n + 1]; + asCScriptFunction *f = FindFunction(*fid); if( f ) *fid = f->id; else @@ -3041,21 +3077,21 @@ void asCReader::TranslateFunction(asCScriptFunction *func) else if( c == asBC_FuncPtr ) { // Translate the index to the func pointer - asPWORD *fid = (asPWORD*)&bc[n+1]; - *fid = (asPWORD)FindFunction(int(*fid)); + asPWORD *fid = (asPWORD *)&bc[n + 1]; + *fid = (asPWORD)FindFunction(int(*fid)); } else if( c == asBC_ALLOC ) { // Translate the index to the true object type - asPWORD *arg = (asPWORD*)&bc[n+1]; - *(asCObjectType**)arg = CastToObjectType(FindType(int(*arg))); + asPWORD *arg = (asPWORD *)&bc[n + 1]; + *(asCObjectType **)arg = CastToObjectType(FindType(int(*arg))); // The constructor function id must be translated, unless it is zero - int *fid = (int*)&bc[n+1+AS_PTR_SIZE]; + int *fid = (int *)&bc[n + 1 + AS_PTR_SIZE]; if( *fid != 0 ) { // Subtract 1 from the id, as it was incremented during the writing - asCScriptFunction *f = FindFunction(*fid-1); + asCScriptFunction *f = FindFunction(*fid - 1); if( f ) *fid = f->id; else @@ -3073,7 +3109,7 @@ void asCReader::TranslateFunction(asCScriptFunction *func) else if( c == asBC_CALLBND ) { // Translate the function id - asUINT *fid = (asUINT*)&bc[n+1]; + asUINT *fid = (asUINT *)&bc[n + 1]; if( *fid < module->m_bindInformations.GetLength() ) { sBindInfo *bi = module->m_bindInformations[*fid]; @@ -3091,21 +3127,21 @@ void asCReader::TranslateFunction(asCScriptFunction *func) return; } } - else if( c == asBC_PGA || - c == asBC_PshGPtr || - c == asBC_LDG || - c == asBC_PshG4 || - c == asBC_LdGRdR4 || - c == asBC_CpyGtoV4 || - c == asBC_CpyVtoG4 || - c == asBC_SetG4 ) + else if( c == asBC_PGA || + c == asBC_PshGPtr || + c == asBC_LDG || + c == asBC_PshG4 || + c == asBC_LdGRdR4 || + c == asBC_CpyGtoV4 || + c == asBC_CpyVtoG4 || + c == asBC_SetG4 ) { // Translate the index to pointer - asPWORD *index = (asPWORD*)&bc[n + 1]; - if ((*index & 1)) + asPWORD *index = (asPWORD *)&bc[n + 1]; + if( (*index & 1) ) { - if ((asUINT(*index)>>1) < usedGlobalProperties.GetLength()) - *(void**)index = usedGlobalProperties[asUINT(*index)>>1]; + if( (asUINT(*index) >> 1) < usedGlobalProperties.GetLength() ) + *(void **)index = usedGlobalProperties[asUINT(*index) >> 1]; else { Error(TXT_INVALID_BYTECODE_d); @@ -3117,8 +3153,8 @@ void asCReader::TranslateFunction(asCScriptFunction *func) // Only PGA and PshGPtr can hold string constants asASSERT(c == asBC_PGA || c == asBC_PshGPtr); - if ((asUINT(*index)>>1) < usedStringConstants.GetLength()) - *(void**)index = usedStringConstants[asUINT(*index)>>1]; + if( (asUINT(*index) >> 1) < usedStringConstants.GetLength() ) + *(void **)index = usedStringConstants[asUINT(*index) >> 1]; else { Error(TXT_INVALID_BYTECODE_d); @@ -3126,24 +3162,24 @@ void asCReader::TranslateFunction(asCScriptFunction *func) } } } - else if( c == asBC_JMP || - c == asBC_JZ || - c == asBC_JNZ || - c == asBC_JLowZ || - c == asBC_JLowNZ || - c == asBC_JS || - c == asBC_JNS || - c == asBC_JP || - c == asBC_JNP ) // The JMPP instruction doesn't need modification + else if( c == asBC_JMP || + c == asBC_JZ || + c == asBC_JNZ || + c == asBC_JLowZ || + c == asBC_JLowNZ || + c == asBC_JS || + c == asBC_JNS || + c == asBC_JP || + c == asBC_JNP ) // The JMPP instruction doesn't need modification { // Get the offset - int offset = int(bc[n+1]); + int offset = int(bc[n + 1]); // Count the instruction sizes to the destination instruction int size = 0; if( offset >= 0 ) // If moving ahead, then start from next instruction - for( asUINT num = bcNum+1; offset-- > 0; num++ ) + for( asUINT num = bcNum + 1; offset-- > 0; num++ ) size += bcSizes[num]; else // If moving backwards, then start at current instruction @@ -3151,7 +3187,7 @@ void asCReader::TranslateFunction(asCScriptFunction *func) size -= bcSizes[num]; // The size is dword offset - bc[n+1] = size; + bc[n + 1] = size; } else if( c == asBC_AllocMem ) { @@ -3171,10 +3207,10 @@ void asCReader::TranslateFunction(asCScriptFunction *func) else if( c == asBC_FREE ) { // Translate the index to the true object type - asPWORD *pot = (asPWORD*)&bc[n+1]; - *(asCObjectType**)pot = CastToObjectType(FindType(int(*pot))); + asPWORD *pot = (asPWORD *)&bc[n + 1]; + *(asCObjectType **)pot = CastToObjectType(FindType(int(*pot))); - asCObjectType *ot = *(asCObjectType**)pot; + asCObjectType *ot = *(asCObjectType **)pot; if( ot && (ot->flags & asOBJ_LIST_PATTERN) ) { if( listAdjusters.GetLength() == 0 ) @@ -3192,29 +3228,29 @@ void asCReader::TranslateFunction(asCScriptFunction *func) else if( c == asBC_SetListSize ) { // Adjust the offset in the list where the size is informed - SListAdjuster *listAdj = listAdjusters[listAdjusters.GetLength()-1]; - bc[n+1] = listAdj->AdjustOffset(bc[n+1]); + SListAdjuster *listAdj = listAdjusters[listAdjusters.GetLength() - 1]; + bc[n + 1] = listAdj->AdjustOffset(bc[n + 1]); // Inform the list adjuster how many values will be repeated - listAdj->SetRepeatCount(bc[n+2]); + listAdj->SetRepeatCount(bc[n + 2]); } else if( c == asBC_PshListElmnt ) { // Adjust the offset in the list where the size is informed - SListAdjuster *listAdj = listAdjusters[listAdjusters.GetLength()-1]; - bc[n+1] = listAdj->AdjustOffset(bc[n+1]); + SListAdjuster *listAdj = listAdjusters[listAdjusters.GetLength() - 1]; + bc[n + 1] = listAdj->AdjustOffset(bc[n + 1]); } else if( c == asBC_SetListType ) { // Adjust the offset in the list where the typeid is informed - SListAdjuster *listAdj = listAdjusters[listAdjusters.GetLength()-1]; - bc[n+1] = listAdj->AdjustOffset(bc[n+1]); + SListAdjuster *listAdj = listAdjusters[listAdjusters.GetLength() - 1]; + bc[n + 1] = listAdj->AdjustOffset(bc[n + 1]); // Translate the type id - bc[n+2] = FindTypeId(bc[n+2]); + bc[n + 2] = FindTypeId(bc[n + 2]); // Inform the list adjuster the type id of the next element - listAdj->SetNextType(bc[n+2]); + listAdj->SetNextType(bc[n + 2]); } n += asBCTypeSize[asBCInfo[c].type]; @@ -3227,33 +3263,33 @@ void asCReader::TranslateFunction(asCScriptFunction *func) bc = func->scriptData->byteCode.AddressOf(); for( n = 0; n < bcLength; ) { - int c = *(asBYTE*)&bc[n]; + int c = *(asBYTE *)&bc[n]; switch( asBCInfo[c].type ) { - case asBCTYPE_wW_ARG: - case asBCTYPE_rW_DW_ARG: - case asBCTYPE_wW_QW_ARG: - case asBCTYPE_rW_ARG: - case asBCTYPE_wW_DW_ARG: - case asBCTYPE_wW_W_ARG: - case asBCTYPE_rW_QW_ARG: - case asBCTYPE_rW_W_DW_ARG: - case asBCTYPE_rW_DW_DW_ARG: + case asBCTYPE_wW_ARG: + case asBCTYPE_rW_DW_ARG: + case asBCTYPE_wW_QW_ARG: + case asBCTYPE_rW_ARG: + case asBCTYPE_wW_DW_ARG: + case asBCTYPE_wW_W_ARG: + case asBCTYPE_rW_QW_ARG: + case asBCTYPE_rW_W_DW_ARG: + case asBCTYPE_rW_DW_DW_ARG: { asBC_SWORDARG0(&bc[n]) = (short)AdjustStackPosition(asBC_SWORDARG0(&bc[n])); } break; - case asBCTYPE_wW_rW_ARG: - case asBCTYPE_wW_rW_DW_ARG: - case asBCTYPE_rW_rW_ARG: + case asBCTYPE_wW_rW_ARG: + case asBCTYPE_wW_rW_DW_ARG: + case asBCTYPE_rW_rW_ARG: { asBC_SWORDARG0(&bc[n]) = (short)AdjustStackPosition(asBC_SWORDARG0(&bc[n])); asBC_SWORDARG1(&bc[n]) = (short)AdjustStackPosition(asBC_SWORDARG1(&bc[n])); } break; - case asBCTYPE_wW_rW_rW_ARG: + case asBCTYPE_wW_rW_rW_ARG: { asBC_SWORDARG0(&bc[n]) = (short)AdjustStackPosition(asBC_SWORDARG0(&bc[n])); asBC_SWORDARG1(&bc[n]) = (short)AdjustStackPosition(asBC_SWORDARG1(&bc[n])); @@ -3261,15 +3297,15 @@ void asCReader::TranslateFunction(asCScriptFunction *func) } break; - case asBCTYPE_W_rW_ARG: + case asBCTYPE_W_rW_ARG: { asBC_SWORDARG1(&bc[n]) = (short)AdjustStackPosition(asBC_SWORDARG1(&bc[n])); } break; - default: - // The other types don't treat variables so won't be modified - break; + default: + // The other types don't treat variables so won't be modified + break; } n += asBCTypeSize[asBCInfo[c].type]; @@ -3282,7 +3318,7 @@ void asCReader::TranslateFunction(asCScriptFunction *func) for( n = 0; n < func->scriptData->variables.GetLength(); n++ ) { func->scriptData->variables[n]->declaredAtProgramPos = instructionNbrToPos[func->scriptData->variables[n]->declaredAtProgramPos]; - func->scriptData->variables[n]->stackOffset = AdjustStackPosition(func->scriptData->variables[n]->stackOffset); + func->scriptData->variables[n]->stackOffset = AdjustStackPosition(func->scriptData->variables[n]->stackOffset); } // Adjust the get offsets. This must be done in the second iteration because @@ -3295,7 +3331,7 @@ void asCReader::TranslateFunction(asCScriptFunction *func) bc = func->scriptData->byteCode.AddressOf(); for( n = 0; n < bcLength; ) { - int c = *(asBYTE*)&bc[n]; + int c = *(asBYTE *)&bc[n]; if( c == asBC_GETREF || c == asBC_GETOBJ || @@ -3311,14 +3347,14 @@ void asCReader::TranslateFunction(asCScriptFunction *func) for( n = 0; n < func->scriptData->objVariableInfo.GetLength(); n++ ) { // The program position must be adjusted as it is stored in number of instructions - func->scriptData->objVariableInfo[n].programPos = instructionNbrToPos[func->scriptData->objVariableInfo[n].programPos]; + func->scriptData->objVariableInfo[n].programPos = instructionNbrToPos[func->scriptData->objVariableInfo[n].programPos]; func->scriptData->objVariableInfo[n].variableOffset = AdjustStackPosition(func->scriptData->objVariableInfo[n].variableOffset); } - for (n = 0; n < func->scriptData->tryCatchInfo.GetLength(); n++) + for( n = 0; n < func->scriptData->tryCatchInfo.GetLength(); n++ ) { - func->scriptData->tryCatchInfo[n].tryPos = instructionNbrToPos[func->scriptData->tryCatchInfo[n].tryPos]; - func->scriptData->tryCatchInfo[n].catchPos = instructionNbrToPos[func->scriptData->tryCatchInfo[n].catchPos]; + func->scriptData->tryCatchInfo[n].tryPos = instructionNbrToPos[func->scriptData->tryCatchInfo[n].tryPos]; + func->scriptData->tryCatchInfo[n].catchPos = instructionNbrToPos[func->scriptData->tryCatchInfo[n].catchPos]; func->scriptData->tryCatchInfo[n].stackSize = AdjustStackPosition(func->scriptData->tryCatchInfo[n].stackSize); } @@ -3332,15 +3368,14 @@ void asCReader::TranslateFunction(asCScriptFunction *func) CalculateStackNeeded(func); } -asCReader::SListAdjuster::SListAdjuster(asCReader* rd, asDWORD* bc, asCObjectType* listType) : - reader(rd), allocMemBC(bc), maxOffset(0), patternType(listType), repeatCount(0), lastOffset(-1), nextOffset(0), lastAdjustedOffset(0), patternNode(0), nextTypeId(-1) +asCReader::SListAdjuster::SListAdjuster(asCReader *rd, asDWORD *bc, asCObjectType *listType) : reader(rd), allocMemBC(bc), maxOffset(0), patternType(listType), repeatCount(0), lastOffset(-1), nextOffset(0), lastAdjustedOffset(0), patternNode(0), nextTypeId(-1) { asASSERT( patternType && (patternType->flags & asOBJ_LIST_PATTERN) ); // Find the first expected value in the list - if (patternType && (patternType->flags & asOBJ_LIST_PATTERN) ) + if( patternType && (patternType->flags & asOBJ_LIST_PATTERN) ) { - asSListPatternNode* node = patternType->engine->scriptFunctions[patternType->templateSubTypes[0].GetBehaviour()->listFactory]->listPattern; + asSListPatternNode *node = patternType->engine->scriptFunctions[patternType->templateSubTypes[0].GetBehaviour()->listFactory]->listPattern; asASSERT(node && node->type == asLPT_START); patternNode = node->next; } @@ -3360,7 +3395,7 @@ int asCReader::SListAdjuster::AdjustOffset(int offset) if( lastOffset == offset ) return lastAdjustedOffset; - lastOffset = offset; + lastOffset = offset; lastAdjustedOffset = maxOffset; // What is being expected at this position? @@ -3369,18 +3404,18 @@ int asCReader::SListAdjuster::AdjustOffset(int offset) // Align the offset to 4 bytes boundary if( maxOffset & 0x3 ) { - maxOffset += 4 - (maxOffset & 0x3); - lastAdjustedOffset = maxOffset; + maxOffset += 4 - (maxOffset & 0x3); + lastAdjustedOffset = maxOffset; } // Don't move the patternNode yet because the caller must make a call to SetRepeatCount too - maxOffset += 4; - nextOffset = offset+1; + maxOffset += 4; + nextOffset = offset + 1; return lastAdjustedOffset; } else if( patternNode->type == asLPT_TYPE ) { - const asCDataType &dt = reinterpret_cast(patternNode)->dataType; + const asCDataType &dt = reinterpret_cast(patternNode)->dataType; if( dt.GetTokenType() == ttQuestion ) { if( nextTypeId != -1 ) @@ -3389,17 +3424,17 @@ int asCReader::SListAdjuster::AdjustOffset(int offset) repeatCount--; asCDataType nextdt = patternType->engine->GetDataTypeFromTypeId(nextTypeId); - asUINT size; - if(nextdt.IsObjectHandle() || (nextdt.GetTypeInfo() && (nextdt.GetTypeInfo()->flags & asOBJ_REF)) ) - size = AS_PTR_SIZE*4; + asUINT size; + if( nextdt.IsObjectHandle() || (nextdt.GetTypeInfo() && (nextdt.GetTypeInfo()->flags & asOBJ_REF)) ) + size = AS_PTR_SIZE * 4; else size = nextdt.GetSizeInMemoryBytes(); // Align the offset to 4 bytes boundary if( size >= 4 && (maxOffset & 0x3) ) { - maxOffset += 4 - (maxOffset & 0x3); - lastAdjustedOffset = maxOffset; + maxOffset += 4 - (maxOffset & 0x3); + lastAdjustedOffset = maxOffset; } // Only move the patternNode if we're not expecting any more repeated entries @@ -3408,8 +3443,8 @@ int asCReader::SListAdjuster::AdjustOffset(int offset) nextTypeId = -1; - maxOffset += size; - nextOffset = offset+1; + maxOffset += size; + nextOffset = offset + 1; return lastAdjustedOffset; } else @@ -3417,13 +3452,13 @@ int asCReader::SListAdjuster::AdjustOffset(int offset) // Align the offset to 4 bytes boundary if( maxOffset & 0x3 ) { - maxOffset += 4 - (maxOffset & 0x3); - lastAdjustedOffset = maxOffset; + maxOffset += 4 - (maxOffset & 0x3); + lastAdjustedOffset = maxOffset; } // The first adjustment is for the typeId - maxOffset += 4; - nextOffset = offset+1; + maxOffset += 4; + nextOffset = offset + 1; return lastAdjustedOffset; } } @@ -3432,7 +3467,7 @@ int asCReader::SListAdjuster::AdjustOffset(int offset) // Determine the size of the element asUINT size; if( dt.IsObjectHandle() || (dt.GetTypeInfo() && (dt.GetTypeInfo()->flags & asOBJ_REF)) ) - size = AS_PTR_SIZE*4; + size = AS_PTR_SIZE * 4; else size = dt.GetSizeInMemoryBytes(); @@ -3446,16 +3481,16 @@ int asCReader::SListAdjuster::AdjustOffset(int offset) if( size >= 4 && (maxOffset & 0x3) ) maxOffset += 4 - (maxOffset & 0x3); - lastAdjustedOffset = maxOffset; - nextOffset += 1; - maxOffset += size; + lastAdjustedOffset = maxOffset; + nextOffset += 1; + maxOffset += size; } // Only move the patternNode if we're not expecting any more repeated entries if( repeatCount == 0 ) patternNode = patternNode->next; - nextOffset = offset+1; + nextOffset = offset + 1; return lastAdjustedOffset; } } @@ -3480,7 +3515,7 @@ int asCReader::SListAdjuster::AdjustOffset(int offset) return 0; } - SInfo info = stack.PopLast(); + SInfo info = stack.PopLast(); repeatCount = info.repeatCount; if( repeatCount ) patternNode = info.startNode; @@ -3532,7 +3567,7 @@ void asCReader::CalculateStackNeeded(asCScriptFunction *func) // Clear the known stack size for each bytecode asCArray stackSize; stackSize.SetLength(func->scriptData->byteCode.GetLength()); - memset(&stackSize[0], -1, stackSize.GetLength()*4); + memset(&stackSize[0], -1, stackSize.GetLength() * 4); // Add the first instruction to the list of unchecked code // paths and set the stack size at that instruction to variableSpace @@ -3543,10 +3578,10 @@ void asCReader::CalculateStackNeeded(asCScriptFunction *func) // Go through each of the code paths for( asUINT p = 0; p < paths.GetLength(); ++p ) { - asUINT pos = paths[p]; - int currStackSize = stackSize[pos]; + asUINT pos = paths[p]; + int currStackSize = stackSize[pos]; - asBYTE bc = *(asBYTE*)&func->scriptData->byteCode[pos]; + asBYTE bc = *(asBYTE *)&func->scriptData->byteCode[pos]; if( bc == asBC_RET ) continue; @@ -3556,19 +3591,19 @@ void asCReader::CalculateStackNeeded(asCScriptFunction *func) { // Determine the true delta from the instruction arguments if( bc == asBC_CALL || - bc == asBC_CALLSYS || - bc == asBC_Thiscall1 || - bc == asBC_CALLBND || - bc == asBC_ALLOC || - bc == asBC_CALLINTF || - bc == asBC_CallPtr ) + bc == asBC_CALLSYS || + bc == asBC_Thiscall1 || + bc == asBC_CALLBND || + bc == asBC_ALLOC || + bc == asBC_CALLINTF || + bc == asBC_CallPtr ) { asCScriptFunction *called = func->GetCalledFunction(pos); if( called ) { // For variadic functions we need to determine the number of arguments from the bytecode and calculate the stackInc accordingly - if (called->IsVariadic()) - { + if( called->IsVariadic() ) + { // Only these instructions can be used to call variadic functions asASSERT(bc == asBC_CALLSYS || bc == asBC_ALLOC || bc == asBC_CallPtr); @@ -3576,9 +3611,9 @@ void asCReader::CalculateStackNeeded(asCScriptFunction *func) int numArgs = asBC_WORDARG0(&func->scriptData->byteCode[pos]); // Calculate the actual size of arguments for this function call - stackInc = -(called->GetSpaceNeededForArguments() + // size of fixed arguments - (numArgs - int(called->parameterTypes.GetLength()))*called->parameterTypes[called->parameterTypes.GetLength()-1].GetSizeOnStackDWords() + // size of dynamic arguments - 1); // argument count + stackInc = -(called->GetSpaceNeededForArguments() + // size of fixed arguments + (numArgs - int(called->parameterTypes.GetLength())) * called->parameterTypes[called->parameterTypes.GetLength() - 1].GetSizeOnStackDWords() + // size of dynamic arguments + 1); // argument count } else stackInc = -called->GetSpaceNeededForArguments(); @@ -3605,8 +3640,8 @@ void asCReader::CalculateStackNeeded(asCScriptFunction *func) if( bc == asBC_JMP ) { // Find the label that we should jump to - int offset = asBC_INTARG(&func->scriptData->byteCode[pos]); - pos += 2 + offset; + int offset = asBC_INTARG(&func->scriptData->byteCode[pos]); + pos += 2 + offset; // Add the destination as a new path if( stackSize[pos] == -1 ) @@ -3618,10 +3653,10 @@ void asCReader::CalculateStackNeeded(asCScriptFunction *func) asASSERT(stackSize[pos] == currStackSize); continue; } - else if( bc == asBC_JZ || bc == asBC_JNZ || - bc == asBC_JLowZ || bc == asBC_JLowNZ || - bc == asBC_JS || bc == asBC_JNS || - bc == asBC_JP || bc == asBC_JNP ) + else if( bc == asBC_JZ || bc == asBC_JNZ || + bc == asBC_JLowZ || bc == asBC_JLowNZ || + bc == asBC_JS || bc == asBC_JNS || + bc == asBC_JP || bc == asBC_JNP ) { // Find the label that is being jumped to int offset = asBC_INTARG(&func->scriptData->byteCode[pos]); @@ -3652,7 +3687,7 @@ void asCReader::CalculateStackNeeded(asCScriptFunction *func) pos++; // Add all subsequent JMP instructions to the path - while( *(asBYTE*)&func->scriptData->byteCode[pos] == asBC_JMP ) + while( *(asBYTE *)&func->scriptData->byteCode[pos] == asBC_JMP ) { if( stackSize[pos] == -1 ) { @@ -3688,28 +3723,28 @@ void asCReader::CalculateAdjustmentByPos(asCScriptFunction *func) { // Adjust the offset of all negative variables (parameters) as // all pointers have been stored as having a size of 1 dword - asUINT n; + asUINT n; asCArray adjustments; - asUINT offset = 0; + asUINT offset = 0; if( func->objectType ) { adjustments.PushLast(offset); - adjustments.PushLast(1-AS_PTR_SIZE); + adjustments.PushLast(1 - AS_PTR_SIZE); offset += 1; } if( func->DoesReturnOnStack() ) { adjustments.PushLast(offset); - adjustments.PushLast(1-AS_PTR_SIZE); + adjustments.PushLast(1 - AS_PTR_SIZE); offset += 1; } for( n = 0; n < func->parameterTypes.GetLength(); n++ ) { if( !func->parameterTypes[n].IsPrimitive() || - func->parameterTypes[n].IsReference() ) + func->parameterTypes[n].IsReference() ) { adjustments.PushLast(offset); - adjustments.PushLast(1-AS_PTR_SIZE); + adjustments.PushLast(1 - AS_PTR_SIZE); offset += 1; } else @@ -3721,13 +3756,13 @@ void asCReader::CalculateAdjustmentByPos(asCScriptFunction *func) // Build look-up table with the adjustments for each stack position adjustNegativeStackByPos.SetLength(offset); - memset(adjustNegativeStackByPos.AddressOf(), 0, adjustNegativeStackByPos.GetLength()*sizeof(int)); - for( n = 0; n < adjustments.GetLength(); n+=2 ) + memset(adjustNegativeStackByPos.AddressOf(), 0, adjustNegativeStackByPos.GetLength() * sizeof(int)); + for( n = 0; n < adjustments.GetLength(); n += 2 ) { int pos = adjustments[n]; - int adjust = adjustments[n+1]; + int adjust = adjustments[n + 1]; - for( asUINT i = pos+1; i < adjustNegativeStackByPos.GetLength(); i++ ) + for( asUINT i = pos + 1; i < adjustNegativeStackByPos.GetLength(); i++ ) adjustNegativeStackByPos[i] += adjust; } @@ -3735,25 +3770,25 @@ void asCReader::CalculateAdjustmentByPos(asCScriptFunction *func) // It is necessary to adjust to the size according to the current platform. adjustments.SetLength(0); int highestPos = 0; - for (n = 0; n < func->scriptData->variables.GetLength(); n++) + for( n = 0; n < func->scriptData->variables.GetLength(); n++ ) { // Skip function parameters as these are adjusted by adjustNegativeStackByPos - if (func->scriptData->variables[n]->stackOffset <= 0) + if( func->scriptData->variables[n]->stackOffset <= 0 ) continue; asCDataType t = func->scriptData->variables[n]->type; - if (!t.IsObject() && !t.IsObjectHandle()) + if( !t.IsObject() && !t.IsObjectHandle() ) continue; // Determing the size of the variable currently occupies on the stack int size = AS_PTR_SIZE; - if (t.GetTypeInfo() && (t.GetTypeInfo()->GetFlags() & asOBJ_VALUE) && !func->scriptData->variables[n]->onHeap) + if( t.GetTypeInfo() && (t.GetTypeInfo()->GetFlags() & asOBJ_VALUE) && !func->scriptData->variables[n]->onHeap ) size = t.GetSizeInMemoryDWords(); // Check if type has a different size than stored - if (size > 1) + if( size > 1 ) { - if (func->scriptData->variables[n]->stackOffset > highestPos) + if( func->scriptData->variables[n]->stackOffset > highestPos ) highestPos = func->scriptData->variables[n]->stackOffset; adjustments.PushLast(func->scriptData->variables[n]->stackOffset); @@ -3762,14 +3797,14 @@ void asCReader::CalculateAdjustmentByPos(asCScriptFunction *func) } // Count position 0 too - adjustByPos.SetLength(highestPos+1); - memset(adjustByPos.AddressOf(), 0, adjustByPos.GetLength()*sizeof(int)); + adjustByPos.SetLength(highestPos + 1); + memset(adjustByPos.AddressOf(), 0, adjustByPos.GetLength() * sizeof(int)); // Build look-up table with the adjustments for each stack position - for( n = 0; n < adjustments.GetLength(); n+=2 ) + for( n = 0; n < adjustments.GetLength(); n += 2 ) { int pos = adjustments[n]; - int adjust = adjustments[n+1]; + int adjust = adjustments[n + 1]; // If multiple variables in different scope occupy the same position they must have the same size asASSERT(adjustByPos[pos] == 0 || adjustByPos[pos] == adjust); @@ -3778,10 +3813,10 @@ void asCReader::CalculateAdjustmentByPos(asCScriptFunction *func) } // Accumulate adjustments int adjust = adjustByPos[0]; - for (asUINT i = 1; i < adjustByPos.GetLength(); i++) + for( asUINT i = 1; i < adjustByPos.GetLength(); i++ ) { - adjust += adjustByPos[i]; - adjustByPos[i] = adjust; + adjust += adjustByPos[i]; + adjustByPos[i] = adjust; } } @@ -3791,7 +3826,7 @@ int asCReader::AdjustStackPosition(int pos) { // It can be higher for primitives allocated on top of highest object variable if( adjustByPos.GetLength() ) - pos += (short)adjustByPos[adjustByPos.GetLength()-1]; + pos += (short)adjustByPos[adjustByPos.GetLength() - 1]; } else if( pos >= 0 ) pos += (short)adjustByPos[pos]; @@ -3816,28 +3851,28 @@ int asCReader::AdjustGetOffset(int offset, asCScriptFunction *func, asDWORD prog // Find out which function that will be called // TODO: Can the asCScriptFunction::FindNextFunctionCalled be adapted so it can be reused here (support for asBC_ALLOC, asBC_REFCPY and asBC_COPY)? asCScriptFunction *calledFunc = 0; - int stackDelta = 0; + int stackDelta = 0; for( asUINT n = programPos; n < func->scriptData->byteCode.GetLength(); ) { - asBYTE bc = *(asBYTE*)&func->scriptData->byteCode[n]; + asBYTE bc = *(asBYTE *)&func->scriptData->byteCode[n]; if( bc == asBC_CALL || - bc == asBC_CALLSYS || - bc == asBC_Thiscall1 || - bc == asBC_CALLINTF || - bc == asBC_ALLOC || - bc == asBC_CALLBND || - bc == asBC_CallPtr ) + bc == asBC_CALLSYS || + bc == asBC_Thiscall1 || + bc == asBC_CALLINTF || + bc == asBC_ALLOC || + bc == asBC_CALLBND || + bc == asBC_CallPtr ) { // The alloc instruction allocates the object memory // so it doesn't take the this pointer as input - if (bc == asBC_ALLOC) + if( bc == asBC_ALLOC ) bcAlloc = true; calledFunc = func->GetCalledFunction(n); break; } else if( bc == asBC_REFCPY || - bc == asBC_COPY ) + bc == asBC_COPY ) { // In this case we know there is only 1 pointer on the stack above asASSERT( offset == 1 ); @@ -3859,8 +3894,8 @@ int asCReader::AdjustGetOffset(int offset, asCScriptFunction *func, asDWORD prog // Count the number of pointers pushed on the stack above the // current offset, and then adjust the offset accordingly - asUINT numPtrs = 0; - int currOffset = -stackDelta; + asUINT numPtrs = 0; + int currOffset = -stackDelta; if( offset > currOffset && calledFunc->GetObjectType() && !bcAlloc ) { currOffset++; @@ -3885,14 +3920,14 @@ int asCReader::AdjustGetOffset(int offset, asCScriptFunction *func, asDWORD prog currOffset++; #endif } - if (offset > currOffset && calledFunc->IsVariadic()) + if( offset > currOffset && calledFunc->IsVariadic() ) currOffset++; for( asUINT p = 0; p < calledFunc->parameterTypes.GetLength(); p++ ) { if( offset <= currOffset ) break; if( !calledFunc->parameterTypes[p].IsPrimitive() || - calledFunc->parameterTypes[p].IsReference() ) + calledFunc->parameterTypes[p].IsReference() ) { currOffset++; if( currOffset > 0 ) @@ -3915,28 +3950,28 @@ int asCReader::AdjustGetOffset(int offset, asCScriptFunction *func, asDWORD prog currOffset += calledFunc->parameterTypes[p].GetSizeOnStackDWords(); } } - if (offset > currOffset && calledFunc->IsVariadic()) + if( offset > currOffset && calledFunc->IsVariadic() ) { asCDataType variadicType = calledFunc->parameterTypes[calledFunc->parameterTypes.GetLength() - 1]; - for (;;) + for( ;; ) { - if (offset <= currOffset) break; + if( offset <= currOffset ) break; - if (!variadicType.IsPrimitive() || - variadicType.IsReference()) + if( !variadicType.IsPrimitive() || + variadicType.IsReference() ) { // objects and references are passed by pointer currOffset++; - if (currOffset > 0) + if( currOffset > 0 ) numPtrs++; #if AS_PTR_SIZE == 2 // For 64bit platforms it is necessary to increment the currOffset by one more // DWORD since the stackDelta was counting the full 64bit size of the pointer - else if (stackDelta) + else if( stackDelta ) currOffset++; #endif // The variable arg ? has an additional 32bit int with the typeid - if (variadicType.IsAnyType()) + if( variadicType.IsAnyType() ) currOffset += 1; } else @@ -3975,15 +4010,15 @@ asCTypeInfo *asCReader::FindType(int idx) #ifndef AS_NO_COMPILER -asCWriter::asCWriter(asCModule* _module, asIBinaryStream* _stream, asCScriptEngine* _engine, bool _stripDebug) - : module(_module), stream(_stream), engine(_engine), stripDebugInfo(_stripDebug), error(false), bytesWritten(0), lastWasComposite(false) +asCWriter::asCWriter(asCModule *_module, asIBinaryStream *_stream, asCScriptEngine *_engine, bool _stripDebug) + : module(_module), stream(_stream), engine(_engine), stripDebugInfo(_stripDebug), error(false), bytesWritten(0), lastWasComposite(false) { } int asCWriter::Error(const char *msg) { // Don't write if it has already been reported an error earlier - if (!error) + if( !error ) { asCString str; str.Format(msg, bytesWritten); @@ -3998,14 +4033,14 @@ int asCWriter::WriteData(const void *data, asUINT size) { asASSERT(size == 1 || size == 2 || size == 4 || size == 8); int ret = 0; -#if defined(AS_BIG_ENDIAN) + #if defined(AS_BIG_ENDIAN) for( asUINT n = 0; ret >= 0 && n < size; n++ ) - ret = stream->Write(((const asBYTE*)data)+n, 1); -#else - for( int n = size-1; ret >= 0 && n >= 0; n-- ) - ret = stream->Write(((const asBYTE*)data)+n, 1); -#endif - if (ret < 0) + ret = stream->Write(((const asBYTE *)data) + n, 1); + #else + for( int n = size - 1; ret >= 0 && n >= 0; n-- ) + ret = stream->Write(((const asBYTE *)data) + n, 1); + #endif + if( ret < 0 ) Error(TXT_UNEXPECTED_END_OF_FILE); bytesWritten += size; return ret; @@ -4138,7 +4173,7 @@ int asCWriter::Write() { TimeIt("globalFunctions"); - count = (int)module->m_globalFunctions.GetSize(); + count = (int)module->m_globalFunctions.GetSize(); asCSymbolTable::iterator funcIt = module->m_globalFunctions.List(); WriteEncodedInt64(count); while( funcIt ) @@ -4191,8 +4226,8 @@ int asCWriter::Write() int asCWriter::FindStringConstantIndex(void *str) { - asSMapNode *cursor = 0; - if (stringToIndexMap.MoveTo(&cursor, str)) + asSMapNode *cursor = 0; + if( stringToIndexMap.MoveTo(&cursor, str) ) return cursor->value; usedStringConstants.PushLast(str); @@ -4209,7 +4244,7 @@ void asCWriter::WriteUsedStringConstants() WriteEncodedInt64(count); asCString str; - for (asUINT i = 0; i < count; ++i) + for( asUINT i = 0; i < count; ++i ) { asUINT length; engine->stringFactory->GetRawStringData(usedStringConstants[i], 0, &length); @@ -4232,14 +4267,14 @@ void asCWriter::WriteUsedFunctions() // Write enough data to be able to uniquely identify the function upon load asCScriptFunction *func = usedFunctions[n]; - if(func) + if( func ) { // Is the function from the module or the application? c = func->module ? 'm' : 'a'; // Functions and methods that are shared should be stored as 's' as the bytecode // may be imported from other modules (even if the current module have received ownership) - if (c == 'm' && func->IsShared() ) + if( c == 'm' && func->IsShared() ) c = 's'; WriteData(&c, 1); @@ -4274,60 +4309,60 @@ void asCWriter::WriteFunctionSignature(asCScriptFunction *func) // Only write the inout flags if any of them are set // If the number of parameters is 0, then no need to save this - if (func->parameterTypes.GetLength() > 0) + if( func->parameterTypes.GetLength() > 0 ) { count = 0; - for (i = asUINT(func->inOutFlags.GetLength()); i > 0; i--) - if (func->inOutFlags[i - 1] != asTM_NONE) + for( i = asUINT(func->inOutFlags.GetLength()); i > 0; i-- ) + if( func->inOutFlags[i - 1] != asTM_NONE ) { count = i; break; } WriteEncodedInt64(count); - for (i = 0; i < count; ++i) + for( i = 0; i < count; ++i ) WriteEncodedInt64(func->inOutFlags[i]); } asUINT val = func->funcType; - if (func->templateSubTypes.GetLength()) + if( func->templateSubTypes.GetLength() ) val += 128; WriteEncodedInt64(val); // Write the default args, from last to first // If the number of parameters is 0, then no need to save this - if (func->parameterTypes.GetLength() > 0) + if( func->parameterTypes.GetLength() > 0 ) { count = 0; - for (i = (asUINT)func->defaultArgs.GetLength(); i-- > 0; ) - if (func->defaultArgs[i]) + for( i = (asUINT)func->defaultArgs.GetLength(); i-- > 0; ) + if( func->defaultArgs[i] ) count++; WriteEncodedInt64(count); - for (i = (asUINT)func->defaultArgs.GetLength(); i-- > 0; ) - if (func->defaultArgs[i]) + for( i = (asUINT)func->defaultArgs.GetLength(); i-- > 0; ) + if( func->defaultArgs[i] ) WriteString(func->defaultArgs[i]); } WriteTypeInfo(func->objectType); - // TODO: Only the Variadic trait must be saved for all - // function types. Can we store that bit somewhere else so it + // TODO: Only the Variadic trait must be saved for all + // function types. Can we store that bit somewhere else so it // is possible to save 1 byte for other types of functions/methods? - asBYTE b = 0; - b += func->IsReadOnly() ? 1 : 0; - b += func->IsPrivate() ? 2 : 0; - b += func->IsProtected() ? 4 : 0; - b += func->IsFinal() ? 8 : 0; - b += func->IsOverride() ? 16 : 0; - b += func->IsExplicit() ? 32 : 0; - b += func->IsProperty() ? 64 : 0; - b += func->IsVariadic() ? 128 : 0; + asBYTE b = 0; + b += func->IsReadOnly() ? 1 : 0; + b += func->IsPrivate() ? 2 : 0; + b += func->IsProtected() ? 4 : 0; + b += func->IsFinal() ? 8 : 0; + b += func->IsOverride() ? 16 : 0; + b += func->IsExplicit() ? 32 : 0; + b += func->IsProperty() ? 64 : 0; + b += func->IsVariadic() ? 128 : 0; WriteData(&b, 1); - if (!func->objectType) + if( !func->objectType ) { - if (func->funcType == asFUNC_FUNCDEF) + if( func->funcType == asFUNC_FUNCDEF ) { - if (func->nameSpace) + if( func->nameSpace ) { // This funcdef was declared as global entity b = 'n'; @@ -4347,15 +4382,15 @@ void asCWriter::WriteFunctionSignature(asCScriptFunction *func) } // Save the function template subtypes - if (func->templateSubTypes.GetLength()) + if( func->templateSubTypes.GetLength() ) { WriteEncodedInt64(func->templateSubTypes.GetLength()); - for (asUINT n = 0; n < func->templateSubTypes.GetLength(); n++) + for( asUINT n = 0; n < func->templateSubTypes.GetLength(); n++ ) WriteDataType(&func->templateSubTypes[n]); } } -void asCWriter::WriteFunction(asCScriptFunction* func) +void asCWriter::WriteFunction(asCScriptFunction *func) { char c; @@ -4392,23 +4427,23 @@ void asCWriter::WriteFunction(asCScriptFunction* func) if( func->funcType == asFUNC_SCRIPT ) { // Skip this for external shared entities - if (module->m_externalTypes.IndexOf(func->objectType) >= 0) + if( module->m_externalTypes.IndexOf(func->objectType) >= 0 ) return; - char bits = 0; - bits += func->IsShared() ? 1 : 0; - bits += func->dontCleanUpOnException ? 2 : 0; - if (module->m_externalFunctions.IndexOf(func) >= 0) + char bits = 0; + bits += func->IsShared() ? 1 : 0; + bits += func->dontCleanUpOnException ? 2 : 0; + if( module->m_externalFunctions.IndexOf(func) >= 0 ) bits += 4; - if (func->scriptData->objVariableInfo.GetLength()) + if( func->scriptData->objVariableInfo.GetLength() ) bits += 8; - if (func->scriptData->tryCatchInfo.GetLength()) + if( func->scriptData->tryCatchInfo.GetLength() ) bits += 16; bits += func->IsExplicit() ? 32 : 0; WriteData(&bits, 1); // For external shared functions the rest is not needed - if (bits & 4) + if( bits & 4 ) return; // Calculate the adjustment by position lookup table @@ -4419,10 +4454,10 @@ void asCWriter::WriteFunction(asCScriptFunction* func) asDWORD varSpace = AdjustStackPosition(func->scriptData->variableSpace); WriteEncodedInt64(varSpace); - if (bits & 8) + if( bits & 8 ) { WriteEncodedInt64((asUINT)func->scriptData->objVariableInfo.GetLength()); - for (i = 0; i < func->scriptData->objVariableInfo.GetLength(); ++i) + for( i = 0; i < func->scriptData->objVariableInfo.GetLength(); ++i ) { // The program position must be adjusted to be in number of instructions WriteEncodedInt64(bytecodeNbrByPos[func->scriptData->objVariableInfo[i].programPos]); @@ -4431,11 +4466,11 @@ void asCWriter::WriteFunction(asCScriptFunction* func) } } - if (bits & 16) + if( bits & 16 ) { // Write info on try/catch blocks WriteEncodedInt64((asUINT)func->scriptData->tryCatchInfo.GetLength()); - for (i = 0; i < func->scriptData->tryCatchInfo.GetLength(); ++i) + for( i = 0; i < func->scriptData->tryCatchInfo.GetLength(); ++i ) { // The program position must be adjusted to be in number of instructions WriteEncodedInt64(bytecodeNbrByPos[func->scriptData->tryCatchInfo[i].tryPos]); @@ -4487,7 +4522,7 @@ void asCWriter::WriteFunction(asCScriptFunction* func) WriteEncodedInt64((asUINT)func->scriptData->variables.GetLength()); for( i = 0; i < func->scriptData->variables.GetLength(); i++ ) { - if (!stripDebugInfo) + if( !stripDebugInfo ) { // The program position must be adjusted to be in number of instructions WriteEncodedInt64(bytecodeNbrByPos[func->scriptData->variables[i]->declaredAtProgramPos]); @@ -4531,11 +4566,11 @@ void asCWriter::WriteFunction(asCScriptFunction* func) } else if( func->funcType == asFUNC_FUNCDEF ) { - char bits = 0; - bits += func->IsShared() ? 1 : 0; - if (module->m_externalTypes.IndexOf(func->funcdefType) >= 0) + char bits = 0; + bits += func->IsShared() ? 1 : 0; + if( module->m_externalTypes.IndexOf(func->funcdefType) >= 0 ) bits += 2; - WriteData(&bits,1); + WriteData(&bits, 1); } } @@ -4568,10 +4603,10 @@ void asCWriter::WriteTypeDeclaration(asCTypeInfo *type, int phase) WriteString(&type->nameSpace->name); // external shared flag - if ((type->flags & asOBJ_SHARED)) + if( (type->flags & asOBJ_SHARED) ) { char c = ' '; - if (module->m_externalTypes.IndexOf(type) >= 0) + if( module->m_externalTypes.IndexOf(type) >= 0 ) c = 'e'; WriteData(&c, 1); } @@ -4579,13 +4614,13 @@ void asCWriter::WriteTypeDeclaration(asCTypeInfo *type, int phase) else if( phase == 2 ) { // external shared types doesn't need to save this - if ((type->flags & asOBJ_SHARED) && module->m_externalTypes.IndexOf(type) >= 0) + if( (type->flags & asOBJ_SHARED) && module->m_externalTypes.IndexOf(type) >= 0 ) return; - if(type->flags & asOBJ_ENUM ) + if( type->flags & asOBJ_ENUM ) { // underlying type - asCEnumType* t = CastToEnumType(type); + asCEnumType *t = CastToEnumType(type); WriteEncodedInt64(t->enumType.GetTokenType()); // enumValues[] @@ -4598,10 +4633,10 @@ void asCWriter::WriteTypeDeclaration(asCTypeInfo *type, int phase) WriteData(&t->enumValues[n]->value, t->GetSize()); } } - else if(type->flags & asOBJ_TYPEDEF ) + else if( type->flags & asOBJ_TYPEDEF ) { asCTypedefType *td = CastToTypedefType(type); - eTokenType t = td->aliasForType.GetTokenType(); + eTokenType t = td->aliasForType.GetTokenType(); WriteEncodedInt64(t); } else @@ -4660,7 +4695,7 @@ void asCWriter::WriteTypeDeclaration(asCTypeInfo *type, int phase) else if( phase == 3 ) { // external shared types doesn't need to save this - if ((type->flags & asOBJ_SHARED) && module->m_externalTypes.IndexOf(type) >= 0) + if( (type->flags & asOBJ_SHARED) && module->m_externalTypes.IndexOf(type) >= 0 ) return; // properties[] @@ -4671,7 +4706,7 @@ void asCWriter::WriteTypeDeclaration(asCTypeInfo *type, int phase) asUINT size = (asUINT)t->properties.GetLength(); WriteEncodedInt64(size); - for (asUINT n = 0; n < t->properties.GetLength(); n++) + for( asUINT n = 0; n < t->properties.GetLength(); n++ ) { WriteObjectProperty(t->properties[n]); } @@ -4680,89 +4715,126 @@ void asCWriter::WriteTypeDeclaration(asCTypeInfo *type, int phase) void asCWriter::WriteEncodedInt64(asINT64 i) { - asBYTE signBit = ( i & asINT64(1)<<63 ) ? 0x80 : 0; + asBYTE signBit = (i & asINT64(1) << 63) ? 0x80 : 0; if( signBit ) i = -i; asBYTE b; - if( i < (1<<6) ) - { - b = (asBYTE)(signBit + i); WriteData(&b, 1); - } - else if( i < (1<<13) ) - { - b = asBYTE(0x40 + signBit + (i >> 8)); WriteData(&b, 1); - b = asBYTE(i & 0xFF); WriteData(&b, 1); - } - else if( i < (1<<20) ) - { - b = asBYTE(0x60 + signBit + (i >> 16)); WriteData(&b, 1); - b = asBYTE((i >> 8) & 0xFF); WriteData(&b, 1); - b = asBYTE(i & 0xFF); WriteData(&b, 1); - } - else if( i < (1<<27) ) - { - b = asBYTE(0x70 + signBit + (i >> 24)); WriteData(&b, 1); - b = asBYTE((i >> 16) & 0xFF); WriteData(&b, 1); - b = asBYTE((i >> 8) & 0xFF); WriteData(&b, 1); - b = asBYTE(i & 0xFF); WriteData(&b, 1); - } - else if( i < (asINT64(1)<<34) ) - { - b = asBYTE(0x78 + signBit + (i >> 32)); WriteData(&b, 1); - b = asBYTE((i >> 24) & 0xFF); WriteData(&b, 1); - b = asBYTE((i >> 16) & 0xFF); WriteData(&b, 1); - b = asBYTE((i >> 8) & 0xFF); WriteData(&b, 1); - b = asBYTE(i & 0xFF); WriteData(&b, 1); - } - else if( i < (asINT64(1)<<41) ) - { - b = asBYTE(0x7C + signBit + (i >> 40)); WriteData(&b, 1); - b = asBYTE((i >> 32) & 0xFF); WriteData(&b, 1); - b = asBYTE((i >> 24) & 0xFF); WriteData(&b, 1); - b = asBYTE((i >> 16) & 0xFF); WriteData(&b, 1); - b = asBYTE((i >> 8) & 0xFF); WriteData(&b, 1); - b = asBYTE(i & 0xFF); WriteData(&b, 1); - } - else if( i < (asINT64(1)<<48) ) - { - b = asBYTE(0x7E + signBit + (i >> 48)); WriteData(&b, 1); - b = asBYTE((i >> 40) & 0xFF); WriteData(&b, 1); - b = asBYTE((i >> 32) & 0xFF); WriteData(&b, 1); - b = asBYTE((i >> 24) & 0xFF); WriteData(&b, 1); - b = asBYTE((i >> 16) & 0xFF); WriteData(&b, 1); - b = asBYTE((i >> 8) & 0xFF); WriteData(&b, 1); - b = asBYTE(i & 0xFF); WriteData(&b, 1); + if( i < (1 << 6) ) + { + b = (asBYTE)(signBit + i); + WriteData(&b, 1); + } + else if( i < (1 << 13) ) + { + b = asBYTE(0x40 + signBit + (i >> 8)); + WriteData(&b, 1); + b = asBYTE(i & 0xFF); + WriteData(&b, 1); + } + else if( i < (1 << 20) ) + { + b = asBYTE(0x60 + signBit + (i >> 16)); + WriteData(&b, 1); + b = asBYTE((i >> 8) & 0xFF); + WriteData(&b, 1); + b = asBYTE(i & 0xFF); + WriteData(&b, 1); + } + else if( i < (1 << 27) ) + { + b = asBYTE(0x70 + signBit + (i >> 24)); + WriteData(&b, 1); + b = asBYTE((i >> 16) & 0xFF); + WriteData(&b, 1); + b = asBYTE((i >> 8) & 0xFF); + WriteData(&b, 1); + b = asBYTE(i & 0xFF); + WriteData(&b, 1); + } + else if( i < (asINT64(1) << 34) ) + { + b = asBYTE(0x78 + signBit + (i >> 32)); + WriteData(&b, 1); + b = asBYTE((i >> 24) & 0xFF); + WriteData(&b, 1); + b = asBYTE((i >> 16) & 0xFF); + WriteData(&b, 1); + b = asBYTE((i >> 8) & 0xFF); + WriteData(&b, 1); + b = asBYTE(i & 0xFF); + WriteData(&b, 1); + } + else if( i < (asINT64(1) << 41) ) + { + b = asBYTE(0x7C + signBit + (i >> 40)); + WriteData(&b, 1); + b = asBYTE((i >> 32) & 0xFF); + WriteData(&b, 1); + b = asBYTE((i >> 24) & 0xFF); + WriteData(&b, 1); + b = asBYTE((i >> 16) & 0xFF); + WriteData(&b, 1); + b = asBYTE((i >> 8) & 0xFF); + WriteData(&b, 1); + b = asBYTE(i & 0xFF); + WriteData(&b, 1); + } + else if( i < (asINT64(1) << 48) ) + { + b = asBYTE(0x7E + signBit + (i >> 48)); + WriteData(&b, 1); + b = asBYTE((i >> 40) & 0xFF); + WriteData(&b, 1); + b = asBYTE((i >> 32) & 0xFF); + WriteData(&b, 1); + b = asBYTE((i >> 24) & 0xFF); + WriteData(&b, 1); + b = asBYTE((i >> 16) & 0xFF); + WriteData(&b, 1); + b = asBYTE((i >> 8) & 0xFF); + WriteData(&b, 1); + b = asBYTE(i & 0xFF); + WriteData(&b, 1); } else { - b = asBYTE(0x7F + signBit); WriteData(&b, 1); - b = asBYTE((i >> 56) & 0xFF); WriteData(&b, 1); - b = asBYTE((i >> 48) & 0xFF); WriteData(&b, 1); - b = asBYTE((i >> 40) & 0xFF); WriteData(&b, 1); - b = asBYTE((i >> 32) & 0xFF); WriteData(&b, 1); - b = asBYTE((i >> 24) & 0xFF); WriteData(&b, 1); - b = asBYTE((i >> 16) & 0xFF); WriteData(&b, 1); - b = asBYTE((i >> 8) & 0xFF); WriteData(&b, 1); - b = asBYTE(i & 0xFF); WriteData(&b, 1); + b = asBYTE(0x7F + signBit); + WriteData(&b, 1); + b = asBYTE((i >> 56) & 0xFF); + WriteData(&b, 1); + b = asBYTE((i >> 48) & 0xFF); + WriteData(&b, 1); + b = asBYTE((i >> 40) & 0xFF); + WriteData(&b, 1); + b = asBYTE((i >> 32) & 0xFF); + WriteData(&b, 1); + b = asBYTE((i >> 24) & 0xFF); + WriteData(&b, 1); + b = asBYTE((i >> 16) & 0xFF); + WriteData(&b, 1); + b = asBYTE((i >> 8) & 0xFF); + WriteData(&b, 1); + b = asBYTE(i & 0xFF); + WriteData(&b, 1); } } -void asCWriter::WriteString(asCString* str) +void asCWriter::WriteString(asCString *str) { // First check if the string hasn't been saved already asSMapNode *cursor = 0; - if (stringToIdMap.MoveTo(&cursor, *str)) + if( stringToIdMap.MoveTo(&cursor, *str) ) { // Save a reference to the existing string // The lowest bit is set to 1 to indicate a reference - WriteEncodedInt64(cursor->value*2+1); + WriteEncodedInt64(cursor->value * 2 + 1); return; } // Save a new string // The lowest bit is set to 0 to indicate a new string asUINT len = (asUINT)str->GetLength(); - WriteEncodedInt64(len*2); + WriteEncodedInt64(len * 2); if( len > 0 ) { @@ -4774,7 +4846,7 @@ void asCWriter::WriteString(asCString* str) } } -void asCWriter::WriteGlobalProperty(asCGlobalProperty* prop) +void asCWriter::WriteGlobalProperty(asCGlobalProperty *prop) { // TODO: We might be able to avoid storing the name and type of the global // properties twice if we merge this with the WriteUsedGlobalProperties. @@ -4786,7 +4858,7 @@ void asCWriter::WriteGlobalProperty(asCGlobalProperty* prop) WriteFunction(prop->GetInitFunc()); } -void asCWriter::WriteObjectProperty(asCObjectProperty* prop) +void asCWriter::WriteObjectProperty(asCObjectProperty *prop) { WriteString(&prop->name); WriteDataType(&prop->type); @@ -4804,7 +4876,7 @@ void asCWriter::WriteDataType(const asCDataType *dt) { if( *dt == savedDataTypes[n] ) { - WriteEncodedInt64(n+1); + WriteEncodedInt64(n + 1); return; } } @@ -4830,7 +4902,7 @@ void asCWriter::WriteDataType(const asCDataType *dt) WriteData(&bits, 1); } -void asCWriter::WriteTypeInfo(asCTypeInfo* ti) +void asCWriter::WriteTypeInfo(asCTypeInfo *ti) { char ch; @@ -4906,28 +4978,28 @@ void asCWriter::WriteTypeInfo(asCTypeInfo* ti) void asCWriter::CalculateAdjustmentByPos(asCScriptFunction *func) { // Adjust the offset of all negative variables (parameters) so all pointers will have a size of 1 dword - asUINT n; + asUINT n; asCArray adjustments; - asUINT offset = 0; + asUINT offset = 0; if( func->objectType ) { adjustments.PushLast(offset); - adjustments.PushLast(1-AS_PTR_SIZE); + adjustments.PushLast(1 - AS_PTR_SIZE); offset += AS_PTR_SIZE; } if( func->DoesReturnOnStack() ) { adjustments.PushLast(offset); - adjustments.PushLast(1-AS_PTR_SIZE); + adjustments.PushLast(1 - AS_PTR_SIZE); offset += AS_PTR_SIZE; } for( n = 0; n < func->parameterTypes.GetLength(); n++ ) { if( !func->parameterTypes[n].IsPrimitive() || - func->parameterTypes[n].IsReference() ) + func->parameterTypes[n].IsReference() ) { adjustments.PushLast(offset); - adjustments.PushLast(1-AS_PTR_SIZE); + adjustments.PushLast(1 - AS_PTR_SIZE); offset += AS_PTR_SIZE; } else @@ -4939,36 +5011,36 @@ void asCWriter::CalculateAdjustmentByPos(asCScriptFunction *func) // Build look-up table with the adjustments for each stack position adjustNegativeStackByPos.SetLength(offset); - memset(adjustNegativeStackByPos.AddressOf(), 0, adjustNegativeStackByPos.GetLength()*sizeof(int)); - for( n = 0; n < adjustments.GetLength(); n+=2 ) + memset(adjustNegativeStackByPos.AddressOf(), 0, adjustNegativeStackByPos.GetLength() * sizeof(int)); + for( n = 0; n < adjustments.GetLength(); n += 2 ) { int pos = adjustments[n]; - int adjust = adjustments[n+1]; + int adjust = adjustments[n + 1]; - for( asUINT i = pos+1; i < adjustNegativeStackByPos.GetLength(); i++ ) + for( asUINT i = pos + 1; i < adjustNegativeStackByPos.GetLength(); i++ ) adjustNegativeStackByPos[i] += adjust; } // Adjust the offset of all positive variables so that all object types and handles have a size of 1 dword // This is similar to how the adjustment is done in the asCReader::TranslateFunction, only the reverse adjustments.SetLength(0); - for (n = 0; n < func->scriptData->variables.GetLength(); n++) + for( n = 0; n < func->scriptData->variables.GetLength(); n++ ) { // Skip function parameters as these are adjusted by adjustNegativeStackByPos - if (func->scriptData->variables[n]->stackOffset <= 0) + if( func->scriptData->variables[n]->stackOffset <= 0 ) continue; asCDataType t = func->scriptData->variables[n]->type; - if (!t.IsObject() && !t.IsObjectHandle()) + if( !t.IsObject() && !t.IsObjectHandle() ) continue; // Determing the size of the variable currently occupies on the stack int size = AS_PTR_SIZE; - if (t.GetTypeInfo() && (t.GetTypeInfo()->GetFlags() & asOBJ_VALUE) && !func->scriptData->variables[n]->onHeap) + if( t.GetTypeInfo() && (t.GetTypeInfo()->GetFlags() & asOBJ_VALUE) && !func->scriptData->variables[n]->onHeap ) size = t.GetSizeInMemoryDWords(); // If larger than 1 dword, adjust the offsets accordingly - if (size > 1) + if( size > 1 ) { // How much needs to be adjusted? adjustments.PushLast(func->scriptData->variables[n]->stackOffset); @@ -4977,42 +5049,42 @@ void asCWriter::CalculateAdjustmentByPos(asCScriptFunction *func) } // Build look-up table with the adjustments for each stack position - adjustStackByPos.SetLength(func->scriptData->stackNeeded+AS_PTR_SIZE); // Add space for a pointer stored in a temporary variable - memset(adjustStackByPos.AddressOf(), 0, adjustStackByPos.GetLength()*sizeof(int)); - for( n = 0; n < adjustments.GetLength(); n+=2 ) + adjustStackByPos.SetLength(func->scriptData->stackNeeded + AS_PTR_SIZE); // Add space for a pointer stored in a temporary variable + memset(adjustStackByPos.AddressOf(), 0, adjustStackByPos.GetLength() * sizeof(int)); + for( n = 0; n < adjustments.GetLength(); n += 2 ) { int pos = adjustments[n]; - int adjust = adjustments[n+1]; + int adjust = adjustments[n + 1]; // If more than one variable in different scopes occupy the same position on the stack they must have the same size asASSERT(adjustStackByPos[pos] == 0 || adjustStackByPos[pos] == adjust); adjustStackByPos[pos] = adjust; } - // Accumulate adjustments + // Accumulate adjustments int adjust = adjustStackByPos[0]; - for (asUINT i = 1; i < adjustStackByPos.GetLength(); i++) + for( asUINT i = 1; i < adjustStackByPos.GetLength(); i++ ) { - adjust += adjustStackByPos[i]; - adjustStackByPos[i] = adjust; + adjust += adjustStackByPos[i]; + adjustStackByPos[i] = adjust; } // Compute the sequence number of each bytecode instruction in order to update the jump offsets - asUINT length = func->scriptData->byteCode.GetLength() + 1; // accomodate one more for invisible instructions, e.g. scope end - asDWORD *bc = func->scriptData->byteCode.AddressOf(); - bytecodeNbrByPos.SetLength(length); + asUINT length = func->scriptData->byteCode.GetLength() + 1; // accomodate one more for invisible instructions, e.g. scope end + asDWORD *bc = func->scriptData->byteCode.AddressOf(); + bytecodeNbrByPos.SetLength(length); asUINT num; - for( offset = 0, num = 0; offset < length-1; ) + for( offset = 0, num = 0; offset < length - 1; ) { - bytecodeNbrByPos[offset] = num; - offset += asBCTypeSize[asBCInfo[*(asBYTE*)(bc+offset)].type]; + bytecodeNbrByPos[offset] = num; + offset += asBCTypeSize[asBCInfo[*(asBYTE *)(bc + offset)].type]; num++; } bytecodeNbrByPos[offset] = num; - // Store the number of instructions in the last position of bytecodeNbrByPos, + // Store the number of instructions in the last position of bytecodeNbrByPos, // so this can be easily queried in SaveBytecode. Normally this is already done - // as most functions end with BC_RET, but in some cases the last instruction in + // as most functions end with BC_RET, but in some cases the last instruction in // the function is not a BC_RET, e.g. when a function has a never ending loop. bytecodeNbrByPos[length - 1] = num - 1; } @@ -5024,7 +5096,7 @@ int asCWriter::AdjustStackPosition(int pos) // This happens for example if the function only have temporary variables // The adjustByPos can also be empty if the function doesn't have any variables at all, but receive a handle by parameter if( adjustStackByPos.GetLength() > 0 ) - pos += adjustStackByPos[adjustStackByPos.GetLength()-1]; + pos += adjustStackByPos[adjustStackByPos.GetLength() - 1]; } else if( pos >= 0 ) pos += adjustStackByPos[pos]; @@ -5049,14 +5121,14 @@ int asCWriter::AdjustGetOffset(int offset, asCScriptFunction *func, asDWORD prog // Find out which function that will be called asCScriptFunction *calledFunc = 0; - int stackDelta = 0; + int stackDelta = 0; for( asUINT n = programPos; n < func->scriptData->byteCode.GetLength(); ) { - asBYTE bc = *(asBYTE*)&func->scriptData->byteCode[n]; + asBYTE bc = *(asBYTE *)&func->scriptData->byteCode[n]; if( bc == asBC_CALL || - bc == asBC_CALLSYS || - bc == asBC_Thiscall1 || - bc == asBC_CALLINTF ) + bc == asBC_CALLSYS || + bc == asBC_Thiscall1 || + bc == asBC_CALLINTF ) { // Find the function from the function id in bytecode int funcId = asBC_INTARG(&func->scriptData->byteCode[n]); @@ -5070,7 +5142,7 @@ int asCWriter::AdjustGetOffset(int offset, asCScriptFunction *func, asDWORD prog bcAlloc = true; // Find the function from the function id in the bytecode - int funcId = asBC_INTARG(&func->scriptData->byteCode[n+AS_PTR_SIZE]); + int funcId = asBC_INTARG(&func->scriptData->byteCode[n + AS_PTR_SIZE]); calledFunc = engine->scriptFunctions[funcId]; break; } @@ -5083,12 +5155,12 @@ int asCWriter::AdjustGetOffset(int offset, asCScriptFunction *func, asDWORD prog } else if( bc == asBC_CallPtr ) { - int var = asBC_SWORDARG1(&func->scriptData->byteCode[n]); + int var = asBC_SWORDARG1(&func->scriptData->byteCode[n]); asUINT v; // Find the funcdef from the local variable - for (v = 0; v < func->scriptData->variables.GetLength(); v++) + for( v = 0; v < func->scriptData->variables.GetLength(); v++ ) { - if (func->scriptData->variables[v]->stackOffset == var) + if( func->scriptData->variables[v]->stackOffset == var ) { asASSERT(func->scriptData->variables[v]->type.GetTypeInfo()); calledFunc = CastToFuncdefType(func->scriptData->variables[v]->type.GetTypeInfo())->funcdef; @@ -5116,7 +5188,7 @@ int asCWriter::AdjustGetOffset(int offset, asCScriptFunction *func, asDWORD prog break; } else if( bc == asBC_REFCPY || - bc == asBC_COPY ) + bc == asBC_COPY ) { // In this case we know there is only 1 pointer on the stack above asASSERT( offset == AS_PTR_SIZE ); @@ -5134,8 +5206,8 @@ int asCWriter::AdjustGetOffset(int offset, asCScriptFunction *func, asDWORD prog // Count the number of pointers pushed on the stack above the // current offset, and then adjust the offset accordingly - asUINT numPtrs = 0; - int currOffset = -stackDelta; + asUINT numPtrs = 0; + int currOffset = -stackDelta; if( offset > currOffset && calledFunc->GetObjectType() && !bcAlloc ) { currOffset += AS_PTR_SIZE; @@ -5148,14 +5220,14 @@ int asCWriter::AdjustGetOffset(int offset, asCScriptFunction *func, asDWORD prog if( currOffset > 0 ) numPtrs++; } - if (offset > currOffset && calledFunc->IsVariadic()) + if( offset > currOffset && calledFunc->IsVariadic() ) currOffset++; for( asUINT p = 0; p < calledFunc->parameterTypes.GetLength(); p++ ) { if( offset <= currOffset ) break; if( !calledFunc->parameterTypes[p].IsPrimitive() || - calledFunc->parameterTypes[p].IsReference() ) + calledFunc->parameterTypes[p].IsReference() ) { // objects and references are passed by pointer currOffset += AS_PTR_SIZE; @@ -5173,23 +5245,23 @@ int asCWriter::AdjustGetOffset(int offset, asCScriptFunction *func, asDWORD prog currOffset += calledFunc->parameterTypes[p].GetSizeOnStackDWords(); } } - if (offset > currOffset && calledFunc->IsVariadic()) + if( offset > currOffset && calledFunc->IsVariadic() ) { asCDataType variadicType = calledFunc->parameterTypes[calledFunc->parameterTypes.GetLength() - 1]; - for (;;) + for( ;; ) { - if (offset <= currOffset) break; + if( offset <= currOffset ) break; - if(!variadicType.IsPrimitive() || - variadicType.IsReference()) + if( !variadicType.IsPrimitive() || + variadicType.IsReference() ) { // objects and references are passed by pointer currOffset += AS_PTR_SIZE; - if (currOffset > 0) + if( currOffset > 0 ) numPtrs++; // The variable arg ? has an additional 32bit int with the typeid - if (variadicType.IsAnyType()) + if( variadicType.IsAnyType() ) currOffset += 1; } else @@ -5209,86 +5281,86 @@ int asCWriter::AdjustGetOffset(int offset, asCScriptFunction *func, asDWORD prog void asCWriter::WriteByteCode(asCScriptFunction *func) { - asDWORD *bc = func->scriptData->byteCode.AddressOf(); - size_t length = func->scriptData->byteCode.GetLength(); + asDWORD *bc = func->scriptData->byteCode.AddressOf(); + size_t length = func->scriptData->byteCode.GetLength(); // The length cannot be stored, because it is platform dependent, // instead we store the number of instructions - asUINT count = bytecodeNbrByPos[bytecodeNbrByPos.GetLength()-1] + 1; + asUINT count = bytecodeNbrByPos[bytecodeNbrByPos.GetLength() - 1] + 1; WriteEncodedInt64(count); asDWORD *startBC = bc; while( length ) { asDWORD tmpBC[4]; // The biggest instructions take up 4 DWORDs - asDWORD c = *(asBYTE*)bc; + asDWORD c = *(asBYTE *)bc; // Copy the instruction to a temp buffer so we can work on it before saving - memcpy(tmpBC, bc, asBCTypeSize[asBCInfo[c].type]*sizeof(asDWORD)); + memcpy(tmpBC, bc, asBCTypeSize[asBCInfo[c].type] * sizeof(asDWORD)); if( c == asBC_ALLOC ) // W_PTR_DW_ARG { // Translate the object type - asCObjectType *ot = *(asCObjectType**)(tmpBC+1); - *(asPWORD*)(tmpBC+1) = FindTypeInfoIdx(ot); + asCObjectType *ot = *(asCObjectType **)(tmpBC + 1); + *(asPWORD *)(tmpBC + 1) = FindTypeInfoIdx(ot); // Translate the constructor func id, unless it is 0 - if( *(int*)&tmpBC[1+AS_PTR_SIZE] != 0 ) + if( *(int *)&tmpBC[1 + AS_PTR_SIZE] != 0 ) { // Increment 1 to the translated function id, as 0 will be reserved for no function - *(int*)&tmpBC[1+AS_PTR_SIZE] = 1+FindFunctionIndex(engine->scriptFunctions[*(int*)&tmpBC[1+AS_PTR_SIZE]]); + *(int *)&tmpBC[1 + AS_PTR_SIZE] = 1 + FindFunctionIndex(engine->scriptFunctions[*(int *)&tmpBC[1 + AS_PTR_SIZE]]); } } - else if( c == asBC_REFCPY || // PTR_ARG - c == asBC_RefCpyV || // wW_PTR_ARG - c == asBC_OBJTYPE ) // PTR_ARG + else if( c == asBC_REFCPY || // PTR_ARG + c == asBC_RefCpyV || // wW_PTR_ARG + c == asBC_OBJTYPE ) // PTR_ARG { // Translate object type pointers into indices - *(asPWORD*)(tmpBC+1) = FindTypeInfoIdx(*(asCObjectType**)(tmpBC+1)); + *(asPWORD *)(tmpBC + 1) = FindTypeInfoIdx(*(asCObjectType **)(tmpBC + 1)); } else if( c == asBC_JitEntry ) // PTR_ARG { // We don't store the JIT argument - *(asPWORD*)(tmpBC+1) = 0; + *(asPWORD *)(tmpBC + 1) = 0; } else if( c == asBC_TYPEID || // DW_ARG - c == asBC_Cast ) // DW_ARG + c == asBC_Cast ) // DW_ARG { // Translate type ids into indices - *(int*)(tmpBC+1) = FindTypeIdIdx(*(int*)(tmpBC+1)); + *(int *)(tmpBC + 1) = FindTypeIdIdx(*(int *)(tmpBC + 1)); } - else if( c == asBC_ADDSi || // W_DW_ARG - c == asBC_LoadThisR ) // W_DW_ARG + else if( c == asBC_ADDSi || // W_DW_ARG + c == asBC_LoadThisR ) // W_DW_ARG { // Translate property offsets into indices - *(((short*)tmpBC)+1) = (short)FindObjectPropIndex(*(((short*)tmpBC)+1), *(int*)(tmpBC+1), bc); + *(((short *)tmpBC) + 1) = (short)FindObjectPropIndex(*(((short *)tmpBC) + 1), *(int *)(tmpBC + 1), bc); // Translate type ids into indices - *(int*)(tmpBC+1) = FindTypeIdIdx(*(int*)(tmpBC+1)); + *(int *)(tmpBC + 1) = FindTypeIdIdx(*(int *)(tmpBC + 1)); } - else if( c == asBC_LoadRObjR || // rW_W_DW_ARG - c == asBC_LoadVObjR ) // rW_W_DW_ARG + else if( c == asBC_LoadRObjR || // rW_W_DW_ARG + c == asBC_LoadVObjR ) // rW_W_DW_ARG { - asCObjectType *ot = engine->GetObjectTypeFromTypeId(*(int*)(tmpBC+2)); + asCObjectType *ot = engine->GetObjectTypeFromTypeId(*(int *)(tmpBC + 2)); if( ot->flags & asOBJ_LIST_PATTERN ) { // List patterns have a different way of translating the offsets - SListAdjuster *listAdj = listAdjusters[listAdjusters.GetLength()-1]; - *(((short*)tmpBC)+2) = (short)listAdj->AdjustOffset(*(((short*)tmpBC)+2), ot); + SListAdjuster *listAdj = listAdjusters[listAdjusters.GetLength() - 1]; + *(((short *)tmpBC) + 2) = (short)listAdj->AdjustOffset(*(((short *)tmpBC) + 2), ot); } else { // Translate property offsets into indices - *(((short*)tmpBC)+2) = (short)FindObjectPropIndex(*(((short*)tmpBC)+2), *(int*)(tmpBC+2), bc); + *(((short *)tmpBC) + 2) = (short)FindObjectPropIndex(*(((short *)tmpBC) + 2), *(int *)(tmpBC + 2), bc); } // Translate type ids into indices - *(int*)(tmpBC+2) = FindTypeIdIdx(*(int*)(tmpBC+2)); + *(int *)(tmpBC + 2) = FindTypeIdIdx(*(int *)(tmpBC + 2)); } - else if( c == asBC_COPY ) // W_DW_ARG + else if( c == asBC_COPY ) // W_DW_ARG { // Translate type ids into indices - *(int*)(tmpBC+1) = FindTypeIdIdx(*(int*)(tmpBC+1)); + *(int *)(tmpBC + 1) = FindTypeIdIdx(*(int *)(tmpBC + 1)); // Update the WORDARG0 to 0, as this will be recalculated on the target platform asBC_WORDARG0(tmpBC) = 0; @@ -5299,17 +5371,17 @@ void asCWriter::WriteByteCode(asCScriptFunction *func) asBC_WORDARG0(tmpBC) = 0; } else if( c == asBC_CALL || // DW_ARG - c == asBC_CALLINTF || // DW_ARG - c == asBC_CALLSYS || // W_DW_ARG - c == asBC_Thiscall1 ) // DW_ARG + c == asBC_CALLINTF || // DW_ARG + c == asBC_CALLSYS || // W_DW_ARG + c == asBC_Thiscall1 ) // DW_ARG { // Translate the function id - *(int*)(tmpBC+1) = FindFunctionIndex(engine->scriptFunctions[*(int*)(tmpBC+1)]); + *(int *)(tmpBC + 1) = FindFunctionIndex(engine->scriptFunctions[*(int *)(tmpBC + 1)]); } else if( c == asBC_FuncPtr ) // PTR_ARG { // Translate the function pointer - *(asPWORD*)(tmpBC+1) = FindFunctionIndex(*(asCScriptFunction**)(tmpBC+1)); + *(asPWORD *)(tmpBC + 1) = FindFunctionIndex(*(asCScriptFunction **)(tmpBC + 1)); } else if( c == asBC_CALLBND ) // DW_ARG { @@ -5324,22 +5396,22 @@ void asCWriter::WriteByteCode(asCScriptFunction *func) tmpBC[1] = funcId; } - else if( c == asBC_PGA || // PTR_ARG - c == asBC_PshGPtr || // PTR_ARG - c == asBC_LDG || // PTR_ARG - c == asBC_PshG4 || // PTR_ARG - c == asBC_LdGRdR4 || // wW_PTR_ARG - c == asBC_CpyGtoV4 || // wW_PTR_ARG - c == asBC_CpyVtoG4 || // rW_PTR_ARG - c == asBC_SetG4 ) // PTR_DW_ARG + else if( c == asBC_PGA || // PTR_ARG + c == asBC_PshGPtr || // PTR_ARG + c == asBC_LDG || // PTR_ARG + c == asBC_PshG4 || // PTR_ARG + c == asBC_LdGRdR4 || // wW_PTR_ARG + c == asBC_CpyGtoV4 || // wW_PTR_ARG + c == asBC_CpyVtoG4 || // rW_PTR_ARG + c == asBC_SetG4 ) // PTR_DW_ARG { // Check if the address is a global property or a string constant - void *ptr = *(void**)(tmpBC + 1); - if (engine->varAddressMap.MoveTo(0, ptr)) + void *ptr = *(void **)(tmpBC + 1); + if( engine->varAddressMap.MoveTo(0, ptr) ) { // Translate global variable pointers into indices // Flag the first bit to signal global property - *(asPWORD*)(tmpBC + 1) = (asPWORD(FindGlobalPropPtrIndex(*(void**)(tmpBC + 1))) << 1) + 1; + *(asPWORD *)(tmpBC + 1) = (asPWORD(FindGlobalPropPtrIndex(*(void **)(tmpBC + 1))) << 1) + 1; } else { @@ -5348,34 +5420,34 @@ void asCWriter::WriteByteCode(asCScriptFunction *func) // Translate string constants into indices // Leave the first bit clear to signal string constant - *(asPWORD*)(tmpBC + 1) = asPWORD(FindStringConstantIndex(*(void**)(tmpBC + 1))) << 1; + *(asPWORD *)(tmpBC + 1) = asPWORD(FindStringConstantIndex(*(void **)(tmpBC + 1))) << 1; } } - else if( c == asBC_JMP || // DW_ARG - c == asBC_JZ || - c == asBC_JNZ || - c == asBC_JLowZ || - c == asBC_JLowNZ || - c == asBC_JS || - c == asBC_JNS || - c == asBC_JP || - c == asBC_JNP ) // The JMPP instruction doesn't need modification + else if( c == asBC_JMP || // DW_ARG + c == asBC_JZ || + c == asBC_JNZ || + c == asBC_JLowZ || + c == asBC_JLowNZ || + c == asBC_JS || + c == asBC_JNS || + c == asBC_JP || + c == asBC_JNP ) // The JMPP instruction doesn't need modification { // Get the DWORD offset from arg - int offset = *(int*)(tmpBC+1); + int offset = *(int *)(tmpBC + 1); // Determine instruction number for next instruction and destination - int bcSeqNum = bytecodeNbrByPos[asUINT(bc - startBC)] + 1; - asDWORD *targetBC = bc + 2 + offset; - int targetBcSeqNum = bytecodeNbrByPos[asUINT(targetBC - startBC)]; + int bcSeqNum = bytecodeNbrByPos[asUINT(bc - startBC)] + 1; + asDWORD *targetBC = bc + 2 + offset; + int targetBcSeqNum = bytecodeNbrByPos[asUINT(targetBC - startBC)]; // Set the offset in number of instructions - *(int*)(tmpBC+1) = targetBcSeqNum - bcSeqNum; + *(int *)(tmpBC + 1) = targetBcSeqNum - bcSeqNum; } - else if( c == asBC_GETOBJ || // W_ARG - c == asBC_GETOBJREF || - c == asBC_GETREF || - c == asBC_ChkNullS ) + else if( c == asBC_GETOBJ || // W_ARG + c == asBC_GETOBJREF || + c == asBC_GETREF || + c == asBC_ChkNullS ) { // Adjust the offset according to the function call that comes after asBC_WORDARG0(tmpBC) = (asWORD)AdjustGetOffset(asBC_WORDARG0(tmpBC), func, asDWORD(bc - startBC)); @@ -5386,8 +5458,8 @@ void asCWriter::WriteByteCode(asCScriptFunction *func) asBC_DWORDARG(tmpBC) = 0; // Determine the type of the list pattern from the variable - short var = asBC_WORDARG0(tmpBC); - asCObjectType *ot = CastToObjectType(func->GetTypeInfoOfLocalVar(var)); + short var = asBC_WORDARG0(tmpBC); + asCObjectType *ot = CastToObjectType(func->GetTypeInfoOfLocalVar(var)); // Create this helper object to adjust the offset of the elements accessed in the buffer listAdjusters.PushLast(asNEW(SListAdjuster)(ot)); @@ -5395,8 +5467,8 @@ void asCWriter::WriteByteCode(asCScriptFunction *func) else if( c == asBC_FREE ) // wW_PTR_ARG { // Translate object type pointers into indices - asCObjectType *ot = *(asCObjectType**)(tmpBC+1); - *(asPWORD*)(tmpBC+1) = FindTypeInfoIdx(ot); + asCObjectType *ot = *(asCObjectType **)(tmpBC + 1); + *(asPWORD *)(tmpBC + 1) = FindTypeInfoIdx(ot); // Pop and destroy the list adjuster helper that was created with asBC_AllocMem if( ot && (ot->flags & asOBJ_LIST_PATTERN) ) @@ -5408,23 +5480,23 @@ void asCWriter::WriteByteCode(asCScriptFunction *func) else if( c == asBC_SetListSize ) { // Adjust the offset in the initialization list - SListAdjuster *listAdj = listAdjusters[listAdjusters.GetLength()-1]; - tmpBC[1] = listAdj->AdjustOffset(tmpBC[1], listAdj->patternType); + SListAdjuster *listAdj = listAdjusters[listAdjusters.GetLength() - 1]; + tmpBC[1] = listAdj->AdjustOffset(tmpBC[1], listAdj->patternType); // Tell the adjuster how many repeated values there are listAdj->SetRepeatCount(tmpBC[2]); } - else if( c == asBC_PshListElmnt ) // W_DW_ARG + else if( c == asBC_PshListElmnt ) // W_DW_ARG { // Adjust the offset in the initialization list - SListAdjuster *listAdj = listAdjusters[listAdjusters.GetLength()-1]; - tmpBC[1] = listAdj->AdjustOffset(tmpBC[1], listAdj->patternType); + SListAdjuster *listAdj = listAdjusters[listAdjusters.GetLength() - 1]; + tmpBC[1] = listAdj->AdjustOffset(tmpBC[1], listAdj->patternType); } else if( c == asBC_SetListType ) { // Adjust the offset in the initialization list - SListAdjuster *listAdj = listAdjusters[listAdjusters.GetLength()-1]; - tmpBC[1] = listAdj->AdjustOffset(tmpBC[1], listAdj->patternType); + SListAdjuster *listAdj = listAdjusters[listAdjusters.GetLength() - 1]; + tmpBC[1] = listAdj->AdjustOffset(tmpBC[1], listAdj->patternType); // Inform the adjuster of the type id of the next element listAdj->SetNextType(tmpBC[2]); @@ -5435,30 +5507,30 @@ void asCWriter::WriteByteCode(asCScriptFunction *func) // Adjust the variable offsets switch( asBCInfo[c].type ) { - case asBCTYPE_wW_ARG: - case asBCTYPE_rW_DW_ARG: - case asBCTYPE_wW_QW_ARG: - case asBCTYPE_rW_ARG: - case asBCTYPE_wW_DW_ARG: - case asBCTYPE_wW_W_ARG: - case asBCTYPE_rW_QW_ARG: - case asBCTYPE_rW_W_DW_ARG: - case asBCTYPE_rW_DW_DW_ARG: + case asBCTYPE_wW_ARG: + case asBCTYPE_rW_DW_ARG: + case asBCTYPE_wW_QW_ARG: + case asBCTYPE_rW_ARG: + case asBCTYPE_wW_DW_ARG: + case asBCTYPE_wW_W_ARG: + case asBCTYPE_rW_QW_ARG: + case asBCTYPE_rW_W_DW_ARG: + case asBCTYPE_rW_DW_DW_ARG: { asBC_SWORDARG0(tmpBC) = (short)AdjustStackPosition(asBC_SWORDARG0(tmpBC)); } break; - case asBCTYPE_wW_rW_ARG: - case asBCTYPE_wW_rW_DW_ARG: - case asBCTYPE_rW_rW_ARG: + case asBCTYPE_wW_rW_ARG: + case asBCTYPE_wW_rW_DW_ARG: + case asBCTYPE_rW_rW_ARG: { asBC_SWORDARG0(tmpBC) = (short)AdjustStackPosition(asBC_SWORDARG0(tmpBC)); asBC_SWORDARG1(tmpBC) = (short)AdjustStackPosition(asBC_SWORDARG1(tmpBC)); } break; - case asBCTYPE_wW_rW_rW_ARG: + case asBCTYPE_wW_rW_rW_ARG: { asBC_SWORDARG0(tmpBC) = (short)AdjustStackPosition(asBC_SWORDARG0(tmpBC)); asBC_SWORDARG1(tmpBC) = (short)AdjustStackPosition(asBC_SWORDARG1(tmpBC)); @@ -5466,15 +5538,15 @@ void asCWriter::WriteByteCode(asCScriptFunction *func) } break; - case asBCTYPE_W_rW_ARG: + case asBCTYPE_W_rW_ARG: { asBC_SWORDARG1(tmpBC) = (short)AdjustStackPosition(asBC_SWORDARG1(tmpBC)); } break; - default: - // The other types don't treat variables so won't be modified - break; + default: + // The other types don't treat variables so won't be modified + break; } // TODO: bytecode: Must make sure that floats and doubles are always stored the same way regardless of platform. @@ -5483,43 +5555,43 @@ void asCWriter::WriteByteCode(asCScriptFunction *func) // Now store the instruction in the smallest possible way switch( asBCInfo[c].type ) { - case asBCTYPE_NO_ARG: + case asBCTYPE_NO_ARG: { // Just write 1 byte asBYTE b = (asBYTE)c; WriteData(&b, 1); } break; - case asBCTYPE_W_ARG: - case asBCTYPE_wW_ARG: - case asBCTYPE_rW_ARG: + case asBCTYPE_W_ARG: + case asBCTYPE_wW_ARG: + case asBCTYPE_rW_ARG: { // Write the instruction code asBYTE b = (asBYTE)c; WriteData(&b, 1); // Write the argument - short w = *(((short*)tmpBC)+1); + short w = *(((short *)tmpBC) + 1); WriteEncodedInt64(w); } break; - case asBCTYPE_rW_DW_ARG: - case asBCTYPE_wW_DW_ARG: - case asBCTYPE_W_DW_ARG: + case asBCTYPE_rW_DW_ARG: + case asBCTYPE_wW_DW_ARG: + case asBCTYPE_W_DW_ARG: { // Write the instruction code asBYTE b = (asBYTE)c; WriteData(&b, 1); // Write the word argument - short w = *(((short*)tmpBC)+1); + short w = *(((short *)tmpBC) + 1); WriteEncodedInt64(w); // Write the dword argument WriteEncodedInt64((int)tmpBC[1]); } break; - case asBCTYPE_DW_ARG: + case asBCTYPE_DW_ARG: { // Write the instruction code asBYTE b = (asBYTE)c; @@ -5529,7 +5601,7 @@ void asCWriter::WriteByteCode(asCScriptFunction *func) WriteEncodedInt64((int)tmpBC[1]); } break; - case asBCTYPE_DW_DW_ARG: + case asBCTYPE_DW_DW_ARG: { // Write the instruction code asBYTE b = (asBYTE)c; @@ -5542,56 +5614,56 @@ void asCWriter::WriteByteCode(asCScriptFunction *func) WriteEncodedInt64((int)tmpBC[2]); } break; - case asBCTYPE_wW_rW_rW_ARG: + case asBCTYPE_wW_rW_rW_ARG: { // Write the instruction code asBYTE b = (asBYTE)c; WriteData(&b, 1); // Write the first argument - short w = *(((short*)tmpBC)+1); + short w = *(((short *)tmpBC) + 1); WriteEncodedInt64(w); // Write the second argument - w = *(((short*)tmpBC)+2); + w = *(((short *)tmpBC) + 2); WriteEncodedInt64(w); // Write the third argument - w = *(((short*)tmpBC)+3); + w = *(((short *)tmpBC) + 3); WriteEncodedInt64(w); } break; - case asBCTYPE_wW_rW_ARG: - case asBCTYPE_rW_rW_ARG: - case asBCTYPE_wW_W_ARG: - case asBCTYPE_W_rW_ARG: + case asBCTYPE_wW_rW_ARG: + case asBCTYPE_rW_rW_ARG: + case asBCTYPE_wW_W_ARG: + case asBCTYPE_W_rW_ARG: { // Write the instruction code asBYTE b = (asBYTE)c; WriteData(&b, 1); // Write the first argument - short w = *(((short*)tmpBC)+1); + short w = *(((short *)tmpBC) + 1); WriteEncodedInt64(w); // Write the second argument - w = *(((short*)tmpBC)+2); + w = *(((short *)tmpBC) + 2); WriteEncodedInt64(w); } break; - case asBCTYPE_wW_rW_DW_ARG: - case asBCTYPE_rW_W_DW_ARG: + case asBCTYPE_wW_rW_DW_ARG: + case asBCTYPE_rW_W_DW_ARG: { // Write the instruction code asBYTE b = (asBYTE)c; WriteData(&b, 1); // Write the first argument - short w = *(((short*)tmpBC)+1); + short w = *(((short *)tmpBC) + 1); WriteEncodedInt64(w); // Write the second argument - w = *(((short*)tmpBC)+2); + w = *(((short *)tmpBC) + 2); WriteEncodedInt64(w); // Write the third argument @@ -5599,25 +5671,25 @@ void asCWriter::WriteByteCode(asCScriptFunction *func) WriteEncodedInt64(dw); } break; - case asBCTYPE_QW_ARG: + case asBCTYPE_QW_ARG: { // Write the instruction code asBYTE b = (asBYTE)c; WriteData(&b, 1); // Write the argument - asQWORD qw = *(asQWORD*)&tmpBC[1]; + asQWORD qw = *(asQWORD *)&tmpBC[1]; WriteEncodedInt64(qw); } break; - case asBCTYPE_QW_DW_ARG: + case asBCTYPE_QW_DW_ARG: { // Write the instruction code asBYTE b = (asBYTE)c; WriteData(&b, 1); // Write the argument - asQWORD qw = *(asQWORD*)&tmpBC[1]; + asQWORD qw = *(asQWORD *)&tmpBC[1]; WriteEncodedInt64(qw); // Write the second argument @@ -5625,18 +5697,18 @@ void asCWriter::WriteByteCode(asCScriptFunction *func) WriteEncodedInt64(dw); } break; - case asBCTYPE_W_QW_DW_ARG: + case asBCTYPE_W_QW_DW_ARG: { // Write the instruction code asBYTE b = (asBYTE)c; WriteData(&b, 1); // Write the first argument - short w = *(((short*)tmpBC) + 1); + short w = *(((short *)tmpBC) + 1); WriteEncodedInt64(w); // Write the second argument - asQWORD qw = *(asQWORD*)&tmpBC[1]; + asQWORD qw = *(asQWORD *)&tmpBC[1]; WriteEncodedInt64(qw); // Write the third argument @@ -5644,31 +5716,31 @@ void asCWriter::WriteByteCode(asCScriptFunction *func) WriteEncodedInt64(dw); } break; - case asBCTYPE_rW_QW_ARG: - case asBCTYPE_wW_QW_ARG: + case asBCTYPE_rW_QW_ARG: + case asBCTYPE_wW_QW_ARG: { // Write the instruction code asBYTE b = (asBYTE)c; WriteData(&b, 1); // Write the first argument - short w = *(((short*)tmpBC)+1); + short w = *(((short *)tmpBC) + 1); WriteEncodedInt64(w); // Write the argument - asQWORD qw = *(asQWORD*)&tmpBC[1]; + asQWORD qw = *(asQWORD *)&tmpBC[1]; WriteEncodedInt64(qw); } break; - case asBCTYPE_rW_DW_DW_ARG: - case asBCTYPE_W_DW_DW_ARG: + case asBCTYPE_rW_DW_DW_ARG: + case asBCTYPE_W_DW_DW_ARG: { // Write the instruction code asBYTE b = (asBYTE)c; WriteData(&b, 1); // Write the short argument - short w = *(((short*)tmpBC)+1); + short w = *(((short *)tmpBC) + 1); WriteEncodedInt64(w); // Write the dword argument @@ -5678,7 +5750,7 @@ void asCWriter::WriteByteCode(asCScriptFunction *func) WriteEncodedInt64((int)tmpBC[2]); } break; - default: + default: { // This should never happen asASSERT(false); @@ -5690,7 +5762,7 @@ void asCWriter::WriteByteCode(asCScriptFunction *func) } // Move to the next instruction - bc += asBCTypeSize[asBCInfo[c].type]; + bc += asBCTypeSize[asBCInfo[c].type]; length -= asBCTypeSize[asBCInfo[c].type]; } } @@ -5715,7 +5787,7 @@ int asCWriter::SListAdjuster::AdjustOffset(int offset, asCObjectType *listPatter // If it is the same offset being accessed again, just return the same adjusted value if( offset == lastOffset ) - return entries-1; + return entries - 1; asASSERT( offset >= nextOffset ); @@ -5731,7 +5803,7 @@ int asCWriter::SListAdjuster::AdjustOffset(int offset, asCObjectType *listPatter } else if( patternNode->type == asLPT_TYPE ) { - const asCDataType &dt = reinterpret_cast(patternNode)->dataType; + const asCDataType &dt = reinterpret_cast(patternNode)->dataType; if( dt.GetTokenType() == ttQuestion ) { // The bytecode need to inform the type that will @@ -5758,7 +5830,7 @@ int asCWriter::SListAdjuster::AdjustOffset(int offset, asCObjectType *listPatter // Was any value skipped? asUINT size; if( dt.IsObjectHandle() || (dt.GetTypeInfo() && (dt.GetTypeInfo()->flags & asOBJ_REF)) ) - size = AS_PTR_SIZE*4; + size = AS_PTR_SIZE * 4; else size = dt.GetSizeInMemoryBytes(); @@ -5777,7 +5849,7 @@ int asCWriter::SListAdjuster::AdjustOffset(int offset, asCObjectType *listPatter { // Skip these values repeatCount -= count; - entries += count; + entries += count; } nextOffset = offset + size; @@ -5806,7 +5878,7 @@ int asCWriter::SListAdjuster::AdjustOffset(int offset, asCObjectType *listPatter } else if( patternNode->type == asLPT_END ) { - SInfo info = stack.PopLast(); + SInfo info = stack.PopLast(); repeatCount = info.repeatCount; if( repeatCount ) patternNode = info.startNode; @@ -5865,7 +5937,7 @@ int asCWriter::FindGlobalPropPtrIndex(void *ptr) if( i >= 0 ) return i; usedGlobalProperties.PushLast(ptr); - return (int)usedGlobalProperties.GetLength()-1; + return (int)usedGlobalProperties.GetLength() - 1; } void asCWriter::WriteUsedGlobalProps() @@ -5877,11 +5949,11 @@ void asCWriter::WriteUsedGlobalProps() for( int n = 0; n < c; n++ ) { - asPWORD *p = (asPWORD*)usedGlobalProperties[n]; + asPWORD *p = (asPWORD *)usedGlobalProperties[n]; // Find the property descriptor from the address - asCGlobalProperty *prop = 0; - asSMapNode *cursor; + asCGlobalProperty *prop = 0; + asSMapNode *cursor; if( engine->varAddressMap.MoveTo(&cursor, p) ) { prop = engine->varAddressMap.GetValue(cursor); @@ -5919,50 +5991,50 @@ void asCWriter::WriteUsedObjectProps() int asCWriter::FindObjectPropIndex(short offset, int typeId, asDWORD *bc) { // If the last property was a composite property, then just return 0, because it won't be translated - if (lastWasComposite) + if( lastWasComposite ) { lastWasComposite = false; return 0; } - - asCObjectType *objType = engine->GetObjectTypeFromTypeId(typeId); + + asCObjectType *objType = engine->GetObjectTypeFromTypeId(typeId); asCObjectProperty *objProp = 0; // Look for composite properties first - for (asUINT n = 0; objProp == 0 && n < objType->properties.GetLength(); n++) + for( asUINT n = 0; objProp == 0 && n < objType->properties.GetLength(); n++ ) { - // TODO: Composite: Perhaps it would be better to add metadata to the bytecode instruction to give the exact property. + // TODO: Composite: Perhaps it would be better to add metadata to the bytecode instruction to give the exact property. // That would also allow me to remove the typeId from the bytecode instruction itself // Or perhaps a new bytecode instruction all together for accessing composite properties // One that would do both offsets and indirection in a single go. // TODO: Composite: Need to be able to handle instructions replaced in bytecode optimizations too - if (objType->properties[n]->compositeOffset == offset) + if( objType->properties[n]->compositeOffset == offset ) { // This is a potential composite property. Need to check the following instructions to be sure objProp = objType->properties[n]; asASSERT(objProp); - if (objProp == 0) + if( objProp == 0 ) continue; - asDWORD *bcTemp = bc; - bcTemp += asBCTypeSize[asBCInfo[*(asBYTE*)bcTemp].type]; - if (objProp->isCompositeIndirect) + asDWORD *bcTemp = bc; + bcTemp += asBCTypeSize[asBCInfo[*(asBYTE *)bcTemp].type]; + if( objProp->isCompositeIndirect ) { // The next instruction would be a asBC_RDSPtr - if ((*(asBYTE*)bcTemp) != asBC_RDSPtr) + if( (*(asBYTE *)bcTemp) != asBC_RDSPtr ) { objProp = 0; continue; } - bcTemp += asBCTypeSize[asBCInfo[*(asBYTE*)bcTemp].type]; + bcTemp += asBCTypeSize[asBCInfo[*(asBYTE *)bcTemp].type]; } // The next instruction would be asBC_ADDSi - if ((*(asBYTE*)bcTemp) != asBC_ADDSi) + if( (*(asBYTE *)bcTemp) != asBC_ADDSi ) { objProp = 0; continue; } // Make sure the offset is the expected one - if (*(((short*)bcTemp) + 1) != objProp->byteOffset) + if( *(((short *)bcTemp) + 1) != objProp->byteOffset ) { objProp = 0; continue; @@ -5971,23 +6043,23 @@ int asCWriter::FindObjectPropIndex(short offset, int typeId, asDWORD *bc) } // If none of the composite properties matched, then look for ordinary property - for (asUINT n = 0; objProp == 0 && n < objType->properties.GetLength(); n++) + for( asUINT n = 0; objProp == 0 && n < objType->properties.GetLength(); n++ ) { - if (objType->properties[n]->byteOffset == offset && !(objType->properties[n]->compositeOffset || objType->properties[n]->isCompositeIndirect)) + if( objType->properties[n]->byteOffset == offset && !(objType->properties[n]->compositeOffset || objType->properties[n]->isCompositeIndirect) ) objProp = objType->properties[n]; } asASSERT(objProp); // Remember if this is a composite property as the next call will then be for the same property - if (objProp->compositeOffset || objProp->isCompositeIndirect) + if( objProp->compositeOffset || objProp->isCompositeIndirect ) lastWasComposite = true; // Now check if the same property has already been accessed for( asUINT n = 0; n < usedObjectProperties.GetLength(); n++ ) { if( usedObjectProperties[n].objType == objType && - usedObjectProperties[n].prop == objProp ) + usedObjectProperties[n].prop == objProp ) return n; } @@ -6038,4 +6110,3 @@ int asCWriter::FindTypeInfoIdx(asCTypeInfo *obj) #endif // AS_NO_COMPILER END_AS_NAMESPACE - diff --git a/sdk/angelscript/source/as_restore.h b/sdk/angelscript/source/as_restore.h index 5b288d9d..6c88cdb2 100644 --- a/sdk/angelscript/source/as_restore.h +++ b/sdk/angelscript/source/as_restore.h @@ -60,9 +60,9 @@ class asCReader bool error; asUINT bytesRead; - int Error(const char *msg); + int Error(const char *msg); - int ReadInner(); + int ReadInner(); int ReadData(void *data, asUINT size); void ReadString(asCString *str); @@ -87,7 +87,7 @@ class asCReader void ReadUsedStringConstants(); void ReadUsedObjectProps(); - asCTypeInfo * FindType(int idx); + asCTypeInfo *FindType(int idx); int FindTypeId(int idx); short FindObjectPropOffset(asWORD index); asCScriptFunction *FindFunction(int idx); @@ -100,18 +100,18 @@ class asCReader void CalculateStackNeeded(asCScriptFunction *func); // Temporary storage for persisting variable data - asCArray usedTypeIds; - asCArray usedTypes; - asCArray usedFunctions; - asCArray usedGlobalProperties; - asCArray usedStringConstants; + asCArray usedTypeIds; + asCArray usedTypes; + asCArray usedFunctions; + asCArray usedGlobalProperties; + asCArray usedStringConstants; - asCArray savedFunctions; + asCArray savedFunctions; asCArray savedDataTypes; asCArray savedStrings; - asCArray adjustByPos; - asCArray adjustNegativeStackByPos; + asCArray adjustByPos; + asCArray adjustNegativeStackByPos; struct SObjProp { @@ -120,8 +120,8 @@ class asCReader }; asCArray usedObjectProperties; - asCMap existingShared; - asCMap dontTranslate; + asCMap existingShared; + asCMap dontTranslate; // Helper class for adjusting offsets within initialization list buffers struct SListAdjuster @@ -150,10 +150,10 @@ class asCReader asSListPatternNode *patternNode; int nextTypeId; }; - asCArray listAdjusters; + asCArray listAdjusters; // Used by FindObjectPropOffset - asCObjectProperty* lastCompositeProp; + asCObjectProperty *lastCompositeProp; }; #ifndef AS_NO_COMPILER @@ -173,9 +173,9 @@ class asCWriter bool error; asUINT bytesWritten; - int Error(const char *msg); + int Error(const char *msg); - int WriteData(const void *data, asUINT size); + int WriteData(const void *data, asUINT size); void WriteString(asCString *str); void WriteFunction(asCScriptFunction *func); @@ -208,14 +208,14 @@ class asCWriter void WriteUsedObjectProps(); // Temporary storage for persisting variable data - asCArray usedTypeIds; - asCArray usedTypes; - asCArray usedFunctions; - asCArray usedGlobalProperties; - asCArray usedStringConstants; - asCMap stringToIndexMap; - - asCArray savedFunctions; + asCArray usedTypeIds; + asCArray usedTypes; + asCArray usedFunctions; + asCArray usedGlobalProperties; + asCArray usedStringConstants; + asCMap stringToIndexMap; + + asCArray savedFunctions; asCArray savedDataTypes; asCArray savedStrings; asCMap stringToIdMap; @@ -228,7 +228,7 @@ class asCWriter asCObjectType *objType; asCObjectProperty *prop; }; - asCArray usedObjectProperties; + asCArray usedObjectProperties; // Helper class for adjusting offsets within initialization list buffers struct SListAdjuster @@ -249,11 +249,11 @@ class asCWriter asUINT repeatCount; asSListPatternNode *patternNode; asUINT entries; - int lastOffset; // Last offset adjusted - int nextOffset; // next expected offset to be adjusted + int lastOffset; // Last offset adjusted + int nextOffset; // next expected offset to be adjusted int nextTypeId; }; - asCArray listAdjusters; + asCArray listAdjusters; // Used by FindObjectPropIndex bool lastWasComposite; diff --git a/sdk/angelscript/source/as_scriptcode.cpp b/sdk/angelscript/source/as_scriptcode.cpp index d8f8b92e..c74fafc5 100644 --- a/sdk/angelscript/source/as_scriptcode.cpp +++ b/sdk/angelscript/source/as_scriptcode.cpp @@ -45,15 +45,15 @@ BEGIN_AS_NAMESPACE asCScriptCode::asCScriptCode() { lineOffset = 0; - code = 0; + code = 0; codeLength = 0; sharedCode = false; - idx = 0; + idx = 0; } asCScriptCode::~asCScriptCode() { - if( !sharedCode && code ) + if( !sharedCode && code ) { asDELETEARRAY(code); } @@ -66,9 +66,9 @@ int asCScriptCode::SetCode(const char *in_name, const char *in_code, bool in_mak int asCScriptCode::SetCode(const char *in_name, const char *in_code, size_t in_length, bool in_makeCopy) { - if( !in_code) return asINVALID_ARG; + if( !in_code ) return asINVALID_ARG; this->name = in_name ? in_name : ""; - if( !sharedCode && code ) + if( !sharedCode && code ) asDELETEARRAY(code); if( in_length == 0 ) @@ -77,7 +77,7 @@ int asCScriptCode::SetCode(const char *in_name, const char *in_code, size_t in_l { codeLength = in_length; sharedCode = false; - code = asNEWARRAY(char, in_length); + code = asNEWARRAY(char, in_length); if( code == 0 ) return asOUT_OF_MEMORY; memcpy(code, in_code, in_length); @@ -85,14 +85,14 @@ int asCScriptCode::SetCode(const char *in_name, const char *in_code, size_t in_l else { codeLength = in_length; - code = const_cast(in_code); + code = const_cast(in_code); sharedCode = true; } // Find the positions of each line linePositions.PushLast(0); for( size_t n = 0; n < in_length; n++ ) - if( in_code[n] == '\n' ) linePositions.PushLast(n+1); + if( in_code[n] == '\n' ) linePositions.PushLast(n + 1); linePositions.PushLast(in_length); return asSUCCESS; @@ -100,7 +100,7 @@ int asCScriptCode::SetCode(const char *in_name, const char *in_code, size_t in_l void asCScriptCode::ConvertPosToRowCol(size_t pos, int *row, int *col) { - if( linePositions.GetLength() == 0 ) + if( linePositions.GetLength() == 0 ) { if( row ) *row = lineOffset; if( col ) *col = 1; @@ -110,9 +110,9 @@ void asCScriptCode::ConvertPosToRowCol(size_t pos, int *row, int *col) // Do a binary search in the buffer int max = (int)linePositions.GetLength() - 1; int min = 0; - int i = max/2; + int i = max / 2; - for(;;) + for( ;; ) { if( linePositions[i] < pos ) { @@ -120,7 +120,7 @@ void asCScriptCode::ConvertPosToRowCol(size_t pos, int *row, int *col) if( min == i ) break; min = i; - i = (max + min)/2; + i = (max + min) / 2; } else if( linePositions[i] > pos ) { @@ -128,7 +128,7 @@ void asCScriptCode::ConvertPosToRowCol(size_t pos, int *row, int *col) if( max == i ) break; max = i; - i = (max + min)/2; + i = (max + min) / 2; } else { diff --git a/sdk/angelscript/source/as_scriptengine.cpp b/sdk/angelscript/source/as_scriptengine.cpp index 23a57286..53110663 100644 --- a/sdk/angelscript/source/as_scriptengine.cpp +++ b/sdk/angelscript/source/as_scriptengine.cpp @@ -65,10 +65,9 @@ CProfiler g_profiler; -extern "C" -{ +extern "C" { -AS_API const char * asGetLibraryVersion() +AS_API const char *asGetLibraryVersion() { #ifdef _DEBUG return ANGELSCRIPT_VERSION_STRING " DEBUG"; @@ -77,155 +76,155 @@ AS_API const char * asGetLibraryVersion() #endif } -AS_API const char * asGetLibraryOptions() +AS_API const char *asGetLibraryOptions() { const char *string = " " // Options #ifdef AS_MAX_PORTABILITY - "AS_MAX_PORTABILITY " + "AS_MAX_PORTABILITY " #endif #ifdef AS_DEBUG - "AS_DEBUG " + "AS_DEBUG " #endif #ifdef AS_NO_CLASS_METHODS - "AS_NO_CLASS_METHODS " + "AS_NO_CLASS_METHODS " #endif #ifdef AS_USE_DOUBLE_AS_FLOAT - "AS_USE_DOUBLE_AS_FLOAT " + "AS_USE_DOUBLE_AS_FLOAT " #endif #ifdef AS_64BIT_PTR - "AS_64BIT_PTR " + "AS_64BIT_PTR " #endif #ifdef AS_NO_THREADS - "AS_NO_THREADS " + "AS_NO_THREADS " #endif #ifdef AS_NO_ATOMIC - "AS_NO_ATOMIC " + "AS_NO_ATOMIC " #endif #ifdef AS_NO_COMPILER - "AS_NO_COMPILER " + "AS_NO_COMPILER " #endif #ifdef AS_NO_MEMBER_INIT - "AS_NO_MEMBER_INIT " + "AS_NO_MEMBER_INIT " #endif #ifdef AS_NO_THISCALL_FUNCTOR_METHOD - "AS_NO_THISCALL_FUNCTOR_METHOD " + "AS_NO_THISCALL_FUNCTOR_METHOD " #endif #ifdef AS_NO_EXCEPTIONS - "AS_NO_EXCEPTIONS " + "AS_NO_EXCEPTIONS " #endif #ifdef WIP_16BYTE_ALIGN - "WIP_16BYTE_ALIGN " + "WIP_16BYTE_ALIGN " #endif #ifdef AS_BIG_ENDIAN - "AS_BIG_ENDIAN " + "AS_BIG_ENDIAN " #endif // Target system #ifdef AS_WIN - "AS_WIN " + "AS_WIN " #endif #ifdef AS_LINUX - "AS_LINUX " + "AS_LINUX " #endif #ifdef AS_MAC - "AS_MAC " + "AS_MAC " #endif #ifdef AS_SUN - "AS_SUN " + "AS_SUN " #endif #ifdef AS_BSD - "AS_BSD " + "AS_BSD " #endif #ifdef AS_XBOX - "AS_XBOX " + "AS_XBOX " #endif #ifdef AS_XBOX360 - "AS_XBOX360 " + "AS_XBOX360 " #endif #ifdef AS_PSP - "AS_PSP " + "AS_PSP " #endif #ifdef AS_PS2 - "AS_PS2 " + "AS_PS2 " #endif #ifdef AS_PS3 - "AS_PS3 " + "AS_PS3 " #endif #ifdef AS_PSVITA - "AS_PSVITA " + "AS_PSVITA " #endif #ifdef AS_DC - "AS_DC " + "AS_DC " #endif #ifdef AS_GC - "AS_GC " + "AS_GC " #endif #ifdef AS_WII - "AS_WII " + "AS_WII " #endif #ifdef AS_WIIU - "AS_WIIU " + "AS_WIIU " #endif #ifdef AS_IPHONE - "AS_IPHONE " + "AS_IPHONE " #endif #ifdef AS_ANDROID - "AS_ANDROID " + "AS_ANDROID " #endif #ifdef AS_HAIKU - "AS_HAIKU " + "AS_HAIKU " #endif #ifdef AS_ILLUMOS - "AS_ILLUMOS " + "AS_ILLUMOS " #endif #ifdef AS_MARMALADE - "AS_MARMALADE " + "AS_MARMALADE " #endif // CPU family #ifdef AS_PPC - "AS_PPC " + "AS_PPC " #endif #ifdef AS_PPC_64 - "AS_PPC_64 " + "AS_PPC_64 " #endif #ifdef AS_X86 - "AS_X86 " + "AS_X86 " #endif #ifdef AS_MIPS - "AS_MIPS " + "AS_MIPS " #endif #ifdef AS_SH4 - "AS_SH4 " + "AS_SH4 " #endif #ifdef AS_XENON - "AS_XENON " + "AS_XENON " #endif #ifdef AS_ARM - "AS_ARM " + "AS_ARM " #endif #ifdef AS_SOFTFP - "AS_SOFTFP " + "AS_SOFTFP " #endif #ifdef AS_X64_GCC - "AS_X64_GCC " + "AS_X64_GCC " #endif #ifdef AS_X64_MSVC - "AS_X64_MSVC " + "AS_X64_MSVC " #endif #ifdef AS_SPARC - "AS_SPARC " + "AS_SPARC " #endif #ifdef AS_ARM64 - "AS_ARM64 " + "AS_ARM64 " #endif #ifdef AS_RISCV64 - "AS_RISCV64 " + "AS_RISCV64 " #endif - ; + ; return string; } @@ -233,13 +232,13 @@ AS_API const char * asGetLibraryOptions() AS_API asIScriptEngine *asCreateScriptEngine(asDWORD version) { // Verify the version that the application expects - if( (version/10000) != (ANGELSCRIPT_VERSION/10000) ) + if( (version / 10000) != (ANGELSCRIPT_VERSION / 10000) ) return 0; - if( (version/100)%100 != (ANGELSCRIPT_VERSION/100)%100 ) + if( (version / 100) % 100 != (ANGELSCRIPT_VERSION / 100) % 100 ) return 0; - if( (version%100) > (ANGELSCRIPT_VERSION%100) ) + if( (version % 100) > (ANGELSCRIPT_VERSION % 100) ) return 0; // Verify the size of the types @@ -256,13 +255,13 @@ AS_API asIScriptEngine *asCreateScriptEngine(asDWORD version) // Verify endianess #ifdef AS_BIG_ENDIAN asDWORD dw = 0x00010203; - asQWORD qw = ((asQWORD(0x00010203)<<32)|asQWORD(0x04050607)); + asQWORD qw = ((asQWORD(0x00010203) << 32) | asQWORD(0x04050607)); #else asDWORD dw = 0x03020100; // C++ didn't have a standard way of declaring 64bit literal constants until C++11, so // I'm forced to do it like this to avoid compilers warnings when compiling with the full // C++ compliance. - asQWORD qw = ((asQWORD(0x07060504)<<32)|asQWORD(0x03020100)); + asQWORD qw = ((asQWORD(0x07060504) << 32) | asQWORD(0x03020100)); #endif asASSERT( memcmp("\x00\x01\x02\x03", &dw, 4) == 0 ); asASSERT( memcmp("\x00\x01\x02\x03\x04\x05\x06\x07", &qw, 8) == 0 ); @@ -280,226 +279,226 @@ int asCScriptEngine::SetEngineProperty(asEEngineProp property, asPWORD value) { switch( property ) { - case asEP_ALLOW_UNSAFE_REFERENCES: - ep.allowUnsafeReferences = value ? true : false; - break; + case asEP_ALLOW_UNSAFE_REFERENCES: + ep.allowUnsafeReferences = value ? true : false; + break; - case asEP_OPTIMIZE_BYTECODE: - ep.optimizeByteCode = value ? true : false; - break; + case asEP_OPTIMIZE_BYTECODE: + ep.optimizeByteCode = value ? true : false; + break; - case asEP_COPY_SCRIPT_SECTIONS: - ep.copyScriptSections = value ? true : false; - break; + case asEP_COPY_SCRIPT_SECTIONS: + ep.copyScriptSections = value ? true : false; + break; - case asEP_MAX_STACK_SIZE: - if( value == 0 ) - { - // Restore default: no limit and initially size 4KB - ep.maximumContextStackSize = 0; - } - else - { - // The size is given in bytes, but we only store dwords - ep.maximumContextStackSize = (asUINT)value/4; - } - break; + case asEP_MAX_STACK_SIZE: + if( value == 0 ) + { + // Restore default: no limit and initially size 4KB + ep.maximumContextStackSize = 0; + } + else + { + // The size is given in bytes, but we only store dwords + ep.maximumContextStackSize = (asUINT)value / 4; + } + break; - case asEP_INIT_STACK_SIZE: - if (value < 4) - { - // At least one dword - ep.initContextStackSize = 1; - } - else - { - // The size is given in bytes, but we only store dwords - ep.initContextStackSize = (asUINT)value / 4; - } - break; + case asEP_INIT_STACK_SIZE: + if( value < 4 ) + { + // At least one dword + ep.initContextStackSize = 1; + } + else + { + // The size is given in bytes, but we only store dwords + ep.initContextStackSize = (asUINT)value / 4; + } + break; - case asEP_USE_CHARACTER_LITERALS: - ep.useCharacterLiterals = value ? true : false; - break; + case asEP_USE_CHARACTER_LITERALS: + ep.useCharacterLiterals = value ? true : false; + break; - case asEP_ALLOW_MULTILINE_STRINGS: - ep.allowMultilineStrings = value ? true : false; - break; + case asEP_ALLOW_MULTILINE_STRINGS: + ep.allowMultilineStrings = value ? true : false; + break; - case asEP_ALLOW_IMPLICIT_HANDLE_TYPES: - ep.allowImplicitHandleTypes = value ? true : false; - break; + case asEP_ALLOW_IMPLICIT_HANDLE_TYPES: + ep.allowImplicitHandleTypes = value ? true : false; + break; - case asEP_BUILD_WITHOUT_LINE_CUES: - ep.buildWithoutLineCues = value ? true : false; - break; + case asEP_BUILD_WITHOUT_LINE_CUES: + ep.buildWithoutLineCues = value ? true : false; + break; - case asEP_INIT_GLOBAL_VARS_AFTER_BUILD: - ep.initGlobalVarsAfterBuild = value ? true : false; - break; + case asEP_INIT_GLOBAL_VARS_AFTER_BUILD: + ep.initGlobalVarsAfterBuild = value ? true : false; + break; - case asEP_REQUIRE_ENUM_SCOPE: - ep.requireEnumScope = value ? true : false; - break; + case asEP_REQUIRE_ENUM_SCOPE: + ep.requireEnumScope = value ? true : false; + break; - case asEP_SCRIPT_SCANNER: - if( value <= 1 ) - ep.scanner = (int)value; - else - return asINVALID_ARG; - break; + case asEP_SCRIPT_SCANNER: + if( value <= 1 ) + ep.scanner = (int)value; + else + return asINVALID_ARG; + break; - case asEP_INCLUDE_JIT_INSTRUCTIONS: - ep.includeJitInstructions = value ? true : false; - break; + case asEP_INCLUDE_JIT_INSTRUCTIONS: + ep.includeJitInstructions = value ? true : false; + break; - case asEP_STRING_ENCODING: - if( value <= 1 ) - ep.stringEncoding = (int)value; - else - return asINVALID_ARG; - break; + case asEP_STRING_ENCODING: + if( value <= 1 ) + ep.stringEncoding = (int)value; + else + return asINVALID_ARG; + break; - case asEP_PROPERTY_ACCESSOR_MODE: - if( value <= 3 ) - ep.propertyAccessorMode = (int)value; - else - return asINVALID_ARG; - break; + case asEP_PROPERTY_ACCESSOR_MODE: + if( value <= 3 ) + ep.propertyAccessorMode = (int)value; + else + return asINVALID_ARG; + break; - case asEP_EXPAND_DEF_ARRAY_TO_TMPL: - ep.expandDefaultArrayToTemplate = value ? true : false; - break; + case asEP_EXPAND_DEF_ARRAY_TO_TMPL: + ep.expandDefaultArrayToTemplate = value ? true : false; + break; - case asEP_AUTO_GARBAGE_COLLECT: - ep.autoGarbageCollect = value ? true : false; - break; + case asEP_AUTO_GARBAGE_COLLECT: + ep.autoGarbageCollect = value ? true : false; + break; - case asEP_DISALLOW_GLOBAL_VARS: - ep.disallowGlobalVars = value ? true : false; - break; + case asEP_DISALLOW_GLOBAL_VARS: + ep.disallowGlobalVars = value ? true : false; + break; - case asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT: - if (value > 2) - return asINVALID_ARG; - ep.alwaysImplDefaultConstruct = (int)value; - break; + case asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT: + if( value > 2 ) + return asINVALID_ARG; + ep.alwaysImplDefaultConstruct = (int)value; + break; - case asEP_COMPILER_WARNINGS: - if( value <= 2 ) - ep.compilerWarnings = (int)value; - else - return asINVALID_ARG; - break; + case asEP_COMPILER_WARNINGS: + if( value <= 2 ) + ep.compilerWarnings = (int)value; + else + return asINVALID_ARG; + break; - case asEP_DISALLOW_VALUE_ASSIGN_FOR_REF_TYPE: - ep.disallowValueAssignForRefType = value ? true : false; - break; + case asEP_DISALLOW_VALUE_ASSIGN_FOR_REF_TYPE: + ep.disallowValueAssignForRefType = value ? true : false; + break; - case asEP_ALTER_SYNTAX_NAMED_ARGS: - if( value <= 2 ) - ep.alterSyntaxNamedArgs = (int)value; - else - return asINVALID_ARG; - break; + case asEP_ALTER_SYNTAX_NAMED_ARGS: + if( value <= 2 ) + ep.alterSyntaxNamedArgs = (int)value; + else + return asINVALID_ARG; + break; - case asEP_DISABLE_INTEGER_DIVISION: - ep.disableIntegerDivision = value ? true : false; - break; + case asEP_DISABLE_INTEGER_DIVISION: + ep.disableIntegerDivision = value ? true : false; + break; - case asEP_DISALLOW_EMPTY_LIST_ELEMENTS: - ep.disallowEmptyListElements = value ? true : false; - break; + case asEP_DISALLOW_EMPTY_LIST_ELEMENTS: + ep.disallowEmptyListElements = value ? true : false; + break; - case asEP_PRIVATE_PROP_AS_PROTECTED: - ep.privatePropAsProtected = value ? true : false; - break; + case asEP_PRIVATE_PROP_AS_PROTECTED: + ep.privatePropAsProtected = value ? true : false; + break; - case asEP_ALLOW_UNICODE_IDENTIFIERS: - ep.allowUnicodeIdentifiers = value ? true : false; - break; + case asEP_ALLOW_UNICODE_IDENTIFIERS: + ep.allowUnicodeIdentifiers = value ? true : false; + break; - case asEP_HEREDOC_TRIM_MODE: - if (value <= 2) - ep.heredocTrimMode = (int)value; - else - return asINVALID_ARG; - break; + case asEP_HEREDOC_TRIM_MODE: + if( value <= 2 ) + ep.heredocTrimMode = (int)value; + else + return asINVALID_ARG; + break; - case asEP_MAX_NESTED_CALLS: - if (value > 0xFFFFFFFF) - ep.maxNestedCalls = 0xFFFFFFFF; - else - ep.maxNestedCalls = (asUINT)value; - break; + case asEP_MAX_NESTED_CALLS: + if( value > 0xFFFFFFFF ) + ep.maxNestedCalls = 0xFFFFFFFF; + else + ep.maxNestedCalls = (asUINT)value; + break; - case asEP_GENERIC_CALL_MODE: - if (value > 1) - ep.genericCallMode = 1; - else - ep.genericCallMode = (asUINT)value; - break; + case asEP_GENERIC_CALL_MODE: + if( value > 1 ) + ep.genericCallMode = 1; + else + ep.genericCallMode = (asUINT)value; + break; - case asEP_INIT_CALL_STACK_SIZE: - ep.initCallStackSize = (asUINT)value; - break; + case asEP_INIT_CALL_STACK_SIZE: + ep.initCallStackSize = (asUINT)value; + break; - case asEP_MAX_CALL_STACK_SIZE: - ep.maxCallStackSize = (asUINT)value; - break; + case asEP_MAX_CALL_STACK_SIZE: + ep.maxCallStackSize = (asUINT)value; + break; - case asEP_IGNORE_DUPLICATE_SHARED_INTF: - ep.ignoreDuplicateSharedIntf = value ? true : false; - break; + case asEP_IGNORE_DUPLICATE_SHARED_INTF: + ep.ignoreDuplicateSharedIntf = value ? true : false; + break; - case asEP_NO_DEBUG_OUTPUT: - ep.noDebugOutput = value ? true : false; - break; + case asEP_NO_DEBUG_OUTPUT: + ep.noDebugOutput = value ? true : false; + break; - case asEP_DISABLE_SCRIPT_CLASS_GC: - ep.disableScriptClassGC = value ? true : false; - break; + case asEP_DISABLE_SCRIPT_CLASS_GC: + ep.disableScriptClassGC = value ? true : false; + break; - case asEP_JIT_INTERFACE_VERSION: - if (value < 1 || value > 2) - return asINVALID_ARG; - ep.jitInterfaceVersion = (asUINT)value; - break; + case asEP_JIT_INTERFACE_VERSION: + if( value < 1 || value > 2 ) + return asINVALID_ARG; + ep.jitInterfaceVersion = (asUINT)value; + break; - case asEP_ALWAYS_IMPL_DEFAULT_COPY: - if (value > 2) - return asINVALID_ARG; - ep.alwaysImplDefaultCopy = (int)value; - break; + case asEP_ALWAYS_IMPL_DEFAULT_COPY: + if( value > 2 ) + return asINVALID_ARG; + ep.alwaysImplDefaultCopy = (int)value; + break; - case asEP_ALWAYS_IMPL_DEFAULT_COPY_CONSTRUCT: - if (value > 2) - return asINVALID_ARG; - ep.alwaysImplDefaultCopyConstruct = (int)value; - break; + case asEP_ALWAYS_IMPL_DEFAULT_COPY_CONSTRUCT: + if( value > 2 ) + return asINVALID_ARG; + ep.alwaysImplDefaultCopyConstruct = (int)value; + break; - case asEP_MEMBER_INIT_MODE: - if (value > 1) - return asINVALID_ARG; - ep.memberInitMode = (asUINT)value; - break; + case asEP_MEMBER_INIT_MODE: + if( value > 1 ) + return asINVALID_ARG; + ep.memberInitMode = (asUINT)value; + break; - case asEP_BOOL_CONVERSION_MODE: - if (value > 1) - return asINVALID_ARG; - ep.boolConversionMode = (asUINT)value; - break; + case asEP_BOOL_CONVERSION_MODE: + if( value > 1 ) + return asINVALID_ARG; + ep.boolConversionMode = (asUINT)value; + break; - case asEP_FOREACH_SUPPORT: - if (value > 1) - return asINVALID_ARG; - ep.foreachSupport = value ? true : false; - // TODO: funcdef: Make sure there is no compilation currently in progress - tok.InitJumpTable(); - break; + case asEP_FOREACH_SUPPORT: + if( value > 1 ) + return asINVALID_ARG; + ep.foreachSupport = value ? true : false; + // TODO: funcdef: Make sure there is no compilation currently in progress + tok.InitJumpTable(); + break; - default: - return asINVALID_ARG; + default: + return asINVALID_ARG; } return asSUCCESS; @@ -510,128 +509,128 @@ asPWORD asCScriptEngine::GetEngineProperty(asEEngineProp property) const { switch( property ) { - case asEP_ALLOW_UNSAFE_REFERENCES: - return ep.allowUnsafeReferences; + case asEP_ALLOW_UNSAFE_REFERENCES: + return ep.allowUnsafeReferences; - case asEP_OPTIMIZE_BYTECODE: - return ep.optimizeByteCode; + case asEP_OPTIMIZE_BYTECODE: + return ep.optimizeByteCode; - case asEP_COPY_SCRIPT_SECTIONS: - return ep.copyScriptSections; + case asEP_COPY_SCRIPT_SECTIONS: + return ep.copyScriptSections; - case asEP_MAX_STACK_SIZE: - return ep.maximumContextStackSize * 4; + case asEP_MAX_STACK_SIZE: + return ep.maximumContextStackSize * 4; - case asEP_INIT_STACK_SIZE: - return ep.initContextStackSize * 4; + case asEP_INIT_STACK_SIZE: + return ep.initContextStackSize * 4; - case asEP_USE_CHARACTER_LITERALS: - return ep.useCharacterLiterals; + case asEP_USE_CHARACTER_LITERALS: + return ep.useCharacterLiterals; - case asEP_ALLOW_MULTILINE_STRINGS: - return ep.allowMultilineStrings; + case asEP_ALLOW_MULTILINE_STRINGS: + return ep.allowMultilineStrings; - case asEP_ALLOW_IMPLICIT_HANDLE_TYPES: - return ep.allowImplicitHandleTypes; + case asEP_ALLOW_IMPLICIT_HANDLE_TYPES: + return ep.allowImplicitHandleTypes; - case asEP_BUILD_WITHOUT_LINE_CUES: - return ep.buildWithoutLineCues; + case asEP_BUILD_WITHOUT_LINE_CUES: + return ep.buildWithoutLineCues; - case asEP_INIT_GLOBAL_VARS_AFTER_BUILD: - return ep.initGlobalVarsAfterBuild; + case asEP_INIT_GLOBAL_VARS_AFTER_BUILD: + return ep.initGlobalVarsAfterBuild; - case asEP_REQUIRE_ENUM_SCOPE: - return ep.requireEnumScope; + case asEP_REQUIRE_ENUM_SCOPE: + return ep.requireEnumScope; - case asEP_SCRIPT_SCANNER: - return ep.scanner; + case asEP_SCRIPT_SCANNER: + return ep.scanner; - case asEP_INCLUDE_JIT_INSTRUCTIONS: - return ep.includeJitInstructions; + case asEP_INCLUDE_JIT_INSTRUCTIONS: + return ep.includeJitInstructions; - case asEP_STRING_ENCODING: - return ep.stringEncoding; + case asEP_STRING_ENCODING: + return ep.stringEncoding; - case asEP_PROPERTY_ACCESSOR_MODE: - return ep.propertyAccessorMode; + case asEP_PROPERTY_ACCESSOR_MODE: + return ep.propertyAccessorMode; - case asEP_EXPAND_DEF_ARRAY_TO_TMPL: - return ep.expandDefaultArrayToTemplate; + case asEP_EXPAND_DEF_ARRAY_TO_TMPL: + return ep.expandDefaultArrayToTemplate; - case asEP_AUTO_GARBAGE_COLLECT: - return ep.autoGarbageCollect; + case asEP_AUTO_GARBAGE_COLLECT: + return ep.autoGarbageCollect; - case asEP_DISALLOW_GLOBAL_VARS: - return ep.disallowGlobalVars; + case asEP_DISALLOW_GLOBAL_VARS: + return ep.disallowGlobalVars; - case asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT: - return ep.alwaysImplDefaultConstruct; + case asEP_ALWAYS_IMPL_DEFAULT_CONSTRUCT: + return ep.alwaysImplDefaultConstruct; - case asEP_COMPILER_WARNINGS: - return ep.compilerWarnings; + case asEP_COMPILER_WARNINGS: + return ep.compilerWarnings; - case asEP_DISALLOW_VALUE_ASSIGN_FOR_REF_TYPE: - return ep.disallowValueAssignForRefType; + case asEP_DISALLOW_VALUE_ASSIGN_FOR_REF_TYPE: + return ep.disallowValueAssignForRefType; - case asEP_ALTER_SYNTAX_NAMED_ARGS: - return ep.alterSyntaxNamedArgs; + case asEP_ALTER_SYNTAX_NAMED_ARGS: + return ep.alterSyntaxNamedArgs; - case asEP_DISABLE_INTEGER_DIVISION: - return ep.disableIntegerDivision; + case asEP_DISABLE_INTEGER_DIVISION: + return ep.disableIntegerDivision; - case asEP_DISALLOW_EMPTY_LIST_ELEMENTS: - return ep.disallowEmptyListElements; + case asEP_DISALLOW_EMPTY_LIST_ELEMENTS: + return ep.disallowEmptyListElements; - case asEP_PRIVATE_PROP_AS_PROTECTED: - return ep.privatePropAsProtected; + case asEP_PRIVATE_PROP_AS_PROTECTED: + return ep.privatePropAsProtected; - case asEP_ALLOW_UNICODE_IDENTIFIERS: - return ep.allowUnicodeIdentifiers; + case asEP_ALLOW_UNICODE_IDENTIFIERS: + return ep.allowUnicodeIdentifiers; - case asEP_HEREDOC_TRIM_MODE: - return ep.heredocTrimMode; + case asEP_HEREDOC_TRIM_MODE: + return ep.heredocTrimMode; - case asEP_MAX_NESTED_CALLS: - return ep.maxNestedCalls; + case asEP_MAX_NESTED_CALLS: + return ep.maxNestedCalls; - case asEP_GENERIC_CALL_MODE: - return ep.genericCallMode; + case asEP_GENERIC_CALL_MODE: + return ep.genericCallMode; - case asEP_INIT_CALL_STACK_SIZE: - return ep.initCallStackSize; + case asEP_INIT_CALL_STACK_SIZE: + return ep.initCallStackSize; - case asEP_MAX_CALL_STACK_SIZE: - return ep.maxCallStackSize; + case asEP_MAX_CALL_STACK_SIZE: + return ep.maxCallStackSize; - case asEP_IGNORE_DUPLICATE_SHARED_INTF: - return ep.ignoreDuplicateSharedIntf; + case asEP_IGNORE_DUPLICATE_SHARED_INTF: + return ep.ignoreDuplicateSharedIntf; - case asEP_NO_DEBUG_OUTPUT: - return ep.noDebugOutput; + case asEP_NO_DEBUG_OUTPUT: + return ep.noDebugOutput; - case asEP_DISABLE_SCRIPT_CLASS_GC: - return ep.disableScriptClassGC; + case asEP_DISABLE_SCRIPT_CLASS_GC: + return ep.disableScriptClassGC; - case asEP_JIT_INTERFACE_VERSION: - return ep.jitInterfaceVersion; + case asEP_JIT_INTERFACE_VERSION: + return ep.jitInterfaceVersion; - case asEP_ALWAYS_IMPL_DEFAULT_COPY: - return ep.alwaysImplDefaultCopy; + case asEP_ALWAYS_IMPL_DEFAULT_COPY: + return ep.alwaysImplDefaultCopy; - case asEP_ALWAYS_IMPL_DEFAULT_COPY_CONSTRUCT: - return ep.alwaysImplDefaultCopyConstruct; + case asEP_ALWAYS_IMPL_DEFAULT_COPY_CONSTRUCT: + return ep.alwaysImplDefaultCopyConstruct; - case asEP_MEMBER_INIT_MODE: - return ep.memberInitMode; + case asEP_MEMBER_INIT_MODE: + return ep.memberInitMode; - case asEP_BOOL_CONVERSION_MODE: - return ep.boolConversionMode; - - case asEP_FOREACH_SUPPORT: - return ep.foreachSupport; + case asEP_BOOL_CONVERSION_MODE: + return ep.boolConversionMode; - default: - return 0; + case asEP_FOREACH_SUPPORT: + return ep.foreachSupport; + + default: + return 0; } UNREACHABLE_RETURN; @@ -653,7 +652,7 @@ asIScriptFunction *asCScriptEngine::CreateDelegate(asIScriptFunction *func, void return 0; // Create the delegate the same way it would be created by the scripts - return AS_NAMESPACE_QUALIFIER CreateDelegate(reinterpret_cast(func), obj); + return AS_NAMESPACE_QUALIFIER CreateDelegate(reinterpret_cast(func), obj); } asCScriptEngine::asCScriptEngine() @@ -665,61 +664,61 @@ asCScriptEngine::asCScriptEngine() // Engine properties { - ep.allowUnsafeReferences = false; - ep.optimizeByteCode = true; - ep.copyScriptSections = true; - ep.maximumContextStackSize = 0; // no limit - ep.initContextStackSize = 1024; // 4KB default init stack size - ep.useCharacterLiterals = false; - ep.allowMultilineStrings = false; - ep.allowImplicitHandleTypes = false; + ep.allowUnsafeReferences = false; + ep.optimizeByteCode = true; + ep.copyScriptSections = true; + ep.maximumContextStackSize = 0; // no limit + ep.initContextStackSize = 1024; // 4KB default init stack size + ep.useCharacterLiterals = false; + ep.allowMultilineStrings = false; + ep.allowImplicitHandleTypes = false; // TODO: optimize: Maybe this should be turned off by default? If a debugger is not used // then this is just slowing down the execution. - ep.buildWithoutLineCues = false; - ep.initGlobalVarsAfterBuild = true; - ep.requireEnumScope = false; - ep.scanner = 1; // utf8. 0 = ascii - ep.includeJitInstructions = false; - ep.stringEncoding = 0; // utf8. 1 = utf16 - ep.propertyAccessorMode = 3; // 0 = disable, 1 = app registered only, 2 = app and script created, 3 = flag with 'property' - ep.expandDefaultArrayToTemplate = false; - ep.autoGarbageCollect = true; - ep.disallowGlobalVars = false; - ep.alwaysImplDefaultConstruct = 0; // 0 = as per language spec, 1 = always implement it, 2, never implement - ep.compilerWarnings = 1; // 0 = no warnings, 1 = warning, 2 = treat as error + ep.buildWithoutLineCues = false; + ep.initGlobalVarsAfterBuild = true; + ep.requireEnumScope = false; + ep.scanner = 1; // utf8. 0 = ascii + ep.includeJitInstructions = false; + ep.stringEncoding = 0; // utf8. 1 = utf16 + ep.propertyAccessorMode = 3; // 0 = disable, 1 = app registered only, 2 = app and script created, 3 = flag with 'property' + ep.expandDefaultArrayToTemplate = false; + ep.autoGarbageCollect = true; + ep.disallowGlobalVars = false; + ep.alwaysImplDefaultConstruct = 0; // 0 = as per language spec, 1 = always implement it, 2, never implement + ep.compilerWarnings = 1; // 0 = no warnings, 1 = warning, 2 = treat as error // TODO: 3.0.0: disallowValueAssignForRefType should be true by default - ep.disallowValueAssignForRefType = false; - ep.alterSyntaxNamedArgs = 0; // 0 = no alternate syntax, 1 = accept alternate syntax but warn, 2 = accept without warning - ep.disableIntegerDivision = false; - ep.disallowEmptyListElements = false; - ep.privatePropAsProtected = false; - ep.allowUnicodeIdentifiers = false; - ep.heredocTrimMode = 1; // 0 = never trim, 1 = don't trim on single line, 2 = trim initial and final empty line - ep.maxNestedCalls = 100; - ep.genericCallMode = 1; // 0 = old (pre 2.33.0) behavior where generic ignored auto handles, 1 = treat handles like in native call - ep.initCallStackSize = 10; // 10 levels of calls - ep.maxCallStackSize = 0; // 0 = no limit - ep.ignoreDuplicateSharedIntf = false; - ep.noDebugOutput = false; - ep.disableScriptClassGC = false; - ep.jitInterfaceVersion = 1; // 1 = JIT compiler uses asJITCompiler, 2 = JIT compiler uses asJITCompilerV2 - ep.alwaysImplDefaultCopy = 0; // 0 = as per language spec, 1 = always implement it, 2, never implement - ep.alwaysImplDefaultCopyConstruct = 0; // 0 = as per language spec, 1 = always implement it, 2, never implement - ep.memberInitMode = 1; // 0 = pre 2.38.0, members with init expr in declaration are initialized after super(), 1 = all members initialized in beginning, except if explicitly initialized in body - ep.boolConversionMode = 0; // 0 = only do use opImplConv for registered value type, 1 = use also opConv in contextual conversion even for reference types - ep.foreachSupport = true; - } - - gc.engine = this; + ep.disallowValueAssignForRefType = false; + ep.alterSyntaxNamedArgs = 0; // 0 = no alternate syntax, 1 = accept alternate syntax but warn, 2 = accept without warning + ep.disableIntegerDivision = false; + ep.disallowEmptyListElements = false; + ep.privatePropAsProtected = false; + ep.allowUnicodeIdentifiers = false; + ep.heredocTrimMode = 1; // 0 = never trim, 1 = don't trim on single line, 2 = trim initial and final empty line + ep.maxNestedCalls = 100; + ep.genericCallMode = 1; // 0 = old (pre 2.33.0) behavior where generic ignored auto handles, 1 = treat handles like in native call + ep.initCallStackSize = 10; // 10 levels of calls + ep.maxCallStackSize = 0; // 0 = no limit + ep.ignoreDuplicateSharedIntf = false; + ep.noDebugOutput = false; + ep.disableScriptClassGC = false; + ep.jitInterfaceVersion = 1; // 1 = JIT compiler uses asJITCompiler, 2 = JIT compiler uses asJITCompilerV2 + ep.alwaysImplDefaultCopy = 0; // 0 = as per language spec, 1 = always implement it, 2, never implement + ep.alwaysImplDefaultCopyConstruct = 0; // 0 = as per language spec, 1 = always implement it, 2, never implement + ep.memberInitMode = 1; // 0 = pre 2.38.0, members with init expr in declaration are initialized after super(), 1 = all members initialized in beginning, except if explicitly initialized in body + ep.boolConversionMode = 0; // 0 = only do use opImplConv for registered value type, 1 = use also opConv in contextual conversion even for reference types + ep.foreachSupport = true; + } + + gc.engine = this; tok.engine = this; refCount.set(1); - stringFactory = 0; - configFailed = false; - isPrepared = false; - isBuilding = false; + stringFactory = 0; + configFailed = false; + isPrepared = false; + isBuilding = false; deferValidationOfTemplateTypes = false; - lastModule = 0; + lastModule = 0; typeIdSeqNbr = 0; currentGroup = &defaultGroup; @@ -738,8 +737,8 @@ asCScriptEngine::asCScriptEngine() // We must set the namespace in the built-in types explicitly as // this wasn't done by the default constructor. If we do not do // this we will get null pointer access in other parts of the code - scriptTypeBehaviours.nameSpace = defaultNamespace; - functionBehaviours.nameSpace = defaultNamespace; + scriptTypeBehaviours.nameSpace = defaultNamespace; + functionBehaviours.nameSpace = defaultNamespace; // Reserve function id 0 for no function scriptFunctions.PushLast(0); @@ -865,7 +864,7 @@ asCScriptEngine::~asCScriptEngine() if( grp ) { grp->RemoveConfiguration(this); - asDELETE(grp,asCConfigGroup); + asDELETE(grp, asCConfigGroup); } } // Remove what is remaining @@ -910,8 +909,8 @@ asCScriptEngine::~asCScriptEngine() functionBehaviours.ReleaseAllFunctions(); // Release all instances of template functions - for (asUINT n = 0; n < generatedTemplateFunctionInstances.GetLength(); n++) - if (generatedTemplateFunctionInstances[n]) + for( asUINT n = 0; n < generatedTemplateFunctionInstances.GetLength(); n++ ) + if( generatedTemplateFunctionInstances[n] ) generatedTemplateFunctionInstances[n]->ReleaseInternal(); generatedTemplateFunctionInstances.SetLength(0); @@ -952,13 +951,13 @@ asCScriptEngine::~asCScriptEngine() // Free the script section names for( asUINT n = 0; n < scriptSectionNames.GetLength(); n++ ) - asDELETE(scriptSectionNames[n],asCString); + asDELETE(scriptSectionNames[n], asCString); scriptSectionNames.SetLength(0); // Clean the user data for( asUINT n = 0; n < userData.GetLength(); n += 2 ) { - if( userData[n+1] ) + if( userData[n + 1] ) { for( asUINT c = 0; c < cleanEngineFuncs.GetLength(); c++ ) if( cleanEngineFuncs[c].type == userData[n] ) @@ -1009,22 +1008,22 @@ asCModule *asCScriptEngine::FindNewOwnerForSharedType(asCTypeInfo *in_type, asCM { asASSERT( in_type->IsShared() ); - if( in_type->module != in_mod) + if( in_type->module != in_mod ) return in_type->module; for( asUINT n = 0; n < scriptModules.GetLength(); n++ ) { // TODO: optimize: If the modules already stored the shared types separately, this would be quicker - int foundIdx = -1; - asCModule *mod = scriptModules[n]; + int foundIdx = -1; + asCModule *mod = scriptModules[n]; if( mod == in_type->module ) continue; if( in_type->flags & asOBJ_ENUM ) foundIdx = mod->m_enumTypes.IndexOf(CastToEnumType(in_type)); - else if (in_type->flags & asOBJ_TYPEDEF) + else if( in_type->flags & asOBJ_TYPEDEF ) foundIdx = mod->m_typeDefs.IndexOf(CastToTypedefType(in_type)); - else if (in_type->flags & asOBJ_FUNCDEF) + else if( in_type->flags & asOBJ_FUNCDEF ) foundIdx = mod->m_funcDefs.IndexOf(CastToFuncdefType(in_type)); - else if (in_type->flags & asOBJ_TEMPLATE) + else if( in_type->flags & asOBJ_TEMPLATE ) foundIdx = mod->m_templateInstances.IndexOf(CastToObjectType(in_type)); else foundIdx = mod->m_classTypes.IndexOf(CastToObjectType(in_type)); @@ -1045,16 +1044,16 @@ asCModule *asCScriptEngine::FindNewOwnerForSharedFunc(asCScriptFunction *in_func asASSERT( in_func->IsShared() ); asASSERT(!(in_func->funcType & asFUNC_FUNCDEF)); - if( in_func->module != in_mod) + if( in_func->module != in_mod ) return in_func->module; // Check if this is a class method or class factory for a type that has already been moved to a different module - if ((in_func->objectType && in_func->objectType->module && in_func->objectType->module != in_func->module) || - (in_func->IsFactory() && in_func->returnType.GetTypeInfo()->module && in_func->returnType.GetTypeInfo()->module != in_func->module)) + if( (in_func->objectType && in_func->objectType->module && in_func->objectType->module != in_func->module) || + (in_func->IsFactory() && in_func->returnType.GetTypeInfo()->module && in_func->returnType.GetTypeInfo()->module != in_func->module) ) { - // The object type for the method has already been transferred to + // The object type for the method has already been transferred to // another module, so transfer the method to the same module - if (in_func->objectType) + if( in_func->objectType ) in_func->module = in_func->objectType->module; else in_func->module = in_func->returnType.GetTypeInfo()->module; @@ -1062,7 +1061,7 @@ asCModule *asCScriptEngine::FindNewOwnerForSharedFunc(asCScriptFunction *in_func // Make sure the function is listed in the module // The compiler may not have done this earlier, since the object // type is shared and originally compiled from another module - if (in_func->module && in_func->module->m_scriptFunctions.IndexOf(in_func) < 0) + if( in_func->module && in_func->module->m_scriptFunctions.IndexOf(in_func) < 0 ) { in_func->module->m_scriptFunctions.PushLast(in_func); in_func->AddRefInternal(); @@ -1072,8 +1071,8 @@ asCModule *asCScriptEngine::FindNewOwnerForSharedFunc(asCScriptFunction *in_func for( asUINT n = 0; n < scriptModules.GetLength(); n++ ) { // TODO: optimize: If the modules already stored the shared types separately, this would be quicker - int foundIdx = -1; - asCModule *mod = scriptModules[n]; + int foundIdx = -1; + asCModule *mod = scriptModules[n]; if( mod == in_func->module ) continue; foundIdx = mod->m_scriptFunctions.IndexOf(in_func); @@ -1118,7 +1117,7 @@ int asCScriptEngine::Release() const // It is possible that some function will temporarily increment the engine ref count // during clean-up for example while destroying the objects in the garbage collector. if( !inDestructor ) - asDELETE(const_cast(this),asCScriptEngine); + asDELETE(const_cast(this), asCScriptEngine); return 0; } @@ -1204,35 +1203,35 @@ const char *asCScriptEngine::GetDefaultNamespace() const } // internal -int asCScriptEngine::ParseNamespace(const char* nameSpace, asCArray& nsStrings) const +int asCScriptEngine::ParseNamespace(const char *nameSpace, asCArray &nsStrings) const { - if (nameSpace == 0) + if( nameSpace == 0 ) return asINVALID_ARG; asCString ns = nameSpace; - if (ns != "") + if( ns != "" ) { // Make sure the namespace is composed of alternating identifier and :: - size_t pos = 0; - bool expectIdentifier = true; - size_t len; + size_t pos = 0; + bool expectIdentifier = true; + size_t len; eTokenType t = ttIdentifier; - for (; pos < ns.GetLength(); pos += len) + for( ; pos < ns.GetLength(); pos += len ) { t = tok.GetToken(ns.AddressOf() + pos, ns.GetLength() - pos, &len); - if ((expectIdentifier && t != ttIdentifier) || (!expectIdentifier && t != ttScope)) + if( (expectIdentifier && t != ttIdentifier) || (!expectIdentifier && t != ttScope) ) return asINVALID_DECLARATION; // Make sure parent namespaces are registred in case of nested namespaces - if (expectIdentifier) + if( expectIdentifier ) nsStrings.PushLast(ns.SubString(0, pos + len)); expectIdentifier = !expectIdentifier; } // If the namespace ends with :: then strip it off - if (t == ttScope) + if( t == ttScope ) ns.SetLength(ns.GetLength() - 2); } @@ -1245,7 +1244,7 @@ int asCScriptEngine::ParseNamespace(const char* nameSpace, asCArray& int asCScriptEngine::SetDefaultNamespace(const char *nameSpace) { asCArray nsStrings; - int r = ParseNamespace(nameSpace, nsStrings); + int r = ParseNamespace(nameSpace, nsStrings); if( r < 0 ) return ConfigError(r, "SetDefaultNamespace", nameSpace, 0); @@ -1269,8 +1268,8 @@ void *asCScriptEngine::SetUserData(void *data, asPWORD type) { if( userData[n] == type ) { - void *oldData = reinterpret_cast(userData[n+1]); - userData[n+1] = reinterpret_cast(data); + void *oldData = reinterpret_cast(userData[n + 1]); + userData[n + 1] = reinterpret_cast(data); RELEASEEXCLUSIVE(engineRWLock); @@ -1298,7 +1297,7 @@ void *asCScriptEngine::GetUserData(asPWORD type) const if( userData[n] == type ) { RELEASESHARED(engineRWLock); - return reinterpret_cast(userData[n+1]); + return reinterpret_cast(userData[n + 1]); } } @@ -1308,16 +1307,16 @@ void *asCScriptEngine::GetUserData(asPWORD type) const } // interface -int asCScriptEngine::GetMessageCallback(asSFuncPtr* callback, void** obj, asDWORD* callConv) +int asCScriptEngine::GetMessageCallback(asSFuncPtr *callback, void **obj, asDWORD *callConv) { - if (!msgCallback) + if( !msgCallback ) return asNO_FUNCTION; - if (callback) + if( callback ) *callback = msgCallbackOriginalFuncPtr; - if (obj) + if( obj ) *obj = msgCallbackObj; - if (callConv) + if( callConv ) *callConv = msgCallbackOriginalCallConv; return asSUCCESS; @@ -1326,11 +1325,11 @@ int asCScriptEngine::GetMessageCallback(asSFuncPtr* callback, void** obj, asDWOR // interface int asCScriptEngine::SetMessageCallback(const asSFuncPtr &callback, void *obj, asDWORD callConv) { - msgCallback = true; - msgCallbackObj = obj; - msgCallbackOriginalFuncPtr = callback; + msgCallback = true; + msgCallbackObj = obj; + msgCallbackOriginalFuncPtr = callback; msgCallbackOriginalCallConv = callConv; - bool isObj = false; + bool isObj = false; if( (unsigned)callConv == asCALL_GENERIC || (unsigned)callConv == asCALL_THISCALL_OBJFIRST || (unsigned)callConv == asCALL_THISCALL_OBJLAST ) { msgCallback = false; @@ -1362,7 +1361,7 @@ int asCScriptEngine::WriteMessage(const char *section, int row, int col, asEMsgT { // Validate input parameters if( section == 0 || - message == 0 ) + message == 0 ) return asINVALID_ARG; // If there is no callback then there's nothing to do @@ -1420,7 +1419,7 @@ asETokenClass asCScriptEngine::ParseToken(const char *string, size_t stringLengt if( stringLength == 0 ) stringLength = strlen(string); - size_t len; + size_t len; asETokenClass tc; tok.GetToken(string, stringLength, &len, &tc); @@ -1495,7 +1494,7 @@ int asCScriptEngine::GetFactoryIdByDecl(const asCObjectType *ot, const char *dec bld.silent = true; asCScriptFunction func(this, mod, asFUNC_DUMMY); - int r = bld.ParseFunctionDeclaration(0, decl, &func, false, 0, 0, defaultNamespace); + int r = bld.ParseFunctionDeclaration(0, decl, &func, false, 0, 0, defaultNamespace); if( r < 0 ) return asINVALID_DECLARATION; @@ -1531,7 +1530,7 @@ int asCScriptEngine::GetMethodIdByDecl(const asCObjectType *ot, const char *decl // Set the object type so that the signature can be properly compared // This cast is OK, it will only be used for comparison - func.objectType = const_cast(ot); + func.objectType = const_cast(ot); func.objectType->AddRefInternal(); int r = bld.ParseFunctionDeclaration(func.objectType, decl, &func, false); @@ -1560,7 +1559,7 @@ int asCScriptEngine::GetMethodIdByDecl(const asCObjectType *ot, const char *decl // internal asCString asCScriptEngine::GetFunctionDeclaration(int funcId) { - asCString str; + asCString str; asCScriptFunction *func = GetScriptFunction(funcId); if( func ) str = func->GetDeclarationStr(); @@ -1603,14 +1602,14 @@ int asCScriptEngine::CreateContext(asIScriptContext **context, bool isInternal) // interface int asCScriptEngine::RegisterObjectProperty(const char *obj, const char *declaration, int byteOffset, int compositeOffset, bool isCompositeIndirect) { - int r; + int r; asCDataType dt; - asCBuilder bld(this, 0); + asCBuilder bld(this, 0); r = bld.ParseDataType(obj, &dt, defaultNamespace); if( r < 0 ) return ConfigError(r, "RegisterObjectProperty", obj, declaration); - if (dt.GetTypeInfo() == 0 || (dt.IsObjectHandle() && !(dt.GetTypeInfo()->GetFlags() & asOBJ_IMPLICIT_HANDLE))) + if( dt.GetTypeInfo() == 0 || (dt.IsObjectHandle() && !(dt.GetTypeInfo()->GetFlags() & asOBJ_IMPLICIT_HANDLE)) ) return ConfigError(asINVALID_OBJECT, "RegisterObjectProperty", obj, declaration); // Don't allow modifying generated template instances @@ -1622,7 +1621,7 @@ int asCScriptEngine::RegisterObjectProperty(const char *obj, const char *declara return ConfigError(asWRONG_CONFIG_GROUP, "RegisterObjectProperty", obj, declaration); asCDataType type; - asCString name; + asCString name; if( (r = bld.VerifyProperty(&dt, declaration, name, type, 0)) < 0 ) return ConfigError(r, "RegisterObjectProperty", obj, declaration); @@ -1635,7 +1634,7 @@ int asCScriptEngine::RegisterObjectProperty(const char *obj, const char *declara if( byteOffset > 32767 || byteOffset < -32768 ) return ConfigError(asINVALID_ARG, "RegisterObjectProperty", obj, declaration); // The composite offset must also obey the ADDSi restriction - if (compositeOffset > 32767 || compositeOffset < -32768) + if( compositeOffset > 32767 || compositeOffset < -32768 ) return ConfigError(asINVALID_ARG, "RegisterObjectProperty", obj, declaration); asCObjectProperty *prop = asNEW(asCObjectProperty); @@ -1651,8 +1650,8 @@ int asCScriptEngine::RegisterObjectProperty(const char *obj, const char *declara prop->isCompositeIndirect = isCompositeIndirect; prop->accessMask = defaultAccessMask; - asCObjectType *ot = CastToObjectType(dt.GetTypeInfo()); - asUINT idx = ot->properties.GetLength(); + asCObjectType *ot = CastToObjectType(dt.GetTypeInfo()); + asUINT idx = ot->properties.GetLength(); ot->properties.PushLast(prop); // Add references to types so they are not released too early @@ -1682,10 +1681,11 @@ int asCScriptEngine::RegisterInterface(const char *name) // Use builder to parse the datatype asCDataType dt; - asCBuilder bld(this, 0); - bool oldMsgCallback = msgCallback; msgCallback = false; - int r = bld.ParseDataType(name, &dt, defaultNamespace); - msgCallback = oldMsgCallback; + asCBuilder bld(this, 0); + bool oldMsgCallback = msgCallback; + msgCallback = false; + int r = bld.ParseDataType(name, &dt, defaultNamespace); + msgCallback = oldMsgCallback; if( r >= 0 ) { // If it is not in the defaultNamespace then the type was successfully parsed because @@ -1696,7 +1696,7 @@ int asCScriptEngine::RegisterInterface(const char *name) // Make sure the name is not a reserved keyword size_t tokenLen; - int token = tok.GetToken(name, strlen(name), &tokenLen); + int token = tok.GetToken(name, strlen(name), &tokenLen); if( token != ttIdentifier || strlen(name) != tokenLen ) return ConfigError(asINVALID_NAME, "RegisterInterface", name, 0); @@ -1712,14 +1712,14 @@ int asCScriptEngine::RegisterInterface(const char *name) if( st == 0 ) return ConfigError(asOUT_OF_MEMORY, "RegisterInterface", name, 0); - st->flags = asOBJ_REF | asOBJ_SCRIPT_OBJECT | asOBJ_SHARED; - st->size = 0; // Cannot be instantiated - st->name = name; + st->flags = asOBJ_REF | asOBJ_SCRIPT_OBJECT | asOBJ_SHARED; + st->size = 0; // Cannot be instantiated + st->name = name; st->nameSpace = defaultNamespace; // Use the default script class behaviours st->beh.factory = 0; - st->beh.addref = scriptTypeBehaviours.beh.addref; + st->beh.addref = scriptTypeBehaviours.beh.addref; scriptFunctions[st->beh.addref]->AddRefInternal(); st->beh.release = scriptTypeBehaviours.beh.release; scriptFunctions[st->beh.release]->AddRefInternal(); @@ -1741,8 +1741,8 @@ int asCScriptEngine::RegisterInterfaceMethod(const char *intf, const char *decla return ConfigError(asWRONG_CONFIG_GROUP, "RegisterInterfaceMethod", intf, declaration); asCDataType dt; - asCBuilder bld(this, 0); - int r = bld.ParseDataType(intf, &dt, defaultNamespace); + asCBuilder bld(this, 0); + int r = bld.ParseDataType(intf, &dt, defaultNamespace); if( r < 0 ) return ConfigError(r, "RegisterInterfaceMethod", intf, declaration); @@ -1757,7 +1757,7 @@ int asCScriptEngine::RegisterInterfaceMethod(const char *intf, const char *decla if( r < 0 ) { func->funcType = asFUNC_DUMMY; - asDELETE(func,asCScriptFunction); + asDELETE(func, asCScriptFunction); return ConfigError(asINVALID_DECLARATION, "RegisterInterfaceMethod", intf, declaration); } @@ -1766,7 +1766,7 @@ int asCScriptEngine::RegisterInterfaceMethod(const char *intf, const char *decla if( r < 0 ) { func->funcType = asFUNC_DUMMY; - asDELETE(func,asCScriptFunction); + asDELETE(func, asCScriptFunction); return ConfigError(asNAME_TAKEN, "RegisterInterfaceMethod", intf, declaration); } @@ -1787,26 +1787,26 @@ int asCScriptEngine::RegisterInterfaceMethod(const char *intf, const char *decla return func->id; } -asCTypeInfo* asCScriptEngine::GetTemplateSubTypeByName(const asCString &name) +asCTypeInfo *asCScriptEngine::GetTemplateSubTypeByName(const asCString &name) { - asCTypeInfo* subtype = 0; - for (asUINT n = 0; n < registeredTemplateSubTypes.GetLength(); n++) + asCTypeInfo *subtype = 0; + for( asUINT n = 0; n < registeredTemplateSubTypes.GetLength(); n++ ) { - if (registeredTemplateSubTypes[n]->name == name) + if( registeredTemplateSubTypes[n]->name == name ) { subtype = registeredTemplateSubTypes[n]; break; } } - if (subtype == 0) + if( subtype == 0 ) { // Create the new subtype if not already existing subtype = asNEW(asCTypeInfo)(this); - if (subtype == 0) + if( subtype == 0 ) return 0; - subtype->name = name; - subtype->size = 0; + subtype->name = name; + subtype->size = 0; subtype->flags = asOBJ_TEMPLATE_SUBTYPE; registeredTemplateSubTypes.PushLast(subtype); } @@ -1828,13 +1828,13 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asQWORD return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0); // flags are exclusive - if( (flags & asOBJ_GC) && (flags & (asOBJ_NOHANDLE|asOBJ_SCOPED|asOBJ_NOCOUNT)) ) + if( (flags & asOBJ_GC) && (flags & (asOBJ_NOHANDLE | asOBJ_SCOPED | asOBJ_NOCOUNT)) ) return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0); - if( (flags & asOBJ_NOHANDLE) && (flags & (asOBJ_GC|asOBJ_SCOPED|asOBJ_NOCOUNT|asOBJ_IMPLICIT_HANDLE)) ) + if( (flags & asOBJ_NOHANDLE) && (flags & (asOBJ_GC | asOBJ_SCOPED | asOBJ_NOCOUNT | asOBJ_IMPLICIT_HANDLE)) ) return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0); - if( (flags & asOBJ_SCOPED) && (flags & (asOBJ_GC|asOBJ_NOHANDLE|asOBJ_NOCOUNT|asOBJ_IMPLICIT_HANDLE)) ) + if( (flags & asOBJ_SCOPED) && (flags & (asOBJ_GC | asOBJ_NOHANDLE | asOBJ_NOCOUNT | asOBJ_IMPLICIT_HANDLE)) ) return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0); - if( (flags & asOBJ_NOCOUNT) && (flags & (asOBJ_GC|asOBJ_NOHANDLE|asOBJ_SCOPED)) ) + if( (flags & asOBJ_NOCOUNT) && (flags & (asOBJ_GC | asOBJ_NOHANDLE | asOBJ_SCOPED)) ) return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0); // Implicit handle is only allowed if the engine property for this is turned on @@ -1861,13 +1861,13 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asQWORD else { // Must not set the class properties, without the class flag - if( flags & (asOBJ_APP_CLASS_CONSTRUCTOR | - asOBJ_APP_CLASS_DESTRUCTOR | - asOBJ_APP_CLASS_ASSIGNMENT | - asOBJ_APP_CLASS_COPY_CONSTRUCTOR | - asOBJ_APP_CLASS_ALLINTS | - asOBJ_APP_CLASS_ALLFLOATS | - asOBJ_APP_CLASS_UNION) ) + if( flags & (asOBJ_APP_CLASS_CONSTRUCTOR | + asOBJ_APP_CLASS_DESTRUCTOR | + asOBJ_APP_CLASS_ASSIGNMENT | + asOBJ_APP_CLASS_COPY_CONSTRUCTOR | + asOBJ_APP_CLASS_ALLINTS | + asOBJ_APP_CLASS_ALLFLOATS | + asOBJ_APP_CLASS_UNION) ) { return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0); } @@ -1876,22 +1876,22 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asQWORD if( flags & asOBJ_APP_PRIMITIVE ) { if( flags & (asOBJ_APP_CLASS | - asOBJ_APP_FLOAT | - asOBJ_APP_ARRAY) ) + asOBJ_APP_FLOAT | + asOBJ_APP_ARRAY) ) return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0); } else if( flags & asOBJ_APP_FLOAT ) { - if( flags & (asOBJ_APP_CLASS | - asOBJ_APP_PRIMITIVE | - asOBJ_APP_ARRAY) ) + if( flags & (asOBJ_APP_CLASS | + asOBJ_APP_PRIMITIVE | + asOBJ_APP_ARRAY) ) return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0); } else if( flags & asOBJ_APP_ARRAY ) { - if( flags & (asOBJ_APP_CLASS | - asOBJ_APP_PRIMITIVE | - asOBJ_APP_FLOAT) ) + if( flags & (asOBJ_APP_CLASS | + asOBJ_APP_PRIMITIVE | + asOBJ_APP_FLOAT) ) return ConfigError(asINVALID_ARG, "RegisterObjectType", name, 0); } } @@ -1917,7 +1917,7 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asQWORD if( name == 0 ) return ConfigError(asINVALID_NAME, "RegisterObjectType", name, 0); - asCString typeName; + asCString typeName; asCBuilder bld(this, 0); if( flags & asOBJ_TEMPLATE ) { @@ -1935,12 +1935,12 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asQWORD if( type == 0 ) return ConfigError(asOUT_OF_MEMORY, "RegisterObjectType", name, 0); - type->name = typeName; - type->nameSpace = defaultNamespace; - type->size = byteSize; + type->name = typeName; + type->nameSpace = defaultNamespace; + type->size = byteSize; #ifdef WIP_16BYTE_ALIGN // TODO: Types smaller than 4 don't need to be aligned to 4 byte boundaries - type->alignment = (flags & asOBJ_APP_ALIGN16) ? 16 : 4; + type->alignment = (flags & asOBJ_APP_ALIGN16) ? 16 : 4; #endif type->flags = flags; type->accessMask = defaultAccessMask; @@ -1972,16 +1972,17 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asQWORD return asALREADY_REGISTERED; // Keep the most recent template generated instance type, so we know what it was before parsing the datatype - asCObjectType *mostRecentTemplateInstanceType = 0; - asUINT originalSizeOfGeneratedTemplateTypes = (asUINT)generatedTemplateTypes.GetLength(); + asCObjectType *mostRecentTemplateInstanceType = 0; + asUINT originalSizeOfGeneratedTemplateTypes = (asUINT)generatedTemplateTypes.GetLength(); if( originalSizeOfGeneratedTemplateTypes ) - mostRecentTemplateInstanceType = generatedTemplateTypes[originalSizeOfGeneratedTemplateTypes-1]; + mostRecentTemplateInstanceType = generatedTemplateTypes[originalSizeOfGeneratedTemplateTypes - 1]; // Use builder to parse the datatype asCDataType dt; - bool oldMsgCallback = msgCallback; msgCallback = false; - r = bld.ParseDataType(name, &dt, defaultNamespace); - msgCallback = oldMsgCallback; + bool oldMsgCallback = msgCallback; + msgCallback = false; + r = bld.ParseDataType(name, &dt, defaultNamespace); + msgCallback = oldMsgCallback; // If the builder fails or the namespace is different than the default // namespace, then the type name is new and it should be registered @@ -1989,7 +1990,7 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asQWORD { // Make sure the name is not a reserved keyword size_t tokenLen; - int token = tok.GetToken(name, typeName.GetLength(), &tokenLen); + int token = tok.GetToken(name, typeName.GetLength(), &tokenLen); if( token != ttIdentifier || typeName.GetLength() != tokenLen ) return ConfigError(asINVALID_NAME, "RegisterObjectType", name, 0); @@ -2005,12 +2006,12 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asQWORD if( type == 0 ) return ConfigError(asOUT_OF_MEMORY, "RegisterObjectType", name, 0); - type->name = typeName; - type->nameSpace = defaultNamespace; - type->size = byteSize; + type->name = typeName; + type->nameSpace = defaultNamespace; + type->size = byteSize; #ifdef WIP_16BYTE_ALIGN // TODO: Types smaller than 4 don't need to be aligned to 4 byte boundaries - type->alignment = (flags & asOBJ_APP_ALIGN16) ? 16 : 4; + type->alignment = (flags & asOBJ_APP_ALIGN16) ? 16 : 4; #endif type->flags = flags; type->accessMask = defaultAccessMask; @@ -2032,12 +2033,12 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asQWORD return ConfigError(asLOWER_ARRAY_DIMENSION_NOT_REGISTERED, "RegisterObjectType", name, 0); if( dt.IsReadOnly() || - dt.IsReference() ) + dt.IsReference() ) return ConfigError(asINVALID_TYPE, "RegisterObjectType", name, 0); // Was the template instance type generated before? if( generatedTemplateTypes.Exists(CastToObjectType(dt.GetTypeInfo())) && - generatedTemplateTypes[generatedTemplateTypes.GetLength()-1] == mostRecentTemplateInstanceType ) + generatedTemplateTypes[generatedTemplateTypes.GetLength() - 1] == mostRecentTemplateInstanceType ) { asCString str; str.Format(TXT_TEMPLATE_s_ALREADY_GENERATED_CANT_REGISTER, typeName.AddressOf()); @@ -2052,27 +2053,27 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asQWORD // TODO: Add this again. The type is used by the factory stubs so we need to discount that // Is the template instance type already being used? -// if( dt.GetTypeInfo()->GetRefCount() > 1 ) -// return ConfigError(asNOT_SUPPORTED, "RegisterObjectType", name, 0); + // if( dt.GetTypeInfo()->GetRefCount() > 1 ) + // return ConfigError(asNOT_SUPPORTED, "RegisterObjectType", name, 0); // Put the data type in the list asCObjectType *type = asNEW(asCObjectType)(this); if( type == 0 ) return ConfigError(asOUT_OF_MEMORY, "RegisterObjectType", name, 0); - type->name = dt.GetTypeInfo()->name; + type->name = dt.GetTypeInfo()->name; // The namespace will be the same as the original template type - type->nameSpace = dt.GetTypeInfo()->nameSpace; - for (asUINT s = 0; s < dt.GetTypeInfo()->GetSubTypeCount(); s++) + type->nameSpace = dt.GetTypeInfo()->nameSpace; + for( asUINT s = 0; s < dt.GetTypeInfo()->GetSubTypeCount(); s++ ) { type->templateSubTypes.PushLast(dt.GetSubType(s)); - if (type->templateSubTypes[s].GetTypeInfo()) + if( type->templateSubTypes[s].GetTypeInfo() ) type->templateSubTypes[s].GetTypeInfo()->AddRefInternal(); } - type->size = byteSize; + type->size = byteSize; #ifdef WIP_16BYTE_ALIGN // TODO: Types smaller than 4 don't need to be aligned to 4 byte boundaries - type->alignment = (flags & asOBJ_APP_ALIGN16) ? 16 : 4; + type->alignment = (flags & asOBJ_APP_ALIGN16) ? 16 : 4; #endif type->flags = flags; type->accessMask = defaultAccessMask; @@ -2085,7 +2086,7 @@ int asCScriptEngine::RegisterObjectType(const char *name, int byteSize, asQWORD // It is possible that multiple template instances are generated if // they have any relationship, so all of them must be removed while( generatedTemplateTypes.GetLength() > originalSizeOfGeneratedTemplateTypes ) - RemoveTemplateInstanceType(generatedTemplateTypes[generatedTemplateTypes.GetLength()-1]); + RemoveTemplateInstanceType(generatedTemplateTypes[generatedTemplateTypes.GetLength() - 1]); } } @@ -2102,9 +2103,9 @@ int asCScriptEngine::RegisterObjectBehaviour(const char *datatype, asEBehaviours if( datatype == 0 ) return ConfigError(asINVALID_ARG, "RegisterObjectBehaviour", datatype, decl); // Determine the object type - asCBuilder bld(this, 0); + asCBuilder bld(this, 0); asCDataType type; - int r = bld.ParseDataType(datatype, &type, defaultNamespace); + int r = bld.ParseDataType(datatype, &type, defaultNamespace); if( r < 0 ) return ConfigError(r, "RegisterObjectBehaviour", datatype, decl); @@ -2113,7 +2114,7 @@ int asCScriptEngine::RegisterObjectBehaviour(const char *datatype, asEBehaviours // Don't allow application to modify built-in types if( type.GetTypeInfo() == &functionBehaviours || - type.GetTypeInfo() == &scriptTypeBehaviours ) + type.GetTypeInfo() == &scriptTypeBehaviours ) return ConfigError(asINVALID_TYPE, "RegisterObjectBehaviour", datatype, decl); if( type.IsReadOnly() || type.IsReference() ) @@ -2135,14 +2136,14 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as #endif asSSystemFunctionInterface internal; - bool isMethod = !(behaviour == asBEHAVE_FACTORY || - behaviour == asBEHAVE_LIST_FACTORY || - behaviour == asBEHAVE_TEMPLATE_CALLBACK); - int r = DetectCallingConvention(isMethod, funcPointer, callConv, auxiliary, &internal); + bool isMethod = !(behaviour == asBEHAVE_FACTORY || + behaviour == asBEHAVE_LIST_FACTORY || + behaviour == asBEHAVE_TEMPLATE_CALLBACK); + int r = DetectCallingConvention(isMethod, funcPointer, callConv, auxiliary, &internal); if( r < 0 ) return ConfigError(r, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl); - internal.compositeOffset = compositeOffset; + internal.compositeOffset = compositeOffset; internal.isCompositeIndirect = isCompositeIndirect; if( (compositeOffset || isCompositeIndirect) && callConv != asCALL_THISCALL ) return ConfigError(asINVALID_ARG, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl); @@ -2155,12 +2156,12 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as { asCObjectType *tmpl = generatedTemplateTypes[n]; if( tmpl->name == objectType->name && - tmpl->nameSpace == objectType->nameSpace && - !(tmpl->templateSubTypes[0].GetTypeInfo() && (tmpl->templateSubTypes[0].GetTypeInfo()->flags & asOBJ_TEMPLATE_SUBTYPE)) ) + tmpl->nameSpace == objectType->nameSpace && + !(tmpl->templateSubTypes[0].GetTypeInfo() && (tmpl->templateSubTypes[0].GetTypeInfo()->flags & asOBJ_TEMPLATE_SUBTYPE)) ) { asCString msg; msg.Format(TXT_TEMPLATE_s_ALREADY_GENERATED_CANT_REGISTER, asCDataType::CreateType(tmpl, false).Format(tmpl->nameSpace).AddressOf()); - WriteMessage("",0,0, asMSGTYPE_ERROR, msg.AddressOf()); + WriteMessage("", 0, 0, asMSGTYPE_ERROR, msg.AddressOf()); return ConfigError(asERROR, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl); } } @@ -2173,9 +2174,9 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as // Verify function declaration asCScriptFunction func(this, 0, asFUNC_DUMMY); - bool expectListPattern = behaviour == asBEHAVE_LIST_FACTORY || behaviour == asBEHAVE_LIST_CONSTRUCT; - asCScriptNode *listPattern = 0; - asCBuilder bld(this, 0); + bool expectListPattern = behaviour == asBEHAVE_LIST_FACTORY || behaviour == asBEHAVE_LIST_CONSTRUCT; + asCScriptNode *listPattern = 0; + asCBuilder bld(this, 0); r = bld.ParseFunctionDeclaration(objectType, decl, &func, true, &internal.paramAutoHandles, &internal.returnAutoHandle, 0, expectListPattern ? &listPattern : 0); if( r < 0 ) { @@ -2195,7 +2196,7 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as if( objectType->flags & asOBJ_TEMPLATE ) { r = SetTemplateRestrictions(objectType, &func, "RegisterObjectBehaviour", decl); - if (r < 0) + if( r < 0 ) return r; } @@ -2228,8 +2229,8 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as // The templates take a hidden parameter with the object type if( (objectType->flags & asOBJ_TEMPLATE) && - (func.parameterTypes.GetLength() == 0 || - !func.parameterTypes[0].IsReference()) ) + (func.parameterTypes.GetLength() == 0 || + !func.parameterTypes[0].IsReference()) ) { WriteMessage("", 0, 0, asMSGTYPE_ERROR, TXT_FIRST_PARAM_MUST_BE_REF_FOR_TEMPLATE_FACTORY); return ConfigError(asINVALID_DECLARATION, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl); @@ -2241,7 +2242,7 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as func.id = AddBehaviourFunction(func, internal); beh->constructors.PushLast(func.id); if( func.parameterTypes.GetLength() == 0 || - (func.parameterTypes.GetLength() == 1 && (objectType->flags & asOBJ_TEMPLATE)) ) + (func.parameterTypes.GetLength() == 1 && (objectType->flags & asOBJ_TEMPLATE)) ) { beh->construct = func.id; } @@ -2253,7 +2254,7 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as // If the parameter is object, and const reference for input or inout, // and same type as this class, then this is a copy constructor. if( paramType.IsObject() && paramType.IsReference() && paramType.IsReadOnly() && - (func.inOutFlags[0] & asTM_INREF) && paramType.GetTypeInfo() == objectType ) + (func.inOutFlags[0] & asTM_INREF) && paramType.GetTypeInfo() == objectType ) beh->copyconstruct = func.id; } } @@ -2283,7 +2284,7 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as else if( behaviour == asBEHAVE_LIST_CONSTRUCT ) { func.name = "$list"; - + // Verify that the return type is void if( func.returnType != asCDataType::CreatePrimitive(ttVoid, false) ) { @@ -2305,8 +2306,8 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as // Verify the parameters // The templates take a hidden parameter with the object type - if( (!(objectType->flags & asOBJ_TEMPLATE) && (func.parameterTypes.GetLength() != 1 || !func.parameterTypes[0].IsReference())) || - ((objectType->flags & asOBJ_TEMPLATE) && (func.parameterTypes.GetLength() != 2 || !func.parameterTypes[0].IsReference() || !func.parameterTypes[1].IsReference())) ) + if( (!(objectType->flags & asOBJ_TEMPLATE) && (func.parameterTypes.GetLength() != 1 || !func.parameterTypes[0].IsReference())) || + ((objectType->flags & asOBJ_TEMPLATE) && (func.parameterTypes.GetLength() != 2 || !func.parameterTypes[0].IsReference() || !func.parameterTypes[1].IsReference())) ) { if( listPattern ) listPattern->Destroy(this); @@ -2343,7 +2344,7 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as { if( behaviour == asBEHAVE_LIST_FACTORY ) func.name = "$list"; - + // Must be a ref type and must not have asOBJ_NOHANDLE if( !(objectType->flags & asOBJ_REF) || (objectType->flags & asOBJ_NOHANDLE) ) { @@ -2363,8 +2364,8 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as // The templates take a hidden parameter with the object type if( (objectType->flags & asOBJ_TEMPLATE) && - (func.parameterTypes.GetLength() == 0 || - !func.parameterTypes[0].IsReference()) ) + (func.parameterTypes.GetLength() == 0 || + !func.parameterTypes[0].IsReference()) ) { if( listPattern ) listPattern->Destroy(this); @@ -2419,12 +2420,12 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as beh->factories.PushLast(func.id); if( (func.parameterTypes.GetLength() == 0) || - (func.parameterTypes.GetLength() == 1 && (objectType->flags & asOBJ_TEMPLATE)) ) + (func.parameterTypes.GetLength() == 1 && (objectType->flags & asOBJ_TEMPLATE)) ) { beh->factory = func.id; } else if( (func.parameterTypes.GetLength() == 1) || - (func.parameterTypes.GetLength() == 2 && (objectType->flags & asOBJ_TEMPLATE)) ) + (func.parameterTypes.GetLength() == 2 && (objectType->flags & asOBJ_TEMPLATE)) ) { if( behaviour == asBEHAVE_LIST_FACTORY ) { @@ -2442,11 +2443,11 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as else { // Is this the copy factory? - asCDataType paramType = func.parameterTypes[func.parameterTypes.GetLength()-1]; + asCDataType paramType = func.parameterTypes[func.parameterTypes.GetLength() - 1]; // If the parameter is object, and const reference for input, // and same type as this class, then this is a copy constructor. - if( paramType.IsObject() && paramType.IsReference() && paramType.IsReadOnly() && (func.inOutFlags[func.parameterTypes.GetLength()-1] & asTM_INREF) && paramType.GetTypeInfo() == objectType ) + if( paramType.IsObject() && paramType.IsReference() && paramType.IsReadOnly() && (func.inOutFlags[func.parameterTypes.GetLength() - 1] & asTM_INREF) && paramType.GetTypeInfo() == objectType ) beh->copyfactory = func.id; } } @@ -2455,9 +2456,9 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as { // Must be a ref type and must not have asOBJ_NOHANDLE, nor asOBJ_SCOPED if( !(func.objectType->flags & asOBJ_REF) || - (func.objectType->flags & asOBJ_NOHANDLE) || - (func.objectType->flags & asOBJ_SCOPED) || - (func.objectType->flags & asOBJ_NOCOUNT) ) + (func.objectType->flags & asOBJ_NOHANDLE) || + (func.objectType->flags & asOBJ_SCOPED) || + (func.objectType->flags & asOBJ_NOCOUNT) ) { WriteMessage("", 0, 0, asMSGTYPE_ERROR, TXT_ILLEGAL_BEHAVIOUR_FOR_TYPE); return ConfigError(asILLEGAL_BEHAVIOUR_FOR_TYPE, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl); @@ -2480,8 +2481,8 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as { // Must be a ref type and must not have asOBJ_NOHANDLE if( !(func.objectType->flags & asOBJ_REF) || - (func.objectType->flags & asOBJ_NOHANDLE) || - (func.objectType->flags & asOBJ_NOCOUNT) ) + (func.objectType->flags & asOBJ_NOHANDLE) || + (func.objectType->flags & asOBJ_NOCOUNT) ) { WriteMessage("", 0, 0, asMSGTYPE_ERROR, TXT_ILLEGAL_BEHAVIOUR_FOR_TYPE); return ConfigError(asILLEGAL_BEHAVIOUR_FOR_TYPE, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl); @@ -2528,7 +2529,7 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as func.id = beh->templateCallback = AddBehaviourFunction(func, internal); } else if( behaviour >= asBEHAVE_FIRST_GC && - behaviour <= asBEHAVE_LAST_GC ) + behaviour <= asBEHAVE_LAST_GC ) { // Only allow GC behaviours for types registered to be garbage collected if( !(func.objectType->flags & asOBJ_GC) ) @@ -2539,29 +2540,29 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as // Verify parameter count if( (behaviour == asBEHAVE_GETREFCOUNT || - behaviour == asBEHAVE_SETGCFLAG || - behaviour == asBEHAVE_GETGCFLAG) && - func.parameterTypes.GetLength() != 0 ) + behaviour == asBEHAVE_SETGCFLAG || + behaviour == asBEHAVE_GETGCFLAG) && + func.parameterTypes.GetLength() != 0 ) return ConfigError(asINVALID_DECLARATION, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl); if( (behaviour == asBEHAVE_ENUMREFS || - behaviour == asBEHAVE_RELEASEREFS) && - func.parameterTypes.GetLength() != 1 ) + behaviour == asBEHAVE_RELEASEREFS) && + func.parameterTypes.GetLength() != 1 ) return ConfigError(asINVALID_DECLARATION, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl); // Verify return type if( behaviour == asBEHAVE_GETREFCOUNT && - func.returnType != asCDataType::CreatePrimitive(ttInt, false) ) + func.returnType != asCDataType::CreatePrimitive(ttInt, false) ) return ConfigError(asINVALID_DECLARATION, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl); if( behaviour == asBEHAVE_GETGCFLAG && - func.returnType != asCDataType::CreatePrimitive(ttBool, false) ) + func.returnType != asCDataType::CreatePrimitive(ttBool, false) ) return ConfigError(asINVALID_DECLARATION, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl); if( (behaviour == asBEHAVE_SETGCFLAG || - behaviour == asBEHAVE_ENUMREFS || - behaviour == asBEHAVE_RELEASEREFS) && - func.returnType != asCDataType::CreatePrimitive(ttVoid, false) ) + behaviour == asBEHAVE_ENUMREFS || + behaviour == asBEHAVE_RELEASEREFS) && + func.returnType != asCDataType::CreatePrimitive(ttVoid, false) ) return ConfigError(asINVALID_DECLARATION, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl); if( behaviour == asBEHAVE_GETREFCOUNT ) @@ -2575,7 +2576,7 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as else if( behaviour == asBEHAVE_RELEASEREFS ) func.id = beh->gcReleaseAllReferences = AddBehaviourFunction(func, internal); } - else if ( behaviour == asBEHAVE_GET_WEAKREF_FLAG ) + else if( behaviour == asBEHAVE_GET_WEAKREF_FLAG ) { // This behaviour is only allowed for reference types if( !(func.objectType->flags & asOBJ_REF) ) @@ -2585,7 +2586,7 @@ int asCScriptEngine::RegisterBehaviourToObjectType(asCObjectType *objectType, as } // Don't allow it if the type is registered with nohandle or scoped - if( func.objectType->flags & (asOBJ_NOHANDLE|asOBJ_SCOPED) ) + if( func.objectType->flags & (asOBJ_NOHANDLE | asOBJ_SCOPED) ) { WriteMessage("", 0, 0, asMSGTYPE_ERROR, TXT_ILLEGAL_BEHAVIOUR_FOR_TYPE); return ConfigError(asILLEGAL_BEHAVIOUR_FOR_TYPE, "RegisterObjectBehaviour", objectType->name.AddressOf(), decl); @@ -2622,32 +2623,32 @@ int asCScriptEngine::SetTemplateRestrictions(asCObjectType *templateType, asCScr { asASSERT(templateType->flags & asOBJ_TEMPLATE); - for (asUINT subTypeIdx = 0; subTypeIdx < templateType->templateSubTypes.GetLength(); subTypeIdx++) + for( asUINT subTypeIdx = 0; subTypeIdx < templateType->templateSubTypes.GetLength(); subTypeIdx++ ) { - if (func->returnType.GetTypeInfo() == templateType->templateSubTypes[subTypeIdx].GetTypeInfo()) + if( func->returnType.GetTypeInfo() == templateType->templateSubTypes[subTypeIdx].GetTypeInfo() ) { - if (func->returnType.IsObjectHandle()) + if( func->returnType.IsObjectHandle() ) templateType->acceptValueSubType = false; - else if (!func->returnType.IsReference()) + else if( !func->returnType.IsReference() ) templateType->acceptRefSubType = false; // Can't support template subtypes by value, since each type is treated differently in the ABI - if (!func->returnType.IsObjectHandle() && !func->returnType.IsReference()) + if( !func->returnType.IsObjectHandle() && !func->returnType.IsReference() ) return ConfigError(asNOT_SUPPORTED, caller, templateType->name.AddressOf(), decl); } - for (asUINT n = 0; n < func->parameterTypes.GetLength(); n++) + for( asUINT n = 0; n < func->parameterTypes.GetLength(); n++ ) { - if (func->parameterTypes[n].GetTypeInfo() == templateType->templateSubTypes[subTypeIdx].GetTypeInfo()) + if( func->parameterTypes[n].GetTypeInfo() == templateType->templateSubTypes[subTypeIdx].GetTypeInfo() ) { - if (func->parameterTypes[n].IsObjectHandle() || - (!ep.allowUnsafeReferences && func->parameterTypes[n].IsReference() && func->inOutFlags[n] == asTM_INOUTREF)) + if( func->parameterTypes[n].IsObjectHandle() || + (!ep.allowUnsafeReferences && func->parameterTypes[n].IsReference() && func->inOutFlags[n] == asTM_INOUTREF) ) templateType->acceptValueSubType = false; - else if (!func->parameterTypes[n].IsReference()) + else if( !func->parameterTypes[n].IsReference() ) templateType->acceptRefSubType = false; // Can't support template subtypes by value, since each type is treated differently in the ABI - if (!func->parameterTypes[n].IsObjectHandle() && !func->parameterTypes[n].IsReference()) + if( !func->parameterTypes[n].IsObjectHandle() && !func->parameterTypes[n].IsReference() ) return ConfigError(asNOT_SUPPORTED, caller, templateType->name.AddressOf(), decl); } } @@ -2687,13 +2688,13 @@ int asCScriptEngine::AddBehaviourFunction(asCScriptFunction &func, asSSystemFunc } asASSERT(func.name != "" && func.name != "f"); - f->name = func.name; - f->sysFuncIntf = newInterface; - f->returnType = func.returnType; - f->objectType = func.objectType; + f->name = func.name; + f->sysFuncIntf = newInterface; + f->returnType = func.returnType; + f->objectType = func.objectType; if( f->objectType ) f->objectType->AddRefInternal(); - f->id = id; + f->id = id; f->SetReadOnly(func.IsReadOnly()); f->accessMask = defaultAccessMask; f->parameterTypes = func.parameterTypes; @@ -2722,9 +2723,9 @@ int asCScriptEngine::RegisterGlobalProperty(const char *declaration, void *point return ConfigError(asINVALID_ARG, "RegisterGlobalProperty", declaration, 0); asCDataType type; - asCString name; + asCString name; - int r; + int r; asCBuilder bld(this, 0); if( (r = bld.VerifyProperty(0, declaration, name, type, defaultNamespace)) < 0 ) return ConfigError(r, "RegisterGlobalProperty", declaration, 0); @@ -2735,10 +2736,10 @@ int asCScriptEngine::RegisterGlobalProperty(const char *declaration, void *point // Store the property info asCGlobalProperty *prop = AllocateGlobalProperty(); - prop->name = name; - prop->nameSpace = defaultNamespace; - prop->type = type; - prop->accessMask = defaultAccessMask; + prop->name = name; + prop->nameSpace = defaultNamespace; + prop->type = type; + prop->accessMask = defaultAccessMask; prop->SetRegisteredAddress(pointer); varAddressMap.Insert(prop->GetAddressOfValue(), prop); @@ -2766,7 +2767,7 @@ asCGlobalProperty *asCScriptEngine::AllocateGlobalProperty() // First check the availability of a free slot if( freeGlobalPropertyIds.GetLength() ) { - prop->id = freeGlobalPropertyIds.PopLast(); + prop->id = freeGlobalPropertyIds.PopLast(); globalProperties[prop->id] = prop; return prop; } @@ -2785,7 +2786,7 @@ void asCScriptEngine::RemoveGlobalProperty(asCGlobalProperty *prop) freeGlobalPropertyIds.PushLast(index); globalProperties[index] = 0; - asSMapNode *node; + asSMapNode *node; varAddressMap.MoveTo(&node, prop->GetAddressOfValue()); asASSERT(node); if( node ) @@ -2809,11 +2810,11 @@ int asCScriptEngine::GetGlobalPropertyByIndex(asUINT index, const char **name, c if( !prop ) return asINVALID_ARG; - if( name ) *name = prop->name.AddressOf(); - if( nameSpace ) *nameSpace = prop->nameSpace->name.AddressOf(); - if( typeId ) *typeId = GetTypeIdFromDataType(prop->type); - if( isConst ) *isConst = prop->type.IsReadOnly(); - if( pointer ) *pointer = prop->GetRegisteredAddress(); + if( name ) *name = prop->name.AddressOf(); + if( nameSpace ) *nameSpace = prop->nameSpace->name.AddressOf(); + if( typeId ) *typeId = GetTypeIdFromDataType(prop->type); + if( isConst ) *isConst = prop->type.IsReadOnly(); + if( pointer ) *pointer = prop->GetRegisteredAddress(); if( accessMask ) *accessMask = prop->accessMask; if( configGroup ) @@ -2831,11 +2832,11 @@ int asCScriptEngine::GetGlobalPropertyByIndex(asUINT index, const char **name, c // interface int asCScriptEngine::GetGlobalPropertyIndexByName(const char *in_name) const { - asCString name; + asCString name; asSNameSpace *ns = 0; if( DetermineNameAndNamespace(in_name, defaultNamespace, name, ns) < 0 ) return asINVALID_ARG; - + // Find the global var id while( ns ) { @@ -2854,15 +2855,15 @@ int asCScriptEngine::GetGlobalPropertyIndexByName(const char *in_name) const int asCScriptEngine::GetGlobalPropertyIndexByDecl(const char *decl) const { // This const cast is OK. The builder won't modify the engine - asCBuilder bld(const_cast(this), 0); + asCBuilder bld(const_cast(this), 0); // Don't write parser errors to the message callback bld.silent = true; - asCString name; + asCString name; asSNameSpace *ns; - asCDataType dt; - int r = bld.ParseVariableDeclaration(decl, defaultNamespace, name, ns, dt); + asCDataType dt; + int r = bld.ParseVariableDeclaration(decl, defaultNamespace, name, ns, dt); if( r < 0 ) return r; @@ -2887,19 +2888,19 @@ int asCScriptEngine::RegisterObjectMethod(const char *obj, const char *declarati // Determine the object type asCDataType dt; - asCBuilder bld(this, 0); - int r = bld.ParseDataType(obj, &dt, defaultNamespace); + asCBuilder bld(this, 0); + int r = bld.ParseDataType(obj, &dt, defaultNamespace); if( r < 0 ) return ConfigError(r, "RegisterObjectMethod", obj, declaration); // Don't allow application to modify primitives or handles - if( dt.GetTypeInfo() == 0 || (dt.IsObjectHandle() && !(dt.GetTypeInfo()->GetFlags() & asOBJ_IMPLICIT_HANDLE))) + if( dt.GetTypeInfo() == 0 || (dt.IsObjectHandle() && !(dt.GetTypeInfo()->GetFlags() & asOBJ_IMPLICIT_HANDLE)) ) return ConfigError(asINVALID_ARG, "RegisterObjectMethod", obj, declaration); // Don't allow application to modify built-in types or funcdefs if( dt.GetTypeInfo() == &functionBehaviours || - dt.GetTypeInfo() == &scriptTypeBehaviours || - CastToFuncdefType(dt.GetTypeInfo()) ) + dt.GetTypeInfo() == &scriptTypeBehaviours || + CastToFuncdefType(dt.GetTypeInfo()) ) return ConfigError(asINVALID_ARG, "RegisterObjectMethod", obj, declaration); // Don't allow modifying generated template instances @@ -2918,11 +2919,11 @@ int asCScriptEngine::RegisterMethodToObjectType(asCObjectType *objectType, const #endif asSSystemFunctionInterface internal; - int r = DetectCallingConvention(true, funcPointer, callConv, auxiliary, &internal); + int r = DetectCallingConvention(true, funcPointer, callConv, auxiliary, &internal); if( r < 0 ) return ConfigError(r, "RegisterObjectMethod", objectType->name.AddressOf(), declaration); - internal.compositeOffset = compositeOffset; + internal.compositeOffset = compositeOffset; internal.isCompositeIndirect = isCompositeIndirect; if( (compositeOffset || isCompositeIndirect) && callConv != asCALL_THISCALL ) return ConfigError(asINVALID_ARG, "RegisterObjectMethod", objectType->name.AddressOf(), declaration); @@ -2935,12 +2936,12 @@ int asCScriptEngine::RegisterMethodToObjectType(asCObjectType *objectType, const { asCObjectType *tmpl = generatedTemplateTypes[n]; if( tmpl->name == objectType->name && - tmpl->nameSpace == objectType->nameSpace && - !(tmpl->templateSubTypes[0].GetTypeInfo() && (tmpl->templateSubTypes[0].GetTypeInfo()->flags & asOBJ_TEMPLATE_SUBTYPE)) ) + tmpl->nameSpace == objectType->nameSpace && + !(tmpl->templateSubTypes[0].GetTypeInfo() && (tmpl->templateSubTypes[0].GetTypeInfo()->flags & asOBJ_TEMPLATE_SUBTYPE)) ) { asCString msg; msg.Format(TXT_TEMPLATE_s_ALREADY_GENERATED_CANT_REGISTER, asCDataType::CreateType(tmpl, false).Format(tmpl->nameSpace).AddressOf()); - WriteMessage("",0,0, asMSGTYPE_ERROR, msg.AddressOf()); + WriteMessage("", 0, 0, asMSGTYPE_ERROR, msg.AddressOf()); return ConfigError(asERROR, "RegisterObjectMethod", objectType->name.AddressOf(), declaration); } } @@ -2970,23 +2971,23 @@ int asCScriptEngine::RegisterMethodToObjectType(asCObjectType *objectType, const { // Set as dummy function before deleting func->funcType = asFUNC_DUMMY; - asDELETE(func,asCScriptFunction); + asDELETE(func, asCScriptFunction); return ConfigError(asINVALID_DECLARATION, "RegisterObjectMethod", objectType->name.AddressOf(), declaration); } - if (func->templateSubTypes.GetLength()) + if( func->templateSubTypes.GetLength() ) { func->funcType = asFUNC_TEMPLATE; // Template functions are only supported for generic calling convention - if (callConv != asCALL_GENERIC) + if( callConv != asCALL_GENERIC ) return ConfigError(asNOT_SUPPORTED, "RegisterObjectMethod", declaration, 0); } - if (func->IsVariadic()) + if( func->IsVariadic() ) { // Variadic functions are only supported for generic calling convention - if (callConv != asCALL_GENERIC) + if( callConv != asCALL_GENERIC ) return ConfigError(asNOT_SUPPORTED, "RegisterGlobalFunction", declaration, 0); } @@ -2995,7 +2996,7 @@ int asCScriptEngine::RegisterMethodToObjectType(asCObjectType *objectType, const if( r < 0 ) { func->funcType = asFUNC_DUMMY; - asDELETE(func,asCScriptFunction); + asDELETE(func, asCScriptFunction); return ConfigError(asNAME_TAKEN, "RegisterObjectMethod", objectType->name.AddressOf(), declaration); } @@ -3004,13 +3005,13 @@ int asCScriptEngine::RegisterMethodToObjectType(asCObjectType *objectType, const { // Set as dummy function before deleting func->funcType = asFUNC_DUMMY; - asDELETE(func,asCScriptFunction); + asDELETE(func, asCScriptFunction); if( r == -5 ) return ConfigError(asNAME_TAKEN, "RegisterObjectMethod", objectType->name.AddressOf(), declaration); else return ConfigError(asINVALID_DECLARATION, "RegisterObjectMethod", objectType->name.AddressOf(), declaration); } - + // Check against duplicate methods if( func->name == "opConv" || func->name == "opImplConv" || func->name == "opCast" || func->name == "opImplCast" ) { @@ -3019,10 +3020,10 @@ int asCScriptEngine::RegisterMethodToObjectType(asCObjectType *objectType, const { asCScriptFunction *f = scriptFunctions[func->objectType->methods[n]]; if( f->name == func->name && - f->IsSignatureExceptNameEqual(func) ) + f->IsSignatureExceptNameEqual(func) ) { func->funcType = asFUNC_DUMMY; - asDELETE(func,asCScriptFunction); + asDELETE(func, asCScriptFunction); return ConfigError(asALREADY_REGISTERED, "RegisterObjectMethod", objectType->name.AddressOf(), declaration); } } @@ -3033,10 +3034,10 @@ int asCScriptEngine::RegisterMethodToObjectType(asCObjectType *objectType, const { asCScriptFunction *f = scriptFunctions[func->objectType->methods[n]]; if( f->name == func->name && - f->IsSignatureExceptNameAndReturnTypeEqual(func) ) + f->IsSignatureExceptNameAndReturnTypeEqual(func) ) { func->funcType = asFUNC_DUMMY; - asDELETE(func,asCScriptFunction); + asDELETE(func, asCScriptFunction); return ConfigError(asALREADY_REGISTERED, "RegisterObjectMethod", objectType->name.AddressOf(), declaration); } } @@ -3054,14 +3055,14 @@ int asCScriptEngine::RegisterMethodToObjectType(asCObjectType *objectType, const if( func->objectType->flags & asOBJ_TEMPLATE ) { r = SetTemplateRestrictions(func->objectType, func, "RegisterObjectMethod", declaration); - if (r < 0) + if( r < 0 ) return r; } // TODO: beh.copy member will be removed, so this is not necessary // Is this the default copy behaviour? if( func->name == "opAssign" && func->parameterTypes.GetLength() == 1 && !func->IsReadOnly() && - ((objectType->flags & asOBJ_SCRIPT_OBJECT) || func->parameterTypes[0].IsEqualExceptRefAndConst(asCDataType::CreateType(func->objectType, false))) ) + ((objectType->flags & asOBJ_SCRIPT_OBJECT) || func->parameterTypes[0].IsEqualExceptRefAndConst(asCDataType::CreateType(func->objectType, false))) ) { if( func->objectType->beh.copy != 0 ) return ConfigError(asALREADY_REGISTERED, "RegisterObjectMethod", objectType->name.AddressOf(), declaration); @@ -3083,7 +3084,7 @@ int asCScriptEngine::RegisterGlobalFunction(const char *declaration, const asSFu #endif asSSystemFunctionInterface internal; - int r = DetectCallingConvention(false, funcPointer, callConv, auxiliary, &internal); + int r = DetectCallingConvention(false, funcPointer, callConv, auxiliary, &internal); if( r < 0 ) return ConfigError(r, "RegisterGlobalFunction", declaration, 0); @@ -3109,23 +3110,23 @@ int asCScriptEngine::RegisterGlobalFunction(const char *declaration, const asSFu { // Set as dummy function before deleting func->funcType = asFUNC_DUMMY; - asDELETE(func,asCScriptFunction); + asDELETE(func, asCScriptFunction); return ConfigError(asINVALID_DECLARATION, "RegisterGlobalFunction", declaration, 0); } - if (func->templateSubTypes.GetLength()) + if( func->templateSubTypes.GetLength() ) { func->funcType = asFUNC_TEMPLATE; // Template functions are only supported for generic calling convention - if (callConv != asCALL_GENERIC) + if( callConv != asCALL_GENERIC ) return ConfigError(asNOT_SUPPORTED, "RegisterGlobalFunction", declaration, 0); } - if (func->IsVariadic()) + if( func->IsVariadic() ) { // Variadic functions are only supported for generic calling convention - if(callConv != asCALL_GENERIC) + if( callConv != asCALL_GENERIC ) return ConfigError(asNOT_SUPPORTED, "RegisterGlobalFunction", declaration, 0); } @@ -3138,16 +3139,16 @@ int asCScriptEngine::RegisterGlobalFunction(const char *declaration, const asSFu { // Set as dummy function before deleting func->funcType = asFUNC_DUMMY; - asDELETE(func,asCScriptFunction); + asDELETE(func, asCScriptFunction); return ConfigError(asNAME_TAKEN, "RegisterGlobalFunction", declaration, 0); } - + // Validate property signature if( func->IsProperty() && (r = bld.ValidateVirtualProperty(func)) < 0 ) { // Set as dummy function before deleting func->funcType = asFUNC_DUMMY; - asDELETE(func,asCScriptFunction); + asDELETE(func, asCScriptFunction); if( r == -5 ) return ConfigError(asNAME_TAKEN, "RegisterGlobalFunction", declaration, 0); else @@ -3155,7 +3156,7 @@ int asCScriptEngine::RegisterGlobalFunction(const char *declaration, const asSFu } // Make sure the function is not identical to a previously registered function - asUINT n; + asUINT n; const asCArray &idxs = registeredGlobalFuncs.GetIndexes(func->nameSpace, func->name); for( n = 0; n < idxs.GetLength(); n++ ) { @@ -3163,7 +3164,7 @@ int asCScriptEngine::RegisterGlobalFunction(const char *declaration, const asSFu if( f->IsSignatureExceptNameAndReturnTypeEqual(func) ) { func->funcType = asFUNC_DUMMY; - asDELETE(func,asCScriptFunction); + asDELETE(func, asCScriptFunction); return ConfigError(asALREADY_REGISTERED, "RegisterGlobalFunction", declaration, 0); } } @@ -3174,8 +3175,8 @@ int asCScriptEngine::RegisterGlobalFunction(const char *declaration, const asSFu currentGroup->scriptFunctions.PushLast(func); func->accessMask = defaultAccessMask; registeredGlobalFuncs.Put(func); - if(func->templateSubTypes.GetLength()) registeredTemplateGlobalFuncs.PushLast(func); - + if( func->templateSubTypes.GetLength() ) registeredTemplateGlobalFuncs.PushLast(func); + // If parameter type from other groups are used, add references currentGroup->AddReferencesForFunc(this, func); @@ -3184,52 +3185,52 @@ int asCScriptEngine::RegisterGlobalFunction(const char *declaration, const asSFu return func->id; } -int asCScriptEngine::GetTemplateFunctionInstance(asCScriptFunction* baseFunc, const asCArray& types) +int asCScriptEngine::GetTemplateFunctionInstance(asCScriptFunction *baseFunc, const asCArray &types) { // Check if the template function instance already exists // TODO: optimize look up. Build a hash of the baseFunc pointer and types, then store the lookup in a asCMap - for (asUINT n = 0; n < generatedTemplateFunctionInstances.GetLength(); n++) + for( asUINT n = 0; n < generatedTemplateFunctionInstances.GetLength(); n++ ) { - asCScriptFunction* func = generatedTemplateFunctionInstances[n]; - if (func == 0) continue; + asCScriptFunction *func = generatedTemplateFunctionInstances[n]; + if( func == 0 ) continue; - if (func->name == baseFunc->name && - func->nameSpace == baseFunc->nameSpace && - func->objectType == baseFunc->objectType && - func->templateSubTypes == types) + if( func->name == baseFunc->name && + func->nameSpace == baseFunc->nameSpace && + func->objectType == baseFunc->objectType && + func->templateSubTypes == types ) return func->id; } // Generate the new template function instance - asCScriptFunction* newFunc = asNEW(asCScriptFunction)(this, 0, baseFunc->funcType); - if (newFunc == 0) + asCScriptFunction *newFunc = asNEW(asCScriptFunction)(this, 0, baseFunc->funcType); + if( newFunc == 0 ) return asOUT_OF_MEMORY; newFunc->name = baseFunc->name; - for (asUINT n = 0; n < baseFunc->defaultArgs.GetLength(); n++) - if (baseFunc->defaultArgs[n]) + for( asUINT n = 0; n < baseFunc->defaultArgs.GetLength(); n++ ) + if( baseFunc->defaultArgs[n] ) newFunc->defaultArgs.PushLast(asNEW(asCString)(*baseFunc->defaultArgs[n])); else newFunc->defaultArgs.PushLast(0); newFunc->parameterNames = baseFunc->parameterNames; - newFunc->inOutFlags = baseFunc->inOutFlags; - newFunc->traits = baseFunc->traits; + newFunc->inOutFlags = baseFunc->inOutFlags; + newFunc->traits = baseFunc->traits; newFunc->SetReadOnly(baseFunc->IsReadOnly()); newFunc->objectType = baseFunc->objectType; if( newFunc->objectType ) newFunc->objectType->AddRefInternal(); newFunc->sysFuncIntf = asNEW(asSSystemFunctionInterface)(*baseFunc->sysFuncIntf); - newFunc->funcType = asFUNC_SYSTEM; - newFunc->nameSpace = baseFunc->nameSpace; + newFunc->funcType = asFUNC_SYSTEM; + newFunc->nameSpace = baseFunc->nameSpace; // TODO: Need to know the module if it is a script that instantiates the template function newFunc->returnType = DetermineTypeForTemplate(baseFunc->returnType, baseFunc->templateSubTypes, types, 0, 0, 0); newFunc->parameterTypes.SetLength(baseFunc->parameterTypes.GetLength()); - for (asUINT p = 0; p < baseFunc->parameterTypes.GetLength(); p++) + for( asUINT p = 0; p < baseFunc->parameterTypes.GetLength(); p++ ) newFunc->parameterTypes[p] = DetermineTypeForTemplate(baseFunc->parameterTypes[p], baseFunc->templateSubTypes, types, 0, 0, 0); newFunc->templateSubTypes = types; - for (asUINT t = 0; t < newFunc->templateSubTypes.GetLength(); t++) - if (newFunc->templateSubTypes[t].GetTypeInfo()) + for( asUINT t = 0; t < newFunc->templateSubTypes.GetLength(); t++ ) + if( newFunc->templateSubTypes[t].GetTypeInfo() ) newFunc->templateSubTypes[t].GetTypeInfo()->AddRefInternal(); newFunc->id = GetNextScriptFunctionId(); @@ -3239,8 +3240,8 @@ int asCScriptEngine::GetTemplateFunctionInstance(asCScriptFunction* baseFunc, co generatedTemplateFunctionInstances.PushLast(newFunc); // This holds a reference (constructor already set it to 1) // Adjust the clean up instructions - if (newFunc->sysFuncIntf->callConv == ICC_GENERIC_FUNC || - newFunc->sysFuncIntf->callConv == ICC_GENERIC_METHOD) + if( newFunc->sysFuncIntf->callConv == ICC_GENERIC_FUNC || + newFunc->sysFuncIntf->callConv == ICC_GENERIC_METHOD ) PrepareSystemFunctionGeneric(newFunc, newFunc->sysFuncIntf, this); else PrepareSystemFunction(newFunc, newFunc->sysFuncIntf, this); @@ -3252,7 +3253,7 @@ int asCScriptEngine::GetTemplateFunctionInstance(asCScriptFunction* baseFunc, co asUINT asCScriptEngine::GetGlobalFunctionCount() const { // Don't count the builtin delegate factory - return asUINT(registeredGlobalFuncs.GetSize()-1); + return asUINT(registeredGlobalFuncs.GetSize() - 1); } // interface @@ -3264,19 +3265,19 @@ asIScriptFunction *asCScriptEngine::GetGlobalFunctionByIndex(asUINT index) const if( index >= registeredGlobalFuncs.GetSize() ) return 0; - return static_cast(const_cast(registeredGlobalFuncs.Get(index))); + return static_cast(const_cast(registeredGlobalFuncs.Get(index))); } // interface asIScriptFunction *asCScriptEngine::GetGlobalFunctionByDecl(const char *decl) const { - asCBuilder bld(const_cast(this), 0); + asCBuilder bld(const_cast(this), 0); // Don't write parser errors to the message callback bld.silent = true; - asCScriptFunction func(const_cast(this), 0, asFUNC_DUMMY); - int r = bld.ParseFunctionDeclaration(0, decl, &func, false, 0, 0, defaultNamespace); + asCScriptFunction func(const_cast(this), 0, asFUNC_DUMMY); + int r = bld.ParseFunctionDeclaration(0, decl, &func, false, 0, 0, defaultNamespace); if( r < 0 ) return 0; @@ -3286,15 +3287,14 @@ asIScriptFunction *asCScriptEngine::GetGlobalFunctionByDecl(const char *decl) co // Search script functions for matching interface while( ns ) { - asIScriptFunction *f = 0; + asIScriptFunction *f = 0; const asCArray &idxs = registeredGlobalFuncs.GetIndexes(ns, func.name); for( unsigned int n = 0; n < idxs.GetLength(); n++ ) { const asCScriptFunction *funcPtr = registeredGlobalFuncs.Get(idxs[n]); if( funcPtr->objectType == 0 && - func.returnType == funcPtr->returnType && - func.parameterTypes.GetLength() == funcPtr->parameterTypes.GetLength() - ) + func.returnType == funcPtr->returnType && + func.parameterTypes.GetLength() == funcPtr->parameterTypes.GetLength() ) { bool match = true; for( asUINT p = 0; p < func.parameterTypes.GetLength(); ++p ) @@ -3309,7 +3309,7 @@ asIScriptFunction *asCScriptEngine::GetGlobalFunctionByDecl(const char *decl) co if( match ) { if( f == 0 ) - f = const_cast(funcPtr); + f = const_cast(funcPtr); else // Multiple functions return 0; @@ -3352,7 +3352,7 @@ void asCScriptEngine::PrepareEngine() if( scriptFunctions[n] && scriptFunctions[n]->funcType == asFUNC_SYSTEM ) { if( scriptFunctions[n]->sysFuncIntf->callConv == ICC_GENERIC_FUNC || - scriptFunctions[n]->sysFuncIntf->callConv == ICC_GENERIC_METHOD ) + scriptFunctions[n]->sysFuncIntf->callConv == ICC_GENERIC_METHOD ) PrepareSystemFunctionGeneric(scriptFunctions[n], scriptFunctions[n]->sysFuncIntf, this); else PrepareSystemFunction(scriptFunctions[n], scriptFunctions[n]->sysFuncIntf, this); @@ -3365,31 +3365,31 @@ void asCScriptEngine::PrepareEngine() asCObjectType *type = registeredObjTypes[n]; if( type && !(type->flags & asOBJ_SCRIPT_OBJECT) ) { - bool missingBehaviour = false; - const char *infoMsg = 0; + bool missingBehaviour = false; + const char *infoMsg = 0; // Verify that GC types have all behaviours if( type->flags & asOBJ_GC ) { - if (type->flags & asOBJ_REF) + if( type->flags & asOBJ_REF ) { - if (type->beh.addref == 0 || - type->beh.release == 0 || - type->beh.gcGetRefCount == 0 || - type->beh.gcSetFlag == 0 || - type->beh.gcGetFlag == 0 || - type->beh.gcEnumReferences == 0 || - type->beh.gcReleaseAllReferences == 0) + if( type->beh.addref == 0 || + type->beh.release == 0 || + type->beh.gcGetRefCount == 0 || + type->beh.gcSetFlag == 0 || + type->beh.gcGetFlag == 0 || + type->beh.gcEnumReferences == 0 || + type->beh.gcReleaseAllReferences == 0 ) { - infoMsg = TXT_GC_REQUIRE_ADD_REL_GC_BEHAVIOUR; + infoMsg = TXT_GC_REQUIRE_ADD_REL_GC_BEHAVIOUR; missingBehaviour = true; } } else { - if (type->beh.gcEnumReferences == 0) + if( type->beh.gcEnumReferences == 0 ) { - infoMsg = TXT_VALUE_GC_REQUIRE_GC_BEHAVIOUR; + infoMsg = TXT_VALUE_GC_REQUIRE_GC_BEHAVIOUR; missingBehaviour = true; } } @@ -3399,31 +3399,31 @@ void asCScriptEngine::PrepareEngine() { if( type->beh.release == 0 ) { - infoMsg = TXT_SCOPE_REQUIRE_REL_BEHAVIOUR; + infoMsg = TXT_SCOPE_REQUIRE_REL_BEHAVIOUR; missingBehaviour = true; } } // Verify that ref types have add ref and release behaviours if( (type->flags & asOBJ_REF) && - !(type->flags & asOBJ_SCOPED) && - !(type->flags & asOBJ_NOHANDLE) && - !(type->flags & asOBJ_NOCOUNT) ) + !(type->flags & asOBJ_SCOPED) && + !(type->flags & asOBJ_NOHANDLE) && + !(type->flags & asOBJ_NOCOUNT) ) { - if( type->beh.addref == 0 || - type->beh.release == 0 ) + if( type->beh.addref == 0 || + type->beh.release == 0 ) { - infoMsg = TXT_REF_REQUIRE_ADD_REL_BEHAVIOUR; + infoMsg = TXT_REF_REQUIRE_ADD_REL_BEHAVIOUR; missingBehaviour = true; } } // Verify that non-pod value types have the constructor and destructor registered if( (type->flags & asOBJ_VALUE) && - !(type->flags & asOBJ_POD) ) + !(type->flags & asOBJ_POD) ) { if( type->beh.constructors.GetLength() == 0 || - type->beh.destruct == 0 ) + type->beh.destruct == 0 ) { - infoMsg = TXT_NON_POD_REQUIRE_CONSTR_DESTR_BEHAVIOUR; + infoMsg = TXT_NON_POD_REQUIRE_CONSTR_DESTR_BEHAVIOUR; missingBehaviour = true; } } @@ -3466,13 +3466,13 @@ int asCScriptEngine::ConfigError(int err, const char *funcName, const char *arg1 // interface int asCScriptEngine::RegisterDefaultArrayType(const char *type) { - asCBuilder bld(this, 0); + asCBuilder bld(this, 0); asCDataType dt; - int r = bld.ParseDataType(type, &dt, defaultNamespace); + int r = bld.ParseDataType(type, &dt, defaultNamespace); if( r < 0 ) return r; if( dt.GetTypeInfo() == 0 || - !(dt.GetTypeInfo()->GetFlags() & asOBJ_TEMPLATE) ) + !(dt.GetTypeInfo()->GetFlags() & asOBJ_TEMPLATE) ) return asINVALID_TYPE; defaultArrayObjectType = CastToObjectType(dt.GetTypeInfo()); @@ -3494,42 +3494,42 @@ int asCScriptEngine::GetDefaultArrayTypeId() const int asCScriptEngine::RegisterStringFactory(const char *datatype, asIStringFactory *factory) { // TODO: Add check to prohibit registering a new factory if one already is registered - // This is because the engine keeps references to strings in the factory, and + // This is because the engine keeps references to strings in the factory, and // won't be able to handle it if the string factory is replaced - if (factory == 0) + if( factory == 0 ) return ConfigError(asINVALID_ARG, "RegisterStringFactory", datatype, 0); // Parse the data type - asCBuilder bld(this, 0); + asCBuilder bld(this, 0); asCDataType dt; - int r = bld.ParseDataType(datatype, &dt, defaultNamespace, true); - if (r < 0) + int r = bld.ParseDataType(datatype, &dt, defaultNamespace, true); + if( r < 0 ) return ConfigError(asINVALID_TYPE, "RegisterStringFactory", datatype, 0); // Validate the type. It must not be reference or handle - if (dt.IsReference() || dt.IsObjectHandle()) + if( dt.IsReference() || dt.IsObjectHandle() ) return ConfigError(asINVALID_TYPE, "RegisterStringFactory", datatype, 0); // All string literals will be treated as const dt.MakeReadOnly(true); - stringType = dt; + stringType = dt; stringFactory = factory; return asSUCCESS; } // interface -int asCScriptEngine::GetStringFactory(asDWORD* flags, asIStringFactory **factory) const +int asCScriptEngine::GetStringFactory(asDWORD *flags, asIStringFactory **factory) const { - if (factory) + if( factory ) *factory = stringFactory; - if (stringFactory == 0) + if( stringFactory == 0 ) return asNO_FUNCTION; - if (flags) + if( flags ) *flags = 0; return GetTypeIdFromDataType(stringType); } @@ -3664,9 +3664,9 @@ asCObjectType *asCScriptEngine::GetTemplateInstanceType(asCObjectType *templateT { asCObjectType *type = templateInstanceTypes[n]; if( type && - type->name == templateType->name && - type->nameSpace == templateType->nameSpace && - type->templateSubTypes == subTypes ) + type->name == templateType->name && + type->nameSpace == templateType->nameSpace && + type->templateSubTypes == subTypes ) { // If the template instance is generated, then the module should hold a reference // to it so the config group can determine see that the template type is in use. @@ -3785,12 +3785,12 @@ asCObjectType *asCScriptEngine::GetTemplateInstanceType(asCObjectType *templateT { // Store the real factory in the constructor. This is used by the CreateScriptObject function. // Otherwise it wouldn't be necessary to store the real factory ids. - ot->beh.construct = templateType->beh.factory; + ot->beh.construct = templateType->beh.factory; ot->beh.constructors = templateType->beh.factories; } else { - ot->beh.construct = templateType->beh.construct; + ot->beh.construct = templateType->beh.construct; ot->beh.constructors = templateType->beh.constructors; } for( n = 0; n < ot->beh.constructors.GetLength(); n++ ) @@ -3810,10 +3810,10 @@ asCObjectType *asCScriptEngine::GetTemplateInstanceType(asCObjectType *templateT // Any child funcdefs must be copied to the template instance (with adjustments in case of template subtypes) // This must be done before resolving other methods, to make sure the other methods that may refer to the // templated funcdef will resolve to the new funcdef - for (n = 0; n < templateType->childFuncDefs.GetLength(); n++) + for( n = 0; n < templateType->childFuncDefs.GetLength(); n++ ) { asCFuncdefType *funcdef = GenerateFuncdefForTemplateObjectInstance(templateType, ot, templateType->childFuncDefs[n]); - funcdef->parentClass = ot; + funcdef->parentClass = ot; ot->childFuncDefs.PushLast(funcdef); } @@ -3821,8 +3821,8 @@ asCObjectType *asCScriptEngine::GetTemplateInstanceType(asCObjectType *templateT // generate new functions to substitute the ones with the template subtype. for( n = 0; n < ot->beh.constructors.GetLength(); n++ ) { - int funcId = ot->beh.constructors[n]; - asCScriptFunction *func = scriptFunctions[funcId]; + int funcId = ot->beh.constructors[n]; + asCScriptFunction *func = scriptFunctions[funcId]; if( GenerateFunctionForTemplateObjectInstance(templateType, ot, func, &func) ) { @@ -3880,44 +3880,44 @@ asCObjectType *asCScriptEngine::GetTemplateInstanceType(asCObjectType *templateT } // Create new template functions for behaviours that may need to know the new object type id - int funcId = templateType->beh.destruct; - asCScriptFunction* func = scriptFunctions[funcId]; - if (func && GenerateFunctionForTemplateObjectInstance(templateType, ot, func, &func)) + int funcId = templateType->beh.destruct; + asCScriptFunction *func = scriptFunctions[funcId]; + if( func && GenerateFunctionForTemplateObjectInstance(templateType, ot, func, &func) ) ot->beh.destruct = func->id; else { ot->beh.destruct = templateType->beh.destruct; - if (scriptFunctions[ot->beh.destruct]) scriptFunctions[ot->beh.destruct]->AddRefInternal(); + if( scriptFunctions[ot->beh.destruct] ) scriptFunctions[ot->beh.destruct]->AddRefInternal(); } funcId = templateType->beh.copy; - func = scriptFunctions[funcId]; - if (func && GenerateFunctionForTemplateObjectInstance(templateType, ot, func, &func)) + func = scriptFunctions[funcId]; + if( func && GenerateFunctionForTemplateObjectInstance(templateType, ot, func, &func) ) ot->beh.copy = func->id; else { ot->beh.copy = templateType->beh.copy; - if (scriptFunctions[ot->beh.copy]) scriptFunctions[ot->beh.copy]->AddRefInternal(); + if( scriptFunctions[ot->beh.copy] ) scriptFunctions[ot->beh.copy]->AddRefInternal(); } funcId = templateType->beh.gcEnumReferences; - func = scriptFunctions[funcId]; - if (func && GenerateFunctionForTemplateObjectInstance(templateType, ot, func, &func)) + func = scriptFunctions[funcId]; + if( func && GenerateFunctionForTemplateObjectInstance(templateType, ot, func, &func) ) ot->beh.gcEnumReferences = func->id; else { ot->beh.gcEnumReferences = templateType->beh.gcEnumReferences; - if (scriptFunctions[ot->beh.gcEnumReferences]) scriptFunctions[ot->beh.gcEnumReferences]->AddRefInternal(); + if( scriptFunctions[ot->beh.gcEnumReferences] ) scriptFunctions[ot->beh.gcEnumReferences]->AddRefInternal(); } funcId = templateType->beh.gcReleaseAllReferences; - func = scriptFunctions[funcId]; - if (func && GenerateFunctionForTemplateObjectInstance(templateType, ot, func, &func)) + func = scriptFunctions[funcId]; + if( func && GenerateFunctionForTemplateObjectInstance(templateType, ot, func, &func) ) ot->beh.gcReleaseAllReferences = func->id; else { ot->beh.gcReleaseAllReferences = templateType->beh.gcReleaseAllReferences; - if (scriptFunctions[ot->beh.gcReleaseAllReferences]) scriptFunctions[ot->beh.gcReleaseAllReferences]->AddRefInternal(); + if( scriptFunctions[ot->beh.gcReleaseAllReferences] ) scriptFunctions[ot->beh.gcReleaseAllReferences]->AddRefInternal(); } // For the last behaviours no unique copy is generated. It is not expected that @@ -3940,7 +3940,7 @@ asCObjectType *asCScriptEngine::GetTemplateInstanceType(asCObjectType *templateT for( n = 0; n < ot->methods.GetLength(); n++ ) { funcId = ot->methods[n]; - func = scriptFunctions[funcId]; + func = scriptFunctions[funcId]; if( GenerateFunctionForTemplateObjectInstance(templateType, ot, func, &func) ) { @@ -3973,12 +3973,12 @@ asILockableSharedBool *asCScriptEngine::GetWeakRefFlagOfScriptObject(void *obj, // Make sure it is not a null pointer if( obj == 0 || type == 0 ) return 0; - const asCObjectType *objType = static_cast(type); - asILockableSharedBool *dest = 0; + const asCObjectType *objType = static_cast(type); + asILockableSharedBool *dest = 0; if( objType->beh.getWeakRefFlag ) { // Call the getweakrefflag behaviour - dest = reinterpret_cast(CallObjectMethodRetPtr(obj, objType->beh.getWeakRefFlag)); + dest = reinterpret_cast(CallObjectMethodRetPtr(obj, objType->beh.getWeakRefFlag)); } return dest; } @@ -3988,9 +3988,9 @@ asILockableSharedBool *asCScriptEngine::GetWeakRefFlagOfScriptObject(void *obj, // templateSubTypes is the list of template subtypes in the original declaration, used to find the index into the target type list for replacement // targetSubTypes is the list of target subtypes in the instance // (optional) mod is the module that should be used if a new template instance is needed -// (optional) tmpl is the registered template object. Used to find which subtype is being replaced -// (optional) ot is the new template object instance that is being created. Used to find the target type -asCDataType asCScriptEngine::DetermineTypeForTemplate(const asCDataType &orig, const asCArray& templateSubTypes, const asCArray& targetSubTypes, asCModule *mod, asCObjectType *tmpl, asCObjectType *ot) +// (optional) tmpl is the registered template object. Used to find which subtype is being replaced +// (optional) ot is the new template object instance that is being created. Used to find the target type +asCDataType asCScriptEngine::DetermineTypeForTemplate(const asCDataType &orig, const asCArray &templateSubTypes, const asCArray &targetSubTypes, asCModule *mod, asCObjectType *tmpl, asCObjectType *ot) { asASSERT( (!tmpl && !ot) || (tmpl && ot)); @@ -4003,7 +4003,7 @@ asCDataType asCScriptEngine::DetermineTypeForTemplate(const asCDataType &orig, c if( orig.GetTypeInfo() == templateSubTypes[n].GetTypeInfo() ) { found = true; - dt = targetSubTypes[n]; + dt = targetSubTypes[n]; if( orig.IsObjectHandle() && !dt.IsObjectHandle() ) { dt.MakeHandle(true, true); @@ -4018,7 +4018,7 @@ asCDataType asCScriptEngine::DetermineTypeForTemplate(const asCDataType &orig, c // The target type is a handle, then check if the application // wants this handle to be to a const object. This is done by // flagging the type with 'if_handle_then_const' in the declaration. - if (dt.IsObjectHandle() && orig.HasIfHandleThenConst()) + if( dt.IsObjectHandle() && orig.HasIfHandleThenConst() ) dt.MakeHandleToConst(true); dt.MakeReference(orig.IsReference()); @@ -4028,7 +4028,7 @@ asCDataType asCScriptEngine::DetermineTypeForTemplate(const asCDataType &orig, c } } asASSERT( found ); - UNUSED_VAR( found ); + UNUSED_VAR(found); } else if( tmpl && orig.GetTypeInfo() == tmpl ) { @@ -4044,14 +4044,14 @@ asCDataType asCScriptEngine::DetermineTypeForTemplate(const asCDataType &orig, c { // The type is itself a template, so it is necessary to find the correct template instance type asCArray tmplSubTypes; - asCObjectType *origType = CastToObjectType(orig.GetTypeInfo()); - bool needInstance = true; + asCObjectType *origType = CastToObjectType(orig.GetTypeInfo()); + bool needInstance = true; // Find the matching replacements for the subtypes for( asUINT n = 0; n < origType->templateSubTypes.GetLength(); n++ ) { if( origType->templateSubTypes[n].GetTypeInfo() == 0 || - !(origType->templateSubTypes[n].GetTypeInfo()->flags & asOBJ_TEMPLATE_SUBTYPE) ) + !(origType->templateSubTypes[n].GetTypeInfo()->flags & asOBJ_TEMPLATE_SUBTYPE) ) { // The template is already an instance so we shouldn't attempt to create another instance needInstance = false; @@ -4062,7 +4062,7 @@ asCDataType asCScriptEngine::DetermineTypeForTemplate(const asCDataType &orig, c if( origType->templateSubTypes[n].GetTypeInfo() == templateSubTypes[m].GetTypeInfo() ) tmplSubTypes.PushLast(targetSubTypes[m]); - if( tmplSubTypes.GetLength() != n+1 ) + if( tmplSubTypes.GetLength() != n + 1 ) { asASSERT( false ); return orig; @@ -4076,7 +4076,7 @@ asCDataType asCScriptEngine::DetermineTypeForTemplate(const asCDataType &orig, c // generation will fail since it will attempt to create factory stubs when they already exists, etc for( asUINT n = 0; n < registeredTemplateTypes.GetLength(); n++ ) if( registeredTemplateTypes[n]->name == origType->name && - registeredTemplateTypes[n]->nameSpace == origType->nameSpace ) + registeredTemplateTypes[n]->nameSpace == origType->nameSpace ) { origType = registeredTemplateTypes[n]; break; @@ -4099,12 +4099,12 @@ asCDataType asCScriptEngine::DetermineTypeForTemplate(const asCDataType &orig, c dt.MakeReference(orig.IsReference()); dt.MakeReadOnly(orig.IsReadOnly()); } - else if (tmpl && orig.GetTypeInfo() && (orig.GetTypeInfo()->flags & asOBJ_FUNCDEF) && CastToFuncdefType(orig.GetTypeInfo())->parentClass == tmpl) + else if( tmpl && orig.GetTypeInfo() && (orig.GetTypeInfo()->flags & asOBJ_FUNCDEF) && CastToFuncdefType(orig.GetTypeInfo())->parentClass == tmpl ) { // The type is a child funcdef. Find the corresponding child funcdef in the template instance - for (asUINT n = 0; n < ot->childFuncDefs.GetLength(); n++) + for( asUINT n = 0; n < ot->childFuncDefs.GetLength(); n++ ) { - if (ot->childFuncDefs[n]->name == orig.GetTypeInfo()->name) + if( ot->childFuncDefs[n]->name == orig.GetTypeInfo()->name ) { dt = orig; dt.SetTypeInfo(ot->childFuncDefs[n]); @@ -4142,28 +4142,28 @@ asCScriptFunction *asCScriptEngine::GenerateFactoryStubForTemplateObjectInstance func->SetShared(true); if( templateType->flags & asOBJ_REF ) { - func->name = "$fact"; + func->name = "$fact"; func->returnType = asCDataType::CreateObjectHandle(ot, false); } else { - func->name = "$beh0"; + func->name = "$beh0"; func->returnType = factory->returnType; // constructors return nothing func->objectType = ot; func->objectType->AddRefInternal(); } // Skip the first parameter as this is the object type pointer that the stub will add - func->parameterTypes.SetLength(factory->parameterTypes.GetLength()-1); - func->parameterNames.SetLength(factory->parameterNames.GetLength()-1); - func->inOutFlags.SetLength(factory->inOutFlags.GetLength()-1); - func->defaultArgs.SetLength(factory->defaultArgs.GetLength()-1); + func->parameterTypes.SetLength(factory->parameterTypes.GetLength() - 1); + func->parameterNames.SetLength(factory->parameterNames.GetLength() - 1); + func->inOutFlags.SetLength(factory->inOutFlags.GetLength() - 1); + func->defaultArgs.SetLength(factory->defaultArgs.GetLength() - 1); for( asUINT p = 1; p < factory->parameterTypes.GetLength(); p++ ) { - func->parameterTypes[p-1] = factory->parameterTypes[p]; - func->parameterNames[p-1] = factory->parameterNames[p]; - func->inOutFlags[p-1] = factory->inOutFlags[p]; - func->defaultArgs[p-1] = factory->defaultArgs[p] ? asNEW(asCString)(*factory->defaultArgs[p]) : 0; + func->parameterTypes[p - 1] = factory->parameterTypes[p]; + func->parameterNames[p - 1] = factory->parameterNames[p]; + func->inOutFlags[p - 1] = factory->inOutFlags[p]; + func->defaultArgs[p - 1] = factory->defaultArgs[p] ? asNEW(asCString)(*factory->defaultArgs[p]) : 0; } // Generate the bytecode for the factory stub @@ -4181,25 +4181,25 @@ asCScriptFunction *asCScriptEngine::GenerateFactoryStubForTemplateObjectInstance if( ep.includeJitInstructions ) { - *(asBYTE*)bc = asBC_JitEntry; - *(asPWORD*)(bc+1) = 0; - bc += asBCTypeSize[asBCInfo[asBC_JitEntry].type]; + *(asBYTE *)bc = asBC_JitEntry; + *(asPWORD *)(bc + 1) = 0; + bc += asBCTypeSize[asBCInfo[asBC_JitEntry].type]; } - *(asBYTE*)bc = asBC_OBJTYPE; - *(asPWORD*)(bc+1) = (asPWORD)ot; - bc += asBCTypeSize[asBCInfo[asBC_OBJTYPE].type]; + *(asBYTE *)bc = asBC_OBJTYPE; + *(asPWORD *)(bc + 1) = (asPWORD)ot; + bc += asBCTypeSize[asBCInfo[asBC_OBJTYPE].type]; if( templateType->flags & asOBJ_VALUE ) { // Swap the object pointer with the object type - *(asBYTE*)bc = asBC_SwapPtr; - bc += asBCTypeSize[asBCInfo[asBC_SwapPtr].type]; + *(asBYTE *)bc = asBC_SwapPtr; + bc += asBCTypeSize[asBCInfo[asBC_SwapPtr].type]; } - *(asBYTE*)bc = asBC_CALLSYS; - *(asDWORD*)(bc+1) = factoryId; - bc += asBCTypeSize[asBCInfo[asBC_CALLSYS].type]; - *(asBYTE*)bc = asBC_RET; - *(((asWORD*)bc)+1) = (asWORD)func->GetSpaceNeededForArguments() + (func->objectType ? AS_PTR_SIZE : 0); + *(asBYTE *)bc = asBC_CALLSYS; + *(asDWORD *)(bc + 1) = factoryId; + bc += asBCTypeSize[asBCInfo[asBC_CALLSYS].type]; + *(asBYTE *)bc = asBC_RET; + *(((asWORD *)bc) + 1) = (asWORD)func->GetSpaceNeededForArguments() + (func->objectType ? AS_PTR_SIZE : 0); func->AddReferences(); func->scriptData->stackNeeded = AS_PTR_SIZE; @@ -4212,15 +4212,15 @@ asCScriptFunction *asCScriptEngine::GenerateFactoryStubForTemplateObjectInstance // Need to translate the list pattern too so the VM and compiler will know the correct type of the members if( factory->listPattern ) { - asSListPatternNode *n = factory->listPattern; + asSListPatternNode *n = factory->listPattern; asSListPatternNode *last = 0; while( n ) { asSListPatternNode *newNode = n->Duplicate(); if( newNode->type == asLPT_TYPE ) { - asSListPatternDataTypeNode *typeNode = reinterpret_cast(newNode); - typeNode->dataType = DetermineTypeForTemplate(typeNode->dataType, templateType->templateSubTypes, ot->templateSubTypes, ot->module, templateType, ot); + asSListPatternDataTypeNode *typeNode = reinterpret_cast(newNode); + typeNode->dataType = DetermineTypeForTemplate(typeNode->dataType, templateType->templateSubTypes, ot->templateSubTypes, ot->module, templateType, ot); } if( last ) @@ -4239,9 +4239,9 @@ asCScriptFunction *asCScriptEngine::GenerateFactoryStubForTemplateObjectInstance bool asCScriptEngine::GenerateFunctionForTemplateObjectInstance(asCObjectType *templateType, asCObjectType *ot, asCScriptFunction *func, asCScriptFunction **newFunc) { - // Due to the objectType it is always required to generate a new function, + // Due to the objectType it is always required to generate a new function, // even if none of the function arguments needs to be changed. -/* + /* // TODO: Can we store the new function in some other optimized way to avoid // duplicating all information just because of the different objectType member? bool needNewFunc = false; @@ -4271,15 +4271,15 @@ bool asCScriptEngine::GenerateFunctionForTemplateObjectInstance(asCObjectType *t return false; } - func2->name = func->name; + func2->name = func->name; func2->returnType = DetermineTypeForTemplate(func->returnType, templateType->templateSubTypes, ot->templateSubTypes, ot->module, templateType, ot); func2->parameterTypes.SetLength(func->parameterTypes.GetLength()); - for (asUINT p = 0; p < func->parameterTypes.GetLength(); p++) + for( asUINT p = 0; p < func->parameterTypes.GetLength(); p++ ) func2->parameterTypes[p] = DetermineTypeForTemplate(func->parameterTypes[p], templateType->templateSubTypes, ot->templateSubTypes, ot->module, templateType, ot); - for (asUINT n = 0; n < func->defaultArgs.GetLength(); n++) - if (func->defaultArgs[n]) + for( asUINT n = 0; n < func->defaultArgs.GetLength(); n++ ) + if( func->defaultArgs[n] ) func2->defaultArgs.PushLast(asNEW(asCString)(*func->defaultArgs[n])); else func2->defaultArgs.PushLast(0); @@ -4290,8 +4290,8 @@ bool asCScriptEngine::GenerateFunctionForTemplateObjectInstance(asCObjectType *t // this instance. func2->parameterNames = func->parameterNames; - func2->inOutFlags = func->inOutFlags; - func2->traits = func->traits; + func2->inOutFlags = func->inOutFlags; + func2->traits = func->traits; func2->SetReadOnly(func->IsReadOnly()); func2->objectType = ot; func2->objectType->AddRefInternal(); @@ -4299,12 +4299,12 @@ bool asCScriptEngine::GenerateFunctionForTemplateObjectInstance(asCObjectType *t // Adjust the clean up instructions if( func2->sysFuncIntf->callConv == ICC_GENERIC_FUNC || - func2->sysFuncIntf->callConv == ICC_GENERIC_METHOD ) + func2->sysFuncIntf->callConv == ICC_GENERIC_METHOD ) PrepareSystemFunctionGeneric(func2, func2->sysFuncIntf, this); else PrepareSystemFunction(func2, func2->sysFuncIntf, this); - func2->id = GetNextScriptFunctionId(); + func2->id = GetNextScriptFunctionId(); AddScriptFunction(func2); // Return the new function @@ -4322,7 +4322,7 @@ asCFuncdefType *asCScriptEngine::GenerateFuncdefForTemplateObjectInstance(asCObj // parent class (in this case the template instance). asCScriptFunction *func2 = asNEW(asCScriptFunction)(this, 0, func->funcdef->funcType); - if (func2 == 0) + if( func2 == 0 ) { // Out of memory return 0; @@ -4332,7 +4332,7 @@ asCFuncdefType *asCScriptEngine::GenerateFuncdefForTemplateObjectInstance(asCObj func2->returnType = DetermineTypeForTemplate(func->funcdef->returnType, templateType->templateSubTypes, ot->templateSubTypes, ot->module, templateType, ot); func2->parameterTypes.SetLength(func->funcdef->parameterTypes.GetLength()); - for (asUINT p = 0; p < func->funcdef->parameterTypes.GetLength(); p++) + for( asUINT p = 0; p < func->funcdef->parameterTypes.GetLength(); p++ ) func2->parameterTypes[p] = DetermineTypeForTemplate(func->funcdef->parameterTypes[p], templateType->templateSubTypes, ot->templateSubTypes, ot->module, templateType, ot); // TODO: template: Must be careful when instantiating templates for garbage collected types @@ -4367,11 +4367,11 @@ void asCScriptEngine::CallObjectMethod(void *obj, asSSystemFunctionInterface *i, #if defined(__GNUC__) || defined(AS_PSVITA) if( i->callConv == ICC_GENERIC_METHOD ) { - asCGeneric gen(const_cast(this), s, obj, 0); + asCGeneric gen(const_cast(this), s, obj, 0); void (*f)(asIScriptGeneric *) = (void (*)(asIScriptGeneric *))(i->func); f(&gen); } -#ifndef AS_NO_CLASS_METHODS + #ifndef AS_NO_CLASS_METHODS else if( i->callConv == ICC_THISCALL || i->callConv == ICC_VIRTUAL_THISCALL ) { // For virtual thiscalls we must call the method as a true class method @@ -4382,49 +4382,49 @@ void asCScriptEngine::CallObjectMethod(void *obj, asSSystemFunctionInterface *i, struct { asFUNCTION_t func; - asPWORD baseOffset; // Same size as the pointer + asPWORD baseOffset; // Same size as the pointer } f; } p; - obj = (void*) ((char*) obj + i->compositeOffset); - if(i->isCompositeIndirect) - obj = *((void**)obj); + obj = (void *)((char *)obj + i->compositeOffset); + if( i->isCompositeIndirect ) + obj = *((void **)obj); - p.f.func = (asFUNCTION_t)(i->func); - p.f.baseOffset = asPWORD(i->baseOffset); + p.f.func = (asFUNCTION_t)(i->func); + p.f.baseOffset = asPWORD(i->baseOffset); void (asCSimpleDummy::*f)() = p.mthd; - (((asCSimpleDummy*)obj)->*f)(); + (((asCSimpleDummy *)obj)->*f)(); } -#endif + #endif else /*if( i->callConv == ICC_CDECL_OBJLAST || i->callConv == ICC_CDECL_OBJFIRST )*/ { void (*f)(void *) = (void (*)(void *))(i->func); f(obj); } #else -#ifndef AS_NO_CLASS_METHODS + #ifndef AS_NO_CLASS_METHODS if( i->callConv == ICC_THISCALL ) { union { asSIMPLEMETHOD_t mthd; - asFUNCTION_t func; + asFUNCTION_t func; } p; - p.func = (asFUNCTION_t)(i->func); + p.func = (asFUNCTION_t)(i->func); void (asCSimpleDummy::*f)() = p.mthd; - obj = (void*) ((char*) obj + i->compositeOffset); - if(i->isCompositeIndirect) - obj = *((void**)obj); + obj = (void *)((char *)obj + i->compositeOffset); + if( i->isCompositeIndirect ) + obj = *((void **)obj); - obj = (void*)(asPWORD(obj) + i->baseOffset); - (((asCSimpleDummy*)obj)->*f)(); + obj = (void *)(asPWORD(obj) + i->baseOffset); + (((asCSimpleDummy *)obj)->*f)(); } else -#endif - if( i->callConv == ICC_GENERIC_METHOD ) + #endif + if( i->callConv == ICC_GENERIC_METHOD ) { - asCGeneric gen(const_cast(this), s, obj, 0); + asCGeneric gen(const_cast(this), s, obj, 0); void (*f)(asIScriptGeneric *) = (void (*)(asIScriptGeneric *))(i->func); f(&gen); } @@ -4445,12 +4445,12 @@ bool asCScriptEngine::CallObjectMethodRetBool(void *obj, int func) const #if defined(__GNUC__) || defined(AS_PSVITA) if( i->callConv == ICC_GENERIC_METHOD ) { - asCGeneric gen(const_cast(this), s, obj, 0); + asCGeneric gen(const_cast(this), s, obj, 0); void (*f)(asIScriptGeneric *) = (void (*)(asIScriptGeneric *))(i->func); f(&gen); - return *(bool*)gen.GetReturnPointer(); + return *(bool *)gen.GetReturnPointer(); } -#ifndef AS_NO_CLASS_METHODS + #ifndef AS_NO_CLASS_METHODS else if( i->callConv == ICC_THISCALL || i->callConv == ICC_VIRTUAL_THISCALL ) { // For virtual thiscalls we must call the method as a true class method so that the compiler will lookup the function address in the vftable @@ -4460,52 +4460,52 @@ bool asCScriptEngine::CallObjectMethodRetBool(void *obj, int func) const struct { asFUNCTION_t func; - asPWORD baseOffset; + asPWORD baseOffset; } f; } p; - obj = (void*) ((char*) obj + i->compositeOffset); - if(i->isCompositeIndirect) - obj = *((void**)obj); + obj = (void *)((char *)obj + i->compositeOffset); + if( i->isCompositeIndirect ) + obj = *((void **)obj); - p.f.func = (asFUNCTION_t)(i->func); - p.f.baseOffset = asPWORD(i->baseOffset); + p.f.func = (asFUNCTION_t)(i->func); + p.f.baseOffset = asPWORD(i->baseOffset); bool (asCSimpleDummy::*f)() = (bool (asCSimpleDummy::*)())(p.mthd); - return (((asCSimpleDummy*)obj)->*f)(); + return (((asCSimpleDummy *)obj)->*f)(); } -#endif + #endif else /*if( i->callConv == ICC_CDECL_OBJLAST || i->callConv == ICC_CDECL_OBJFIRST )*/ { bool (*f)(void *) = (bool (*)(void *))(i->func); return f(obj); } #else -#ifndef AS_NO_CLASS_METHODS + #ifndef AS_NO_CLASS_METHODS if( i->callConv == ICC_THISCALL ) { union { asSIMPLEMETHOD_t mthd; - asFUNCTION_t func; + asFUNCTION_t func; } p; - p.func = (asFUNCTION_t)(i->func); + p.func = (asFUNCTION_t)(i->func); bool (asCSimpleDummy::*f)() = (bool (asCSimpleDummy::*)())p.mthd; - obj = (void*) ((char*) obj + i->compositeOffset); - if(i->isCompositeIndirect) - obj = *((void**)obj); + obj = (void *)((char *)obj + i->compositeOffset); + if( i->isCompositeIndirect ) + obj = *((void **)obj); - obj = (void*)(asPWORD(obj) + i->baseOffset); - return (((asCSimpleDummy*)obj)->*f)(); + obj = (void *)(asPWORD(obj) + i->baseOffset); + return (((asCSimpleDummy *)obj)->*f)(); } else -#endif - if( i->callConv == ICC_GENERIC_METHOD ) + #endif + if( i->callConv == ICC_GENERIC_METHOD ) { - asCGeneric gen(const_cast(this), s, obj, 0); + asCGeneric gen(const_cast(this), s, obj, 0); void (*f)(asIScriptGeneric *) = (void (*)(asIScriptGeneric *))(i->func); f(&gen); - return *(bool*)gen.GetReturnPointer(); + return *(bool *)gen.GetReturnPointer(); } else /*if( i->callConv == ICC_CDECL_OBJLAST || i->callConv == ICC_CDECL_OBJFIRST )*/ { @@ -4524,12 +4524,12 @@ int asCScriptEngine::CallObjectMethodRetInt(void *obj, int func) const #if defined(__GNUC__) || defined(AS_PSVITA) if( i->callConv == ICC_GENERIC_METHOD ) { - asCGeneric gen(const_cast(this), s, obj, 0); + asCGeneric gen(const_cast(this), s, obj, 0); void (*f)(asIScriptGeneric *) = (void (*)(asIScriptGeneric *))(i->func); f(&gen); - return *(int*)gen.GetReturnPointer(); + return *(int *)gen.GetReturnPointer(); } -#ifndef AS_NO_CLASS_METHODS + #ifndef AS_NO_CLASS_METHODS else if( i->callConv == ICC_THISCALL || i->callConv == ICC_VIRTUAL_THISCALL ) { // For virtual thiscalls we must call the method as a true class method so that the compiler will lookup the function address in the vftable @@ -4539,52 +4539,52 @@ int asCScriptEngine::CallObjectMethodRetInt(void *obj, int func) const struct { asFUNCTION_t func; - asPWORD baseOffset; + asPWORD baseOffset; } f; } p; - p.f.func = (asFUNCTION_t)(i->func); + p.f.func = (asFUNCTION_t)(i->func); p.f.baseOffset = asPWORD(i->baseOffset); - obj = (void*) ((char*) obj + i->compositeOffset); - if(i->isCompositeIndirect) - obj = *((void**)obj); + obj = (void *)((char *)obj + i->compositeOffset); + if( i->isCompositeIndirect ) + obj = *((void **)obj); int (asCSimpleDummy::*f)() = (int (asCSimpleDummy::*)())(p.mthd); - return (((asCSimpleDummy*)obj)->*f)(); + return (((asCSimpleDummy *)obj)->*f)(); } -#endif + #endif else /*if( i->callConv == ICC_CDECL_OBJLAST || i->callConv == ICC_CDECL_OBJFIRST )*/ { int (*f)(void *) = (int (*)(void *))(i->func); return f(obj); } #else -#ifndef AS_NO_CLASS_METHODS + #ifndef AS_NO_CLASS_METHODS if( i->callConv == ICC_THISCALL ) { union { asSIMPLEMETHOD_t mthd; - asFUNCTION_t func; + asFUNCTION_t func; } p; - p.func = (asFUNCTION_t)(i->func); + p.func = (asFUNCTION_t)(i->func); int (asCSimpleDummy::*f)() = (int (asCSimpleDummy::*)())p.mthd; - obj = (void*) ((char*) obj + i->compositeOffset); - if(i->isCompositeIndirect) - obj = *((void**)obj); + obj = (void *)((char *)obj + i->compositeOffset); + if( i->isCompositeIndirect ) + obj = *((void **)obj); - obj = (void*)(asPWORD(obj) + i->baseOffset); - return (((asCSimpleDummy*)obj)->*f)(); + obj = (void *)(asPWORD(obj) + i->baseOffset); + return (((asCSimpleDummy *)obj)->*f)(); } else -#endif - if( i->callConv == ICC_GENERIC_METHOD ) + #endif + if( i->callConv == ICC_GENERIC_METHOD ) { - asCGeneric gen(const_cast(this), s, obj, 0); + asCGeneric gen(const_cast(this), s, obj, 0); void (*f)(asIScriptGeneric *) = (void (*)(asIScriptGeneric *))(i->func); f(&gen); - return *(int*)gen.GetReturnPointer(); + return *(int *)gen.GetReturnPointer(); } else /*if( i->callConv == ICC_CDECL_OBJLAST || i->callConv == ICC_CDECL_OBJFIRST )*/ { @@ -4603,12 +4603,12 @@ void *asCScriptEngine::CallObjectMethodRetPtr(void *obj, int func) const #if defined(__GNUC__) || defined(AS_PSVITA) if( i->callConv == ICC_GENERIC_METHOD ) { - asCGeneric gen(const_cast(this), s, obj, 0); + asCGeneric gen(const_cast(this), s, obj, 0); void (*f)(asIScriptGeneric *) = (void (*)(asIScriptGeneric *))(i->func); f(&gen); - return *(void**)gen.GetReturnPointer(); + return *(void **)gen.GetReturnPointer(); } -#ifndef AS_NO_CLASS_METHODS + #ifndef AS_NO_CLASS_METHODS else if( i->callConv == ICC_THISCALL || i->callConv == ICC_VIRTUAL_THISCALL ) { // For virtual thiscalls we must call the method as a true class method so that the compiler will lookup the function address in the vftable @@ -4618,49 +4618,49 @@ void *asCScriptEngine::CallObjectMethodRetPtr(void *obj, int func) const struct { asFUNCTION_t func; - asPWORD baseOffset; + asPWORD baseOffset; } f; } p; - p.f.func = (asFUNCTION_t)(i->func); + p.f.func = (asFUNCTION_t)(i->func); p.f.baseOffset = asPWORD(i->baseOffset); - obj = (void*) ((char*) obj + i->compositeOffset); - if(i->isCompositeIndirect) - obj = *((void**)obj); + obj = (void *)((char *)obj + i->compositeOffset); + if( i->isCompositeIndirect ) + obj = *((void **)obj); void *(asCSimpleDummy::*f)() = (void *(asCSimpleDummy::*)())(p.mthd); - return (((asCSimpleDummy*)obj)->*f)(); + return (((asCSimpleDummy *)obj)->*f)(); } -#endif + #endif else /*if( i->callConv == ICC_CDECL_OBJLAST || i->callConv == ICC_CDECL_OBJFIRST )*/ { void *(*f)(void *) = (void *(*)(void *))(i->func); return f(obj); } #else -#ifndef AS_NO_CLASS_METHODS + #ifndef AS_NO_CLASS_METHODS if( i->callConv == ICC_THISCALL ) { union { asSIMPLEMETHOD_t mthd; - asFUNCTION_t func; + asFUNCTION_t func; } p; - p.func = (asFUNCTION_t)(i->func); + p.func = (asFUNCTION_t)(i->func); void *(asCSimpleDummy::*f)() = (void *(asCSimpleDummy::*)())p.mthd; - obj = (void*) ((char*) obj + i->compositeOffset); - if(i->isCompositeIndirect) - obj = *((void**)obj); + obj = (void *)((char *)obj + i->compositeOffset); + if( i->isCompositeIndirect ) + obj = *((void **)obj); - obj = (void*)(asPWORD(obj) + i->baseOffset); - return (((asCSimpleDummy*)obj)->*f)(); + obj = (void *)(asPWORD(obj) + i->baseOffset); + return (((asCSimpleDummy *)obj)->*f)(); } else -#endif - if( i->callConv == ICC_GENERIC_METHOD ) + #endif + if( i->callConv == ICC_GENERIC_METHOD ) { - asCGeneric gen(const_cast(this), s, obj, 0); + asCGeneric gen(const_cast(this), s, obj, 0); void (*f)(asIScriptGeneric *) = (void (*)(asIScriptGeneric *))(i->func); f(&gen); return *(void **)gen.GetReturnPointer(); @@ -4682,7 +4682,7 @@ void *asCScriptEngine::CallObjectMethodRetPtr(void *obj, int param1, asCScriptFu #ifndef AS_NO_CLASS_METHODS if( i->callConv == ICC_THISCALL || i->callConv == ICC_VIRTUAL_THISCALL ) { -#if defined(__GNUC__) || defined(AS_PSVITA) + #if defined(__GNUC__) || defined(AS_PSVITA) // For virtual thiscalls we must call the method as a true class method so that the compiler will lookup the function address in the vftable union { @@ -4690,40 +4690,40 @@ void *asCScriptEngine::CallObjectMethodRetPtr(void *obj, int param1, asCScriptFu struct { asFUNCTION_t func; - asPWORD baseOffset; + asPWORD baseOffset; } f; } p; - p.f.func = (asFUNCTION_t)(i->func); + p.f.func = (asFUNCTION_t)(i->func); p.f.baseOffset = asPWORD(i->baseOffset); - obj = (void*) ((char*) obj + i->compositeOffset); - if(i->isCompositeIndirect) - obj = *((void**)obj); + obj = (void *)((char *)obj + i->compositeOffset); + if( i->isCompositeIndirect ) + obj = *((void **)obj); void *(asCSimpleDummy::*f)(int) = (void *(asCSimpleDummy::*)(int))(p.mthd); - return (((asCSimpleDummy*)obj)->*f)(param1); -#else + return (((asCSimpleDummy *)obj)->*f)(param1); + #else union { asSIMPLEMETHOD_t mthd; - asFUNCTION_t func; + asFUNCTION_t func; } p; - p.func = (asFUNCTION_t)(i->func); + p.func = (asFUNCTION_t)(i->func); void *(asCSimpleDummy::*f)(int) = (void *(asCSimpleDummy::*)(int))p.mthd; - obj = (void*) ((char*) obj + i->compositeOffset); - if(i->isCompositeIndirect) - obj = *((void**)obj); + obj = (void *)((char *)obj + i->compositeOffset); + if( i->isCompositeIndirect ) + obj = *((void **)obj); - obj = (void*)(asPWORD(obj) + i->baseOffset); - return (((asCSimpleDummy*)obj)->*f)(param1); -#endif + obj = (void *)(asPWORD(obj) + i->baseOffset); + return (((asCSimpleDummy *)obj)->*f)(param1); + #endif } else #endif - if( i->callConv == ICC_GENERIC_METHOD ) + if( i->callConv == ICC_GENERIC_METHOD ) { - asCGeneric gen(const_cast(this), func, obj, reinterpret_cast(¶m1)); + asCGeneric gen(const_cast(this), func, obj, reinterpret_cast(¶m1)); void (*f)(asIScriptGeneric *) = (void (*)(asIScriptGeneric *))(i->func); f(&gen); return *(void **)gen.GetReturnPointer(); @@ -4763,21 +4763,21 @@ void *asCScriptEngine::CallGlobalFunctionRetPtr(asSSystemFunctionInterface *i, a } else if( i->callConv == ICC_STDCALL ) { - typedef void *(STDCALL *func_t)(); + typedef void *(STDCALL * func_t)(); func_t f = (func_t)(i->func); return f(); } - else if (i->callConv == ICC_CDECL_OBJFIRST || i->callConv == ICC_CDECL_OBJLAST) + else if( i->callConv == ICC_CDECL_OBJFIRST || i->callConv == ICC_CDECL_OBJLAST ) { - void* (*f)(void*) = (void* (*)(void*))(i->func); + void *(*f)(void *) = (void *(*)(void *))(i->func); return f(i->auxiliary); } else { - asCGeneric gen(const_cast(this), s, 0, 0); + asCGeneric gen(const_cast(this), s, 0, 0); void (*f)(asIScriptGeneric *) = (void (*)(asIScriptGeneric *))(i->func); f(&gen); - return *(void**)gen.GetReturnPointer(); + return *(void **)gen.GetReturnPointer(); } } @@ -4790,26 +4790,26 @@ void *asCScriptEngine::CallGlobalFunctionRetPtr(asSSystemFunctionInterface *i, a } else if( i->callConv == ICC_STDCALL ) { - typedef void *(STDCALL *func_t)(void *); + typedef void *(STDCALL * func_t)(void *); func_t f = (func_t)(i->func); return f(param1); } - else if (i->callConv == ICC_CDECL_OBJFIRST ) + else if( i->callConv == ICC_CDECL_OBJFIRST ) { - void* (*f)(void*,void*) = (void* (*)(void*,void*))(i->func); - return f(i->auxiliary,param1); + void *(*f)(void *, void *) = (void *(*)(void *, void *))(i->func); + return f(i->auxiliary, param1); } - else if (i->callConv == ICC_CDECL_OBJLAST) + else if( i->callConv == ICC_CDECL_OBJLAST ) { - void* (*f)(void*,void*) = (void* (*)(void*,void*))(i->func); - return f(param1,i->auxiliary); + void *(*f)(void *, void *) = (void *(*)(void *, void *))(i->func); + return f(param1, i->auxiliary); } else { - asCGeneric gen(const_cast(this), s, 0, (asDWORD*)¶m1); + asCGeneric gen(const_cast(this), s, 0, (asDWORD *)¶m1); void (*f)(asIScriptGeneric *) = (void (*)(asIScriptGeneric *))(i->func); f(&gen); - return *(void**)gen.GetReturnPointer(); + return *(void **)gen.GetReturnPointer(); } } @@ -4830,11 +4830,11 @@ void asCScriptEngine::CallObjectMethod(void *obj, void *param, asSSystemFunction } else if( i->callConv == ICC_GENERIC_METHOD ) { - asCGeneric gen(const_cast(this), s, obj, (asDWORD*)¶m); + asCGeneric gen(const_cast(this), s, obj, (asDWORD *)¶m); void (*f)(asIScriptGeneric *) = (void (*)(asIScriptGeneric *))(i->func); f(&gen); } -#ifndef AS_NO_CLASS_METHODS + #ifndef AS_NO_CLASS_METHODS else if( i->callConv == ICC_VIRTUAL_THISCALL || i->callConv == ICC_THISCALL ) { // For virtual thiscalls we must call the method as a true class method @@ -4845,54 +4845,54 @@ void asCScriptEngine::CallObjectMethod(void *obj, void *param, asSSystemFunction struct { asFUNCTION_t func; - asPWORD baseOffset; // Same size as the pointer + asPWORD baseOffset; // Same size as the pointer } f; } p; - p.f.func = (asFUNCTION_t)(i->func); + p.f.func = (asFUNCTION_t)(i->func); p.f.baseOffset = asPWORD(i->baseOffset); - obj = (void*) ((char*) obj + i->compositeOffset); - if(i->isCompositeIndirect) - obj = *((void**)obj); + obj = (void *)((char *)obj + i->compositeOffset); + if( i->isCompositeIndirect ) + obj = *((void **)obj); - void (asCSimpleDummy::*f)(void*) = (void (asCSimpleDummy::*)(void*))(p.mthd); - (((asCSimpleDummy*)obj)->*f)(param); + void (asCSimpleDummy::*f)(void *) = (void (asCSimpleDummy::*)(void *))(p.mthd); + (((asCSimpleDummy *)obj)->*f)(param); } -#endif + #endif else /*if( i->callConv == ICC_CDECL_OBJFIRST */ { void (*f)(void *, void *) = (void (*)(void *, void *))(i->func); f(obj, param); } #else -#ifndef AS_NO_CLASS_METHODS + #ifndef AS_NO_CLASS_METHODS if( i->callConv == ICC_THISCALL ) { union { asSIMPLEMETHOD_t mthd; - asFUNCTION_t func; + asFUNCTION_t func; } p; - p.func = (asFUNCTION_t)(i->func); + p.func = (asFUNCTION_t)(i->func); void (asCSimpleDummy::*f)(void *) = (void (asCSimpleDummy::*)(void *))(p.mthd); - obj = (void*) ((char*) obj + i->compositeOffset); - if(i->isCompositeIndirect) - obj = *((void**)obj); + obj = (void *)((char *)obj + i->compositeOffset); + if( i->isCompositeIndirect ) + obj = *((void **)obj); - obj = (void*)(asPWORD(obj) + i->baseOffset); - (((asCSimpleDummy*)obj)->*f)(param); + obj = (void *)(asPWORD(obj) + i->baseOffset); + (((asCSimpleDummy *)obj)->*f)(param); } else -#endif - if( i->callConv == ICC_CDECL_OBJLAST ) + #endif + if( i->callConv == ICC_CDECL_OBJLAST ) { void (*f)(void *, void *) = (void (*)(void *, void *))(i->func); f(param, obj); } else if( i->callConv == ICC_GENERIC_METHOD ) { - asCGeneric gen(const_cast(this), s, obj, (asDWORD*)¶m); + asCGeneric gen(const_cast(this), s, obj, (asDWORD *)¶m); void (*f)(asIScriptGeneric *) = (void (*)(asIScriptGeneric *))(i->func); f(&gen); } @@ -4913,7 +4913,7 @@ void asCScriptEngine::CallGlobalFunction(void *param1, void *param2, asSSystemFu } else if( i->callConv == ICC_STDCALL ) { - typedef void (STDCALL *func_t)(void *, void *); + typedef void(STDCALL * func_t)(void *, void *); func_t f = (func_t)(i->func); f(param1, param2); } @@ -4924,7 +4924,7 @@ void asCScriptEngine::CallGlobalFunction(void *param1, void *param2, asSSystemFu // in the registers which causes problem. void *params[2] = {param1, param2}; - asCGeneric gen(const_cast(this), s, 0, (asDWORD*)¶ms); + asCGeneric gen(const_cast(this), s, 0, (asDWORD *)¶ms); void (*f)(asIScriptGeneric *) = (void (*)(asIScriptGeneric *))(i->func); f(&gen); } @@ -4939,7 +4939,7 @@ bool asCScriptEngine::CallGlobalFunctionRetBool(void *param1, void *param2, asSS } else if( i->callConv == ICC_STDCALL ) { - typedef bool (STDCALL *func_t)(void *, void *); + typedef bool(STDCALL * func_t)(void *, void *); func_t f = (func_t)(i->func); return f(param1, param2); } @@ -4951,11 +4951,11 @@ bool asCScriptEngine::CallGlobalFunctionRetBool(void *param1, void *param2, asSS // We must guarantee the order of the arguments which is why we copy them to this // array. Otherwise the compiler may put them anywhere it likes, or even keep them // in the registers which causes problem. - void *params[2] = {param1, param2}; - asCGeneric gen(const_cast(this), s, 0, (asDWORD*)params); + void *params[2] = {param1, param2}; + asCGeneric gen(const_cast(this), s, 0, (asDWORD *)params); void (*f)(asIScriptGeneric *) = (void (*)(asIScriptGeneric *))(i->func); f(&gen); - return *(bool*)gen.GetReturnPointer(); + return *(bool *)gen.GetReturnPointer(); } } @@ -4970,17 +4970,17 @@ void *asCScriptEngine::CallAlloc(const asCObjectType *type) const size += 4 - (size & 0x3); #ifndef WIP_16BYTE_ALIGN -#if defined(AS_DEBUG) + #if defined(AS_DEBUG) return ((asALLOCFUNCDEBUG_t)userAlloc)(size, __FILE__, __LINE__); -#else + #else return userAlloc(size); -#endif + #endif #else -#if defined(AS_DEBUG) + #if defined(AS_DEBUG) return ((asALLOCALIGNEDFUNCDEBUG_t)userAllocAligned)(size, type->alignment, __FILE__, __LINE__); -#else + #else return userAllocAligned(size, type->alignment); -#endif + #endif #endif } @@ -4996,7 +4996,7 @@ void asCScriptEngine::CallFree(void *obj) const // interface int asCScriptEngine::NotifyGarbageCollectorOfNewObject(void *obj, asITypeInfo *type) { - return gc.AddScriptObjectToGC(obj, static_cast(type)); + return gc.AddScriptObjectToGC(obj, static_cast(type)); } // interface @@ -5035,8 +5035,8 @@ void asCScriptEngine::GCEnumCallback(void *reference) // interface void asCScriptEngine::ForwardGCEnumReferences(void *ref, asITypeInfo *type) { - asCTypeInfo *t = reinterpret_cast(type); - if ((t->flags & asOBJ_VALUE) && (t->flags & asOBJ_GC)) + asCTypeInfo *t = reinterpret_cast(type); + if( (t->flags & asOBJ_VALUE) && (t->flags & asOBJ_GC) ) { CallObjectMethod(ref, this, CastToObjectType(t)->beh.gcEnumReferences); } @@ -5045,8 +5045,8 @@ void asCScriptEngine::ForwardGCEnumReferences(void *ref, asITypeInfo *type) // interface void asCScriptEngine::ForwardGCReleaseReferences(void *ref, asITypeInfo *type) { - asCTypeInfo *t = reinterpret_cast(type); - if ((t->flags & asOBJ_VALUE) && (t->flags & asOBJ_GC)) + asCTypeInfo *t = reinterpret_cast(type); + if( (t->flags & asOBJ_VALUE) && (t->flags & asOBJ_GC) ) { CallObjectMethod(ref, this, CastToObjectType(t)->beh.gcReleaseAllReferences); } @@ -5068,27 +5068,39 @@ int asCScriptEngine::GetTypeIdFromDataType(const asCDataType &dtIn) const // Primitives have pre-fixed typeIds switch( dtIn.GetTokenType() ) { - case ttVoid: return asTYPEID_VOID; - case ttBool: return asTYPEID_BOOL; - case ttInt8: return asTYPEID_INT8; - case ttInt16: return asTYPEID_INT16; - case ttInt: return asTYPEID_INT32; - case ttInt64: return asTYPEID_INT64; - case ttUInt8: return asTYPEID_UINT8; - case ttUInt16: return asTYPEID_UINT16; - case ttUInt: return asTYPEID_UINT32; - case ttUInt64: return asTYPEID_UINT64; - case ttFloat: return asTYPEID_FLOAT; - case ttDouble: return asTYPEID_DOUBLE; - default: - // All types should be covered by the above. The variable type is not really a type - asASSERT(dtIn.GetTokenType() == ttQuestion || dtIn.IsAuto()); - return -1; - } - } - - int typeId = -1; - asCTypeInfo *ot = dtIn.GetTypeInfo(); + case ttVoid: + return asTYPEID_VOID; + case ttBool: + return asTYPEID_BOOL; + case ttInt8: + return asTYPEID_INT8; + case ttInt16: + return asTYPEID_INT16; + case ttInt: + return asTYPEID_INT32; + case ttInt64: + return asTYPEID_INT64; + case ttUInt8: + return asTYPEID_UINT8; + case ttUInt16: + return asTYPEID_UINT16; + case ttUInt: + return asTYPEID_UINT32; + case ttUInt64: + return asTYPEID_UINT64; + case ttFloat: + return asTYPEID_FLOAT; + case ttDouble: + return asTYPEID_DOUBLE; + default: + // All types should be covered by the above. The variable type is not really a type + asASSERT(dtIn.GetTokenType() == ttQuestion || dtIn.IsAuto()); + return -1; + } + } + + int typeId = -1; + asCTypeInfo *ot = dtIn.GetTypeInfo(); asASSERT(ot != &functionBehaviours); // Object's hold the typeId themselves typeId = ot->typeId; @@ -5128,7 +5140,7 @@ int asCScriptEngine::GetTypeIdFromDataType(const asCDataType &dtIn) const asCDataType asCScriptEngine::GetDataTypeFromTypeId(int typeId) const { - if (typeId < 0) + if( typeId < 0 ) return asCDataType(); int baseId = typeId & (asTYPEID_MASK_OBJECT | asTYPEID_MASK_SEQNBR); @@ -5142,7 +5154,7 @@ asCDataType asCScriptEngine::GetDataTypeFromTypeId(int typeId) const // First check if the typeId is an object type asCTypeInfo *ot = 0; ACQUIRESHARED(engineRWLock); - asSMapNode *cursor = 0; + asSMapNode *cursor = 0; if( mapTypeIdToTypeInfo.MoveTo(&cursor, baseId) ) ot = mapTypeIdToTypeInfo.GetValue(cursor); RELEASESHARED(engineRWLock); @@ -5170,11 +5182,11 @@ asCObjectType *asCScriptEngine::GetObjectTypeFromTypeId(int typeId) const void asCScriptEngine::RemoveFromTypeIdMap(asCTypeInfo *type) { ACQUIREEXCLUSIVE(engineRWLock); - asSMapNode *cursor = 0; + asSMapNode *cursor = 0; mapTypeIdToTypeInfo.MoveFirst(&cursor); while( cursor ) { - if(mapTypeIdToTypeInfo.GetValue(cursor) == type ) + if( mapTypeIdToTypeInfo.GetValue(cursor) == type ) { mapTypeIdToTypeInfo.Erase(cursor); break; @@ -5189,13 +5201,13 @@ asITypeInfo *asCScriptEngine::GetTypeInfoByDecl(const char *decl) const { asCDataType dt; // This cast is ok, because we are not changing anything in the engine - asCBuilder bld(const_cast(this), 0); + asCBuilder bld(const_cast(this), 0); // Don't write parser errors to the message callback bld.silent = true; int r = bld.ParseDataType(decl, &dt, defaultNamespace); - if (r < 0) + if( r < 0 ) return 0; return dt.GetTypeInfo(); @@ -5206,7 +5218,7 @@ int asCScriptEngine::GetTypeIdByDecl(const char *decl) const { asCDataType dt; // This cast is ok, because we are not changing anything in the engine - asCBuilder bld(const_cast(this), 0); + asCBuilder bld(const_cast(this), 0); // Don't write parser errors to the message callback bld.silent = true; @@ -5226,7 +5238,7 @@ const char *asCScriptEngine::GetTypeDeclaration(int typeId, bool includeNamespac asCString str = dt.Format(defaultNamespace, includeNamespace); asCString *tempString = &asCThreadManager::GetLocalData()->string; - *tempString = str; + *tempString = str; return tempString->AddressOf(); } @@ -5259,12 +5271,12 @@ int asCScriptEngine::RefCastObject(void *obj, asITypeInfo *fromType, asITypeInfo } // Check for funcdefs - if ((fromType->GetFlags() & asOBJ_FUNCDEF) && (toType->GetFlags() & asOBJ_FUNCDEF)) + if( (fromType->GetFlags() & asOBJ_FUNCDEF) && (toType->GetFlags() & asOBJ_FUNCDEF) ) { - asCFuncdefType *fromFunc = CastToFuncdefType(reinterpret_cast(fromType)); - asCFuncdefType *toFunc = CastToFuncdefType(reinterpret_cast(toType)); + asCFuncdefType *fromFunc = CastToFuncdefType(reinterpret_cast(fromType)); + asCFuncdefType *toFunc = CastToFuncdefType(reinterpret_cast(toType)); - if (fromFunc && toFunc && fromFunc->funcdef->IsSignatureExceptNameEqual(toFunc->funcdef)) + if( fromFunc && toFunc && fromFunc->funcdef->IsSignatureExceptNameEqual(toFunc->funcdef) ) { *newPtr = obj; AddRefScriptObject(*newPtr, toType); @@ -5276,13 +5288,13 @@ int asCScriptEngine::RefCastObject(void *obj, asITypeInfo *fromType, asITypeInfo // Look for ref cast behaviours asCScriptFunction *universalCastFunc = 0; - asCObjectType *from = CastToObjectType(reinterpret_cast< asCTypeInfo*>(fromType)); + asCObjectType *from = CastToObjectType(reinterpret_cast(fromType)); if( from == 0 ) return asINVALID_ARG; for( asUINT n = 0; n < from->methods.GetLength(); n++ ) { asCScriptFunction *func = scriptFunctions[from->methods[n]]; if( func->name == "opImplCast" || - (!useOnlyImplicitCast && func->name == "opCast") ) + (!useOnlyImplicitCast && func->name == "opCast") ) { if( func->returnType.GetTypeInfo() == toType ) { @@ -5295,8 +5307,8 @@ int asCScriptEngine::RefCastObject(void *obj, asITypeInfo *fromType, asITypeInfo return asSUCCESS; } else if( func->returnType.GetTokenType() == ttVoid && - func->parameterTypes.GetLength() == 1 && - func->parameterTypes[0].GetTokenType() == ttQuestion ) + func->parameterTypes.GetLength() == 1 && + func->parameterTypes[0].GetTokenType() == ttQuestion ) { universalCastFunc = func; } @@ -5325,28 +5337,28 @@ int asCScriptEngine::RefCastObject(void *obj, asITypeInfo *fromType, asITypeInfo if( fromType == toType ) { *newPtr = obj; - reinterpret_cast(*newPtr)->AddRef(); + reinterpret_cast(*newPtr)->AddRef(); return asSUCCESS; } // Up casts to base class or interface can be done implicitly if( fromType->DerivesFrom(toType) || - fromType->Implements(toType) ) + fromType->Implements(toType) ) { *newPtr = obj; - reinterpret_cast(*newPtr)->AddRef(); + reinterpret_cast(*newPtr)->AddRef(); return asSUCCESS; } // Down casts to derived class or from interface can only be done explicitly if( !useOnlyImplicitCast ) { // Get the true type of the object so the explicit cast can evaluate all possibilities - asITypeInfo *trueType = reinterpret_cast(obj)->GetObjectType(); - if (trueType->DerivesFrom(toType) || - trueType->Implements(toType)) + asITypeInfo *trueType = reinterpret_cast(obj)->GetObjectType(); + if( trueType->DerivesFrom(toType) || + trueType->Implements(toType) ) { *newPtr = obj; - reinterpret_cast(*newPtr)->AddRef(); + reinterpret_cast(*newPtr)->AddRef(); return asSUCCESS; } } @@ -5361,8 +5373,8 @@ void *asCScriptEngine::CreateScriptObject(const asITypeInfo *type) { if( type == 0 ) return 0; - asCObjectType *objType = CastToObjectType(const_cast(reinterpret_cast(type))); - if (objType == 0) return 0; + asCObjectType *objType = CastToObjectType(const_cast(reinterpret_cast(type))); + if( objType == 0 ) return 0; void *ptr = 0; // Check that there is a default factory for ref types @@ -5370,9 +5382,9 @@ void *asCScriptEngine::CreateScriptObject(const asITypeInfo *type) { // TODO: How to report the reason the object couldn't be created, without writing to the message callback? optional argument with return code? // TODO: Warn about the invalid call to message callback. Make it an optional, so the warning can be turned off -// asCString str; -// str.Format(TXT_FAILED_IN_FUNC_s_s_d, "CreateScriptObject", errorNames[-asNO_FUNCTION], asNO_FUNCTION); -// WriteMessage("", 0, 0, asMSGTYPE_ERROR, str.AddressOf()); + // asCString str; + // str.Format(TXT_FAILED_IN_FUNC_s_s_d, "CreateScriptObject", errorNames[-asNO_FUNCTION], asNO_FUNCTION); + // WriteMessage("", 0, 0, asMSGTYPE_ERROR, str.AddressOf()); return 0; } @@ -5392,11 +5404,10 @@ void *asCScriptEngine::CreateScriptObject(const asITypeInfo *type) try { ptr = CallGlobalFunctionRetPtr(objType->beh.construct, objType); - } - catch (...) + } catch( ... ) { - asCContext *ctx = reinterpret_cast(asGetActiveContext()); - if (ctx) + asCContext *ctx = reinterpret_cast(asGetActiveContext()); + if( ctx ) ctx->HandleAppException(); } #endif @@ -5410,10 +5421,9 @@ void *asCScriptEngine::CreateScriptObject(const asITypeInfo *type) try { ptr = CallGlobalFunctionRetPtr(objType->beh.factory); - } - catch(...) + } catch( ... ) { - asCContext *ctx = reinterpret_cast(asGetActiveContext()); + asCContext *ctx = reinterpret_cast(asGetActiveContext()); if( ctx ) ctx->HandleAppException(); } @@ -5426,18 +5436,18 @@ void *asCScriptEngine::CreateScriptObject(const asITypeInfo *type) { // TODO: How to report the reason the object couldn't be created, without writing to the message callback? optional argument with return code? // TODO: Warn about the invalid call to message callback. Make it an optional, so the warning can be turned off -// asCString str; -// str.Format(TXT_FAILED_IN_FUNC_s_s_d, "CreateScriptObject", errorNames[-asNO_FUNCTION], asNO_FUNCTION); -// WriteMessage("", 0, 0, asMSGTYPE_ERROR, str.AddressOf()); + // asCString str; + // str.Format(TXT_FAILED_IN_FUNC_s_s_d, "CreateScriptObject", errorNames[-asNO_FUNCTION], asNO_FUNCTION); + // WriteMessage("", 0, 0, asMSGTYPE_ERROR, str.AddressOf()); return 0; } // Manually allocate the memory, then call the default constructor - ptr = CallAlloc(objType); + ptr = CallAlloc(objType); int funcIndex = objType->beh.construct; - if (funcIndex) + if( funcIndex ) { - if (objType->flags & asOBJ_TEMPLATE) + if( objType->flags & asOBJ_TEMPLATE ) { // Templates of value types create script functions as the constructors CallScriptObjectMethod(ptr, funcIndex); @@ -5450,11 +5460,10 @@ void *asCScriptEngine::CreateScriptObject(const asITypeInfo *type) try { CallObjectMethod(ptr, funcIndex); - } - catch (...) + } catch( ... ) { - asCContext *ctx = reinterpret_cast(asGetActiveContext()); - if (ctx) + asCContext *ctx = reinterpret_cast(asGetActiveContext()); + if( ctx ) ctx->HandleAppException(); // Free the memory @@ -5472,27 +5481,27 @@ void *asCScriptEngine::CreateScriptObject(const asITypeInfo *type) // internal int asCScriptEngine::CallScriptObjectMethod(void *obj, int funcId) { - asIScriptContext *ctx = 0; - int r = 0; - bool isNested = false; + asIScriptContext *ctx = 0; + int r = 0; + bool isNested = false; // Use nested call in the context if there is an active context ctx = asGetActiveContext(); - if (ctx) + if( ctx ) { // It may not always be possible to reuse the current context, // in which case we'll have to create a new one any way. - if (ctx->GetEngine() == this && ctx->PushState() == asSUCCESS) + if( ctx->GetEngine() == this && ctx->PushState() == asSUCCESS ) isNested = true; else ctx = 0; } - if (ctx == 0) + if( ctx == 0 ) { // Request a context from the engine ctx = RequestContext(); - if (ctx == 0) + if( ctx == 0 ) { // TODO: How to best report this failure? return asERROR; @@ -5500,9 +5509,9 @@ int asCScriptEngine::CallScriptObjectMethod(void *obj, int funcId) } r = ctx->Prepare(scriptFunctions[funcId]); - if (r < 0) + if( r < 0 ) { - if (isNested) + if( isNested ) ctx->PopState(); else ReturnContext(ctx); @@ -5513,30 +5522,30 @@ int asCScriptEngine::CallScriptObjectMethod(void *obj, int funcId) // Set the object ctx->SetObject(obj); - for (;;) + for( ;; ) { r = ctx->Execute(); // We can't allow this execution to be suspended // so resume the execution immediately - if (r != asEXECUTION_SUSPENDED) + if( r != asEXECUTION_SUSPENDED ) break; } - if (r != asEXECUTION_FINISHED) + if( r != asEXECUTION_FINISHED ) { - if (isNested) + if( isNested ) { ctx->PopState(); // If the execution was aborted or an exception occurred, // then we should forward that to the outer execution. - if (r == asEXECUTION_EXCEPTION) + if( r == asEXECUTION_EXCEPTION ) { // TODO: How to improve this exception ctx->SetException(TXT_EXCEPTION_IN_NESTED_CALL); } - else if (r == asEXECUTION_ABORTED) + else if( r == asEXECUTION_ABORTED ) ctx->Abort(); } else @@ -5546,7 +5555,7 @@ int asCScriptEngine::CallScriptObjectMethod(void *obj, int funcId) return asERROR; } - if (isNested) + if( isNested ) ctx->PopState(); else ReturnContext(ctx); @@ -5561,13 +5570,13 @@ void *asCScriptEngine::CreateUninitializedScriptObject(const asITypeInfo *type) if( type == 0 || !(type->GetFlags() & asOBJ_SCRIPT_OBJECT) ) return 0; - asCObjectType *objType = CastToObjectType(const_cast(reinterpret_cast(type))); - if (objType == 0) + asCObjectType *objType = CastToObjectType(const_cast(reinterpret_cast(type))); + if( objType == 0 ) return 0; // Construct the object, but do not call the actual constructor that initializes the members // The initialization will be done by the application afterwards, e.g. through serialization. - asCScriptObject *obj = reinterpret_cast(CallAlloc(objType)); + asCScriptObject *obj = reinterpret_cast(CallAlloc(objType)); // Pre-initialize the memory so there are no invalid pointers ScriptObject_ConstructUnitialized(objType, obj); @@ -5580,17 +5589,17 @@ void *asCScriptEngine::CreateScriptObjectCopy(void *origObj, const asITypeInfo * { if( origObj == 0 || type == 0 ) return 0; - const asCObjectType* ot = CastToObjectType(const_cast(reinterpret_cast(type))); - if (ot == 0) return 0; + const asCObjectType *ot = CastToObjectType(const_cast(reinterpret_cast(type))); + if( ot == 0 ) return 0; void *newObj = 0; - if ((ot->flags & asOBJ_SCRIPT_OBJECT) && ot->beh.copyfactory) + if( (ot->flags & asOBJ_SCRIPT_OBJECT) && ot->beh.copyfactory ) { // Call the script class' default factory with a context newObj = ScriptObjectCopyFactory(ot, origObj, this); } - else if (ot->beh.copyfactory) + else if( ot->beh.copyfactory ) { // Call the copy factory which will allocate the memory then copy the original object #ifdef AS_NO_EXCEPTIONS @@ -5599,16 +5608,15 @@ void *asCScriptEngine::CreateScriptObjectCopy(void *origObj, const asITypeInfo * try { newObj = CallGlobalFunctionRetPtr(ot->beh.copyfactory, origObj); - } - catch (...) + } catch( ... ) { - asCContext *ctx = reinterpret_cast(asGetActiveContext()); - if (ctx) + asCContext *ctx = reinterpret_cast(asGetActiveContext()); + if( ctx ) ctx->HandleAppException(); } #endif } - else if(ot->beh.copyconstruct ) + else if( ot->beh.copyconstruct ) { // Manually allocate the memory, then call the copy constructor newObj = CallAlloc(ot); @@ -5618,10 +5626,9 @@ void *asCScriptEngine::CreateScriptObjectCopy(void *origObj, const asITypeInfo * try { CallObjectMethod(newObj, origObj, ot->beh.copyconstruct); - } - catch(...) + } catch( ... ) { - asCContext *ctx = reinterpret_cast(asGetActiveContext()); + asCContext *ctx = reinterpret_cast(asGetActiveContext()); if( ctx ) ctx->HandleAppException(); @@ -5673,39 +5680,39 @@ int asCScriptEngine::AssignScriptObject(void *dstObj, void *srcObj, const asITyp // TODO: Warn about invalid call in message stream (make it optional) if( type == 0 || dstObj == 0 || srcObj == 0 ) return asINVALID_ARG; - const asCObjectType *objType = CastToObjectType(const_cast(reinterpret_cast(type))); - if (objType == 0) return asINVALID_ARG; + const asCObjectType *objType = CastToObjectType(const_cast(reinterpret_cast(type))); + if( objType == 0 ) return asINVALID_ARG; // If value assign for ref types has been disabled, then don't do anything if the type is a ref type - if (ep.disallowValueAssignForRefType && (objType->flags & asOBJ_REF) && !(objType->flags & asOBJ_SCOPED)) + if( ep.disallowValueAssignForRefType && (objType->flags & asOBJ_REF) && !(objType->flags & asOBJ_SCOPED) ) { asIScriptContext *ctx = asGetActiveContext(); - if (ctx) + if( ctx ) ctx->SetException("Cannot do value assignment"); return asNOT_SUPPORTED; } // Must not copy if the opAssign is not available and the object is not a POD object - if (objType->beh.copy) + if( objType->beh.copy ) { - asCScriptFunction* func = scriptFunctions[objType->beh.copy]; - if (func->funcType == asFUNC_SYSTEM) + asCScriptFunction *func = scriptFunctions[objType->beh.copy]; + if( func->funcType == asFUNC_SYSTEM ) CallObjectMethod(dstObj, srcObj, objType->beh.copy); else { // Call the script class' opAssign method asASSERT(objType->flags & asOBJ_SCRIPT_OBJECT); - reinterpret_cast(dstObj)->CopyFrom(reinterpret_cast(srcObj)); + reinterpret_cast(dstObj)->CopyFrom(reinterpret_cast(srcObj)); } } - else if (objType->size && (objType->flags & asOBJ_POD)) + else if( objType->size && (objType->flags & asOBJ_POD) ) { memcpy(dstObj, srcObj, objType->size); } else { - asIScriptContext* ctx = asGetActiveContext(); - if (ctx) + asIScriptContext *ctx = asGetActiveContext(); + if( ctx ) ctx->SetException("Cannot do value assignment"); return asNOT_SUPPORTED; } @@ -5719,15 +5726,15 @@ void asCScriptEngine::AddRefScriptObject(void *obj, const asITypeInfo *type) // Make sure it is not a null pointer if( obj == 0 || type == 0 ) return; - const asCTypeInfo *ti = reinterpret_cast(type); - if (ti->flags & asOBJ_FUNCDEF) + const asCTypeInfo *ti = reinterpret_cast(type); + if( ti->flags & asOBJ_FUNCDEF ) { CallObjectMethod(obj, functionBehaviours.beh.addref); } else { - asCObjectType *objType = CastToObjectType(const_cast(ti)); - if (objType && objType->beh.addref) + asCObjectType *objType = CastToObjectType(const_cast(ti)); + if( objType && objType->beh.addref ) { // Call the addref behaviour CallObjectMethod(obj, objType->beh.addref); @@ -5741,18 +5748,18 @@ void asCScriptEngine::ReleaseScriptObject(void *obj, const asITypeInfo *type) // Make sure it is not a null pointer if( obj == 0 || type == 0 ) return; - const asCTypeInfo *ti = reinterpret_cast(type); - if (ti->flags & asOBJ_FUNCDEF) + const asCTypeInfo *ti = reinterpret_cast(type); + if( ti->flags & asOBJ_FUNCDEF ) { CallObjectMethod(obj, functionBehaviours.beh.release); } else { - asCObjectType *objType = CastToObjectType(const_cast(ti)); - if (objType && objType->flags & asOBJ_REF) + asCObjectType *objType = CastToObjectType(const_cast(ti)); + if( objType && objType->flags & asOBJ_REF ) { asASSERT((objType->flags & asOBJ_NOCOUNT) || objType->beh.release); - if (objType->beh.release) + if( objType->beh.release ) { // Call the release behaviour CallObjectMethod(obj, objType->beh.release); @@ -5761,10 +5768,10 @@ void asCScriptEngine::ReleaseScriptObject(void *obj, const asITypeInfo *type) else if( objType ) { // Call the destructor - if (objType->beh.destruct) + if( objType->beh.destruct ) CallObjectMethod(obj, objType->beh.destruct); - else if (objType->flags & asOBJ_LIST_PATTERN) - DestroyList((asBYTE*)obj, objType); + else if( objType->flags & asOBJ_LIST_PATTERN ) + DestroyList((asBYTE *)obj, objType); // We'll have to trust that the memory for the object was allocated with CallAlloc. // This is true if the object was created in the context, or with CreateScriptObject. @@ -5853,7 +5860,7 @@ int asCScriptEngine::RemoveConfigGroup(const char *groupName) // Remove the configurations registered with this group group->RemoveConfiguration(this); - asDELETE(group,asCConfigGroup); + asDELETE(group, asCConfigGroup); } } @@ -5909,7 +5916,7 @@ asCConfigGroup *asCScriptEngine::FindConfigGroupForFuncDef(const asCFuncdefType { for( asUINT n = 0; n < configGroups.GetLength(); n++ ) { - asCFuncdefType *f = const_cast(funcDef); + asCFuncdefType *f = const_cast(funcDef); if( configGroups[n]->types.Exists(f) ) return configGroups[n]; } @@ -5920,7 +5927,7 @@ asCConfigGroup *asCScriptEngine::FindConfigGroupForFuncDef(const asCFuncdefType // interface asDWORD asCScriptEngine::SetDefaultAccessMask(asDWORD defaultMask) { - asDWORD old = defaultAccessMask; + asDWORD old = defaultAccessMask; defaultAccessMask = defaultMask; return old; } @@ -5930,7 +5937,7 @@ int asCScriptEngine::GetNextScriptFunctionId() // This function only returns the next function id that // should be used. It doesn't update the internal arrays. if( freeScriptFunctionIds.GetLength() ) - return freeScriptFunctionIds[freeScriptFunctionIds.GetLength()-1]; + return freeScriptFunctionIds[freeScriptFunctionIds.GetLength() - 1]; return (int)scriptFunctions.GetLength(); } @@ -5938,7 +5945,7 @@ int asCScriptEngine::GetNextScriptFunctionId() void asCScriptEngine::AddScriptFunction(asCScriptFunction *func) { // Update the internal arrays with the function id that is now used - if( freeScriptFunctionIds.GetLength() && freeScriptFunctionIds[freeScriptFunctionIds.GetLength()-1] == func->id ) + if( freeScriptFunctionIds.GetLength() && freeScriptFunctionIds[freeScriptFunctionIds.GetLength() - 1] == func->id ) freeScriptFunctionIds.PopLast(); if( asUINT(func->id) == scriptFunctions.GetLength() ) @@ -6033,14 +6040,14 @@ int asCScriptEngine::RegisterFuncdef(const char *decl) if( func == 0 ) return ConfigError(asOUT_OF_MEMORY, "RegisterFuncdef", decl, 0); - asCBuilder bld(this, 0); + asCBuilder bld(this, 0); asCObjectType *parentClass = 0; - int r = bld.ParseFunctionDeclaration(0, decl, func, false, 0, 0, defaultNamespace, 0, &parentClass); + int r = bld.ParseFunctionDeclaration(0, decl, func, false, 0, 0, defaultNamespace, 0, &parentClass); if( r < 0 ) { // Set as dummy function before deleting func->funcType = asFUNC_DUMMY; - asDELETE(func,asCScriptFunction); + asDELETE(func, asCScriptFunction); return ConfigError(asINVALID_DECLARATION, "RegisterFuncdef", decl, 0); } @@ -6048,7 +6055,7 @@ int asCScriptEngine::RegisterFuncdef(const char *decl) r = bld.CheckNameConflict(func->name.AddressOf(), 0, 0, defaultNamespace, true, false, false); if( r < 0 ) { - asDELETE(func,asCScriptFunction); + asDELETE(func, asCScriptFunction); return ConfigError(asNAME_TAKEN, "RegisterFuncdef", decl, 0); } @@ -6056,21 +6063,21 @@ int asCScriptEngine::RegisterFuncdef(const char *decl) AddScriptFunction(func); asCFuncdefType *fdt = asNEW(asCFuncdefType)(this, func); - funcDefs.PushLast(fdt); // doesn't increase refcount - registeredFuncDefs.PushLast(fdt); // doesn't increase refcount + funcDefs.PushLast(fdt); // doesn't increase refcount + registeredFuncDefs.PushLast(fdt); // doesn't increase refcount allRegisteredTypes.Insert(asSNameSpaceNamePair(fdt->nameSpace, fdt->name), fdt); // constructor already set the ref count to 1 currentGroup->types.PushLast(fdt); - if (parentClass) + if( parentClass ) { parentClass->childFuncDefs.PushLast(fdt); fdt->parentClass = parentClass; // Check if the method restricts that use of the template to value types or reference types - if (parentClass->flags & asOBJ_TEMPLATE) + if( parentClass->flags & asOBJ_TEMPLATE ) { r = SetTemplateRestrictions(parentClass, func, "RegisterFuncdef", decl); - if (r < 0) + if( r < 0 ) return r; } } @@ -6102,14 +6109,14 @@ asCFuncdefType *asCScriptEngine::FindMatchingFuncdef(asCScriptFunction *func, as { asCFuncdefType *funcDef = func->funcdefType; - if (funcDef == 0) + if( funcDef == 0 ) { // Check if there is any matching funcdefs already in the engine that can be reused - for (asUINT n = 0; n < funcDefs.GetLength(); n++) + for( asUINT n = 0; n < funcDefs.GetLength(); n++ ) { - if (funcDefs[n]->funcdef->IsSignatureExceptNameEqual(func)) + if( funcDefs[n]->funcdef->IsSignatureExceptNameEqual(func) ) { - if (func->IsShared() && !funcDefs[n]->funcdef->IsShared()) + if( func->IsShared() && !funcDefs[n]->funcdef->IsShared() ) continue; funcDef = funcDefs[n]; break; @@ -6117,17 +6124,17 @@ asCFuncdefType *asCScriptEngine::FindMatchingFuncdef(asCScriptFunction *func, as } } - if (funcDef == 0) + if( funcDef == 0 ) { // Create a matching funcdef asCScriptFunction *fd = asNEW(asCScriptFunction)(this, 0, asFUNC_FUNCDEF); - fd->name = "$func_" + func->name; // Add a prefix to avoid name conflicts with explicitly declared funcdefs - fd->nameSpace = func->nameSpace; + fd->name = "$func_" + func->name; // Add a prefix to avoid name conflicts with explicitly declared funcdefs + fd->nameSpace = func->nameSpace; fd->SetShared(func->IsShared()); - fd->returnType = func->returnType; + fd->returnType = func->returnType; fd->parameterTypes = func->parameterTypes; - fd->inOutFlags = func->inOutFlags; + fd->inOutFlags = func->inOutFlags; funcDef = asNEW(asCFuncdefType)(this, fd); funcDefs.PushLast(funcDef); // doesn't increase the refCount @@ -6135,7 +6142,7 @@ asCFuncdefType *asCScriptEngine::FindMatchingFuncdef(asCScriptFunction *func, as fd->id = GetNextScriptFunctionId(); AddScriptFunction(fd); - if (module) + if( module ) { // Add the new funcdef to the module so it will // be available when saving the bytecode @@ -6148,11 +6155,11 @@ asCFuncdefType *asCScriptEngine::FindMatchingFuncdef(asCScriptFunction *func, as // until the engine is released. } - if (funcDef && module && funcDef->module && funcDef->module != module) + if( funcDef && module && funcDef->module && funcDef->module != module ) { // Unless this is a registered funcDef the returned funcDef must // be stored as part of the module for saving/loading bytecode - if (!module->m_funcDefs.Exists(funcDef)) + if( !module->m_funcDefs.Exists(funcDef) ) { module->AddFuncDef(funcDef); funcDef->AddRefInternal(); @@ -6179,33 +6186,33 @@ int asCScriptEngine::RegisterTypedef(const char *type, const char *decl) return asALREADY_REGISTERED; // Grab the data type - size_t tokenLen; - eTokenType token; + size_t tokenLen; + eTokenType token; asCDataType dataType; // Create the data type token = tok.GetToken(decl, strlen(decl), &tokenLen); - switch(token) - { - case ttBool: - case ttInt: - case ttInt8: - case ttInt16: - case ttInt64: - case ttUInt: - case ttUInt8: - case ttUInt16: - case ttUInt64: - case ttFloat: - case ttDouble: - if( strlen(decl) != tokenLen ) - { - return ConfigError(asINVALID_TYPE, "RegisterTypedef", type, decl); - } - break; + switch( token ) + { + case ttBool: + case ttInt: + case ttInt8: + case ttInt16: + case ttInt64: + case ttUInt: + case ttUInt8: + case ttUInt16: + case ttUInt64: + case ttFloat: + case ttDouble: + if( strlen(decl) != tokenLen ) + { + return ConfigError(asINVALID_TYPE, "RegisterTypedef", type, decl); + } + break; - default: - return ConfigError(asINVALID_TYPE, "RegisterTypedef", type, decl); + default: + return ConfigError(asINVALID_TYPE, "RegisterTypedef", type, decl); } dataType = asCDataType::CreatePrimitive(token, false); @@ -6216,7 +6223,7 @@ int asCScriptEngine::RegisterTypedef(const char *type, const char *decl) return ConfigError(asINVALID_NAME, "RegisterTypedef", type, decl); asCBuilder bld(this, 0); - int r = bld.CheckNameConflict(type, 0, 0, defaultNamespace, true, false, false); + int r = bld.CheckNameConflict(type, 0, 0, defaultNamespace, true, false, false); if( r < 0 ) return ConfigError(asNAME_TAKEN, "RegisterTypedef", type, decl); @@ -6228,11 +6235,11 @@ int asCScriptEngine::RegisterTypedef(const char *type, const char *decl) if( td == 0 ) return ConfigError(asOUT_OF_MEMORY, "RegisterTypedef", type, decl); - td->flags = asOBJ_TYPEDEF; - td->size = dataType.GetSizeInMemoryBytes(); - td->name = type; - td->nameSpace = defaultNamespace; - td->aliasForType = dataType; + td->flags = asOBJ_TYPEDEF; + td->size = dataType.GetSizeInMemoryBytes(); + td->name = type; + td->nameSpace = defaultNamespace; + td->aliasForType = dataType; allRegisteredTypes.Insert(asSNameSpaceNamePair(td->nameSpace, td->name), td); registeredTypeDefs.PushLast(td); @@ -6258,22 +6265,22 @@ asITypeInfo *asCScriptEngine::GetTypedefByIndex(asUINT index) const } // interface -int asCScriptEngine::RegisterEnum(const char* typeName, const char* underlyingType) +int asCScriptEngine::RegisterEnum(const char *typeName, const char *underlyingType) { // Check the name if( NULL == typeName ) return ConfigError(asINVALID_NAME, "RegisterEnum", typeName, 0); // and the type - if (NULL == underlyingType) + if( NULL == underlyingType ) return ConfigError(asINVALID_NAME, "RegisterEnum", underlyingType, 0); // make sure the type is valid - size_t tokenLen; + size_t tokenLen; eTokenType token = tok.GetToken(underlyingType, strlen(underlyingType), &tokenLen); - - if (!(token >= ttUInt && token <= ttUInt64) && !(token >= ttInt && token <= ttInt64)) + + if( !(token >= ttUInt && token <= ttUInt64) && !(token >= ttInt && token <= ttInt64) ) return ConfigError(asINVALID_NAME, "RegisterEnum", underlyingType, 0); - + asCDataType dataType = asCDataType::CreatePrimitive(token, true); // Verify if the name has been registered as a type already @@ -6282,10 +6289,11 @@ int asCScriptEngine::RegisterEnum(const char* typeName, const char* underlyingTy // Use builder to parse the datatype asCDataType dt; - asCBuilder bld(this, 0); - bool oldMsgCallback = msgCallback; msgCallback = false; - int r = bld.ParseDataType(typeName, &dt, defaultNamespace); - msgCallback = oldMsgCallback; + asCBuilder bld(this, 0); + bool oldMsgCallback = msgCallback; + msgCallback = false; + int r = bld.ParseDataType(typeName, &dt, defaultNamespace); + msgCallback = oldMsgCallback; if( r >= 0 ) { // If it is not in the defaultNamespace then the type was successfully parsed because @@ -6309,11 +6317,11 @@ int asCScriptEngine::RegisterEnum(const char* typeName, const char* underlyingTy dataType.CreatePrimitive(ttInt, false); - st->flags = asOBJ_ENUM | asOBJ_SHARED; - st->size = dataType.GetSizeInMemoryBytes(); - st->name = typeName; + st->flags = asOBJ_ENUM | asOBJ_SHARED; + st->size = dataType.GetSizeInMemoryBytes(); + st->name = typeName; st->nameSpace = defaultNamespace; - st->enumType = dataType; + st->enumType = dataType; allRegisteredTypes.Insert(asSNameSpaceNamePair(st->nameSpace, st->name), st); registeredEnums.PushLast(st); @@ -6331,8 +6339,8 @@ int asCScriptEngine::RegisterEnumValue(const char *typeName, const char *valueNa return ConfigError(asWRONG_CONFIG_GROUP, "RegisterEnumValue", typeName, valueName); asCDataType dt; - int r; - asCBuilder bld(this, 0); + int r; + asCBuilder bld(this, 0); r = bld.ParseDataType(typeName, &dt, defaultNamespace); if( r < 0 ) return ConfigError(r, "RegisterEnumValue", typeName, valueName); @@ -6345,7 +6353,7 @@ int asCScriptEngine::RegisterEnumValue(const char *typeName, const char *valueNa if( NULL == valueName ) return ConfigError(asINVALID_NAME, "RegisterEnumValue", typeName, valueName); - asUINT tokenLen = 0; + asUINT tokenLen = 0; asETokenClass tokenClass = ParseToken(valueName, 0, &tokenLen); if( tokenClass != asTC_IDENTIFIER || tokenLen != strlen(valueName) ) return ConfigError(asINVALID_NAME, "RegisterEnumValue", typeName, valueName); @@ -6360,7 +6368,7 @@ int asCScriptEngine::RegisterEnumValue(const char *typeName, const char *valueNa if( e == 0 ) return ConfigError(asOUT_OF_MEMORY, "RegisterEnumValue", typeName, valueName); - e->name = valueName; + e->name = valueName; e->value = value; ot->enumValues.PushLast(e); @@ -6401,43 +6409,43 @@ asITypeInfo *asCScriptEngine::GetObjectTypeByIndex(asUINT index) const // interface asITypeInfo *asCScriptEngine::GetTypeInfoByName(const char *in_name) const { - asCString name; + asCString name; asSNameSpace *ns = 0; if( DetermineNameAndNamespace(in_name, defaultNamespace, name, ns) < 0 ) return 0; - - while (ns) + + while( ns ) { // Check the object types - for (asUINT n = 0; n < registeredObjTypes.GetLength(); n++) + for( asUINT n = 0; n < registeredObjTypes.GetLength(); n++ ) { - if (registeredObjTypes[n]->name == name && - registeredObjTypes[n]->nameSpace == ns) + if( registeredObjTypes[n]->name == name && + registeredObjTypes[n]->nameSpace == ns ) return registeredObjTypes[n]; } // Perhaps it is a template type? In this case // the returned type will be the generic type - for (asUINT n = 0; n < registeredTemplateTypes.GetLength(); n++) + for( asUINT n = 0; n < registeredTemplateTypes.GetLength(); n++ ) { - if (registeredTemplateTypes[n]->name == name && - registeredTemplateTypes[n]->nameSpace == ns) + if( registeredTemplateTypes[n]->name == name && + registeredTemplateTypes[n]->nameSpace == ns ) return registeredTemplateTypes[n]; } // Check the enum types - for (asUINT n = 0; n < registeredEnums.GetLength(); n++) + for( asUINT n = 0; n < registeredEnums.GetLength(); n++ ) { - if (registeredEnums[n]->name == name && - registeredEnums[n]->nameSpace == ns) + if( registeredEnums[n]->name == name && + registeredEnums[n]->nameSpace == ns ) return registeredEnums[n]; } // Check the typedefs - for (asUINT n = 0; n < registeredTypeDefs.GetLength();n++) + for( asUINT n = 0; n < registeredTypeDefs.GetLength(); n++ ) { - if (registeredTypeDefs[n]->name == name && - registeredTypeDefs[n]->nameSpace == ns) + if( registeredTypeDefs[n]->name == name && + registeredTypeDefs[n]->nameSpace == ns ) return registeredTypeDefs[n]; } @@ -6453,17 +6461,17 @@ int asCScriptEngine::DetermineNameAndNamespace(const char *in_name, asSNameSpace { if( in_name == 0 ) return asINVALID_ARG; - - asCString name = in_name; - asCString scope; + + asCString name = in_name; + asCString scope; asSNameSpace *ns = implicitNs; - + // Check if the given name contains a scope int pos = name.FindLast("::"); if( pos >= 0 ) { scope = name.SubString(0, pos); - name = name.SubString(pos+2); + name = name.SubString(pos + 2); if( pos == 0 ) { // The scope is '::' so the search must start in the global namespace @@ -6483,10 +6491,10 @@ int asCScriptEngine::DetermineNameAndNamespace(const char *in_name, asSNameSpace ns = FindNameSpace((implicitNs->name + "::" + scope).AddressOf()); } } - + out_name = name; - out_ns = ns; - + out_ns = ns; + return 0; } @@ -6497,7 +6505,7 @@ asITypeInfo *asCScriptEngine::GetTypeInfoById(int typeId) const asCDataType dt = GetDataTypeFromTypeId(typeId); // Is the type id valid? - if (!dt.IsValid()) return 0; + if( !dt.IsValid() ) return 0; return dt.GetTypeInfo(); } @@ -6529,12 +6537,12 @@ bool asCScriptEngine::IsTemplateType(const char *name) const } // internal -bool asCScriptEngine::IsTemplateFn(const char* name) const +bool asCScriptEngine::IsTemplateFn(const char *name) const { - for(unsigned int n = 0; n < registeredTemplateGlobalFuncs.GetLength(); n++) + for( unsigned int n = 0; n < registeredTemplateGlobalFuncs.GetLength(); n++ ) { - asCScriptFunction* fn = registeredTemplateGlobalFuncs[n]; - if(fn && fn->name == name) + asCScriptFunction *fn = registeredTemplateGlobalFuncs[n]; + if( fn && fn->name == name ) return true; } return false; @@ -6562,7 +6570,7 @@ int asCScriptEngine::GetScriptSectionNameIndex(const char *name) asCString *str = asNEW(asCString)(name); if( str ) scriptSectionNames.PushLast(str); - int r = int(scriptSectionNames.GetLength()-1); + int r = int(scriptSectionNames.GetLength() - 1); RELEASEEXCLUSIVE(engineRWLock); @@ -6707,7 +6715,7 @@ int asCScriptEngine::SetTranslateAppExceptionCallback(const asSFuncPtr &callback #ifdef AS_NO_EXCEPTIONS return asNOT_SUPPORTED; #else - if (callback.ptr.f.func == 0) + if( callback.ptr.f.func == 0 ) { // Clear the callback translateExceptionCallback = false; @@ -6715,22 +6723,22 @@ int asCScriptEngine::SetTranslateAppExceptionCallback(const asSFuncPtr &callback } // Detect the new callback - translateExceptionCallback = true; + translateExceptionCallback = true; translateExceptionCallbackObj = param; - bool isObj = false; - if ((unsigned)callConv == asCALL_GENERIC || (unsigned)callConv == asCALL_THISCALL_OBJFIRST || (unsigned)callConv == asCALL_THISCALL_OBJLAST) + bool isObj = false; + if( (unsigned)callConv == asCALL_GENERIC || (unsigned)callConv == asCALL_THISCALL_OBJFIRST || (unsigned)callConv == asCALL_THISCALL_OBJLAST ) return asNOT_SUPPORTED; - if ((unsigned)callConv >= asCALL_THISCALL) + if( (unsigned)callConv >= asCALL_THISCALL ) { isObj = true; - if (param == 0) + if( param == 0 ) { translateExceptionCallback = false; return asINVALID_ARG; } } int r = DetectCallingConvention(isObj, callback, callConv, 0, &translateExceptionCallbackFunc); - if (r < 0) + if( r < 0 ) translateExceptionCallback = false; return r; @@ -6771,7 +6779,7 @@ void asCScriptEngine::DestroyList(asBYTE *buffer, const asCObjectType *listPatte // Get the list pattern from the listFactory function // TODO: runtime optimize: Store the used list factory in the listPatternType itself // TODO: runtime optimize: Keep a flag to indicate if there is really a need to free anything - asCObjectType *ot = CastToObjectType(listPatternType->templateSubTypes[0].GetTypeInfo()); + asCObjectType *ot = CastToObjectType(listPatternType->templateSubTypes[0].GetTypeInfo()); asCScriptFunction *listFactory = scriptFunctions[ot->beh.listFactory]; asASSERT( listFactory ); @@ -6798,7 +6806,7 @@ void asCScriptEngine::DestroySubList(asBYTE *&buffer, asSListPatternNode *&node) buffer += 4 - (asPWORD(buffer) & 0x3); // Determine how many times the pattern repeat - count = *(asUINT*)buffer; + count = *(asUINT *)buffer; buffer += 4; if( count == 0 ) @@ -6827,8 +6835,8 @@ void asCScriptEngine::DestroySubList(asBYTE *&buffer, asSListPatternNode *&node) if( count <= 0 ) count = 1; - asCDataType dt = reinterpret_cast(node)->dataType; - bool isVarType = dt.GetTokenType() == ttQuestion; + asCDataType dt = reinterpret_cast(node)->dataType; + bool isVarType = dt.GetTokenType() == ttQuestion; while( count-- ) { @@ -6838,9 +6846,9 @@ void asCScriptEngine::DestroySubList(asBYTE *&buffer, asSListPatternNode *&node) if( (asPWORD(buffer) & 0x3) ) buffer += 4 - (asPWORD(buffer) & 0x3); - int typeId = *(int*)buffer; - buffer += 4; - dt = GetDataTypeFromTypeId(typeId); + int typeId = *(int *)buffer; + buffer += 4; + dt = GetDataTypeFromTypeId(typeId); } asCTypeInfo *ti = dt.GetTypeInfo(); @@ -6871,7 +6879,7 @@ void asCScriptEngine::DestroySubList(asBYTE *&buffer, asSListPatternNode *&node) { if( buffer[n] != 0 ) { - void *ptr = (void*)buffer; + void *ptr = (void *)buffer; CallObjectMethod(ptr, ot->beh.destruct); break; } @@ -6888,10 +6896,10 @@ void asCScriptEngine::DestroySubList(asBYTE *&buffer, asSListPatternNode *&node) buffer += 4 - (asPWORD(buffer) & 0x3); // Call the release behaviour - void *ptr = *(void**)buffer; + void *ptr = *(void **)buffer; if( ptr ) ReleaseScriptObject(ptr, ti); - buffer += AS_PTR_SIZE*4; + buffer += AS_PTR_SIZE * 4; } } else @@ -6944,7 +6952,7 @@ asSNameSpace *asCScriptEngine::GetParentNameSpace(asSNameSpace *ns) const if( ns == nameSpaces[0] ) return 0; asCString scope = ns->name; - int pos = scope.FindLast("::"); + int pos = scope.FindLast("::"); if( pos >= 0 ) { scope = scope.SubString(0, pos); @@ -6955,4 +6963,3 @@ asSNameSpace *asCScriptEngine::GetParentNameSpace(asSNameSpace *ns) const } END_AS_NAMESPACE - diff --git a/sdk/angelscript/source/as_scriptengine.h b/sdk/angelscript/source/as_scriptengine.h index 0cd50b1b..768db0d9 100644 --- a/sdk/angelscript/source/as_scriptengine.h +++ b/sdk/angelscript/source/as_scriptengine.h @@ -64,9 +64,9 @@ struct sBindInfo; class asCScriptEngine : public asIScriptEngine { -//============================================================= -// From asIScriptEngine -//============================================================= + //============================================================= + // From asIScriptEngine + //============================================================= public: // Memory management virtual int AddRef() const; @@ -79,7 +79,7 @@ class asCScriptEngine : public asIScriptEngine // Compiler messages virtual int SetMessageCallback(const asSFuncPtr &callback, void *obj, asDWORD callConv); - virtual int GetMessageCallback(asSFuncPtr* callback, void** obj, asDWORD* callConv); + virtual int GetMessageCallback(asSFuncPtr *callback, void **obj, asDWORD *callConv); virtual int ClearMessageCallback(); virtual int WriteMessage(const char *section, int row, int col, asEMsgType type, const char *message); @@ -101,18 +101,18 @@ class asCScriptEngine : public asIScriptEngine virtual int GetGlobalPropertyIndexByDecl(const char *decl) const; // Type registration - virtual int RegisterObjectType(const char *obj, int byteSize, asQWORD flags); - virtual int RegisterObjectProperty(const char *obj, const char *declaration, int byteOffset, int compositeOffset = 0, bool isCompositeIndirect = false); - virtual int RegisterObjectMethod(const char *obj, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0, int compositeOffset = 0, bool isCompositeIndirect = false); - virtual int RegisterObjectBehaviour(const char *obj, asEBehaviours behaviour, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0, int compositeOffset = 0, bool isCompositeIndirect = false); - virtual int RegisterInterface(const char *name); - virtual int RegisterInterfaceMethod(const char *intf, const char *declaration); - virtual asUINT GetObjectTypeCount() const; - virtual asITypeInfo *GetObjectTypeByIndex(asUINT index) const; + virtual int RegisterObjectType(const char *obj, int byteSize, asQWORD flags); + virtual int RegisterObjectProperty(const char *obj, const char *declaration, int byteOffset, int compositeOffset = 0, bool isCompositeIndirect = false); + virtual int RegisterObjectMethod(const char *obj, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0, int compositeOffset = 0, bool isCompositeIndirect = false); + virtual int RegisterObjectBehaviour(const char *obj, asEBehaviours behaviour, const char *declaration, const asSFuncPtr &funcPointer, asDWORD callConv, void *auxiliary = 0, int compositeOffset = 0, bool isCompositeIndirect = false); + virtual int RegisterInterface(const char *name); + virtual int RegisterInterfaceMethod(const char *intf, const char *declaration); + virtual asUINT GetObjectTypeCount() const; + virtual asITypeInfo *GetObjectTypeByIndex(asUINT index) const; // String factory virtual int RegisterStringFactory(const char *datatype, asIStringFactory *factory); - virtual int GetStringFactory(asDWORD* typeModifiers, asIStringFactory** factory) const; + virtual int GetStringFactory(asDWORD *typeModifiers, asIStringFactory **factory) const; #ifdef AS_DEPRECATED // deprecated since 2024-07-27, 2.38.0 virtual int GetStringFactoryReturnTypeId(asDWORD *flags) const; @@ -123,8 +123,8 @@ class asCScriptEngine : public asIScriptEngine virtual int GetDefaultArrayTypeId() const; // Enums - virtual int RegisterEnum(const char* typeName, const char* underlyingType = "int32"); - virtual int RegisterEnumValue(const char* type, const char* name, asINT64 value); + virtual int RegisterEnum(const char *typeName, const char *underlyingType = "int32"); + virtual int RegisterEnumValue(const char *type, const char *name, asINT64 value); virtual asUINT GetEnumCount() const; virtual asITypeInfo *GetEnumByIndex(asUINT index) const; @@ -158,12 +158,12 @@ class asCScriptEngine : public asIScriptEngine virtual asIScriptFunction *GetFunctionById(int funcId) const; // Type identification - virtual int GetTypeIdByDecl(const char *decl) const; - virtual const char *GetTypeDeclaration(int typeId, bool includeNamespace = false) const; - virtual int GetSizeOfPrimitiveType(int typeId) const; - virtual asITypeInfo *GetTypeInfoById(int typeId) const; - virtual asITypeInfo *GetTypeInfoByName(const char *name) const; - virtual asITypeInfo *GetTypeInfoByDecl(const char *decl) const; + virtual int GetTypeIdByDecl(const char *decl) const; + virtual const char *GetTypeDeclaration(int typeId, bool includeNamespace = false) const; + virtual int GetSizeOfPrimitiveType(int typeId) const; + virtual asITypeInfo *GetTypeInfoById(int typeId) const; + virtual asITypeInfo *GetTypeInfoByName(const char *name) const; + virtual asITypeInfo *GetTypeInfoByDecl(const char *decl) const; // Script execution virtual asIScriptContext *CreateContext(); @@ -208,14 +208,14 @@ class asCScriptEngine : public asIScriptEngine // Exception handling virtual int SetTranslateAppExceptionCallback(const asSFuncPtr &callback, void *param, int callConv); -//=========================================================== -// internal methods -//=========================================================== + //=========================================================== + // internal methods + //=========================================================== public: asCScriptEngine(); virtual ~asCScriptEngine(); -//protected: + //protected: friend class asCBuilder; friend class asCCompiler; friend class asCContext; @@ -271,12 +271,12 @@ class asCScriptEngine : public asIScriptEngine asCTypeInfo *GetRegisteredType(const asCString &name, asSNameSpace *ns) const; asCObjectType *GetListPatternType(int listPatternFuncId); - void DestroyList(asBYTE *buffer, const asCObjectType *listPatternType); - void DestroySubList(asBYTE *&buffer, asSListPatternNode *&patternNode); + void DestroyList(asBYTE *buffer, const asCObjectType *listPatternType); + void DestroySubList(asBYTE *&buffer, asSListPatternNode *&patternNode); int AddBehaviourFunction(asCScriptFunction &func, asSSystemFunctionInterface &internal); - int ParseNamespace(const char* ns, asCArray& nsStrings) const; + int ParseNamespace(const char *ns, asCArray &nsStrings) const; asCString GetFunctionDeclaration(int funcId); asCScriptFunction *GetScriptFunction(int funcId) const; @@ -284,8 +284,8 @@ class asCScriptEngine : public asIScriptEngine asCModule *GetModule(const char *name, bool create); asCModule *GetModuleFromFuncId(int funcId); - int GetMethodIdByDecl(const asCObjectType *ot, const char *decl, asCModule *mod); - int GetFactoryIdByDecl(const asCObjectType *ot, const char *decl); + int GetMethodIdByDecl(const asCObjectType *ot, const char *decl, asCModule *mod); + int GetFactoryIdByDecl(const asCObjectType *ot, const char *decl); int GetNextScriptFunctionId(); void AddScriptFunction(asCScriptFunction *func); @@ -294,32 +294,32 @@ class asCScriptEngine : public asIScriptEngine int ConfigError(int err, const char *funcName, const char *arg1, const char *arg2); - int GetTypeIdFromDataType(const asCDataType &dt) const; - asCDataType GetDataTypeFromTypeId(int typeId) const; - asCObjectType *GetObjectTypeFromTypeId(int typeId) const; - void RemoveFromTypeIdMap(asCTypeInfo *type); + int GetTypeIdFromDataType(const asCDataType &dt) const; + asCDataType GetDataTypeFromTypeId(int typeId) const; + asCObjectType *GetObjectTypeFromTypeId(int typeId) const; + void RemoveFromTypeIdMap(asCTypeInfo *type); bool IsTemplateType(const char *name) const; bool IsTemplateFn(const char *name) const; - int GetTemplateFunctionInstance(asCScriptFunction* templateFunction, const asCArray& subTypes); + int GetTemplateFunctionInstance(asCScriptFunction *templateFunction, const asCArray &subTypes); int SetTemplateRestrictions(asCObjectType *templateType, asCScriptFunction *func, const char *caller, const char *decl); asCObjectType *GetTemplateInstanceType(asCObjectType *templateType, asCArray &subTypes, asCModule *requestingModule); asCScriptFunction *GenerateFactoryStubForTemplateObjectInstance(asCObjectType *templateType, asCObjectType *templateInstanceType, int origFactoryId); bool GenerateFunctionForTemplateObjectInstance(asCObjectType *templateType, asCObjectType *templateInstanceType, asCScriptFunction *templateFunc, asCScriptFunction **newFunc); asCFuncdefType *GenerateFuncdefForTemplateObjectInstance(asCObjectType *templateType, asCObjectType *templateInstanceType, asCFuncdefType *templateFuncdef); - asCDataType DetermineTypeForTemplate(const asCDataType &orig, const asCArray& templateSubTypes, const asCArray& targetSubTypes, asCModule *mod, asCObjectType* tmpl, asCObjectType* ot); + asCDataType DetermineTypeForTemplate(const asCDataType &orig, const asCArray &templateSubTypes, const asCArray &targetSubTypes, asCModule *mod, asCObjectType *tmpl, asCObjectType *ot); - asCModule *FindNewOwnerForSharedType(asCTypeInfo *type, asCModule *mod); - asCModule *FindNewOwnerForSharedFunc(asCScriptFunction *func, asCModule *mod); + asCModule *FindNewOwnerForSharedType(asCTypeInfo *type, asCModule *mod); + asCModule *FindNewOwnerForSharedFunc(asCScriptFunction *func, asCModule *mod); - asCFuncdefType *FindMatchingFuncdef(asCScriptFunction *func, asCModule *mod); + asCFuncdefType *FindMatchingFuncdef(asCScriptFunction *func, asCModule *mod); + + int DetermineNameAndNamespace(const char *in_name, asSNameSpace *implicitNs, asCString &out_name, asSNameSpace *&out_ns) const; + asCTypeInfo *GetTemplateSubTypeByName(const asCString &name); - int DetermineNameAndNamespace(const char *in_name, asSNameSpace *implicitNs, asCString &out_name, asSNameSpace *&out_ns) const; - asCTypeInfo *GetTemplateSubTypeByName(const asCString &name); - // Global property management asCGlobalProperty *AllocateGlobalProperty(); - void RemoveGlobalProperty(asCGlobalProperty *prop); + void RemoveGlobalProperty(asCGlobalProperty *prop); int GetScriptSectionNameIndex(const char *name); @@ -328,45 +328,45 @@ class asCScriptEngine : public asIScriptEngine asSNameSpace *FindNameSpace(const char *name) const; asSNameSpace *GetParentNameSpace(asSNameSpace *ns) const; -//=========================================================== -// internal properties -//=========================================================== + //=========================================================== + // internal properties + //=========================================================== asCMemoryMgr memoryMgr; - asCObjectType *defaultArrayObjectType; - asCObjectType scriptTypeBehaviours; - asCObjectType functionBehaviours; + asCObjectType *defaultArrayObjectType; + asCObjectType scriptTypeBehaviours; + asCObjectType functionBehaviours; // Registered interface - asCArray registeredObjTypes; // doesn't increase ref count - asCArray registeredTypeDefs; // doesn't increase ref count - asCArray registeredEnums; // doesn't increase ref count + asCArray registeredObjTypes; // doesn't increase ref count + asCArray registeredTypeDefs; // doesn't increase ref count + asCArray registeredEnums; // doesn't increase ref count // TODO: memory savings: Since there can be only one property with the same name a simpler symbol table should be used for global props - asCSymbolTable registeredGlobalProps; // increases ref count + asCSymbolTable registeredGlobalProps; // increases ref count asCSymbolTable registeredGlobalFuncs; // The template global function instances will be stored in this array - asCArray generatedTemplateFunctionInstances; // increases ref count + asCArray generatedTemplateFunctionInstances; // increases ref count // This array contains a list of registered template global functions - asCArray registeredTemplateGlobalFuncs; - asCArray registeredFuncDefs; // doesn't increase ref count - asCArray registeredTemplateTypes; // doesn't increase ref count - asIStringFactory *stringFactory; - asCDataType stringType; - bool configFailed; + asCArray registeredTemplateGlobalFuncs; + asCArray registeredFuncDefs; // doesn't increase ref count + asCArray registeredTemplateTypes; // doesn't increase ref count + asIStringFactory *stringFactory; + asCDataType stringType; + bool configFailed; // Stores all registered types - asCMap allRegisteredTypes; // increases ref count + asCMap allRegisteredTypes; // increases ref count // Dummy types used to name the subtypes in the template objects - asCArray registeredTemplateSubTypes; + asCArray registeredTemplateSubTypes; // Store information about template types // This list will contain all instances of templates, both registered specialized // types and those automacially instantiated from scripts - asCArray templateInstanceTypes; // increases ref count + asCArray templateInstanceTypes; // increases ref count // Store information about list patterns - asCArray listPatternTypes; // increases ref count + asCArray listPatternTypes; // increases ref count // Stores all global properties, both those registered by application, and those declared by scripts. // The id of a global property is the index in this array. @@ -375,37 +375,37 @@ class asCScriptEngine : public asIScriptEngine // This map is used to quickly find a property by its memory address // It is used principally during building, cleanup, and garbage detection for script functions - asCMap varAddressMap; // doesn't increase ref count + asCMap varAddressMap; // doesn't increase ref count // Stores all functions, i.e. registered functions, script functions, class methods, behaviours, etc. - asCArray scriptFunctions; // doesn't increase ref count + asCArray scriptFunctions; // doesn't increase ref count asCArray freeScriptFunctionIds; asCArray signatureIds; // An array with all module imported functions - asCArray importedFunctions; // doesn't increase ref count - asCArray freeImportedFunctionIdxs; + asCArray importedFunctions; // doesn't increase ref count + asCArray freeImportedFunctionIdxs; // Synchronized - mutable asCAtomic refCount; + mutable asCAtomic refCount; // Synchronized with engineRWLock // This array holds all live script modules - asCArray scriptModules; + asCArray scriptModules; // Synchronized with engineRWLock // This is a pointer to the last module that was requested. It is used for performance // improvement, since it is common that the same module is accessed many times in a row - asCModule *lastModule; + asCModule *lastModule; // Synchronized with engineRWLock // This flag is true if a script is currently being compiled. It is used to prevent multiple // threads from requesting builds at the same time (without blocking) - bool isBuilding; + bool isBuilding; // Synchronized with engineRWLock // This array holds modules that have been discard (thus are no longer visible to the application) // but cannot yet be deleted due to having external references to some of the entities in them - asCArray discardedModules; + asCArray discardedModules; // This flag is set to true during compilations of scripts (or loading pre-compiled scripts) // to delay the validation of template types until the subtypes have been fully declared - bool deferValidationOfTemplateTypes; + bool deferValidationOfTemplateTypes; // Tokenizer is instantiated once to share resources asCTokenizer tok; @@ -423,28 +423,32 @@ class asCScriptEngine : public asIScriptEngine asCArray scriptSectionNames; // Type identifiers - mutable int typeIdSeqNbr; - mutable asCMap mapTypeIdToTypeInfo; + mutable int typeIdSeqNbr; + mutable asCMap mapTypeIdToTypeInfo; // Garbage collector asCGarbageCollector gc; // Dynamic groups asCConfigGroup defaultGroup; - asCArray configGroups; + asCArray configGroups; asCConfigGroup *currentGroup; asDWORD defaultAccessMask; asSNameSpace *defaultNamespace; // Message callback - bool msgCallback; - asSSystemFunctionInterface msgCallbackFunc; - asSFuncPtr msgCallbackOriginalFuncPtr; - asDWORD msgCallbackOriginalCallConv; - void *msgCallbackObj; + bool msgCallback; + asSSystemFunctionInterface msgCallbackFunc; + asSFuncPtr msgCallbackOriginalFuncPtr; + asDWORD msgCallbackOriginalCallConv; + void *msgCallbackObj; struct preMessage_t { - preMessage_t() { isSet = false; r = c = 0; } + preMessage_t() + { + isSet = false; + r = c = 0; + } bool isSet; asCString message; asCString scriptname; @@ -458,27 +462,51 @@ class asCScriptEngine : public asIScriptEngine // Namespaces // These are shared between all entities and are // only deleted once the engine is destroyed - asCArray nameSpaces; + asCArray nameSpaces; // Callbacks for context pooling - asREQUESTCONTEXTFUNC_t requestCtxFunc; - asRETURNCONTEXTFUNC_t returnCtxFunc; - void *ctxCallbackParam; + asREQUESTCONTEXTFUNC_t requestCtxFunc; + asRETURNCONTEXTFUNC_t returnCtxFunc; + void *ctxCallbackParam; // User data - asCArray userData; - - struct SEngineClean { asPWORD type; asCLEANENGINEFUNC_t cleanFunc; }; - asCArray cleanEngineFuncs; - struct SModuleClean { asPWORD type; asCLEANMODULEFUNC_t cleanFunc; }; - asCArray cleanModuleFuncs; - struct SContextClean { asPWORD type; asCLEANCONTEXTFUNC_t cleanFunc; }; - asCArray cleanContextFuncs; - struct SFunctionClean { asPWORD type; asCLEANFUNCTIONFUNC_t cleanFunc; }; - asCArray cleanFunctionFuncs; - struct STypeInfoClean { asPWORD type; asCLEANTYPEINFOFUNC_t cleanFunc; }; - asCArray cleanTypeInfoFuncs; - struct SScriptObjClean { asPWORD type; asCLEANSCRIPTOBJECTFUNC_t cleanFunc; }; + asCArray userData; + + struct SEngineClean + { + asPWORD type; + asCLEANENGINEFUNC_t cleanFunc; + }; + asCArray cleanEngineFuncs; + struct SModuleClean + { + asPWORD type; + asCLEANMODULEFUNC_t cleanFunc; + }; + asCArray cleanModuleFuncs; + struct SContextClean + { + asPWORD type; + asCLEANCONTEXTFUNC_t cleanFunc; + }; + asCArray cleanContextFuncs; + struct SFunctionClean + { + asPWORD type; + asCLEANFUNCTIONFUNC_t cleanFunc; + }; + asCArray cleanFunctionFuncs; + struct STypeInfoClean + { + asPWORD type; + asCLEANTYPEINFOFUNC_t cleanFunc; + }; + asCArray cleanTypeInfoFuncs; + struct SScriptObjClean + { + asPWORD type; + asCLEANSCRIPTOBJECTFUNC_t cleanFunc; + }; asCArray cleanScriptObjectFuncs; // Synchronization for threads @@ -509,9 +537,9 @@ class asCScriptEngine : public asIScriptEngine int compilerWarnings; bool disallowValueAssignForRefType; // TODO: 3.0.0: Remove the alterSyntaxNamedArgs - int alterSyntaxNamedArgs; - bool disableIntegerDivision; - bool disallowEmptyListElements; + int alterSyntaxNamedArgs; + bool disableIntegerDivision; + bool disallowEmptyListElements; // TODO: 3.0.0: Remove the privatePropAsProtected bool privatePropAsProtected; bool allowUnicodeIdentifiers; @@ -535,7 +563,7 @@ class asCScriptEngine : public asIScriptEngine #ifndef AS_NO_EXCEPTIONS bool translateExceptionCallback; asSSystemFunctionInterface translateExceptionCallbackFunc; - void * translateExceptionCallbackObj; + void *translateExceptionCallbackObj; #endif // This flag is to allow a quicker shutdown when releasing the engine diff --git a/sdk/angelscript/source/as_scriptfunction.cpp b/sdk/angelscript/source/as_scriptfunction.cpp index 4b87f108..c12f5536 100644 --- a/sdk/angelscript/source/as_scriptfunction.cpp +++ b/sdk/angelscript/source/as_scriptfunction.cpp @@ -56,56 +56,56 @@ BEGIN_AS_NAMESPACE static void ScriptFunction_AddRef_Generic(asIScriptGeneric *gen) { - asCScriptFunction *self = (asCScriptFunction*)gen->GetObject(); + asCScriptFunction *self = (asCScriptFunction *)gen->GetObject(); self->AddRef(); } static void ScriptFunction_Release_Generic(asIScriptGeneric *gen) { - asCScriptFunction *self = (asCScriptFunction*)gen->GetObject(); + asCScriptFunction *self = (asCScriptFunction *)gen->GetObject(); self->Release(); } static void ScriptFunction_GetRefCount_Generic(asIScriptGeneric *gen) { - asCScriptFunction *self = (asCScriptFunction*)gen->GetObject(); - *(int*)gen->GetAddressOfReturnLocation() = self->GetRefCount(); + asCScriptFunction *self = (asCScriptFunction *)gen->GetObject(); + *(int *)gen->GetAddressOfReturnLocation() = self->GetRefCount(); } static void ScriptFunction_SetFlag_Generic(asIScriptGeneric *gen) { - asCScriptFunction *self = (asCScriptFunction*)gen->GetObject(); + asCScriptFunction *self = (asCScriptFunction *)gen->GetObject(); self->SetFlag(); } static void ScriptFunction_GetFlag_Generic(asIScriptGeneric *gen) { - asCScriptFunction *self = (asCScriptFunction*)gen->GetObject(); - *(bool*)gen->GetAddressOfReturnLocation() = self->GetFlag(); + asCScriptFunction *self = (asCScriptFunction *)gen->GetObject(); + *(bool *)gen->GetAddressOfReturnLocation() = self->GetFlag(); } static void ScriptFunction_EnumReferences_Generic(asIScriptGeneric *gen) { - asCScriptFunction *self = (asCScriptFunction*)gen->GetObject(); - asIScriptEngine *engine = *(asIScriptEngine**)gen->GetAddressOfArg(0); + asCScriptFunction *self = (asCScriptFunction *)gen->GetObject(); + asIScriptEngine *engine = *(asIScriptEngine **)gen->GetAddressOfArg(0); self->EnumReferences(engine); } static void ScriptFunction_ReleaseAllHandles_Generic(asIScriptGeneric *gen) { - asCScriptFunction *self = (asCScriptFunction*)gen->GetObject(); - asIScriptEngine *engine = *(asIScriptEngine**)gen->GetAddressOfArg(0); + asCScriptFunction *self = (asCScriptFunction *)gen->GetObject(); + asIScriptEngine *engine = *(asIScriptEngine **)gen->GetAddressOfArg(0); self->ReleaseAllHandles(engine); } -#ifdef AS_MAX_PORTABILITY + #ifdef AS_MAX_PORTABILITY static void ScriptFunction_CreateDelegate_Generic(asIScriptGeneric *gen) { - asCScriptFunction *func = (asCScriptFunction*)gen->GetArgAddress(0); - void *obj = gen->GetArgAddress(1); + asCScriptFunction *func = (asCScriptFunction *)gen->GetArgAddress(0); + void *obj = gen->GetArgAddress(1); gen->SetReturnAddress(CreateDelegate(func, obj)); } -#endif + #endif // TODO: operator== /*static void ScriptFunction_opEquals_Generic(asIScriptGeneric *gen) @@ -125,26 +125,40 @@ void RegisterScriptFunction(asCScriptEngine *engine) int r = 0; UNUSED_VAR(r); // It is only used in debug mode engine->functionBehaviours.engine = engine; - engine->functionBehaviours.flags = asOBJ_REF | asOBJ_GC; - engine->functionBehaviours.name = "$func"; + engine->functionBehaviours.flags = asOBJ_REF | asOBJ_GC; + engine->functionBehaviours.name = "$func"; #if !defined(AS_MAX_PORTABILITY) && !defined(AS_NO_CLASS_METHODS) - r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_ADDREF, "void f()", asMETHOD(asCScriptFunction,AddRef), asCALL_THISCALL, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_RELEASE, "void f()", asMETHOD(asCScriptFunction,Release), asCALL_THISCALL, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_GETREFCOUNT, "int f()", asMETHOD(asCScriptFunction,GetRefCount), asCALL_THISCALL, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_SETGCFLAG, "void f()", asMETHOD(asCScriptFunction,SetFlag), asCALL_THISCALL, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_GETGCFLAG, "bool f()", asMETHOD(asCScriptFunction,GetFlag), asCALL_THISCALL, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_ENUMREFS, "void f(int&in)", asMETHOD(asCScriptFunction,EnumReferences), asCALL_THISCALL, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_RELEASEREFS, "void f(int&in)", asMETHOD(asCScriptFunction,ReleaseAllHandles), asCALL_THISCALL, 0); asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_ADDREF, "void f()", asMETHOD(asCScriptFunction, AddRef), asCALL_THISCALL, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_RELEASE, "void f()", asMETHOD(asCScriptFunction, Release), asCALL_THISCALL, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_GETREFCOUNT, "int f()", asMETHOD(asCScriptFunction, GetRefCount), asCALL_THISCALL, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_SETGCFLAG, "void f()", asMETHOD(asCScriptFunction, SetFlag), asCALL_THISCALL, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_GETGCFLAG, "bool f()", asMETHOD(asCScriptFunction, GetFlag), asCALL_THISCALL, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_ENUMREFS, "void f(int&in)", asMETHOD(asCScriptFunction, EnumReferences), asCALL_THISCALL, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_RELEASEREFS, "void f(int&in)", asMETHOD(asCScriptFunction, ReleaseAllHandles), asCALL_THISCALL, 0); + asASSERT( r >= 0 ); // TODO: Need some way to allow the arg type to adapt when the funcdefs are instantiated // r = engine->RegisterMethodToObjectType(&engine->functionBehaviours, "bool opEquals(const int &in)", asMETHOD(asCScriptFunction,operator==), asCALL_THISCALL); asASSERT( r >= 0 ); #else - r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_ADDREF, "void f()", asFUNCTION(ScriptFunction_AddRef_Generic), asCALL_GENERIC, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_RELEASE, "void f()", asFUNCTION(ScriptFunction_Release_Generic), asCALL_GENERIC, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_GETREFCOUNT, "int f()", asFUNCTION(ScriptFunction_GetRefCount_Generic), asCALL_GENERIC, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_SETGCFLAG, "void f()", asFUNCTION(ScriptFunction_SetFlag_Generic), asCALL_GENERIC, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_GETGCFLAG, "bool f()", asFUNCTION(ScriptFunction_GetFlag_Generic), asCALL_GENERIC, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_ENUMREFS, "void f(int&in)", asFUNCTION(ScriptFunction_EnumReferences_Generic), asCALL_GENERIC, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_RELEASEREFS, "void f(int&in)", asFUNCTION(ScriptFunction_ReleaseAllHandles_Generic), asCALL_GENERIC, 0); asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_ADDREF, "void f()", asFUNCTION(ScriptFunction_AddRef_Generic), asCALL_GENERIC, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_RELEASE, "void f()", asFUNCTION(ScriptFunction_Release_Generic), asCALL_GENERIC, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_GETREFCOUNT, "int f()", asFUNCTION(ScriptFunction_GetRefCount_Generic), asCALL_GENERIC, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_SETGCFLAG, "void f()", asFUNCTION(ScriptFunction_SetFlag_Generic), asCALL_GENERIC, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_GETGCFLAG, "bool f()", asFUNCTION(ScriptFunction_GetFlag_Generic), asCALL_GENERIC, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_ENUMREFS, "void f(int&in)", asFUNCTION(ScriptFunction_EnumReferences_Generic), asCALL_GENERIC, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->functionBehaviours, asBEHAVE_RELEASEREFS, "void f(int&in)", asFUNCTION(ScriptFunction_ReleaseAllHandles_Generic), asCALL_GENERIC, 0); + asASSERT( r >= 0 ); // r = engine->RegisterMethodToObjectType(&engine->functionBehaviours, "bool opEquals(const int &in)", asFUNCTION(ScriptFunction_opEquals_Generic), asCALL_GENERIC); asASSERT( r >= 0 ); #endif @@ -153,9 +167,11 @@ void RegisterScriptFunction(asCScriptEngine *engine) // registered to return a void then the return type is changed manually to the builtin function type // The name of the function is an invalid identifier so it cannot be invoked accidentally from the script #ifndef AS_MAX_PORTABILITY - r = engine->RegisterGlobalFunction("void f(int &in, int &in)", asFUNCTION(CreateDelegate), asCALL_CDECL); asASSERT( r >= 0 ); + r = engine->RegisterGlobalFunction("void f(int &in, int &in)", asFUNCTION(CreateDelegate), asCALL_CDECL); + asASSERT( r >= 0 ); #else - r = engine->RegisterGlobalFunction("void f(int &in, int &in)", asFUNCTION(ScriptFunction_CreateDelegate_Generic), asCALL_GENERIC); asASSERT( r >= 0 ); + r = engine->RegisterGlobalFunction("void f(int &in, int &in)", asFUNCTION(ScriptFunction_CreateDelegate_Generic), asCALL_GENERIC); + asASSERT( r >= 0 ); #endif // Rename the function so that it cannot be called manually by the script @@ -179,7 +195,7 @@ asCScriptFunction *CreateDelegate(asCScriptFunction *func, void *obj) // Create an instance of a asCScriptFunction with the type asFUNC_DELEGATE // The delegate shouldn't have a function id and is not added to the engine->scriptFunctions - asCScriptFunction *delegate = asNEW(asCScriptFunction)(static_cast(func->GetEngine()), 0, asFUNC_DELEGATE); + asCScriptFunction *delegate = asNEW(asCScriptFunction)(static_cast(func->GetEngine()), 0, asFUNC_DELEGATE); if( delegate ) delegate->MakeDelegate(func, obj); @@ -210,7 +226,7 @@ void asCScriptFunction::MakeDelegate(asCScriptFunction *func, void *obj) // interface void *asCScriptFunction::GetAuxiliary() const { - if (sysFuncIntf) + if( sysFuncIntf ) return sysFuncIntf->auxiliary; return 0; @@ -264,7 +280,7 @@ int asCScriptFunction::RegisterListPattern(const char *decl, asCScriptNode *list // Build the representation of the list pattern from the script nodes asSListPatternNode *node; listPattern = asNEW(asSListPatternNode)(asLPT_START); - node = listPattern; + node = listPattern; // Recursively parse the child int r = ParseListPattern(node, decl, listNodes); @@ -288,13 +304,13 @@ int asCScriptFunction::ParseListPattern(asSListPatternNode *&target, const char if( token == "repeat" ) { node->next = asNEW(asSListPatternNode)(asLPT_REPEAT); - node = node->next; + node = node->next; } else if( token == "repeat_same" ) { // TODO: list: Should make sure this is a sub-list node->next = asNEW(asSListPatternNode)(asLPT_REPEAT_SAME); - node = node->next; + node = node->next; } else { @@ -304,8 +320,8 @@ int asCScriptFunction::ParseListPattern(asSListPatternNode *&target, const char } else if( listNodes->nodeType == snDataType ) { - asCDataType dt; - asCBuilder builder(engine, 0); + asCDataType dt; + asCBuilder builder(engine, 0); asCScriptCode code; code.SetCode("", decl, 0, false); @@ -313,12 +329,12 @@ int asCScriptFunction::ParseListPattern(asSListPatternNode *&target, const char dt = builder.CreateDataTypeFromNode(listNodes, &code, engine->defaultNamespace, false, objectType ? objectType : CastToObjectType(returnType.GetTypeInfo())); node->next = asNEW(asSListPatternDataTypeNode)(dt); - node = node->next; + node = node->next; } else if( listNodes->nodeType == snListPattern ) { node->next = asNEW(asSListPatternNode)(asLPT_START); - node = node->next; + node = node->next; // Recursively parse the child int r = ParseListPattern(node, decl, listNodes); @@ -326,7 +342,7 @@ int asCScriptFunction::ParseListPattern(asSListPatternNode *&target, const char return r; node->next = asNEW(asSListPatternNode)(asLPT_END); - node = node->next; + node = node->next; } else { @@ -345,7 +361,7 @@ int asCScriptFunction::ParseListPattern(asSListPatternNode *&target, const char // internal asCScriptFunction::asCScriptFunction(asCScriptEngine *engine, asCModule *mod, asEFuncType _funcType) { - funcType = _funcType; + funcType = _funcType; if( funcType == asFUNC_DELEGATE ) { // Delegates behave like object instances, rather than script code @@ -402,7 +418,7 @@ void asCScriptFunction::DeallocateScriptFunctionData() if( !scriptData ) return; for( asUINT n = 0; n < scriptData->variables.GetLength(); n++ ) - asDELETE(scriptData->variables[n],asSScriptVariable); + asDELETE(scriptData->variables[n], asSScriptVariable); scriptData->variables.SetLength(0); asDELETE(scriptData, ScriptFunctionData); @@ -455,7 +471,7 @@ void asCScriptFunction::DestroyInternal() // Clean up user data for( asUINT n = 0; n < userData.GetLength(); n += 2 ) { - if( userData[n+1] ) + if( userData[n + 1] ) { for( asUINT c = 0; c < engine->cleanFunctionFuncs.GetLength(); c++ ) if( engine->cleanFunctionFuncs[c].type == userData[n] ) @@ -475,7 +491,7 @@ void asCScriptFunction::DestroyInternal() defaultArgs.SetLength(0); if( sysFuncIntf ) - asDELETE(sysFuncIntf,asSSystemFunctionInterface); + asDELETE(sysFuncIntf, asSSystemFunctionInterface); sysFuncIntf = 0; if( objectType ) @@ -495,8 +511,8 @@ void asCScriptFunction::DestroyInternal() } // Release template sub types - for (asUINT n = 0; n < templateSubTypes.GetLength(); n++) - if(templateSubTypes[n].GetTypeInfo()) + for( asUINT n = 0; n < templateSubTypes.GetLength(); n++ ) + if( templateSubTypes[n].GetTypeInfo() ) templateSubTypes[n].GetTypeInfo()->ReleaseInternal(); } @@ -517,9 +533,9 @@ int asCScriptFunction::AddRef() const int asCScriptFunction::Release() const { gcFlag = false; - int r = externalRefCount.atomicDec(); + int r = externalRefCount.atomicDec(); if( r == 0 && - funcType != asFUNC_DUMMY ) // Dummy functions are allocated on the stack and cannot be deleted + funcType != asFUNC_DUMMY ) // Dummy functions are allocated on the stack and cannot be deleted { // There are no more external references, if there are also no // internal references then it is time to delete the function @@ -529,7 +545,7 @@ int asCScriptFunction::Release() const // For example if the function was dynamically compiled without adding it to the scope of the module asASSERT( module == 0 ); - asDELETE(const_cast(this),asCScriptFunction); + asDELETE(const_cast(this), asCScriptFunction); } } @@ -547,13 +563,13 @@ int asCScriptFunction::ReleaseInternal() { int r = internalRefCount.atomicDec(); if( r == 0 && - funcType != asFUNC_DUMMY ) + funcType != asFUNC_DUMMY ) { // There are no more internal references, if there are also no // external references then it is time to delete the function if( externalRefCount.get() == 0 ) { - asDELETE(const_cast(this),asCScriptFunction); + asDELETE(const_cast(this), asCScriptFunction); } } @@ -564,7 +580,7 @@ int asCScriptFunction::ReleaseInternal() int asCScriptFunction::GetTypeId() const { // This const cast is ok, the object won't be modified - asCDataType dt = asCDataType::CreateType(engine->FindMatchingFuncdef(const_cast(this), 0), false); + asCDataType dt = asCDataType::CreateType(engine->FindMatchingFuncdef(const_cast(this), 0), false); return engine->GetTypeIdFromDataType(dt); } @@ -574,7 +590,7 @@ bool asCScriptFunction::IsCompatibleWithTypeId(int typeId) const asCDataType dt = engine->GetDataTypeFromTypeId(typeId); // Make sure the type is a function - if (!dt.IsFuncdef()) + if( !dt.IsFuncdef() ) return false; asCScriptFunction *func = CastToFuncdefType(dt.GetTypeInfo())->funcdef; @@ -627,7 +643,7 @@ const char *asCScriptFunction::GetName() const // interface const char *asCScriptFunction::GetNamespace() const { - if (nameSpace) + if( nameSpace ) return nameSpace->name.AddressOf(); return 0; @@ -672,8 +688,8 @@ int asCScriptFunction::GetSpaceNeededForReturnValue() bool asCScriptFunction::DoesReturnOnStack() const { if( returnType.GetTypeInfo() && - (returnType.GetTypeInfo()->flags & asOBJ_VALUE) && - !returnType.IsReference() ) + (returnType.GetTypeInfo()->flags & asOBJ_VALUE) && + !returnType.IsReference() ) return true; return false; @@ -688,24 +704,24 @@ asCString asCScriptFunction::GetDeclarationStr(bool includeObjectName, bool incl // Don't add the return type for constructors and destructors if( !(returnType.GetTokenType() == ttVoid && - objectType && - (name == objectType->name || (name.GetLength() > 0 && name[0] == '~') || - name == "$beh0" || name == "$beh2")) ) + objectType && + (name == objectType->name || (name.GetLength() > 0 && name[0] == '~') || + name == "$beh0" || name == "$beh2")) ) { - str = returnType.Format(nameSpace, includeNamespace); + str = returnType.Format(nameSpace, includeNamespace); str += " "; } if( objectType && includeObjectName ) { - asCDataType dt = asCDataType::CreateType(objectType, false); - str += dt.Format(nameSpace, includeNamespace); - str += "::"; + asCDataType dt = asCDataType::CreateType(objectType, false); + str += dt.Format(nameSpace, includeNamespace); + str += "::"; } - else if (funcdefType && funcdefType->parentClass && includeObjectName) + else if( funcdefType && funcdefType->parentClass && includeObjectName ) { - asCDataType dt = asCDataType::CreateType(funcdefType->parentClass, false); - str += dt.Format(nameSpace, includeNamespace); - str += "::"; + asCDataType dt = asCDataType::CreateType(funcdefType->parentClass, false); + str += dt.Format(nameSpace, includeNamespace); + str += "::"; } else if( includeNamespace && nameSpace->name != "" && !objectType && !(funcdefType && funcdefType->parentClass) ) { @@ -713,7 +729,7 @@ asCString asCScriptFunction::GetDeclarationStr(bool includeObjectName, bool incl } if( name == "" ) str += "_unnamed_function_("; - else if( name.SubString(0,4) == "$beh" && name.GetLength() == 5 ) + else if( name.SubString(0, 4) == "$beh" && name.GetLength() == 5 ) { if( name[4] == '0' + asBEHAVE_CONSTRUCT ) str += objectType->name + "("; @@ -726,10 +742,10 @@ asCString asCScriptFunction::GetDeclarationStr(bool includeObjectName, bool incl } else { - if (funcType == asFUNC_TEMPLATE) + if( funcType == asFUNC_TEMPLATE ) { str += name + "<"; - for (asUINT t = 0; t < templateSubTypes.GetLength()-1; t++) + for( asUINT t = 0; t < templateSubTypes.GetLength() - 1; t++ ) str += templateSubTypes[t].GetTypeInfo()->name + ","; str += templateSubTypes[templateSubTypes.GetLength() - 1].GetTypeInfo()->name; str += ">("; @@ -790,7 +806,7 @@ asCString asCScriptFunction::GetDeclarationStr(bool includeObjectName, bool incl } } - if (IsVariadic()) + if( IsVariadic() ) { str += "..."; } @@ -803,19 +819,19 @@ asCString asCScriptFunction::GetDeclarationStr(bool includeObjectName, bool incl // Add the declaration of the list pattern if( listPattern ) { - asSListPatternNode *n = listPattern; - bool first = true; + asSListPatternNode *n = listPattern; + bool first = true; while( n ) { if( n->type == asLPT_START ) { - str += " {"; - first = true; + str += " {"; + first = true; } else if( n->type == asLPT_END ) { - str += " }"; - first = false; + str += " }"; + first = false; } else if( n->type == asLPT_REPEAT ) str += " repeat"; @@ -825,12 +841,12 @@ asCString asCScriptFunction::GetDeclarationStr(bool includeObjectName, bool incl { if( first ) { - str += " "; - first = false; + str += " "; + first = false; } else str += ", "; - str += reinterpret_cast(n)->dataType.Format(nameSpace, includeNamespace); + str += reinterpret_cast(n)->dataType.Format(nameSpace, includeNamespace); } n = n->next; @@ -857,16 +873,19 @@ int asCScriptFunction::FindNextLineWithCode(int line) const // Sort all line numbers before looking for the next asCArray lineNbrs; for( asUINT n = 1; n < scriptData->lineNumbers.GetLength(); n += 2 ) - lineNbrs.PushLast(scriptData->lineNumbers[n]&0xFFFFF); + lineNbrs.PushLast(scriptData->lineNumbers[n] & 0xFFFFF); struct C { - static int cmp(const void *a, const void *b) { return *(const int*)a - *(const int*)b; } + static int cmp(const void *a, const void *b) + { + return *(const int *)a - *(const int *)b; + } }; std::qsort(&lineNbrs[0], lineNbrs.GetLength(), sizeof(int), C::cmp); - if( line < lineNbrs[0] && line < (scriptData->declaredAt&0xFFFFF)) return -1; - if( line > lineNbrs[lineNbrs.GetLength()-1] ) return -1; + if( line < lineNbrs[0] && line < (scriptData->declaredAt & 0xFFFFF) ) return -1; + if( line > lineNbrs[lineNbrs.GetLength() - 1] ) return -1; // Find the line with code on or right after the input line // TODO: optimize: Do binary search @@ -877,15 +896,15 @@ int asCScriptFunction::FindNextLineWithCode(int line) const else { // Check if given line is outside function - if( line < (scriptData->declaredAt&0xFFFFF) ) return -1; - if( line > (scriptData->lineNumbers[scriptData->lineNumbers.GetLength()-1]&0xFFFFF) ) return -1; + if( line < (scriptData->declaredAt & 0xFFFFF) ) return -1; + if( line > (scriptData->lineNumbers[scriptData->lineNumbers.GetLength() - 1] & 0xFFFFF) ) return -1; // Find the line with code on or right after the input line // TODO: optimize: Do binary search instead for( asUINT n = 1; n < scriptData->lineNumbers.GetLength(); n += 2 ) { - if( line <= (scriptData->lineNumbers[n]&0xFFFFF) ) - return (scriptData->lineNumbers[n]&0xFFFFF); + if( line <= (scriptData->lineNumbers[n] & 0xFFFFF) ) + return (scriptData->lineNumbers[n] & 0xFFFFF); } } @@ -896,35 +915,35 @@ int asCScriptFunction::FindNextLineWithCode(int line) const // interface int asCScriptFunction::GetLineEntryCount() const { - if (scriptData == 0) return asNOT_SUPPORTED; + if( scriptData == 0 ) return asNOT_SUPPORTED; return scriptData->lineNumbers.GetLength() / 2; } // interface -int asCScriptFunction::GetLineEntry(asUINT index, int* row, int *col, const char** sectionName, const asDWORD** byteCode) const +int asCScriptFunction::GetLineEntry(asUINT index, int *row, int *col, const char **sectionName, const asDWORD **byteCode) const { - if (scriptData == 0) return asNOT_SUPPORTED; - if (index >= scriptData->lineNumbers.GetLength() / 2) + if( scriptData == 0 ) return asNOT_SUPPORTED; + if( index >= scriptData->lineNumbers.GetLength() / 2 ) return asINVALID_ARG; int position = scriptData->lineNumbers[index * 2]; - int rowcol = scriptData->lineNumbers[(index * 2) + 1]; + int rowcol = scriptData->lineNumbers[(index * 2) + 1]; - if (row) *row = rowcol & 0xFFFFF; - if (col) *col = rowcol >> 20; + if( row ) *row = rowcol & 0xFFFFF; + if( col ) *col = rowcol >> 20; - if (sectionName) + if( sectionName ) { - if (scriptData->sectionIdxs.GetLength() > 0) + if( scriptData->sectionIdxs.GetLength() > 0 ) { int sectionIdx = 0; // Find the correct section index if the function is compiled from multiple sections // This array will be empty most of the time so we don't need a sofisticated algorithm to search it - for (asUINT n = 0; n < scriptData->sectionIdxs.GetLength(); n += 2) + for( asUINT n = 0; n < scriptData->sectionIdxs.GetLength(); n += 2 ) { - if (scriptData->sectionIdxs[n] <= position) + if( scriptData->sectionIdxs[n] <= position ) sectionIdx = scriptData->sectionIdxs[n + 1]; } @@ -936,7 +955,7 @@ int asCScriptFunction::GetLineEntry(asUINT index, int* row, int *col, const char if( byteCode ) { - if (scriptData->byteCode.GetLength() == 0) + if( scriptData->byteCode.GetLength() == 0 ) return asERROR; *byteCode = scriptData->byteCode.AddressOf() + position; } @@ -945,18 +964,18 @@ int asCScriptFunction::GetLineEntry(asUINT index, int* row, int *col, const char } // interface -int asCScriptFunction::GetDeclaredAt(const char** scriptSection, int* row, int* col) const +int asCScriptFunction::GetDeclaredAt(const char **scriptSection, int *row, int *col) const { - if (!scriptData) + if( !scriptData ) { - if (scriptSection) *scriptSection = 0; - if (row) *row = 0; - if (col) *col = 0; + if( scriptSection ) *scriptSection = 0; + if( row ) *row = 0; + if( col ) *col = 0; return asNOT_SUPPORTED; } - if (scriptSection) *scriptSection = scriptData->scriptSectionIdx >= 0 ? engine->scriptSectionNames[scriptData->scriptSectionIdx]->AddressOf() : 0; - if (row) *row = scriptData->declaredAt & 0xFFFFF; - if (col) *col = scriptData->declaredAt >> 20; + if( scriptSection ) *scriptSection = scriptData->scriptSectionIdx >= 0 ? engine->scriptSectionNames[scriptData->scriptSectionIdx]->AddressOf() : 0; + if( row ) *row = scriptData->declaredAt & 0xFFFFF; + if( col ) *col = scriptData->declaredAt >> 20; return 0; } @@ -975,38 +994,38 @@ int asCScriptFunction::GetLineNumber(int programPosition, int *sectionIdx) for( asUINT n = 0; n < scriptData->sectionIdxs.GetLength(); n += 2 ) { if( scriptData->sectionIdxs[n] <= programPosition ) - *sectionIdx = scriptData->sectionIdxs[n+1]; + *sectionIdx = scriptData->sectionIdxs[n + 1]; } } // Do a binary search in the buffer - int max = (int)scriptData->lineNumbers.GetLength()/2 - 1; + int max = (int)scriptData->lineNumbers.GetLength() / 2 - 1; int min = 0; - int i = max/2; + int i = max / 2; - for(;;) + for( ;; ) { - if( scriptData->lineNumbers[i*2] < programPosition ) + if( scriptData->lineNumbers[i * 2] < programPosition ) { // Have we found the largest number < programPosition? - if( max == i ) return scriptData->lineNumbers[i*2+1]; - if( scriptData->lineNumbers[i*2+2] > programPosition ) return scriptData->lineNumbers[i*2+1]; + if( max == i ) return scriptData->lineNumbers[i * 2 + 1]; + if( scriptData->lineNumbers[i * 2 + 2] > programPosition ) return scriptData->lineNumbers[i * 2 + 1]; min = i + 1; - i = (max + min)/2; + i = (max + min) / 2; } - else if( scriptData->lineNumbers[i*2] > programPosition ) + else if( scriptData->lineNumbers[i * 2] > programPosition ) { // Have we found the smallest number > programPosition? - if( min == i ) return scriptData->lineNumbers[i*2+1]; + if( min == i ) return scriptData->lineNumbers[i * 2 + 1]; max = i - 1; - i = (max + min)/2; + i = (max + min) / 2; } else { // We found the exact position - return scriptData->lineNumbers[i*2+1]; + return scriptData->lineNumbers[i * 2 + 1]; } } } @@ -1047,9 +1066,9 @@ const char *asCScriptFunction::GetVarDecl(asUINT index, bool includeNamespace) c if( scriptData == 0 || index >= scriptData->variables.GetLength() ) return 0; - asCString *tempString = &asCThreadManager::GetLocalData()->string; - *tempString = scriptData->variables[index]->type.Format(nameSpace, includeNamespace); - *tempString += " " + scriptData->variables[index]->name; + asCString *tempString = &asCThreadManager::GetLocalData()->string; + *tempString = scriptData->variables[index]->type.Format(nameSpace, includeNamespace); + *tempString += " " + scriptData->variables[index]->name; return tempString->AddressOf(); } @@ -1079,7 +1098,7 @@ asCTypeInfo *asCScriptFunction::GetTypeInfoOfLocalVar(short varOffset) for( asUINT n = 0; n < scriptData->variables.GetLength(); n++ ) { - if (scriptData->variables[n]->stackOffset == varOffset) + if( scriptData->variables[n]->stackOffset == varOffset ) return scriptData->variables[n]->type.GetTypeInfo(); } @@ -1146,11 +1165,11 @@ bool asCScriptFunction::IsSignatureExceptNameAndReturnTypeEqual(const asCScriptF // internal bool asCScriptFunction::IsSignatureExceptNameAndReturnTypeEqual(const asCArray ¶mTypes, const asCArray ¶mInOut, const asCObjectType *objType, bool readOnly, bool isVariadic) const { - if( this->IsReadOnly() != readOnly ) return false; + if( this->IsReadOnly() != readOnly ) return false; if( (this->objectType != 0) != (objType != 0) ) return false; - if( this->inOutFlags != paramInOut ) return false; - if( this->parameterTypes != paramTypes ) return false; - if (this->IsVariadic() != isVariadic ) return false; + if( this->inOutFlags != paramInOut ) return false; + if( this->parameterTypes != paramTypes ) return false; + if( this->IsVariadic() != isVariadic ) return false; return true; } @@ -1163,7 +1182,7 @@ void asCScriptFunction::AddReferences() // to hold only one reference to the variable. However, if the variable is initialized through // the default constructor followed by the assignment operator we will have two references to // the variable in the function. - asCArray ptrs; + asCArray ptrs; // Only count references if there is any bytecode if( scriptData && scriptData->byteCode.GetLength() ) @@ -1185,108 +1204,108 @@ void asCScriptFunction::AddReferences() if( group != 0 ) group->AddRef(); } - for (asUINT v = 0; v < scriptData->variables.GetLength(); v++) + for( asUINT v = 0; v < scriptData->variables.GetLength(); v++ ) { - asCTypeInfo* ti = reinterpret_cast(scriptData->variables[v]->type.GetTypeInfo()); - if (ti) // The null handle is also stored, but it doesn't have an object type + asCTypeInfo *ti = reinterpret_cast(scriptData->variables[v]->type.GetTypeInfo()); + if( ti ) // The null handle is also stored, but it doesn't have an object type { ti->AddRefInternal(); - asCConfigGroup* group = engine->FindConfigGroupForTypeInfo(ti); - if (group != 0) group->AddRef(); + asCConfigGroup *group = engine->FindConfigGroupForTypeInfo(ti); + if( group != 0 ) group->AddRef(); } } // Go through the byte code and add references to all resources used by the function asCArray &bc = scriptData->byteCode; - for( asUINT n = 0; n < bc.GetLength(); n += asBCTypeSize[asBCInfo[*(asBYTE*)&bc[n]].type] ) + for( asUINT n = 0; n < bc.GetLength(); n += asBCTypeSize[asBCInfo[*(asBYTE *)&bc[n]].type] ) { - switch( *(asBYTE*)&bc[n] ) + switch( *(asBYTE *)&bc[n] ) { - // Object types - case asBC_OBJTYPE: - case asBC_FREE: - case asBC_REFCPY: - case asBC_RefCpyV: + // Object types + case asBC_OBJTYPE: + case asBC_FREE: + case asBC_REFCPY: + case asBC_RefCpyV: { - asCObjectType *objType = (asCObjectType*)asBC_PTRARG(&bc[n]); + asCObjectType *objType = (asCObjectType *)asBC_PTRARG(&bc[n]); asASSERT( objType ); if( objType ) objType->AddRefInternal(); } break; - // Object type and function - case asBC_ALLOC: + // Object type and function + case asBC_ALLOC: { - asCObjectType *objType = (asCObjectType*)asBC_PTRARG(&bc[n]); + asCObjectType *objType = (asCObjectType *)asBC_PTRARG(&bc[n]); asASSERT( objType ); if( objType ) objType->AddRefInternal(); - int funcId = asBC_INTARG(&bc[n]+AS_PTR_SIZE); + int funcId = asBC_INTARG(&bc[n] + AS_PTR_SIZE); if( funcId ) engine->scriptFunctions[funcId]->AddRefInternal(); } break; - // Global variables - case asBC_PGA: - case asBC_PshGPtr: - case asBC_LDG: - case asBC_PshG4: - case asBC_LdGRdR4: - case asBC_CpyGtoV4: - case asBC_CpyVtoG4: - case asBC_SetG4: - // Need to increase the reference for each global variable - { - void *gvarPtr = (void*)asBC_PTRARG(&bc[n]); - if( !gvarPtr ) break; - asCGlobalProperty *prop = GetPropertyByGlobalVarPtr(gvarPtr); - - if (!prop) + // Global variables + case asBC_PGA: + case asBC_PshGPtr: + case asBC_LDG: + case asBC_PshG4: + case asBC_LdGRdR4: + case asBC_CpyGtoV4: + case asBC_CpyVtoG4: + case asBC_SetG4: + // Need to increase the reference for each global variable { - // The pointer is a string constant. In order to make sure the correct resource - // management is maintained we request a new string constant here, so the compiler - // or bytecode loader can release its copy afterwards. - asCString str; - asUINT length; - int r = engine->stringFactory->GetRawStringData(gvarPtr, 0, &length); - if (r >= 0) + void *gvarPtr = (void *)asBC_PTRARG(&bc[n]); + if( !gvarPtr ) break; + asCGlobalProperty *prop = GetPropertyByGlobalVarPtr(gvarPtr); + + if( !prop ) { - str.SetLength(length); - engine->stringFactory->GetRawStringData(gvarPtr, str.AddressOf(), &length); + // The pointer is a string constant. In order to make sure the correct resource + // management is maintained we request a new string constant here, so the compiler + // or bytecode loader can release its copy afterwards. + asCString str; + asUINT length; + int r = engine->stringFactory->GetRawStringData(gvarPtr, 0, &length); + if( r >= 0 ) + { + str.SetLength(length); + engine->stringFactory->GetRawStringData(gvarPtr, str.AddressOf(), &length); + + // Get a new pointer (depending on the string factory implementation it may actually be the same) + gvarPtr = const_cast(engine->stringFactory->GetStringConstant(str.AddressOf(), length)); + asBC_PTRARG(&bc[n]) = (asPWORD)gvarPtr; + } + + // If we get an error from the string factory there is not + // anything we can do about it, except report a message. + // TODO: NEWSTRING: Write a message and then exit gracefully + asASSERT(r >= 0); + break; + } - // Get a new pointer (depending on the string factory implementation it may actually be the same) - gvarPtr = const_cast(engine->stringFactory->GetStringConstant(str.AddressOf(), length)); - asBC_PTRARG(&bc[n]) = (asPWORD)gvarPtr; + // Only addref the properties once + if( !ptrs.Exists(gvarPtr) ) + { + prop->AddRef(); + ptrs.PushLast(gvarPtr); } - - // If we get an error from the string factory there is not - // anything we can do about it, except report a message. - // TODO: NEWSTRING: Write a message and then exit gracefully - asASSERT(r >= 0); - break; - } - // Only addref the properties once - if( !ptrs.Exists(gvarPtr) ) - { - prop->AddRef(); - ptrs.PushLast(gvarPtr); + asCConfigGroup *group = engine->FindConfigGroupForGlobalVar(prop->id); + if( group != 0 ) group->AddRef(); } + break; - asCConfigGroup *group = engine->FindConfigGroupForGlobalVar(prop->id); - if( group != 0 ) group->AddRef(); - } - break; - - // System functions - case asBC_CALLSYS: + // System functions + case asBC_CALLSYS: { - int funcId = asBC_INTARG(&bc[n]); - asCConfigGroup *group = engine->FindConfigGroupForFunction(funcId); + int funcId = asBC_INTARG(&bc[n]); + asCConfigGroup *group = engine->FindConfigGroupForFunction(funcId); if( group != 0 ) group->AddRef(); asASSERT( funcId > 0 ); @@ -1295,9 +1314,9 @@ void asCScriptFunction::AddReferences() } break; - // Functions - case asBC_CALL: - case asBC_CALLINTF: + // Functions + case asBC_CALL: + case asBC_CALLINTF: { int funcId = asBC_INTARG(&bc[n]); asASSERT( funcId > 0 ); @@ -1306,10 +1325,10 @@ void asCScriptFunction::AddReferences() } break; - // Function pointers - case asBC_FuncPtr: + // Function pointers + case asBC_FuncPtr: { - asCScriptFunction *func = (asCScriptFunction*)asBC_PTRARG(&bc[n]); + asCScriptFunction *func = (asCScriptFunction *)asBC_PTRARG(&bc[n]); asASSERT( func ); if( func ) func->AddRefInternal(); @@ -1323,7 +1342,7 @@ void asCScriptFunction::AddReferences() // internal void asCScriptFunction::ReleaseReferences() { - asCArray ptrs; + asCArray ptrs; // Only count references if there is any bytecode if( scriptData && scriptData->byteCode.GetLength() ) @@ -1345,44 +1364,44 @@ void asCScriptFunction::ReleaseReferences() if( group != 0 ) group->Release(); } - for (asUINT v = 0; v < scriptData->variables.GetLength(); v++) + for( asUINT v = 0; v < scriptData->variables.GetLength(); v++ ) { - asCTypeInfo* ti = reinterpret_cast(scriptData->variables[v]->type.GetTypeInfo()); - if (ti) // The null handle is also stored, but it doesn't have an object type + asCTypeInfo *ti = reinterpret_cast(scriptData->variables[v]->type.GetTypeInfo()); + if( ti ) // The null handle is also stored, but it doesn't have an object type { ti->ReleaseInternal(); - asCConfigGroup* group = engine->FindConfigGroupForTypeInfo(ti); - if (group != 0) group->Release(); + asCConfigGroup *group = engine->FindConfigGroupForTypeInfo(ti); + if( group != 0 ) group->Release(); } } // Go through the byte code and release references to all resources used by the function asCArray &bc = scriptData->byteCode; - for( asUINT n = 0; n < bc.GetLength(); n += asBCTypeSize[asBCInfo[*(asBYTE*)&bc[n]].type] ) + for( asUINT n = 0; n < bc.GetLength(); n += asBCTypeSize[asBCInfo[*(asBYTE *)&bc[n]].type] ) { - switch( *(asBYTE*)&bc[n] ) + switch( *(asBYTE *)&bc[n] ) { - // Object types - case asBC_OBJTYPE: - case asBC_FREE: - case asBC_REFCPY: - case asBC_RefCpyV: + // Object types + case asBC_OBJTYPE: + case asBC_FREE: + case asBC_REFCPY: + case asBC_RefCpyV: { - asCObjectType *objType = (asCObjectType*)asBC_PTRARG(&bc[n]); + asCObjectType *objType = (asCObjectType *)asBC_PTRARG(&bc[n]); if( objType ) objType->ReleaseInternal(); } break; - // Object type and function - case asBC_ALLOC: + // Object type and function + case asBC_ALLOC: { - asCObjectType *objType = (asCObjectType*)asBC_PTRARG(&bc[n]); + asCObjectType *objType = (asCObjectType *)asBC_PTRARG(&bc[n]); if( objType ) objType->ReleaseInternal(); - int funcId = asBC_INTARG(&bc[n]+AS_PTR_SIZE); + int funcId = asBC_INTARG(&bc[n] + AS_PTR_SIZE); if( funcId > 0 ) { asCScriptFunction *fptr = engine->scriptFunctions[funcId]; @@ -1398,53 +1417,53 @@ void asCScriptFunction::ReleaseReferences() } break; - // Global variables - case asBC_PGA: - case asBC_PshGPtr: - case asBC_LDG: - case asBC_PshG4: - case asBC_LdGRdR4: - case asBC_CpyGtoV4: - case asBC_CpyVtoG4: - case asBC_SetG4: - // Need to increase the reference for each global variable - { - void *gvarPtr = (void*)asBC_PTRARG(&bc[n]); - if( !gvarPtr ) break; - asCGlobalProperty *prop = GetPropertyByGlobalVarPtr(gvarPtr); - - if (!prop) + // Global variables + case asBC_PGA: + case asBC_PshGPtr: + case asBC_LDG: + case asBC_PshG4: + case asBC_LdGRdR4: + case asBC_CpyGtoV4: + case asBC_CpyVtoG4: + case asBC_SetG4: + // Need to increase the reference for each global variable { - // The pointer is a string constant, so it needs to be released by the string factory - int r = engine->stringFactory->ReleaseStringConstant(gvarPtr); - UNUSED_VAR(r); - - // If we get an error from the string factory there is not - // anything we can do about it, except report a message. - // TODO: Write a message showing that the string couldn't be - // released. Include the first 10 characters and the length - // to make it easier to identify which string it was - asASSERT(r >= 0); - break; - } + void *gvarPtr = (void *)asBC_PTRARG(&bc[n]); + if( !gvarPtr ) break; + asCGlobalProperty *prop = GetPropertyByGlobalVarPtr(gvarPtr); - // Only release the properties once - if( !ptrs.Exists(gvarPtr) ) - { - prop->Release(); - ptrs.PushLast(gvarPtr); - } + if( !prop ) + { + // The pointer is a string constant, so it needs to be released by the string factory + int r = engine->stringFactory->ReleaseStringConstant(gvarPtr); + UNUSED_VAR(r); + + // If we get an error from the string factory there is not + // anything we can do about it, except report a message. + // TODO: Write a message showing that the string couldn't be + // released. Include the first 10 characters and the length + // to make it easier to identify which string it was + asASSERT(r >= 0); + break; + } - asCConfigGroup *group = engine->FindConfigGroupForGlobalVar(prop->id); - if( group != 0 ) group->Release(); - } - break; + // Only release the properties once + if( !ptrs.Exists(gvarPtr) ) + { + prop->Release(); + ptrs.PushLast(gvarPtr); + } - // System functions - case asBC_CALLSYS: + asCConfigGroup *group = engine->FindConfigGroupForGlobalVar(prop->id); + if( group != 0 ) group->Release(); + } + break; + + // System functions + case asBC_CALLSYS: { - int funcId = asBC_INTARG(&bc[n]); - asCConfigGroup *group = engine->FindConfigGroupForFunction(funcId); + int funcId = asBC_INTARG(&bc[n]); + asCConfigGroup *group = engine->FindConfigGroupForFunction(funcId); if( group != 0 ) group->Release(); if( funcId ) @@ -1456,9 +1475,9 @@ void asCScriptFunction::ReleaseReferences() } break; - // Functions - case asBC_CALL: - case asBC_CALLINTF: + // Functions + case asBC_CALL: + case asBC_CALLINTF: { int funcId = asBC_INTARG(&bc[n]); if( funcId ) @@ -1476,10 +1495,10 @@ void asCScriptFunction::ReleaseReferences() } break; - // Function pointers - case asBC_FuncPtr: + // Function pointers + case asBC_FuncPtr: { - asCScriptFunction *func = (asCScriptFunction*)asBC_PTRARG(&bc[n]); + asCScriptFunction *func = (asCScriptFunction *)asBC_PTRARG(&bc[n]); if( func ) func->ReleaseInternal(); } @@ -1488,15 +1507,15 @@ void asCScriptFunction::ReleaseReferences() } // Release the jit compiled function - if (scriptData->jitFunction) + if( scriptData->jitFunction ) { - if (engine->ep.jitInterfaceVersion == 1) - static_cast(engine->jitCompiler)->ReleaseJITFunction(scriptData->jitFunction); + if( engine->ep.jitInterfaceVersion == 1 ) + static_cast(engine->jitCompiler)->ReleaseJITFunction(scriptData->jitFunction); } // For JIT v2, the CleanFunction is called even if the jitFunction has not been set. This is because the // JIT compiler may have cached data associated with the function that needs to be cleaned up. - if (funcType == asFUNC_SCRIPT && scriptData && engine->ep.jitInterfaceVersion == 2) - static_cast(engine->jitCompiler)->CleanFunction(this, scriptData->jitFunction); + if( funcType == asFUNC_SCRIPT && scriptData && engine->ep.jitInterfaceVersion == 2 ) + static_cast(engine->jitCompiler)->CleanFunction(this, scriptData->jitFunction); scriptData->jitFunction = 0; } @@ -1516,7 +1535,7 @@ int asCScriptFunction::GetReturnTypeId(asDWORD *flags) const { if( returnType.IsReference() ) { - *flags = asTM_INOUTREF; + *flags = asTM_INOUTREF; *flags |= returnType.IsReadOnly() ? asTM_CONST : 0; } else @@ -1543,7 +1562,7 @@ int asCScriptFunction::GetParam(asUINT index, int *out_typeId, asDWORD *out_flag if( out_flags ) { - *out_flags = inOutFlags[index]; + *out_flags = inOutFlags[index]; *out_flags |= parameterTypes[index].IsReadOnly() ? asTM_CONST : 0; } @@ -1576,9 +1595,9 @@ asIScriptEngine *asCScriptFunction::GetEngine() const // interface const char *asCScriptFunction::GetDeclaration(bool includeObjectName, bool includeNamespace, bool includeParamNames) const { - asCString str = GetDeclarationStr(includeObjectName, includeNamespace, includeParamNames); - asCString* tempString = &asCThreadManager::GetLocalData()->string; - *tempString = str; + asCString str = GetDeclarationStr(includeObjectName, includeNamespace, includeParamNames); + asCString *tempString = &asCThreadManager::GetLocalData()->string; + *tempString = str; return tempString->AddressOf(); } @@ -1618,16 +1637,16 @@ asDWORD asCScriptFunction::GetAccessMask() const // interface int asCScriptFunction::SetJITFunction(asJITFunction jitFunc) { - if (engine->ep.jitInterfaceVersion == 1) + if( engine->ep.jitInterfaceVersion == 1 ) return asNOT_SUPPORTED; - if (funcType != asFUNC_SCRIPT) + if( funcType != asFUNC_SCRIPT ) return asERROR; - if (scriptData->jitFunction && scriptData->jitFunction != jitFunc ) + if( scriptData->jitFunction && scriptData->jitFunction != jitFunc ) { - if (engine->ep.jitInterfaceVersion == 2) - static_cast(engine->jitCompiler)->CleanFunction(this, scriptData->jitFunction); + if( engine->ep.jitInterfaceVersion == 2 ) + static_cast(engine->jitCompiler)->CleanFunction(this, scriptData->jitFunction); scriptData->jitFunction = 0; } @@ -1639,7 +1658,7 @@ int asCScriptFunction::SetJITFunction(asJITFunction jitFunc) // interface asJITFunction asCScriptFunction::GetJITFunction() const { - if (scriptData) + if( scriptData ) return scriptData->jitFunction; return 0; @@ -1658,14 +1677,14 @@ void asCScriptFunction::JITCompile() // Make sure the function has been compiled with JitEntry instructions // For functions that has JitEntry this will be a quick test - asUINT length; - asDWORD *byteCode = GetByteCode(&length); - asDWORD *end = byteCode + length; - bool foundJitEntry = false; + asUINT length; + asDWORD *byteCode = GetByteCode(&length); + asDWORD *end = byteCode + length; + bool foundJitEntry = false; while( byteCode < end ) { // Determine the instruction - asEBCInstr op = asEBCInstr(*(asBYTE*)byteCode); + asEBCInstr op = asEBCInstr(*(asBYTE *)byteCode); if( op == asBC_JitEntry ) { foundJitEntry = true; @@ -1686,26 +1705,26 @@ void asCScriptFunction::JITCompile() // Release the previous function, if any if( scriptData->jitFunction ) { - if (engine->ep.jitInterfaceVersion == 1) - static_cast(engine->jitCompiler)->ReleaseJITFunction(scriptData->jitFunction); - else if (engine->ep.jitInterfaceVersion == 2) - static_cast(engine->jitCompiler)->CleanFunction(this, scriptData->jitFunction); + if( engine->ep.jitInterfaceVersion == 1 ) + static_cast(engine->jitCompiler)->ReleaseJITFunction(scriptData->jitFunction); + else if( engine->ep.jitInterfaceVersion == 2 ) + static_cast(engine->jitCompiler)->CleanFunction(this, scriptData->jitFunction); scriptData->jitFunction = 0; } - if (engine->ep.jitInterfaceVersion == 1) + if( engine->ep.jitInterfaceVersion == 1 ) { - // Compile for native system. If the JIT compiler decides to compile the function it + // Compile for native system. If the JIT compiler decides to compile the function it // must do so now, as it is not allowed to do it later. - int r = static_cast(engine->jitCompiler)->CompileFunction(this, &scriptData->jitFunction); - if (r < 0) + int r = static_cast(engine->jitCompiler)->CompileFunction(this, &scriptData->jitFunction); + if( r < 0 ) asASSERT(scriptData->jitFunction == 0); } - else if (engine->ep.jitInterfaceVersion == 2) + else if( engine->ep.jitInterfaceVersion == 2 ) { // Notify the JIT compiler about the new function, it may do JIT compilation now, or later, or not at all. // If it does the compilation now, it will use SetJITFunction to inform the compiled JIT function. - static_cast(engine->jitCompiler)->NewFunction(this); + static_cast(engine->jitCompiler)->NewFunction(this); } } @@ -1737,8 +1756,8 @@ void *asCScriptFunction::SetUserData(void *data, asPWORD type) { if( userData[n] == type ) { - void *oldData = reinterpret_cast(userData[n+1]); - userData[n+1] = reinterpret_cast(data); + void *oldData = reinterpret_cast(userData[n + 1]); + userData[n + 1] = reinterpret_cast(data); RELEASEEXCLUSIVE(engine->engineRWLock); @@ -1766,7 +1785,7 @@ void *asCScriptFunction::GetUserData(asPWORD type) const if( userData[n] == type ) { RELEASESHARED(engine->engineRWLock); - return reinterpret_cast(userData[n+1]); + return reinterpret_cast(userData[n + 1]); } } @@ -1779,7 +1798,7 @@ void *asCScriptFunction::GetUserData(asPWORD type) const // TODO: cleanup: This method should probably be a member of the engine asCGlobalProperty *asCScriptFunction::GetPropertyByGlobalVarPtr(void *gvarPtr) { - asSMapNode *node; + asSMapNode *node; if( engine->varAddressMap.MoveTo(&node, gvarPtr) ) { asASSERT(gvarPtr == node->value->GetAddressOfValue()); @@ -1842,7 +1861,7 @@ bool asCScriptFunction::IsShared() const if( objectType && (objectType->flags & asOBJ_SHARED) ) return true; // funcdefs that are registered by the application are shared - if (funcType == asFUNC_FUNCDEF && module == 0) return true; + if( funcType == asFUNC_FUNCDEF && module == 0 ) return true; // Functions that have been specifically marked as shared are shared return traits.GetTrait(asTRAIT_SHARED); @@ -1881,44 +1900,44 @@ bool asCScriptFunction::IsVariadic() const // internal bool asCScriptFunction::IsFactory() const { - if (objectType) return false; - - asCObjectType* type = CastToObjectType(returnType.GetTypeInfo()); - if (type == 0) return false; + if( objectType ) return false; - if (type->name != name) return false; + asCObjectType *type = CastToObjectType(returnType.GetTypeInfo()); + if( type == 0 ) return false; + + if( type->name != name ) return false; + + if( type->nameSpace != nameSpace ) return false; - if (type->nameSpace != nameSpace) return false; - return true; } // internal -asCScriptFunction* asCScriptFunction::FindNextFunctionCalled(asUINT startSearchFromProgramPos, int *outStackDelta, asUINT *outProgramPos) +asCScriptFunction *asCScriptFunction::FindNextFunctionCalled(asUINT startSearchFromProgramPos, int *outStackDelta, asUINT *outProgramPos) { - if (scriptData == 0) + if( scriptData == 0 ) return 0; - if (outProgramPos) + if( outProgramPos ) *outProgramPos = startSearchFromProgramPos; // Find out which function that will be called - asCScriptFunction* calledFunc = 0; - int stackDelta = 0; - for (asUINT n = startSearchFromProgramPos; n < scriptData->byteCode.GetLength(); ) + asCScriptFunction *calledFunc = 0; + int stackDelta = 0; + for( asUINT n = startSearchFromProgramPos; n < scriptData->byteCode.GetLength(); ) { - asBYTE bc = *(asBYTE*)&scriptData->byteCode[n]; - if (bc == asBC_CALL || - bc == asBC_CALLSYS || - bc == asBC_Thiscall1 || - bc == asBC_CALLINTF || - bc == asBC_ALLOC || - bc == asBC_CALLBND || - bc == asBC_CallPtr) + asBYTE bc = *(asBYTE *)&scriptData->byteCode[n]; + if( bc == asBC_CALL || + bc == asBC_CALLSYS || + bc == asBC_Thiscall1 || + bc == asBC_CALLINTF || + bc == asBC_ALLOC || + bc == asBC_CALLBND || + bc == asBC_CallPtr ) { calledFunc = GetCalledFunction(n); - if (outProgramPos) + if( outProgramPos ) *outProgramPos = n + asBCTypeSize[asBCInfo[bc].type]; break; @@ -1931,62 +1950,62 @@ asCScriptFunction* asCScriptFunction::FindNextFunctionCalled(asUINT startSearchF n += asBCTypeSize[asBCInfo[bc].type]; } - if (outStackDelta) + if( outStackDelta ) *outStackDelta = stackDelta; return calledFunc; } // internal -asCScriptFunction* asCScriptFunction::GetCalledFunction(asDWORD programPos) +asCScriptFunction *asCScriptFunction::GetCalledFunction(asDWORD programPos) { - if (scriptData == 0) + if( scriptData == 0 ) return 0; - asBYTE bc = *(asBYTE*)&scriptData->byteCode[programPos]; + asBYTE bc = *(asBYTE *)&scriptData->byteCode[programPos]; - if (bc == asBC_CALL || - bc == asBC_CALLSYS || - bc == asBC_Thiscall1 || - bc == asBC_CALLINTF) + if( bc == asBC_CALL || + bc == asBC_CALLSYS || + bc == asBC_Thiscall1 || + bc == asBC_CALLINTF ) { // Find the function from the function id in bytecode int funcId = asBC_INTARG(&scriptData->byteCode[programPos]); return engine->scriptFunctions[funcId]; } - else if (bc == asBC_ALLOC) + else if( bc == asBC_ALLOC ) { // Find the function from the function id in the bytecode int funcId = asBC_INTARG(&scriptData->byteCode[programPos + AS_PTR_SIZE]); return engine->scriptFunctions[funcId]; } - else if (bc == asBC_CALLBND) + else if( bc == asBC_CALLBND ) { // Find the function from the engine's bind array int funcId = asBC_INTARG(&scriptData->byteCode[programPos]); return engine->importedFunctions[funcId & ~FUNC_IMPORTED]->importedFunctionSignature; } - else if (bc == asBC_CallPtr) + else if( bc == asBC_CallPtr ) { asUINT v; - int var = asBC_SWORDARG1(&scriptData->byteCode[programPos]); + int var = asBC_SWORDARG1(&scriptData->byteCode[programPos]); // Find the funcdef from the local variable - for (v = 0; v < scriptData->variables.GetLength(); v++) - if (scriptData->variables[v]->stackOffset == var) + for( v = 0; v < scriptData->variables.GetLength(); v++ ) + if( scriptData->variables[v]->stackOffset == var ) return CastToFuncdefType(scriptData->variables[v]->type.GetTypeInfo())->funcdef; // Look in parameters int paramPos = 0; - if (objectType) + if( objectType ) paramPos -= AS_PTR_SIZE; - if (DoesReturnOnStack()) + if( DoesReturnOnStack() ) paramPos -= AS_PTR_SIZE; - for (v = 0; v < parameterTypes.GetLength(); v++) + for( v = 0; v < parameterTypes.GetLength(); v++ ) { - if (var == paramPos) + if( var == paramPos ) { - if (parameterTypes[v].IsFuncdef()) + if( parameterTypes[v].IsFuncdef() ) return CastToFuncdefType(parameterTypes[v].GetTypeInfo())->funcdef; else return 0; @@ -2008,23 +2027,22 @@ asUINT asCScriptFunction::GetSubTypeCount() const int asCScriptFunction::GetSubTypeId(asUINT subtypeIndex) const { // This method is only supported for templates and template specializations - if (templateSubTypes.GetLength() == 0) + if( templateSubTypes.GetLength() == 0 ) return asERROR; - if (subtypeIndex >= templateSubTypes.GetLength()) + if( subtypeIndex >= templateSubTypes.GetLength() ) return asINVALID_ARG; return engine->GetTypeIdFromDataType(templateSubTypes[subtypeIndex]); } // interface -asITypeInfo* asCScriptFunction::GetSubType(asUINT subtypeIndex) const +asITypeInfo *asCScriptFunction::GetSubType(asUINT subtypeIndex) const { - if (subtypeIndex >= templateSubTypes.GetLength()) + if( subtypeIndex >= templateSubTypes.GetLength() ) return 0; return templateSubTypes[subtypeIndex].GetTypeInfo(); } END_AS_NAMESPACE - diff --git a/sdk/angelscript/source/as_scriptfunction.h b/sdk/angelscript/source/as_scriptfunction.h index 01045a35..1d1bb377 100644 --- a/sdk/angelscript/source/as_scriptfunction.h +++ b/sdk/angelscript/source/as_scriptfunction.h @@ -58,7 +58,9 @@ struct asSNameSpace; struct asSScriptVariable { - asSScriptVariable() : type(), stackOffset(0), onHeap(false), declaredAtProgramPos(0) {} + asSScriptVariable() : type(), stackOffset(0), onHeap(false), declaredAtProgramPos(0) + { + } asCString name; asCDataType type; int stackOffset; @@ -66,8 +68,7 @@ struct asSScriptVariable asUINT declaredAtProgramPos : 31; }; -enum asEListPatternNodeType -{ +enum asEListPatternNodeType { asLPT_REPEAT, asLPT_REPEAT_SAME, asLPT_START, @@ -77,51 +78,69 @@ enum asEListPatternNodeType struct asSListPatternNode { - asSListPatternNode(asEListPatternNodeType t) : type(t), next(0) {} + asSListPatternNode(asEListPatternNodeType t) : type(t), next(0) + { + } virtual ~asSListPatternNode() {}; - virtual asSListPatternNode *Duplicate() { return asNEW(asSListPatternNode)(type); } - asEListPatternNodeType type; - asSListPatternNode *next; + virtual asSListPatternNode *Duplicate() + { + return asNEW(asSListPatternNode)(type); + } + asEListPatternNodeType type; + asSListPatternNode *next; }; struct asSListPatternDataTypeNode : public asSListPatternNode { - asSListPatternDataTypeNode(const asCDataType &dt) : asSListPatternNode(asLPT_TYPE), dataType(dt) {} - asSListPatternNode *Duplicate() { return asNEW(asSListPatternDataTypeNode)(dataType); } + asSListPatternDataTypeNode(const asCDataType &dt) : asSListPatternNode(asLPT_TYPE), dataType(dt) + { + } + asSListPatternNode *Duplicate() + { + return asNEW(asSListPatternDataTypeNode)(dataType); + } asCDataType dataType; }; -enum asEObjVarInfoOption -{ - asOBJ_UNINIT, // object is uninitialized/destroyed - asOBJ_INIT, // object is initialized - asBLOCK_BEGIN, // scope block begins - asBLOCK_END, // scope block ends - asOBJ_VARDECL // object variable is declared (but not necessarily initialized) +enum asEObjVarInfoOption { + asOBJ_UNINIT, // object is uninitialized/destroyed + asOBJ_INIT, // object is initialized + asBLOCK_BEGIN, // scope block begins + asBLOCK_END, // scope block ends + asOBJ_VARDECL // object variable is declared (but not necessarily initialized) }; -enum asEFuncTrait -{ - asTRAIT_CONSTRUCTOR = 1<<0, // method - asTRAIT_DESTRUCTOR = 1<<1, // method - asTRAIT_CONST = 1<<2, // method - asTRAIT_PRIVATE = 1<<3, // method - asTRAIT_PROTECTED = 1<<4, // method - asTRAIT_FINAL = 1<<5, // method - asTRAIT_OVERRIDE = 1<<6, // method - asTRAIT_SHARED = 1<<7, // function - asTRAIT_EXTERNAL = 1<<8, // function - asTRAIT_EXPLICIT = 1<<9, // method - asTRAIT_PROPERTY = 1<<10, // method/function - asTRAIT_DELETED = 1<<11, // method - asTRAIT_VARIADIC = 1<<12 // method/function +enum asEFuncTrait { + asTRAIT_CONSTRUCTOR = 1 << 0, // method + asTRAIT_DESTRUCTOR = 1 << 1, // method + asTRAIT_CONST = 1 << 2, // method + asTRAIT_PRIVATE = 1 << 3, // method + asTRAIT_PROTECTED = 1 << 4, // method + asTRAIT_FINAL = 1 << 5, // method + asTRAIT_OVERRIDE = 1 << 6, // method + asTRAIT_SHARED = 1 << 7, // function + asTRAIT_EXTERNAL = 1 << 8, // function + asTRAIT_EXPLICIT = 1 << 9, // method + asTRAIT_PROPERTY = 1 << 10, // method/function + asTRAIT_DELETED = 1 << 11, // method + asTRAIT_VARIADIC = 1 << 12 // method/function }; struct asSFunctionTraits { - asSFunctionTraits() : traits(0) {} - void SetTrait(asEFuncTrait trait, bool set) { if (set) traits |= trait; else traits &= ~trait; } - bool GetTrait(asEFuncTrait trait) const { return (traits & trait) ? true : false; } + asSFunctionTraits() : traits(0) + { + } + void SetTrait(asEFuncTrait trait, bool set) + { + if( set ) traits |= trait; + else traits &= ~trait; + } + bool GetTrait(asEFuncTrait trait) const + { + return (traits & trait) ? true : false; + } + protected: asDWORD traits; }; @@ -152,92 +171,119 @@ class asCScriptFunction : public asIScriptFunction { public: // From asIScriptFunction - asIScriptEngine *GetEngine() const; + asIScriptEngine *GetEngine() const; // Memory management int AddRef() const; int Release() const; // Miscellaneous - int GetId() const; - asEFuncType GetFuncType() const; - const char *GetModuleName() const; - asIScriptModule *GetModule() const; + int GetId() const; + asEFuncType GetFuncType() const; + const char *GetModuleName() const; + asIScriptModule *GetModule() const; #ifdef AS_DEPRECATED // deprecated since 2025-04-25, 2.38.0 - const char *GetScriptSectionName() const; + const char *GetScriptSectionName() const; #endif - const char *GetConfigGroup() const; - asDWORD GetAccessMask() const; - void *GetAuxiliary() const; + const char *GetConfigGroup() const; + asDWORD GetAccessMask() const; + void *GetAuxiliary() const; // Function signature - asITypeInfo *GetObjectType() const; - const char *GetObjectName() const; - const char *GetName() const; - const char *GetNamespace() const; - const char *GetDeclaration(bool includeObjectName = true, bool includeNamespace = false, bool includeParamNames = false) const; - bool IsReadOnly() const; - bool IsPrivate() const; - bool IsProtected() const; - bool IsFinal() const; - bool IsOverride() const; - bool IsShared() const; - bool IsExplicit() const; - bool IsProperty() const; - bool IsVariadic() const; - asUINT GetParamCount() const; - int GetParam(asUINT index, int *typeId, asDWORD *flags = 0, const char **name = 0, const char **defaultArg = 0) const; - int GetReturnTypeId(asDWORD *flags = 0) const; + asITypeInfo *GetObjectType() const; + const char *GetObjectName() const; + const char *GetName() const; + const char *GetNamespace() const; + const char *GetDeclaration(bool includeObjectName = true, bool includeNamespace = false, bool includeParamNames = false) const; + bool IsReadOnly() const; + bool IsPrivate() const; + bool IsProtected() const; + bool IsFinal() const; + bool IsOverride() const; + bool IsShared() const; + bool IsExplicit() const; + bool IsProperty() const; + bool IsVariadic() const; + asUINT GetParamCount() const; + int GetParam(asUINT index, int *typeId, asDWORD *flags = 0, const char **name = 0, const char **defaultArg = 0) const; + int GetReturnTypeId(asDWORD *flags = 0) const; // Template functions asUINT GetSubTypeCount() const; int GetSubTypeId(asUINT subTypeIndex = 0) const; - asITypeInfo* GetSubType(asUINT subTypeIndex = 0) const; + asITypeInfo *GetSubType(asUINT subTypeIndex = 0) const; // Type id for function pointers - int GetTypeId() const; - bool IsCompatibleWithTypeId(int typeId) const; + int GetTypeId() const; + bool IsCompatibleWithTypeId(int typeId) const; // Delegates - void *GetDelegateObject() const; - asITypeInfo *GetDelegateObjectType() const; - asIScriptFunction *GetDelegateFunction() const; + void *GetDelegateObject() const; + asITypeInfo *GetDelegateObjectType() const; + asIScriptFunction *GetDelegateFunction() const; // Debug information - asUINT GetVarCount() const; - int GetVar(asUINT index, const char **name, int *typeId = 0) const; - const char * GetVarDecl(asUINT index, bool includeNamespace = false) const; + asUINT GetVarCount() const; + int GetVar(asUINT index, const char **name, int *typeId = 0) const; + const char *GetVarDecl(asUINT index, bool includeNamespace = false) const; #ifdef AS_DEPRECATED // deprecated since 2025-11-14, 2.39.0 - int FindNextLineWithCode(int line) const; + int FindNextLineWithCode(int line) const; #endif - int GetDeclaredAt(const char** scriptSection, int* row, int* col) const; - int GetLineEntryCount() const; - int GetLineEntry(asUINT index, int* row, int* col, const char** sectionName, const asDWORD** byteCode) const; + int GetDeclaredAt(const char **scriptSection, int *row, int *col) const; + int GetLineEntryCount() const; + int GetLineEntry(asUINT index, int *row, int *col, const char **sectionName, const asDWORD **byteCode) const; // For JIT compilation - asDWORD * GetByteCode(asUINT *length = 0); - int SetJITFunction(asJITFunction jitFunc); - asJITFunction GetJITFunction() const; + asDWORD *GetByteCode(asUINT *length = 0); + int SetJITFunction(asJITFunction jitFunc); + asJITFunction GetJITFunction() const; // User data - void *SetUserData(void *userData, asPWORD type); - void *GetUserData(asPWORD type) const; + void *SetUserData(void *userData, asPWORD type); + void *GetUserData(asPWORD type) const; public: //----------------------------------- // Internal methods - void SetShared(bool set) { traits.SetTrait(asTRAIT_SHARED, set); } - void SetReadOnly(bool set) { traits.SetTrait(asTRAIT_CONST, set); } - void SetFinal(bool set) { traits.SetTrait(asTRAIT_FINAL, set); } - void SetOverride(bool set) { traits.SetTrait(asTRAIT_OVERRIDE, set); } - void SetExplicit(bool set) { traits.SetTrait(asTRAIT_EXPLICIT, set); } - void SetProtected(bool set) { traits.SetTrait(asTRAIT_PROTECTED, set); } - void SetPrivate(bool set) { traits.SetTrait(asTRAIT_PRIVATE, set); } - void SetProperty(bool set) { traits.SetTrait(asTRAIT_PROPERTY, set); } - void SetVariadic(bool set) { traits.SetTrait(asTRAIT_VARIADIC, set); } + void SetShared(bool set) + { + traits.SetTrait(asTRAIT_SHARED, set); + } + void SetReadOnly(bool set) + { + traits.SetTrait(asTRAIT_CONST, set); + } + void SetFinal(bool set) + { + traits.SetTrait(asTRAIT_FINAL, set); + } + void SetOverride(bool set) + { + traits.SetTrait(asTRAIT_OVERRIDE, set); + } + void SetExplicit(bool set) + { + traits.SetTrait(asTRAIT_EXPLICIT, set); + } + void SetProtected(bool set) + { + traits.SetTrait(asTRAIT_PROTECTED, set); + } + void SetPrivate(bool set) + { + traits.SetTrait(asTRAIT_PRIVATE, set); + } + void SetProperty(bool set) + { + traits.SetTrait(asTRAIT_PROPERTY, set); + } + void SetVariadic(bool set) + { + traits.SetTrait(asTRAIT_VARIADIC, set); + } bool IsFactory() const; asCScriptFunction(asCScriptEngine *engine, asCModule *mod, asEFuncType funcType); @@ -248,7 +294,7 @@ class asCScriptFunction : public asIScriptFunction int AddRefInternal(); int ReleaseInternal(); - void DestroyHalfCreated(); + void DestroyHalfCreated(); // TODO: operator== // TODO: The asIScriptFunction should provide operator== and operator!= that should do a @@ -258,9 +304,9 @@ class asCScriptFunction : public asIScriptFunction // Perhaps reusing 'auto' to mean the same type as the object //bool operator==(const asCScriptFunction &other) const; - void DestroyInternal(); + void DestroyInternal(); - void AddVariable(const asCString &name, const asCDataType &type, int stackOffset, bool onHeap); + void AddVariable(const asCString &name, const asCDataType &type, int stackOffset, bool onHeap); int GetSpaceNeededForArguments(); int GetSpaceNeededForReturnValue(); @@ -276,23 +322,23 @@ class asCScriptFunction : public asIScriptFunction asCTypeInfo *GetTypeInfoOfLocalVar(short varOffset); - void MakeDelegate(asCScriptFunction *func, void *obj); + void MakeDelegate(asCScriptFunction *func, void *obj); - int RegisterListPattern(const char *decl, asCScriptNode *listPattern); - int ParseListPattern(asSListPatternNode *&target, const char *decl, asCScriptNode *listPattern); + int RegisterListPattern(const char *decl, asCScriptNode *listPattern); + int ParseListPattern(asSListPatternNode *&target, const char *decl, asCScriptNode *listPattern); - bool DoesReturnOnStack() const; + bool DoesReturnOnStack() const; - void JITCompile(); + void JITCompile(); - void AddReferences(); - void ReleaseReferences(); + void AddReferences(); + void ReleaseReferences(); - void AllocateScriptFunctionData(); - void DeallocateScriptFunctionData(); + void AllocateScriptFunctionData(); + void DeallocateScriptFunctionData(); - asCScriptFunction* FindNextFunctionCalled(asUINT startSearchFromProgramPos, int *stackDelta, asUINT *outProgramPos); - asCScriptFunction* GetCalledFunction(asDWORD programPos); + asCScriptFunction *FindNextFunctionCalled(asUINT startSearchFromProgramPos, int *stackDelta, asUINT *outProgramPos); + asCScriptFunction *GetCalledFunction(asDWORD programPos); asCGlobalProperty *GetPropertyByGlobalVarPtr(void *gvarPtr); @@ -305,43 +351,43 @@ class asCScriptFunction : public asIScriptFunction // Don't allow the script function to be copied private: - asCScriptFunction(const asCScriptFunction&); + asCScriptFunction(const asCScriptFunction &); public: //----------------------------------- // Properties - mutable asCAtomic externalRefCount; // Used for external referneces - asCAtomic internalRefCount; // Used for internal references - mutable bool gcFlag; - asCScriptEngine *engine; - asCModule *module; + mutable asCAtomic externalRefCount; // Used for external referneces + asCAtomic internalRefCount; // Used for internal references + mutable bool gcFlag; + asCScriptEngine *engine; + asCModule *module; - asCArray userData; + asCArray userData; // Function signature - asCString name; - asCDataType returnType; - asCArray parameterTypes; - asCArray templateSubTypes; // Increase ref of template subtypes - asCArray parameterNames; - asCArray inOutFlags; - asCArray defaultArgs; - asSFunctionTraits traits; - asCObjectType *objectType; - int signatureId; - - int id; - - asEFuncType funcType; - asDWORD accessMask; + asCString name; + asCDataType returnType; + asCArray parameterTypes; + asCArray templateSubTypes; // Increase ref of template subtypes + asCArray parameterNames; + asCArray inOutFlags; + asCArray defaultArgs; + asSFunctionTraits traits; + asCObjectType *objectType; + int signatureId; + + int id; + + asEFuncType funcType; + asDWORD accessMask; // Namespace will be null for funcdefs that are declared as child funcdefs // of a class. In this case the namespace shall be taken from the parentClass // in the funcdefType - asSNameSpace *nameSpace; + asSNameSpace *nameSpace; - asCFuncdefType *funcdefType; // Doesn't increase refCount + asCFuncdefType *funcdefType; // Doesn't increase refCount // Used by asFUNC_DELEGATE void *objForDelegate; @@ -354,46 +400,46 @@ class asCScriptFunction : public asIScriptFunction struct ScriptFunctionData { // Bytecode for the script function - asCArray byteCode; + asCArray byteCode; // The stack space needed for the local variables - asDWORD variableSpace; + asDWORD variableSpace; // Holds information on scope for object variables on the stack asCArray objVariableInfo; // Holds information on try/catch blocks for exception handling - asCArray tryCatchInfo; + asCArray tryCatchInfo; // The stack needed to execute the function - int stackNeeded; + int stackNeeded; // JIT compiled code of this function - asJITFunction jitFunction; + asJITFunction jitFunction; // Holds type information on both explicitly declared variables and temporary variables // Used during exception handling, byte code serialization, debugging, and context serialization - asCArray variables; + asCArray variables; // Store position, line number pairs for debug information - asCArray lineNumbers; + asCArray lineNumbers; // Store the script section where the code was declared - int scriptSectionIdx; + int scriptSectionIdx; // Store the location where the function was declared (row in the lower 20 bits, and column in the upper 12) - int declaredAt; + int declaredAt; // Store position/index pairs if the bytecode is compiled from multiple script sections - asCArray sectionIdxs; + asCArray sectionIdxs; }; - ScriptFunctionData *scriptData; + ScriptFunctionData *scriptData; // Stub functions and delegates don't own the object and parameters - bool dontCleanUpOnException; + bool dontCleanUpOnException; // Used by asFUNC_VIRTUAL - int vfTableIdx; + int vfTableIdx; // Used by asFUNC_SYSTEM - asSSystemFunctionInterface *sysFuncIntf; + asSSystemFunctionInterface *sysFuncIntf; }; const char * const DELEGATE_FACTORY = "$dlgte"; diff --git a/sdk/angelscript/source/as_scriptnode.cpp b/sdk/angelscript/source/as_scriptnode.cpp index 9bd9cfd2..b57e15d6 100644 --- a/sdk/angelscript/source/as_scriptnode.cpp +++ b/sdk/angelscript/source/as_scriptnode.cpp @@ -49,11 +49,11 @@ asCScriptNode::asCScriptNode(eScriptNode type) tokenPos = 0; tokenLength = 0; - parent = 0; - next = 0; - prev = 0; - firstChild = 0; - lastChild = 0; + parent = 0; + next = 0; + prev = 0; + firstChild = 0; + lastChild = 0; } void asCScriptNode::Destroy(asCScriptEngine *engine) @@ -82,12 +82,12 @@ asCScriptNode *asCScriptNode::CreateCopy(asCScriptEngine *engine) return 0; } - new(ptr) asCScriptNode(nodeType); - - asCScriptNode *node = reinterpret_cast(ptr); - node->tokenLength = tokenLength; - node->tokenPos = tokenPos; - node->tokenType = tokenType; + new (ptr) asCScriptNode(nodeType); + + asCScriptNode *node = reinterpret_cast(ptr); + node->tokenLength = tokenLength; + node->tokenPos = tokenPos; + node->tokenType = tokenType; asCScriptNode *child = firstChild; while( child ) @@ -101,7 +101,7 @@ asCScriptNode *asCScriptNode::CreateCopy(asCScriptEngine *engine) void asCScriptNode::SetToken(sToken *token) { - tokenType = token->type; + tokenType = token->type; } void asCScriptNode::UpdateSourcePos(size_t pos, size_t length) @@ -110,7 +110,7 @@ void asCScriptNode::UpdateSourcePos(size_t pos, size_t length) if( tokenPos == 0 && tokenLength == 0 ) { - tokenPos = pos; + tokenPos = pos; tokenLength = length; } else @@ -118,7 +118,7 @@ void asCScriptNode::UpdateSourcePos(size_t pos, size_t length) if( tokenPos > pos ) { tokenLength = tokenPos + tokenLength - pos; - tokenPos = pos; + tokenPos = pos; } if( pos + length > tokenPos + tokenLength ) @@ -170,9 +170,8 @@ void asCScriptNode::DisconnectParent() prev->next = next; parent = 0; - next = 0; - prev = 0; + next = 0; + prev = 0; } END_AS_NAMESPACE - diff --git a/sdk/angelscript/source/as_scriptnode.h b/sdk/angelscript/source/as_scriptnode.h index 1e4810dd..f85d8b72 100644 --- a/sdk/angelscript/source/as_scriptnode.h +++ b/sdk/angelscript/source/as_scriptnode.h @@ -44,8 +44,7 @@ BEGIN_AS_NAMESPACE -enum eScriptNode -{ +enum eScriptNode { snUndefined, snScript, snFunction, @@ -100,8 +99,8 @@ enum eScriptNode struct sToken { eTokenType type; - size_t pos; - size_t length; + size_t pos; + size_t length; }; class asCScriptEngine; @@ -111,7 +110,7 @@ class asCScriptNode public: asCScriptNode(eScriptNode nodeType); - void Destroy(asCScriptEngine *engine); + void Destroy(asCScriptEngine *engine); asCScriptNode *CreateCopy(asCScriptEngine *engine); void SetToken(sToken *token); @@ -121,9 +120,9 @@ class asCScriptNode void UpdateSourcePos(size_t pos, size_t length); eScriptNode nodeType; - eTokenType tokenType; - size_t tokenPos; - size_t tokenLength; + eTokenType tokenType; + size_t tokenPos; + size_t tokenLength; asCScriptNode *parent; asCScriptNode *next; @@ -133,7 +132,9 @@ class asCScriptNode protected: // Must call Destroy instead - ~asCScriptNode() {} + ~asCScriptNode() + { + } }; END_AS_NAMESPACE diff --git a/sdk/angelscript/source/as_scriptobject.cpp b/sdk/angelscript/source/as_scriptobject.cpp index da365dd3..49622843 100644 --- a/sdk/angelscript/source/as_scriptobject.cpp +++ b/sdk/angelscript/source/as_scriptobject.cpp @@ -40,22 +40,22 @@ BEGIN_AS_NAMESPACE // This helper function will call the default factory, that is a script function asIScriptObject *ScriptObjectFactory(const asCObjectType *objType, asCScriptEngine *engine) { - asIScriptContext *ctx = 0; - int r = 0; - bool isNested = false; + asIScriptContext *ctx = 0; + int r = 0; + bool isNested = false; // Use nested call in the context if there is an active context ctx = asGetActiveContext(); if( ctx ) { - // It may not always be possible to reuse the current context, + // It may not always be possible to reuse the current context, // in which case we'll have to create a new one any way. if( ctx->GetEngine() == objType->GetEngine() && ctx->PushState() == asSUCCESS ) isNested = true; else ctx = 0; } - + if( ctx == 0 ) { // Request a context from the engine @@ -77,11 +77,11 @@ asIScriptObject *ScriptObjectFactory(const asCObjectType *objType, asCScriptEngi return 0; } - for(;;) + for( ;; ) { r = ctx->Execute(); - // We can't allow this execution to be suspended + // We can't allow this execution to be suspended // so resume the execution immediately if( r != asEXECUTION_SUSPENDED ) break; @@ -108,7 +108,7 @@ asIScriptObject *ScriptObjectFactory(const asCObjectType *objType, asCScriptEngi return 0; } - asIScriptObject *ptr = (asIScriptObject*)ctx->GetReturnAddress(); + asIScriptObject *ptr = (asIScriptObject *)ctx->GetReturnAddress(); // Increase the reference, because the context will release its pointer ptr->AddRef(); @@ -125,27 +125,27 @@ asIScriptObject *ScriptObjectFactory(const asCObjectType *objType, asCScriptEngi // TODO: Clean up: This function is almost identical to ScriptObjectFactory. Should make better use of the identical code. asIScriptObject *ScriptObjectCopyFactory(const asCObjectType *objType, void *origObj, asCScriptEngine *engine) { - asIScriptContext *ctx = 0; - int r = 0; - bool isNested = false; + asIScriptContext *ctx = 0; + int r = 0; + bool isNested = false; // Use nested call in the context if there is an active context ctx = asGetActiveContext(); - if (ctx) + if( ctx ) { - // It may not always be possible to reuse the current context, + // It may not always be possible to reuse the current context, // in which case we'll have to create a new one any way. - if (ctx->GetEngine() == objType->GetEngine() && ctx->PushState() == asSUCCESS) + if( ctx->GetEngine() == objType->GetEngine() && ctx->PushState() == asSUCCESS ) isNested = true; else ctx = 0; } - if (ctx == 0) + if( ctx == 0 ) { // Request a context from the engine ctx = engine->RequestContext(); - if (ctx == 0) + if( ctx == 0 ) { // TODO: How to best report this failure? return 0; @@ -153,9 +153,9 @@ asIScriptObject *ScriptObjectCopyFactory(const asCObjectType *objType, void *ori } r = ctx->Prepare(engine->scriptFunctions[objType->beh.copyfactory]); - if (r < 0) + if( r < 0 ) { - if (isNested) + if( isNested ) ctx->PopState(); else engine->ReturnContext(ctx); @@ -165,30 +165,30 @@ asIScriptObject *ScriptObjectCopyFactory(const asCObjectType *objType, void *ori // Let the context handle the case for argument by ref (&) or by handle (@) ctx->SetArgObject(0, origObj); - for (;;) + for( ;; ) { r = ctx->Execute(); - // We can't allow this execution to be suspended + // We can't allow this execution to be suspended // so resume the execution immediately - if (r != asEXECUTION_SUSPENDED) + if( r != asEXECUTION_SUSPENDED ) break; } - if (r != asEXECUTION_FINISHED) + if( r != asEXECUTION_FINISHED ) { - if (isNested) + if( isNested ) { ctx->PopState(); // If the execution was aborted or an exception occurred, // then we should forward that to the outer execution. - if (r == asEXECUTION_EXCEPTION) + if( r == asEXECUTION_EXCEPTION ) { // TODO: How to improve this exception ctx->SetException(TXT_EXCEPTION_IN_NESTED_CALL); } - else if (r == asEXECUTION_ABORTED) + else if( r == asEXECUTION_ABORTED ) ctx->Abort(); } else @@ -196,12 +196,12 @@ asIScriptObject *ScriptObjectCopyFactory(const asCObjectType *objType, void *ori return 0; } - asIScriptObject *ptr = (asIScriptObject*)ctx->GetReturnAddress(); + asIScriptObject *ptr = (asIScriptObject *)ctx->GetReturnAddress(); // Increase the reference, because the context will release its pointer ptr->AddRef(); - if (isNested) + if( isNested ) ctx->PopState(); else engine->ReturnContext(ctx); @@ -213,68 +213,68 @@ asIScriptObject *ScriptObjectCopyFactory(const asCObjectType *objType, void *ori static void ScriptObject_AddRef_Generic(asIScriptGeneric *gen) { - asCScriptObject *self = (asCScriptObject*)gen->GetObject(); + asCScriptObject *self = (asCScriptObject *)gen->GetObject(); self->AddRef(); } static void ScriptObject_Release_Generic(asIScriptGeneric *gen) { - asCScriptObject *self = (asCScriptObject*)gen->GetObject(); + asCScriptObject *self = (asCScriptObject *)gen->GetObject(); self->Release(); } static void ScriptObject_GetRefCount_Generic(asIScriptGeneric *gen) { - asCScriptObject *self = (asCScriptObject*)gen->GetObject(); - *(int*)gen->GetAddressOfReturnLocation() = self->GetRefCount(); + asCScriptObject *self = (asCScriptObject *)gen->GetObject(); + *(int *)gen->GetAddressOfReturnLocation() = self->GetRefCount(); } static void ScriptObject_SetFlag_Generic(asIScriptGeneric *gen) { - asCScriptObject *self = (asCScriptObject*)gen->GetObject(); + asCScriptObject *self = (asCScriptObject *)gen->GetObject(); self->SetFlag(); } static void ScriptObject_GetFlag_Generic(asIScriptGeneric *gen) { - asCScriptObject *self = (asCScriptObject*)gen->GetObject(); - *(bool*)gen->GetAddressOfReturnLocation() = self->GetFlag(); + asCScriptObject *self = (asCScriptObject *)gen->GetObject(); + *(bool *)gen->GetAddressOfReturnLocation() = self->GetFlag(); } static void ScriptObject_GetWeakRefFlag_Generic(asIScriptGeneric *gen) { - asCScriptObject *self = (asCScriptObject*)gen->GetObject(); - *(asILockableSharedBool**)gen->GetAddressOfReturnLocation() = self->GetWeakRefFlag(); + asCScriptObject *self = (asCScriptObject *)gen->GetObject(); + *(asILockableSharedBool **)gen->GetAddressOfReturnLocation() = self->GetWeakRefFlag(); } static void ScriptObject_EnumReferences_Generic(asIScriptGeneric *gen) { - asCScriptObject *self = (asCScriptObject*)gen->GetObject(); - asIScriptEngine *engine = *(asIScriptEngine**)gen->GetAddressOfArg(0); + asCScriptObject *self = (asCScriptObject *)gen->GetObject(); + asIScriptEngine *engine = *(asIScriptEngine **)gen->GetAddressOfArg(0); self->EnumReferences(engine); } static void ScriptObject_ReleaseAllHandles_Generic(asIScriptGeneric *gen) { - asCScriptObject *self = (asCScriptObject*)gen->GetObject(); - asIScriptEngine *engine = *(asIScriptEngine**)gen->GetAddressOfArg(0); + asCScriptObject *self = (asCScriptObject *)gen->GetObject(); + asIScriptEngine *engine = *(asIScriptEngine **)gen->GetAddressOfArg(0); self->ReleaseAllHandles(engine); } static void ScriptObject_Assignment_Generic(asIScriptGeneric *gen) { - asCScriptObject *other = *(asCScriptObject**)gen->GetAddressOfArg(0); - asCScriptObject *self = (asCScriptObject*)gen->GetObject(); + asCScriptObject *other = *(asCScriptObject **)gen->GetAddressOfArg(0); + asCScriptObject *self = (asCScriptObject *)gen->GetObject(); *self = *other; - *(asCScriptObject**)gen->GetAddressOfReturnLocation() = self; + *(asCScriptObject **)gen->GetAddressOfReturnLocation() = self; } static void ScriptObject_Construct_Generic(asIScriptGeneric *gen) { - asCObjectType *objType = *(asCObjectType**)gen->GetAddressOfArg(0); - asCScriptObject *self = (asCScriptObject*)gen->GetObject(); + asCObjectType *objType = *(asCObjectType **)gen->GetAddressOfArg(0); + asCScriptObject *self = (asCScriptObject *)gen->GetObject(); ScriptObject_Construct(objType, self); } @@ -287,49 +287,69 @@ void RegisterScriptObject(asCScriptEngine *engine) int r = 0; UNUSED_VAR(r); // It is only used in debug mode engine->scriptTypeBehaviours.engine = engine; - engine->scriptTypeBehaviours.flags = asOBJ_SCRIPT_OBJECT | asOBJ_REF | asOBJ_GC; - engine->scriptTypeBehaviours.name = "$obj"; + engine->scriptTypeBehaviours.flags = asOBJ_SCRIPT_OBJECT | asOBJ_REF | asOBJ_GC; + engine->scriptTypeBehaviours.name = "$obj"; #if !defined(AS_MAX_PORTABILITY) && !defined(AS_NO_CLASS_METHODS) - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_CONSTRUCT, "void f(int&in)", asFUNCTION(ScriptObject_Construct), asCALL_CDECL_OBJLAST, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_ADDREF, "void f()", asMETHOD(asCScriptObject,AddRef), asCALL_THISCALL, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_RELEASE, "void f()", asMETHOD(asCScriptObject,Release), asCALL_THISCALL, 0); asASSERT( r >= 0 ); - r = engine->RegisterMethodToObjectType(&engine->scriptTypeBehaviours, "int &opAssign(int &in)", asFUNCTION(ScriptObject_Assignment), asCALL_CDECL_OBJLAST); asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_CONSTRUCT, "void f(int&in)", asFUNCTION(ScriptObject_Construct), asCALL_CDECL_OBJLAST, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_ADDREF, "void f()", asMETHOD(asCScriptObject, AddRef), asCALL_THISCALL, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_RELEASE, "void f()", asMETHOD(asCScriptObject, Release), asCALL_THISCALL, 0); + asASSERT( r >= 0 ); + r = engine->RegisterMethodToObjectType(&engine->scriptTypeBehaviours, "int &opAssign(int &in)", asFUNCTION(ScriptObject_Assignment), asCALL_CDECL_OBJLAST); + asASSERT( r >= 0 ); // Weakref behaviours - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_GET_WEAKREF_FLAG, "int &f()", asMETHOD(asCScriptObject,GetWeakRefFlag), asCALL_THISCALL, 0); asASSERT( r >= 0 ); - + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_GET_WEAKREF_FLAG, "int &f()", asMETHOD(asCScriptObject, GetWeakRefFlag), asCALL_THISCALL, 0); + asASSERT( r >= 0 ); + // Register GC behaviours - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_GETREFCOUNT, "int f()", asMETHOD(asCScriptObject,GetRefCount), asCALL_THISCALL, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_SETGCFLAG, "void f()", asMETHOD(asCScriptObject,SetFlag), asCALL_THISCALL, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_GETGCFLAG, "bool f()", asMETHOD(asCScriptObject,GetFlag), asCALL_THISCALL, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_ENUMREFS, "void f(int&in)", asMETHOD(asCScriptObject,EnumReferences), asCALL_THISCALL, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_RELEASEREFS, "void f(int&in)", asMETHOD(asCScriptObject,ReleaseAllHandles), asCALL_THISCALL, 0); asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_GETREFCOUNT, "int f()", asMETHOD(asCScriptObject, GetRefCount), asCALL_THISCALL, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_SETGCFLAG, "void f()", asMETHOD(asCScriptObject, SetFlag), asCALL_THISCALL, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_GETGCFLAG, "bool f()", asMETHOD(asCScriptObject, GetFlag), asCALL_THISCALL, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_ENUMREFS, "void f(int&in)", asMETHOD(asCScriptObject, EnumReferences), asCALL_THISCALL, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_RELEASEREFS, "void f(int&in)", asMETHOD(asCScriptObject, ReleaseAllHandles), asCALL_THISCALL, 0); + asASSERT( r >= 0 ); #else - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_CONSTRUCT, "void f(int&in)", asFUNCTION(ScriptObject_Construct_Generic), asCALL_GENERIC, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_ADDREF, "void f()", asFUNCTION(ScriptObject_AddRef_Generic), asCALL_GENERIC, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_RELEASE, "void f()", asFUNCTION(ScriptObject_Release_Generic), asCALL_GENERIC, 0); asASSERT( r >= 0 ); - r = engine->RegisterMethodToObjectType(&engine->scriptTypeBehaviours, "int &opAssign(int &in)", asFUNCTION(ScriptObject_Assignment_Generic), asCALL_GENERIC); asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_CONSTRUCT, "void f(int&in)", asFUNCTION(ScriptObject_Construct_Generic), asCALL_GENERIC, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_ADDREF, "void f()", asFUNCTION(ScriptObject_AddRef_Generic), asCALL_GENERIC, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_RELEASE, "void f()", asFUNCTION(ScriptObject_Release_Generic), asCALL_GENERIC, 0); + asASSERT( r >= 0 ); + r = engine->RegisterMethodToObjectType(&engine->scriptTypeBehaviours, "int &opAssign(int &in)", asFUNCTION(ScriptObject_Assignment_Generic), asCALL_GENERIC); + asASSERT( r >= 0 ); // Weakref behaviours - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_GET_WEAKREF_FLAG, "int &f()", asFUNCTION(ScriptObject_GetWeakRefFlag_Generic), asCALL_GENERIC, 0); asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_GET_WEAKREF_FLAG, "int &f()", asFUNCTION(ScriptObject_GetWeakRefFlag_Generic), asCALL_GENERIC, 0); + asASSERT( r >= 0 ); // Register GC behaviours - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_GETREFCOUNT, "int f()", asFUNCTION(ScriptObject_GetRefCount_Generic), asCALL_GENERIC, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_SETGCFLAG, "void f()", asFUNCTION(ScriptObject_SetFlag_Generic), asCALL_GENERIC, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_GETGCFLAG, "bool f()", asFUNCTION(ScriptObject_GetFlag_Generic), asCALL_GENERIC, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_ENUMREFS, "void f(int&in)", asFUNCTION(ScriptObject_EnumReferences_Generic), asCALL_GENERIC, 0); asASSERT( r >= 0 ); - r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_RELEASEREFS, "void f(int&in)", asFUNCTION(ScriptObject_ReleaseAllHandles_Generic), asCALL_GENERIC, 0); asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_GETREFCOUNT, "int f()", asFUNCTION(ScriptObject_GetRefCount_Generic), asCALL_GENERIC, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_SETGCFLAG, "void f()", asFUNCTION(ScriptObject_SetFlag_Generic), asCALL_GENERIC, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_GETGCFLAG, "bool f()", asFUNCTION(ScriptObject_GetFlag_Generic), asCALL_GENERIC, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_ENUMREFS, "void f(int&in)", asFUNCTION(ScriptObject_EnumReferences_Generic), asCALL_GENERIC, 0); + asASSERT( r >= 0 ); + r = engine->RegisterBehaviourToObjectType(&engine->scriptTypeBehaviours, asBEHAVE_RELEASEREFS, "void f(int&in)", asFUNCTION(ScriptObject_ReleaseAllHandles_Generic), asCALL_GENERIC, 0); + asASSERT( r >= 0 ); #endif } void ScriptObject_Construct(asCObjectType *objType, asCScriptObject *self) { - new(self) asCScriptObject(objType); + new (self) asCScriptObject(objType); } void ScriptObject_ConstructUnitialized(asCObjectType *objType, asCScriptObject *self) { - new(self) asCScriptObject(objType, false); + new (self) asCScriptObject(objType, false); } asCScriptObject::asCScriptObject(asCObjectType *ot, bool doInitialize) @@ -337,8 +357,8 @@ asCScriptObject::asCScriptObject(asCObjectType *ot, bool doInitialize) refCount.set(1); objType = ot; objType->AddRef(); - isDestructCalled = false; - extra = 0; + isDestructCalled = false; + extra = 0; hasRefCountReachedZero = false; // Notify the garbage collector of this object @@ -347,7 +367,7 @@ asCScriptObject::asCScriptObject(asCObjectType *ot, bool doInitialize) // Initialize members to zero. Technically we only need to zero the pointer // members, but just the memset is faster than having to loop and check the datatypes - memset((void*)(this+1), 0, objType->size - sizeof(asCScriptObject)); + memset((void *)(this + 1), 0, objType->size - sizeof(asCScriptObject)); if( doInitialize ) { @@ -361,7 +381,7 @@ asCScriptObject::asCScriptObject(asCObjectType *ot, bool doInitialize) { if( prop->type.IsReference() || prop->type.GetTypeInfo()->flags & asOBJ_REF ) { - asPWORD *ptr = reinterpret_cast(reinterpret_cast(this) + prop->byteOffset); + asPWORD *ptr = reinterpret_cast(reinterpret_cast(this) + prop->byteOffset); if( prop->type.GetTypeInfo()->flags & asOBJ_SCRIPT_OBJECT ) *ptr = (asPWORD)ScriptObjectFactory(prop->type.GetTypeInfo(), ot->engine); else @@ -382,8 +402,8 @@ asCScriptObject::asCScriptObject(asCObjectType *ot, bool doInitialize) { if( prop->type.IsReference() || (prop->type.GetTypeInfo()->flags & asOBJ_REF) ) { - asPWORD *ptr = reinterpret_cast(reinterpret_cast(this) + prop->byteOffset); - *ptr = (asPWORD)AllocateUninitializedObject(CastToObjectType(prop->type.GetTypeInfo()), engine); + asPWORD *ptr = reinterpret_cast(reinterpret_cast(this) + prop->byteOffset); + *ptr = (asPWORD)AllocateUninitializedObject(CastToObjectType(prop->type.GetTypeInfo()), engine); } } } @@ -420,7 +440,7 @@ asCScriptObject::~asCScriptObject() // Clean the user data for( asUINT n = 0; n < extra->userData.GetLength(); n += 2 ) { - if( extra->userData[n+1] ) + if( extra->userData[n + 1] ) { for( asUINT c = 0; c < objType->engine->cleanScriptObjectFuncs.GetLength(); c++ ) if( objType->engine->cleanScriptObjectFuncs[c].type == extra->userData[n] ) @@ -433,18 +453,18 @@ asCScriptObject::~asCScriptObject() } // The engine pointer should be available from the objectType - asCScriptEngine* engine = objType->engine; + asCScriptEngine *engine = objType->engine; asASSERT(engine); // Destroy all properties - // In most cases the members are initialized in the order they have been declared, + // In most cases the members are initialized in the order they have been declared, // so it's safer to uninitialize them from last to first. The order may be different // depending on the use of inheritance and or initialization in the declaration. - // TODO: Should the order of initialization be stored by the compiler so that the + // TODO: Should the order of initialization be stored by the compiler so that the // reverse order can be guaranteed during the destruction? - if (engine) + if( engine ) { - for( int n = (int)objType->properties.GetLength()-1; n >= 0; n-- ) + for( int n = (int)objType->properties.GetLength() - 1; n >= 0; n-- ) { asCObjectProperty *prop = objType->properties[n]; if( prop->type.IsObject() ) @@ -453,11 +473,11 @@ asCScriptObject::~asCScriptObject() asCObjectType *propType = CastToObjectType(prop->type.GetTypeInfo()); if( prop->type.IsReference() || propType->flags & asOBJ_REF ) { - void **ptr = (void**)(((char*)this) + prop->byteOffset); + void **ptr = (void **)(((char *)this) + prop->byteOffset); if( *ptr ) { FreeObject(*ptr, propType, engine); - *(asDWORD*)ptr = 0; + *(asDWORD *)ptr = 0; } } else @@ -466,8 +486,8 @@ asCScriptObject::~asCScriptObject() // it is not a problem to call the destructor even if the object may never have // been initialized, e.g. if an exception interrupted the constructor. asASSERT( propType->flags & asOBJ_POD ); - - void *ptr = (void**)(((char*)this) + prop->byteOffset); + + void *ptr = (void **)(((char *)this) + prop->byteOffset); if( propType->beh.destruct ) engine->CallObjectMethod(ptr, propType->beh.destruct); } @@ -475,8 +495,8 @@ asCScriptObject::~asCScriptObject() else if( prop->type.IsFuncdef() ) { // Release the function descriptor - asCScriptFunction **ptr = (asCScriptFunction**)(((char*)this) + prop->byteOffset); - if (*ptr) + asCScriptFunction **ptr = (asCScriptFunction **)(((char *)this) + prop->byteOffset); + if( *ptr ) { (*ptr)->Release(); *ptr = 0; @@ -504,12 +524,12 @@ asILockableSharedBool *asCScriptObject::GetWeakRefFlag() const // Lock globally so no other thread can attempt // to create a shared bool at the same time. - // TODO: runtime optimize: Instead of locking globally, it would be possible to have - // a critical section per object type. This would reduce the + // TODO: runtime optimize: Instead of locking globally, it would be possible to have + // a critical section per object type. This would reduce the // chances of two threads lock on the same critical section. asAcquireExclusiveLock(); - // Make sure another thread didn't create the + // Make sure another thread didn't create the // flag while we waited for the lock if( !extra ) extra = asNEW(SExtra); @@ -535,7 +555,7 @@ void *asCScriptObject::GetUserData(asPWORD type) const { if( extra->userData[n] == type ) { - void *userData = reinterpret_cast(extra->userData[n+1]); + void *userData = reinterpret_cast(extra->userData[n + 1]); asReleaseSharedLock(); return userData; } @@ -550,12 +570,12 @@ void *asCScriptObject::SetUserData(void *data, asPWORD type) { // Lock globally so no other thread can attempt // to manipulate the extra data at the same time. - // TODO: runtime optimize: Instead of locking globally, it would be possible to have - // a critical section per object type. This would reduce the + // TODO: runtime optimize: Instead of locking globally, it would be possible to have + // a critical section per object type. This would reduce the // chances of two threads lock on the same critical section. asAcquireExclusiveLock(); - // Make sure another thread didn't create the + // Make sure another thread didn't create the // flag while we waited for the lock if( !extra ) extra = asNEW(SExtra); @@ -567,8 +587,8 @@ void *asCScriptObject::SetUserData(void *data, asPWORD type) { if( extra->userData[n] == type ) { - void *oldData = reinterpret_cast(extra->userData[n+1]); - extra->userData[n+1] = reinterpret_cast(data); + void *oldData = reinterpret_cast(extra->userData[n + 1]); + extra->userData[n + 1] = reinterpret_cast(data); asReleaseExclusiveLock(); @@ -618,13 +638,13 @@ int asCScriptObject::Release() const // If the weak ref flag exists it is because someone held a weak ref // and that someone may add a reference to the object at any time. It // is ok to check the existance of the weakRefFlag without locking here - // because if the refCount is 1 then no other thread is currently + // because if the refCount is 1 then no other thread is currently // creating the weakRefFlag. if( refCount.get() == 1 && extra && extra->weakRefFlag ) { // Set the flag to tell others that the object is no longer alive // We must do this before decreasing the refCount to 0 so we don't - // end up with a race condition between this thread attempting to + // end up with a race condition between this thread attempting to // destroy the object and the other that temporary added a strong // ref from the weak ref. extra->weakRefFlag->Set(true); @@ -634,7 +654,7 @@ int asCScriptObject::Release() const if( refCount.get() == 1 && !isDestructCalled ) { // This cast is OK since we are the last reference - const_cast(this)->CallDestructor(); + const_cast(this)->CallDestructor(); } // Now do the actual releasing @@ -651,7 +671,7 @@ int asCScriptObject::Release() const hasRefCountReachedZero = true; // This cast is OK since we are the last reference - const_cast(this)->Destruct(); + const_cast(this)->Destruct(); } return 0; } @@ -664,11 +684,11 @@ void asCScriptObject::CallDestructor() // Only allow the destructor to be called once if( isDestructCalled ) return; - asIScriptContext *ctx = 0; - bool isNested = false; - bool doAbort = false; + asIScriptContext *ctx = 0; + bool isNested = false; + bool doAbort = false; - // Make sure the destructor is called once only, even if the + // Make sure the destructor is called once only, even if the // reference count is increased and then decreased again isDestructCalled = true; @@ -709,7 +729,7 @@ void asCScriptObject::CallDestructor() { ctx->SetObject(this); - for(;;) + for( ;; ) { r = ctx->Execute(); @@ -807,10 +827,10 @@ void *asCScriptObject::GetAddressOfProperty(asUINT prop) // Objects are stored by reference, so this must be dereferenced asCDataType *dt = &objType->properties[prop]->type; if( dt->IsObject() && !dt->IsObjectHandle() && - (dt->IsReference() || dt->GetTypeInfo()->flags & asOBJ_REF) ) - return *(void**)(((char*)this) + objType->properties[prop]->byteOffset); + (dt->IsReference() || dt->GetTypeInfo()->flags & asOBJ_REF) ) + return *(void **)(((char *)this) + objType->properties[prop]->byteOffset); - return (void*)(((char*)this) + objType->properties[prop]->byteOffset); + return (void *)(((char *)this) + objType->properties[prop]->byteOffset); } void asCScriptObject::EnumReferences(asIScriptEngine *engine) @@ -819,26 +839,26 @@ void asCScriptObject::EnumReferences(asIScriptEngine *engine) for( asUINT n = 0; n < objType->properties.GetLength(); n++ ) { asCObjectProperty *prop = objType->properties[n]; - void *ptr = 0; - if (prop->type.IsObject()) + void *ptr = 0; + if( prop->type.IsObject() ) { - if (prop->type.IsReference() || (prop->type.GetTypeInfo()->flags & asOBJ_REF)) - ptr = *(void**)(((char*)this) + prop->byteOffset); + if( prop->type.IsReference() || (prop->type.GetTypeInfo()->flags & asOBJ_REF) ) + ptr = *(void **)(((char *)this) + prop->byteOffset); else - ptr = (void*)(((char*)this) + prop->byteOffset); + ptr = (void *)(((char *)this) + prop->byteOffset); // The members of the value type needs to be enumerated // too, since the value type may be holding a reference. - if ((prop->type.GetTypeInfo()->flags & asOBJ_VALUE) && (prop->type.GetTypeInfo()->flags & asOBJ_GC)) + if( (prop->type.GetTypeInfo()->flags & asOBJ_VALUE) && (prop->type.GetTypeInfo()->flags & asOBJ_GC) ) { - reinterpret_cast(engine)->CallObjectMethod(ptr, engine, CastToObjectType(prop->type.GetTypeInfo())->beh.gcEnumReferences); + reinterpret_cast(engine)->CallObjectMethod(ptr, engine, CastToObjectType(prop->type.GetTypeInfo())->beh.gcEnumReferences); } } - else if (prop->type.IsFuncdef()) - ptr = *(void**)(((char*)this) + prop->byteOffset); + else if( prop->type.IsFuncdef() ) + ptr = *(void **)(((char *)this) + prop->byteOffset); - if (ptr) - ((asCScriptEngine*)engine)->GCEnumCallback(ptr); + if( ptr ) + ((asCScriptEngine *)engine)->GCEnumCallback(ptr); } } @@ -848,37 +868,37 @@ void asCScriptObject::ReleaseAllHandles(asIScriptEngine *engine) { asCObjectProperty *prop = objType->properties[n]; - if (prop->type.IsObject()) + if( prop->type.IsObject() ) { - if (prop->type.IsObjectHandle()) + if( prop->type.IsObjectHandle() ) { - void **ptr = (void**)(((char*)this) + prop->byteOffset); - if (*ptr) + void **ptr = (void **)(((char *)this) + prop->byteOffset); + if( *ptr ) { asASSERT((prop->type.GetTypeInfo()->flags & asOBJ_NOCOUNT) || prop->type.GetBehaviour()->release); - if (prop->type.GetBehaviour()->release) - ((asCScriptEngine*)engine)->CallObjectMethod(*ptr, prop->type.GetBehaviour()->release); + if( prop->type.GetBehaviour()->release ) + ((asCScriptEngine *)engine)->CallObjectMethod(*ptr, prop->type.GetBehaviour()->release); *ptr = 0; } } - else if ((prop->type.GetTypeInfo()->flags & asOBJ_VALUE) && (prop->type.GetTypeInfo()->flags & asOBJ_GC)) + else if( (prop->type.GetTypeInfo()->flags & asOBJ_VALUE) && (prop->type.GetTypeInfo()->flags & asOBJ_GC) ) { // The members of the members needs to be released // too, since they may be holding a reference. Even // if the member is a value type. void *ptr = 0; - if (prop->type.IsReference()) - ptr = *(void**)(((char*)this) + prop->byteOffset); + if( prop->type.IsReference() ) + ptr = *(void **)(((char *)this) + prop->byteOffset); else - ptr = (void*)(((char*)this) + prop->byteOffset); + ptr = (void *)(((char *)this) + prop->byteOffset); - reinterpret_cast(engine)->CallObjectMethod(ptr, engine, CastToObjectType(prop->type.GetTypeInfo())->beh.gcReleaseAllReferences); + reinterpret_cast(engine)->CallObjectMethod(ptr, engine, CastToObjectType(prop->type.GetTypeInfo())->beh.gcReleaseAllReferences); } } - else if (prop->type.IsFuncdef()) + else if( prop->type.IsFuncdef() ) { - asCScriptFunction **ptr = (asCScriptFunction**)(((char*)this) + prop->byteOffset); - if (*ptr) + asCScriptFunction **ptr = (asCScriptFunction **)(((char *)this) + prop->byteOffset); + if( *ptr ) { (*ptr)->Release(); *ptr = 0; @@ -905,7 +925,7 @@ int asCScriptObject::CopyFromAs(const asCScriptObject *other, asCObjectType *in_ { if( !other->objType->DerivesFrom(in_objType) ) { - // We cannot allow a value assignment from a type that isn't the same or + // We cannot allow a value assignment from a type that isn't the same or // derives from this type as the member properties may not have the same layout asIScriptContext *ctx = asGetActiveContext(); ctx->SetException(TXT_MISMATCH_IN_VALUE_ASSIGN); @@ -913,24 +933,24 @@ int asCScriptObject::CopyFromAs(const asCScriptObject *other, asCObjectType *in_ } // If the script class implements the opAssign method, it should be called - asCScriptEngine *engine = in_objType->engine; - asCScriptFunction *func = engine->scriptFunctions[in_objType->beh.copy]; + asCScriptEngine *engine = in_objType->engine; + asCScriptFunction *func = engine->scriptFunctions[in_objType->beh.copy]; if( func->funcType == asFUNC_SYSTEM ) { // If derived, use the base class' assignment operator to copy the inherited // properties. Then only copy new properties for the derived class if( in_objType->derivedFrom ) CopyFromAs(other, in_objType->derivedFrom); - - for( asUINT n = in_objType->derivedFrom ? in_objType->derivedFrom->properties.GetLength() : 0; - n < in_objType->properties.GetLength(); - n++ ) + + for( asUINT n = in_objType->derivedFrom ? in_objType->derivedFrom->properties.GetLength() : 0; + n < in_objType->properties.GetLength(); + n++ ) { asCObjectProperty *prop = in_objType->properties[n]; if( prop->type.IsObject() ) { - void **dst = (void**)(((char*)this) + prop->byteOffset); - void **src = (void**)(const_cast((const char*)other) + prop->byteOffset); + void **dst = (void **)(((char *)this) + prop->byteOffset); + void **src = (void **)(const_cast((const char *)other) + prop->byteOffset); if( !prop->type.IsObjectHandle() ) { if( prop->type.IsReference() || (prop->type.GetTypeInfo()->flags & asOBJ_REF) ) @@ -939,22 +959,22 @@ int asCScriptObject::CopyFromAs(const asCScriptObject *other, asCObjectType *in_ CopyObject(src, dst, CastToObjectType(prop->type.GetTypeInfo()), engine); } else - CopyHandle((asPWORD*)src, (asPWORD*)dst, CastToObjectType(prop->type.GetTypeInfo()), engine); + CopyHandle((asPWORD *)src, (asPWORD *)dst, CastToObjectType(prop->type.GetTypeInfo()), engine); } - else if (prop->type.IsFuncdef()) + else if( prop->type.IsFuncdef() ) { - asCScriptFunction **dst = (asCScriptFunction**)(((char*)this) + prop->byteOffset); - asCScriptFunction **src = (asCScriptFunction**)(const_cast((const char*)other) + prop->byteOffset); - if (*dst) + asCScriptFunction **dst = (asCScriptFunction **)(((char *)this) + prop->byteOffset); + asCScriptFunction **src = (asCScriptFunction **)(const_cast((const char *)other) + prop->byteOffset); + if( *dst ) (*dst)->Release(); - *dst = *const_cast(src); - if (*dst) + *dst = *const_cast(src); + if( *dst ) (*dst)->AddRef(); } else { - void *dst = ((char*)this) + prop->byteOffset; - const void *src = ((const char*)other) + prop->byteOffset; + void *dst = ((char *)this) + prop->byteOffset; + const void *src = ((const char *)other) + prop->byteOffset; memcpy(dst, src, prop->type.GetSizeInMemoryBytes()); } } @@ -962,9 +982,9 @@ int asCScriptObject::CopyFromAs(const asCScriptObject *other, asCObjectType *in_ else { // Reuse the active context or create a new one to call the script class' opAssign method - asIScriptContext *ctx = 0; - int r = 0; - bool isNested = false; + asIScriptContext *ctx = 0; + int r = 0; + bool isNested = false; ctx = asGetActiveContext(); if( ctx ) @@ -993,16 +1013,16 @@ int asCScriptObject::CopyFromAs(const asCScriptObject *other, asCObjectType *in_ return r; } - r = ctx->SetArgAddress(0, const_cast(other)); + r = ctx->SetArgAddress(0, const_cast(other)); asASSERT( r >= 0 ); r = ctx->SetObject(this); asASSERT( r >= 0 ); - for(;;) + for( ;; ) { r = ctx->Execute(); - // We can't allow this execution to be suspended + // We can't allow this execution to be suspended // so resume the execution immediately if( r != asEXECUTION_SUSPENDED ) break; @@ -1052,7 +1072,7 @@ int asCScriptObject::CopyFrom(const asIScriptObject *other) if( GetTypeId() != other->GetTypeId() ) return asINVALID_TYPE; - *this = *(const asCScriptObject*)other; + *this = *(const asCScriptObject *)other; return asSUCCESS; } @@ -1064,7 +1084,7 @@ void *asCScriptObject::AllocateUninitializedObject(asCObjectType *in_objType, as if( in_objType->flags & asOBJ_SCRIPT_OBJECT ) { ptr = engine->CallAlloc(in_objType); - ScriptObject_ConstructUnitialized(in_objType, reinterpret_cast(ptr)); + ScriptObject_ConstructUnitialized(in_objType, reinterpret_cast(ptr)); } else if( in_objType->flags & asOBJ_TEMPLATE ) { @@ -1078,7 +1098,7 @@ void *asCScriptObject::AllocateUninitializedObject(asCObjectType *in_objType, as } else { - ptr = engine->CallAlloc(in_objType); + ptr = engine->CallAlloc(in_objType); int funcIndex = in_objType->beh.construct; if( funcIndex ) engine->CallObjectMethod(ptr, funcIndex); @@ -1092,7 +1112,7 @@ void asCScriptObject::FreeObject(void *ptr, asCObjectType *in_objType, asCScript if( in_objType->flags & asOBJ_REF ) { asASSERT( (in_objType->flags & asOBJ_NOCOUNT) || in_objType->beh.release ); - if(in_objType->beh.release ) + if( in_objType->beh.release ) engine->CallObjectMethod(ptr, in_objType->beh.release); } else @@ -1111,12 +1131,12 @@ void asCScriptObject::CopyObject(const void *src, void *dst, asCObjectType *in_o { asCScriptFunction *func = engine->scriptFunctions[in_objType->beh.copy]; if( func->funcType == asFUNC_SYSTEM ) - engine->CallObjectMethod(dst, const_cast(src), funcIndex); + engine->CallObjectMethod(dst, const_cast(src), funcIndex); else { // Call the script class' opAssign method asASSERT(in_objType->flags & asOBJ_SCRIPT_OBJECT ); - reinterpret_cast(dst)->CopyFrom(reinterpret_cast(src)); + reinterpret_cast(dst)->CopyFrom(reinterpret_cast(src)); } } else if( in_objType->size && (in_objType->flags & asOBJ_POD) ) @@ -1129,14 +1149,14 @@ void asCScriptObject::CopyHandle(asPWORD *src, asPWORD *dst, asCObjectType *in_o asASSERT( (in_objType->flags & asOBJ_NOCOUNT) || (in_objType->beh.release && in_objType->beh.addref) ); if( *dst && in_objType->beh.release ) - engine->CallObjectMethod(*(void**)dst, in_objType->beh.release); + engine->CallObjectMethod(*(void **)dst, in_objType->beh.release); *dst = *src; if( *dst && in_objType->beh.addref ) - engine->CallObjectMethod(*(void**)dst, in_objType->beh.addref); + engine->CallObjectMethod(*(void **)dst, in_objType->beh.addref); } // TODO: weak: Should move to its own file -asCLockableSharedBool::asCLockableSharedBool() : value(false) +asCLockableSharedBool::asCLockableSharedBool() : value(false) { refCount.set(1); } @@ -1150,7 +1170,7 @@ int asCLockableSharedBool::Release() const { int r = refCount.atomicDec(); if( r == 0 ) - asDELETE(const_cast(this), asCLockableSharedBool); + asDELETE(const_cast(this), asCLockableSharedBool); return r; } @@ -1161,7 +1181,7 @@ bool asCLockableSharedBool::Get() const void asCLockableSharedBool::Set(bool v) { - // Make sure the value is not changed while another thread + // Make sure the value is not changed while another thread // is inspecting it and taking a decision on what to do. Lock(); value = v; @@ -1179,7 +1199,7 @@ void asCLockableSharedBool::Unlock() const } // Interface -// Auxiliary function to allow applications to create shared +// Auxiliary function to allow applications to create shared // booleans without having to implement the logic for them AS_API asILockableSharedBool *asCreateLockableSharedBool() { @@ -1187,4 +1207,3 @@ AS_API asILockableSharedBool *asCreateLockableSharedBool() } END_AS_NAMESPACE - diff --git a/sdk/angelscript/source/as_scriptobject.h b/sdk/angelscript/source/as_scriptobject.h index 4cbdf5bc..70c52371 100644 --- a/sdk/angelscript/source/as_scriptobject.h +++ b/sdk/angelscript/source/as_scriptobject.h @@ -66,16 +66,16 @@ class asCLockableSharedBool : public asILockableSharedBool protected: mutable asCAtomic refCount; - bool value; + bool value; DECLARECRITICALSECTION(mutable lock) }; class asCScriptObject : public asIScriptObject { public: -//=================================== -// From asIScriptObject -//=================================== + //=================================== + // From asIScriptObject + //=================================== // Memory management int AddRef() const; @@ -83,8 +83,8 @@ class asCScriptObject : public asIScriptObject asILockableSharedBool *GetWeakRefFlag() const; // Type info - int GetTypeId() const; - asITypeInfo *GetObjectType() const; + int GetTypeId() const; + asITypeInfo *GetObjectType() const; // Class properties asUINT GetPropertyCount() const; @@ -100,9 +100,9 @@ class asCScriptObject : public asIScriptObject void *SetUserData(void *data, asPWORD type = 0); void *GetUserData(asPWORD type = 0) const; -//==================================== -// Internal -//==================================== + //==================================== + // Internal + //==================================== asCScriptObject(asCObjectType *objType, bool doInitialize = true); virtual ~asCScriptObject(); @@ -118,25 +118,25 @@ class asCScriptObject : public asIScriptObject // Used for properties void *AllocateUninitializedObject(asCObjectType *objType, asCScriptEngine *engine); - void FreeObject(void *ptr, asCObjectType *objType, asCScriptEngine *engine); - void CopyObject(const void *src, void *dst, asCObjectType *objType, asCScriptEngine *engine); - void CopyHandle(asPWORD *src, asPWORD *dst, asCObjectType *objType, asCScriptEngine *engine); - int CopyFromAs(const asCScriptObject *other, asCObjectType *objType); + void FreeObject(void *ptr, asCObjectType *objType, asCScriptEngine *engine); + void CopyObject(const void *src, void *dst, asCObjectType *objType, asCScriptEngine *engine); + void CopyHandle(asPWORD *src, asPWORD *dst, asCObjectType *objType, asCScriptEngine *engine); + int CopyFromAs(const asCScriptObject *other, asCObjectType *objType); void CallDestructor(); -//============================================= -// Properties -//============================================= + //============================================= + // Properties + //============================================= public: - // This is public to allow external code (e.g. JIT compiler) to do asOFFSET to + // This is public to allow external code (e.g. JIT compiler) to do asOFFSET to // access the members directly without having to modify the code to add friend - asCObjectType* objType; + asCObjectType *objType; protected: mutable asCAtomic refCount; - mutable asBYTE gcFlag:1; - mutable asBYTE hasRefCountReachedZero:1; + mutable asBYTE gcFlag : 1; + mutable asBYTE hasRefCountReachedZero : 1; bool isDestructCalled; // Most script classes instances won't have neither the weakRefFlags nor @@ -152,7 +152,7 @@ class asCScriptObject : public asIScriptObject mutable SExtra *extra; }; -void ScriptObject_Construct(asCObjectType *objType, asCScriptObject *self); +void ScriptObject_Construct(asCObjectType *objType, asCScriptObject *self); asCScriptObject &ScriptObject_Assignment(asCScriptObject *other, asCScriptObject *self); void ScriptObject_ConstructUnitialized(asCObjectType *objType, asCScriptObject *self); diff --git a/sdk/angelscript/source/as_string.cpp b/sdk/angelscript/source/as_string.cpp index 039077e6..2be2b82c 100644 --- a/sdk/angelscript/source/as_string.cpp +++ b/sdk/angelscript/source/as_string.cpp @@ -30,12 +30,12 @@ #include "as_config.h" -#include // va_list, va_start(), etc -#include // strtod(), strtol() -#include // some compilers declare memcpy() here +#include // va_list, va_start(), etc +#include // strtod(), strtol() +#include // some compilers declare memcpy() here #if !defined(AS_NO_MEMORY_H) -#include + #include #endif #include "as_string.h" @@ -43,14 +43,14 @@ asCString::asCString() { - length = 0; + length = 0; local[0] = 0; } // Copy constructor asCString::asCString(const asCString &str) { - length = 0; + length = 0; local[0] = 0; Assign(str.AddressOf(), str.length); @@ -68,17 +68,17 @@ asCString::asCString(asCString &&str) noexcept else { dynamic = str.dynamic; - length = str.length; + length = str.length; } str.dynamic = 0; - str.length = 0; + str.length = 0; } #endif // c++11 asCString::asCString(const char *str, size_t len) { - length = 0; + length = 0; local[0] = 0; Assign(str, len); @@ -86,7 +86,7 @@ asCString::asCString(const char *str, size_t len) asCString::asCString(const char *str) { - length = 0; + length = 0; local[0] = 0; size_t len = strlen(str); @@ -95,7 +95,7 @@ asCString::asCString(const char *str) asCString::asCString(char ch) { - length = 0; + length = 0; local[0] = 0; Assign(&ch, 1); @@ -134,7 +134,7 @@ void asCString::Allocate(size_t len, bool keepData) { // If we stored the capacity of the dynamically allocated buffer it would be possible // to save some memory allocations if a string decreases in size then increases again, - // but this would require extra bytes in the string object itself, or a decrease of + // but this would require extra bytes in the string object itself, or a decrease of // the static buffer, which in turn would mean extra memory is needed. I've tested each // of these options, and it turned out that the current choice is what best balanced // the number of allocations against the size of the allocations. @@ -142,7 +142,7 @@ void asCString::Allocate(size_t len, bool keepData) if( len > 11 && len > length ) { // Allocate a new dynamic buffer if the new one is larger than the old - char *buf = asNEWARRAY(char,len+1); + char *buf = asNEWARRAY(char, len + 1); if( buf == 0 ) { // Out of memory. Return without modifying anything @@ -188,7 +188,7 @@ void asCString::Assign(const char *str, size_t len) AddressOf()[length] = 0; } -asCString &asCString::operator =(const char *str) +asCString &asCString::operator=(const char *str) { size_t len = str ? strlen(str) : 0; Assign(str, len); @@ -196,7 +196,7 @@ asCString &asCString::operator =(const char *str) return *this; } -asCString &asCString::operator =(const asCString &str) +asCString &asCString::operator=(const asCString &str) { Assign(str.AddressOf(), str.length); @@ -204,7 +204,7 @@ asCString &asCString::operator =(const asCString &str) } #ifdef AS_CAN_USE_CPP11 -asCString &asCString::operator =(asCString &&str) noexcept +asCString &asCString::operator=(asCString &&str) noexcept { if( this != &str ) { @@ -213,7 +213,7 @@ asCString &asCString::operator =(asCString &&str) noexcept asDELETEARRAY(dynamic); } - if ( str.length <= 11 ) + if( str.length <= 11 ) { length = str.length; @@ -223,18 +223,18 @@ asCString &asCString::operator =(asCString &&str) noexcept else { dynamic = str.dynamic; - length = str.length; + length = str.length; } str.dynamic = 0; - str.length = 0; + str.length = 0; } return *this; } #endif // c++11 -asCString &asCString::operator =(char ch) +asCString &asCString::operator=(char ch) { Assign(&ch, 1); @@ -250,7 +250,7 @@ void asCString::Concatenate(const char *str, size_t len) AddressOf()[length] = 0; } -asCString &asCString::operator +=(const char *str) +asCString &asCString::operator+=(const char *str) { size_t len = strlen(str); Concatenate(str, len); @@ -258,14 +258,14 @@ asCString &asCString::operator +=(const char *str) return *this; } -asCString &asCString::operator +=(const asCString &str) +asCString &asCString::operator+=(const asCString &str) { Concatenate(str.AddressOf(), str.length); return *this; } -asCString &asCString::operator +=(char ch) +asCString &asCString::operator+=(char ch) { Concatenate(&ch, 1); @@ -284,8 +284,8 @@ size_t asCString::Format(const char *format, ...) va_start(args, format); const size_t startSize = 1024; - char tmp[startSize]; - int r = asVSNPRINTF(tmp, startSize-1, format, args); + char tmp[startSize]; + int r = asVSNPRINTF(tmp, startSize - 1, format, args); if( r > 0 && r < int(startSize) ) { @@ -296,7 +296,7 @@ size_t asCString::Format(const char *format, ...) // TODO: For some reason this doesn't work properly on Linux. Perhaps the // problem is related to vsnprintf not keeping the state of va_arg. // Perhaps I need to rewrite this in some way to keep the state - size_t n = startSize*2; + size_t n = startSize * 2; asCString str; // Use temporary string in case the current buffer is a parameter str.Allocate(n, false); @@ -314,14 +314,14 @@ size_t asCString::Format(const char *format, ...) return length; } -char &asCString::operator [](size_t index) +char &asCString::operator[](size_t index) { asASSERT(index < length); return AddressOf()[index]; } -const char &asCString::operator [](size_t index) const +const char &asCString::operator[](size_t index) const { asASSERT(index < length); @@ -365,7 +365,7 @@ size_t asCString::RecalculateLength() int asCString::FindLast(const char *str, int *count) const { - // There is no strstr that starts from the end, so + // There is no strstr that starts from the end, so // we'll iterate until we find the last occurrance. // This shouldn't cause a performance problem because // it is not expected that this will be done very often, @@ -374,8 +374,8 @@ int asCString::FindLast(const char *str, int *count) const if( count ) *count = 0; const char *last = 0; - const char *curr = AddressOf()-1; - while( (curr = strstr(curr+1, str)) != 0 ) + const char *curr = AddressOf() - 1; + while( (curr = strstr(curr + 1, str)) != 0 ) { if( count ) (*count)++; last = curr; @@ -390,61 +390,61 @@ int asCString::FindLast(const char *str, int *count) const //----------------------------------------------------------------------------- // Helper functions -bool operator ==(const asCString &a, const char *b) +bool operator==(const asCString &a, const char *b) { return a.Compare(b) == 0; } -bool operator !=(const asCString &a, const char *b) +bool operator!=(const asCString &a, const char *b) { return a.Compare(b) != 0; } -bool operator ==(const asCString &a, const asCString &b) +bool operator==(const asCString &a, const asCString &b) { return a.Compare(b) == 0; } -bool operator !=(const asCString &a, const asCString &b) +bool operator!=(const asCString &a, const asCString &b) { return a.Compare(b) != 0; } -bool operator ==(const char *a, const asCString &b) +bool operator==(const char *a, const asCString &b) { return b.Compare(a) == 0; } -bool operator !=(const char *a, const asCString &b) +bool operator!=(const char *a, const asCString &b) { return b.Compare(a) != 0; } -bool operator <(const asCString &a, const asCString &b) +bool operator<(const asCString &a, const asCString &b) { return a.Compare(b) < 0; } -asCString operator +(const asCString &a, const asCString &b) +asCString operator+(const asCString &a, const asCString &b) { - asCString res = a; - res += b; + asCString res = a; + res += b; return res; } -asCString operator +(const char *a, const asCString &b) +asCString operator+(const char *a, const asCString &b) { - asCString res = a; - res += b; + asCString res = a; + res += b; return res; } -asCString operator +(const asCString &a, const char *b) +asCString operator+(const asCString &a, const char *b) { - asCString res = a; - res += b; + asCString res = a; + res += b; return res; } @@ -452,17 +452,17 @@ asCString operator +(const asCString &a, const char *b) // wrapper class asCStringPointer::asCStringPointer() - : string(0), length(0), cstring(0) + : string(0), length(0), cstring(0) { } asCStringPointer::asCStringPointer(const char *str, size_t len) - : string(str), length(len), cstring(0) + : string(str), length(len), cstring(0) { } asCStringPointer::asCStringPointer(asCString *cstr) - : string(0), length(0), cstring(cstr) + : string(0), length(0), cstring(cstr) { } @@ -476,12 +476,12 @@ size_t asCStringPointer::GetLength() const return string ? length : cstring->GetLength(); } -bool asCStringPointer::operator==(const asCStringPointer& other) const +bool asCStringPointer::operator==(const asCStringPointer &other) const { return asCompareStrings(AddressOf(), GetLength(), other.AddressOf(), other.GetLength()) == 0; } -bool asCStringPointer::operator<(const asCStringPointer& other) const +bool asCStringPointer::operator<(const asCStringPointer &other) const { return asCompareStrings(AddressOf(), GetLength(), other.AddressOf(), other.GetLength()) < 0; } diff --git a/sdk/angelscript/source/as_string.h b/sdk/angelscript/source/as_string.h index 2a6e7170..777d3be7 100644 --- a/sdk/angelscript/source/as_string.h +++ b/sdk/angelscript/source/as_string.h @@ -45,8 +45,8 @@ class asCString ~asCString(); #ifdef AS_CAN_USE_CPP11 - asCString(asCString&&) noexcept; - asCString &operator =(asCString &&) noexcept; + asCString(asCString &&) noexcept; + asCString &operator=(asCString &&) noexcept; #endif // c++11 asCString(const asCString &); @@ -58,15 +58,15 @@ class asCString void SetLength(size_t len); size_t GetLength() const; - void Concatenate(const char *str, size_t length); - asCString &operator +=(const asCString &); - asCString &operator +=(const char *); - asCString &operator +=(char); + void Concatenate(const char *str, size_t length); + asCString &operator+=(const asCString &); + asCString &operator+=(const char *); + asCString &operator+=(char); - void Assign(const char *str, size_t length); - asCString &operator =(const asCString &); - asCString &operator =(const char *); - asCString &operator =(char); + void Assign(const char *str, size_t length); + asCString &operator=(const asCString &); + asCString &operator=(const char *); + asCString &operator=(char); asCString SubString(size_t start, size_t length = (size_t)(-1)) const; @@ -78,37 +78,37 @@ class asCString int Compare(const asCString &str) const; int Compare(const char *str, size_t length) const; - char *AddressOf(); + char *AddressOf(); const char *AddressOf() const; - char &operator [](size_t index); + char &operator[](size_t index); const char &operator[](size_t index) const; - size_t RecalculateLength(); + size_t RecalculateLength(); protected: unsigned int length; union { char *dynamic; - char local[12]; + char local[12]; }; }; // Helper functions -bool operator ==(const asCString &, const asCString &); -bool operator !=(const asCString &, const asCString &); +bool operator==(const asCString &, const asCString &); +bool operator!=(const asCString &, const asCString &); -bool operator ==(const asCString &, const char *); -bool operator !=(const asCString &, const char *); +bool operator==(const asCString &, const char *); +bool operator!=(const asCString &, const char *); -bool operator ==(const char *, const asCString &); -bool operator !=(const char *, const asCString &); +bool operator==(const char *, const asCString &); +bool operator!=(const char *, const asCString &); -bool operator <(const asCString &, const asCString &); +bool operator<(const asCString &, const asCString &); -asCString operator +(const asCString &, const char *); -asCString operator +(const char *, const asCString &); -asCString operator +(const asCString &, const asCString &); +asCString operator+(const asCString &, const char *); +asCString operator+(const char *, const asCString &); +asCString operator+(const asCString &, const asCString &); // a wrapper for using the pointer of asCString in asCMap class asCStringPointer @@ -119,10 +119,10 @@ class asCStringPointer asCStringPointer(asCString *cstr); const char *AddressOf() const; - size_t GetLength() const; + size_t GetLength() const; - bool operator==(const asCStringPointer& other) const; - bool operator<(const asCStringPointer& other) const; + bool operator==(const asCStringPointer &other) const; + bool operator<(const asCStringPointer &other) const; private: // Either string/length or cstring is stored diff --git a/sdk/angelscript/source/as_string_util.cpp b/sdk/angelscript/source/as_string_util.cpp index 5440f04c..10f089ce 100644 --- a/sdk/angelscript/source/as_string_util.cpp +++ b/sdk/angelscript/source/as_string_util.cpp @@ -31,11 +31,11 @@ #include "as_config.h" -#include // some compilers declare memcpy() here -#include // pow() +#include // some compilers declare memcpy() here +#include // pow() #if !defined(AS_NO_MEMORY_H) -#include + #include #endif #include "as_string.h" @@ -45,7 +45,7 @@ BEGIN_AS_NAMESPACE int asCompareStrings(const char *str1, size_t len1, const char *str2, size_t len2) { - if( len1 == 0 ) + if( len1 == 0 ) { if( str2 == 0 || len2 == 0 ) return 0; // Equal @@ -54,7 +54,7 @@ int asCompareStrings(const char *str1, size_t len1, const char *str2, size_t len if( str2 == 0 ) { - if( len1 == 0 ) + if( len1 == 0 ) return 0; // Equal return -1; // The other string is smaller than this @@ -77,31 +77,31 @@ int asCompareStrings(const char *str1, size_t len1, const char *str2, size_t len double asStringScanDouble(const char *string, size_t *numScanned) { // I decided to do my own implementation of strtod() because this function - // doesn't seem to be present on all systems. iOS 5 for example doesn't appear + // doesn't seem to be present on all systems. iOS 5 for example doesn't appear // to include the function in the standard lib. - + // Another reason is that the standard implementation of strtod() is dependent - // on the locale on some systems, i.e. it may use comma instead of dot for + // on the locale on some systems, i.e. it may use comma instead of dot for // the decimal indicator. This can be avoided by forcing the locale to "C" with // setlocale(), but this is another thing that is highly platform dependent. - double value = 0; - double fraction = 0.1; - int exponent = 0; - bool negativeExponent = false; - int c = 0; + double value = 0; + double fraction = 0.1; + int exponent = 0; + bool negativeExponent = false; + int c = 0; - // The tokenizer separates the sign from the number in + // The tokenizer separates the sign from the number in // two tokens so we'll never have a sign to parse here // Parse the integer value for( ;; ) { - if (string[c] >= '0' && string[c] <= '9') + if( string[c] >= '0' && string[c] <= '9' ) value = value * 10 + double(string[c] - '0'); - else if (string[c] == '\'' && string[c + 1] && string[c + 1] >= '0' && string[c + 1] <= '9') + else if( string[c] == '\'' && string[c + 1] && string[c + 1] >= '0' && string[c + 1] <= '9' ) ; // skip separators - else + else break; c++; @@ -116,7 +116,7 @@ double asStringScanDouble(const char *string, size_t *numScanned) { if( string[c] >= '0' && string[c] <= '9' ) value += fraction * double(string[c] - '0'); - else if (string[c] == '\'' && string[c + 1] && string[c + 1] >= '0' && string[c + 1] <= '9') + else if( string[c] == '\'' && string[c + 1] && string[c + 1] >= '0' && string[c + 1] <= '9' ) { // skip separators c++; @@ -147,8 +147,8 @@ double asStringScanDouble(const char *string, size_t *numScanned) for( ;; ) { if( string[c] >= '0' && string[c] <= '9' ) - exponent = exponent*10 + int(string[c] - '0'); - else if (string[c] == '\'' && string[c + 1] && string[c + 1] >= '0' && string[c + 1] <= '9') + exponent = exponent * 10 + int(string[c] - '0'); + else if( string[c] == '\'' && string[c + 1] && string[c + 1] >= '0' && string[c + 1] <= '9' ) ; // skip separators else break; @@ -175,8 +175,8 @@ double asStringScanDouble(const char *string, size_t *numScanned) static int asCharToNbr(char ch, int radix) { if( ch >= '0' && ch <= '9' ) return ((ch -= '0') < radix ? ch : -1); - if( ch >= 'A' && ch <= 'Z' ) return ((ch -= 'A'-10) < radix ? ch : -1); - if( ch >= 'a' && ch <= 'z' ) return ((ch -= 'a'-10) < radix ? ch : -1); + if( ch >= 'A' && ch <= 'Z' ) return ((ch -= 'A' - 10) < radix ? ch : -1); + if( ch >= 'a' && ch <= 'z' ) return ((ch -= 'a' - 10) < radix ? ch : -1); return -1; } @@ -185,7 +185,7 @@ asQWORD asStringScanUInt64(const char *string, int base, size_t *numScanned, boo { asASSERT(base == 10 || base == 16 || base == 0); - if (overflow) + if( overflow ) *overflow = false; const char *end = string; @@ -198,14 +198,14 @@ asQWORD asStringScanUInt64(const char *string, int base, size_t *numScanned, boo while( (*end >= '0' && *end <= '9') || *end == '\'' ) { // skip separators - if (*end == '\'' && *(end + 1)) + if( *end == '\'' && *(end + 1) ) { - if (*(end + 1) >= '0' && *(end + 1) <= '9') + if( *(end + 1) >= '0' && *(end + 1) <= '9' ) { end++; continue; } - + // we're not a separator, start of a char literal end--; break; @@ -219,15 +219,27 @@ asQWORD asStringScanUInt64(const char *string, int base, size_t *numScanned, boo } else { - if( base == 0 && string[0] == '0') + if( base == 0 && string[0] == '0' ) { // Determine the radix from the prefix switch( string[1] ) { - case 'b': case 'B': base = 2; break; - case 'o': case 'O': base = 8; break; - case 'd': case 'D': base = 10; break; - case 'x': case 'X': base = 16; break; + case 'b': + case 'B': + base = 2; + break; + case 'o': + case 'O': + base = 8; + break; + case 'd': + case 'D': + base = 10; + break; + case 'x': + case 'X': + base = 16; + break; } end += 2; } @@ -236,25 +248,25 @@ asQWORD asStringScanUInt64(const char *string, int base, size_t *numScanned, boo if( base ) { - for (int nbr; ; end++) + for( int nbr;; end++ ) { nbr = asCharToNbr(*end, base); - - if (nbr < 0) + + if( nbr < 0 ) { // skip separators, if one exists - if (*end == '\'') + if( *end == '\'' ) { - if (*(end + 1) && asCharToNbr(*(end + 1), base) < 0) + if( *(end + 1) && asCharToNbr(*(end + 1), base) < 0 ) break; - + continue; } - + break; } - - if (overflow && ((res > QWORD_MAX / base) || ((asUINT(nbr) > (QWORD_MAX - (QWORD_MAX / base) * base)) && res == QWORD_MAX / base)) ) + + if( overflow && ((res > QWORD_MAX / base) || ((asUINT(nbr) > (QWORD_MAX - (QWORD_MAX / base) * base)) && res == QWORD_MAX / base)) ) *overflow = true; res = res * base + nbr; @@ -270,14 +282,14 @@ asQWORD asStringScanUInt64(const char *string, int base, size_t *numScanned, boo // // The function will encode the unicode code point into the outEncodedBuffer, and then -// return the length of the encoded value. If the input value is not a valid unicode code +// return the length of the encoded value. If the input value is not a valid unicode code // point, then the function will return -1. // // This function is taken from the AngelCode ToolBox. // int asStringEncodeUTF8(unsigned int value, char *outEncodedBuffer) { - unsigned char *buf = (unsigned char*)outEncodedBuffer; + unsigned char *buf = (unsigned char *)outEncodedBuffer; int length = -1; @@ -304,11 +316,11 @@ int asStringEncodeUTF8(unsigned int value, char *outEncodedBuffer) length = 4; } - int n = length-1; + int n = length - 1; for( ; n > 0; n-- ) { - buf[n] = static_cast(0x80 + (value & 0x3F)); - value >>= 6; + buf[n] = static_cast(0x80 + (value & 0x3F)); + value >>= 6; } return length; @@ -322,11 +334,11 @@ int asStringEncodeUTF8(unsigned int value, char *outEncodedBuffer) // int asStringDecodeUTF8(const char *encodedBuffer, unsigned int *outLength) { - const unsigned char *buf = (const unsigned char*)encodedBuffer; - - int value = 0; - int length = -1; - unsigned char byte = buf[0]; + const unsigned char *buf = (const unsigned char *)encodedBuffer; + + int value = 0; + int length = -1; + unsigned char byte = buf[0]; if( (byte & 0x80) == 0 ) { // This is the only byte @@ -336,10 +348,10 @@ int asStringDecodeUTF8(const char *encodedBuffer, unsigned int *outLength) else if( (byte & 0xE0) == 0xC0 ) { // There is one more byte - value = int(byte & 0x1F); + value = int(byte & 0x1F); length = 2; - // The value at this moment must not be less than 2, because + // The value at this moment must not be less than 2, because // that should have been encoded with one byte only. if( value < 2 ) length = -1; @@ -347,13 +359,13 @@ int asStringDecodeUTF8(const char *encodedBuffer, unsigned int *outLength) else if( (byte & 0xF0) == 0xE0 ) { // There are two more bytes - value = int(byte & 0x0F); + value = int(byte & 0x0F); length = 3; } else if( (byte & 0xF8) == 0xF0 ) { // There are three more bytes - value = int(byte & 0x07); + value = int(byte & 0x07); length = 4; } @@ -363,7 +375,7 @@ int asStringDecodeUTF8(const char *encodedBuffer, unsigned int *outLength) byte = buf[n]; if( (byte & 0xC0) == 0x80 ) value = (value << 6) + int(byte & 0x3F); - else + else break; } @@ -379,7 +391,7 @@ int asStringDecodeUTF8(const char *encodedBuffer, unsigned int *outLength) // // The function will encode the unicode code point into the outEncodedBuffer, and then -// return the length of the encoded value. If the input value is not a valid unicode code +// return the length of the encoded value. If the input value is not a valid unicode code // point, then the function will return -1. // // This function is taken from the AngelCode ToolBox. @@ -399,9 +411,9 @@ int asStringEncodeUTF16(unsigned int value, char *outEncodedBuffer) } else { - value -= 0x10000; - int surrogate1 = ((value >> 10) & 0x3FF) + 0xD800; - int surrogate2 = (value & 0x3FF) + 0xDC00; + value -= 0x10000; + int surrogate1 = ((value >> 10) & 0x3FF) + 0xD800; + int surrogate2 = (value & 0x3FF) + 0xDC00; #ifndef AS_BIG_ENDIAN outEncodedBuffer[0] = (surrogate1 & 0xFF); diff --git a/sdk/angelscript/source/as_string_util.h b/sdk/angelscript/source/as_string_util.h index 29174dfb..528eca1c 100644 --- a/sdk/angelscript/source/as_string_util.h +++ b/sdk/angelscript/source/as_string_util.h @@ -36,15 +36,15 @@ BEGIN_AS_NAMESPACE -int asCompareStrings(const char *str1, size_t len1, const char *str2, size_t len2); +int asCompareStrings(const char *str1, size_t len1, const char *str2, size_t len2); double asStringScanDouble(const char *string, size_t *numScanned); asQWORD asStringScanUInt64(const char *string, int base, size_t *numScanned, bool *overflow); -int asStringEncodeUTF8(unsigned int value, char *outEncodedBuffer); -int asStringDecodeUTF8(const char *encodedBuffer, unsigned int *outLength); +int asStringEncodeUTF8(unsigned int value, char *outEncodedBuffer); +int asStringDecodeUTF8(const char *encodedBuffer, unsigned int *outLength); -int asStringEncodeUTF16(unsigned int value, char *outEncodedBuffer); +int asStringEncodeUTF16(unsigned int value, char *outEncodedBuffer); END_AS_NAMESPACE diff --git a/sdk/angelscript/source/as_symboltable.h b/sdk/angelscript/source/as_symboltable.h index 261b4f33..85860d23 100644 --- a/sdk/angelscript/source/as_symboltable.h +++ b/sdk/angelscript/source/as_symboltable.h @@ -58,7 +58,7 @@ BEGIN_AS_NAMESPACE // Interface to avoid nested templates which is not well supported by older compilers, e.g. MSVC6 struct asIFilter { - virtual bool operator()(const void*) const = 0; + virtual bool operator()(const void *) const = 0; virtual ~asIFilter() {}; }; @@ -66,23 +66,26 @@ struct asIFilter // forward declaration -template +template class asCSymbolTable; // Iterator that allows iterating in index order -template +template class asCSymbolTableIterator { public: - T2* operator*() const; - T2* operator->() const; - asCSymbolTableIterator& operator++(int); - asCSymbolTableIterator& operator--(int); + T2 *operator*() const; + T2 *operator->() const; + asCSymbolTableIterator &operator++(int); + asCSymbolTableIterator &operator--(int); operator bool() const; - int GetIndex() const { return m_idx; } + int GetIndex() const + { + return m_idx; + } private: friend class asCSymbolTable; @@ -91,7 +94,7 @@ class asCSymbolTableIterator void Next(); void Previous(); - asCSymbolTable* m_table; + asCSymbolTable *m_table; unsigned int m_idx; }; @@ -101,34 +104,34 @@ class asCSymbolTableIterator // Symbol table mapping namespace + name to symbols // The structure keeps the entries indexed in an array so the indices will not change // There is also a map for a quick lookup. The map supports multiple entries with the same name -template +template class asCSymbolTable { public: - typedef asCSymbolTableIterator iterator; + typedef asCSymbolTableIterator iterator; typedef asCSymbolTableIterator const_iterator; asCSymbolTable(asUINT initialCapacity = 0); - int GetFirstIndex(const asSNameSpace *ns, const asCString &name, const asIFilter &comparator) const; - int GetFirstIndex(const asSNameSpace *ns, const asCString &name) const; - int GetLastIndex() const; + int GetFirstIndex(const asSNameSpace *ns, const asCString &name, const asIFilter &comparator) const; + int GetFirstIndex(const asSNameSpace *ns, const asCString &name) const; + int GetLastIndex() const; - int GetIndex(const T*) const; + int GetIndex(const T *) const; - T* GetFirst(const asSNameSpace *ns, const asCString &name, const asIFilter &comparator) const; - T* GetFirst(const asSNameSpace *ns, const asCString &name); - const T* GetFirst(const asSNameSpace *ns, const asCString &name) const; - T* Get(asUINT index); - const T* Get(asUINT index) const; - T* GetLast(); - const T* GetLast() const; + T *GetFirst(const asSNameSpace *ns, const asCString &name, const asIFilter &comparator) const; + T *GetFirst(const asSNameSpace *ns, const asCString &name); + const T *GetFirst(const asSNameSpace *ns, const asCString &name) const; + T *Get(asUINT index); + const T *Get(asUINT index) const; + T *GetLast(); + const T *GetLast() const; const asCArray &GetIndexes(const asSNameSpace *ns, const asCString &name) const; - asUINT Put(T* entry); + asUINT Put(T *entry); - asUINT GetSize() const; + asUINT GetSize() const; void SwapWith(asCSymbolTable &other); @@ -136,12 +139,15 @@ class asCSymbolTable bool Erase(asUINT idx); void Allocate(asUINT elem_cnt, bool keep_data); - iterator List(); + iterator List(); const_iterator List() const; private: // Don't allow assignment - asCSymbolTable& operator=(const asCSymbolTable &other) { return *this; } + asCSymbolTable &operator=(const asCSymbolTable &other) + { + return *this; + } friend class asCSymbolTableIterator; friend class asCSymbolTableIterator; @@ -150,21 +156,21 @@ class asCSymbolTable bool CheckIdx(asUINT idx) const; asCMap > m_map; - asCArray m_entries; + asCArray m_entries; unsigned int m_size; }; -template +template void asCSymbolTable::SwapWith(asCSymbolTable &other) { m_map.SwapWith(other.m_map); m_entries.SwapWith(other.m_entries); - asUINT tmp = m_size; - m_size = other.m_size; + asUINT tmp = m_size; + m_size = other.m_size; other.m_size = tmp; } @@ -173,7 +179,7 @@ void asCSymbolTable::SwapWith(asCSymbolTable &other) // Constructor // initialCapacity gives the number of entries to allocate in advance -template +template asCSymbolTable::asCSymbolTable(asUINT initialCapacity) : m_entries(initialCapacity) { m_size = 0; @@ -181,11 +187,11 @@ asCSymbolTable::asCSymbolTable(asUINT initialCapacity) : m_entries(initialCap -template +template int asCSymbolTable::GetFirstIndex( - const asSNameSpace *ns, - const asCString &name, - const asIFilter &filter) const + const asSNameSpace *ns, + const asCString &name, + const asIFilter &filter) const { asSNameSpaceNamePair key(ns, name); @@ -206,7 +212,7 @@ int asCSymbolTable::GetFirstIndex( -template +template const asCArray &asCSymbolTable::GetIndexes(const asSNameSpace *ns, const asCString &name) const { asSNameSpaceNamePair key(ns, name); @@ -222,18 +228,18 @@ const asCArray &asCSymbolTable::GetIndexes(const asSNameSpace *ns, co -template -T* asCSymbolTable::GetFirst(const asSNameSpace *ns, const asCString &name, const asIFilter &comp) const +template +T *asCSymbolTable::GetFirst(const asSNameSpace *ns, const asCString &name, const asIFilter &comp) const { int idx = GetFirstIndex(ns, name, comp); - if (idx != -1) return m_entries[idx]; + if( idx != -1 ) return m_entries[idx]; return 0; } -template +template int asCSymbolTable::GetFirstIndex(const asSNameSpace *ns, const asCString &name) const { asSNameSpaceNamePair key(ns, name); @@ -250,8 +256,8 @@ int asCSymbolTable::GetFirstIndex(const asSNameSpace *ns, const asCString &na // Find the index of a certain symbol // ATTENTION: this function has linear runtime complexity O(n)!! -template -int asCSymbolTable::GetIndex(const T* entry) const +template +int asCSymbolTable::GetIndex(const T *entry) const { for( asUINT n = 0; n < m_entries.GetLength(); n++ ) if( m_entries[n] == entry ) @@ -265,8 +271,8 @@ int asCSymbolTable::GetIndex(const T* entry) const -template -T* asCSymbolTable::Get(asUINT idx) +template +T *asCSymbolTable::Get(asUINT idx) { if( !CheckIdx(idx) ) return 0; @@ -274,43 +280,43 @@ T* asCSymbolTable::Get(asUINT idx) return m_entries[idx]; } -template -const T* asCSymbolTable::Get(asUINT idx) const +template +const T *asCSymbolTable::Get(asUINT idx) const { - return const_cast< asCSymbolTable* >(this)->Get(idx); + return const_cast *>(this)->Get(idx); } -template -T* asCSymbolTable::GetFirst(const asSNameSpace *ns, const asCString &name) +template +T *asCSymbolTable::GetFirst(const asSNameSpace *ns, const asCString &name) { int idx = GetFirstIndex(ns, name); return Get(idx); } -template -const T* asCSymbolTable::GetFirst(const asSNameSpace *ns, const asCString &name) const +template +const T *asCSymbolTable::GetFirst(const asSNameSpace *ns, const asCString &name) const { - return const_cast< asCSymbolTable* >(this)->GetFirst(ns, name); + return const_cast *>(this)->GetFirst(ns, name); } -template -T* asCSymbolTable::GetLast() +template +T *asCSymbolTable::GetLast() { return Get(GetLastIndex()); } -template -const T* asCSymbolTable::GetLast() const +template +const T *asCSymbolTable::GetLast() const { - return const_cast< asCSymbolTable* >(this)->GetLast(); + return const_cast *>(this)->GetLast(); } @@ -319,7 +325,7 @@ const T* asCSymbolTable::GetLast() const // Clear the symbol table // ATTENTION: The contained symbols are not rleased. This is up to the client -template +template void asCSymbolTable::Clear() { m_entries.SetLength(0); @@ -331,7 +337,7 @@ void asCSymbolTable::Clear() // Pre-allocate slots for elemCnt entries -template +template void asCSymbolTable::Allocate(asUINT elemCnt, bool keepData) { asASSERT( elemCnt >= m_entries.GetLength() ); @@ -342,7 +348,7 @@ void asCSymbolTable::Allocate(asUINT elemCnt, bool keepData) -template +template bool asCSymbolTable::Erase(asUINT idx) { if( !CheckIdx(idx) ) @@ -377,15 +383,15 @@ bool asCSymbolTable::Erase(asUINT idx) else { // Must keep the array packed - int prevIdx = int(m_entries.GetLength()-1); + int prevIdx = int(m_entries.GetLength() - 1); m_entries[idx] = m_entries.PopLast(); - + // Update the index in the lookup map entry = m_entries[idx]; GetKey(entry, key); if( m_map.MoveTo(&cursor, key) ) { - asCArray &arr = m_map.GetValue(cursor); + asCArray &arr = m_map.GetValue(cursor); arr[arr.IndexOf(prevIdx)] = idx; } else @@ -399,10 +405,10 @@ bool asCSymbolTable::Erase(asUINT idx) -template +template asUINT asCSymbolTable::Put(T *entry) { - asUINT idx = m_entries.GetLength(); + asUINT idx = m_entries.GetLength(); asSNameSpaceNamePair key; GetKey(entry, key); @@ -425,7 +431,7 @@ asUINT asCSymbolTable::Put(T *entry) // Return key for specified symbol (namespace and name are used to generate the key) -template +template void asCSymbolTable::GetKey(const T *entry, asSNameSpaceNamePair &key) const { key = asSNameSpaceNamePair(entry->nameSpace, entry->name); @@ -434,7 +440,7 @@ void asCSymbolTable::GetKey(const T *entry, asSNameSpaceNamePair &key) const -template +template asUINT asCSymbolTable::GetSize() const { return m_size; @@ -443,7 +449,7 @@ asUINT asCSymbolTable::GetSize() const -template +template bool asCSymbolTable::CheckIdx(asUINT idx) const { return idx < m_entries.GetLength(); @@ -452,7 +458,7 @@ bool asCSymbolTable::CheckIdx(asUINT idx) const -template +template int asCSymbolTable::GetLastIndex() const { int idx = int(m_entries.GetLength()) - 1; @@ -463,7 +469,7 @@ int asCSymbolTable::GetLastIndex() const -template +template asCSymbolTableIterator asCSymbolTable::List() { return asCSymbolTableIterator(this); @@ -472,10 +478,10 @@ asCSymbolTableIterator asCSymbolTable::List() -template +template typename asCSymbolTable::const_iterator asCSymbolTable::List() const { - return asCSymbolTableIterator(const_cast< asCSymbolTable *>(this)); + return asCSymbolTableIterator(const_cast *>(this)); } @@ -483,7 +489,7 @@ typename asCSymbolTable::const_iterator asCSymbolTable::List() const // Iterator -template +template asCSymbolTableIterator::asCSymbolTableIterator(asCSymbolTable *table) : m_table(table), m_idx(0) { asUINT sz = m_table->m_entries.GetLength(); @@ -493,8 +499,8 @@ asCSymbolTableIterator::asCSymbolTableIterator(asCSymbolTable *table) -template -T2* asCSymbolTableIterator::operator*() const +template +T2 *asCSymbolTableIterator::operator*() const { asASSERT(m_table->CheckIdx(m_idx)); return m_table->m_entries[m_idx]; @@ -502,8 +508,8 @@ T2* asCSymbolTableIterator::operator*() const -template -T2* asCSymbolTableIterator::operator->() const +template +T2 *asCSymbolTableIterator::operator->() const { asASSERT(m_table->CheckIdx(m_idx)); return m_table->m_entries[m_idx]; @@ -511,8 +517,8 @@ T2* asCSymbolTableIterator::operator->() const -template -asCSymbolTableIterator& asCSymbolTableIterator::operator++(int) +template +asCSymbolTableIterator &asCSymbolTableIterator::operator++(int) { Next(); return *this; @@ -523,7 +529,7 @@ asCSymbolTableIterator& asCSymbolTableIterator::operator++(int) // Return true if more elements are following // ATTENTION: When deleting the object currently pointed to by this iterator this // method returns false even though there might be more elements in the list -template +template asCSymbolTableIterator::operator bool() const { return m_idx < m_table->m_entries.GetLength() && m_table->m_entries[m_idx] != 0; @@ -531,7 +537,7 @@ asCSymbolTableIterator::operator bool() const -template +template void asCSymbolTableIterator::Next() { asUINT sz = m_table->m_entries.GetLength(); @@ -542,7 +548,7 @@ void asCSymbolTableIterator::Next() -template +template void asCSymbolTableIterator::Previous() { // overflow on stepping over first element @@ -554,8 +560,8 @@ void asCSymbolTableIterator::Previous() -template -asCSymbolTableIterator& asCSymbolTableIterator::operator--(int) +template +asCSymbolTableIterator &asCSymbolTableIterator::operator--(int) { Previous(); return *this; diff --git a/sdk/angelscript/source/as_texts.h b/sdk/angelscript/source/as_texts.h index b184fd62..2bde5738 100644 --- a/sdk/angelscript/source/as_texts.h +++ b/sdk/angelscript/source/as_texts.h @@ -41,386 +41,385 @@ // Compiler messages -#define TXT_s_ALREADY_DECLARED "'%s' is already declared" +#define TXT_s_ALREADY_DECLARED "'%s' is already declared" #define TXT_ABSTRACT_CLASS_s_CANNOT_BE_INSTANTIATED "Abstract class '%s' cannot be instantiated" -#define TXT_ACCESSING_PRIVATE_PROP_s "Accessing private property '%s' of parent class" -#define TXT_ALL_CODE_PATHS_MUST_INIT_MEMBER "Initialization after return. All code paths must initialize the members" -#define TXT_ARG_NOT_LVALUE "Output argument expression is not assignable" -#define TXT_ARGUMENT_TYPE_ERROR_i "Rejected due to type mismatch at positional parameter %i" -#define TXT_ARGUMENT_TYPE_ERROR_s "Rejected due to type mismatch on parameter '%s'" -#define TXT_ATTR_s_INFORMED_MULTIPLE_TIMES "Attribute '%s' informed multiple times" -#define TXT_AUTO_NOT_ALLOWED "Auto is not allowed here" - -#define TXT_BOTH_MUST_BE_SAME "Can't find unambiguous implicit conversion to make both expressions have the same type" +#define TXT_ACCESSING_PRIVATE_PROP_s "Accessing private property '%s' of parent class" +#define TXT_ALL_CODE_PATHS_MUST_INIT_MEMBER "Initialization after return. All code paths must initialize the members" +#define TXT_ARG_NOT_LVALUE "Output argument expression is not assignable" +#define TXT_ARGUMENT_TYPE_ERROR_i "Rejected due to type mismatch at positional parameter %i" +#define TXT_ARGUMENT_TYPE_ERROR_s "Rejected due to type mismatch on parameter '%s'" +#define TXT_ATTR_s_INFORMED_MULTIPLE_TIMES "Attribute '%s' informed multiple times" +#define TXT_AUTO_NOT_ALLOWED "Auto is not allowed here" + +#define TXT_BOTH_MUST_BE_SAME "Can't find unambiguous implicit conversion to make both expressions have the same type" #define TXT_BOTH_CONDITIONS_MUST_CALL_CONSTRUCTOR "Both conditions must call constructor" -#define TXT_BOTH_CONDITIONS_MUST_INIT_MEMBER_s "Both conditions must initialize member '%s'" -#define TXT_BASE_DOESNT_HAVE_DEF_CONSTR "Base class doesn't have default constructor. Make explicit call to base constructor" -#define TXT_BASE_DOESNT_HAVE_CPY_CONSTR_OR_DEF_CONSTR "Base class doesn't have copy constructor or default constructor and assign operator. Make explicit call to base constructor" - -#define TXT_CANDIDATES_ARE "Candidates are:" -#define TXT_CANNOT_CALL_CONSTRUCTOR_IN_LOOPS "Can't call a constructor in loops" -#define TXT_CANNOT_CALL_CONSTRUCTOR_IN_SWITCH "Can't call a constructor in switch" -#define TXT_CANNOT_CALL_CONSTRUCTOR_TWICE "Can't call a constructor multiple times" -#define TXT_CANNOT_CREATE_DELEGATE "Can't create delegate" +#define TXT_BOTH_CONDITIONS_MUST_INIT_MEMBER_s "Both conditions must initialize member '%s'" +#define TXT_BASE_DOESNT_HAVE_DEF_CONSTR "Base class doesn't have default constructor. Make explicit call to base constructor" +#define TXT_BASE_DOESNT_HAVE_CPY_CONSTR_OR_DEF_CONSTR "Base class doesn't have copy constructor or default constructor and assign operator. Make explicit call to base constructor" + +#define TXT_CANDIDATES_ARE "Candidates are:" +#define TXT_CANNOT_CALL_CONSTRUCTOR_IN_LOOPS "Can't call a constructor in loops" +#define TXT_CANNOT_CALL_CONSTRUCTOR_IN_SWITCH "Can't call a constructor in switch" +#define TXT_CANNOT_CALL_CONSTRUCTOR_TWICE "Can't call a constructor multiple times" +#define TXT_CANNOT_CREATE_DELEGATE "Can't create delegate" #define TXT_CANNOT_CREATE_DELEGATE_FOR_NOREF_TYPES "Can't create delegate for types that do not support handles" -#define TXT_CANNOT_DELETE_NON_AUTO_FUNC "Cannot flag function that will not be auto generated as deleted" -#define TXT_CANNOT_DEFINE_FUNC_THAT_IS_DELETED "Conflict with explicit declaration of function and deleted function" -#define TXT_CANNOT_FORM_ARRAY_OF_s "Can't form arrays of subtype '%s'" -#define TXT_CANNOT_IMPLEMENT_SELF "Can't implement itself, or another interface that implements this interface" -#define TXT_CANNOT_IMPLICITLY_CALL_EXPLICIT_COPY_CONSTR "Can't implicitly call explicit copy constructor" -#define TXT_CANNOT_INHERIT_FROM_s_FINAL "Can't inherit from class '%s' marked as final" -#define TXT_CANNOT_INHERIT_FROM_MULTIPLE_CLASSES "Can't inherit from multiple classes" -#define TXT_CANNOT_INHERIT_FROM_SELF "Can't inherit from itself, or another class that inherits from this class" -#define TXT_CANNOT_INIT_MEMBERS_IN_LOOPS "Can't initialize the members in loops" -#define TXT_CANNOT_INIT_MEMBERS_IN_SWITCH "Can't initialize the members in switch" -#define TXT_CANNOT_PASS_CLASS_METHOD_AS_ARG "Can't pass class method as arg directly. Use a delegate object instead" -#define TXT_CANNOT_RESOLVE_AUTO "Unable to resolve auto type" -#define TXT_CANNOT_ACCESS_NON_STATIC_MEMBER_s "Cannot access non-static member '%s' like this" -#define TXT_CANNOT_RETURN_REF_TO_LOCAL "Can't return reference to local value." -#define TXT_CANT_CONSTRUCT_s_USE_REF_CAST "Can't construct handle '%s'. Use ref cast instead" -#define TXT_CANT_IMPLICITLY_CONVERT_s_TO_s "Can't implicitly convert from '%s' to '%s'." -#define TXT_CANT_RETURN_VALUE "Can't return value when return type is 'void'" -#define TXT_CHANGE_SIGN "Implicit conversion changed sign of value" -#define TXT_CLASS_CANT_BE_FINAL_AND_ABSTRACT "A class cannot be both abstract and final" -#define TXT_COMPILING_s "Compiling %s" -#define TXT_COMPILING_AUTO_s "Compiling auto generated %s" -#define TXT_COMPOUND_ASGN_ON_VALUE_TYPE "Compound assignments with property accessors on value types are not supported" -#define TXT_COMPOUND_ASGN_WITH_IDX_PROP "Compound assignments with indexed property accessors are not supported" -#define TXT_COMPOUND_ASGN_REQUIRE_GET_SET "Compound assignments with property accessors require both get and set accessors" -#define TXT_PROP_ACCESS_s_DOES_NOT_EXPECT_INDEX "Implemented property accessor '%s' does not expect index argument" -#define TXT_PROP_ACCESS_s_EXPECTS_INDEX "Implemented property accessor '%s' expects index argument" - -#define TXT_DATA_TYPE_CANT_BE_s "Data type can't be '%s'" -#define TXT_DECL_IN_SWITCH "Variables cannot be declared in switch cases, except inside statement blocks" -#define TXT_DEFAULT_MUST_BE_LAST "The default case must be the last one" -#define TXT_DEF_ARG_MISSING_IN_FUNC_s "All subsequent parameters after the first default value must have default values in function '%s'" -#define TXT_DEF_ARG_TYPE_DOESNT_MATCH "The type of the default argument expression doesn't match the function parameter type" -#define TXT_DELETED_FUNC_CANT_HAVE_IMPL "Deleted functions cannot have implementation" +#define TXT_CANNOT_DELETE_NON_AUTO_FUNC "Cannot flag function that will not be auto generated as deleted" +#define TXT_CANNOT_DEFINE_FUNC_THAT_IS_DELETED "Conflict with explicit declaration of function and deleted function" +#define TXT_CANNOT_FORM_ARRAY_OF_s "Can't form arrays of subtype '%s'" +#define TXT_CANNOT_IMPLEMENT_SELF "Can't implement itself, or another interface that implements this interface" +#define TXT_CANNOT_IMPLICITLY_CALL_EXPLICIT_COPY_CONSTR "Can't implicitly call explicit copy constructor" +#define TXT_CANNOT_INHERIT_FROM_s_FINAL "Can't inherit from class '%s' marked as final" +#define TXT_CANNOT_INHERIT_FROM_MULTIPLE_CLASSES "Can't inherit from multiple classes" +#define TXT_CANNOT_INHERIT_FROM_SELF "Can't inherit from itself, or another class that inherits from this class" +#define TXT_CANNOT_INIT_MEMBERS_IN_LOOPS "Can't initialize the members in loops" +#define TXT_CANNOT_INIT_MEMBERS_IN_SWITCH "Can't initialize the members in switch" +#define TXT_CANNOT_PASS_CLASS_METHOD_AS_ARG "Can't pass class method as arg directly. Use a delegate object instead" +#define TXT_CANNOT_RESOLVE_AUTO "Unable to resolve auto type" +#define TXT_CANNOT_ACCESS_NON_STATIC_MEMBER_s "Cannot access non-static member '%s' like this" +#define TXT_CANNOT_RETURN_REF_TO_LOCAL "Can't return reference to local value." +#define TXT_CANT_CONSTRUCT_s_USE_REF_CAST "Can't construct handle '%s'. Use ref cast instead" +#define TXT_CANT_IMPLICITLY_CONVERT_s_TO_s "Can't implicitly convert from '%s' to '%s'." +#define TXT_CANT_RETURN_VALUE "Can't return value when return type is 'void'" +#define TXT_CHANGE_SIGN "Implicit conversion changed sign of value" +#define TXT_CLASS_CANT_BE_FINAL_AND_ABSTRACT "A class cannot be both abstract and final" +#define TXT_COMPILING_s "Compiling %s" +#define TXT_COMPILING_AUTO_s "Compiling auto generated %s" +#define TXT_COMPOUND_ASGN_ON_VALUE_TYPE "Compound assignments with property accessors on value types are not supported" +#define TXT_COMPOUND_ASGN_WITH_IDX_PROP "Compound assignments with indexed property accessors are not supported" +#define TXT_COMPOUND_ASGN_REQUIRE_GET_SET "Compound assignments with property accessors require both get and set accessors" +#define TXT_PROP_ACCESS_s_DOES_NOT_EXPECT_INDEX "Implemented property accessor '%s' does not expect index argument" +#define TXT_PROP_ACCESS_s_EXPECTS_INDEX "Implemented property accessor '%s' expects index argument" + +#define TXT_DATA_TYPE_CANT_BE_s "Data type can't be '%s'" +#define TXT_DECL_IN_SWITCH "Variables cannot be declared in switch cases, except inside statement blocks" +#define TXT_DEFAULT_MUST_BE_LAST "The default case must be the last one" +#define TXT_DEF_ARG_MISSING_IN_FUNC_s "All subsequent parameters after the first default value must have default values in function '%s'" +#define TXT_DEF_ARG_TYPE_DOESNT_MATCH "The type of the default argument expression doesn't match the function parameter type" +#define TXT_DELETED_FUNC_CANT_HAVE_IMPL "Deleted functions cannot have implementation" #define TXT_DERIVED_METHOD_MUST_HAVE_SAME_RETTYPE_s "The method in the derived class must have the same return type as in the base class: '%s'" -#define TXT_DESTRUCTOR_MAY_NOT_HAVE_PARM "The destructor must not have any parameters" -#define TXT_DESTRUCTOR_s_s_NAME_ERROR "The name of the destructor '%s::~%s' must be the same as the class" -#define TXT_DISALLOW_ASSIGN_ON_REF_TYPE "Value assignment on reference types is not allowed. Did you mean to do a handle assignment?" -#define TXT_DISALLOW_COMPOUND_ASSIGN_ON_REF_TYPE "Compound assignment on reference types is not allowed" -#define TXT_DUPLICATE_NAMED_ARGUMENT_s "Duplicate named argument '%s'" -#define TXT_DUPLICATE_SWITCH_CASE "Duplicate switch case" - -#define TXT_ELSE_WITH_EMPTY_STATEMENT "Else with empty statement" +#define TXT_DESTRUCTOR_MAY_NOT_HAVE_PARM "The destructor must not have any parameters" +#define TXT_DESTRUCTOR_s_s_NAME_ERROR "The name of the destructor '%s::~%s' must be the same as the class" +#define TXT_DISALLOW_ASSIGN_ON_REF_TYPE "Value assignment on reference types is not allowed. Did you mean to do a handle assignment?" +#define TXT_DISALLOW_COMPOUND_ASSIGN_ON_REF_TYPE "Compound assignment on reference types is not allowed" +#define TXT_DUPLICATE_NAMED_ARGUMENT_s "Duplicate named argument '%s'" +#define TXT_DUPLICATE_SWITCH_CASE "Duplicate switch case" + +#define TXT_ELSE_WITH_EMPTY_STATEMENT "Else with empty statement" #define TXT_EMPTY_LIST_ELEMENT_IS_NOT_ALLOWED "Empty list element is not allowed" -#define TXT_EMPTY_SWITCH "Empty switch statement" -#define TXT_EXPECTED_s "Expected '%s'" -#define TXT_EXPECTED_CONSTANT "Expected constant" -#define TXT_EXPECTED_DATA_TYPE "Expected data type" -#define TXT_EXPECTED_EXPRESSION_VALUE "Expected expression value" -#define TXT_EXPECTED_IDENTIFIER "Expected identifier" -#define TXT_EXPECTED_LIST "Expected a list enclosed by { } to match pattern" -#define TXT_EXPECTED_METHOD_OR_PROPERTY "Expected method or property" -#define TXT_EXPECTED_ONE_OF "Expected one of: " -#define TXT_EXPECTED_OPERATOR "Expected operator" -#define TXT_EXPECTED_s_OR_s "Expected '%s' or '%s'" -#define TXT_EXPECTED_POST_OPERATOR "Expected post operator" -#define TXT_EXPECTED_PRE_OPERATOR "Expected pre operator" -#define TXT_EXPECTED_STRING "Expected string" -#define TXT_EXPR_DOESNT_EVAL_TO_FUNC "Expression doesn't evaluate to a function" -#define TXT_EXPR_MUST_BE_BOOL_s "Expression must be of boolean type, instead found '%s'" -#define TXT_EXPR_s_IS_DATA_TYPE "Expression '%s' is a data type" -#define TXT_EXTERNAL_SHARED_s_NOT_FOUND "External shared entity '%s' not found" -#define TXT_EXTERNAL_SHARED_s_CANNOT_REDEF "External shared entity '%s' cannot redefine the original entity" +#define TXT_EMPTY_SWITCH "Empty switch statement" +#define TXT_EXPECTED_s "Expected '%s'" +#define TXT_EXPECTED_CONSTANT "Expected constant" +#define TXT_EXPECTED_DATA_TYPE "Expected data type" +#define TXT_EXPECTED_EXPRESSION_VALUE "Expected expression value" +#define TXT_EXPECTED_IDENTIFIER "Expected identifier" +#define TXT_EXPECTED_LIST "Expected a list enclosed by { } to match pattern" +#define TXT_EXPECTED_METHOD_OR_PROPERTY "Expected method or property" +#define TXT_EXPECTED_ONE_OF "Expected one of: " +#define TXT_EXPECTED_OPERATOR "Expected operator" +#define TXT_EXPECTED_s_OR_s "Expected '%s' or '%s'" +#define TXT_EXPECTED_POST_OPERATOR "Expected post operator" +#define TXT_EXPECTED_PRE_OPERATOR "Expected pre operator" +#define TXT_EXPECTED_STRING "Expected string" +#define TXT_EXPR_DOESNT_EVAL_TO_FUNC "Expression doesn't evaluate to a function" +#define TXT_EXPR_MUST_BE_BOOL_s "Expression must be of boolean type, instead found '%s'" +#define TXT_EXPR_s_IS_DATA_TYPE "Expression '%s' is a data type" +#define TXT_EXTERNAL_SHARED_s_NOT_FOUND "External shared entity '%s' not found" +#define TXT_EXTERNAL_SHARED_s_CANNOT_REDEF "External shared entity '%s' cannot redefine the original entity" #define TXT_FAILED_TO_COMPILE_DEF_ARG_d_IN_FUNC_s "Failed while compiling default arg for parameter %d in function '%s'" -#define TXT_FAILED_TO_CREATE_TEMP_OBJ "Previous error occurred while attempting to create a temporary copy of object" -#define TXT_FLOAT_CONV_TO_INT_CAUSE_TRUNC "Float value truncated in implicit conversion to integer" -#define TXT_FOUND_MULTIPLE_ENUM_VALUES "Found multiple matching enum values" -#define TXT_FUNCTION_ALREADY_EXIST "A function with the same name and parameters already exists" -#define TXT_FUNCTION_s_NOT_FOUND "Function '%s' not found" +#define TXT_FAILED_TO_CREATE_TEMP_OBJ "Previous error occurred while attempting to create a temporary copy of object" +#define TXT_FLOAT_CONV_TO_INT_CAUSE_TRUNC "Float value truncated in implicit conversion to integer" +#define TXT_FOUND_MULTIPLE_ENUM_VALUES "Found multiple matching enum values" +#define TXT_FUNCTION_ALREADY_EXIST "A function with the same name and parameters already exists" +#define TXT_FUNCTION_s_NOT_FOUND "Function '%s' not found" #define TXT_GET_SET_ACCESSOR_TYPE_MISMATCH_FOR_s "The property '%s' has mismatching types for the get and set accessors" -#define TXT_GLOBAL_VARS_NOT_ALLOWED "Global variables have been disabled by the application" +#define TXT_GLOBAL_VARS_NOT_ALLOWED "Global variables have been disabled by the application" -#define TXT_HANDLE_ASSIGN_ON_NON_HANDLE_PROP "It is not allowed to perform a handle assignment on a non-handle property" -#define TXT_HANDLE_COMPARISON "The operand is implicitly converted to handle in order to compare them" -#define TXT_HANDLE_OF_HANDLE_IS_NOT_ALLOWED "Handle to handle is not allowed" -#define TXT_s_HIDES_VAR_IN_OUTER_SCOPE "Variable '%s' hides another variable of same name in outer scope" +#define TXT_HANDLE_ASSIGN_ON_NON_HANDLE_PROP "It is not allowed to perform a handle assignment on a non-handle property" +#define TXT_HANDLE_COMPARISON "The operand is implicitly converted to handle in order to compare them" +#define TXT_HANDLE_OF_HANDLE_IS_NOT_ALLOWED "Handle to handle is not allowed" +#define TXT_s_HIDES_VAR_IN_OUTER_SCOPE "Variable '%s' hides another variable of same name in outer scope" -#define TXT_IDENTIFIER_s_NOT_DATA_TYPE "Identifier '%s' is not a data type" +#define TXT_IDENTIFIER_s_NOT_DATA_TYPE "Identifier '%s' is not a data type" #define TXT_IDENTIFIER_s_NOT_DATA_TYPE_IN_GLOBAL_NS "Identifier '%s' is not a data type in global namespace" -#define TXT_IDENTIFIER_s_NOT_DATA_TYPE_IN_NS_s "Identifier '%s' is not a data type in namespace '%s' or parent" -#define TXT_IF_WITH_EMPTY_STATEMENT "If with empty statement" -#define TXT_ILLEGAL_MEMBER_TYPE "Illegal member type" +#define TXT_IDENTIFIER_s_NOT_DATA_TYPE_IN_NS_s "Identifier '%s' is not a data type in namespace '%s' or parent" +#define TXT_IF_WITH_EMPTY_STATEMENT "If with empty statement" +#define TXT_ILLEGAL_MEMBER_TYPE "Illegal member type" // TODO: Should be TXT_ILLEGAL_OPERATION_ON_s -#define TXT_ILLEGAL_OPERATION "Illegal operation on this datatype" -#define TXT_ILLEGAL_OPERATION_ON_s "Illegal operation on '%s'" -#define TXT_ILLEGAL_RETURN_BY_VALUE_FOR_s "Illegal return by value for '%s' in type cast" -#define TXT_ILLEGAL_TARGET_TYPE_FOR_REF_CAST "Illegal target type for reference cast" -#define TXT_ILLEGAL_VARIABLE_NAME_s "Illegal variable name '%s'." -#define TXT_INHERITED_PRIVATE_PROP_ACCESS_s "Illegal access to inherited private property '%s'" -#define TXT_INIT_LIST_CANNOT_BE_USED_WITH_s "Initialization lists cannot be used with '%s'" -#define TXT_INSTANCING_INVLD_TMPL_TYPE_s_s "Attempting to instantiate invalid template type '%s<%s>'" -#define TXT_INSTEAD_FOUND_s "Instead found '%s'" -#define TXT_INSTEAD_FOUND_IDENTIFIER_s "Instead found identifier '%s'" -#define TXT_INSTEAD_FOUND_KEYWORD_s "Instead found reserved keyword '%s'" -#define TXT_INTERFACE_s_CANNOT_BE_INSTANTIATED "Interface '%s' cannot be instantiated" +#define TXT_ILLEGAL_OPERATION "Illegal operation on this datatype" +#define TXT_ILLEGAL_OPERATION_ON_s "Illegal operation on '%s'" +#define TXT_ILLEGAL_RETURN_BY_VALUE_FOR_s "Illegal return by value for '%s' in type cast" +#define TXT_ILLEGAL_TARGET_TYPE_FOR_REF_CAST "Illegal target type for reference cast" +#define TXT_ILLEGAL_VARIABLE_NAME_s "Illegal variable name '%s'." +#define TXT_INHERITED_PRIVATE_PROP_ACCESS_s "Illegal access to inherited private property '%s'" +#define TXT_INIT_LIST_CANNOT_BE_USED_WITH_s "Initialization lists cannot be used with '%s'" +#define TXT_INSTANCING_INVLD_TMPL_TYPE_s_s "Attempting to instantiate invalid template type '%s<%s>'" +#define TXT_INSTEAD_FOUND_s "Instead found '%s'" +#define TXT_INSTEAD_FOUND_IDENTIFIER_s "Instead found identifier '%s'" +#define TXT_INSTEAD_FOUND_KEYWORD_s "Instead found reserved keyword '%s'" +#define TXT_INTERFACE_s_CANNOT_BE_INSTANTIATED "Interface '%s' cannot be instantiated" #define TXT_INTERFACE_CAN_ONLY_IMPLEMENT_INTERFACE "Interfaces can only implement other interfaces" -#define TXT_INVALID_BREAK "Invalid 'break'" -#define TXT_INVALID_CHAR_LITERAL "Invalid character literal" -#define TXT_INVALID_CONTINUE "Invalid 'continue'" -#define TXT_INVALID_ESCAPE_SEQUENCE "Invalid escape sequence" -#define TXT_INVALID_EXPRESSION_AMBIGUOUS_NAME "Invalid expression: ambiguous name" -#define TXT_INVALID_EXPRESSION_LAMBDA "Invalid expression: stand-alone anonymous function" -#define TXT_INVALID_OP_ON_METHOD "Invalid operation on method" -#define TXT_INVALID_REF_PROP_ACCESS "Invalid reference. Property accessors cannot be used in combined read/write operations" -#define TXT_INVALID_SCOPE "Invalid scope resolution" -#define TXT_INVALID_SIG_FOR_VIRTPROP "Invalid signature for virtual property" -#define TXT_INVALID_TYPE "Invalid type" -#define TXT_INVALID_UNICODE_FORMAT_EXPECTED_d "Invalid unicode escape sequence, expected %d hex digits" -#define TXT_INVALID_UNICODE_VALUE "Invalid unicode code point" -#define TXT_INVALID_UNICODE_SEQUENCE_IN_SRC "Invalid unicode sequence in source" -#define TXT_INVALID_USE_OF_NAMED_ARGS "Invalid use of named arguments" - -#define TXT_MEMBER_s_ACCESSED_BEFORE_INIT "The member '%s' is accessed before the initialization" -#define TXT_METHOD_CANNOT_OVERRIDE_s "Method '%s' declared as final and cannot be overridden" -#define TXT_METHOD_CANT_HAVE_NAME_OF_CLASS "The method cannot be named with the class name" -#define TXT_METHOD_s_DOES_NOT_OVERRIDE "Method '%s' marked as override but does not replace any base class or interface method" -#define TXT_METHOD_s_s_HAS_NO_RETURN_TYPE "Method '%s::%s' is missing the return type, nor is it the same name as object to be a constructor" -#define TXT_METHOD_s_NOT_PART_OF_OBJECT_s "Method '%s' is not part of object '%s'" -#define TXT_MISSING_ARGUMENT_s "Rejected due to named parameter '%s' missing" -#define TXT_MISSING_IMPLEMENTATION_OF_s "Missing implementation of '%s'" -#define TXT_MISSING_DEFINITION_OF_s "Missing definition of '%s'" -#define TXT_MISSING_OR_INVALID_DEFINITON_OF_s "Missing or invalid definition of '%s'" -#define TXT_MIXIN_CANNOT_BE_DECLARED_AS_s "Mixin class cannot be declared as '%s'" -#define TXT_MIXIN_CANNOT_HAVE_CONSTRUCTOR "Mixin classes cannot have constructors or destructors" -#define TXT_MIXIN_CLASS_CANNOT_INHERIT "Mixin class cannot inherit from classes" -#define TXT_MIXIN_CANNOT_HAVE_CHILD_TYPES "Mixin classes cannot have child types" -#define TXT_MORE_THAN_ONE_MATCHING_OP "Found more than one matching operator" -#define TXT_MULTIPLE_MATCHING_SIGNATURES_TO_s "Multiple matching signatures to '%s'" -#define TXT_MULTIPLE_PROP_GET_ACCESSOR_FOR_s "Found multiple get accessors for property '%s'" -#define TXT_MULTIPLE_PROP_SET_ACCESSOR_FOR_s "Found multiple set accessors for property '%s'" -#define TXT_MULTILINE_STRINGS_NOT_ALLOWED "Multiline strings are not allowed in this application" -#define TXT_MUST_BE_OBJECT "Only objects have constructors" -#define TXT_MUST_RETURN_VALUE "Must return a value" - -#define TXT_NAMESPACE_s_DOESNT_EXIST "Namespace '%s' doesn't exist." -#define TXT_NAME_CONFLICT_s_EXTENDED_TYPE "Name conflict. '%s' is an extended data type." -#define TXT_NAME_CONFLICT_s_GLOBAL_PROPERTY "Name conflict. '%s' is a global property." -#define TXT_NAME_CONFLICT_s_IS_NAMED_TYPE "Name conflict. '%s' is a named type." -#define TXT_NAME_CONFLICT_s_IS_FUNCDEF "Name conflict. '%s' is a funcdef." -#define TXT_NAME_CONFLICT_s_IS_FUNCTION "Name conflict. '%s' is a global function." -#define TXT_NAME_CONFLICT_s_IS_MIXIN "Name conflict. '%s' is a mixin class." -#define TXT_NAME_CONFLICT_s_IS_VIRTPROP "Name conflict. '%s' is a virtual property." -#define TXT_NAME_CONFLICT_s_STRUCT "Name conflict. '%s' is a class." -#define TXT_NAME_CONFLICT_s_INTF "Name conflict. '%s' is an interface." -#define TXT_NAME_CONFLICT_s_OBJ_PROPERTY "Name conflict. '%s' is an object property." -#define TXT_NAME_CONFLICT_s_METHOD "Name conflict. '%s' is a class method." -#define TXT_NAME_CONFLICT_s_ALREADY_USED "Name conflict. '%s' is already used." -#define TXT_NAMED_ARGS_WITH_OLD_SYNTAX "Detected named argument with old syntax" -#define TXT_NO_APPROPRIATE_INDEX_OPERATOR "No appropriate indexing operator found" -#define TXT_NO_APPROPRIATE_OPHNDLASSIGN_s "No appropriate opHndlAssign method found in '%s' for handle assignment" -#define TXT_NO_APPROPRIATE_OPEQUALS "No appropriate opEquals method found" -#define TXT_NO_CONVERSION_s_TO_s "No conversion from '%s' to '%s' available." -#define TXT_NO_CONVERSION_s_TO_MATH_TYPE "No conversion from '%s' to math type available." -#define TXT_NO_DEFAULT_ARRAY_TYPE "The application doesn't support the default array type." -#define TXT_NO_DEFAULT_CONSTRUCTOR_FOR_s "No default constructor for object of type '%s'." -#define TXT_NO_DEFAULT_COPY_OP_FOR_s "No appropriate opAssign method found in '%s' for value assignment" -#define TXT_NO_COPY_CONSTRUCTOR_FOR_s "No copy constructor for object of type '%s'." -#define TXT_NO_MATCHING_SIGNATURES_TO_s "No matching signatures to '%s'" -#define TXT_NO_MATCHING_OP_FOUND_FOR_TYPE_s "No matching operator that takes the type '%s' found" +#define TXT_INVALID_BREAK "Invalid 'break'" +#define TXT_INVALID_CHAR_LITERAL "Invalid character literal" +#define TXT_INVALID_CONTINUE "Invalid 'continue'" +#define TXT_INVALID_ESCAPE_SEQUENCE "Invalid escape sequence" +#define TXT_INVALID_EXPRESSION_AMBIGUOUS_NAME "Invalid expression: ambiguous name" +#define TXT_INVALID_EXPRESSION_LAMBDA "Invalid expression: stand-alone anonymous function" +#define TXT_INVALID_OP_ON_METHOD "Invalid operation on method" +#define TXT_INVALID_REF_PROP_ACCESS "Invalid reference. Property accessors cannot be used in combined read/write operations" +#define TXT_INVALID_SCOPE "Invalid scope resolution" +#define TXT_INVALID_SIG_FOR_VIRTPROP "Invalid signature for virtual property" +#define TXT_INVALID_TYPE "Invalid type" +#define TXT_INVALID_UNICODE_FORMAT_EXPECTED_d "Invalid unicode escape sequence, expected %d hex digits" +#define TXT_INVALID_UNICODE_VALUE "Invalid unicode code point" +#define TXT_INVALID_UNICODE_SEQUENCE_IN_SRC "Invalid unicode sequence in source" +#define TXT_INVALID_USE_OF_NAMED_ARGS "Invalid use of named arguments" + +#define TXT_MEMBER_s_ACCESSED_BEFORE_INIT "The member '%s' is accessed before the initialization" +#define TXT_METHOD_CANNOT_OVERRIDE_s "Method '%s' declared as final and cannot be overridden" +#define TXT_METHOD_CANT_HAVE_NAME_OF_CLASS "The method cannot be named with the class name" +#define TXT_METHOD_s_DOES_NOT_OVERRIDE "Method '%s' marked as override but does not replace any base class or interface method" +#define TXT_METHOD_s_s_HAS_NO_RETURN_TYPE "Method '%s::%s' is missing the return type, nor is it the same name as object to be a constructor" +#define TXT_METHOD_s_NOT_PART_OF_OBJECT_s "Method '%s' is not part of object '%s'" +#define TXT_MISSING_ARGUMENT_s "Rejected due to named parameter '%s' missing" +#define TXT_MISSING_IMPLEMENTATION_OF_s "Missing implementation of '%s'" +#define TXT_MISSING_DEFINITION_OF_s "Missing definition of '%s'" +#define TXT_MISSING_OR_INVALID_DEFINITON_OF_s "Missing or invalid definition of '%s'" +#define TXT_MIXIN_CANNOT_BE_DECLARED_AS_s "Mixin class cannot be declared as '%s'" +#define TXT_MIXIN_CANNOT_HAVE_CONSTRUCTOR "Mixin classes cannot have constructors or destructors" +#define TXT_MIXIN_CLASS_CANNOT_INHERIT "Mixin class cannot inherit from classes" +#define TXT_MIXIN_CANNOT_HAVE_CHILD_TYPES "Mixin classes cannot have child types" +#define TXT_MORE_THAN_ONE_MATCHING_OP "Found more than one matching operator" +#define TXT_MULTIPLE_MATCHING_SIGNATURES_TO_s "Multiple matching signatures to '%s'" +#define TXT_MULTIPLE_PROP_GET_ACCESSOR_FOR_s "Found multiple get accessors for property '%s'" +#define TXT_MULTIPLE_PROP_SET_ACCESSOR_FOR_s "Found multiple set accessors for property '%s'" +#define TXT_MULTILINE_STRINGS_NOT_ALLOWED "Multiline strings are not allowed in this application" +#define TXT_MUST_BE_OBJECT "Only objects have constructors" +#define TXT_MUST_RETURN_VALUE "Must return a value" + +#define TXT_NAMESPACE_s_DOESNT_EXIST "Namespace '%s' doesn't exist." +#define TXT_NAME_CONFLICT_s_EXTENDED_TYPE "Name conflict. '%s' is an extended data type." +#define TXT_NAME_CONFLICT_s_GLOBAL_PROPERTY "Name conflict. '%s' is a global property." +#define TXT_NAME_CONFLICT_s_IS_NAMED_TYPE "Name conflict. '%s' is a named type." +#define TXT_NAME_CONFLICT_s_IS_FUNCDEF "Name conflict. '%s' is a funcdef." +#define TXT_NAME_CONFLICT_s_IS_FUNCTION "Name conflict. '%s' is a global function." +#define TXT_NAME_CONFLICT_s_IS_MIXIN "Name conflict. '%s' is a mixin class." +#define TXT_NAME_CONFLICT_s_IS_VIRTPROP "Name conflict. '%s' is a virtual property." +#define TXT_NAME_CONFLICT_s_STRUCT "Name conflict. '%s' is a class." +#define TXT_NAME_CONFLICT_s_INTF "Name conflict. '%s' is an interface." +#define TXT_NAME_CONFLICT_s_OBJ_PROPERTY "Name conflict. '%s' is an object property." +#define TXT_NAME_CONFLICT_s_METHOD "Name conflict. '%s' is a class method." +#define TXT_NAME_CONFLICT_s_ALREADY_USED "Name conflict. '%s' is already used." +#define TXT_NAMED_ARGS_WITH_OLD_SYNTAX "Detected named argument with old syntax" +#define TXT_NO_APPROPRIATE_INDEX_OPERATOR "No appropriate indexing operator found" +#define TXT_NO_APPROPRIATE_OPHNDLASSIGN_s "No appropriate opHndlAssign method found in '%s' for handle assignment" +#define TXT_NO_APPROPRIATE_OPEQUALS "No appropriate opEquals method found" +#define TXT_NO_CONVERSION_s_TO_s "No conversion from '%s' to '%s' available." +#define TXT_NO_CONVERSION_s_TO_MATH_TYPE "No conversion from '%s' to math type available." +#define TXT_NO_DEFAULT_ARRAY_TYPE "The application doesn't support the default array type." +#define TXT_NO_DEFAULT_CONSTRUCTOR_FOR_s "No default constructor for object of type '%s'." +#define TXT_NO_DEFAULT_COPY_OP_FOR_s "No appropriate opAssign method found in '%s' for value assignment" +#define TXT_NO_COPY_CONSTRUCTOR_FOR_s "No copy constructor for object of type '%s'." +#define TXT_NO_MATCHING_SIGNATURES_TO_s "No matching signatures to '%s'" +#define TXT_NO_MATCHING_OP_FOUND_FOR_TYPE_s "No matching operator that takes the type '%s' found" #define TXT_NO_MATCHING_OP_FOUND_FOR_TYPES_s_AND_s "No matching operator that takes the types '%s' and '%s' found" -#define TXT_NO_MATCHING_SYMBOL_s "No matching symbol '%s'" -#define TXT_NON_CONST_METHOD_ON_CONST_OBJ "Non-const method call on read-only object reference" -#define TXT_NONTERMINATED_STRING "Non-terminated string literal" -#define TXT_NOT_A_FUNC_s_IS_TYPE_s "Expression doesn't form a function call. '%s' evaluates to the non-function type '%s'" -#define TXT_NOT_ALL_PATHS_RETURN "Not all paths return a value" -#define TXT_NOT_ENOUGH_ARGUMENTS "Rejected due to not enough parameters" -#define TXT_NOT_ENOUGH_VALUES_FOR_LIST "Not enough values to match pattern" -#define TXT_s_NOT_DECLARED "'%s' is not declared" -#define TXT_NOT_EXACT "Implicit conversion of value is not exact" -#define TXT_s_NOT_A_FOREACH_TYPE "Type '%s' is not valid type for foreach loops" -#define TXT_s_NOT_INITIALIZED "'%s' is not initialized." -#define TXT_NOT_LVALUE "Expression is not an l-value" -#define TXT_s_NOT_MEMBER_OF_s "'%s' is not a member of '%s'" -#define TXT_NOT_VALID_REFERENCE "Not a valid reference" -#define TXT_NOT_VALID_LVALUE "Not a valid lvalue" -#define TXT_NOTHING_WAS_BUILT "Nothing was built in the module" -#define TXT_AMBIGUOUS_SYMBOL_NAME_s "Ambiguous symbol name '%s'" - -#define TXT_OBJECT_DOESNT_SUPPORT_INDEX_OP "Type '%s' doesn't support the indexing operator" -#define TXT_OBJECT_HANDLE_NOT_SUPPORTED "Object handle is not supported for this type" -#define TXT_ONLY_OBJECTS_MAY_USE_REF_INOUT "Only object types that support object handles can use &inout. Use &in or &out instead" -#define TXT_ONLY_ONE_ARGUMENT_IN_CAST "A cast operator has one argument" -#define TXT_ONLY_ONE_FUNCTION_ALLOWED "The code must contain one and only one function" -#define TXT_ONLY_ONE_VARIABLE_ALLOWED "The code must contain one and only one global variable" -#define TXT_OPERANDS_MUST_BE_HANDLES "Both operands must be handles when comparing identity" -#define TXT_OVERLOAD_CONFLICTS_DUE_TO_DEFAULT_ARGS "The overloaded functions are identical on initial parameters without default arguments" - -#define TXT_PARAMETER_ALREADY_DECLARED "Parameter already declared" -#define TXT_PARAMETER_CANT_BE_s "Parameter type can't be '%s', because the type cannot be instantiated." -#define TXT_POS_ARG_AFTER_NAMED_ARG "Positional arguments cannot be passed after named arguments" +#define TXT_NO_MATCHING_SYMBOL_s "No matching symbol '%s'" +#define TXT_NON_CONST_METHOD_ON_CONST_OBJ "Non-const method call on read-only object reference" +#define TXT_NONTERMINATED_STRING "Non-terminated string literal" +#define TXT_NOT_A_FUNC_s_IS_TYPE_s "Expression doesn't form a function call. '%s' evaluates to the non-function type '%s'" +#define TXT_NOT_ALL_PATHS_RETURN "Not all paths return a value" +#define TXT_NOT_ENOUGH_ARGUMENTS "Rejected due to not enough parameters" +#define TXT_NOT_ENOUGH_VALUES_FOR_LIST "Not enough values to match pattern" +#define TXT_s_NOT_DECLARED "'%s' is not declared" +#define TXT_NOT_EXACT "Implicit conversion of value is not exact" +#define TXT_s_NOT_A_FOREACH_TYPE "Type '%s' is not valid type for foreach loops" +#define TXT_s_NOT_INITIALIZED "'%s' is not initialized." +#define TXT_NOT_LVALUE "Expression is not an l-value" +#define TXT_s_NOT_MEMBER_OF_s "'%s' is not a member of '%s'" +#define TXT_NOT_VALID_REFERENCE "Not a valid reference" +#define TXT_NOT_VALID_LVALUE "Not a valid lvalue" +#define TXT_NOTHING_WAS_BUILT "Nothing was built in the module" +#define TXT_AMBIGUOUS_SYMBOL_NAME_s "Ambiguous symbol name '%s'" + +#define TXT_OBJECT_DOESNT_SUPPORT_INDEX_OP "Type '%s' doesn't support the indexing operator" +#define TXT_OBJECT_HANDLE_NOT_SUPPORTED "Object handle is not supported for this type" +#define TXT_ONLY_OBJECTS_MAY_USE_REF_INOUT "Only object types that support object handles can use &inout. Use &in or &out instead" +#define TXT_ONLY_ONE_ARGUMENT_IN_CAST "A cast operator has one argument" +#define TXT_ONLY_ONE_FUNCTION_ALLOWED "The code must contain one and only one function" +#define TXT_ONLY_ONE_VARIABLE_ALLOWED "The code must contain one and only one global variable" +#define TXT_OPERANDS_MUST_BE_HANDLES "Both operands must be handles when comparing identity" +#define TXT_OVERLOAD_CONFLICTS_DUE_TO_DEFAULT_ARGS "The overloaded functions are identical on initial parameters without default arguments" + +#define TXT_PARAMETER_ALREADY_DECLARED "Parameter already declared" +#define TXT_PARAMETER_CANT_BE_s "Parameter type can't be '%s', because the type cannot be instantiated." +#define TXT_POS_ARG_AFTER_NAMED_ARG "Positional arguments cannot be passed after named arguments" #define TXT_POTENTIAL_MATCHING_NON_CONST_METHOD_HIDDEN "Potentially matching non-const method is hidden on read-only object reference" -#define TXT_PREV_ERROR_WHILE_COMP_LIST_FOR_TYPE_s "Previous error occurred while attempting to compile initialization list for type '%s'" -#define TXT_PRIVATE_METHOD_CALL_s "Illegal call to private method '%s'" -#define TXT_PRIVATE_PROP_ACCESS_s "Illegal access to private property '%s'" -#define TXT_PROTECTED_METHOD_CALL_s "Illegal call to protected method '%s'" -#define TXT_PROTECTED_PROP_ACCESS_s "Illegal access to protected property '%s'" -#define TXT_PROP_ACCESS_WITH_INDEX_ONE_ARG "Property accessor with index must have 1 and only 1 index argument" -#define TXT_PROPERTY_ACCESSOR_DISABLED "Property accessors have been disabled by the application" -#define TXT_PROPERTY_ACCESSOR_MUST_BE_IMPLEMENTED "Property accessor must be implemented" -#define TXT_PROPERTY_CANT_BE_CONST "Class properties cannot be declared as const" -#define TXT_PROPERTY_HAS_NO_GET_ACCESSOR "The property has no get accessor" -#define TXT_PROPERTY_HAS_NO_SET_ACCESSOR "The property has no set accessor" -#define TXT_PROPERTY_WITHOUT_ACCESSOR "Virtual property must have at least one get or set accessor" - -#define TXT_REF_CANT_BE_TO_LOCAL_VAR "Resulting reference cannot be returned. Returned references must not refer to local variables." +#define TXT_PREV_ERROR_WHILE_COMP_LIST_FOR_TYPE_s "Previous error occurred while attempting to compile initialization list for type '%s'" +#define TXT_PRIVATE_METHOD_CALL_s "Illegal call to private method '%s'" +#define TXT_PRIVATE_PROP_ACCESS_s "Illegal access to private property '%s'" +#define TXT_PROTECTED_METHOD_CALL_s "Illegal call to protected method '%s'" +#define TXT_PROTECTED_PROP_ACCESS_s "Illegal access to protected property '%s'" +#define TXT_PROP_ACCESS_WITH_INDEX_ONE_ARG "Property accessor with index must have 1 and only 1 index argument" +#define TXT_PROPERTY_ACCESSOR_DISABLED "Property accessors have been disabled by the application" +#define TXT_PROPERTY_ACCESSOR_MUST_BE_IMPLEMENTED "Property accessor must be implemented" +#define TXT_PROPERTY_CANT_BE_CONST "Class properties cannot be declared as const" +#define TXT_PROPERTY_HAS_NO_GET_ACCESSOR "The property has no get accessor" +#define TXT_PROPERTY_HAS_NO_SET_ACCESSOR "The property has no set accessor" +#define TXT_PROPERTY_WITHOUT_ACCESSOR "Virtual property must have at least one get or set accessor" + +#define TXT_REF_CANT_BE_TO_LOCAL_VAR "Resulting reference cannot be returned. Returned references must not refer to local variables." #define TXT_REF_CANT_BE_RETURNED_DEFERRED_PARAM "Resulting reference cannot be returned. There are deferred arguments that may invalidate it." -#define TXT_REF_CANT_BE_RETURNED_LOCAL_VARS "Resulting reference cannot be returned. The expression uses objects that during cleanup may invalidate it." -#define TXT_REF_IS_READ_ONLY "Reference is read-only" -#define TXT_REF_IS_TEMP "Reference is temporary" -#define TXT_REF_TYPE_CANT_BE_PASSED_BY_VAL "Reference types cannot be passed by value in function parameters" -#define TXT_REF_TYPE_CANT_BE_RETURNED_BY_VAL "Reference types cannot be returned by value from functions" -#define TXT_RETURN_CANT_BE_s "Return type can't be '%s'" - -#define TXT_SHARED_CANNOT_ACCESS_NON_SHARED_VAR_s "Shared code cannot access non-shared global variable '%s'" -#define TXT_SHARED_CANNOT_CALL_NON_SHARED_FUNC_s "Shared code cannot call non-shared function '%s'" -#define TXT_SHARED_CANNOT_IMPLEMENT_NON_SHARED_s "Shared type cannot implement non-shared interface '%s'" -#define TXT_SHARED_CANNOT_INHERIT_FROM_NON_SHARED_s "Shared class cannot inherit from non-shared class '%s'" -#define TXT_SHARED_CANNOT_USE_NON_SHARED_TYPE_s "Shared code cannot use non-shared type '%s'" -#define TXT_SHARED_s_DOESNT_MATCH_ORIGINAL_s "Shared type '%s' doesn't match the declaration in module '%s'" -#define TXT_SECTION_IS_EMPTY "The script section is empty" -#define TXT_SIGNED_UNSIGNED_MISMATCH "Signed/Unsigned mismatch" -#define TXT_STRINGS_NOT_RECOGNIZED "Strings are not recognized by the application" -#define TXT_SWITCH_CASE_MUST_BE_CONSTANT "Case expressions must be literal constants" -#define TXT_SWITCH_MUST_BE_INTEGRAL "Switch expressions must be integral numbers" - -#define TXT_TMPL_s_EXPECTS_d_SUBTYPES "Template '%s' expects %d sub type(s)" -#define TXT_TOO_MANY_ARGUMENTS "Rejected due to too many parameters" -#define TXT_TOO_MANY_JUMP_LABELS "The function has too many jump labels to handle. Split the function into smaller ones." -#define TXT_TOO_MANY_VALUES_FOR_LIST "Too many values to match pattern" -#define TXT_TYPE_s_CANNOT_BE_REFERENCE "Type '%s' cannot be a reference" -#define TXT_TYPE_s_NOT_AVAILABLE_FOR_MODULE "Type '%s' is not available for this module" -#define TXT_TYPE_s_NOT_TEMPLATE "Type '%s' is not a template type" - -#define TXT_UNEXPECTED_END_OF_FILE "Unexpected end of file" -#define TXT_UNEXPECTED_TOKEN_s "Unexpected token '%s'" -#define TXT_UNEXPECTED_VAR_DECL "Unexpected variable declaration" -#define TXT_UNINITIALIZED_GLOBAL_VAR_s "Use of uninitialized global variable '%s'." -#define TXT_UNKNOWN_SCOPE_s "Unknown scope '%s'" -#define TXT_UNREACHABLE_CODE "Unreachable code" +#define TXT_REF_CANT_BE_RETURNED_LOCAL_VARS "Resulting reference cannot be returned. The expression uses objects that during cleanup may invalidate it." +#define TXT_REF_IS_READ_ONLY "Reference is read-only" +#define TXT_REF_IS_TEMP "Reference is temporary" +#define TXT_REF_TYPE_CANT_BE_PASSED_BY_VAL "Reference types cannot be passed by value in function parameters" +#define TXT_REF_TYPE_CANT_BE_RETURNED_BY_VAL "Reference types cannot be returned by value from functions" +#define TXT_RETURN_CANT_BE_s "Return type can't be '%s'" + +#define TXT_SHARED_CANNOT_ACCESS_NON_SHARED_VAR_s "Shared code cannot access non-shared global variable '%s'" +#define TXT_SHARED_CANNOT_CALL_NON_SHARED_FUNC_s "Shared code cannot call non-shared function '%s'" +#define TXT_SHARED_CANNOT_IMPLEMENT_NON_SHARED_s "Shared type cannot implement non-shared interface '%s'" +#define TXT_SHARED_CANNOT_INHERIT_FROM_NON_SHARED_s "Shared class cannot inherit from non-shared class '%s'" +#define TXT_SHARED_CANNOT_USE_NON_SHARED_TYPE_s "Shared code cannot use non-shared type '%s'" +#define TXT_SHARED_s_DOESNT_MATCH_ORIGINAL_s "Shared type '%s' doesn't match the declaration in module '%s'" +#define TXT_SECTION_IS_EMPTY "The script section is empty" +#define TXT_SIGNED_UNSIGNED_MISMATCH "Signed/Unsigned mismatch" +#define TXT_STRINGS_NOT_RECOGNIZED "Strings are not recognized by the application" +#define TXT_SWITCH_CASE_MUST_BE_CONSTANT "Case expressions must be literal constants" +#define TXT_SWITCH_MUST_BE_INTEGRAL "Switch expressions must be integral numbers" + +#define TXT_TMPL_s_EXPECTS_d_SUBTYPES "Template '%s' expects %d sub type(s)" +#define TXT_TOO_MANY_ARGUMENTS "Rejected due to too many parameters" +#define TXT_TOO_MANY_JUMP_LABELS "The function has too many jump labels to handle. Split the function into smaller ones." +#define TXT_TOO_MANY_VALUES_FOR_LIST "Too many values to match pattern" +#define TXT_TYPE_s_CANNOT_BE_REFERENCE "Type '%s' cannot be a reference" +#define TXT_TYPE_s_NOT_AVAILABLE_FOR_MODULE "Type '%s' is not available for this module" +#define TXT_TYPE_s_NOT_TEMPLATE "Type '%s' is not a template type" + +#define TXT_UNEXPECTED_END_OF_FILE "Unexpected end of file" +#define TXT_UNEXPECTED_TOKEN_s "Unexpected token '%s'" +#define TXT_UNEXPECTED_VAR_DECL "Unexpected variable declaration" +#define TXT_UNINITIALIZED_GLOBAL_VAR_s "Use of uninitialized global variable '%s'." +#define TXT_UNKNOWN_SCOPE_s "Unknown scope '%s'" +#define TXT_UNREACHABLE_CODE "Unreachable code" #define TXT_UNRECOGNIZED_VIRTUAL_PROPERTY_NODE "Virtual property contains unrecognized aspect" -#define TXT_UNUSED_SCRIPT_NODE "Unused script node" +#define TXT_UNUSED_SCRIPT_NODE "Unused script node" -#define TXT_VALUE_TOO_LARGE_FOR_TYPE "Value is too large for data type" -#define TXT_VOID_CANT_BE_OPERAND "Void cannot be an operand in expressions" +#define TXT_VALUE_TOO_LARGE_FOR_TYPE "Value is too large for data type" +#define TXT_VOID_CANT_BE_OPERAND "Void cannot be an operand in expressions" -#define TXT_WARNINGS_TREATED_AS_ERROR "Warnings are treated as errors by the application" -#define TXT_WHERE_s_IS_s "Where '%s' is '%s'" -#define TXT_WHILE_PARSING_ARG_LIST "While parsing argument list" -#define TXT_WHILE_PARSING_EXPRESSION "While parsing expression" -#define TXT_WHILE_PARSING_INIT_LIST "While parsing initialization list" -#define TXT_WHILE_PARSING_NAMESPACE "While parsing namespace" +#define TXT_WARNINGS_TREATED_AS_ERROR "Warnings are treated as errors by the application" +#define TXT_WHERE_s_IS_s "Where '%s' is '%s'" +#define TXT_WHILE_PARSING_ARG_LIST "While parsing argument list" +#define TXT_WHILE_PARSING_EXPRESSION "While parsing expression" +#define TXT_WHILE_PARSING_INIT_LIST "While parsing initialization list" +#define TXT_WHILE_PARSING_NAMESPACE "While parsing namespace" #define TXT_WHILE_PARSING_STATEMENT_BLOCK "While parsing statement block" -#define TXT_WHILE_INCLUDING_MIXIN "Previous error occurred while including mixin" +#define TXT_WHILE_INCLUDING_MIXIN "Previous error occurred while including mixin" // Global variable initialization -#define TXT_FAILED_TO_INITIALIZE_s "Failed to initialize global variable '%s'" -#define TXT_EXCEPTION_s_IN_s "Exception '%s' in '%s'" +#define TXT_FAILED_TO_INITIALIZE_s "Failed to initialize global variable '%s'" +#define TXT_EXCEPTION_s_IN_s "Exception '%s' in '%s'" // Engine message -#define TXT_AUTOHANDLE_CANNOT_BE_USED_FOR_NOCOUNT "Autohandles cannot be used with types that have been registered with NOCOUNT" +#define TXT_AUTOHANDLE_CANNOT_BE_USED_FOR_NOCOUNT "Autohandles cannot be used with types that have been registered with NOCOUNT" #define TXT_FIRST_PARAM_MUST_BE_REF_FOR_TEMPLATE_FACTORY "First parameter to template factory must be a reference. This will be used to pass the object type of the template" -#define TXT_INVALID_CONFIGURATION "Invalid configuration. Verify the registered application interface." -#define TXT_VALUE_TYPE_MUST_HAVE_SIZE "A value type must be registered with a non-zero size" -#define TXT_TYPE_s_IS_MISSING_BEHAVIOURS "Type '%s' is missing behaviours" -#define TXT_ILLEGAL_BEHAVIOUR_FOR_TYPE "The behaviour is not compatible with the type" -#define TXT_GC_REQUIRE_ADD_REL_GC_BEHAVIOUR "A garbage collected ref type must have the addref, release, and all gc behaviours" -#define TXT_VALUE_GC_REQUIRE_GC_BEHAVIOUR "A garbage collected value type must have the gc enum references behaviour" -#define TXT_SCOPE_REQUIRE_REL_BEHAVIOUR "A scoped reference type must have the release behaviour" -#define TXT_REF_REQUIRE_ADD_REL_BEHAVIOUR "A reference type must have the addref and release behaviours" -#define TXT_NON_POD_REQUIRE_CONSTR_DESTR_BEHAVIOUR "A non-pod value type must have at least one constructor and the destructor behaviours" -#define TXT_CANNOT_PASS_TYPE_s_BY_VAL "Can't pass type '%s' by value unless the application type is informed in the registration" -#define TXT_CANNOT_RET_TYPE_s_BY_VAL "Can't return type '%s' by value unless the application type is informed in the registration" +#define TXT_INVALID_CONFIGURATION "Invalid configuration. Verify the registered application interface." +#define TXT_VALUE_TYPE_MUST_HAVE_SIZE "A value type must be registered with a non-zero size" +#define TXT_TYPE_s_IS_MISSING_BEHAVIOURS "Type '%s' is missing behaviours" +#define TXT_ILLEGAL_BEHAVIOUR_FOR_TYPE "The behaviour is not compatible with the type" +#define TXT_GC_REQUIRE_ADD_REL_GC_BEHAVIOUR "A garbage collected ref type must have the addref, release, and all gc behaviours" +#define TXT_VALUE_GC_REQUIRE_GC_BEHAVIOUR "A garbage collected value type must have the gc enum references behaviour" +#define TXT_SCOPE_REQUIRE_REL_BEHAVIOUR "A scoped reference type must have the release behaviour" +#define TXT_REF_REQUIRE_ADD_REL_BEHAVIOUR "A reference type must have the addref and release behaviours" +#define TXT_NON_POD_REQUIRE_CONSTR_DESTR_BEHAVIOUR "A non-pod value type must have at least one constructor and the destructor behaviours" +#define TXT_CANNOT_PASS_TYPE_s_BY_VAL "Can't pass type '%s' by value unless the application type is informed in the registration" +#define TXT_CANNOT_RET_TYPE_s_BY_VAL "Can't return type '%s' by value unless the application type is informed in the registration" // TODO: Should be something like "This platform requires that AngelScript knows the exact content of the type '%s' in order to pass by value to application in native calling convention" -#define TXT_DONT_SUPPORT_TYPE_s_BY_VAL "Don't support passing type '%s' by value to application in native calling convention on this platform" +#define TXT_DONT_SUPPORT_TYPE_s_BY_VAL "Don't support passing type '%s' by value to application in native calling convention on this platform" // TODO: Should be something like "This platform requires that AngelScript knows the exact content of the type '%s' in order to return by value from application in native calling convention" -#define TXT_DONT_SUPPORT_RET_TYPE_s_BY_VAL "Don't support returning type '%s' by value from application in native calling convention on this platform" -#define TXT_d_GC_CANNOT_FREE_OBJ_OF_TYPE_s "Object {%d}. GC cannot destroy an object of type '%s' as it doesn't know how many references to there are." -#define TXT_d_GC_CANNOT_FREE_OBJ_OF_TYPE_s_REF_COUNT_d "Object {%d}. GC cannot destroy an object of type '%s' as it can't see all references. Current ref count is %d." -#define TXT_OBJECT_TYPE_s_DOESNT_EXIST "Object type '%s' doesn't exist" -#define TXT_TEMPLATE_s_ALREADY_GENERATED_CANT_REGISTER "Cannot register. The template type instance '%s' has already been generated." -#define TXT_TEMPLATE_TYPE_s_DOESNT_EXIST "Template type '%s' doesn't exist" -#define TXT_TEMPLATE_SUBTYPE_s_DOESNT_EXIST "Template subtype '%s' doesn't exist" -#define TXT_TEMPLATE_LIST_FACTORY_EXPECTS_2_REF_PARAMS "Template list factory expects two reference parameters. The last is the pointer to the initialization buffer" -#define TXT_LIST_FACTORY_EXPECTS_1_REF_PARAM "List factory expects only one reference parameter. The pointer to the initialization buffer will be passed in this parameter" -#define TXT_FAILED_READ_SUBTYPE_OF_TEMPLATE_s "Failed to read subtype of template type '%s'" -#define TXT_FAILED_IN_FUNC_s_s_d "Failed in call to function '%s' (Code: %s, %d)" -#define TXT_FAILED_IN_FUNC_s_WITH_s_s_d "Failed in call to function '%s' with '%s' (Code: %s, %d)" -#define TXT_FAILED_IN_FUNC_s_WITH_s_AND_s_s_d "Failed in call to function '%s' with '%s' and '%s' (Code: %s, %d)" -#define TXT_GC_RECEIVED_NULL_PTR "AddScriptObjectToGC called with null pointer" -#define TXT_EXCEPTION_IN_NESTED_CALL "An exception occurred in a nested call" -#define TXT_TYPE_s_IS_STILL_USED_BY_FUNC_s "Type '%s' is still used by function '%s'" -#define TXT_PREV_TYPE_IS_NAMED_s "The builtin type in previous message is named '%s'" -#define TXT_PREV_FUNC_IS_NAMED_s_TYPE_IS_d "The function in previous message is named '%s'. The func type is %d" -#define TXT_RESURRECTING_SCRIPTOBJECT_s "The script object of type '%s' is being resurrected illegally during destruction" -#define TXT_INVALID_BYTECODE_d "LoadByteCode failed. The bytecode is invalid. Number of bytes read from stream: %d" -#define TXT_NO_JIT_IN_FUNC_s "Function '%s' appears to have been compiled without JIT entry points" -#define TXT_ENGINE_REF_COUNT_ERROR_DURING_SHUTDOWN "Uh oh! The engine's reference count is increasing while it is being destroyed. Make sure references needed for clean-up are immediately released" -#define TXT_MODULE_IS_IN_USE "The module is still in use and cannot be rebuilt. Discard it and request another module" -#define TXT_EXTRNL_REF_TO_MODULE_s "There is an external reference to an object in module '%s', preventing it from being deleted" -#define TXT_FUNC_s_RELEASED_BEFORE_CLEANUP "The engine was shutdown before the context released. Function '%s' cannot be cleaned up" +#define TXT_DONT_SUPPORT_RET_TYPE_s_BY_VAL "Don't support returning type '%s' by value from application in native calling convention on this platform" +#define TXT_d_GC_CANNOT_FREE_OBJ_OF_TYPE_s "Object {%d}. GC cannot destroy an object of type '%s' as it doesn't know how many references to there are." +#define TXT_d_GC_CANNOT_FREE_OBJ_OF_TYPE_s_REF_COUNT_d "Object {%d}. GC cannot destroy an object of type '%s' as it can't see all references. Current ref count is %d." +#define TXT_OBJECT_TYPE_s_DOESNT_EXIST "Object type '%s' doesn't exist" +#define TXT_TEMPLATE_s_ALREADY_GENERATED_CANT_REGISTER "Cannot register. The template type instance '%s' has already been generated." +#define TXT_TEMPLATE_TYPE_s_DOESNT_EXIST "Template type '%s' doesn't exist" +#define TXT_TEMPLATE_SUBTYPE_s_DOESNT_EXIST "Template subtype '%s' doesn't exist" +#define TXT_TEMPLATE_LIST_FACTORY_EXPECTS_2_REF_PARAMS "Template list factory expects two reference parameters. The last is the pointer to the initialization buffer" +#define TXT_LIST_FACTORY_EXPECTS_1_REF_PARAM "List factory expects only one reference parameter. The pointer to the initialization buffer will be passed in this parameter" +#define TXT_FAILED_READ_SUBTYPE_OF_TEMPLATE_s "Failed to read subtype of template type '%s'" +#define TXT_FAILED_IN_FUNC_s_s_d "Failed in call to function '%s' (Code: %s, %d)" +#define TXT_FAILED_IN_FUNC_s_WITH_s_s_d "Failed in call to function '%s' with '%s' (Code: %s, %d)" +#define TXT_FAILED_IN_FUNC_s_WITH_s_AND_s_s_d "Failed in call to function '%s' with '%s' and '%s' (Code: %s, %d)" +#define TXT_GC_RECEIVED_NULL_PTR "AddScriptObjectToGC called with null pointer" +#define TXT_EXCEPTION_IN_NESTED_CALL "An exception occurred in a nested call" +#define TXT_TYPE_s_IS_STILL_USED_BY_FUNC_s "Type '%s' is still used by function '%s'" +#define TXT_PREV_TYPE_IS_NAMED_s "The builtin type in previous message is named '%s'" +#define TXT_PREV_FUNC_IS_NAMED_s_TYPE_IS_d "The function in previous message is named '%s'. The func type is %d" +#define TXT_RESURRECTING_SCRIPTOBJECT_s "The script object of type '%s' is being resurrected illegally during destruction" +#define TXT_INVALID_BYTECODE_d "LoadByteCode failed. The bytecode is invalid. Number of bytes read from stream: %d" +#define TXT_NO_JIT_IN_FUNC_s "Function '%s' appears to have been compiled without JIT entry points" +#define TXT_ENGINE_REF_COUNT_ERROR_DURING_SHUTDOWN "Uh oh! The engine's reference count is increasing while it is being destroyed. Make sure references needed for clean-up are immediately released" +#define TXT_MODULE_IS_IN_USE "The module is still in use and cannot be rebuilt. Discard it and request another module" +#define TXT_EXTRNL_REF_TO_MODULE_s "There is an external reference to an object in module '%s', preventing it from being deleted" +#define TXT_FUNC_s_RELEASED_BEFORE_CLEANUP "The engine was shutdown before the context released. Function '%s' cannot be cleaned up" // Internal names -#define TXT_PROPERTY "Property" -#define TXT_SYSTEM_FUNCTION "System function" -#define TXT_VARIABLE_DECL "Variable declaration" +#define TXT_PROPERTY "Property" +#define TXT_SYSTEM_FUNCTION "System function" +#define TXT_VARIABLE_DECL "Variable declaration" // Exceptions -#define TXT_STACK_OVERFLOW "Stack overflow" -#define TXT_NULL_POINTER_ACCESS "Null pointer access" -#define TXT_DIVIDE_BY_ZERO "Divide by zero" -#define TXT_DIVIDE_OVERFLOW "Overflow in integer division" -#define TXT_POW_OVERFLOW "Overflow in exponent operation" -#define TXT_UNRECOGNIZED_BYTE_CODE "Unrecognized byte code" -#define TXT_INVALID_CALLING_CONVENTION "Invalid calling convention" -#define TXT_UNBOUND_FUNCTION "Unbound function called" -#define TXT_OUT_OF_BOUNDS "Out of range" -#define TXT_EXCEPTION_CAUGHT "Caught an exception from the application" -#define TXT_MISMATCH_IN_VALUE_ASSIGN "Mismatching types in value assignment" -#define TXT_TOO_MANY_NESTED_CALLS "Too many nested calls" +#define TXT_STACK_OVERFLOW "Stack overflow" +#define TXT_NULL_POINTER_ACCESS "Null pointer access" +#define TXT_DIVIDE_BY_ZERO "Divide by zero" +#define TXT_DIVIDE_OVERFLOW "Overflow in integer division" +#define TXT_POW_OVERFLOW "Overflow in exponent operation" +#define TXT_UNRECOGNIZED_BYTE_CODE "Unrecognized byte code" +#define TXT_INVALID_CALLING_CONVENTION "Invalid calling convention" +#define TXT_UNBOUND_FUNCTION "Unbound function called" +#define TXT_OUT_OF_BOUNDS "Out of range" +#define TXT_EXCEPTION_CAUGHT "Caught an exception from the application" +#define TXT_MISMATCH_IN_VALUE_ASSIGN "Mismatching types in value assignment" +#define TXT_TOO_MANY_NESTED_CALLS "Too many nested calls" // Error codes #define ERROR_NAME(x) #x -static const char*const errorNames[] = -{ - ERROR_NAME(asSUCCESS), - ERROR_NAME(asERROR), - ERROR_NAME(asCONTEXT_ACTIVE), - ERROR_NAME(asCONTEXT_NOT_FINISHED), - ERROR_NAME(asCONTEXT_NOT_PREPARED), - ERROR_NAME(asINVALID_ARG), - ERROR_NAME(asNO_FUNCTION), - ERROR_NAME(asNOT_SUPPORTED), - ERROR_NAME(asINVALID_NAME), - ERROR_NAME(asNAME_TAKEN), - ERROR_NAME(asINVALID_DECLARATION), - ERROR_NAME(asINVALID_OBJECT), - ERROR_NAME(asINVALID_TYPE), - ERROR_NAME(asALREADY_REGISTERED), - ERROR_NAME(asMULTIPLE_FUNCTIONS), - ERROR_NAME(asNO_MODULE), - ERROR_NAME(asNO_GLOBAL_VAR), - ERROR_NAME(asINVALID_CONFIGURATION), - ERROR_NAME(asINVALID_INTERFACE), - ERROR_NAME(asCANT_BIND_ALL_FUNCTIONS), - ERROR_NAME(asLOWER_ARRAY_DIMENSION_NOT_REGISTERED), - ERROR_NAME(asWRONG_CONFIG_GROUP), - ERROR_NAME(asCONFIG_GROUP_IS_IN_USE), - ERROR_NAME(asILLEGAL_BEHAVIOUR_FOR_TYPE), - ERROR_NAME(asWRONG_CALLING_CONV), - ERROR_NAME(asBUILD_IN_PROGRESS), - ERROR_NAME(asINIT_GLOBAL_VARS_FAILED), - ERROR_NAME(asOUT_OF_MEMORY), - ERROR_NAME(asMODULE_IS_IN_USE) -}; +static const char * const errorNames[] = + { + ERROR_NAME(asSUCCESS), + ERROR_NAME(asERROR), + ERROR_NAME(asCONTEXT_ACTIVE), + ERROR_NAME(asCONTEXT_NOT_FINISHED), + ERROR_NAME(asCONTEXT_NOT_PREPARED), + ERROR_NAME(asINVALID_ARG), + ERROR_NAME(asNO_FUNCTION), + ERROR_NAME(asNOT_SUPPORTED), + ERROR_NAME(asINVALID_NAME), + ERROR_NAME(asNAME_TAKEN), + ERROR_NAME(asINVALID_DECLARATION), + ERROR_NAME(asINVALID_OBJECT), + ERROR_NAME(asINVALID_TYPE), + ERROR_NAME(asALREADY_REGISTERED), + ERROR_NAME(asMULTIPLE_FUNCTIONS), + ERROR_NAME(asNO_MODULE), + ERROR_NAME(asNO_GLOBAL_VAR), + ERROR_NAME(asINVALID_CONFIGURATION), + ERROR_NAME(asINVALID_INTERFACE), + ERROR_NAME(asCANT_BIND_ALL_FUNCTIONS), + ERROR_NAME(asLOWER_ARRAY_DIMENSION_NOT_REGISTERED), + ERROR_NAME(asWRONG_CONFIG_GROUP), + ERROR_NAME(asCONFIG_GROUP_IS_IN_USE), + ERROR_NAME(asILLEGAL_BEHAVIOUR_FOR_TYPE), + ERROR_NAME(asWRONG_CALLING_CONV), + ERROR_NAME(asBUILD_IN_PROGRESS), + ERROR_NAME(asINIT_GLOBAL_VARS_FAILED), + ERROR_NAME(asOUT_OF_MEMORY), + ERROR_NAME(asMODULE_IS_IN_USE)}; #endif diff --git a/sdk/angelscript/source/as_thread.cpp b/sdk/angelscript/source/as_thread.cpp index b68f9bb7..55e75e32 100644 --- a/sdk/angelscript/source/as_thread.cpp +++ b/sdk/angelscript/source/as_thread.cpp @@ -50,8 +50,7 @@ static asCThreadManager *threadManager = 0; //====================================================================== // Global API functions -extern "C" -{ +extern "C" { AS_API int asThreadCleanup() { @@ -104,27 +103,26 @@ AS_API void asReleaseSharedLock() RELEASESHARED(threadManager->appRWLock); } } - } //====================================================================== #if !defined(AS_NO_THREADS) && defined(AS_WINDOWS_THREADS) #if defined(_MSC_VER) && (WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) - __declspec(thread) asCThreadLocalData *asCThreadManager::tld = 0; +__declspec(thread) asCThreadLocalData *asCThreadManager::tld = 0; #else #ifdef AS_WINDOWS_USEFLS - #define WinMTLsAlloc() (asDWORD)FlsAlloc(asCThreadManager::WinFLSCallback); - #define WinMTLsFree(key) FlsFree(key); + #define WinMTLsAlloc() (asDWORD) FlsAlloc(asCThreadManager::WinFLSCallback); + #define WinMTLsFree(key) FlsFree(key); #define WinMTLsSetValue(key, value) FlsSetValue(key, value); #define WinMTLsGetValue(key) FlsGetValue(key); #else - #define WinMTLsAlloc() (asDWORD)TlsAlloc(); + #define WinMTLsAlloc() (asDWORD) TlsAlloc(); #define WinMTLsFree(key) TlsFree(key); #define WinMTLsSetValue(key, value) TlsSetValue(key, value); #define WinMTLsGetValue(key) TlsGetValue(key); #endif - //WinMTLs prefix for Windows Multi-Thread Local Storage. Either Threads or fibers. + //WinMTLs prefix for Windows Multi-Thread Local Storage. Either Threads or fibers. #endif #endif @@ -137,14 +135,14 @@ asCThreadManager::asCThreadManager() #else // Allocate the thread local storage #if defined AS_POSIX_THREADS - pthread_key_t pKey; - pthread_key_create(&pKey, 0); - mtlsKey = (asDWORD)pKey; + pthread_key_t pKey; + pthread_key_create(&pKey, 0); + mtlsKey = (asDWORD)pKey; #elif defined AS_WINDOWS_THREADS #if defined(_MSC_VER) && (WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) - tld = 0; + tld = 0; #else - mtlsKey = WinMTLsAlloc(); + mtlsKey = WinMTLsAlloc(); #endif #endif #endif @@ -177,7 +175,7 @@ int asCThreadManager::Prepare(asIThreadManager *externalThreadMgr) // global thread support functions it is then best to share the thread // manager to make sure all dlls use the same critical section. if( externalThreadMgr ) - threadManager = reinterpret_cast(externalThreadMgr); + threadManager = reinterpret_cast(externalThreadMgr); ENTERCRITICALSECTION(threadManager->criticalSection); threadManager->refCount++; @@ -208,12 +206,12 @@ void asCThreadManager::Unprepare() // with the thread manager we must first clear the global // variable in case a new thread manager needs to be created; asCThreadManager *mgr = threadManager; - threadManager = 0; + threadManager = 0; // Leave the critical section before it is destroyed LEAVECRITICALSECTION(mgr->criticalSection); - asDELETE(mgr,asCThreadManager); + asDELETE(mgr, asCThreadManager); } else LEAVECRITICALSECTION(threadManager->criticalSection); @@ -224,18 +222,18 @@ asCThreadManager::~asCThreadManager() #ifndef AS_NO_THREADS // Deallocate the thread local storage #if defined AS_POSIX_THREADS - pthread_key_delete((pthread_key_t)mtlsKey); + pthread_key_delete((pthread_key_t)mtlsKey); #elif defined AS_WINDOWS_THREADS #if defined(_MSC_VER) && (WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) - tld = 0; + tld = 0; #else - WinMTLsFree(mtlsKey); + WinMTLsFree(mtlsKey); #endif #endif #else if( tld ) { - asDELETE(tld,asCThreadLocalData); + asDELETE(tld, asCThreadLocalData); } tld = 0; #endif @@ -244,8 +242,8 @@ asCThreadManager::~asCThreadManager() #ifdef AS_WINDOWS_USEFLS void asCThreadManager::WinFLSCallback(PVOID lpFlsData) { - asCThreadLocalData* fld = (asCThreadLocalData*)lpFlsData; - if ( fld ) + asCThreadLocalData *fld = (asCThreadLocalData *)lpFlsData; + if( fld ) { asDELETE(fld, asCThreadLocalData); } @@ -258,30 +256,30 @@ int asCThreadManager::CleanupLocalData() return 0; #ifndef AS_NO_THREADS -#if defined AS_POSIX_THREADS - asCThreadLocalData *tld = (asCThreadLocalData*)pthread_getspecific((pthread_key_t)threadManager->mtlsKey); -#elif defined AS_WINDOWS_THREADS - #if !defined(_MSC_VER) || !(WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) - asCThreadLocalData *tld = (asCThreadLocalData*)WinMTLsGetValue((DWORD)threadManager->mtlsKey); + #if defined AS_POSIX_THREADS + asCThreadLocalData *tld = (asCThreadLocalData *)pthread_getspecific((pthread_key_t)threadManager->mtlsKey); + #elif defined AS_WINDOWS_THREADS + #if !defined(_MSC_VER) || !(WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) + asCThreadLocalData *tld = (asCThreadLocalData *)WinMTLsGetValue((DWORD)threadManager->mtlsKey); + #endif #endif -#endif if( tld == 0 ) return 0; if( tld->activeContexts.GetLength() == 0 ) { - asDELETE(tld,asCThreadLocalData); - #if defined AS_POSIX_THREADS - pthread_setspecific((pthread_key_t)threadManager->mtlsKey, 0); - #elif defined AS_WINDOWS_THREADS - #if defined(_MSC_VER) && (WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) - tld = 0; - #else - //ASDelete was called on the TLD. In case we use fibers, setting the value to 0 is necessary to prevent the fiber callback to be called, preventing a duplicate delete. - WinMTLsSetValue((DWORD)threadManager->mtlsKey, 0); - #endif + asDELETE(tld, asCThreadLocalData); + #if defined AS_POSIX_THREADS + pthread_setspecific((pthread_key_t)threadManager->mtlsKey, 0); + #elif defined AS_WINDOWS_THREADS + #if defined(_MSC_VER) && (WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) + tld = 0; + #else + //ASDelete was called on the TLD. In case we use fibers, setting the value to 0 is necessary to prevent the fiber callback to be called, preventing a duplicate delete. + WinMTLsSetValue((DWORD)threadManager->mtlsKey, 0); #endif + #endif return 0; } else @@ -292,7 +290,7 @@ int asCThreadManager::CleanupLocalData() { if( threadManager->tld->activeContexts.GetLength() == 0 ) { - asDELETE(threadManager->tld,asCThreadLocalData); + asDELETE(threadManager->tld, asCThreadLocalData); threadManager->tld = 0; } else @@ -308,26 +306,26 @@ asCThreadLocalData *asCThreadManager::GetLocalData() return 0; #ifndef AS_NO_THREADS -#if defined AS_POSIX_THREADS - asCThreadLocalData *tld = (asCThreadLocalData*)pthread_getspecific((pthread_key_t)threadManager->mtlsKey); + #if defined AS_POSIX_THREADS + asCThreadLocalData *tld = (asCThreadLocalData *)pthread_getspecific((pthread_key_t)threadManager->mtlsKey); if( tld == 0 ) { tld = asNEW(asCThreadLocalData)(); pthread_setspecific((pthread_key_t)threadManager->mtlsKey, tld); } -#elif defined AS_WINDOWS_THREADS - #if defined(_MSC_VER) && (WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) - if( tld == 0 ) - tld = asNEW(asCThreadLocalData)(); - #else - asCThreadLocalData *tld = (asCThreadLocalData*)WinMTLsGetValue((DWORD)threadManager->mtlsKey); - if( tld == 0 ) - { - tld = asNEW(asCThreadLocalData)(); - WinMTLsSetValue((DWORD)threadManager->mtlsKey, tld); - } + #elif defined AS_WINDOWS_THREADS + #if defined(_MSC_VER) && (WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) + if( tld == 0 ) + tld = asNEW(asCThreadLocalData)(); + #else + asCThreadLocalData *tld = (asCThreadLocalData *)WinMTLsGetValue((DWORD)threadManager->mtlsKey); + if( tld == 0 ) + { + tld = asNEW(asCThreadLocalData)(); + WinMTLsSetValue((DWORD)threadManager->mtlsKey, tld); + } + #endif #endif -#endif return tld; #else @@ -353,94 +351,94 @@ asCThreadLocalData::~asCThreadLocalData() #ifndef AS_NO_THREADS asCThreadCriticalSection::asCThreadCriticalSection() { -#if defined AS_POSIX_THREADS + #if defined AS_POSIX_THREADS pthread_mutex_init(&cs, 0); -#elif defined AS_WINDOWS_THREADS -#if defined(_MSC_VER) && (WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) + #elif defined AS_WINDOWS_THREADS + #if defined(_MSC_VER) && (WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) // Only the Ex version is available on Windows Store InitializeCriticalSectionEx(&cs, 4000, 0); -#else + #else // Only the non-Ex version is available on WinXP and older // MinGW also only defines this version InitializeCriticalSection(&cs); -#endif -#endif + #endif + #endif } asCThreadCriticalSection::~asCThreadCriticalSection() { -#if defined AS_POSIX_THREADS + #if defined AS_POSIX_THREADS pthread_mutex_destroy(&cs); -#elif defined AS_WINDOWS_THREADS + #elif defined AS_WINDOWS_THREADS DeleteCriticalSection(&cs); -#endif + #endif } void asCThreadCriticalSection::Enter() { -#if defined AS_POSIX_THREADS + #if defined AS_POSIX_THREADS pthread_mutex_lock(&cs); -#elif defined AS_WINDOWS_THREADS + #elif defined AS_WINDOWS_THREADS EnterCriticalSection(&cs); -#endif + #endif } void asCThreadCriticalSection::Leave() { -#if defined AS_POSIX_THREADS + #if defined AS_POSIX_THREADS pthread_mutex_unlock(&cs); -#elif defined AS_WINDOWS_THREADS + #elif defined AS_WINDOWS_THREADS LeaveCriticalSection(&cs); -#endif + #endif } bool asCThreadCriticalSection::TryEnter() { -#if defined AS_POSIX_THREADS + #if defined AS_POSIX_THREADS return !pthread_mutex_trylock(&cs); -#elif defined AS_WINDOWS_THREADS + #elif defined AS_WINDOWS_THREADS return TryEnterCriticalSection(&cs) ? true : false; -#else + #else return true; -#endif + #endif } asCThreadReadWriteLock::asCThreadReadWriteLock() { -#if defined AS_POSIX_THREADS + #if defined AS_POSIX_THREADS int r = pthread_rwlock_init(&lock, 0); asASSERT( r == 0 ); UNUSED_VAR(r); -#elif defined AS_WINDOWS_THREADS -#if defined(_MSC_VER) && (WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) + #elif defined AS_WINDOWS_THREADS + #if defined(_MSC_VER) && (WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) // Only the Ex versions are available on Windows Store // Create a semaphore to allow up to maxReaders simultaneous readers readLocks = CreateSemaphoreExW(NULL, maxReaders, maxReaders, 0, 0, 0); // Create a critical section to synchronize writers InitializeCriticalSectionEx(&writeLock, 4000, 0); -#else + #else readLocks = CreateSemaphoreW(NULL, maxReaders, maxReaders, 0); InitializeCriticalSection(&writeLock); -#endif -#endif + #endif + #endif } asCThreadReadWriteLock::~asCThreadReadWriteLock() { -#if defined AS_POSIX_THREADS + #if defined AS_POSIX_THREADS pthread_rwlock_destroy(&lock); -#elif defined AS_WINDOWS_THREADS + #elif defined AS_WINDOWS_THREADS DeleteCriticalSection(&writeLock); CloseHandle(readLocks); -#endif + #endif } void asCThreadReadWriteLock::AcquireExclusive() { -#if defined AS_POSIX_THREADS + #if defined AS_POSIX_THREADS pthread_rwlock_wrlock(&lock); -#elif defined AS_WINDOWS_THREADS + #elif defined AS_WINDOWS_THREADS // Synchronize writers, so only one tries to lock out the readers EnterCriticalSection(&writeLock); @@ -454,37 +452,37 @@ void asCThreadReadWriteLock::AcquireExclusive() // Allow another writer to lock. It will only be able to // lock the readers when this writer releases them anyway. LeaveCriticalSection(&writeLock); -#endif + #endif } void asCThreadReadWriteLock::ReleaseExclusive() { -#if defined AS_POSIX_THREADS + #if defined AS_POSIX_THREADS pthread_rwlock_unlock(&lock); -#elif defined AS_WINDOWS_THREADS + #elif defined AS_WINDOWS_THREADS // Release all readers at once ReleaseSemaphore(readLocks, maxReaders, 0); -#endif + #endif } void asCThreadReadWriteLock::AcquireShared() { -#if defined AS_POSIX_THREADS + #if defined AS_POSIX_THREADS pthread_rwlock_rdlock(&lock); -#elif defined AS_WINDOWS_THREADS + #elif defined AS_WINDOWS_THREADS // Lock a reader slot WaitForSingleObjectEx(readLocks, INFINITE, FALSE); -#endif + #endif } void asCThreadReadWriteLock::ReleaseShared() { -#if defined AS_POSIX_THREADS + #if defined AS_POSIX_THREADS pthread_rwlock_unlock(&lock); -#elif defined AS_WINDOWS_THREADS + #elif defined AS_WINDOWS_THREADS // Release the reader slot ReleaseSemaphore(readLocks, 1, 0); -#endif + #endif } #endif @@ -492,4 +490,3 @@ void asCThreadReadWriteLock::ReleaseShared() //======================================================================== END_AS_NAMESPACE - diff --git a/sdk/angelscript/source/as_thread.h b/sdk/angelscript/source/as_thread.h index b1fdc56c..c969e888 100644 --- a/sdk/angelscript/source/as_thread.h +++ b/sdk/angelscript/source/as_thread.h @@ -53,7 +53,7 @@ class asCThreadManager : public asIThreadManager { public: static asCThreadLocalData *GetLocalData(); - static int CleanupLocalData(); + static int CleanupLocalData(); static int Prepare(asIThreadManager *externalThreadMgr); static void Unprepare(); @@ -74,16 +74,16 @@ class asCThreadManager : public asIThreadManager int refCount; #ifndef AS_NO_THREADS -#if defined(_MSC_VER) && defined(AS_WINDOWS_THREADS) && (WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) + #if defined(_MSC_VER) && defined(AS_WINDOWS_THREADS) && (WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP) // On Windows Store we must use MSVC specific thread variables for thread // local storage, as the TLS API isn't available. On desktop we can't use // this as it may cause problems if the library is used in a dll. // ref: http://msdn.microsoft.com/en-us/library/2s9wt68x.aspx // ref: http://msdn.microsoft.com/en-us/library/9w1sdazb.aspx __declspec(thread) static asCThreadLocalData *tld; -#else + #else asDWORD mtlsKey; //Multi-thread local storage key -#endif + #endif DECLARECRITICALSECTION(criticalSection) #else asCThreadLocalData *tld; @@ -98,7 +98,7 @@ class asCThreadLocalData { public: asCArray activeContexts; - asCString string; + asCString string; protected: friend class asCThreadManager; diff --git a/sdk/angelscript/source/as_tokendef.h b/sdk/angelscript/source/as_tokendef.h index dfe1eb4a..08e3c791 100644 --- a/sdk/angelscript/source/as_tokendef.h +++ b/sdk/angelscript/source/as_tokendef.h @@ -43,16 +43,15 @@ BEGIN_AS_NAMESPACE -enum eTokenType -{ +enum eTokenType { ttUnrecognizedToken, - ttEnd, // End of file + ttEnd, // End of file // White space and comments - ttWhiteSpace, // ' ', '\t', '\r', '\n', UTF8 byte-order-mark - ttOnelineComment, // // \n - ttMultilineComment, // /* */ + ttWhiteSpace, // ' ', '\t', '\r', '\n', UTF8 byte-order-mark + ttOnelineComment, // // \n + ttMultilineComment, // /* */ // Atoms ttIdentifier, // abc123 @@ -66,35 +65,35 @@ enum eTokenType ttBitsConstant, // 0xFFFF // Math operators - ttPlus, // + - ttMinus, // - - ttStar, // * - ttSlash, // / - ttPercent, // % - ttStarStar, // ** - - ttHandle, // @ - - ttAddAssign, // += - ttSubAssign, // -= - ttMulAssign, // *= - ttDivAssign, // /= - ttModAssign, // %= - ttPowAssign, // **= - - ttOrAssign, // |= - ttAndAssign, // &= - ttXorAssign, // ^= - ttShiftLeftAssign, // <<= - ttShiftRightLAssign, // >>= - ttShiftRightAAssign, // >>>= - - ttInc, // ++ - ttDec, // -- - - ttDot, // . - ttVariadic, // ... - ttScope, // :: + ttPlus, // + + ttMinus, // - + ttStar, // * + ttSlash, // / + ttPercent, // % + ttStarStar, // ** + + ttHandle, // @ + + ttAddAssign, // += + ttSubAssign, // -= + ttMulAssign, // *= + ttDivAssign, // /= + ttModAssign, // %= + ttPowAssign, // **= + + ttOrAssign, // |= + ttAndAssign, // &= + ttXorAssign, // ^= + ttShiftLeftAssign, // <<= + ttShiftRightLAssign, // >>= + ttShiftRightAAssign, // >>>= + + ttInc, // ++ + ttDec, // -- + + ttDot, // . + ttVariadic, // ... + ttScope, // :: // Statement tokens ttAssignment, // = @@ -109,77 +108,77 @@ enum eTokenType ttAmp, // & // Bitwise operators - ttBitOr, // | - ttBitNot, // ~ - ttBitXor, // ^ - ttBitShiftLeft, // << - ttBitShiftRight, // >> // TODO: In Java this is the arithmetical shift - ttBitShiftRightArith, // >>> // TODO: In Java this is the logical shift + ttBitOr, // | + ttBitNot, // ~ + ttBitXor, // ^ + ttBitShiftLeft, // << + ttBitShiftRight, // >> // TODO: In Java this is the arithmetical shift + ttBitShiftRightArith, // >>> // TODO: In Java this is the logical shift // Compare operators - ttEqual, // == - ttNotEqual, // != - ttLessThan, // < - ttGreaterThan, // > - ttLessThanOrEqual, // <= - ttGreaterThanOrEqual, // >= + ttEqual, // == + ttNotEqual, // != + ttLessThan, // < + ttGreaterThan, // > + ttLessThanOrEqual, // <= + ttGreaterThanOrEqual, // >= - ttQuestion, // ? - ttColon, // : + ttQuestion, // ? + ttColon, // : // Reserved keywords - ttIf, // if - ttElse, // else - ttFor, // for - ttForEach, // foreach - ttWhile, // while - ttBool, // bool - ttFuncDef, // funcdef - ttImport, // import - ttInt, // int - ttInt8, // int8 - ttInt16, // int16 - ttInt64, // int64 - ttInterface, // interface - ttIs, // is - ttNotIs, // !is - ttUInt, // uint - ttUInt8, // uint8 - ttUInt16, // uint16 - ttUInt64, // uint64 - ttFloat, // float - ttVoid, // void - ttTrue, // true - ttFalse, // false - ttReturn, // return - ttNot, // not - ttAnd, // and, && - ttOr, // or, || - ttXor, // xor, ^^ - ttBreak, // break - ttContinue, // continue - ttConst, // const - ttDo, // do - ttDouble, // double - ttSwitch, // switch - ttCase, // case - ttDefault, // default - ttIn, // in - ttOut, // out - ttInOut, // inout - ttNull, // null - ttClass, // class - ttTypedef, // typedef - ttEnum, // enum - ttCast, // cast - ttPrivate, // private - ttProtected, // protected - ttNamespace, // namespace - ttMixin, // mixin - ttAuto, // auto - ttTry, // try - ttCatch, // catch - ttUsing // using + ttIf, // if + ttElse, // else + ttFor, // for + ttForEach, // foreach + ttWhile, // while + ttBool, // bool + ttFuncDef, // funcdef + ttImport, // import + ttInt, // int + ttInt8, // int8 + ttInt16, // int16 + ttInt64, // int64 + ttInterface, // interface + ttIs, // is + ttNotIs, // !is + ttUInt, // uint + ttUInt8, // uint8 + ttUInt16, // uint16 + ttUInt64, // uint64 + ttFloat, // float + ttVoid, // void + ttTrue, // true + ttFalse, // false + ttReturn, // return + ttNot, // not + ttAnd, // and, && + ttOr, // or, || + ttXor, // xor, ^^ + ttBreak, // break + ttContinue, // continue + ttConst, // const + ttDo, // do + ttDouble, // double + ttSwitch, // switch + ttCase, // case + ttDefault, // default + ttIn, // in + ttOut, // out + ttInOut, // inout + ttNull, // null + ttClass, // class + ttTypedef, // typedef + ttEnum, // enum + ttCast, // cast + ttPrivate, // private + ttProtected, // protected + ttNamespace, // namespace + ttMixin, // mixin + ttAuto, // auto + ttTry, // try + ttCatch, // catch + ttUsing // using }; struct sTokenWord @@ -189,8 +188,9 @@ struct sTokenWord eTokenType tokenType; }; -#define asTokenDef(str, tok) {str, sizeof(str)-1, tok} +#define asTokenDef(str, tok) {str, sizeof(str) - 1, tok} +// clang-format off sTokenWord const tokenWords[] = { asTokenDef("+" , ttPlus), @@ -304,8 +304,9 @@ sTokenWord const tokenWords[] = asTokenDef("while" , ttWhile), asTokenDef("xor" , ttXor), }; +// clang-format on -const unsigned int numTokenWords = sizeof(tokenWords)/sizeof(sTokenWord); +const unsigned int numTokenWords = sizeof(tokenWords) / sizeof(sTokenWord); const char * const whiteSpace = " \t\r\n"; diff --git a/sdk/angelscript/source/as_tokenizer.cpp b/sdk/angelscript/source/as_tokenizer.cpp index 3ea40cc4..e599dfeb 100644 --- a/sdk/angelscript/source/as_tokenizer.cpp +++ b/sdk/angelscript/source/as_tokenizer.cpp @@ -41,7 +41,7 @@ #include "as_tokendef.h" #if !defined(AS_NO_MEMORY_H) -#include + #include #endif #include // strcmp() @@ -63,9 +63,9 @@ asCTokenizer::~asCTokenizer() void asCTokenizer::FreeJumpTable() { // Deallocate the jump table - for (asUINT n = 0; n < 256; n++) + for( asUINT n = 0; n < 256; n++ ) { - if (keywordTable[n]) + if( keywordTable[n] ) asDELETEARRAY(keywordTable[n]); } memset(keywordTable, 0, sizeof(keywordTable)); @@ -76,37 +76,37 @@ void asCTokenizer::InitJumpTable() FreeJumpTable(); // Initialize the jump table - for (asUINT n = 0; n < numTokenWords; n++) + for( asUINT n = 0; n < numTokenWords; n++ ) { - const sTokenWord& current = tokenWords[n]; + const sTokenWord ¤t = tokenWords[n]; // Check if a token must be skipped due to engine properties - if (current.tokenType == ttForEach && engine && !engine->ep.foreachSupport) + if( current.tokenType == ttForEach && engine && !engine->ep.foreachSupport ) continue; unsigned char start = current.word[0]; // Create new jump table entry if none exists - if (!keywordTable[start]) + if( !keywordTable[start] ) { // Surely there won't ever be more than 32 keywords starting with // the same character. Right? - keywordTable[start] = asNEWARRAY(const sTokenWord*, 32); - memset(keywordTable[start], 0, sizeof(sTokenWord*) * 32); + keywordTable[start] = asNEWARRAY(const sTokenWord *, 32); + memset(keywordTable[start], 0, sizeof(sTokenWord *) * 32); } // Add the token sorted from longest to shortest so // we check keywords greedily. - const sTokenWord** tok = keywordTable[start]; - unsigned insert = 0, index = 0; - while (tok[index]) + const sTokenWord **tok = keywordTable[start]; + unsigned insert = 0, index = 0; + while( tok[index] ) { - if (tok[index]->wordLength >= current.wordLength) + if( tok[index]->wordLength >= current.wordLength ) ++insert; ++index; } - while (index > insert) + while( index > insert ) { tok[index] = tok[index - 1]; --index; @@ -119,20 +119,20 @@ void asCTokenizer::InitJumpTable() // static const char *asCTokenizer::GetDefinition(int tokenType) { - if( tokenType == ttUnrecognizedToken ) return ""; - if( tokenType == ttEnd ) return ""; - if( tokenType == ttWhiteSpace ) return ""; - if( tokenType == ttOnelineComment ) return ""; - if( tokenType == ttMultilineComment ) return ""; - if( tokenType == ttIdentifier ) return ""; - if( tokenType == ttIntConstant ) return ""; - if( tokenType == ttFloatConstant ) return ""; - if( tokenType == ttDoubleConstant ) return ""; - if( tokenType == ttStringConstant ) return ""; - if( tokenType == ttMultilineStringConstant ) return ""; - if( tokenType == ttNonTerminatedStringConstant ) return ""; - if( tokenType == ttBitsConstant ) return ""; - if( tokenType == ttHeredocStringConstant ) return ""; + if( tokenType == ttUnrecognizedToken ) return ""; + if( tokenType == ttEnd ) return ""; + if( tokenType == ttWhiteSpace ) return ""; + if( tokenType == ttOnelineComment ) return ""; + if( tokenType == ttMultilineComment ) return ""; + if( tokenType == ttIdentifier ) return ""; + if( tokenType == ttIntConstant ) return ""; + if( tokenType == ttFloatConstant ) return ""; + if( tokenType == ttDoubleConstant ) return ""; + if( tokenType == ttStringConstant ) return ""; + if( tokenType == ttMultilineStringConstant ) return ""; + if( tokenType == ttNonTerminatedStringConstant ) return ""; + if( tokenType == ttBitsConstant ) return ""; + if( tokenType == ttHeredocStringConstant ) return ""; for( asUINT n = 0; n < numTokenWords; n++ ) if( tokenWords[n].tokenType == tokenType ) @@ -144,8 +144,8 @@ const char *asCTokenizer::GetDefinition(int tokenType) bool asCTokenizer::IsDigitInRadix(char ch, int radix) const { if( ch >= '0' && ch <= '9' ) return (ch -= '0') < radix; - if( ch >= 'A' && ch <= 'Z' ) return (ch -= 'A'-10) < radix; - if( ch >= 'a' && ch <= 'z' ) return (ch -= 'a'-10) < radix; + if( ch >= 'A' && ch <= 'Z' ) return (ch -= 'A' - 10) < radix; + if( ch >= 'a' && ch <= 'z' ) return (ch -= 'a' - 10) < radix; return false; } @@ -154,10 +154,10 @@ eTokenType asCTokenizer::GetToken(const char *source, size_t sourceLength, size_ asASSERT(source != 0); asASSERT(tokenLength != 0); - eTokenType tokenType; - size_t tlen; + eTokenType tokenType; + size_t tlen; asETokenClass t = ParseToken(source, sourceLength, tlen, tokenType); - if( tc ) *tc = t; + if( tc ) *tc = t; if( tokenLength ) *tokenLength = tlen; return tokenType; @@ -166,10 +166,10 @@ eTokenType asCTokenizer::GetToken(const char *source, size_t sourceLength, size_ asETokenClass asCTokenizer::ParseToken(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const { if( IsWhiteSpace(source, sourceLength, tokenLength, tokenType) ) return asTC_WHITESPACE; - if( IsComment(source, sourceLength, tokenLength, tokenType) ) return asTC_COMMENT; - if( IsConstant(source, sourceLength, tokenLength, tokenType) ) return asTC_VALUE; + if( IsComment(source, sourceLength, tokenLength, tokenType) ) return asTC_COMMENT; + if( IsConstant(source, sourceLength, tokenLength, tokenType) ) return asTC_VALUE; if( IsIdentifier(source, sourceLength, tokenLength, tokenType) ) return asTC_IDENTIFIER; - if( IsKeyWord(source, sourceLength, tokenLength, tokenType) ) return asTC_KEYWORD; + if( IsKeyWord(source, sourceLength, tokenLength, tokenType) ) return asTC_KEYWORD; // If none of the above this is an unrecognized token // We can find the length of the token by advancing @@ -183,10 +183,10 @@ asETokenClass asCTokenizer::ParseToken(const char *source, size_t sourceLength, bool asCTokenizer::IsWhiteSpace(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const { // Treat UTF8 byte-order-mark (EF BB BF) as whitespace - if( sourceLength >= 3 && - asBYTE(source[0]) == 0xEFu && - asBYTE(source[1]) == 0xBBu && - asBYTE(source[2]) == 0xBFu ) + if( sourceLength >= 3 && + asBYTE(source[0]) == 0xEFu && + asBYTE(source[1]) == 0xBBu && + asBYTE(source[2]) == 0xBFu ) { tokenType = ttWhiteSpace; tokenLength = 3; @@ -195,7 +195,7 @@ bool asCTokenizer::IsWhiteSpace(const char *source, size_t sourceLength, size_t // Group all other white space characters into one size_t n; - int numWsChars = (int)strlen(whiteSpace); + int numWsChars = (int)strlen(whiteSpace); for( n = 0; n < sourceLength; n++ ) { bool isWhiteSpace = false; @@ -207,7 +207,7 @@ bool asCTokenizer::IsWhiteSpace(const char *source, size_t sourceLength, size_t break; } } - if( !isWhiteSpace ) break; + if( !isWhiteSpace ) break; } if( n > 0 ) @@ -241,7 +241,7 @@ bool asCTokenizer::IsComment(const char *source, size_t sourceLength, size_t &to } tokenType = ttOnelineComment; - tokenLength = n < sourceLength ? n+1 : n; + tokenLength = n < sourceLength ? n + 1 : n; return true; } @@ -252,14 +252,14 @@ bool asCTokenizer::IsComment(const char *source, size_t sourceLength, size_t &to // Find the length size_t n; - for( n = 2; n < sourceLength-1; ) + for( n = 2; n < sourceLength - 1; ) { if( source[n++] == '*' && source[n] == '/' ) break; } tokenType = ttMultilineComment; - tokenLength = n+1; + tokenLength = n + 1; return true; } @@ -267,13 +267,13 @@ bool asCTokenizer::IsComment(const char *source, size_t sourceLength, size_t &to return false; } -bool asCTokenizer::IsValidSeparatorDigitInRadix(const char* source, size_t sourceLength, size_t n, int radix) const +bool asCTokenizer::IsValidSeparatorDigitInRadix(const char *source, size_t sourceLength, size_t n, int radix) const { - if (source[n] != '\'') + if( source[n] != '\'' ) return false; - if ((n + 1) >= sourceLength || n == 0) + if( (n + 1) >= sourceLength || n == 0 ) return false; - else if (!IsDigitInRadix(source[n + 1], radix) || !IsDigitInRadix(source[n - 1], radix)) + else if( !IsDigitInRadix(source[n + 1], radix) || !IsDigitInRadix(source[n - 1], radix) ) return false; return true; @@ -290,12 +290,24 @@ bool asCTokenizer::IsConstant(const char *source, size_t sourceLength, size_t &t // Determine the radix for the constant int radix = 0; switch( source[1] ) - { - case 'b': case 'B': radix = 2; break; - case 'o': case 'O': radix = 8; break; - case 'd': case 'D': radix = 10; break; - case 'x': case 'X': radix = 16; break; - } + { + case 'b': + case 'B': + radix = 2; + break; + case 'o': + case 'O': + radix = 8; + break; + case 'd': + case 'D': + radix = 10; + break; + case 'x': + case 'X': + radix = 16; + break; + } if( radix ) { @@ -350,9 +362,9 @@ bool asCTokenizer::IsConstant(const char *source, size_t sourceLength, size_t &t else { #ifdef AS_USE_DOUBLE_AS_FLOAT - tokenType = ttFloatConstant; + tokenType = ttFloatConstant; #else - tokenType = ttDoubleConstant; + tokenType = ttDoubleConstant; #endif tokenLength = n; } @@ -374,25 +386,25 @@ bool asCTokenizer::IsConstant(const char *source, size_t sourceLength, size_t &t // Find the length size_t n; - for( n = 3; n < sourceLength-2; n++ ) + for( n = 3; n < sourceLength - 2; n++ ) { - if (source[n] == '"' && source[n + 1] == '"' && source[n + 2] == '"') + if( source[n] == '"' && source[n + 1] == '"' && source[n + 2] == '"' ) { - tokenType = ttHeredocStringConstant; + tokenType = ttHeredocStringConstant; tokenLength = n + 3; return true; } } tokenType = ttNonTerminatedStringConstant; - tokenLength = n+2; + tokenLength = n + 2; } else { // Normal string constant - tokenType = ttStringConstant; - char quote = source[0]; - bool evenSlashes = true; + tokenType = ttStringConstant; + char quote = source[0]; + bool evenSlashes = true; size_t n; for( n = 1; n < sourceLength; n++ ) { @@ -400,21 +412,22 @@ bool asCTokenizer::IsConstant(const char *source, size_t sourceLength, size_t &t // Double-byte characters are only allowed for ASCII if( (source[n] & 0x80) && engine->ep.scanner == 0 ) { - // This is a leading character in a double byte character, + // This is a leading character in a double byte character, // include both in the string and continue processing. n++; continue; } #endif - if( source[n] == '\n' ) + if( source[n] == '\n' ) tokenType = ttMultilineStringConstant; if( source[n] == quote && evenSlashes ) { - tokenLength = n+1; + tokenLength = n + 1; return true; } - if( source[n] == '\\' ) evenSlashes = !evenSlashes; else evenSlashes = true; + if( source[n] == '\\' ) evenSlashes = !evenSlashes; + else evenSlashes = true; } tokenType = ttNonTerminatedStringConstant; @@ -435,9 +448,9 @@ bool asCTokenizer::IsIdentifier(const char *source, size_t sourceLength, size_t // Starting with letter or underscore if( (c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') || - c == '_' || - (c < 0 && engine->ep.allowUnicodeIdentifiers) ) + (c >= 'A' && c <= 'Z') || + c == '_' || + (c < 0 && engine->ep.allowUnicodeIdentifiers) ) { tokenType = ttIdentifier; tokenLength = 1; @@ -446,10 +459,10 @@ bool asCTokenizer::IsIdentifier(const char *source, size_t sourceLength, size_t { c = source[n]; if( (c >= 'a' && c <= 'z') || - (c >= 'A' && c <= 'Z') || - (c >= '0' && c <= '9') || - c == '_' || - (c < 0 && engine->ep.allowUnicodeIdentifiers) ) + (c >= 'A' && c <= 'Z') || + (c >= '0' && c <= '9') || + c == '_' || + (c < 0 && engine->ep.allowUnicodeIdentifiers) ) tokenLength++; else break; @@ -467,8 +480,8 @@ bool asCTokenizer::IsIdentifier(const char *source, size_t sourceLength, size_t bool asCTokenizer::IsKeyWord(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const { - unsigned char start = source[0]; - const sTokenWord **ptr = keywordTable[start]; + unsigned char start = source[0]; + const sTokenWord **ptr = keywordTable[start]; if( !ptr ) return false; @@ -478,25 +491,25 @@ bool asCTokenizer::IsKeyWord(const char *source, size_t sourceLength, size_t &to size_t wlen = (*ptr)->wordLength; if( sourceLength >= wlen && strncmp(source, (*ptr)->word, wlen) == 0 ) { - // Tokens that end with a character that can be part of an - // identifier require an extra verification to guarantee that - // we don't split an identifier token, e.g. the "!is" token + // Tokens that end with a character that can be part of an + // identifier require an extra verification to guarantee that + // we don't split an identifier token, e.g. the "!is" token // and the tokens "!" and "isTrue" in the "!isTrue" expression. if( wlen < sourceLength && - ((source[wlen-1] >= 'a' && source[wlen-1] <= 'z') || - (source[wlen-1] >= 'A' && source[wlen-1] <= 'Z') || - (source[wlen-1] >= '0' && source[wlen-1] <= '9')) && - ((source[wlen] >= 'a' && source[wlen] <= 'z') || - (source[wlen] >= 'A' && source[wlen] <= 'Z') || - (source[wlen] >= '0' && source[wlen] <= '9') || - (source[wlen] == '_')) ) + ((source[wlen - 1] >= 'a' && source[wlen - 1] <= 'z') || + (source[wlen - 1] >= 'A' && source[wlen - 1] <= 'Z') || + (source[wlen - 1] >= '0' && source[wlen - 1] <= '9')) && + ((source[wlen] >= 'a' && source[wlen] <= 'z') || + (source[wlen] >= 'A' && source[wlen] <= 'Z') || + (source[wlen] >= '0' && source[wlen] <= '9') || + (source[wlen] == '_')) ) { - // The token doesn't really match, even though + // The token doesn't really match, even though // the start of the source matches the token continue; } - tokenType = (*ptr)->tokenType; + tokenType = (*ptr)->tokenType; tokenLength = wlen; return true; } @@ -506,4 +519,3 @@ bool asCTokenizer::IsKeyWord(const char *source, size_t sourceLength, size_t &to } END_AS_NAMESPACE - diff --git a/sdk/angelscript/source/as_tokenizer.h b/sdk/angelscript/source/as_tokenizer.h index 8144148b..3b58ff5d 100644 --- a/sdk/angelscript/source/as_tokenizer.h +++ b/sdk/angelscript/source/as_tokenizer.h @@ -51,7 +51,7 @@ class asCTokenizer { public: eTokenType GetToken(const char *source, size_t sourceLength, size_t *tokenLength, asETokenClass *tc = 0) const; - + static const char *GetDefinition(int tokenType); protected: @@ -61,13 +61,13 @@ class asCTokenizer ~asCTokenizer(); asETokenClass ParseToken(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const; - bool IsWhiteSpace(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const; - bool IsComment(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const; - bool IsConstant(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const; - bool IsKeyWord(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const; - bool IsIdentifier(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const; - bool IsDigitInRadix(char ch, int radix) const; - bool IsValidSeparatorDigitInRadix(const char* source, size_t sourceLength, size_t n, int radix) const; + bool IsWhiteSpace(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const; + bool IsComment(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const; + bool IsConstant(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const; + bool IsKeyWord(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const; + bool IsIdentifier(const char *source, size_t sourceLength, size_t &tokenLength, eTokenType &tokenType) const; + bool IsDigitInRadix(char ch, int radix) const; + bool IsValidSeparatorDigitInRadix(const char *source, size_t sourceLength, size_t n, int radix) const; void InitJumpTable(); void FreeJumpTable(); @@ -80,4 +80,3 @@ class asCTokenizer END_AS_NAMESPACE #endif - diff --git a/sdk/angelscript/source/as_typeinfo.cpp b/sdk/angelscript/source/as_typeinfo.cpp index 3b4b4ed0..637a66c2 100644 --- a/sdk/angelscript/source/as_typeinfo.cpp +++ b/sdk/angelscript/source/as_typeinfo.cpp @@ -46,15 +46,15 @@ asCTypeInfo::asCTypeInfo() internalRefCount.set(1); // start with one internal ref-count engine = 0; module = 0; - size = 0; - flags = 0; + size = 0; + flags = 0; typeId = -1; // start as -1 to signal that it hasn't been defined scriptSectionIdx = -1; - declaredAt = 0; + declaredAt = 0; accessMask = 0xFFFFFFFF; - nameSpace = 0; + nameSpace = 0; } asCTypeInfo::asCTypeInfo(asCScriptEngine *in_engine) @@ -63,15 +63,15 @@ asCTypeInfo::asCTypeInfo(asCScriptEngine *in_engine) internalRefCount.set(1); // start with one internal ref count engine = in_engine; module = 0; - size = 0; - flags = 0; + size = 0; + flags = 0; typeId = -1; // start as -1 to signal that it hasn't been defined scriptSectionIdx = -1; - declaredAt = 0; + declaredAt = 0; accessMask = 0xFFFFFFFF; - nameSpace = engine->nameSpaces[0]; + nameSpace = engine->nameSpaces[0]; } asCTypeInfo::~asCTypeInfo() @@ -89,15 +89,15 @@ int asCTypeInfo::Release() const { int r = externalRefCount.atomicDec(); - if (r == 0) + if( r == 0 ) { // There are no more external references, if there are also no // internal references then it is time to delete the object type - if (internalRefCount.get() == 0) + if( internalRefCount.get() == 0 ) { // If the engine is no longer set, then it has already been // released and we must take care of the deletion ourselves - asDELETE(const_cast(this), asCTypeInfo); + asDELETE(const_cast(this), asCTypeInfo); } } @@ -113,15 +113,15 @@ int asCTypeInfo::ReleaseInternal() { int r = internalRefCount.atomicDec(); - if (r == 0) + if( r == 0 ) { // There are no more internal references, if there are also no // external references then it is time to delete the object type - if (externalRefCount.get() == 0) + if( externalRefCount.get() == 0 ) { // If the engine is no longer set, then it has already been // released and we must take care of the deletion ourselves - asDELETE(const_cast(this), asCTypeInfo); + asDELETE(const_cast(this), asCTypeInfo); } } @@ -143,11 +143,11 @@ void *asCTypeInfo::SetUserData(void *data, asPWORD type) // It is not intended to store a lot of different types of userdata, // so a more complex structure like a associative map would just have // more overhead than a simple array. - for (asUINT n = 0; n < userData.GetLength(); n += 2) + for( asUINT n = 0; n < userData.GetLength(); n += 2 ) { - if (userData[n] == type) + if( userData[n] == type ) { - void *oldData = reinterpret_cast(userData[n + 1]); + void *oldData = reinterpret_cast(userData[n + 1]); userData[n + 1] = reinterpret_cast(data); RELEASEEXCLUSIVE(engine->engineRWLock); @@ -170,12 +170,12 @@ void *asCTypeInfo::GetUserData(asPWORD type) const // setting the user data nobody must be reading. ACQUIRESHARED(engine->engineRWLock); - for (asUINT n = 0; n < userData.GetLength(); n += 2) + for( asUINT n = 0; n < userData.GetLength(); n += 2 ) { - if (userData[n] == type) + if( userData[n] == type ) { RELEASESHARED(engine->engineRWLock); - return reinterpret_cast(userData[n + 1]); + return reinterpret_cast(userData[n + 1]); } } @@ -214,12 +214,12 @@ asUINT asCTypeInfo::GetSize() const // interface int asCTypeInfo::GetTypeId() const { - if (typeId == -1) + if( typeId == -1 ) { // We need a non const pointer to create the asCDataType object. // We're not breaking anything here because this function is not // modifying the object, so this const cast is safe. - asCTypeInfo *ot = const_cast(this); + asCTypeInfo *ot = const_cast(this); // The engine will define the typeId for this object type engine->GetTypeIdFromDataType(asCDataType::CreateType(ot, false)); @@ -238,7 +238,7 @@ asIScriptEngine *asCTypeInfo::GetEngine() const const char *asCTypeInfo::GetConfigGroup() const { asCConfigGroup *group = engine->FindConfigGroupForTypeInfo(this); - if (group == 0) + if( group == 0 ) return 0; return group->groupName.AddressOf(); @@ -254,16 +254,16 @@ asDWORD asCTypeInfo::GetAccessMask() const int asCTypeInfo::GetProperty(asUINT index, const char **out_name, int *out_typeId, bool *out_isPrivate, bool *out_isProtected, int *out_offset, bool *out_isReference, asDWORD *out_accessMask, int *out_compositeOffset, bool *out_isCompositeIndirect, bool *out_isConst) const { UNUSED_VAR(index); - if (out_name) *out_name = 0; - if (out_typeId) *out_typeId = 0; - if (out_isPrivate) *out_isPrivate = false; - if (out_isProtected) *out_isProtected = false; - if (out_offset) *out_offset = 0; - if (out_isReference) *out_isReference = false; - if (out_accessMask) *out_accessMask = 0; - if (out_compositeOffset) *out_compositeOffset = 0; - if (out_isCompositeIndirect) *out_isCompositeIndirect = false; - if (out_isConst) *out_isConst = false; + if( out_name ) *out_name = 0; + if( out_typeId ) *out_typeId = 0; + if( out_isPrivate ) *out_isPrivate = false; + if( out_isProtected ) *out_isProtected = false; + if( out_offset ) *out_offset = 0; + if( out_isReference ) *out_isReference = false; + if( out_accessMask ) *out_accessMask = 0; + if( out_compositeOffset ) *out_compositeOffset = 0; + if( out_isCompositeIndirect ) *out_isCompositeIndirect = false; + if( out_isConst ) *out_isConst = false; return -1; } @@ -271,11 +271,11 @@ int asCTypeInfo::GetProperty(asUINT index, const char **out_name, int *out_typeI asCObjectType *CastToObjectType(asCTypeInfo *ti) { // Allow call on null pointer - if (ti == 0) return 0; + if( ti == 0 ) return 0; // TODO: type: Should List pattern have its own type class? - if ((ti->flags & (asOBJ_VALUE | asOBJ_REF | asOBJ_LIST_PATTERN)) && !(ti->flags & asOBJ_FUNCDEF)) - return reinterpret_cast(ti); + if( (ti->flags & (asOBJ_VALUE | asOBJ_REF | asOBJ_LIST_PATTERN)) && !(ti->flags & asOBJ_FUNCDEF) ) + return reinterpret_cast(ti); return 0; } @@ -284,10 +284,10 @@ asCObjectType *CastToObjectType(asCTypeInfo *ti) asCEnumType *CastToEnumType(asCTypeInfo *ti) { // Allow call on null pointer - if (ti == 0) return 0; + if( ti == 0 ) return 0; - if (ti->flags & (asOBJ_ENUM)) - return reinterpret_cast(ti); + if( ti->flags & (asOBJ_ENUM) ) + return reinterpret_cast(ti); return 0; } @@ -296,10 +296,10 @@ asCEnumType *CastToEnumType(asCTypeInfo *ti) asCTypedefType *CastToTypedefType(asCTypeInfo *ti) { // Allow call on null pointer - if (ti == 0) return 0; + if( ti == 0 ) return 0; - if (ti->flags & (asOBJ_TYPEDEF)) - return reinterpret_cast(ti); + if( ti->flags & (asOBJ_TYPEDEF) ) + return reinterpret_cast(ti); return 0; } @@ -308,10 +308,10 @@ asCTypedefType *CastToTypedefType(asCTypeInfo *ti) asCFuncdefType *CastToFuncdefType(asCTypeInfo *ti) { // Allow call on null pointer - if (ti == 0) return 0; + if( ti == 0 ) return 0; - if (ti->flags & (asOBJ_FUNCDEF)) - return reinterpret_cast(ti); + if( ti->flags & (asOBJ_FUNCDEF) ) + return reinterpret_cast(ti); return 0; } @@ -320,12 +320,12 @@ asCFuncdefType *CastToFuncdefType(asCTypeInfo *ti) void asCTypeInfo::CleanUserData() { asASSERT(engine); - for (asUINT n = 0; n < userData.GetLength(); n += 2) + for( asUINT n = 0; n < userData.GetLength(); n += 2 ) { - if (userData[n + 1]) + if( userData[n + 1] ) { - for (asUINT c = 0; c < engine->cleanTypeInfoFuncs.GetLength(); c++) - if (engine->cleanTypeInfoFuncs[c].type == userData[n]) + for( asUINT c = 0; c < engine->cleanTypeInfoFuncs.GetLength(); c++ ) + if( engine->cleanTypeInfoFuncs[c].type == userData[n] ) engine->cleanTypeInfoFuncs[c].cleanFunc(this); } } @@ -336,7 +336,7 @@ void asCTypeInfo::CleanUserData() bool asCTypeInfo::IsShared() const { // Types that can be declared by scripts need to have the explicit flag asOBJ_SHARED - if (flags & (asOBJ_SCRIPT_OBJECT | asOBJ_ENUM)) return flags & asOBJ_SHARED ? true : false; + if( flags & (asOBJ_SCRIPT_OBJECT | asOBJ_ENUM) ) return flags & asOBJ_SHARED ? true : false; // Otherwise we assume the type to be shared return true; @@ -347,9 +347,9 @@ bool asCTypeInfo::IsShared() const asCEnumType::~asCEnumType() { asUINT n; - for (n = 0; n < enumValues.GetLength(); n++) + for( n = 0; n < enumValues.GetLength(); n++ ) { - if (enumValues[n]) + if( enumValues[n] ) asDELETE(enumValues[n], asSEnumValue); } enumValues.SetLength(0); @@ -364,22 +364,22 @@ asUINT asCEnumType::GetEnumValueCount() const // interface const char *asCEnumType::GetEnumValueByIndex(asUINT index, asINT64 *outValue) const { - if (outValue) + if( outValue ) *outValue = 0; - if (index >= enumValues.GetLength()) + if( index >= enumValues.GetLength() ) return 0; - if (outValue) + if( outValue ) *outValue = enumValues[index]->value; return enumValues[index]->name.AddressOf(); } // interface -int asCEnumType::GetUnderlyingTypeId() const -{ - return engine->GetTypeIdFromDataType(enumType); +int asCEnumType::GetUnderlyingTypeId() const +{ + return engine->GetTypeIdFromDataType(enumType); } ////////////////////////////////////////////////////////////////////////////////////////// @@ -391,18 +391,18 @@ asCTypedefType::~asCTypedefType() void asCTypedefType::DestroyInternal() { - if (engine == 0) return; + if( engine == 0 ) return; // Release the object types held by the alias - if (aliasForType.GetTypeInfo()) - aliasForType.GetTypeInfo()->ReleaseInternal(); + if( aliasForType.GetTypeInfo() ) + aliasForType.GetTypeInfo()->ReleaseInternal(); aliasForType = asCDataType::CreatePrimitive(ttVoid, false); CleanUserData(); // Remove the type from the engine - if (typeId != -1) + if( typeId != -1 ) engine->RemoveFromTypeIdMap(this); // Clear the engine pointer to mark the object type as invalid @@ -451,7 +451,7 @@ asCFuncdefType::~asCFuncdefType() void asCFuncdefType::DestroyInternal() { - if (engine == 0) return; + if( engine == 0 ) return; // Release the funcdef if( funcdef ) @@ -459,7 +459,7 @@ void asCFuncdefType::DestroyInternal() funcdef = 0; // Detach from parent class - if (parentClass) + if( parentClass ) { parentClass->childFuncDefs.RemoveValue(this); parentClass = 0; @@ -468,7 +468,7 @@ void asCFuncdefType::DestroyInternal() CleanUserData(); // Remove the type from the engine - if (typeId != -1) + if( typeId != -1 ) engine->RemoveFromTypeIdMap(this); // Clear the engine pointer to mark the object type as invalid @@ -488,5 +488,3 @@ asITypeInfo *asCFuncdefType::GetParentType() const } END_AS_NAMESPACE - - diff --git a/sdk/angelscript/source/as_typeinfo.h b/sdk/angelscript/source/as_typeinfo.h index d0fb36da..cfe56f9b 100644 --- a/sdk/angelscript/source/as_typeinfo.h +++ b/sdk/angelscript/source/as_typeinfo.h @@ -55,9 +55,9 @@ struct asSNameSpace; // TODO: type: asCPrimitiveType shall be implemented to represent primitives (void, int, double, etc) -// TODO: type: asCTypeInfo should have an internal virtual method GetBehaviours. For asCObjectType it -// should return the beh member. For asCFuncdefType it should return the beh member of -// engine->functionBehaviours. This will allow the code that needs the behaviour to handle +// TODO: type: asCTypeInfo should have an internal virtual method GetBehaviours. For asCObjectType it +// should return the beh member. For asCFuncdefType it should return the beh member of +// engine->functionBehaviours. This will allow the code that needs the behaviour to handle // both object types and funcdefs the same way class asCTypeInfo : public asITypeInfo @@ -76,60 +76,161 @@ class asCTypeInfo : public asITypeInfo int Release() const; // Type info - const char *GetName() const; - const char *GetNamespace() const; - asITypeInfo *GetBaseType() const { return 0; } - bool DerivesFrom(const asITypeInfo *objType) const { UNUSED_VAR(objType); return 0; } - asQWORD GetFlags() const; - asUINT GetSize() const; - int GetTypeId() const; - int GetSubTypeId(asUINT subtypeIndex = 0) const { UNUSED_VAR(subtypeIndex); return -1; } - asITypeInfo *GetSubType(asUINT subtypeIndex = 0) const { UNUSED_VAR(subtypeIndex); return 0; } - asUINT GetSubTypeCount() const { return 0; } - int GetUnderlyingTypeId() const { return asERROR; } + const char *GetName() const; + const char *GetNamespace() const; + asITypeInfo *GetBaseType() const + { + return 0; + } + bool DerivesFrom(const asITypeInfo *objType) const + { + UNUSED_VAR(objType); + return 0; + } + asQWORD GetFlags() const; + asUINT GetSize() const; + int GetTypeId() const; + int GetSubTypeId(asUINT subtypeIndex = 0) const + { + UNUSED_VAR(subtypeIndex); + return -1; + } + asITypeInfo *GetSubType(asUINT subtypeIndex = 0) const + { + UNUSED_VAR(subtypeIndex); + return 0; + } + asUINT GetSubTypeCount() const + { + return 0; + } + int GetUnderlyingTypeId() const + { + return asERROR; + } // Interfaces - asUINT GetInterfaceCount() const { return 0; } - asITypeInfo *GetInterface(asUINT index) const { UNUSED_VAR(index); return 0; } - bool Implements(const asITypeInfo *objType) const { UNUSED_VAR(objType); return false; } + asUINT GetInterfaceCount() const + { + return 0; + } + asITypeInfo *GetInterface(asUINT index) const + { + UNUSED_VAR(index); + return 0; + } + bool Implements(const asITypeInfo *objType) const + { + UNUSED_VAR(objType); + return false; + } // Factories - asUINT GetFactoryCount() const { return 0; } - asIScriptFunction *GetFactoryByIndex(asUINT index) const { UNUSED_VAR(index); return 0; } - asIScriptFunction *GetFactoryByDecl(const char *decl) const { UNUSED_VAR(decl); return 0; } + asUINT GetFactoryCount() const + { + return 0; + } + asIScriptFunction *GetFactoryByIndex(asUINT index) const + { + UNUSED_VAR(index); + return 0; + } + asIScriptFunction *GetFactoryByDecl(const char *decl) const + { + UNUSED_VAR(decl); + return 0; + } // Methods - asUINT GetMethodCount() const { return 0; } - asIScriptFunction *GetMethodByIndex(asUINT index, bool getVirtual) const { UNUSED_VAR(index); UNUSED_VAR(getVirtual); return 0; } - asIScriptFunction *GetMethodByName(const char *in_name, bool getVirtual) const { UNUSED_VAR(in_name); UNUSED_VAR(getVirtual); return 0; } - asIScriptFunction *GetMethodByDecl(const char *decl, bool getVirtual) const { UNUSED_VAR(decl); UNUSED_VAR(getVirtual); return 0; } + asUINT GetMethodCount() const + { + return 0; + } + asIScriptFunction *GetMethodByIndex(asUINT index, bool getVirtual) const + { + UNUSED_VAR(index); + UNUSED_VAR(getVirtual); + return 0; + } + asIScriptFunction *GetMethodByName(const char *in_name, bool getVirtual) const + { + UNUSED_VAR(in_name); + UNUSED_VAR(getVirtual); + return 0; + } + asIScriptFunction *GetMethodByDecl(const char *decl, bool getVirtual) const + { + UNUSED_VAR(decl); + UNUSED_VAR(getVirtual); + return 0; + } // Properties - asUINT GetPropertyCount() const { return 0; } + asUINT GetPropertyCount() const + { + return 0; + } int GetProperty(asUINT index, const char **name, int *typeId, bool *isPrivate, bool *isProtected, int *offset, bool *isReference, asDWORD *accessMask, int *compositeOffset, bool *isCompositeIndirect, bool *isConst) const; - const char *GetPropertyDeclaration(asUINT index, bool includeNamespace = false) const { UNUSED_VAR(index); UNUSED_VAR(includeNamespace); return 0; } + const char *GetPropertyDeclaration(asUINT index, bool includeNamespace = false) const + { + UNUSED_VAR(index); + UNUSED_VAR(includeNamespace); + return 0; + } // Behaviours - asUINT GetBehaviourCount() const { return 0; } - asIScriptFunction *GetBehaviourByIndex(asUINT index, asEBehaviours *outBehaviour) const { UNUSED_VAR(index); UNUSED_VAR(outBehaviour); return 0; } + asUINT GetBehaviourCount() const + { + return 0; + } + asIScriptFunction *GetBehaviourByIndex(asUINT index, asEBehaviours *outBehaviour) const + { + UNUSED_VAR(index); + UNUSED_VAR(outBehaviour); + return 0; + } // Child types - asUINT GetChildFuncdefCount() const { return 0; } - asITypeInfo *GetChildFuncdef(asUINT index) const { UNUSED_VAR(index); return 0; } - asITypeInfo *GetParentType() const { return 0; } + asUINT GetChildFuncdefCount() const + { + return 0; + } + asITypeInfo *GetChildFuncdef(asUINT index) const + { + UNUSED_VAR(index); + return 0; + } + asITypeInfo *GetParentType() const + { + return 0; + } // Enums - asUINT GetEnumValueCount() const { return 0; } - const char *GetEnumValueByIndex(asUINT index, asINT64 *outValue) const { UNUSED_VAR(index); if (outValue) *outValue = 0; return 0; } + asUINT GetEnumValueCount() const + { + return 0; + } + const char *GetEnumValueByIndex(asUINT index, asINT64 *outValue) const + { + UNUSED_VAR(index); + if( outValue ) *outValue = 0; + return 0; + } #ifdef AS_DEPRECATED // deprecated since 2025-09-13, 2.39.0 // Typedef - int GetTypedefTypeId() const { return asERROR; } + int GetTypedefTypeId() const + { + return asERROR; + } #endif // Funcdef - asIScriptFunction *GetFuncdefSignature() const { return 0; } + asIScriptFunction *GetFuncdefSignature() const + { + return 0; + } // User data void *SetUserData(void *data, asPWORD type); @@ -142,12 +243,14 @@ class asCTypeInfo : public asITypeInfo asCTypeInfo(asCScriptEngine *engine); virtual ~asCTypeInfo(); - // Keep an internal reference counter to separate references coming from + // Keep an internal reference counter to separate references coming from // application or script objects and references coming from the script code virtual int AddRefInternal(); virtual int ReleaseInternal(); - virtual void DestroyInternal() {} + virtual void DestroyInternal() + { + } void CleanUserData(); @@ -160,17 +263,17 @@ class asCTypeInfo : public asITypeInfo friend asCFuncdefType *CastToFuncdefType(asCTypeInfo *); - asCString name; - asSNameSpace *nameSpace; - int size; - mutable int typeId; - asQWORD flags; - asDWORD accessMask; + asCString name; + asSNameSpace *nameSpace; + int size; + mutable int typeId; + asQWORD flags; + asDWORD accessMask; // Store the script section where the code was declared - int scriptSectionIdx; + int scriptSectionIdx; // Store the location where the function was declared (row in the lower 20 bits, and column in the upper 12) - int declaredAt; + int declaredAt; asCScriptEngine *engine; asCModule *module; @@ -192,17 +295,21 @@ struct asSEnumValue asCString name; asINT64 value; - asSEnumValue() : value(0) {} + asSEnumValue() : value(0) + { + } }; class asCEnumType : public asCTypeInfo { public: - asCEnumType(asCScriptEngine *engine) : asCTypeInfo(engine) {} + asCEnumType(asCScriptEngine *engine) : asCTypeInfo(engine) + { + } ~asCEnumType(); - asCArray enumValues; - asCDataType enumType; + asCArray enumValues; + asCDataType enumType; asUINT GetEnumValueCount() const; const char *GetEnumValueByIndex(asUINT index, asINT64 *outValue) const; @@ -210,13 +317,17 @@ class asCEnumType : public asCTypeInfo int GetUnderlyingTypeId() const; protected: - asCEnumType() : asCTypeInfo() {} + asCEnumType() : asCTypeInfo() + { + } }; class asCTypedefType : public asCTypeInfo { public: - asCTypedefType(asCScriptEngine *engine) : asCTypeInfo(engine) {} + asCTypedefType(asCScriptEngine *engine) : asCTypeInfo(engine) + { + } ~asCTypedefType(); void DestroyInternal(); @@ -230,7 +341,9 @@ class asCTypedefType : public asCTypeInfo #endif protected: - asCTypedefType() : asCTypeInfo() {} + asCTypedefType() : asCTypeInfo() + { + } }; class asCFuncdefType : public asCTypeInfo @@ -242,12 +355,14 @@ class asCFuncdefType : public asCTypeInfo asIScriptFunction *GetFuncdefSignature() const; asITypeInfo *GetParentType() const; - void DestroyInternal(); + void DestroyInternal(); asCScriptFunction *funcdef; // increases refCount asCObjectType *parentClass; // doesn't increase refCount protected: - asCFuncdefType() : asCTypeInfo(), funcdef(0), parentClass(0) {} + asCFuncdefType() : asCTypeInfo(), funcdef(0), parentClass(0) + { + } }; END_AS_NAMESPACE diff --git a/sdk/angelscript/source/as_variablescope.cpp b/sdk/angelscript/source/as_variablescope.cpp index aca36dae..46b65654 100644 --- a/sdk/angelscript/source/as_variablescope.cpp +++ b/sdk/angelscript/source/as_variablescope.cpp @@ -40,13 +40,13 @@ #ifndef AS_NO_COMPILER -#include "as_variablescope.h" + #include "as_variablescope.h" BEGIN_AS_NAMESPACE asCVariableScope::asCVariableScope(asCVariableScope *parent) { - this->parent = parent; + this->parent = parent; Reset(); } @@ -57,13 +57,13 @@ asCVariableScope::~asCVariableScope() void asCVariableScope::Reset() { - isBreakScope = false; + isBreakScope = false; isContinueScope = false; for( asUINT n = 0; n < variables.GetLength(); n++ ) - if( variables[n] ) + if( variables[n] ) { - asDELETE(variables[n],sVariable); + asDELETE(variables[n], sVariable); } variables.SetLength(0); } @@ -138,5 +138,3 @@ sVariable *asCVariableScope::GetVariableByOffset(int offset) END_AS_NAMESPACE #endif // AS_NO_COMPILER - - diff --git a/sdk/angelscript/source/as_variablescope.h b/sdk/angelscript/source/as_variablescope.h index d4b220a0..d55eb69e 100644 --- a/sdk/angelscript/source/as_variablescope.h +++ b/sdk/angelscript/source/as_variablescope.h @@ -43,9 +43,9 @@ #ifndef AS_NO_COMPILER -#include "as_array.h" -#include "as_string.h" -#include "as_datatype.h" + #include "as_array.h" + #include "as_string.h" + #include "as_datatype.h" BEGIN_AS_NAMESPACE @@ -68,7 +68,7 @@ class asCVariableScope void Reset(); - int DeclareVariable(const char *name, const asCDataType &type, int stackOffset, bool isObjectOnHeap); + int DeclareVariable(const char *name, const asCDataType &type, int stackOffset, bool isObjectOnHeap); sVariable *GetVariable(const char *name); sVariable *GetVariableByOffset(int offset);