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.

360 lines
12 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989-1999 Microsoft Corporation
  3. Module Name:
  4. fldattr.hxx
  5. Abstract:
  6. types for semantic analysis
  7. Notes:
  8. Author:
  9. GregJen Sep-24-1993 Created.
  10. Notes:
  11. ----------------------------------------------------------------------------*/
  12. #ifndef __FLDATTR_HXX__
  13. #define __FLDATTR_HXX__
  14. /****************************************************************************
  15. * include files
  16. ***************************************************************************/
  17. #include "listhndl.hxx"
  18. #include "midlnode.hxx"
  19. #include "attrlist.hxx"
  20. #include "nodeskl.hxx"
  21. #include "optprop.hxx"
  22. #include "cmdana.hxx"
  23. /****************************************************************************
  24. * local data
  25. ***************************************************************************/
  26. /****************************************************************************
  27. * externs
  28. ***************************************************************************/
  29. /****************************************************************************
  30. * definitions
  31. ***************************************************************************/
  32. class node_interface;
  33. class type_node_list;
  34. class ATTRLIST;
  35. class SEM_ANALYSIS_CTXT;
  36. //
  37. //
  38. // class FIELD_ATTR_INFO
  39. //
  40. // describes the collection of field attributes on a node
  41. //
  42. #define STR_NO_STRING 0x00
  43. #define STR_STRING 0x01
  44. #define STR_BSTRING 0x02
  45. #define FA_NONE 0x00
  46. #define FA_CONFORMANT 0x01
  47. #define FA_VARYING 0x02
  48. #define FA_CONFORMANT_VARYING (FA_CONFORMANT | FA_VARYING)
  49. #define FA_STRING 0x04
  50. #define FA_CONFORMANT_STRING (FA_STRING | FA_CONFORMANT)
  51. #define FA_INTERFACE 0x08
  52. // control flags
  53. #define FA_PTR_STYLE 0x00
  54. #define FA_ARRAY_STYLE 0x01
  55. #define FA_STYLE_MASK 0x01
  56. #define FA_CHILD_IS_ARRAY_OR_PTR 0x02
  57. class FIELD_ATTR_INFO
  58. {
  59. public:
  60. expr_node * pSizeIsExpr;
  61. expr_node * pMinIsExpr;
  62. expr_node * pMaxIsExpr;
  63. expr_node * pLengthIsExpr;
  64. expr_node * pFirstIsExpr;
  65. expr_node * pIIDIsExpr;
  66. expr_node * pLastIsExpr;
  67. unsigned char StringKind;
  68. unsigned char Kind;
  69. unsigned char Control;
  70. FIELD_ATTR_INFO()
  71. {
  72. Control = 0;
  73. pSizeIsExpr =
  74. pMinIsExpr =
  75. pMaxIsExpr =
  76. pLengthIsExpr =
  77. pIIDIsExpr =
  78. pFirstIsExpr =
  79. pLastIsExpr = NULL;
  80. StringKind = STR_NO_STRING;
  81. Kind = FA_NONE;
  82. }
  83. FIELD_ATTR_INFO( expr_node * pSizeExpr,
  84. expr_node * pMinExpr = NULL,
  85. expr_node * pMaxExpr = NULL,
  86. expr_node * pLengthExpr = NULL,
  87. expr_node * pFirstExpr = NULL,
  88. expr_node * pLastExpr = NULL,
  89. expr_node * pIIDExpr = NULL )
  90. {
  91. Control = 0;
  92. pSizeIsExpr = pSizeExpr;
  93. pMinIsExpr = pMinExpr;
  94. pMaxIsExpr = pMaxExpr;
  95. pLengthIsExpr = pLengthExpr;
  96. pIIDIsExpr = pIIDExpr;
  97. pFirstIsExpr = pFirstExpr;
  98. pLastIsExpr = pLastExpr;
  99. StringKind = STR_NO_STRING;
  100. Kind = FA_NONE;
  101. }
  102. void SetControl( BOOL PtrStyle, BOOL ChildFA )
  103. {
  104. Control = ( unsigned char ) ( (PtrStyle) ? FA_PTR_STYLE : FA_ARRAY_STYLE );
  105. Control |= (ChildFA) ? FA_CHILD_IS_ARRAY_OR_PTR : 0;
  106. }
  107. // normalize all the attributes into canonical forms for backend:
  108. // sizing -> min & size
  109. // lengthing -> first & length
  110. void Normalize();
  111. void Normalize( expr_node * pLower, expr_node * pUpper );
  112. // validate the bunch of attributes: check combinations, ranges,
  113. // and expressions
  114. void Validate( SEM_ANALYSIS_CTXT * pCtxt );
  115. void Validate( SEM_ANALYSIS_CTXT * pCtxt,
  116. expr_node * pLower,
  117. expr_node * pUpper );
  118. bool VerifyOnlySimpleExpression();
  119. //
  120. // get and set methods
  121. //
  122. void SetSizeIs( expr_node * pE )
  123. {
  124. pSizeIsExpr = pE;
  125. Kind |= FA_CONFORMANT;
  126. }
  127. void SetMinIs( expr_node * pE )
  128. {
  129. pMinIsExpr = pE;
  130. Kind |= FA_CONFORMANT;
  131. }
  132. void SetMaxIs( expr_node * pE )
  133. {
  134. pMaxIsExpr = pE;
  135. Kind |= FA_CONFORMANT;
  136. }
  137. void SetLengthIs( expr_node * pE )
  138. {
  139. pLengthIsExpr = pE;
  140. Kind |= FA_VARYING;
  141. }
  142. void SetFirstIs( expr_node * pE )
  143. {
  144. pFirstIsExpr = pE;
  145. Kind |= FA_VARYING;
  146. }
  147. void SetLastIs( expr_node * pE )
  148. {
  149. pLastIsExpr = pE;
  150. Kind |= FA_VARYING;
  151. }
  152. void SetIIDIs( expr_node * pE )
  153. {
  154. pIIDIsExpr = pE;
  155. Kind |= FA_INTERFACE;
  156. }
  157. void SetString()
  158. {
  159. StringKind = STR_STRING;
  160. Kind |= FA_STRING;
  161. }
  162. void SetBString()
  163. {
  164. StringKind = STR_BSTRING;
  165. Kind |= FA_STRING;
  166. }
  167. BOOL SetExpressionVariableUsage( SIZE_LENGTH_USAGE usage );
  168. BOOL SetExpressionVariableUsage(
  169. expr_node *pExpr,
  170. SIZE_LENGTH_USAGE usage );
  171. };
  172. class CG_NDR;
  173. class XLAT_SIZE_INFO
  174. {
  175. private:
  176. unsigned short MemAlign;
  177. unsigned short WireAlign;
  178. unsigned long MemSize;
  179. unsigned long WireSize;
  180. unsigned long MemOffset;
  181. unsigned long WireOffset;
  182. unsigned short ZeePee;
  183. BOOL MustAlign;
  184. public:
  185. XLAT_SIZE_INFO()
  186. {
  187. MemAlign = 1;
  188. MemSize = 0;
  189. MemOffset = 0;
  190. WireAlign = 1;
  191. WireSize = 0;
  192. WireOffset = 0;
  193. ZeePee = pCommand->GetZeePee();
  194. MustAlign = false;
  195. }
  196. XLAT_SIZE_INFO( unsigned short MA,
  197. unsigned short WA,
  198. unsigned long MS = 0,
  199. unsigned long WS = 0,
  200. unsigned short ZP = 8,
  201. unsigned long MO = 0,
  202. unsigned long WO = 0
  203. )
  204. {
  205. ZeePee = pCommand->GetZeePee();
  206. MemAlign = MA;
  207. WireAlign = WA;
  208. MemSize = MS;
  209. WireSize = WS;
  210. MemOffset = 0;
  211. WireOffset = 0;
  212. MustAlign = false;
  213. // get rid of unreferenced formal parameter warning
  214. WO, MO, ZP;
  215. }
  216. XLAT_SIZE_INFO( XLAT_SIZE_INFO * pCtxt )
  217. {
  218. MemAlign = 1;
  219. MemSize = 0;
  220. MemOffset = 0;
  221. WireAlign = 1;
  222. WireSize = 0;
  223. WireOffset = 0;
  224. ZeePee = pCtxt->ZeePee;
  225. MustAlign = false;
  226. }
  227. XLAT_SIZE_INFO( CG_NDR * pCG );
  228. unsigned short & GetMemAlign()
  229. {
  230. return MemAlign;
  231. }
  232. unsigned long & GetMemSize()
  233. {
  234. return MemSize;
  235. }
  236. unsigned long & GetMemOffset()
  237. {
  238. return MemOffset;
  239. }
  240. unsigned short & GetWireAlign()
  241. {
  242. return WireAlign;
  243. }
  244. unsigned long & GetWireSize()
  245. {
  246. return WireSize;
  247. }
  248. unsigned long & GetWireOffset()
  249. {
  250. return WireOffset;
  251. }
  252. unsigned short & GetZeePee()
  253. {
  254. return ZeePee;
  255. }
  256. BOOL & GetMustAlign()
  257. {
  258. return MustAlign;
  259. }
  260. BOOL SameOffsets()
  261. {
  262. return ( MemOffset == WireOffset );
  263. }
  264. //
  265. // size etc calculation routines
  266. //
  267. void ReturnSize( XLAT_SIZE_INFO & pCtxt );
  268. void ReturnConfSize( XLAT_SIZE_INFO & pCtxt );
  269. void ReturnUnionSize( XLAT_SIZE_INFO & pCtxt );
  270. void BaseTypeSizes( node_skl * pNode );
  271. void EnumTypeSizes( node_skl * pNode, BOOL Enum32 );
  272. void ContextHandleSizes( node_skl * pNode );
  273. void ArraySize( node_skl * pNode, FIELD_ATTR_INFO * pFA );
  274. void GetOffset( XLAT_SIZE_INFO & pInfo );
  275. void AlignOffset();
  276. void AlignConfOffset();
  277. void AlignEmbeddedUnion();
  278. void AdjustForZP();
  279. void AdjustSize();
  280. void AdjustConfSize();
  281. void AdjustTotalSize();
  282. void Ndr64AdjustTotalStructSize();
  283. void FixMemSizes( node_skl * pNode );
  284. void IgnoredPtrSizes();
  285. void ReturnOffset( XLAT_SIZE_INFO & pInfo )
  286. {
  287. GetOffset( pInfo );
  288. }
  289. };
  290. #endif // __FLDATTR_HXX__