Merge pull request #2121 from JeffProgrammer/TSImprovementsDevMerge

TorqueScript Improvements - Faster Interpreter.
This commit is contained in:
Areloch 2017-11-27 01:35:17 -06:00 committed by GitHub
commit 4f78143dc8
23 changed files with 10231 additions and 8513 deletions

View file

@ -45,6 +45,7 @@
#include "console/debugOutputConsumer.h"
#include "console/consoleTypes.h"
#include "console/engineAPI.h"
#include "console/codeInterpreter.h"
#include "gfx/bitmap/gBitmap.h"
#include "gfx/gFont.h"
@ -227,6 +228,9 @@ void StandardMainLoop::init()
ManagedSingleton< ThreadManager >::createSingleton();
FrameAllocator::init(TORQUE_FRAME_SIZE); // See comments in torqueConfig.h
// Initialize the TorqueScript interpreter.
CodeInterpreter::init();
// Yell if we can't initialize the network.
if(!Net::init())
{

View file

@ -496,9 +496,9 @@ class_name_expr
assign_op_struct
: opPLUSPLUS
{ $$.lineNumber = $1.lineNumber; $$.token = '+'; $$.expr = FloatNode::alloc( $1.lineNumber, 1 ); }
{ $$.lineNumber = $1.lineNumber; $$.token = opPLUSPLUS; $$.expr = FloatNode::alloc( $1.lineNumber, 1 ); }
| opMINUSMINUS
{ $$.lineNumber = $1.lineNumber; $$.token = '-'; $$.expr = FloatNode::alloc( $1.lineNumber, 1 ); }
{ $$.lineNumber = $1.lineNumber; $$.token = opMINUSMINUS; $$.expr = FloatNode::alloc( $1.lineNumber, 1 ); }
| opPLASN expr
{ $$.lineNumber = $1.lineNumber; $$.token = '+'; $$.expr = $2; }
| opMIASN expr
@ -551,6 +551,8 @@ funcall_expr
{ $$ = FuncCallExprNode::alloc( $1.lineNumber, $3.value, $1.value, $5, false); }
| expr '.' IDENT '(' expr_list_decl ')'
{ $1->append($5); $$ = FuncCallExprNode::alloc( $1->dbgLineNumber, $3.value, NULL, $1, true); }
| expr '(' expr_list_decl ')'
{ $$ = FuncPointerCallExprNode::alloc( $1->dbgLineNumber, $1, $3); }
;
assert_expr

File diff suppressed because it is too large Load diff

View file

@ -56,7 +56,7 @@ struct StmtNode
StmtNode();
virtual ~StmtNode() {}
/// @name next Accessors
/// @{
@ -99,17 +99,17 @@ struct StmtNode
struct BreakStmtNode : StmtNode
{
static BreakStmtNode *alloc( S32 lineNumber );
static BreakStmtNode *alloc(S32 lineNumber);
U32 compileStmt(CodeStream &codeStream, U32 ip);
DBG_STMT_TYPE(BreakStmtNode);
};
struct ContinueStmtNode : StmtNode
{
static ContinueStmtNode *alloc( S32 lineNumber );
static ContinueStmtNode *alloc(S32 lineNumber);
U32 compileStmt(CodeStream &codeStream, U32 ip);
DBG_STMT_TYPE(ContinueStmtNode);
};
@ -117,7 +117,7 @@ struct ContinueStmtNode : StmtNode
/// A mathematical expression.
struct ExprNode : StmtNode
{
U32 compileStmt(CodeStream &codeStream, U32 ip);
virtual U32 compile(CodeStream &codeStream, U32 ip, TypeReq type) = 0;
@ -128,8 +128,8 @@ struct ReturnStmtNode : StmtNode
{
ExprNode *expr;
static ReturnStmtNode *alloc( S32 lineNumber, ExprNode *expr );
static ReturnStmtNode *alloc(S32 lineNumber, ExprNode *expr);
U32 compileStmt(CodeStream &codeStream, U32 ip);
DBG_STMT_TYPE(ReturnStmtNode);
};
@ -143,10 +143,10 @@ struct IfStmtNode : StmtNode
bool integer;
bool propagate;
static IfStmtNode *alloc( S32 lineNumber, ExprNode *testExpr, StmtNode *ifBlock, StmtNode *elseBlock, bool propagateThrough );
static IfStmtNode *alloc(S32 lineNumber, ExprNode *testExpr, StmtNode *ifBlock, StmtNode *elseBlock, bool propagateThrough);
void propagateSwitchExpr(ExprNode *left, bool string);
ExprNode *getSwitchOR(ExprNode *left, ExprNode *list, bool string);
U32 compileStmt(CodeStream &codeStream, U32 ip);
DBG_STMT_TYPE(IfStmtNode);
};
@ -163,8 +163,8 @@ struct LoopStmtNode : StmtNode
U32 loopBlockStartOffset;
bool integer;
static LoopStmtNode *alloc( S32 lineNumber, ExprNode *testExpr, ExprNode *initExpr, ExprNode *endLoopExpr, StmtNode *loopBlock, bool isDoLoop );
static LoopStmtNode *alloc(S32 lineNumber, ExprNode *testExpr, ExprNode *initExpr, ExprNode *endLoopExpr, StmtNode *loopBlock, bool isDoLoop);
U32 compileStmt(CodeStream &codeStream, U32 ip);
DBG_STMT_TYPE(LoopStmtNode);
};
@ -174,22 +174,22 @@ struct IterStmtNode : StmtNode
{
/// Local variable name to use for the container element.
StringTableEntry varName;
/// Expression evaluating to a SimSet object.
ExprNode* containerExpr;
/// The statement body.
StmtNode* body;
/// If true, this is a 'foreach$'.
bool isStringIter;
/// Bytecode size of body statement. Set by precompileStmt.
U32 bodySize;
static IterStmtNode* alloc( S32 lineNumber, StringTableEntry varName, ExprNode* containerExpr, StmtNode* body, bool isStringIter );
U32 compileStmt( CodeStream &codeStream, U32 ip );
static IterStmtNode* alloc(S32 lineNumber, StringTableEntry varName, ExprNode* containerExpr, StmtNode* body, bool isStringIter);
U32 compileStmt(CodeStream &codeStream, U32 ip);
};
/// A binary mathematical expression (ie, left op right).
@ -202,8 +202,8 @@ struct BinaryExprNode : ExprNode
struct FloatBinaryExprNode : BinaryExprNode
{
static FloatBinaryExprNode *alloc( S32 lineNumber, S32 op, ExprNode *left, ExprNode *right );
static FloatBinaryExprNode *alloc(S32 lineNumber, S32 op, ExprNode *left, ExprNode *right);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(FloatBinaryExprNode);
@ -215,8 +215,8 @@ struct ConditionalExprNode : ExprNode
ExprNode *trueExpr;
ExprNode *falseExpr;
bool integer;
static ConditionalExprNode *alloc( S32 lineNumber, ExprNode *testExpr, ExprNode *trueExpr, ExprNode *falseExpr );
static ConditionalExprNode *alloc(S32 lineNumber, ExprNode *testExpr, ExprNode *trueExpr, ExprNode *falseExpr);
virtual U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
virtual TypeReq getPreferredType();
DBG_STMT_TYPE(ConditionalExprNode);
@ -227,10 +227,10 @@ struct IntBinaryExprNode : BinaryExprNode
TypeReq subType;
U32 operand;
static IntBinaryExprNode *alloc( S32 lineNumber, S32 op, ExprNode *left, ExprNode *right );
static IntBinaryExprNode *alloc(S32 lineNumber, S32 op, ExprNode *left, ExprNode *right);
void getSubTypeOperand();
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(IntBinaryExprNode);
@ -239,8 +239,8 @@ struct IntBinaryExprNode : BinaryExprNode
struct StreqExprNode : BinaryExprNode
{
bool eq;
static StreqExprNode *alloc( S32 lineNumber, ExprNode *left, ExprNode *right, bool eq );
static StreqExprNode *alloc(S32 lineNumber, ExprNode *left, ExprNode *right, bool eq);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(StreqExprNode);
@ -249,8 +249,8 @@ struct StreqExprNode : BinaryExprNode
struct StrcatExprNode : BinaryExprNode
{
S32 appendChar;
static StrcatExprNode *alloc( S32 lineNumber, ExprNode *left, ExprNode *right, S32 appendChar );
static StrcatExprNode *alloc(S32 lineNumber, ExprNode *left, ExprNode *right, S32 appendChar);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(StrcatExprNode);
@ -258,9 +258,9 @@ struct StrcatExprNode : BinaryExprNode
struct CommaCatExprNode : BinaryExprNode
{
static CommaCatExprNode *alloc( S32 lineNumber, ExprNode *left, ExprNode *right );
static CommaCatExprNode *alloc(S32 lineNumber, ExprNode *left, ExprNode *right);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(CommaCatExprNode);
@ -272,8 +272,8 @@ struct IntUnaryExprNode : ExprNode
ExprNode *expr;
bool integer;
static IntUnaryExprNode *alloc( S32 lineNumber, S32 op, ExprNode *expr );
static IntUnaryExprNode *alloc(S32 lineNumber, S32 op, ExprNode *expr);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(IntUnaryExprNode);
@ -284,8 +284,8 @@ struct FloatUnaryExprNode : ExprNode
S32 op;
ExprNode *expr;
static FloatUnaryExprNode *alloc( S32 lineNumber, S32 op, ExprNode *expr );
static FloatUnaryExprNode *alloc(S32 lineNumber, S32 op, ExprNode *expr);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(FloatUnaryExprNode);
@ -296,8 +296,8 @@ struct VarNode : ExprNode
StringTableEntry varName;
ExprNode *arrayIndex;
static VarNode *alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex );
static VarNode *alloc(S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(VarNode);
@ -308,8 +308,8 @@ struct IntNode : ExprNode
S32 value;
U32 index; // if it's converted to float/string
static IntNode *alloc( S32 lineNumber, S32 value );
static IntNode *alloc(S32 lineNumber, S32 value);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(IntNode);
@ -320,8 +320,8 @@ struct FloatNode : ExprNode
F64 value;
U32 index;
static FloatNode *alloc( S32 lineNumber, F64 value );
static FloatNode *alloc(S32 lineNumber, F64 value);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(FloatNode);
@ -335,8 +335,8 @@ struct StrConstNode : ExprNode
bool tag;
bool doc; // Specifies that this string is a documentation block.
static StrConstNode *alloc( S32 lineNumber, char *str, bool tag, bool doc = false );
static StrConstNode *alloc(S32 lineNumber, char *str, bool tag, bool doc = false);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(StrConstNode);
@ -348,8 +348,8 @@ struct ConstantNode : ExprNode
F64 fVal;
U32 index;
static ConstantNode *alloc( S32 lineNumber, StringTableEntry value );
static ConstantNode *alloc(S32 lineNumber, StringTableEntry value);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(ConstantNode);
@ -362,8 +362,8 @@ struct AssignExprNode : ExprNode
ExprNode *arrayIndex;
TypeReq subType;
static AssignExprNode *alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr );
static AssignExprNode *alloc(S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(AssignExprNode);
@ -386,8 +386,8 @@ struct AssignOpExprNode : ExprNode
U32 operand;
TypeReq subType;
static AssignOpExprNode *alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr, S32 op );
static AssignOpExprNode *alloc(S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr, S32 op);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(AssignOpExprNode);
@ -399,8 +399,8 @@ struct TTagSetStmtNode : StmtNode
ExprNode *valueExpr;
ExprNode *stringExpr;
static TTagSetStmtNode *alloc( S32 lineNumber, StringTableEntry tag, ExprNode *valueExpr, ExprNode *stringExpr );
static TTagSetStmtNode *alloc(S32 lineNumber, StringTableEntry tag, ExprNode *valueExpr, ExprNode *stringExpr);
U32 compileStmt(CodeStream &codeStream, U32 ip);
DBG_STMT_TYPE(TTagSetStmtNode);
};
@ -409,8 +409,8 @@ struct TTagDerefNode : ExprNode
{
ExprNode *expr;
static TTagDerefNode *alloc( S32 lineNumber, ExprNode *expr );
static TTagDerefNode *alloc(S32 lineNumber, ExprNode *expr);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(TTagDerefNode);
@ -420,8 +420,8 @@ struct TTagExprNode : ExprNode
{
StringTableEntry tag;
static TTagExprNode *alloc( S32 lineNumber, StringTableEntry tag );
static TTagExprNode *alloc(S32 lineNumber, StringTableEntry tag);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(TTagExprNode);
@ -439,21 +439,33 @@ struct FuncCallExprNode : ExprNode
ParentCall
};
static FuncCallExprNode *alloc( S32 lineNumber, StringTableEntry funcName, StringTableEntry nameSpace, ExprNode *args, bool dot );
static FuncCallExprNode *alloc(S32 lineNumber, StringTableEntry funcName, StringTableEntry nameSpace, ExprNode *args, bool dot);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(FuncCallExprNode);
};
struct FuncPointerCallExprNode : ExprNode
{
ExprNode *funcPointer;
ExprNode *args;
static FuncPointerCallExprNode *alloc(S32 lineNumber, ExprNode *stmt, ExprNode *args);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(FuncPointerCallExprNode);
};
struct AssertCallExprNode : ExprNode
{
ExprNode *testExpr;
const char *message;
U32 messageIndex;
static AssertCallExprNode *alloc( S32 lineNumber, ExprNode *testExpr, const char *message );
static AssertCallExprNode *alloc(S32 lineNumber, ExprNode *testExpr, const char *message);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(AssertCallExprNode);
@ -472,8 +484,8 @@ struct SlotAccessNode : ExprNode
ExprNode *objectExpr, *arrayExpr;
StringTableEntry slotName;
static SlotAccessNode *alloc( S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName );
static SlotAccessNode *alloc(S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(SlotAccessNode);
@ -492,8 +504,8 @@ struct InternalSlotAccessNode : ExprNode
ExprNode *objectExpr, *slotExpr;
bool recurse;
static InternalSlotAccessNode *alloc( S32 lineNumber, ExprNode *objectExpr, ExprNode *slotExpr, bool recurse );
static InternalSlotAccessNode *alloc(S32 lineNumber, ExprNode *objectExpr, ExprNode *slotExpr, bool recurse);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(InternalSlotAccessNode);
@ -506,8 +518,8 @@ struct SlotAssignNode : ExprNode
ExprNode *valueExpr;
U32 typeID;
static SlotAssignNode *alloc( S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName, ExprNode *valueExpr, U32 typeID = -1 );
static SlotAssignNode *alloc(S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName, ExprNode *valueExpr, U32 typeID = -1);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(SlotAssignNode);
@ -522,8 +534,8 @@ struct SlotAssignOpNode : ExprNode
U32 operand;
TypeReq subType;
static SlotAssignOpNode *alloc( S32 lineNumber, ExprNode *objectExpr, StringTableEntry slotName, ExprNode *arrayExpr, S32 op, ExprNode *valueExpr );
static SlotAssignOpNode *alloc(S32 lineNumber, ExprNode *objectExpr, StringTableEntry slotName, ExprNode *arrayExpr, S32 op, ExprNode *valueExpr);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
TypeReq getPreferredType();
DBG_STMT_TYPE(SlotAssignOpNode);
@ -542,8 +554,8 @@ struct ObjectDeclNode : ExprNode
bool isClassNameInternal;
bool isSingleton;
static ObjectDeclNode *alloc( S32 lineNumber, ExprNode *classNameExpr, ExprNode *objectNameExpr, ExprNode *argList, StringTableEntry parentObject, SlotAssignNode *slotDecls, ObjectDeclNode *subObjects, bool isDatablock, bool classNameInternal, bool isSingleton );
static ObjectDeclNode *alloc(S32 lineNumber, ExprNode *classNameExpr, ExprNode *objectNameExpr, ExprNode *argList, StringTableEntry parentObject, SlotAssignNode *slotDecls, ObjectDeclNode *subObjects, bool isDatablock, bool classNameInternal, bool isSingleton);
U32 precompileSubObject(bool);
U32 compile(CodeStream &codeStream, U32 ip, TypeReq type);
U32 compileSubObject(CodeStream &codeStream, U32 ip, bool);
@ -567,8 +579,8 @@ struct FunctionDeclStmtNode : StmtNode
U32 endOffset;
U32 argc;
static FunctionDeclStmtNode *alloc( S32 lineNumber, StringTableEntry fnName, StringTableEntry nameSpace, VarNode *args, StmtNode *stmts );
static FunctionDeclStmtNode *alloc(S32 lineNumber, StringTableEntry fnName, StringTableEntry nameSpace, VarNode *args, StmtNode *stmts);
U32 compileStmt(CodeStream &codeStream, U32 ip);
void setPackage(StringTableEntry packageName);
DBG_STMT_TYPE(FunctionDeclStmtNode);

View file

@ -38,25 +38,25 @@ using namespace Compiler;
//------------------------------------------------------------
BreakStmtNode *BreakStmtNode::alloc( S32 lineNumber )
BreakStmtNode *BreakStmtNode::alloc(S32 lineNumber)
{
BreakStmtNode *ret = (BreakStmtNode *) consoleAlloc(sizeof(BreakStmtNode));
BreakStmtNode *ret = (BreakStmtNode *)consoleAlloc(sizeof(BreakStmtNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
return ret;
}
ContinueStmtNode *ContinueStmtNode::alloc( S32 lineNumber )
ContinueStmtNode *ContinueStmtNode::alloc(S32 lineNumber)
{
ContinueStmtNode *ret = (ContinueStmtNode *) consoleAlloc(sizeof(ContinueStmtNode));
ContinueStmtNode *ret = (ContinueStmtNode *)consoleAlloc(sizeof(ContinueStmtNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
return ret;
}
ReturnStmtNode *ReturnStmtNode::alloc( S32 lineNumber, ExprNode *expr)
ReturnStmtNode *ReturnStmtNode::alloc(S32 lineNumber, ExprNode *expr)
{
ReturnStmtNode *ret = (ReturnStmtNode *) consoleAlloc(sizeof(ReturnStmtNode));
ReturnStmtNode *ret = (ReturnStmtNode *)consoleAlloc(sizeof(ReturnStmtNode));
constructInPlace(ret);
ret->expr = expr;
ret->dbgLineNumber = lineNumber;
@ -64,9 +64,9 @@ ReturnStmtNode *ReturnStmtNode::alloc( S32 lineNumber, ExprNode *expr)
return ret;
}
IfStmtNode *IfStmtNode::alloc( S32 lineNumber, ExprNode *testExpr, StmtNode *ifBlock, StmtNode *elseBlock, bool propagate )
IfStmtNode *IfStmtNode::alloc(S32 lineNumber, ExprNode *testExpr, StmtNode *ifBlock, StmtNode *elseBlock, bool propagate)
{
IfStmtNode *ret = (IfStmtNode *) consoleAlloc(sizeof(IfStmtNode));
IfStmtNode *ret = (IfStmtNode *)consoleAlloc(sizeof(IfStmtNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
@ -78,9 +78,9 @@ IfStmtNode *IfStmtNode::alloc( S32 lineNumber, ExprNode *testExpr, StmtNode *ifB
return ret;
}
LoopStmtNode *LoopStmtNode::alloc( S32 lineNumber, ExprNode *initExpr, ExprNode *testExpr, ExprNode *endLoopExpr, StmtNode *loopBlock, bool isDoLoop )
LoopStmtNode *LoopStmtNode::alloc(S32 lineNumber, ExprNode *initExpr, ExprNode *testExpr, ExprNode *endLoopExpr, StmtNode *loopBlock, bool isDoLoop)
{
LoopStmtNode *ret = (LoopStmtNode *) consoleAlloc(sizeof(LoopStmtNode));
LoopStmtNode *ret = (LoopStmtNode *)consoleAlloc(sizeof(LoopStmtNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->testExpr = testExpr;
@ -92,28 +92,28 @@ LoopStmtNode *LoopStmtNode::alloc( S32 lineNumber, ExprNode *initExpr, ExprNode
// Deal with setting some dummy constant nodes if we weren't provided with
// info... This allows us to play nice with missing parts of for(;;) for
// instance.
if(!ret->testExpr) ret->testExpr = IntNode::alloc( lineNumber, 1 );
if (!ret->testExpr) ret->testExpr = IntNode::alloc(lineNumber, 1);
return ret;
}
IterStmtNode* IterStmtNode::alloc( S32 lineNumber, StringTableEntry varName, ExprNode* containerExpr, StmtNode* body, bool isStringIter )
IterStmtNode* IterStmtNode::alloc(S32 lineNumber, StringTableEntry varName, ExprNode* containerExpr, StmtNode* body, bool isStringIter)
{
IterStmtNode* ret = ( IterStmtNode* ) consoleAlloc( sizeof( IterStmtNode ) );
constructInPlace( ret );
IterStmtNode* ret = (IterStmtNode*)consoleAlloc(sizeof(IterStmtNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->varName = varName;
ret->containerExpr = containerExpr;
ret->body = body;
ret->isStringIter = isStringIter;
return ret;
}
FloatBinaryExprNode *FloatBinaryExprNode::alloc( S32 lineNumber, S32 op, ExprNode *left, ExprNode *right )
FloatBinaryExprNode *FloatBinaryExprNode::alloc(S32 lineNumber, S32 op, ExprNode *left, ExprNode *right)
{
FloatBinaryExprNode *ret = (FloatBinaryExprNode *) consoleAlloc(sizeof(FloatBinaryExprNode));
FloatBinaryExprNode *ret = (FloatBinaryExprNode *)consoleAlloc(sizeof(FloatBinaryExprNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
@ -124,9 +124,9 @@ FloatBinaryExprNode *FloatBinaryExprNode::alloc( S32 lineNumber, S32 op, ExprNod
return ret;
}
IntBinaryExprNode *IntBinaryExprNode::alloc( S32 lineNumber, S32 op, ExprNode *left, ExprNode *right )
IntBinaryExprNode *IntBinaryExprNode::alloc(S32 lineNumber, S32 op, ExprNode *left, ExprNode *right)
{
IntBinaryExprNode *ret = (IntBinaryExprNode *) consoleAlloc(sizeof(IntBinaryExprNode));
IntBinaryExprNode *ret = (IntBinaryExprNode *)consoleAlloc(sizeof(IntBinaryExprNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
@ -137,9 +137,9 @@ IntBinaryExprNode *IntBinaryExprNode::alloc( S32 lineNumber, S32 op, ExprNode *l
return ret;
}
StreqExprNode *StreqExprNode::alloc( S32 lineNumber, ExprNode *left, ExprNode *right, bool eq )
StreqExprNode *StreqExprNode::alloc(S32 lineNumber, ExprNode *left, ExprNode *right, bool eq)
{
StreqExprNode *ret = (StreqExprNode *) consoleAlloc(sizeof(StreqExprNode));
StreqExprNode *ret = (StreqExprNode *)consoleAlloc(sizeof(StreqExprNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->left = left;
@ -149,9 +149,9 @@ StreqExprNode *StreqExprNode::alloc( S32 lineNumber, ExprNode *left, ExprNode *r
return ret;
}
StrcatExprNode *StrcatExprNode::alloc( S32 lineNumber, ExprNode *left, ExprNode *right, S32 appendChar )
StrcatExprNode *StrcatExprNode::alloc(S32 lineNumber, ExprNode *left, ExprNode *right, S32 appendChar)
{
StrcatExprNode *ret = (StrcatExprNode *) consoleAlloc(sizeof(StrcatExprNode));
StrcatExprNode *ret = (StrcatExprNode *)consoleAlloc(sizeof(StrcatExprNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->left = left;
@ -161,9 +161,9 @@ StrcatExprNode *StrcatExprNode::alloc( S32 lineNumber, ExprNode *left, ExprNode
return ret;
}
CommaCatExprNode *CommaCatExprNode::alloc( S32 lineNumber, ExprNode *left, ExprNode *right )
CommaCatExprNode *CommaCatExprNode::alloc(S32 lineNumber, ExprNode *left, ExprNode *right)
{
CommaCatExprNode *ret = (CommaCatExprNode *) consoleAlloc(sizeof(CommaCatExprNode));
CommaCatExprNode *ret = (CommaCatExprNode *)consoleAlloc(sizeof(CommaCatExprNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->left = left;
@ -172,9 +172,9 @@ CommaCatExprNode *CommaCatExprNode::alloc( S32 lineNumber, ExprNode *left, ExprN
return ret;
}
IntUnaryExprNode *IntUnaryExprNode::alloc( S32 lineNumber, S32 op, ExprNode *expr )
IntUnaryExprNode *IntUnaryExprNode::alloc(S32 lineNumber, S32 op, ExprNode *expr)
{
IntUnaryExprNode *ret = (IntUnaryExprNode *) consoleAlloc(sizeof(IntUnaryExprNode));
IntUnaryExprNode *ret = (IntUnaryExprNode *)consoleAlloc(sizeof(IntUnaryExprNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->op = op;
@ -182,9 +182,9 @@ IntUnaryExprNode *IntUnaryExprNode::alloc( S32 lineNumber, S32 op, ExprNode *exp
return ret;
}
FloatUnaryExprNode *FloatUnaryExprNode::alloc( S32 lineNumber, S32 op, ExprNode *expr )
FloatUnaryExprNode *FloatUnaryExprNode::alloc(S32 lineNumber, S32 op, ExprNode *expr)
{
FloatUnaryExprNode *ret = (FloatUnaryExprNode *) consoleAlloc(sizeof(FloatUnaryExprNode));
FloatUnaryExprNode *ret = (FloatUnaryExprNode *)consoleAlloc(sizeof(FloatUnaryExprNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->op = op;
@ -192,9 +192,9 @@ FloatUnaryExprNode *FloatUnaryExprNode::alloc( S32 lineNumber, S32 op, ExprNode
return ret;
}
VarNode *VarNode::alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex )
VarNode *VarNode::alloc(S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex)
{
VarNode *ret = (VarNode *) consoleAlloc(sizeof(VarNode));
VarNode *ret = (VarNode *)consoleAlloc(sizeof(VarNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->varName = varName;
@ -202,18 +202,18 @@ VarNode *VarNode::alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arr
return ret;
}
IntNode *IntNode::alloc( S32 lineNumber, S32 value )
IntNode *IntNode::alloc(S32 lineNumber, S32 value)
{
IntNode *ret = (IntNode *) consoleAlloc(sizeof(IntNode));
IntNode *ret = (IntNode *)consoleAlloc(sizeof(IntNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->value = value;
return ret;
}
ConditionalExprNode *ConditionalExprNode::alloc( S32 lineNumber, ExprNode *testExpr, ExprNode *trueExpr, ExprNode *falseExpr )
ConditionalExprNode *ConditionalExprNode::alloc(S32 lineNumber, ExprNode *testExpr, ExprNode *trueExpr, ExprNode *falseExpr)
{
ConditionalExprNode *ret = (ConditionalExprNode *) consoleAlloc(sizeof(ConditionalExprNode));
ConditionalExprNode *ret = (ConditionalExprNode *)consoleAlloc(sizeof(ConditionalExprNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->testExpr = testExpr;
@ -223,22 +223,22 @@ ConditionalExprNode *ConditionalExprNode::alloc( S32 lineNumber, ExprNode *testE
return ret;
}
FloatNode *FloatNode::alloc( S32 lineNumber, F64 value )
FloatNode *FloatNode::alloc(S32 lineNumber, F64 value)
{
FloatNode *ret = (FloatNode *) consoleAlloc(sizeof(FloatNode));
FloatNode *ret = (FloatNode *)consoleAlloc(sizeof(FloatNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->value = value;
return ret;
}
StrConstNode *StrConstNode::alloc( S32 lineNumber, char *str, bool tag, bool doc )
StrConstNode *StrConstNode::alloc(S32 lineNumber, char *str, bool tag, bool doc)
{
StrConstNode *ret = (StrConstNode *) consoleAlloc(sizeof(StrConstNode));
StrConstNode *ret = (StrConstNode *)consoleAlloc(sizeof(StrConstNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->str = (char *) consoleAlloc(dStrlen(str) + 1);
ret->str = (char *)consoleAlloc(dStrlen(str) + 1);
ret->tag = tag;
ret->doc = doc;
dStrcpy(ret->str, str);
@ -246,18 +246,18 @@ StrConstNode *StrConstNode::alloc( S32 lineNumber, char *str, bool tag, bool doc
return ret;
}
ConstantNode *ConstantNode::alloc( S32 lineNumber, StringTableEntry value )
ConstantNode *ConstantNode::alloc(S32 lineNumber, StringTableEntry value)
{
ConstantNode *ret = (ConstantNode *) consoleAlloc(sizeof(ConstantNode));
ConstantNode *ret = (ConstantNode *)consoleAlloc(sizeof(ConstantNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->value = value;
return ret;
}
AssignExprNode *AssignExprNode::alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr )
AssignExprNode *AssignExprNode::alloc(S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr)
{
AssignExprNode *ret = (AssignExprNode *) consoleAlloc(sizeof(AssignExprNode));
AssignExprNode *ret = (AssignExprNode *)consoleAlloc(sizeof(AssignExprNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->varName = varName;
@ -267,9 +267,9 @@ AssignExprNode *AssignExprNode::alloc( S32 lineNumber, StringTableEntry varName,
return ret;
}
AssignOpExprNode *AssignOpExprNode::alloc( S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr, S32 op )
AssignOpExprNode *AssignOpExprNode::alloc(S32 lineNumber, StringTableEntry varName, ExprNode *arrayIndex, ExprNode *expr, S32 op)
{
AssignOpExprNode *ret = (AssignOpExprNode *) consoleAlloc(sizeof(AssignOpExprNode));
AssignOpExprNode *ret = (AssignOpExprNode *)consoleAlloc(sizeof(AssignOpExprNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->varName = varName;
@ -279,9 +279,9 @@ AssignOpExprNode *AssignOpExprNode::alloc( S32 lineNumber, StringTableEntry varN
return ret;
}
TTagSetStmtNode *TTagSetStmtNode::alloc( S32 lineNumber, StringTableEntry tag, ExprNode *valueExpr, ExprNode *stringExpr )
TTagSetStmtNode *TTagSetStmtNode::alloc(S32 lineNumber, StringTableEntry tag, ExprNode *valueExpr, ExprNode *stringExpr)
{
TTagSetStmtNode *ret = (TTagSetStmtNode *) consoleAlloc(sizeof(TTagSetStmtNode));
TTagSetStmtNode *ret = (TTagSetStmtNode *)consoleAlloc(sizeof(TTagSetStmtNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->tag = tag;
@ -290,37 +290,37 @@ TTagSetStmtNode *TTagSetStmtNode::alloc( S32 lineNumber, StringTableEntry tag, E
return ret;
}
TTagDerefNode *TTagDerefNode::alloc( S32 lineNumber, ExprNode *expr )
TTagDerefNode *TTagDerefNode::alloc(S32 lineNumber, ExprNode *expr)
{
TTagDerefNode *ret = (TTagDerefNode *) consoleAlloc(sizeof(TTagDerefNode));
TTagDerefNode *ret = (TTagDerefNode *)consoleAlloc(sizeof(TTagDerefNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->expr = expr;
return ret;
}
TTagExprNode *TTagExprNode::alloc( S32 lineNumber, StringTableEntry tag )
TTagExprNode *TTagExprNode::alloc(S32 lineNumber, StringTableEntry tag)
{
TTagExprNode *ret = (TTagExprNode *) consoleAlloc(sizeof(TTagExprNode));
TTagExprNode *ret = (TTagExprNode *)consoleAlloc(sizeof(TTagExprNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->tag = tag;
return ret;
}
FuncCallExprNode *FuncCallExprNode::alloc( S32 lineNumber, StringTableEntry funcName, StringTableEntry nameSpace, ExprNode *args, bool dot )
FuncCallExprNode *FuncCallExprNode::alloc(S32 lineNumber, StringTableEntry funcName, StringTableEntry nameSpace, ExprNode *args, bool dot)
{
FuncCallExprNode *ret = (FuncCallExprNode *) consoleAlloc(sizeof(FuncCallExprNode));
FuncCallExprNode *ret = (FuncCallExprNode *)consoleAlloc(sizeof(FuncCallExprNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->funcName = funcName;
ret->nameSpace = nameSpace;
ret->args = args;
if(dot)
if (dot)
ret->callType = MethodCall;
else
{
if(nameSpace && !dStricmp(nameSpace, "Parent"))
if (nameSpace && !dStricmp(nameSpace, "Parent"))
ret->callType = ParentCall;
else
ret->callType = FunctionCall;
@ -328,27 +328,37 @@ FuncCallExprNode *FuncCallExprNode::alloc( S32 lineNumber, StringTableEntry func
return ret;
}
AssertCallExprNode *AssertCallExprNode::alloc( S32 lineNumber, ExprNode *testExpr, const char *message )
FuncPointerCallExprNode *FuncPointerCallExprNode::alloc(S32 lineNumber, ExprNode *funcPointer, ExprNode *args)
{
#ifdef TORQUE_ENABLE_SCRIPTASSERTS
AssertCallExprNode *ret = (AssertCallExprNode *) consoleAlloc(sizeof(FuncCallExprNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->testExpr = testExpr;
ret->message = message ? message : "TorqueScript assert!";
return ret;
#else
return NULL;
#endif
FuncPointerCallExprNode *ret = (FuncPointerCallExprNode *)consoleAlloc(sizeof(FuncPointerCallExprNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->funcPointer = funcPointer;
ret->args = args;
return ret;
}
SlotAccessNode *SlotAccessNode::alloc( S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName )
AssertCallExprNode *AssertCallExprNode::alloc(S32 lineNumber, ExprNode *testExpr, const char *message)
{
SlotAccessNode *ret = (SlotAccessNode *) consoleAlloc(sizeof(SlotAccessNode));
#ifdef TORQUE_ENABLE_SCRIPTASSERTS
AssertCallExprNode *ret = (AssertCallExprNode *)consoleAlloc(sizeof(FuncCallExprNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->testExpr = testExpr;
ret->message = message ? message : "TorqueScript assert!";
return ret;
#else
return NULL;
#endif
}
SlotAccessNode *SlotAccessNode::alloc(S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName)
{
SlotAccessNode *ret = (SlotAccessNode *)consoleAlloc(sizeof(SlotAccessNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->objectExpr = objectExpr;
@ -357,9 +367,9 @@ SlotAccessNode *SlotAccessNode::alloc( S32 lineNumber, ExprNode *objectExpr, Exp
return ret;
}
InternalSlotAccessNode *InternalSlotAccessNode::alloc( S32 lineNumber, ExprNode *objectExpr, ExprNode *slotExpr, bool recurse )
InternalSlotAccessNode *InternalSlotAccessNode::alloc(S32 lineNumber, ExprNode *objectExpr, ExprNode *slotExpr, bool recurse)
{
InternalSlotAccessNode *ret = (InternalSlotAccessNode *) consoleAlloc(sizeof(InternalSlotAccessNode));
InternalSlotAccessNode *ret = (InternalSlotAccessNode *)consoleAlloc(sizeof(InternalSlotAccessNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->objectExpr = objectExpr;
@ -368,9 +378,9 @@ InternalSlotAccessNode *InternalSlotAccessNode::alloc( S32 lineNumber, ExprNode
return ret;
}
SlotAssignNode *SlotAssignNode::alloc( S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName, ExprNode *valueExpr, U32 typeID /* = -1 */ )
SlotAssignNode *SlotAssignNode::alloc(S32 lineNumber, ExprNode *objectExpr, ExprNode *arrayExpr, StringTableEntry slotName, ExprNode *valueExpr, U32 typeID /* = -1 */)
{
SlotAssignNode *ret = (SlotAssignNode *) consoleAlloc(sizeof(SlotAssignNode));
SlotAssignNode *ret = (SlotAssignNode *)consoleAlloc(sizeof(SlotAssignNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->objectExpr = objectExpr;
@ -381,9 +391,9 @@ SlotAssignNode *SlotAssignNode::alloc( S32 lineNumber, ExprNode *objectExpr, Exp
return ret;
}
SlotAssignOpNode *SlotAssignOpNode::alloc( S32 lineNumber, ExprNode *objectExpr, StringTableEntry slotName, ExprNode *arrayExpr, S32 op, ExprNode *valueExpr )
SlotAssignOpNode *SlotAssignOpNode::alloc(S32 lineNumber, ExprNode *objectExpr, StringTableEntry slotName, ExprNode *arrayExpr, S32 op, ExprNode *valueExpr)
{
SlotAssignOpNode *ret = (SlotAssignOpNode *) consoleAlloc(sizeof(SlotAssignOpNode));
SlotAssignOpNode *ret = (SlotAssignOpNode *)consoleAlloc(sizeof(SlotAssignOpNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->objectExpr = objectExpr;
@ -394,9 +404,9 @@ SlotAssignOpNode *SlotAssignOpNode::alloc( S32 lineNumber, ExprNode *objectExpr,
return ret;
}
ObjectDeclNode *ObjectDeclNode::alloc( S32 lineNumber, ExprNode *classNameExpr, ExprNode *objectNameExpr, ExprNode *argList, StringTableEntry parentObject, SlotAssignNode *slotDecls, ObjectDeclNode *subObjects, bool isDatablock, bool classNameInternal, bool isSingleton )
ObjectDeclNode *ObjectDeclNode::alloc(S32 lineNumber, ExprNode *classNameExpr, ExprNode *objectNameExpr, ExprNode *argList, StringTableEntry parentObject, SlotAssignNode *slotDecls, ObjectDeclNode *subObjects, bool isDatablock, bool classNameInternal, bool isSingleton)
{
ObjectDeclNode *ret = (ObjectDeclNode *) consoleAlloc(sizeof(ObjectDeclNode));
ObjectDeclNode *ret = (ObjectDeclNode *)consoleAlloc(sizeof(ObjectDeclNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->classNameExpr = classNameExpr;
@ -408,16 +418,16 @@ ObjectDeclNode *ObjectDeclNode::alloc( S32 lineNumber, ExprNode *classNameExpr,
ret->isClassNameInternal = classNameInternal;
ret->isSingleton = isSingleton;
ret->failOffset = 0;
if(parentObject)
if (parentObject)
ret->parentObject = parentObject;
else
ret->parentObject = StringTable->EmptyString();
return ret;
}
FunctionDeclStmtNode *FunctionDeclStmtNode::alloc( S32 lineNumber, StringTableEntry fnName, StringTableEntry nameSpace, VarNode *args, StmtNode *stmts )
FunctionDeclStmtNode *FunctionDeclStmtNode::alloc(S32 lineNumber, StringTableEntry fnName, StringTableEntry nameSpace, VarNode *args, StmtNode *stmts)
{
FunctionDeclStmtNode *ret = (FunctionDeclStmtNode *) consoleAlloc(sizeof(FunctionDeclStmtNode));
FunctionDeclStmtNode *ret = (FunctionDeclStmtNode *)consoleAlloc(sizeof(FunctionDeclStmtNode));
constructInPlace(ret);
ret->dbgLineNumber = lineNumber;
ret->fnName = fnName;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -15,78 +15,78 @@ typedef union {
AssignDecl asn;
IfStmtNode* ifnode;
} YYSTYPE;
#define rwDEFINE 258
#define rwENDDEF 259
#define rwDECLARE 260
#define rwDECLARESINGLETON 261
#define rwBREAK 262
#define rwELSE 263
#define rwCONTINUE 264
#define rwGLOBAL 265
#define rwIF 266
#define rwNIL 267
#define rwRETURN 268
#define rwWHILE 269
#define rwDO 270
#define rwENDIF 271
#define rwENDWHILE 272
#define rwENDFOR 273
#define rwDEFAULT 274
#define rwFOR 275
#define rwFOREACH 276
#define rwFOREACHSTR 277
#define rwIN 278
#define rwDATABLOCK 279
#define rwSWITCH 280
#define rwCASE 281
#define rwSWITCHSTR 282
#define rwCASEOR 283
#define rwPACKAGE 284
#define rwNAMESPACE 285
#define rwCLASS 286
#define rwASSERT 287
#define ILLEGAL_TOKEN 288
#define CHRCONST 289
#define INTCONST 290
#define TTAG 291
#define VAR 292
#define IDENT 293
#define TYPEIDENT 294
#define DOCBLOCK 295
#define STRATOM 296
#define TAGATOM 297
#define FLTCONST 298
#define opINTNAME 299
#define opINTNAMER 300
#define opMINUSMINUS 301
#define opPLUSPLUS 302
#define STMT_SEP 303
#define opSHL 304
#define opSHR 305
#define opPLASN 306
#define opMIASN 307
#define opMLASN 308
#define opDVASN 309
#define opMODASN 310
#define opANDASN 311
#define opXORASN 312
#define opORASN 313
#define opSLASN 314
#define opSRASN 315
#define opCAT 316
#define opEQ 317
#define opNE 318
#define opGE 319
#define opLE 320
#define opAND 321
#define opOR 322
#define opSTREQ 323
#define opCOLONCOLON 324
#define opMDASN 325
#define opNDASN 326
#define opNTASN 327
#define opSTRNE 328
#define UNARY 329
#define rwDEFINE 258
#define rwENDDEF 259
#define rwDECLARE 260
#define rwDECLARESINGLETON 261
#define rwBREAK 262
#define rwELSE 263
#define rwCONTINUE 264
#define rwGLOBAL 265
#define rwIF 266
#define rwNIL 267
#define rwRETURN 268
#define rwWHILE 269
#define rwDO 270
#define rwENDIF 271
#define rwENDWHILE 272
#define rwENDFOR 273
#define rwDEFAULT 274
#define rwFOR 275
#define rwFOREACH 276
#define rwFOREACHSTR 277
#define rwIN 278
#define rwDATABLOCK 279
#define rwSWITCH 280
#define rwCASE 281
#define rwSWITCHSTR 282
#define rwCASEOR 283
#define rwPACKAGE 284
#define rwNAMESPACE 285
#define rwCLASS 286
#define rwASSERT 287
#define ILLEGAL_TOKEN 288
#define CHRCONST 289
#define INTCONST 290
#define TTAG 291
#define VAR 292
#define IDENT 293
#define TYPEIDENT 294
#define DOCBLOCK 295
#define STRATOM 296
#define TAGATOM 297
#define FLTCONST 298
#define opINTNAME 299
#define opINTNAMER 300
#define opMINUSMINUS 301
#define opPLUSPLUS 302
#define STMT_SEP 303
#define opSHL 304
#define opSHR 305
#define opPLASN 306
#define opMIASN 307
#define opMLASN 308
#define opDVASN 309
#define opMODASN 310
#define opANDASN 311
#define opXORASN 312
#define opORASN 313
#define opSLASN 314
#define opSRASN 315
#define opCAT 316
#define opEQ 317
#define opNE 318
#define opGE 319
#define opLE 320
#define opAND 321
#define opOR 322
#define opSTREQ 323
#define opCOLONCOLON 324
#define opMDASN 325
#define opNDASN 326
#define opNTASN 327
#define opSTRNE 328
#define UNARY 329
extern YYSTYPE CMDlval;

File diff suppressed because it is too large Load diff

View file

@ -35,10 +35,11 @@ class ConsoleValueRef;
/// This class represents a block of code, usually mapped directly to a file.
class CodeBlock
{
friend class CodeInterpreter;
private:
static CodeBlock* smCodeBlockList;
static CodeBlock* smCurrentCodeBlock;
public:
static bool smInFunction;
static Compiler::ConsoleParser * smCurrentParser;
@ -89,7 +90,7 @@ public:
void calcBreakList();
void clearAllBreaks();
void setAllBreaks();
void dumpInstructions( U32 startIp = 0, bool upToReturn = false );
void dumpInstructions(U32 startIp = 0, bool upToReturn = false);
/// Returns the first breakable line or 0 if none was found.
/// @param lineNumber The one based line number.
@ -106,7 +107,7 @@ public:
const char *getFileLine(U32 ip);
///
String getFunctionArgs( U32 offset );
String getFunctionArgs(U32 offset);
bool read(StringTableEntry fileName, Stream &st);
bool compile(const char *dsoName, StringTableEntry fileName, const char *script, bool overrideNoDso = false);
@ -129,8 +130,8 @@ public:
/// with, zero being the top of the stack. If the the index is
/// -1 a new frame is created. If the index is out of range the
/// top stack frame is used.
ConsoleValueRef compileExec(StringTableEntry fileName, const char *script,
bool noCalls, S32 setFrame = -1 );
ConsoleValueRef compileExec(StringTableEntry fileName, const char *script,
bool noCalls, S32 setFrame = -1);
/// Executes the existing code in the CodeBlock. The return string is any
/// result of the code executed, if any, or an empty string.
@ -147,7 +148,7 @@ public:
/// -1 a new frame is created. If the index is out of range the
/// top stack frame is used.
/// @param packageName The code package name or null.
ConsoleValueRef exec(U32 offset, const char *fnName, Namespace *ns, U32 argc,
ConsoleValueRef exec(U32 offset, const char *fnName, Namespace *ns, U32 argc,
ConsoleValueRef *argv, bool noCalls, StringTableEntry packageName,
S32 setFrame = -1);
};

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,262 @@
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _CODEINTERPRETER_H_
#define _CODEINTERPRETER_H_
#include "console/codeBlock.h"
#include "console/console.h"
#include "console/consoleInternal.h"
/// Frame data for a foreach/foreach$ loop.
struct IterStackRecord
{
/// If true, this is a foreach$ loop; if not, it's a foreach loop.
bool mIsStringIter;
/// The iterator variable.
Dictionary::Entry* mVariable;
/// Information for an object iterator loop.
struct ObjectPos
{
/// The set being iterated over.
SimSet* mSet;
/// Current index in the set.
U32 mIndex;
};
/// Information for a string iterator loop.
struct StringPos
{
/// The raw string data on the string stack.
StringStackPtr mString;
/// Current parsing position.
U32 mIndex;
};
union
{
ObjectPos mObj;
StringPos mStr;
} mData;
};
enum OPCodeReturn
{
exitCode = -1,
success = 0,
breakContinue = 1
};
class CodeInterpreter
{
public:
CodeInterpreter(CodeBlock *cb);
~CodeInterpreter();
ConsoleValueRef exec(U32 ip,
StringTableEntry functionName,
Namespace *thisNamespace,
U32 argc,
ConsoleValueRef *argv,
bool noCalls,
StringTableEntry packageName,
S32 setFrame);
static void init();
// Methods
private:
void parseArgs(U32 &ip);
/// Group op codes
/// @{
OPCodeReturn op_func_decl(U32 &ip);
OPCodeReturn op_create_object(U32 &ip);
OPCodeReturn op_add_object(U32 &ip);
OPCodeReturn op_end_object(U32 &ip);
OPCodeReturn op_finish_object(U32 &ip);
OPCodeReturn op_jmpiffnot(U32 &ip);
OPCodeReturn op_jmpifnot(U32 &ip);
OPCodeReturn op_jmpiff(U32 &ip);
OPCodeReturn op_jmpif(U32 &ip);
OPCodeReturn op_jmpifnot_np(U32 &ip);
OPCodeReturn op_jmpif_np(U32 &ip);
OPCodeReturn op_jmp(U32 &ip);
OPCodeReturn op_return_void(U32 &ip);
OPCodeReturn op_return(U32 &ip);
OPCodeReturn op_return_flt(U32 &ip);
OPCodeReturn op_return_uint(U32 &ip);
OPCodeReturn op_cmpeq(U32 &ip);
OPCodeReturn op_cmpgr(U32 &ip);
OPCodeReturn op_cmpge(U32 &ip);
OPCodeReturn op_cmplt(U32 &ip);
OPCodeReturn op_cmple(U32 &ip);
OPCodeReturn op_cmpne(U32 &ip);
OPCodeReturn op_xor(U32 &ip);
OPCodeReturn op_mod(U32 &ip);
OPCodeReturn op_bitand(U32 &ip);
OPCodeReturn op_bitor(U32 &ip);
OPCodeReturn op_not(U32 &ip);
OPCodeReturn op_notf(U32 &ip);
OPCodeReturn op_onescomplement(U32 &ip);
OPCodeReturn op_shr(U32 &ip);
OPCodeReturn op_shl(U32 &ip);
OPCodeReturn op_and(U32 &ip);
OPCodeReturn op_or(U32 &ip);
OPCodeReturn op_add(U32 &ip);
OPCodeReturn op_sub(U32 &ip);
OPCodeReturn op_mul(U32 &ip);
OPCodeReturn op_div(U32 &ip);
OPCodeReturn op_neg(U32 &ip);
OPCodeReturn op_inc(U32 &ip);
OPCodeReturn op_dec(U32 &ip);
OPCodeReturn op_setcurvar(U32 &ip);
OPCodeReturn op_setcurvar_create(U32 &ip);
OPCodeReturn op_setcurvar_array(U32 &ip);
OPCodeReturn op_setcurvar_array_varlookup(U32 &ip);
OPCodeReturn op_setcurvar_array_create(U32 &ip);
OPCodeReturn op_setcurvar_array_create_varlookup(U32 &ip);
OPCodeReturn op_loadvar_uint(U32 &ip);
OPCodeReturn op_loadvar_flt(U32 &ip);
OPCodeReturn op_loadvar_str(U32 &ip);
OPCodeReturn op_loadvar_var(U32 &ip);
OPCodeReturn op_savevar_uint(U32 &ip);
OPCodeReturn op_savevar_flt(U32 &ip);
OPCodeReturn op_savevar_str(U32 &ip);
OPCodeReturn op_savevar_var(U32 &ip);
OPCodeReturn op_setcurobject(U32 &ip);
OPCodeReturn op_setcurobject_internal(U32 &ip);
OPCodeReturn op_setcurobject_new(U32 &ip);
OPCodeReturn op_setcurfield(U32 &ip);
OPCodeReturn op_setcurfield_array(U32 &ip);
OPCodeReturn op_setcurfield_type(U32 &ip);
OPCodeReturn op_setcurfield_this(U32 &ip);
OPCodeReturn op_setcurfield_array_var(U32 &ip);
OPCodeReturn op_loadfield_uint(U32 &ip);
OPCodeReturn op_loadfield_flt(U32 &ip);
OPCodeReturn op_loadfield_str(U32 &ip);
OPCodeReturn op_savefield_uint(U32 &ip);
OPCodeReturn op_savefield_flt(U32 &ip);
OPCodeReturn op_savefield_str(U32 &ip);
OPCodeReturn op_str_to_uint(U32 &ip);
OPCodeReturn op_str_to_flt(U32 &ip);
OPCodeReturn op_str_to_none(U32 &ip);
OPCodeReturn op_flt_to_uint(U32 &ip);
OPCodeReturn op_flt_to_str(U32 &ip);
OPCodeReturn op_flt_to_none(U32 &ip);
OPCodeReturn op_uint_to_flt(U32 &ip);
OPCodeReturn op_uint_to_str(U32 &ip);
OPCodeReturn op_uint_to_none(U32 &ip);
OPCodeReturn op_copyvar_to_none(U32 &ip);
OPCodeReturn op_loadimmed_uint(U32 &ip);
OPCodeReturn op_loadimmed_flt(U32 &ip);
OPCodeReturn op_tag_to_str(U32 &ip);
OPCodeReturn op_loadimmed_str(U32 &ip);
OPCodeReturn op_docblock_str(U32 &ip);
OPCodeReturn op_loadimmed_ident(U32 &ip);
OPCodeReturn op_callfunc_resolve(U32 &ip);
OPCodeReturn op_callfunc(U32 &ip);
OPCodeReturn op_callfunc_pointer(U32 &ip);
OPCodeReturn op_callfunc_this(U32 &ip);
OPCodeReturn op_advance_str(U32 &ip);
OPCodeReturn op_advance_str_appendchar(U32 &ip);
OPCodeReturn op_advance_str_comma(U32 &ip);
OPCodeReturn op_advance_str_nul(U32 &ip);
OPCodeReturn op_rewind_str(U32 &ip);
OPCodeReturn op_terminate_rewind_str(U32 &ip);
OPCodeReturn op_compare_str(U32 &ip);
OPCodeReturn op_push(U32 &ip);
OPCodeReturn op_push_uint(U32 &ip);
OPCodeReturn op_push_flt(U32 &ip);
OPCodeReturn op_push_var(U32 &ip);
OPCodeReturn op_push_this(U32 &ip);
OPCodeReturn op_push_frame(U32 &ip);
OPCodeReturn op_assert(U32 &ip);
OPCodeReturn op_break(U32 &ip);
OPCodeReturn op_iter_begin_str(U32 &ip);
OPCodeReturn op_iter_begin(U32 &ip);
OPCodeReturn op_iter(U32 &ip);
OPCodeReturn op_iter_end(U32 &ip);
OPCodeReturn op_invalid(U32 &ip);
/// @}
private:
CodeBlock *mCodeBlock;
/// Group exec arguments.
struct
{
StringTableEntry functionName;
Namespace *thisNamespace;
U32 argc;
ConsoleValueRef *argv;
bool noCalls;
StringTableEntry packageName;
S32 setFrame;
} mExec;
U32 mIterDepth;
F64 *mCurFloatTable;
char *mCurStringTable;
StringTableEntry mThisFunctionName;
bool mPopFrame;
// Add local object creation stack [7/9/2007 Black]
static const U32 objectCreationStackSize = 32;
U32 mObjectCreationStackIndex;
struct
{
SimObject *newObject;
U32 failJump;
} mObjectCreationStack[objectCreationStackSize];
SimObject *mCurrentNewObject;
U32 mFailJump;
StringTableEntry mPrevField;
StringTableEntry mCurField;
SimObject *mPrevObject;
SimObject *mCurObject;
SimObject *mSaveObject;
SimObject *mThisObject;
Namespace::Entry *mNSEntry;
StringTableEntry mCurFNDocBlock;
StringTableEntry mCurNSDocBlock;
U32 mCallArgc;
ConsoleValueRef *mCallArgv;
CodeBlock *mSaveCodeBlock;
// note: anything returned is pushed to CSTK and will be invalidated on the next exec()
ConsoleValueRef mReturnValue;
U32 mCurrentInstruction;
static const S32 nsDocLength = 128;
char mNSDocBlockClass[nsDocLength];
};
#endif

File diff suppressed because it is too large Load diff

View file

@ -40,13 +40,13 @@ namespace Compiler
F64 consoleStringToNumber(const char *str, StringTableEntry file, U32 line)
{
F64 val = dAtof(str);
if(val != 0)
if (val != 0)
return val;
else if(!dStricmp(str, "true"))
else if (!dStricmp(str, "true"))
return 1;
else if(!dStricmp(str, "false"))
else if (!dStricmp(str, "false"))
return 0;
else if(file)
else if (file)
{
Con::warnf(ConsoleLogEntry::General, "%s (%d): string always evaluates to 0.", file, line);
return 0;
@ -57,7 +57,7 @@ namespace Compiler
//------------------------------------------------------------
CompilerStringTable *gCurrentStringTable, gGlobalStringTable, gFunctionStringTable;
CompilerFloatTable *gCurrentFloatTable, gGlobalFloatTable, gFunctionFloatTable;
CompilerFloatTable *gCurrentFloatTable, gGlobalFloatTable, gFunctionFloatTable;
DataChunker gConsoleAllocator;
CompilerIdentTable gIdentTable;
@ -71,16 +71,16 @@ namespace Compiler
*ptr = (U32)ste;
#endif
}
void compileSTEtoCode(StringTableEntry ste, U32 ip, U32 *ptr)
{
if(ste)
if (ste)
getIdentTable().add(ste, ip);
*ptr = 0;
*(ptr+1) = 0;
*(ptr + 1) = 0;
}
void (*STEtoCode)(StringTableEntry ste, U32 ip, U32 *ptr) = evalSTEtoCode;
void(*STEtoCode)(StringTableEntry ste, U32 ip, U32 *ptr) = evalSTEtoCode;
//------------------------------------------------------------
@ -88,23 +88,23 @@ namespace Compiler
//------------------------------------------------------------
CompilerStringTable *getCurrentStringTable() { return gCurrentStringTable; }
CompilerStringTable &getGlobalStringTable() { return gGlobalStringTable; }
CompilerStringTable *getCurrentStringTable() { return gCurrentStringTable; }
CompilerStringTable &getGlobalStringTable() { return gGlobalStringTable; }
CompilerStringTable &getFunctionStringTable() { return gFunctionStringTable; }
void setCurrentStringTable (CompilerStringTable* cst) { gCurrentStringTable = cst; }
void setCurrentStringTable(CompilerStringTable* cst) { gCurrentStringTable = cst; }
CompilerFloatTable *getCurrentFloatTable() { return gCurrentFloatTable; }
CompilerFloatTable &getGlobalFloatTable() { return gGlobalFloatTable; }
CompilerFloatTable &getFunctionFloatTable() { return gFunctionFloatTable; }
CompilerFloatTable *getCurrentFloatTable() { return gCurrentFloatTable; }
CompilerFloatTable &getGlobalFloatTable() { return gGlobalFloatTable; }
CompilerFloatTable &getFunctionFloatTable() { return gFunctionFloatTable; }
void setCurrentFloatTable (CompilerFloatTable* cst) { gCurrentFloatTable = cst; }
void setCurrentFloatTable(CompilerFloatTable* cst) { gCurrentFloatTable = cst; }
CompilerIdentTable &getIdentTable() { return gIdentTable; }
void precompileIdent(StringTableEntry ident)
{
if(ident)
if (ident)
gGlobalStringTable.add(ident);
}
@ -119,8 +119,8 @@ namespace Compiler
getIdentTable().reset();
}
void *consoleAlloc(U32 size) { return gConsoleAllocator.alloc(size); }
void consoleAllocReset() { gConsoleAllocator.freeBlocks(); }
void *consoleAlloc(U32 size) { return gConsoleAllocator.alloc(size); }
void consoleAllocReset() { gConsoleAllocator.freeBlocks(); }
}
@ -135,36 +135,40 @@ U32 CompilerStringTable::add(const char *str, bool caseSens, bool tag)
{
// Is it already in?
Entry **walk;
for(walk = &list; *walk; walk = &((*walk)->next))
for (walk = &list; *walk; walk = &((*walk)->next))
{
if((*walk)->tag != tag)
if ((*walk)->tag != tag)
continue;
if(caseSens)
if (caseSens)
{
if(!dStrcmp((*walk)->string, str))
if (!dStrcmp((*walk)->string, str))
return (*walk)->start;
}
else
{
if(!dStricmp((*walk)->string, str))
if (!dStricmp((*walk)->string, str))
return (*walk)->start;
}
}
// Write it out.
Entry *newStr = (Entry *) consoleAlloc(sizeof(Entry));
Entry *newStr = (Entry *)consoleAlloc(sizeof(Entry));
*walk = newStr;
newStr->next = NULL;
newStr->start = totalLen;
U32 len = dStrlen(str) + 1;
if(tag && len < 7) // alloc space for the numeric tag 1 for tag, 5 for # and 1 for nul
if (tag && len < 7) // alloc space for the numeric tag 1 for tag, 5 for # and 1 for nul
len = 7;
totalLen += len;
newStr->string = (char *) consoleAlloc(len);
newStr->string = (char *)consoleAlloc(len);
newStr->len = len;
newStr->tag = tag;
dStrcpy(newStr->string, str);
// Put into the hash table.
hashTable[str] = newStr;
return newStr->start;
}
@ -189,7 +193,8 @@ void CompilerStringTable::reset()
char *CompilerStringTable::build()
{
char *ret = new char[totalLen];
for(Entry *walk = list; walk; walk = walk->next)
dMemset(ret, 0, totalLen);
for (Entry *walk = list; walk; walk = walk->next)
dStrcpy(ret + walk->start, walk->string);
return ret;
}
@ -197,7 +202,7 @@ char *CompilerStringTable::build()
void CompilerStringTable::write(Stream &st)
{
st.write(totalLen);
for(Entry *walk = list; walk; walk = walk->next)
for (Entry *walk = list; walk; walk = walk->next)
st.write(walk->len, walk->string);
}
@ -207,15 +212,15 @@ U32 CompilerFloatTable::add(F64 value)
{
Entry **walk;
U32 i = 0;
for(walk = &list; *walk; walk = &((*walk)->next), i++)
if(value == (*walk)->val)
for (walk = &list; *walk; walk = &((*walk)->next), i++)
if (value == (*walk)->val)
return i;
Entry *newFloat = (Entry *) consoleAlloc(sizeof(Entry));
Entry *newFloat = (Entry *)consoleAlloc(sizeof(Entry));
newFloat->val = value;
newFloat->next = NULL;
count++;
*walk = newFloat;
return count-1;
return count - 1;
}
void CompilerFloatTable::reset()
{
@ -226,7 +231,7 @@ F64 *CompilerFloatTable::build()
{
F64 *ret = new F64[count];
U32 i = 0;
for(Entry *walk = list; walk; walk = walk->next, i++)
for (Entry *walk = list; walk; walk = walk->next, i++)
ret[i] = walk->val;
return ret;
}
@ -234,7 +239,7 @@ F64 *CompilerFloatTable::build()
void CompilerFloatTable::write(Stream &st)
{
st.write(count);
for(Entry *walk = list; walk; walk = walk->next)
for (Entry *walk = list; walk; walk = walk->next)
st.write(walk->val);
}
@ -248,12 +253,12 @@ void CompilerIdentTable::reset()
void CompilerIdentTable::add(StringTableEntry ste, U32 ip)
{
U32 index = gGlobalStringTable.add(ste, false);
Entry *newEntry = (Entry *) consoleAlloc(sizeof(Entry));
Entry *newEntry = (Entry *)consoleAlloc(sizeof(Entry));
newEntry->offset = index;
newEntry->ip = ip;
for(Entry *walk = list; walk; walk = walk->next)
for (Entry *walk = list; walk; walk = walk->next)
{
if(walk->offset == index)
if (walk->offset == index)
{
newEntry->nextIdent = walk->nextIdent;
walk->nextIdent = newEntry;
@ -269,24 +274,24 @@ void CompilerIdentTable::write(Stream &st)
{
U32 count = 0;
Entry * walk;
for(walk = list; walk; walk = walk->next)
for (walk = list; walk; walk = walk->next)
count++;
st.write(count);
for(walk = list; walk; walk = walk->next)
for (walk = list; walk; walk = walk->next)
{
U32 ec = 0;
Entry * el;
for(el = walk; el; el = el->nextIdent)
for (el = walk; el; el = el->nextIdent)
ec++;
st.write(walk->offset);
st.write(ec);
for(el = walk; el; el = el->nextIdent)
for (el = walk; el; el = el->nextIdent)
st.write(el->ip);
}
}
//-------------------------------------------------------------------------
U8 *CodeStream::allocCode(U32 sz)
{
U8 *ptr = NULL;
@ -300,12 +305,12 @@ U8 *CodeStream::allocCode(U32 sz)
return ptr;
}
}
CodeData *data = new CodeData;
data->data = (U8*)dMalloc(BlockSize);
data->size = sz;
data->next = NULL;
if (mCodeHead)
mCodeHead->next = data;
mCodeHead = data;
@ -313,21 +318,21 @@ U8 *CodeStream::allocCode(U32 sz)
mCode = data;
return data->data;
}
//-------------------------------------------------------------------------
void CodeStream::fixLoop(U32 loopBlockStart, U32 breakPoint, U32 continuePoint)
{
AssertFatal(mFixStack.size() > 0, "Fix stack mismatch");
U32 fixStart = mFixStack[mFixStack.size()-1];
for (U32 i=fixStart; i<mFixList.size(); i += 2)
U32 fixStart = mFixStack[mFixStack.size() - 1];
for (U32 i = fixStart; i<mFixList.size(); i += 2)
{
FixType type = (FixType)mFixList[i+1];
FixType type = (FixType)mFixList[i + 1];
U32 fixedIp = 0;
bool valid = true;
switch (type)
{
case FIXTYPE_LOOPBLOCKSTART:
@ -344,7 +349,7 @@ void CodeStream::fixLoop(U32 loopBlockStart, U32 breakPoint, U32 continuePoint)
valid = false;
break;
}
if (valid)
{
patch(mFixList[i], fixedIp);
@ -353,7 +358,7 @@ void CodeStream::fixLoop(U32 loopBlockStart, U32 breakPoint, U32 continuePoint)
}
//-------------------------------------------------------------------------
void CodeStream::emitCodeStream(U32 *size, U32 **stream, U32 **lineBreaks)
{
// Alloc stream
@ -361,7 +366,7 @@ void CodeStream::emitCodeStream(U32 *size, U32 **stream, U32 **lineBreaks)
*stream = new U32[mCodePos + (numLineBreaks * 2)];
dMemset(*stream, '\0', mCodePos + (numLineBreaks * 2));
*size = mCodePos;
// Dump chunks & line breaks
U32 outBytes = mCodePos * sizeof(U32);
U8 *outPtr = *((U8**)stream);
@ -372,20 +377,20 @@ void CodeStream::emitCodeStream(U32 *size, U32 **stream, U32 **lineBreaks)
outPtr += bytesToCopy;
outBytes -= bytesToCopy;
}
*lineBreaks = *stream + mCodePos;
dMemcpy(*lineBreaks, mBreakLines.address(), sizeof(U32) * mBreakLines.size());
// Apply patches on top
for (U32 i=0; i<mPatchList.size(); i++)
for (U32 i = 0; i<mPatchList.size(); i++)
{
PatchEntry &e = mPatchList[i];
(*stream)[e.addr] = e.value;
}
}
//-------------------------------------------------------------------------
void CodeStream::reset()
{
mCodePos = 0;
@ -393,7 +398,7 @@ void CodeStream::reset()
mFixLoopStack.clear();
mFixList.clear();
mBreakLines.clear();
// Pop down to one code block
CodeData *itr = mCode ? mCode->next : NULL;
while (itr != NULL)
@ -403,7 +408,7 @@ void CodeStream::reset()
delete(itr);
itr = next;
}
if (mCode)
{
mCode->size = 0;

View file

@ -30,6 +30,9 @@
#include <stdio.h>
#endif
#include <string>
#include <unordered_map>
class Stream;
class DataChunker;
@ -91,10 +94,15 @@ namespace Compiler
OP_DIV,
OP_NEG,
OP_INC,
OP_DEC,
OP_SETCURVAR,
OP_SETCURVAR_CREATE,
OP_SETCURVAR_ARRAY,
OP_SETCURVAR_ARRAY_VARLOOKUP,
OP_SETCURVAR_ARRAY_CREATE,
OP_SETCURVAR_ARRAY_CREATE_VARLOOKUP,
OP_LOADVAR_UINT,// 40
OP_LOADVAR_FLT,
@ -113,6 +121,8 @@ namespace Compiler
OP_SETCURFIELD,
OP_SETCURFIELD_ARRAY, // 50
OP_SETCURFIELD_TYPE,
OP_SETCURFIELD_ARRAY_VAR,
OP_SETCURFIELD_THIS,
OP_LOADFIELD_UINT,
OP_LOADFIELD_FLT,
@ -142,6 +152,8 @@ namespace Compiler
OP_CALLFUNC_RESOLVE,
OP_CALLFUNC,
OP_CALLFUNC_POINTER,
OP_CALLFUNC_THIS,
OP_ADVANCE_STR,
OP_ADVANCE_STR_APPENDCHAR,
@ -155,23 +167,26 @@ namespace Compiler
OP_PUSH_UINT, // Integer
OP_PUSH_FLT, // Float
OP_PUSH_VAR, // Variable
OP_PUSH_THIS, // This pointer
OP_PUSH_FRAME, // Frame
OP_ASSERT,
OP_BREAK,
OP_ITER_BEGIN, ///< Prepare foreach iterator.
OP_ITER_BEGIN_STR, ///< Prepare foreach$ iterator.
OP_ITER, ///< Enter foreach loop.
OP_ITER_END, ///< End foreach loop.
OP_INVALID // 90
OP_INVALID, // 90
MAX_OP_CODELEN ///< The amount of op codes.
};
//------------------------------------------------------------
F64 consoleStringToNumber(const char *str, StringTableEntry file = 0, U32 line = 0);
U32 compileBlock(StmtNode *block, CodeStream &codeStream, U32 ip);
//------------------------------------------------------------
@ -207,6 +222,7 @@ namespace Compiler
Entry *list;
char buf[256];
std::unordered_map<std::string, Entry*> hashTable;
U32 add(const char *str, bool caseSens = true, bool tag = false);
U32 addIntString(U32 value);
@ -239,14 +255,14 @@ namespace Compiler
inline StringTableEntry CodeToSTE(U32 *code, U32 ip)
{
#ifdef TORQUE_CPU_X64
return (StringTableEntry)(*((U64*)(code+ip)));
return (StringTableEntry)(*((U64*)(code + ip)));
#else
return (StringTableEntry)(*(code+ip));
return (StringTableEntry)(*(code + ip));
#endif
}
extern void (*STEtoCode)(StringTableEntry ste, U32 ip, U32 *ptr);
extern void(*STEtoCode)(StringTableEntry ste, U32 ip, U32 *ptr);
void evalSTEtoCode(StringTableEntry ste, U32 ip, U32 *ptr);
void compileSTEtoCode(StringTableEntry ste, U32 ip, U32 *ptr);
@ -254,13 +270,13 @@ namespace Compiler
CompilerStringTable &getGlobalStringTable();
CompilerStringTable &getFunctionStringTable();
void setCurrentStringTable (CompilerStringTable* cst);
void setCurrentStringTable(CompilerStringTable* cst);
CompilerFloatTable *getCurrentFloatTable();
CompilerFloatTable &getGlobalFloatTable();
CompilerFloatTable &getFunctionFloatTable();
void setCurrentFloatTable (CompilerFloatTable* cst);
void setCurrentFloatTable(CompilerFloatTable* cst);
CompilerIdentTable &getIdentTable();
@ -280,7 +296,7 @@ namespace Compiler
class CodeStream
{
public:
enum FixType
{
// For loops
@ -288,37 +304,37 @@ public:
FIXTYPE_BREAK,
FIXTYPE_CONTINUE
};
enum Constants
{
BlockSize = 16384,
};
protected:
typedef struct PatchEntry
{
U32 addr; ///< Address to patch
U32 value; ///< Value to place at addr
PatchEntry() {;}
PatchEntry(U32 a, U32 v) : addr(a), value(v) {;}
PatchEntry() { ; }
PatchEntry(U32 a, U32 v) : addr(a), value(v) { ; }
} PatchEntry;
typedef struct CodeData
{
U8 *data; ///< Allocated data (size is BlockSize)
U32 size; ///< Bytes used in data
CodeData *next; ///< Next block
} CodeData;
/// @name Emitted code
/// {
CodeData *mCode;
CodeData *mCodeHead;
U32 mCodePos;
/// }
/// @name Code fixing stacks
/// {
Vector<U32> mFixList;
@ -326,28 +342,28 @@ protected:
Vector<bool> mFixLoopStack;
Vector<PatchEntry> mPatchList;
/// }
Vector<U32> mBreakLines; ///< Line numbers
public:
CodeStream() : mCode(0), mCodeHead(NULL), mCodePos(0)
{
}
~CodeStream()
{
reset();
if (mCode)
{
dFree(mCode->data);
delete mCode;
}
}
U8 *allocCode(U32 sz);
inline U32 emit(U32 code)
{
U32 *ptr = (U32*)allocCode(4);
@ -357,7 +373,7 @@ public:
#endif
return mCodePos++;
}
inline void patch(U32 addr, U32 code)
{
#ifdef DEBUG_CODESTREAM
@ -365,7 +381,7 @@ public:
#endif
mPatchList.push_back(PatchEntry(addr, code));
}
inline U32 emitSTE(const char *code)
{
U64 *ptr = (U64*)allocCode(8);
@ -375,70 +391,70 @@ public:
printf("code[%u] = %s\n", mCodePos, code);
#endif
mCodePos += 2;
return mCodePos-2;
return mCodePos - 2;
}
inline U32 tell()
{
return mCodePos;
}
inline bool inLoop()
{
for (U32 i=0; i<mFixLoopStack.size(); i++)
for (U32 i = 0; i<mFixLoopStack.size(); i++)
{
if (mFixLoopStack[i])
return true;
}
return false;
}
inline U32 emitFix(FixType type)
{
U32 *ptr = (U32*)allocCode(4);
*ptr = (U32)type;
#ifdef DEBUG_CODESTREAM
printf("code[%u] = [FIX:%u]\n", mCodePos, (U32)type);
#endif
mFixList.push_back(mCodePos);
mFixList.push_back((U32)type);
return mCodePos++;
}
inline void pushFixScope(bool isLoop)
{
mFixStack.push_back(mFixList.size());
mFixLoopStack.push_back(isLoop);
}
inline void popFixScope()
{
AssertFatal(mFixStack.size() > 0, "Fix stack mismatch");
U32 newSize = mFixStack[mFixStack.size()-1];
U32 newSize = mFixStack[mFixStack.size() - 1];
while (mFixList.size() > newSize)
mFixList.pop_back();
mFixStack.pop_back();
mFixLoopStack.pop_back();
}
void fixLoop(U32 loopBlockStart, U32 breakPoint, U32 continuePoint);
inline void addBreakLine(U32 lineNumber, U32 ip)
{
mBreakLines.push_back(lineNumber);
mBreakLines.push_back(ip);
}
inline U32 getNumLineBreaks()
{
return mBreakLines.size() / 2;
}
void emitCodeStream(U32 *size, U32 **stream, U32 **lineBreaks);
void reset();
};

View file

@ -24,13 +24,13 @@
#define _CONSOLE_H_
#ifndef _PLATFORM_H_
#include "platform/platform.h"
#include "platform/platform.h"
#endif
#ifndef _BITSET_H_
#include "core/bitSet.h"
#include "core/bitSet.h"
#endif
#ifndef _REFBASE_H_
#include "core/util/refBase.h"
#include "core/util/refBase.h"
#endif
#include <stdarg.h>
@ -95,8 +95,8 @@ struct ConsoleLogEntry
Script,
GUI,
Network,
GGConnect,
NUM_TYPE
GGConnect,
NUM_TYPE
} mType;
/// Indicates the actual log entry.
@ -120,7 +120,7 @@ extern char *typeValueEmpty;
class ConsoleValue
{
public:
enum
{
TypeInternalInt = -5,
@ -129,17 +129,17 @@ public:
TypeInternalStackString = -2,
TypeInternalString = -1,
};
S32 type;
public:
// NOTE: This is protected to ensure no one outside
// of this structure is messing with it.
#pragma warning( push )
#pragma warning( disable : 4201 ) // warning C4201: nonstandard extension used : nameless struct/union
// An variable is either a real dynamic type or
// its one exposed from C++ using a data pointer.
//
@ -154,24 +154,24 @@ public:
F32 fval;
U32 bufferLen;
};
struct
{
/// The real data pointer.
void *dataPtr;
/// The enum lookup table for enumerated types.
const EnumTable *enumTable;
};
};
U32 getIntValue();
S32 getSignedIntValue();
F32 getFloatValue();
const char *getStringValue();
StringStackPtr getStringStackPtr();
bool getBoolValue();
void setIntValue(U32 val);
void setIntValue(S32 val);
void setFloatValue(F32 val);
@ -179,7 +179,7 @@ public:
void setStackStringValue(const char *value);
void setStringStackPtrValue(StringStackPtr ptr);
void setBoolValue(bool val);
void init()
{
ival = 0;
@ -188,7 +188,7 @@ public:
bufferLen = 0;
type = TypeInternalString;
}
void cleanup()
{
if ((type <= TypeInternalString) && (bufferLen > 0))
@ -201,8 +201,8 @@ public:
ival = 0;
fval = 0;
}
ConsoleValue(){ init(); };
~ConsoleValue(){ cleanup(); };
ConsoleValue() { init(); };
~ConsoleValue() { cleanup(); };
};
// Proxy class for console variables
@ -234,7 +234,7 @@ public:
inline operator S32() { return getSignedIntValue(); }
inline operator F32() { return getFloatValue(); }
inline operator bool() { return getBoolValue(); }
inline bool isStringStackPtr() { return value ? value->type == ConsoleValue::TypeInternalStringStackPtr : false; }
inline bool isString() { return value ? value->type >= ConsoleValue::TypeInternalStringStackPtr : true; }
inline bool isInt() { return value ? value->type == ConsoleValue::TypeInternalInt : false; }
@ -320,12 +320,12 @@ public:
///
typedef const char * (*StringCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]);
typedef S32 (*IntCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]);
typedef F32 (*FloatCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]);
typedef void (*VoidCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]); // We have it return a value so things don't break..
typedef bool (*BoolCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]);
typedef S32(*IntCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]);
typedef F32(*FloatCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]);
typedef void(*VoidCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]); // We have it return a value so things don't break..
typedef bool(*BoolCallback)(SimObject *obj, S32 argc, ConsoleValueRef argv[]);
typedef void (*ConsumerCallback)(U32 level, const char *consoleLine);
typedef void(*ConsumerCallback)(U32 level, const char *consoleLine);
/// @}
/// @defgroup console_types Scripting Engine Type Functions
@ -333,7 +333,7 @@ typedef void (*ConsumerCallback)(U32 level, const char *consoleLine);
/// @see Con::registerType
/// @{
typedef const char* (*GetDataFunction)(void *dptr, EnumTable *tbl, BitSet32 flag);
typedef void (*SetDataFunction)(void *dptr, S32 argc, const char **argv, EnumTable *tbl, BitSet32 flag);
typedef void(*SetDataFunction)(void *dptr, S32 argc, const char **argv, EnumTable *tbl, BitSet32 flag);
/// @}
/// This namespace contains the core of the console functionality.
@ -347,7 +347,7 @@ typedef void (*SetDataFunction)(void *dptr, S32 argc, const char **argv,
namespace Con
{
/// Various configuration constants.
enum Constants
enum Constants
{
/// This is the version number associated with DSO files.
///
@ -361,20 +361,22 @@ namespace Con
/// 12/29/04 - BJG - 33->34 Removed some opcodes, part of namespace upgrade.
/// 12/30/04 - BJG - 34->35 Reordered some things, further general shuffling.
/// 11/03/05 - BJG - 35->36 Integrated new debugger code.
// 09/08/06 - THB - 36->37 New opcode for internal names
// 09/15/06 - THB - 37->38 Added unit conversions
// 11/23/06 - THB - 38->39 Added recursive internal name operator
// 02/15/07 - THB - 39->40 Bumping to 40 for TGB since the console has been
// majorly hacked without the version number being bumped
// 02/16/07 - THB - 40->41 newmsg operator
// 06/15/07 - THB - 41->42 script types
/// 09/08/06 - THB - 36->37 New opcode for internal names
/// 09/15/06 - THB - 37->38 Added unit conversions
/// 11/23/06 - THB - 38->39 Added recursive internal name operator
/// 02/15/07 - THB - 39->40 Bumping to 40 for TGB since the console has been
/// majorly hacked without the version number being bumped
/// 02/16/07 - THB - 40->41 newmsg operator
/// 06/15/07 - THB - 41->42 script types
/// 07/31/07 - THB - 42->43 Patch from Andreas Kirsch: Added opcode to support nested new declarations.
/// 09/12/07 - CAF - 43->44 remove newmsg operator
/// 09/27/07 - RDB - 44->45 Patch from Andreas Kirsch: Added opcode to support correct void return
/// 01/13/09 - TMS - 45->46 Added script assert
/// 09/07/14 - jamesu - 46->47 64bit support
/// 10/14/14 - jamesu - 47->48 Added opcodes to reduce reliance on strings in function calls
DSOVersion = 48,
/// 10/07/17 - JTH - 48->49 Added opcode for function pointers and revamp of interpreter
/// from switch to function calls.
DSOVersion = 49,
MaxLineLength = 512, ///< Maximum length of a line of console input.
MaxDataTypes = 256 ///< Maximum number of registered data types.
@ -552,11 +554,11 @@ namespace Con
/// @param usage Documentation string.
///
/// @see ConsoleDynamicTypes
void addVariable( const char *name,
S32 type,
void *pointer,
const char* usage = NULL );
void addVariable(const char *name,
S32 type,
void *pointer,
const char* usage = NULL);
/// Add a console constant that references the value of a constant in C++ code.
///
/// @param name Global console constant name to create.
@ -565,11 +567,11 @@ namespace Con
/// @param usage Documentation string.
///
/// @see ConsoleDynamicTypes
void addConstant( const char *name,
S32 type,
const void *pointer,
const char* usage = NULL );
void addConstant(const char *name,
S32 type,
const void *pointer,
const char* usage = NULL);
/// Remove a console variable.
///
/// @param name Global console variable name to remove
@ -582,14 +584,14 @@ namespace Con
/// @param name An existing global console variable name.
/// @param callback The notification delegate function.
///
void addVariableNotify( const char *name, const NotifyDelegate &callback );
void addVariableNotify(const char *name, const NotifyDelegate &callback);
/// Remove an existing variable assignment notification callback.
///
/// @param name An existing global console variable name.
/// @param callback The notification delegate function.
///
void removeVariableNotify( const char *name, const NotifyDelegate &callback );
void removeVariableNotify(const char *name, const NotifyDelegate &callback);
/// Assign a string value to a locally scoped console variable
///
@ -628,31 +630,31 @@ namespace Con
const char* getObjectField(const char* name);
/// Same as setVariable(), but for bools.
void setBoolVariable (const char* name,bool var);
void setBoolVariable(const char* name, bool var);
/// Same as getVariable(), but for bools.
///
/// @param name Name of the variable.
/// @param def Default value to supply if no matching variable is found.
bool getBoolVariable (const char* name,bool def = false);
bool getBoolVariable(const char* name, bool def = false);
/// Same as setVariable(), but for ints.
void setIntVariable (const char* name,S32 var);
void setIntVariable(const char* name, S32 var);
/// Same as getVariable(), but for ints.
///
/// @param name Name of the variable.
/// @param def Default value to supply if no matching variable is found.
S32 getIntVariable (const char* name,S32 def = 0);
S32 getIntVariable(const char* name, S32 def = 0);
/// Same as setVariable(), but for floats.
void setFloatVariable(const char* name,F32 var);
void setFloatVariable(const char* name, F32 var);
/// Same as getVariable(), but for floats.
///
/// @param name Name of the variable.
/// @param def Default value to supply if no matching variable is found.
F32 getFloatVariable(const char* name,F32 def = .0f);
F32 getFloatVariable(const char* name, F32 def = .0f);
/// @}
@ -668,52 +670,52 @@ namespace Con
/// @param maxArgs Maximum number of arguments this function accepts
/// @param toolOnly Wether this is a TORQUE_TOOLS only function.
/// @param header The extended function header.
void addCommand( const char* name, StringCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
void addCommand(const char* name, StringCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
void addCommand( const char* name, IntCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL ); ///< @copydoc addCommand( const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
void addCommand( const char* name, FloatCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL ); ///< @copydoc addCommand( const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
void addCommand( const char* name, VoidCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL ); ///< @copydoc addCommand( const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
void addCommand( const char* name, BoolCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL ); ///< @copydoc addCommand( const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
/// @}
void addCommand(const char* name, IntCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL); ///< @copydoc addCommand( const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
void addCommand(const char* name, FloatCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL); ///< @copydoc addCommand( const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
void addCommand(const char* name, VoidCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL); ///< @copydoc addCommand( const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
void addCommand(const char* name, BoolCallback cb, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL); ///< @copydoc addCommand( const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
/// @name Namespace Function Registration
/// @{
/// @}
/// Register a C++ function with the console making it callable
/// as a method of the given namespace from the scripting engine.
///
/// @param nameSpace Name of the namespace to associate the new function with; this is usually the name of a class.
/// @param name Name of the new function.
/// @param cb Pointer to the function implementing the scripting call; a console callback function returning a specific type value.
/// @param usage Documentation for this function. @ref console_autodoc
/// @param minArgs Minimum number of arguments this function accepts
/// @param maxArgs Maximum number of arguments this function accepts
/// @param toolOnly Wether this is a TORQUE_TOOLS only function.
/// @param header The extended function header.
void addCommand(const char *nameSpace, const char *name,StringCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
/// @name Namespace Function Registration
/// @{
void addCommand(const char *nameSpace, const char *name,IntCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL ); ///< @copydoc addCommand( const char*, const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
void addCommand(const char *nameSpace, const char *name,FloatCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL ); ///< @copydoc addCommand( const char*, const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
void addCommand(const char *nameSpace, const char *name,VoidCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL ); ///< @copydoc addCommand( const char*, const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
void addCommand(const char *nameSpace, const char *name,BoolCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL ); ///< @copydoc addCommand( const char*, const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
/// Register a C++ function with the console making it callable
/// as a method of the given namespace from the scripting engine.
///
/// @param nameSpace Name of the namespace to associate the new function with; this is usually the name of a class.
/// @param name Name of the new function.
/// @param cb Pointer to the function implementing the scripting call; a console callback function returning a specific type value.
/// @param usage Documentation for this function. @ref console_autodoc
/// @param minArgs Minimum number of arguments this function accepts
/// @param maxArgs Maximum number of arguments this function accepts
/// @param toolOnly Wether this is a TORQUE_TOOLS only function.
/// @param header The extended function header.
void addCommand(const char *nameSpace, const char *name, StringCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
/// @}
void addCommand(const char *nameSpace, const char *name, IntCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL); ///< @copydoc addCommand( const char*, const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
void addCommand(const char *nameSpace, const char *name, FloatCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL); ///< @copydoc addCommand( const char*, const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
void addCommand(const char *nameSpace, const char *name, VoidCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL); ///< @copydoc addCommand( const char*, const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
void addCommand(const char *nameSpace, const char *name, BoolCallback cb, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL); ///< @copydoc addCommand( const char*, const char *, StringCallback, const char *, S32, S32, bool, ConsoleFunctionHeader* )
/// @name Special Purpose Registration
///
/// These are special-purpose functions that exist to allow commands to be grouped, so
/// that when we generate console docs, they can be more meaningfully presented.
///
/// @ref console_autodoc "Click here for more information about console docs and grouping."
///
/// @{
/// @}
void markCommandGroup (const char * nsName, const char *name, const char* usage=NULL);
/// @name Special Purpose Registration
///
/// These are special-purpose functions that exist to allow commands to be grouped, so
/// that when we generate console docs, they can be more meaningfully presented.
///
/// @ref console_autodoc "Click here for more information about console docs and grouping."
///
/// @{
void markCommandGroup(const char * nsName, const char *name, const char* usage = NULL);
void beginCommandGroup(const char * nsName, const char *name, const char* usage);
void endCommandGroup (const char * nsName, const char *name);
void endCommandGroup(const char * nsName, const char *name);
void noteScriptCallback( const char *className, const char *funcName, const char *usage, ConsoleFunctionHeader* header = NULL );
void noteScriptCallback(const char *className, const char *funcName, const char *usage, ConsoleFunctionHeader* header = NULL);
/// @}
@ -841,15 +843,15 @@ namespace Con
///
char* getReturnBuffer(U32 bufferSize);
char* getReturnBuffer(const char *stringToCopy);
char* getReturnBuffer( const String& str );
char* getReturnBuffer( const StringBuilder& str );
char* getReturnBuffer(const String& str);
char* getReturnBuffer(const StringBuilder& str);
char* getArgBuffer(U32 bufferSize);
char* getFloatArg(F64 arg);
char* getIntArg (S32 arg);
char* getIntArg(S32 arg);
char* getBoolArg(bool arg);
char* getStringArg( const char* arg );
char* getStringArg( const String& arg );
char* getStringArg(const char* arg);
char* getStringArg(const String& arg);
/// @}
/// @name Namespaces
@ -877,7 +879,7 @@ namespace Con
/// @name Instant Group
/// @{
void pushInstantGroup( String name = String() );
void pushInstantGroup(String name = String());
void popInstantGroup();
/// @}
@ -915,7 +917,7 @@ namespace Con
template<typename R, typename ...ArgTs>
ConsoleValueRef executef(R r, ArgTs ...argTs)
{
_EngineConsoleExecCallbackHelper<R> callback( r );
_EngineConsoleExecCallbackHelper<R> callback(r);
return callback.template call<ConsoleValueRef>(argTs...);
}
/// }
@ -931,25 +933,25 @@ struct ConsoleFunctionHeader
{
/// Return type string.
const char* mReturnString;
/// List of arguments taken by the function. Used for documentation.
const char* mArgString;
/// List of default argument values. Used for documentation.
const char* mDefaultArgString;
/// Whether this is a static method in a class.
bool mIsStatic;
ConsoleFunctionHeader(
const char* returnString,
const char* argString,
const char* defaultArgString,
bool isStatic = false )
: mReturnString( returnString ),
mArgString( argString ),
mDefaultArgString( defaultArgString ),
mIsStatic( isStatic ) {}
bool isStatic = false)
: mReturnString(returnString),
mArgString(argString),
mDefaultArgString(defaultArgString),
mIsStatic(isStatic) {}
};
@ -969,7 +971,7 @@ public:
///
/// @ref console_autodoc
/// @{
StringCallback sc; ///< A function/method that returns a string.
IntCallback ic; ///< A function/method that returns an int.
FloatCallback fc; ///< A function/method that returns a float.
@ -979,18 +981,18 @@ public:
bool ns; ///< Indicates that this is a namespace marker.
/// @deprecated Unused.
bool callback; ///< Is this a callback into script?
/// @}
/// Minimum number of arguments expected by the function.
/// @}
/// Minimum number of arguments expected by the function.
S32 mina;
/// Maximum number of arguments accepted by the funtion. Zero for varargs.
S32 maxa;
/// Name of the function/method.
const char* funcName;
/// Name of the class namespace to which to add the method.
const char* className;
@ -999,10 +1001,10 @@ public:
/// Whether this is a TORQUE_TOOLS only function.
bool toolOnly;
/// The extended function header.
ConsoleFunctionHeader* header;
/// @name ConsoleConstructor Innards
///
/// The ConsoleConstructor class is used as the backend for the ConsoleFunction() and
@ -1067,7 +1069,7 @@ public:
ConsoleConstructor *next;
static ConsoleConstructor *first;
void init( const char* cName, const char* fName, const char *usg, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
void init(const char* cName, const char* fName, const char *usg, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
static void setup();
@ -1079,12 +1081,12 @@ public:
/// @name Basic Console Constructors
/// @{
ConsoleConstructor( const char* className, const char* funcName, StringCallback sfunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
ConsoleConstructor( const char* className, const char* funcName, IntCallback ifunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
ConsoleConstructor( const char* className, const char* funcName, FloatCallback ffunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
ConsoleConstructor( const char* className, const char* funcName, VoidCallback vfunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
ConsoleConstructor( const char* className, const char* funcName, BoolCallback bfunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
ConsoleConstructor(const char* className, const char* funcName, StringCallback sfunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
ConsoleConstructor(const char* className, const char* funcName, IntCallback ifunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
ConsoleConstructor(const char* className, const char* funcName, FloatCallback ffunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
ConsoleConstructor(const char* className, const char* funcName, VoidCallback vfunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
ConsoleConstructor(const char* className, const char* funcName, BoolCallback bfunc, const char* usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
/// @}
/// @name Magic Console Constructors
@ -1097,10 +1099,10 @@ public:
///
/// @see Con::markCommandGroup
/// @ref console_autodoc
ConsoleConstructor( const char *className, const char *groupName, const char* usage );
ConsoleConstructor(const char *className, const char *groupName, const char* usage);
/// Indicates a callback declared with the DECLARE_SCRIPT_CALLBACK macro and friends.
ConsoleConstructor( const char *className, const char *callbackName, const char *usage, ConsoleFunctionHeader* header );
ConsoleConstructor(const char *className, const char *callbackName, const char *usage, ConsoleFunctionHeader* header);
/// @}
};
@ -1112,25 +1114,25 @@ struct ConsoleDocFragment
/// The class in which to put the fragment. If NULL, the fragment
/// will be placed globally.
const char* mClass;
/// The definition to output for this fragment. NULL for fragments
/// not associated with a definition.
const char* mDefinition;
/// The documentation text.
const char* mText;
/// Next fragment in the global link chain.
ConsoleDocFragment* mNext;
/// First fragment in the global link chain.
static ConsoleDocFragment* smFirst;
ConsoleDocFragment( const char* text, const char* inClass = NULL, const char* definition = NULL )
: mClass( inClass ),
mDefinition( definition ),
mText( text ),
mNext( smFirst )
ConsoleDocFragment(const char* text, const char* inClass = NULL, const char* definition = NULL)
: mClass(inClass),
mDefinition(definition),
mText(text),
mNext(smFirst)
{
smFirst = this;
}
@ -1229,7 +1231,7 @@ public:
# define ConsoleMethodGroupEnd(className, groupName) \
static ConsoleConstructor cc_##className##_##groupName##_GroupEnd(#className,#groupName,NULL)
/// Add a fragment of auto-doc text to the console API reference.
/// @note There can only be one ConsoleDoc per source file.
# define ConsoleDoc( text ) \

File diff suppressed because it is too large Load diff

View file

@ -24,22 +24,21 @@
#define _CONSOLEINTERNAL_H_
#ifndef _STRINGFUNCTIONS_H_
#include "core/strings/stringFunctions.h"
#include "core/strings/stringFunctions.h"
#endif
#ifndef _STRINGTABLE_H_
#include "core/stringTable.h"
#include "core/stringTable.h"
#endif
#ifndef _CONSOLETYPES_H
#include "console/consoleTypes.h"
#include "console/consoleTypes.h"
#endif
#ifndef _CONSOLEOBJECT_H_
#include "console/simObject.h"
#include "console/simObject.h"
#endif
#ifndef _DATACHUNKER_H_
#include "core/dataChunker.h"
#include "core/dataChunker.h"
#endif
/// @ingroup console_system Console System
/// @{
@ -55,222 +54,222 @@ class AbstractClassRep;
/// Namespaces are used for dispatching calls in the console system.
class Namespace
{
enum {
MaxActivePackages = 512,
enum {
MaxActivePackages = 512,
};
static U32 mNumActivePackages;
static U32 mOldNumActivePackages;
static StringTableEntry mActivePackages[MaxActivePackages];
public:
StringTableEntry mName;
StringTableEntry mPackage;
Namespace *mParent;
Namespace *mNext;
AbstractClassRep *mClassRep;
U32 mRefCountToParent;
const char* mUsage;
/// Script defined usage strings need to be cleaned up. This
/// field indicates whether or not the usage was set from script.
bool mCleanUpUsage;
/// A function entry in the namespace.
struct Entry
{
enum
{
ScriptCallbackType = -3,
GroupMarker = -2,
InvalidFunctionType = -1,
ConsoleFunctionType,
StringCallbackType,
IntCallbackType,
FloatCallbackType,
VoidCallbackType,
BoolCallbackType
};
static U32 mNumActivePackages;
static U32 mOldNumActivePackages;
static StringTableEntry mActivePackages[MaxActivePackages];
/// Link back to the namespace to which the entry belongs.
Namespace* mNamespace;
public:
StringTableEntry mName;
/// Next function entry in the hashtable link chain of the namespace.
Entry* mNext;
/// Name of this function.
StringTableEntry mFunctionName;
///
S32 mType;
/// Min number of arguments expected by this function.
S32 mMinArgs;
/// Max number of arguments expected by this function. If zero,
/// function takes an arbitrary number of arguments.
S32 mMaxArgs;
/// Name of the package to which this function belongs.
StringTableEntry mPackage;
Namespace *mParent;
Namespace *mNext;
AbstractClassRep *mClassRep;
U32 mRefCountToParent;
/// Whether this function is included only in TORQUE_TOOLS builds.
bool mToolOnly;
/// Usage string for documentation.
const char* mUsage;
/// Script defined usage strings need to be cleaned up. This
/// field indicates whether or not the usage was set from script.
bool mCleanUpUsage;
/// A function entry in the namespace.
struct Entry
{
enum
{
ScriptCallbackType = -3,
GroupMarker = -2,
InvalidFunctionType = -1,
ConsoleFunctionType,
StringCallbackType,
IntCallbackType,
FloatCallbackType,
VoidCallbackType,
BoolCallbackType
};
/// Extended console function information.
ConsoleFunctionHeader* mHeader;
/// Link back to the namespace to which the entry belongs.
Namespace* mNamespace;
/// Next function entry in the hashtable link chain of the namespace.
Entry* mNext;
/// Name of this function.
StringTableEntry mFunctionName;
///
S32 mType;
/// Min number of arguments expected by this function.
S32 mMinArgs;
/// Max number of arguments expected by this function. If zero,
/// function takes an arbitrary number of arguments.
S32 mMaxArgs;
/// Name of the package to which this function belongs.
StringTableEntry mPackage;
/// Whether this function is included only in TORQUE_TOOLS builds.
bool mToolOnly;
/// The compiled script code if this is a script function.
CodeBlock* mCode;
/// Usage string for documentation.
const char* mUsage;
/// Extended console function information.
ConsoleFunctionHeader* mHeader;
/// The offset in the compiled script code at which this function begins.
U32 mFunctionOffset;
/// The compiled script code if this is a script function.
CodeBlock* mCode;
/// The offset in the compiled script code at which this function begins.
U32 mFunctionOffset;
/// If it's a script function, this is the line of the declaration in code.
/// @note 0 for functions read from legacy DSOs that have no line number information.
U32 mFunctionLineNumber;
/// If it's a script function, this is the line of the declaration in code.
/// @note 0 for functions read from legacy DSOs that have no line number information.
U32 mFunctionLineNumber;
union CallbackUnion {
StringCallback mStringCallbackFunc;
IntCallback mIntCallbackFunc;
VoidCallback mVoidCallbackFunc;
FloatCallback mFloatCallbackFunc;
BoolCallback mBoolCallbackFunc;
const char *mGroupName;
const char *mCallbackName;
} cb;
Entry();
///
void clear();
union CallbackUnion {
StringCallback mStringCallbackFunc;
IntCallback mIntCallbackFunc;
VoidCallback mVoidCallbackFunc;
FloatCallback mFloatCallbackFunc;
BoolCallback mBoolCallbackFunc;
const char *mGroupName;
const char *mCallbackName;
} cb;
///
ConsoleValueRef execute( S32 argc, ConsoleValueRef* argv, ExprEvalState* state );
/// Return a one-line documentation text string for the function.
String getBriefDescription( String* outRemainingDocText = NULL ) const;
/// Get the auto-doc string for this function. This string does not included prototype information.
String getDocString() const;
/// Return a string describing the arguments the function takes including default argument values.
String getArgumentsString() const;
Entry();
/// Return a full prototype string for the function including return type, function name,
/// and arguments.
String getPrototypeString() const;
};
Entry* mEntryList;
///
void clear();
Entry** mHashTable;
U32 mHashSize;
U32 mHashSequence; ///< @note The hash sequence is used by the autodoc console facility
/// as a means of testing reference state.
///
ConsoleValueRef execute(S32 argc, ConsoleValueRef* argv, ExprEvalState* state);
Namespace();
~Namespace();
/// Return a one-line documentation text string for the function.
String getBriefDescription(String* outRemainingDocText = NULL) const;
void addFunction( StringTableEntry name, CodeBlock* cb, U32 functionOffset, const char* usage = NULL, U32 lineNumber = 0 );
void addCommand( StringTableEntry name, StringCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
void addCommand( StringTableEntry name, IntCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
void addCommand( StringTableEntry name, FloatCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
void addCommand( StringTableEntry name, VoidCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
void addCommand( StringTableEntry name, BoolCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL );
/// Get the auto-doc string for this function. This string does not included prototype information.
String getDocString() const;
void addScriptCallback( const char *funcName, const char *usage, ConsoleFunctionHeader* header = NULL );
/// Return a string describing the arguments the function takes including default argument values.
String getArgumentsString() const;
void markGroup(const char* name, const char* usage);
char * lastUsage;
/// Return a full prototype string for the function including return type, function name,
/// and arguments.
String getPrototypeString() const;
};
/// Returns true if this namespace represents an engine defined
/// class and is not just a script defined class namespace.
bool isClass() const { return mClassRep && mClassRep->getNameSpace() == this; }
Entry* mEntryList;
void getEntryList(VectorPtr<Entry *> *);
Entry** mHashTable;
/// Return the name of this namespace.
StringTableEntry getName() const { return mName; }
U32 mHashSize;
U32 mHashSequence; ///< @note The hash sequence is used by the autodoc console facility
/// as a means of testing reference state.
/// Return the superordinate namespace to this namespace. Symbols are inherited from
/// this namespace.
Namespace* getParent() const { return mParent; }
Namespace();
~Namespace();
/// Return the topmost package in the parent hierarchy of this namespace
/// that still refers to the same namespace. If packages are active and
/// adding to this namespace, then they will be linked in-between the namespace
/// they are adding to and its real parent namespace.
Namespace* getPackageRoot()
{
Namespace* walk = this;
while( walk->mParent && walk->mParent->mName == mName )
walk = walk->mParent;
void addFunction(StringTableEntry name, CodeBlock* cb, U32 functionOffset, const char* usage = NULL, U32 lineNumber = 0);
void addCommand(StringTableEntry name, StringCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
void addCommand(StringTableEntry name, IntCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
void addCommand(StringTableEntry name, FloatCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
void addCommand(StringTableEntry name, VoidCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
void addCommand(StringTableEntry name, BoolCallback, const char *usage, S32 minArgs, S32 maxArgs, bool toolOnly = false, ConsoleFunctionHeader* header = NULL);
return walk;
}
void addScriptCallback(const char *funcName, const char *usage, ConsoleFunctionHeader* header = NULL);
/// Return the package in which this namespace is defined.
StringTableEntry getPackage() const { return mPackage; }
void markGroup(const char* name, const char* usage);
char * lastUsage;
/// Increase the count on the reference that this namespace
/// holds to its parent.
/// @note Must not be called on namespaces coming from packages.
void incRefCountToParent()
{
AssertFatal( mPackage == NULL, "Namespace::incRefCountToParent - Must not be called on a namespace coming from a package!" );
mRefCountToParent ++;
}
/// Returns true if this namespace represents an engine defined
/// class and is not just a script defined class namespace.
bool isClass() const { return mClassRep && mClassRep->getNameSpace() == this; }
/// Decrease the count on the reference that this namespace
/// holds to its parent.
/// @note Must not be called on namespaces coming from packages.
void decRefCountToParent()
{
unlinkClass( NULL );
}
void getEntryList(VectorPtr<Entry *> *);
Entry *lookup(StringTableEntry name);
Entry *lookupRecursive(StringTableEntry name);
Entry *createLocalEntry(StringTableEntry name);
void buildHashTable();
void clearEntries();
bool classLinkTo(Namespace *parent);
bool unlinkClass(Namespace *parent);
void getUniqueEntryLists( Namespace *other, VectorPtr<Entry *> *outThisList, VectorPtr<Entry *> *outOtherList );
/// Return the name of this namespace.
StringTableEntry getName() const { return mName; }
const char *tabComplete(const char *prevText, S32 baseLen, bool fForward);
/// Return the superordinate namespace to this namespace. Symbols are inherited from
/// this namespace.
Namespace* getParent() const { return mParent; }
static U32 mCacheSequence;
static DataChunker mCacheAllocator;
static DataChunker mAllocator;
static void trashCache();
static Namespace *mNamespaceList;
static Namespace *mGlobalNamespace;
/// Return the topmost package in the parent hierarchy of this namespace
/// that still refers to the same namespace. If packages are active and
/// adding to this namespace, then they will be linked in-between the namespace
/// they are adding to and its real parent namespace.
Namespace* getPackageRoot()
{
Namespace* walk = this;
while (walk->mParent && walk->mParent->mName == mName)
walk = walk->mParent;
static void init();
static void shutdown();
static Namespace *global();
return walk;
}
static Namespace *find(StringTableEntry name, StringTableEntry package=NULL);
/// Return the package in which this namespace is defined.
StringTableEntry getPackage() const { return mPackage; }
static void activatePackage(StringTableEntry name);
static void deactivatePackage(StringTableEntry name);
static void deactivatePackageStack(StringTableEntry name);
static void dumpClasses( bool dumpScript = true, bool dumpEngine = true );
static void dumpFunctions( bool dumpScript = true, bool dumpEngine = true );
static void printNamespaceEntries(Namespace * g, bool dumpScript = true, bool dumpEngine = true);
static void unlinkPackages();
static void relinkPackages();
static bool isPackage(StringTableEntry name);
static U32 getActivePackagesCount();
static StringTableEntry getActivePackage(U32 index);
/// Increase the count on the reference that this namespace
/// holds to its parent.
/// @note Must not be called on namespaces coming from packages.
void incRefCountToParent()
{
AssertFatal(mPackage == NULL, "Namespace::incRefCountToParent - Must not be called on a namespace coming from a package!");
mRefCountToParent++;
}
/// Decrease the count on the reference that this namespace
/// holds to its parent.
/// @note Must not be called on namespaces coming from packages.
void decRefCountToParent()
{
unlinkClass(NULL);
}
Entry *lookup(StringTableEntry name);
Entry *lookupRecursive(StringTableEntry name);
Entry *createLocalEntry(StringTableEntry name);
void buildHashTable();
void clearEntries();
bool classLinkTo(Namespace *parent);
bool unlinkClass(Namespace *parent);
void getUniqueEntryLists(Namespace *other, VectorPtr<Entry *> *outThisList, VectorPtr<Entry *> *outOtherList);
const char *tabComplete(const char *prevText, S32 baseLen, bool fForward);
static U32 mCacheSequence;
static DataChunker mCacheAllocator;
static DataChunker mAllocator;
static void trashCache();
static Namespace *mNamespaceList;
static Namespace *mGlobalNamespace;
static void init();
static void shutdown();
static Namespace *global();
static Namespace *find(StringTableEntry name, StringTableEntry package = NULL);
static void activatePackage(StringTableEntry name);
static void deactivatePackage(StringTableEntry name);
static void deactivatePackageStack(StringTableEntry name);
static void dumpClasses(bool dumpScript = true, bool dumpEngine = true);
static void dumpFunctions(bool dumpScript = true, bool dumpEngine = true);
static void printNamespaceEntries(Namespace * g, bool dumpScript = true, bool dumpEngine = true);
static void unlinkPackages();
static void relinkPackages();
static bool isPackage(StringTableEntry name);
static U32 getActivePackagesCount();
static StringTableEntry getActivePackage(U32 index);
};
typedef VectorPtr<Namespace::Entry *>::iterator NamespaceEntryListIterator;
@ -292,10 +291,10 @@ public:
/// The optional notification signal called when
/// a value is assigned to this variable.
NotifySignal *notify;
/// Usage doc string.
const char* mUsage;
/// Whether this is a constant that cannot be assigned to.
bool mIsConstant;
@ -309,16 +308,16 @@ public:
mIsConstant = false;
value.init();
}
Entry(StringTableEntry name);
~Entry();
Entry *mNext;
void reset() {
name = NULL;
value.cleanup();
if ( notify )
if (notify)
delete notify;
}
@ -339,63 +338,63 @@ public:
void setIntValue(U32 val)
{
if( mIsConstant )
if (mIsConstant)
{
Con::errorf( "Cannot assign value to constant '%s'.", name );
Con::errorf("Cannot assign value to constant '%s'.", name);
return;
}
value.setIntValue(val);
// Fire off the notification if we have one.
if ( notify )
if (notify)
notify->trigger();
}
void setFloatValue(F32 val)
{
if( mIsConstant )
if (mIsConstant)
{
Con::errorf( "Cannot assign value to constant '%s'.", name );
Con::errorf("Cannot assign value to constant '%s'.", name);
return;
}
value.setFloatValue(val);
// Fire off the notification if we have one.
if ( notify )
if (notify)
notify->trigger();
}
void setStringStackPtrValue(StringStackPtr newValue)
{
if( mIsConstant )
if (mIsConstant)
{
Con::errorf( "Cannot assign value to constant '%s'.", name );
Con::errorf("Cannot assign value to constant '%s'.", name);
return;
}
value.setStringStackPtrValue(newValue);
// Fire off the notification if we have one.
if ( notify )
if (notify)
notify->trigger();
}
void setStringValue(const char *newValue)
{
if( mIsConstant )
if (mIsConstant)
{
Con::errorf( "Cannot assign value to constant '%s'.", name );
Con::errorf("Cannot assign value to constant '%s'.", name);
return;
}
value.setStringValue(newValue);
// Fire off the notification if we have one.
if ( notify )
if (notify)
notify->trigger();
}
};
@ -407,9 +406,9 @@ public:
S32 count;
Entry **data;
FreeListChunker< Entry > mChunker;
HashTableData( Dictionary* owner )
: owner( owner ), size( 0 ), count( 0 ), data( NULL ) {}
HashTableData(Dictionary* owner)
: owner(owner), size(0), count(0), data(NULL) {}
};
HashTableData* hashTable;
@ -426,13 +425,13 @@ public:
Entry *lookup(StringTableEntry name);
Entry *add(StringTableEntry name);
void setState(ExprEvalState *state, Dictionary* ref=NULL);
void setState(ExprEvalState *state, Dictionary* ref = NULL);
void remove(Entry *);
void reset();
void exportVariables( const char *varString, const char *fileName, bool append );
void exportVariables( const char *varString, Vector<String> *names, Vector<String> *values );
void deleteVariables( const char *varString );
void exportVariables(const char *varString, const char *fileName, bool append);
void exportVariables(const char *varString, Vector<String> *names, Vector<String> *values);
void deleteVariables(const char *varString);
void setVariable(StringTableEntry name, const char *value);
const char *getVariable(StringTableEntry name, bool *valid = NULL);
@ -449,19 +448,19 @@ public:
}
/// @see Con::addVariable
Entry* addVariable( const char *name,
S32 type,
void *dataPtr,
const char* usage );
Entry* addVariable(const char *name,
S32 type,
void *dataPtr,
const char* usage);
/// @see Con::removeVariable
bool removeVariable(StringTableEntry name);
/// @see Con::addVariableNotify
void addVariableNotify( const char *name, const Con::NotifyDelegate &callback );
void addVariableNotify(const char *name, const Con::NotifyDelegate &callback);
/// @see Con::removeVariableNotify
void removeVariableNotify( const char *name, const Con::NotifyDelegate &callback );
void removeVariableNotify(const char *name, const Con::NotifyDelegate &callback);
/// Return the best tab completion for prevText, with the length
/// of the pre-tab string in baseLen.
@ -520,15 +519,15 @@ public:
/// Puts a reference to an existing stack frame
/// on the top of the stack.
void pushFrameRef(S32 stackIndex);
U32 getStackDepth() const
{
return mStackDepth;
}
Dictionary& getCurrentFrame()
{
return *( stack[ mStackDepth - 1 ] );
return *(stack[mStackDepth - 1]);
}
/// @}

View file

@ -45,7 +45,7 @@ SimNameDictionary::~SimNameDictionary()
void SimNameDictionary::insert(SimObject* obj)
{
if(!obj || !obj->objectName)
if (!obj || !obj->objectName)
return;
SimObject* checkForDup = find(obj->objectName);
@ -55,47 +55,47 @@ void SimNameDictionary::insert(SimObject* obj)
Mutex::lockMutex(mutex);
#ifndef USE_NEW_SIMDICTIONARY
if(!hashTable)
if (!hashTable)
{
hashTable = new SimObject *[DefaultTableSize];
hashTableSize = DefaultTableSize;
hashEntryCount = 0;
dMemset( hashTable, 0, sizeof( *hashTable ) * DefaultTableSize );
dMemset(hashTable, 0, sizeof(*hashTable) * DefaultTableSize);
}
S32 idx = HashPointer(obj->objectName) % hashTableSize;
obj->nextNameObject = hashTable[idx];
hashTable[idx] = obj;
hashEntryCount++;
// Rehash if necessary.
if( hashEntryCount > hashTableSize )
if (hashEntryCount > hashTableSize)
{
// Allocate new table.
U32 newHashTableSize = hashTableSize * 2 + 1;
SimObject** newHashTable = new SimObject *[ newHashTableSize ];
dMemset( newHashTable, 0, sizeof( newHashTable[ 0 ] ) * newHashTableSize );
SimObject** newHashTable = new SimObject *[newHashTableSize];
dMemset(newHashTable, 0, sizeof(newHashTable[0]) * newHashTableSize);
// Move entries over.
for( U32 i = 0; i < hashTableSize; ++ i )
for( SimObject* object = hashTable[ i ]; object != NULL; )
for (U32 i = 0; i < hashTableSize; ++i)
for (SimObject* object = hashTable[i]; object != NULL; )
{
SimObject* next = object->nextNameObject;
idx = HashPointer( object->objectName ) % newHashTableSize;
object->nextNameObject = newHashTable[ idx ];
newHashTable[ idx ] = object;
idx = HashPointer(object->objectName) % newHashTableSize;
object->nextNameObject = newHashTable[idx];
newHashTable[idx] = object;
object = next;
}
// Switch tables.
delete [] hashTable;
delete[] hashTable;
hashTable = newHashTable;
hashTableSize = newHashTableSize;
}
@ -109,16 +109,16 @@ SimObject* SimNameDictionary::find(StringTableEntry name)
{
#ifndef USE_NEW_SIMDICTIONARY
// NULL is a valid lookup - it will always return NULL
if(!hashTable)
if (!hashTable)
return NULL;
Mutex::lockMutex(mutex);
S32 idx = HashPointer(name) % hashTableSize;
SimObject *walk = hashTable[idx];
while(walk)
while (walk)
{
if(walk->objectName == name)
if (walk->objectName == name)
{
Mutex::unlockMutex(mutex);
return walk;
@ -129,28 +129,28 @@ SimObject* SimNameDictionary::find(StringTableEntry name)
Mutex::unlockMutex(mutex);
return NULL;
#else
Mutex::lockMutex(mutex);
StringDictDef::iterator it = root.find(name);
SimObject* f = (it == root.end() ? NULL : it->second);
Mutex::unlockMutex(mutex);
return f;
Mutex::lockMutex(mutex);
StringDictDef::iterator it = root.find(name);
SimObject* f = (it == root.end() ? NULL : it->second);
Mutex::unlockMutex(mutex);
return f;
#endif
}
void SimNameDictionary::remove(SimObject* obj)
{
if(!obj || !obj->objectName)
if (!obj || !obj->objectName)
return;
Mutex::lockMutex(mutex);
#ifndef USE_NEW_SIMDICTIONARY
SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
while(*walk)
while (*walk)
{
if(*walk == obj)
if (*walk == obj)
{
*walk = obj->nextNameObject;
obj->nextNameObject = (SimObject*)-1;
obj->nextNameObject = nullptr;
hashEntryCount--;
Mutex::unlockMutex(mutex);
@ -164,7 +164,7 @@ void SimNameDictionary::remove(SimObject* obj)
root.erase(name);
#endif
Mutex::unlockMutex(mutex);
}
}
//----------------------------------------------------------------------------
@ -174,8 +174,8 @@ SimManagerNameDictionary::SimManagerNameDictionary()
hashTable = new SimObject *[DefaultTableSize];
hashTableSize = DefaultTableSize;
hashEntryCount = 0;
dMemset( hashTable, 0, sizeof( hashTable[ 0 ] ) * hashTableSize );
dMemset(hashTable, 0, sizeof(hashTable[0]) * hashTableSize);
#endif
mutex = Mutex::createMutex();
}
@ -190,7 +190,7 @@ SimManagerNameDictionary::~SimManagerNameDictionary()
void SimManagerNameDictionary::insert(SimObject* obj)
{
if(!obj || !obj->objectName)
if (!obj || !obj->objectName)
return;
Mutex::lockMutex(mutex);
@ -199,34 +199,34 @@ void SimManagerNameDictionary::insert(SimObject* obj)
obj->nextManagerNameObject = hashTable[idx];
hashTable[idx] = obj;
hashEntryCount++;
// Rehash if necessary.
if( hashEntryCount > hashTableSize )
if (hashEntryCount > hashTableSize)
{
// Allocate new table.
U32 newHashTableSize = hashTableSize * 2 + 1;
SimObject** newHashTable = new SimObject *[ newHashTableSize ];
dMemset( newHashTable, 0, sizeof( newHashTable[ 0 ] ) * newHashTableSize );
SimObject** newHashTable = new SimObject *[newHashTableSize];
dMemset(newHashTable, 0, sizeof(newHashTable[0]) * newHashTableSize);
// Move entries over.
for( U32 i = 0; i < hashTableSize; ++ i )
for( SimObject* object = hashTable[ i ]; object != NULL; )
for (U32 i = 0; i < hashTableSize; ++i)
for (SimObject* object = hashTable[i]; object != NULL; )
{
SimObject* next = object->nextManagerNameObject;
idx = HashPointer( object->objectName ) % newHashTableSize;
object->nextManagerNameObject = newHashTable[ idx ];
newHashTable[ idx ] = object;
idx = HashPointer(object->objectName) % newHashTableSize;
object->nextManagerNameObject = newHashTable[idx];
newHashTable[idx] = object;
object = next;
}
// Switch tables.
delete [] hashTable;
delete[] hashTable;
hashTable = newHashTable;
hashTableSize = newHashTableSize;
}
@ -245,9 +245,9 @@ SimObject* SimManagerNameDictionary::find(StringTableEntry name)
#ifndef USE_NEW_SIMDICTIONARY
S32 idx = HashPointer(name) % hashTableSize;
SimObject *walk = hashTable[idx];
while(walk)
while (walk)
{
if(walk->objectName == name)
if (walk->objectName == name)
{
Mutex::unlockMutex(mutex);
return walk;
@ -267,19 +267,19 @@ SimObject* SimManagerNameDictionary::find(StringTableEntry name)
void SimManagerNameDictionary::remove(SimObject* obj)
{
if(!obj || !obj->objectName)
if (!obj || !obj->objectName)
return;
#ifndef USE_NEW_SIMDICTIONARY
Mutex::lockMutex(mutex);
SimObject **walk = &hashTable[HashPointer(obj->objectName) % hashTableSize];
while(*walk)
while (*walk)
{
if(*walk == obj)
if (*walk == obj)
{
*walk = obj->nextManagerNameObject;
obj->nextManagerNameObject = (SimObject*)-1;
obj->nextManagerNameObject = nullptr;
hashEntryCount--;
Mutex::unlockMutex(mutex);
@ -293,7 +293,7 @@ void SimManagerNameDictionary::remove(SimObject* obj)
root.erase(name);
#endif
Mutex::unlockMutex(mutex);
}
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
@ -301,7 +301,7 @@ void SimManagerNameDictionary::remove(SimObject* obj)
SimIdDictionary::SimIdDictionary()
{
#ifndef USE_NEW_SIMDICTIONARY
dMemset( table, 0, sizeof( table[ 0 ] ) * DefaultTableSize );
dMemset(table, 0, sizeof(table[0]) * DefaultTableSize);
#endif
mutex = Mutex::createMutex();
}
@ -322,7 +322,7 @@ void SimIdDictionary::insert(SimObject* obj)
#ifndef USE_NEW_SIMDICTIONARY
S32 idx = obj->getId() & TableBitMask;
obj->nextIdObject = table[idx];
AssertFatal( obj->nextIdObject != obj, "SimIdDictionary::insert - Creating Infinite Loop linking to self!" );
AssertFatal(obj->nextIdObject != obj, "SimIdDictionary::insert - Creating Infinite Loop linking to self!");
table[idx] = obj;
#else
root[obj->getId()] = obj;
@ -336,9 +336,9 @@ SimObject* SimIdDictionary::find(S32 id)
#ifndef USE_NEW_SIMDICTIONARY
S32 idx = id & TableBitMask;
SimObject *walk = table[idx];
while(walk)
while (walk)
{
if(walk->getId() == U32(id))
if (walk->getId() == U32(id))
{
Mutex::unlockMutex(mutex);
return walk;
@ -364,9 +364,9 @@ void SimIdDictionary::remove(SimObject* obj)
Mutex::lockMutex(mutex);
#ifndef USE_NEW_SIMDICTIONARY
SimObject **walk = &table[obj->getId() & TableBitMask];
while(*walk && *walk != obj)
while (*walk && *walk != obj)
walk = &((*walk)->nextIdObject);
if(*walk)
if (*walk)
*walk = obj->nextIdObject;
#else
root.erase(obj->getId());

View file

@ -36,20 +36,20 @@ SimFieldDictionary::Entry *SimFieldDictionary::smFreeList = NULL;
static Chunker<SimFieldDictionary::Entry> fieldChunker;
U32 SimFieldDictionary::getHashValue( StringTableEntry slotName )
U32 SimFieldDictionary::getHashValue(StringTableEntry slotName)
{
return HashPointer( slotName ) % HashTableSize;
return HashPointer(slotName) % HashTableSize;
}
U32 SimFieldDictionary::getHashValue( const String& fieldName )
U32 SimFieldDictionary::getHashValue(const String& fieldName)
{
return getHashValue( StringTable->insert( fieldName ) );
return getHashValue(StringTable->insert(fieldName));
}
SimFieldDictionary::Entry *SimFieldDictionary::addEntry( U32 bucket, StringTableEntry slotName, ConsoleBaseType* type, char* value )
SimFieldDictionary::Entry *SimFieldDictionary::addEntry(U32 bucket, StringTableEntry slotName, ConsoleBaseType* type, char* value)
{
Entry* ret;
if(smFreeList)
if (smFreeList)
{
ret = smFreeList;
smFreeList = ret->next;
@ -57,14 +57,14 @@ SimFieldDictionary::Entry *SimFieldDictionary::addEntry( U32 bucket, StringTable
else
ret = fieldChunker.alloc();
ret->next = mHashTable[ bucket ];
ret->slotName = slotName;
ret->type = type;
ret->value = value;
ret->next = mHashTable[bucket];
ret->slotName = slotName;
ret->type = type;
ret->value = value;
mHashTable[ bucket ] = ret;
mNumFields ++;
mVersion ++;
mHashTable[bucket] = ret;
mNumFields++;
mVersion++;
return ret;
}
@ -74,37 +74,37 @@ void SimFieldDictionary::freeEntry(SimFieldDictionary::Entry *ent)
ent->next = smFreeList;
smFreeList = ent;
mNumFields --;
mNumFields--;
}
SimFieldDictionary::SimFieldDictionary()
: mNumFields( 0 ),
mVersion( 0 )
: mNumFields(0),
mVersion(0)
{
dMemset( mHashTable, 0, sizeof( mHashTable ) );
dMemset(mHashTable, 0, sizeof(mHashTable));
}
SimFieldDictionary::~SimFieldDictionary()
{
for(U32 i = 0; i < HashTableSize; i++)
for (U32 i = 0; i < HashTableSize; i++)
{
for(Entry *walk = mHashTable[i]; walk;)
for (Entry *walk = mHashTable[i]; walk;)
{
Entry *temp = walk;
walk = temp->next;
if( temp->value )
if (temp->value)
dFree(temp->value);
freeEntry(temp);
}
}
AssertFatal( mNumFields == 0, "Incorrect count on field dictionary" );
AssertFatal(mNumFields == 0, "Incorrect count on field dictionary");
}
void SimFieldDictionary::setFieldType(StringTableEntry slotName, const char *typeString)
{
ConsoleBaseType *cbt = ConsoleBaseType::getTypeByName( typeString );
ConsoleBaseType *cbt = ConsoleBaseType::getTypeByName(typeString);
setFieldType(slotName, cbt);
}
@ -117,11 +117,11 @@ void SimFieldDictionary::setFieldType(StringTableEntry slotName, const U32 typeI
void SimFieldDictionary::setFieldType(StringTableEntry slotName, ConsoleBaseType *type)
{
// If the field exists on the object, set the type
U32 bucket = getHashValue( slotName );
U32 bucket = getHashValue(slotName);
for( Entry *walk = mHashTable[bucket]; walk; walk = walk->next )
for (Entry *walk = mHashTable[bucket]; walk; walk = walk->next)
{
if( walk->slotName == slotName )
if (walk->slotName == slotName)
{
// Found and type assigned, let's bail
walk->type = type;
@ -130,15 +130,15 @@ void SimFieldDictionary::setFieldType(StringTableEntry slotName, ConsoleBaseType
}
// Otherwise create the field, and set the type. Assign a null value.
addEntry( bucket, slotName, type );
addEntry(bucket, slotName, type);
}
U32 SimFieldDictionary::getFieldType(StringTableEntry slotName) const
{
U32 bucket = getHashValue( slotName );
U32 bucket = getHashValue(slotName);
for( Entry *walk = mHashTable[bucket]; walk; walk = walk->next )
if( walk->slotName == slotName )
for (Entry *walk = mHashTable[bucket]; walk; walk = walk->next)
if (walk->slotName == slotName)
return walk->type ? walk->type->getTypeID() : TypeString;
return TypeString;
@ -146,27 +146,27 @@ U32 SimFieldDictionary::getFieldType(StringTableEntry slotName) const
SimFieldDictionary::Entry *SimFieldDictionary::findDynamicField(const String &fieldName) const
{
U32 bucket = getHashValue( fieldName );
U32 bucket = getHashValue(fieldName);
for( Entry *walk = mHashTable[bucket]; walk; walk = walk->next )
for (Entry *walk = mHashTable[bucket]; walk; walk = walk->next)
{
if( fieldName.equal(walk->slotName, String::NoCase) )
if (fieldName.equal(walk->slotName, String::NoCase))
return walk;
}
return NULL;
}
SimFieldDictionary::Entry *SimFieldDictionary::findDynamicField( StringTableEntry fieldName) const
SimFieldDictionary::Entry *SimFieldDictionary::findDynamicField(StringTableEntry fieldName) const
{
U32 bucket = getHashValue( fieldName );
U32 bucket = getHashValue(fieldName);
for( Entry *walk = mHashTable[bucket]; walk; walk = walk->next )
for (Entry *walk = mHashTable[bucket]; walk; walk = walk->next)
{
if( walk->slotName == fieldName )
{
return walk;
}
if (walk->slotName == fieldName)
{
return walk;
}
}
return NULL;
@ -177,17 +177,17 @@ void SimFieldDictionary::setFieldValue(StringTableEntry slotName, const char *va
{
U32 bucket = getHashValue(slotName);
Entry **walk = &mHashTable[bucket];
while(*walk && (*walk)->slotName != slotName)
while (*walk && (*walk)->slotName != slotName)
walk = &((*walk)->next);
Entry *field = *walk;
if( !value || !*value )
if (!value || !*value)
{
if(field)
if (field)
{
mVersion++;
if( field->value )
if (field->value)
dFree(field->value);
*walk = field->next;
@ -196,15 +196,15 @@ void SimFieldDictionary::setFieldValue(StringTableEntry slotName, const char *va
}
else
{
if(field)
if (field)
{
if( field->value )
if (field->value)
dFree(field->value);
field->value = dStrdup(value);
}
else
addEntry( bucket, slotName, 0, dStrdup( value ) );
addEntry(bucket, slotName, 0, dStrdup(value));
}
}
@ -212,8 +212,8 @@ const char *SimFieldDictionary::getFieldValue(StringTableEntry slotName)
{
U32 bucket = getHashValue(slotName);
for(Entry *walk = mHashTable[bucket];walk;walk = walk->next)
if(walk->slotName == slotName)
for (Entry *walk = mHashTable[bucket]; walk; walk = walk->next)
if (walk->slotName == slotName)
return walk->value;
return NULL;
@ -223,9 +223,9 @@ void SimFieldDictionary::assignFrom(SimFieldDictionary *dict)
{
mVersion++;
for(U32 i = 0; i < HashTableSize; i++)
for (U32 i = 0; i < HashTableSize; i++)
{
for(Entry *walk = dict->mHashTable[i];walk; walk = walk->next)
for (Entry *walk = dict->mHashTable[i]; walk; walk = walk->next)
{
setFieldValue(walk->slotName, walk->value);
setFieldType(walk->slotName, walk->type);
@ -233,7 +233,7 @@ void SimFieldDictionary::assignFrom(SimFieldDictionary *dict)
}
}
static S32 QSORT_CALLBACK compareEntries(const void* a,const void* b)
static S32 QSORT_CALLBACK compareEntries(const void* a, const void* b)
{
SimFieldDictionary::Entry *fa = *((SimFieldDictionary::Entry **)a);
SimFieldDictionary::Entry *fb = *((SimFieldDictionary::Entry **)b);
@ -245,17 +245,17 @@ void SimFieldDictionary::writeFields(SimObject *obj, Stream &stream, U32 tabStop
const AbstractClassRep::FieldList &list = obj->getFieldList();
Vector<Entry *> flist(__FILE__, __LINE__);
for(U32 i = 0; i < HashTableSize; i++)
for (U32 i = 0; i < HashTableSize; i++)
{
for(Entry *walk = mHashTable[i];walk; walk = walk->next)
for (Entry *walk = mHashTable[i]; walk; walk = walk->next)
{
// make sure we haven't written this out yet:
U32 i;
for(i = 0; i < list.size(); i++)
if(list[i].pFieldname == walk->slotName)
for (i = 0; i < list.size(); i++)
if (list[i].pFieldname == walk->slotName)
break;
if(i != list.size())
if (i != list.size())
continue;
@ -267,23 +267,23 @@ void SimFieldDictionary::writeFields(SimObject *obj, Stream &stream, U32 tabStop
}
// Sort Entries to prevent version control conflicts
dQsort(flist.address(),flist.size(),sizeof(Entry *),compareEntries);
dQsort(flist.address(), flist.size(), sizeof(Entry *), compareEntries);
// Save them out
for(Vector<Entry *>::iterator itr = flist.begin(); itr != flist.end(); itr++)
for (Vector<Entry *>::iterator itr = flist.begin(); itr != flist.end(); itr++)
{
U32 nBufferSize = (dStrlen( (*itr)->value ) * 2) + dStrlen( (*itr)->slotName ) + 16;
FrameTemp<char> expandedBuffer( nBufferSize );
U32 nBufferSize = (dStrlen((*itr)->value) * 2) + dStrlen((*itr)->slotName) + 16;
FrameTemp<char> expandedBuffer(nBufferSize);
stream.writeTabs(tabStop+1);
stream.writeTabs(tabStop + 1);
const char *typeName = (*itr)->type && (*itr)->type->getTypeID() != TypeString ? (*itr)->type->getTypeName() : "";
dSprintf(expandedBuffer, nBufferSize, "%s%s%s = \"", typeName, *typeName ? " " : "", (*itr)->slotName);
if ( (*itr)->value )
if ((*itr)->value)
expandEscape((char*)expandedBuffer + dStrlen(expandedBuffer), (*itr)->value);
dStrcat(expandedBuffer, "\";\r\n");
stream.write(dStrlen(expandedBuffer),expandedBuffer);
stream.write(dStrlen(expandedBuffer), expandedBuffer);
}
}
@ -293,32 +293,32 @@ void SimFieldDictionary::printFields(SimObject *obj)
char expandedBuffer[4096];
Vector<Entry *> flist(__FILE__, __LINE__);
for(U32 i = 0; i < HashTableSize; i++)
for (U32 i = 0; i < HashTableSize; i++)
{
for(Entry *walk = mHashTable[i];walk; walk = walk->next)
for (Entry *walk = mHashTable[i]; walk; walk = walk->next)
{
// make sure we haven't written this out yet:
U32 i;
for(i = 0; i < list.size(); i++)
if(list[i].pFieldname == walk->slotName)
for (i = 0; i < list.size(); i++)
if (list[i].pFieldname == walk->slotName)
break;
if(i != list.size())
if (i != list.size())
continue;
flist.push_back(walk);
}
}
dQsort(flist.address(),flist.size(),sizeof(Entry *),compareEntries);
dQsort(flist.address(), flist.size(), sizeof(Entry *), compareEntries);
for(Vector<Entry *>::iterator itr = flist.begin(); itr != flist.end(); itr++)
for (Vector<Entry *>::iterator itr = flist.begin(); itr != flist.end(); itr++)
{
const char* type = "string";
if( ( *itr )->type )
type = ( *itr )->type->getTypeClassName();
dSprintf( expandedBuffer, sizeof( expandedBuffer ), " %s %s = \"", type, ( *itr )->slotName );
if ( (*itr)->value )
if ((*itr)->type)
type = (*itr)->type->getTypeClassName();
dSprintf(expandedBuffer, sizeof(expandedBuffer), " %s %s = \"", type, (*itr)->slotName);
if ((*itr)->value)
expandEscape(expandedBuffer + dStrlen(expandedBuffer), (*itr)->value);
Con::printf("%s\"", expandedBuffer);
}
@ -326,9 +326,9 @@ void SimFieldDictionary::printFields(SimObject *obj)
SimFieldDictionary::Entry *SimFieldDictionary::operator[](U32 index)
{
AssertFatal ( index < mNumFields, "out of range" );
AssertFatal(index < mNumFields, "out of range");
if ( index > mNumFields )
if (index > mNumFields)
return NULL;
SimFieldDictionaryIterator itr(this);
@ -350,13 +350,13 @@ SimFieldDictionaryIterator::SimFieldDictionaryIterator(SimFieldDictionary * dict
SimFieldDictionary::Entry* SimFieldDictionaryIterator::operator++()
{
if(!mDictionary)
if (!mDictionary)
return(mEntry);
if(mEntry)
if (mEntry)
mEntry = mEntry->next;
while(!mEntry && (mHashIndex < (SimFieldDictionary::HashTableSize-1)))
while (!mEntry && (mHashIndex < (SimFieldDictionary::HashTableSize - 1)))
mEntry = mDictionary->mHashTable[++mHashIndex];
return(mEntry);
@ -386,14 +386,14 @@ void SimFieldDictionary::setFieldValue(StringTableEntry slotName, const char *va
U32 bucket = getHashValue(slotName);
Entry **walk = &mHashTable[bucket];
while(*walk && (*walk)->slotName != slotName)
while (*walk && (*walk)->slotName != slotName)
walk = &((*walk)->next);
Entry *field = *walk;
if (field)
return;
addEntry( bucket, slotName, type, dStrdup( value ) );
addEntry(bucket, slotName, type, dStrdup(value));
}
// A variation of the stock SimFieldDictionary::assignFrom(), this method adds <no_replace>
// and <filter> arguments. When true, <no_replace> prohibits the replacement of fields that already
@ -412,15 +412,15 @@ void SimFieldDictionary::assignFrom(SimFieldDictionary *dict, const char* filter
if (filter_len == 0)
{
for(U32 i = 0; i < HashTableSize; i++)
for(Entry *walk = dict->mHashTable[i];walk; walk = walk->next)
for (U32 i = 0; i < HashTableSize; i++)
for (Entry *walk = dict->mHashTable[i]; walk; walk = walk->next)
setFieldValue(walk->slotName, walk->value, walk->type, no_replace);
}
else
{
for(U32 i = 0; i < HashTableSize; i++)
for(Entry *walk = dict->mHashTable[i];walk; walk = walk->next)
for (U32 i = 0; i < HashTableSize; i++)
for (Entry *walk = dict->mHashTable[i]; walk; walk = walk->next)
if (dStrncmp(walk->slotName, filter, filter_len) == 0)
setFieldValue(walk->slotName, walk->value, walk->type, no_replace);
}
}
}

View file

@ -47,7 +47,7 @@ class SimFieldDictionary
public:
struct Entry
{
Entry() : type( NULL ) {};
Entry() : type(NULL) {};
StringTableEntry slotName;
char *value;
@ -64,10 +64,10 @@ private:
static Entry *smFreeList;
void freeEntry(Entry *entry);
Entry* addEntry( U32 bucket, StringTableEntry slotName, ConsoleBaseType* type, char* value = 0 );
Entry* addEntry(U32 bucket, StringTableEntry slotName, ConsoleBaseType* type, char* value = 0);
static U32 getHashValue( StringTableEntry slotName );
static U32 getHashValue( const String& fieldName );
static U32 getHashValue(StringTableEntry slotName);
static U32 getHashValue(const String& fieldName);
U32 mNumFields;
@ -88,7 +88,7 @@ public:
const char *getFieldValue(StringTableEntry slotName);
U32 getFieldType(StringTableEntry slotName) const;
Entry *findDynamicField(const String &fieldName) const;
Entry *findDynamicField( StringTableEntry fieldName) const;
Entry *findDynamicField(StringTableEntry fieldName) const;
void writeFields(SimObject *obj, Stream &strem, U32 tabStop);
void printFields(SimObject *obj);
void assignFrom(SimFieldDictionary *dict);
@ -112,4 +112,4 @@ public:
};
#endif // _SIMFIELDDICTIONARY_H_
#endif // _SIMFIELDDICTIONARY_H_

View file

@ -72,8 +72,8 @@ SimObject::SimObject()
objectName = NULL;
mOriginalName = NULL;
mInternalName = NULL;
nextNameObject = (SimObject*)-1;
nextManagerNameObject = (SimObject*)-1;
nextNameObject = nullptr;
nextManagerNameObject = nullptr;
nextIdObject = NULL;
mFilename = NULL;
@ -86,6 +86,8 @@ SimObject::SimObject()
mNotifyList = NULL;
mFlags.set( ModStaticFields | ModDynamicFields );
mProgenitorFile = StringTable->EmptyString();
mFieldDictionary = NULL;
mCanSaveFieldDictionary = true;
@ -122,10 +124,10 @@ SimObject::~SimObject()
if( mCopySource )
mCopySource->unregisterReference( &mCopySource );
AssertFatal(nextNameObject == (SimObject*)-1,avar(
AssertFatal(nextNameObject == nullptr,avar(
"SimObject::~SimObject: Not removed from dictionary: name %s, id %i",
objectName, mId));
AssertFatal(nextManagerNameObject == (SimObject*)-1,avar(
AssertFatal(nextManagerNameObject == nullptr,avar(
"SimObject::~SimObject: Not removed from manager dictionary: name %s, id %i",
objectName,mId));
AssertFatal(mFlags.test(Added) == 0, "SimObject::object "

File diff suppressed because it is too large Load diff