Source code of Windows XP (NT5)
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.

825 lines
18 KiB

  1. /*****************************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1987-1999 **/
  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 ) : node_base_attr( pOld->GetAttrID() )
  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. };
  67. /****************************************************************************
  68. size - related attributes
  69. ****************************************************************************/
  70. class expr_node;
  71. class size_attr : public nbattr
  72. {
  73. private:
  74. class expr_node * pExpr;
  75. public:
  76. size_attr( expr_node * pE, ATTR_T A)
  77. : nbattr( A )
  78. {
  79. pExpr = pE;
  80. }
  81. virtual
  82. class node_base_attr * Clone()
  83. {
  84. size_attr * pNew = new size_attr( NULL, GetAttrID() );
  85. *pNew = *this;
  86. if ( pExpr )
  87. {
  88. pNew->pExpr = pExpr->Clone();
  89. pExpr->CopyTo( pNew->pExpr );
  90. }
  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. node_skl * GetType()
  116. {
  117. return pType;
  118. }
  119. };
  120. class node_transmit : public ta
  121. {
  122. public:
  123. node_transmit( node_skl * pTransmitAs )
  124. : ta( pTransmitAs, ATTR_TRANSMIT )
  125. {
  126. }
  127. node_transmit( node_transmit * pOld ) : ta( pOld->GetType(), pOld->GetAttrID() )
  128. {
  129. }
  130. virtual
  131. class node_base_attr * Clone()
  132. {
  133. node_base_attr * pNew = new node_transmit( this );
  134. return pNew;
  135. }
  136. node_skl * GetTransmitAsType()
  137. {
  138. return GetType();
  139. }
  140. };
  141. /*
  142. Rkk left just in case
  143. */
  144. class node_wire_marshal : public ta
  145. {
  146. public:
  147. node_wire_marshal( node_skl * pN )
  148. : ta( pN, ATTR_WIRE_MARSHAL )
  149. {
  150. }
  151. node_wire_marshal( node_wire_marshal * pOld )
  152. : ta( pOld->GetType(), pOld->GetAttrID() )
  153. {
  154. }
  155. virtual
  156. node_base_attr * Clone()
  157. {
  158. node_base_attr * pNew = new node_wire_marshal( this );
  159. return pNew;
  160. }
  161. node_skl * GetWireMarshalType() // wire type, not local
  162. {
  163. return GetType();
  164. }
  165. };
  166. class node_switch_type : public ta
  167. {
  168. public:
  169. node_switch_type( class node_skl * pSwitchType)
  170. : ta( pSwitchType, ATTR_SWITCH_TYPE )
  171. {
  172. }
  173. node_switch_type( node_switch_type * pOld )
  174. : ta( pOld->GetType(), pOld->GetAttrID() )
  175. {
  176. }
  177. virtual
  178. class node_base_attr * Clone()
  179. {
  180. node_base_attr * pNew = new node_switch_type(this);
  181. return pNew;
  182. }
  183. node_skl * GetSwitchType()
  184. {
  185. return GetType();
  186. }
  187. };
  188. /****************************************************************************
  189. other miscellaneous attributes
  190. ****************************************************************************/
  191. class ma : public nbattr
  192. {
  193. public:
  194. ma( ATTR_T At ) : nbattr( At )
  195. {
  196. }
  197. };
  198. typedef struct _INTERNAL_UUID
  199. {
  200. unsigned long Data1;
  201. unsigned short Data2;
  202. unsigned short Data3;
  203. unsigned char Data4[8];
  204. } INTERNAL_UUID;
  205. class GUID_STRS
  206. {
  207. public:
  208. INTERNAL_UUID Value;
  209. char * str1,
  210. * str2,
  211. * str3,
  212. * str4,
  213. * str5;
  214. GUID_STRS()
  215. {
  216. }
  217. GUID_STRS( char *p1, char *p2, char *p3, char *p4, char *p5 )
  218. {
  219. str1 = p1;
  220. str2 = p2;
  221. str3 = p3;
  222. str4 = p4;
  223. str5 = p5;
  224. SetValue();
  225. }
  226. void SetStrs( char *p1, char *p2, char *p3, char *p4, char *p5 )
  227. {
  228. str1 = p1;
  229. str2 = p2;
  230. str3 = p3;
  231. str4 = p4;
  232. str5 = p5;
  233. SetValue();
  234. }
  235. void GetStrs( char *&p1, char *&p2, char *&p3, char *&p4, char *&p5 )
  236. {
  237. p1 = str1;
  238. p2 = str2;
  239. p3 = str3;
  240. p4 = str4;
  241. p5 = str5;
  242. }
  243. void SetValue();
  244. };
  245. struct _GUID;
  246. class node_guid : public ma
  247. {
  248. private:
  249. char * guidstr;
  250. GUID_STRS cStrs;
  251. public:
  252. node_guid( char*, char*, char*, char*, char*, ATTR_T At = ATTR_GUID );
  253. node_guid( char*, ATTR_T At = ATTR_GUID );
  254. node_guid(node_guid * pOld) : ma( pOld->GetAttrID() )
  255. {
  256. *this = *pOld;
  257. }
  258. virtual
  259. class node_base_attr * Clone()
  260. {
  261. node_base_attr * pNew = new node_guid(this);
  262. return pNew;
  263. }
  264. char * GetGuidString()
  265. {
  266. return guidstr;
  267. }
  268. void CheckAndSetGuid( char *,char *,char *,char *, char * );
  269. void GetStrs( char **, char **, char **, char **, char ** );
  270. void GetGuid(_GUID &);
  271. GUID_STRS & GetStrs()
  272. {
  273. return cStrs;
  274. }
  275. };
  276. class node_version : public nbattr
  277. {
  278. private:
  279. unsigned long major;
  280. unsigned long minor;
  281. public:
  282. node_version( unsigned long, unsigned long );
  283. node_version( char *p );
  284. node_version(node_version * pOld) : nbattr( pOld->GetAttrID() )
  285. {
  286. *this = *pOld;
  287. }
  288. virtual
  289. class node_base_attr * Clone()
  290. {
  291. node_base_attr * pNew = new node_version(this);
  292. return pNew;
  293. }
  294. STATUS_T GetVersion( unsigned short *, unsigned short * );
  295. // we want to delete these two
  296. STATUS_T GetVersion( short *, short * );
  297. STATUS_T GetVersion( int *pma, int *pmi )
  298. {
  299. *pma = (int) major;
  300. *pmi = (int) minor;
  301. return STATUS_OK;
  302. }
  303. };
  304. /////////////////////////////////////////////////////////////////////////////
  305. // inherited pointer type.
  306. /////////////////////////////////////////////////////////////////////////////
  307. typedef unsigned short PTRTYPE;
  308. //
  309. // Initialized value (pointer type not yet determined).
  310. //
  311. #define PTR_UNKNOWN 0x0
  312. // [REF] pointer.
  313. #define PTR_REF 0x1
  314. // [UNIQUE] pointer
  315. #define PTR_UNIQUE 0x2
  316. // [FULL] pointer
  317. #define PTR_FULL 0x3
  318. class node_ptr_attr : public nbattr
  319. {
  320. private:
  321. PTRTYPE Kind;
  322. public:
  323. node_ptr_attr( PTRTYPE K )
  324. : nbattr( ATTR_PTR_KIND )
  325. {
  326. Kind = K;
  327. }
  328. node_ptr_attr(node_ptr_attr * pOld) : nbattr( pOld->GetAttrID() )
  329. {
  330. *this = *pOld;
  331. }
  332. virtual
  333. class node_base_attr * Clone()
  334. {
  335. node_base_attr * pNew = new node_ptr_attr(this);
  336. return pNew;
  337. }
  338. PTRTYPE GetPtrKind()
  339. {
  340. return Kind;
  341. }
  342. };
  343. typedef struct _endptpair
  344. {
  345. char * pString1;
  346. char * pString2;
  347. } ENDPT_PAIR;
  348. class node_endpoint : public nbattr
  349. {
  350. private:
  351. gplistmgr EndPointStringList;
  352. public:
  353. node_endpoint( char * );
  354. node_endpoint(node_endpoint * pOld) : nbattr( pOld->GetAttrID() )
  355. {
  356. *this = *pOld;
  357. }
  358. virtual
  359. class node_base_attr * Clone()
  360. {
  361. node_base_attr * pNew = new node_endpoint(this);
  362. return pNew;
  363. }
  364. void SetEndPointString( char *p );
  365. // don't destroy the iterator returned here; just use it in place
  366. // it is an iterator of ENDPT_PAIR nodes defined above.
  367. ITERATOR & GetEndPointPairs();
  368. };
  369. class node_switch_is : public nbattr
  370. {
  371. private:
  372. class expr_node * pExpr;
  373. public:
  374. node_switch_is( class expr_node * pE )
  375. : nbattr( ATTR_SWITCH_IS )
  376. {
  377. pExpr = pE;
  378. }
  379. node_switch_is(node_switch_is * pOld) : nbattr( pOld->GetAttrID() )
  380. {
  381. *this = *pOld;
  382. }
  383. virtual
  384. class node_base_attr * Clone()
  385. {
  386. node_base_attr * pNew = new node_switch_is(this);
  387. ((node_switch_is*)pNew)->pExpr = pExpr->Clone();
  388. pExpr->CopyTo( ((node_switch_is*)pNew)->pExpr );
  389. return pNew;
  390. }
  391. node_skl * GetSwitchIsType()
  392. {
  393. return pExpr->GetType();
  394. }
  395. expr_node * GetExpr()
  396. {
  397. return pExpr;
  398. }
  399. };
  400. class node_case : public nbattr
  401. {
  402. private:
  403. class expr_list * pExprList;
  404. public:
  405. node_case( expr_list * pL )
  406. : nbattr( ATTR_CASE )
  407. {
  408. pExprList = pL;
  409. }
  410. node_case(node_case * pOld) : nbattr( pOld->GetAttrID() )
  411. {
  412. *this = *pOld;
  413. }
  414. virtual
  415. class node_base_attr * Clone()
  416. {
  417. node_base_attr * pNew = new node_case(this);
  418. return pNew;
  419. }
  420. class expr_list * GetExprList()
  421. {
  422. return pExprList;
  423. }
  424. };
  425. //+---------------------------------------------------------------------------
  426. //
  427. // Class: node_constant_attr
  428. //
  429. // Purpose: Used by attributes that are associated with constant data
  430. // such as: id(x), helpcontext(x), lcid(x), fdescattr etc.
  431. //
  432. //----------------------------------------------------------------------------
  433. class node_constant_attr : public nbattr
  434. {
  435. private:
  436. class expr_node * _pExprNode;
  437. public:
  438. node_constant_attr(expr_node * pN, ATTR_T attr)
  439. : nbattr(attr)
  440. {
  441. if (pN->AlwaysGetType()->NodeKind() == NODE_POINTER && attr != ATTR_DEFAULTVALUE )
  442. ParseError( ILLEGAL_EXPRESSION_TYPE, (char *)0 );
  443. _pExprNode = pN;
  444. }
  445. node_constant_attr(node_constant_attr * pOld) : nbattr( pOld->GetAttrID() )
  446. {
  447. *this = *pOld;
  448. }
  449. virtual class node_base_attr * Clone()
  450. {
  451. node_base_attr * pNew = new node_constant_attr(this);
  452. return pNew;
  453. }
  454. class expr_node * GetExpr(void)
  455. {
  456. return _pExprNode;
  457. }
  458. };
  459. //+---------------------------------------------------------------------------
  460. //
  461. // Function: TranslateEscapeSequences
  462. //
  463. // Purpose: Replaces a string's escape sequences with the appropriate
  464. // ASCII characters.
  465. //
  466. // NOTE: this can be done in place because the resulting string
  467. // length will always be shorter than or equal to the input string
  468. // length.
  469. //
  470. //----------------------------------------------------------------------------
  471. void TranslateEscapeSequences(char * sz);
  472. //+---------------------------------------------------------------------------
  473. //
  474. // Class: node_text_attr
  475. //
  476. // Purpose: Used by attributes that are associated with string data
  477. // such as: helpstring("foo"), helpfile("foo"), dllname("foo"), etc.
  478. //
  479. //----------------------------------------------------------------------------
  480. class node_text_attr : public nbattr
  481. {
  482. private:
  483. char * _szText;
  484. public:
  485. node_text_attr(char * szText, ATTR_T attr)
  486. : nbattr(attr)
  487. {
  488. _szText = szText;
  489. }
  490. node_text_attr(node_text_attr * pOld) : nbattr( pOld->GetAttrID() )
  491. {
  492. *this = *pOld;
  493. }
  494. virtual class node_base_attr * Clone()
  495. {
  496. node_base_attr * pNew = new node_text_attr(this);
  497. return pNew;
  498. }
  499. char * GetText(void)
  500. {
  501. return _szText;
  502. }
  503. };
  504. //+---------------------------------------------------------------------------
  505. //
  506. // Class: node_custom_attr
  507. //
  508. // Purpose: extensible custom attribute support for new ODL syntax
  509. //
  510. //----------------------------------------------------------------------------
  511. class node_custom_attr : public nbattr
  512. {
  513. private:
  514. node_guid * pGuid;
  515. expr_node * pExpr;
  516. public:
  517. node_custom_attr( node_guid * pg, expr_node * px)
  518. : nbattr(ATTR_CUSTOM)
  519. {
  520. pGuid = pg;
  521. pExpr = px;
  522. }
  523. node_guid * GetGuid(void)
  524. {
  525. return pGuid;
  526. }
  527. expr_node * GetVal(void)
  528. {
  529. return pExpr;
  530. }
  531. };
  532. //+---------------------------------------------------------------------------
  533. //
  534. // Class: node_entry_attr
  535. //
  536. // Purpose: Used by the entry attribute who's parameter is either an
  537. // index or a named library entry point.
  538. //
  539. //----------------------------------------------------------------------------
  540. class node_entry_attr : public nbattr
  541. {
  542. private:
  543. char * _szVal;
  544. LONG_PTR _lVal;
  545. BOOL _fNumeric;
  546. public:
  547. node_entry_attr(LONG_PTR lVal)
  548. : nbattr(ATTR_ENTRY)
  549. {
  550. _lVal = lVal;
  551. _fNumeric = TRUE;
  552. }
  553. node_entry_attr(char * sz)
  554. : nbattr(ATTR_ENTRY)
  555. {
  556. _szVal = sz;
  557. _fNumeric = FALSE;
  558. }
  559. node_entry_attr(node_entry_attr * pOld) : nbattr( pOld->GetAttrID() )
  560. {
  561. *this = *pOld;
  562. }
  563. virtual class node_base_attr * Clone()
  564. {
  565. node_base_attr * pNew = new node_entry_attr(this);
  566. return pNew;
  567. }
  568. BOOL IsNumeric(void)
  569. {
  570. return _fNumeric;
  571. }
  572. char * GetSz(void)
  573. {
  574. return _szVal;
  575. }
  576. LONG_PTR GetID(void)
  577. {
  578. return _lVal;
  579. }
  580. };
  581. //+---------------------------------------------------------------------------
  582. //
  583. // Class: node_type_attr
  584. //
  585. // Purpose: Used whenever an ODL bit attribute is seen that only may be
  586. // applied to TYPEATTRs.
  587. //
  588. //----------------------------------------------------------------------------
  589. class node_type_attr : public nbattr
  590. {
  591. private:
  592. TATTR_T _attr;
  593. public:
  594. node_type_attr(TATTR_T attr)
  595. : nbattr(ATTR_TYPE)
  596. {
  597. _attr = attr;
  598. }
  599. node_type_attr(node_type_attr * pOld) : nbattr( pOld->GetAttrID() )
  600. {
  601. *this = *pOld;
  602. }
  603. virtual class node_base_attr * Clone()
  604. {
  605. node_base_attr * pNew = new node_type_attr(this);
  606. return pNew;
  607. }
  608. TATTR_T GetAttr(void)
  609. {
  610. return _attr;
  611. }
  612. };
  613. //+---------------------------------------------------------------------------
  614. //
  615. // Class: node_member_attr
  616. //
  617. // Purpose: Used whenever an ODL bit attribute is seen that only may be
  618. // applied to FUNCDESCs or VARDESCs.
  619. //
  620. //----------------------------------------------------------------------------
  621. class node_member_attr : public nbattr
  622. {
  623. private:
  624. MATTR_T _attr;
  625. public:
  626. node_member_attr(MATTR_T attr)
  627. : nbattr(ATTR_MEMBER)
  628. {
  629. _attr = attr;
  630. }
  631. node_member_attr(node_member_attr * pOld) : nbattr( pOld->GetAttrID() )
  632. {
  633. *this = *pOld;
  634. }
  635. virtual class node_base_attr * Clone()
  636. {
  637. node_base_attr * pNew = new node_member_attr(this);
  638. return pNew;
  639. }
  640. MATTR_T GetAttr(void)
  641. {
  642. return _attr;
  643. }
  644. };
  645. //+---------------------------------------------------------------------------
  646. //
  647. // Class: node_range_attr
  648. //
  649. // Purpose: Used by attribute range(min, max).
  650. //
  651. //----------------------------------------------------------------------------
  652. class node_range_attr : public nbattr
  653. {
  654. private:
  655. class expr_node* _pMinExpr;
  656. class expr_node* _pMaxExpr;
  657. public:
  658. node_range_attr(expr_node* pMinExpr, expr_node* pMaxExpr)
  659. : nbattr(ATTR_RANGE), _pMinExpr(pMinExpr), _pMaxExpr(pMaxExpr)
  660. {
  661. }
  662. node_range_attr(node_range_attr* pOld) : nbattr( pOld->GetAttrID() )
  663. {
  664. *this = *pOld;
  665. }
  666. virtual class node_base_attr * Clone()
  667. {
  668. return new node_range_attr(this);
  669. }
  670. class expr_node * GetMinExpr(void)
  671. {
  672. return _pMinExpr;
  673. }
  674. class expr_node * GetMaxExpr(void)
  675. {
  676. return _pMaxExpr;
  677. }
  678. };
  679. #endif // __attrnode_hxx__