consoleNamespace.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _CONSOLE_NAMESPACE_H
  23. #define _CONSOLE_NAMESPACE_H
  24. #ifndef _STRINGTABLE_H_
  25. #include "string/stringTable.h"
  26. #endif
  27. #ifndef _VECTOR_H_
  28. #include "collection/vector.h"
  29. #endif
  30. #ifndef _CONSOLETYPES_H_
  31. #include "console/consoleTypes.h"
  32. #endif
  33. //-----------------------------------------------------------------------------
  34. class ExprEvalState;
  35. class CodeBlock;
  36. class AbstractClassRep;
  37. //-----------------------------------------------------------------------------
  38. class Namespace
  39. {
  40. enum {
  41. MaxActivePackages = 512,
  42. };
  43. static U32 mNumActivePackages;
  44. static U32 mOldNumActivePackages;
  45. static StringTableEntry mActivePackages[MaxActivePackages];
  46. public:
  47. StringTableEntry mName;
  48. StringTableEntry mPackage;
  49. Namespace *mParent;
  50. Namespace *mNext;
  51. AbstractClassRep *mClassRep;
  52. U32 mRefCountToParent;
  53. const char* mUsage;
  54. // Script defined usage strings need to be cleaned up. This
  55. // field indicates whether or not the usage was set from script.
  56. bool mCleanUpUsage;
  57. struct Entry
  58. {
  59. enum {
  60. GroupMarker = -3,
  61. OverloadMarker = -2,
  62. InvalidFunctionType = -1,
  63. ScriptFunctionType,
  64. StringCallbackType,
  65. IntCallbackType,
  66. FloatCallbackType,
  67. VoidCallbackType,
  68. BoolCallbackType
  69. };
  70. Namespace *mNamespace;
  71. Entry *mNext;
  72. StringTableEntry mFunctionName;
  73. S32 mType;
  74. S32 mMinArgs;
  75. S32 mMaxArgs;
  76. const char *mUsage;
  77. StringTableEntry mPackage;
  78. CodeBlock *mCode;
  79. U32 mFunctionOffset;
  80. union CallbackUnion {
  81. StringCallback mStringCallbackFunc;
  82. IntCallback mIntCallbackFunc;
  83. VoidCallback mVoidCallbackFunc;
  84. FloatCallback mFloatCallbackFunc;
  85. BoolCallback mBoolCallbackFunc;
  86. const char* mGroupName;
  87. } cb;
  88. Entry();
  89. void clear();
  90. const char *execute(S32 argc, const char **argv, ExprEvalState *state);
  91. };
  92. Entry *mEntryList;
  93. Entry **mHashTable;
  94. U32 mHashSize;
  95. U32 mHashSequence; ///< @note The hash sequence is used by the autodoc console facility
  96. /// as a means of testing reference state.
  97. Namespace();
  98. ~Namespace();
  99. void addFunction(StringTableEntry name, CodeBlock *cb, U32 functionOffset, const char* usage = NULL);
  100. void addCommand(StringTableEntry name,StringCallback, const char *usage, S32 minArgs, S32 maxArgs);
  101. void addCommand(StringTableEntry name,IntCallback, const char *usage, S32 minArgs, S32 maxArgs);
  102. void addCommand(StringTableEntry name,FloatCallback, const char *usage, S32 minArgs, S32 maxArgs);
  103. void addCommand(StringTableEntry name,VoidCallback, const char *usage, S32 minArgs, S32 maxArgs);
  104. void addCommand(StringTableEntry name,BoolCallback, const char *usage, S32 minArgs, S32 maxArgs);
  105. void addOverload(const char *name, const char* altUsage);
  106. void markGroup(const char* name, const char* usage);
  107. char * lastUsage;
  108. void getEntryList(Vector<Entry *> *);
  109. Entry *lookup(StringTableEntry name);
  110. Entry *lookupRecursive(StringTableEntry name);
  111. Entry *createLocalEntry(StringTableEntry name);
  112. void buildHashTable();
  113. void clearEntries();
  114. bool classLinkTo(Namespace *parent);
  115. bool unlinkClass(Namespace *parent);
  116. const char *tabComplete(const char *prevText, S32 baseLen, bool fForward);
  117. static U32 mCacheSequence;
  118. static DataChunker mCacheAllocator;
  119. static DataChunker mAllocator;
  120. static void trashCache();
  121. static Namespace *mNamespaceList;
  122. static Namespace *mGlobalNamespace;
  123. static void init();
  124. static void shutdown();
  125. static Namespace *global();
  126. static Namespace *find(StringTableEntry name, StringTableEntry package=NULL);
  127. static bool canTabComplete(const char *prevText, const char *bestMatch, const char *newText, S32 baseLen, bool fForward);
  128. static void activatePackage(StringTableEntry name);
  129. static void deactivatePackage(StringTableEntry name);
  130. static void dumpClasses( bool dumpScript = true, bool dumpEngine = true );
  131. static void dumpFunctions( bool dumpScript = true, bool dumpEngine = true );
  132. static void printNamespaceEntries(Namespace * g, bool dumpScript = true, bool dumpEngine = true);
  133. static void unlinkPackages();
  134. static void relinkPackages();
  135. static bool isPackage(StringTableEntry name);
  136. };
  137. #endif // _CONSOLE_NAMESPACE_H