/indra/lscript/lscript_compile/lscript_tree.cpp
C++ | 2002 lines | 1954 code | 19 blank | 29 comment | 4 complexity | 9a642e4b3c4c6c134920499e3410d98b MD5 | raw file
Possible License(s): LGPL-2.1
- /**
- * @file lscript_tree.cpp
- * @brief implements methods for lscript_tree.h classes
- *
- * $LicenseInfo:firstyear=2002&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
- // TO DO: Move print functionality from .h file to here
- #include "linden_common.h"
- #include "lscript_tree.h"
- #include "lscript_typecheck.h"
- #include "lscript_resource.h"
- #include "lscript_bytecode.h"
- #include "lscript_heap.h"
- #include "lscript_library.h"
- #include "lscript_alloc.h"
- //#define LSL_INCLUDE_DEBUG_INFO
- static void print_cil_box(LLFILE* fp, LSCRIPTType type)
- {
-
- switch(type)
- {
- case LST_INTEGER:
- fprintf(fp, "box [mscorlib]System.Int32\n");
- break;
- case LST_FLOATINGPOINT:
- fprintf(fp, "box [mscorlib]System.Single\n");
- break;
- case LST_STRING:
- // System.String is not a System.ValueType,
- // so does not need to be boxed.
- break;
- case LST_KEY:
- fprintf(fp, "box [ScriptTypes]LindenLab.SecondLife.Key\n");
- break;
- case LST_VECTOR:
- fprintf(fp, "box [ScriptTypes]LindenLab.SecondLife.Vector\n");
- break;
- case LST_QUATERNION:
- fprintf(fp, "box [ScriptTypes]LindenLab.SecondLife.Quaternion\n");
- break;
- default:
- llassert(false);
- break;
- }
- }
- static void print_cil_type(LLFILE* fp, LSCRIPTType type)
- {
- switch(type)
- {
- case LST_INTEGER:
- fprintf(fp, "int32");
- break;
- case LST_FLOATINGPOINT:
- fprintf(fp, "float32");
- break;
- case LST_STRING:
- fprintf(fp, "string");
- break;
- case LST_KEY:
- fprintf(fp, "valuetype [ScriptTypes]LindenLab.SecondLife.Key");
- break;
- case LST_VECTOR:
- fprintf(fp, "class [ScriptTypes]LindenLab.SecondLife.Vector");
- break;
- case LST_QUATERNION:
- fprintf(fp, "class [ScriptTypes]LindenLab.SecondLife.Quaternion");
- break;
- case LST_LIST:
- fprintf(fp, "class [mscorlib]System.Collections.ArrayList");
- break;
- case LST_NULL:
- fprintf(fp, "void");
- break;
- default:
- break;
- }
- }
- void LLScriptType::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- case LSCP_EMIT_ASSEMBLY:
- fprintf(fp,"%s",LSCRIPTTypeNames[mType]);
- break;
- case LSCP_TYPE:
- type = mType;
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- print_cil_type(fp, mType);
- break;
- default:
- break;
- }
- }
- S32 LLScriptType::getSize()
- {
- return LSCRIPTDataSize[mType];
- }
- void LLScriptConstant::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- case LSCP_EMIT_ASSEMBLY:
- fprintf(fp,"Script Constant Base class -- should never get here!\n");
- break;
- default:
- break;
- }
- }
- S32 LLScriptConstant::getSize()
- {
- printf("Script Constant Base class -- should never get here!\n");
- return 0;
- }
- void LLScriptConstantInteger::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- fprintf(fp, "%d", mValue);
- break;
- case LSCP_EMIT_ASSEMBLY:
- fprintf(fp, "PUSHARGI %d\n", mValue);
- break;
- case LSCP_TYPE:
- type = mType;
- break;
- case LSCP_EMIT_BYTE_CODE:
- {
- chunk->addInteger(mValue);
- type = mType;
- }
- break;
- case LSCP_TO_STACK:
- {
- chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGI]);
- chunk->addInteger(mValue);
- type = mType;
- }
- break;
- case LSCP_LIST_BUILD_SIMPLE:
- {
- *ldata = new LLScriptLibData(mValue);
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- fprintf(fp, "ldc.i4 %d\n", mValue);
- type = mType;
- break;
- default:
- break;
- }
- }
- S32 LLScriptConstantInteger::getSize()
- {
- return LSCRIPTDataSize[LST_INTEGER];
- }
- void LLScriptConstantFloat::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- fprintf(fp, "%5.5f", mValue);
- break;
- case LSCP_EMIT_ASSEMBLY:
- fprintf(fp, "PUSHARGF %5.5f\n", mValue);
- break;
- case LSCP_TYPE:
- type = mType;
- break;
- case LSCP_EMIT_BYTE_CODE:
- {
- chunk->addFloat(mValue);
- type = mType;
- }
- break;
- case LSCP_TO_STACK:
- {
- chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGF]);
- chunk->addFloat(mValue);
- type = mType;
- }
- break;
- case LSCP_LIST_BUILD_SIMPLE:
- {
- *ldata = new LLScriptLibData(mValue);
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- {
- double v = (double)mValue;
- U8 * p = (U8 *)&v; // See ECMA-335 Partition VI, Appendix C.4.6 Examples, line 4
- fprintf(fp, "ldc.r8 (%02x %02x %02x %02x %02x %02x %02x %02x)\n", p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
- type = mType;
- }
- break;
- default:
- break;
- }
- }
- S32 LLScriptConstantFloat::getSize()
- {
- return LSCRIPTDataSize[LST_FLOATINGPOINT];
- }
- void print_escaped(LLFILE* fp, const char* str)
- {
- putc('"', fp);
- for(const char* c = str; *c != '\0'; ++c)
- {
- switch(*c)
- {
- case '"':
- putc('\\', fp);
- putc(*c, fp);
- break;
- case '\n':
- putc('\\', fp);
- putc('n', fp);
- break;
- case '\t':
- putc(' ', fp);
- putc(' ', fp);
- putc(' ', fp);
- putc(' ', fp);
- break;
- case '\\':
- putc('\\', fp);
- putc('\\', fp);
- break;
- default:
- putc(*c, fp);
- }
- }
- putc('"', fp);
- }
- void LLScriptConstantString::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- fprintf(fp, "\"%s\"", mValue);
- break;
- case LSCP_EMIT_ASSEMBLY:
- fprintf(fp, "PUSHARGS \"%s\"\n", mValue);
- break;
- case LSCP_TYPE:
- type = mType;
- break;
- case LSCP_EMIT_BYTE_CODE:
- {
- chunk->addInteger(heap->mCurrentOffset + 1);
- LLScriptLibData *data = new LLScriptLibData(mValue);
- U8 *temp;
- S32 size = lsa_create_data_block(&temp, data, heap->mCurrentOffset);
- heap->addBytes(temp, size);
- delete [] temp;
- delete data;
- }
- break;
- case LSCP_TO_STACK:
- {
- chunk->addByte(LSCRIPTOpCodes[LOPC_PUSHARGS]);
- chunk->addBytes(mValue, (S32)strlen(mValue) + 1);
- type = mType;
- }
- break;
- case LSCP_LIST_BUILD_SIMPLE:
- {
- *ldata = new LLScriptLibData(mValue);
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- fprintf(fp, "ldstr ");
- print_escaped(fp, mValue);
- fprintf(fp, "\n");
- default:
- break;
- }
- }
- S32 LLScriptConstantString::getSize()
- {
- return (S32)strlen(mValue) + 1;
- }
- void LLScriptIdentifier::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- fprintf(fp, "%s", mName);
- break;
- case LSCP_EMIT_ASSEMBLY:
- if (mScopeEntry)
- {
- if (mScopeEntry->mIDType == LIT_VARIABLE)
- {
- fprintf(fp, "$BP + %d [%s]", mScopeEntry->mOffset, mName);
- }
- else if (mScopeEntry->mIDType == LIT_GLOBAL)
- {
- fprintf(fp, "$GVR + %d [%s]", mScopeEntry->mOffset, mName);
- }
- else
- {
- fprintf(fp, "%s", mName);
- }
- }
- break;
- case LSCP_TYPE:
- if (mScopeEntry)
- type = mScopeEntry->mType;
- else
- type = LST_NULL;
- break;
- case LSCP_RESOURCE:
- if (mScopeEntry)
- {
- if (mScopeEntry->mIDType == LIT_VARIABLE)
- {
- // fprintf(fp, "LOCAL : %d : %d : %s\n", mScopeEntry->mOffset, mScopeEntry->mSize, mName);
- }
- else if (mScopeEntry->mIDType == LIT_GLOBAL)
- {
- // fprintf(fp, "GLOBAL: %d : %d : %s\n", mScopeEntry->mOffset, mScopeEntry->mSize, mName);
- }
- }
- break;
- case LSCP_LIST_BUILD_SIMPLE:
- {
- if (mScopeEntry)
- {
- if (mScopeEntry->mType == LST_LIST)
- {
- gErrorToText.writeError(fp, this, LSERROR_NO_LISTS_IN_LISTS);
- }
- else if (mScopeEntry->mAssignable)
- {
- mScopeEntry->mAssignable->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, ldata);
- }
- else
- {
- gErrorToText.writeError(fp, this, LSERROR_NO_UNITIALIZED_VARIABLES_IN_LISTS);
- }
- }
- else
- {
- gErrorToText.writeError(fp, this, LSERROR_UNDEFINED_NAME);
- }
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- fprintf(fp, "'%s'", mName);
- break;
- default:
- break;
- }
- }
- S32 LLScriptIdentifier::getSize()
- {
-
- return 0;
- }
- void LLScriptSimpleAssignable::addAssignable(LLScriptSimpleAssignable *assign)
- {
- if (mNextp)
- {
- assign->mNextp = mNextp;
- }
- mNextp = assign;
- }
- void LLScriptSimpleAssignable::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- fprintf(fp, "Simple Assignable Base Class -- should never get here!\n");
- }
- S32 LLScriptSimpleAssignable::getSize()
- {
-
- printf("Simple Assignable Base Class -- should never get here!\n");
- return 0;
- }
- static void print_cil_member(LLFILE* fp, LLScriptIdentifier *ident)
- {
- print_cil_type(fp, ident->mScopeEntry->mType);
- fprintf(fp, " %s::'%s'\n", gScriptp->getClassName(), ident->mScopeEntry->mIdentifier);
- }
- void LLScriptSAIdentifier::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- case LSCP_EMIT_ASSEMBLY:
- mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (mNextp)
- {
- fprintf(fp, ", ");
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- case LSCP_SCOPE_PASS1:
- {
- LLScriptScopeEntry *entry = scope->findEntry(mIdentifier->mName);
- if (!entry)
- {
- gErrorToText.writeError(fp, this, LSERROR_UNDEFINED_NAME);
- }
- else
- {
- // if we did find it, make sure this identifier is associated with the correct scope entry
- mIdentifier->mScopeEntry = entry;
- }
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- }
- break;
- case LSCP_EMIT_BYTE_CODE:
- {
- if (mIdentifier->mScopeEntry)
- {
- if(mIdentifier->mScopeEntry->mAssignable)
- {
- mIdentifier->mScopeEntry->mAssignable->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- else
- {
- // Babbage: 29/8/06: If the scope entry has no mAssignable,
- // set the default type and add the default 0 value to the
- // chunk. Without this SAVectors and SAQuaternions will
- // assume the arbitrary current type is the assignable type
- // and may attempt to access a null chunk. (SL-20156)
- type = mIdentifier->mScopeEntry->mType;
- chunk->addBytes(LSCRIPTDataSize[type]);
- }
- }
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- }
- break;
- case LSCP_LIST_BUILD_SIMPLE:
- {
- mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, ldata);
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, &(*ldata)->mListp);
- }
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- {
- fprintf(fp, "ldarg.0\n");
- fprintf(fp, "ldfld ");
- print_cil_member(fp, mIdentifier);
- fprintf(fp, "\n");
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- }
- default:
- mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- }
- }
- S32 LLScriptSAIdentifier::getSize()
- {
- return mIdentifier->getSize();
- }
- void LLScriptSAConstant::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- case LSCP_EMIT_ASSEMBLY:
- mConstant->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (mNextp)
- {
- fprintf(fp, ", ");
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- case LSCP_LIST_BUILD_SIMPLE:
- {
- mConstant->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, ldata);
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, &(*ldata)->mListp);
- }
- }
- break;
- default:
- mConstant->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- }
- }
- S32 LLScriptSAConstant::getSize()
- {
- return mConstant->getSize();
- }
- static void print_cil_cast(LLFILE* fp, LSCRIPTType srcType, LSCRIPTType targetType)
- {
- switch(srcType)
- {
- case LST_INTEGER:
- switch(targetType)
- {
- case LST_FLOATINGPOINT:
- fprintf(fp, "conv.r8\n");
- break;
- case LST_STRING:
- fprintf(fp, "call string class [mscorlib]System.Convert::ToString(int32)\n");
- break;
- case LST_LIST:
- print_cil_box(fp, LST_INTEGER);
- fprintf(fp, "call class [mscorlib]System.Collections.ArrayList class [LslUserScript]LindenLab.SecondLife.LslUserScript::CreateList(object)\n");
- break;
- default:
- break;
- }
- break;
- case LST_FLOATINGPOINT:
- switch(targetType)
- {
- case LST_INTEGER:
- fprintf(fp, "call int32 [LslLibrary]LindenLab.SecondLife.LslRunTime::ToInteger(float32)\n");
- break;
- case LST_STRING:
- fprintf(fp, "call string [LslLibrary]LindenLab.SecondLife.LslRunTime::ToString(float32)\n");
- break;
- case LST_LIST:
- print_cil_box(fp, LST_FLOATINGPOINT);
- fprintf(fp, "call class [mscorlib]System.Collections.ArrayList class [LslUserScript]LindenLab.SecondLife.LslUserScript::CreateList(object)\n");
- break;
- default:
- break;
- }
- break;
- case LST_STRING:
- switch(targetType)
- {
- case LST_INTEGER:
- fprintf(fp, "call int32 [LslLibrary]LindenLab.SecondLife.LslRunTime::StringToInt(string)\n");
- break;
- case LST_FLOATINGPOINT:
- fprintf(fp, "call float32 [LslLibrary]LindenLab.SecondLife.LslRunTime::StringToFloat(string)\n");
- break;
- case LST_KEY:
- fprintf(fp, "call valuetype [ScriptTypes]LindenLab.SecondLife.Key class [LslUserScript]LindenLab.SecondLife.LslUserScript::'CreateKey'(string)\n");
- break;
- case LST_LIST:
- fprintf(fp, "call class [mscorlib]System.Collections.ArrayList class [LslUserScript]LindenLab.SecondLife.LslUserScript::CreateList(object)\n");
- break;
- case LST_VECTOR:
- fprintf(fp, "call class [ScriptTypes]LindenLab.SecondLife.Vector class [LslUserScript]LindenLab.SecondLife.LslUserScript::'ParseVector'(string)\n");
- break;
- case LST_QUATERNION:
- fprintf(fp, "call class [ScriptTypes]LindenLab.SecondLife.Quaternion class [LslUserScript]LindenLab.SecondLife.LslUserScript::'ParseQuaternion'(string)\n");
- break;
- default:
- break;
- }
- break;
- case LST_KEY:
- switch(targetType)
- {
- case LST_KEY:
- break;
- case LST_STRING:
- fprintf(fp, "call string [LslUserScript]LindenLab.SecondLife.LslUserScript::'ToString'(valuetype [ScriptTypes]LindenLab.SecondLife.Key)\n");
- break;
- case LST_LIST:
- print_cil_box(fp, LST_KEY);
- fprintf(fp, "call class [mscorlib]System.Collections.ArrayList class [LslUserScript]LindenLab.SecondLife.LslUserScript::CreateList(object)\n");
- break;
- default:
- break;
- }
- break;
- case LST_VECTOR:
- switch(targetType)
- {
- case LST_VECTOR:
- break;
- case LST_STRING:
- fprintf(fp, "call string [LslUserScript]LindenLab.SecondLife.LslUserScript::'ToString'(valuetype [ScriptTypes]LindenLab.SecondLife.Vector)\n");
- break;
- case LST_LIST:
- print_cil_box(fp, LST_VECTOR);
- fprintf(fp, "call class [mscorlib]System.Collections.ArrayList class [LslUserScript]LindenLab.SecondLife.LslUserScript::CreateList(object)\n");
- break;
- default:
- break;
- }
- break;
- case LST_QUATERNION:
- switch(targetType)
- {
- case LST_QUATERNION:
- break;
- case LST_STRING:
- fprintf(fp, "call string [LslUserScript]LindenLab.SecondLife.LslUserScript::'ToString'(valuetype [ScriptTypes]LindenLab.SecondLife.Quaternion)\n");
- break;
- case LST_LIST:
- print_cil_box(fp, LST_QUATERNION);
- fprintf(fp, "call class [mscorlib]System.Collections.ArrayList class [LslUserScript]LindenLab.SecondLife.LslUserScript::CreateList(object)\n");
- break;
- default:
- break;
- }
- break;
- case LST_LIST:
- switch(targetType)
- {
- case LST_LIST:
- break;
- case LST_STRING:
- fprintf(fp, "call string [LslLibrary]LindenLab.SecondLife.LslRunTime::ListToString(class [mscorlib]System.Collections.ArrayList)\n");
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
- }
- static void print_cil_numeric_cast(LLFILE* fp, LSCRIPTType currentArg, LSCRIPTType otherArg)
- {
- if((currentArg == LST_INTEGER) && ((otherArg == LST_FLOATINGPOINT) || (otherArg == LST_VECTOR)))
- {
- print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT);
- }
- }
- static void print_cil_assignment_cast(LLFILE* fp, LSCRIPTType src,
- LSCRIPTType dest)
- {
- if (LST_STRING == src && LST_KEY == dest)
- {
- print_cil_cast(fp, src, dest);
- }
- else if(LST_KEY == src && LST_STRING == dest)
- {
- print_cil_cast(fp, src, dest);
- }
- else
- {
- print_cil_numeric_cast(fp, src, dest);
- }
- }
-
- // HACK! Babbage: should be converted to virtual on LSCRIPTSimpleAssignableType to avoid downcasts.
- LSCRIPTType get_type(LLScriptSimpleAssignable* sa)
- {
- LSCRIPTType result = LST_NULL;
- switch(sa->mType)
- {
- case LSSAT_IDENTIFIER:
- result = ((LLScriptSAIdentifier*) sa)->mIdentifier->mScopeEntry->mType;
- break;
- case LSSAT_CONSTANT:
- result = ((LLScriptSAConstant*) sa)->mConstant->mType;
- break;
- case LSSAT_VECTOR_CONSTANT:
- result = LST_VECTOR;
- break;
- case LSSAT_QUATERNION_CONSTANT:
- result = LST_QUATERNION;
- break;
- case LSSAT_LIST_CONSTANT:
- result = LST_LIST;
- break;
- default:
- result = LST_UNDEFINED;
- break;
- }
- return result;
- }
- void LLScriptSAVector::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- case LSCP_EMIT_ASSEMBLY:
- fprintf(fp, "< ");
- mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, ", ");
- mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, ", ");
- mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, " >");
- if (mNextp)
- {
- fprintf(fp, ", ");
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- case LSCP_TYPE:
- // vector's take floats
- mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (!legal_assignment(LST_FLOATINGPOINT, type))
- {
- gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH);
- }
- mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (!legal_assignment(LST_FLOATINGPOINT, type))
- {
- gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH);
- }
- mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (!legal_assignment(LST_FLOATINGPOINT, type))
- {
- gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH);
- }
- type = LST_VECTOR;
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- case LSCP_EMIT_BYTE_CODE:
- mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (type == LST_INTEGER)
- {
- S32 offset = chunk->mCurrentOffset - 4;
- bytestream_int2float(chunk->mCodeChunk, offset);
- }
- mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (type == LST_INTEGER)
- {
- S32 offset = chunk->mCurrentOffset - 4;
- bytestream_int2float(chunk->mCodeChunk, offset);
- }
- mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (type == LST_INTEGER)
- {
- S32 offset = chunk->mCurrentOffset - 4;
- bytestream_int2float(chunk->mCodeChunk, offset);
- }
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- case LSCP_LIST_BUILD_SIMPLE:
- {
- LLScriptByteCodeChunk *list = new LLScriptByteCodeChunk(FALSE);
- mEntry3->recurse(fp, tabs, tabsize, LSCP_EMIT_BYTE_CODE, ptype, prunearg, scope, type, basetype, count, list, heap, stacksize, entry, entrycount, NULL);
- if (type == LST_INTEGER)
- {
- S32 offset = list->mCurrentOffset - 4;
- bytestream_int2float(list->mCodeChunk, offset);
- }
- mEntry2->recurse(fp, tabs, tabsize, LSCP_EMIT_BYTE_CODE, ptype, prunearg, scope, type, basetype, count, list, heap, stacksize, entry, entrycount, NULL);
- if (type == LST_INTEGER)
- {
- S32 offset = list->mCurrentOffset - 4;
- bytestream_int2float(list->mCodeChunk, offset);
- }
- mEntry1->recurse(fp, tabs, tabsize, LSCP_EMIT_BYTE_CODE, ptype, prunearg, scope, type, basetype, count, list, heap, stacksize, entry, entrycount, NULL);
- if (type == LST_INTEGER)
- {
- S32 offset = list->mCurrentOffset - 4;
- bytestream_int2float(list->mCodeChunk, offset);
- }
- LLVector3 vec;
- S32 offset = 0;
- bytestream2vector(vec, list->mCodeChunk, offset);
- *ldata = new LLScriptLibData(vec);
- delete list;
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, &(*ldata)->mListp);
- }
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- // Load arguments.
- mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if(LST_INTEGER == get_type(mEntry1))
- {
- print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT);
- }
- mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if(LST_INTEGER == get_type(mEntry2))
- {
- print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT);
- }
- mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if(LST_INTEGER == get_type(mEntry3))
- {
- print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT);
- }
-
- // Call named ctor, which leaves new Vector on stack, so it can be saved in to local or argument just like a primitive type.
- fprintf(fp, "call class [ScriptTypes]LindenLab.SecondLife.Vector class [LslUserScript]LindenLab.SecondLife.LslUserScript::'CreateVector'(float32, float32, float32)\n");
- // Next.
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- default:
- mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- }
- }
- S32 LLScriptSAVector::getSize()
- {
- return mEntry1->getSize() + mEntry2->getSize() + mEntry3->getSize();
- }
- void LLScriptSAQuaternion::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- case LSCP_EMIT_ASSEMBLY:
- fprintf(fp, "< ");
- mEntry4->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, ", ");
- mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, ", ");
- mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, ", ");
- mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, " >");
- if (mNextp)
- {
- fprintf(fp, ", ");
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- case LSCP_TYPE:
- // vector's take floats
- mEntry4->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (!legal_assignment(LST_FLOATINGPOINT, type))
- {
- gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH);
- }
- mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (!legal_assignment(LST_FLOATINGPOINT, type))
- {
- gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH);
- }
- mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (!legal_assignment(LST_FLOATINGPOINT, type))
- {
- gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH);
- }
- mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (!legal_assignment(LST_FLOATINGPOINT, type))
- {
- gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH);
- }
- type = LST_QUATERNION;
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- case LSCP_EMIT_BYTE_CODE:
- mEntry4->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (type == LST_INTEGER)
- {
- S32 offset = chunk->mCurrentOffset - 4;
- bytestream_int2float(chunk->mCodeChunk, offset);
- }
- mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (type == LST_INTEGER)
- {
- S32 offset = chunk->mCurrentOffset - 4;
- bytestream_int2float(chunk->mCodeChunk, offset);
- }
- mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (type == LST_INTEGER)
- {
- S32 offset = chunk->mCurrentOffset - 4;
- bytestream_int2float(chunk->mCodeChunk, offset);
- }
- mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (type == LST_INTEGER)
- {
- S32 offset = chunk->mCurrentOffset - 4;
- bytestream_int2float(chunk->mCodeChunk, offset);
- }
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- case LSCP_LIST_BUILD_SIMPLE:
- {
- LLScriptByteCodeChunk *list = new LLScriptByteCodeChunk(FALSE);
- mEntry4->recurse(fp, tabs, tabsize, LSCP_EMIT_BYTE_CODE, ptype, prunearg, scope, type, basetype, count, list, heap, stacksize, entry, entrycount, NULL);
- if (type == LST_INTEGER)
- {
- S32 offset = list->mCurrentOffset - 4;
- bytestream_int2float(list->mCodeChunk, offset);
- }
- mEntry3->recurse(fp, tabs, tabsize, LSCP_EMIT_BYTE_CODE, ptype, prunearg, scope, type, basetype, count, list, heap, stacksize, entry, entrycount, NULL);
- if (type == LST_INTEGER)
- {
- S32 offset = list->mCurrentOffset - 4;
- bytestream_int2float(list->mCodeChunk, offset);
- }
- mEntry2->recurse(fp, tabs, tabsize, LSCP_EMIT_BYTE_CODE, ptype, prunearg, scope, type, basetype, count, list, heap, stacksize, entry, entrycount, NULL);
- if (type == LST_INTEGER)
- {
- S32 offset = list->mCurrentOffset - 4;
- bytestream_int2float(list->mCodeChunk, offset);
- }
- mEntry1->recurse(fp, tabs, tabsize, LSCP_EMIT_BYTE_CODE, ptype, prunearg, scope, type, basetype, count, list, heap, stacksize, entry, entrycount, NULL);
- if (type == LST_INTEGER)
- {
- S32 offset = list->mCurrentOffset - 4;
- bytestream_int2float(list->mCodeChunk, offset);
- }
- LLQuaternion quat;
- S32 offset = 0;
- bytestream2quaternion(quat, list->mCodeChunk, offset);
- *ldata = new LLScriptLibData(quat);
- delete list;
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, &(*ldata)->mListp);
- }
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- // Load arguments.
- mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if(LST_INTEGER == get_type(mEntry1))
- {
- print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT);
- }
- mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if(LST_INTEGER == get_type(mEntry2))
- {
- print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT);
- }
- mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if(LST_INTEGER == get_type(mEntry3))
- {
- print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT);
- }
- mEntry4->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if(LST_INTEGER == get_type(mEntry4))
- {
- print_cil_cast(fp, LST_INTEGER, LST_FLOATINGPOINT);
- }
-
- // Call named ctor, which leaves new Vector on stack, so it can be saved in to local or argument just like a primitive type.
- fprintf(fp, "call class [ScriptTypes]LindenLab.SecondLife.Quaternion class [LslUserScript]LindenLab.SecondLife.LslUserScript::'CreateQuaternion'(float32, float32, float32, float32)\n");
- // Next.
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- default:
- mEntry4->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- mEntry3->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- mEntry2->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- mEntry1->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- }
- }
- S32 LLScriptSAQuaternion::getSize()
- {
- return mEntry1->getSize() + mEntry2->getSize() + mEntry3->getSize() + mEntry4->getSize();
- }
- void LLScriptSAList::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- case LSCP_EMIT_ASSEMBLY:
- fprintf(fp, "[ ");
- if (mEntryList)
- mEntryList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, " ]");
- if (mNextp)
- {
- fprintf(fp, ", ");
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- case LSCP_TYPE:
- if (mEntryList)
- mEntryList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- type = LST_LIST;
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- case LSCP_EMIT_BYTE_CODE:
- {
- LLScriptLibData *list_data = new LLScriptLibData;
- list_data->mType = LST_LIST;
- if (mEntryList)
- mEntryList->recurse(fp, tabs, tabsize, LSCP_LIST_BUILD_SIMPLE, ptype, prunearg, scope, type, basetype, count, chunk, NULL, stacksize, entry, entrycount, &(list_data->mListp));
- U8 *temp;
- chunk->addInteger(heap->mCurrentOffset + 1);
- S32 size = lsa_create_data_block(&temp, list_data, heap->mCurrentOffset);
- heap->addBytes(temp, size);
- delete list_data;
- delete [] temp;
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, LSCP_EMIT_BYTE_CODE, ptype, prunearg, scope, type, basetype, count, chunk, NULL, stacksize, entry, entrycount, NULL);
- }
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- {
- // Create list.
- fprintf(fp, "call class [mscorlib]System.Collections.ArrayList [LslUserScript]LindenLab.SecondLife.LslUserScript::CreateList()\n");
- // Add elements.
- LLScriptSimpleAssignable* current_entry = mEntryList;
- LLScriptSimpleAssignable* next_entry = NULL;
- while(NULL != current_entry)
- {
- next_entry = current_entry->mNextp;
- // Null mNextp pointer, so only current list element is processed.
- current_entry->mNextp = NULL;
- current_entry->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- // Restore mNextp pointer.
- current_entry->mNextp = next_entry;
- // Box element and store in list.
- print_cil_box(fp, get_type(current_entry));
- fprintf(fp, "call class [mscorlib]System.Collections.ArrayList class [LslUserScript]LindenLab.SecondLife.LslUserScript::Append(class [mscorlib]System.Collections.ArrayList, object)\n");
- // Process next element.
- current_entry = next_entry;
- }
- // Process next list.
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- }
- break;
- default:
- if (mEntryList)
- mEntryList->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, ldata);
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, ldata);
- }
- break;
- }
- }
- S32 LLScriptSAList::getSize()
- {
- return mEntryList->getSize();
- }
- void LLScriptGlobalVariable::addGlobal(LLScriptGlobalVariable *global)
- {
- if (mNextp)
- {
- global->mNextp = mNextp;
- }
- mNextp = global;
- }
- void LLScriptGlobalVariable::gonext(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- default:
- if (mNextp)
- {
- mNextp->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- }
- }
- // Push initialised variable of type on to stack.
- static void print_cil_init_variable(LLFILE* fp, LSCRIPTType type)
- {
- switch(type)
- {
- case LST_INTEGER:
- fprintf(fp, "ldc.i4.0\n");
- break;
- case LST_FLOATINGPOINT:
- fprintf(fp, "ldc.r8 0\n");
- break;
- case LST_STRING:
- fprintf(fp, "ldstr \"\"\n");
- break;
- case LST_KEY:
- fprintf(fp, "ldstr \"\"\n");
- fprintf(fp, "call valuetype [ScriptTypes]LindenLab.SecondLife.Key class [LslUserScript]LindenLab.SecondLife.LslUserScript::'CreateKey'(string)\n");
- break;
- case LST_VECTOR:
- fprintf(fp, "ldc.r8 0\n");
- fprintf(fp, "ldc.r8 0\n");
- fprintf(fp, "ldc.r8 0\n");
- fprintf(fp, "call class [ScriptTypes]LindenLab.SecondLife.Vector class [LslUserScript]LindenLab.SecondLife.LslUserScript::'CreateVector'(float32, float32, float32)\n");
- break;
- case LST_QUATERNION:
- fprintf(fp, "ldc.r8 0\n");
- fprintf(fp, "ldc.r8 0\n");
- fprintf(fp, "ldc.r8 0\n");
- fprintf(fp, "ldc.r8 1\n");
- fprintf(fp, "call class [ScriptTypes]LindenLab.SecondLife.Quaternion class [LslUserScript]LindenLab.SecondLife.LslUserScript::'CreateQuaternion'(float32, float32, float32, float32)\n");
- break;
- case LST_LIST:
- fprintf(fp, "call class [mscorlib]System.Collections.ArrayList class [LslUserScript]LindenLab.SecondLife.LslUserScript::CreateList()\n");
- break;
- default:
- break;
- }
- }
- void LLScriptGlobalVariable::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp,"\t");
- mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (mAssignable)
- {
- fprintf(fp, " = ");
- mAssignable->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- fprintf(fp, ";\n");
- break;
- case LSCP_EMIT_ASSEMBLY:
- mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp,"\t");
- mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (mAssignable)
- {
- fprintf(fp, " = ");
- mAssignable->recurse(fp, tabs, tabsize, LSCP_PRETTY_PRINT, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, "\n");
- fprintf(fp, "Offset: %d Type: %d\n", mIdentifier->mScopeEntry->mOffset, (S32)LSCRIPTTypeByte[mType->mType]);
- }
- else
- {
- fprintf(fp, "\n");
- fprintf(fp, "Offset: %d Type: %d\n", mIdentifier->mScopeEntry->mOffset, (S32)LSCRIPTTypeByte[mType->mType]);
- }
- break;
- case LSCP_SCOPE_PASS1:
- if (scope->checkEntry(mIdentifier->mName))
- {
- gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME);
- }
- else
- {
- if (mAssignable)
- {
- mAssignable->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- // this needs to go after expression decent to make sure that we don't add ourselves or something silly
- mIdentifier->mScopeEntry = scope->addEntry(mIdentifier->mName, LIT_GLOBAL, mType->mType);
- if (mIdentifier->mScopeEntry && mAssignable)
- mIdentifier->mScopeEntry->mAssignable = mAssignable;
- }
- break;
- case LSCP_TYPE:
- // if the variable has an assignable, it must assignable to the variable's type
- if (mAssignable)
- {
- mAssignable->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- mAssignableType = type;
- if (!legal_assignment(mType->mType, mAssignableType))
- {
- gErrorToText.writeError(fp, this, LSERROR_TYPE_MISMATCH);
- }
- }
- break;
- case LSCP_RESOURCE:
- {
- // we're just tryng to determine how much space the variable needs
- // it also includes the name of the variable as well as the type
- // plus 4 bytes of offset from it's apparent address to the actual data
- #ifdef LSL_INCLUDE_DEBUG_INFO
- count += strlen(mIdentifier->mName) + 1 + 1 + 4;
- #else
- count += 1 + 1 + 4;
- #endif
- mIdentifier->mScopeEntry->mOffset = (S32)count;
- mIdentifier->mScopeEntry->mSize = mType->getSize();
- count += mIdentifier->mScopeEntry->mSize;
- mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- case LSCP_EMIT_BYTE_CODE:
- {
- // order for global variables
- // 0 - 4: offset to actual data
- S32 offsetoffset = chunk->mCurrentOffset;
- S32 offsetdelta = 0;
- chunk->addBytes(4);
- // type
- char vtype;
- vtype = LSCRIPTTypeByte[mType->mType];
- chunk->addBytes(&vtype, 1);
- // null terminated name
- #ifdef LSL_INCLUDE_DEBUG_INFO
- chunk->addBytes(mIdentifier->mName, strlen(mIdentifier->mName) + 1);
- #else
- chunk->addBytes(1);
- #endif
- // put correct offset delta in
- offsetdelta = chunk->mCurrentOffset - offsetoffset;
- integer2bytestream(chunk->mCodeChunk, offsetoffset, offsetdelta);
- // now we need space for the variable itself
- LLScriptByteCodeChunk *value = new LLScriptByteCodeChunk(FALSE);
- if (mAssignable)
- {
- mAssignable->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, value, heap, stacksize, entry, entrycount, NULL);
- // need to put sneaky type conversion here
- if (mAssignableType != mType->mType)
- {
- // the only legal case that is a problem is int->float
- if (mType->mType == LST_FLOATINGPOINT && mAssignableType == LST_INTEGER)
- {
- S32 offset = value->mCurrentOffset - 4;
- bytestream_int2float(value->mCodeChunk, offset);
- }
- }
- }
- else
- {
- if ( (mType->mType == LST_STRING)
- ||(mType->mType == LST_KEY))
- {
- // string and keys (even empty ones) need heap entries
- chunk->addInteger(heap->mCurrentOffset + 1);
- LLScriptLibData *data = new LLScriptLibData("");
- U8 *temp;
- S32 size = lsa_create_data_block(&temp, data, heap->mCurrentOffset);
- heap->addBytes(temp, size);
- delete [] temp;
- delete data;
- }
- else if (mType->mType == LST_LIST)
- {
- chunk->addInteger(heap->mCurrentOffset + 1);
- LLScriptLibData *data = new LLScriptLibData;
- data->mType = LST_LIST;
- U8 *temp;
- S32 size = lsa_create_data_block(&temp, data, heap->mCurrentOffset);
- heap->addBytes(temp, size);
- delete [] temp;
- delete data;
- }
- else if (mType->mType == LST_QUATERNION)
- {
- chunk->addFloat(1.f);
- chunk->addFloat(0.f);
- chunk->addFloat(0.f);
- chunk->addFloat(0.f);
- }
- else
- {
- value->addBytes(LSCRIPTDataSize[mType->mType]);
- }
- }
- chunk->addBytes(value->mCodeChunk, value->mCurrentOffset);
- delete value;
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- // Initialisation inside ctor.
- fprintf(fp, "ldarg.0\n");
- if (mAssignable)
- {
- // Initialise to value.
- mAssignable->recurse(fp, tabs, tabsize, LSCP_EMIT_CIL_ASSEMBLY,
- ptype, prunearg, scope, type, basetype,
- count, chunk, heap, stacksize, entry,
- entrycount, NULL);
- print_cil_assignment_cast(fp, get_type(mAssignable), mType->mType);
- }
- else
- {
- // Initialise to zero.
- print_cil_init_variable(fp, mType->mType);
- }
- // Store value.
- fprintf(fp, "stfld ");
- mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp," %s::", gScriptp->getClassName());
- mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, "\n");
- break;
- default:
- mType->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- mIdentifier->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- if (mAssignable)
- {
- mAssignable->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- break;
- }
- gonext(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- }
- S32 LLScriptGlobalVariable::getSize()
- {
- S32 return_size;
- return_size = mType->getSize();
- return return_size;
- }
- void LLScriptEvent::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- fprintf(fp, "Event Base Class -- should never get here!\n");
- }
- S32 LLScriptEvent::getSize()
- {
- printf("Event Base Class -- should never get here!\n");
- return 0;
- }
- static void checkForDuplicateHandler(LLFILE *fp, LLScriptFilePosition *pos,
- LLScriptScope *scope,
- const char* name)
- {
- LLScriptScope *parent = scope->mParentScope;
- if (parent->checkEntry((char*)name))
- {
- gErrorToText.writeError(fp, pos, LSERROR_DUPLICATE_NAME);
- }
- else
- {
- parent->addEntry(((char*)name), LIT_HANDLER, LST_NULL);
- }
- }
- void LLScriptStateEntryEvent::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- fdotabs(fp, tabs, tabsize);
- fprintf(fp, "state_entry()\n");
- break;
- case LSCP_EMIT_ASSEMBLY:
- fprintf(fp, "state_entry()\n");
- break;
- case LSCP_SCOPE_PASS1:
- checkForDuplicateHandler(fp, this, scope, "state_entry");
- break;
- case LSCP_EMIT_BYTE_CODE:
- {
- #ifdef LSL_INCLUDE_DEBUG_INFO
- char name[] = "state_entry";
- chunk->addBytes(name, strlen(name) + 1);
- #endif
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- fprintf(fp, "state_entry()");
- break;
- default:
- break;
- }
- }
- S32 LLScriptStateEntryEvent::getSize()
- {
- return 0;
- }
- void LLScriptStateExitEvent::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- fdotabs(fp, tabs, tabsize);
- fprintf(fp, "state_exit()\n");
- break;
- case LSCP_SCOPE_PASS1:
- checkForDuplicateHandler(fp, this, scope, "state_exit");
- break;
- case LSCP_EMIT_ASSEMBLY:
- fprintf(fp, "state_exit()\n");
- break;
- case LSCP_EMIT_BYTE_CODE:
- {
- #ifdef LSL_INCLUDE_DEBUG_INFO
- char name[] = "state_exit";
- chunk->addBytes(name, strlen(name) + 1);
- #endif
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- fprintf(fp, "state_exit()");
- break;
- default:
- break;
- }
- }
- S32 LLScriptStateExitEvent::getSize()
- {
- return 0;
- }
- void LLScriptTouchStartEvent::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- case LSCP_EMIT_ASSEMBLY:
- fdotabs(fp, tabs, tabsize);
- fprintf(fp, "touch_start( integer ");
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, " )\n");
- break;
- break;
- case LSCP_SCOPE_PASS1:
- checkForDuplicateHandler(fp, this, scope, "touch_start");
- if (scope->checkEntry(mCount->mName))
- {
- gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME);
- }
- else
- {
- mCount->mScopeEntry = scope->addEntry(mCount->mName, LIT_VARIABLE, LST_INTEGER);
- }
- break;
- case LSCP_RESOURCE:
- {
- // we're just tryng to determine how much space the variable needs
- if (mCount->mScopeEntry)
- {
- mCount->mScopeEntry->mOffset = (S32)count;
- mCount->mScopeEntry->mSize = 4;
- count += mCount->mScopeEntry->mSize;
- }
- }
- break;
- case LSCP_EMIT_BYTE_CODE:
- {
- #ifdef LSL_INCLUDE_DEBUG_INFO
- char name[] = "touch_start";
- chunk->addBytes(name, strlen(name) + 1);
- chunk->addBytes(mCount->mName, strlen(mCount->mName) + 1);
- #endif
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- fdotabs(fp, tabs, tabsize);
- fprintf(fp, "touch_start( int32 ");
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, " )");
- break;
- break;
- default:
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- break;
- }
- }
- S32 LLScriptTouchStartEvent::getSize()
- {
- // integer = 4
- return 4;
- }
- void LLScriptTouchEvent::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- case LSCP_EMIT_ASSEMBLY:
- fdotabs(fp, tabs, tabsize);
- fprintf(fp, "touch( integer ");
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, " )\n");
- break;
- break;
- case LSCP_SCOPE_PASS1:
- checkForDuplicateHandler(fp, this, scope, "touch");
- if (scope->checkEntry(mCount->mName))
- {
- gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME);
- }
- else
- {
- mCount->mScopeEntry = scope->addEntry(mCount->mName, LIT_VARIABLE, LST_INTEGER);
- }
- break;
- case LSCP_RESOURCE:
- {
- // we're just tryng to determine how much space the variable needs
- if (mCount->mScopeEntry)
- {
- mCount->mScopeEntry->mOffset = (S32)count;
- mCount->mScopeEntry->mSize = 4;
- count += mCount->mScopeEntry->mSize;
- }
- }
- break;
- case LSCP_EMIT_BYTE_CODE:
- {
- #ifdef LSL_INCLUDE_DEBUG_INFO
- char name[] = "touch";
- chunk->addBytes(name, strlen(name) + 1);
- chunk->addBytes(mCount->mName, strlen(mCount->mName) + 1);
- #endif
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- fdotabs(fp, tabs, tabsize);
- fprintf(fp, "touch( int32 ");
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, " )");
- break;
- break;
- default:
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- break;
- }
- }
- S32 LLScriptTouchEvent::getSize()
- {
- // integer = 4
- return 4;
- }
- void LLScriptTouchEndEvent::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- case LSCP_EMIT_ASSEMBLY:
- fdotabs(fp, tabs, tabsize);
- fprintf(fp, "touch_end( integer ");
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, " )\n");
- break;
- break;
- case LSCP_SCOPE_PASS1:
- checkForDuplicateHandler(fp, this, scope, "touch_end");
- if (scope->checkEntry(mCount->mName))
- {
- gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME);
- }
- else
- {
- mCount->mScopeEntry = scope->addEntry(mCount->mName, LIT_VARIABLE, LST_INTEGER);
- }
- break;
- case LSCP_RESOURCE:
- {
- // we're just tryng to determine how much space the variable needs
- if (mCount->mScopeEntry)
- {
- mCount->mScopeEntry->mOffset = (S32)count;
- mCount->mScopeEntry->mSize = 4;
- count += mCount->mScopeEntry->mSize;
- }
- }
- break;
- case LSCP_EMIT_BYTE_CODE:
- {
- #ifdef LSL_INCLUDE_DEBUG_INFO
- char name[] = "touch_end";
- chunk->addBytes(name, strlen(name) + 1);
- chunk->addBytes(mCount->mName, strlen(mCount->mName) + 1);
- #endif
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- fdotabs(fp, tabs, tabsize);
- fprintf(fp, "touch_end( int32 ");
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, " )");
- break;
- break;
- default:
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- break;
- }
- }
- S32 LLScriptTouchEndEvent::getSize()
- {
- // integer = 4
- return 4;
- }
- void LLScriptCollisionStartEvent::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- case LSCP_EMIT_ASSEMBLY:
- fdotabs(fp, tabs, tabsize);
- fprintf(fp, "collision_start( integer ");
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, " )\n");
- break;
- break;
- case LSCP_SCOPE_PASS1:
- checkForDuplicateHandler(fp, this, scope, "collision_start");
- if (scope->checkEntry(mCount->mName))
- {
- gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME);
- }
- else
- {
- mCount->mScopeEntry = scope->addEntry(mCount->mName, LIT_VARIABLE, LST_INTEGER);
- }
- break;
- case LSCP_RESOURCE:
- {
- // we're just tryng to determine how much space the variable needs
- if (mCount->mScopeEntry)
- {
- mCount->mScopeEntry->mOffset = (S32)count;
- mCount->mScopeEntry->mSize = 4;
- count += mCount->mScopeEntry->mSize;
- }
- }
- break;
- case LSCP_EMIT_BYTE_CODE:
- {
- #ifdef LSL_INCLUDE_DEBUG_INFO
- char name[] = "collision_start";
- chunk->addBytes(name, (S32)strlen(name) + 1);
- chunk->addBytes(mCount->mName, (S32)strlen(mCount->mName) + 1);
- #endif
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- fdotabs(fp, tabs, tabsize);
- fprintf(fp, "collision_start( int32 ");
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, " )");
- break;
- default:
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- break;
- }
- }
- S32 LLScriptCollisionStartEvent::getSize()
- {
- // integer = 4
- return 4;
- }
- void LLScriptCollisionEvent::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- case LSCP_EMIT_ASSEMBLY:
- fdotabs(fp, tabs, tabsize);
- fprintf(fp, "collision( integer ");
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, " )\n");
- break;
- break;
- case LSCP_SCOPE_PASS1:
- checkForDuplicateHandler(fp, this, scope, "collision");
- if (scope->checkEntry(mCount->mName))
- {
- gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME);
- }
- else
- {
- mCount->mScopeEntry = scope->addEntry(mCount->mName, LIT_VARIABLE, LST_INTEGER);
- }
- break;
- case LSCP_RESOURCE:
- {
- // we're just tryng to determine how much space the variable needs
- if (mCount->mScopeEntry)
- {
- mCount->mScopeEntry->mOffset = (S32)count;
- mCount->mScopeEntry->mSize = 4;
- count += mCount->mScopeEntry->mSize;
- }
- }
- break;
- case LSCP_EMIT_BYTE_CODE:
- {
- #ifdef LSL_INCLUDE_DEBUG_INFO
- char name[] = "collision";
- chunk->addBytes(name, strlen(name) + 1);
- chunk->addBytes(mCount->mName, strlen(mCount->mName) + 1);
- #endif
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- fprintf(fp, "collision( int32 ");
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, " )");
- break;
- default:
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- break;
- }
- }
- S32 LLScriptCollisionEvent::getSize()
- {
- // integer = 4
- return 4;
- }
- void LLScriptCollisionEndEvent::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- case LSCP_EMIT_ASSEMBLY:
- fdotabs(fp, tabs, tabsize);
- fprintf(fp, "collision_end( integer ");
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, " )\n");
- break;
- break;
- case LSCP_SCOPE_PASS1:
- checkForDuplicateHandler(fp, this, scope, "collision_end");
- if (scope->checkEntry(mCount->mName))
- {
- gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME);
- }
- else
- {
- mCount->mScopeEntry = scope->addEntry(mCount->mName, LIT_VARIABLE, LST_INTEGER);
- }
- break;
- case LSCP_RESOURCE:
- {
- // we're just tryng to determine how much space the variable needs
- if (mCount->mScopeEntry)
- {
- mCount->mScopeEntry->mOffset = (S32)count;
- mCount->mScopeEntry->mSize = 4;
- count += mCount->mScopeEntry->mSize;
- }
- }
- break;
- case LSCP_EMIT_BYTE_CODE:
- {
- #ifdef LSL_INCLUDE_DEBUG_INFO
- char name[] = "collision_end";
- chunk->addBytes(name, strlen(name) + 1);
- chunk->addBytes(mCount->mName, strlen(mCount->mName) + 1);
- #endif
- }
- break;
- case LSCP_EMIT_CIL_ASSEMBLY:
- fdotabs(fp, tabs, tabsize);
- fprintf(fp, "collision_end( int32 ");
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, " )");
- break;
- default:
- mCount->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- break;
- }
- }
- S32 LLScriptCollisionEndEvent::getSize()
- {
- // integer = 4
- return 4;
- }
- void LLScriptLandCollisionStartEvent::recurse(LLFILE *fp, S32 tabs, S32 tabsize, LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg, LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count, LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata)
- {
- if (gErrorToText.getErrors())
- {
- return;
- }
- switch(pass)
- {
- case LSCP_PRETTY_PRINT:
- case LSCP_EMIT_ASSEMBLY:
- fdotabs(fp, tabs, tabsize);
- fprintf(fp, "land_collision_start( vector ");
- mPosition->recurse(fp, tabs, tabsize, pass, ptype, prunearg, scope, type, basetype, count, chunk, heap, stacksize, entry, entrycount, NULL);
- fprintf(fp, " )\n");
- break;
- case LSCP_SCOPE_PASS1:
- checkForDuplicateHandler(fp, this, scope, "land_collision_start");
- if (scope->checkEntry(mPosition->mName))
- {
- gErrorToText.writeError(fp, this, LSERROR_DUPLICATE_NAME);
- }
- else
- {
- mPosition->mScopeEntry = scope->addEntry(mPosition->mName, LIT_VARIABLE, LST_VECTOR);
- }
- break;
- case LSCP_RESOURCE:
- {
- // we're just tryng to determine how much space the variable needs
- if (mPosition->mScopeEntry)
- {
- mPosition->m