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.

613 lines
17 KiB

  1. /*****************************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1987-1999 **/
  4. /*****************************************************************************/
  5. /*****************************************************************************
  6. File : gramutil.hxx
  7. Title : grammar utility module
  8. Description : contains definitions associated with the grammar and
  9. : associated routines
  10. History :
  11. 05-Sep-1990 VibhasC Created
  12. 11-Sep-1990 VibhasC Merged gramdefs.hxx into this one for easy
  13. maintainability
  14. 20-Sep-1990 NateO Safeguards against double inclusion, added
  15. include of rpctypes, common
  16. *****************************************************************************/
  17. #ifndef __GRAMUTIL_HXX__
  18. #define __GRAMUTIL_HXX__
  19. #include "allnodes.hxx"
  20. #include "symtable.hxx"
  21. #include "idict.hxx"
  22. extern "C" {
  23. #include "lex.h"
  24. }
  25. /***************************************************************************
  26. * prototypes of all grammar related utility routines
  27. ***************************************************************************/
  28. void BaseTypeSpecAnalysis( struct _type_ana *, short );
  29. void SignSpecAnalysis( struct _type_ana *, short );
  30. void SizeSpecAnalysis( struct _type_ana *, short );
  31. void ParseError( STATUS_T , char *);
  32. STATUS_T GetBaseTypeNode( node_skl **, short, short, short, short typeAttrib = 0);
  33. STATUS_T GetBaseTypeNode( node_skl **, struct _type_ana );
  34. /***************************************************************************
  35. * general definitions
  36. ***************************************************************************/
  37. //
  38. // definitions for type specification and analysis
  39. //
  40. // basic types
  41. #define TYPE_UNDEF (0)
  42. #define TYPE_INT (1)
  43. #define TYPE_FLOAT (2)
  44. #define TYPE_DOUBLE (3)
  45. #define TYPE_VOID (4)
  46. #define TYPE_BOOLEAN (5)
  47. #define TYPE_BYTE (6)
  48. #define TYPE_HANDLE_T (7)
  49. #define TYPE_PIPE (8)
  50. #define TYPE_FLOAT80 (9)
  51. #define TYPE_FLOAT128 (10)
  52. // sizes of basic types
  53. #define SIZE_UNDEF (0)
  54. #define SIZE_CHAR (1)
  55. #define SIZE_SHORT (2)
  56. #define SIZE_LONG (3)
  57. #define SIZE_HYPER (4)
  58. #define SIZE_SMALL (5)
  59. #define SIZE_LONGLONG (6)
  60. #define SIZE_INT64 (7)
  61. #define SIZE_INT32 (8)
  62. #define SIZE_INT3264 (9)
  63. #define SIZE_INT128 (10)
  64. // signs
  65. #define SIGN_UNDEF (0)
  66. #define SIGN_SIGNED (1)
  67. #define SIGN_UNSIGNED (2)
  68. // attribs
  69. #define ATT_NONE (0)
  70. #define ATT_W64 (1)
  71. #define SET_ATTRIB(x,att) (x = x | att)
  72. #define SET_TYPE(x,type) (x = x | (type << 4 ))
  73. #define SET_SIZE(x,size) (x = x | (size << 8))
  74. #define SET_SIGN(x,sign) (x = x | (sign << 12))
  75. #define GET_ATTRIB(x) (x & 0x000f)
  76. #define GET_TYPE(x) ((x & 0x00f0) >> 4)
  77. #define GET_SIZE(x) ((x & 0x0f00) >> 8)
  78. #define GET_SIGN(x) ((x & 0xf000) >> 12)
  79. #define MAKE_TYPE_SPEC(sign,size,type, attrib) ((sign << 12) | (size << 8) | (type << 4) | attrib)
  80. //
  81. // array bounds
  82. //
  83. #define DEFAULT_LOWER_BOUND (0)
  84. /*****************************************************************************
  85. * definitions local to the parser
  86. ****************************************************************************/
  87. struct _type_ana
  88. {
  89. short TypeSize; // char/short/small/hyper/long/etc
  90. short BaseType; // int/float/double/void/bool/handle_t ect
  91. short TypeSign; // signed/unsigned
  92. short TypeAttrib; // vanilla/__w64
  93. };
  94. class _DECLARATOR
  95. {
  96. public:
  97. class node_skl * pHighest;
  98. class node_skl * pLowest;
  99. void Init()
  100. {
  101. pHighest = (node_skl *) NULL;
  102. pLowest = (node_skl *) NULL;
  103. };
  104. void Init( node_skl * pSoloNode )
  105. {
  106. pHighest = pSoloNode;
  107. pLowest = pSoloNode;
  108. };
  109. void Init( node_skl * pTop, node_skl * pBottom)
  110. {
  111. pHighest = pTop;
  112. pLowest = pBottom;
  113. };
  114. void ReplTop( node_skl * pTop )
  115. {
  116. pTop->SetChild( pHighest->GetChild() );
  117. pHighest = pTop;
  118. };
  119. // void MergeBelow( _DECLARATOR & dec );
  120. };
  121. // declarator lists are maintained as circular lists with a pointer to the
  122. // tail element. Also, the list pointer is a full entry, not just a pointer.
  123. class _DECLARATOR_SET;
  124. class DECLARATOR_LIST_MGR;
  125. class _DECLARATOR_SET: public _DECLARATOR
  126. {
  127. private:
  128. class _DECLARATOR_SET * pNext;
  129. friend class DECLARATOR_LIST_MGR;
  130. public:
  131. void Init()
  132. {
  133. pNext = NULL;
  134. pHighest = NULL;
  135. pLowest = NULL;
  136. };
  137. void Init( _DECLARATOR pFirst )
  138. {
  139. pHighest = pFirst.pHighest;
  140. pLowest = pFirst.pLowest;
  141. pNext = NULL;
  142. };
  143. void Add( _DECLARATOR pExtra )
  144. {
  145. // skip empty declarator
  146. if (pExtra.pHighest == NULL)
  147. return;
  148. // fill in anchor if empty
  149. if (pHighest == NULL)
  150. {
  151. Init( pExtra);
  152. return;
  153. };
  154. // create a new link node, and fill it in
  155. _DECLARATOR_SET * pNew = new _DECLARATOR_SET;
  156. pNew->pHighest = pExtra.pHighest ;
  157. pNew->pLowest = pExtra.pLowest ;
  158. if ( pNext )
  159. {
  160. // point pNext to list head (tail's tail)
  161. // point tail to new one
  162. pNew->pNext = pNext->pNext;
  163. pNext->pNext = pNew;
  164. }
  165. else
  166. {
  167. pNew->pNext = pNew;
  168. }
  169. // advance tail pointer
  170. pNext = pNew;
  171. };
  172. };
  173. class DECLARATOR_LIST_MGR
  174. {
  175. class _DECLARATOR_SET * pCur;
  176. class _DECLARATOR_SET * pAnchor;
  177. public:
  178. DECLARATOR_LIST_MGR(_DECLARATOR_SET & First)
  179. {
  180. _DECLARATOR_SET * pTail = First.pNext;
  181. pCur = NULL;
  182. pAnchor = &First;
  183. // break the circular list, so first points to head
  184. // of list, and tail points to NULL
  185. if (pTail)
  186. {
  187. First.pNext = pTail->pNext;
  188. pTail->pNext = NULL;
  189. }
  190. };
  191. // return next element
  192. _DECLARATOR * DestructiveGetNext()
  193. {
  194. _DECLARATOR_SET * pLast = pCur;
  195. // delete the element we returned last time (if
  196. // not NULL or the Anchor node)
  197. if (pCur)
  198. {
  199. pCur = pCur->pNext;
  200. if (pLast != pAnchor)
  201. {
  202. delete pLast;
  203. }
  204. }
  205. else
  206. {
  207. pCur = pAnchor;
  208. };
  209. return pCur;
  210. };
  211. BOOL NonEmpty()
  212. {
  213. return ( pAnchor->pHighest != NULL );
  214. };
  215. };
  216. class SIBLING_LIST
  217. {
  218. named_node * pTail;
  219. friend class SIBLING_ITER;
  220. public:
  221. SIBLING_LIST Init()
  222. {
  223. pTail = NULL;
  224. return *this;
  225. };
  226. SIBLING_LIST Init( node_skl * pLoneNode )
  227. {
  228. named_node * pSoloNode = (named_node *) pLoneNode;
  229. pTail = pSoloNode;
  230. if ( pSoloNode )
  231. {
  232. pSoloNode->SetSibling( pSoloNode );
  233. };
  234. return *this;
  235. };
  236. BOOL NonNull()
  237. {
  238. return pTail != NULL;
  239. };
  240. named_node * Tail()
  241. {
  242. return pTail;
  243. };
  244. SIBLING_LIST SetPeer( named_node * pNewNode )
  245. {
  246. return Add( pNewNode );
  247. };
  248. SIBLING_LIST Add( named_node * pNewNode ); // add to tail
  249. SIBLING_LIST Merge( SIBLING_LIST & NewList );
  250. named_node * Linearize();
  251. void AddAttributes( ATTRLIST & AList );
  252. operator void * ()
  253. {
  254. return pTail;
  255. };
  256. };
  257. class SIBLING_ITER
  258. {
  259. private:
  260. named_node * pHead;
  261. named_node * pCur;
  262. public:
  263. SIBLING_ITER( SIBLING_LIST & SibList )
  264. {
  265. pCur = NULL;
  266. pHead = (SibList.pTail == NULL) ?
  267. NULL :
  268. (named_node *) SibList.pTail->GetSibling();
  269. };
  270. named_node * Next()
  271. {
  272. if (pCur == NULL)
  273. {
  274. pCur = pHead;
  275. }
  276. else
  277. {
  278. pCur = (named_node *) pCur->GetSibling();
  279. pCur = (pCur == pHead) ? NULL : pCur;
  280. }
  281. return pCur;
  282. };
  283. };
  284. class _decl_spec
  285. {
  286. public:
  287. node_skl * pNode;
  288. MODIFIER_SET modifiers;
  289. void Init( node_skl * pOnly )
  290. {
  291. pNode = pOnly;
  292. };
  293. void Init( node_skl *pOnly, const MODIFIER_SET & mod )
  294. {
  295. pNode = pOnly;
  296. modifiers = mod;
  297. }
  298. };
  299. struct _interface_header
  300. {
  301. node_interface * pInterface; // interface node
  302. };
  303. struct _numeric
  304. {
  305. union
  306. {
  307. double dVal; // value
  308. float fVal; // value
  309. long Val; // value
  310. };
  311. char *pValStr; // value string as user specified
  312. };
  313. struct _array_bounds
  314. {
  315. class expr_node * LowerBound; // lower array bound
  316. class expr_node * UpperBound; // upper bound
  317. };
  318. struct _int_body
  319. {
  320. SIBLING_LIST Imports; // import nodes
  321. SIBLING_LIST Members; // type graph node below interface node
  322. };
  323. struct _library_header
  324. {
  325. node_library * pLibrary;
  326. };
  327. struct _disp_header
  328. {
  329. node_dispinterface * pDispInterface;
  330. };
  331. struct _coclass_header
  332. {
  333. node_coclass * pCoclass;
  334. };
  335. struct _module_header
  336. {
  337. node_module * pModule;
  338. };
  339. struct _enlab
  340. {
  341. class expr_node * pExpr;
  342. class node_label * pLabel;
  343. unsigned short fSparse;
  344. };
  345. struct _enlist
  346. {
  347. class SIBLING_LIST NodeList;
  348. class node_label * pPrevLabel;
  349. unsigned short fSparse;
  350. };
  351. struct _en_switch
  352. {
  353. class node_skl * pNode;
  354. class node_switch_is * pSwitch;
  355. char * pName;
  356. };
  357. struct _nu_caselabel
  358. {
  359. class expr_node * pExpr;
  360. node_base_attr * pDefault;
  361. };
  362. struct _nu_cllist
  363. {
  364. class expr_list * pExprList;
  365. class node_base_attr * pDefault;
  366. short DefCount;
  367. };
  368. struct _nu_cases
  369. {
  370. SIBLING_LIST CaseList;
  371. short DefCount;
  372. };
  373. union s_lextype {
  374. short yy_short;
  375. USHORT yy_ushort;
  376. int yy_int;
  377. long yy_long;
  378. MODIFIER_SET yy_modifiers;
  379. enum _operators yy_operator;
  380. char * yy_pSymName;
  381. char * yy_string;
  382. _type_ana yy_type;
  383. node_skl * yy_graph;
  384. _DECLARATOR yy_declarator;
  385. _DECLARATOR_SET yy_declarator_set;
  386. _decl_spec yy_declspec;
  387. _interface_header yy_inthead;
  388. type_node_list * yy_tnlist;
  389. _array_bounds yy_abounds;
  390. _int_body yy_intbody;
  391. expr_node * yy_expr;
  392. expr_list * yy_exprlist;
  393. _numeric yy_numeric;
  394. _enlab yy_enlab;
  395. _enlist yy_enlist;
  396. expr_init_list * yy_initlist;
  397. ATTR_T yy_attrenum;
  398. class SIBLING_LIST yy_siblist;
  399. class ATTRLIST yy_attrlist;
  400. class node_base_attr * yy_attr;
  401. struct _en_switch yy_en_switch;
  402. struct _nu_caselabel yy_nucaselabel;
  403. struct _nu_cllist yy_nucllist;
  404. struct _nu_cases yy_nucases;
  405. _library_header yy_libhead;
  406. _disp_header yy_disphead;
  407. _module_header yy_modulehead;
  408. _coclass_header yy_coclasshead;
  409. token_t yy_tokentype;
  410. };
  411. typedef union s_lextype lextype_t;
  412. //
  413. // the parse stack depth
  414. //
  415. #define YYMAXDEPTH 150
  416. /////////////////////////////////////////////////////////////////////////////
  417. // predefined type node data base
  418. /////////////////////////////////////////////////////////////////////////////
  419. struct _pre_type
  420. {
  421. unsigned short TypeSpec;
  422. class node_skl * pPreAlloc;
  423. };
  424. #define PRE_TYPE_DB_SIZE (36)
  425. class pre_type_db
  426. {
  427. private:
  428. struct _pre_type TypeDB[ PRE_TYPE_DB_SIZE ];
  429. public:
  430. pre_type_db( void );
  431. STATUS_T GetPreAllocType(node_skl **, unsigned short);
  432. };
  433. //
  434. // A structure which carries the interface information while the interface
  435. // is being processed. This is necessary since the interface node and the
  436. // type graph gets joined after the interface declarations are fully processed
  437. // and the interface declarations need this while it is being processed.
  438. //
  439. typedef struct _iInfo
  440. {
  441. node_interface * pInterfaceNode;
  442. short CurrentTagNumber;
  443. unsigned short IntfKey;
  444. ATTR_T InterfacePtrAttribute;
  445. BOOL fPtrDefErrorReported;
  446. BOOL fPtrWarningIssued;
  447. BOOL fLocal;
  448. } IINFO ;
  449. class IINFODICT : public ISTACK
  450. {
  451. private:
  452. BOOL fBaseLocal;
  453. ATTR_T BaseInterfacePtrAttribute;
  454. node_interface * pBaseInterfaceNode;
  455. public:
  456. IINFODICT() : ISTACK( 5 )
  457. {
  458. BaseInterfacePtrAttribute = ATTR_NONE;
  459. }
  460. BOOL IsPtrWarningIssued();
  461. void SetPtrWarningIssued();
  462. void StartNewInterface();
  463. void EndNewInterface();
  464. void SetInterfacePtrAttribute( ATTR_T A );
  465. ATTR_T GetInterfacePtrAttribute();
  466. ATTR_T GetBaseInterfacePtrAttribute();
  467. void SetInterfaceLocal();
  468. BOOL IsInterfaceLocal();
  469. void SetInterfaceNode( node_interface *p );
  470. node_interface * GetInterfaceNode();
  471. SymTable * GetInterfaceProcTable()
  472. {
  473. return GetInterfaceNode()->GetProcTbl();
  474. }
  475. char * GetInterfaceName()
  476. {
  477. return GetInterfaceNode()->GetSymName();
  478. }
  479. short GetCurrentTagNumber();
  480. void IncrementCurrentTagNumber();
  481. void SetPtrDefErrorReported();
  482. BOOL IsPtrDefErrorReported();
  483. };
  484. class nsa : public gplistmgr
  485. {
  486. short CurrentLevel;
  487. public:
  488. nsa(void);
  489. ~nsa(void) { };
  490. STATUS_T PushSymLevel( class SymTable ** );
  491. STATUS_T PopSymLevel( class SymTable ** );
  492. short GetCurrentLevel( void );
  493. class SymTable * GetCurrentSymbolTable( void );
  494. };
  495. #endif