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.

551 lines
14 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989-1999 Microsoft Corporation
  3. Module Name:
  4. arrayana.cxx
  5. Abstract:
  6. Implementation of array marshall and unmarshall analysis.
  7. Notes:
  8. History:
  9. Nov-13-1993 VibhasC Created.
  10. ----------------------------------------------------------------------------*/
  11. /****************************************************************************
  12. * include files
  13. ***************************************************************************/
  14. #include "allana.hxx"
  15. #pragma hdrstop
  16. /****************************************************************************
  17. * local definitions
  18. ***************************************************************************/
  19. /****************************************************************************
  20. * local data
  21. ***************************************************************************/
  22. /****************************************************************************
  23. * externs
  24. ***************************************************************************/
  25. /****************************************************************************/
  26. CG_STATUS
  27. CG_FIXED_ARRAY::MarshallAnalysis(
  28. ANALYSIS_INFO * pAna )
  29. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  30. Routine Description:
  31. Perform marshall analysis for a fixed array.
  32. Arguments:
  33. pAna = The analysis block.
  34. Return Value:
  35. CG_OK
  36. Notes:
  37. ----------------------------------------------------------------------------*/
  38. {
  39. CG_NDR * pBasicCGClass = GetBasicCGClass();
  40. ID_CG ID = pBasicCGClass->GetCGID();
  41. BOOL fIsArrayOfUnion = FALSE;
  42. if((ID == ID_CG_UNION) || (ID == ID_CG_ENCAP_STRUCT))
  43. fIsArrayOfUnion = TRUE;
  44. // Temp fix for varying arrays.
  45. if( IsVarying() || fIsArrayOfUnion )
  46. {
  47. return CG_OK;
  48. }
  49. pBasicCGClass->MarshallAnalysis( pAna );
  50. return CG_OK;
  51. }
  52. CG_STATUS
  53. CG_FIXED_ARRAY::FollowerMarshallAnalysis(
  54. ANALYSIS_INFO * pAna )
  55. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  56. Routine Description:
  57. Perform Follower (embedded pointer) marshall analysis on the fixed array
  58. Arguments:
  59. pAna - The analyser block.
  60. Return Value:
  61. CG_OK
  62. Notes:
  63. // For buffer size calculation, we trick the child cg into beleieving it
  64. // is the only element being marshalled, so that it gives us the real
  65. // size per element. Then based on the alignment property before and
  66. // after the analysis, we make the sizing decisions.
  67. ----------------------------------------------------------------------------*/
  68. {
  69. CG_NDR * pBasicCGClass = GetBasicCGClass();
  70. pBasicCGClass->FollowerMarshallAnalysis( pAna );
  71. return CG_OK;
  72. }
  73. CG_STATUS
  74. CG_ARRAY::DimByDimMarshallAnalysis(
  75. ANALYSIS_INFO * pAna )
  76. {
  77. pAna->PushEmbeddingLevel();
  78. GetBasicCGClass()->MarshallAnalysis( pAna );
  79. pAna->PopEmbeddingLevel();
  80. return CG_OK;
  81. }
  82. CG_STATUS
  83. CG_ARRAY::DimByDimUnMarshallAnalysis(
  84. ANALYSIS_INFO* )
  85. {
  86. return CG_OK;
  87. }
  88. CG_STATUS
  89. CG_ARRAY::S_OutLocalAnalysis(
  90. ANALYSIS_INFO * pAna )
  91. {
  92. if( IsFixedArray() )
  93. {
  94. if( pAna->GetCurrentSide() != C_SIDE )
  95. {
  96. PNAME pName = pAna->GenTempResourceName( "A" );
  97. node_skl * pType= MakeIDNode( pName, GetType() );
  98. SetResource( pAna->AddLocalResource( pName, pType ));
  99. }
  100. SetAllocatedOnStack( 1 );
  101. }
  102. return CG_OK;
  103. }
  104. CG_STATUS
  105. CG_ARRAY::MarshallAnalysis(
  106. ANALYSIS_INFO * pAna )
  107. {
  108. ID_CG MyID = GetCGID();
  109. short NoOfDimensions = short( GetDimensions() - 1 );
  110. int i;
  111. //
  112. // Depending upon the id, perform analysis. Basically declare the
  113. // needed local variables.
  114. //
  115. // If it has embedded pointers or if block copy is not possible, declare
  116. // an index variable for each dimension.
  117. if( !IsBlockCopyPossible() )
  118. {
  119. CG_ARRAY * pThis;
  120. for( i = 0, pThis = this;
  121. i <= NoOfDimensions;
  122. i++, pThis = (CG_ARRAY *)pThis->GetChild() )
  123. {
  124. if( !pThis->GetIndexResource() )
  125. {
  126. node_skl * pType;
  127. PNAME pResName = pAna->GenTempResourceName( "I" );
  128. GetBaseTypeNode( &pType, SIGN_UNSIGNED, SIZE_UNDEF, TYPE_INT );
  129. pType = MakeIDNode( pResName, pType );
  130. pThis->SetIndexResource( pAna->AddTransientResource( pResName, pType ));
  131. }
  132. else
  133. pAna->AddTransientResource( GetIndexResource()->GetResourceName(),
  134. GetIndexResource()->GetType()
  135. );
  136. }
  137. DimByDimMarshallAnalysis( pAna );
  138. }
  139. if( IsFixedArray() && !IsArrayOfRefPointers() )
  140. {
  141. CG_FIXED_ARRAY * pThis = (CG_FIXED_ARRAY *)this;
  142. unsigned long TotalSize = pThis->GetNumOfElements();
  143. for( i = 0;
  144. i < NoOfDimensions;
  145. i++, pThis = (CG_FIXED_ARRAY *)pThis->GetChild() )
  146. {
  147. TotalSize = TotalSize * pThis->GetNumOfElements();
  148. }
  149. TotalSize = TotalSize * pThis->GetBasicCGClass()->GetWireSize();
  150. }
  151. if( (MyID == ID_CG_CONF_ARRAY) || (MyID == ID_CG_CONF_VAR_ARRAY))
  152. {
  153. CG_ARRAY * pThis;
  154. for( i = 0, pThis = this;
  155. i <= NoOfDimensions;
  156. i++, pThis = (CG_ARRAY *)pThis->GetChild() )
  157. {
  158. if( !pThis->GetSizeResource() )
  159. {
  160. node_skl * pType;
  161. PNAME pResName = pAna->GenTempResourceName( "S" );
  162. GetBaseTypeNode( &pType, SIGN_UNSIGNED, SIZE_LONG, TYPE_INT );
  163. pType = MakeIDNode( pResName, pType );
  164. pThis->SetSizeResource( pAna->AddTransientResource( pResName, pType ));
  165. }
  166. else
  167. pAna->AddTransientResource(GetSizeResource()->GetResourceName(),
  168. GetSizeResource()->GetType()
  169. );
  170. }
  171. }
  172. //
  173. // If this has any form of variance, generate locals for variance stuff.
  174. //
  175. if( (MyID == ID_CG_VAR_ARRAY ) || (MyID == ID_CG_CONF_VAR_ARRAY ))
  176. {
  177. CG_ARRAY * pThis;
  178. for( i = 0, pThis = this;
  179. i <= NoOfDimensions;
  180. i++, pThis = (CG_ARRAY *)pThis->GetChild() )
  181. {
  182. if( !pThis->GetFirstResource() )
  183. {
  184. node_skl * pType;
  185. PNAME pResName = pAna->GenTempResourceName( "F" );
  186. GetBaseTypeNode( &pType, SIGN_UNSIGNED, SIZE_UNDEF, TYPE_INT );
  187. pType = MakeIDNode( pResName, pType );
  188. pThis->SetFirstResource(pAna->AddTransientResource(pResName, pType));
  189. }
  190. else
  191. pAna->AddTransientResource(GetFirstResource()->GetResourceName(),
  192. GetFirstResource()->GetType()
  193. );
  194. }
  195. for( i = 0, pThis = this;
  196. i <= NoOfDimensions;
  197. i++, pThis = (CG_ARRAY *)pThis->GetChild() )
  198. {
  199. if( !pThis->GetLengthResource() )
  200. {
  201. node_skl * pType;
  202. PNAME pResName = pAna->GenTempResourceName( "L" );
  203. GetBaseTypeNode( &pType, SIGN_UNSIGNED, SIZE_LONG, TYPE_INT );
  204. pType = MakeIDNode( pResName, pType );
  205. pThis->SetLengthResource( pAna->AddTransientResource( pResName, pType ));
  206. }
  207. else
  208. pAna->AddTransientResource(GetLengthResource()->GetResourceName(),
  209. GetLengthResource()->GetType()
  210. );
  211. }
  212. }
  213. if( pAna->IsPointeeDeferred() && HasPointer() )
  214. {
  215. pAna->SetHasAtLeastOneDeferredPointee();
  216. }
  217. return CG_OK;
  218. }
  219. CG_STATUS
  220. CG_ARRAY::UnMarshallAnalysis(
  221. ANALYSIS_INFO * pAna )
  222. {
  223. ID_CG MyID = GetCGID();
  224. short NoOfDimensions = short( GetDimensions() - 1 );
  225. int i;
  226. //
  227. // Depending upon the id, perform analysis. Basically declare the
  228. // needed local variables.
  229. //
  230. // If it has embedded pointers or if block copy is not possible, declare
  231. // an index variable for each dimension.
  232. if( HasPointer() || !IsBlockCopyPossible() )
  233. {
  234. CG_ARRAY * pThis;
  235. for( i = 0, pThis = this;
  236. i <= NoOfDimensions;
  237. i++, pThis = (CG_ARRAY *)pThis->GetChild() )
  238. {
  239. if( !pThis->GetIndexResource() )
  240. {
  241. node_skl * pType;
  242. PNAME pResName= pAna->GenTempResourceName( "I" );
  243. GetBaseTypeNode(&pType,SIGN_UNSIGNED, SIZE_UNDEF, TYPE_INT );
  244. pType = MakeIDNode( pResName, pType );
  245. pThis->SetIndexResource( pAna->AddTransientResource( pResName, pType ));
  246. }
  247. else
  248. pAna->AddTransientResource( pThis->GetIndexResource()->GetResourceName(),
  249. pThis->GetIndexResource()->GetType()
  250. );
  251. }
  252. }
  253. if( (MyID == ID_CG_CONF_ARRAY) || (MyID == ID_CG_CONF_VAR_ARRAY))
  254. {
  255. CG_ARRAY * pThis;
  256. for( i = 0, pThis = this;
  257. i <= NoOfDimensions;
  258. i++, pThis = (CG_ARRAY *)pThis->GetChild() )
  259. {
  260. if( !pThis->GetSizeResource() )
  261. {
  262. node_skl * pType;
  263. PNAME pResName = pAna->GenTempResourceName( "S" );
  264. GetBaseTypeNode( &pType, SIGN_UNSIGNED, SIZE_LONG, TYPE_INT );
  265. pType = MakeIDNode( pResName, pType );
  266. pThis->SetSizeResource( pAna->AddTransientResource( pResName, pType ));
  267. }
  268. else
  269. pAna->AddTransientResource(pThis->GetSizeResource()->GetResourceName(),
  270. pThis->GetSizeResource()->GetType()
  271. );
  272. }
  273. }
  274. //
  275. // If this has any form of variance, generate locals for variance stuff.
  276. //
  277. if( (MyID == ID_CG_VAR_ARRAY ) || (MyID == ID_CG_CONF_VAR_ARRAY ))
  278. {
  279. CG_ARRAY * pThis;
  280. for( i = 0, pThis = this;
  281. i <= NoOfDimensions;
  282. i++, pThis = (CG_ARRAY *)pThis->GetChild() )
  283. {
  284. if( !pThis->GetFirstResource() )
  285. {
  286. node_skl * pType;
  287. PNAME pResName = pAna->GenTempResourceName( "F" );
  288. GetBaseTypeNode( &pType, SIGN_UNSIGNED, SIZE_UNDEF, TYPE_INT );
  289. pType = MakeIDNode( pResName, pType );
  290. pThis->SetFirstResource(pAna->AddTransientResource(pResName, pType));
  291. }
  292. else
  293. pAna->AddTransientResource(pThis->GetFirstResource()->GetResourceName(),
  294. pThis->GetFirstResource()->GetType()
  295. );
  296. }
  297. for( i = 0, pThis = this;
  298. i <= NoOfDimensions;
  299. i++, pThis = (CG_ARRAY *)pThis->GetChild() )
  300. {
  301. if( !pThis->GetLengthResource() )
  302. {
  303. node_skl * pType;
  304. PNAME pResName = pAna->GenTempResourceName( "L" );
  305. GetBaseTypeNode( &pType, SIGN_UNSIGNED, SIZE_LONG, TYPE_INT );
  306. pType = MakeIDNode( pResName, pType );
  307. pThis->SetLengthResource( pAna->AddTransientResource( pResName, pType ));
  308. }
  309. else
  310. pAna->AddTransientResource(pThis->GetLengthResource()->GetResourceName(),
  311. pThis->GetLengthResource()->GetType()
  312. );
  313. }
  314. }
  315. if( HasPointer() )
  316. {
  317. pAna->SetHasAtLeastOneDeferredPointee();
  318. }
  319. return CG_OK;
  320. }
  321. CG_STATUS
  322. CG_ARRAY::FollowerMarshallAnalysis(
  323. ANALYSIS_INFO * pAna )
  324. {
  325. pAna;
  326. return CG_OK;
  327. }
  328. CG_STATUS
  329. CG_ARRAY::FollowerUnMarshallAnalysis(
  330. ANALYSIS_INFO * pAna )
  331. {
  332. node_skl * pType = GetBasicCGClass()->GetType();
  333. PNAME pName;
  334. // Declare a local variable for a member by member unmarshall of the
  335. // array elements.
  336. pName = pAna->GenTempResourceName("PE");
  337. pType = MakePtrIDNode( pName, pType );
  338. SetPtrResource( pAna->AddTransientResource( pName, pType ) );
  339. GetBasicCGClass()->FollowerUnMarshallAnalysis( pAna );
  340. return CG_OK;
  341. }
  342. CG_STATUS
  343. CG_ARRAY::RefCheckAnalysis(
  344. ANALYSIS_INFO * pAna )
  345. {
  346. int i;
  347. int NoOfDimensions = GetDimensions();
  348. if( IsArrayOfRefPointers() )
  349. {
  350. // Allocate an index resource per dimension.
  351. CG_ARRAY * pThis;
  352. for( i = 0, pThis = this;
  353. i < NoOfDimensions;
  354. i++, pThis = (CG_ARRAY *)pThis->GetChild() )
  355. {
  356. if( !pThis->GetIndexResource() )
  357. {
  358. node_skl * pType;
  359. PNAME pResName = pAna->GenTempResourceName( "I" );
  360. GetBaseTypeNode( &pType, SIGN_UNSIGNED, SIZE_UNDEF, TYPE_INT );
  361. pType = MakeIDNode( pResName, pType );
  362. pThis->SetIndexResource( pAna->AddLocalResource( pResName, pType ));
  363. }
  364. else
  365. pAna->AddLocalResource(
  366. GetIndexResource()->GetResourceName(),
  367. GetIndexResource()->GetType()
  368. );
  369. }
  370. }
  371. return CG_OK;
  372. }
  373. CG_STATUS
  374. CG_ARRAY::InLocalAnalysis(
  375. ANALYSIS_INFO * pAna )
  376. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  377. Routine Description:
  378. Perform Allocation of local resources on server side stub for an
  379. array of ref pointers.
  380. Arguments:
  381. Return Value:
  382. CG_OK
  383. Notes:
  384. ----------------------------------------------------------------------------*/
  385. {
  386. if( IsArrayOfRefPointers() && IsFixedArray() )
  387. {
  388. if( !GetInLocalResource() )
  389. {
  390. node_skl * pType = GetType();
  391. PNAME pResName = pAna->GenTempResourceName( "A" );
  392. pType = MakeIDNode( pResName, pType );
  393. SetInLocalResource(pAna->AddLocalResource(pResName,pType));
  394. }
  395. else
  396. {
  397. pAna->AddLocalResource(
  398. GetInLocalResource()->GetResourceName(),
  399. GetInLocalResource()->GetType()
  400. );
  401. }
  402. }
  403. return CG_OK;
  404. }
  405. /*****************************************************************************
  406. CG_STRING_ARRAY methods.
  407. *****************************************************************************/
  408. CG_STATUS
  409. CG_STRING_ARRAY::MarshallAnalysis(
  410. ANALYSIS_INFO * pAna )
  411. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  412. Routine Description:
  413. Perform marshall analysis for a fixed string array.
  414. Arguments:
  415. pAna = The analysis block.
  416. Return Value:
  417. CG_OK
  418. Notes:
  419. For now this will work only for a single dimensional array on which
  420. [string] is applied.
  421. ----------------------------------------------------------------------------*/
  422. {
  423. CG_NDR * pBasicCGClass = GetBasicCGClass();
  424. pBasicCGClass->MarshallAnalysis( pAna );
  425. return CG_OK;
  426. }
  427. /*****************************************************************************
  428. CG_VARYING_ARRAY methods.
  429. *****************************************************************************/
  430. CG_STATUS
  431. CG_VARYING_ARRAY::MarshallAnalysis(
  432. ANALYSIS_INFO * pAna )
  433. {
  434. pAna;
  435. return CG_OK;
  436. }