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.

499 lines
11 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989-1999 Microsoft Corporation
  3. Module Name:
  4. ptrgen.cxx
  5. Abstract:
  6. Implementations of the pointer cg class methods.
  7. Notes:
  8. History:
  9. Oct-10-1993 VibhasC Created
  10. ----------------------------------------------------------------------------*/
  11. /****************************************************************************
  12. * include files
  13. ***************************************************************************/
  14. #include "becls.hxx"
  15. #pragma hdrstop
  16. /****************************************************************************
  17. * local definitions
  18. ***************************************************************************/
  19. /****************************************************************************
  20. * local data
  21. ***************************************************************************/
  22. /****************************************************************************
  23. * externs
  24. ***************************************************************************/
  25. /****************************************************************************/
  26. CG_STATUS
  27. CG_POINTER::S_GenInitOutLocals(
  28. CCB * pCCB )
  29. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  30. Routine Description:
  31. Generate code for initialization of server side local variables.
  32. Arguments:
  33. pCCB - A Ptr to the code gen controller block.
  34. Return Value:
  35. Notes:
  36. The source expression field of the ccb has the final presented expression.
  37. ----------------------------------------------------------------------------*/
  38. {
  39. expr_node * pExpr;
  40. if( pCCB->IsRefAllocDone() )
  41. {
  42. pExpr = MakeAddressExpressionNoMatterWhat( GetResource() );
  43. Out_Assign( pCCB, pCCB->GetSourceExpression(), pExpr );
  44. pExpr = pCCB->SetSourceExpression( GetResource() );
  45. Out_Assign( pCCB, GetResource(), new expr_constant( 0L ) );
  46. }
  47. else
  48. pExpr = pCCB->GetSourceExpression();
  49. if( IsRef() && !IsQualifiedPointer() )
  50. {
  51. pCCB->ResetMemoryAllocDone();
  52. pCCB->SetRefAllocDone();
  53. ((CG_NDR *)GetChild())->S_GenInitOutLocals( pCCB );
  54. }
  55. // If it is a byte count pointer, allocate the bytes specified as the
  56. // byte count param.
  57. // else if it is an out sized etc pointer, then must allocate.
  58. if( GetCGID() == ID_CG_BC_PTR )
  59. {
  60. PNAME pName = ((CG_BYTE_COUNT_POINTER *)this)->GetByteCountParam()->GetSymName();
  61. expr_node * pByteCountExpr = new expr_variable( pName );
  62. Out_Alloc(pCCB,
  63. pExpr,
  64. 0,
  65. pByteCountExpr );
  66. }
  67. else if( IsQualifiedPointer() && !(GetCGID() == ID_CG_STRING_PTR) && IsRef() )
  68. {
  69. expr_node * pElementExpr;
  70. expr_node * pFinalExpr;
  71. expr_node * pCheckExpr;
  72. BOOL fIsSigned;
  73. // Fool the presented expression to beleive it is marshalling, so that
  74. // it generates the correct expression.
  75. CGPHASE Ph = pCCB->GetCodeGenPhase();
  76. pCCB->SetCodeGenPhase( CGPHASE_MARSHALL );
  77. // The proper size of the allocation is size times the element size.
  78. pElementExpr = new expr_constant(
  79. (long) (((CG_NDR *)GetChild())->GetMemorySize()) );
  80. pFinalExpr = FinalSizeExpression( pCCB );
  81. fIsSigned = !((node_base_type *)pFinalExpr->GetType()->GetBasicType())->IsUnsigned();
  82. pFinalExpr = new expr_op_binary( OP_STAR,
  83. pFinalExpr,
  84. pElementExpr );
  85. // Allocate the proper size.
  86. // If the size expression is signed and the value is less than 0, we
  87. // need to raise an exception.
  88. if( pCCB->MustCheckBounds() && fIsSigned )
  89. {
  90. pCheckExpr = new expr_op_binary( OP_LESS,
  91. pFinalExpr,
  92. new expr_constant(0L));
  93. Out_If( pCCB, pCheckExpr);
  94. Out_RaiseException( pCCB, "RPC_X_INVALID_BOUND" );
  95. Out_Endif( pCCB );
  96. }
  97. Out_Alloc(pCCB,
  98. pExpr,
  99. 0,
  100. pFinalExpr );
  101. pCCB->SetCodeGenPhase( Ph );
  102. }
  103. return CG_OK;
  104. }
  105. CG_STATUS
  106. CG_STRING_POINTER::GenConfVarianceEtcUnMarshall( CCB* )
  107. {
  108. return CG_OK;
  109. }
  110. /*****************************************************************************
  111. utility functions
  112. *****************************************************************************/
  113. expr_node *
  114. CG_POINTER::GenBindOrUnBindExpression(
  115. CCB * pCCB,
  116. BOOL )
  117. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  118. Routine Description:
  119. Generate the final binding expression.
  120. Arguments:
  121. pCCB - Ptr to Code gen controller block.
  122. fBind - Indicates a bind or unbind code gen.
  123. Return Value:
  124. Notes:
  125. ----------------------------------------------------------------------------*/
  126. {
  127. MIDL_ASSERT( pCCB->GetSourceExpression() );
  128. return new expr_u_deref( pCCB->GetSourceExpression() );
  129. }
  130. CG_STATUS
  131. CG_POINTER::GenRefChecks(
  132. CCB * pCCB )
  133. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  134. Routine Description:
  135. Generate ref checks for a pointer.
  136. Arguments:
  137. Return Value:
  138. CG_OK
  139. Notes:
  140. ----------------------------------------------------------------------------*/
  141. {
  142. expr_node * pSrc = pCCB->GetSourceExpression();
  143. if( IsRef() )
  144. {
  145. if( pCCB->IsRefAllocDone() )
  146. pSrc = pCCB->SetSourceExpression(
  147. MakeDereferentExpressionIfNecessary(
  148. pCCB->GetSourceExpression()));
  149. // using the source expression, check for null ref pointers.
  150. Out_If( pCCB, new expr_u_not( pSrc ) );
  151. Out_RaiseException( pCCB, "RPC_X_NULL_REF_POINTER" );
  152. Out_Endif( pCCB );
  153. pCCB->SetRefAllocDone();
  154. pCCB->ResetMemoryAllocDone();
  155. ((CG_NDR *)GetChild())->GenRefChecks( pCCB );
  156. }
  157. return CG_OK;
  158. }
  159. CG_STATUS
  160. CG_POINTER::S_GenInitInLocals(
  161. CCB * pCCB )
  162. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  163. Routine Description:
  164. Perform in local init code generation. This method does nothing for
  165. pointers. Ref pointers are supposed to pass this message to their
  166. children after setting the appropriate source expressions.
  167. Arguments:
  168. pCCB - The code gen block.
  169. Return Value:
  170. CG_OK
  171. Notes:
  172. ----------------------------------------------------------------------------*/
  173. {
  174. expr_node * pSrc = pCCB->GetSourceExpression();
  175. if( IsRef() )
  176. {
  177. if( pCCB->IsRefAllocDone() )
  178. pSrc = pCCB->SetSourceExpression(
  179. MakeDereferentExpressionIfNecessary(
  180. pCCB->GetSourceExpression()));
  181. ((CG_NDR *)GetChild())->S_GenInitInLocals( pCCB );
  182. }
  183. return CG_OK;
  184. }
  185. expr_node *
  186. CG_POINTER::FinalSizeExpression(
  187. CCB * pCCB )
  188. {
  189. return PresentedSizeExpression( pCCB );
  190. }
  191. expr_node *
  192. CG_POINTER::FinalFirstExpression(
  193. CCB * pCCB )
  194. {
  195. return PresentedFirstExpression( pCCB );
  196. }
  197. expr_node *
  198. CG_POINTER::FinalLengthExpression(
  199. CCB * pCCB )
  200. {
  201. return PresentedLengthExpression( pCCB );
  202. }
  203. expr_node *
  204. CG_STRING_POINTER::PresentedSizeExpression(
  205. CCB * pCCB )
  206. {
  207. if( pCCB->GetCodeGenPhase() == CGPHASE_UNMARSHALL )
  208. {
  209. return GetSizeResource();
  210. }
  211. else
  212. {
  213. return PresentedLengthExpression( pCCB );
  214. }
  215. }
  216. expr_node *
  217. CG_STRING_POINTER::PresentedLengthExpression(
  218. CCB * pCCB )
  219. {
  220. if( pCCB->GetCodeGenPhase() == CGPHASE_UNMARSHALL )
  221. {
  222. return GetLengthResource();
  223. }
  224. else if((pCCB->GetCodeGenPhase() == CGPHASE_MARSHALL ) && !IsUsedInArray())
  225. {
  226. return GetLengthResource();
  227. }
  228. else
  229. {
  230. unsigned short Size = (unsigned short )((CG_NDR *)GetChild())->GetMemorySize();
  231. expr_proc_call * pProc;
  232. PNAME pName;
  233. expr_node * pExpr;
  234. if( Size == 1 )
  235. {
  236. pName = "strlen";
  237. }
  238. else if( Size == 2)
  239. {
  240. pName = "MIDL_wchar_strlen";
  241. }
  242. else
  243. pName = "MIDL_NChar_strlen";
  244. pProc = new expr_proc_call( pName );
  245. pProc->SetParam( new expr_param( pCCB->GetSourceExpression() ));
  246. pExpr = new expr_b_arithmetic( OP_PLUS,
  247. pProc,
  248. new expr_constant( 1L ));
  249. return pExpr;
  250. }
  251. }
  252. expr_node *
  253. CG_SIZE_STRING_POINTER::PresentedSizeExpression(
  254. CCB * pCCB )
  255. {
  256. if( pCCB->GetCodeGenPhase() == CGPHASE_UNMARSHALL )
  257. {
  258. return GetSizeResource();
  259. }
  260. else
  261. {
  262. return GetSizeIsExpr();
  263. }
  264. }
  265. expr_node *
  266. CG_SIZE_POINTER::PresentedSizeExpression(
  267. CCB * pCCB )
  268. {
  269. if( pCCB->GetCodeGenPhase() == CGPHASE_UNMARSHALL )
  270. {
  271. return GetSizeResource();
  272. }
  273. else
  274. {
  275. return GetSizeIsExpr();
  276. }
  277. }
  278. expr_node *
  279. CG_LENGTH_POINTER::PresentedLengthExpression(
  280. CCB * pCCB )
  281. {
  282. if( pCCB->GetCodeGenPhase() == CGPHASE_UNMARSHALL )
  283. {
  284. return GetLengthResource();
  285. }
  286. else
  287. {
  288. return GetLengthIsExpr();
  289. }
  290. }
  291. expr_node *
  292. CG_LENGTH_POINTER::PresentedFirstExpression(
  293. CCB * pCCB )
  294. {
  295. if( pCCB->GetCodeGenPhase() == CGPHASE_UNMARSHALL )
  296. {
  297. return GetFirstResource();
  298. }
  299. else
  300. {
  301. return GetFirstIsExpr();
  302. }
  303. }
  304. expr_node *
  305. CG_SIZE_LENGTH_POINTER::PresentedSizeExpression(
  306. CCB * pCCB )
  307. {
  308. if( pCCB->GetCodeGenPhase() == CGPHASE_UNMARSHALL )
  309. {
  310. return GetSizeResource();
  311. }
  312. else
  313. {
  314. return GetSizeIsExpr();
  315. }
  316. }
  317. expr_node *
  318. CG_SIZE_LENGTH_POINTER::PresentedLengthExpression(
  319. CCB * pCCB )
  320. {
  321. if( pCCB->GetCodeGenPhase() == CGPHASE_UNMARSHALL )
  322. {
  323. return GetLengthResource();
  324. }
  325. else
  326. {
  327. return GetLengthIsExpr();
  328. }
  329. }
  330. expr_node *
  331. CG_SIZE_LENGTH_POINTER::PresentedFirstExpression(
  332. CCB * pCCB )
  333. {
  334. if( pCCB->GetCodeGenPhase() == CGPHASE_UNMARSHALL )
  335. {
  336. return GetFirstResource();
  337. }
  338. else
  339. {
  340. return GetFirstIsExpr();
  341. }
  342. }
  343. CG_STATUS
  344. CG_IIDIS_INTERFACE_POINTER::S_GenInitOutLocals(
  345. CCB * pCCB )
  346. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  347. Routine Description:
  348. Generate the init call for the locals.
  349. Arguments:
  350. pCCB - The ptr to code gen block.
  351. Return Value:
  352. Notes:
  353. ----------------------------------------------------------------------------*/
  354. {
  355. expr_node * pExpr;
  356. if( !pCCB->IsRefAllocDone() )
  357. {
  358. pExpr = new expr_sizeof( GetType() );
  359. Out_Alloc( pCCB, pCCB->GetSourceExpression(), 0, pExpr );
  360. }
  361. else
  362. {
  363. pExpr = MakeAddressExpressionNoMatterWhat( GetResource() );
  364. Out_Assign( pCCB, pCCB->GetSourceExpression(), pExpr );
  365. pExpr = pCCB->SetSourceExpression( GetResource() );
  366. Out_Assign( pCCB, GetResource(), new expr_constant( 0L ) );
  367. }
  368. return CG_OK;
  369. }
  370. CG_STATUS
  371. CG_INTERFACE_POINTER::S_GenInitOutLocals(
  372. CCB * pCCB )
  373. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  374. Routine Description:
  375. Generate the init call for the locals.
  376. Arguments:
  377. pCCB - The ptr to code gen block.
  378. Return Value:
  379. Notes:
  380. ----------------------------------------------------------------------------*/
  381. {
  382. expr_node * pExpr;
  383. if( !pCCB->IsRefAllocDone() )
  384. {
  385. pExpr = new expr_sizeof( GetType() );
  386. Out_Alloc( pCCB, pCCB->GetSourceExpression(), 0, pExpr );
  387. }
  388. else
  389. {
  390. pExpr = MakeAddressExpressionNoMatterWhat( GetResource() );
  391. Out_Assign( pCCB, pCCB->GetSourceExpression(), pExpr );
  392. pExpr = pCCB->SetSourceExpression( GetResource() );
  393. Out_Assign( pCCB, GetResource(), new expr_constant( 0L ) );
  394. }
  395. return CG_OK;
  396. }