Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

293 lines
6.5 KiB

  1. /**********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1987-1999 **/
  4. /**********************************************************************/
  5. /*
  6. symtable.hxx
  7. MIDL Compiler Symbol Table Definition
  8. This class centralizes access to the symbol table throughout the
  9. compiler.
  10. */
  11. /*
  12. FILE HISTORY :
  13. DonnaLi 08-24-1990 Created.
  14. */
  15. #ifndef __SYMTABLE_HXX__
  16. #define __SYMTABLE_HXX__
  17. #include "dict.hxx"
  18. enum name_t {
  19. NAME_UNDEF = 0x0000,
  20. NAME_DEF = 0x0001, // for types
  21. NAME_PROC = 0x0002, // for procedures (including temp names)
  22. NAME_LABEL = 0x0004, // for enum labels
  23. NAME_ID = 0x0008, // for any named instance of a type
  24. NAME_MEMBER = 0x0010, // for fields and parameters
  25. NAME_INTERFACE = 0x0020, // for importing and imported interfaces
  26. NAME_FILE = 0x0040, // for imported file names
  27. // all tags share the same namespace
  28. NAME_TAG = 0x0180, // for struct tags (including temp names)
  29. NAME_ENUM = 0x0280, // for enum tags (including temp names)
  30. NAME_UNION = 0x0380, // for union tags (including temp names)
  31. NAME_MASK = 0x00ff, // mask for unique part
  32. } ;
  33. typedef name_t NAME_T;
  34. /**********************************************************************\
  35. NAME: SymKey
  36. SYNOPSIS: Defines the key to the symbol table.
  37. INTERFACE:
  38. CAVEATS:
  39. NOTES: Why can't we use NAME_TAG for struct, union, and enum tags?
  40. They live in the same name space.
  41. HISTORY:
  42. Donnali 08-24-1990 Initial creation
  43. Donnali 12-04-1990 Port to Dov's generic dictionary
  44. \**********************************************************************/
  45. class SymKey
  46. {
  47. char * name; // lexeme that serves as key to the SymTable
  48. NAME_T kind; // identifies which kind of lexeme
  49. public:
  50. SymKey()
  51. {
  52. name = 0;
  53. kind = NAME_UNDEF;
  54. }
  55. SymKey(char * NewName, NAME_T NewKind)
  56. {
  57. name = NewName;
  58. kind = NewKind;
  59. }
  60. SymKey( SymKey * pNewKey )
  61. {
  62. *this = *pNewKey;
  63. }
  64. char * GetString() { return name; }
  65. void SetString(char * psz) { name = psz; }
  66. NAME_T GetKind() { return kind; }
  67. void SetKind(NAME_T k) { kind = k; }
  68. void Print(void) { printf("<%s,%d>", name, kind); }
  69. friend class SymTable;
  70. friend class CaselessDictionary;
  71. friend class CaselessList;
  72. friend class GlobalSymTable;
  73. friend class CaselessEntry;
  74. };
  75. class SymEntry;
  76. class CaselessEntry
  77. {
  78. private:
  79. SymEntry * pSymEntry;
  80. unsigned hash;
  81. public:
  82. CaselessEntry(SymEntry * pItem);
  83. int Compare(CaselessEntry * pEntry2);
  84. friend class CaselessDictionary;
  85. friend class GlobalSymTable;
  86. friend class SymTable;
  87. friend class CaselessList;
  88. friend class CaselessEntry;
  89. };
  90. class named_node;
  91. class CaselessListElement
  92. {
  93. public:
  94. CaselessListElement * pNext;
  95. CaselessEntry * pEntry;
  96. CaselessListElement(CaselessEntry * p)
  97. {
  98. pEntry = p;
  99. pNext = NULL;
  100. }
  101. };
  102. class CaselessList
  103. {
  104. private:
  105. CaselessListElement * pHead;
  106. public:
  107. CaselessList()
  108. {
  109. pHead = NULL;
  110. }
  111. ~CaselessList();
  112. CaselessEntry * Add(CaselessEntry * pEl);
  113. CaselessEntry * Find(CaselessEntry * pEntry);
  114. CaselessEntry * Delete(CaselessEntry * pEntry);
  115. CaselessEntry * DeleteExact(CaselessEntry *pEntry);
  116. };
  117. /**********************************************************************\
  118. NAME: SymTable
  119. SYNOPSIS: Defines the symbol table.
  120. INTERFACE: SymTable ()
  121. Constructor.
  122. SymInsert ()
  123. Inserts a symbol into the symbol table.
  124. SymDelete ()
  125. Deletes a symbol from the symbol table.
  126. SymSearch ()
  127. Searches the symbol table for a symbol.
  128. EnterScope ()
  129. Transition from current scope to inner scope.
  130. ExitScope ()
  131. Transition from current scope to outer scope.
  132. CAVEATS:
  133. NOTES:
  134. HISTORY:
  135. Donnali 08-24-1990 Initial creation
  136. Donnali 12-04-1990 Port to Dov's generic dictionary
  137. \**********************************************************************/
  138. class SymTable : public Dictionary
  139. {
  140. SymTable * pPrevScope; // pointer to container symbol table
  141. BOOL fHasFwds;
  142. CaselessList caseless_list;
  143. public:
  144. SymTable()
  145. {
  146. pPrevScope = (SymTable *)0;
  147. fHasFwds = FALSE;
  148. }
  149. virtual named_node * SymInsert(SymKey, SymTable *, named_node *);
  150. virtual named_node * SymDelete(SymKey);
  151. virtual named_node * SymSearch(SymKey);
  152. STATUS_T EnterScope(SymKey, SymTable **);
  153. STATUS_T ExitScope(SymTable **);
  154. void DiscardScope();
  155. void SetHasFwds()
  156. {
  157. fHasFwds = TRUE;
  158. }
  159. SSIZE_T Compare (pUserType pL, pUserType pR);
  160. virtual
  161. void Print(pUserType pItem);
  162. void * operator new ( size_t size )
  163. {
  164. return AllocateOnceNew( size );
  165. }
  166. void operator delete( void * ptr )
  167. {
  168. AllocateOnceDelete( ptr );
  169. }
  170. };
  171. class CaselessDictionary : public Dictionary
  172. {
  173. public:
  174. CaselessDictionary()
  175. {
  176. }
  177. SSIZE_T Compare (pUserType pL, pUserType pR);
  178. void * operator new ( size_t size )
  179. {
  180. return AllocateOnceNew( size );
  181. }
  182. void operator delete( void * ptr )
  183. {
  184. AllocateOnceDelete( ptr );
  185. }
  186. };
  187. class GlobalSymTable: public SymTable
  188. {
  189. private:
  190. CaselessDictionary * pCaselessDictionary;
  191. public:
  192. GlobalSymTable()
  193. {
  194. pCaselessDictionary = new CaselessDictionary;
  195. }
  196. virtual named_node * SymInsert(SymKey, SymTable *, named_node *);
  197. virtual named_node * SymDelete(SymKey);
  198. virtual named_node * SymSearch(SymKey);
  199. };
  200. class CSNODE
  201. {
  202. public:
  203. BOOL fStackValue;
  204. class CSNODE * pNext;
  205. CSNODE(BOOL f, CSNODE * p)
  206. {
  207. fStackValue = f;
  208. pNext = p;
  209. }
  210. };
  211. class CaseStack
  212. {
  213. private:
  214. CSNODE * pHead;
  215. public:
  216. CaseStack()
  217. {
  218. pHead = NULL;
  219. }
  220. void Push(BOOL fVal)
  221. {
  222. pHead = new CSNODE(fVal, pHead);
  223. }
  224. void Pop(BOOL &fVal)
  225. {
  226. if (!pHead)
  227. {
  228. // default to case sensitive mode
  229. fVal = TRUE;
  230. return;
  231. }
  232. fVal = pHead->fStackValue;
  233. CSNODE * pTemp = pHead;
  234. pHead = pTemp->pNext;
  235. delete pTemp;
  236. }
  237. };
  238. extern CaseStack gCaseStack;
  239. extern BOOL gfCaseSensitive;
  240. #endif // __SYMTABLE_HXX__