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.

456 lines
10 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989-1999 Microsoft Corporation
  3. Module Name:
  4. fldcls.hxx
  5. Abstract:
  6. Contains definitions for base type related code generation class
  7. definitions.
  8. Notes:
  9. History:
  10. GregJen Sep-30-1993 Created.
  11. ----------------------------------------------------------------------------*/
  12. #ifndef __FLDCLS_HXX__
  13. #define __FLDCLS_HXX__
  14. #pragma warning ( disable : 4238 4239 )
  15. #include "nulldefs.h"
  16. extern "C"
  17. {
  18. #include <stdio.h>
  19. }
  20. #include "ndrcls.hxx"
  21. //
  22. // This class corresponds to a structure field type.
  23. //
  24. class CG_FIELD : public CG_NDR, public CG_CLONEABLE
  25. {
  26. private:
  27. unsigned long MemOffset;
  28. unsigned long WireOffset;
  29. // These two are union specific.
  30. expr_node * pSwitchExpr;
  31. // Used to hold a union field's format string offset.
  32. long UnionFormatStringOffset;
  33. //
  34. // All this is used to help fixed imbeded struct's with pointers.
  35. //
  36. BOOL fClonedField : 1;
  37. BOOL fSizeIsDone : 1;
  38. BOOL fIsRegionField : 1;
  39. // more stuff for embedded unknown represent_as
  40. BOOL fEmbeddedUnknownRepAs : 1;
  41. char * PrintPrefix;
  42. expr_node * pSizeExpression;
  43. CG_STRUCT * pRegionHint;
  44. public:
  45. //
  46. // The constructor.
  47. //
  48. CG_FIELD(
  49. node_skl * pBT, // base type
  50. XLAT_SIZE_INFO & Info // memory offset etc
  51. ) :
  52. CG_NDR( pBT, Info )
  53. {
  54. MemOffset = Info.GetMemOffset();
  55. WireOffset = Info.GetWireOffset();
  56. pSwitchExpr = NULL;
  57. UnionFormatStringOffset = -1;
  58. SetSizeIsDone( FALSE );
  59. fIsRegionField = FALSE;
  60. fClonedField = FALSE;
  61. PrintPrefix = "";
  62. fEmbeddedUnknownRepAs = FALSE;
  63. SetSizeExpression( NULL );
  64. pRegionHint = NULL;
  65. }
  66. CG_FIELD( const CG_FIELD & Field ) :
  67. CG_NDR( (CG_NDR &)Field )
  68. {
  69. MemOffset = Field.MemOffset;
  70. WireOffset = Field.MemOffset;
  71. pSwitchExpr = Field.pSwitchExpr;
  72. UnionFormatStringOffset = Field.UnionFormatStringOffset;
  73. fEmbeddedUnknownRepAs = Field.fEmbeddedUnknownRepAs;
  74. pSizeExpression = Field.pSizeExpression;
  75. fClonedField = TRUE;
  76. fSizeIsDone = FALSE;
  77. fIsRegionField = Field.fIsRegionField;
  78. // Make a new copy of the PrintPrefix field.
  79. PrintPrefix = new char[
  80. strlen( Field.GetPrintPrefix() ) + 1];
  81. strcpy( PrintPrefix, Field.GetPrintPrefix() );
  82. pRegionHint = Field.GetRegionHint();
  83. }
  84. CG_CLASS * Clone()
  85. {
  86. return new CG_FIELD( *this );
  87. }
  88. virtual
  89. ID_CG GetCGID()
  90. {
  91. return ID_CG_FIELD;
  92. }
  93. virtual
  94. void Visit( CG_VISITOR *pVisitor )
  95. {
  96. pVisitor->Visit( this );
  97. }
  98. //
  99. // Generate typeinfo
  100. //
  101. virtual
  102. CG_STATUS GenTypeInfo( CCB * pCCB);
  103. //
  104. // Get and set methods.
  105. //
  106. // make sure the ZP gets set along the way
  107. virtual
  108. void SetSizesAndAlignments( XLAT_SIZE_INFO & Info )
  109. {
  110. CG_NDR::SetSizesAndAlignments( Info );
  111. MemOffset = Info.GetMemOffset();
  112. WireOffset = Info.GetWireOffset();
  113. }
  114. unsigned long GetMemOffset()
  115. {
  116. return MemOffset;
  117. }
  118. void SetMemOffset( unsigned long offset )
  119. {
  120. MemOffset = offset;
  121. }
  122. unsigned long GetWireOffset()
  123. {
  124. return WireOffset;
  125. }
  126. void SetWireOffset( unsigned long offset )
  127. {
  128. WireOffset = offset;
  129. }
  130. expr_node * SetSwitchExpr( expr_node * pE )
  131. {
  132. return (pSwitchExpr = pE);
  133. }
  134. expr_node * GetSwitchExpr()
  135. {
  136. return pSwitchExpr;
  137. }
  138. BOOL IsClonedField()
  139. {
  140. return fClonedField;
  141. }
  142. BOOL SetHasEmbeddedUnknownRepAs()
  143. {
  144. return (BOOL) (fEmbeddedUnknownRepAs = TRUE);
  145. }
  146. BOOL HasEmbeddedUnknownRepAs()
  147. {
  148. return (BOOL) fEmbeddedUnknownRepAs;
  149. }
  150. void SetSizeIsDone( BOOL b )
  151. {
  152. fSizeIsDone = b;
  153. }
  154. BOOL GetSizeIsDone()
  155. {
  156. //
  157. // If this is a cloned field then we return
  158. // the fSizeIsDone flag, otherwise we always
  159. // return FALSE.
  160. //
  161. if ( IsClonedField() )
  162. return fSizeIsDone;
  163. else
  164. return FALSE;
  165. }
  166. void AddPrintPrefix( char * Prefix )
  167. {
  168. char * OldPrefix;
  169. OldPrefix = PrintPrefix;
  170. PrintPrefix = new char[ strlen(PrintPrefix) +
  171. strlen(Prefix) + 2 ];
  172. //
  173. // We add the new print prefix to the
  174. // BEGINNING of the prefix string and we insert
  175. // a '.' in between.
  176. //
  177. strcpy( PrintPrefix, Prefix );
  178. strcat( PrintPrefix, "." );
  179. strcat( PrintPrefix, OldPrefix );
  180. }
  181. char * GetPrintPrefix() const
  182. {
  183. return PrintPrefix;
  184. }
  185. void SetUnionFormatStringOffset( long offset )
  186. {
  187. UnionFormatStringOffset = offset;
  188. }
  189. long GetUnionFormatStringOffset()
  190. {
  191. return UnionFormatStringOffset;
  192. }
  193. expr_node * SetSizeExpression( expr_node * pE )
  194. {
  195. return (pSizeExpression = pE);
  196. }
  197. expr_node * GetSizeExpression()
  198. {
  199. return pSizeExpression;
  200. }
  201. virtual
  202. BOOL HasAFixedBufferSize()
  203. {
  204. return (GetChild()->HasAFixedBufferSize());
  205. }
  206. BOOL IsRegionField() const
  207. {
  208. return fIsRegionField;
  209. }
  210. void SetIsRegionField()
  211. {
  212. fIsRegionField = TRUE;
  213. }
  214. CG_STRUCT * GetRegionHint() const
  215. {
  216. return pRegionHint;
  217. }
  218. void SetRegionHint( CG_STRUCT *pHint )
  219. {
  220. pRegionHint = pHint;
  221. }
  222. };
  223. //
  224. // This class corresponds to a union field type.
  225. //
  226. class CG_UNION_FIELD : public CG_FIELD
  227. {
  228. private:
  229. public:
  230. //
  231. // The constructor.
  232. //
  233. CG_UNION_FIELD(
  234. node_skl * pBT, // base type
  235. XLAT_SIZE_INFO & Info
  236. ) :
  237. CG_FIELD( pBT, Info )
  238. {
  239. }
  240. virtual
  241. ID_CG GetCGID()
  242. {
  243. return ID_CG_UNION_FIELD;
  244. }
  245. virtual
  246. void Visit( CG_VISITOR *pVisitor )
  247. {
  248. pVisitor->Visit( this );
  249. }
  250. virtual
  251. CG_CLASS* Clone()
  252. {
  253. return new CG_UNION_FIELD( *this );
  254. }
  255. };
  256. //
  257. // This class corresponds to a union case
  258. //
  259. class CG_CASE : public CG_NDR, public CG_CLONEABLE
  260. {
  261. private:
  262. expr_node * pExpr;
  263. BOOL fLastCase; // last case for this arm
  264. public:
  265. //
  266. // The constructor.
  267. //
  268. CG_CASE(
  269. node_skl * pBT, // expression type
  270. expr_node * pE // expression
  271. ) :
  272. CG_NDR( pBT, XLAT_SIZE_INFO() )
  273. {
  274. SetExpr( pE );
  275. fLastCase = FALSE;
  276. }
  277. virtual
  278. CG_STATUS GenTypeInfo(CCB *pCCB);
  279. virtual
  280. ID_CG GetCGID()
  281. {
  282. return ID_CG_CASE;
  283. }
  284. virtual
  285. CG_CLASS* Clone()
  286. {
  287. return new CG_CASE( *this );
  288. }
  289. virtual
  290. void Visit( CG_VISITOR *pVisitor )
  291. {
  292. pVisitor->Visit( this );
  293. }
  294. //
  295. // Get and set methods.
  296. //
  297. expr_node * SetExpr( expr_node * pE )
  298. {
  299. return (pExpr = pE);
  300. }
  301. expr_node * GetExpr()
  302. {
  303. return pExpr;
  304. }
  305. BOOL SetLastCase( BOOL Flag )
  306. {
  307. return (fLastCase = Flag);
  308. }
  309. BOOL FLastCase()
  310. {
  311. return fLastCase;
  312. }
  313. };
  314. //
  315. // This class corresponds to a union default case
  316. //
  317. class CG_DEFAULT_CASE : public CG_CASE
  318. {
  319. private:
  320. public:
  321. //
  322. // The constructor.
  323. //
  324. CG_DEFAULT_CASE(
  325. node_skl * pBT // expression type
  326. ) :
  327. CG_CASE( pBT, NULL )
  328. {
  329. }
  330. virtual
  331. ID_CG GetCGID()
  332. {
  333. return ID_CG_DEFAULT_CASE;
  334. }
  335. virtual
  336. void Visit( CG_VISITOR *pVisitor )
  337. {
  338. pVisitor->Visit( this );
  339. }
  340. virtual
  341. CG_CLASS* Clone()
  342. {
  343. return new CG_DEFAULT_CASE( *this );
  344. }
  345. //
  346. // Get and set methods.
  347. //
  348. };
  349. #endif // __FLDCLS_HXX__