Windows NT 4.0 source code leak
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.

797 lines
17 KiB

4 years ago
  1. /*****************************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1987-1990 **/
  4. /*****************************************************************************/
  5. /*****************************************************************************
  6. File : attrnode.hxx
  7. Title : attribute node definitions
  8. History :
  9. 08-Aug-1991 VibhasC Created
  10. *****************************************************************************/
  11. #ifndef __attrnode_hxx__
  12. #define __attrnode_hxx__
  13. /**
  14. ** We classify attributes into these classes:
  15. **
  16. ** A) IDL attributes and B) ACF attributes.
  17. **
  18. ** IDL Attributes, are further divided into:
  19. **
  20. ** . bit_attributes( whose presence is indicated by a bit in the summary
  21. ** vector and which requre no further info. ( BA )
  22. ** . non-bit attributes ( whic have some info conatained in them. (NBA)
  23. **
  24. ** There is no such classification in acf attributes. All acf attributes
  25. ** have attribute class instances.
  26. **
  27. ** BAs are further divided into:
  28. **
  29. ** 1. size-based attributes (SA), size_is, length_is etc, except string
  30. ** 2. type-based attributes(TA) switch_type, transmit_as etc
  31. ** 3. acf attributes (AA)
  32. ** 4. miscellaneous attributes (MA) guid, endpoint, switch_is etc
  33. **
  34. ** The classification is loosely based on the semantic checks needed. size_is
  35. ** length_is etc have almost similar semantic checks, so we group them
  36. ** together. The miscellaneous attributes are completely unrelated to each
  37. ** other and so such we just group them into one.
  38. **/
  39. #include "expr.hxx"
  40. #include "midlnode.hxx"
  41. #include "stream.hxx"
  42. #include "nodeskl.hxx"
  43. class node_e_attr : public node_base_attr
  44. {
  45. public:
  46. node_e_attr() : node_base_attr( ATTR_NONE )
  47. {
  48. }
  49. node_e_attr( node_e_attr * pOld )
  50. {
  51. *this = *pOld;
  52. }
  53. virtual
  54. class node_base_attr * Clone()
  55. {
  56. node_base_attr * pNew = new node_e_attr(this);
  57. return pNew;
  58. }
  59. };
  60. class nbattr : public node_base_attr
  61. {
  62. public:
  63. nbattr( ATTR_T At ) : node_base_attr( At )
  64. {
  65. };
  66. nbattr()
  67. {
  68. };
  69. };
  70. /****************************************************************************
  71. size - related attributes
  72. ****************************************************************************/
  73. class expr_node;
  74. class size_attr : public nbattr
  75. {
  76. private:
  77. class expr_node * pExpr;
  78. public:
  79. size_attr( expr_node * pE, ATTR_T A)
  80. : nbattr( A )
  81. {
  82. pExpr = pE;
  83. }
  84. size_attr()
  85. {
  86. };
  87. virtual
  88. class node_base_attr * Clone()
  89. {
  90. size_attr * pNew = new size_attr;
  91. return pNew;
  92. }
  93. void SetExpr( expr_node *pE )
  94. {
  95. pExpr = pE;
  96. }
  97. expr_node * GetExpr()
  98. {
  99. return pExpr;
  100. }
  101. };
  102. /****************************************************************************
  103. type - based attributes
  104. ****************************************************************************/
  105. class ta : public nbattr
  106. {
  107. private:
  108. node_skl * pType;
  109. public:
  110. ta( node_skl *pT, ATTR_T A)
  111. : nbattr( A )
  112. {
  113. pType = pT;
  114. }
  115. ta()
  116. {
  117. }
  118. node_skl * GetType()
  119. {
  120. return pType;
  121. }
  122. };
  123. class node_transmit : public ta
  124. {
  125. public:
  126. node_transmit( node_skl * pTransmitAs )
  127. : ta( pTransmitAs, ATTR_TRANSMIT )
  128. {
  129. }
  130. node_transmit( node_transmit * pOld )
  131. {
  132. *this = *pOld;
  133. }
  134. virtual
  135. class node_base_attr * Clone()
  136. {
  137. node_base_attr * pNew = new node_transmit( this );
  138. return pNew;
  139. }
  140. node_skl * GetTransmitAsType()
  141. {
  142. return GetType();
  143. }
  144. };
  145. /*
  146. Rkk left just in case
  147. */
  148. class node_wire_marshal : public ta
  149. {
  150. public:
  151. node_wire_marshal( node_skl * pN )
  152. : ta( pN, ATTR_WIRE_MARSHAL )
  153. {
  154. }
  155. node_wire_marshal( node_wire_marshal * pOld )
  156. {
  157. *this = *pOld;
  158. }
  159. virtual
  160. node_base_attr * Clone()
  161. {
  162. node_base_attr * pNew = new node_wire_marshal( this );
  163. return pNew;
  164. }
  165. node_skl * GetWireMarshalType() // wire type, not local
  166. {
  167. return GetType();
  168. }
  169. };
  170. class node_switch_type : public ta
  171. {
  172. public:
  173. node_switch_type( class node_skl * pSwitchType)
  174. : ta( pSwitchType, ATTR_SWITCH_TYPE )
  175. {
  176. }
  177. node_switch_type( node_switch_type * pOld )
  178. {
  179. *this = *pOld;
  180. }
  181. virtual
  182. class node_base_attr * Clone()
  183. {
  184. node_base_attr * pNew = new node_switch_type(this);
  185. return pNew;
  186. }
  187. node_skl * GetSwitchType()
  188. {
  189. return GetType();
  190. }
  191. };
  192. /****************************************************************************
  193. other miscellaneous attributes
  194. ****************************************************************************/
  195. class ma : public nbattr
  196. {
  197. public:
  198. ma( ATTR_T At ) : nbattr( At )
  199. {
  200. }
  201. ma() { }
  202. };
  203. typedef struct _INTERNAL_UUID
  204. {
  205. unsigned long Data1;
  206. unsigned short Data2;
  207. unsigned short Data3;
  208. unsigned char Data4[8];
  209. } INTERNAL_UUID;
  210. class GUID_STRS
  211. {
  212. public:
  213. INTERNAL_UUID Value;
  214. char * str1,
  215. * str2,
  216. * str3,
  217. * str4,
  218. * str5;
  219. GUID_STRS()
  220. {
  221. }
  222. GUID_STRS( char *p1, char *p2, char *p3, char *p4, char *p5 )
  223. {
  224. str1 = p1;
  225. str2 = p2;
  226. str3 = p3;
  227. str4 = p4;
  228. str5 = p5;
  229. SetValue();
  230. }
  231. void SetStrs( char *p1, char *p2, char *p3, char *p4, char *p5 )
  232. {
  233. str1 = p1;
  234. str2 = p2;
  235. str3 = p3;
  236. str4 = p4;
  237. str5 = p5;
  238. SetValue();
  239. }
  240. void GetStrs( char *&p1, char *&p2, char *&p3, char *&p4, char *&p5 )
  241. {
  242. p1 = str1;
  243. p2 = str2;
  244. p3 = str3;
  245. p4 = str4;
  246. p5 = str5;
  247. }
  248. void SetValue();
  249. };
  250. struct _GUID;
  251. class node_guid : public ma
  252. {
  253. private:
  254. char * guidstr;
  255. GUID_STRS cStrs;
  256. public:
  257. node_guid( char *, char *, char *, char *, char * );
  258. node_guid( char * );
  259. node_guid(node_guid * pOld)
  260. {
  261. *this = *pOld;
  262. }
  263. virtual
  264. class node_base_attr * Clone()
  265. {
  266. node_base_attr * pNew = new node_guid(this);
  267. return pNew;
  268. }
  269. char * GetGuidString()
  270. {
  271. return guidstr;
  272. }
  273. void CheckAndSetGuid( char *,char *,char *,char *, char * );
  274. void GetStrs( char **, char **, char **, char **, char ** );
  275. void GetGuid(_GUID &);
  276. GUID_STRS & GetStrs()
  277. {
  278. return cStrs;
  279. }
  280. };
  281. class node_version : public nbattr
  282. {
  283. private:
  284. unsigned long major;
  285. unsigned long minor;
  286. public:
  287. node_version( unsigned long, unsigned long );
  288. node_version( char *p );
  289. node_version(node_version * pOld)
  290. {
  291. *this = *pOld;
  292. }
  293. virtual
  294. class node_base_attr * Clone()
  295. {
  296. node_base_attr * pNew = new node_version(this);
  297. return pNew;
  298. }
  299. STATUS_T GetVersion( unsigned short *, unsigned short * );
  300. // we want to delete these two
  301. STATUS_T GetVersion( short *, short * );
  302. STATUS_T GetVersion( int *pma, int *pmi )
  303. {
  304. *pma = (int) major;
  305. *pmi = (int) minor;
  306. return STATUS_OK;
  307. }
  308. };
  309. /////////////////////////////////////////////////////////////////////////////
  310. // inherited pointer type.
  311. /////////////////////////////////////////////////////////////////////////////
  312. typedef unsigned short PTRTYPE;
  313. //
  314. // Initialized value (pointer type not yet determined).
  315. //
  316. #define PTR_UNKNOWN 0x0
  317. // [REF] pointer.
  318. #define PTR_REF 0x1
  319. // [UNIQUE] pointer
  320. #define PTR_UNIQUE 0x2
  321. // [FULL] pointer
  322. #define PTR_FULL 0x3
  323. class node_ptr_attr : public nbattr
  324. {
  325. private:
  326. PTRTYPE Kind;
  327. public:
  328. node_ptr_attr( PTRTYPE K )
  329. : nbattr( ATTR_PTR_KIND )
  330. {
  331. Kind = K;
  332. }
  333. node_ptr_attr(node_ptr_attr * pOld)
  334. {
  335. *this = *pOld;
  336. }
  337. virtual
  338. class node_base_attr * Clone()
  339. {
  340. node_base_attr * pNew = new node_ptr_attr(this);
  341. return pNew;
  342. }
  343. PTRTYPE GetPtrKind()
  344. {
  345. return Kind;
  346. }
  347. };
  348. typedef struct _endptpair
  349. {
  350. char * pString1;
  351. char * pString2;
  352. } ENDPT_PAIR;
  353. class node_endpoint : public nbattr
  354. {
  355. private:
  356. gplistmgr EndPointStringList;
  357. public:
  358. node_endpoint( char * );
  359. node_endpoint(node_endpoint * pOld)
  360. {
  361. *this = *pOld;
  362. }
  363. virtual
  364. class node_base_attr * Clone()
  365. {
  366. node_base_attr * pNew = new node_endpoint(this);
  367. return pNew;
  368. }
  369. void SetEndPointString( char *p );
  370. // don't destroy the iterator returned here; just use it in place
  371. // it is an iterator of ENDPT_PAIR nodes defined above.
  372. ITERATOR & GetEndPointPairs();
  373. };
  374. class node_switch_is : public nbattr
  375. {
  376. private:
  377. class expr_node * pExpr;
  378. public:
  379. node_switch_is( class expr_node * pE )
  380. : nbattr( ATTR_SWITCH_IS )
  381. {
  382. pExpr = pE;
  383. }
  384. node_switch_is(node_switch_is * pOld)
  385. {
  386. *this = *pOld;
  387. }
  388. virtual
  389. class node_base_attr * Clone()
  390. {
  391. node_base_attr * pNew = new node_switch_is(this);
  392. return pNew;
  393. }
  394. node_skl * GetSwitchIsType()
  395. {
  396. return pExpr->GetType();
  397. }
  398. expr_node * GetExpr()
  399. {
  400. return pExpr;
  401. }
  402. };
  403. class node_case : public nbattr
  404. {
  405. private:
  406. class expr_list * pExprList;
  407. public:
  408. node_case( expr_list * pL )
  409. : nbattr( ATTR_CASE )
  410. {
  411. pExprList = pL;
  412. }
  413. node_case(node_case * pOld)
  414. {
  415. *this = *pOld;
  416. }
  417. virtual
  418. class node_base_attr * Clone()
  419. {
  420. node_base_attr * pNew = new node_case(this);
  421. return pNew;
  422. }
  423. class expr_list * GetExprList()
  424. {
  425. return pExprList;
  426. }
  427. };
  428. //+---------------------------------------------------------------------------
  429. //
  430. // Class: node_constant_attr
  431. //
  432. // Purpose: Used by attributes that are associated with constant data
  433. // such as: id(x), helpcontext(x), lcid(x), fdescattr etc.
  434. //
  435. //----------------------------------------------------------------------------
  436. class node_constant_attr : public nbattr
  437. {
  438. private:
  439. class expr_node * _pExprNode;
  440. public:
  441. node_constant_attr(expr_node * pN, ATTR_T attr)
  442. : nbattr(attr)
  443. {
  444. if (pN->AlwaysGetType()->NodeKind() == NODE_POINTER && attr != ATTR_DEFAULTVALUE )
  445. ParseError( ILLEGAL_EXPRESSION_TYPE, (char *)0 );
  446. _pExprNode = pN;
  447. }
  448. node_constant_attr(node_constant_attr * pOld)
  449. {
  450. *this = *pOld;
  451. }
  452. virtual class node_base_attr * Clone()
  453. {
  454. node_base_attr * pNew = new node_constant_attr(this);
  455. return pNew;
  456. }
  457. class expr_node * GetExpr(void)
  458. {
  459. return _pExprNode;
  460. }
  461. };
  462. //+---------------------------------------------------------------------------
  463. //
  464. // Function: TranslateEscapeSequences
  465. //
  466. // Purpose: Replaces a string's escape sequences with the appropriate
  467. // ASCII characters.
  468. //
  469. // NOTE: this can be done in place because the resulting string
  470. // length will always be shorter than or equal to the input string
  471. // length.
  472. //
  473. //----------------------------------------------------------------------------
  474. void TranslateEscapeSequences(char * sz);
  475. //+---------------------------------------------------------------------------
  476. //
  477. // Class: node_text_attr
  478. //
  479. // Purpose: Used by attributes that are associated with string data
  480. // such as: helpstring("foo"), helpfile("foo"), dllname("foo"), etc.
  481. //
  482. //----------------------------------------------------------------------------
  483. class node_text_attr : public nbattr
  484. {
  485. private:
  486. char * _szText;
  487. public:
  488. node_text_attr(char * szText, ATTR_T attr)
  489. : nbattr(attr)
  490. {
  491. _szText = szText;
  492. }
  493. node_text_attr(node_text_attr * pOld)
  494. {
  495. *this = *pOld;
  496. }
  497. virtual class node_base_attr * Clone()
  498. {
  499. node_base_attr * pNew = new node_text_attr(this);
  500. return pNew;
  501. }
  502. char * GetText(void)
  503. {
  504. return _szText;
  505. }
  506. };
  507. //+---------------------------------------------------------------------------
  508. //
  509. // Class: node_custom_attr
  510. //
  511. // Purpose: extensible custom attribute support for new ODL syntax
  512. //
  513. //----------------------------------------------------------------------------
  514. class node_custom_attr : public nbattr
  515. {
  516. private:
  517. node_guid * pGuid;
  518. expr_node * pExpr;
  519. public:
  520. node_custom_attr( node_guid * pg, expr_node * px)
  521. : nbattr(ATTR_CUSTOM)
  522. {
  523. pGuid = pg;
  524. pExpr = px;
  525. }
  526. node_guid * GetGuid(void)
  527. {
  528. return pGuid;
  529. }
  530. expr_node * GetVal(void)
  531. {
  532. return pExpr;
  533. }
  534. };
  535. //+---------------------------------------------------------------------------
  536. //
  537. // Class: node_entry_attr
  538. //
  539. // Purpose: Used by the entry attribute who's parameter is either an
  540. // index or a named library entry point.
  541. //
  542. //----------------------------------------------------------------------------
  543. class node_entry_attr : public nbattr
  544. {
  545. private:
  546. char * _szVal;
  547. long _lVal;
  548. BOOL _fNumeric;
  549. public:
  550. node_entry_attr(long lVal)
  551. : nbattr(ATTR_ENTRY)
  552. {
  553. _lVal = lVal;
  554. _fNumeric = TRUE;
  555. }
  556. node_entry_attr(char * sz)
  557. : nbattr(ATTR_ENTRY)
  558. {
  559. _szVal = sz;
  560. _fNumeric = FALSE;
  561. }
  562. node_entry_attr(node_entry_attr * pOld)
  563. {
  564. *this = *pOld;
  565. }
  566. virtual class node_base_attr * Clone()
  567. {
  568. node_base_attr * pNew = new node_entry_attr(this);
  569. return pNew;
  570. }
  571. BOOL IsNumeric(void)
  572. {
  573. return _fNumeric;
  574. }
  575. char * GetSz(void)
  576. {
  577. return _szVal;
  578. }
  579. long GetID(void)
  580. {
  581. return _lVal;
  582. }
  583. };
  584. //+---------------------------------------------------------------------------
  585. //
  586. // Class: node_type_attr
  587. //
  588. // Purpose: Used whenever an ODL bit attribute is seen that only may be
  589. // applied to TYPEATTRs.
  590. //
  591. //----------------------------------------------------------------------------
  592. class node_type_attr : public nbattr
  593. {
  594. private:
  595. TATTR_T _attr;
  596. public:
  597. node_type_attr(TATTR_T attr)
  598. : nbattr(ATTR_TYPE)
  599. {
  600. _attr = attr;
  601. }
  602. node_type_attr(node_type_attr * pOld)
  603. {
  604. *this = *pOld;
  605. }
  606. virtual class node_base_attr * Clone()
  607. {
  608. node_base_attr * pNew = new node_type_attr(this);
  609. return pNew;
  610. }
  611. TATTR_T GetAttr(void)
  612. {
  613. return _attr;
  614. }
  615. };
  616. //+---------------------------------------------------------------------------
  617. //
  618. // Class: node_member_attr
  619. //
  620. // Purpose: Used whenever an ODL bit attribute is seen that only may be
  621. // applied to FUNCDESCs or VARDESCs.
  622. //
  623. //----------------------------------------------------------------------------
  624. class node_member_attr : public nbattr
  625. {
  626. private:
  627. MATTR_T _attr;
  628. public:
  629. node_member_attr(MATTR_T attr)
  630. : nbattr(ATTR_MEMBER)
  631. {
  632. _attr = attr;
  633. }
  634. node_member_attr(node_member_attr * pOld)
  635. {
  636. *this = *pOld;
  637. }
  638. virtual class node_base_attr * Clone()
  639. {
  640. node_base_attr * pNew = new node_member_attr(this);
  641. return pNew;
  642. }
  643. MATTR_T GetAttr(void)
  644. {
  645. return _attr;
  646. }
  647. };
  648. #endif // __attrnode_hxx__