evalState.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef _EVALSTATE_H
  2. #define _EVALSTATE_H
  3. #include "console/consoleInternal.h"
  4. class ExprEvalState
  5. {
  6. public:
  7. /// @name Expression Evaluation
  8. /// @{
  9. ///
  10. Dictionary::Entry *currentVariable;
  11. Dictionary::Entry *copyVariable;
  12. U32 mStackDepth;
  13. bool mShouldReset; ///< Designates if the value stack should be reset
  14. bool mResetLocked; ///< mShouldReset will be set at the end
  15. ExprEvalState();
  16. ~ExprEvalState();
  17. /// @}
  18. /// @name Stack Management
  19. /// @{
  20. /// The stack of callframes. The extra redirection is necessary since Dictionary holds
  21. /// an interior pointer that will become invalid when the object changes address.
  22. Vector< Dictionary* > stack;
  23. S32 getTopOfStack() { return (S32)mStackDepth; }
  24. Vector< ConsoleValueFrame > localStack;
  25. ConsoleValueFrame* currentRegisterArray; // contains array at to top of localStack
  26. ///
  27. void setCurVarName(StringTableEntry name);
  28. void setCurVarNameCreate(StringTableEntry name);
  29. S32 getIntVariable();
  30. F64 getFloatVariable();
  31. const char *getStringVariable();
  32. void setIntVariable(S32 val);
  33. void setFloatVariable(F64 val);
  34. void setStringVariable(const char *str);
  35. TORQUE_FORCEINLINE S32 getLocalIntVariable(S32 reg)
  36. {
  37. return currentRegisterArray->values[reg].getInt();
  38. }
  39. TORQUE_FORCEINLINE F64 getLocalFloatVariable(S32 reg)
  40. {
  41. return currentRegisterArray->values[reg].getFloat();
  42. }
  43. TORQUE_FORCEINLINE const char* getLocalStringVariable(S32 reg)
  44. {
  45. return currentRegisterArray->values[reg].getString();
  46. }
  47. TORQUE_FORCEINLINE void setLocalIntVariable(S32 reg, S64 val)
  48. {
  49. currentRegisterArray->values[reg].setInt(val);
  50. }
  51. TORQUE_FORCEINLINE void setLocalFloatVariable(S32 reg, F64 val)
  52. {
  53. currentRegisterArray->values[reg].setFloat(val);
  54. }
  55. TORQUE_FORCEINLINE void setLocalStringVariable(S32 reg, const char* val, S32 len)
  56. {
  57. currentRegisterArray->values[reg].setString(val, len);
  58. }
  59. TORQUE_FORCEINLINE void setLocalStringTableEntryVariable(S32 reg, StringTableEntry val)
  60. {
  61. currentRegisterArray->values[reg].setStringTableEntry(val);
  62. }
  63. TORQUE_FORCEINLINE void moveConsoleValue(S32 reg, ConsoleValue val)
  64. {
  65. currentRegisterArray->values[reg] = (val);
  66. }
  67. void pushFrame(StringTableEntry frameName, Namespace *ns, S32 regCount);
  68. void popFrame();
  69. /// Puts a reference to an existing stack frame
  70. /// on the top of the stack.
  71. void pushFrameRef(S32 stackIndex);
  72. void pushDebugFrame(S32 stackIndex);
  73. U32 getStackDepth() const
  74. {
  75. return mStackDepth;
  76. }
  77. Dictionary& getCurrentFrame()
  78. {
  79. return *(stack[mStackDepth - 1]);
  80. }
  81. Dictionary& getFrameAt(S32 depth)
  82. {
  83. return *(stack[depth]);
  84. }
  85. /// @}
  86. /// Run integrity checks for debugging.
  87. void validate();
  88. };
  89. #endif